diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Ability/AbilityFeature/AppScope/app.json5 b/code/BasicFeature/Ability/AbilityFeature/AppScope/app.json5 index 151a5d2ac9a4d845b96d8d47bfd4aa7d019c859b..0a2e1b209ca5ffa5e78f7c325090f5fc2c8e832b 100644 --- a/code/BasicFeature/Ability/AbilityFeature/AppScope/app.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.abilityFeature", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.abilityFeature", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Ability/AbilityFeature/AppScope/resources/base/element/string.json b/code/BasicFeature/Ability/AbilityFeature/AppScope/resources/base/element/string.json index 7f9e90ebc7812d334e0423f3c46fa1899f325550..3c15b21f5a08edb9efae62d0937dff7c257fb14f 100644 --- a/code/BasicFeature/Ability/AbilityFeature/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Ability/AbilityFeature/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AbilityFeature" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AbilityFeature" + } + ] +} diff --git a/code/BasicFeature/Ability/AbilityFeature/README_zh.md b/code/BasicFeature/Ability/AbilityFeature/README_zh.md index 42a50d6eebcfb331542fd3e9d26d1402c225ec63..bc3e4ff2fc6499916dd2a3efe0d3d0ff3a05428d 100644 --- a/code/BasicFeature/Ability/AbilityFeature/README_zh.md +++ b/code/BasicFeature/Ability/AbilityFeature/README_zh.md @@ -1,98 +1,98 @@ -# 基础能力增强 - -### 介绍 - -本示例使用 [ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) ,[ohos.ability.wantConstant](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-ability-wantConstant.md) ,[ohos.app.ability.StartOptions](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-startOptions.md)等接口实现了以下功能: - -1. 支持应用定制系统环境参数; - -5. 支持隐式启动个数为0时才触发提示弹框--增加了一个flag; - -6. 支持应用清理自己的数据; - -7. Ability启动参数支持传递初始位置/初始大小/是否携带动效; - -### 效果预览 - -| 主页面 | 隐式启动弹窗 | 英文切换页 | 深色模式切换页 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | :--------------------------------------------------: | :--------------------------------------------------: | -| | | ![](./screenshots/Screenshot_20231208091638669.jpeg) | ![](./screenshots/Screenshot_20231208091619146.jpeg) | - -使用说明 - -1.应用切换语言的能力; - -点击'切换英文语言'的ListItem,当前页面切换为英文,标题'基础能力增强'切换成'Basic capabilities are enhanced' -,点击'切换中文语言'的ListItem,当前页面切换为中文,标题'Basic capabilities are enhanced'切换成'基础能力增强'; - -2.应用切换颜色模式的能力 - -点击'切换深色模式'的ListItem,当前页面颜色切换为深色,弹出Toast提示'切换成功',点击'切换浅色模式' -的ListItem,当前页面颜色切换为浅色,弹出Toast提示'切换成功'; - -3.应用隐式启动个数为0时,才触发提示弹框的特性 - -点击'隐式启动弹窗'的ListItem,弹出弹窗,弹窗标题为'未找到文件',点击'隐式启动不弹窗' -的ListItem,弹出Toast提示'隐式启动不弹窗',且无弹窗(仅支持rk); - -4.应用清理自己的数据的能力 - -点击'创建数据'的ListItem,弹出Toast提示创建'缓存文件成功',点击'检查数据'的ListItem,弹出Toast提示创建'查询到缓存文件' -,点击'清除数据'的ListItem,应用清理缓存文件后自动退出。手动重新启动应用后,点击'检查数据'的ListItem,弹出Toast提示创建'未找到缓存文件'; - -5.应用可以设置启动参数启动Ability能力 - -点击'StartOptions配置'的ListItem,应用启动NewAbility。返回主界面后,点击'启动动画'的Toggle,再点击' -StartOptions配置'的ListItem,应用启动NewAbility; - -### 工程目录 - -``` -entry/src/main/ets/ -|---characteroperation -| |---CharacterOperation.ets // 调用applicationContext方法的工具类 -|---entryability -| |---EntryAbility.ets // 首页的Ability -|---pages -| |---Index.ets // 首页 -| |---New.ets // 被启动UIAbility的展示页 -|---newability -| |---NewAbility.ets // 被启动的UIAbility(验证新接口启动使用) -|---utils // 工具 -| |---Logger.ets // 日志工具 -``` - -### 具体实现 - -- 应用切换语言的功能接口封装在CharacterOperation,使用[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) 调用setLanguage(language: string): void方法实现,源码参考:[CharacterOperation.ets](entry/src/main/ets/characteroperation/CharacterOperation.ets) -- 应用切换颜色模式的功能接口封装在CharacterOperation,使用[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) 调用setColorMode(colorMode: ConfigurationConstant.ColorMode): void方法实现,源码参考:[CharacterOperation.ets](entry/src/main/ets/characteroperation/CharacterOperation.ets) -- 应用清理自己的数据的功能接口封装在CharacterOperation,使用[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) 调用clearUpApplicationData(callback: AsyncCallback): void方法实现,源码参考:[CharacterOperation.ets](entry/src/main/ets/characteroperation/CharacterOperation.ets) -- 应用隐式启动个数为0时不触发提示弹框的特性,通过给Want的flags设置为FLAG_START_WITHOUT_TIPS,源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) -- 应用可以设置启动参数启动Ability能力,通过给startAbility(want: Want, options: StartOptions, callback: AsyncCallback): void;方法传递新增参数StartOptions来设置启动位置,大小以及是否包含动画,源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) - -### 相关权限 - -无 - -### 依赖 - -无 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568; - -2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.5.1; - -3.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; - -### 下载 - -```shell -git init -git config core.sparsecheckout true -echo code/BasicFeature/Ability/AbilityFeature/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# 基础能力增强 + +### 介绍 + +本示例使用 [ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) ,[ohos.ability.wantConstant](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-ability-wantConstant.md) ,[ohos.app.ability.StartOptions](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-startOptions.md)等接口实现了以下功能: + +1. 支持应用定制系统环境参数; + +5. 支持隐式启动个数为0时才触发提示弹框--增加了一个flag; + +6. 支持应用清理自己的数据; + +7. Ability启动参数支持传递初始位置/初始大小/是否携带动效; + +### 效果预览 + +| 主页面 | 隐式启动弹窗 | 英文切换页 | 深色模式切换页 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | :--------------------------------------------------: | :--------------------------------------------------: | +| | | ![](./screenshots/Screenshot_20231208091638669.jpeg) | ![](./screenshots/Screenshot_20231208091619146.jpeg) | + +使用说明 + +1.应用切换语言的能力; + +点击'切换英文语言'的ListItem,当前页面切换为英文,标题'基础能力增强'切换成'Basic capabilities are enhanced' +,点击'切换中文语言'的ListItem,当前页面切换为中文,标题'Basic capabilities are enhanced'切换成'基础能力增强'; + +2.应用切换颜色模式的能力 + +点击'切换深色模式'的ListItem,当前页面颜色切换为深色,弹出Toast提示'切换成功',点击'切换浅色模式' +的ListItem,当前页面颜色切换为浅色,弹出Toast提示'切换成功'; + +3.应用隐式启动个数为0时,才触发提示弹框的特性 + +点击'隐式启动弹窗'的ListItem,弹出弹窗,弹窗标题为'未找到文件',点击'隐式启动不弹窗' +的ListItem,弹出Toast提示'隐式启动不弹窗',且无弹窗(仅支持rk); + +4.应用清理自己的数据的能力 + +点击'创建数据'的ListItem,弹出Toast提示创建'缓存文件成功',点击'检查数据'的ListItem,弹出Toast提示创建'查询到缓存文件' +,点击'清除数据'的ListItem,应用清理缓存文件后自动退出。手动重新启动应用后,点击'检查数据'的ListItem,弹出Toast提示创建'未找到缓存文件'; + +5.应用可以设置启动参数启动Ability能力 + +点击'StartOptions配置'的ListItem,应用启动NewAbility。返回主界面后,点击'启动动画'的Toggle,再点击' +StartOptions配置'的ListItem,应用启动NewAbility; + +### 工程目录 + +``` +entry/src/main/ets/ +|---characteroperation +| |---CharacterOperation.ets // 调用applicationContext方法的工具类 +|---entryability +| |---EntryAbility.ets // 首页的Ability +|---pages +| |---Index.ets // 首页 +| |---New.ets // 被启动UIAbility的展示页 +|---newability +| |---NewAbility.ets // 被启动的UIAbility(验证新接口启动使用) +|---utils // 工具 +| |---Logger.ets // 日志工具 +``` + +### 具体实现 + +- 应用切换语言的功能接口封装在CharacterOperation,使用[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) 调用setLanguage(language: string): void方法实现,源码参考:[CharacterOperation.ets](entry/src/main/ets/characteroperation/CharacterOperation.ets) +- 应用切换颜色模式的功能接口封装在CharacterOperation,使用[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) 调用setColorMode(colorMode: ConfigurationConstant.ColorMode): void方法实现,源码参考:[CharacterOperation.ets](entry/src/main/ets/characteroperation/CharacterOperation.ets) +- 应用清理自己的数据的功能接口封装在CharacterOperation,使用[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md) 调用clearUpApplicationData(callback: AsyncCallback): void方法实现,源码参考:[CharacterOperation.ets](entry/src/main/ets/characteroperation/CharacterOperation.ets) +- 应用隐式启动个数为0时不触发提示弹框的特性,通过给Want的flags设置为FLAG_START_WITHOUT_TIPS,源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) +- 应用可以设置启动参数启动Ability能力,通过给startAbility(want: Want, options: StartOptions, callback: AsyncCallback): void;方法传递新增参数StartOptions来设置启动位置,大小以及是否包含动画,源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) + +### 相关权限 + +无 + +### 依赖 + +无 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568; + +2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.5.1; + +3.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; + +### 下载 + +```shell +git init +git config core.sparsecheckout true +echo code/BasicFeature/Ability/AbilityFeature/ > .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/Ability/AbilityFeature/build-profile.json5 b/code/BasicFeature/Ability/AbilityFeature/build-profile.json5 index 6e4824ee32c74ed2c8150843557de85a879e7c39..51d43b29fefc5fa4622edbb868c588525238f272 100644 --- a/code/BasicFeature/Ability/AbilityFeature/build-profile.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/build-profile.json5 @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/build-profile.json5 b/code/BasicFeature/Ability/AbilityFeature/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/build-profile.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/oh-package.json5 b/code/BasicFeature/Ability/AbilityFeature/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/oh-package.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/characteroperation/CharacterOperation.ets b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/characteroperation/CharacterOperation.ets index 9a5778e9e502d9e5483102b942edd79cdc0aa4f4..290786979084f19a17ecf37ff3116a6a2a492eef 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/characteroperation/CharacterOperation.ets +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/characteroperation/CharacterOperation.ets @@ -1,146 +1,146 @@ -/* - * Copyright (c) 2023 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 ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; -import fs from '@ohos.file.fs'; -import prompt from '@ohos.promptAction'; -import { logger } from '../util/Logger'; - -const TAG: string = 'EntryAbility'; -const TIME: number = 3000; - -export default class CharacterOperation { - private context: Context; - - constructor(context: Context) { - this.context = context; - } - // 设置中文 - setZHCNLanguage = () => { - let applicationContext = this.context.getApplicationContext(); - applicationContext.setLanguage('zh-cn'); - logger.info(`${TAG} Chinese success`); - } - // 设置英文 - setENUSLanguage = () => { - let applicationContext = this.context.getApplicationContext(); - applicationContext.setLanguage('en-us'); - logger.info(`${TAG} English success`); - } - // 设置深色模式 - setDarKColorMode = () => { - let applicationContext = this.context.getApplicationContext(); - applicationContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); - prompt.showToast({ - message: $r('app.string.switchDarkSuccess'), duration: TIME - }); - } - // 设置浅色模式 - setLightColorMode = () => { - let applicationContext = this.context.getApplicationContext(); - applicationContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT); - prompt.showToast({ - message: $r('app.string.switchLightSuccess'), duration: TIME - }); - } - // 获取缓存路径 - generateStorageFiles = () => { - let context = this.context; - let filePathName = '/test.txt'; - let cacheDirPath = context.cacheDir + filePathName; - let filesDirPath = context.filesDir + filePathName; - let preferencesDirPath = context.preferencesDir + filePathName; - let tempDirPath = context.tempDir + filePathName; - let databaseDirPath = context.databaseDir + filePathName; - - return [cacheDirPath, filesDirPath, preferencesDirPath, tempDirPath, databaseDirPath]; - } - // 创建存储数据 - createStorageData = () => { - let context = this.context; - let filePathName = '/test.txt'; - let cacheDirPath = context.cacheDir + filePathName; - let filesDirPath = context.filesDir + filePathName; - let preferencesDirPath = context.preferencesDir + filePathName; - let tempDirPath = context.tempDir + filePathName; - let databaseDirPath = context.databaseDir + filePathName; - try { - let file1 = fs.openSync(cacheDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - let file2 = fs.openSync(filesDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - let file3 = fs.openSync(preferencesDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - let file4 = fs.openSync(tempDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - let file5 = fs.openSync(databaseDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - - fs.closeSync(file1); - fs.closeSync(file2); - fs.closeSync(file3); - fs.closeSync(file4); - fs.closeSync(file5); - - if (fs.accessSync(cacheDirPath) && fs.accessSync(filesDirPath) - && fs.accessSync(preferencesDirPath) && fs.accessSync(tempDirPath) - && fs.accessSync(databaseDirPath)) { - prompt.showToast({ - message: $r('app.string.create_File_Success'), duration: TIME - }); - } - } catch (error) { - } - } - // 检查文件 - checkStorageData = () => { - let context = this.context; - let filePathName = '/test.txt'; - let cacheDirPath = context.cacheDir + filePathName; - let filesDirPath = context.filesDir + filePathName; - let preferencesDirPath = context.preferencesDir + filePathName; - let tempDirPath = context.tempDir + filePathName; - let databaseDirPath = context.databaseDir + filePathName; - if (fs.accessSync(cacheDirPath) && fs.accessSync(filesDirPath) - && fs.accessSync(preferencesDirPath) && fs.accessSync(tempDirPath) && fs.accessSync(databaseDirPath)) { - prompt.showToast({ - message: $r('app.string.search_File_Success'), duration: TIME - }); - } else { - prompt.showToast({ - message: $r('app.string.search_File_Failed'), duration: TIME - }); - } - } - // 清理存储数据 - clearStorageData = () => { - let context = this.context; - let filePathName = '/test.txt'; - let cacheDirPath = context.cacheDir + filePathName; - let filesDirPath = context.filesDir + filePathName; - let preferencesDirPath = context.preferencesDir + filePathName; - let tempDirPath = context.tempDir + filePathName; - let databaseDirPath = context.databaseDir + filePathName; - if (fs.accessSync(cacheDirPath) && fs.accessSync(filesDirPath) && fs.accessSync(preferencesDirPath) - && fs.accessSync(tempDirPath) && fs.accessSync(databaseDirPath)) { - context.getApplicationContext().clearUpApplicationData((err) => { - logger.info(`clearUpApplicationData err:${JSON.stringify(err)}}`); - prompt.showToast({ - message: $r('app.string.clean_Data_Success'), duration: TIME - }); - }); - } else { - // 清理存储数据失败 - prompt.showToast({ - message: $r('app.string.clean_Data_Failed'), duration: TIME - }); - } - } -} +/* + * Copyright (c) 2023 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 ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; +import fs from '@ohos.file.fs'; +import prompt from '@ohos.promptAction'; +import { logger } from '../util/Logger'; + +const TAG: string = 'EntryAbility'; +const TIME: number = 3000; + +export default class CharacterOperation { + private context: Context; + + constructor(context: Context) { + this.context = context; + } + // 设置中文 + setZHCNLanguage = () => { + let applicationContext = this.context.getApplicationContext(); + applicationContext.setLanguage('zh-cn'); + logger.info(`${TAG} Chinese success`); + } + // 设置英文 + setENUSLanguage = () => { + let applicationContext = this.context.getApplicationContext(); + applicationContext.setLanguage('en-us'); + logger.info(`${TAG} English success`); + } + // 设置深色模式 + setDarKColorMode = () => { + let applicationContext = this.context.getApplicationContext(); + applicationContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_DARK); + prompt.showToast({ + message: $r('app.string.switchDarkSuccess'), duration: TIME + }); + } + // 设置浅色模式 + setLightColorMode = () => { + let applicationContext = this.context.getApplicationContext(); + applicationContext.setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT); + prompt.showToast({ + message: $r('app.string.switchLightSuccess'), duration: TIME + }); + } + // 获取缓存路径 + generateStorageFiles = () => { + let context = this.context; + let filePathName = '/test.txt'; + let cacheDirPath = context.cacheDir + filePathName; + let filesDirPath = context.filesDir + filePathName; + let preferencesDirPath = context.preferencesDir + filePathName; + let tempDirPath = context.tempDir + filePathName; + let databaseDirPath = context.databaseDir + filePathName; + + return [cacheDirPath, filesDirPath, preferencesDirPath, tempDirPath, databaseDirPath]; + } + // 创建存储数据 + createStorageData = () => { + let context = this.context; + let filePathName = '/test.txt'; + let cacheDirPath = context.cacheDir + filePathName; + let filesDirPath = context.filesDir + filePathName; + let preferencesDirPath = context.preferencesDir + filePathName; + let tempDirPath = context.tempDir + filePathName; + let databaseDirPath = context.databaseDir + filePathName; + try { + let file1 = fs.openSync(cacheDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + let file2 = fs.openSync(filesDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + let file3 = fs.openSync(preferencesDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + let file4 = fs.openSync(tempDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + let file5 = fs.openSync(databaseDirPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + + fs.closeSync(file1); + fs.closeSync(file2); + fs.closeSync(file3); + fs.closeSync(file4); + fs.closeSync(file5); + + if (fs.accessSync(cacheDirPath) && fs.accessSync(filesDirPath) + && fs.accessSync(preferencesDirPath) && fs.accessSync(tempDirPath) + && fs.accessSync(databaseDirPath)) { + prompt.showToast({ + message: $r('app.string.create_File_Success'), duration: TIME + }); + } + } catch (error) { + } + } + // 检查文件 + checkStorageData = () => { + let context = this.context; + let filePathName = '/test.txt'; + let cacheDirPath = context.cacheDir + filePathName; + let filesDirPath = context.filesDir + filePathName; + let preferencesDirPath = context.preferencesDir + filePathName; + let tempDirPath = context.tempDir + filePathName; + let databaseDirPath = context.databaseDir + filePathName; + if (fs.accessSync(cacheDirPath) && fs.accessSync(filesDirPath) + && fs.accessSync(preferencesDirPath) && fs.accessSync(tempDirPath) && fs.accessSync(databaseDirPath)) { + prompt.showToast({ + message: $r('app.string.search_File_Success'), duration: TIME + }); + } else { + prompt.showToast({ + message: $r('app.string.search_File_Failed'), duration: TIME + }); + } + } + // 清理存储数据 + clearStorageData = () => { + let context = this.context; + let filePathName = '/test.txt'; + let cacheDirPath = context.cacheDir + filePathName; + let filesDirPath = context.filesDir + filePathName; + let preferencesDirPath = context.preferencesDir + filePathName; + let tempDirPath = context.tempDir + filePathName; + let databaseDirPath = context.databaseDir + filePathName; + if (fs.accessSync(cacheDirPath) && fs.accessSync(filesDirPath) && fs.accessSync(preferencesDirPath) + && fs.accessSync(tempDirPath) && fs.accessSync(databaseDirPath)) { + context.getApplicationContext().clearUpApplicationData((err) => { + logger.info(`clearUpApplicationData err:${JSON.stringify(err)}}`); + prompt.showToast({ + message: $r('app.string.clean_Data_Success'), duration: TIME + }); + }); + } else { + // 清理存储数据失败 + prompt.showToast({ + message: $r('app.string.clean_Data_Failed'), duration: TIME + }); + } + } +} diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/entryability/EntryAbility.ets index f640336e76d40da47dc2cfe81cb8bf326a3e8efc..d759f4f0a6333fc2ba066566399d9decaf3cef4e 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; -import { logger } from '../util/Logger'; - -export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - windowStage.loadContent('pages/Index', (err: BusinessError) => { - }); - windowStage.getMainWindow((err, windowClass) => { - if (err.code) { - return; - } - windowClass.setWindowLayoutFullScreen(true); - }) - logger.info(`EntryAbility onWindowStageCreate`); - } - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - AppStorage.setOrCreate('want', want); - AppStorage.setOrCreate('launchParam', launchParam); - logger.info(`EntryAbility onCreate ${want.bundleName},${launchParam.launchReason}`); - } - - onDestroy() { - logger.info(`EntryAbility onDestroy`); - } - - onWindowStageDestroy() { - logger.info(`EntryAbility onWindowStageDestroy`); - // Main window is destroyed, release UI related resources - } - - onForeground() { - logger.info(`EntryAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`EntryAbility onBackground`); - // Ability has back to background - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; +import { logger } from '../util/Logger'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + windowStage.loadContent('pages/Index', (err: BusinessError) => { + }); + windowStage.getMainWindow((err, windowClass) => { + if (err.code) { + return; + } + windowClass.setWindowLayoutFullScreen(true); + }) + logger.info(`EntryAbility onWindowStageCreate`); + } + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + AppStorage.setOrCreate('want', want); + AppStorage.setOrCreate('launchParam', launchParam); + logger.info(`EntryAbility onCreate ${want.bundleName},${launchParam.launchReason}`); + } + + onDestroy() { + logger.info(`EntryAbility onDestroy`); + } + + onWindowStageDestroy() { + logger.info(`EntryAbility onWindowStageDestroy`); + // Main window is destroyed, release UI related resources + } + + onForeground() { + logger.info(`EntryAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`EntryAbility onBackground`); + // Ability has back to background + } +} diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/newability/NewAbility.ets b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/newability/NewAbility.ets index b9acfd827cba61cc2599d55a6276c0a9c86f2146..f74c81a86dd1897ce35bdcdbb86ecfdabed384ef 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/newability/NewAbility.ets +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/newability/NewAbility.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import { logger } from '../util/Logger'; - -export default class NewAbility extends UIAbility { - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - windowStage.loadContent('pages/New', () => { - }); - windowStage.getMainWindow((err, windowClass) => { - if (err.code) { - return; - } - windowClass.setWindowLayoutFullScreen(true); - }) - } - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - AppStorage.setOrCreate('want', want); - AppStorage.setOrCreate('launchParam', launchParam); - logger.info(`NewAbility onCreate ${want.bundleName},${launchParam.launchReason}`); - } - - onDestroy() { - logger.info(`NewAbility onDestroy`); - } - - onWindowStageDestroy() { - logger.info(`NewAbility onWindowStageDestroy`); - // Main window is destroyed, release UI related resources - } - - onForeground() { - logger.info(`NewAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`NewAbility onBackground`); - // Ability has back to background - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../util/Logger'; + +export default class NewAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + windowStage.loadContent('pages/New', () => { + }); + windowStage.getMainWindow((err, windowClass) => { + if (err.code) { + return; + } + windowClass.setWindowLayoutFullScreen(true); + }) + } + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + AppStorage.setOrCreate('want', want); + AppStorage.setOrCreate('launchParam', launchParam); + logger.info(`NewAbility onCreate ${want.bundleName},${launchParam.launchReason}`); + } + + onDestroy() { + logger.info(`NewAbility onDestroy`); + } + + onWindowStageDestroy() { + logger.info(`NewAbility onWindowStageDestroy`); + // Main window is destroyed, release UI related resources + } + + onForeground() { + logger.info(`NewAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`NewAbility onBackground`); + // Ability has back to background + } +} diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/pages/New.ets b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/pages/New.ets index 93bec9d38dd07ad771841d2cc56da4073508c586..e7eb83d5d253e08d483651767fb70d986183b1af 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/pages/New.ets +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/pages/New.ets @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import { logger } from '../util/Logger'; - -const TAG: string = 'NewAbility'; - -@Entry -@Component -struct New { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Image($r('app.media.ic_back')) - .size({ width: 20, height: 18 }) - .margin({ right: 18 }) - .onClick(() => { - this.context.terminateSelf((err, data) => { - logger.info(`${TAG} terminateSelf err:${JSON.stringify(err)},data:${JSON.stringify(data)}`); - }) - }) - Text($r('app.string.NewAbility_label')) - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 26, right: 26 }) - .width('100%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { - Column() { - Image($r('app.media.pic_empty')).width('33%') - Text($r('app.string.empty')) - .fontSize(14) - } - }.width('100%') - .height('90%') - } - .width('100%') - .height('100%') - .padding({ top: 36, bottom: 0 }) - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import { logger } from '../util/Logger'; + +const TAG: string = 'NewAbility'; + +@Entry +@Component +struct New { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Image($r('app.media.ic_back')) + .size({ width: 20, height: 18 }) + .margin({ right: 18 }) + .onClick(() => { + this.context.terminateSelf((err, data) => { + logger.info(`${TAG} terminateSelf err:${JSON.stringify(err)},data:${JSON.stringify(data)}`); + }) + }) + Text($r('app.string.NewAbility_label')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 26, right: 26 }) + .width('100%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { + Column() { + Image($r('app.media.pic_empty')).width('33%') + Text($r('app.string.empty')) + .fontSize(14) + } + }.width('100%') + .height('90%') + } + .width('100%') + .height('100%') + .padding({ top: 36, bottom: 0 }) + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/util/Logger.ets b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/util/Logger.ets index dbbf08e5292486204cef219969154b1b20c21178..69eaf0c33edd29ce360ff25dcb87a4cbf66c3119 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/util/Logger.ets +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/ets/util/Logger.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export let logger = new Logger('[Basic capabilities are enhanced]'); \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/module.json5 b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/module.json5 index 420b8c1ce3f861db27530fd7fb3c9fcf9b05496c..1658c2f6e809945ae4f0b6866dc53d8e3f5961a1 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/module.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/module.json5 @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "NewAbility", - "srcEntry": "./ets/newability/NewAbility.ets", - "description": "$string:NewAbility_desc", - "icon": "$media:icon", - "label": "$string:NewAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - ], - "extensionAbilities": [ - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "NewAbility", + "srcEntry": "./ets/newability/NewAbility.ets", + "description": "$string:NewAbility_desc", + "icon": "$media:icon", + "label": "$string:NewAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + ], + "extensionAbilities": [ + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/color.json index a55608bdfd4b80e04025510c67c65dd138310caf..01dee5176177a542d94efac26fae560c5c19a30a 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#FAFAFA" - }, - { - "name": "line_color", - "value": "#182431" - }, - { - "name": "text_color", - "value": "#182431" - }, - { - "name": "button_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#FAFAFA" + }, + { + "name": "line_color", + "value": "#182431" + }, + { + "name": "text_color", + "value": "#182431" + }, + { + "name": "button_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/float.json b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/float.json index 51aeb0059ce9ff1532c80bc800f52ad416ef23eb..c8d10991d67b86589cd2d8fc78970850f27999ab 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/float.json +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/main/resources/base/element/float.json @@ -1,8 +1,8 @@ -{ - "float": [ - { - "name": "font_size", - "value": "16fp" - } - ] +{ + "float": [ + { + "name": "font_size", + "value": "16fp" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/ets/util/Logger.ts b/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/ets/util/Logger.ts index dbbf08e5292486204cef219969154b1b20c21178..69eaf0c33edd29ce360ff25dcb87a4cbf66c3119 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/ets/util/Logger.ts +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/ets/util/Logger.ts @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export let logger = new Logger('[Basic capabilities are enhanced]'); \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/module.json5 b/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Ability/AbilityFeature/hvigor/hvigor-config.json5 b/code/BasicFeature/Ability/AbilityFeature/hvigor/hvigor-config.json5 index b84b124bfadf1c52f5df987d3193ec1a3768aaaf..69b4a2dad77150c87f3186d5d296756443ca6b3f 100644 --- a/code/BasicFeature/Ability/AbilityFeature/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - } +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityFeature/oh-package.json5 b/code/BasicFeature/Ability/AbilityFeature/oh-package.json5 index 1919d17c03c8556675bf79bccdedcc07e6536db7..6daa33b9126c1fd7df3cbb16a02467793281ac34 100644 --- a/code/BasicFeature/Ability/AbilityFeature/oh-package.json5 +++ b/code/BasicFeature/Ability/AbilityFeature/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "abilityFeature", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "abilityFeature", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Ability/AbilityFeature/ohosTest.md b/code/BasicFeature/Ability/AbilityFeature/ohosTest.md index de91defcc09e02e0964f5c6990a22cb8a3b57e07..dd6adf53fb18889283ccd3914693c37a4cdf6d94 100644 --- a/code/BasicFeature/Ability/AbilityFeature/ohosTest.md +++ b/code/BasicFeature/Ability/AbilityFeature/ohosTest.md @@ -1,15 +1,15 @@ -# 基础能力增强测试用例 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------------- | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -------- | -| 应用切换语言的能力 | 设备正常运行 | 应用启动成功,点击'切换英文语言'的ListItem | 当前页面切换为英文,标题'基础能力增强'切换成'Basic capabilities are enhanced' | Yes | Pass | -| 应用切换语言的能力 | 设备正常运行 | 应用启动成功,点击'切换中文语言'的ListItem | 当前页面切换为中文,标题'Basic capabilities are enhanced'切换成'基础能力增强' | Yes | Pass | -| 应用切换颜色模式的能力 | 设备正常运行 | 应用启动成功,点击'切换深色模式'的ListItem | 当前页面颜色切换为深色,弹出Toast提示'切换成功' | Yes | Pass | -| 应用切换颜色模式的能力 | 设备正常运行 | 应用启动成功,点击'切换浅色模式'的ListItem | 当前页面颜色切换为浅色,弹出Toast提示'切换成功' | Yes | Pass | -| 应用隐式启动个数为0时不触发提示弹框的特性 | 设备正常运行 | 应用启动成功,点击'隐式启动弹窗'的ListItem | 弹出Toast提示'隐式启动弹窗',并且弹出弹窗,弹窗标题为'未找到文件' | Yes | Pass | -| 应用隐式启动个数为0时不触发提示弹框的特性 | 设备正常运行 | 应用启动成功,点击'隐式启动不弹窗'的ListItem | 弹出Toast提示'隐式启动不弹窗',且无弹窗 | Yes | Pass | -| 应用可以设置启动参数启动Ability能力 | 设备正常运行 | 1.应用启动成功,点击''启动动画'的“开启”的按钮
2.点击''StartOptions配置'的ListItem | 1.按钮变为“关闭”
2.应用启动NewAbility | Yes | Pass | -| 应用清理自己的数据的能力 | 设备正常运行 | 1.应用启动成功,点击'创建数据'的ListItem
2.点击'检查数据'的ListItem
3.点击'清除数据'的ListItem
4.点击应用图标
5.点击'检查数据'的ListItem | 1.弹出Toast提示'创建缓存文件成功'
2.弹出Toast提示'查询到缓存文件',
3.应用退出
4.重新启动应用
5.弹出Toast提示'未找到缓存文件' | No | Pass | - +# 基础能力增强测试用例 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------------- | ------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -------- | +| 应用切换语言的能力 | 设备正常运行 | 应用启动成功,点击'切换英文语言'的ListItem | 当前页面切换为英文,标题'基础能力增强'切换成'Basic capabilities are enhanced' | Yes | Pass | +| 应用切换语言的能力 | 设备正常运行 | 应用启动成功,点击'切换中文语言'的ListItem | 当前页面切换为中文,标题'Basic capabilities are enhanced'切换成'基础能力增强' | Yes | Pass | +| 应用切换颜色模式的能力 | 设备正常运行 | 应用启动成功,点击'切换深色模式'的ListItem | 当前页面颜色切换为深色,弹出Toast提示'切换成功' | Yes | Pass | +| 应用切换颜色模式的能力 | 设备正常运行 | 应用启动成功,点击'切换浅色模式'的ListItem | 当前页面颜色切换为浅色,弹出Toast提示'切换成功' | Yes | Pass | +| 应用隐式启动个数为0时不触发提示弹框的特性 | 设备正常运行 | 应用启动成功,点击'隐式启动弹窗'的ListItem | 弹出Toast提示'隐式启动弹窗',并且弹出弹窗,弹窗标题为'未找到文件' | Yes | Pass | +| 应用隐式启动个数为0时不触发提示弹框的特性 | 设备正常运行 | 应用启动成功,点击'隐式启动不弹窗'的ListItem | 弹出Toast提示'隐式启动不弹窗',且无弹窗 | Yes | Pass | +| 应用可以设置启动参数启动Ability能力 | 设备正常运行 | 1.应用启动成功,点击''启动动画'的“开启”的按钮
2.点击''StartOptions配置'的ListItem | 1.按钮变为“关闭”
2.应用启动NewAbility | Yes | Pass | +| 应用清理自己的数据的能力 | 设备正常运行 | 1.应用启动成功,点击'创建数据'的ListItem
2.点击'检查数据'的ListItem
3.点击'清除数据'的ListItem
4.点击应用图标
5.点击'检查数据'的ListItem | 1.弹出Toast提示'创建缓存文件成功'
2.弹出Toast提示'查询到缓存文件',
3.应用退出
4.重新启动应用
5.弹出Toast提示'未找到缓存文件' | No | Pass | + diff --git a/code/BasicFeature/Ability/AbilityRuntime/AppScope/app.json5 b/code/BasicFeature/Ability/AbilityRuntime/AppScope/app.json5 index 38b4d0880e972eefc5d73315f4dc61ed343fe650..c15af56bb0a4212ab1f58ab8ac746d1c43e9d22f 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/AppScope/app.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/AppScope/app.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2024 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.abilityruntime", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name", - "multiAppMode": { - "multiAppModeType": "appClone", - "maxCount": 5 - } - } -} +/* + * Copyright (c) 2024 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.abilityruntime", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "multiAppMode": { + "multiAppModeType": "appClone", + "maxCount": 5 + } + } +} diff --git a/code/BasicFeature/Ability/AbilityRuntime/AppScope/resources/base/element/string.json b/code/BasicFeature/Ability/AbilityRuntime/AppScope/resources/base/element/string.json index 7de244d006478b63a9a60309dda74d6c4c4d1ca7..07d445beadfec06f249f471ba539e66301f9a32c 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Ability/AbilityRuntime/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AbilityRuntime" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AbilityRuntime" + } + ] +} diff --git a/code/BasicFeature/Ability/AbilityRuntime/README_zh.md b/code/BasicFeature/Ability/AbilityRuntime/README_zh.md index 81b3f5aae92b2c50991460d49ff267039cd6ccac..486d032d946f500ee5e29a2cd997d616b2825ac0 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/README_zh.md +++ b/code/BasicFeature/Ability/AbilityRuntime/README_zh.md @@ -1,204 +1,204 @@ -# 基础能力增强 - -### 介绍 - -本示例使用 [AppManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-appManager.md) ,[dataUriUtils](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-ability-dataUriUtils.md),[WantAgent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-wantAgent.md),[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md),[errorManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-errorManager.md),[UIAbilityContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)中的接口进行实现。 - -### 效果预览 - -| 主页面 | appManager开发示例 | errorManager开发示例 | UIAbilityContext开发示例 | -| :----------------------------------------------: | :---------------------------------------------------: | :-----------------------------------------------------: | :---------------------------------------------------------: | -| | | | | - -### 使用说明 - -AppManager对应接口 - -1.点击主页面**appManager开发示例**按钮,跳转到'appManager开发示例'界面; - -2.点击**isRunningInStabilityTest callback**按钮,弹出'isRunningInStabilityTest(callback) success...'信息; - -3.点击**isRunningInStabilityTest promise**按钮,弹出提示'isRunningInStabilityTest(promise) success...'信息; - -4.点击**isRamConstrainedDevice callback**按钮,弹出提示'isRamConstrainedDevice(callback) success...'信息; - -5.点击**isRamConstrainedDevice promise**按钮,弹出提示'isRamConstrainedDevice(promise) success...'信息; - -6.点击**getAppMemorySize callback**按钮,弹出提示'getAppMemorySize(callback) success...'信息; - -7.点击**getAppMemorySize promise**按钮,弹出提示'getAppMemorySize(promise) success...'信息; - -8.点击**getRunningProcessInformation callback**按钮,弹出提示'getRunningProcessInformation(callback) success...'信息; - -9.点击**getRunningProcessInformation promise**按钮,弹出提示'getRunningProcessInformation(promise) success...'信息; - - - -dataUriUtils对应接口 - -1.点击主页面**dataUriUtils开发示例**按钮,跳转到'dataUriUtils开发示例'界面; - -2.点击**getId**按钮,弹出提示'dataUriUtils.getId() called...'信息; - -3.点击**attachId**按钮,弹出提示'dataUriUtils.attachd() called...'信息; - -4.点击**deleteId**按钮,弹出提示'dataUriUtils.deleteId() called...'信息; - -5.点击**updateId**按钮,弹出提示'dataUriUtils.updateId() called...'信息; - - - -WantAgent对应接口 - -1.点击主页面**WantAgent开发示例**按钮,跳转到'WantAgent开发示例'界面; - -2.点击**getBundleName callback**按钮,弹出提示'getBundleName(callback) success...'信息; - -3.点击**getBundleName promise**按钮,弹出提示'getBundleName(promise) success...'信息; - -4.点击**getUid callback**按钮,弹出提示'getUid(callback) success...'信息; - -5.点击**getUid promise**按钮,弹出提示'getUid(promise) success...'信息; - -6.点击**cancel callback**按钮,弹出提示'cancel(callback) success'信息; - -7.点击**cancel promise**按钮,弹出提示'cancel(promise) success'信息; - -8.点击**equal callback**按钮,弹出提示'equal(callback) success...'信息; - -9.点击**equal promise**按钮,弹出提示'equal(promise) success...'信息; - -10.点击**getOperationType callback**按钮,弹出提示'getOperationType(callback) success...'信息; - -11.点击**getOperationType promise**按钮,弹出提示'getOperationType(promise) success...'信息; - -12.点击**trigger**按钮,弹出提示'trigger success...'信息; - - - -ApplicationContext对应接口 - -1.点击主页面**ApplicationContext开发示例**按钮,跳转到'ApplicationContext开发示例'界面; - -2.点击**setFont**按钮,弹出提示'setFont successfully'信息; - -3.点击**getRunningProcessInformation promise**按钮,弹出提示'getRunningProcessInformation promise successfully...'信息; - -4.点击**getRunningProcessInformation callback**按钮,弹出提示'getRunningProcessInformation callback successfully...'信息; - -5.点击**getCurrentAppCloneIndex**按钮,弹出提示'getCurrentAppCloneIndex successfully...'信息; - - - -errorManager对应接口 - -1.点击主页面**errorManager开发示例**按钮,跳转到'errorManager开发示例'界面; - -2.点击**注册LoopObserver**按钮,弹出提示'loopObserver registered successfully...'信息; - -3.点击**注册UnhandledRejectionObserver**按钮,弹出提示'unhandledRejection registered successfully'信息,列表中增加**模拟UnhandledRejection**按钮,并且原**注册UnhandledRejectionObserver**按钮变为**注销UnhandledRejectionObserver**按钮 - -4.点击**模拟UnhandledRejection**按钮,弹出提示'UnhandledRejectionObserver reason...'信息; - -5.点击**注销UnhandledRejection**按钮,弹出提示'unhandledRejection unregistered successfully'信息,**注销UnhandledRejectionObserver**按钮变回**注册UnhandledRejectionObserver**按钮,列表中**模拟UnhandledRejection**按钮消失; - - - -UIAbilityContext对应接口 - -1.点击主页面**UIAbilityContext开发示例**按钮,启动新的Ability显示'UIAbilityContext开发示例'界面; - -2.点击**moveAbilityToBackground**按钮,将启动的Ability移动到后台,页面显示为主页面,触发AbilityLifecycleCallback中的生命周期; - -3.再次点击主页面**UIAbilityContext开发示例**按钮,启动新的Ability显示'UIAbilityContext开发示例'界面,点击**terminateSelf**按钮,回到主页面; - -### 工程目录 - -``` -entry/src/main/ets/ -|---abilitylifecyclecallback -| |---AbilityLifecycleCallback.ets //AbilityLifecycleCallback生命周期 -|---abilitypages -| |---ApplicationContext.ets //ApplicationContext中对应接口 -| |---AppManager.ets //AppManager中对应接口 -| |---DataUriUtils.ets //DataUriUtils中对应接口 -| |---ErrorManager.ets //ErrorManager中对应接口 -| |---UIAbilityContext.ets //UIAbilityContext中对应接口 -| |---WantAgent.ets //WantAgent中对应接口 -|---entryability -| |---EntryAbility.ets // 首页的Ability -|---pages -| |---Index.ets // 首页 -``` - -### 具体实现 - -* AppManager对应接口实现,源码参考[AppManager.ets](entry/src/main/ets/abilitypages/appManager.ets) - - * isRunningInStabilityTest(callback)接口实现:通过调用appManager.isRunningInStabilityTest()接口,查询当前是否处于稳定性测试场景。使用callback异步回调,并将弹出Toast信息的功能; - * isRunningInStabilityTest(promise)接口实现:通过调用appManager.isRunningInStabilityTest()接口,查询当前是否处于稳定性测试场景。使用Promise异步回调,并将弹出Toast信息的功能; - * isRamConstrainedDevice(callback)接口实现:通过调用appManager.isRamConstrainedDevice()接口,查询是否为ram受限设备。使用callback异步回调,并将弹出Toast信息的功能; - * isRamConstrainedDevice(promise)接口实现:通过调用appManager.isRamConstrainedDevice()接口,查询是否为ram受限设备。使用Promise异步回调,并将弹出Toast信息的功能; - * getAppMemorySize(callback)接口实现:通过调用appManager.getAppMemorySize()接口,获取当前应用程序可以使用的内存的值。使用callback异步回调,并将弹出Toast信息的功能; - * getAppMemorySize(promise)接口实现:通过调用appManager.getAppMemorySize()接口,获取当前应用程序可以使用的内存的值。使用Promise异步回调,并将弹出Toast信息的功能; - * getRunningProcessInformation(callback)接口实现:通过调用appManager.getRunningProcessInformation()接口,获取当前运行进程的有关信息。使用callback异步回调,并将弹出Toast信息的功能; - * getRunningProcessInformation(promise)接口实现:通过调用appManager.getRunningProcessInformation()接口,获取当前运行进程的有关信息。使用Promise异步回调,并将弹出Toast信息的功能; -* dataUriUtils对应接口实现,源码参考[DataUriUtils.ets](entry/src/main/ets/abilitypages/DataUriUtils.ets) - - * getId接口实现:通过调用dataUriUtils.getId()接口,获取指定uri路径末尾的ID的功能; - * attachId接口实现:通过调用dataUriUtils.attachId()接口,将ID附加到uri的路径末尾的功能; - * deleteId接口实现:通过调用dataUriUtils.deleteId()接口,删除指定uri路径末尾的ID的功能; - * updateId接口实现:通过调用dataUriUtils.updateId()接口,更新指定uri中的ID的功能; -* WantAgent对应接口实现,源码参考[WantAgent.ets](entry/src/main/ets/abilitypages/WantAgent.ets) - - * getBundleName(callback)接口实现:通过调用this.getBundleNameCallback()接口,获取WantAgent实例的包名; - * getBundleName(promise)接口实现:通过调用this.getBundleNamePromise()接口,获取WantAgent实例的包名; - * getUid(callback)接口实现:通过调用this.getUidCallback()接口,获取WantAgent实例的用户ID; - * getUid(promise)接口实现:通过调用this.getUidPromise接口,获取WantAgent实例的用户ID; - * cancel(callback)接口实现:通过调用this.cancelCallback()接口,取消WantAgent实例; - * cancel(promise)接口实现:通过调用this.cancelPromise()接口,取消WantAgent实例; - * equal(callback)接口实现:通过调用this.equalCallback()接口,以此来判断是否是来自同一应用的相同操作,判断两个WantAgent实例是否相等的回调方法。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等; - * equal(promise)接口实现:通过调用this.equalPromise()接口,以此来判断是否是来自同一应用的相同操作,判断两个WantAgent实例是否相等的结果。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等; - * getOperationType(callback)接口实现:通过调用this.getOperationTypeCallback()接口,获取一个WantAgent的OperationType信息; - * getOperationType(promise)接口实现:通过调用this.getOperationTypePromise()接口,获取一个WantAgent的OperationType信息; - * trigger接口实现:通过调用this.trigger()接口,主动激发WantAgent实例; -* ApplicationContext对应接口实现,源码参考[ApplicationContext.ets](entry/src/main/ets/abilitypages/ApplicationContext.ets) - - * setFont接口实现:通过调用applicationContext.setFont接口,设置应用的字体类型。仅支持主线程调用,设置字体类型,字体可以通过font.registerFont方法进行注册使用; - * getRunningProcessInformation(callback)接口实现:通过调用ApplicationContext.getRunningProcessInformation接口,获取有关运行进程的信息; - * getRunningProcessInformation(promise)接口实现:通过调用ApplicationContext.getRunningProcessInformation接口,获取有关运行进程的信息; - * getCurrentAppCloneIndex接口实现:通过调用ApplicationContext.getCurrentAppCloneIndex接口,获取当前应用的分身索引; -* errorManager对应接口实现,源码参考[ErrorManager.ets](entry/src/main/ets/abilitypages/ErrorManager.ets) - * 注册on(loopObserver类型)接口实现:通过调用errorManager.on 接口,注册监听loopObserver,注册后可以捕获到应用主线程处理消息的具体执行时间,触发onLoopTimeOut,之后注销监听; - * 注册on(unhandledRejection类型)接口实现:通过调用errorManager.on接口,注册监听unhandledRejection,注册后可以捕获到当前线程中未被捕获到的promise rejection,模拟unhandledRejection类型错误,触发监听,之后注销监听; -* UIAbilityContext对应接口实现:源码参考[UIAbilityContext.ets](entry/src/main/ets/abilitypages/UIAbilityContext.ets) - * moveAbilityToBackground接口实现:通过调用context.moveAbilityToBackground()接口,将处于前台的Ability移动到后台,调用context.terminateSelf(),停止Ability自身,触发AbilityLifecycleCallback中的生命周期; - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568; - -2.本示例为Stage模型,支持API12版本SDK,版本号:5.0.0.31; - -3.本示例需要使用DevEco Studio NEXT Developer Beta1 (Build Version: 5.0.3.502, built on July 28, 2024)才可编译运行; - -### 下载 - -```shell -git init -git config core.sparsecheckout true -echo code/BasicFeature/Ability/AbilityRuntime > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - - - +# 基础能力增强 + +### 介绍 + +本示例使用 [AppManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-appManager.md) ,[dataUriUtils](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-ability-dataUriUtils.md),[WantAgent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-wantAgent.md),[ApplicationContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-applicationContext.md),[errorManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-errorManager.md),[UIAbilityContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)中的接口进行实现。 + +### 效果预览 + +| 主页面 | appManager开发示例 | errorManager开发示例 | UIAbilityContext开发示例 | +| :----------------------------------------------: | :---------------------------------------------------: | :-----------------------------------------------------: | :---------------------------------------------------------: | +| | | | | + +### 使用说明 + +AppManager对应接口 + +1.点击主页面**appManager开发示例**按钮,跳转到'appManager开发示例'界面; + +2.点击**isRunningInStabilityTest callback**按钮,弹出'isRunningInStabilityTest(callback) success...'信息; + +3.点击**isRunningInStabilityTest promise**按钮,弹出提示'isRunningInStabilityTest(promise) success...'信息; + +4.点击**isRamConstrainedDevice callback**按钮,弹出提示'isRamConstrainedDevice(callback) success...'信息; + +5.点击**isRamConstrainedDevice promise**按钮,弹出提示'isRamConstrainedDevice(promise) success...'信息; + +6.点击**getAppMemorySize callback**按钮,弹出提示'getAppMemorySize(callback) success...'信息; + +7.点击**getAppMemorySize promise**按钮,弹出提示'getAppMemorySize(promise) success...'信息; + +8.点击**getRunningProcessInformation callback**按钮,弹出提示'getRunningProcessInformation(callback) success...'信息; + +9.点击**getRunningProcessInformation promise**按钮,弹出提示'getRunningProcessInformation(promise) success...'信息; + + + +dataUriUtils对应接口 + +1.点击主页面**dataUriUtils开发示例**按钮,跳转到'dataUriUtils开发示例'界面; + +2.点击**getId**按钮,弹出提示'dataUriUtils.getId() called...'信息; + +3.点击**attachId**按钮,弹出提示'dataUriUtils.attachd() called...'信息; + +4.点击**deleteId**按钮,弹出提示'dataUriUtils.deleteId() called...'信息; + +5.点击**updateId**按钮,弹出提示'dataUriUtils.updateId() called...'信息; + + + +WantAgent对应接口 + +1.点击主页面**WantAgent开发示例**按钮,跳转到'WantAgent开发示例'界面; + +2.点击**getBundleName callback**按钮,弹出提示'getBundleName(callback) success...'信息; + +3.点击**getBundleName promise**按钮,弹出提示'getBundleName(promise) success...'信息; + +4.点击**getUid callback**按钮,弹出提示'getUid(callback) success...'信息; + +5.点击**getUid promise**按钮,弹出提示'getUid(promise) success...'信息; + +6.点击**cancel callback**按钮,弹出提示'cancel(callback) success'信息; + +7.点击**cancel promise**按钮,弹出提示'cancel(promise) success'信息; + +8.点击**equal callback**按钮,弹出提示'equal(callback) success...'信息; + +9.点击**equal promise**按钮,弹出提示'equal(promise) success...'信息; + +10.点击**getOperationType callback**按钮,弹出提示'getOperationType(callback) success...'信息; + +11.点击**getOperationType promise**按钮,弹出提示'getOperationType(promise) success...'信息; + +12.点击**trigger**按钮,弹出提示'trigger success...'信息; + + + +ApplicationContext对应接口 + +1.点击主页面**ApplicationContext开发示例**按钮,跳转到'ApplicationContext开发示例'界面; + +2.点击**setFont**按钮,弹出提示'setFont successfully'信息; + +3.点击**getRunningProcessInformation promise**按钮,弹出提示'getRunningProcessInformation promise successfully...'信息; + +4.点击**getRunningProcessInformation callback**按钮,弹出提示'getRunningProcessInformation callback successfully...'信息; + +5.点击**getCurrentAppCloneIndex**按钮,弹出提示'getCurrentAppCloneIndex successfully...'信息; + + + +errorManager对应接口 + +1.点击主页面**errorManager开发示例**按钮,跳转到'errorManager开发示例'界面; + +2.点击**注册LoopObserver**按钮,弹出提示'loopObserver registered successfully...'信息; + +3.点击**注册UnhandledRejectionObserver**按钮,弹出提示'unhandledRejection registered successfully'信息,列表中增加**模拟UnhandledRejection**按钮,并且原**注册UnhandledRejectionObserver**按钮变为**注销UnhandledRejectionObserver**按钮 + +4.点击**模拟UnhandledRejection**按钮,弹出提示'UnhandledRejectionObserver reason...'信息; + +5.点击**注销UnhandledRejection**按钮,弹出提示'unhandledRejection unregistered successfully'信息,**注销UnhandledRejectionObserver**按钮变回**注册UnhandledRejectionObserver**按钮,列表中**模拟UnhandledRejection**按钮消失; + + + +UIAbilityContext对应接口 + +1.点击主页面**UIAbilityContext开发示例**按钮,启动新的Ability显示'UIAbilityContext开发示例'界面; + +2.点击**moveAbilityToBackground**按钮,将启动的Ability移动到后台,页面显示为主页面,触发AbilityLifecycleCallback中的生命周期; + +3.再次点击主页面**UIAbilityContext开发示例**按钮,启动新的Ability显示'UIAbilityContext开发示例'界面,点击**terminateSelf**按钮,回到主页面; + +### 工程目录 + +``` +entry/src/main/ets/ +|---abilitylifecyclecallback +| |---AbilityLifecycleCallback.ets //AbilityLifecycleCallback生命周期 +|---abilitypages +| |---ApplicationContext.ets //ApplicationContext中对应接口 +| |---AppManager.ets //AppManager中对应接口 +| |---DataUriUtils.ets //DataUriUtils中对应接口 +| |---ErrorManager.ets //ErrorManager中对应接口 +| |---UIAbilityContext.ets //UIAbilityContext中对应接口 +| |---WantAgent.ets //WantAgent中对应接口 +|---entryability +| |---EntryAbility.ets // 首页的Ability +|---pages +| |---Index.ets // 首页 +``` + +### 具体实现 + +* AppManager对应接口实现,源码参考[AppManager.ets](entry/src/main/ets/abilitypages/appManager.ets) + + * isRunningInStabilityTest(callback)接口实现:通过调用appManager.isRunningInStabilityTest()接口,查询当前是否处于稳定性测试场景。使用callback异步回调,并将弹出Toast信息的功能; + * isRunningInStabilityTest(promise)接口实现:通过调用appManager.isRunningInStabilityTest()接口,查询当前是否处于稳定性测试场景。使用Promise异步回调,并将弹出Toast信息的功能; + * isRamConstrainedDevice(callback)接口实现:通过调用appManager.isRamConstrainedDevice()接口,查询是否为ram受限设备。使用callback异步回调,并将弹出Toast信息的功能; + * isRamConstrainedDevice(promise)接口实现:通过调用appManager.isRamConstrainedDevice()接口,查询是否为ram受限设备。使用Promise异步回调,并将弹出Toast信息的功能; + * getAppMemorySize(callback)接口实现:通过调用appManager.getAppMemorySize()接口,获取当前应用程序可以使用的内存的值。使用callback异步回调,并将弹出Toast信息的功能; + * getAppMemorySize(promise)接口实现:通过调用appManager.getAppMemorySize()接口,获取当前应用程序可以使用的内存的值。使用Promise异步回调,并将弹出Toast信息的功能; + * getRunningProcessInformation(callback)接口实现:通过调用appManager.getRunningProcessInformation()接口,获取当前运行进程的有关信息。使用callback异步回调,并将弹出Toast信息的功能; + * getRunningProcessInformation(promise)接口实现:通过调用appManager.getRunningProcessInformation()接口,获取当前运行进程的有关信息。使用Promise异步回调,并将弹出Toast信息的功能; +* dataUriUtils对应接口实现,源码参考[DataUriUtils.ets](entry/src/main/ets/abilitypages/DataUriUtils.ets) + + * getId接口实现:通过调用dataUriUtils.getId()接口,获取指定uri路径末尾的ID的功能; + * attachId接口实现:通过调用dataUriUtils.attachId()接口,将ID附加到uri的路径末尾的功能; + * deleteId接口实现:通过调用dataUriUtils.deleteId()接口,删除指定uri路径末尾的ID的功能; + * updateId接口实现:通过调用dataUriUtils.updateId()接口,更新指定uri中的ID的功能; +* WantAgent对应接口实现,源码参考[WantAgent.ets](entry/src/main/ets/abilitypages/WantAgent.ets) + + * getBundleName(callback)接口实现:通过调用this.getBundleNameCallback()接口,获取WantAgent实例的包名; + * getBundleName(promise)接口实现:通过调用this.getBundleNamePromise()接口,获取WantAgent实例的包名; + * getUid(callback)接口实现:通过调用this.getUidCallback()接口,获取WantAgent实例的用户ID; + * getUid(promise)接口实现:通过调用this.getUidPromise接口,获取WantAgent实例的用户ID; + * cancel(callback)接口实现:通过调用this.cancelCallback()接口,取消WantAgent实例; + * cancel(promise)接口实现:通过调用this.cancelPromise()接口,取消WantAgent实例; + * equal(callback)接口实现:通过调用this.equalCallback()接口,以此来判断是否是来自同一应用的相同操作,判断两个WantAgent实例是否相等的回调方法。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等; + * equal(promise)接口实现:通过调用this.equalPromise()接口,以此来判断是否是来自同一应用的相同操作,判断两个WantAgent实例是否相等的结果。返回true表示两个WantAgent实例相等,false表示两个WantAgent实例不相等; + * getOperationType(callback)接口实现:通过调用this.getOperationTypeCallback()接口,获取一个WantAgent的OperationType信息; + * getOperationType(promise)接口实现:通过调用this.getOperationTypePromise()接口,获取一个WantAgent的OperationType信息; + * trigger接口实现:通过调用this.trigger()接口,主动激发WantAgent实例; +* ApplicationContext对应接口实现,源码参考[ApplicationContext.ets](entry/src/main/ets/abilitypages/ApplicationContext.ets) + + * setFont接口实现:通过调用applicationContext.setFont接口,设置应用的字体类型。仅支持主线程调用,设置字体类型,字体可以通过font.registerFont方法进行注册使用; + * getRunningProcessInformation(callback)接口实现:通过调用ApplicationContext.getRunningProcessInformation接口,获取有关运行进程的信息; + * getRunningProcessInformation(promise)接口实现:通过调用ApplicationContext.getRunningProcessInformation接口,获取有关运行进程的信息; + * getCurrentAppCloneIndex接口实现:通过调用ApplicationContext.getCurrentAppCloneIndex接口,获取当前应用的分身索引; +* errorManager对应接口实现,源码参考[ErrorManager.ets](entry/src/main/ets/abilitypages/ErrorManager.ets) + * 注册on(loopObserver类型)接口实现:通过调用errorManager.on 接口,注册监听loopObserver,注册后可以捕获到应用主线程处理消息的具体执行时间,触发onLoopTimeOut,之后注销监听; + * 注册on(unhandledRejection类型)接口实现:通过调用errorManager.on接口,注册监听unhandledRejection,注册后可以捕获到当前线程中未被捕获到的promise rejection,模拟unhandledRejection类型错误,触发监听,之后注销监听; +* UIAbilityContext对应接口实现:源码参考[UIAbilityContext.ets](entry/src/main/ets/abilitypages/UIAbilityContext.ets) + * moveAbilityToBackground接口实现:通过调用context.moveAbilityToBackground()接口,将处于前台的Ability移动到后台,调用context.terminateSelf(),停止Ability自身,触发AbilityLifecycleCallback中的生命周期; + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568; + +2.本示例为Stage模型,支持API12版本SDK,版本号:5.0.0.31; + +3.本示例需要使用DevEco Studio NEXT Developer Beta1 (Build Version: 5.0.3.502, built on July 28, 2024)才可编译运行; + +### 下载 + +```shell +git init +git config core.sparsecheckout true +echo code/BasicFeature/Ability/AbilityRuntime > .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/Ability/AbilityRuntime/build-profile.json5 b/code/BasicFeature/Ability/AbilityRuntime/build-profile.json5 index 96292e1b2c960be8f23d27bb37ad8f5b12b9738a..7848132072eeab1ffb83134de010a80b4d2a968c 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/build-profile.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 12, - "compileSdkVersion": 12, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 12, + "compileSdkVersion": 12, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/build-profile.json5 b/code/BasicFeature/Ability/AbilityRuntime/entry/build-profile.json5 index d04cb6b90c59558304ba27b9c22f604769997bf1..b4c2311b76761268310e37bd9be997808d39880e 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/build-profile.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/oh-package.json5 b/code/BasicFeature/Ability/AbilityRuntime/entry/oh-package.json5 index 65ca50243f0eee898fd9c639fe4c431c5a66a15a..3d327009e012ac531803ce2d2db2968d07446d17 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/oh-package.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2024 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": {} -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitylifecyclecallback/AbilityLifecycleCallback.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitylifecyclecallback/AbilityLifecycleCallback.ets index 430cc485375e48ef471e61dfe5e3b4bdf38b6953..3500fd2007c837849eff203b31cbe9df075ada1a 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitylifecyclecallback/AbilityLifecycleCallback.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitylifecyclecallback/AbilityLifecycleCallback.ets @@ -1,240 +1,240 @@ -/* - * Copyright (c) 2024 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, AbilityLifecycleCallback, UIAbility } from '@kit.AbilityKit'; -import { BusinessError } from '@ohos.base'; -import { window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = '[AbilityLifecycleCallback]'; -const DOMAIN: number = 0xFF00; - -export class GlobalContext { - private constructor() { - } - - private static instance: GlobalContext; - private _objects = new Map(); - - public static getContext(): GlobalContext { - if (!GlobalContext.instance) { - GlobalContext.instance = new GlobalContext(); - } - return GlobalContext.instance; - } - - getObject(value: string): Object | undefined { - return this._objects.get(value); - } - - setObject(key: string, objectClass: Object): void { - this._objects.set(key, objectClass); - } -} - -// 声明ability生命周期回调,需配置所有回调后才可以在applicationContext注册 -let abilityLifecycleCallback: AbilityLifecycleCallback = { - onAbilityCreate(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityCreate.'); - }, - onWindowStageCreate(ability, windowStage) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageCreate.'); - }, - onWindowStageActive(ability, windowStage) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageActive.'); - }, - onWindowStageInactive(ability, windowStage) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageInactive.'); - }, - onWindowStageDestroy(ability, windowStage) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageDestroy.'); - }, - onAbilityDestroy(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityDestroy.'); - }, - onAbilityForeground(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityForeground.'); - }, - onAbilityBackground(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityBackground.'); - }, - onAbilityContinue(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityContinue.'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onNewWant]触发后回调。 - onNewWant(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onNewWant'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onNewWant]触发前回调。 - onWillNewWant(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWillNewWant'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onCreate]触发前回调。 - onAbilityWillCreate(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillCreate'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onWindowStageCreate]触发前回调。 - onWindowStageWillCreate(ability, windowStage) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageWillCreate'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onWindowStageDestroy]触发前回调。 - onWindowStageWillDestroy(ability, windowStage) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageWillDestroy'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onDestroy]触发前回调。 - onAbilityWillDestroy(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillDestroy'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onForeground]触发前回调。 - onAbilityWillForeground(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillForeground'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onBackground]触发前回调。 - onAbilityWillBackground(ability) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillBackground'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onSaveState]触发前回调。 - onAbilityWillSaveState(ability: UIAbility) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillSaveState.'); - }, - // 注册监听应用上下文的生命周期后,在UIAbility的[onSaveState]触发后回调。 - onAbilitySaveState(ability: UIAbility) { - hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilitySaveState.'); - } -}; - -export default class AbilityLifecycle extends UIAbility { - onCreate() { - hilog.info(DOMAIN, TAG, 'MyAbilityStage onCreate'); - - // 1.通过context属性获取applicationContext - let applicationContext = this.context.getApplicationContext(); - // 2.通过applicationContext注册监听应用内生命周期 - try { - let lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback); - GlobalContext.getContext().setObject('lifecycleId', lifecycleId); - hilog.info(DOMAIN, TAG, - `registerAbilityLifecycleCallback lifecycleId: ${GlobalContext.getContext().getObject('lifecycleId')}`); - } catch (paramError) { - hilog.error(DOMAIN, TAG, `error: ${paramError.code}, ${paramError.message}`); - } - } - - onWindowStageCreate(windowStage: window.WindowStage) { - hilog.info(DOMAIN, TAG, 'onWindowStageCreate'); - - let windowClass: window.Window | undefined = undefined; - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - let systemBarProperties: window.SystemBarProperties = { - statusBarColor: '#f1f3f5', - navigationBarColor: '#f1f3f5', - }; - try { - windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); - } - }); - - windowStage.loadContent('abilitypages/UIAbilityContext', (err, data) => { - if (err.code) { - return; - } - }); - } - - onBackground() { - hilog.info(DOMAIN, TAG, 'onBackground'); - } - - onForeground() { - hilog.info(DOMAIN, TAG, 'onBackground'); - } - - onPrepareToTerminate() { - hilog.info(DOMAIN, TAG, 'onPrepareToTerminate'); - // 开发者定义预关闭动作 - // 例如拉起另一个ability,根据ability处理结果执行异步关闭 - let want: Want = { - bundleName: 'com.samples.abilityruntime', - abilityName: 'AbilityLifecycleAbility' - } - this.context.startAbilityForResult(want) - .then((result) => { - // 获取ability处理结果,当返回结果的resultCode为0关闭当前UIAbility - hilog.info(DOMAIN, TAG, 'startAbilityForResult success, resultCode is ' + result.resultCode); - if (result.resultCode === 0) { - this.context.terminateSelf(); - } - }).catch((err: BusinessError) => { - // 异常处理 - hilog.error(DOMAIN, TAG, 'startAbilityForResult failed, err:' + JSON.stringify(err)); - this.context.terminateSelf(); - }) - - return true; // 已定义预关闭操作后,返回true表示UIAbility取消关闭 - } - - onWindowStageWillDestroy(windowStage: window.WindowStage) { - hilog.info(DOMAIN, TAG, 'onWindowStageWillDestroy'); - } - - onWindowStageRestore(windowStage: window.WindowStage) { - hilog.info(DOMAIN, TAG, 'onWindowStageRestore'); - } - - onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { - // No need to save state - hilog.info(DOMAIN, TAG, 'onSaveState'); - return AbilityConstant.OnSaveResult.ALL_REJECT; - } - - onWindowStageDestroy() { - hilog.info(DOMAIN, TAG, 'onWindowStageDestroy'); - } - - onDestroy() { - let applicationContext = this.context.getApplicationContext(); - let lifecycleId = GlobalContext.getContext().getObject('lifecycleId') as number; - try { - // 3.通过applicationContext注销监听应用内生命周期 - applicationContext.off('abilityLifecycle', lifecycleId, (error) => { - if (error && error.code !== 0) { - hilog.error(DOMAIN, TAG, `unregisterAbilityLifecycleCallback fail, error: ${JSON.stringify(error)}`); - } else { - hilog.info(DOMAIN, TAG, 'unregisterAbilityLifecycleCallback success.'); - } - }); - } catch (paramError) { - hilog.error(DOMAIN, TAG, - `error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); - } - } +/* + * Copyright (c) 2024 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, AbilityLifecycleCallback, UIAbility } from '@kit.AbilityKit'; +import { BusinessError } from '@ohos.base'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[AbilityLifecycleCallback]'; +const DOMAIN: number = 0xFF00; + +export class GlobalContext { + private constructor() { + } + + private static instance: GlobalContext; + private _objects = new Map(); + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getObject(value: string): Object | undefined { + return this._objects.get(value); + } + + setObject(key: string, objectClass: Object): void { + this._objects.set(key, objectClass); + } +} + +// 声明ability生命周期回调,需配置所有回调后才可以在applicationContext注册 +let abilityLifecycleCallback: AbilityLifecycleCallback = { + onAbilityCreate(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityCreate.'); + }, + onWindowStageCreate(ability, windowStage) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageCreate.'); + }, + onWindowStageActive(ability, windowStage) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageActive.'); + }, + onWindowStageInactive(ability, windowStage) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageInactive.'); + }, + onWindowStageDestroy(ability, windowStage) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageDestroy.'); + }, + onAbilityDestroy(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityDestroy.'); + }, + onAbilityForeground(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityForeground.'); + }, + onAbilityBackground(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityBackground.'); + }, + onAbilityContinue(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityContinue.'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onNewWant]触发后回调。 + onNewWant(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onNewWant'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onNewWant]触发前回调。 + onWillNewWant(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWillNewWant'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onCreate]触发前回调。 + onAbilityWillCreate(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillCreate'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onWindowStageCreate]触发前回调。 + onWindowStageWillCreate(ability, windowStage) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageWillCreate'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onWindowStageDestroy]触发前回调。 + onWindowStageWillDestroy(ability, windowStage) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onWindowStageWillDestroy'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onDestroy]触发前回调。 + onAbilityWillDestroy(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillDestroy'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onForeground]触发前回调。 + onAbilityWillForeground(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillForeground'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onBackground]触发前回调。 + onAbilityWillBackground(ability) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillBackground'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onSaveState]触发前回调。 + onAbilityWillSaveState(ability: UIAbility) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilityWillSaveState.'); + }, + // 注册监听应用上下文的生命周期后,在UIAbility的[onSaveState]触发后回调。 + onAbilitySaveState(ability: UIAbility) { + hilog.info(DOMAIN, TAG, 'AbilityLifecycleCallback onAbilitySaveState.'); + } +}; + +export default class AbilityLifecycle extends UIAbility { + onCreate() { + hilog.info(DOMAIN, TAG, 'MyAbilityStage onCreate'); + + // 1.通过context属性获取applicationContext + let applicationContext = this.context.getApplicationContext(); + // 2.通过applicationContext注册监听应用内生命周期 + try { + let lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback); + GlobalContext.getContext().setObject('lifecycleId', lifecycleId); + hilog.info(DOMAIN, TAG, + `registerAbilityLifecycleCallback lifecycleId: ${GlobalContext.getContext().getObject('lifecycleId')}`); + } catch (paramError) { + hilog.error(DOMAIN, TAG, `error: ${paramError.code}, ${paramError.message}`); + } + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(DOMAIN, TAG, 'onWindowStageCreate'); + + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#f1f3f5', + navigationBarColor: '#f1f3f5', + }; + try { + windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); + }); + } catch (exception) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + + windowStage.loadContent('abilitypages/UIAbilityContext', (err, data) => { + if (err.code) { + return; + } + }); + } + + onBackground() { + hilog.info(DOMAIN, TAG, 'onBackground'); + } + + onForeground() { + hilog.info(DOMAIN, TAG, 'onBackground'); + } + + onPrepareToTerminate() { + hilog.info(DOMAIN, TAG, 'onPrepareToTerminate'); + // 开发者定义预关闭动作 + // 例如拉起另一个ability,根据ability处理结果执行异步关闭 + let want: Want = { + bundleName: 'com.samples.abilityruntime', + abilityName: 'AbilityLifecycleAbility' + } + this.context.startAbilityForResult(want) + .then((result) => { + // 获取ability处理结果,当返回结果的resultCode为0关闭当前UIAbility + hilog.info(DOMAIN, TAG, 'startAbilityForResult success, resultCode is ' + result.resultCode); + if (result.resultCode === 0) { + this.context.terminateSelf(); + } + }).catch((err: BusinessError) => { + // 异常处理 + hilog.error(DOMAIN, TAG, 'startAbilityForResult failed, err:' + JSON.stringify(err)); + this.context.terminateSelf(); + }) + + return true; // 已定义预关闭操作后,返回true表示UIAbility取消关闭 + } + + onWindowStageWillDestroy(windowStage: window.WindowStage) { + hilog.info(DOMAIN, TAG, 'onWindowStageWillDestroy'); + } + + onWindowStageRestore(windowStage: window.WindowStage) { + hilog.info(DOMAIN, TAG, 'onWindowStageRestore'); + } + + onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { + // No need to save state + hilog.info(DOMAIN, TAG, 'onSaveState'); + return AbilityConstant.OnSaveResult.ALL_REJECT; + } + + onWindowStageDestroy() { + hilog.info(DOMAIN, TAG, 'onWindowStageDestroy'); + } + + onDestroy() { + let applicationContext = this.context.getApplicationContext(); + let lifecycleId = GlobalContext.getContext().getObject('lifecycleId') as number; + try { + // 3.通过applicationContext注销监听应用内生命周期 + applicationContext.off('abilityLifecycle', lifecycleId, (error) => { + if (error && error.code !== 0) { + hilog.error(DOMAIN, TAG, `unregisterAbilityLifecycleCallback fail, error: ${JSON.stringify(error)}`); + } else { + hilog.info(DOMAIN, TAG, 'unregisterAbilityLifecycleCallback success.'); + } + }); + } catch (paramError) { + hilog.error(DOMAIN, TAG, + `error: ${(paramError as BusinessError).code}, ${(paramError as BusinessError).message}`); + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/AppManager.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/AppManager.ets index d9d9c9df20fb95c9cdb119bec8a1bdbb9ef292cf..a87a3f5b41a435b912fa51e854d3bd18c74488c1 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/AppManager.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/AppManager.ets @@ -1,349 +1,349 @@ -/* - * Copyright (c) 2024 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 { appManager } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = 'AppManager'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct AppManager { - private promptDuration: number = 2000; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.AppManager')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('7.18%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - .margin({ - top: '7.18%', - bottom: '6.41%', - left: '3.33%' - }) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.isRunningInStabilityTestCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('isRunningInStabilityTestCallback') - } - .onClick(() => { - try { - appManager.isRunningInStabilityTest((err, data) => { - hilog.info(DOMAIN, TAG, - `The result of isRunningInStabilityTest(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `isRunningInStabilityTest(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `isRunningInStabilityTest(callback) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.isRunningInStabilityTestPromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('isRunningInStabilityTestPromise') - } - .onClick(() => { - try { - appManager.isRunningInStabilityTest().then((data) => { - hilog.info(DOMAIN, TAG, - `The result of isRunningInStabilityTest(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `isRunningInStabilityTest(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `isRunningInStabilityTest(promise) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.isRamConstrainedDeviceCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('isRamConstrainedDeviceCallback') - } - .onClick(() => { - try { - appManager.isRamConstrainedDevice((err, data) => { - hilog.info(DOMAIN, TAG, - `The result of isRamConstrainedDevice(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `isRamConstrainedDevice(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `isRamConstrainedDevice(callback) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.isRamConstrainedDevicePromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('isRamConstrainedDevicePromise') - } - .onClick(() => { - try { - appManager.isRamConstrainedDevice().then((data) => { - hilog.info(DOMAIN, TAG, - `The result of isRamConstrainedDevice(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `isRamConstrainedDevice(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `isRamConstrainedDevice(promise) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.getAppMemorySizeCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('getAppMemorySizeCallback') - } - .onClick(() => { - try { - appManager.getAppMemorySize((err, data) => { - hilog.info(DOMAIN, TAG, - `The result of getAppMemorySize(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getAppMemorySize(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `getAppMemorySize(callback) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.getAppMemorySizePromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('getAppMemorySizePromise') - } - .onClick(() => { - try { - appManager.getAppMemorySize().then((data) => { - hilog.info(DOMAIN, TAG, - `The result of getAppMemorySize(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getAppMemorySize(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `getAppMemorySize(promise) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.getRunningProcessInformationCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('100%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('getRunningProcessInformationCallback') - } - .onClick(() => { - try { - appManager.getRunningProcessInformation((err, data) => { - hilog.info(DOMAIN, TAG, - `The result of getRunningProcessInformation(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getRunningProcessInformation(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `getRunningProcessInformation(callback) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.getRunningProcessInformationPromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('100%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - .id('getRunningProcessInformationPromise') - } - .onClick(() => { - try { - appManager.getRunningProcessInformation().then((data) => { - hilog.info(DOMAIN, TAG, - `The result of getRunningProcessInformation(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getRunningProcessInformation(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, `getRunningProcessInformation(promise) fail, err: ${JSON.stringify(err)}`); - } - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2024 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 { appManager } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'AppManager'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct AppManager { + private promptDuration: number = 2000; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.AppManager')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('7.18%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + .margin({ + top: '7.18%', + bottom: '6.41%', + left: '3.33%' + }) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.isRunningInStabilityTestCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('isRunningInStabilityTestCallback') + } + .onClick(() => { + try { + appManager.isRunningInStabilityTest((err, data) => { + hilog.info(DOMAIN, TAG, + `The result of isRunningInStabilityTest(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `isRunningInStabilityTest(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `isRunningInStabilityTest(callback) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.isRunningInStabilityTestPromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('isRunningInStabilityTestPromise') + } + .onClick(() => { + try { + appManager.isRunningInStabilityTest().then((data) => { + hilog.info(DOMAIN, TAG, + `The result of isRunningInStabilityTest(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `isRunningInStabilityTest(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `isRunningInStabilityTest(promise) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.isRamConstrainedDeviceCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('isRamConstrainedDeviceCallback') + } + .onClick(() => { + try { + appManager.isRamConstrainedDevice((err, data) => { + hilog.info(DOMAIN, TAG, + `The result of isRamConstrainedDevice(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `isRamConstrainedDevice(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `isRamConstrainedDevice(callback) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.isRamConstrainedDevicePromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('isRamConstrainedDevicePromise') + } + .onClick(() => { + try { + appManager.isRamConstrainedDevice().then((data) => { + hilog.info(DOMAIN, TAG, + `The result of isRamConstrainedDevice(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `isRamConstrainedDevice(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `isRamConstrainedDevice(promise) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.getAppMemorySizeCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('getAppMemorySizeCallback') + } + .onClick(() => { + try { + appManager.getAppMemorySize((err, data) => { + hilog.info(DOMAIN, TAG, + `The result of getAppMemorySize(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getAppMemorySize(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `getAppMemorySize(callback) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.getAppMemorySizePromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('getAppMemorySizePromise') + } + .onClick(() => { + try { + appManager.getAppMemorySize().then((data) => { + hilog.info(DOMAIN, TAG, + `The result of getAppMemorySize(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getAppMemorySize(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `getAppMemorySize(promise) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.getRunningProcessInformationCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('100%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('getRunningProcessInformationCallback') + } + .onClick(() => { + try { + appManager.getRunningProcessInformation((err, data) => { + hilog.info(DOMAIN, TAG, + `The result of getRunningProcessInformation(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getRunningProcessInformation(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `getRunningProcessInformation(callback) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.getRunningProcessInformationPromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('100%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + .id('getRunningProcessInformationPromise') + } + .onClick(() => { + try { + appManager.getRunningProcessInformation().then((data) => { + hilog.info(DOMAIN, TAG, + `The result of getRunningProcessInformation(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getRunningProcessInformation(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, `getRunningProcessInformation(promise) fail, err: ${JSON.stringify(err)}`); + } + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ApplicationContext.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ApplicationContext.ets index ea2e6252237d4d9e25c8de27c412eb1f95631ab1..18c221ec1d33db18beae27a2ce0679dd75c14f7f 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ApplicationContext.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ApplicationContext.ets @@ -1,225 +1,225 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { common } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { font, promptAction } from '@kit.ArkUI'; - -const TAG: string = 'ApplicationContext'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct ApplicationContext { - private promptDuration: number = 2000; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.ApplicationContext')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.ApplicationContext_getCurrentAppCloneIndex')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('100%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getCurrentAppCloneIndex') - .onClick(() => { - hilog.info(DOMAIN, TAG, 'ApplicationContext.getCurrentAppCloneIndex begin.'); - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let applicationContext = context.getApplicationContext(); - try { - let index = applicationContext.getCurrentAppCloneIndex(); - let msg = `getCurrentAppCloneIndex successfully, index: ${index}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - } catch (error) { - hilog.info(DOMAIN, TAG, - `ApplicationContext.getCurrentAppCloneIndex fail, error: ${JSON.stringify(error)}`); - } - hilog.info(DOMAIN, TAG, 'ApplicationContext.getCurrentAppCloneIndex succeed.'); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.ApplicationContext_getRunningProcessInformation_callback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('100%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getRunningProcessInformationCallback') - .onClick(() => { - hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation callback begin.'); - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let applicationContext = context.getApplicationContext(); - - try { - applicationContext.getRunningProcessInformation((err, data) => { - let msg = `getRunningProcessInformation callback successfully, data: ${JSON.stringify(data)}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, - `ApplicationContext.getRunningProcessInformation callback fail, error: ${JSON.stringify(err)}`); - } - hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation callback succeed.'); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.ApplicationContext_getRunningProcessInformation_promise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('100%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getRunningProcessInformationPromise') - .onClick(() => { - hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation promise begin.'); - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let applicationContext = context.getApplicationContext(); - - try { - applicationContext.getRunningProcessInformation().then((data) => { - let msg = `getRunningProcessInformation promise successfully, data: ${JSON.stringify(data)}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - }) - } catch (err) { - hilog.info(DOMAIN, TAG, - `ApplicationContext.getRunningProcessInformation promise fail, error: ${JSON.stringify(err)}`); - } - hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation promise succeed.'); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.ApplicationContext_setFont')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('100%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('setFont') - .onClick(() => { - font.registerFont({ - familyName: 'fontName', - familySrc: $rawfile('font/Roboto-Regular.ttf') - }) - - hilog.info(DOMAIN, TAG, 'ApplicationContext.setFont begin.'); - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let applicationContext = context.getApplicationContext(); - - try { - applicationContext.setFont('fontName'); - let msg = `setFont successfully`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - } catch (err) { - hilog.info(DOMAIN, TAG, - `ApplicationContext.setFont fail, error: ${JSON.stringify(err)}`); - } - hilog.info(DOMAIN, TAG, 'ApplicationContext.setFont succeed.'); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { font, promptAction } from '@kit.ArkUI'; + +const TAG: string = 'ApplicationContext'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct ApplicationContext { + private promptDuration: number = 2000; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.ApplicationContext')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.ApplicationContext_getCurrentAppCloneIndex')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('100%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getCurrentAppCloneIndex') + .onClick(() => { + hilog.info(DOMAIN, TAG, 'ApplicationContext.getCurrentAppCloneIndex begin.'); + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let applicationContext = context.getApplicationContext(); + try { + let index = applicationContext.getCurrentAppCloneIndex(); + let msg = `getCurrentAppCloneIndex successfully, index: ${index}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + } catch (error) { + hilog.info(DOMAIN, TAG, + `ApplicationContext.getCurrentAppCloneIndex fail, error: ${JSON.stringify(error)}`); + } + hilog.info(DOMAIN, TAG, 'ApplicationContext.getCurrentAppCloneIndex succeed.'); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.ApplicationContext_getRunningProcessInformation_callback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('100%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getRunningProcessInformationCallback') + .onClick(() => { + hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation callback begin.'); + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let applicationContext = context.getApplicationContext(); + + try { + applicationContext.getRunningProcessInformation((err, data) => { + let msg = `getRunningProcessInformation callback successfully, data: ${JSON.stringify(data)}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, + `ApplicationContext.getRunningProcessInformation callback fail, error: ${JSON.stringify(err)}`); + } + hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation callback succeed.'); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.ApplicationContext_getRunningProcessInformation_promise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('100%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getRunningProcessInformationPromise') + .onClick(() => { + hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation promise begin.'); + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let applicationContext = context.getApplicationContext(); + + try { + applicationContext.getRunningProcessInformation().then((data) => { + let msg = `getRunningProcessInformation promise successfully, data: ${JSON.stringify(data)}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + }) + } catch (err) { + hilog.info(DOMAIN, TAG, + `ApplicationContext.getRunningProcessInformation promise fail, error: ${JSON.stringify(err)}`); + } + hilog.info(DOMAIN, TAG, 'ApplicationContext.getRunningProcessInformation promise succeed.'); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.ApplicationContext_setFont')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('100%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('setFont') + .onClick(() => { + font.registerFont({ + familyName: 'fontName', + familySrc: $rawfile('font/Roboto-Regular.ttf') + }) + + hilog.info(DOMAIN, TAG, 'ApplicationContext.setFont begin.'); + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let applicationContext = context.getApplicationContext(); + + try { + applicationContext.setFont('fontName'); + let msg = `setFont successfully`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + } catch (err) { + hilog.info(DOMAIN, TAG, + `ApplicationContext.setFont fail, error: ${JSON.stringify(err)}`); + } + hilog.info(DOMAIN, TAG, 'ApplicationContext.setFont succeed.'); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/DataUriUtils.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/DataUriUtils.ets index 274b22b686e2d15420eae399f2c0b51253b1f993..f969d2154da7856e69c6f0590a0628ade7753e7f 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/DataUriUtils.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/DataUriUtils.ets @@ -1,198 +1,198 @@ -/* - * Copyright (c) 2024 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 { dataUriUtils } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = 'DataUriUtils'; -const DOMAIN: number = 0xFF00; -const ID = 1122; - -@Entry -@Component -struct DataUriUtils { - private promptDuration: number = 2000; - @State loopObserverRegistered: boolean = false; - @State unhandledRejectionRegistered: boolean = false; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.DataUriUtils')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.getId')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getId') - .onClick(() => { - ((): void => { - try { - let id = dataUriUtils.getId('com.example.dataUriUtils/1221'); - hilog.info(DOMAIN, TAG, `dataUriUtils.getId() called. id: ${id}`); - promptAction.showToast({ - message: `dataUriUtils.getId() called. id: ${id}`, - duration: this.promptDuration - }); - } catch (err) { - hilog.info(DOMAIN, TAG, `dataUriUtils.getId() error: ${err}`); - promptAction.showToast({ - message: `dataUriUtils.getId() error: ${err}`, - duration: this.promptDuration - }); - } - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.attachId')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('attachId') - .onClick(() => { - ((): void => { - let id = 1122; - let uri = dataUriUtils.attachId( - 'com.example.dataUriUtils', - id, - ); - promptAction.showToast({ - message: `dataUriUtils.attachId() called. uri: ${JSON.stringify(uri)}`, - duration: this.promptDuration - }); - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.deleteId')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('deleteId') - .onClick(() => { - ((): void => { - let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221'); - promptAction.showToast({ - message: `dataUriUtils.deleteId() called. uri: ${JSON.stringify(uri)}`, - duration: this.promptDuration - }); - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.updateId')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('updateId') - .onClick(() => { - ((): void => { - let uri = dataUriUtils.updateId( - 'com.example.dataUriUtils/1221', - ID - ); - promptAction.showToast({ - message: `dataUriUtils.updateId() called. uri: ${JSON.stringify(uri)}`, - duration: this.promptDuration - }); - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - } +/* + * Copyright (c) 2024 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 { dataUriUtils } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'DataUriUtils'; +const DOMAIN: number = 0xFF00; +const ID = 1122; + +@Entry +@Component +struct DataUriUtils { + private promptDuration: number = 2000; + @State loopObserverRegistered: boolean = false; + @State unhandledRejectionRegistered: boolean = false; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.DataUriUtils')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.getId')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getId') + .onClick(() => { + ((): void => { + try { + let id = dataUriUtils.getId('com.example.dataUriUtils/1221'); + hilog.info(DOMAIN, TAG, `dataUriUtils.getId() called. id: ${id}`); + promptAction.showToast({ + message: `dataUriUtils.getId() called. id: ${id}`, + duration: this.promptDuration + }); + } catch (err) { + hilog.info(DOMAIN, TAG, `dataUriUtils.getId() error: ${err}`); + promptAction.showToast({ + message: `dataUriUtils.getId() error: ${err}`, + duration: this.promptDuration + }); + } + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.attachId')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('attachId') + .onClick(() => { + ((): void => { + let id = 1122; + let uri = dataUriUtils.attachId( + 'com.example.dataUriUtils', + id, + ); + promptAction.showToast({ + message: `dataUriUtils.attachId() called. uri: ${JSON.stringify(uri)}`, + duration: this.promptDuration + }); + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.deleteId')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('deleteId') + .onClick(() => { + ((): void => { + let uri = dataUriUtils.deleteId('com.example.dataUriUtils/1221'); + promptAction.showToast({ + message: `dataUriUtils.deleteId() called. uri: ${JSON.stringify(uri)}`, + duration: this.promptDuration + }); + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.updateId')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('updateId') + .onClick(() => { + ((): void => { + let uri = dataUriUtils.updateId( + 'com.example.dataUriUtils/1221', + ID + ); + promptAction.showToast({ + message: `dataUriUtils.updateId() called. uri: ${JSON.stringify(uri)}`, + duration: this.promptDuration + }); + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ErrorManager.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ErrorManager.ets index 701e0d6c81e88cdca042a77491c646610ac18083..84c71b39b539b6166f5f0b761a9088db3e933159 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ErrorManager.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/ErrorManager.ets @@ -1,195 +1,195 @@ -/* - * Copyright (c) 2024 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 { errorManager } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = 'ErrorManager'; -const DOMAIN: number = 0xFF00; - -let observer: errorManager.LoopObserver = { - onLoopTimeOut(timeout: number) { - hilog.info(DOMAIN, TAG, `onLoopTimeOut, timeout: ${timeout}`) - errorManager.off('loopObserver'); - } -}; - -@Entry -@Component -struct ErrorManager { - private promptDuration: number = 2000; - private loopTimeOut: number = 20; - @State unhandledRejectionRegistered: boolean = false; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.ErrorManager')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.registerLoopObserver')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('registerLoopObserver') - .onClick(() => { - ((): void => { - try { - errorManager.on('loopObserver', this.loopTimeOut, observer); - let msg = `loopObserver registered successfully, loopTimeOut: ${this.loopTimeOut}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - } catch (error) { - hilog.info(DOMAIN, TAG, `errorManager.on('loopObserver') failed, error: ${JSON.stringify(error)}`); - } - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text(this.unhandledRejectionRegistered ? - $r('app.string.unregisterUnhandledRejection') : $r('app.string.registerUnhandledRejection')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id(this.unhandledRejectionRegistered ? ('unregisterUnhandledRejection') : ('registerUnhandledRejection')) - .onClick(() => { - ((): void => { - if (this.unhandledRejectionRegistered == false) { - let observer: errorManager.UnhandledRejectionObserver = (reason: Error, promise: Promise) => { - let msg = `UnhandledRejectionObserver reason: ${JSON.stringify(reason)}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - }; - - try { - errorManager.on('unhandledRejection', observer); - this.unhandledRejectionRegistered = true; - let msg = `unhandledRejection registered successfully`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - } catch (error) { - hilog.info(DOMAIN, TAG, - `errorManager.on('unhandledRejection') failed, error: ${JSON.stringify(error)}`); - this.unhandledRejectionRegistered = false; - } - - } else { - try { - errorManager.off('unhandledRejection'); - this.unhandledRejectionRegistered = false; - let msg: string = `unhandledRejection unregistered successfully`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ - message: msg, - duration: this.promptDuration - }) - } catch (error) { - this.unhandledRejectionRegistered = true; - hilog.info(DOMAIN, TAG, `unhandledRejection unregistered failed, error: ${JSON.stringify(error)}`); - } - } - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - if (this.unhandledRejectionRegistered) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.simulateUnhandledRejection')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('simulateUnhandledRejection') - .onClick(() => { - Promise.reject({ name: 'test', message: 'simulateUnhandledRejection' }); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - } +/* + * Copyright (c) 2024 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 { errorManager } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'ErrorManager'; +const DOMAIN: number = 0xFF00; + +let observer: errorManager.LoopObserver = { + onLoopTimeOut(timeout: number) { + hilog.info(DOMAIN, TAG, `onLoopTimeOut, timeout: ${timeout}`) + errorManager.off('loopObserver'); + } +}; + +@Entry +@Component +struct ErrorManager { + private promptDuration: number = 2000; + private loopTimeOut: number = 20; + @State unhandledRejectionRegistered: boolean = false; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.ErrorManager')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.registerLoopObserver')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('registerLoopObserver') + .onClick(() => { + ((): void => { + try { + errorManager.on('loopObserver', this.loopTimeOut, observer); + let msg = `loopObserver registered successfully, loopTimeOut: ${this.loopTimeOut}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + } catch (error) { + hilog.info(DOMAIN, TAG, `errorManager.on('loopObserver') failed, error: ${JSON.stringify(error)}`); + } + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text(this.unhandledRejectionRegistered ? + $r('app.string.unregisterUnhandledRejection') : $r('app.string.registerUnhandledRejection')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id(this.unhandledRejectionRegistered ? ('unregisterUnhandledRejection') : ('registerUnhandledRejection')) + .onClick(() => { + ((): void => { + if (this.unhandledRejectionRegistered == false) { + let observer: errorManager.UnhandledRejectionObserver = (reason: Error, promise: Promise) => { + let msg = `UnhandledRejectionObserver reason: ${JSON.stringify(reason)}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + }; + + try { + errorManager.on('unhandledRejection', observer); + this.unhandledRejectionRegistered = true; + let msg = `unhandledRejection registered successfully`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + } catch (error) { + hilog.info(DOMAIN, TAG, + `errorManager.on('unhandledRejection') failed, error: ${JSON.stringify(error)}`); + this.unhandledRejectionRegistered = false; + } + + } else { + try { + errorManager.off('unhandledRejection'); + this.unhandledRejectionRegistered = false; + let msg: string = `unhandledRejection unregistered successfully`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ + message: msg, + duration: this.promptDuration + }) + } catch (error) { + this.unhandledRejectionRegistered = true; + hilog.info(DOMAIN, TAG, `unhandledRejection unregistered failed, error: ${JSON.stringify(error)}`); + } + } + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + if (this.unhandledRejectionRegistered) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.simulateUnhandledRejection')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('simulateUnhandledRejection') + .onClick(() => { + Promise.reject({ name: 'test', message: 'simulateUnhandledRejection' }); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/UIAbilityContext.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/UIAbilityContext.ets index 26baf797fd911d53e28213acb9c6c2635f29d947..914f1337b5c61db817baf2356a7f61c3bca10cab 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/UIAbilityContext.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/UIAbilityContext.ets @@ -1,113 +1,113 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { common } from '@kit.AbilityKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'UIAbilityContext'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct UIAbilityContext { - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityContext')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityContext_moveAbilityToBackground')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('moveAbilityToBackground') - .onClick(() => { - let context = getContext(this) as common.UIAbilityContext; - context.moveAbilityToBackground().then(() => { - hilog.info(DOMAIN, TAG, 'moveAbilityToBackground success.'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN, TAG, `moveAbilityToBackground error: ${JSON.stringify(err)}.`); - }); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityContext_terminateSelf')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('terminateSelf') - .onClick(() => { - let context = getContext(this) as common.UIAbilityContext; - context.terminateSelf().then(() => { - hilog.info(DOMAIN, TAG, 'terminateSelf success.'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN, TAG, `terminateSelf error: ${JSON.stringify(err)}.`); - }); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .backgroundColor($r('app.color.backGrounding')) - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'UIAbilityContext'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct UIAbilityContext { + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityContext')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityContext_moveAbilityToBackground')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('moveAbilityToBackground') + .onClick(() => { + let context = getContext(this) as common.UIAbilityContext; + context.moveAbilityToBackground().then(() => { + hilog.info(DOMAIN, TAG, 'moveAbilityToBackground success.'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN, TAG, `moveAbilityToBackground error: ${JSON.stringify(err)}.`); + }); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityContext_terminateSelf')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('terminateSelf') + .onClick(() => { + let context = getContext(this) as common.UIAbilityContext; + context.terminateSelf().then(() => { + hilog.info(DOMAIN, TAG, 'terminateSelf success.'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN, TAG, `terminateSelf error: ${JSON.stringify(err)}.`); + }); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .backgroundColor($r('app.color.backGrounding')) + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/WantAgent.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/WantAgent.ets index 8e4bad93d05284834649bafcd57ad6d3e09ae3e9..33c1177c84e803e013e0e08ae425af90023b347e 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/WantAgent.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/abilitypages/WantAgent.ets @@ -1,506 +1,506 @@ -/* - * Copyright (c) 2024 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 { wantAgent } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = 'WantAgent'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct WantAgentClass { - private promptDuration: number = 2000; - private wantAgentInfo: wantAgent.WantAgentInfo = { - wants: [ - { - bundleName: 'com.samples.abilityruntime', - abilityName: 'EntryAbility', - } - ], - actionType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - actionFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] - } - - async getBundleNameCallback(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.getBundleName(dataBase, (err, data) => { - hilog.info(DOMAIN, TAG, - `The result of getBundleName(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getBundleName(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async getBundleNamePromise(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.getBundleName(dataBase).then((data) => { - hilog.info(DOMAIN, TAG, - `The result of getBundleName(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getBundleName(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async getUidCallback(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.getUid(dataBase, (err, data) => { - hilog.info(DOMAIN, TAG, - `The result of getUid(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getUid(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async getUidPromise(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.getUid(dataBase).then((data) => { - hilog.info(DOMAIN, TAG, - `The result of getUid(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getUid(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async cancelCallback(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.cancel(dataBase, (err, data) => { - hilog.info(DOMAIN, TAG, - `The result of cancel(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `cancel(callback) success`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async cancelPromise(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.cancel(dataBase).then((data) => { - hilog.info(DOMAIN, TAG, - `The result of cancel(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `cancel(promise) success`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async equalCallback(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.equal(dataBase, dataBase, (err, data) => { - hilog.info(DOMAIN, TAG, - `The result of equal(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `equal(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async equalPromise(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.equal(dataBase, dataBase).then((data) => { - hilog.info(DOMAIN, TAG, - `The result of equal(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `equal(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async getOperationTypeCallback(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.getOperationType(dataBase, (err, data) => { - hilog.info(DOMAIN, TAG, - `The result of getOperationType(callback) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getOperationType(callback) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async getOperationTypePromise(): Promise { - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.getOperationType(dataBase).then((data) => { - hilog.info(DOMAIN, TAG, - `The result of getOperationType(promise) is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `getOperationType(promise) success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - async trigger(): Promise { - let triggerInfo: wantAgent.TriggerInfo = { - code: 0, - want: { - bundleName: 'com.samples.abilityruntime', - abilityName: 'EntryAbility', - }, - permission: '', - extraInfo: { - test: 'this is a test value' - } - } - - wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { - wantAgent.trigger(dataBase, triggerInfo, (err, data) => { - hilog.info(DOMAIN, TAG, - `The result of trigger is: ${JSON.stringify(data)}`); - promptAction.showToast({ - message: `trigger success, data: ${JSON.stringify(data)}`, - duration: this.promptDuration - }) - }) - console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) - }) - } - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.WantAgent')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.getBundleNameCallback`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getBundleNameCallback') - .onClick(() => { - this.getBundleNameCallback(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.getBundleNamePromise`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getBundleNamePromise') - .onClick(() => { - this.getBundleNamePromise(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.getUidCallback`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getUidCallback') - .onClick(() => { - this.getUidCallback(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.getUidPromise`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getUidPromise') - .onClick(() => { - this.getUidPromise(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.cancelCallback`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('cancelCallback') - .onClick(() => { - this.cancelCallback(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.cancelPromise`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('cancelPromise') - .onClick(() => { - this.cancelPromise(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.equalCallback`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('equalCallback') - .onClick(() => { - this.equalCallback(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.equalPromise`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('equalPromise') - .onClick(() => { - this.equalPromise(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.getOperationTypeCallback`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getOperationTypeCallback') - .onClick(() => { - this.getOperationTypeCallback(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.getOperationTypePromise`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getOperationTypePromise') - .onClick(() => { - this.getOperationTypePromise(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r(`app.string.trigger`)) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('trigger') - .onClick(() => { - this.trigger(); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - } +/* + * Copyright (c) 2024 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 { wantAgent } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'WantAgent'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct WantAgentClass { + private promptDuration: number = 2000; + private wantAgentInfo: wantAgent.WantAgentInfo = { + wants: [ + { + bundleName: 'com.samples.abilityruntime', + abilityName: 'EntryAbility', + } + ], + actionType: wantAgent.OperationType.START_ABILITY, + requestCode: 0, + actionFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] + } + + async getBundleNameCallback(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.getBundleName(dataBase, (err, data) => { + hilog.info(DOMAIN, TAG, + `The result of getBundleName(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getBundleName(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async getBundleNamePromise(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.getBundleName(dataBase).then((data) => { + hilog.info(DOMAIN, TAG, + `The result of getBundleName(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getBundleName(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async getUidCallback(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.getUid(dataBase, (err, data) => { + hilog.info(DOMAIN, TAG, + `The result of getUid(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getUid(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async getUidPromise(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.getUid(dataBase).then((data) => { + hilog.info(DOMAIN, TAG, + `The result of getUid(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getUid(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async cancelCallback(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.cancel(dataBase, (err, data) => { + hilog.info(DOMAIN, TAG, + `The result of cancel(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `cancel(callback) success`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async cancelPromise(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.cancel(dataBase).then((data) => { + hilog.info(DOMAIN, TAG, + `The result of cancel(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `cancel(promise) success`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async equalCallback(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.equal(dataBase, dataBase, (err, data) => { + hilog.info(DOMAIN, TAG, + `The result of equal(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `equal(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async equalPromise(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.equal(dataBase, dataBase).then((data) => { + hilog.info(DOMAIN, TAG, + `The result of equal(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `equal(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async getOperationTypeCallback(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.getOperationType(dataBase, (err, data) => { + hilog.info(DOMAIN, TAG, + `The result of getOperationType(callback) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getOperationType(callback) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async getOperationTypePromise(): Promise { + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.getOperationType(dataBase).then((data) => { + hilog.info(DOMAIN, TAG, + `The result of getOperationType(promise) is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `getOperationType(promise) success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + async trigger(): Promise { + let triggerInfo: wantAgent.TriggerInfo = { + code: 0, + want: { + bundleName: 'com.samples.abilityruntime', + abilityName: 'EntryAbility', + }, + permission: '', + extraInfo: { + test: 'this is a test value' + } + } + + wantAgent.getWantAgent(this.wantAgentInfo).then((dataBase) => { + wantAgent.trigger(dataBase, triggerInfo, (err, data) => { + hilog.info(DOMAIN, TAG, + `The result of trigger is: ${JSON.stringify(data)}`); + promptAction.showToast({ + message: `trigger success, data: ${JSON.stringify(data)}`, + duration: this.promptDuration + }) + }) + console.info(`${TAG} getWantAgent success: ${JSON.stringify(dataBase)}`) + }) + } + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.WantAgent')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.getBundleNameCallback`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getBundleNameCallback') + .onClick(() => { + this.getBundleNameCallback(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.getBundleNamePromise`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getBundleNamePromise') + .onClick(() => { + this.getBundleNamePromise(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.getUidCallback`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getUidCallback') + .onClick(() => { + this.getUidCallback(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.getUidPromise`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getUidPromise') + .onClick(() => { + this.getUidPromise(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.cancelCallback`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('cancelCallback') + .onClick(() => { + this.cancelCallback(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.cancelPromise`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('cancelPromise') + .onClick(() => { + this.cancelPromise(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.equalCallback`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('equalCallback') + .onClick(() => { + this.equalCallback(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.equalPromise`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('equalPromise') + .onClick(() => { + this.equalPromise(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.getOperationTypeCallback`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getOperationTypeCallback') + .onClick(() => { + this.getOperationTypeCallback(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.getOperationTypePromise`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getOperationTypePromise') + .onClick(() => { + this.getOperationTypePromise(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r(`app.string.trigger`)) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('trigger') + .onClick(() => { + this.trigger(); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entryability/EntryAbility.ets index 57f379afafd78e29bf9929ba5faf57ed2f1db886..9b1882bc130db6a5d1d451809c9b7639a1bc50fe 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,88 +1,88 @@ -/* - * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const TAG: string = 'EntryAbility'; -const DOMAIN: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, TAG, 'Ability onWindowStageCreate'); - - let windowClass: window.Window | undefined = undefined; - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - let systemBarProperties: window.SystemBarProperties = { - statusBarColor: '#f1f3f5', - navigationBarColor: '#f1f3f5', - }; - try { - windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); - } - }); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, TAG, 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, TAG, 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const TAG: string = 'EntryAbility'; +const DOMAIN: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, TAG, 'Ability onWindowStageCreate'); + + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#f1f3f5', + navigationBarColor: '#f1f3f5', + }; + try { + windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); + }); + } catch (exception) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, TAG, 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, TAG, 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, TAG, 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index b72fc477d96447e221cf45c9c6671c8018ae05f3..dc55c03d3eea7ce53d5346c732a39ce9bf5267e1 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,12 +1,12 @@ -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)); - } +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/BasicFeature/Ability/AbilityRuntime/entry/src/main/module.json5 b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/module.json5 index f7ffb1e19b00d4a35828f8a673f3ba8b6c429488..b46bb5595a8f18e3aa0abf23ae5f8aa66b755f0e 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/module.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/module.json5 @@ -1,87 +1,87 @@ -/* - * Copyright (c) 2024 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, - "recoverable": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "AbilityLifecycleAbility", - "srcEntry": "./ets/abilitylifecyclecallback/AbilityLifecycleCallback.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:startIcon", - "label": "$string:EntryAbility_label", - "recoverable": true, - "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" - } - ] - }, - ], - } +/* + * Copyright (c) 2024 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, + "recoverable": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "AbilityLifecycleAbility", + "srcEntry": "./ets/abilitylifecyclecallback/AbilityLifecycleCallback.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:startIcon", + "label": "$string:EntryAbility_label", + "recoverable": true, + "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/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/element/color.json index 73d32c4c75edccd6fab2427bf3977e8bd43a7e90..6cdb3e3002dfe27880828a3b181946668beef78c 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "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/Ability/AbilityRuntime/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/profile/backup_config.json +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/entry/src/ohosTest/module.json5 b/code/BasicFeature/Ability/AbilityRuntime/entry/src/ohosTest/module.json5 index 93f5a2e5d62e1291b55d7da9c6a5d3e424b2301d..556081afc70bbbf25783da08557005cb84a80c85 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/entry/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/Ability/AbilityRuntime/hvigor/hvigor-config.json5 b/code/BasicFeature/Ability/AbilityRuntime/hvigor/hvigor-config.json5 index ab4cf8bc329595e8f37227a3cb8e175d8f4645b3..3ac9626c8b452bddbb689aaff5ec6cbd4180caf7 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/hvigor/hvigor-config.json5 @@ -1,19 +1,19 @@ -/* - * Copyright (c) 2024 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": { - } +/* + * Copyright (c) 2024 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": { + } } \ No newline at end of file diff --git a/code/BasicFeature/Ability/AbilityRuntime/oh-package.json5 b/code/BasicFeature/Ability/AbilityRuntime/oh-package.json5 index 5d3d2f801cb089d08fb1f3a91bb7fd51d244c08b..4b93216c0453e48ea6e6728e3d962d09e8a11e05 100644 --- a/code/BasicFeature/Ability/AbilityRuntime/oh-package.json5 +++ b/code/BasicFeature/Ability/AbilityRuntime/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2024 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.18", - "@ohos/hamock": "1.0.0" - } -} +/* + * Copyright (c) 2024 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.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/Ability/UniversalLink/AppScope/app.json5 b/code/BasicFeature/Ability/UniversalLink/AppScope/app.json5 index 036de8101091e501c88e8c1ef276997595681f67..e0633485236121045966166739a42d330593b124 100644 --- a/code/BasicFeature/Ability/UniversalLink/AppScope/app.json5 +++ b/code/BasicFeature/Ability/UniversalLink/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.universallink", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.universallink", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Ability/UniversalLink/AppScope/resources/base/element/string.json b/code/BasicFeature/Ability/UniversalLink/AppScope/resources/base/element/string.json index f9a2f3aa9d1f31c0b66ddfabeaac7769729b5691..c8e33e8783751102f9bf7b274ab5827e27ec933a 100644 --- a/code/BasicFeature/Ability/UniversalLink/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Ability/UniversalLink/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UniversalLink" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UniversalLink" + } + ] +} diff --git a/code/BasicFeature/Ability/UniversalLink/README_zh.md b/code/BasicFeature/Ability/UniversalLink/README_zh.md index 6482300789f6f00863260dc15c1e74382c3bb2af..0009ef24e40e74140bc85af931569f34762fa116 100644 --- a/code/BasicFeature/Ability/UniversalLink/README_zh.md +++ b/code/BasicFeature/Ability/UniversalLink/README_zh.md @@ -1,66 +1,66 @@ -# 基础能力增强 - -### 介绍 - -本示例使用 [UIAbilityContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) 接口实现了通过AppLinking启动UIAbility功能。 - -### 效果预览 - -| 主页面 | 点击按钮拉起Ability | -| :----------------------------------------------: | :---------------------------------------------------: | -| | | - -### 使用说明 - -UniversalLink基础能力展示 - -1.点击主页面**openLink(promise)拉起应用**按钮,拉起新的Ability,页面显示'UniversalLink方式拉起Ability成功'; - -2.点击主页面**openLink(callback)拉起应用**按钮,拉起新的Ability,页面显示'UniversalLink方式拉起Ability成功'; - -### 工程目录 - -``` -entry/src/main/ets/ -|---entryability -| |---EntryAbility.ets // 首页的Ability -| |---OpenLinkAbility.ets // UIAbility(用于验证UniversalLink功能使用) -|---pages -| |---Index.ets // 首页(包含openLink接口的调用) -| |---UniversalLinkIndex.ets // 被启动的UIAbility的展示页 -``` - -### 具体实现 - -* UniversalLink基础能力实现,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) - - * openLink(promise)接口实现:通过调用context.openLink接口,传入与要拉起的应用相同的配置,实现拉起应用的功能; - * openLink(callback)接口实现:通过调用context.openLink接口,传入与要拉起的应用相同的配置,实现拉起应用的功能; - - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568; - -2.本示例为Stage模型,支持API12版本SDK,版本号:5.0.0.31; - -3.本示例需要使用DevEco Studio NEXT Developer Beta1 (Build Version: 5.0.3.403, built on June 20, 2024)才可编译运行; - -### 下载 - -```shell -git init -git config core.sparsecheckout true -echo code/BasicFeature/Ability/UniversalLink/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# 基础能力增强 + +### 介绍 + +本示例使用 [UIAbilityContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) 接口实现了通过AppLinking启动UIAbility功能。 + +### 效果预览 + +| 主页面 | 点击按钮拉起Ability | +| :----------------------------------------------: | :---------------------------------------------------: | +| | | + +### 使用说明 + +UniversalLink基础能力展示 + +1.点击主页面**openLink(promise)拉起应用**按钮,拉起新的Ability,页面显示'UniversalLink方式拉起Ability成功'; + +2.点击主页面**openLink(callback)拉起应用**按钮,拉起新的Ability,页面显示'UniversalLink方式拉起Ability成功'; + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets // 首页的Ability +| |---OpenLinkAbility.ets // UIAbility(用于验证UniversalLink功能使用) +|---pages +| |---Index.ets // 首页(包含openLink接口的调用) +| |---UniversalLinkIndex.ets // 被启动的UIAbility的展示页 +``` + +### 具体实现 + +* UniversalLink基础能力实现,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) + + * openLink(promise)接口实现:通过调用context.openLink接口,传入与要拉起的应用相同的配置,实现拉起应用的功能; + * openLink(callback)接口实现:通过调用context.openLink接口,传入与要拉起的应用相同的配置,实现拉起应用的功能; + + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568; + +2.本示例为Stage模型,支持API12版本SDK,版本号:5.0.0.31; + +3.本示例需要使用DevEco Studio NEXT Developer Beta1 (Build Version: 5.0.3.403, built on June 20, 2024)才可编译运行; + +### 下载 + +```shell +git init +git config core.sparsecheckout true +echo code/BasicFeature/Ability/UniversalLink/ > .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/Ability/UniversalLink/build-profile.json5 b/code/BasicFeature/Ability/UniversalLink/build-profile.json5 index f0b12f54c143d8dbc3f7093b44d7591b4c62cbb3..6774a445081b2bb2d3c125696c625a15faf308e0 100644 --- a/code/BasicFeature/Ability/UniversalLink/build-profile.json5 +++ b/code/BasicFeature/Ability/UniversalLink/build-profile.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 12, - "compileSdkVersion": 12, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 12, + "compileSdkVersion": 12, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/UniversalLink/entry/build-profile.json5 b/code/BasicFeature/Ability/UniversalLink/entry/build-profile.json5 index 97f563b45aac28e7e3ae336f7c0eb06b7b789179..63b88fb1a0053e40acb2391457a7e9d71af748fe 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/build-profile.json5 +++ b/code/BasicFeature/Ability/UniversalLink/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Ability/UniversalLink/entry/oh-package.json5 b/code/BasicFeature/Ability/UniversalLink/entry/oh-package.json5 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..4e54d14e1b444a338b2c922f94a4fe4deed5be45 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/oh-package.json5 +++ b/code/BasicFeature/Ability/UniversalLink/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": {} -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/EntryAbility.ets index 3722d79ef8d33545f91f33f548a48ada9a0c41be..08928746d7d90cb450028ec3a60994017bc32c66 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,88 +1,88 @@ -/* - * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; - -const TAG: string = '[EntryAbility]'; -const DOMAIN: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(): void { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - let windowClass: window.Window | undefined = undefined; - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - let systemBarProperties: window.SystemBarProperties = { - statusBarColor: '#f1f3f5', - navigationBarColor: '#f1f3f5', - }; - try { - windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); - } - }); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.info(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG: string = '[EntryAbility]'; +const DOMAIN: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(): void { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#f1f3f5', + navigationBarColor: '#f1f3f5', + }; + try { + windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); + }); + } catch (exception) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.info(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/OpenLinkAbility.ets b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/OpenLinkAbility.ets index 08686c38189af1b85f9ce11dc6410f6c73ab5d0f..e836d7f74c05450cd2d33006f7906729881714f0 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/OpenLinkAbility.ets +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entryability/OpenLinkAbility.ets @@ -1,86 +1,86 @@ -/* - * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import { UIAbility } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const TAG: string = '[OpenLinkAbility]'; -const DOMAIN: number = 0xFF00; - -export default class OpenLinkAbility extends UIAbility { - onCreate(): void { - hilog.info(DOMAIN, TAG, '%{public}s', 'OpenLinkAbility onCreate'); - } - - onForeground() { - hilog.info(DOMAIN, TAG, `OpenLinkAbility onForeground`); - } - - onBackground() { - hilog.info(DOMAIN, TAG, `OpenLinkAbility onBackground`); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, TAG, '%{public}s', 'OpenLinkAbility onWindowStageCreate'); - - let windowClass: window.Window | undefined = undefined; - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - let systemBarProperties: window.SystemBarProperties = { - statusBarColor: '#f1f3f5', - navigationBarColor: '#f1f3f5', - }; - try { - windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); - } - }); - - windowStage.loadContent('pages/UniversalLinkIndex', (err) => { - if (err.code) { - hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); - }); - } - - onDestroy(): void { - hilog.info(DOMAIN, TAG, 'OpenLinkAbility onDestroy'); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, TAG, 'OpenLinkAbility onWindowStageDestroy'); - } +/* + * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import { UIAbility } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const TAG: string = '[OpenLinkAbility]'; +const DOMAIN: number = 0xFF00; + +export default class OpenLinkAbility extends UIAbility { + onCreate(): void { + hilog.info(DOMAIN, TAG, '%{public}s', 'OpenLinkAbility onCreate'); + } + + onForeground() { + hilog.info(DOMAIN, TAG, `OpenLinkAbility onForeground`); + } + + onBackground() { + hilog.info(DOMAIN, TAG, `OpenLinkAbility onBackground`); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, TAG, '%{public}s', 'OpenLinkAbility onWindowStageCreate'); + + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#f1f3f5', + navigationBarColor: '#f1f3f5', + }; + try { + windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); + }); + } catch (exception) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + + windowStage.loadContent('pages/UniversalLinkIndex', (err) => { + if (err.code) { + hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); + }); + } + + onDestroy(): void { + hilog.info(DOMAIN, TAG, 'OpenLinkAbility onDestroy'); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, TAG, 'OpenLinkAbility onWindowStageDestroy'); + } }; \ No newline at end of file diff --git a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index b72fc477d96447e221cf45c9c6671c8018ae05f3..dc55c03d3eea7ce53d5346c732a39ce9bf5267e1 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,12 +1,12 @@ -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)); - } +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/BasicFeature/Ability/UniversalLink/entry/src/main/ets/pages/UniversalLinkIndex.ets b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/pages/UniversalLinkIndex.ets index 6c706d3e123fe9f7897c9eb15c48e95f4efec6f5..b86832a068a4464614ce122ec1a7558113daa512 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/pages/UniversalLinkIndex.ets +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/ets/pages/UniversalLinkIndex.ets @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct UniversalLinkIndex { - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.OpenLinkTitle')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - } - } - .width('100%') - .height('80%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct UniversalLinkIndex { + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.OpenLinkTitle')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + } + } + .width('100%') + .height('80%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } +} diff --git a/code/BasicFeature/Ability/UniversalLink/entry/src/main/module.json5 b/code/BasicFeature/Ability/UniversalLink/entry/src/main/module.json5 index 5c5e88d321ff3f1df13dae9aa2f867c55b0f19e6..1e83bc34d3caa305360a74494cb356e347128eb2 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/module.json5 +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/module.json5 @@ -1,97 +1,97 @@ -/* - * Copyright (c) 2024 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" - ] - } - ] - }, - { - "name": "OpenLinkAbility", - "srcEntry": "./ets/entryability/OpenLinkAbility.ets", - "description": "uri", - "icon": "$media:layered_image", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "entities": [ - "entity.system.home", - "entity.system.browsable" - ], - "actions": [ - "action.system.home", - "ohos.want.action.viewData" - ], - "uris": [ - { - // scheme可以自定义 - "scheme": "http", - // host须配置关联的域名 - "host": "docs.openharmony.cn", - // path可选,为了避免匹配到多个应用,建议配置该字段 - "path": "" - } - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EntryBackupAbility", - "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ] - } +/* + * Copyright (c) 2024 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" + ] + } + ] + }, + { + "name": "OpenLinkAbility", + "srcEntry": "./ets/entryability/OpenLinkAbility.ets", + "description": "uri", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "entities": [ + "entity.system.home", + "entity.system.browsable" + ], + "actions": [ + "action.system.home", + "ohos.want.action.viewData" + ], + "uris": [ + { + // scheme可以自定义 + "scheme": "http", + // host须配置关联的域名 + "host": "docs.openharmony.cn", + // path可选,为了避免匹配到多个应用,建议配置该字段 + "path": "" + } + ] + } + ] + } + ], + "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/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/element/color.json index 73d32c4c75edccd6fab2427bf3977e8bd43a7e90..6cdb3e3002dfe27880828a3b181946668beef78c 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "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/Ability/UniversalLink/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/profile/backup_config.json +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/BasicFeature/Ability/UniversalLink/entry/src/ohosTest/module.json5 b/code/BasicFeature/Ability/UniversalLink/entry/src/ohosTest/module.json5 index 1f646ea03f584d15f4a5406ea548af0214a093d4..5f63462032245655b8df990c83c5d7312015c089 100644 --- a/code/BasicFeature/Ability/UniversalLink/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Ability/UniversalLink/entry/src/ohosTest/module.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/Ability/UniversalLink/hvigor/hvigor-config.json5 b/code/BasicFeature/Ability/UniversalLink/hvigor/hvigor-config.json5 index 5f9d8a57584fa98d3e8f6c63a304213b801d0dff..76e3231223076011f7f4400f54fa73a5ab0141d4 100644 --- a/code/BasicFeature/Ability/UniversalLink/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Ability/UniversalLink/hvigor/hvigor-config.json5 @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2024 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": { - }, - "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*/ - } -} +/* + * Copyright (c) 2024 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": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/BasicFeature/Ability/UniversalLink/oh-package.json5 b/code/BasicFeature/Ability/UniversalLink/oh-package.json5 index d645a02be51ec3ec6bec2da93c5350d0b80b935f..a941f4458316c00220a8f9a3b0c15342b6b6255b 100644 --- a/code/BasicFeature/Ability/UniversalLink/oh-package.json5 +++ b/code/BasicFeature/Ability/UniversalLink/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.18", - "@ohos/hamock": "1.0.0" - } -} +/* + * Copyright (c) 2024 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.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/app.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/app.json5 old mode 100755 new mode 100644 index 9933eb9fd509c087acc391262ab33e116c26c7a1..8a01fbc442dcdb3996aa38265a48ee4a0fe3380a --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/app.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.bundlemanagement", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.bundlemanagement", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/resources/base/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 5987cf90b2d1595accad39e2b15fe3d33ccabc9e..6e551034bff4efca47cfac83c2662cca5d2c5fae --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "bundleManagement" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "bundleManagement" + } + ] +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/resources/base/media/app_icon.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/README_zh.md b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/README_zh.md old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/build-profile.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/build-profile.json5 old mode 100755 new mode 100644 index b38a57b1059331878ebb82aec7a79aebb5e5a45a..f2e5bbf7eaabad09449575051cf484543b407ecf --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/build-profile.json5 @@ -1,67 +1,67 @@ -/** - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "libraryOverlay", - "srcPath": "./libraryOverlay", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "libraryRuntimeOverlay", - "srcPath": "./libraryRuntimeOverlay", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/** + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "libraryOverlay", + "srcPath": "./libraryOverlay", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "libraryRuntimeOverlay", + "srcPath": "./libraryRuntimeOverlay", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/build-profile.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/build-profile.json5 old mode 100755 new mode 100644 index f6cbf2f1e1662bf11f099bb743387f0eebe953d4..85d986b1fcb577c8016bc56ef1577c4d509626ee --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/build-profile.json5 @@ -1,28 +1,28 @@ -/* -* Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/hvigorfile.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/oh-package.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/oh-package.json5 old mode 100755 new mode 100644 index 57a65bc4999dbe974ae64cf7850f4f6bdf71f74a..bf70bbf4667a5a35c5834f72a76091460f7aacdb --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/oh-package.json5 @@ -1,13 +1,13 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "libraryOverlay": "file:../libraryOverlay", - "libraryRuntimeOverlay": "file:../libraryRuntimeOverlay" - } -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "libraryOverlay": "file:../libraryOverlay", + "libraryRuntimeOverlay": "file:../libraryRuntimeOverlay" + } +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/entryability/EntryAbility.ts old mode 100755 new mode 100644 index 40c6f70ca40e26ca147d61bb324a1b03a9fb6dc7..e4316af59182323c6503a865214d9e14c90b2524 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; -import { window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'entryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - - windowStage.getMainWindow((err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); - return; - } - let windowClass = data; - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); - - let SystemBarProperties = { - statusBarColor: "#f1f3f5", - navigationBarColor: "#f1f3f5" - }; - windowClass.setWindowSystemBarProperties(SystemBarProperties, (err) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in setting the system bar properties.'); - }); - }) - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); - } +/* + * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'entryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + + windowStage.getMainWindow((err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + return; + } + let windowClass = data; + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); + + let SystemBarProperties = { + statusBarColor: "#f1f3f5", + navigationBarColor: "#f1f3f5" + }; + windowClass.setWindowSystemBarProperties(SystemBarProperties, (err) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to set the system bar properties. Cause: ' + JSON.stringify(err)); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in setting the system bar properties.'); + }); + }) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newability/NewAbility.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newability/NewAbility.ts old mode 100755 new mode 100644 index 587e40dce9c69c5403fd8c3f1f86540ab04106b1..3d4d3890460e29e7aeb57a46eb3c766ac27afd6d --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newability/NewAbility.ts +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newability/NewAbility.ts @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; -import { window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'newAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class NewAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onCreate'); - } - - onDestroy() { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onWindowStageCreate'); - - windowStage.loadContent('pages/NewPage', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onBackground'); - } +/* + * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'newAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class NewAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onCreate'); + } + + onDestroy() { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onWindowStageCreate'); + + windowStage.loadContent('pages/NewPage', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'NewAbility onBackground'); + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newuiextability/NewUIExtAbility.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newuiextability/NewUIExtAbility.ets old mode 100755 new mode 100644 index 272295249708067d08d45163c27a53ff39f0d080..c78ee214701d9267e7b68e705610f51b0874bd94 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newuiextability/NewUIExtAbility.ets +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/newuiextability/NewUIExtAbility.ets @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 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 { Want, UIExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; - -export default class NewUIExtAbility extends UIExtensionAbility { - onCreate() { - } - - onDestroy() { - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - let param: Record = { - 'session': session, - 'want': want - }; - - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('pages/NewPage', storage); - } - - onForeground() { - // Ability has brought to foreground - } - - onBackground() { - // Ability has back to background - } +/* + * Copyright (c) 2024 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 { Want, UIExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; + +export default class NewUIExtAbility extends UIExtensionAbility { + onCreate() { + } + + onDestroy() { + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + let param: Record = { + 'session': session, + 'want': want + }; + + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/NewPage', storage); + } + + onForeground() { + // Ability has brought to foreground + } + + onBackground() { + // Ability has back to background + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/pages/NewPage.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/pages/NewPage.ets old mode 100755 new mode 100644 index 9cab3d3b3eaf218a666c338ab39846fbb42cd55d..93826059c749c52456087e5f00a4d0fb1d5e32f0 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/pages/NewPage.ets +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/ets/pages/NewPage.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { common } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = '[Sample_ShortCut]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct NewPage { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Image($r('app.media.ic_back')) - .size({ width: 20, height: 18 }) - .margin({ right: 18 }) - .onClick(() => { - this.context.terminateSelf(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'terminateSelf'); - }) - }) - Text($r('app.string.NewAbility_label')) - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 26, right: 26 }) - .width('100%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { - Column() { - Image($r('app.media.pic_empty')).width('33%') - Text($r('app.string.empty')) - .fontSize(14) - } - }.width('100%') - .height('90%') - } - .width('100%') - .height('100%') - .padding({ top: 36, bottom: 0 }) - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[Sample_ShortCut]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct NewPage { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Image($r('app.media.ic_back')) + .size({ width: 20, height: 18 }) + .margin({ right: 18 }) + .onClick(() => { + this.context.terminateSelf(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'terminateSelf'); + }) + }) + Text($r('app.string.NewAbility_label')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 26, right: 26 }) + .width('100%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { + Column() { + Image($r('app.media.pic_empty')).width('33%') + Text($r('app.string.empty')) + .fontSize(14) + } + }.width('100%') + .height('90%') + } + .width('100%') + .height('100%') + .padding({ top: 36, bottom: 0 }) + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/module.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/module.json5 old mode 100755 new mode 100644 index cc8bd34fc23790183865833c8980ab8436210035..b6e22c8236b255d587bab862ebdd30313a9e41ad --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/module.json5 @@ -1,102 +1,102 @@ -/* - * Copyright (c) 2024 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ], - "uris": [ - { - "scheme": "http" - } - ] - } - ], - "metadata": [ - { - "name": "ohos.ability.shortcuts", - "resource": "$profile:shortcuts_config" - } - ] - }, - { - "name": "NewAbility", - "srcEntry": "./ets/newability/NewAbility.ts", - "description": "$string:NewAbility_desc", - "icon": "$media:icon", - "label": "$string:NewAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "metadata": [ - { - "name": "ohos.ability.NewAbility", - "resource": "$profile:shortcuts_config" - } - ] - } - ], - "extensionAbilities": [ - { - "name": "NewUIExtAbility", - "icon": "$media:icon", - "description": "NewUIExtAbility", - "exported": true, - "type": "sysPicker/share", - "srcEntry": "./ets/newuiextability/NewUIExtAbility.ets", - "metadata": [ - { - "name": "ohos.ability.NewUIExtAbility", - "resource": "$profile:shortcuts_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.RUN_DYN_CODE", - } - ], - "querySchemes": [ - "http" - ] - } +/* + * Copyright (c) 2024 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ], + "uris": [ + { + "scheme": "http" + } + ] + } + ], + "metadata": [ + { + "name": "ohos.ability.shortcuts", + "resource": "$profile:shortcuts_config" + } + ] + }, + { + "name": "NewAbility", + "srcEntry": "./ets/newability/NewAbility.ts", + "description": "$string:NewAbility_desc", + "icon": "$media:icon", + "label": "$string:NewAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "metadata": [ + { + "name": "ohos.ability.NewAbility", + "resource": "$profile:shortcuts_config" + } + ] + } + ], + "extensionAbilities": [ + { + "name": "NewUIExtAbility", + "icon": "$media:icon", + "description": "NewUIExtAbility", + "exported": true, + "type": "sysPicker/share", + "srcEntry": "./ets/newuiextability/NewUIExtAbility.ets", + "metadata": [ + { + "name": "ohos.ability.NewUIExtAbility", + "resource": "$profile:shortcuts_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.RUN_DYN_CODE", + } + ], + "querySchemes": [ + "http" + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/element/color.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index 397f3ddb2b31d903d416d57db6b3d620d7ee0246..8fe12b6f07e4a587f7b61e7622c8366f7854bed4 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/element/color.json @@ -1,20 +1,20 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "button_color", - "value": "#027DFF" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "button_color", + "value": "#027DFF" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#000" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/media/ic_back.svg b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/media/ic_back.svg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/media/icon.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/media/pic_empty.svg b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/media/pic_empty.svg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/profile/shortcuts_config.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/base/profile/shortcuts_config.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/testability/TestAbility.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/testability/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/module.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 0ea2ffbd558bdf27353ca4579aef9823fee5c79d..91e15a07aef33644652ef6c612dfe7d0c8c41c40 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* -* Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } +/* +* Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/element/color.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/media/icon.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/base/profile/test_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/en_US/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/zh_CN/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/entry/src/ohosTest/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigor/hvigor-config.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigor/hvigor-wrapper.js b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigor/hvigor-wrapper.js old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigorfile.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigorw b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigorw old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigorw.bat b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/hvigorw.bat old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/build-profile.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/build-profile.json5 old mode 100755 new mode 100644 index 28dd9a05d1e3c7b10ee44bcb97cfc9554aa2cf97..26d4447c1161fb39d6eeaa1da5e7eb4e07974040 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/build-profile.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default" - } - ] +/* + * Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/hvigorfile.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/oh-package.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/oh-package.json5 old mode 100755 new mode 100644 index 2c177c4b11f80e383029b82f9cdb3b3dd019cfd8..8921a9e7f61193863f3bd3128c02b902414de887 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "libraryOverlay", - "description": "Please describe the basic information.", - "main": "./src/main/ets/Index.ets", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "libraryOverlay", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/Index.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/Index.ets old mode 100755 new mode 100644 index ac3645ba793388b3bff3e02ebe9005d557fd9f72..8facc0b5e707c9d1b5f08c5fac5f7698a6b098f3 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/Index.ets +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/Index.ets @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 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. - */ - +/* + * Copyright (c) 2024 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 { add } from './utils/Calc' \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/pages/Index.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/utils/Calc.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/ets/utils/Calc.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/module.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/module.json5 old mode 100755 new mode 100644 index 35e810f31bda428e9856325e85b036da151daa84..e576fbd6bd7423adf051a3963a128e9d262f97eb --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/module.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2024 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": "libraryOverlay", - "type": "shared", - "description": "$string:shared_desc", - "targetModuleName":"entry", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "pages": "$profile:main_pages" - } +/* + * Copyright (c) 2024 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": "libraryOverlay", + "type": "shared", + "description": "$string:shared_desc", + "targetModuleName":"entry", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/element/color.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/element/string.json old mode 100755 new mode 100644 index 8ff4fc989c899f0db87436de16a37ef3f60072c9..e5e5574f732b85e60e36335fcc849273953e1c7e --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/element/string.json +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "shared_desc", - "value": "description" - }, - { - "name": "test_string", - "value": "base_overlay_test" - } - ] +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + }, + { + "name": "test_string", + "value": "base_overlay_test" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/media/icon.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/media/setting.jpeg b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/media/setting.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/en_US/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryOverlay/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/build-profile.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/build-profile.json5 old mode 100755 new mode 100644 index 28dd9a05d1e3c7b10ee44bcb97cfc9554aa2cf97..26d4447c1161fb39d6eeaa1da5e7eb4e07974040 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/build-profile.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default" - } - ] +/* + * Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/hvigorfile.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/oh-package.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/oh-package.json5 old mode 100755 new mode 100644 index 52496b1d38c98b74a28f11ecce8e0398ea1aaaf3..fff6109ffbb636629f85b13edf4aed7296f1f31e --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "libraryRuntimeOverlay", - "description": "Please describe the basic information.", - "main": "./src/main/ets/Index.ets", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "libraryRuntimeOverlay", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/Index.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/Index.ets old mode 100755 new mode 100644 index ac3645ba793388b3bff3e02ebe9005d557fd9f72..8facc0b5e707c9d1b5f08c5fac5f7698a6b098f3 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/Index.ets +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/Index.ets @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2024 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. - */ - +/* + * Copyright (c) 2024 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 { add } from './utils/Calc' \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/pages/Index.ets b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/utils/Calc.ts b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/ets/utils/Calc.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/module.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/module.json5 old mode 100755 new mode 100644 index b43187367782c38be6e908fcad95743e81bc545f..f110da50736c0ddd7fa5b97534562808fabbfe97 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/module.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2024 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": "libraryRuntimeOverlay", - "type": "shared", - "description": "$string:shared_desc", - "targetModuleName":"entry", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "pages": "$profile:main_pages" - } +/* + * Copyright (c) 2024 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": "libraryRuntimeOverlay", + "type": "shared", + "description": "$string:shared_desc", + "targetModuleName":"entry", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/element/color.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/element/string.json old mode 100755 new mode 100644 index 6175c8ac06a81be44a917fe60af4e712715309f3..999663191370eba1f0ce98b600336e16bbe83eaa --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/element/string.json +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "shared_desc", - "value": "description" - }, - { - "name": "test_string", - "value": "en_US_overlay_RUNTIME" - } - ] +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + }, + { + "name": "test_string", + "value": "en_US_overlay_RUNTIME" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/media/icon.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/media/setting.jpeg b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/media/setting.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/en_US/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/libraryRuntimeOverlay/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/oh-package.json5 b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/oh-package.json5 old mode 100755 new mode 100644 index 5092a626e51126911ca564a804eefcabe4583ad0..6faa9e99fcf33988268cb08b749a31f0a5f26043 --- a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "shortcut", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "shortcut", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/ohosTest.md b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/sceenshots/device/Scene-directory.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/sceenshots/device/Scene-directory.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/sceenshots/device/snapshot_directory.png b/code/BasicFeature/ApplicationModels/BundleManager/BundleManagement/sceenshots/device/snapshot_directory.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/app.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/app.json5 index 375c5a9b4b0aa4e25dab9f3cf874067afe9d74d6..615d9c69bc5e83bd8ad2e1bc82f91fb9a0e32c02 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/app.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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.navigation", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* +* Copyright (C) 2024 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.navigation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/resources/base/element/string.json b/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/resources/base/element/string.json index f2fd092934af1e589c8767bd12ee162272ac12e4..03ada0a8e4aaf97e7e46249cd02c9bc407d865fe 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "Navigation" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "Navigation" + } + ] +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/README_zh.md b/code/BasicFeature/ApplicationModels/DynamicRouter/README_zh.md index e149ceff523a61be6abf51de6501c4aa86a47f9a..2e2b728c43a9c7fe186649368426b6aabeba380b 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/README_zh.md +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/README_zh.md @@ -1,86 +1,86 @@ -# Navigation动态路由 - -### 介绍 - -本项目提供动态路由的验证,运用了WrapperBuilder的自定义函数打包能力,以及动态路由的跨模块文件引用的能力,解除了har包和hap包的依赖关系,实现了 -即使hap包不引用har包,依然能跳转到har包中的页面的能力 -目前还不支持动态import变量表达式和跨模块相对路径的文件,所以代码中使用switch作为替代,若后续版本支持,会出相应的补丁 -由于环境的差异,不建议下载后直接编译,应先当创建项目,参考示例代码进行编写 - -### 效果预览 -![image](images/Index.jpg) -![image](images/HarA.jpg) -![image](images/HarB.jpg) - -使用说明 - -1. 主页会提供一个NavIndex的导航页,点击按钮会跳转到不同的来自har包的页面 - -2. 每个har包的页面也存在跳转到别的页面的按钮 - -### 工程目录 - -``` -. -├── entry // 主页面 -│ ├── pages -│ │ ├── Index.ets -│ ├── entryability -│ │ ├── EntryAbility.ets -├── harA -│ ├── pages -│ │ ├── page1.ets -│ │ ├── page2.ets -│ │ ├── page3.ets -│ ├── entryability -│ │ ├── EntryAbility.ets -├── harB -│ ├── pages -│ │ ├── page1.ets -│ │ ├── page2.ets -│ │ ├── page3.ets -│ ├── entryability -│ │ ├── EntryAbility.ets -├── RouterModule -│ ├── utils -│ │ ├── RouterModule.ets -│ ├── entryability -│ │ ├── EntryAbility.ets -. -``` - -### 具体实现 - -1.创建hapA harA harB - -2.创建路由框架RouterModule,使用map存储hap包的路由和har包的页面信息 - -3.在RouterModule中封装get和set方法,并对外开放,允许外部模块引用和调用 - -4.创建push方法,允许传入一串url,并对其进行解析,通过拆解出路由名称从map中获取到路由栈,并将目标页面压栈 - -5.在hap和har包中引入RouterModule,将hap包的路由栈和har包的页面信息通过开放的set方法存入RouterModule - -### 相关权限 - -不涉及 - -### 约束与限制 - -1. 本示例仅支持标准系统上运行,支持设备:RK3568。 - -2. 本示例需要使用DevEco Studio 版本号(Build Version: 4.1.1.500, built on January 21, 2024)及以上版本才可编译运行。 - -3. 本示例为Stage模型,支持API11版本SDK,SDK版本号(4.1.6.3以上),镜像版本号(4.1.6.3以上)。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/ApplicationModels/DynamicRouter > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` +# Navigation动态路由 + +### 介绍 + +本项目提供动态路由的验证,运用了WrapperBuilder的自定义函数打包能力,以及动态路由的跨模块文件引用的能力,解除了har包和hap包的依赖关系,实现了 +即使hap包不引用har包,依然能跳转到har包中的页面的能力 +目前还不支持动态import变量表达式和跨模块相对路径的文件,所以代码中使用switch作为替代,若后续版本支持,会出相应的补丁 +由于环境的差异,不建议下载后直接编译,应先当创建项目,参考示例代码进行编写 + +### 效果预览 +![image](images/Index.jpg) +![image](images/HarA.jpg) +![image](images/HarB.jpg) + +使用说明 + +1. 主页会提供一个NavIndex的导航页,点击按钮会跳转到不同的来自har包的页面 + +2. 每个har包的页面也存在跳转到别的页面的按钮 + +### 工程目录 + +``` +. +├── entry // 主页面 +│ ├── pages +│ │ ├── Index.ets +│ ├── entryability +│ │ ├── EntryAbility.ets +├── harA +│ ├── pages +│ │ ├── page1.ets +│ │ ├── page2.ets +│ │ ├── page3.ets +│ ├── entryability +│ │ ├── EntryAbility.ets +├── harB +│ ├── pages +│ │ ├── page1.ets +│ │ ├── page2.ets +│ │ ├── page3.ets +│ ├── entryability +│ │ ├── EntryAbility.ets +├── RouterModule +│ ├── utils +│ │ ├── RouterModule.ets +│ ├── entryability +│ │ ├── EntryAbility.ets +. +``` + +### 具体实现 + +1.创建hapA harA harB + +2.创建路由框架RouterModule,使用map存储hap包的路由和har包的页面信息 + +3.在RouterModule中封装get和set方法,并对外开放,允许外部模块引用和调用 + +4.创建push方法,允许传入一串url,并对其进行解析,通过拆解出路由名称从map中获取到路由栈,并将目标页面压栈 + +5.在hap和har包中引入RouterModule,将hap包的路由栈和har包的页面信息通过开放的set方法存入RouterModule + +### 相关权限 + +不涉及 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 + +2. 本示例需要使用DevEco Studio 版本号(Build Version: 4.1.1.500, built on January 21, 2024)及以上版本才可编译运行。 + +3. 本示例为Stage模型,支持API11版本SDK,SDK版本号(4.1.6.3以上),镜像版本号(4.1.6.3以上)。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/ApplicationModels/DynamicRouter > .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/ApplicationModels/DynamicRouter/RouterModule/Index.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/Index.ets index f5920d2bb661095ed236416c4940d123b8fcd962..e1547ce35a4e8ca1e5529affeab25c557f69b9de 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/Index.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/Index.ets @@ -1,14 +1,14 @@ -/* -* Copyright (C) 2024 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. -*/ +/* +* Copyright (C) 2024 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. +*/ diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/build-profile.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/build-profile.json5 index ac6f2b3a182125d02ee6857a13d3954859665255..6a291812425481b231600ab8a2be2cbd37d333a0 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/build-profile.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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": { - }, - "targets": [ - { - "name": "default" - } - ] -} +/* +* Copyright (C) 2024 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": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/oh-package.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/oh-package.json5 index 1be403cb8b384ab001edf0714ac0003acd32a765..e71c1f8b1f29b1c2b1bd90cca7a8d9bca27ab789 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/oh-package.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "routermodule", - "description": "Please describe the basic information.", - "main": "Index.ets", - "version": "1.0.0", - "dependencies": {} -} +/* +* Copyright (C) 2024 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. +*/ +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "routermodule", + "description": "Please describe the basic information.", + "main": "Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/ets/utils/RouterModule.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/ets/utils/RouterModule.ets index a6c3b72b49670045c874b047c4b0d254978201d8..5c2269bf6346ed64d70da0fc7e9a49aaa74a2899 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/ets/utils/RouterModule.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/ets/utils/RouterModule.ets @@ -1,72 +1,72 @@ -/* -* Copyright (C) 2024 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 class RouterModule { - static builderMap: Map> = new Map>(); - static routerMap: Map = new Map(); - - // 通过名称注册builder - public static registerBuilder(builderName: string, builder: WrappedBuilder<[object]>): void{ - RouterModule.builderMap.set(builderName, builder); - } - - // 通过名称获取builder - public static getBuilder(builderName: string): WrappedBuilder<[object]>{ - let builder = RouterModule.builderMap.get(builderName); - return builder as WrappedBuilder<[object]>; - } - - // 通过名称注册router - public static createRouter(routerName: string, router: NavPathStack): void{ - RouterModule.routerMap.set(routerName, router); - } - - // 通过名称获取router - public static getRouter(routerName: string): NavPathStack{ - let router = RouterModule.routerMap.get(routerName); - return router as NavPathStack; - } - - // 通过获取页面栈跳转到指定页面 - public static async push(url: string): Promise{ - // 分解url - // 获取包名、路由名、页面名 - let params = url.split("/"); - const harName = params[0]; - let context = params[params.length - 1].split("-"); - const routerName = context[0]; - const builderName = context[1]; - // 获取路径 - let path = "."; - for (let i = 1; i < params.length - 1; i++) { - path += "/" + params[i]; - } - // 动态引入要跳转的页面 - let ns: ESObject = await import(harName); - ns.harInit(path); - RouterModule.getRouter(routerName).pushPathByName(builderName, null); - } - - // 通过获取页面栈并pop - public static pop(routerName: string): void { - // 查找到对应的路由栈进行pop - RouterModule.getRouter(routerName).pop(); - } - - // 通过获取页面栈并将其清空 - public static clear(routerName: string): void { - // 查找到对应的路由栈进行pop - RouterModule.getRouter(routerName).clear(); - } -} +/* +* Copyright (C) 2024 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 class RouterModule { + static builderMap: Map> = new Map>(); + static routerMap: Map = new Map(); + + // 通过名称注册builder + public static registerBuilder(builderName: string, builder: WrappedBuilder<[object]>): void{ + RouterModule.builderMap.set(builderName, builder); + } + + // 通过名称获取builder + public static getBuilder(builderName: string): WrappedBuilder<[object]>{ + let builder = RouterModule.builderMap.get(builderName); + return builder as WrappedBuilder<[object]>; + } + + // 通过名称注册router + public static createRouter(routerName: string, router: NavPathStack): void{ + RouterModule.routerMap.set(routerName, router); + } + + // 通过名称获取router + public static getRouter(routerName: string): NavPathStack{ + let router = RouterModule.routerMap.get(routerName); + return router as NavPathStack; + } + + // 通过获取页面栈跳转到指定页面 + public static async push(url: string): Promise{ + // 分解url + // 获取包名、路由名、页面名 + let params = url.split("/"); + const harName = params[0]; + let context = params[params.length - 1].split("-"); + const routerName = context[0]; + const builderName = context[1]; + // 获取路径 + let path = "."; + for (let i = 1; i < params.length - 1; i++) { + path += "/" + params[i]; + } + // 动态引入要跳转的页面 + let ns: ESObject = await import(harName); + ns.harInit(path); + RouterModule.getRouter(routerName).pushPathByName(builderName, null); + } + + // 通过获取页面栈并pop + public static pop(routerName: string): void { + // 查找到对应的路由栈进行pop + RouterModule.getRouter(routerName).pop(); + } + + // 通过获取页面栈并将其清空 + public static clear(routerName: string): void { + // 查找到对应的路由栈进行pop + RouterModule.getRouter(routerName).clear(); + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/module.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/module.json5 index 8d6911a8ce26188348e77371fc73ae7ee39ca78f..e72c17c68e850608af5b3fd46303c17ff21bd19d 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/RouterModule/src/main/module.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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": "RouterModule", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } +/* +* Copyright (C) 2024 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": "RouterModule", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/build-profile.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/build-profile.json5 index 774f06a9c7f48b5803feade5def0d8d06a0104c3..08a3adf541e9f79f99f6d0c162b30cb5f49b8ac7 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/build-profile.json5 @@ -1,53 +1,53 @@ -/* -* Copyright (C) 2024 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", - "runtimeOS": "OpenHarmony", - "compileSdkVersion": 11, - "compatibleSdkVersion": 11 - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "harA", - "srcPath": "./harA" - }, - { - "name": "harB", - "srcPath": "./harB" - }, - { - "name": "RouterModule", - "srcPath": "./RouterModule" - } - ] +/* +* Copyright (C) 2024 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", + "runtimeOS": "OpenHarmony", + "compileSdkVersion": 11, + "compatibleSdkVersion": 11 + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "harA", + "srcPath": "./harA" + }, + { + "name": "harB", + "srcPath": "./harB" + }, + { + "name": "RouterModule", + "srcPath": "./RouterModule" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/build-profile.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/build-profile.json5 index 8a11f781240548477f6af2699554a3f080d3138a..5afd0f621bd261dbad47f74479f98d1063cfc5cf 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/build-profile.json5 @@ -1,37 +1,37 @@ -/* -* Copyright (C) 2024 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": { - "arkOptions": { - "runtimeOnly": { - "sources": [ - ], - "packages": [ - "HarA", - "HarB" - ] - } - } - }, - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (C) 2024 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": { + "arkOptions": { + "runtimeOnly": { + "sources": [ + ], + "packages": [ + "HarA", + "HarB" + ] + } + } + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package-lock.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package-lock.json5 index 6262463277d0b0ac008930edec242f86180d204a..4413194cad1a21d3fb9b3ce8d88227844da7999d 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package-lock.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package-lock.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "HarB@../harB": "HarB@../harB", - "RouterModule@../RouterModule": "RouterModule@../RouterModule", - "HarA@../harA": "HarA@../harA" - }, - "packages": { - "HarB@../harB": { - "mtime": "1707210920658.4658", - "resolved": "../harB", - "dependencies": { - "RouterModule": "file:../RouterModule" - } - }, - "RouterModule@../RouterModule": { - "mtime": "1707210724992.75", - "resolved": "../RouterModule" - }, - "HarA@../harA": { - "mtime": "1707210916733.4844", - "resolved": "../harA", - "dependencies": { - "RouterModule": "file:../RouterModule" - } - } - } +/* +* Copyright (C) 2024 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. +*/ +{ + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "HarB@../harB": "HarB@../harB", + "RouterModule@../RouterModule": "RouterModule@../RouterModule", + "HarA@../harA": "HarA@../harA" + }, + "packages": { + "HarB@../harB": { + "mtime": "1707210920658.4658", + "resolved": "../harB", + "dependencies": { + "RouterModule": "file:../RouterModule" + } + }, + "RouterModule@../RouterModule": { + "mtime": "1707210724992.75", + "resolved": "../RouterModule" + }, + "HarA@../harA": { + "mtime": "1707210916733.4844", + "resolved": "../harA", + "dependencies": { + "RouterModule": "file:../RouterModule" + } + } + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package.json5 index 73a404a398a60d2b720b130a8de410007436038d..f95a2f9fba096ec94fb08cbd532feb34ff048d46 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/oh-package.json5 @@ -1,28 +1,28 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "RouterModule": "file:../RouterModule", - "HarA": "file:../harA", - "HarB": "file:../harB" - } -} +/* +* Copyright (C) 2024 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. +*/ +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "RouterModule": "file:../RouterModule", + "HarA": "file:../harA", + "HarB": "file:../harB" + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/ets/entryability/EntryAbility.ts index 42252a5bd21b40fcb14f7df4c558815b2e9402e2..0037532ae8024301130767e18d7517fbfe970f67 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,57 +1,57 @@ -/* -* Copyright (C) 2024 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -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, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - 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'); - } -} +/* +* Copyright (C) 2024 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +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, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + 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/ApplicationModels/DynamicRouter/entry/src/main/module.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/module.json5 index 89ec46f0396c816c680631e7e517e4bc311e99af..11e428235ec35a98e7c0a5a25f89e5165ab2448a 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -/* -* Copyright (C) 2024 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* +* Copyright (C) 2024 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/resources/base/element/color.json b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/ohosTest/module.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/ohosTest/module.json5 index 7c9a2ac3fb02ac14c1a58fbd6e231cc1621b11fd..4a6cc8c2ccb76abaaca6a9ed7908623ca9b2fc67 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* -* Copyright (C) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* +* Copyright (C) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/Index.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/Index.ets index b739b34f383cbe6fcb9745c0e25d155021e9d7d9..e68e860c43a562a96f60d07676aca24c431acf5b 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/Index.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/Index.ets @@ -1,30 +1,30 @@ -/* -* Copyright (C) 2024 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 function harInit(path: string): void{ - // 动态引入要跳转的页面 - switch (path) { - case "./src/main/ets/components/mainpage/page1": - import("./src/main/ets/components/mainpage/page1"); - break; - case "./src/main/ets/components/mainpage/page2": - import("./src/main/ets/components/mainpage/page2"); - break; - case "./src/main/ets/components/mainpage/page3": - import("./src/main/ets/components/mainpage/page3"); - break; - default: - break; - } -} +/* +* Copyright (C) 2024 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 function harInit(path: string): void{ + // 动态引入要跳转的页面 + switch (path) { + case "./src/main/ets/components/mainpage/page1": + import("./src/main/ets/components/mainpage/page1"); + break; + case "./src/main/ets/components/mainpage/page2": + import("./src/main/ets/components/mainpage/page2"); + break; + case "./src/main/ets/components/mainpage/page3": + import("./src/main/ets/components/mainpage/page3"); + break; + default: + break; + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/build-profile.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/build-profile.json5 index ac6f2b3a182125d02ee6857a13d3954859665255..6a291812425481b231600ab8a2be2cbd37d333a0 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/build-profile.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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": { - }, - "targets": [ - { - "name": "default" - } - ] -} +/* +* Copyright (C) 2024 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": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package-lock.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package-lock.json5 index 595baf01e17b56a3be982a651d9532cc4bdfe8d0..4d162199c600fe61542078e84876d46d3f7b6fe4 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package-lock.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package-lock.json5 @@ -1,27 +1,27 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "RouterModule@../RouterModule": "RouterModule@../RouterModule" - }, - "packages": { - "RouterModule@../RouterModule": { - "mtime": "1707210724992.75", - "resolved": "../RouterModule" - } - } +/* +* Copyright (C) 2024 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. +*/ +{ + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "RouterModule@../RouterModule": "RouterModule@../RouterModule" + }, + "packages": { + "RouterModule@../RouterModule": { + "mtime": "1707210724992.75", + "resolved": "../RouterModule" + } + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package.json5 index 84ed860c140fd455bc3d3ed19bbe4f84d9d3518f..2f818abe093b750be4d97bde8dc1bd8125cffc90 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/oh-package.json5 @@ -1,26 +1,26 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "hara", - "description": "Please describe the basic information.", - "main": "Index.ets", - "version": "1.0.0", - "dependencies": { - "RouterModule": "file:../RouterModule" - } -} +/* +* Copyright (C) 2024 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. +*/ +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "hara", + "description": "Please describe the basic information.", + "main": "Index.ets", + "version": "1.0.0", + "dependencies": { + "RouterModule": "file:../RouterModule" + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page1.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page1.ets index 2ceb4ad898fddf6d1632fa3f80b3b8171ab4637e..8b117082b476ed45903ffcfed317486e8b6f0579 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page1.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page1.ets @@ -1,65 +1,65 @@ -/* -* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; - -@Builder -export function harBuilder(value: object) { - NavDestination(){ - Column(){ - Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let routerName = "HapA_Router"; - RouterModule.clear(routerName); - }) - Button($r("app.string.to_harb_page1"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page1/HapA_Router-HarB_Page1_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_harb_page2"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page2/HapA_Router-HarB_Page2_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_harb_page3"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page3/HapA_Router-HarB_Page3_Builder"; - RouterModule.push(url); - }) - }.width('100%').height('100%') - }.title('HarA_Page1') - .onBackPressed(() => { - RouterModule.pop("HapA_Router"); - return true; - }) -} - -let builderName = 'HarA_Page1_Builder'; -if (!RouterModule.getBuilder(builderName)) { - let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); - RouterModule.registerBuilder(builderName, builder); -} +/* +* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; + +@Builder +export function harBuilder(value: object) { + NavDestination(){ + Column(){ + Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let routerName = "HapA_Router"; + RouterModule.clear(routerName); + }) + Button($r("app.string.to_harb_page1"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page1/HapA_Router-HarB_Page1_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_harb_page2"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page2/HapA_Router-HarB_Page2_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_harb_page3"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page3/HapA_Router-HarB_Page3_Builder"; + RouterModule.push(url); + }) + }.width('100%').height('100%') + }.title('HarA_Page1') + .onBackPressed(() => { + RouterModule.pop("HapA_Router"); + return true; + }) +} + +let builderName = 'HarA_Page1_Builder'; +if (!RouterModule.getBuilder(builderName)) { + let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); + RouterModule.registerBuilder(builderName, builder); +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page2.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page2.ets index 30ab96b16172cc61e2a2374c13b42168b7b5cddc..047e4ba416b1feec0738b2f644629bb873824e47 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page2.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page2.ets @@ -1,65 +1,65 @@ -/* -* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; - -@Builder -export function harBuilder(value: object) { - NavDestination(){ - Column(){ - Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let routerName = "HapA_Router"; - RouterModule.clear(routerName); - }) - Button($r("app.string.to_harb_page1"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page1/HapA_Router-HarB_Page1_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_harb_page2"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page2/HapA_Router-HarB_Page2_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_harb_page3"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page3/HapA_Router-HarB_Page3_Builder"; - RouterModule.push(url); - }) - }.width('100%').height('100%') - }.title('HarA_Page2') - .onBackPressed(() => { - RouterModule.pop("HapA_Router"); - return true; - }) -} - -let builderName = 'HarA_Page2_Builder'; -if (!RouterModule.getBuilder(builderName)) { - let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); - RouterModule.registerBuilder(builderName, builder); +/* +* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; + +@Builder +export function harBuilder(value: object) { + NavDestination(){ + Column(){ + Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let routerName = "HapA_Router"; + RouterModule.clear(routerName); + }) + Button($r("app.string.to_harb_page1"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page1/HapA_Router-HarB_Page1_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_harb_page2"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page2/HapA_Router-HarB_Page2_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_harb_page3"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page3/HapA_Router-HarB_Page3_Builder"; + RouterModule.push(url); + }) + }.width('100%').height('100%') + }.title('HarA_Page2') + .onBackPressed(() => { + RouterModule.pop("HapA_Router"); + return true; + }) +} + +let builderName = 'HarA_Page2_Builder'; +if (!RouterModule.getBuilder(builderName)) { + let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); + RouterModule.registerBuilder(builderName, builder); } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page3.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page3.ets index 2fbd970720bfe029a18aa796f8a4da9a29a4ce38..eb1adce692cafe72cab74f01fa1b14042edbe611 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page3.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/ets/components/mainpage/page3.ets @@ -1,65 +1,65 @@ -/* -* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; - -@Builder -export function harBuilder(value: object) { - NavDestination(){ - Column(){ - Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let routerName = "HapA_Router"; - RouterModule.clear(routerName); - }) - Button($r("app.string.to_harb_page1"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page1/HapA_Router-HarB_Page1_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_harb_page2"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page2/HapA_Router-HarB_Page2_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_harb_page3"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarB/src/main/ets/components/mainpage/page3/HapA_Router-HarB_Page3_Builder"; - RouterModule.push(url); - }) - }.width('100%').height('100%') - }.title('HarA_Page3') - .onBackPressed(() => { - RouterModule.pop("HapA_Router"); - return true; - }) -} - -let builderName = 'HarA_Page3_Builder'; -if (!RouterModule.getBuilder(builderName)) { - let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); - RouterModule.registerBuilder(builderName, builder); +/* +* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; + +@Builder +export function harBuilder(value: object) { + NavDestination(){ + Column(){ + Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let routerName = "HapA_Router"; + RouterModule.clear(routerName); + }) + Button($r("app.string.to_harb_page1"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page1/HapA_Router-HarB_Page1_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_harb_page2"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page2/HapA_Router-HarB_Page2_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_harb_page3"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarB/src/main/ets/components/mainpage/page3/HapA_Router-HarB_Page3_Builder"; + RouterModule.push(url); + }) + }.width('100%').height('100%') + }.title('HarA_Page3') + .onBackPressed(() => { + RouterModule.pop("HapA_Router"); + return true; + }) +} + +let builderName = 'HarA_Page3_Builder'; +if (!RouterModule.getBuilder(builderName)) { + let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); + RouterModule.registerBuilder(builderName, builder); } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/module.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/module.json5 index a0c6877ad90c19e1cdad51929647b38bddc98046..5d4200318679b26de5a82c5545f4dd6cb469a7e3 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harA/src/main/module.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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": "harA", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} +/* +* Copyright (C) 2024 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": "harA", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/Index.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/Index.ets index b739b34f383cbe6fcb9745c0e25d155021e9d7d9..e68e860c43a562a96f60d07676aca24c431acf5b 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/Index.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/Index.ets @@ -1,30 +1,30 @@ -/* -* Copyright (C) 2024 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 function harInit(path: string): void{ - // 动态引入要跳转的页面 - switch (path) { - case "./src/main/ets/components/mainpage/page1": - import("./src/main/ets/components/mainpage/page1"); - break; - case "./src/main/ets/components/mainpage/page2": - import("./src/main/ets/components/mainpage/page2"); - break; - case "./src/main/ets/components/mainpage/page3": - import("./src/main/ets/components/mainpage/page3"); - break; - default: - break; - } -} +/* +* Copyright (C) 2024 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 function harInit(path: string): void{ + // 动态引入要跳转的页面 + switch (path) { + case "./src/main/ets/components/mainpage/page1": + import("./src/main/ets/components/mainpage/page1"); + break; + case "./src/main/ets/components/mainpage/page2": + import("./src/main/ets/components/mainpage/page2"); + break; + case "./src/main/ets/components/mainpage/page3": + import("./src/main/ets/components/mainpage/page3"); + break; + default: + break; + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/build-profile.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/build-profile.json5 index 2783f9a949c5ed6037669e607c3356d682d4566f..c776629856763c44cb9db724bdfea7e24d46bdc0 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/build-profile.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/build-profile.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (C) 2024 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": { - }, - "targets": [ - { - "name": "default" - } - ] -} +/* +* Copyright (C) 2024 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": { + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package-lock.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package-lock.json5 index 595baf01e17b56a3be982a651d9532cc4bdfe8d0..4d162199c600fe61542078e84876d46d3f7b6fe4 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package-lock.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package-lock.json5 @@ -1,27 +1,27 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "RouterModule@../RouterModule": "RouterModule@../RouterModule" - }, - "packages": { - "RouterModule@../RouterModule": { - "mtime": "1707210724992.75", - "resolved": "../RouterModule" - } - } +/* +* Copyright (C) 2024 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. +*/ +{ + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "RouterModule@../RouterModule": "RouterModule@../RouterModule" + }, + "packages": { + "RouterModule@../RouterModule": { + "mtime": "1707210724992.75", + "resolved": "../RouterModule" + } + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package.json5 index 489a3704df4abeaabf91ba20c68244e3e09dbdaa..584b7808d56340d46a69faba09d5ef65794ef232 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/oh-package.json5 @@ -1,26 +1,26 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "harb", - "description": "Please describe the basic information.", - "main": "Index.ets", - "version": "1.0.0", - "dependencies": { - "RouterModule": "file:../RouterModule" - } -} +/* +* Copyright (C) 2024 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. +*/ +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "harb", + "description": "Please describe the basic information.", + "main": "Index.ets", + "version": "1.0.0", + "dependencies": { + "RouterModule": "file:../RouterModule" + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page1.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page1.ets index 8f9752914dae5c5d7ce781b24740461e2d47322f..b0f04cedae21ee3efa9e7cf031b0a2729c98f36e 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page1.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page1.ets @@ -1,65 +1,65 @@ -/* -* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; - -@Builder -export function harBuilder(value: object) { - NavDestination(){ - Column(){ - Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let routerName = "HapA_Router"; - RouterModule.clear(routerName); - }) - Button($r("app.string.to_hara_page1"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page1/HapA_Router-HarA_Page1_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_hara_page2"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page2/HapA_Router-HarA_Page2_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_hara_page3"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page3/HapA_Router-HarA_Page3_Builder"; - RouterModule.push(url); - }) - }.width('100%').height('100%') - }.title('HarB_Page1') - .onBackPressed(() => { - RouterModule.pop("HapA_Router"); - return true; - }) -} - -let builderName = 'HarB_Page1_Builder'; -if (!RouterModule.getBuilder(builderName)) { - let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); - RouterModule.registerBuilder(builderName, builder); -} +/* +* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; + +@Builder +export function harBuilder(value: object) { + NavDestination(){ + Column(){ + Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let routerName = "HapA_Router"; + RouterModule.clear(routerName); + }) + Button($r("app.string.to_hara_page1"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page1/HapA_Router-HarA_Page1_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_hara_page2"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page2/HapA_Router-HarA_Page2_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_hara_page3"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page3/HapA_Router-HarA_Page3_Builder"; + RouterModule.push(url); + }) + }.width('100%').height('100%') + }.title('HarB_Page1') + .onBackPressed(() => { + RouterModule.pop("HapA_Router"); + return true; + }) +} + +let builderName = 'HarB_Page1_Builder'; +if (!RouterModule.getBuilder(builderName)) { + let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); + RouterModule.registerBuilder(builderName, builder); +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page2.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page2.ets index 6ff8d325a646dd11c46f21e90b5c730a2c85e488..6fef357292f71f7350fd4bbd032653d89bc194db 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page2.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page2.ets @@ -1,65 +1,65 @@ -/* -* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; - -@Builder -export function harBuilder(value: object) { - NavDestination(){ - Column(){ - Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let routerName = "HapA_Router"; - RouterModule.clear(routerName); - }) - Button($r("app.string.to_hara_page1"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page1/HapA_Router-HarA_Page1_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_hara_page2"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page2/HapA_Router-HarA_Page2_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_hara_page3"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page3/HapA_Router-HarA_Page3_Builder"; - RouterModule.push(url); - }) - }.width('100%').height('100%') - }.title('HarB_Page2') - .onBackPressed(() => { - RouterModule.pop("HapA_Router"); - return true; - }) -} - -let builderName = 'HarB_Page2_Builder'; -if (!RouterModule.getBuilder(builderName)) { - let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); - RouterModule.registerBuilder(builderName, builder); -} +/* +* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; + +@Builder +export function harBuilder(value: object) { + NavDestination(){ + Column(){ + Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let routerName = "HapA_Router"; + RouterModule.clear(routerName); + }) + Button($r("app.string.to_hara_page1"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page1/HapA_Router-HarA_Page1_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_hara_page2"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page2/HapA_Router-HarA_Page2_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_hara_page3"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page3/HapA_Router-HarA_Page3_Builder"; + RouterModule.push(url); + }) + }.width('100%').height('100%') + }.title('HarB_Page2') + .onBackPressed(() => { + RouterModule.pop("HapA_Router"); + return true; + }) +} + +let builderName = 'HarB_Page2_Builder'; +if (!RouterModule.getBuilder(builderName)) { + let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); + RouterModule.registerBuilder(builderName, builder); +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page3.ets b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page3.ets index a8f0b9e4ff39d17c8a828a28f4f2705b06573f5b..b4922252f889c5744d3996d623b718071536e7e5 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page3.ets +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/ets/components/mainpage/page3.ets @@ -1,65 +1,65 @@ -/* -* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; - -@Builder -export function harBuilder(value: object) { - NavDestination(){ - Column(){ - Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let routerName = "HapA_Router"; - RouterModule.clear(routerName); - }) - Button($r("app.string.to_hara_page1"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page1/HapA_Router-HarA_Page1_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_hara_page2"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page2/HapA_Router-HarA_Page2_Builder"; - RouterModule.push(url); - }) - Button($r("app.string.to_hara_page3"), { stateEffect: true, type: ButtonType.Capsule }) - .width('80%') - .height(40) - .margin(20) - .onClick(() => { - let url = "HarA/src/main/ets/components/mainpage/page3/HapA_Router-HarA_Page3_Builder"; - RouterModule.push(url); - }) - }.width('100%').height('100%') - }.title('HarB_Page3') - .onBackPressed(() => { - RouterModule.pop("HapA_Router"); - return true; - }) -} - -let builderName = 'HarB_Page3_Builder'; -if (!RouterModule.getBuilder(builderName)) { - let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); - RouterModule.registerBuilder(builderName, builder); -} +/* +* Copyright (C) 2024 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 { RouterModule } from "RouterModule/src/main/ets/utils/RouterModule"; + +@Builder +export function harBuilder(value: object) { + NavDestination(){ + Column(){ + Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let routerName = "HapA_Router"; + RouterModule.clear(routerName); + }) + Button($r("app.string.to_hara_page1"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page1/HapA_Router-HarA_Page1_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_hara_page2"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page2/HapA_Router-HarA_Page2_Builder"; + RouterModule.push(url); + }) + Button($r("app.string.to_hara_page3"), { stateEffect: true, type: ButtonType.Capsule }) + .width('80%') + .height(40) + .margin(20) + .onClick(() => { + let url = "HarA/src/main/ets/components/mainpage/page3/HapA_Router-HarA_Page3_Builder"; + RouterModule.push(url); + }) + }.width('100%').height('100%') + }.title('HarB_Page3') + .onBackPressed(() => { + RouterModule.pop("HapA_Router"); + return true; + }) +} + +let builderName = 'HarB_Page3_Builder'; +if (!RouterModule.getBuilder(builderName)) { + let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder); + RouterModule.registerBuilder(builderName, builder); +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/module.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/module.json5 index 51a6edaffbf91b53b8a8017944112c4d0063a942..a052108752cb82eb1b034a4f1966ad50756c7667 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/module.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/harB/src/main/module.json5 @@ -1,24 +1,24 @@ -/* -* Copyright (C) 2024 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": "harB", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} +/* +* Copyright (C) 2024 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": "harB", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/hvigor/hvigor-config.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/hvigor/hvigor-config.json5 index e1b617db91f338598ae6d118b6866a33cba4042d..0b5647c97e634a2746cae72de8f7b6a26692fd87 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/oh-package.json5 b/code/BasicFeature/ApplicationModels/DynamicRouter/oh-package.json5 index dce34f96c0f184c1a1c138b7896f7b17e431475a..41f1d62f0d4e2cb0c13d60e57d515a8d51c886d6 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/oh-package.json5 +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/oh-package.json5 @@ -1,26 +1,26 @@ -/* -* Copyright (C) 2024 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. -*/ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myapplication", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* +* Copyright (C) 2024 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. +*/ +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "myapplication", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/ApplicationModels/DynamicRouter/ohosTest.md b/code/BasicFeature/ApplicationModels/DynamicRouter/ohosTest.md index 74fe3b6ece37080728c3f5c036e8d421f4f5e2c6..8d459c87e35aaaf95672e3011763c426ff8aad85 100644 --- a/code/BasicFeature/ApplicationModels/DynamicRouter/ohosTest.md +++ b/code/BasicFeature/ApplicationModels/DynamicRouter/ohosTest.md @@ -1,10 +1,10 @@ -# FileManager 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 |是否自动|测试结果| -|----------------|----------|-----------|--------------|--------------------------------|--------------------------------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 |是|Pass| -| 从首页跳转到harA页面 | 进入首页 | 点击ToHarA | 成功跳转到harA页面 |是|Pass| -| 从harA跳转到harB页面 | 进入HarA页面 | 点击ToHarB | 成功跳转跳转到harB页面 |是|Pass| +# FileManager 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 |是否自动|测试结果| +|----------------|----------|-----------|--------------|--------------------------------|--------------------------------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 |是|Pass| +| 从首页跳转到harA页面 | 进入首页 | 点击ToHarA | 成功跳转到harA页面 |是|Pass| +| 从harA跳转到harB页面 | 进入HarA页面 | 点击ToHarB | 成功跳转跳转到harB页面 |是|Pass| | 从harB跳转到首页 | 进入HarB页面 | 点击ToIndex | 成功跳转到首页 |是|Pass| \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/app.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/app.json5 index 7422edb8a7cae8445cc8df0b5551e92be3cea203..f8349cd66b3ccf7b539c3c52eb1bfc7701fcec61 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/app.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * 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.multiplefilesdownload", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.multiplefilesdownload", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/resources/base/element/string.json b/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/resources/base/element/string.json index f5b165b8435a9f736e04891cf68477b44f7d5eec..35ce4d49ab8cd241f966b9b9e3e8a805e34f6435 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MultipleFilesDownload" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MultipleFilesDownload" + } + ] +} diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/README.md b/code/BasicFeature/Connectivity/MultipleFilesDownload/README.md index b75f037faf819330f7aaab4be3bd379bad2e7c54..281c945193cb5e1b7dbc5822e0492d3b83d87481 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/README.md +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/README.md @@ -1,201 +1,201 @@ - - -# 多文件下载监听案例 - -### 介绍 - -多文件下载监听在应用开发中是一个非常常见的需求。本示例将介绍如何使用request上传下载模块实现多文件下载监听,如监听每个文件下载任务的进度,任务暂停,下载完成等下载情况。下载历史页面展示的是下载完成的文件,可对页面中已删除的文件进行重新下载 。每个应用至多支持创建10个未完成的任务,相关规格说明请参考[request.agent.create](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md#requestagentcreate10)。 - -### 效果图预览 - -![](./casesfeature/multiplefilesdownload/multiple_files_download.gif) - -**使用说明** - -1. 连接网络。进入页面,点击“全部开始”,启动所有文件的下载任务。点击“全部暂停”,暂停所有文件下载任务。再次点击“全部开始”,可重新启动未完成的下载任务。如出现下载失败,一般是网络不稳定,点击“全部开始”即可重新下载。 -2. 下载完成的文件会保存在应用缓存路径下,出现在下载历史页面中。 -3. 可点击删除按钮,在应用缓存路径下删除该文件存储的数据。 -4. 点击文件,若文件中在应用缓存路径下存在,弹窗提示用户“文件已存在”;否则弹窗提示用户“文件不存在,是否重新下载?”,点击确认按钮,该条文件数据会出现在下载列表中,可点击“全部开始“按钮重新下载。 - -### 实现思路 - -1. 配置下载参数。一个下载任务需要配置对应一套下载参数request.agent.Config。本例中使用downloadConfig方法简单配置了下载文件的url,实际业务中请按实际情况按需配置。源码参考[MultipleFilesDownload.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/MultipleFilesDownload.ets)。 - - ```typescript - let config: request.agent.Config = { - action: request.agent.Action.DOWNLOAD, // 配置任务选项,这里配置为下载任务 - url: downloadUrl, // 配置下载任务url - overwrite: true, // 下载过程中路径已存在时的解决方案选择。true表示覆盖已存在的文件 - method: 'GET', // HTTP标准方法。下载时,使用GET或POST。 - saveas: './', // 这里'./'表示下载至应用当前缓存路径下。 - mode: request.agent.Mode.BACKGROUND, // 任务模式设置后台任务。 - gauge: true // 后台任务的过程进度通知策略,仅应用于后台任务。true表示发出每个进度已完成或失败的通知。 - }; - ``` - -2. 创建多个文件下载监听实例。单个文件下载监听只需要配置下载参数,创建下载任务,注册下载任务相关监听,启动下载任务即可实现。而要实现多文件下载监听,需要每个下载任务注册独立的下载监听回调。本例通过封装自定义组件FileDownloadItem,在每个FileDownloadItem中创建各自的下载任务和监听回调,从而实现多文件下载监听。源码参考[MultipleFilesDownload.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/MultipleFilesDownload.ets)。 - - ```typescript - ForEach(this.downloadConfigArray, (item: request.agent.Config) => { - ListItem() { - // 创建文件下载监听实例 - FileDownloadItem({ - downloadConfig: item, // 文件下载配置 - isStartAllDownload: this.isStartAllDownload, // 是否全部开始下载 - downloadCount: this.downloadCount // 待下载任务数量 - downloadFailCount: this.downloadFailCount // 下载失败任务数量 - }) - } - }, (item: request.agent.Config) => JSON.stringify(item)) - ``` - -3. 创建下载任务,并注册下载任务相关监听。本例在每个FileDownloadItem中使用request.agent.create创建下载任务。然后在下载任务创建成功后,注册各自下载任务相关监听。本例中注册了下载任务完成回调,下载任务失败回调,下载进度更新回调,暂停任务回调,重新启动任务回调。源码参考[FileDownloadItem.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/FileDownloadItem.ets)。 - - ```typescript - request.agent.create(context, this.downloadConfig).then((task: request.agent.Task) => { - // 注册下载任务相关回调 - task.on('completed', this.completedCallback); // 下载任务完成回调 - task.on('failed', this.failedCallback); // 下载任务失败回调 - task.on('pause', this.pauseCallback); // 暂停任务回调 - task.on('resume', this.resumeCallback); // 重新启动任务回调 - task.on('progress', this.progressCallback); // 下载进度更新回调 - }).catch((err: BusinessError) => { - logger.error(TAG, `Failed to task create with error message: ${err.message}, error code: ${err.code}`); - }); - ``` - -4. 启动下载任务。本例在每个FileDownloadItem中使用task.start方法启动各自的下载任务。源码参考[FileDownloadItem.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/FileDownloadItem.ets)。 - - ```typescript - task.start((err: BusinessError) => { - if (err) { - logger.error(TAG, `Failed to task start with error message: ${err.message}, error code: ${err.code}`); - return; - } - this.downloadTask = task; - }) - ``` - -5. 删除文件。使用fs.unlink删除该条数据应用文件路径 - - ```typescript - // TODO:知识点:删除该条数据应用文件路径 - fs.unlink(filePath).then(() => { - // 文件状态变为已删除 - this.FileInfo.fileStatus = 3; - promptAction.showToast({ - message: $r('app.string.multiple_files_download_history_toast_text_del'), - duration: 2000, - bottom: '50%', - }) - }).catch((error: BusinessError) => { - logger.error("remove file failed with error:" + error); - }); - ``` - -6. 重新下载已删除的文件。使用fs.access判断文件是否已经存在,若不存在弹窗提示用户是否重新下载。 - - ```typescript - // 获取应用文件路径 - const cacheDir = context.cacheDir; - const FilePath: string = `${cacheDir}/${this.fileName}`; - - // TODO:知识点:使用fs.access判断目录是否已经存在。 - fs.access(FilePath).then((res: boolean) => { - if (!res) { - // 文件已删除,弹窗提示是否重新下载 - AlertDialog.show({ - message: `${this.fileName}文件不存在,是否重新下载?`, - alignment: DialogAlignment.Center, // 弹窗在竖直方向上的对齐方式。 - autoCancel: false, // 点击遮罩层时,是否关闭弹窗。默认值:true - primaryButton: { - value: $r('app.string.multiple_files_download_history_button_text_cancel'), - fontColor: $r('app.color.multiple_files_download_text_color'), - action: () => { - logger.info('已取消'); - } - }, - secondaryButton: { - value: $r('app.string.multiple_files_download_history_button_text_confirm'), - fontColor: $r('app.color.multiple_files_download_del_bgc'), - action: () => { - // 更改该条数据下载状态 - this.FileInfo.fileStatus = 0; - // 该条数据加入下载列表数组中 - this.downloadFileArray.push(this.FileInfo); - // 下载历史列表删除该条数据 - this.historyArray = this.historyArray.filter( ( item: downloadFilesData ) => { - return item.id !== this.FileInfo.id; - }); - // 更新待下载任务数量 - this.downloadCount = this.downloadFileArray.length; - } - }, - cornerRadius: $r('app.integer.multiple_files_download_borderRadius_twelve'), // 弹窗边框弧度 - width: $r('app.string.multiple_files_download_list_height'), // 弹窗宽度 - cancel: () => { - logger.info('点击关闭按钮'); - } - }); - } else { - // 文件已下载到本地,弹窗提示文件已存在 - promptAction.showToast({ - message: $r('app.string.multiple_files_download_history_toast_text_exist'), - duration: 1000, - bottom: '50%', - }) - } - ``` - -### 高性能知识点 - -本示例中注册了progress下载进度更新监听,不建议在下载进度更新回调中加日志打印,以减少不必要的性能损耗。 - -### FAQ - -1. 无网络时,点击”全部开始“,下载队列中的任务状态却显示”已暂停“。 - - 答:request.agent.Config有一个参数retry默认是true,如果没有网络或者网络不满足时,会自动暂停waiting,所以在没网络的时候下载底层逻辑会走暂停回调,应用侧在暂停回调里设置了显示当前下载状态,所以无网络时,点击”全部开始“,下载队列中的任务状态显示”已暂停“。目前本例中已经把retry设置为false,没网络时,开启下载任务会直接走入失败回调,直接显示”下载失败“。 - -### 工程结构&模块类型 - - ``` - multiplefilesdownload // har类型 - |---view - | |---MultipleFilesDownload.ets // 视图层-文件下载页面 - | |---FileDownloadItem.ets // 视图层-单个文件下载组件 - | |---HistoryItem.ets // 视图层-单个文件历史组件 - ``` - -### 参考资料 - -[上传下载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md) - -### 相关权限 - -| 权限名 | 权限说明 | 级别 | -| ------------------------ | -------------------- | ------ | -| ohos.permission.INTERNET | 允许使用Interent网络 | normal | - -### 依赖 - -不涉及。 -### 约束与限制 - -1.本示例仅支持标准系统上运行。 - -2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12 Release)。 - -3.本示例需要使用DevEco Studio版本号(DevEco Studio 5.0.0 Release)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```shell -git init -git config core.sparsecheckout true -echo code/BasicFeature/Connectivity/MultipleFilesDownload > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master + + +# 多文件下载监听案例 + +### 介绍 + +多文件下载监听在应用开发中是一个非常常见的需求。本示例将介绍如何使用request上传下载模块实现多文件下载监听,如监听每个文件下载任务的进度,任务暂停,下载完成等下载情况。下载历史页面展示的是下载完成的文件,可对页面中已删除的文件进行重新下载 。每个应用至多支持创建10个未完成的任务,相关规格说明请参考[request.agent.create](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md#requestagentcreate10)。 + +### 效果图预览 + +![](./casesfeature/multiplefilesdownload/multiple_files_download.gif) + +**使用说明** + +1. 连接网络。进入页面,点击“全部开始”,启动所有文件的下载任务。点击“全部暂停”,暂停所有文件下载任务。再次点击“全部开始”,可重新启动未完成的下载任务。如出现下载失败,一般是网络不稳定,点击“全部开始”即可重新下载。 +2. 下载完成的文件会保存在应用缓存路径下,出现在下载历史页面中。 +3. 可点击删除按钮,在应用缓存路径下删除该文件存储的数据。 +4. 点击文件,若文件中在应用缓存路径下存在,弹窗提示用户“文件已存在”;否则弹窗提示用户“文件不存在,是否重新下载?”,点击确认按钮,该条文件数据会出现在下载列表中,可点击“全部开始“按钮重新下载。 + +### 实现思路 + +1. 配置下载参数。一个下载任务需要配置对应一套下载参数request.agent.Config。本例中使用downloadConfig方法简单配置了下载文件的url,实际业务中请按实际情况按需配置。源码参考[MultipleFilesDownload.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/MultipleFilesDownload.ets)。 + + ```typescript + let config: request.agent.Config = { + action: request.agent.Action.DOWNLOAD, // 配置任务选项,这里配置为下载任务 + url: downloadUrl, // 配置下载任务url + overwrite: true, // 下载过程中路径已存在时的解决方案选择。true表示覆盖已存在的文件 + method: 'GET', // HTTP标准方法。下载时,使用GET或POST。 + saveas: './', // 这里'./'表示下载至应用当前缓存路径下。 + mode: request.agent.Mode.BACKGROUND, // 任务模式设置后台任务。 + gauge: true // 后台任务的过程进度通知策略,仅应用于后台任务。true表示发出每个进度已完成或失败的通知。 + }; + ``` + +2. 创建多个文件下载监听实例。单个文件下载监听只需要配置下载参数,创建下载任务,注册下载任务相关监听,启动下载任务即可实现。而要实现多文件下载监听,需要每个下载任务注册独立的下载监听回调。本例通过封装自定义组件FileDownloadItem,在每个FileDownloadItem中创建各自的下载任务和监听回调,从而实现多文件下载监听。源码参考[MultipleFilesDownload.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/MultipleFilesDownload.ets)。 + + ```typescript + ForEach(this.downloadConfigArray, (item: request.agent.Config) => { + ListItem() { + // 创建文件下载监听实例 + FileDownloadItem({ + downloadConfig: item, // 文件下载配置 + isStartAllDownload: this.isStartAllDownload, // 是否全部开始下载 + downloadCount: this.downloadCount // 待下载任务数量 + downloadFailCount: this.downloadFailCount // 下载失败任务数量 + }) + } + }, (item: request.agent.Config) => JSON.stringify(item)) + ``` + +3. 创建下载任务,并注册下载任务相关监听。本例在每个FileDownloadItem中使用request.agent.create创建下载任务。然后在下载任务创建成功后,注册各自下载任务相关监听。本例中注册了下载任务完成回调,下载任务失败回调,下载进度更新回调,暂停任务回调,重新启动任务回调。源码参考[FileDownloadItem.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/FileDownloadItem.ets)。 + + ```typescript + request.agent.create(context, this.downloadConfig).then((task: request.agent.Task) => { + // 注册下载任务相关回调 + task.on('completed', this.completedCallback); // 下载任务完成回调 + task.on('failed', this.failedCallback); // 下载任务失败回调 + task.on('pause', this.pauseCallback); // 暂停任务回调 + task.on('resume', this.resumeCallback); // 重新启动任务回调 + task.on('progress', this.progressCallback); // 下载进度更新回调 + }).catch((err: BusinessError) => { + logger.error(TAG, `Failed to task create with error message: ${err.message}, error code: ${err.code}`); + }); + ``` + +4. 启动下载任务。本例在每个FileDownloadItem中使用task.start方法启动各自的下载任务。源码参考[FileDownloadItem.ets](./casesfeature/multiplefilesdownload/src/main/ets/view/FileDownloadItem.ets)。 + + ```typescript + task.start((err: BusinessError) => { + if (err) { + logger.error(TAG, `Failed to task start with error message: ${err.message}, error code: ${err.code}`); + return; + } + this.downloadTask = task; + }) + ``` + +5. 删除文件。使用fs.unlink删除该条数据应用文件路径 + + ```typescript + // TODO:知识点:删除该条数据应用文件路径 + fs.unlink(filePath).then(() => { + // 文件状态变为已删除 + this.FileInfo.fileStatus = 3; + promptAction.showToast({ + message: $r('app.string.multiple_files_download_history_toast_text_del'), + duration: 2000, + bottom: '50%', + }) + }).catch((error: BusinessError) => { + logger.error("remove file failed with error:" + error); + }); + ``` + +6. 重新下载已删除的文件。使用fs.access判断文件是否已经存在,若不存在弹窗提示用户是否重新下载。 + + ```typescript + // 获取应用文件路径 + const cacheDir = context.cacheDir; + const FilePath: string = `${cacheDir}/${this.fileName}`; + + // TODO:知识点:使用fs.access判断目录是否已经存在。 + fs.access(FilePath).then((res: boolean) => { + if (!res) { + // 文件已删除,弹窗提示是否重新下载 + AlertDialog.show({ + message: `${this.fileName}文件不存在,是否重新下载?`, + alignment: DialogAlignment.Center, // 弹窗在竖直方向上的对齐方式。 + autoCancel: false, // 点击遮罩层时,是否关闭弹窗。默认值:true + primaryButton: { + value: $r('app.string.multiple_files_download_history_button_text_cancel'), + fontColor: $r('app.color.multiple_files_download_text_color'), + action: () => { + logger.info('已取消'); + } + }, + secondaryButton: { + value: $r('app.string.multiple_files_download_history_button_text_confirm'), + fontColor: $r('app.color.multiple_files_download_del_bgc'), + action: () => { + // 更改该条数据下载状态 + this.FileInfo.fileStatus = 0; + // 该条数据加入下载列表数组中 + this.downloadFileArray.push(this.FileInfo); + // 下载历史列表删除该条数据 + this.historyArray = this.historyArray.filter( ( item: downloadFilesData ) => { + return item.id !== this.FileInfo.id; + }); + // 更新待下载任务数量 + this.downloadCount = this.downloadFileArray.length; + } + }, + cornerRadius: $r('app.integer.multiple_files_download_borderRadius_twelve'), // 弹窗边框弧度 + width: $r('app.string.multiple_files_download_list_height'), // 弹窗宽度 + cancel: () => { + logger.info('点击关闭按钮'); + } + }); + } else { + // 文件已下载到本地,弹窗提示文件已存在 + promptAction.showToast({ + message: $r('app.string.multiple_files_download_history_toast_text_exist'), + duration: 1000, + bottom: '50%', + }) + } + ``` + +### 高性能知识点 + +本示例中注册了progress下载进度更新监听,不建议在下载进度更新回调中加日志打印,以减少不必要的性能损耗。 + +### FAQ + +1. 无网络时,点击”全部开始“,下载队列中的任务状态却显示”已暂停“。 + + 答:request.agent.Config有一个参数retry默认是true,如果没有网络或者网络不满足时,会自动暂停waiting,所以在没网络的时候下载底层逻辑会走暂停回调,应用侧在暂停回调里设置了显示当前下载状态,所以无网络时,点击”全部开始“,下载队列中的任务状态显示”已暂停“。目前本例中已经把retry设置为false,没网络时,开启下载任务会直接走入失败回调,直接显示”下载失败“。 + +### 工程结构&模块类型 + + ``` + multiplefilesdownload // har类型 + |---view + | |---MultipleFilesDownload.ets // 视图层-文件下载页面 + | |---FileDownloadItem.ets // 视图层-单个文件下载组件 + | |---HistoryItem.ets // 视图层-单个文件历史组件 + ``` + +### 参考资料 + +[上传下载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md) + +### 相关权限 + +| 权限名 | 权限说明 | 级别 | +| ------------------------ | -------------------- | ------ | +| ohos.permission.INTERNET | 允许使用Interent网络 | normal | + +### 依赖 + +不涉及。 +### 约束与限制 + +1.本示例仅支持标准系统上运行。 + +2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12 Release)。 + +3.本示例需要使用DevEco Studio版本号(DevEco Studio 5.0.0 Release)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```shell +git init +git config core.sparsecheckout true +echo code/BasicFeature/Connectivity/MultipleFilesDownload > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/build-profile.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/build-profile.json5 index 62ec91ec46e3e6364d3cdef3e7cd648156a763d4..3bd213566f375a40ef87008867db312b57cbbabe 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/build-profile.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/build-profile.json5 @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - compileSdkVersion: 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug" - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "multiplefilesdownload", - "srcPath": "./casesfeature/multiplefilesdownload" - } - ] +/* + * 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: 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "multiplefilesdownload", + "srcPath": "./casesfeature/multiplefilesdownload" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/casesfeature/multiplefilesdownload/oh-package.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/casesfeature/multiplefilesdownload/oh-package.json5 index b6a8c714facd51937a0a2f470bb24ecea17e4cd3..2464e14a8cd5370489c5259f0b0b20f68ed0f15d 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/casesfeature/multiplefilesdownload/oh-package.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/casesfeature/multiplefilesdownload/oh-package.json5 @@ -1,23 +1,23 @@ -/* - * 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" : "multiplefilesdownload", - "version" : "1.0.0", - "description" : "Please describe the basic information.", - "main" : "Index.ets", - "author" : "", - "license" : "Apache-2.0", - "dependencies" : { } +/* + * 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" : "multiplefilesdownload", + "version" : "1.0.0", + "description" : "Please describe the basic information.", + "main" : "Index.ets", + "author" : "", + "license" : "Apache-2.0", + "dependencies" : { } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/build-profile.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/build-profile.json5 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/build-profile.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/oh-package.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/oh-package.json5 index f24d0a9a5ec9e1d584e09fddc01b076e7336bf22..71c70d510aef177dcc607ad38ce9f097c7bcb213 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/oh-package.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/oh-package.json5 @@ -1,26 +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": { - "multiplefilesdownload": "file:../casesfeature/multiplefilesdownload" - } +/* + * 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": { + "multiplefilesdownload": "file:../casesfeature/multiplefilesdownload" + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entryability/EntryAbility.ets index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/module.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/module.json5 index dfbe47e6ac287d71e455c7f49cef83dd292447e6..9deddb7dec7ee08ea3fea42236e640756faa9e43 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/module.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/module.json5 @@ -1,66 +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:app_name", - "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" - } - ] - } - ] - } +/* + * 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:app_name", + "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/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/profile/backup_config.json +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/dark/element/color.json b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/dark/element/color.json index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/dark/element/color.json +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/ohosTest/module.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/ohosTest/module.json5 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Connectivity/MultipleFilesDownload/hvigor/hvigor-config.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/hvigor/hvigor-config.json5 index dccc142c233ab36842dfb663f67d845e5446179d..5282eefe0593f56f8ddabfbf05783dc836c3c8b4 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/hvigor/hvigor-config.json5 @@ -1,36 +1,36 @@ -/* - * 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*/ - } -} +/* + * 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/BasicFeature/Connectivity/MultipleFilesDownload/oh-package.json5 b/code/BasicFeature/Connectivity/MultipleFilesDownload/oh-package.json5 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/oh-package.json5 +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/BasicFeature/Connectivity/MultipleFilesDownload/ohosTest.md b/code/BasicFeature/Connectivity/MultipleFilesDownload/ohosTest.md index 7691735123dfcf4320758d8d5074bb5bcbada342..1d79cbba9d9146cdb7cf0503f64d6a34322d14a9 100644 --- a/code/BasicFeature/Connectivity/MultipleFilesDownload/ohosTest.md +++ b/code/BasicFeature/Connectivity/MultipleFilesDownload/ohosTest.md @@ -1,13 +1,13 @@ -# 多文件下载监听案例 测试用例归档 - -## 用例表 - -|测试功能|预置条件|输入|预期输出|是否自动|测试结果| -|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| -|点击“全部开始”功能是否正常启动下载| 1.进入案例页面 2.正常连接网络 | 点击“全部开始” |点击“全部开始”,下载队列中两个任务能正常下载|是|Pass| -|点击“全部暂停”功能是否能正常暂停下载| 1.进入案例页面 2.正常连接网络 | 点击“全部暂停” |点击“全部暂停”,下载队列中正在下载的任务被暂停了|是|Pass| -|点击“全部开始”,然后在下载完成前点击“全部暂停”,然后再次点击“全部开始”查看被暂停的下载任务能否正常恢复下载| 1.进入案例页面 2.正常连接网络 | 点击“全部开始”,然后在下载完成前点击点击“全部暂停”,然后再次点击“全部开始” |下载任务重新恢复下载|是|Pass| -|下载文件保存是否正常| 1.进入案例页面 2.正常连接网络 | 点击“全部开始”,等待下载完成后,查看下载的文件是否保存在应用缓存路径下。(手工可用hdc shell cd /data/app/el2/100/base/com/north.cases/haps/entry/cache/) |下载完成后,在案例应用缓存路径下可以找到下载的文件:favor_list_tea.png favor_list_tree.png|是|Pass| -|在下载历史中已下载的文件是否能删除|1.进入案例页面 2.正常连接网络 3.点击下载历史tab|点击“删除”| 点击“删除”,文件被删除样式发生变化且在案例应用缓存路径下不能找到已删除的文件 |是|Pass| -|点击下载历史中的文件,是否能把已删除的文件重新下载|1.进入案例页面 2.正常连接网络 3.点击下载历史tab|点击已删除文件|弹出“xxx文件已被删除,是否重新下载”的弹窗提示用户是否重新下载,若用户点击“确认”文件重新下载|是|Pass| -|在下载历史中点击已下载的文件是否弹出“文件已存在”信息|1.进入案例页面 2.正常连接网络 3.点击下载历史tab|点击已下载文件|弹出“文件已存在”toast|是|Pass| +# 多文件下载监听案例 测试用例归档 + +## 用例表 + +|测试功能|预置条件|输入|预期输出|是否自动|测试结果| +|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| +|点击“全部开始”功能是否正常启动下载| 1.进入案例页面 2.正常连接网络 | 点击“全部开始” |点击“全部开始”,下载队列中两个任务能正常下载|是|Pass| +|点击“全部暂停”功能是否能正常暂停下载| 1.进入案例页面 2.正常连接网络 | 点击“全部暂停” |点击“全部暂停”,下载队列中正在下载的任务被暂停了|是|Pass| +|点击“全部开始”,然后在下载完成前点击“全部暂停”,然后再次点击“全部开始”查看被暂停的下载任务能否正常恢复下载| 1.进入案例页面 2.正常连接网络 | 点击“全部开始”,然后在下载完成前点击点击“全部暂停”,然后再次点击“全部开始” |下载任务重新恢复下载|是|Pass| +|下载文件保存是否正常| 1.进入案例页面 2.正常连接网络 | 点击“全部开始”,等待下载完成后,查看下载的文件是否保存在应用缓存路径下。(手工可用hdc shell cd /data/app/el2/100/base/com/north.cases/haps/entry/cache/) |下载完成后,在案例应用缓存路径下可以找到下载的文件:favor_list_tea.png favor_list_tree.png|是|Pass| +|在下载历史中已下载的文件是否能删除|1.进入案例页面 2.正常连接网络 3.点击下载历史tab|点击“删除”| 点击“删除”,文件被删除样式发生变化且在案例应用缓存路径下不能找到已删除的文件 |是|Pass| +|点击下载历史中的文件,是否能把已删除的文件重新下载|1.进入案例页面 2.正常连接网络 3.点击下载历史tab|点击已删除文件|弹出“xxx文件已被删除,是否重新下载”的弹窗提示用户是否重新下载,若用户点击“确认”文件重新下载|是|Pass| +|在下载历史中点击已下载的文件是否弹出“文件已存在”信息|1.进入案例页面 2.正常连接网络 3.点击下载历史tab|点击已下载文件|弹出“文件已存在”toast|是|Pass| diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/README_zh.md b/code/BasicFeature/Connectivity/UploadAndDownLoad/README_zh.md index a5e7b5a88257babe4b9a7265b5c1a971ee18c7b0..9536aca54575ccabd165ba0c1768f78a599cbb4b 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/README_zh.md +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/README_zh.md @@ -1,152 +1,152 @@ -# 上传和下载 - -### 介绍 -本示例使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)接口创建上传和下载任务,实现上传、下载功能,hfs作为服务器,实现了文件的上传和下载和任务的查询功能。 - -### 效果预览 - -| 主页 | 上传 | 片段上传 | 下载 | 证书锁定 | -| :---------------------------------------: | :---------------------------------------: | :--------------------------------------: | :--------------------------------------: | ---------------------------------------- | -| ![home](screenshots/devices/zh/home.jpg) | ![util](screenshots/devices/zh/upload.jpg) | ![util](screenshots/devices/zh/uploadchunk.jpg) | ![convertxml](screenshots/devices/zh/download.jpg) | ![cert_lock](screenshots/devices/zh/cert_lock.jpg) | - -使用说明 - -1.本示例功能需要先配置服务器环境后使用,具体配置见[上传下载服务配置](./environment)。 - -2.首页展示上传、下载和证书锁定三个入口组件,点击进入对应的页面,如果要使用后台下载任务,请开启后台任务开关。 - -3.上传页面: - -点击 **+**,**从相册选择**拉起图库选择照片,图片选择页面支持拍照,选择照片后点击**上传**进行上传。 - -可选的,点击缩略图,显示文件片段上传配置选项弹窗,可以配置上传起点和终点,取值为闭区间;起点默认为0,终点默认为文件结尾。点击**上传**进行选中文件片段以及后续文件全部内容上传。 - -点击**返回**键或片段上传配置选项弹窗外区域,取消片段上传。 - -在首页中打开后台任务开关后,上传页面开启的是后台上传任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 - -后台上传**暂停**时,需要服务器支持上传暂停服务(HFS暂不支持此操作)。如仍然使用HFS作为服务器,此时HFS服务将中断文件写入,立即将当前传输的数据保存为文件片段。点击**继续**时则会重新生成一份文件,并在新文件中开始写入。 - -4.下载页面: - -点击文件列表选择要下载的文件后,点击**下载**选择指定路径后开始下载。 - -点击**查看下载文件**进入下载文件页面,点击文件夹查看文件夹内的文件。 - -在首页中打开后台任务开关后,下载页面开启的是后台下载任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 - -前台下载时只支持单文件下载,后台下载时支持选择多个文件下载。 - -后台下载**暂停**时,本示例功能将自动记录断点。此时HFS服务仍会进行一定时间的传输,但是传输的数据并不会被接受。点击**继续**后将会从上次暂停的断点继续下载。 - -5.证书锁定页面: - -点击**下载**按钮会使用get方式访问百度,并在空白处显示返回的响应header内容。 - -点击**上传**按钮会使用post方式访问百度,并在空白处显示返回的响应header内容。 - -以上功能需要在src/main/resources/base/profile/network_config.json中配置domains和digest,只有你配置的证书信息通过验证,上传和下载才可以正常响应;否则将无法正常访问百度,会通过toast提示上传或者下载失败,日志中会有具体错误信息。如果你要访问的服务器根证书不在系统中,你需要把它的根证书放到src/main/resources/resfile目录下。 - -如示例中访问百度,则digest需要取百度服务器的证书生成: - -```bash -cat server.crt \ -| openssl x509 -noout -pubkey \ -| openssl pkey -pubin -outform der \ -| openssl dgst -sha256 -binary \ -| openssl enc -base64 -``` - -因为服务器证书可能定期更新,所以digest的值需要与服务端证书对应,及时更新。 - -![服务端证书](screenshots/ca.png) - -![获取digest](screenshots/get_digest.png) - - -### 工程目录 - -``` -UploadAndDownload -├── AppScope -│ └── app.json5 //APP信息配置文件 -├── entry/src/main //应用首页 -│ ├── ets -│ │ ├── entryability -│ │ ├── components //自定义组件 -│ │ ├── pages -│ │ │ ├── Index.ets //主页入口 -│ │ │ ├── Download.ets //下载页面 -│ │ │ ├── DownloadFiles.ets //查看下载文件页面 -│ │ │ ├── Upload.ets //上传页面 -│ │ │ ├── CertLock.ets //证书锁定页面 -│ └── module.json5 -│ -├── features/uploadanddownload/src/main //上传和下载 -│ ├── ets -│ │ ├── Index.ets //对外提供的接口列表 -│ │ ├── components -│ │ │ └── FileBrowse.ets //查看下载文件组件 -│ │ ├── download //下载任务相关 -│ │ ├── upload //上传任务相关 -│ │ ├── utils //相关工具类 -│ └── module.json5 -``` - -### 具体实现 - -* 该示例分为三个模块: - * 上传模块 - * 使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)中API 12接口agent.create创建上传任务,调用@ohos.request中的Task相关接口实现上传任务的创建、取消、进度加载,失败的任务会调用查询接口获取失败原因并打印在日志中,支持多个文件上传及片段上传。 - * 源码链接:[RequestUpload.ets](./features/uploadanddownload/src/main/ets/upload/RequestUpload.ets),[AddPictures.ets](./entry/src/main/ets/components/AddPictures.ets),[Upload.ets](./entry/src/main/ets/pages/Upload.ets) - * 参考接口:[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md),[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) - - * 下载模块 - - * 使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)中API 12接口agent.create创建上传任务,调用@ohos.request中的Task相关接口实现上传任务的创建、取消、进度加载,失败的任务会调用查询接口获取失败原因并打印在日志中,前台下载任务只支持单个文件下载,后台下载任务支持多文件下载。使用[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md)完成指定路径的创建和查询已下载的文件。 - * 源码链接:[RequestDownload.ets](./features/uploadanddownload/src/main/ets/download/RequestDownload.ets),[Download.ets](./entry/src/main/ets/pages/Download.ets),[FileUtils.ets](./features/uploadanddownload/src/main/ets/utils/FileUtils.ets),[FileBrowse.ets](./features/uploadanddownload/src/main/ets/components/FileBrowse.ets) - * 参考接口:[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md),[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) - - * 证书锁定模块 - - * 使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)中API 12接口agent.create创建上传任务,调用@ohos.request中的Task相关接口实现通过get或者post方式访问指定的网页,点击按钮后会在空白处显示返回的响应header内容。你需要提前在src/main/resources/base/profile/network_config.json中配置domains和digest,只有你配置的证书信息通过验证,上传和下载才可以正常响应。如果你要访问的服务器根证书不在系统中,你需要把它的根证书放在src/main/resources/resfile目录下。 - - * 源码链接,[CertLock.ets](./entry/src/main/ets/pages/CertLock.ets) - - * 参考接口:[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md) - - - - - -### 相关权限 - -[ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) - -[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_media) - -### 依赖 - -[上传下载服务配置](./environment)。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12),镜像版本号(5.0) - -3.本示例需要使用DevEco Studio 版本号(4.1 Release)及以上版本才可编译运行。 - -4.运行本示例需全程联网。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```bash -git init -git config core.sparsecheckout true -echo code/BasicFeature/Connectivity/UploadAndDownload/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 上传和下载 + +### 介绍 +本示例使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)接口创建上传和下载任务,实现上传、下载功能,hfs作为服务器,实现了文件的上传和下载和任务的查询功能。 + +### 效果预览 + +| 主页 | 上传 | 片段上传 | 下载 | 证书锁定 | +| :---------------------------------------: | :---------------------------------------: | :--------------------------------------: | :--------------------------------------: | ---------------------------------------- | +| ![home](screenshots/devices/zh/home.jpg) | ![util](screenshots/devices/zh/upload.jpg) | ![util](screenshots/devices/zh/uploadchunk.jpg) | ![convertxml](screenshots/devices/zh/download.jpg) | ![cert_lock](screenshots/devices/zh/cert_lock.jpg) | + +使用说明 + +1.本示例功能需要先配置服务器环境后使用,具体配置见[上传下载服务配置](./environment)。 + +2.首页展示上传、下载和证书锁定三个入口组件,点击进入对应的页面,如果要使用后台下载任务,请开启后台任务开关。 + +3.上传页面: + +点击 **+**,**从相册选择**拉起图库选择照片,图片选择页面支持拍照,选择照片后点击**上传**进行上传。 + +可选的,点击缩略图,显示文件片段上传配置选项弹窗,可以配置上传起点和终点,取值为闭区间;起点默认为0,终点默认为文件结尾。点击**上传**进行选中文件片段以及后续文件全部内容上传。 + +点击**返回**键或片段上传配置选项弹窗外区域,取消片段上传。 + +在首页中打开后台任务开关后,上传页面开启的是后台上传任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 + +后台上传**暂停**时,需要服务器支持上传暂停服务(HFS暂不支持此操作)。如仍然使用HFS作为服务器,此时HFS服务将中断文件写入,立即将当前传输的数据保存为文件片段。点击**继续**时则会重新生成一份文件,并在新文件中开始写入。 + +4.下载页面: + +点击文件列表选择要下载的文件后,点击**下载**选择指定路径后开始下载。 + +点击**查看下载文件**进入下载文件页面,点击文件夹查看文件夹内的文件。 + +在首页中打开后台任务开关后,下载页面开启的是后台下载任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 + +前台下载时只支持单文件下载,后台下载时支持选择多个文件下载。 + +后台下载**暂停**时,本示例功能将自动记录断点。此时HFS服务仍会进行一定时间的传输,但是传输的数据并不会被接受。点击**继续**后将会从上次暂停的断点继续下载。 + +5.证书锁定页面: + +点击**下载**按钮会使用get方式访问百度,并在空白处显示返回的响应header内容。 + +点击**上传**按钮会使用post方式访问百度,并在空白处显示返回的响应header内容。 + +以上功能需要在src/main/resources/base/profile/network_config.json中配置domains和digest,只有你配置的证书信息通过验证,上传和下载才可以正常响应;否则将无法正常访问百度,会通过toast提示上传或者下载失败,日志中会有具体错误信息。如果你要访问的服务器根证书不在系统中,你需要把它的根证书放到src/main/resources/resfile目录下。 + +如示例中访问百度,则digest需要取百度服务器的证书生成: + +```bash +cat server.crt \ +| openssl x509 -noout -pubkey \ +| openssl pkey -pubin -outform der \ +| openssl dgst -sha256 -binary \ +| openssl enc -base64 +``` + +因为服务器证书可能定期更新,所以digest的值需要与服务端证书对应,及时更新。 + +![服务端证书](screenshots/ca.png) + +![获取digest](screenshots/get_digest.png) + + +### 工程目录 + +``` +UploadAndDownload +├── AppScope +│ └── app.json5 //APP信息配置文件 +├── entry/src/main //应用首页 +│ ├── ets +│ │ ├── entryability +│ │ ├── components //自定义组件 +│ │ ├── pages +│ │ │ ├── Index.ets //主页入口 +│ │ │ ├── Download.ets //下载页面 +│ │ │ ├── DownloadFiles.ets //查看下载文件页面 +│ │ │ ├── Upload.ets //上传页面 +│ │ │ ├── CertLock.ets //证书锁定页面 +│ └── module.json5 +│ +├── features/uploadanddownload/src/main //上传和下载 +│ ├── ets +│ │ ├── Index.ets //对外提供的接口列表 +│ │ ├── components +│ │ │ └── FileBrowse.ets //查看下载文件组件 +│ │ ├── download //下载任务相关 +│ │ ├── upload //上传任务相关 +│ │ ├── utils //相关工具类 +│ └── module.json5 +``` + +### 具体实现 + +* 该示例分为三个模块: + * 上传模块 + * 使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)中API 12接口agent.create创建上传任务,调用@ohos.request中的Task相关接口实现上传任务的创建、取消、进度加载,失败的任务会调用查询接口获取失败原因并打印在日志中,支持多个文件上传及片段上传。 + * 源码链接:[RequestUpload.ets](./features/uploadanddownload/src/main/ets/upload/RequestUpload.ets),[AddPictures.ets](./entry/src/main/ets/components/AddPictures.ets),[Upload.ets](./entry/src/main/ets/pages/Upload.ets) + * 参考接口:[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md),[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) + + * 下载模块 + + * 使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)中API 12接口agent.create创建上传任务,调用@ohos.request中的Task相关接口实现上传任务的创建、取消、进度加载,失败的任务会调用查询接口获取失败原因并打印在日志中,前台下载任务只支持单个文件下载,后台下载任务支持多文件下载。使用[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md)完成指定路径的创建和查询已下载的文件。 + * 源码链接:[RequestDownload.ets](./features/uploadanddownload/src/main/ets/download/RequestDownload.ets),[Download.ets](./entry/src/main/ets/pages/Download.ets),[FileUtils.ets](./features/uploadanddownload/src/main/ets/utils/FileUtils.ets),[FileBrowse.ets](./features/uploadanddownload/src/main/ets/components/FileBrowse.ets) + * 参考接口:[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md),[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) + + * 证书锁定模块 + + * 使用[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md)中API 12接口agent.create创建上传任务,调用@ohos.request中的Task相关接口实现通过get或者post方式访问指定的网页,点击按钮后会在空白处显示返回的响应header内容。你需要提前在src/main/resources/base/profile/network_config.json中配置domains和digest,只有你配置的证书信息通过验证,上传和下载才可以正常响应。如果你要访问的服务器根证书不在系统中,你需要把它的根证书放在src/main/resources/resfile目录下。 + + * 源码链接,[CertLock.ets](./entry/src/main/ets/pages/CertLock.ets) + + * 参考接口:[@ohos.request](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-request.md) + + + + + +### 相关权限 + +[ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_media) + +### 依赖 + +[上传下载服务配置](./environment)。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12),镜像版本号(5.0) + +3.本示例需要使用DevEco Studio 版本号(4.1 Release)及以上版本才可编译运行。 + +4.运行本示例需全程联网。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```bash +git init +git config core.sparsecheckout true +echo code/BasicFeature/Connectivity/UploadAndDownload/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/build-profile.json5 b/code/BasicFeature/Connectivity/UploadAndDownLoad/build-profile.json5 index 49dfabaaebd6ee47414f91c55299f79b16629226..39778e6c094b450e56dc8e3a120ad7cc27d9f776 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/build-profile.json5 +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/build-profile.json5 @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2023 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "uploadanddownload", - "srcPath": "./features/uploadanddownload" - } - ] +/* + * Copyright (c) 2023 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "uploadanddownload", + "srcPath": "./features/uploadanddownload" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/CertLock.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/CertLock.ets index 5a026070811206ebe9ab3ed0923553f91206dbe5..1ded11e16cec9222008c044133a01e2f5ee0d57c 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/CertLock.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/CertLock.ets @@ -1,192 +1,192 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import promptAction from '@ohos.promptAction'; -import request from '@ohos.request'; -import connection from '@ohos.net.connection'; -import router from '@ohos.router'; -import { BusinessError } from '@ohos.base'; -import { logger, TOAST_BOTTOM } from '@ohos/uploaddownload'; - -const TAG: string = 'CertLockSample'; - -@Entry -@Component -struct CertLock { - @State message: string = '' - @State taskId: string = ''; - @State progress: string = '0%'; - - build() { - Navigation() { - Text(this.message) - .fontSize(16) - .fontColor($r('app.color.text_message')) - .textAlign(TextAlign.Start) - .id('http_response') - .width('90%') - .height('80%') - .maxLines(30) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - - Button($r('app.string.upload')) - .id('upload') - .width('90%') - .fontSize(16) - .height(40) - .margin({ top: 10, bottom: 20 }) - .enabled(true) - .backgroundColor($r('app.color.button_blue')) - .onClick(() => { - this.uploadTask(); - }) - - Button($r('app.string.download')) - .id('download') - .type(ButtonType.Capsule) - .width('90%') - .fontSize(16) - .fontColor($r('app.color.btn_text_blue')) - .height(40) - .margin({ bottom: 10 }) - .enabled(true) - .backgroundColor($r('app.color.button_light_gray')) - .onClick(() => { - this.DownloadTask(); - }) - } - .width('100%') - .height('100%') - .hideBackButton(false) - .titleMode(NavigationTitleMode.Mini) - .mode(NavigationMode.Stack) - .backgroundColor($r('app.color.light_gray')) - .hideToolBar(false) - .title($r('app.string.cert_lock')) - } - - static task: request.agent.Task; - static netConnection = connection.createNetConnection(); - - async DownloadTask() { - logger.debug(TAG, 'DownloadTask'); - let config: request.agent.Config = { - action: request.agent.Action.DOWNLOAD, - url: 'https://www.baidu.com', - gauge: true, - overwrite: true, - method: 'GET', - network: request.agent.Network.ANY, - }; - let task: request.agent.Task = await request.agent.create(getContext(), config); - CertLock.task = task; - task.on('progress', async (progress) => { - logger.debug(TAG, `/Request download status ${progress.state}, downloaded ${progress.processed}`); - promptAction.showToast({ - message: $r('app.string.download_finish'), - bottom: TOAST_BOTTOM, - offset: { dx: 10, dy: 96 } - }); - this.taskId = task.tid; - }) - let responseOnCallback = (response: request.agent.HttpResponse) => { - logger.debug(TAG, `response : ${response.version} ${response.statusCode} ${response.reason} ${response.headers} ${response.headers.size}`) - let headers: string = ''; - for (let k of response.headers.keys()) { - headers = headers + k + ':' + response.headers.get(k) + '\r\n'; - ; - logger.debug(TAG, `response 1 ${k}, ${response.headers.get(k)}`) - } - this.message = headers; - }; - task.on('response', responseOnCallback); - - task.on('failed', async (progress) => { - this.message = JSON.stringify(progress); - logger.debug(TAG, `/Request download failed ${(JSON.stringify(progress))}`); - promptAction.showToast({ message: $r('app.string.download_fail'), bottom: TOAST_BOTTOM }); - }) - logger.debug(TAG, 'Downloading before'); - await task.start(); - logger.debug(TAG, 'Downloading started'); - } - - async uploadTask() { - logger.debug(TAG, 'uploadTask'); - let attachments: Array = []; - let attachment: request.agent.FormItem = { - name: 'test', - value: [ - { - filename: 'testUpload.txt', - path: './testUpload.txt', - }, - ] - }; - attachments.push(attachment); - let config: request.agent.Config = { - action: request.agent.Action.UPLOAD, - url: 'https://www.baidu.com', - title: 'taskOnTest', - mode: request.agent.Mode.FOREGROUND, - overwrite: true, - method: 'POST', - data: attachments, - saveas: './' - }; - let createOnCallback = (progress: request.agent.Progress) => { - let txt: string = $r('app.string.upload_fail').bundleName; - this.progress = txt + ((progress.processed / 1024 / 1024)); - promptAction.showToast({ message: $r('app.string.upload_success'), bottom: TOAST_BOTTOM }); - }; - request.agent.create(getContext(), config).then((task: request.agent.Task) => { - task.start((err: BusinessError) => { - if (err) { - this.progress = `Failed to start the upload task, Code: ${err.code} message: ${err.message}`; - return; - } - }); - task.on('progress', createOnCallback); - let responseOnCallback = (response: request.agent.HttpResponse) => { - logger.debug(TAG, `response : ${response.version} ${response.statusCode} ${response.reason} ${response.headers} ${response.headers.size}`) - let headers: string = ''; - for (let k of response.headers.keys()) { - headers = headers + k + ':' + response.headers.get(k) + '\r\n'; - ; - logger.debug(TAG, `response 1 ${k}, ${response.headers.get(k)}`) - } - this.message = headers; - }; - task.on('response', responseOnCallback); - task.on('failed', async (progress) => { - this.message = JSON.stringify(progress); - logger.debug(TAG, `/Request upload failed ${(JSON.stringify(progress))}`); - promptAction.showToast({ message: $r('app.string.upload_fail'), bottom: TOAST_BOTTOM }); - }) - logger.debug(TAG, `Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err: BusinessError) => { - this.progress = `Failed to create a upload task, Code: ${err.code}, message: ${err.message}`; - }); - } - - aboutToAppear() { - logger.debug(TAG, 'aboutToAppear'); - } - - stateChange() { - logger.debug(TAG, 'stateChange'); - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import promptAction from '@ohos.promptAction'; +import request from '@ohos.request'; +import connection from '@ohos.net.connection'; +import router from '@ohos.router'; +import { BusinessError } from '@ohos.base'; +import { logger, TOAST_BOTTOM } from '@ohos/uploaddownload'; + +const TAG: string = 'CertLockSample'; + +@Entry +@Component +struct CertLock { + @State message: string = '' + @State taskId: string = ''; + @State progress: string = '0%'; + + build() { + Navigation() { + Text(this.message) + .fontSize(16) + .fontColor($r('app.color.text_message')) + .textAlign(TextAlign.Start) + .id('http_response') + .width('90%') + .height('80%') + .maxLines(30) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + + Button($r('app.string.upload')) + .id('upload') + .width('90%') + .fontSize(16) + .height(40) + .margin({ top: 10, bottom: 20 }) + .enabled(true) + .backgroundColor($r('app.color.button_blue')) + .onClick(() => { + this.uploadTask(); + }) + + Button($r('app.string.download')) + .id('download') + .type(ButtonType.Capsule) + .width('90%') + .fontSize(16) + .fontColor($r('app.color.btn_text_blue')) + .height(40) + .margin({ bottom: 10 }) + .enabled(true) + .backgroundColor($r('app.color.button_light_gray')) + .onClick(() => { + this.DownloadTask(); + }) + } + .width('100%') + .height('100%') + .hideBackButton(false) + .titleMode(NavigationTitleMode.Mini) + .mode(NavigationMode.Stack) + .backgroundColor($r('app.color.light_gray')) + .hideToolBar(false) + .title($r('app.string.cert_lock')) + } + + static task: request.agent.Task; + static netConnection = connection.createNetConnection(); + + async DownloadTask() { + logger.debug(TAG, 'DownloadTask'); + let config: request.agent.Config = { + action: request.agent.Action.DOWNLOAD, + url: 'https://www.baidu.com', + gauge: true, + overwrite: true, + method: 'GET', + network: request.agent.Network.ANY, + }; + let task: request.agent.Task = await request.agent.create(getContext(), config); + CertLock.task = task; + task.on('progress', async (progress) => { + logger.debug(TAG, `/Request download status ${progress.state}, downloaded ${progress.processed}`); + promptAction.showToast({ + message: $r('app.string.download_finish'), + bottom: TOAST_BOTTOM, + offset: { dx: 10, dy: 96 } + }); + this.taskId = task.tid; + }) + let responseOnCallback = (response: request.agent.HttpResponse) => { + logger.debug(TAG, `response : ${response.version} ${response.statusCode} ${response.reason} ${response.headers} ${response.headers.size}`) + let headers: string = ''; + for (let k of response.headers.keys()) { + headers = headers + k + ':' + response.headers.get(k) + '\r\n'; + ; + logger.debug(TAG, `response 1 ${k}, ${response.headers.get(k)}`) + } + this.message = headers; + }; + task.on('response', responseOnCallback); + + task.on('failed', async (progress) => { + this.message = JSON.stringify(progress); + logger.debug(TAG, `/Request download failed ${(JSON.stringify(progress))}`); + promptAction.showToast({ message: $r('app.string.download_fail'), bottom: TOAST_BOTTOM }); + }) + logger.debug(TAG, 'Downloading before'); + await task.start(); + logger.debug(TAG, 'Downloading started'); + } + + async uploadTask() { + logger.debug(TAG, 'uploadTask'); + let attachments: Array = []; + let attachment: request.agent.FormItem = { + name: 'test', + value: [ + { + filename: 'testUpload.txt', + path: './testUpload.txt', + }, + ] + }; + attachments.push(attachment); + let config: request.agent.Config = { + action: request.agent.Action.UPLOAD, + url: 'https://www.baidu.com', + title: 'taskOnTest', + mode: request.agent.Mode.FOREGROUND, + overwrite: true, + method: 'POST', + data: attachments, + saveas: './' + }; + let createOnCallback = (progress: request.agent.Progress) => { + let txt: string = $r('app.string.upload_fail').bundleName; + this.progress = txt + ((progress.processed / 1024 / 1024)); + promptAction.showToast({ message: $r('app.string.upload_success'), bottom: TOAST_BOTTOM }); + }; + request.agent.create(getContext(), config).then((task: request.agent.Task) => { + task.start((err: BusinessError) => { + if (err) { + this.progress = `Failed to start the upload task, Code: ${err.code} message: ${err.message}`; + return; + } + }); + task.on('progress', createOnCallback); + let responseOnCallback = (response: request.agent.HttpResponse) => { + logger.debug(TAG, `response : ${response.version} ${response.statusCode} ${response.reason} ${response.headers} ${response.headers.size}`) + let headers: string = ''; + for (let k of response.headers.keys()) { + headers = headers + k + ':' + response.headers.get(k) + '\r\n'; + ; + logger.debug(TAG, `response 1 ${k}, ${response.headers.get(k)}`) + } + this.message = headers; + }; + task.on('response', responseOnCallback); + task.on('failed', async (progress) => { + this.message = JSON.stringify(progress); + logger.debug(TAG, `/Request upload failed ${(JSON.stringify(progress))}`); + promptAction.showToast({ message: $r('app.string.upload_fail'), bottom: TOAST_BOTTOM }); + }) + logger.debug(TAG, `Succeeded in creating a upload task. result: ${task.tid}`); + }).catch((err: BusinessError) => { + this.progress = `Failed to create a upload task, Code: ${err.code}, message: ${err.message}`; + }); + } + + aboutToAppear() { + logger.debug(TAG, 'aboutToAppear'); + } + + stateChange() { + logger.debug(TAG, 'stateChange'); + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Download.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Download.ets index 86f662222dd22f84372d6ee674273b61a430513b..21827b079c7ab885831931ce99dc2476e9f85762 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Download.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Download.ets @@ -1,332 +1,332 @@ -/* - * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; -import router from '@ohos.router'; -import { CustomDataSource } from '../components/CustomDataSource'; -import { - FileModel, - FileType, - fileUtils, - logger, - requestFiles, - requestDownload, - BackgroundTaskState, - TOAST_BOTTOM -} from '@ohos/uploaddownload'; -import { SelectFolderDialog } from '../components/SelectFolderDialog'; - -const TAG: string = 'DownloadSample'; - -@Entry -@Component -struct Download { - private fileData: CustomDataSource = new CustomDataSource([]); - @StorageLink('isBackground') isBackground: boolean = false; - @StorageLink('backDownTaskState') backDownTaskState: BackgroundTaskState = BackgroundTaskState.NONE; - @Provide downloadFolder: Array = []; - @State isGetData: boolean = false; - @State checkFile: Array = []; - @State checkList: Array = []; - @State isRunning: boolean = false; - @State isPause: boolean = false; - @State progress: number = 0; - private selectFolder = (folder: string) => { - logger.info(TAG, `selectFolder = ${folder}`); - this.download(folder); - } - private folderDialogController: CustomDialogController = new CustomDialogController({ - builder: SelectFolderDialog({ selectFolder: this.selectFolder }), - autoCancel: true, - alignment: DialogAlignment.Bottom, - offset: { dx: 0, dy: -12 } - }); - - build() { - Navigation() { - Column() { - if (this.isGetData) { - LoadingProgress() - .width(100) - .layoutWeight(1) - } else { - List({ space: 12 }) { - LazyForEach(this.fileData, (item: FileModel, index?: number) => { - ListItem() { - if (index !== undefined) { - this.FileItem(item, index) - } - } - }, (item: FileModel) => JSON.stringify(item)) - } - .width('100%') - .scrollBar(BarState.Off) - .layoutWeight(1) - .backgroundColor(Color.White) - .borderRadius(24) - .padding({ top: 4, bottom: 4 }) - .divider({ strokeWidth: 1, startMargin: 44, endMargin: 12 }) - } - this.BottomView() - } - .padding({ left: 12, right: 12, bottom: 12 }) - .height('100%') - } - .width('100%') - .height('100%') - .hideBackButton(false) - .titleMode(NavigationTitleMode.Mini) - .mode(NavigationMode.Stack) - .backgroundColor($r('app.color.light_gray')) - .hideToolBar(false) - .title($r('app.string.download')) - } - - @Builder - FileItem(file: FileModel, index: number) { - Row() { - Row() { - if (file.fileType === FileType.FOLDER) { - Image($r('app.media.ic_files_folder')) - .size({ width: 24, height: 24 }) - .objectFit(ImageFit.Contain) - } else if (file.fileType === FileType.IMAGE) { - Image($r('app.media.ic_public_picture')) - .size({ width: 24, height: 24 }) - .objectFit(ImageFit.Contain) - } else if (file.fileType === FileType.MUSIC) { - Image($r('app.media.ic_public_music')) - .size({ width: 24, height: 24 }) - .objectFit(ImageFit.Contain) - } else if (file.fileType === FileType.Video) { - Image($r('app.media.ic_public_video')) - .size({ width: 24, height: 24 }) - .objectFit(ImageFit.Contain) - } else { - Image($r('app.media.ic_public_document')) - .size({ width: 24, height: 24 }) - .objectFit(ImageFit.Contain) - } - - Text(decodeURIComponent(file.name)) - .fontSize(16) - .fontWeight(400) - .layoutWeight(1) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .margin({ left: 12 }) - } - .layoutWeight(1) - - Checkbox({ name: '', group: 'checkboxGroup' }) - .select(this.checkList[index]) - .selectedColor($r('app.color.button_blue')) - .margin({ left: 12 }) - .hitTestBehavior(HitTestMode.None) - } - .width('100%') - .padding({ left: 12, right: 12 }) - .height(48) - .onClick(() => { - this.fileCheck(index); - }) - } - - @Builder - BottomView() { - Column({ space: 12 }) { - if (this.isBackground && this.backDownTaskState !== BackgroundTaskState.NONE) { - Button() { - Row() { - Text(this.backDownTaskState === BackgroundTaskState.PAUSE ? $r('app.string.continue') : $r('app.string.pause')) - .fontColor(Color.White) - .fontSize(16) - } - } - .id('download_to') - .type(ButtonType.Capsule) - .height(45) - .width('100%') - .backgroundColor($r('app.color.button_blue')) - .onClick(() => { - requestDownload.pauseOrResume(); - }) - - Button() { - Row() { - Text($r('app.string.cancel')) - .fontColor(Color.White) - .fontSize(16) - } - } - .id('download_to') - .type(ButtonType.Capsule) - .height(45) - .width('100%') - .backgroundColor($r('app.color.button_blue')) - .onClick(() => { - requestDownload.deleteAllBackTasks(); - }) - } - if (!this.isBackground || this.isBackground && this.backDownTaskState === BackgroundTaskState.NONE) { - Button() { - Row() { - if (!this.isBackground && this.isRunning) { - Text(`${this.progress}%`) - .fontColor(Color.White) - .fontSize(16) - Text($r('app.string.downloading')) - .fontColor(Color.White) - .fontSize(16) - .margin({ left: 12 }) - } else { - Text($r('app.string.download')) - .fontColor(Color.White) - .fontSize(16) - } - } - } - .id('download_to') - .type(ButtonType.Capsule) - .height(45) - .width('100%') - .backgroundColor($r('app.color.button_blue')) - .onClick(() => { - if (!this.isRunning) { - this.folderDialogController.open(); - } - }) - } - Button($r('app.string.view_download_files')) - .id('view_download_files') - .type(ButtonType.Capsule) - .backgroundColor($r('sys.color.ohos_id_color_button_normal')) - .width('100%') - .fontSize(16) - .margin({ bottom: 12 }) - .fontColor($r('app.color.btn_text_blue')) - .onClick(() => { - router.pushUrl({ - url: 'pages/DownloadFiles' - }); - }) - } - .margin({ top: 12, left: 12, right: 12 }) - } - - aboutToAppear() { - logger.debug(TAG, 'aboutToAppear'); - this.isRunning = false; - this.isPause = false; - this.isGetData = true; - requestFiles.requestFiles().then((data: FileModel[]) => { - this.checkList = []; - this.isRunning = false; - this.fileData.dataArray = data; - this.fileData.dataArray.forEach((item: FileModel) => { - this.checkList.push(false); - }) - this.isGetData = false; - this.fileData.notifyDataReload(); - }) - fileUtils.listFolders().then((folders: Array) => { - this.downloadFolder = folders; - }) - } - - fileCheck(index: number) { - logger.debug(TAG, `fileCheck= ${index}`); - if (!this.isBackground) { - for (let i = 0; i < this.checkList.length; i++) { - if (i !== index) { - this.checkList[i] = false; - } - } - } - this.checkList[index] = !this.checkList[index]; - logger.info(TAG, `this.checkList = ${JSON.stringify(this.checkList)}`); - } - - download(folder: string) { - logger.debug(TAG, `download folder= ${folder}`); - this.checkFile = []; - if (this.checkList === undefined) { - return; - } - logger.info(TAG, `this.checkList = ${JSON.stringify(this.checkList)}`); - for (let i = 0; i < this.checkList.length; i++) { - if (this.checkList[i]) { - let fileModel = this.fileData.getData(i); - logger.info(TAG, `fileModel = ${JSON.stringify(fileModel)}`); - fileModel.files.forEach((url: string) => { - let splitUrl = url.split('//')[1].split('/'); - if (splitUrl[splitUrl.length-1] !== '') { - this.checkFile.push(url); - } - }); - } - } - logger.info(TAG, `this.checkFile = ${JSON.stringify(this.checkFile)}`); - if (this.checkFile.length === 0) { - promptAction.showToast({ message: $r('app.string.check_file_tips'), bottom: TOAST_BOTTOM }); - return; - } - this.progress = 0; - logger.info(TAG, `this.isBackground = ${JSON.stringify(this.isBackground)}`); - if (this.isBackground) { - this.isRunning = false; - this.backDownTaskState = BackgroundTaskState.RUNNING; - requestDownload.downloadFilesBackground(folder, this.checkFile); - this.checkFile = []; - this.checkList = []; - this.fileData.dataArray.forEach((item: FileModel) => { - this.checkList.push(false); - }) - this.fileData.notifyDataReload(); - promptAction.showToast({ message: $r('app.string.background_task_start'), bottom: TOAST_BOTTOM }); - } else { - this.isRunning = true; - requestDownload.downloadFile(folder, this.checkFile[0], this.downloadFileCallback); - } - } - - downloadFilesCallback = (downloadCount: number, isSuccess: boolean) => { - logger.debug(TAG, 'downloadFilesCallback'); - this.progress = downloadCount; - if (downloadCount === this.checkFile.length) { - this.downloadFinish(isSuccess); - } - } - downloadFileCallback = (progress: number, isSuccess: boolean) => { - logger.debug(TAG, 'downloadFileCallback'); - this.progress = progress; - if (this.progress === 100) { - this.downloadFinish(isSuccess); - } - } - - downloadFinish(isSuccess: boolean) { - logger.debug(TAG, 'downloadFinish'); - this.isRunning = false; - this.checkFile = []; - this.checkList = []; - this.fileData.dataArray.forEach((item: FileModel) => { - this.checkList.push(false); - }) - this.fileData.notifyDataReload(); - let message = isSuccess ? $r('app.string.download_finish') : $r('app.string.download_fail'); - promptAction.showToast({ message: message, bottom: TOAST_BOTTOM }); - } +/* + * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; +import router from '@ohos.router'; +import { CustomDataSource } from '../components/CustomDataSource'; +import { + FileModel, + FileType, + fileUtils, + logger, + requestFiles, + requestDownload, + BackgroundTaskState, + TOAST_BOTTOM +} from '@ohos/uploaddownload'; +import { SelectFolderDialog } from '../components/SelectFolderDialog'; + +const TAG: string = 'DownloadSample'; + +@Entry +@Component +struct Download { + private fileData: CustomDataSource = new CustomDataSource([]); + @StorageLink('isBackground') isBackground: boolean = false; + @StorageLink('backDownTaskState') backDownTaskState: BackgroundTaskState = BackgroundTaskState.NONE; + @Provide downloadFolder: Array = []; + @State isGetData: boolean = false; + @State checkFile: Array = []; + @State checkList: Array = []; + @State isRunning: boolean = false; + @State isPause: boolean = false; + @State progress: number = 0; + private selectFolder = (folder: string) => { + logger.info(TAG, `selectFolder = ${folder}`); + this.download(folder); + } + private folderDialogController: CustomDialogController = new CustomDialogController({ + builder: SelectFolderDialog({ selectFolder: this.selectFolder }), + autoCancel: true, + alignment: DialogAlignment.Bottom, + offset: { dx: 0, dy: -12 } + }); + + build() { + Navigation() { + Column() { + if (this.isGetData) { + LoadingProgress() + .width(100) + .layoutWeight(1) + } else { + List({ space: 12 }) { + LazyForEach(this.fileData, (item: FileModel, index?: number) => { + ListItem() { + if (index !== undefined) { + this.FileItem(item, index) + } + } + }, (item: FileModel) => JSON.stringify(item)) + } + .width('100%') + .scrollBar(BarState.Off) + .layoutWeight(1) + .backgroundColor(Color.White) + .borderRadius(24) + .padding({ top: 4, bottom: 4 }) + .divider({ strokeWidth: 1, startMargin: 44, endMargin: 12 }) + } + this.BottomView() + } + .padding({ left: 12, right: 12, bottom: 12 }) + .height('100%') + } + .width('100%') + .height('100%') + .hideBackButton(false) + .titleMode(NavigationTitleMode.Mini) + .mode(NavigationMode.Stack) + .backgroundColor($r('app.color.light_gray')) + .hideToolBar(false) + .title($r('app.string.download')) + } + + @Builder + FileItem(file: FileModel, index: number) { + Row() { + Row() { + if (file.fileType === FileType.FOLDER) { + Image($r('app.media.ic_files_folder')) + .size({ width: 24, height: 24 }) + .objectFit(ImageFit.Contain) + } else if (file.fileType === FileType.IMAGE) { + Image($r('app.media.ic_public_picture')) + .size({ width: 24, height: 24 }) + .objectFit(ImageFit.Contain) + } else if (file.fileType === FileType.MUSIC) { + Image($r('app.media.ic_public_music')) + .size({ width: 24, height: 24 }) + .objectFit(ImageFit.Contain) + } else if (file.fileType === FileType.Video) { + Image($r('app.media.ic_public_video')) + .size({ width: 24, height: 24 }) + .objectFit(ImageFit.Contain) + } else { + Image($r('app.media.ic_public_document')) + .size({ width: 24, height: 24 }) + .objectFit(ImageFit.Contain) + } + + Text(decodeURIComponent(file.name)) + .fontSize(16) + .fontWeight(400) + .layoutWeight(1) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .margin({ left: 12 }) + } + .layoutWeight(1) + + Checkbox({ name: '', group: 'checkboxGroup' }) + .select(this.checkList[index]) + .selectedColor($r('app.color.button_blue')) + .margin({ left: 12 }) + .hitTestBehavior(HitTestMode.None) + } + .width('100%') + .padding({ left: 12, right: 12 }) + .height(48) + .onClick(() => { + this.fileCheck(index); + }) + } + + @Builder + BottomView() { + Column({ space: 12 }) { + if (this.isBackground && this.backDownTaskState !== BackgroundTaskState.NONE) { + Button() { + Row() { + Text(this.backDownTaskState === BackgroundTaskState.PAUSE ? $r('app.string.continue') : $r('app.string.pause')) + .fontColor(Color.White) + .fontSize(16) + } + } + .id('download_to') + .type(ButtonType.Capsule) + .height(45) + .width('100%') + .backgroundColor($r('app.color.button_blue')) + .onClick(() => { + requestDownload.pauseOrResume(); + }) + + Button() { + Row() { + Text($r('app.string.cancel')) + .fontColor(Color.White) + .fontSize(16) + } + } + .id('download_to') + .type(ButtonType.Capsule) + .height(45) + .width('100%') + .backgroundColor($r('app.color.button_blue')) + .onClick(() => { + requestDownload.deleteAllBackTasks(); + }) + } + if (!this.isBackground || this.isBackground && this.backDownTaskState === BackgroundTaskState.NONE) { + Button() { + Row() { + if (!this.isBackground && this.isRunning) { + Text(`${this.progress}%`) + .fontColor(Color.White) + .fontSize(16) + Text($r('app.string.downloading')) + .fontColor(Color.White) + .fontSize(16) + .margin({ left: 12 }) + } else { + Text($r('app.string.download')) + .fontColor(Color.White) + .fontSize(16) + } + } + } + .id('download_to') + .type(ButtonType.Capsule) + .height(45) + .width('100%') + .backgroundColor($r('app.color.button_blue')) + .onClick(() => { + if (!this.isRunning) { + this.folderDialogController.open(); + } + }) + } + Button($r('app.string.view_download_files')) + .id('view_download_files') + .type(ButtonType.Capsule) + .backgroundColor($r('sys.color.ohos_id_color_button_normal')) + .width('100%') + .fontSize(16) + .margin({ bottom: 12 }) + .fontColor($r('app.color.btn_text_blue')) + .onClick(() => { + router.pushUrl({ + url: 'pages/DownloadFiles' + }); + }) + } + .margin({ top: 12, left: 12, right: 12 }) + } + + aboutToAppear() { + logger.debug(TAG, 'aboutToAppear'); + this.isRunning = false; + this.isPause = false; + this.isGetData = true; + requestFiles.requestFiles().then((data: FileModel[]) => { + this.checkList = []; + this.isRunning = false; + this.fileData.dataArray = data; + this.fileData.dataArray.forEach((item: FileModel) => { + this.checkList.push(false); + }) + this.isGetData = false; + this.fileData.notifyDataReload(); + }) + fileUtils.listFolders().then((folders: Array) => { + this.downloadFolder = folders; + }) + } + + fileCheck(index: number) { + logger.debug(TAG, `fileCheck= ${index}`); + if (!this.isBackground) { + for (let i = 0; i < this.checkList.length; i++) { + if (i !== index) { + this.checkList[i] = false; + } + } + } + this.checkList[index] = !this.checkList[index]; + logger.info(TAG, `this.checkList = ${JSON.stringify(this.checkList)}`); + } + + download(folder: string) { + logger.debug(TAG, `download folder= ${folder}`); + this.checkFile = []; + if (this.checkList === undefined) { + return; + } + logger.info(TAG, `this.checkList = ${JSON.stringify(this.checkList)}`); + for (let i = 0; i < this.checkList.length; i++) { + if (this.checkList[i]) { + let fileModel = this.fileData.getData(i); + logger.info(TAG, `fileModel = ${JSON.stringify(fileModel)}`); + fileModel.files.forEach((url: string) => { + let splitUrl = url.split('//')[1].split('/'); + if (splitUrl[splitUrl.length-1] !== '') { + this.checkFile.push(url); + } + }); + } + } + logger.info(TAG, `this.checkFile = ${JSON.stringify(this.checkFile)}`); + if (this.checkFile.length === 0) { + promptAction.showToast({ message: $r('app.string.check_file_tips'), bottom: TOAST_BOTTOM }); + return; + } + this.progress = 0; + logger.info(TAG, `this.isBackground = ${JSON.stringify(this.isBackground)}`); + if (this.isBackground) { + this.isRunning = false; + this.backDownTaskState = BackgroundTaskState.RUNNING; + requestDownload.downloadFilesBackground(folder, this.checkFile); + this.checkFile = []; + this.checkList = []; + this.fileData.dataArray.forEach((item: FileModel) => { + this.checkList.push(false); + }) + this.fileData.notifyDataReload(); + promptAction.showToast({ message: $r('app.string.background_task_start'), bottom: TOAST_BOTTOM }); + } else { + this.isRunning = true; + requestDownload.downloadFile(folder, this.checkFile[0], this.downloadFileCallback); + } + } + + downloadFilesCallback = (downloadCount: number, isSuccess: boolean) => { + logger.debug(TAG, 'downloadFilesCallback'); + this.progress = downloadCount; + if (downloadCount === this.checkFile.length) { + this.downloadFinish(isSuccess); + } + } + downloadFileCallback = (progress: number, isSuccess: boolean) => { + logger.debug(TAG, 'downloadFileCallback'); + this.progress = progress; + if (this.progress === 100) { + this.downloadFinish(isSuccess); + } + } + + downloadFinish(isSuccess: boolean) { + logger.debug(TAG, 'downloadFinish'); + this.isRunning = false; + this.checkFile = []; + this.checkList = []; + this.fileData.dataArray.forEach((item: FileModel) => { + this.checkList.push(false); + }) + this.fileData.notifyDataReload(); + let message = isSuccess ? $r('app.string.download_finish') : $r('app.string.download_fail'); + promptAction.showToast({ message: message, bottom: TOAST_BOTTOM }); + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Index.ets index a2ed4f2e8e9a7474c0a19f792de9ef08d864266c..7d201e0a0df57b16a1ce01a946118d59df9abf3b 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Index.ets @@ -1,136 +1,136 @@ -/* - * Copyright (c) 2023 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 notificationManager from '@ohos.notificationManager'; -import router from '@ohos.router'; -import common from '@ohos.app.ability.common'; -import { urlUtils } from '@ohos/uploaddownload'; -import util from '@ohos.util'; - -@Styles -function itemStyle() { - .width('100%') - .height(56) - .padding({ top: 17, bottom: 17, left: 12, right: 12 }) - .backgroundColor(Color.White) - .borderRadius(24) - .margin({ top: 20 }) -} - -@Extend(Text) -function textStyle() { - .fontColor($r('app.color.text_normal')) - .fontWeight(400) - .fontFamily('HarmonyHeiTi') - .fontSize(16) -} - -@Entry -@Component -struct Index { - @StorageLink('isBackground') isBackground: boolean = false; - - aboutToAppear() { - notificationManager.requestEnableNotification(); - } - - build() { - Navigation() { - Scroll() { - Column() { - Row() { - Text($r('app.string.background_tips')) - .textStyle() - Blank() - Toggle({ type: ToggleType.Switch, isOn: this.isBackground }) - .width(40) - .height(24) - .onChange((isOn: boolean) => { - this.isBackground = isOn; - AppStorage.setOrCreate('isBackground', isOn); - }) - } - .itemStyle() - .margin({ top: 20 }) - - Row() { - Text($r('app.string.HFS_tips')) - .textStyle() - Blank() - TextInput() - .width(250) - .height(40) - .margin({left : 20}) - .onChange((val) => urlUtils.saveUrl(getContext(this) as common.UIAbilityContext,val)) - } - - .itemStyle() - .margin({ top: 15 }) - - this.CapabilityView($r('app.media.ic_upload'), $r('app.string.upload'), 'btn_upload', () => { - router.pushUrl({ - url: 'pages/Upload' - }) - }) - this.CapabilityView($r('app.media.ic_download'), $r('app.string.download'), 'btn_download', () => { - router.pushUrl({ - url: 'pages/Download' - }) - }) - this.CapabilityView($r('app.media.ic_certified'), $r('app.string.cert_lock'), 'btn_cert_lock', () => { - router.pushUrl({ - url: 'pages/CertLock' - }) - }) - } - .width('100%') - .margin({ left:-12 }) - } - .padding({ left: 12, right: 6 }) - .height('100%') - .align(Alignment.Top) - } - .width('100%') - .height('100%') - .hideBackButton(true) - .titleMode(NavigationTitleMode.Mini) - .backgroundColor($r('app.color.light_gray')) - .title({ - main: this.getResourceString($r('app.string.EntryAbility_label')), - sub: this.getResourceString($r('app.string.home_tips')) - }) - .padding({ top:5 }) - } - - @Builder - CapabilityView(image: Resource, text: Resource, id: string, onClick: () => void) { - Row() { - Image(image) - .size({ width: 24, height: 24 }) - .objectFit(ImageFit.Cover) - Text(text) - .textStyle() - .margin({ left: 12 }) - } - .itemStyle() - .id(id) - .onClick(onClick) - } - - getResourceString(resource: Resource) { - let context = getContext(this) as common.UIAbilityContext; - return context.resourceManager.getStringSync(resource.id); - } +/* + * Copyright (c) 2023 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 notificationManager from '@ohos.notificationManager'; +import router from '@ohos.router'; +import common from '@ohos.app.ability.common'; +import { urlUtils } from '@ohos/uploaddownload'; +import util from '@ohos.util'; + +@Styles +function itemStyle() { + .width('100%') + .height(56) + .padding({ top: 17, bottom: 17, left: 12, right: 12 }) + .backgroundColor(Color.White) + .borderRadius(24) + .margin({ top: 20 }) +} + +@Extend(Text) +function textStyle() { + .fontColor($r('app.color.text_normal')) + .fontWeight(400) + .fontFamily('HarmonyHeiTi') + .fontSize(16) +} + +@Entry +@Component +struct Index { + @StorageLink('isBackground') isBackground: boolean = false; + + aboutToAppear() { + notificationManager.requestEnableNotification(); + } + + build() { + Navigation() { + Scroll() { + Column() { + Row() { + Text($r('app.string.background_tips')) + .textStyle() + Blank() + Toggle({ type: ToggleType.Switch, isOn: this.isBackground }) + .width(40) + .height(24) + .onChange((isOn: boolean) => { + this.isBackground = isOn; + AppStorage.setOrCreate('isBackground', isOn); + }) + } + .itemStyle() + .margin({ top: 20 }) + + Row() { + Text($r('app.string.HFS_tips')) + .textStyle() + Blank() + TextInput() + .width(250) + .height(40) + .margin({left : 20}) + .onChange((val) => urlUtils.saveUrl(getContext(this) as common.UIAbilityContext,val)) + } + + .itemStyle() + .margin({ top: 15 }) + + this.CapabilityView($r('app.media.ic_upload'), $r('app.string.upload'), 'btn_upload', () => { + router.pushUrl({ + url: 'pages/Upload' + }) + }) + this.CapabilityView($r('app.media.ic_download'), $r('app.string.download'), 'btn_download', () => { + router.pushUrl({ + url: 'pages/Download' + }) + }) + this.CapabilityView($r('app.media.ic_certified'), $r('app.string.cert_lock'), 'btn_cert_lock', () => { + router.pushUrl({ + url: 'pages/CertLock' + }) + }) + } + .width('100%') + .margin({ left:-12 }) + } + .padding({ left: 12, right: 6 }) + .height('100%') + .align(Alignment.Top) + } + .width('100%') + .height('100%') + .hideBackButton(true) + .titleMode(NavigationTitleMode.Mini) + .backgroundColor($r('app.color.light_gray')) + .title({ + main: this.getResourceString($r('app.string.EntryAbility_label')), + sub: this.getResourceString($r('app.string.home_tips')) + }) + .padding({ top:5 }) + } + + @Builder + CapabilityView(image: Resource, text: Resource, id: string, onClick: () => void) { + Row() { + Image(image) + .size({ width: 24, height: 24 }) + .objectFit(ImageFit.Cover) + Text(text) + .textStyle() + .margin({ left: 12 }) + } + .itemStyle() + .id(id) + .onClick(onClick) + } + + getResourceString(resource: Resource) { + let context = getContext(this) as common.UIAbilityContext; + return context.resourceManager.getStringSync(resource.id); + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Upload.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Upload.ets index 33bb2eb4adad8c8e5493bfcba1eff8c30e5d6f67..be9defe7129716335dd094a7e2b93c926b81161b 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Upload.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/ets/pages/Upload.ets @@ -1,246 +1,246 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import fs from '@ohos.file.fs'; -import promptAction from '@ohos.promptAction'; -import { AddPictures } from '../components/AddPictures'; -import { ConfigFileChunkDialog } from '../components/ConfigFileChunkDialog'; -import { BackgroundTaskState, requestUpload, logger, TOAST_BOTTOM, NO_IMAGE_SELECTED } from '@ohos/uploaddownload'; - -const TIME_MAX: number = 5; -const TAG: string = 'UploadSample'; - -@Entry -@Component -struct Upload { - @StorageLink('isBackground') isBackground: boolean = false; - @StorageLink('backTaskState') @Watch('stateChange') backTaskState: BackgroundTaskState = BackgroundTaskState.NONE; - @State isBegin: boolean = false; - @Provide imageList: Array = []; - @State progress: number = 0; - @State countdown: number = 0; - @Provide @Watch('onChunkImgIndexChange') chunkImgIndex: number = NO_IMAGE_SELECTED; - @Provide chunkInputEnable: boolean = false; - @Provide chunkParaBegins: number = 0; - @Provide chunkParaEnds: number = -1; - chunkDialog: CustomDialogController = new CustomDialogController({ - builder: ConfigFileChunkDialog({ - upload: this.uploadFiles - }), - alignment: DialogAlignment.Bottom, - offset: { dx: 0, dy: -12 }, - cancel: this.onChunkDiaglogCancel - }); - - build() { - Navigation() { - Scroll() { - AddPictures() - } - .padding({ left: 24, right: 24 }) - .width('100%') - .layoutWeight(1) - .align(Alignment.Top) - .margin({ bottom: 24 }) - - Column() { - Button() { - if (this.isBackground && this.backTaskState !== BackgroundTaskState.NONE) { - if (this.backTaskState === BackgroundTaskState.RUNNING) { - Text($r('app.string.pause')) - .fontSize(16) - .fontWeight(500) - .fontColor($r('app.color.white')) - } else { - Text($r('app.string.continue')) - .fontSize(16) - .fontWeight(500) - .fontColor($r('app.color.white')) - } - } else if (this.isBegin && !this.isBackground) { - Row() { - Progress({ value: this.progress, type: ProgressType.Ring }) - .width(20) - .height(20) - .backgroundColor('#FFFFFF') - .color('#558DFF') - .style({ strokeWidth: 2, scaleCount: 100, scaleWidth: 2 }) - Text(`${this.getResourceString($r('app.string.uploading'))}${this.progress}%`) - .fontSize(16) - .fontColor(0xffffff) - .fontWeight(500) - .margin({ left: 12 }) - }.alignItems(VerticalAlign.Center) - } else { - if (this.countdown > 0) { - Text(`${this.countdown}s`) - .fontSize(16) - .fontWeight(500) - .fontColor($r('app.color.white')) - } else { - Text($r('app.string.upload')) - .fontSize(16) - .fontWeight(500) - .fontColor($r('app.color.white')) - } - } - } - .id('publish') - .width('100%') - .height(40) - .margin({ bottom: this.isBegin ? 16 : 24 }) - .enabled(this.countdown > 0 ? false : true) - .backgroundColor($r('app.color.button_blue')) - .onClick(() => { - if (this.isBackground && this.backTaskState !== BackgroundTaskState.NONE) { - requestUpload.pauseOrResume(); - } else { - this.uploadFiles(); - } - }) - - if (this.isBegin) { - Button() { - Text($r('app.string.cancel')) - .fontSize(16) - .fontWeight(500) - .fontColor($r('app.color.btn_text_blue')) - } - .id('cancel') - .width('100%') - .height(40) - .margin({ bottom: 24 }) - .backgroundColor($r('app.color.button_light_gray')) - .onClick(() => { - // 取消上传任务 - requestUpload.cancelTask(); - this.progress = 0; - this.isBegin = false; - }) - } - } - .width('100%') - .padding({ left: 24, right: 24 }) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.light_gray')) - .title($r('app.string.upload')) - .hideBackButton(false) - .titleMode(NavigationTitleMode.Mini) - .mode(NavigationMode.Stack) - } - - aboutToAppear() { - logger.debug(TAG, 'aboutToAppear'); - this.isBegin = false; - this.backTaskState = BackgroundTaskState.NONE; - } - - stateChange() { - logger.debug(TAG, 'stateChange'); - if (this.backTaskState === BackgroundTaskState.NONE) { - this.imageList = []; - } - } - - uploadFiles() { - logger.debug(TAG, 'uploadFiles'); - if (this.imageList.length == 0) { - return; - } - - if (this.chunkInputEnable) { // 选中checkbox,从该文件分段上传 - this.isBegin = true; - this.progress = 0; - let index = this.chunkImgIndex; - let fileUris = this.imageList.slice(index); - console.debug(TAG + 'fileuri:' + fileUris); - requestUpload.uploadFileChunk(fileUris, this.chunkParaBegins, this.chunkParaEnds, (progress: number, isSucceed: boolean) => { - this.progress = progress; - if (this.progress === 100 && isSucceed) { - this.isBegin = false; - this.imageList = this.imageList.slice(0, index); - promptAction.showToast({ message: $r('app.string.upload_success'), bottom: TOAST_BOTTOM }); - } - if (this.progress === 100 && isSucceed === false) { - this.isBegin = false; - this.countdown = TIME_MAX; - let interval = setInterval(() => { - if (this.countdown > 0) { - this.countdown--; - } else { - clearInterval(interval); - } - }, 1000); - promptAction.showToast({ message: $r('app.string.upload_fail'), bottom: TOAST_BOTTOM }); - } - }); - return; - } - console.debug(TAG + ':imageList:' + this.imageList); - if (this.isBackground) { - AppStorage.setOrCreate('backTaskState', BackgroundTaskState.RUNNING); - requestUpload.uploadFilesBackground(this.imageList); - promptAction.showToast({ message: $r('app.string.background_task_start'), bottom: TOAST_BOTTOM }); - } else { - this.isBegin = true; - this.progress = 0; - requestUpload.uploadFiles(this.imageList, (progress: number, isSucceed: boolean) => { - this.progress = progress; - if (this.progress === 100 && isSucceed) { - this.isBegin = false; - this.imageList = []; - promptAction.showToast({ message: $r('app.string.upload_success'), bottom: TOAST_BOTTOM }) - } - if (this.progress === 100 && isSucceed === false) { - this.isBegin = false; - this.countdown = TIME_MAX; - let interval = setInterval(() => { - if (this.countdown > 0) { - this.countdown--; - } else { - clearInterval(interval); - } - }, 1000); - promptAction.showToast({ message: $r('app.string.upload_fail'), bottom: TOAST_BOTTOM }) - } - }); - } - } - - getResourceString(resource: Resource) { - let context = getContext(this) as common.UIAbilityContext; - let res = context.resourceManager.getStringSync(resource.id); - logger.debug(TAG + ':****' + res); - return res; - } - - onChunkImgIndexChange(propName: string) { - logger.debug(TAG, 'onChunkImgIndexChange'); - if (this.chunkImgIndex != NO_IMAGE_SELECTED) { - this.chunkDialog.open(); - } - this.chunkInputEnable = false; - this.chunkParaBegins = 0; - this.chunkParaEnds = -1; - } - - onChunkDiaglogCancel() { - logger.debug(TAG, 'onChunkDiaglogCancel'); - this.chunkImgIndex = NO_IMAGE_SELECTED; - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import fs from '@ohos.file.fs'; +import promptAction from '@ohos.promptAction'; +import { AddPictures } from '../components/AddPictures'; +import { ConfigFileChunkDialog } from '../components/ConfigFileChunkDialog'; +import { BackgroundTaskState, requestUpload, logger, TOAST_BOTTOM, NO_IMAGE_SELECTED } from '@ohos/uploaddownload'; + +const TIME_MAX: number = 5; +const TAG: string = 'UploadSample'; + +@Entry +@Component +struct Upload { + @StorageLink('isBackground') isBackground: boolean = false; + @StorageLink('backTaskState') @Watch('stateChange') backTaskState: BackgroundTaskState = BackgroundTaskState.NONE; + @State isBegin: boolean = false; + @Provide imageList: Array = []; + @State progress: number = 0; + @State countdown: number = 0; + @Provide @Watch('onChunkImgIndexChange') chunkImgIndex: number = NO_IMAGE_SELECTED; + @Provide chunkInputEnable: boolean = false; + @Provide chunkParaBegins: number = 0; + @Provide chunkParaEnds: number = -1; + chunkDialog: CustomDialogController = new CustomDialogController({ + builder: ConfigFileChunkDialog({ + upload: this.uploadFiles + }), + alignment: DialogAlignment.Bottom, + offset: { dx: 0, dy: -12 }, + cancel: this.onChunkDiaglogCancel + }); + + build() { + Navigation() { + Scroll() { + AddPictures() + } + .padding({ left: 24, right: 24 }) + .width('100%') + .layoutWeight(1) + .align(Alignment.Top) + .margin({ bottom: 24 }) + + Column() { + Button() { + if (this.isBackground && this.backTaskState !== BackgroundTaskState.NONE) { + if (this.backTaskState === BackgroundTaskState.RUNNING) { + Text($r('app.string.pause')) + .fontSize(16) + .fontWeight(500) + .fontColor($r('app.color.white')) + } else { + Text($r('app.string.continue')) + .fontSize(16) + .fontWeight(500) + .fontColor($r('app.color.white')) + } + } else if (this.isBegin && !this.isBackground) { + Row() { + Progress({ value: this.progress, type: ProgressType.Ring }) + .width(20) + .height(20) + .backgroundColor('#FFFFFF') + .color('#558DFF') + .style({ strokeWidth: 2, scaleCount: 100, scaleWidth: 2 }) + Text(`${this.getResourceString($r('app.string.uploading'))}${this.progress}%`) + .fontSize(16) + .fontColor(0xffffff) + .fontWeight(500) + .margin({ left: 12 }) + }.alignItems(VerticalAlign.Center) + } else { + if (this.countdown > 0) { + Text(`${this.countdown}s`) + .fontSize(16) + .fontWeight(500) + .fontColor($r('app.color.white')) + } else { + Text($r('app.string.upload')) + .fontSize(16) + .fontWeight(500) + .fontColor($r('app.color.white')) + } + } + } + .id('publish') + .width('100%') + .height(40) + .margin({ bottom: this.isBegin ? 16 : 24 }) + .enabled(this.countdown > 0 ? false : true) + .backgroundColor($r('app.color.button_blue')) + .onClick(() => { + if (this.isBackground && this.backTaskState !== BackgroundTaskState.NONE) { + requestUpload.pauseOrResume(); + } else { + this.uploadFiles(); + } + }) + + if (this.isBegin) { + Button() { + Text($r('app.string.cancel')) + .fontSize(16) + .fontWeight(500) + .fontColor($r('app.color.btn_text_blue')) + } + .id('cancel') + .width('100%') + .height(40) + .margin({ bottom: 24 }) + .backgroundColor($r('app.color.button_light_gray')) + .onClick(() => { + // 取消上传任务 + requestUpload.cancelTask(); + this.progress = 0; + this.isBegin = false; + }) + } + } + .width('100%') + .padding({ left: 24, right: 24 }) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.light_gray')) + .title($r('app.string.upload')) + .hideBackButton(false) + .titleMode(NavigationTitleMode.Mini) + .mode(NavigationMode.Stack) + } + + aboutToAppear() { + logger.debug(TAG, 'aboutToAppear'); + this.isBegin = false; + this.backTaskState = BackgroundTaskState.NONE; + } + + stateChange() { + logger.debug(TAG, 'stateChange'); + if (this.backTaskState === BackgroundTaskState.NONE) { + this.imageList = []; + } + } + + uploadFiles() { + logger.debug(TAG, 'uploadFiles'); + if (this.imageList.length == 0) { + return; + } + + if (this.chunkInputEnable) { // 选中checkbox,从该文件分段上传 + this.isBegin = true; + this.progress = 0; + let index = this.chunkImgIndex; + let fileUris = this.imageList.slice(index); + console.debug(TAG + 'fileuri:' + fileUris); + requestUpload.uploadFileChunk(fileUris, this.chunkParaBegins, this.chunkParaEnds, (progress: number, isSucceed: boolean) => { + this.progress = progress; + if (this.progress === 100 && isSucceed) { + this.isBegin = false; + this.imageList = this.imageList.slice(0, index); + promptAction.showToast({ message: $r('app.string.upload_success'), bottom: TOAST_BOTTOM }); + } + if (this.progress === 100 && isSucceed === false) { + this.isBegin = false; + this.countdown = TIME_MAX; + let interval = setInterval(() => { + if (this.countdown > 0) { + this.countdown--; + } else { + clearInterval(interval); + } + }, 1000); + promptAction.showToast({ message: $r('app.string.upload_fail'), bottom: TOAST_BOTTOM }); + } + }); + return; + } + console.debug(TAG + ':imageList:' + this.imageList); + if (this.isBackground) { + AppStorage.setOrCreate('backTaskState', BackgroundTaskState.RUNNING); + requestUpload.uploadFilesBackground(this.imageList); + promptAction.showToast({ message: $r('app.string.background_task_start'), bottom: TOAST_BOTTOM }); + } else { + this.isBegin = true; + this.progress = 0; + requestUpload.uploadFiles(this.imageList, (progress: number, isSucceed: boolean) => { + this.progress = progress; + if (this.progress === 100 && isSucceed) { + this.isBegin = false; + this.imageList = []; + promptAction.showToast({ message: $r('app.string.upload_success'), bottom: TOAST_BOTTOM }) + } + if (this.progress === 100 && isSucceed === false) { + this.isBegin = false; + this.countdown = TIME_MAX; + let interval = setInterval(() => { + if (this.countdown > 0) { + this.countdown--; + } else { + clearInterval(interval); + } + }, 1000); + promptAction.showToast({ message: $r('app.string.upload_fail'), bottom: TOAST_BOTTOM }) + } + }); + } + } + + getResourceString(resource: Resource) { + let context = getContext(this) as common.UIAbilityContext; + let res = context.resourceManager.getStringSync(resource.id); + logger.debug(TAG + ':****' + res); + return res; + } + + onChunkImgIndexChange(propName: string) { + logger.debug(TAG, 'onChunkImgIndexChange'); + if (this.chunkImgIndex != NO_IMAGE_SELECTED) { + this.chunkDialog.open(); + } + this.chunkInputEnable = false; + this.chunkParaBegins = 0; + this.chunkParaEnds = -1; + } + + onChunkDiaglogCancel() { + logger.debug(TAG, 'onChunkDiaglogCancel'); + this.chunkImgIndex = NO_IMAGE_SELECTED; + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/color.json index c11c9fb28463f284c8e19aca39faf9ce31a12b44..123baf3b97b69c545c97d196af63d233e37eddfa 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/color.json @@ -1,44 +1,44 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "text_normal", - "value": "#182431" - }, - { - "name": "button_light_gray", - "value": "#0C182431" - }, - { - "name": "button_blue", - "value": "#007DFF" - }, - { - "name": "btn_text_blue", - "value": "#007DFF" - }, - { - "name": "maskColor", - "value": "#66182431" - }, - { - "name": "white", - "value": "#FFFFFF" - }, - { - "name": "gray", - "value": "#F7F7F7" - }, - { - "name": "light_gray", - "value": "#F1F3F5" - }, - { - "name": "text_message", - "value": "#99182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "text_normal", + "value": "#182431" + }, + { + "name": "button_light_gray", + "value": "#0C182431" + }, + { + "name": "button_blue", + "value": "#007DFF" + }, + { + "name": "btn_text_blue", + "value": "#007DFF" + }, + { + "name": "maskColor", + "value": "#66182431" + }, + { + "name": "white", + "value": "#FFFFFF" + }, + { + "name": "gray", + "value": "#F7F7F7" + }, + { + "name": "light_gray", + "value": "#F1F3F5" + }, + { + "name": "text_message", + "value": "#99182431" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/string.json b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/string.json index f2f3603345c9a27a841d2e68c39898a5f00ad1d2..2be6aa8fe3d3c44f56eb7daac216e6a0d0757977 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/string.json +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/element/string.json @@ -1,144 +1,144 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "UploadAndDownload" - }, - { - "name": "upload", - "value": "Upload" - }, - { - "name": "upload_fail", - "value": "Upload fail,resume upload later" - }, - { - "name": "upload_success", - "value": "Upload success,continue upload" - }, - { - "name": "uploading", - "value": "Uploading" - }, - { - "name": "user_tip", - "value": "Feature development" - }, - { - "name": "open", - "value": "Open" - }, - { - "name": "anyone", - "value": "Anyone" - }, - { - "name": "gps", - "value": "Location" - }, - { - "name": "tip", - "value": "Thoughts of the moment..." - }, - { - "name": "pick_album", - "value": "Pick from album" - }, - { - "name": "ok", - "value": "OK" - }, - { - "name": "cancel", - "value": "Cancel" - }, - { - "name": "check_file_tips", - "value": "Please check files" - }, - { - "name": "download", - "value": "Download" - }, - { - "name": "download_to", - "value": "Select a download location" - }, - { - "name": "view_download_files", - "value": "View download files" - }, - { - "name": "download_finish", - "value": "Download finish" - }, - { - "name": "download_fail", - "value": "Download fail" - }, - { - "name": "pause", - "value": "Pause" - }, - { - "name": "downloading", - "value": "Downloading" - }, - { - "name": "continue", - "value": "Continue" - }, - { - "name": "media_permission", - "value": "Allows the app to read media file information from the user's external storage" - }, - { - "name": "media_internet_permission", - "value": "Allow access to the network" - }, - { - "name": "background_tips", - "value": "Whether to start background tasks" - }, - { - "name": "HFS_tips", - "value": "HFS Address" - }, - { - "name": "home_tips", - "value": "Demonstrate foreground and background upload and download tasks" - }, - { - "name": "background_task_start", - "value": "The background task has started, and you can check the download status in the notification bar" - }, - { - "name": "chunk_checkbox_tips", - "value": "Upload from this file's chunk" - }, - { - "name": "chunk_begins", - "value": "Null, input the value which uploading from the certain byte" - }, - { - "name": "chunk_ends", - "value": "Null, input the value which uploading to the certain byte" - }, - { - "name": "chunk_para_invalid", - "value": "Begins or Ends is invalid" - }, - { - "name": "cert_lock", - "value": "Cert lock" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "UploadAndDownload" + }, + { + "name": "upload", + "value": "Upload" + }, + { + "name": "upload_fail", + "value": "Upload fail,resume upload later" + }, + { + "name": "upload_success", + "value": "Upload success,continue upload" + }, + { + "name": "uploading", + "value": "Uploading" + }, + { + "name": "user_tip", + "value": "Feature development" + }, + { + "name": "open", + "value": "Open" + }, + { + "name": "anyone", + "value": "Anyone" + }, + { + "name": "gps", + "value": "Location" + }, + { + "name": "tip", + "value": "Thoughts of the moment..." + }, + { + "name": "pick_album", + "value": "Pick from album" + }, + { + "name": "ok", + "value": "OK" + }, + { + "name": "cancel", + "value": "Cancel" + }, + { + "name": "check_file_tips", + "value": "Please check files" + }, + { + "name": "download", + "value": "Download" + }, + { + "name": "download_to", + "value": "Select a download location" + }, + { + "name": "view_download_files", + "value": "View download files" + }, + { + "name": "download_finish", + "value": "Download finish" + }, + { + "name": "download_fail", + "value": "Download fail" + }, + { + "name": "pause", + "value": "Pause" + }, + { + "name": "downloading", + "value": "Downloading" + }, + { + "name": "continue", + "value": "Continue" + }, + { + "name": "media_permission", + "value": "Allows the app to read media file information from the user's external storage" + }, + { + "name": "media_internet_permission", + "value": "Allow access to the network" + }, + { + "name": "background_tips", + "value": "Whether to start background tasks" + }, + { + "name": "HFS_tips", + "value": "HFS Address" + }, + { + "name": "home_tips", + "value": "Demonstrate foreground and background upload and download tasks" + }, + { + "name": "background_task_start", + "value": "The background task has started, and you can check the download status in the notification bar" + }, + { + "name": "chunk_checkbox_tips", + "value": "Upload from this file's chunk" + }, + { + "name": "chunk_begins", + "value": "Null, input the value which uploading from the certain byte" + }, + { + "name": "chunk_ends", + "value": "Null, input the value which uploading to the certain byte" + }, + { + "name": "chunk_para_invalid", + "value": "Begins or Ends is invalid" + }, + { + "name": "cert_lock", + "value": "Cert lock" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/main_pages.json index f76da0fb65f7dfc8edd9922a4d60325a7239f631..7f87ebc087ba6e758dbcfd93fb9a0717898e8884 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/main_pages.json +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/main_pages.json @@ -1,9 +1,9 @@ -{ - "src": [ - "pages/Index", - "pages/Upload", - "pages/Download", - "pages/CertLock", - "pages/DownloadFiles" - ] +{ + "src": [ + "pages/Index", + "pages/Upload", + "pages/Download", + "pages/CertLock", + "pages/DownloadFiles" + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/network_config.json b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/network_config.json index 9f8de4095b47ede4c43bf246c68c2176e74bba74..58d3c06a31785e6be2a7ca4552e6c145aa5f418d 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/network_config.json +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/base/profile/network_config.json @@ -1,24 +1,24 @@ -{ - "network-security-config": { - "domain-config": [ - { - "domains": [ - { - "include-subdomains": true, - "name": "www.baidu.com" - } - ], - "trust-anchors": [{"certificates": "/data/storage/el1/bundle/entry/resources/resfile/"}], - "pin-set": { - "expiration": "2025-04-08", - "pin": [ - { - "digest-algorithm": "sha256", - "digest": "g8CsdcpyAKxmLoWFvMd2hC7ZDUy7L4E2NYOi1i8qEtE=" - } - ] - } - } - ] - } +{ + "network-security-config": { + "domain-config": [ + { + "domains": [ + { + "include-subdomains": true, + "name": "www.baidu.com" + } + ], + "trust-anchors": [{"certificates": "/data/storage/el1/bundle/entry/resources/resfile/"}], + "pin-set": { + "expiration": "2025-04-08", + "pin": [ + { + "digest-algorithm": "sha256", + "digest": "g8CsdcpyAKxmLoWFvMd2hC7ZDUy7L4E2NYOi1i8qEtE=" + } + ] + } + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/en_US/element/string.json index 751ab62d304e701efd05b5e01b206a67ef66f67c..d169c649cbf1c453e7a659cad50958b2e4a27cf0 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/en_US/element/string.json +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/en_US/element/string.json @@ -1,144 +1,144 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "UploadAndDownload" - }, - { - "name": "upload", - "value": "Upload" - }, - { - "name": "upload_fail", - "value": "Upload fail,resume upload later" - }, - { - "name": "upload_success", - "value": "Upload success,continue upload" - }, - { - "name": "uploading", - "value": "Uploading" - }, - { - "name": "user_tip", - "value": "Feature development" - }, - { - "name": "open", - "value": "Open" - }, - { - "name": "anyone", - "value": "Anyone" - }, - { - "name": "gps", - "value": "Location" - }, - { - "name": "tip", - "value": "Thoughts of the moment..." - }, - { - "name": "pick_album", - "value": "Pick from album" - }, - { - "name": "ok", - "value": "OK" - }, - { - "name": "cancel", - "value": "Cancel" - }, - { - "name": "check_file_tips", - "value": "Please check files" - }, - { - "name": "download", - "value": "Download" - }, - { - "name": "downloading", - "value": "Downloading" - }, - { - "name": "download_to", - "value": "Select a download location" - }, - { - "name": "view_download_files", - "value": "View download files" - }, - { - "name": "download_finish", - "value": "Download finish" - }, - { - "name": "download_fail", - "value": "Download fail" - }, - { - "name": "pause", - "value": "Pause" - }, - { - "name": "continue", - "value": "Continue" - }, - { - "name": "media_permission", - "value": "Allows the app to read media file information from the user's external storage" - }, - { - "name": "media_internet_permission", - "value": "Allow access to the network" - }, - { - "name": "background_tips", - "value": "Whether to start background tasks" - }, - { - "name": "HFS_tips", - "value": "HFS Address" - }, - { - "name": "home_tips", - "value": "Demonstrate foreground and background upload and download tasks" - }, - { - "name": "background_task_start", - "value": "The background task has started, and you can check the download status in the notification bar" - }, - { - "name": "chunk_checkbox_tips", - "value": "Upload from this file's chunk" - }, - { - "name": "chunk_begins", - "value": "Null, input the value which uploading from the certain byte" - }, - { - "name": "chunk_ends", - "value": "Null, input the value which uploading to the certain byte" - }, - { - "name": "chunk_para_invalid", - "value": "Begins or Ends is invalid" - }, - { - "name": "cert_lock", - "value": "Cert lock" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "UploadAndDownload" + }, + { + "name": "upload", + "value": "Upload" + }, + { + "name": "upload_fail", + "value": "Upload fail,resume upload later" + }, + { + "name": "upload_success", + "value": "Upload success,continue upload" + }, + { + "name": "uploading", + "value": "Uploading" + }, + { + "name": "user_tip", + "value": "Feature development" + }, + { + "name": "open", + "value": "Open" + }, + { + "name": "anyone", + "value": "Anyone" + }, + { + "name": "gps", + "value": "Location" + }, + { + "name": "tip", + "value": "Thoughts of the moment..." + }, + { + "name": "pick_album", + "value": "Pick from album" + }, + { + "name": "ok", + "value": "OK" + }, + { + "name": "cancel", + "value": "Cancel" + }, + { + "name": "check_file_tips", + "value": "Please check files" + }, + { + "name": "download", + "value": "Download" + }, + { + "name": "downloading", + "value": "Downloading" + }, + { + "name": "download_to", + "value": "Select a download location" + }, + { + "name": "view_download_files", + "value": "View download files" + }, + { + "name": "download_finish", + "value": "Download finish" + }, + { + "name": "download_fail", + "value": "Download fail" + }, + { + "name": "pause", + "value": "Pause" + }, + { + "name": "continue", + "value": "Continue" + }, + { + "name": "media_permission", + "value": "Allows the app to read media file information from the user's external storage" + }, + { + "name": "media_internet_permission", + "value": "Allow access to the network" + }, + { + "name": "background_tips", + "value": "Whether to start background tasks" + }, + { + "name": "HFS_tips", + "value": "HFS Address" + }, + { + "name": "home_tips", + "value": "Demonstrate foreground and background upload and download tasks" + }, + { + "name": "background_task_start", + "value": "The background task has started, and you can check the download status in the notification bar" + }, + { + "name": "chunk_checkbox_tips", + "value": "Upload from this file's chunk" + }, + { + "name": "chunk_begins", + "value": "Null, input the value which uploading from the certain byte" + }, + { + "name": "chunk_ends", + "value": "Null, input the value which uploading to the certain byte" + }, + { + "name": "chunk_para_invalid", + "value": "Begins or Ends is invalid" + }, + { + "name": "cert_lock", + "value": "Cert lock" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/zh_CN/element/string.json index 94ea0de964e570fad3648c6e35964bb2f15a1e72..dafe8357696d0b8e2f6d5523f1be64a11c74d5f4 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/zh_CN/element/string.json +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/entry/src/main/resources/zh_CN/element/string.json @@ -1,144 +1,144 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "上传下载" - }, - { - "name": "upload", - "value": "上传" - }, - { - "name": "upload_fail", - "value": "上传失败,稍后继续上传" - }, - { - "name": "upload_success", - "value": "上传成功,继续上传" - }, - { - "name": "uploading", - "value": "已上传" - }, - { - "name": "user_tip", - "value": "功能开发中" - }, - { - "name": "open", - "value": "公开" - }, - { - "name": "anyone", - "value": "谁可以看" - }, - { - "name": "gps", - "value": "所在位置" - }, - { - "name": "tip", - "value": "这一刻的想法..." - }, - { - "name": "pick_album", - "value": "从相册选择" - }, - { - "name": "ok", - "value": "确定" - }, - { - "name": "cancel", - "value": "取消" - }, - { - "name": "check_file_tips", - "value": "请选择文件" - }, - { - "name": "download", - "value": "下载" - }, - { - "name": "downloading", - "value": "已下载" - }, - { - "name": "view_download_files", - "value": "查看下载文件" - }, - { - "name": "download_to", - "value": "选择下载位置" - }, - { - "name": "download_finish", - "value": "下载完成" - }, - { - "name": "download_fail", - "value": "下载失败" - }, - { - "name": "pause", - "value": "暂停" - }, - { - "name": "continue", - "value": "继续" - }, - { - "name": "media_permission", - "value": "允许应用读取用户外部存储中的媒体文件信息" - }, - { - "name": "media_internet_permission", - "value": "允许访问网络" - }, - { - "name": "background_tips", - "value": "是否开启后台任务" - }, - { - "name": "HFS_tips", - "value": "HFS 地址" - }, - { - "name": "home_tips", - "value": "演示前台和后台上传和下载任务" - }, - { - "name": "background_task_start", - "value": "后台任务已开始,可在通知栏查看下载状态" - }, - { - "name": "chunk_checkbox_tips", - "value": "从当前文件开始片段上传" - }, - { - "name": "chunk_begins", - "value": "空,填入任意数值,表示从某字节开始上传该文件" - }, - { - "name": "chunk_ends", - "value": "空,填入任意数值,表示从某字节结束上传该文件" - }, - { - "name": "chunk_para_invalid", - "value": "Begins 或 Ends 无效" - }, - { - "name": "cert_lock", - "value": "证书锁定" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "上传下载" + }, + { + "name": "upload", + "value": "上传" + }, + { + "name": "upload_fail", + "value": "上传失败,稍后继续上传" + }, + { + "name": "upload_success", + "value": "上传成功,继续上传" + }, + { + "name": "uploading", + "value": "已上传" + }, + { + "name": "user_tip", + "value": "功能开发中" + }, + { + "name": "open", + "value": "公开" + }, + { + "name": "anyone", + "value": "谁可以看" + }, + { + "name": "gps", + "value": "所在位置" + }, + { + "name": "tip", + "value": "这一刻的想法..." + }, + { + "name": "pick_album", + "value": "从相册选择" + }, + { + "name": "ok", + "value": "确定" + }, + { + "name": "cancel", + "value": "取消" + }, + { + "name": "check_file_tips", + "value": "请选择文件" + }, + { + "name": "download", + "value": "下载" + }, + { + "name": "downloading", + "value": "已下载" + }, + { + "name": "view_download_files", + "value": "查看下载文件" + }, + { + "name": "download_to", + "value": "选择下载位置" + }, + { + "name": "download_finish", + "value": "下载完成" + }, + { + "name": "download_fail", + "value": "下载失败" + }, + { + "name": "pause", + "value": "暂停" + }, + { + "name": "continue", + "value": "继续" + }, + { + "name": "media_permission", + "value": "允许应用读取用户外部存储中的媒体文件信息" + }, + { + "name": "media_internet_permission", + "value": "允许访问网络" + }, + { + "name": "background_tips", + "value": "是否开启后台任务" + }, + { + "name": "HFS_tips", + "value": "HFS 地址" + }, + { + "name": "home_tips", + "value": "演示前台和后台上传和下载任务" + }, + { + "name": "background_task_start", + "value": "后台任务已开始,可在通知栏查看下载状态" + }, + { + "name": "chunk_checkbox_tips", + "value": "从当前文件开始片段上传" + }, + { + "name": "chunk_begins", + "value": "空,填入任意数值,表示从某字节开始上传该文件" + }, + { + "name": "chunk_ends", + "value": "空,填入任意数值,表示从某字节结束上传该文件" + }, + { + "name": "chunk_para_invalid", + "value": "Begins 或 Ends 无效" + }, + { + "name": "cert_lock", + "value": "证书锁定" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/download/RequestDownload.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/download/RequestDownload.ets index 4c58ce38c62dbc61c13e7468a701277fd0721275..19f6715ce2f348e58e683d692a70cc377a9bec29 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/download/RequestDownload.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/download/RequestDownload.ets @@ -1,227 +1,227 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import request from '@ohos.request'; -import promptAction from '@ohos.promptAction'; -import { logger } from '../utils/Logger'; -import { BackgroundTaskState, TASK_MAX, TOAST_BOTTOM } from '../utils/Constants'; - -const TAG: string = 'RequestDownload'; - -class RequestDownload { - private context: common.UIAbilityContext | undefined = undefined; - private waitList: Array = []; - private downloadTask: request.agent.Task | undefined = undefined; - private backgroundDownloadTaskList: Array = []; - - constructor() { - setInterval(() => { - this.flushBackgroundTask() - }, 2000); - } - - async downloadFilesBackground(folder: string, files: Array) { - logger.info(TAG, 'downloadFiles'); - this.context = getContext(this) as common.UIAbilityContext; - files.forEach((item: string) => { - this.waitList.push([folder, item]); - }); - } - - async flushBackgroundTask() { - let tasks = await request.agent.search({ - state: request.agent.State.RUNNING - }); - if (tasks.length < TASK_MAX && this.waitList.length > 0) { - let downloadList: Array = []; - if (this.waitList.length <= TASK_MAX - tasks.length) { - downloadList = this.waitList; - this.waitList = []; - } else { - downloadList = this.waitList.slice(0, TASK_MAX - tasks.length); - this.waitList = this.waitList.slice(TASK_MAX - tasks.length, this.waitList.length); - } - logger.info(TAG, `this.waitList = ${JSON.stringify(this.waitList)}`); - this.createBackgroundTask(downloadList); - } else { - let state = AppStorage.get('backDownTaskState'); - logger.info(TAG, `backLists = ${this.backgroundDownloadTaskList.map(i => i.tid)}`); - if (state === BackgroundTaskState.RUNNING) { - if (tasks.length === 0) { - AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.NONE); - this.backgroundDownloadTaskList = []; - } - } - } - } - - async createBackgroundTask(downloadList: Array) { - if (this.context === undefined) { - return; - } - for (let i = 0; i < downloadList.length; i++) { - try { - let splitUrl = downloadList[i][1].split('//')[1].split('/'); - let downloadConfig: request.agent.Config = { - action: request.agent.Action.DOWNLOAD, - url: downloadList[i][1], - method: 'POST', - title: 'download', - mode: request.agent.Mode.BACKGROUND, - network: request.agent.Network.ANY, - saveas: `./${downloadList[i][0]}/${splitUrl[splitUrl.length-1]}`, - overwrite: true, - gauge: true - } - let downTask = await request.agent.create(this.context, downloadConfig); - if (this.backgroundDownloadTaskList.findIndex(task => task.config.url === downTask.config.url) === -1) { - this.backgroundDownloadTaskList.push(downTask); - } - await downTask.start(); - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - this.waitList.push(downloadList[i]); - } - } - } - - async downloadFile(folder: string, url: string, callback: (progress: number, isSuccess: boolean) => void) { - logger.info(TAG, 'downloadFile'); - // 查询到存在正在执行的下载任务,提示并返回 - let tasks = await request.agent.search({ - state: request.agent.State.RUNNING, - action: request.agent.Action.DOWNLOAD, - mode: request.agent.Mode.FOREGROUND - }); - if (tasks.length > 0) { - promptAction.showToast({ message: $r('app.string.have_download_task_tips'), bottom: TOAST_BOTTOM }); - return; - } - let splitUrl = url.split('//')[1].split('/'); - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let downloadConfig: request.agent.Config = { - action: request.agent.Action.DOWNLOAD, - url: url, - method: 'POST', - title: 'download', - mode: request.agent.Mode.FOREGROUND, - network: request.agent.Network.ANY, - saveas: `./${folder}/${splitUrl[splitUrl.length-1]}`, - overwrite: true - } - logger.info(TAG, `downloadFile, downloadConfig = ${JSON.stringify(downloadConfig)}`); - try { - this.downloadTask = await request.agent.create(context, downloadConfig); - this.downloadTask.on('progress', (progress: request.agent.Progress) => { - logger.info(TAG, `progress, progress = ${progress.processed} ${progress.state}`); - let processed = Number(progress.processed.toString()).valueOf(); - let size = progress.sizes[0]; - let process: number = Math.floor(processed / size * 100); - if (process < 100) { - callback(process, false); - } - }) - this.downloadTask.on('completed', (progress: request.agent.Progress) => { - logger.info(TAG, `download complete, file= ${url}, progress = ${progress.processed}`); - callback(100, true); - this.deleteTask(); - }) - this.downloadTask.on('failed', async (progress: request.agent.Progress) => { - if (this.downloadTask) { - let taskInfo = await request.agent.show(this.downloadTask.tid); - logger.info(TAG, `fail, resean = ${taskInfo.reason}, faults = ${JSON.stringify(taskInfo.faults)}`); - } - callback(100, false); - this.deleteTask(); - }) - await this.downloadTask.start(); - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - callback(100, false); - } - } - - async pauseOrResume() { - let state = AppStorage.get('backDownTaskState'); - if (state === BackgroundTaskState.RUNNING) { - await this.pause(); - AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.PAUSE); - } else if (state === BackgroundTaskState.PAUSE) { - await this.resume(); - AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.RUNNING); - } else { - logger.info(TAG, 'this task state is error'); - } - } - - async pause() { - logger.info(TAG, 'pause'); - if (this.backgroundDownloadTaskList.length === 0) { - return; - } - try { - this.backgroundDownloadTaskList.forEach(async task => { - await task.pause(); - }) - } catch (err) { - logger.info(TAG, `pause fail,err= ${JSON.stringify(err)}`); - } - } - - async resume() { - logger.info(TAG, 'resume'); - if (this.backgroundDownloadTaskList.length === 0) { - return; - } - try { - this.backgroundDownloadTaskList.forEach(async task => { - await task.resume(); - }) - } catch (err) { - logger.info(TAG, `resume fail,err= ${JSON.stringify(err)}`); - } - } - - async deleteTask() { - if (this.downloadTask) { - try { - this.downloadTask.off('progress'); - this.downloadTask.off('completed'); - this.downloadTask.off('failed'); - await request.agent.remove(this.downloadTask.tid); - } catch (err) { - logger.info(TAG, `deleteTask fail, err= ${JSON.stringify(err)}`); - } - } - this.downloadTask = undefined; - } - - async deleteAllBackTasks() { - if (this.backgroundDownloadTaskList.length > 0) { - try { - this.backgroundDownloadTaskList.forEach(async task => { - await request.agent.remove(task.tid); - }) - this.backgroundDownloadTaskList = []; - AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.NONE); - } catch (err) { - logger.info(TAG, `deleteAllTask fail, err= ${JSON.stringify(err)}`); - } - } - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import request from '@ohos.request'; +import promptAction from '@ohos.promptAction'; +import { logger } from '../utils/Logger'; +import { BackgroundTaskState, TASK_MAX, TOAST_BOTTOM } from '../utils/Constants'; + +const TAG: string = 'RequestDownload'; + +class RequestDownload { + private context: common.UIAbilityContext | undefined = undefined; + private waitList: Array = []; + private downloadTask: request.agent.Task | undefined = undefined; + private backgroundDownloadTaskList: Array = []; + + constructor() { + setInterval(() => { + this.flushBackgroundTask() + }, 2000); + } + + async downloadFilesBackground(folder: string, files: Array) { + logger.info(TAG, 'downloadFiles'); + this.context = getContext(this) as common.UIAbilityContext; + files.forEach((item: string) => { + this.waitList.push([folder, item]); + }); + } + + async flushBackgroundTask() { + let tasks = await request.agent.search({ + state: request.agent.State.RUNNING + }); + if (tasks.length < TASK_MAX && this.waitList.length > 0) { + let downloadList: Array = []; + if (this.waitList.length <= TASK_MAX - tasks.length) { + downloadList = this.waitList; + this.waitList = []; + } else { + downloadList = this.waitList.slice(0, TASK_MAX - tasks.length); + this.waitList = this.waitList.slice(TASK_MAX - tasks.length, this.waitList.length); + } + logger.info(TAG, `this.waitList = ${JSON.stringify(this.waitList)}`); + this.createBackgroundTask(downloadList); + } else { + let state = AppStorage.get('backDownTaskState'); + logger.info(TAG, `backLists = ${this.backgroundDownloadTaskList.map(i => i.tid)}`); + if (state === BackgroundTaskState.RUNNING) { + if (tasks.length === 0) { + AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.NONE); + this.backgroundDownloadTaskList = []; + } + } + } + } + + async createBackgroundTask(downloadList: Array) { + if (this.context === undefined) { + return; + } + for (let i = 0; i < downloadList.length; i++) { + try { + let splitUrl = downloadList[i][1].split('//')[1].split('/'); + let downloadConfig: request.agent.Config = { + action: request.agent.Action.DOWNLOAD, + url: downloadList[i][1], + method: 'POST', + title: 'download', + mode: request.agent.Mode.BACKGROUND, + network: request.agent.Network.ANY, + saveas: `./${downloadList[i][0]}/${splitUrl[splitUrl.length-1]}`, + overwrite: true, + gauge: true + } + let downTask = await request.agent.create(this.context, downloadConfig); + if (this.backgroundDownloadTaskList.findIndex(task => task.config.url === downTask.config.url) === -1) { + this.backgroundDownloadTaskList.push(downTask); + } + await downTask.start(); + } catch (err) { + logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); + this.waitList.push(downloadList[i]); + } + } + } + + async downloadFile(folder: string, url: string, callback: (progress: number, isSuccess: boolean) => void) { + logger.info(TAG, 'downloadFile'); + // 查询到存在正在执行的下载任务,提示并返回 + let tasks = await request.agent.search({ + state: request.agent.State.RUNNING, + action: request.agent.Action.DOWNLOAD, + mode: request.agent.Mode.FOREGROUND + }); + if (tasks.length > 0) { + promptAction.showToast({ message: $r('app.string.have_download_task_tips'), bottom: TOAST_BOTTOM }); + return; + } + let splitUrl = url.split('//')[1].split('/'); + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let downloadConfig: request.agent.Config = { + action: request.agent.Action.DOWNLOAD, + url: url, + method: 'POST', + title: 'download', + mode: request.agent.Mode.FOREGROUND, + network: request.agent.Network.ANY, + saveas: `./${folder}/${splitUrl[splitUrl.length-1]}`, + overwrite: true + } + logger.info(TAG, `downloadFile, downloadConfig = ${JSON.stringify(downloadConfig)}`); + try { + this.downloadTask = await request.agent.create(context, downloadConfig); + this.downloadTask.on('progress', (progress: request.agent.Progress) => { + logger.info(TAG, `progress, progress = ${progress.processed} ${progress.state}`); + let processed = Number(progress.processed.toString()).valueOf(); + let size = progress.sizes[0]; + let process: number = Math.floor(processed / size * 100); + if (process < 100) { + callback(process, false); + } + }) + this.downloadTask.on('completed', (progress: request.agent.Progress) => { + logger.info(TAG, `download complete, file= ${url}, progress = ${progress.processed}`); + callback(100, true); + this.deleteTask(); + }) + this.downloadTask.on('failed', async (progress: request.agent.Progress) => { + if (this.downloadTask) { + let taskInfo = await request.agent.show(this.downloadTask.tid); + logger.info(TAG, `fail, resean = ${taskInfo.reason}, faults = ${JSON.stringify(taskInfo.faults)}`); + } + callback(100, false); + this.deleteTask(); + }) + await this.downloadTask.start(); + } catch (err) { + logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); + callback(100, false); + } + } + + async pauseOrResume() { + let state = AppStorage.get('backDownTaskState'); + if (state === BackgroundTaskState.RUNNING) { + await this.pause(); + AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.PAUSE); + } else if (state === BackgroundTaskState.PAUSE) { + await this.resume(); + AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.RUNNING); + } else { + logger.info(TAG, 'this task state is error'); + } + } + + async pause() { + logger.info(TAG, 'pause'); + if (this.backgroundDownloadTaskList.length === 0) { + return; + } + try { + this.backgroundDownloadTaskList.forEach(async task => { + await task.pause(); + }) + } catch (err) { + logger.info(TAG, `pause fail,err= ${JSON.stringify(err)}`); + } + } + + async resume() { + logger.info(TAG, 'resume'); + if (this.backgroundDownloadTaskList.length === 0) { + return; + } + try { + this.backgroundDownloadTaskList.forEach(async task => { + await task.resume(); + }) + } catch (err) { + logger.info(TAG, `resume fail,err= ${JSON.stringify(err)}`); + } + } + + async deleteTask() { + if (this.downloadTask) { + try { + this.downloadTask.off('progress'); + this.downloadTask.off('completed'); + this.downloadTask.off('failed'); + await request.agent.remove(this.downloadTask.tid); + } catch (err) { + logger.info(TAG, `deleteTask fail, err= ${JSON.stringify(err)}`); + } + } + this.downloadTask = undefined; + } + + async deleteAllBackTasks() { + if (this.backgroundDownloadTaskList.length > 0) { + try { + this.backgroundDownloadTaskList.forEach(async task => { + await request.agent.remove(task.tid); + }) + this.backgroundDownloadTaskList = []; + AppStorage.setOrCreate('backDownTaskState', BackgroundTaskState.NONE); + } catch (err) { + logger.info(TAG, `deleteAllTask fail, err= ${JSON.stringify(err)}`); + } + } + } +} + export const requestDownload = new RequestDownload(); \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets index 4f97c704188e47a04707896f21e12b078ec0896b..9c5201fe4b90879ff7f524f8729660b7d37b5a06 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/upload/RequestUpload.ets @@ -1,307 +1,307 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import request from '@ohos.request'; -import promptAction from '@ohos.promptAction'; -import { urlUtils } from '../utils/UrlUtils'; -import { logger } from '../utils/Logger'; -import { MediaUtils } from '../utils/MediaUtils'; -import { BackgroundTaskState, UPLOAD_TOKEN, TOAST_BOTTOM, TASK_MAX } from '../utils/Constants'; - -const TAG: string = 'RequestUpload'; -const HEADER: Record = { 'Content-Type': 'multipart/form-data' }; - -class Upload { - private mediaUtils: MediaUtils = new MediaUtils(); - private config: request.agent.Config = { - action: request.agent.Action.UPLOAD, - headers: HEADER, - url: '', - mode: request.agent.Mode.FOREGROUND, - method: 'POST', - title: 'upload', - network: request.agent.Network.ANY, - data: [], - token: UPLOAD_TOKEN - } - private context: common.UIAbilityContext | undefined = undefined; - private uploadTask: request.agent.Task | undefined = undefined; - private backgroundTask: request.agent.Task | undefined = undefined; - private waitList: Array = []; - - constructor() { - setInterval(() => { - this.flushBackgroundTask() - }, 2000); - } - - getFileName(filePath: string): string { - const lastSlashIndex = filePath.lastIndexOf('/'); - if (lastSlashIndex === -1) { - return filePath; - } - return filePath.substring(lastSlashIndex + 1); - } - - async uploadFilesBackground(fileUris: Array): Promise { - logger.info(TAG, `uploadFilesBackground:uploadFiles begin, ${JSON.stringify(fileUris)}`); - this.context = getContext(this) as common.UIAbilityContext; - if (fileUris.length === 0) { - return; - } - fileUris.forEach((item: string) => { - this.waitList.push(item); - }); - } - - async flushBackgroundTask() { - logger.info(TAG, 'flushBackgroundTask:uploadFiles begin'); - let tasks = await request.agent.search({ - state: request.agent.State.RUNNING - }); - let state = AppStorage.get('backTaskState'); - if (state === BackgroundTaskState.RUNNING) { - if (tasks.length < TASK_MAX && this.waitList.length > 0) { - this.createBackgroundTask(this.waitList); - this.waitList = []; - } else { - if (this.backgroundTask === undefined || tasks.indexOf(this.backgroundTask.tid) === -1) { - AppStorage.setOrCreate('backTaskState', BackgroundTaskState.NONE); - this.backgroundTask = undefined; - } - } - } - } - - async createBackgroundTask(fileUris: Array) { - logger.info(TAG, `createBackgroundTask:uploadFiles begin, ${JSON.stringify(fileUris)}`); - if (this.context === undefined) { - return; - } - this.config.url = await urlUtils.getUrl(this.context); - this.config.data = await this.getFilesAndData(this.context.cacheDir, fileUris); - this.config.mode = request.agent.Mode.BACKGROUND; - try { - this.backgroundTask = await request.agent.create(this.context, this.config); - await this.backgroundTask.start(); - let state = AppStorage.get('backTaskState'); - if (state === BackgroundTaskState.PAUSE) { - await this.backgroundTask.pause(); - } - logger.info(TAG, `createBackgroundTask success`); - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - } - } - - async uploadFiles(fileUris: Array, callback: (progress: number, isSucceed: boolean) => void): Promise { - logger.info(TAG, `uploadFiles begin, ${JSON.stringify(fileUris)}`); - if (fileUris.length === 0) { - return; - } - // 查询到存在正在执行的上传任务,提示并返回 - let tasks = await request.agent.search({ - state: request.agent.State.RUNNING, - action: request.agent.Action.UPLOAD, - mode: request.agent.Mode.FOREGROUND - }); - if (tasks.length > 0) { - promptAction.showToast({ message: $r('app.string.have_upload_task_tips'), bottom: TOAST_BOTTOM }); - return; - } - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - this.config.data = await this.getFilesAndData(context.cacheDir, fileUris); - logger.info(TAG, `config data:${JSON.stringify(this.config.data)}`); - this.config.url = await urlUtils.getUrl(context); - logger.info(TAG, `config url:${JSON.stringify(this.config.url)}`); - this.config.mode = request.agent.Mode.FOREGROUND; - try { - this.uploadTask = await request.agent.create(context, this.config); - this.uploadTask.on('progress', (progress: request.agent.Progress) => { - logger.info(TAG, `progress, progress = ${progress.processed} ${progress.state}`); - let processed = Number(progress.processed.toString()).valueOf(); - let size = progress.sizes[0]; - let process: number = Math.floor(processed / size * 100); - if (process < 100) { - callback(process, false); - } - }); - this.uploadTask.on('completed', (progress: request.agent.Progress) => { - logger.info(TAG, `complete, progress = ${progress.processed} ${progress.state}`); - callback(100, true); - this.cancelTask(); - }); - this.uploadTask.on('failed', async (progress: request.agent.Progress) => { - if (this.uploadTask) { - let taskInfo = await request.agent.touch(this.uploadTask.tid, UPLOAD_TOKEN); - logger.info(TAG, `fail, resean = ${taskInfo.reason}, faults = ${JSON.stringify(taskInfo.faults)}`); - } - callback(100, false); - this.cancelTask(); - }); - await this.uploadTask.start(); - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - callback(100, false); - } - } - - async uploadFileChunk(fileUris: Array, begin: number, end: number, callback: (progress: number, isSucceed: boolean) => void): Promise { - logger.info(TAG, `uploadFileChunk begin,${fileUris}, begin:${begin}, end:${end}`); - // 查询到存在正在执行的上传任务,提示并返回 - let tasks = await request.agent.search({ - state: request.agent.State.RUNNING, - action: request.agent.Action.UPLOAD, - mode: request.agent.Mode.FOREGROUND - }); - if (tasks.length > 0) { - promptAction.showToast({ message: $r('app.string.have_upload_task_tips'), bottom: TOAST_BOTTOM }); - return; - } - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let config: request.agent.Config = { - action: request.agent.Action.UPLOAD, - headers: HEADER, - url: await urlUtils.getUrl(context), - mode: request.agent.Mode.FOREGROUND, - method: 'POST', - title: 'upload', - network: request.agent.Network.ANY, - data: await this.getFilesAndData(context.cacheDir, fileUris), - token: UPLOAD_TOKEN, - index: 0, // 指定片段上传的文件 - begins: begin, - ends: end - }; - - try { - this.uploadTask = await request.agent.create(context, config); - this.uploadTask.on('progress', (progress: request.agent.Progress) => { - let processed = Number(progress.processed.toString()).valueOf(); - let size = progress.sizes[progress.index]; - if (progress.index === 0) { - if (end === -1) { - size -= begin; - } else { - size = end - begin + 1; - } - } - logger.info(TAG, `progress, index:${progress.index}, progressed = ${progress.processed}, size=${size}`); - let process: number = Math.floor(processed / size * 100); - if (process < 100) { - callback(process, false); - } - }); - this.uploadTask.on('completed', (progress: request.agent.Progress) => { - logger.info(TAG, `complete, progress = ${progress.processed} ${progress.state}`); - callback(100, true); - this.cancelTask(); - }); - this.uploadTask.on('failed', async (progress: request.agent.Progress) => { - if (this.uploadTask) { - let taskInfo = await request.agent.touch(this.uploadTask.tid, UPLOAD_TOKEN); - logger.info(TAG, `fail, resean = ${taskInfo.reason}, faults = ${JSON.stringify(taskInfo.faults)}`); - } - callback(100, false); - this.cancelTask(); - }) - await this.uploadTask.start(); - } catch (err) { - logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); - callback(100, false); - } - } - - async cancelTask() { - logger.info(TAG, 'cancelTask'); - if (this.uploadTask === undefined) { - return; - } - try { - this.uploadTask.off('progress'); - this.uploadTask.off('failed'); - this.uploadTask.off('completed'); - await this.uploadTask.stop(); - await request.agent.remove(this.uploadTask.tid); - } catch (err) { - logger.info(TAG, `deleteTask fail,err= ${JSON.stringify(err)}`); - } - this.uploadTask = undefined; - } - - async pauseOrResume() { - logger.info(TAG, 'pauseOrResume'); - let state = AppStorage.get('backTaskState'); - if (state === BackgroundTaskState.RUNNING) { - await this.pause(); - AppStorage.setOrCreate('backTaskState', BackgroundTaskState.PAUSE); - } else if (state === BackgroundTaskState.PAUSE) { - await this.resume(); - AppStorage.setOrCreate('backTaskState', BackgroundTaskState.RUNNING); - } else { - logger.info(TAG, 'this task state is error'); - } - } - - async pause() { - logger.info(TAG, 'pause'); - if (this.backgroundTask === undefined) { - return; - } - try { - await this.backgroundTask.pause(); - } catch (err) { - logger.info(TAG, `pause fail,err= ${JSON.stringify(err)}`); - } - } - - async resume() { - logger.info(TAG, 'resume'); - if (this.backgroundTask === undefined) { - return; - } - try { - await this.backgroundTask.resume(); - } catch (err) { - logger.info(TAG, `resume fail,err= ${JSON.stringify(err)}`); - } - } - - private async getFilesAndData(cacheDir: string, fileUris: Array): Promise> { - logger.info(TAG, `getFilesAndData begin`); - let files: Array = []; - for (let i = 0; i < fileUris.length; i++) { - logger.info(TAG, `getFile fileUri = ${fileUris[i]}`); - let imagePath = fileUris[i]; - logger.info(TAG, `getFilesAndData imagePath: ${JSON.stringify(imagePath)}`); - let fileName = this.getFileName(imagePath); - let file: request.agent.FormItem = { - name: 'createTest', - value: { - filename: fileName, - mimeType: 'application/octet-stream', - path: imagePath, - } - } - logger.info(TAG, `getFile file = ${JSON.stringify(file)}`); - files.push(file); - } - logger.info(TAG, `getFilesAndData ${JSON.stringify(files)}`); - return files; - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import request from '@ohos.request'; +import promptAction from '@ohos.promptAction'; +import { urlUtils } from '../utils/UrlUtils'; +import { logger } from '../utils/Logger'; +import { MediaUtils } from '../utils/MediaUtils'; +import { BackgroundTaskState, UPLOAD_TOKEN, TOAST_BOTTOM, TASK_MAX } from '../utils/Constants'; + +const TAG: string = 'RequestUpload'; +const HEADER: Record = { 'Content-Type': 'multipart/form-data' }; + +class Upload { + private mediaUtils: MediaUtils = new MediaUtils(); + private config: request.agent.Config = { + action: request.agent.Action.UPLOAD, + headers: HEADER, + url: '', + mode: request.agent.Mode.FOREGROUND, + method: 'POST', + title: 'upload', + network: request.agent.Network.ANY, + data: [], + token: UPLOAD_TOKEN + } + private context: common.UIAbilityContext | undefined = undefined; + private uploadTask: request.agent.Task | undefined = undefined; + private backgroundTask: request.agent.Task | undefined = undefined; + private waitList: Array = []; + + constructor() { + setInterval(() => { + this.flushBackgroundTask() + }, 2000); + } + + getFileName(filePath: string): string { + const lastSlashIndex = filePath.lastIndexOf('/'); + if (lastSlashIndex === -1) { + return filePath; + } + return filePath.substring(lastSlashIndex + 1); + } + + async uploadFilesBackground(fileUris: Array): Promise { + logger.info(TAG, `uploadFilesBackground:uploadFiles begin, ${JSON.stringify(fileUris)}`); + this.context = getContext(this) as common.UIAbilityContext; + if (fileUris.length === 0) { + return; + } + fileUris.forEach((item: string) => { + this.waitList.push(item); + }); + } + + async flushBackgroundTask() { + logger.info(TAG, 'flushBackgroundTask:uploadFiles begin'); + let tasks = await request.agent.search({ + state: request.agent.State.RUNNING + }); + let state = AppStorage.get('backTaskState'); + if (state === BackgroundTaskState.RUNNING) { + if (tasks.length < TASK_MAX && this.waitList.length > 0) { + this.createBackgroundTask(this.waitList); + this.waitList = []; + } else { + if (this.backgroundTask === undefined || tasks.indexOf(this.backgroundTask.tid) === -1) { + AppStorage.setOrCreate('backTaskState', BackgroundTaskState.NONE); + this.backgroundTask = undefined; + } + } + } + } + + async createBackgroundTask(fileUris: Array) { + logger.info(TAG, `createBackgroundTask:uploadFiles begin, ${JSON.stringify(fileUris)}`); + if (this.context === undefined) { + return; + } + this.config.url = await urlUtils.getUrl(this.context); + this.config.data = await this.getFilesAndData(this.context.cacheDir, fileUris); + this.config.mode = request.agent.Mode.BACKGROUND; + try { + this.backgroundTask = await request.agent.create(this.context, this.config); + await this.backgroundTask.start(); + let state = AppStorage.get('backTaskState'); + if (state === BackgroundTaskState.PAUSE) { + await this.backgroundTask.pause(); + } + logger.info(TAG, `createBackgroundTask success`); + } catch (err) { + logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); + } + } + + async uploadFiles(fileUris: Array, callback: (progress: number, isSucceed: boolean) => void): Promise { + logger.info(TAG, `uploadFiles begin, ${JSON.stringify(fileUris)}`); + if (fileUris.length === 0) { + return; + } + // 查询到存在正在执行的上传任务,提示并返回 + let tasks = await request.agent.search({ + state: request.agent.State.RUNNING, + action: request.agent.Action.UPLOAD, + mode: request.agent.Mode.FOREGROUND + }); + if (tasks.length > 0) { + promptAction.showToast({ message: $r('app.string.have_upload_task_tips'), bottom: TOAST_BOTTOM }); + return; + } + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + this.config.data = await this.getFilesAndData(context.cacheDir, fileUris); + logger.info(TAG, `config data:${JSON.stringify(this.config.data)}`); + this.config.url = await urlUtils.getUrl(context); + logger.info(TAG, `config url:${JSON.stringify(this.config.url)}`); + this.config.mode = request.agent.Mode.FOREGROUND; + try { + this.uploadTask = await request.agent.create(context, this.config); + this.uploadTask.on('progress', (progress: request.agent.Progress) => { + logger.info(TAG, `progress, progress = ${progress.processed} ${progress.state}`); + let processed = Number(progress.processed.toString()).valueOf(); + let size = progress.sizes[0]; + let process: number = Math.floor(processed / size * 100); + if (process < 100) { + callback(process, false); + } + }); + this.uploadTask.on('completed', (progress: request.agent.Progress) => { + logger.info(TAG, `complete, progress = ${progress.processed} ${progress.state}`); + callback(100, true); + this.cancelTask(); + }); + this.uploadTask.on('failed', async (progress: request.agent.Progress) => { + if (this.uploadTask) { + let taskInfo = await request.agent.touch(this.uploadTask.tid, UPLOAD_TOKEN); + logger.info(TAG, `fail, resean = ${taskInfo.reason}, faults = ${JSON.stringify(taskInfo.faults)}`); + } + callback(100, false); + this.cancelTask(); + }); + await this.uploadTask.start(); + } catch (err) { + logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); + callback(100, false); + } + } + + async uploadFileChunk(fileUris: Array, begin: number, end: number, callback: (progress: number, isSucceed: boolean) => void): Promise { + logger.info(TAG, `uploadFileChunk begin,${fileUris}, begin:${begin}, end:${end}`); + // 查询到存在正在执行的上传任务,提示并返回 + let tasks = await request.agent.search({ + state: request.agent.State.RUNNING, + action: request.agent.Action.UPLOAD, + mode: request.agent.Mode.FOREGROUND + }); + if (tasks.length > 0) { + promptAction.showToast({ message: $r('app.string.have_upload_task_tips'), bottom: TOAST_BOTTOM }); + return; + } + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let config: request.agent.Config = { + action: request.agent.Action.UPLOAD, + headers: HEADER, + url: await urlUtils.getUrl(context), + mode: request.agent.Mode.FOREGROUND, + method: 'POST', + title: 'upload', + network: request.agent.Network.ANY, + data: await this.getFilesAndData(context.cacheDir, fileUris), + token: UPLOAD_TOKEN, + index: 0, // 指定片段上传的文件 + begins: begin, + ends: end + }; + + try { + this.uploadTask = await request.agent.create(context, config); + this.uploadTask.on('progress', (progress: request.agent.Progress) => { + let processed = Number(progress.processed.toString()).valueOf(); + let size = progress.sizes[progress.index]; + if (progress.index === 0) { + if (end === -1) { + size -= begin; + } else { + size = end - begin + 1; + } + } + logger.info(TAG, `progress, index:${progress.index}, progressed = ${progress.processed}, size=${size}`); + let process: number = Math.floor(processed / size * 100); + if (process < 100) { + callback(process, false); + } + }); + this.uploadTask.on('completed', (progress: request.agent.Progress) => { + logger.info(TAG, `complete, progress = ${progress.processed} ${progress.state}`); + callback(100, true); + this.cancelTask(); + }); + this.uploadTask.on('failed', async (progress: request.agent.Progress) => { + if (this.uploadTask) { + let taskInfo = await request.agent.touch(this.uploadTask.tid, UPLOAD_TOKEN); + logger.info(TAG, `fail, resean = ${taskInfo.reason}, faults = ${JSON.stringify(taskInfo.faults)}`); + } + callback(100, false); + this.cancelTask(); + }) + await this.uploadTask.start(); + } catch (err) { + logger.error(TAG, `task err, err = ${JSON.stringify(err)}`); + callback(100, false); + } + } + + async cancelTask() { + logger.info(TAG, 'cancelTask'); + if (this.uploadTask === undefined) { + return; + } + try { + this.uploadTask.off('progress'); + this.uploadTask.off('failed'); + this.uploadTask.off('completed'); + await this.uploadTask.stop(); + await request.agent.remove(this.uploadTask.tid); + } catch (err) { + logger.info(TAG, `deleteTask fail,err= ${JSON.stringify(err)}`); + } + this.uploadTask = undefined; + } + + async pauseOrResume() { + logger.info(TAG, 'pauseOrResume'); + let state = AppStorage.get('backTaskState'); + if (state === BackgroundTaskState.RUNNING) { + await this.pause(); + AppStorage.setOrCreate('backTaskState', BackgroundTaskState.PAUSE); + } else if (state === BackgroundTaskState.PAUSE) { + await this.resume(); + AppStorage.setOrCreate('backTaskState', BackgroundTaskState.RUNNING); + } else { + logger.info(TAG, 'this task state is error'); + } + } + + async pause() { + logger.info(TAG, 'pause'); + if (this.backgroundTask === undefined) { + return; + } + try { + await this.backgroundTask.pause(); + } catch (err) { + logger.info(TAG, `pause fail,err= ${JSON.stringify(err)}`); + } + } + + async resume() { + logger.info(TAG, 'resume'); + if (this.backgroundTask === undefined) { + return; + } + try { + await this.backgroundTask.resume(); + } catch (err) { + logger.info(TAG, `resume fail,err= ${JSON.stringify(err)}`); + } + } + + private async getFilesAndData(cacheDir: string, fileUris: Array): Promise> { + logger.info(TAG, `getFilesAndData begin`); + let files: Array = []; + for (let i = 0; i < fileUris.length; i++) { + logger.info(TAG, `getFile fileUri = ${fileUris[i]}`); + let imagePath = fileUris[i]; + logger.info(TAG, `getFilesAndData imagePath: ${JSON.stringify(imagePath)}`); + let fileName = this.getFileName(imagePath); + let file: request.agent.FormItem = { + name: 'createTest', + value: { + filename: fileName, + mimeType: 'application/octet-stream', + path: imagePath, + } + } + logger.info(TAG, `getFile file = ${JSON.stringify(file)}`); + files.push(file); + } + logger.info(TAG, `getFilesAndData ${JSON.stringify(files)}`); + return files; + } +} + export const requestUpload = new Upload(); \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/Constants.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/Constants.ets index 67a4a64cff13bf014067c07874a4b6ee8b6d0aec..8bb5482b04aa9f7e4670e07510e3a2e916efda14 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/Constants.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/Constants.ets @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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 TOAST_BOTTOM: number = 200; -export const UPLOAD_TOKEN: string = 'upload_token'; -export const TASK_MAX: number = 10; -export enum BackgroundTaskState { - NONE = 0, - RUNNING = 1, - PAUSE = 2 -} +/* + * Copyright (c) 2023 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 TOAST_BOTTOM: number = 200; +export const UPLOAD_TOKEN: string = 'upload_token'; +export const TASK_MAX: number = 10; +export enum BackgroundTaskState { + NONE = 0, + RUNNING = 1, + PAUSE = 2 +} export const NO_IMAGE_SELECTED: number = -1; \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/UrlUtils.ets b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/UrlUtils.ets index 8262e18cae50abccb5e6161f77ea1299242ea936..a06833d2f7190051ee4601c9f420100f473a0bff 100644 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/UrlUtils.ets +++ b/code/BasicFeature/Connectivity/UploadAndDownLoad/features/uploadanddownload/src/main/ets/utils/UrlUtils.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import commonEventManager from '@ohos.commonEventManager'; -import preferences from '@ohos.data.preferences'; -import { CommonEventData } from './commonEvent/commonEventData'; -import { CommonEventSubscriber } from './commonEvent/commonEventSubscriber'; -import { logger } from './Logger'; - -const TAG: string = 'UrlUtils'; -const URL_KEY: string = 'url'; -const STORE_NAME: string = 'server_url'; -const DEFAULT_SERVER_URL: string = 'http://192.168.1.1/'; - -class UrlUtil { - async getUrl(context: common.UIAbilityContext): Promise { - let preference = await preferences.getPreferences(context, STORE_NAME); - let url = await preference.get(URL_KEY, '') as string; - if (url == '') { - url = DEFAULT_SERVER_URL; - logger.info(TAG, 'config url is null'); - } - logger.info(TAG, `getUrl,url= ${url}`); - return url; - } - - async saveUrl(context: common.UIAbilityContext, url: string) { - let preference = await preferences.getPreferences(context, STORE_NAME); - await preference.put(URL_KEY, url); - await preference.flush(); - } -} - -export const urlUtils = new UrlUtil(); +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import commonEventManager from '@ohos.commonEventManager'; +import preferences from '@ohos.data.preferences'; +import { CommonEventData } from './commonEvent/commonEventData'; +import { CommonEventSubscriber } from './commonEvent/commonEventSubscriber'; +import { logger } from './Logger'; + +const TAG: string = 'UrlUtils'; +const URL_KEY: string = 'url'; +const STORE_NAME: string = 'server_url'; +const DEFAULT_SERVER_URL: string = 'http://192.168.1.1/'; + +class UrlUtil { + async getUrl(context: common.UIAbilityContext): Promise { + let preference = await preferences.getPreferences(context, STORE_NAME); + let url = await preference.get(URL_KEY, '') as string; + if (url == '') { + url = DEFAULT_SERVER_URL; + logger.info(TAG, 'config url is null'); + } + logger.info(TAG, `getUrl,url= ${url}`); + return url; + } + + async saveUrl(context: common.UIAbilityContext, url: string) { + let preference = await preferences.getPreferences(context, STORE_NAME); + await preference.put(URL_KEY, url); + await preference.flush(); + } +} + +export const urlUtils = new UrlUtil(); diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/hvigor/hvigor-config.json5 b/code/BasicFeature/Connectivity/UploadAndDownLoad/hvigor/hvigor-config.json5 deleted file mode 100644 index 64655e6970c2acdf5708226c4d5a584ca52b6f37..0000000000000000000000000000000000000000 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,6 +0,0 @@ -{ - "hvigorVersion": "3.2.4", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.2.4" - } -} \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/UploadAndDownLoad/hvigor/hvigor-wrapper.js b/code/BasicFeature/Connectivity/UploadAndDownLoad/hvigor/hvigor-wrapper.js deleted file mode 100644 index 372eae8eb4a124095936f9cd78df5c6756746f3f..0000000000000000000000000000000000000000 --- a/code/BasicFeature/Connectivity/UploadAndDownLoad/hvigor/hvigor-wrapper.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var u=require("path"),D=require("os"),e=require("fs"),t=require("crypto"),r=require("child_process"),n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},i={},C={},F=n&&n.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(C,"__esModule",{value:!0}),C.maxPathLength=C.isMac=C.isLinux=C.isWindows=void 0;const E=F(D),A="Windows_NT",o="Darwin";function a(){return E.default.type()===A}function c(){return E.default.type()===o}C.isWindows=a,C.isLinux=function(){return"Linux"===E.default.type()},C.isMac=c,C.maxPathLength=function(){return c()?1016:a()?259:4095},function(e){var t=n&&n.__createBinding||(Object.create?function(u,D,e,t){void 0===t&&(t=e);var r=Object.getOwnPropertyDescriptor(D,e);r&&!("get"in r?!D.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return D[e]}}),Object.defineProperty(u,t,r)}:function(u,D,e,t){void 0===t&&(t=e),u[t]=D[e]}),r=n&&n.__setModuleDefault||(Object.create?function(u,D){Object.defineProperty(u,"default",{enumerable:!0,value:D})}:function(u,D){u.default=D}),i=n&&n.__importStar||function(u){if(u&&u.__esModule)return u;var D={};if(null!=u)for(var e in u)"default"!==e&&Object.prototype.hasOwnProperty.call(u,e)&&t(D,u,e);return r(D,u),D};Object.defineProperty(e,"__esModule",{value:!0}),e.WORK_SPACE=e.HVIGOR_PROJECT_WRAPPER_HOME=e.HVIGOR_PROJECT_ROOT_DIR=e.HVIGOR_PROJECT_CACHES_HOME=e.HVIGOR_PNPM_STORE_PATH=e.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH=e.PROJECT_CACHES=e.HVIGOR_WRAPPER_TOOLS_HOME=e.HVIGOR_USER_HOME=e.DEFAULT_PACKAGE_JSON=e.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME=e.PNPM=e.HVIGOR=e.NPM_TOOL=e.PNPM_TOOL=e.HVIGOR_ENGINE_PACKAGE_NAME=void 0;const F=i(D),E=i(u),A=C;e.HVIGOR_ENGINE_PACKAGE_NAME="@ohos/hvigor",e.PNPM_TOOL=(0,A.isWindows)()?"pnpm.cmd":"pnpm",e.NPM_TOOL=(0,A.isWindows)()?"npm.cmd":"npm",e.HVIGOR="hvigor",e.PNPM="pnpm",e.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME="hvigor-config.json5",e.DEFAULT_PACKAGE_JSON="package.json",e.HVIGOR_USER_HOME=E.resolve(F.homedir(),".hvigor"),e.HVIGOR_WRAPPER_TOOLS_HOME=E.resolve(e.HVIGOR_USER_HOME,"wrapper","tools"),e.PROJECT_CACHES="project_caches",e.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH=E.resolve(e.HVIGOR_WRAPPER_TOOLS_HOME,"node_modules",".bin",e.PNPM_TOOL),e.HVIGOR_PNPM_STORE_PATH=E.resolve(e.HVIGOR_USER_HOME,"caches"),e.HVIGOR_PROJECT_CACHES_HOME=E.resolve(e.HVIGOR_USER_HOME,e.PROJECT_CACHES),e.HVIGOR_PROJECT_ROOT_DIR=process.cwd(),e.HVIGOR_PROJECT_WRAPPER_HOME=E.resolve(e.HVIGOR_PROJECT_ROOT_DIR,e.HVIGOR),e.WORK_SPACE="workspace"}(i);var s={},l={};Object.defineProperty(l,"__esModule",{value:!0}),l.logInfoPrintConsole=l.logErrorAndExit=void 0,l.logErrorAndExit=function(u){u instanceof Error?console.error(u.message):console.error(u),process.exit(-1)},l.logInfoPrintConsole=function(u){console.log(u)};var B=n&&n.__createBinding||(Object.create?function(u,D,e,t){void 0===t&&(t=e);var r=Object.getOwnPropertyDescriptor(D,e);r&&!("get"in r?!D.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return D[e]}}),Object.defineProperty(u,t,r)}:function(u,D,e,t){void 0===t&&(t=e),u[t]=D[e]}),d=n&&n.__setModuleDefault||(Object.create?function(u,D){Object.defineProperty(u,"default",{enumerable:!0,value:D})}:function(u,D){u.default=D}),f=n&&n.__importStar||function(u){if(u&&u.__esModule)return u;var D={};if(null!=u)for(var e in u)"default"!==e&&Object.prototype.hasOwnProperty.call(u,e)&&B(D,u,e);return d(D,u),D};Object.defineProperty(s,"__esModule",{value:!0});var _=s.executeBuild=void 0;const p=f(e),O=f(u),h=l;_=s.executeBuild=function(u){const D=O.resolve(u,"node_modules","@ohos","hvigor","bin","hvigor.js");try{const u=p.realpathSync(D);require(u)}catch(e){(0,h.logErrorAndExit)(`Error: ENOENT: no such file ${D},delete ${u} and retry.`)}};var P={},v={};!function(u){var D=n&&n.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(u,"__esModule",{value:!0}),u.hashFile=u.hash=u.createHash=void 0;const r=D(t),i=D(e);u.createHash=(u="MD5")=>r.default.createHash(u);u.hash=(D,e)=>(0,u.createHash)(e).update(D).digest("hex");u.hashFile=(D,e)=>{if(i.default.existsSync(D))return(0,u.hash)(i.default.readFileSync(D,"utf-8"),e)}}(v);var g={},m={},R={};Object.defineProperty(R,"__esModule",{value:!0}),R.Unicode=void 0;class y{}R.Unicode=y,y.SPACE_SEPARATOR=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,y.ID_START=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,y.ID_CONTINUE=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/,Object.defineProperty(m,"__esModule",{value:!0}),m.JudgeUtil=void 0;const I=R;m.JudgeUtil=class{static isIgnoreChar(u){return"string"==typeof u&&("\t"===u||"\v"===u||"\f"===u||" "===u||" "===u||"\ufeff"===u||"\n"===u||"\r"===u||"\u2028"===u||"\u2029"===u)}static isSpaceSeparator(u){return"string"==typeof u&&I.Unicode.SPACE_SEPARATOR.test(u)}static isIdStartChar(u){return"string"==typeof u&&(u>="a"&&u<="z"||u>="A"&&u<="Z"||"$"===u||"_"===u||I.Unicode.ID_START.test(u))}static isIdContinueChar(u){return"string"==typeof u&&(u>="a"&&u<="z"||u>="A"&&u<="Z"||u>="0"&&u<="9"||"$"===u||"_"===u||"‌"===u||"‍"===u||I.Unicode.ID_CONTINUE.test(u))}static isDigitWithoutZero(u){return/[1-9]/.test(u)}static isDigit(u){return"string"==typeof u&&/[0-9]/.test(u)}static isHexDigit(u){return"string"==typeof u&&/[0-9A-Fa-f]/.test(u)}};var N=n&&n.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(g,"__esModule",{value:!0}),g.parseJsonText=g.parseJsonFile=void 0;const b=N(e),S=N(D),w=N(u),H=m;var x;!function(u){u[u.Char=0]="Char",u[u.EOF=1]="EOF",u[u.Identifier=2]="Identifier"}(x||(x={}));let M,T,V,G,j,J,W="start",U=[],L=0,$=1,k=0,K=!1,z="default",q="'",Z=1;function X(u,D=!1){T=String(u),W="start",U=[],L=0,$=1,k=0,G=void 0,K=D;do{M=Q(),nu[W]()}while("eof"!==M.type);return G}function Q(){for(z="default",j="",q="'",Z=1;;){J=Y();const u=Du[z]();if(u)return u}}function Y(){if(T[L])return String.fromCodePoint(T.codePointAt(L))}function uu(){const u=Y();return"\n"===u?($++,k=0):u?k+=u.length:k++,u&&(L+=u.length),u}g.parseJsonFile=function(u,D=!1,e="utf-8"){const t=b.default.readFileSync(w.default.resolve(u),{encoding:e});try{return X(t,D)}catch(D){if(D instanceof SyntaxError){const e=D.message.split("at");if(2===e.length)throw new Error(`${e[0].trim()}${S.default.EOL}\t at ${u}:${e[1].trim()}`)}throw new Error(`${u} is not in valid JSON/JSON5 format.`)}},g.parseJsonText=X;const Du={default(){switch(J){case"/":return uu(),void(z="comment");case void 0:return uu(),eu("eof")}if(!H.JudgeUtil.isIgnoreChar(J)&&!H.JudgeUtil.isSpaceSeparator(J))return Du[W]();uu()},start(){z="value"},beforePropertyName(){switch(J){case"$":case"_":return j=uu(),void(z="identifierName");case"\\":return uu(),void(z="identifierNameStartEscape");case"}":return eu("punctuator",uu());case'"':case"'":return q=J,uu(),void(z="string")}if(H.JudgeUtil.isIdStartChar(J))return j+=uu(),void(z="identifierName");throw Eu(x.Char,uu())},afterPropertyName(){if(":"===J)return eu("punctuator",uu());throw Eu(x.Char,uu())},beforePropertyValue(){z="value"},afterPropertyValue(){switch(J){case",":case"}":return eu("punctuator",uu())}throw Eu(x.Char,uu())},beforeArrayValue(){if("]"===J)return eu("punctuator",uu());z="value"},afterArrayValue(){switch(J){case",":case"]":return eu("punctuator",uu())}throw Eu(x.Char,uu())},end(){throw Eu(x.Char,uu())},comment(){switch(J){case"*":return uu(),void(z="multiLineComment");case"/":return uu(),void(z="singleLineComment")}throw Eu(x.Char,uu())},multiLineComment(){switch(J){case"*":return uu(),void(z="multiLineCommentAsterisk");case void 0:throw Eu(x.Char,uu())}uu()},multiLineCommentAsterisk(){switch(J){case"*":return void uu();case"/":return uu(),void(z="default");case void 0:throw Eu(x.Char,uu())}uu(),z="multiLineComment"},singleLineComment(){switch(J){case"\n":case"\r":case"\u2028":case"\u2029":return uu(),void(z="default");case void 0:return uu(),eu("eof")}uu()},value(){switch(J){case"{":case"[":return eu("punctuator",uu());case"n":return uu(),tu("ull"),eu("null",null);case"t":return uu(),tu("rue"),eu("boolean",!0);case"f":return uu(),tu("alse"),eu("boolean",!1);case"-":case"+":return"-"===uu()&&(Z=-1),void(z="numerical");case".":case"0":case"I":case"N":return void(z="numerical");case'"':case"'":return q=J,uu(),j="",void(z="string")}if(void 0===J||!H.JudgeUtil.isDigitWithoutZero(J))throw Eu(x.Char,uu());z="numerical"},numerical(){switch(J){case".":return j=uu(),void(z="decimalPointLeading");case"0":return j=uu(),void(z="zero");case"I":return uu(),tu("nfinity"),eu("numeric",Z*(1/0));case"N":return uu(),tu("aN"),eu("numeric",NaN)}if(void 0!==J&&H.JudgeUtil.isDigitWithoutZero(J))return j=uu(),void(z="decimalInteger");throw Eu(x.Char,uu())},zero(){switch(J){case".":case"e":case"E":return void(z="decimal");case"x":case"X":return j+=uu(),void(z="hexadecimal")}return eu("numeric",0)},decimalInteger(){switch(J){case".":case"e":case"E":return void(z="decimal")}if(!H.JudgeUtil.isDigit(J))return eu("numeric",Z*Number(j));j+=uu()},decimal(){switch(J){case".":j+=uu(),z="decimalFraction";break;case"e":case"E":j+=uu(),z="decimalExponent"}},decimalPointLeading(){if(H.JudgeUtil.isDigit(J))return j+=uu(),void(z="decimalFraction");throw Eu(x.Char,uu())},decimalFraction(){switch(J){case"e":case"E":return j+=uu(),void(z="decimalExponent")}if(!H.JudgeUtil.isDigit(J))return eu("numeric",Z*Number(j));j+=uu()},decimalExponent(){switch(J){case"+":case"-":return j+=uu(),void(z="decimalExponentSign")}if(H.JudgeUtil.isDigit(J))return j+=uu(),void(z="decimalExponentInteger");throw Eu(x.Char,uu())},decimalExponentSign(){if(H.JudgeUtil.isDigit(J))return j+=uu(),void(z="decimalExponentInteger");throw Eu(x.Char,uu())},decimalExponentInteger(){if(!H.JudgeUtil.isDigit(J))return eu("numeric",Z*Number(j));j+=uu()},hexadecimal(){if(H.JudgeUtil.isHexDigit(J))return j+=uu(),void(z="hexadecimalInteger");throw Eu(x.Char,uu())},hexadecimalInteger(){if(!H.JudgeUtil.isHexDigit(J))return eu("numeric",Z*Number(j));j+=uu()},identifierNameStartEscape(){if("u"!==J)throw Eu(x.Char,uu());uu();const u=ru();switch(u){case"$":case"_":break;default:if(!H.JudgeUtil.isIdStartChar(u))throw Eu(x.Identifier)}j+=u,z="identifierName"},identifierName(){switch(J){case"$":case"_":case"‌":case"‍":return void(j+=uu());case"\\":return uu(),void(z="identifierNameEscape")}if(!H.JudgeUtil.isIdContinueChar(J))return eu("identifier",j);j+=uu()},identifierNameEscape(){if("u"!==J)throw Eu(x.Char,uu());uu();const u=ru();switch(u){case"$":case"_":case"‌":case"‍":break;default:if(!H.JudgeUtil.isIdContinueChar(u))throw Eu(x.Identifier)}j+=u,z="identifierName"},string(){switch(J){case"\\":return uu(),void(j+=function(){const u=Y(),D=function(){switch(Y()){case"b":return uu(),"\b";case"f":return uu(),"\f";case"n":return uu(),"\n";case"r":return uu(),"\r";case"t":return uu(),"\t";case"v":return uu(),"\v"}return}();if(D)return D;switch(u){case"0":if(uu(),H.JudgeUtil.isDigit(Y()))throw Eu(x.Char,uu());return"\0";case"x":return uu(),function(){let u="",D=Y();if(!H.JudgeUtil.isHexDigit(D))throw Eu(x.Char,uu());if(u+=uu(),D=Y(),!H.JudgeUtil.isHexDigit(D))throw Eu(x.Char,uu());return u+=uu(),String.fromCodePoint(parseInt(u,16))}();case"u":return uu(),ru();case"\n":case"\u2028":case"\u2029":return uu(),"";case"\r":return uu(),"\n"===Y()&&uu(),""}if(void 0===u||H.JudgeUtil.isDigitWithoutZero(u))throw Eu(x.Char,uu());return uu()}());case'"':case"'":if(J===q){const u=eu("string",j);return uu(),u}return void(j+=uu());case"\n":case"\r":case void 0:throw Eu(x.Char,uu());case"\u2028":case"\u2029":!function(u){console.warn(`JSON5: '${Fu(u)}' in strings is not valid ECMAScript; consider escaping.`)}(J)}j+=uu()}};function eu(u,D){return{type:u,value:D,line:$,column:k}}function tu(u){for(const D of u){if(Y()!==D)throw Eu(x.Char,uu());uu()}}function ru(){let u="",D=4;for(;D-- >0;){const D=Y();if(!H.JudgeUtil.isHexDigit(D))throw Eu(x.Char,uu());u+=uu()}return String.fromCodePoint(parseInt(u,16))}const nu={start(){if("eof"===M.type)throw Eu(x.EOF);iu()},beforePropertyName(){switch(M.type){case"identifier":case"string":return V=M.value,void(W="afterPropertyName");case"punctuator":return void Cu();case"eof":throw Eu(x.EOF)}},afterPropertyName(){if("eof"===M.type)throw Eu(x.EOF);W="beforePropertyValue"},beforePropertyValue(){if("eof"===M.type)throw Eu(x.EOF);iu()},afterPropertyValue(){if("eof"===M.type)throw Eu(x.EOF);switch(M.value){case",":return void(W="beforePropertyName");case"}":Cu()}},beforeArrayValue(){if("eof"===M.type)throw Eu(x.EOF);"punctuator"!==M.type||"]"!==M.value?iu():Cu()},afterArrayValue(){if("eof"===M.type)throw Eu(x.EOF);switch(M.value){case",":return void(W="beforeArrayValue");case"]":Cu()}},end(){}};function iu(){const u=function(){let u;switch(M.type){case"punctuator":switch(M.value){case"{":u={};break;case"[":u=[]}break;case"null":case"boolean":case"numeric":case"string":u=M.value}return u}();if(K&&"object"==typeof u&&(u._line=$,u._column=k),void 0===G)G=u;else{const D=U[U.length-1];Array.isArray(D)?K&&"object"!=typeof u?D.push({value:u,_line:$,_column:k}):D.push(u):D[V]=K&&"object"!=typeof u?{value:u,_line:$,_column:k}:u}!function(u){if(u&&"object"==typeof u)U.push(u),W=Array.isArray(u)?"beforeArrayValue":"beforePropertyName";else{const u=U[U.length-1];W=u?Array.isArray(u)?"afterArrayValue":"afterPropertyValue":"end"}}(u)}function Cu(){U.pop();const u=U[U.length-1];W=u?Array.isArray(u)?"afterArrayValue":"afterPropertyValue":"end"}function Fu(u){const D={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(D[u])return D[u];if(u<" "){const D=u.charCodeAt(0).toString(16);return`\\x${`00${D}`.substring(D.length)}`}return u}function Eu(u,D){let e="";switch(u){case x.Char:e=void 0===D?`JSON5: invalid end of input at ${$}:${k}`:`JSON5: invalid character '${Fu(D)}' at ${$}:${k}`;break;case x.EOF:e=`JSON5: invalid end of input at ${$}:${k}`;break;case x.Identifier:k-=5,e=`JSON5: invalid identifier character at ${$}:${k}`}const t=new Au(e);return t.lineNumber=$,t.columnNumber=k,t}class Au extends SyntaxError{}var ou={},au=n&&n.__createBinding||(Object.create?function(u,D,e,t){void 0===t&&(t=e);var r=Object.getOwnPropertyDescriptor(D,e);r&&!("get"in r?!D.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return D[e]}}),Object.defineProperty(u,t,r)}:function(u,D,e,t){void 0===t&&(t=e),u[t]=D[e]}),cu=n&&n.__setModuleDefault||(Object.create?function(u,D){Object.defineProperty(u,"default",{enumerable:!0,value:D})}:function(u,D){u.default=D}),su=n&&n.__importStar||function(u){if(u&&u.__esModule)return u;var D={};if(null!=u)for(var e in u)"default"!==e&&Object.prototype.hasOwnProperty.call(u,e)&&au(D,u,e);return cu(D,u),D},lu=n&&n.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(ou,"__esModule",{value:!0}),ou.isFileExists=ou.offlinePluginConversion=ou.executeCommand=ou.getNpmPath=ou.hasNpmPackInPaths=void 0;const Bu=r,du=lu(e),fu=su(u),_u=i,pu=l;ou.hasNpmPackInPaths=function(u,D){try{return require.resolve(u,{paths:[...D]}),!0}catch(u){return!1}},ou.getNpmPath=function(){const u=process.execPath;return fu.join(fu.dirname(u),_u.NPM_TOOL)},ou.executeCommand=function(u,D,e){0!==(0,Bu.spawnSync)(u,D,e).status&&(0,pu.logErrorAndExit)(`Error: ${u} ${D} execute failed.See above for details.`)},ou.offlinePluginConversion=function(u,D){return D.startsWith("file:")||D.endsWith(".tgz")?fu.resolve(u,_u.HVIGOR,D.replace("file:","")):D},ou.isFileExists=function(u){return du.default.existsSync(u)&&du.default.statSync(u).isFile()};var Ou=n&&n.__createBinding||(Object.create?function(u,D,e,t){void 0===t&&(t=e);var r=Object.getOwnPropertyDescriptor(D,e);r&&!("get"in r?!D.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return D[e]}}),Object.defineProperty(u,t,r)}:function(u,D,e,t){void 0===t&&(t=e),u[t]=D[e]}),hu=n&&n.__setModuleDefault||(Object.create?function(u,D){Object.defineProperty(u,"default",{enumerable:!0,value:D})}:function(u,D){u.default=D}),Pu=n&&n.__importStar||function(u){if(u&&u.__esModule)return u;var D={};if(null!=u)for(var e in u)"default"!==e&&Object.prototype.hasOwnProperty.call(u,e)&&Ou(D,u,e);return hu(D,u),D},vu=n&&n.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(P,"__esModule",{value:!0});var gu=P.initProjectWorkSpace=void 0;const mu=Pu(e),Ru=vu(D),yu=Pu(u),Iu=v,Nu=i,bu=g,Su=l,wu=ou;let Hu,xu,Mu;function Tu(u,D,e){return void 0!==e.dependencies&&(0,wu.offlinePluginConversion)(Nu.HVIGOR_PROJECT_ROOT_DIR,D.dependencies[u])===yu.normalize(e.dependencies[u])}function Vu(){const u=yu.join(Mu,Nu.WORK_SPACE);if((0,Su.logInfoPrintConsole)("Hvigor cleaning..."),!mu.existsSync(u))return;const D=mu.readdirSync(u);if(!D||0===D.length)return;const e=yu.resolve(Mu,"node_modules","@ohos","hvigor","bin","hvigor.js");mu.existsSync(e)&&(0,wu.executeCommand)(process.argv[0],[e,"--stop-daemon"],{});try{D.forEach((D=>{mu.rmSync(yu.resolve(u,D),{recursive:!0})}))}catch(D){(0,Su.logErrorAndExit)(`The hvigor build tool cannot be installed. Please manually clear the workspace directory and synchronize the project again.\n\n Workspace Path: ${u}.`)}}gu=P.initProjectWorkSpace=function(){if(Hu=function(){const u=yu.resolve(Nu.HVIGOR_PROJECT_WRAPPER_HOME,Nu.DEFAULT_HVIGOR_CONFIG_JSON_FILE_NAME);mu.existsSync(u)||(0,Su.logErrorAndExit)(`Error: Hvigor config file ${u} does not exist.`);return(0,bu.parseJsonFile)(u)}(),Mu=function(u){let D;D=function(u){let D=u.hvigorVersion;if(D.startsWith("file:")||D.endsWith(".tgz"))return!1;const e=u.dependencies,t=Object.getOwnPropertyNames(e);for(const u of t){const D=e[u];if(D.startsWith("file:")||D.endsWith(".tgz"))return!1}if(1===t.length&&"@ohos/hvigor-ohos-plugin"===t[0])return D>"2.5.0";return!1}(u)?function(u){let D=`${Nu.HVIGOR_ENGINE_PACKAGE_NAME}@${u.hvigorVersion}`;const e=u.dependencies;if(e){Object.getOwnPropertyNames(e).sort().forEach((u=>{D+=`,${u}@${e[u]}`}))}return(0,Iu.hash)(D)}(u):(0,Iu.hash)(process.cwd());return yu.resolve(Ru.default.homedir(),".hvigor","project_caches",D)}(Hu),xu=function(){const u=yu.resolve(Mu,Nu.WORK_SPACE,Nu.DEFAULT_PACKAGE_JSON);return mu.existsSync(u)?(0,bu.parseJsonFile)(u):{dependencies:{}}}(),!(0,wu.hasNpmPackInPaths)(Nu.HVIGOR_ENGINE_PACKAGE_NAME,[yu.join(Mu,Nu.WORK_SPACE)])||(0,wu.offlinePluginConversion)(Nu.HVIGOR_PROJECT_ROOT_DIR,Hu.hvigorVersion)!==xu.dependencies[Nu.HVIGOR_ENGINE_PACKAGE_NAME]||!function(){function u(u){const D=null==u?void 0:u.dependencies;return void 0===D?0:Object.getOwnPropertyNames(D).length}const D=u(Hu),e=u(xu);if(D+1!==e)return!1;for(const u in null==Hu?void 0:Hu.dependencies)if(!(0,wu.hasNpmPackInPaths)(u,[yu.join(Mu,Nu.WORK_SPACE)])||!Tu(u,Hu,xu))return!1;return!0}()){Vu();try{!function(){(0,Su.logInfoPrintConsole)("Hvigor installing...");for(const u in Hu.dependencies)Hu.dependencies[u]&&(Hu.dependencies[u]=(0,wu.offlinePluginConversion)(Nu.HVIGOR_PROJECT_ROOT_DIR,Hu.dependencies[u]));const u={dependencies:{...Hu.dependencies}};u.dependencies[Nu.HVIGOR_ENGINE_PACKAGE_NAME]=(0,wu.offlinePluginConversion)(Nu.HVIGOR_PROJECT_ROOT_DIR,Hu.hvigorVersion);const D=yu.join(Mu,Nu.WORK_SPACE);try{mu.mkdirSync(D,{recursive:!0});const e=yu.resolve(D,Nu.DEFAULT_PACKAGE_JSON);mu.writeFileSync(e,JSON.stringify(u))}catch(u){(0,Su.logErrorAndExit)(u)}(function(){const u=["config","set","store-dir",Nu.HVIGOR_PNPM_STORE_PATH],D={cwd:yu.join(Mu,Nu.WORK_SPACE),stdio:["inherit","inherit","inherit"]};(0,wu.executeCommand)(Nu.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH,u,D)})(),function(){const u=["install"],D={cwd:yu.join(Mu,Nu.WORK_SPACE),stdio:["inherit","inherit","inherit"]};(0,wu.executeCommand)(Nu.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH,u,D)}(),(0,Su.logInfoPrintConsole)("Hvigor install success.")}()}catch(u){Vu()}}return Mu};var Gu={};!function(t){var C=n&&n.__createBinding||(Object.create?function(u,D,e,t){void 0===t&&(t=e);var r=Object.getOwnPropertyDescriptor(D,e);r&&!("get"in r?!D.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return D[e]}}),Object.defineProperty(u,t,r)}:function(u,D,e,t){void 0===t&&(t=e),u[t]=D[e]}),F=n&&n.__setModuleDefault||(Object.create?function(u,D){Object.defineProperty(u,"default",{enumerable:!0,value:D})}:function(u,D){u.default=D}),E=n&&n.__importStar||function(u){if(u&&u.__esModule)return u;var D={};if(null!=u)for(var e in u)"default"!==e&&Object.prototype.hasOwnProperty.call(u,e)&&C(D,u,e);return F(D,u),D},A=n&&n.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(t,"__esModule",{value:!0}),t.executeInstallPnpm=t.isPnpmInstalled=t.environmentHandler=t.checkNpmConifg=t.PNPM_VERSION=void 0;const o=r,a=E(e),c=A(D),s=E(u),B=i,d=l,f=ou;t.PNPM_VERSION="7.30.0",t.checkNpmConifg=function(){const u=s.resolve(B.HVIGOR_PROJECT_ROOT_DIR,".npmrc"),D=s.resolve(c.default.homedir(),".npmrc");if((0,f.isFileExists)(u)||(0,f.isFileExists)(D))return;const e=(0,f.getNpmPath)(),t=(0,o.spawnSync)(e,["config","get","prefix"],{cwd:B.HVIGOR_PROJECT_ROOT_DIR});if(0!==t.status||!t.stdout)return void(0,d.logErrorAndExit)("Error: The hvigor depends on the npmrc file. Configure the npmrc file first.");const r=s.resolve(`${t.stdout}`.replace(/[\r\n]/gi,""),".npmrc");(0,f.isFileExists)(r)||(0,d.logErrorAndExit)("Error: The hvigor depends on the npmrc file. Configure the npmrc file first.")},t.environmentHandler=function(){process.env["npm_config_update-notifier"]="false"},t.isPnpmInstalled=function(){return!!a.existsSync(B.HVIGOR_WRAPPER_PNPM_SCRIPT_PATH)&&(0,f.hasNpmPackInPaths)("pnpm",[B.HVIGOR_WRAPPER_TOOLS_HOME])},t.executeInstallPnpm=function(){(0,d.logInfoPrintConsole)(`Installing pnpm@${t.PNPM_VERSION}...`);const u=(0,f.getNpmPath)();!function(){const u=s.resolve(B.HVIGOR_WRAPPER_TOOLS_HOME,B.DEFAULT_PACKAGE_JSON);try{a.existsSync(B.HVIGOR_WRAPPER_TOOLS_HOME)||a.mkdirSync(B.HVIGOR_WRAPPER_TOOLS_HOME,{recursive:!0});const D={dependencies:{}};D.dependencies[B.PNPM]=t.PNPM_VERSION,a.writeFileSync(u,JSON.stringify(D))}catch(D){(0,d.logErrorAndExit)(`Error: EPERM: operation not permitted,create ${u} failed.`)}}(),(0,f.executeCommand)(u,["install","pnpm"],{cwd:B.HVIGOR_WRAPPER_TOOLS_HOME,stdio:["inherit","inherit","inherit"],env:process.env}),(0,d.logInfoPrintConsole)("Pnpm install success.")}}(Gu),function(){Gu.checkNpmConifg(),Gu.environmentHandler(),Gu.isPnpmInstalled()||Gu.executeInstallPnpm();const D=gu();_(u.join(D,i.WORK_SPACE))}(); \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/AppScope/app.json5 b/code/BasicFeature/Connectivity/VPN/AppScope/app.json5 index 0b2f74849bd58e1e77c75fc41a5fa249182e51a6..3cdcbddae43b996b292a8ea26fda952286748f5c 100644 --- a/code/BasicFeature/Connectivity/VPN/AppScope/app.json5 +++ b/code/BasicFeature/Connectivity/VPN/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "app": { - "bundleName": "com.example.testvpnclient", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "app": { + "bundleName": "com.example.testvpnclient", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Connectivity/VPN/AppScope/resources/base/element/string.json b/code/BasicFeature/Connectivity/VPN/AppScope/resources/base/element/string.json index 095e4c59b5d6afdbb087a71c09b72d93b0c91e11..5ee9d169b2bf40c6ec257eba1af2cfc126431e84 100644 --- a/code/BasicFeature/Connectivity/VPN/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Connectivity/VPN/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "testvpnclient" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "testvpnclient" + } + ] +} diff --git a/code/BasicFeature/Connectivity/VPN/README_zh.md b/code/BasicFeature/Connectivity/VPN/README_zh.md index a837fea4044512ebb49de8fa2c9004df3efeb83e..c34babfd81c065b15e176b514556a92ce6878e67 100644 --- a/code/BasicFeature/Connectivity/VPN/README_zh.md +++ b/code/BasicFeature/Connectivity/VPN/README_zh.md @@ -1,85 +1,85 @@ -# VPN连接 - -### 介绍 -本示例使用@ohos.net.vpn接口创建VPN 隧道,建立vpn网络,vpn隧道保护,销毁VPN网络以及使用@ohos.net.vpnExtension接口创建三方vpn等功能。 -实现了VPN的进行服务器连接,发送数据的功能 - -### 效果预览 -| 主页 | vpn启动 | vpn关闭 | -| ------------------------------ | --------------------------------- | --------------------------------------- | -| ![main.jpeg](sceenshots%2Fmain.jpeg) | ![start.jpeg](sceenshots%2Fstart.jpeg) | ![stop.jpeg](sceenshots%2Fstop.jpeg) | - - 使用说明 -1. 进入应用前请先安装[VPNFoundation](./lib/VPNFoundation-1.0.0.hap)。 -2. 进入应用后,主界面有启用VPN和停用VPN的选项。分别对应开启和关闭VPN功能。 -3. 在主界面,可以点击启用VPN来创建VPN连接。 -4. 在VPN启动界面,可以配置VPN服务器IP地址/隧道IP地址/使用VPN的应用程序。 -5. 在VPN启动界面,点击创建对象可以创建VPN隧道,点击隧道保护可以开启隧道保护,点击启动VPN可以进行网络连接。 -6. 在主界面,可以点击停用VPN来断开和关闭VPN连接。 - -7. 以上演示系统vpn,如果使用三方vpn,点击启动vpnExt按钮,弹窗提示vpn使用许可,同意后三方vpn启动并自动连接,尝试用浏览器等hap包访问百度 - -| 三方vpn弹窗 | -| ------------------------------ | -| ![vpnextension.jpeg](sceenshots%2Fvpnextension.jpeg)| - -8 .访问成功后返回主页面,点击关闭vpnExt按钮,断开三方vpn连接 - -### 工程目录 - -``` -entry/src/main/ets/ -|---entryability -| |---EntryAbility.ts // 项目入口,请求相关权限 -|---pages -| |---Index.ets // 首页 -| |---StartVpn.ets // 打开vpn -| |---StopVpn.ets // 关闭vpn -|---model -| |---Logger.ets // 日志 -|---serviceextability -| |---MyVpnExtAbility.ts // 三方vpn能力 - -``` - -### 具体实现 - -创建VPN隧道,建立VPN网络,VPN隧道保护,销毁VPN网络,接口封装在StartVpn和StopVpn,源码参考:StartVpn.ets和StopVpn.ets。 - - * 创建VPN隧道:调用StartVpn.CreateTunnel()来创建VPN隧道; - * 建立VPN网络:调用StartVpn.SetupVpn()来建立VPN网络; - * 销毁VPN网络:调用StopVpn.Destroy()来销毁VPN网络; - * VPN隧道保护:调用StartVpn.Protect()来开启VPN隧道保护; - -### 相关权限 -允许系统应用获取网络权限: ohos.permission.INTERNET,允许系统应用获取VPN权限: ohos.permission.MANAGE_VPN。 - -### 依赖 - -不涉及 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API11版本SDK,SDK版本号(API Version 4.1 Beta1),镜像版本号(4.1 Beta1) - -3.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 - -4.本示例在启动前需搭建服务端环境,成功启动相应服务端后再运行客户端,服务端脚本(server_python)需要在Python 3.8.5版本下运行(需与客户端处于同一局域网)。 - -5.该示例运行测试完成后,再次运行需要重新启动服务端和客户端。 - -6.本示例使用了system_basic级别的权限(相关权限级别请查看[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md) ),需要手动配置高级别的权限签名(具体操作可查看[自动化签名方案](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465) ) 。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/Connectivity/VPN/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` +# VPN连接 + +### 介绍 +本示例使用@ohos.net.vpn接口创建VPN 隧道,建立vpn网络,vpn隧道保护,销毁VPN网络以及使用@ohos.net.vpnExtension接口创建三方vpn等功能。 +实现了VPN的进行服务器连接,发送数据的功能 + +### 效果预览 +| 主页 | vpn启动 | vpn关闭 | +| ------------------------------ | --------------------------------- | --------------------------------------- | +| ![main.jpeg](sceenshots%2Fmain.jpeg) | ![start.jpeg](sceenshots%2Fstart.jpeg) | ![stop.jpeg](sceenshots%2Fstop.jpeg) | + + 使用说明 +1. 进入应用前请先安装[VPNFoundation](./lib/VPNFoundation-1.0.0.hap)。 +2. 进入应用后,主界面有启用VPN和停用VPN的选项。分别对应开启和关闭VPN功能。 +3. 在主界面,可以点击启用VPN来创建VPN连接。 +4. 在VPN启动界面,可以配置VPN服务器IP地址/隧道IP地址/使用VPN的应用程序。 +5. 在VPN启动界面,点击创建对象可以创建VPN隧道,点击隧道保护可以开启隧道保护,点击启动VPN可以进行网络连接。 +6. 在主界面,可以点击停用VPN来断开和关闭VPN连接。 + +7. 以上演示系统vpn,如果使用三方vpn,点击启动vpnExt按钮,弹窗提示vpn使用许可,同意后三方vpn启动并自动连接,尝试用浏览器等hap包访问百度 + +| 三方vpn弹窗 | +| ------------------------------ | +| ![vpnextension.jpeg](sceenshots%2Fvpnextension.jpeg)| + +8 .访问成功后返回主页面,点击关闭vpnExt按钮,断开三方vpn连接 + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ts // 项目入口,请求相关权限 +|---pages +| |---Index.ets // 首页 +| |---StartVpn.ets // 打开vpn +| |---StopVpn.ets // 关闭vpn +|---model +| |---Logger.ets // 日志 +|---serviceextability +| |---MyVpnExtAbility.ts // 三方vpn能力 + +``` + +### 具体实现 + +创建VPN隧道,建立VPN网络,VPN隧道保护,销毁VPN网络,接口封装在StartVpn和StopVpn,源码参考:StartVpn.ets和StopVpn.ets。 + + * 创建VPN隧道:调用StartVpn.CreateTunnel()来创建VPN隧道; + * 建立VPN网络:调用StartVpn.SetupVpn()来建立VPN网络; + * 销毁VPN网络:调用StopVpn.Destroy()来销毁VPN网络; + * VPN隧道保护:调用StartVpn.Protect()来开启VPN隧道保护; + +### 相关权限 +允许系统应用获取网络权限: ohos.permission.INTERNET,允许系统应用获取VPN权限: ohos.permission.MANAGE_VPN。 + +### 依赖 + +不涉及 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API11版本SDK,SDK版本号(API Version 4.1 Beta1),镜像版本号(4.1 Beta1) + +3.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 + +4.本示例在启动前需搭建服务端环境,成功启动相应服务端后再运行客户端,服务端脚本(server_python)需要在Python 3.8.5版本下运行(需与客户端处于同一局域网)。 + +5.该示例运行测试完成后,再次运行需要重新启动服务端和客户端。 + +6.本示例使用了system_basic级别的权限(相关权限级别请查看[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md) ),需要手动配置高级别的权限签名(具体操作可查看[自动化签名方案](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ohos-auto-configuring-signature-information-0000001271659465) ) 。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/Connectivity/VPN/ > .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/Connectivity/VPN/VPN\346\265\213\350\257\225\347\224\250\344\276\213\346\212\245\345\221\212.md" "b/code/BasicFeature/Connectivity/VPN/VPN\346\265\213\350\257\225\347\224\250\344\276\213\346\212\245\345\221\212.md" index 9a2a4d043e16a8235bc4e5c8ba2ef3fa274f8fdf..e026087716f6a704cf0928f8cbdc8b06236ba551 100644 --- "a/code/BasicFeature/Connectivity/VPN/VPN\346\265\213\350\257\225\347\224\250\344\276\213\346\212\245\345\221\212.md" +++ "b/code/BasicFeature/Connectivity/VPN/VPN\346\265\213\350\257\225\347\224\250\344\276\213\346\212\245\345\221\212.md" @@ -1,9 +1,9 @@ -| 用例名称 | 预置条件 | 用例测试功能 | 输入 | 预期输出 | 是否自动 | 测试结果 | -|------------------| ---------------- |---------------------------|----------------------------|-----------------------------------------------| -------- | -------- | -| VPN_sample_test001 | 位于主页 | 界面UI展示 | 打开VPNSample。| 展示启用VPN和停用VPN的按钮,以及Toy VPN标题。| 是 | Pass | -| VPN_sample_test002 | 位于主页 | 选择启用VPN | 打开VPNSample,点击启用VPN按钮。| 1.正常跳转到启动VPN页面。
2.正常显示VPN配置,创建对象、隧道保护以及启动vpn按钮正常显示和可用。| 否 | Pass | -| VPN_sample_test003 | 位于启动VPN界面 | 创建VPN隧道 | 打开VPNSample,点击启用VPN按钮,点击创建对象按钮。| 和已经配置IP地址和端口的VpnServer发起Tcp建联,返回隧道的Fd。| 否 | Pass | -| VPN_sample_test004 | 位于启动VPN界面 | 开启隧道保护 | 打开VPNSample,点击启用VPN按钮,点击隧道保护按钮。| 提示开启隧道保护成功。| 否 | Pass | -| VPN_sample_test005 | 位于启动VPN界面 | 启动VPN连接 | 打开VPNSample,点击启用VPN按钮,点击启动vpn按钮。| 提示通过隧道进行VPN连接。| 否 | Pass | -| VPN_sample_test006 | 位于主页 | 选择停用VPN | 打开VPNSample,点击停用VPN按钮。| 1.正常跳转到关闭vpn页面。
2.正常显示关闭vpn按钮且按钮可用。| 否 | Pass | -| VPN_sample_test007 | 位于停用VPN界面 | 选择关闭VPN | 打开VPNSample,点击停用VPN按钮,点击关闭vpn按钮。| 1.正常跳转到关闭vpn页面。
2.提示关闭VPN隧道和连接。| 否 | Pass | +| 用例名称 | 预置条件 | 用例测试功能 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------------------| ---------------- |---------------------------|----------------------------|-----------------------------------------------| -------- | -------- | +| VPN_sample_test001 | 位于主页 | 界面UI展示 | 打开VPNSample。| 展示启用VPN和停用VPN的按钮,以及Toy VPN标题。| 是 | Pass | +| VPN_sample_test002 | 位于主页 | 选择启用VPN | 打开VPNSample,点击启用VPN按钮。| 1.正常跳转到启动VPN页面。
2.正常显示VPN配置,创建对象、隧道保护以及启动vpn按钮正常显示和可用。| 否 | Pass | +| VPN_sample_test003 | 位于启动VPN界面 | 创建VPN隧道 | 打开VPNSample,点击启用VPN按钮,点击创建对象按钮。| 和已经配置IP地址和端口的VpnServer发起Tcp建联,返回隧道的Fd。| 否 | Pass | +| VPN_sample_test004 | 位于启动VPN界面 | 开启隧道保护 | 打开VPNSample,点击启用VPN按钮,点击隧道保护按钮。| 提示开启隧道保护成功。| 否 | Pass | +| VPN_sample_test005 | 位于启动VPN界面 | 启动VPN连接 | 打开VPNSample,点击启用VPN按钮,点击启动vpn按钮。| 提示通过隧道进行VPN连接。| 否 | Pass | +| VPN_sample_test006 | 位于主页 | 选择停用VPN | 打开VPNSample,点击停用VPN按钮。| 1.正常跳转到关闭vpn页面。
2.正常显示关闭vpn按钮且按钮可用。| 否 | Pass | +| VPN_sample_test007 | 位于停用VPN界面 | 选择关闭VPN | 打开VPNSample,点击停用VPN按钮,点击关闭vpn按钮。| 1.正常跳转到关闭vpn页面。
2.提示关闭VPN隧道和连接。| 否 | Pass | diff --git a/code/BasicFeature/Connectivity/VPN/build-profile.json5 b/code/BasicFeature/Connectivity/VPN/build-profile.json5 index 1b9ae4c2c2d450784bb89b6c87af8377b44dee5e..47bc7132870bca565aee0987c72f4d21752e00f7 100644 --- a/code/BasicFeature/Connectivity/VPN/build-profile.json5 +++ b/code/BasicFeature/Connectivity/VPN/build-profile.json5 @@ -1,56 +1,56 @@ -/* -* Copyright (c) 2023 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", - //Specify the version of OpenHarmony application/service to be used during compilation. - "compileSdkVersion": 11, - //Specify the minimum version of OpenHarmony that the application/service is compatible with. - "compatibleSdkVersion": 11, - //Specify the target version of OpenHarmony for the application/service. If not set, it defaults to compatibleSdkVersion. - "targetSdkVersion": 11, - //Specify OpenHarmony as the target platform. - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* Copyright (c) 2023 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", + //Specify the version of OpenHarmony application/service to be used during compilation. + "compileSdkVersion": 11, + //Specify the minimum version of OpenHarmony that the application/service is compatible with. + "compatibleSdkVersion": 11, + //Specify the target version of OpenHarmony for the application/service. If not set, it defaults to compatibleSdkVersion. + "targetSdkVersion": 11, + //Specify OpenHarmony as the target platform. + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/build-profile.json5 b/code/BasicFeature/Connectivity/VPN/entry/build-profile.json5 index 6968595ec3635360bb720d25a55544b2c0967f39..f2e911029623965af728e5be805963578db3a0b9 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/build-profile.json5 +++ b/code/BasicFeature/Connectivity/VPN/entry/build-profile.json5 @@ -1,39 +1,39 @@ -/* -* Copyright (c) 2023-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", - "armeabi-v7a" - ] - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2023-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", + "armeabi-v7a" + ] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/oh-package.json5 b/code/BasicFeature/Connectivity/VPN/entry/oh-package.json5 index e74c2f98f624894d125534044276d1c9e485852e..f4b9ceda4105bb04e8eca5747eeda97f44e0c556 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/oh-package.json5 +++ b/code/BasicFeature/Connectivity/VPN/entry/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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": { - "libvpn_client.so": "file:./src/main/cpp/types/libentry" - } +/* + * Copyright (c) 2023 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": { + "libvpn_client.so": "file:./src/main/cpp/types/libentry" + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/CMakeLists.txt index 0e63d48d35ea069307be04fb84872cb0763877ce..3b34f4f7a20d2b09a7be07bec443b01be119f021 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/CMakeLists.txt @@ -1,21 +1,21 @@ -# Set the minimum required version of CMake to 3.4.1 -cmake_minimum_required(VERSION 3.4.1) - -# set the project name as "XComponent" -project(XComponent) - -# Define the variable NATIVERENDER_ROOT_PATH as the root path of the current source code -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -# Add the header file path to the project -include_directories( - ${NATIVERENDER_ROOT_PATH} - ${NATIVERENDER_ROOT_PATH}/include -) - -# Build the shared library vpn_client and add the source code file vpn_client.cpp -add_library(vpn_client SHARED vpn_client.cpp) - -# Link two library files into the vpn_client library -target_link_libraries(vpn_client PUBLIC libace_napi.z.so libc++.a) +# Set the minimum required version of CMake to 3.4.1 +cmake_minimum_required(VERSION 3.4.1) + +# set the project name as "XComponent" +project(XComponent) + +# Define the variable NATIVERENDER_ROOT_PATH as the root path of the current source code +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +# Add the header file path to the project +include_directories( + ${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include +) + +# Build the shared library vpn_client and add the source code file vpn_client.cpp +add_library(vpn_client SHARED vpn_client.cpp) + +# Link two library files into the vpn_client library +target_link_libraries(vpn_client PUBLIC libace_napi.z.so libc++.a) target_link_libraries(vpn_client PUBLIC libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/index.d.ts b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/index.d.ts index ac36d80b3f9cee59834a30c08f208fbf7ef28268..f80e777f2b7ec6ccd228d4a6d8bb180b636c036d 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2023 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 tcpConnect: (addr: string, port: number) => number; - -export const startVpn: (tunFd: number, tunnelFd: number) => number; - +/* + * Copyright (c) 2023 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 tcpConnect: (addr: string, port: number) => number; + +export const startVpn: (tunFd: number, tunnelFd: number) => number; + export const stopVpn: (tunnelFd: number) => number; \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/oh-package.json5 index b959526d1a00b34e57174eedbbdb821dbfb38fac..9429d311a648ed3ad221a617875881e86f6386ad 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,6 +1,6 @@ -{ - "name": "libvpn_client.so", - "types": "./index.d.ts", - "version": "", - "description": "Please describe the basic information." +{ + "name": "libvpn_client.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/vpn_client.cpp b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/vpn_client.cpp index efc71e40c3b6e5e053ae76a4f896bd723a66124d..605863aa7ce04dc2eb00c79216d4afc942aa4956 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/vpn_client.cpp +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/cpp/vpn_client.cpp @@ -1,250 +1,250 @@ -/* -* Copyright (c) 2023 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#define MAKE_FILE_NAME (strrchr(__FILE__, '/') + 1) - -#define NETMANAGER_VPN_LOGE(fmt, ...) \ - OH_LOG_Print(LOG_APP, LOG_ERROR, 0x15b0, "NetMgrVpn", "vpn [%{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ - __LINE__, ##__VA_ARGS__) - -#define NETMANAGER_VPN_LOGI(fmt, ...) \ - OH_LOG_Print(LOG_APP, LOG_INFO, 0x15b0, "NetMgrVpn", "vpn [%{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ - __LINE__, ##__VA_ARGS__) - -#define NETMANAGER_VPN_LOGD(fmt, ...) \ - OH_LOG_Print(LOG_APP, LOG_DEBUG, 0x15b0, "NetMgrVpn", "vpn [%{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ - __LINE__, ##__VA_ARGS__) - -constexpr int BUFFER_SIZE = 2048; -constexpr int ERRORAGAIN = 11; - -struct FdInfo { - int32_t tunFd = 0; - int32_t tunnelFd = 0; - struct sockaddr_in serverAddr; -}; - -static FdInfo g_fdInfo; -static bool g_threadRunF = false; -static std::thread g_threadt1; -static std::thread g_threadt2; - -static constexpr const int MAX_STRING_LENGTH = 1024; -static std::string GetStringFromValueUtf8(napi_env env, napi_value value) -{ - std::string result; - char str[MAX_STRING_LENGTH] = {0}; - size_t length = 0; - napi_get_value_string_utf8(env, value, str, MAX_STRING_LENGTH, &length); - if (length > 0) { - return result.append(str, length); - } - return result; -} - -static void HandleReadTunfd(FdInfo fdInfo) -{ - uint8_t buffer[BUFFER_SIZE] = {0}; - while (g_threadRunF) { - if (fdInfo.tunFd <= 0) { - sleep(1); - continue; - } - - int ret = read(fdInfo.tunFd, buffer, sizeof(buffer)); - if (ret <= 0) { - if (errno != ERRORAGAIN) { - sleep(1); - } - continue; - } - - // Read the data from the virtual network interface and send it to the client through a TCP tunnel. - NETMANAGER_VPN_LOGD("buffer: %{public}s, len: %{public}d", buffer, ret); - ret = sendto(fdInfo.tunnelFd, buffer, ret, 0, - reinterpret_cast(&fdInfo.serverAddr), sizeof(fdInfo.serverAddr)); - if (ret <= 0) { - NETMANAGER_VPN_LOGE("send to server[%{public}s:%{public}d] failed, ret: %{public}d, error: %{public}s", - inet_ntoa(fdInfo.serverAddr.sin_addr), ntohs(fdInfo.serverAddr.sin_port), ret, - strerror(errno)); - continue; - } - } -} - -static void HandleTcpReceived(FdInfo fdInfo) -{ - int addrlen = sizeof(struct sockaddr_in); - uint8_t buffer[BUFFER_SIZE] = {0}; - while (g_threadRunF) { - if (fdInfo.tunnelFd <= 0) { - sleep(1); - continue; - } - - int length = recvfrom(fdInfo.tunnelFd, buffer, sizeof(buffer), 0, - reinterpret_cast(&fdInfo.serverAddr), - reinterpret_cast(&addrlen)); - if (length < 0) { - if (errno != EAGAIN) { - NETMANAGER_VPN_LOGE("read tun device error: %{public}d %{public}d", errno, fdInfo.tunnelFd); - } - continue; - } - - NETMANAGER_VPN_LOGI("from [%{public}s:%{public}d] data: %{public}s, len: %{public}d", - inet_ntoa(fdInfo.serverAddr.sin_addr), ntohs(fdInfo.serverAddr.sin_port), buffer, length); - int ret = write(fdInfo.tunFd, buffer, length); - if (ret <= 0) { - NETMANAGER_VPN_LOGE("error Write To Tunfd, errno: %{public}d", errno); - } - } -} - -static napi_value TcpConnect(napi_env env, napi_callback_info info) -{ - size_t numArgs = 2; - size_t argc = numArgs; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - int32_t port = 0; - napi_get_value_int32(env, args[1], &port); - std::string ipAddr = GetStringFromValueUtf8(env, args[0]); - - NETMANAGER_VPN_LOGI("ip: %{public}s port: %{public}d", ipAddr.c_str(), port); - - int32_t sockFd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockFd == -1) { - NETMANAGER_VPN_LOGE("socket() error"); - return 0; - } - - struct timeval timeout = {1, 0}; - setsockopt(sockFd, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&timeout), sizeof(struct timeval)); - - memset(&g_fdInfo.serverAddr, 0, sizeof(g_fdInfo.serverAddr)); - g_fdInfo.serverAddr.sin_family = AF_INET; - g_fdInfo.serverAddr.sin_addr.s_addr = inet_addr(ipAddr.c_str()); // server's IP addr - g_fdInfo.serverAddr.sin_port = htons(port); // port - - NETMANAGER_VPN_LOGI("Connection successful\n"); - - napi_value tunnelFd; - napi_create_int32(env, sockFd, &tunnelFd); - return tunnelFd; -} - -static napi_value StartVpn(napi_env env, napi_callback_info info) -{ - size_t numArgs = 2; - size_t argc = numArgs; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_get_value_int32(env, args[0], &g_fdInfo.tunFd); - napi_get_value_int32(env, args[1], &g_fdInfo.tunnelFd); - - if (g_threadRunF) { - g_threadRunF = false; - g_threadt1.join(); - g_threadt2.join(); - } - - g_threadRunF = true; - std::thread tt1(HandleReadTunfd, g_fdInfo); - std::thread tt2(HandleTcpReceived, g_fdInfo); - - g_threadt1 = std::move(tt1); - g_threadt2 = std::move(tt2); - - NETMANAGER_VPN_LOGI("StartVpn successful\n"); - - napi_value retValue; - napi_create_int32(env, 0, &retValue); - return retValue; -} - -static napi_value StopVpn(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - int32_t tunnelFd; - napi_get_value_int32(env, args[0], &tunnelFd); - if (tunnelFd) { - close(tunnelFd); - tunnelFd = 0; - } - - if (g_threadRunF) { - g_threadRunF = false; - g_threadt1.join(); - g_threadt2.join(); - } - - NETMANAGER_VPN_LOGI("StopVpn successful\n"); - - napi_value retValue; - napi_create_int32(env, 0, &retValue); - return retValue; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"tcpConnect", nullptr, TcpConnect, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"startVpn", nullptr, StartVpn, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"stopVpn", nullptr, StopVpn, 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) -{ - NETMANAGER_VPN_LOGI("vpn 15b0 HELLO ~~~~~~~~~~"); - napi_module_register(&demoModule); -} +/* +* Copyright (c) 2023 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define MAKE_FILE_NAME (strrchr(__FILE__, '/') + 1) + +#define NETMANAGER_VPN_LOGE(fmt, ...) \ + OH_LOG_Print(LOG_APP, LOG_ERROR, 0x15b0, "NetMgrVpn", "vpn [%{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ + __LINE__, ##__VA_ARGS__) + +#define NETMANAGER_VPN_LOGI(fmt, ...) \ + OH_LOG_Print(LOG_APP, LOG_INFO, 0x15b0, "NetMgrVpn", "vpn [%{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ + __LINE__, ##__VA_ARGS__) + +#define NETMANAGER_VPN_LOGD(fmt, ...) \ + OH_LOG_Print(LOG_APP, LOG_DEBUG, 0x15b0, "NetMgrVpn", "vpn [%{public}s %{public}d] " fmt, MAKE_FILE_NAME, \ + __LINE__, ##__VA_ARGS__) + +constexpr int BUFFER_SIZE = 2048; +constexpr int ERRORAGAIN = 11; + +struct FdInfo { + int32_t tunFd = 0; + int32_t tunnelFd = 0; + struct sockaddr_in serverAddr; +}; + +static FdInfo g_fdInfo; +static bool g_threadRunF = false; +static std::thread g_threadt1; +static std::thread g_threadt2; + +static constexpr const int MAX_STRING_LENGTH = 1024; +static std::string GetStringFromValueUtf8(napi_env env, napi_value value) +{ + std::string result; + char str[MAX_STRING_LENGTH] = {0}; + size_t length = 0; + napi_get_value_string_utf8(env, value, str, MAX_STRING_LENGTH, &length); + if (length > 0) { + return result.append(str, length); + } + return result; +} + +static void HandleReadTunfd(FdInfo fdInfo) +{ + uint8_t buffer[BUFFER_SIZE] = {0}; + while (g_threadRunF) { + if (fdInfo.tunFd <= 0) { + sleep(1); + continue; + } + + int ret = read(fdInfo.tunFd, buffer, sizeof(buffer)); + if (ret <= 0) { + if (errno != ERRORAGAIN) { + sleep(1); + } + continue; + } + + // Read the data from the virtual network interface and send it to the client through a TCP tunnel. + NETMANAGER_VPN_LOGD("buffer: %{public}s, len: %{public}d", buffer, ret); + ret = sendto(fdInfo.tunnelFd, buffer, ret, 0, + reinterpret_cast(&fdInfo.serverAddr), sizeof(fdInfo.serverAddr)); + if (ret <= 0) { + NETMANAGER_VPN_LOGE("send to server[%{public}s:%{public}d] failed, ret: %{public}d, error: %{public}s", + inet_ntoa(fdInfo.serverAddr.sin_addr), ntohs(fdInfo.serverAddr.sin_port), ret, + strerror(errno)); + continue; + } + } +} + +static void HandleTcpReceived(FdInfo fdInfo) +{ + int addrlen = sizeof(struct sockaddr_in); + uint8_t buffer[BUFFER_SIZE] = {0}; + while (g_threadRunF) { + if (fdInfo.tunnelFd <= 0) { + sleep(1); + continue; + } + + int length = recvfrom(fdInfo.tunnelFd, buffer, sizeof(buffer), 0, + reinterpret_cast(&fdInfo.serverAddr), + reinterpret_cast(&addrlen)); + if (length < 0) { + if (errno != EAGAIN) { + NETMANAGER_VPN_LOGE("read tun device error: %{public}d %{public}d", errno, fdInfo.tunnelFd); + } + continue; + } + + NETMANAGER_VPN_LOGI("from [%{public}s:%{public}d] data: %{public}s, len: %{public}d", + inet_ntoa(fdInfo.serverAddr.sin_addr), ntohs(fdInfo.serverAddr.sin_port), buffer, length); + int ret = write(fdInfo.tunFd, buffer, length); + if (ret <= 0) { + NETMANAGER_VPN_LOGE("error Write To Tunfd, errno: %{public}d", errno); + } + } +} + +static napi_value TcpConnect(napi_env env, napi_callback_info info) +{ + size_t numArgs = 2; + size_t argc = numArgs; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t port = 0; + napi_get_value_int32(env, args[1], &port); + std::string ipAddr = GetStringFromValueUtf8(env, args[0]); + + NETMANAGER_VPN_LOGI("ip: %{public}s port: %{public}d", ipAddr.c_str(), port); + + int32_t sockFd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockFd == -1) { + NETMANAGER_VPN_LOGE("socket() error"); + return 0; + } + + struct timeval timeout = {1, 0}; + setsockopt(sockFd, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast(&timeout), sizeof(struct timeval)); + + memset(&g_fdInfo.serverAddr, 0, sizeof(g_fdInfo.serverAddr)); + g_fdInfo.serverAddr.sin_family = AF_INET; + g_fdInfo.serverAddr.sin_addr.s_addr = inet_addr(ipAddr.c_str()); // server's IP addr + g_fdInfo.serverAddr.sin_port = htons(port); // port + + NETMANAGER_VPN_LOGI("Connection successful\n"); + + napi_value tunnelFd; + napi_create_int32(env, sockFd, &tunnelFd); + return tunnelFd; +} + +static napi_value StartVpn(napi_env env, napi_callback_info info) +{ + size_t numArgs = 2; + size_t argc = numArgs; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_get_value_int32(env, args[0], &g_fdInfo.tunFd); + napi_get_value_int32(env, args[1], &g_fdInfo.tunnelFd); + + if (g_threadRunF) { + g_threadRunF = false; + g_threadt1.join(); + g_threadt2.join(); + } + + g_threadRunF = true; + std::thread tt1(HandleReadTunfd, g_fdInfo); + std::thread tt2(HandleTcpReceived, g_fdInfo); + + g_threadt1 = std::move(tt1); + g_threadt2 = std::move(tt2); + + NETMANAGER_VPN_LOGI("StartVpn successful\n"); + + napi_value retValue; + napi_create_int32(env, 0, &retValue); + return retValue; +} + +static napi_value StopVpn(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + int32_t tunnelFd; + napi_get_value_int32(env, args[0], &tunnelFd); + if (tunnelFd) { + close(tunnelFd); + tunnelFd = 0; + } + + if (g_threadRunF) { + g_threadRunF = false; + g_threadt1.join(); + g_threadt2.join(); + } + + NETMANAGER_VPN_LOGI("StopVpn successful\n"); + + napi_value retValue; + napi_create_int32(env, 0, &retValue); + return retValue; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"tcpConnect", nullptr, TcpConnect, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"startVpn", nullptr, StartVpn, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"stopVpn", nullptr, StopVpn, 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) +{ + NETMANAGER_VPN_LOGI("vpn 15b0 HELLO ~~~~~~~~~~"); + napi_module_register(&demoModule); +} diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/entryability/EntryAbility.ts index fe1acdb252fd749ff9cde86ae89b9fbed803610c..6132d1d0d3679b545df7b78931a717d7aad1a59f 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,58 +1,58 @@ -/* -* Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -}; +/* +* Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +}; diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/model/Logger.ets b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/model/Logger.ets index ec90e1fa3b91cc7b06f83b2e2acabbf9dd7b8b50..1f100b4df59c12b20a93224376b2fbba0a31320c 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/model/Logger.ets +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/model/Logger.ets @@ -1,40 +1,40 @@ -/* -* Copyright (c) 2023 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. -*/ - - class Logger { - private prefix: string - - constructor(prefix: string) { - this.prefix = prefix - } - - log(...args: string[]) { - console.log(`[${this.prefix}].${args.join(' ')}`) - } - - info(...args: string[]) { - console.log(`[${this.prefix}].${args.join(' ')}`) - } - - debug(...args: string[]) { - console.log(`[${this.prefix}].${args.join(' ')}`) - } - - error(...args: string[]) { - console.log(`[${this.prefix}].${args.join(' ')}`) - } - } - +/* +* Copyright (c) 2023 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. +*/ + + class Logger { + private prefix: string + + constructor(prefix: string) { + this.prefix = prefix + } + + log(...args: string[]) { + console.log(`[${this.prefix}].${args.join(' ')}`) + } + + info(...args: string[]) { + console.log(`[${this.prefix}].${args.join(' ')}`) + } + + debug(...args: string[]) { + console.log(`[${this.prefix}].${args.join(' ')}`) + } + + error(...args: string[]) { + console.log(`[${this.prefix}].${args.join(' ')}`) + } + } + export default new Logger('[Sample_Wlan]') \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/Index.ets index c09c56ce836cfac0e47bda607360b88d62144dc5..6c6879fd53c665654e9aa016486c9f1184019c2e 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/Index.ets @@ -1,55 +1,55 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import hilog from '@ohos.hilog'; -import router from '@ohos.router'; -import { BusinessError } from '@ohos.base'; - -@Entry -@Component -struct Index { - @State message: string = 'Toy VPN'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(35) - .fontWeight(FontWeight.Bold) - .onClick(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Client'); - }) - Button('Start VPN').onClick(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in clicking the button.'); - router.pushUrl({ url: 'pages/StartVpn' }).then(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in jumping to the second page.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'developTag', 'Failed to jump to the second page: %{public}s', - JSON.stringify(err) ?? ''); - }) - }).width('70%').fontSize(45).margin(16) - Button('Stop VPN').onClick(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in clicking the button.'); - router.pushUrl({ url: 'pages/StopVpn' }).then(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in jumping to the second page.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'developTag', 'Failed to jump to the second page: %{public}s', - JSON.stringify(err) ?? ''); - }) - }).width('70%').fontSize(45) - }.width('100%') - }.height('100%') - } +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import router from '@ohos.router'; +import { BusinessError } from '@ohos.base'; + +@Entry +@Component +struct Index { + @State message: string = 'Toy VPN'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(35) + .fontWeight(FontWeight.Bold) + .onClick(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Client'); + }) + Button('Start VPN').onClick(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in clicking the button.'); + router.pushUrl({ url: 'pages/StartVpn' }).then(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in jumping to the second page.'); + }).catch((err: BusinessError) => { + hilog.error(0x0000, 'developTag', 'Failed to jump to the second page: %{public}s', + JSON.stringify(err) ?? ''); + }) + }).width('70%').fontSize(45).margin(16) + Button('Stop VPN').onClick(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in clicking the button.'); + router.pushUrl({ url: 'pages/StopVpn' }).then(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'Succeeded in jumping to the second page.'); + }).catch((err: BusinessError) => { + hilog.error(0x0000, 'developTag', 'Failed to jump to the second page: %{public}s', + JSON.stringify(err) ?? ''); + }) + }).width('70%').fontSize(45) + }.width('100%') + }.height('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StartVpn.ets b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StartVpn.ets index 8952dfeaf31250fb4805ba498c0ed161adcab549..8753a423e3537c4d9858462c01582e15e0726c40 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StartVpn.ets +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StartVpn.ets @@ -1,184 +1,184 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import hilog from '@ohos.hilog'; -import vpn_client from 'libvpn_client.so'; -import common from '@ohos.app.ability.common'; -import vpnext from '@ohos.net.vpnExtension'; -import Want from '@ohos.app.ability.Want'; -import { showToast } from '../components/ShowToast'; -import { BusinessError } from '@kit.BasicServicesKit'; - -let want: Want = { - deviceId: "", - bundleName: "com.example.myvpndemo", - abilityName: "MyVpnExtAbility", -}; - -let g_tunFd = -1; -let g_tunnelFd = -1; - -@Entry -@Component -struct StartVpn { - @State message: string = 'Toy VPN'; - @State vpnServerIp: string = '192.168.31.13'; - @State tunIp: string = '10.0.0.5'; - @State prefix: string = '24'; - @State blockedAppName: string = 'com.example.baidumyapplication'; - private context = getContext(this) as common.VpnExtensionContext; - private VpnConnection: vpnext.VpnConnection = vpnext.createVpnConnection(this.context); - - CreateTunnel() { - g_tunnelFd = vpn_client.tcpConnect(this.vpnServerIp, 8888); - if (g_tunnelFd) { - showToast('CreateTunnel Success', 2000); - hilog.info(0x0000, 'developTag', '%{public}s', 'CreateTunnel Success'); - } else { - showToast('CreateTunnel Fail', 2000); - hilog.error(0x0000, 'developTag', 'CreateTunnel Fail %{public}s', 'CreateTunnel Fail'); - } - } - - Protect() { - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Protect'); - this.VpnConnection.protect(g_tunnelFd).then(() => { - showToast('vpn Protect Success', 2000); - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Protect Success'); - }).catch((err: Error) => { - showToast('vpn Protect Failed: ' + JSON.stringify(err), 2000); - hilog.error(0x0000, 'developTag', 'vpn Protect Failed %{public}s', JSON.stringify(err) ?? ''); - }) - } - - SetupVpn() { - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn SetupVpn'); - class Address { - address: string; - family: number; - - constructor(address: string, family: number) { - this.address = address; - this.family = family; - } - } - - class AddressWithPrefix { - address: Address; - prefixLength: number; - - constructor(address: Address, prefixLength: number) { - this.address = address; - this.prefixLength = prefixLength; - } - } - - class Config { - addresses: AddressWithPrefix[]; - mtu: number; - dnsAddresses: string[]; - trustedApplications: string[]; - blockedApplications: string[]; - - constructor( - tunIp: string, - blockedAppName: string - ) { - this.addresses = [ - new AddressWithPrefix(new Address(tunIp, 1), 24) - ]; - this.mtu = 1400; - this.dnsAddresses = ["114.114.114.114"]; - this.trustedApplications = []; - this.blockedApplications = [blockedAppName]; - } - } - - let config = new Config(this.tunIp, this.blockedAppName); - this.VpnConnection.create(config).then((data) => { - g_tunFd = data; - hilog.error(0x0000, 'developTag', 'tunfd: %{public}s', JSON.stringify(data) ?? ''); - vpn_client.startVpn(g_tunFd, g_tunnelFd); - showToast('vpn start Success', 2000); - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn start Success'); - }).catch((err: BusinessError) => { - showToast('vpn start Fail: ' + JSON.stringify(err), 2000); - hilog.error(0x0000, 'developTag', 'vpn start Fail %{public}s', JSON.stringify(err) ?? ''); - }) - } - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(35) - .fontWeight(FontWeight.Bold) - .onClick(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Client'); - }) - - Row() { - //ip address of server - Text('server ip').fontSize(30).width('40%').textAlign(TextAlign.Center) - .backgroundColor(0xAFEEEE) - TextInput({ text: '192.168.31.13' }).onChange((value) => { - this.vpnServerIp = value; - }).width('60%').margin(2) - }.width('90%') - - Row() { - //ip address of tun-vpn on server - Text('tun ip').fontSize(30).width('40%').textAlign(TextAlign.Center) - .backgroundColor(0xAFEEEE) - TextInput({ text: '10.0.0.5' }).onChange((value) => { - this.tunIp = value; - }).width('60%').margin(2) - }.width('90%') - - Row() { - //blocked Hap - Text('blockedApp').fontSize(30).width('40%').textAlign(TextAlign.Center) - .backgroundColor(0xAFEEEE) - TextInput({ text: 'com.example.baidumyapplication' }).onChange((value) => { - this.blockedAppName = value; - }).width('60%').margin(2) - }.width('90%') - - Button($r('app.string.btn_create_tunnel')).onClick(() => { - this.CreateTunnel(); - }).fontSize(50) - Button($r('app.string.btn_protect')).onClick(() => { - this.Protect(); - }).fontSize(50) - Button($r('app.string.btn_start_vpn')).onClick(() => { - this.SetupVpn(); - }).fontSize(50) - Button($r('app.string.btn_start_vpnExt')).onClick(() => { - try { - vpnext.startVpnExtensionAbility(want).then(() => { - showToast('start vpnExt Success', 2000); - hilog.info(0x0000, 'developTag', '%{public}s', 'start vpnExt Success'); - }) - } catch (err) { - showToast('start vpnExt Fail: ' + JSON.stringify(err), 2000); - hilog.error(0x0000, 'developTag', 'start vpnExt Fail %{public}s', JSON.stringify(err) ?? ''); - } - }).fontSize(50) - } - .width('100%') - } - .height('100%') - } +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import vpn_client from 'libvpn_client.so'; +import common from '@ohos.app.ability.common'; +import vpnext from '@ohos.net.vpnExtension'; +import Want from '@ohos.app.ability.Want'; +import { showToast } from '../components/ShowToast'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let want: Want = { + deviceId: "", + bundleName: "com.example.myvpndemo", + abilityName: "MyVpnExtAbility", +}; + +let g_tunFd = -1; +let g_tunnelFd = -1; + +@Entry +@Component +struct StartVpn { + @State message: string = 'Toy VPN'; + @State vpnServerIp: string = '192.168.31.13'; + @State tunIp: string = '10.0.0.5'; + @State prefix: string = '24'; + @State blockedAppName: string = 'com.example.baidumyapplication'; + private context = getContext(this) as common.VpnExtensionContext; + private VpnConnection: vpnext.VpnConnection = vpnext.createVpnConnection(this.context); + + CreateTunnel() { + g_tunnelFd = vpn_client.tcpConnect(this.vpnServerIp, 8888); + if (g_tunnelFd) { + showToast('CreateTunnel Success', 2000); + hilog.info(0x0000, 'developTag', '%{public}s', 'CreateTunnel Success'); + } else { + showToast('CreateTunnel Fail', 2000); + hilog.error(0x0000, 'developTag', 'CreateTunnel Fail %{public}s', 'CreateTunnel Fail'); + } + } + + Protect() { + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Protect'); + this.VpnConnection.protect(g_tunnelFd).then(() => { + showToast('vpn Protect Success', 2000); + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Protect Success'); + }).catch((err: Error) => { + showToast('vpn Protect Failed: ' + JSON.stringify(err), 2000); + hilog.error(0x0000, 'developTag', 'vpn Protect Failed %{public}s', JSON.stringify(err) ?? ''); + }) + } + + SetupVpn() { + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn SetupVpn'); + class Address { + address: string; + family: number; + + constructor(address: string, family: number) { + this.address = address; + this.family = family; + } + } + + class AddressWithPrefix { + address: Address; + prefixLength: number; + + constructor(address: Address, prefixLength: number) { + this.address = address; + this.prefixLength = prefixLength; + } + } + + class Config { + addresses: AddressWithPrefix[]; + mtu: number; + dnsAddresses: string[]; + trustedApplications: string[]; + blockedApplications: string[]; + + constructor( + tunIp: string, + blockedAppName: string + ) { + this.addresses = [ + new AddressWithPrefix(new Address(tunIp, 1), 24) + ]; + this.mtu = 1400; + this.dnsAddresses = ["114.114.114.114"]; + this.trustedApplications = []; + this.blockedApplications = [blockedAppName]; + } + } + + let config = new Config(this.tunIp, this.blockedAppName); + this.VpnConnection.create(config).then((data) => { + g_tunFd = data; + hilog.error(0x0000, 'developTag', 'tunfd: %{public}s', JSON.stringify(data) ?? ''); + vpn_client.startVpn(g_tunFd, g_tunnelFd); + showToast('vpn start Success', 2000); + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn start Success'); + }).catch((err: BusinessError) => { + showToast('vpn start Fail: ' + JSON.stringify(err), 2000); + hilog.error(0x0000, 'developTag', 'vpn start Fail %{public}s', JSON.stringify(err) ?? ''); + }) + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(35) + .fontWeight(FontWeight.Bold) + .onClick(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Client'); + }) + + Row() { + //ip address of server + Text('server ip').fontSize(30).width('40%').textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) + TextInput({ text: '192.168.31.13' }).onChange((value) => { + this.vpnServerIp = value; + }).width('60%').margin(2) + }.width('90%') + + Row() { + //ip address of tun-vpn on server + Text('tun ip').fontSize(30).width('40%').textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) + TextInput({ text: '10.0.0.5' }).onChange((value) => { + this.tunIp = value; + }).width('60%').margin(2) + }.width('90%') + + Row() { + //blocked Hap + Text('blockedApp').fontSize(30).width('40%').textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) + TextInput({ text: 'com.example.baidumyapplication' }).onChange((value) => { + this.blockedAppName = value; + }).width('60%').margin(2) + }.width('90%') + + Button($r('app.string.btn_create_tunnel')).onClick(() => { + this.CreateTunnel(); + }).fontSize(50) + Button($r('app.string.btn_protect')).onClick(() => { + this.Protect(); + }).fontSize(50) + Button($r('app.string.btn_start_vpn')).onClick(() => { + this.SetupVpn(); + }).fontSize(50) + Button($r('app.string.btn_start_vpnExt')).onClick(() => { + try { + vpnext.startVpnExtensionAbility(want).then(() => { + showToast('start vpnExt Success', 2000); + hilog.info(0x0000, 'developTag', '%{public}s', 'start vpnExt Success'); + }) + } catch (err) { + showToast('start vpnExt Fail: ' + JSON.stringify(err), 2000); + hilog.error(0x0000, 'developTag', 'start vpnExt Fail %{public}s', JSON.stringify(err) ?? ''); + } + }).fontSize(50) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StopVpn.ets b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StopVpn.ets index dfae42ccbdfc6664ac42f7964059192ae5df3a68..75b6c7502064b71c4f9942dc27da9e0a5e4ec7b4 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StopVpn.ets +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/ets/pages/StopVpn.ets @@ -1,80 +1,80 @@ -/* -* Copyright (c) 2023 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import hilog from '@ohos.hilog'; -import vpnext from '@ohos.net.vpnExtension'; -import Want from '@ohos.app.ability.Want'; -import common from '@ohos.app.ability.common'; -import vpn_client from "libvpn_client.so"; -import { showToast } from '../components/ShowToast'; - -let want: Want = { - deviceId: "", - bundleName: "com.example.myvpndemo", - abilityName: "MyVpnExtAbility", -}; -let g_tunnelFd = -1; - -@Entry -@Component -struct StopVpn { - @State message: string = 'VPN'; - @State vpnServerIp: string = '192.168.31.13'; - @State tunIp: string = '10.0.0.5'; - @State routeAddr: string = '192.168.214.0'; - @State prefix: string = '24'; - @State blockedAppName: string = 'com.example.baidumyapplication'; - private context = getContext(this) as common.VpnExtensionContext; - private VpnConnection: vpnext.VpnConnection = vpnext.createVpnConnection(this.context); - - Destroy() { - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Destroy'); - vpn_client.stopVpn(g_tunnelFd); - this.VpnConnection.destroy().then(() => { - showToast('vpn Destroy Success', 2000); - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Destroy Success'); - }).catch((err: Error) => { - showToast('vpn Destroy Failed: ' + JSON.stringify(err), 2000); - hilog.error(0x0000, 'developTag', 'vpn Destroy Failed: %{public}s', JSON.stringify(err) ?? ''); - }) - } - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(35) - .fontWeight(FontWeight.Bold) - .onClick(() => { - hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Client'); - }) - Button('stop vpn').onClick(() => { - this.Destroy(); - }).fontSize(50) - Button('stop vpnExt').onClick(() => { - try { - vpnext.stopVpnExtensionAbility(want).then(() => { - showToast('stop vpnExt Success', 2000); - hilog.info(0x0000, 'developTag', '%{public}s', 'stop vpnExt Success'); - }) - } catch (err) { - showToast('stop vpnExt Fail: ' + JSON.stringify(err), 2000); - hilog.error(0x0000, 'developTag', 'stop vpnExt Fail %{public}s', JSON.stringify(err) ?? ''); - } - }).fontSize(50) - }.width('100%') - }.height('100%') - } +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import vpnext from '@ohos.net.vpnExtension'; +import Want from '@ohos.app.ability.Want'; +import common from '@ohos.app.ability.common'; +import vpn_client from "libvpn_client.so"; +import { showToast } from '../components/ShowToast'; + +let want: Want = { + deviceId: "", + bundleName: "com.example.myvpndemo", + abilityName: "MyVpnExtAbility", +}; +let g_tunnelFd = -1; + +@Entry +@Component +struct StopVpn { + @State message: string = 'VPN'; + @State vpnServerIp: string = '192.168.31.13'; + @State tunIp: string = '10.0.0.5'; + @State routeAddr: string = '192.168.214.0'; + @State prefix: string = '24'; + @State blockedAppName: string = 'com.example.baidumyapplication'; + private context = getContext(this) as common.VpnExtensionContext; + private VpnConnection: vpnext.VpnConnection = vpnext.createVpnConnection(this.context); + + Destroy() { + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Destroy'); + vpn_client.stopVpn(g_tunnelFd); + this.VpnConnection.destroy().then(() => { + showToast('vpn Destroy Success', 2000); + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Destroy Success'); + }).catch((err: Error) => { + showToast('vpn Destroy Failed: ' + JSON.stringify(err), 2000); + hilog.error(0x0000, 'developTag', 'vpn Destroy Failed: %{public}s', JSON.stringify(err) ?? ''); + }) + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(35) + .fontWeight(FontWeight.Bold) + .onClick(() => { + hilog.info(0x0000, 'developTag', '%{public}s', 'vpn Client'); + }) + Button('stop vpn').onClick(() => { + this.Destroy(); + }).fontSize(50) + Button('stop vpnExt').onClick(() => { + try { + vpnext.stopVpnExtensionAbility(want).then(() => { + showToast('stop vpnExt Success', 2000); + hilog.info(0x0000, 'developTag', '%{public}s', 'stop vpnExt Success'); + }) + } catch (err) { + showToast('stop vpnExt Fail: ' + JSON.stringify(err), 2000); + hilog.error(0x0000, 'developTag', 'stop vpnExt Fail %{public}s', JSON.stringify(err) ?? ''); + } + }).fontSize(50) + }.width('100%') + }.height('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/module.json5 b/code/BasicFeature/Connectivity/VPN/entry/src/main/module.json5 index 7b5d4bddec9d421068794da986e08778508c1b3c..cf0f399062ceca16c71d8dda8671d3a2cd1cba5b 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/module.json5 +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/module.json5 @@ -1,57 +1,57 @@ -/* -* Copyright (c) 2023 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": [ - "tablet", - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ], - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* +* Copyright (c) 2023 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": [ + "tablet", + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ], + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/string.json b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/string.json index 02ef7dfd955f13bab197477942775838504a1170..55e9d9478baba38af63e4701b3b6b3ed8e08f8e3 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/string.json +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/element/string.json @@ -1,32 +1,32 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "VPN" - }, - { - "name": "btn_create_tunnel", - "value": "创建隧道" - }, - { - "name": "btn_protect", - "value": "隧道保护" - }, - { - "name": "btn_start_vpn", - "value": "启动vpn" - }, - { - "name": "btn_start_vpnExt", - "value": "启动vpnExt" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "VPN" + }, + { + "name": "btn_create_tunnel", + "value": "创建隧道" + }, + { + "name": "btn_protect", + "value": "隧道保护" + }, + { + "name": "btn_start_vpn", + "value": "启动vpn" + }, + { + "name": "btn_start_vpnExt", + "value": "启动vpnExt" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/profile/main_pages.json index fc9de9b35aceff555044ef0083e8e311112f2485..65b5903f306bc5bdf078467edf3e8916ed626ccc 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/profile/main_pages.json +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,7 @@ -{ - "src": [ - "pages/Index", - "pages/StartVpn", - "pages/StopVpn" - ] -} +{ + "src": [ + "pages/Index", + "pages/StartVpn", + "pages/StopVpn" + ] +} diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/en_US/element/string.json index c50c4c2c0dede563b132f095736f6ce2b96a4dc4..172a8567ec3ce7be6b7e113cd24540568b6f11d5 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/en_US/element/string.json +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/en_US/element/string.json @@ -1,32 +1,32 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "btn_create_tunnel", - "value": "创建隧道" - }, - { - "name": "btn_protect", - "value": "隧道保护" - }, - { - "name": "btn_start_vpn", - "value": "启动vpn" - }, - { - "name": "btn_start_vpnExt", - "value": "启动vpnExt" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "btn_create_tunnel", + "value": "创建隧道" + }, + { + "name": "btn_protect", + "value": "隧道保护" + }, + { + "name": "btn_start_vpn", + "value": "启动vpn" + }, + { + "name": "btn_start_vpnExt", + "value": "启动vpnExt" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/zh_CN/element/string.json index 19a14d7711d6df7a14ec5f90d0d3ca98ab72a959..320848d813c1879ff4a05dd6c95a69fd15aae394 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/zh_CN/element/string.json +++ b/code/BasicFeature/Connectivity/VPN/entry/src/main/resources/zh_CN/element/string.json @@ -1,32 +1,32 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "btn_create_tunnel", - "value": "创建隧道" - }, - { - "name": "btn_protect", - "value": "隧道保护" - }, - { - "name": "btn_start_vpn", - "value": "启动vpn" - }, - { - "name": "btn_start_vpnExt", - "value": "启动vpnExt" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "btn_create_tunnel", + "value": "创建隧道" + }, + { + "name": "btn_protect", + "value": "隧道保护" + }, + { + "name": "btn_start_vpn", + "value": "启动vpn" + }, + { + "name": "btn_start_vpnExt", + "value": "启动vpnExt" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/ets/test/Ability.test.ets index f7b9ddf6591ef2cc2f5ec721386a86f3aee491e2..32b21d38782a72d8d5fa2acee5e98b6e9d7cfe7f 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,233 +1,233 @@ -/* -* Copyright (c) 2024 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import hilog from '@ohos.hilog'; -import { describe, it, expect } from '@ohos/hypium' -import { Driver, ON } from '@ohos.UiTest'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - -const TAG = '[Sample_VpnConnect]'; -const DOMAIN = 0xF811; - -let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); -async function getResourceString(resource: Resource): Promise { - let manage = abilityDelegator.getAppContext().resourceManager - let text = await manage.getStringValue(resource) - return text -} - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - /** - * 启动Ability - */ - it('startAbility_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'startAbility_001 start'); - let driver = Driver.create(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - hilog.info(DOMAIN, TAG, 'startAbility_001 end'); - done(); - }); - - /** - * 进入首页,标题显示正确 - */ - it('IndexPageEnter_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'IndexPageEnter_001 start'); - let driver: Driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Toy VPN')); - let titleComponent = await driver.findComponent(ON.text('Toy VPN')); - let titleContent = await titleComponent.getText(); - await driver.delayMs(200); - expect('Toy VPN').assertEqual(titleContent); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'IndexPageEnter_001 end'); - done(); - }); - - /** - * 在主界面启用VPN - */ - it('StartVpn_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'StartVpn_001 start'); - let driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Start VPN')); - let startVpn = await driver.findComponent(ON.text('Start VPN')); - await driver.delayMs(200); - await startVpn.click(); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'StartVpn_001 end'); - done(); - }); - - /** - * 在主界面启用VPN后,再创建隧道 - */ - it('CreateTunnel_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'CreateTunnel_001 start'); - let driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - // 点击启用VPN - await driver.assertComponentExist(ON.text('Start VPN')); - let startVpn = await driver.findComponent(ON.text('Start VPN')); - await driver.delayMs(200); - await startVpn.click(); - // 点击创建隧道 - await driver.delayMs(200); - await driver.assertComponentExist(ON.text('创建对象')); - let createTunnel = await driver.findComponent(ON.text('创建对象')); - await driver.delayMs(200); - await createTunnel.click(); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'CreateTunnel_001 end'); - done(); - }); - - /** - * 启用VPN后开启隧道保护 - */ - it('StartTunnelProtect_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'StartTunnelProtect_001 start'); - let driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - // 点击启用VPN - await driver.assertComponentExist(ON.text('Start VPN')); - let startVpn = await driver.findComponent(ON.text('Start VPN')); - await driver.delayMs(200); - await startVpn.click(); - // 点击开启隧道保护 - await driver.delayMs(200); - await driver.assertComponentExist(ON.text('隧道保护')); - let protect = await driver.findComponent(ON.text('隧道保护')); - await driver.delayMs(200); - await protect.click(); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'StartTunnelProtect_001 end'); - done(); - }); - - /** - * 启用VPN后启动VPN连接 - */ - it('SetupVpn_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'SetupVpn_001 start'); - let driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - // 点击启用VPN - await driver.assertComponentExist(ON.text('Start VPN')); - let startVpn = await driver.findComponent(ON.text('Start VPN')); - await driver.delayMs(200); - await startVpn.click(); - // 点击开启vpn - await driver.delayMs(200); - await driver.assertComponentExist(ON.text('启动vpn')); - let setupVpn = await driver.findComponent(ON.text('启动vpn')); - await setupVpn.click(); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'SetupVpn_001 end'); - done(); - }); - - /** - * 停用VPN - */ - it('StopVpn_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'StopVpn_001 start'); - let driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Stop VPN')); - let stopVpn = await driver.findComponent(ON.text('Stop VPN')); - await stopVpn.click(); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'StopVpn_001 end') - done(); - }); - - /** - * 关闭VPN连接 - */ - it('CloseVpn_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, 'CloseVpn_001 start'); - let driver = Driver.create(); - await terminateAbility(); - await driver.delayMs(1000); - await startAbility(); - await driver.delayMs(1000); - // 点击停用VPN - await driver.assertComponentExist(ON.text('Stop VPN')); - let stopVpn = await driver.findComponent(ON.text('Stop VPN')); - await stopVpn.click(); - // 点击关闭VPN - await driver.delayMs(200); - await driver.assertComponentExist(ON.text('关闭vpn')); - let closeVpn = await driver.findComponent(ON.text('关闭vpn')); - await closeVpn.click(); - await driver.delayMs(200); - hilog.info(DOMAIN, TAG, 'CloseVpn_001 end'); - done(); - }); - }); -} - -/** - * 拉起应用 - */ -async function startAbility() { - try { - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - await abilityDelegator.startAbility({ - bundleName: "com.example.testvpnclient", - abilityName: "EntryAbility" - }); - } catch (err) { - hilog.info(DOMAIN, TAG, 'startAbility err'); - } -} - -/** - * 关闭应用 - */ -async function terminateAbility() { - try { - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let topAbility = await abilityDelegator.getCurrentTopAbility(); - await topAbility.context.terminateSelf(); - } catch (err) { - hilog.info(DOMAIN, TAG, 'terminateAbility err'); - } -} - +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import hilog from '@ohos.hilog'; +import { describe, it, expect } from '@ohos/hypium' +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const TAG = '[Sample_VpnConnect]'; +const DOMAIN = 0xF811; + +let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); +async function getResourceString(resource: Resource): Promise { + let manage = abilityDelegator.getAppContext().resourceManager + let text = await manage.getStringValue(resource) + return text +} + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /** + * 启动Ability + */ + it('startAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'startAbility_001 start'); + let driver = Driver.create(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + hilog.info(DOMAIN, TAG, 'startAbility_001 end'); + done(); + }); + + /** + * 进入首页,标题显示正确 + */ + it('IndexPageEnter_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'IndexPageEnter_001 start'); + let driver: Driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Toy VPN')); + let titleComponent = await driver.findComponent(ON.text('Toy VPN')); + let titleContent = await titleComponent.getText(); + await driver.delayMs(200); + expect('Toy VPN').assertEqual(titleContent); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'IndexPageEnter_001 end'); + done(); + }); + + /** + * 在主界面启用VPN + */ + it('StartVpn_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'StartVpn_001 start'); + let driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Start VPN')); + let startVpn = await driver.findComponent(ON.text('Start VPN')); + await driver.delayMs(200); + await startVpn.click(); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'StartVpn_001 end'); + done(); + }); + + /** + * 在主界面启用VPN后,再创建隧道 + */ + it('CreateTunnel_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'CreateTunnel_001 start'); + let driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + // 点击启用VPN + await driver.assertComponentExist(ON.text('Start VPN')); + let startVpn = await driver.findComponent(ON.text('Start VPN')); + await driver.delayMs(200); + await startVpn.click(); + // 点击创建隧道 + await driver.delayMs(200); + await driver.assertComponentExist(ON.text('创建对象')); + let createTunnel = await driver.findComponent(ON.text('创建对象')); + await driver.delayMs(200); + await createTunnel.click(); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'CreateTunnel_001 end'); + done(); + }); + + /** + * 启用VPN后开启隧道保护 + */ + it('StartTunnelProtect_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'StartTunnelProtect_001 start'); + let driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + // 点击启用VPN + await driver.assertComponentExist(ON.text('Start VPN')); + let startVpn = await driver.findComponent(ON.text('Start VPN')); + await driver.delayMs(200); + await startVpn.click(); + // 点击开启隧道保护 + await driver.delayMs(200); + await driver.assertComponentExist(ON.text('隧道保护')); + let protect = await driver.findComponent(ON.text('隧道保护')); + await driver.delayMs(200); + await protect.click(); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'StartTunnelProtect_001 end'); + done(); + }); + + /** + * 启用VPN后启动VPN连接 + */ + it('SetupVpn_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'SetupVpn_001 start'); + let driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + // 点击启用VPN + await driver.assertComponentExist(ON.text('Start VPN')); + let startVpn = await driver.findComponent(ON.text('Start VPN')); + await driver.delayMs(200); + await startVpn.click(); + // 点击开启vpn + await driver.delayMs(200); + await driver.assertComponentExist(ON.text('启动vpn')); + let setupVpn = await driver.findComponent(ON.text('启动vpn')); + await setupVpn.click(); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'SetupVpn_001 end'); + done(); + }); + + /** + * 停用VPN + */ + it('StopVpn_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'StopVpn_001 start'); + let driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Stop VPN')); + let stopVpn = await driver.findComponent(ON.text('Stop VPN')); + await stopVpn.click(); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'StopVpn_001 end') + done(); + }); + + /** + * 关闭VPN连接 + */ + it('CloseVpn_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, 'CloseVpn_001 start'); + let driver = Driver.create(); + await terminateAbility(); + await driver.delayMs(1000); + await startAbility(); + await driver.delayMs(1000); + // 点击停用VPN + await driver.assertComponentExist(ON.text('Stop VPN')); + let stopVpn = await driver.findComponent(ON.text('Stop VPN')); + await stopVpn.click(); + // 点击关闭VPN + await driver.delayMs(200); + await driver.assertComponentExist(ON.text('关闭vpn')); + let closeVpn = await driver.findComponent(ON.text('关闭vpn')); + await closeVpn.click(); + await driver.delayMs(200); + hilog.info(DOMAIN, TAG, 'CloseVpn_001 end'); + done(); + }); + }); +} + +/** + * 拉起应用 + */ +async function startAbility() { + try { + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + await abilityDelegator.startAbility({ + bundleName: "com.example.testvpnclient", + abilityName: "EntryAbility" + }); + } catch (err) { + hilog.info(DOMAIN, TAG, 'startAbility err'); + } +} + +/** + * 关闭应用 + */ +async function terminateAbility() { + try { + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let topAbility = await abilityDelegator.getCurrentTopAbility(); + await topAbility.context.terminateSelf(); + } catch (err) { + hilog.info(DOMAIN, TAG, 'terminateAbility err'); + } +} + diff --git a/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/module.json5 b/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/module.json5 index 8a85c47aa89de01d2df7c9f1e4955e89cb03c03e..12caf23cd2f308d179831840ef85132591f578a2 100644 --- a/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Connectivity/VPN/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* -* Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* +* Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Connectivity/VPN/hvigor/hvigor-config.json5 b/code/BasicFeature/Connectivity/VPN/hvigor/hvigor-config.json5 index ccfdcf13408fcd4e571a67a0cfbec84ad120c3b5..f6cf5984545c7c13c4bf8e13b801c223b3af7a43 100644 --- a/code/BasicFeature/Connectivity/VPN/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Connectivity/VPN/hvigor/hvigor-config.json5 @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +/* + * Copyright (c) 2023 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. + */ + +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/BasicFeature/Connectivity/VPN/oh-package.json5 b/code/BasicFeature/Connectivity/VPN/oh-package.json5 index 3c30215fd0f84e0b501cf0a6a8ace8278079971a..427c512f09f4ef18a9a92ae874c543dcd77c44d6 100644 --- a/code/BasicFeature/Connectivity/VPN/oh-package.json5 +++ b/code/BasicFeature/Connectivity/VPN/oh-package.json5 @@ -1,28 +1,28 @@ -/* -* Copyright (c) 2023 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": "testvpnclient", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.6" - } -} +/* +* Copyright (c) 2023 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": "testvpnclient", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.6" + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/.gitignore b/code/BasicFeature/DFX/AppRecovery/.gitignore index b031e2b2be48618dee0d1e1643234c0a59200ffe..5a137750855ea0a5006740284db2f4138bff31e8 100644 --- a/code/BasicFeature/DFX/AppRecovery/.gitignore +++ b/code/BasicFeature/DFX/AppRecovery/.gitignore @@ -1,12 +1,12 @@ -/node_modules -/local.properties -/.idea -**/build -/.hvigor -.cxx -/.clangd -/.clang-format -/.clang-tidy -/oh-package-lock.json5 -/package-lock.json -/entry/package-lock.json +/node_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +/oh-package-lock.json5 +/package-lock.json +/entry/package-lock.json diff --git a/code/BasicFeature/DFX/AppRecovery/AppScope/app.json5 b/code/BasicFeature/DFX/AppRecovery/AppScope/app.json5 index 66eeccf56c84f8367b7b246ea6b973a6823362ea..bf1a3d1a33161786e49e631c272065feac168b5e 100644 --- a/code/BasicFeature/DFX/AppRecovery/AppScope/app.json5 +++ b/code/BasicFeature/DFX/AppRecovery/AppScope/app.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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.recovery", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name", - "distributedNotificationEnabled": true - } -} +/* + * Copyright (c) 2023 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.recovery", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/AppScope/resources/base/element/string.json b/code/BasicFeature/DFX/AppRecovery/AppScope/resources/base/element/string.json index 5d97eb3a833f7cbd9abdd6135fb551609ff74f87..21bb9f49856e57358901250d182285b564c1af51 100644 --- a/code/BasicFeature/DFX/AppRecovery/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/DFX/AppRecovery/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AppRecoverySample" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AppRecoverySample" + } + ] +} diff --git a/code/BasicFeature/DFX/AppRecovery/README_zh.md b/code/BasicFeature/DFX/AppRecovery/README_zh.md index 02d787035e57c4b903f6ef2cca325a95a46494fc..f90c553c5a4435568c22e9fe321df680a08478fb 100644 --- a/code/BasicFeature/DFX/AppRecovery/README_zh.md +++ b/code/BasicFeature/DFX/AppRecovery/README_zh.md @@ -1,128 +1,128 @@ -# 应用故障恢复 - -### 介绍 -本示例展示了在应用中如何适配故障恢复相关接口。 - -样例包含以下场景:\ -一.单Ability自动恢复 \ -在EntryAbility的故障触发页面触发故障,自动重启回到故障触发页面。 - -二.多Ability自动恢复 \ -应用中启动了EntryAbility和SecondAbility,在第二个启动的SecondAbility的故障触发页面触发故障。 \ -自动重启到SecondAbility的故障触发页面。 \ -从任务管理中将EntryAbility切回前台,预期能回到故障触发页面,并恢复页面上点击次数信息。 - -三.多Ability主动恢复 \ -应用中启动了EntryAbility和SecondAbility,在第二个启动的SecondAbility的故障触发页面触发故障。 \ -重启时启动RecoveryAbility,让使用者选择具体启动的Ability。 - -四.Ability后台强制终止恢复 \ -应用中启动了EntryAbility和SecondAbility,并切入后台。\ -系统回收该应用,再次拉起时能够恢复先前的状态。 - -相关概念: \ -故障:指的是应用处于无法提供服务的状态,如卡死以及崩溃。 \ -系统强制终止:指的是由于系统或者应用的原因,系统强制终止正在运行的应用进程,并回收资源的操作。 - -### 效果预览 -|首页|故障触发页面| -|---|---| -|![home](screenshots/devices/zh/entry_page.jpeg)|![fault](screenshots/devices/zh/fault_trigger_page.jpeg)| - -使用说明 - -一.单Ability自动恢复 \ -点击首页点击``跳转到故障触发页面`` \ -在故障触发页面点击按钮``点击``,再点击``保存当前Ability状态``以及``触发JsError``。 \ -以上场景预期:\ -能够回到``故障触发页面``页面,页面上的点击次数与触发保存状态时的一致。 - -二.多Ability自动恢复 \ -点击首页点击跳转到``故障触发页面`` \ -在``故障触发页面``点击``启动SecondAbility`` -点击首页点击``跳转到故障触发页面`` \ -在故障触发页面点击按钮``点击``,再点击``保存当前Ability状态``以及``触发JsError``。 \ -以上场景预期:\ -立即回到SecondAbility的故障触发页面,并恢复页面的点击次数信息。\ -从任务管理中将EntryAbility切回前台,预期能回到故障触发页面,页面上的点击次数与触发保存状态时的一致。 - -三.多Ability主动恢复 \ -点击首页点击跳转到``故障触发页面`` \ -在``故障触发页面``点击``启动SecondAbility`` -在SecondAbility的故障触发页面点击设置重启Ability。 \ -在SecondAbility的故障触发页面点击``触发JsError``。 \ -以上场景预期:\ -重启时启动RecoveryAbility。 - -四.Ability后台强制终止恢复 \ -点击首页点击跳转到``故障触发页面`` \ -在``故障触发页面``点击``启动SecondAbility`` -在SecondAbility的故障触发页面点击Counter,点击``保存当前Ability状态``,并切入后台 \ -使用kill命令强制终止当前应用 \ -以上场景预期:\ -从任务管理中将EntryAbility切回前台,预期能回到故障触发页面,并恢复页面上的点击次数信息。\ -从任务管理中将SecondAbility切回前台,预期能回到故障触发页面,并恢复页面上的点击次数信息。 - -为避免反复拉起,两次测试的间隔至少为60秒(自动拉起的间隔为60秒)。 -### 工程目录 -``` -entry/src/main/ -├── cpp // 触发Native卡死代码 -│   ├── CMakeLists.txt -│   ├── hello.cpp -│   └── types -│   └── libentry -│   ├── index.d.ts -│   └── oh-package.json5 -├── ets -│   ├── ability -│   │   ├── EntryAbility.ets // 测试入口Ability -│   │   ├── RecoveryAbility.ets // 恢复引导Ability -│   │   └── SecondAbility.ets // 测试第二Ability -│   ├── app -│   │   └── MyAbilityStage.ets // 用于初始化appRecovery的配置 -│   ├── common -│   │   ├── Logger.ts // 日志 -│   │   └── TitleBar.ets // 标题 -│   └── pages -│   ├── FaultTriggerPage.ets // 故障触发页面 -│   ├── Index.ets // 首页 -│   └── RecoveryPage.ets // 恢复页面 -``` - -### 具体实现 -* 使能应用恢复功能,源码参考:[MyAbilityStage.ets](entry/src/main/ets/app/MyAbilityStage.ets) - * 在``onCreate``中 调用[appRecovery](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/apprecovery-guidelines.md)接口使能功能 -* 配置支持恢复的Ability,源码参考:[module.json5](entry/src/main/module.json5) - * 在``Ability``的节点中增加``recoverable``的配置,并设置为``true`` -* 实现恢复功能,源码参考:[EntryAbility.ets](entry/src/main/ets/ability/EntryAbility.ets) - * 在``onSaveState``中保存用于恢复的数据 - * 在``onCreate``的``want``参数中恢复所需要的数据 - -### 相关权限 -不涉及 - -### 依赖 -无 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release) - -3.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 - -### 下载 - -给出单独下载本工程的命令,在代码中替换工程目录并以/结尾,如下面示例中的 **code/BasicFeature/DFX/AppRecovery/**,示例如下: - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/DFX/AppRecovery/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` +# 应用故障恢复 + +### 介绍 +本示例展示了在应用中如何适配故障恢复相关接口。 + +样例包含以下场景:\ +一.单Ability自动恢复 \ +在EntryAbility的故障触发页面触发故障,自动重启回到故障触发页面。 + +二.多Ability自动恢复 \ +应用中启动了EntryAbility和SecondAbility,在第二个启动的SecondAbility的故障触发页面触发故障。 \ +自动重启到SecondAbility的故障触发页面。 \ +从任务管理中将EntryAbility切回前台,预期能回到故障触发页面,并恢复页面上点击次数信息。 + +三.多Ability主动恢复 \ +应用中启动了EntryAbility和SecondAbility,在第二个启动的SecondAbility的故障触发页面触发故障。 \ +重启时启动RecoveryAbility,让使用者选择具体启动的Ability。 + +四.Ability后台强制终止恢复 \ +应用中启动了EntryAbility和SecondAbility,并切入后台。\ +系统回收该应用,再次拉起时能够恢复先前的状态。 + +相关概念: \ +故障:指的是应用处于无法提供服务的状态,如卡死以及崩溃。 \ +系统强制终止:指的是由于系统或者应用的原因,系统强制终止正在运行的应用进程,并回收资源的操作。 + +### 效果预览 +|首页|故障触发页面| +|---|---| +|![home](screenshots/devices/zh/entry_page.jpeg)|![fault](screenshots/devices/zh/fault_trigger_page.jpeg)| + +使用说明 + +一.单Ability自动恢复 \ +点击首页点击``跳转到故障触发页面`` \ +在故障触发页面点击按钮``点击``,再点击``保存当前Ability状态``以及``触发JsError``。 \ +以上场景预期:\ +能够回到``故障触发页面``页面,页面上的点击次数与触发保存状态时的一致。 + +二.多Ability自动恢复 \ +点击首页点击跳转到``故障触发页面`` \ +在``故障触发页面``点击``启动SecondAbility`` +点击首页点击``跳转到故障触发页面`` \ +在故障触发页面点击按钮``点击``,再点击``保存当前Ability状态``以及``触发JsError``。 \ +以上场景预期:\ +立即回到SecondAbility的故障触发页面,并恢复页面的点击次数信息。\ +从任务管理中将EntryAbility切回前台,预期能回到故障触发页面,页面上的点击次数与触发保存状态时的一致。 + +三.多Ability主动恢复 \ +点击首页点击跳转到``故障触发页面`` \ +在``故障触发页面``点击``启动SecondAbility`` +在SecondAbility的故障触发页面点击设置重启Ability。 \ +在SecondAbility的故障触发页面点击``触发JsError``。 \ +以上场景预期:\ +重启时启动RecoveryAbility。 + +四.Ability后台强制终止恢复 \ +点击首页点击跳转到``故障触发页面`` \ +在``故障触发页面``点击``启动SecondAbility`` +在SecondAbility的故障触发页面点击Counter,点击``保存当前Ability状态``,并切入后台 \ +使用kill命令强制终止当前应用 \ +以上场景预期:\ +从任务管理中将EntryAbility切回前台,预期能回到故障触发页面,并恢复页面上的点击次数信息。\ +从任务管理中将SecondAbility切回前台,预期能回到故障触发页面,并恢复页面上的点击次数信息。 + +为避免反复拉起,两次测试的间隔至少为60秒(自动拉起的间隔为60秒)。 +### 工程目录 +``` +entry/src/main/ +├── cpp // 触发Native卡死代码 +│   ├── CMakeLists.txt +│   ├── hello.cpp +│   └── types +│   └── libentry +│   ├── index.d.ts +│   └── oh-package.json5 +├── ets +│   ├── ability +│   │   ├── EntryAbility.ets // 测试入口Ability +│   │   ├── RecoveryAbility.ets // 恢复引导Ability +│   │   └── SecondAbility.ets // 测试第二Ability +│   ├── app +│   │   └── MyAbilityStage.ets // 用于初始化appRecovery的配置 +│   ├── common +│   │   ├── Logger.ts // 日志 +│   │   └── TitleBar.ets // 标题 +│   └── pages +│   ├── FaultTriggerPage.ets // 故障触发页面 +│   ├── Index.ets // 首页 +│   └── RecoveryPage.ets // 恢复页面 +``` + +### 具体实现 +* 使能应用恢复功能,源码参考:[MyAbilityStage.ets](entry/src/main/ets/app/MyAbilityStage.ets) + * 在``onCreate``中 调用[appRecovery](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/dfx/apprecovery-guidelines.md)接口使能功能 +* 配置支持恢复的Ability,源码参考:[module.json5](entry/src/main/module.json5) + * 在``Ability``的节点中增加``recoverable``的配置,并设置为``true`` +* 实现恢复功能,源码参考:[EntryAbility.ets](entry/src/main/ets/ability/EntryAbility.ets) + * 在``onSaveState``中保存用于恢复的数据 + * 在``onCreate``的``want``参数中恢复所需要的数据 + +### 相关权限 +不涉及 + +### 依赖 +无 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release) + +3.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 + +### 下载 + +给出单独下载本工程的命令,在代码中替换工程目录并以/结尾,如下面示例中的 **code/BasicFeature/DFX/AppRecovery/**,示例如下: + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/DFX/AppRecovery/ > .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/DFX/AppRecovery/build-profile.json5 b/code/BasicFeature/DFX/AppRecovery/build-profile.json5 index 390b41a9444ff9c8f9fdae6934b65992667fe62f..947c318515daba7da7f38dc0121210ba6d4856c9 100644 --- a/code/BasicFeature/DFX/AppRecovery/build-profile.json5 +++ b/code/BasicFeature/DFX/AppRecovery/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/.gitignore b/code/BasicFeature/DFX/AppRecovery/entry/.gitignore index 4a65948351bcf95d2be1fa983394377e3aaa3a2e..5a6ba80fa3d9498a23ae8ae7d9518f8743fa8a96 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/.gitignore +++ b/code/BasicFeature/DFX/AppRecovery/entry/.gitignore @@ -1,4 +1,4 @@ -/node_modules -/.preview -/build +/node_modules +/.preview +/build /.cxx \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/build-profile.json5 b/code/BasicFeature/DFX/AppRecovery/entry/build-profile.json5 index 4822212a5538b5bf7eef93d447aa21945d947c26..71efbba6e55b38784800ea4b7b82c6bdcc88492d 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/build-profile.json5 +++ b/code/BasicFeature/DFX/AppRecovery/entry/build-profile.json5 @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2023 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": "", - "abiFilters": [ - "armeabi-v7a", - "arm64-v8a" - ], - "cppFlags": "", - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": "", + "abiFilters": [ + "armeabi-v7a", + "arm64-v8a" + ], + "cppFlags": "", + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/hvigorfile.ts b/code/BasicFeature/DFX/AppRecovery/entry/hvigorfile.ts index c57c77181d0d36beb49c897ff3fc1ad92f7eaa7c..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/hvigorfile.ts +++ b/code/BasicFeature/DFX/AppRecovery/entry/hvigorfile.ts @@ -1,2 +1,2 @@ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { hapTasks } from '@ohos/hvigor-ohos-plugin'; +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/code/BasicFeature/DFX/AppRecovery/entry/oh-package.json5 b/code/BasicFeature/DFX/AppRecovery/entry/oh-package.json5 index 92a9bafefbc1a3c13b108fea78a65392ebe0faff..3e99258f08d36a6ecb88e5d369e1d1857d272148 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/oh-package.json5 +++ b/code/BasicFeature/DFX/AppRecovery/entry/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "ISC", - "devDependencies": {}, - "name": "entry", - "description": "app recovery sample", - "repository": {}, - "version": "1.0.0", - "dependencies": {} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "description": "app recovery sample", + "repository": {}, + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/CMakeLists.txt index 8825d3732258b61586a58a0e836d30e23d8d1d11..0304a9904c143dcf8941f600a99a43989fb2057a 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/CMakeLists.txt @@ -1,24 +1,24 @@ -# Copyright (c) 2023 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. -# -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(MyApplication6) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -include_directories(${NATIVERENDER_ROOT_PATH} - ${NATIVERENDER_ROOT_PATH}/include) - -add_library(entry SHARED hello.cpp) +# Copyright (c) 2023 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. +# +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(MyApplication6) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED hello.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/hello.cpp b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/hello.cpp index 4b1c45621ccac30286bcc7e84308b5a98e48b658..32c697284e77fdbbb6576cb8aa81096ff7dc13e8 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/hello.cpp +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/hello.cpp @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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 -#include "napi/native_api.h" - -static napi_value DeadLoop(napi_env env, napi_callback_info info) -{ - while (true) { - printf("aaa\n"); - } - return 0; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor functions[] = { - { "deadLoop", nullptr, DeadLoop, nullptr, nullptr, nullptr, napi_default, nullptr } - }; - napi_define_properties(env, exports, sizeof(functions) / sizeof(functions[0]), functions); - 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); -} +/* + * Copyright (c) 2023 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 +#include "napi/native_api.h" + +static napi_value DeadLoop(napi_env env, napi_callback_info info) +{ + while (true) { + printf("aaa\n"); + } + return 0; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor functions[] = { + { "deadLoop", nullptr, DeadLoop, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(functions) / sizeof(functions[0]), functions); + 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/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/index.d.ts b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/index.d.ts index 50ede76b5da6f59d05d5067da8e55163ecbbf962..7811a521b4a5c6cca88354f96cc6921f2513411a 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 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. - */ - +/* + * Copyright (c) 2023 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 deadLoop: () => number; \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/oh-package.json5 index 982d2e7abbd541c31132878bf64c0201d191655d..58bef51c5d4b7b7a530d5f9f1a6d9fc2edcb6874 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "types": "./index.d.ts", - "name": "libentry.so", - "description": "", - "version": "" +/* + * Copyright (c) 2023 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. + */ + +{ + "types": "./index.d.ts", + "name": "libentry.so", + "description": "", + "version": "" } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/EntryAbility.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/EntryAbility.ets index 5f81cef6f1119f9618b46394b405bfa57abbdd6d..0c92955e9746dd49baf3845d6e069a1ff484f64f 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/EntryAbility.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/EntryAbility.ets @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2023 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 appRecovery from '@ohos.app.ability.appRecovery'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import Window from '@ohos.window'; - -import Logger from '../common/Logger'; -import { CurActiveAbility } from '../common/CurActiveAbility'; - -const TAG: string = 'EntryAbility'; - -export default class EntryAbility extends UIAbility { - isRecoverLaunch: boolean = false; - storage: LocalStorage = new LocalStorage(); - - // Read previous saved status from want if we are launched by appRecovery - restoreLocalStorage(want: Want): void { - Logger.info(TAG, "RestoreLocalStorage String:${want.parameters['Page1Str']} Counter:${want.parameters['Page2Counter']}"); - if (want.parameters !== undefined) { - this.storage.setOrCreate('FaultTriggerPageString', want.parameters['FaultTriggerPageString'] as string); - this.storage.setOrCreate('FaultTriggerPageCounter', want.parameters['FaultTriggerPageCounter'] as number); - } - - } - - onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { - Logger.info(TAG, 'onCreate Want:${JSON.stringify(want)} launchParam: ${JSON.stringify(launchParam)}'); - this.isRecoverLaunch = (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY); - this.storage.setOrCreate('CurrentAbilityName', 'EntryAbility'); - this.storage.setOrCreate('launchReason', launchParam.launchReason.toString()); - this.storage.setOrCreate('lastExitReason', launchParam.lastExitReason.toString()); - if (this.isRecoverLaunch) { - // savedState is in wantParams - this.restoreLocalStorage(want); - this.context.restoreWindowStage(this.storage); - } - } - - onDestroy(): void { - Logger.info(TAG, 'onDestroy'); - } - - onWindowStageCreate(windowStage: Window.WindowStage): void { - Logger.info(TAG, 'onWindowStageCreate'); - // Share storage between pages and current ability - windowStage.loadContent('pages/Index', this.storage, (err, data): void => { - if (err.code) { - Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}'); - return; - } - }); - } - - onWindowStageDestroy(): void { - Logger.info(TAG, 'onWindowStageDestroy'); - } - - onForeground(): void { - Logger.info(TAG, 'onForeground'); - CurActiveAbility.GetInstance().SetGlobalAbility(this); - } - - onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { - Logger.info(TAG, 'onSaveState'); - let string = this.storage.get('FaultTriggerPageString'); - let counter = this.storage.get('FaultTriggerPageCounter'); - wantParam['FaultTriggerPageString'] = string ?? 'Empty'; - wantParam['FaultTriggerPageCounter'] = counter as number; - Logger.info(TAG, 'SavedText:${string} SavedCounter:${counter}'); - return AbilityConstant.OnSaveResult.ALL_AGREE; - } - - onBackground(): void { - Logger.info(TAG, 'onBackground'); - // save state when background - appRecovery.saveAppState(this.context); - } -} +/* + * Copyright (c) 2023 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 appRecovery from '@ohos.app.ability.appRecovery'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import Window from '@ohos.window'; + +import Logger from '../common/Logger'; +import { CurActiveAbility } from '../common/CurActiveAbility'; + +const TAG: string = 'EntryAbility'; + +export default class EntryAbility extends UIAbility { + isRecoverLaunch: boolean = false; + storage: LocalStorage = new LocalStorage(); + + // Read previous saved status from want if we are launched by appRecovery + restoreLocalStorage(want: Want): void { + Logger.info(TAG, "RestoreLocalStorage String:${want.parameters['Page1Str']} Counter:${want.parameters['Page2Counter']}"); + if (want.parameters !== undefined) { + this.storage.setOrCreate('FaultTriggerPageString', want.parameters['FaultTriggerPageString'] as string); + this.storage.setOrCreate('FaultTriggerPageCounter', want.parameters['FaultTriggerPageCounter'] as number); + } + + } + + onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { + Logger.info(TAG, 'onCreate Want:${JSON.stringify(want)} launchParam: ${JSON.stringify(launchParam)}'); + this.isRecoverLaunch = (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY); + this.storage.setOrCreate('CurrentAbilityName', 'EntryAbility'); + this.storage.setOrCreate('launchReason', launchParam.launchReason.toString()); + this.storage.setOrCreate('lastExitReason', launchParam.lastExitReason.toString()); + if (this.isRecoverLaunch) { + // savedState is in wantParams + this.restoreLocalStorage(want); + this.context.restoreWindowStage(this.storage); + } + } + + onDestroy(): void { + Logger.info(TAG, 'onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage): void { + Logger.info(TAG, 'onWindowStageCreate'); + // Share storage between pages and current ability + windowStage.loadContent('pages/Index', this.storage, (err, data): void => { + if (err.code) { + Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}'); + return; + } + }); + } + + onWindowStageDestroy(): void { + Logger.info(TAG, 'onWindowStageDestroy'); + } + + onForeground(): void { + Logger.info(TAG, 'onForeground'); + CurActiveAbility.GetInstance().SetGlobalAbility(this); + } + + onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { + Logger.info(TAG, 'onSaveState'); + let string = this.storage.get('FaultTriggerPageString'); + let counter = this.storage.get('FaultTriggerPageCounter'); + wantParam['FaultTriggerPageString'] = string ?? 'Empty'; + wantParam['FaultTriggerPageCounter'] = counter as number; + Logger.info(TAG, 'SavedText:${string} SavedCounter:${counter}'); + return AbilityConstant.OnSaveResult.ALL_AGREE; + } + + onBackground(): void { + Logger.info(TAG, 'onBackground'); + // save state when background + appRecovery.saveAppState(this.context); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/RecoveryAbility.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/RecoveryAbility.ets index da3abb03d5f1b0c5ed5d2bc3d6bfdcce073abc7c..adea24140cd0d8f2f60c3df4fd9957b9eeb64b46 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/RecoveryAbility.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/RecoveryAbility.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import Window from '@ohos.window' -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import Want from '@ohos.app.ability.Want'; - -import Logger from '../common/Logger' -import { CurActiveAbility } from '../common/CurActiveAbility'; - -const TAG: string = 'SecondAbility'; - -export default class RecoveryAbility extends UIAbility { - storage: LocalStorage = new LocalStorage(); - - onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { - Logger.info(TAG, 'onCreate'); - this.storage.setOrCreate('launchReason', launchParam.launchReason.toString()); - this.storage.setOrCreate('lastExitReason', launchParam.lastExitReason.toString()); - if (want.parameters !== undefined) { - AppStorage.SetOrCreate('RecoverAbility', want.parameters['RecoverAbility'] as string); - } - } - - onDestroy(): void { - Logger.info(TAG, 'onDestroy'); - } - - onWindowStageCreate(windowStage: Window.WindowStage):void { - Logger.info(TAG, 'onWindowStageCreate'); - windowStage.loadContent('pages/RecoveryPage', this.storage, (err, data) => { - if (err.code) { - Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}}'); - return; - } - }); - } - - onWindowStageDestroy(): void { - Logger.info(TAG, 'onWindowStageDestroy'); - } - - onForeground(): void { - Logger.info(TAG, 'onForeground'); - CurActiveAbility.GetInstance().SetGlobalAbility(this); - } - - onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { - // No need to save state - Logger.info(TAG, 'onSaveState'); - return AbilityConstant.OnSaveResult.ALL_REJECT; - } - - onBackground(): void { - // Ability has back to background - Logger.info(TAG, 'onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window' +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import Want from '@ohos.app.ability.Want'; + +import Logger from '../common/Logger' +import { CurActiveAbility } from '../common/CurActiveAbility'; + +const TAG: string = 'SecondAbility'; + +export default class RecoveryAbility extends UIAbility { + storage: LocalStorage = new LocalStorage(); + + onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { + Logger.info(TAG, 'onCreate'); + this.storage.setOrCreate('launchReason', launchParam.launchReason.toString()); + this.storage.setOrCreate('lastExitReason', launchParam.lastExitReason.toString()); + if (want.parameters !== undefined) { + AppStorage.SetOrCreate('RecoverAbility', want.parameters['RecoverAbility'] as string); + } + } + + onDestroy(): void { + Logger.info(TAG, 'onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage):void { + Logger.info(TAG, 'onWindowStageCreate'); + windowStage.loadContent('pages/RecoveryPage', this.storage, (err, data) => { + if (err.code) { + Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}}'); + return; + } + }); + } + + onWindowStageDestroy(): void { + Logger.info(TAG, 'onWindowStageDestroy'); + } + + onForeground(): void { + Logger.info(TAG, 'onForeground'); + CurActiveAbility.GetInstance().SetGlobalAbility(this); + } + + onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { + // No need to save state + Logger.info(TAG, 'onSaveState'); + return AbilityConstant.OnSaveResult.ALL_REJECT; + } + + onBackground(): void { + // Ability has back to background + Logger.info(TAG, 'onBackground'); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/SecondAbility.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/SecondAbility.ets index ed13cc61fb68936224b6b08e0c0c435482cb8b02..2754443218b115e8c5bbb96f93adf47d67f21d27 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/SecondAbility.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/ability/SecondAbility.ets @@ -1,90 +1,90 @@ -/* - * Copyright (c) 2023 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 appRecovery from '@ohos.app.ability.appRecovery'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import Window from '@ohos.window'; - -import Logger from '../common/Logger'; -import { CurActiveAbility } from '../common/CurActiveAbility'; - -const TAG: string = 'SecondAbility'; - -export default class SecondAbility extends UIAbility { - isRecoverLaunch: boolean = false; - storage: LocalStorage = new LocalStorage(); - - // Read previous saved status from want if we are launched by appRecovery - restoreLocalStorage(want: Want) : void { - if (want.parameters !== undefined) { - this.storage.setOrCreate('FaultTriggerPageString', want.parameters['FaultTriggerPageString'] as string); - this.storage.setOrCreate('FaultTriggerPageCounter', want.parameters['FaultTriggerPageCounter'] as number); - } - } - - onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { - Logger.info(TAG, 'onCreate'); - this.storage.setOrCreate('CurrentAbilityName', 'SecondAbility'); - this.storage.setOrCreate('launchReason', launchParam.launchReason.toString()); - this.storage.setOrCreate('lastExitReason', launchParam.lastExitReason.toString()); - this.isRecoverLaunch = (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY); - if (this.isRecoverLaunch) { - // savedState is in wantParams - this.restoreLocalStorage(want); - this.context.restoreWindowStage(this.storage); - } - } - - onDestroy(): void { - Logger.info(TAG, 'onDestroy'); - } - - onWindowStageCreate(windowStage: Window.WindowStage): void { - Logger.info(TAG, 'onWindowStageCreate'); - // Share storage between pages and current ability - windowStage.loadContent('pages/Index', this.storage, (err, data) => { - if (err.code) { - Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}}'); - return; - } - }); - } - - onWindowStageDestroy(): void { - Logger.info(TAG, 'onWindowStageDestroy'); - } - - onForeground(): void { - Logger.info(TAG, 'onForeground'); - CurActiveAbility.GetInstance().SetGlobalAbility(this); - } - - onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { - Logger.info(TAG, 'onSaveState'); - let string = this.storage.get('FaultTriggerPageString'); - let counter = this.storage.get('FaultTriggerPageCounter'); - wantParam['FaultTriggerPageString'] = string ?? 'Empty'; - wantParam['FaultTriggerPageCounter'] = counter as number; - return AbilityConstant.OnSaveResult.ALL_AGREE; - } - - onBackground(): void { - Logger.info(TAG, 'onBackground'); - // save state when background - appRecovery.saveAppState(this.context); - } -} +/* + * Copyright (c) 2023 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 appRecovery from '@ohos.app.ability.appRecovery'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import Window from '@ohos.window'; + +import Logger from '../common/Logger'; +import { CurActiveAbility } from '../common/CurActiveAbility'; + +const TAG: string = 'SecondAbility'; + +export default class SecondAbility extends UIAbility { + isRecoverLaunch: boolean = false; + storage: LocalStorage = new LocalStorage(); + + // Read previous saved status from want if we are launched by appRecovery + restoreLocalStorage(want: Want) : void { + if (want.parameters !== undefined) { + this.storage.setOrCreate('FaultTriggerPageString', want.parameters['FaultTriggerPageString'] as string); + this.storage.setOrCreate('FaultTriggerPageCounter', want.parameters['FaultTriggerPageCounter'] as number); + } + } + + onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { + Logger.info(TAG, 'onCreate'); + this.storage.setOrCreate('CurrentAbilityName', 'SecondAbility'); + this.storage.setOrCreate('launchReason', launchParam.launchReason.toString()); + this.storage.setOrCreate('lastExitReason', launchParam.lastExitReason.toString()); + this.isRecoverLaunch = (launchParam.launchReason == AbilityConstant.LaunchReason.APP_RECOVERY); + if (this.isRecoverLaunch) { + // savedState is in wantParams + this.restoreLocalStorage(want); + this.context.restoreWindowStage(this.storage); + } + } + + onDestroy(): void { + Logger.info(TAG, 'onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage): void { + Logger.info(TAG, 'onWindowStageCreate'); + // Share storage between pages and current ability + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + Logger.info(TAG, 'Failed to load the content. Cause:${JSON.stringify(err)}}'); + return; + } + }); + } + + onWindowStageDestroy(): void { + Logger.info(TAG, 'onWindowStageDestroy'); + } + + onForeground(): void { + Logger.info(TAG, 'onForeground'); + CurActiveAbility.GetInstance().SetGlobalAbility(this); + } + + onSaveState(reason: AbilityConstant.StateType, wantParam: Record): AbilityConstant.OnSaveResult { + Logger.info(TAG, 'onSaveState'); + let string = this.storage.get('FaultTriggerPageString'); + let counter = this.storage.get('FaultTriggerPageCounter'); + wantParam['FaultTriggerPageString'] = string ?? 'Empty'; + wantParam['FaultTriggerPageCounter'] = counter as number; + return AbilityConstant.OnSaveResult.ALL_AGREE; + } + + onBackground(): void { + Logger.info(TAG, 'onBackground'); + // save state when background + appRecovery.saveAppState(this.context); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/app/MyAbilityStage.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/app/MyAbilityStage.ets index 08c38d397153c200a0ca1e0c18519810670539a2..95880a84314466b675b2e4a8ec809c3e05823a68 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/app/MyAbilityStage.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/app/MyAbilityStage.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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 AbilityStage from '@ohos.app.ability.AbilityStage'; -import appRecovery from '@ohos.app.ability.appRecovery'; -import Logger from '../common/Logger' -const TAG: string = 'MyAbilityStage' -export default class MyAbilityStage extends AbilityStage { - onCreate() { - Logger.info(TAG, 'onCreate') - // global switch for appRecovery function in current package - appRecovery.enableAppRecovery(); - } +/* + * Copyright (c) 2023 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 AbilityStage from '@ohos.app.ability.AbilityStage'; +import appRecovery from '@ohos.app.ability.appRecovery'; +import Logger from '../common/Logger' +const TAG: string = 'MyAbilityStage' +export default class MyAbilityStage extends AbilityStage { + onCreate() { + Logger.info(TAG, 'onCreate') + // global switch for appRecovery function in current package + appRecovery.enableAppRecovery(); + } } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/CurActiveAbility.ts b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/CurActiveAbility.ts index 8e98759606288a23c2b8b30e7e437ab2fd4d90a4..253aa9ed5e899128dd86aaf72b526f26ffa0b836 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/CurActiveAbility.ts +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/CurActiveAbility.ts @@ -1,36 +1,36 @@ -/** - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; - -export class CurActiveAbility extends UIAbility { - private static instance: CurActiveAbility; - private _object : Object; - - public static GetInstance(): CurActiveAbility { - if (!CurActiveAbility.instance) { - CurActiveAbility.instance = new CurActiveAbility(); - } - return CurActiveAbility.instance; - } - - SetGlobalAbility(object: Object): void{ - this._object = object; - } - - GetGlobalAbility(): UIAbility { - return this._object as UIAbility; - } +/** + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; + +export class CurActiveAbility extends UIAbility { + private static instance: CurActiveAbility; + private _object : Object; + + public static GetInstance(): CurActiveAbility { + if (!CurActiveAbility.instance) { + CurActiveAbility.instance = new CurActiveAbility(); + } + return CurActiveAbility.instance; + } + + SetGlobalAbility(object: Object): void{ + this._object = object; + } + + GetGlobalAbility(): UIAbility { + return this._object as UIAbility; + } } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/ResUtil.ts b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/ResUtil.ts index d25871d66e7b8cb619fad0ef0aa70ba8a654ba5a..789e0158c4dd0900e65e6d570fba7317b6d32183 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/ResUtil.ts +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/common/ResUtil.ts @@ -1,29 +1,29 @@ -/** - * Copyright (c) 2023 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 resourceManager from '@ohos.resourceManager'; -import Logger from './Logger'; -import { CurActiveAbility } from './CurActiveAbility'; - -export class ResUtil { - async getString(id): Promise { - let resourceMgr = CurActiveAbility.GetInstance().GetGlobalAbility().context.resourceManager; - return resourceMgr.getStringValue(id); - } -} - -let resUtil = new ResUtil(); - -export default resUtil as ResUtil; +/** + * Copyright (c) 2023 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 resourceManager from '@ohos.resourceManager'; +import Logger from './Logger'; +import { CurActiveAbility } from './CurActiveAbility'; + +export class ResUtil { + async getString(id): Promise { + let resourceMgr = CurActiveAbility.GetInstance().GetGlobalAbility().context.resourceManager; + return resourceMgr.getStringValue(id); + } +} + +let resUtil = new ResUtil(); + +export default resUtil as ResUtil; diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/FaultTriggerPage.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/FaultTriggerPage.ets index 5d0c57b05cd66bcfccd939f81057604051b041d0..2dda66cb3e1d812337377371f0760f8343eed900 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/FaultTriggerPage.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/FaultTriggerPage.ets @@ -1,315 +1,315 @@ -/* - * Copyright (c) 2023 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 appRecovery from '@ohos.app.ability.appRecovery'; -import testNapi from 'libentry.so'; -import ResUtil from '../common/ResUtil'; -import { CurActiveAbility } from '../common/CurActiveAbility'; - -@Entry -@Component -struct FaultTriggerPage { - storage = LocalStorage.GetShared(); - @State counter: number = 0; - @State callerAbility: string = ''; - @State launchReason: string = ''; - @State lastExitReason: string = ''; - @State curAbilitySaveState: string = ''; - @State allAbilitySaveState: string = ''; - @State setRecoveryAbility: string = ''; - - aboutToAppear() { - this.counter = this.storage.get('FaultTriggerPageCounter') ?? 0; - this.callerAbility = this.storage.get('CurrentAbilityName') ?? 'UnknownCallingAbility'; - this.launchReason = this.storage.get('launchReason') ?? 'Unknown'; - this.lastExitReason = this.storage.get('lastExitReason') ?? 'Unknown'; - ResUtil.getString($r('app.string.save_state').id).then((value: string) => this.curAbilitySaveState = value); - ResUtil.getString($r('app.string.save_state').id).then((value: string) => this.allAbilitySaveState = value); - ResUtil.getString($r('app.string.set_config').id).then((value: string) => this.setRecoveryAbility = value); - } - - doHeavyWork() : void { - let i = 0; - while (i < 1000000000) { - i++; - let j = 0; - while (j < 1000000000) { - j++; - let k = 0; - while (k < 1000000000) { - k++; - } - } - } - } - - build() { - Column() { - Text(this.callerAbility) - .fontSize('30fp') - .fontWeight(FontWeight.Bold) - .padding({ left: '24vp', right: '24vp', top: '7vp', bottom: '8vp' }) - .margin({ top: '14vp' }) - .textAlign(TextAlign.Start) - .height('56vp') - .width('100%') - .fontColor($r('app.color.text_grey')); - - List() { - ListItem() { - Column() { - Row() { - Text($r('app.string.launch_reason')).fontSize('16fp').width('86%'); - Text('0' + this.launchReason) - .fontSize('14fp') - .width('14%') - .fontColor($r('app.color.text_grey')) - .opacity(0.6) - .textAlign(TextAlign.End); - } - } - }.width('100%').height('48vp').align(Alignment.Center); - - ListItem() { - Column() { - Row() { - Text($r('app.string.last_exit_reason')).fontSize('16fp').width('86%'); - Text('0' + this.lastExitReason) - .fontSize('14fp') - .width('14%') - .fontColor($r('app.color.text_grey')) - .opacity(0.6) - .textAlign(TextAlign.End); - } - } - }.width('100%').height('48vp').align(Alignment.Center); - } - .alignListItem(ListItemAlign.Center) - .margin({ left: '12vp', right: '12vp', top: '8vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) - .divider({ strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') }); - - List() { - ListItem() { - Column() { - Row() { - Row() { - Text($r('app.string.click_counter')).fontSize('16fp') - Text(this.counter.toString()).fontSize('16fp') - }.align(Alignment.Center).width('76.3%'); - Button($r('app.string.counter_name')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - this.counter++; - this.storage.setOrCreate('FaultTriggerPageCounter', this.counter); - this.storage.setOrCreate('FaultTriggerPageString', 'TestFaultTriggerPageString'); - }) - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - .align(Alignment.Center) - .height('28vp'); - }.align(Alignment.Center).height('48vp'); - } - }.align(Alignment.Center).padding({ top: '4vp', bottom: '4vp' }).width('100%'); - } - .height('56vp') - .margin({ left: '12vp', right: '12vp', top: '12vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp' }); - - Text($r('app.string.recover_settings')) - .fontSize('14fp') - .margin({ left: '24vp', right: '24vp', top: '19.5vp', bottom: '9.5vp' }) - .textAlign(TextAlign.Start) - .fontColor($r('app.color.text_grey')) - .opacity(0.6) - .height('19vp') - .width('86.7%'); - - List() { - ListItem() { - Column() { - Row() { - Text($r('app.string.save_current_ability_status')).fontSize('16fp').width('76.3%'); - Button(this.curAbilitySaveState) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - appRecovery.saveAppState(CurActiveAbility.GetInstance().GetGlobalAbility().context); - ResUtil.getString($r('app.string.save_state_done').id) - .then((value: string) => this.curAbilitySaveState = value); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').width('100%'); - } - }.width('100%'); - - ListItem() { - Column() { - Row() { - Text($r('app.string.save_all_ability_status')).fontSize('16fp').width('76.3%'); - Button(this.allAbilitySaveState) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - appRecovery.saveAppState(); - ResUtil.getString($r('app.string.save_state_done').id) - .then((value: string) => this.allAbilitySaveState = value); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').width('100%'); - } - }.width('100%'); - - ListItem() { - Column() { - Row() { - Text($r('app.string.set_recovery_ability')).fontSize('16fp').width('76.3%'); - Button(this.setRecoveryAbility) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - let tmp: Record = {'RecoverAbility': this.callerAbility } - let want: Record = { - 'bundleName': 'com.samples.recovery', - 'abilityName': 'RecoveryAbility', - 'parameters': tmp, - }; - appRecovery.setRestartWant(want); - ResUtil.getString($r('app.string.set_config_done').id).then((value: string) => this.setRecoveryAbility = value); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').width('100%'); - } - }.width('100%'); - - if (this.callerAbility === 'EntryAbility') { - ListItem() { - Column() { - Row() { - Text('SecondAbility').fontSize('16fp').width('76.3%'); - Button($r('app.string.launch_ability')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - if (CurActiveAbility.GetInstance().GetGlobalAbility() == undefined) { - return; - } - let want: Record = { - 'bundleName': 'com.samples.recovery', - 'abilityName': 'SecondAbility' - }; - CurActiveAbility.GetInstance().GetGlobalAbility().context.startAbility(want); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').width('100%'); - } - }.width('100%'); - } - } - .margin({ left: '12vp', right: '12vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) - .divider( - { strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') } - ); - - Text($r('app.string.trigger_fault_items')) - .fontSize('14fp') - .margin({ left: '24vp', right: '24vp', top: '19.5vp', bottom: '9.5vp' }) - .textAlign(TextAlign.Start) - .fontColor($r('app.color.text_grey')) - .opacity(0.6) - .height('19vp') - .width('86.7%'); - - List() { - ListItem() { - Column() { - Row() { - Text($r('app.string.trigger_js_error')).fontSize('16fp').width('76.3%'); - Button($r('app.string.trigger')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - throw new Error('Force Crash'); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').align(Alignment.Center).width('100%'); - } - }.width('100%'); - - ListItem() { - Column() { - Row() { - Text($r('app.string.trigger_freeze_in_js_code')).fontSize('16fp').width('76.3%'); - Button($r('app.string.trigger')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - this.doHeavyWork(); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').align(Alignment.Center).width('100%'); - } - }.width('100%'); - - ListItem() { - Column() { - Row() { - Text($r('app.string.trigger_freeze_in_native_code')).fontSize('16fp').width('76.3%'); - Button($r('app.string.trigger')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - testNapi.add(1, 1); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').align(Alignment.Center).width('100%'); - } - }.align(Alignment.Center).width('100%'); - } - .margin({ left: '12vp', right: '12vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) - .divider({ strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') }); - }.backgroundColor($r('sys.color.ohos_id_color_sub_background')).width('100%').height('100%') - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); - } -} +/* + * Copyright (c) 2023 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 appRecovery from '@ohos.app.ability.appRecovery'; +import testNapi from 'libentry.so'; +import ResUtil from '../common/ResUtil'; +import { CurActiveAbility } from '../common/CurActiveAbility'; + +@Entry +@Component +struct FaultTriggerPage { + storage = LocalStorage.GetShared(); + @State counter: number = 0; + @State callerAbility: string = ''; + @State launchReason: string = ''; + @State lastExitReason: string = ''; + @State curAbilitySaveState: string = ''; + @State allAbilitySaveState: string = ''; + @State setRecoveryAbility: string = ''; + + aboutToAppear() { + this.counter = this.storage.get('FaultTriggerPageCounter') ?? 0; + this.callerAbility = this.storage.get('CurrentAbilityName') ?? 'UnknownCallingAbility'; + this.launchReason = this.storage.get('launchReason') ?? 'Unknown'; + this.lastExitReason = this.storage.get('lastExitReason') ?? 'Unknown'; + ResUtil.getString($r('app.string.save_state').id).then((value: string) => this.curAbilitySaveState = value); + ResUtil.getString($r('app.string.save_state').id).then((value: string) => this.allAbilitySaveState = value); + ResUtil.getString($r('app.string.set_config').id).then((value: string) => this.setRecoveryAbility = value); + } + + doHeavyWork() : void { + let i = 0; + while (i < 1000000000) { + i++; + let j = 0; + while (j < 1000000000) { + j++; + let k = 0; + while (k < 1000000000) { + k++; + } + } + } + } + + build() { + Column() { + Text(this.callerAbility) + .fontSize('30fp') + .fontWeight(FontWeight.Bold) + .padding({ left: '24vp', right: '24vp', top: '7vp', bottom: '8vp' }) + .margin({ top: '14vp' }) + .textAlign(TextAlign.Start) + .height('56vp') + .width('100%') + .fontColor($r('app.color.text_grey')); + + List() { + ListItem() { + Column() { + Row() { + Text($r('app.string.launch_reason')).fontSize('16fp').width('86%'); + Text('0' + this.launchReason) + .fontSize('14fp') + .width('14%') + .fontColor($r('app.color.text_grey')) + .opacity(0.6) + .textAlign(TextAlign.End); + } + } + }.width('100%').height('48vp').align(Alignment.Center); + + ListItem() { + Column() { + Row() { + Text($r('app.string.last_exit_reason')).fontSize('16fp').width('86%'); + Text('0' + this.lastExitReason) + .fontSize('14fp') + .width('14%') + .fontColor($r('app.color.text_grey')) + .opacity(0.6) + .textAlign(TextAlign.End); + } + } + }.width('100%').height('48vp').align(Alignment.Center); + } + .alignListItem(ListItemAlign.Center) + .margin({ left: '12vp', right: '12vp', top: '8vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) + .divider({ strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') }); + + List() { + ListItem() { + Column() { + Row() { + Row() { + Text($r('app.string.click_counter')).fontSize('16fp') + Text(this.counter.toString()).fontSize('16fp') + }.align(Alignment.Center).width('76.3%'); + Button($r('app.string.counter_name')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + this.counter++; + this.storage.setOrCreate('FaultTriggerPageCounter', this.counter); + this.storage.setOrCreate('FaultTriggerPageString', 'TestFaultTriggerPageString'); + }) + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + .align(Alignment.Center) + .height('28vp'); + }.align(Alignment.Center).height('48vp'); + } + }.align(Alignment.Center).padding({ top: '4vp', bottom: '4vp' }).width('100%'); + } + .height('56vp') + .margin({ left: '12vp', right: '12vp', top: '12vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp' }); + + Text($r('app.string.recover_settings')) + .fontSize('14fp') + .margin({ left: '24vp', right: '24vp', top: '19.5vp', bottom: '9.5vp' }) + .textAlign(TextAlign.Start) + .fontColor($r('app.color.text_grey')) + .opacity(0.6) + .height('19vp') + .width('86.7%'); + + List() { + ListItem() { + Column() { + Row() { + Text($r('app.string.save_current_ability_status')).fontSize('16fp').width('76.3%'); + Button(this.curAbilitySaveState) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + appRecovery.saveAppState(CurActiveAbility.GetInstance().GetGlobalAbility().context); + ResUtil.getString($r('app.string.save_state_done').id) + .then((value: string) => this.curAbilitySaveState = value); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').width('100%'); + } + }.width('100%'); + + ListItem() { + Column() { + Row() { + Text($r('app.string.save_all_ability_status')).fontSize('16fp').width('76.3%'); + Button(this.allAbilitySaveState) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + appRecovery.saveAppState(); + ResUtil.getString($r('app.string.save_state_done').id) + .then((value: string) => this.allAbilitySaveState = value); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').width('100%'); + } + }.width('100%'); + + ListItem() { + Column() { + Row() { + Text($r('app.string.set_recovery_ability')).fontSize('16fp').width('76.3%'); + Button(this.setRecoveryAbility) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + let tmp: Record = {'RecoverAbility': this.callerAbility } + let want: Record = { + 'bundleName': 'com.samples.recovery', + 'abilityName': 'RecoveryAbility', + 'parameters': tmp, + }; + appRecovery.setRestartWant(want); + ResUtil.getString($r('app.string.set_config_done').id).then((value: string) => this.setRecoveryAbility = value); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').width('100%'); + } + }.width('100%'); + + if (this.callerAbility === 'EntryAbility') { + ListItem() { + Column() { + Row() { + Text('SecondAbility').fontSize('16fp').width('76.3%'); + Button($r('app.string.launch_ability')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + if (CurActiveAbility.GetInstance().GetGlobalAbility() == undefined) { + return; + } + let want: Record = { + 'bundleName': 'com.samples.recovery', + 'abilityName': 'SecondAbility' + }; + CurActiveAbility.GetInstance().GetGlobalAbility().context.startAbility(want); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').width('100%'); + } + }.width('100%'); + } + } + .margin({ left: '12vp', right: '12vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) + .divider( + { strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') } + ); + + Text($r('app.string.trigger_fault_items')) + .fontSize('14fp') + .margin({ left: '24vp', right: '24vp', top: '19.5vp', bottom: '9.5vp' }) + .textAlign(TextAlign.Start) + .fontColor($r('app.color.text_grey')) + .opacity(0.6) + .height('19vp') + .width('86.7%'); + + List() { + ListItem() { + Column() { + Row() { + Text($r('app.string.trigger_js_error')).fontSize('16fp').width('76.3%'); + Button($r('app.string.trigger')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + throw new Error('Force Crash'); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').align(Alignment.Center).width('100%'); + } + }.width('100%'); + + ListItem() { + Column() { + Row() { + Text($r('app.string.trigger_freeze_in_js_code')).fontSize('16fp').width('76.3%'); + Button($r('app.string.trigger')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + this.doHeavyWork(); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').align(Alignment.Center).width('100%'); + } + }.width('100%'); + + ListItem() { + Column() { + Row() { + Text($r('app.string.trigger_freeze_in_native_code')).fontSize('16fp').width('76.3%'); + Button($r('app.string.trigger')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + testNapi.add(1, 1); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').align(Alignment.Center).width('100%'); + } + }.align(Alignment.Center).width('100%'); + } + .margin({ left: '12vp', right: '12vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) + .divider({ strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') }); + }.backgroundColor($r('sys.color.ohos_id_color_sub_background')).width('100%').height('100%') + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/Index.ets index 5d0ad7ec9b40c6a496587d8356b6d597f9fa963b..a18cab7c373ff2f73b582f3aac7c695cce0f730d 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/Index.ets @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; - -@Entry -@Component -struct FirstPage { - storage = LocalStorage.GetShared(); - @State launchReason: string = ''; - @State lastExitReason: string = ''; - @State callerAbility: string = ''; - - aboutToAppear() { - this.launchReason = this.storage.get('launchReason') ?? 'Unknown'; - this.lastExitReason = this.storage.get('lastExitReason') ?? 'Unknown'; - this.callerAbility = this.storage.get('CurrentAbilityName') ?? 'Unknown'; - } - - build() { - Column() { - Text(this.callerAbility) - .fontSize('30fp') - .fontWeight(FontWeight.Bold) - .padding({ left: '24vp', right: '24vp', top: '7vp', bottom: '8vp' }) - .margin({ top: '14vp' }) - .textAlign(TextAlign.Start) - .height('56vp') - .width('100%') - .fontColor($r('app.color.text_grey')); - - List() { - ListItem() { - Column() { - Row() { - Text($r('app.string.launch_reason')).fontSize('16fp').width('86%'); - Text('0' + this.launchReason) - .fontSize('14fp') - .width('14%') - .fontColor($r('app.color.text_grey')) - .opacity(0.6) - .textAlign(TextAlign.End); - } - } - }.width('100%').height('48vp').align(Alignment.Center); - - ListItem() { - Column() { - Row() { - Text($r('app.string.last_exit_reason')).fontSize('16fp').width('86%'); - Text('0' + this.lastExitReason) - .fontSize('14fp') - .width('14%') - .fontColor($r('app.color.text_grey')) - .opacity(0.6) - .textAlign(TextAlign.End); - } - } - }.width('100%').height('48vp').align(Alignment.Center); - } - .alignListItem(ListItemAlign.Center) - .margin({ left: '12vp', right: '12vp', top: '8vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) - .divider({ strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') }); - - Button($r('app.string.trigger_fault')) - .fontSize('16fp') - .onClick(() => { - router.pushUrl({ url: 'pages/FaultTriggerPage' }); - }) - .width('88.9%') - .margin({ top: '480vp', right: '24vp', left: '24vp', bottom: '34vp' }) - .height('40vp') - .backgroundColor($r('app.color.text_blue_opacity')); - }.backgroundColor($r('sys.color.ohos_id_color_sub_background')).width('100%').height('100%') - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); - } -} +/* + * Copyright (c) 2023 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 router from '@ohos.router'; + +@Entry +@Component +struct FirstPage { + storage = LocalStorage.GetShared(); + @State launchReason: string = ''; + @State lastExitReason: string = ''; + @State callerAbility: string = ''; + + aboutToAppear() { + this.launchReason = this.storage.get('launchReason') ?? 'Unknown'; + this.lastExitReason = this.storage.get('lastExitReason') ?? 'Unknown'; + this.callerAbility = this.storage.get('CurrentAbilityName') ?? 'Unknown'; + } + + build() { + Column() { + Text(this.callerAbility) + .fontSize('30fp') + .fontWeight(FontWeight.Bold) + .padding({ left: '24vp', right: '24vp', top: '7vp', bottom: '8vp' }) + .margin({ top: '14vp' }) + .textAlign(TextAlign.Start) + .height('56vp') + .width('100%') + .fontColor($r('app.color.text_grey')); + + List() { + ListItem() { + Column() { + Row() { + Text($r('app.string.launch_reason')).fontSize('16fp').width('86%'); + Text('0' + this.launchReason) + .fontSize('14fp') + .width('14%') + .fontColor($r('app.color.text_grey')) + .opacity(0.6) + .textAlign(TextAlign.End); + } + } + }.width('100%').height('48vp').align(Alignment.Center); + + ListItem() { + Column() { + Row() { + Text($r('app.string.last_exit_reason')).fontSize('16fp').width('86%'); + Text('0' + this.lastExitReason) + .fontSize('14fp') + .width('14%') + .fontColor($r('app.color.text_grey')) + .opacity(0.6) + .textAlign(TextAlign.End); + } + } + }.width('100%').height('48vp').align(Alignment.Center); + } + .alignListItem(ListItemAlign.Center) + .margin({ left: '12vp', right: '12vp', top: '8vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) + .divider({ strokeWidth: '0.5vp', color: $r('app.color.text_grey_opacity') }); + + Button($r('app.string.trigger_fault')) + .fontSize('16fp') + .onClick(() => { + router.pushUrl({ url: 'pages/FaultTriggerPage' }); + }) + .width('88.9%') + .margin({ top: '480vp', right: '24vp', left: '24vp', bottom: '34vp' }) + .height('40vp') + .backgroundColor($r('app.color.text_blue_opacity')); + }.backgroundColor($r('sys.color.ohos_id_color_sub_background')).width('100%').height('100%') + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/RecoveryPage.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/RecoveryPage.ets index 9f4bb4093b7f9614986f1a7b9b3dc7ccf6f7b223..fcc2469853263ff1a4794be23fcbb8a2ba795661 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/RecoveryPage.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/ets/pages/RecoveryPage.ets @@ -1,112 +1,112 @@ -/* - * Copyright (c) 2023 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 { CurActiveAbility } from '../common/CurActiveAbility'; -@Entry -@Component -struct Index { - storage = LocalStorage.GetShared(); - @State launchParam: string = ''; - @State wantParam: string = ''; - fromEntryAbility: boolean = false; - - aboutToAppear() { - this.launchParam = this.storage.get('launchParam') ?? 'UnknownLaunchParam'; - this.wantParam = this.storage.get('wantParam') ?? 'UnknownWantParam'; - let abilityName = AppStorage.Get('RecoverAbility'); - if (abilityName === 'EntryAbility') { - this.fromEntryAbility = true; - } - } - - build() { - Column() { - Text('RecoveryPage') - .fontSize('30fp') - .fontWeight(FontWeight.Bold) - .padding({ left: '24vp', right: '24vp', top: '4vp', bottom: '4vp' }) - .margin({ top: '14vp' }) - .textAlign(TextAlign.Start) - .height('56vp') - .width('100%') - .fontColor($r('app.color.text_grey')); - - if (this.fromEntryAbility === false) { - List() { - ListItem() { - Column() { - Row() { - Text('SecondAbility').fontSize('16fp').width('76.3%'); - Button($r('app.string.recover')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - if (CurActiveAbility.GetInstance().GetGlobalAbility() == undefined) { - return; - } - let want: Record = { - 'bundleName': 'com.samples.recovery', - 'abilityName': 'SecondAbility' - }; - CurActiveAbility.GetInstance().GetGlobalAbility().context.startAbility(want); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').align(Alignment.Center).width('100%'); - } - }.width('100%') - } - .margin({ left: '12vp', right: '12vp', top: '12vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) - } - - List() { - ListItem() { - Column() { - Row() { - Text('EntryAbility').fontSize('16fp').width('76.3%'); - Button($r('app.string.recover')) - .fontSize('12fp') - .width('23.7%') - .fontColor($r('app.color.text_blue_opacity')) - .onClick(() => { - if (CurActiveAbility.GetInstance().GetGlobalAbility() == undefined) { - return; - } - let want: Record = { - 'bundleName': 'com.samples.recovery', - 'abilityName': 'EntryAbility' - }; - CurActiveAbility.GetInstance().GetGlobalAbility().context.startAbility(want); - }) - .height('28vp') - .backgroundColor($r('sys.color.ohos_id_color_sub_background')) - }.height('48vp').align(Alignment.Center).width('100%'); - } - }.width('100%') - } - .margin({ left: '12vp', right: '12vp', top: '12vp' }) - .width('93.3%') - .borderRadius('24vp') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) - }.backgroundColor($r('sys.color.ohos_id_color_sub_background')).width('100%').height('100%') - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); - } -} +/* + * Copyright (c) 2023 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 { CurActiveAbility } from '../common/CurActiveAbility'; +@Entry +@Component +struct Index { + storage = LocalStorage.GetShared(); + @State launchParam: string = ''; + @State wantParam: string = ''; + fromEntryAbility: boolean = false; + + aboutToAppear() { + this.launchParam = this.storage.get('launchParam') ?? 'UnknownLaunchParam'; + this.wantParam = this.storage.get('wantParam') ?? 'UnknownWantParam'; + let abilityName = AppStorage.Get('RecoverAbility'); + if (abilityName === 'EntryAbility') { + this.fromEntryAbility = true; + } + } + + build() { + Column() { + Text('RecoveryPage') + .fontSize('30fp') + .fontWeight(FontWeight.Bold) + .padding({ left: '24vp', right: '24vp', top: '4vp', bottom: '4vp' }) + .margin({ top: '14vp' }) + .textAlign(TextAlign.Start) + .height('56vp') + .width('100%') + .fontColor($r('app.color.text_grey')); + + if (this.fromEntryAbility === false) { + List() { + ListItem() { + Column() { + Row() { + Text('SecondAbility').fontSize('16fp').width('76.3%'); + Button($r('app.string.recover')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + if (CurActiveAbility.GetInstance().GetGlobalAbility() == undefined) { + return; + } + let want: Record = { + 'bundleName': 'com.samples.recovery', + 'abilityName': 'SecondAbility' + }; + CurActiveAbility.GetInstance().GetGlobalAbility().context.startAbility(want); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').align(Alignment.Center).width('100%'); + } + }.width('100%') + } + .margin({ left: '12vp', right: '12vp', top: '12vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) + } + + List() { + ListItem() { + Column() { + Row() { + Text('EntryAbility').fontSize('16fp').width('76.3%'); + Button($r('app.string.recover')) + .fontSize('12fp') + .width('23.7%') + .fontColor($r('app.color.text_blue_opacity')) + .onClick(() => { + if (CurActiveAbility.GetInstance().GetGlobalAbility() == undefined) { + return; + } + let want: Record = { + 'bundleName': 'com.samples.recovery', + 'abilityName': 'EntryAbility' + }; + CurActiveAbility.GetInstance().GetGlobalAbility().context.startAbility(want); + }) + .height('28vp') + .backgroundColor($r('sys.color.ohos_id_color_sub_background')) + }.height('48vp').align(Alignment.Center).width('100%'); + } + }.width('100%') + } + .margin({ left: '12vp', right: '12vp', top: '12vp' }) + .width('93.3%') + .borderRadius('24vp') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .padding({ left: '12vp', right: '12vp', top: '4vp', bottom: '4vp' }) + }.backgroundColor($r('sys.color.ohos_id_color_sub_background')).width('100%').height('100%') + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/module.json5 b/code/BasicFeature/DFX/AppRecovery/entry/src/main/module.json5 index a096762082fa635a29e2722dde744167fd5a9630..f63149349ababcfe1bc740ab9722ee0ec675b50a 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/module.json5 +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/module.json5 @@ -1,74 +1,74 @@ -/* - * Copyright (c) 2023 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", - "srcEntry": "./ets/app/MyAbilityStage.ets", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/ability/EntryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "recoverable": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "SecondAbility", - "srcEntry": "./ets/ability/SecondAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:TextAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "recoverable": true - }, - { - "name": "RecoveryAbility", - "srcEntry": "./ets/ability/RecoveryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:RecoveryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * Copyright (c) 2023 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", + "srcEntry": "./ets/app/MyAbilityStage.ets", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/ability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "recoverable": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "SecondAbility", + "srcEntry": "./ets/ability/SecondAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:TextAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "recoverable": true + }, + { + "name": "RecoveryAbility", + "srcEntry": "./ets/ability/RecoveryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:RecoveryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/color.json b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/color.json index 357a66c7ff386daa7e2b2f6b4702e37b0428bc57..c3a092dc687dc003a88618ee73ef21eeb4b98c22 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/color.json @@ -1,28 +1,28 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "title_background", - "value": "#0D9FFB" - }, - { - "name": "text_grey", - "value": "#182431" - }, - { - "name": "text_black", - "value": "#000000" - }, - { - "name": "text_grey_opacity", - "value": "#F3F4F4" - }, - { - "name": "text_blue_opacity", - "value": "#007dFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "title_background", + "value": "#0D9FFB" + }, + { + "name": "text_grey", + "value": "#182431" + }, + { + "name": "text_black", + "value": "#000000" + }, + { + "name": "text_grey_opacity", + "value": "#F3F4F4" + }, + { + "name": "text_blue_opacity", + "value": "#007dFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/string.json b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/string.json index 63c648fdf061fa4cba40ba28b00e7aa4e54e9525..e0a8911ecb471961e2a6844cc92ca2f3bd81bac6 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/string.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/element/string.json @@ -1,120 +1,120 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "AppRecoverySample" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "EntryAbility" - }, - { - "name": "TextAbility_label", - "value": "TextAbility" - }, - { - "name": "RecoveryAbility_label", - "value": "RecoveryAbility" - }, - { - "name": "app_has_recovered", - "value": "Application has recovered from error" - }, - { - "name": "trigger_fault", - "value": "Fault trigger page" - }, - { - "name": "current_ability", - "value": "Ability:" - }, - { - "name": "launch_reason", - "value": "Launch reason" - }, - { - "name": "last_exit_reason", - "value": "Last exit reason" - }, - { - "name": "current_status", - "value": "Current status:" - }, - { - "name": "click_counter", - "value": "Click Count:" - }, - { - "name": "trigger_fault_items", - "value": "Trigger Faults" - }, - { - "name": "trigger_js_error", - "value": "Trigger JsError" - }, - { - "name": "trigger_freeze_in_js_code", - "value": "Hung In Js Code" - }, - { - "name": "trigger_freeze_in_native_code", - "value": "Hung In Native Code" - }, - { - "name": "recover_settings", - "value": "Recovery settings" - }, - { - "name": "save_all_ability_status", - "value": "Whole abilities status" - }, - { - "name": "save_current_ability_status", - "value": "Current ability status" - }, - { - "name": "route_to_second_ability", - "value": "Route to SecondAbility" - }, - { - "name": "set_recovery_ability", - "value": "Set recovery ability" - }, - { - "name": "counter_name", - "value": "ClickMe" - }, - { - "name": "save_state", - "value": "Save" - }, - { - "name": "set_config", - "value": "Set" - }, - { - "name": "save_state_done", - "value": "Saved" - }, - { - "name": "set_config_done", - "value": "Set" - }, - { - "name": "launch_ability", - "value": "Launch" - }, - { - "name": "trigger", - "value": "Trigger" - }, - { - "name": "recover", - "value": "Recover" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "AppRecoverySample" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "EntryAbility" + }, + { + "name": "TextAbility_label", + "value": "TextAbility" + }, + { + "name": "RecoveryAbility_label", + "value": "RecoveryAbility" + }, + { + "name": "app_has_recovered", + "value": "Application has recovered from error" + }, + { + "name": "trigger_fault", + "value": "Fault trigger page" + }, + { + "name": "current_ability", + "value": "Ability:" + }, + { + "name": "launch_reason", + "value": "Launch reason" + }, + { + "name": "last_exit_reason", + "value": "Last exit reason" + }, + { + "name": "current_status", + "value": "Current status:" + }, + { + "name": "click_counter", + "value": "Click Count:" + }, + { + "name": "trigger_fault_items", + "value": "Trigger Faults" + }, + { + "name": "trigger_js_error", + "value": "Trigger JsError" + }, + { + "name": "trigger_freeze_in_js_code", + "value": "Hung In Js Code" + }, + { + "name": "trigger_freeze_in_native_code", + "value": "Hung In Native Code" + }, + { + "name": "recover_settings", + "value": "Recovery settings" + }, + { + "name": "save_all_ability_status", + "value": "Whole abilities status" + }, + { + "name": "save_current_ability_status", + "value": "Current ability status" + }, + { + "name": "route_to_second_ability", + "value": "Route to SecondAbility" + }, + { + "name": "set_recovery_ability", + "value": "Set recovery ability" + }, + { + "name": "counter_name", + "value": "ClickMe" + }, + { + "name": "save_state", + "value": "Save" + }, + { + "name": "set_config", + "value": "Set" + }, + { + "name": "save_state_done", + "value": "Saved" + }, + { + "name": "set_config_done", + "value": "Set" + }, + { + "name": "launch_ability", + "value": "Launch" + }, + { + "name": "trigger", + "value": "Trigger" + }, + { + "name": "recover", + "value": "Recover" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/profile/main_pages.json index 262d048acf4c6eeffc4ffcba93ffc77000a1a4a5..98e0d65bd89fe79ee4b4f184f35a2ba10a4b5bb6 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/profile/main_pages.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,7 @@ -{ - "src": [ - "pages/Index", - "pages/FaultTriggerPage", - "pages/RecoveryPage" - ] -} +{ + "src": [ + "pages/Index", + "pages/FaultTriggerPage", + "pages/RecoveryPage" + ] +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/en_US/element/string.json index 63c648fdf061fa4cba40ba28b00e7aa4e54e9525..e0a8911ecb471961e2a6844cc92ca2f3bd81bac6 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/en_US/element/string.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/en_US/element/string.json @@ -1,120 +1,120 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "AppRecoverySample" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "EntryAbility" - }, - { - "name": "TextAbility_label", - "value": "TextAbility" - }, - { - "name": "RecoveryAbility_label", - "value": "RecoveryAbility" - }, - { - "name": "app_has_recovered", - "value": "Application has recovered from error" - }, - { - "name": "trigger_fault", - "value": "Fault trigger page" - }, - { - "name": "current_ability", - "value": "Ability:" - }, - { - "name": "launch_reason", - "value": "Launch reason" - }, - { - "name": "last_exit_reason", - "value": "Last exit reason" - }, - { - "name": "current_status", - "value": "Current status:" - }, - { - "name": "click_counter", - "value": "Click Count:" - }, - { - "name": "trigger_fault_items", - "value": "Trigger Faults" - }, - { - "name": "trigger_js_error", - "value": "Trigger JsError" - }, - { - "name": "trigger_freeze_in_js_code", - "value": "Hung In Js Code" - }, - { - "name": "trigger_freeze_in_native_code", - "value": "Hung In Native Code" - }, - { - "name": "recover_settings", - "value": "Recovery settings" - }, - { - "name": "save_all_ability_status", - "value": "Whole abilities status" - }, - { - "name": "save_current_ability_status", - "value": "Current ability status" - }, - { - "name": "route_to_second_ability", - "value": "Route to SecondAbility" - }, - { - "name": "set_recovery_ability", - "value": "Set recovery ability" - }, - { - "name": "counter_name", - "value": "ClickMe" - }, - { - "name": "save_state", - "value": "Save" - }, - { - "name": "set_config", - "value": "Set" - }, - { - "name": "save_state_done", - "value": "Saved" - }, - { - "name": "set_config_done", - "value": "Set" - }, - { - "name": "launch_ability", - "value": "Launch" - }, - { - "name": "trigger", - "value": "Trigger" - }, - { - "name": "recover", - "value": "Recover" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "AppRecoverySample" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "EntryAbility" + }, + { + "name": "TextAbility_label", + "value": "TextAbility" + }, + { + "name": "RecoveryAbility_label", + "value": "RecoveryAbility" + }, + { + "name": "app_has_recovered", + "value": "Application has recovered from error" + }, + { + "name": "trigger_fault", + "value": "Fault trigger page" + }, + { + "name": "current_ability", + "value": "Ability:" + }, + { + "name": "launch_reason", + "value": "Launch reason" + }, + { + "name": "last_exit_reason", + "value": "Last exit reason" + }, + { + "name": "current_status", + "value": "Current status:" + }, + { + "name": "click_counter", + "value": "Click Count:" + }, + { + "name": "trigger_fault_items", + "value": "Trigger Faults" + }, + { + "name": "trigger_js_error", + "value": "Trigger JsError" + }, + { + "name": "trigger_freeze_in_js_code", + "value": "Hung In Js Code" + }, + { + "name": "trigger_freeze_in_native_code", + "value": "Hung In Native Code" + }, + { + "name": "recover_settings", + "value": "Recovery settings" + }, + { + "name": "save_all_ability_status", + "value": "Whole abilities status" + }, + { + "name": "save_current_ability_status", + "value": "Current ability status" + }, + { + "name": "route_to_second_ability", + "value": "Route to SecondAbility" + }, + { + "name": "set_recovery_ability", + "value": "Set recovery ability" + }, + { + "name": "counter_name", + "value": "ClickMe" + }, + { + "name": "save_state", + "value": "Save" + }, + { + "name": "set_config", + "value": "Set" + }, + { + "name": "save_state_done", + "value": "Saved" + }, + { + "name": "set_config_done", + "value": "Set" + }, + { + "name": "launch_ability", + "value": "Launch" + }, + { + "name": "trigger", + "value": "Trigger" + }, + { + "name": "recover", + "value": "Recover" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/zh_CN/element/string.json index eb713b875bc624f7b49b3c44a176e6f3110e594b..b04853b653f87aea6dae1e247bc1d5042ea80f0e 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/zh_CN/element/string.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/main/resources/zh_CN/element/string.json @@ -1,120 +1,120 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "应用恢复范例" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "EntryAbility" - }, - { - "name": "TextAbility_label", - "value": "TextAbility" - }, - { - "name": "RecoveryAbility_label", - "value": "RecoveryAbility" - }, - { - "name": "app_has_recovered", - "value": "应用已经从故障中恢复" - }, - { - "name": "trigger_fault", - "value": "跳转到故障触发页面" - }, - { - "name": "current_ability", - "value": "当前页面:" - }, - { - "name": "launch_reason", - "value": "启动原因" - }, - { - "name": "last_exit_reason", - "value": "上次退出原因" - }, - { - "name": "current_status", - "value": "当前状态:" - }, - { - "name": "click_counter", - "value": "按钮点击计数:" - }, - { - "name": "trigger_fault_items", - "value": "触发故障" - }, - { - "name": "trigger_js_error", - "value": "JsError" - }, - { - "name": "trigger_freeze_in_js_code", - "value": "Js代码卡死" - }, - { - "name": "trigger_freeze_in_native_code", - "value": "Native代码卡死" - }, - { - "name": "recover_settings", - "value": "应用恢复设置" - }, - { - "name": "save_all_ability_status", - "value": "所有Ability状态" - }, - { - "name": "save_current_ability_status", - "value": "当前Ability状态" - }, - { - "name": "route_to_second_ability", - "value": "启动SecondAbility" - }, - { - "name": "set_recovery_ability", - "value": "恢复Ability" - }, - { - "name": "counter_name", - "value": "点击" - }, - { - "name": "save_state", - "value": "保存" - }, - { - "name": "set_config", - "value": "设置" - }, - { - "name": "save_state_done", - "value": "已保存" - }, - { - "name": "set_config_done", - "value": "已设置" - }, - { - "name": "launch_ability", - "value": "启动" - }, - { - "name": "trigger", - "value": "触发" - }, - { - "name": "recover", - "value": "恢复" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "应用恢复范例" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "EntryAbility" + }, + { + "name": "TextAbility_label", + "value": "TextAbility" + }, + { + "name": "RecoveryAbility_label", + "value": "RecoveryAbility" + }, + { + "name": "app_has_recovered", + "value": "应用已经从故障中恢复" + }, + { + "name": "trigger_fault", + "value": "跳转到故障触发页面" + }, + { + "name": "current_ability", + "value": "当前页面:" + }, + { + "name": "launch_reason", + "value": "启动原因" + }, + { + "name": "last_exit_reason", + "value": "上次退出原因" + }, + { + "name": "current_status", + "value": "当前状态:" + }, + { + "name": "click_counter", + "value": "按钮点击计数:" + }, + { + "name": "trigger_fault_items", + "value": "触发故障" + }, + { + "name": "trigger_js_error", + "value": "JsError" + }, + { + "name": "trigger_freeze_in_js_code", + "value": "Js代码卡死" + }, + { + "name": "trigger_freeze_in_native_code", + "value": "Native代码卡死" + }, + { + "name": "recover_settings", + "value": "应用恢复设置" + }, + { + "name": "save_all_ability_status", + "value": "所有Ability状态" + }, + { + "name": "save_current_ability_status", + "value": "当前Ability状态" + }, + { + "name": "route_to_second_ability", + "value": "启动SecondAbility" + }, + { + "name": "set_recovery_ability", + "value": "恢复Ability" + }, + { + "name": "counter_name", + "value": "点击" + }, + { + "name": "save_state", + "value": "保存" + }, + { + "name": "set_config", + "value": "设置" + }, + { + "name": "save_state_done", + "value": "已保存" + }, + { + "name": "set_config_done", + "value": "已设置" + }, + { + "name": "launch_ability", + "value": "启动" + }, + { + "name": "trigger", + "value": "触发" + }, + { + "name": "recover", + "value": "恢复" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts index ece6bfbc6e61c6e37d3c9a586a1db68b680088d9..1cdc33bdf42a0e9586430cad2ea0f574dfe97f40 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -1,84 +1,84 @@ -/* - * Copyright (c) 2023 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 TestRunner from '@ohos.application.testRunner'; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; -import Logger from '../../../main/ets/common/Logger'; - -let abilityDelegator = undefined; -let abilityDelegatorArguments = undefined; - -const TAG: string = 'TestRunner'; -const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout', - '-s dryRun' -]); - -function translateParamsToString(parameters): string { - let targetParams = ''; - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = '${targetParams} ${key} ${parameters[key]}'; - Logger.info(TAG, 'targetParams:${targetParams}'); - } - } - return targetParams.trim(); -} - -async function onAbilityCreateCallback(): Promise { - Logger.info(TAG, 'onAbilityCreateCallback'); -} - -async function addAbilityMonitorCallback(err: Error): Promise { - Logger.info(TAG, 'addAbilityMonitorCallback'); -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare(): void { - Logger.info(TAG, 'OpenHarmonyTestRunner onPrepare'); - } - - async onRun(): Promise { - Logger.info(TAG, 'OpenHarmonyTestRunner onRun'); - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); - - let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'; - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - }; - - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); - - let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName; - cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); - let debug = abilityDelegatorArguments.parameters['-D']; - if (debug === 'true') { - cmd += ' -D'; - } - Logger.info(TAG, 'cmd:${cmd}'); - - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - Logger.info(TAG, 'OpenHarmonyTestRunner onError'); - }); - Logger.info(TAG, 'OpenHarmonyTestRunner onRun end'); - } -} +/* + * Copyright (c) 2023 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 TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import Logger from '../../../main/ets/common/Logger'; + +let abilityDelegator = undefined; +let abilityDelegatorArguments = undefined; + +const TAG: string = 'TestRunner'; +const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' +]); + +function translateParamsToString(parameters): string { + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = '${targetParams} ${key} ${parameters[key]}'; + Logger.info(TAG, 'targetParams:${targetParams}'); + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback(): Promise { + Logger.info(TAG, 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: Error): Promise { + Logger.info(TAG, 'addAbilityMonitorCallback'); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare(): void { + Logger.info(TAG, 'OpenHarmonyTestRunner onPrepare'); + } + + async onRun(): Promise { + Logger.info(TAG, 'OpenHarmonyTestRunner onRun'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + + let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + + let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters); + let debug = abilityDelegatorArguments.parameters['-D']; + if (debug === 'true') { + cmd += ' -D'; + } + Logger.info(TAG, 'cmd:${cmd}'); + + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + Logger.info(TAG, 'OpenHarmonyTestRunner onError'); + }); + Logger.info(TAG, 'OpenHarmonyTestRunner onRun end'); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/Ability.test.ets index 94e6fccffd012581bec78ddf553b387f2e8b10b6..0febaf1ef3fad02d9dff2c89d423c31cb616619b 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,84 +1,84 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' -import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import Logger from '../../../main/ets/common/Logger' - -const TAG = '[Sample_AppRecovery]' -const BUNDLE = 'appRecovery_' - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }); - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }); - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }); - - it('AppRecoverySample_StartAbility_001', 0, () => { - Logger.info(TAG, BUNDLE + 'StartAbility_001 begin'); - let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); - try { - abilityDelegator.startAbility({ - bundleName: 'com.sample.recovery', abilityName: 'EntryAbility' - }); - } catch (exception) { - expect().assertFail(); - } - Logger.info(TAG, BUNDLE + 'StartAbility_001 end'); - }); - - it('AppRecoverySample_StartAbility_002', 0, () => { - Logger.info(TAG, BUNDLE + 'StartAbility_002 begin'); - let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); - try { - abilityDelegator.startAbility({ - bundleName: 'com.sample.recovery', abilityName: 'SecondAbility' - }); - } catch (exception) { - expect().assertFail(); - } - Logger.info(TAG, BUNDLE + 'StartAbility_002 end'); - }); - - it('AppRecoverySample_StartAbility_003', 0, () => { - Logger.info(TAG, BUNDLE + 'StartAbility_003 begin'); - let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); - try { - abilityDelegator.startAbility({ - bundleName: 'com.sample.recovery', abilityName: 'RecoveryAbility' - }); - } catch (exception) { - expect().assertFail(); - } - Logger.info(TAG, BUNDLE + 'StartAbility_003 end'); - }); - }); -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import Logger from '../../../main/ets/common/Logger' + +const TAG = '[Sample_AppRecovery]' +const BUNDLE = 'appRecovery_' + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + + it('AppRecoverySample_StartAbility_001', 0, () => { + Logger.info(TAG, BUNDLE + 'StartAbility_001 begin'); + let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + try { + abilityDelegator.startAbility({ + bundleName: 'com.sample.recovery', abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + Logger.info(TAG, BUNDLE + 'StartAbility_001 end'); + }); + + it('AppRecoverySample_StartAbility_002', 0, () => { + Logger.info(TAG, BUNDLE + 'StartAbility_002 begin'); + let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + try { + abilityDelegator.startAbility({ + bundleName: 'com.sample.recovery', abilityName: 'SecondAbility' + }); + } catch (exception) { + expect().assertFail(); + } + Logger.info(TAG, BUNDLE + 'StartAbility_002 end'); + }); + + it('AppRecoverySample_StartAbility_003', 0, () => { + Logger.info(TAG, BUNDLE + 'StartAbility_003 begin'); + let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); + try { + abilityDelegator.startAbility({ + bundleName: 'com.sample.recovery', abilityName: 'RecoveryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + Logger.info(TAG, BUNDLE + 'StartAbility_003 end'); + }); + }); +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/List.test.ets index 2a22ae6dc9bdd833b75571bef8c29a0e39dde777..27c07a1a174f6862ea84c4bb5f45bc1789234441 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2023 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() +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/TestAbility.ets index 2295bc84968e7802f06e16b6bdf2badd546cf1f3..b71566313bab42773bb2a3ce0705606ae9d74d42 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import Window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; -import Logger from '../../../main/ets/common/Logger'; - -const TAG = '[Sample_AppRecovery]' - -export default class TestAbility extends UIAbility { - onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { - Logger.info(TAG, 'onCreate Want:${JSON.stringify(want)} launchParam: ${JSON.stringify(launchParam)}'); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); - } - - onDestroy(): void { - Logger.info(TAG, 'onDestroy'); - } - - onWindowStageCreate(windowStage: Window.WindowStage): void { - Logger.info(TAG, 'onWindowStageCreate'); - windowStage.loadContent('testability/pages/Index', (err, data) => { - if (err.code) { - return; - } - }); - } - - onWindowStageDestroy(): void { - Logger.info(TAG, 'onWindowStageDestroy'); - } - - onForeground(): void { - Logger.info(TAG, 'onForeground'); - } - - onBackground(): void { - Logger.info(TAG, 'onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import Window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import Logger from '../../../main/ets/common/Logger'; + +const TAG = '[Sample_AppRecovery]' + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam:AbilityConstant.LaunchParam): void { + Logger.info(TAG, 'onCreate Want:${JSON.stringify(want)} launchParam: ${JSON.stringify(launchParam)}'); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy(): void { + Logger.info(TAG, 'onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage): void { + Logger.info(TAG, 'onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } + + onWindowStageDestroy(): void { + Logger.info(TAG, 'onWindowStageDestroy'); + } + + onForeground(): void { + Logger.info(TAG, 'onForeground'); + } + + onBackground(): void { + Logger.info(TAG, 'onBackground'); + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/pages/Index.ets index 874769e7cb5ed899068327ea6c4bda2284ddb936..98da6018fb63b794221dafbac0088bcf83bf825d 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Index { - aboutToAppear() { - } - - @State message: string = 'Hello World' - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(() => { - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Index { + aboutToAppear() { + } + + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(() => { + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/module.json5 b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/module.json5 index be787551f087b82ccb3cda239a6c9a503d40a754..b86e44a1f92d479be6f163b5c225b000f27b4b47 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/color.json b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/color.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/string.json b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/string.json index 04e87abb7232eeca56a0e436b32ecc84576d5ead..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/string.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/element/string.json @@ -1,16 +1,16 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - } - ] +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/profile/test_pages.json index c3d813c41aa8ac1b64ccf124bb705adefb381787..b7e7343cacb32ce982a45e76daad86e435e054fe 100644 --- a/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/profile/test_pages.json +++ b/code/BasicFeature/DFX/AppRecovery/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -1,5 +1,5 @@ -{ - "src": [ - "testability/pages/Index" - ] -} +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/code/BasicFeature/DFX/AppRecovery/hvigorfile.ts b/code/BasicFeature/DFX/AppRecovery/hvigorfile.ts index 1a4d9969c6ab9c5b03543519686d9d713e729402..6478186902c0c1ad7c966a929c7d6b7d8ae7a9f3 100644 --- a/code/BasicFeature/DFX/AppRecovery/hvigorfile.ts +++ b/code/BasicFeature/DFX/AppRecovery/hvigorfile.ts @@ -1,2 +1,2 @@ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/code/BasicFeature/DFX/AppRecovery/oh-package.json5 b/code/BasicFeature/DFX/AppRecovery/oh-package.json5 index 57600fe0a1fabaf59708b8eaeb87e33815dbc144..3dc884c6f82052fd4d5d2a1f1e202fad43cbeb12 100644 --- a/code/BasicFeature/DFX/AppRecovery/oh-package.json5 +++ b/code/BasicFeature/DFX/AppRecovery/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "ISC", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "name": "AppRecoverySample", - "description": "app recovery sample", - "repository": {}, - "version": "1.0.0", - "dependencies": {} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "name": "AppRecoverySample", + "description": "app recovery sample", + "repository": {}, + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/.gitignore b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/.gitignore old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/app.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/app.json5 old mode 100755 new mode 100644 index edc19e4572698a17e57006511172e90fd4473bde..3470aba677de9e4dfce354a98d2b007fa9727be3 --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/app.json5 +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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": "ohos.samples.UTDType", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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": "ohos.samples.UTDType", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/resources/base/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 312b4a8ac19334ec4e2b596fb7fcf6231021cc2e..2f400f979454bec995ff417b3f6875fe5f20d799 --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UTDType" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UTDType" + } + ] +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/resources/base/media/app_icon.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/README_zh.md b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/README_zh.md old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/build-profile.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/build-profile.json5 old mode 100755 new mode 100644 index c38ebad24c2f09453adc769b45e5be152063a258..ce0311a17532780c9b0a98f429f705d32d0f6eee --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/build-profile.json5 +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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": 11, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/* + * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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": 11, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/.gitignore b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/build-profile.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/build-profile.json5 old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/hvigorfile.js b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/hvigorfile.js old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/oh-package.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/oh-package.json5 old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/entryability/EntryAbility.ts old mode 100755 new mode 100644 index db9f5c164eef5f147c46961cf73dbdfd814d29cc..414945cf53013f4ba746d7000f2c32686320ebb9 --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/displayMediaFile.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/displayMediaFile.ets old mode 100755 new mode 100644 index 75723cb5c9c84ffac09b685ea1303313032d7089..509e7ebcd6d1375d6b373726a99a548754788859 --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/displayMediaFile.ets +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/displayMediaFile.ets @@ -1,162 +1,162 @@ -/* - * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 utdDesc from '@ohos.data.uniformTypeDescriptor'; -import router from '@ohos.router'; -import { logger } from '../util/Logger'; - -const TAG: string = 'DisplayMediaFile'; - -interface paramsTape { - src: string, - selectIconFile: string, -} - -interface FileIconType { - type: string, - value: string, - icon: Resource -} - -const FILE_TYPE_ICON: FileIconType[] = [ - { - type: "Image", - value: "general.image", - icon: $r("app.media.image") - }, - { - type: "Audio", - value: "general.audio", - icon: $r("app.media.myAudio") - }, - { - type: "Video", - value: "general.video", - icon: $r("app.media.video") - } -] - -@Entry -@Component -struct selectMediaType { - @State src: string = (router.getParams() as paramsTape).src; - @State selectIconFile: string = (router.getParams() as paramsTape).selectIconFile; - private routerBackUrl: string = 'pages/selectMediaType'; - - onPageShow() { - this.src = (router.getParams() as paramsTape).src; - this.selectIconFile = (router.getParams() as paramsTape).selectIconFile; - } - - getFileIcon(fileName: string): Resource { - let fileIcon = $r("app.media.file"); - let index = fileName.lastIndexOf('.'); - if (index < 0) { - return fileIcon; - } else { - let fileExtension = fileName.substring(index); - let utd = utdDesc.getUniformDataTypeByFilenameExtension(fileExtension); - let typeObj: utdDesc.TypeDescriptor; - try { - typeObj = utdDesc.getTypeDescriptor(utd); - } catch (e) { - logger.info(TAG, `invalid file type`); - return fileIcon; - } - FILE_TYPE_ICON.forEach(DataType => { - if(typeObj.belongsTo(DataType.value)) { - logger.info(TAG, `file type: ${DataType.type}`); - fileIcon = DataType.icon; - } - }) - return fileIcon; - } - } - - build() { - Column() { - Column() { - Row() { - Image($r('app.media.utdType_back')) - .id('thirdPageBack') - .width(24) - .height(24) - .visibility(Visibility.Visible) - .objectFit(ImageFit.Fill) - .alignSelf(ItemAlign.Auto) - .margin({ left: 24, right: 12 }) - .onClick(() => { - router.pushUrl({ url: this.routerBackUrl }, router.RouterMode.Single); - }) - Text($r('app.string.displayMediaFile_title')) - .fontStyle(FontStyle.Normal) - .fontSize(20) - .textAlign(TextAlign.Start) - .fontWeight(700) - } - .width('100%') - .height(56) - } - .width(280) - .height(56) - .alignItems(HorizontalAlign.Start) - .justifyContent(FlexAlign.Center) - - Column() { - List({ space: 2, initialIndex: 0 }) { - ListItem() { - Row() { - Image(this.getFileIcon(this.src)) - .id('imageBack') - .width(24) - .height(24) - .objectFit(ImageFit.Fill) - .alignSelf(ItemAlign.Auto) - .margin({ left: 12, right: 12 }) - Text(this.src) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - }.width('100%').height('100%') - } - } - .listDirection(Axis.Vertical) // 排列方向 - .scrollBar(BarState.Auto) - .friction(0.6) - .margin({ left: 12, right: 12 }) - .borderRadius(24) - .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring - .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { - logger.info(TAG, 'first' + firstIndex) - logger.info(TAG, 'last' + lastIndex) - logger.info(TAG, 'center' + centerIndex) - }) - .onScroll((scrollOffset: number, scrollState: ScrollState) => { - logger.info(TAG, `onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset) - }) - .backgroundColor(0xFFFFFF) - .alignListItem(ListItemAlign.Center) - } - .width('100%') - .height(64) - .alignItems(HorizontalAlign.Start) - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundColor($r('app.color.background_shallow_grey')) - } -} +/* + * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 utdDesc from '@ohos.data.uniformTypeDescriptor'; +import router from '@ohos.router'; +import { logger } from '../util/Logger'; + +const TAG: string = 'DisplayMediaFile'; + +interface paramsTape { + src: string, + selectIconFile: string, +} + +interface FileIconType { + type: string, + value: string, + icon: Resource +} + +const FILE_TYPE_ICON: FileIconType[] = [ + { + type: "Image", + value: "general.image", + icon: $r("app.media.image") + }, + { + type: "Audio", + value: "general.audio", + icon: $r("app.media.myAudio") + }, + { + type: "Video", + value: "general.video", + icon: $r("app.media.video") + } +] + +@Entry +@Component +struct selectMediaType { + @State src: string = (router.getParams() as paramsTape).src; + @State selectIconFile: string = (router.getParams() as paramsTape).selectIconFile; + private routerBackUrl: string = 'pages/selectMediaType'; + + onPageShow() { + this.src = (router.getParams() as paramsTape).src; + this.selectIconFile = (router.getParams() as paramsTape).selectIconFile; + } + + getFileIcon(fileName: string): Resource { + let fileIcon = $r("app.media.file"); + let index = fileName.lastIndexOf('.'); + if (index < 0) { + return fileIcon; + } else { + let fileExtension = fileName.substring(index); + let utd = utdDesc.getUniformDataTypeByFilenameExtension(fileExtension); + let typeObj: utdDesc.TypeDescriptor; + try { + typeObj = utdDesc.getTypeDescriptor(utd); + } catch (e) { + logger.info(TAG, `invalid file type`); + return fileIcon; + } + FILE_TYPE_ICON.forEach(DataType => { + if(typeObj.belongsTo(DataType.value)) { + logger.info(TAG, `file type: ${DataType.type}`); + fileIcon = DataType.icon; + } + }) + return fileIcon; + } + } + + build() { + Column() { + Column() { + Row() { + Image($r('app.media.utdType_back')) + .id('thirdPageBack') + .width(24) + .height(24) + .visibility(Visibility.Visible) + .objectFit(ImageFit.Fill) + .alignSelf(ItemAlign.Auto) + .margin({ left: 24, right: 12 }) + .onClick(() => { + router.pushUrl({ url: this.routerBackUrl }, router.RouterMode.Single); + }) + Text($r('app.string.displayMediaFile_title')) + .fontStyle(FontStyle.Normal) + .fontSize(20) + .textAlign(TextAlign.Start) + .fontWeight(700) + } + .width('100%') + .height(56) + } + .width(280) + .height(56) + .alignItems(HorizontalAlign.Start) + .justifyContent(FlexAlign.Center) + + Column() { + List({ space: 2, initialIndex: 0 }) { + ListItem() { + Row() { + Image(this.getFileIcon(this.src)) + .id('imageBack') + .width(24) + .height(24) + .objectFit(ImageFit.Fill) + .alignSelf(ItemAlign.Auto) + .margin({ left: 12, right: 12 }) + Text(this.src) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + }.width('100%').height('100%') + } + } + .listDirection(Axis.Vertical) // 排列方向 + .scrollBar(BarState.Auto) + .friction(0.6) + .margin({ left: 12, right: 12 }) + .borderRadius(24) + .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring + .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { + logger.info(TAG, 'first' + firstIndex) + logger.info(TAG, 'last' + lastIndex) + logger.info(TAG, 'center' + centerIndex) + }) + .onScroll((scrollOffset: number, scrollState: ScrollState) => { + logger.info(TAG, `onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset) + }) + .backgroundColor(0xFFFFFF) + .alignListItem(ListItemAlign.Center) + } + .width('100%') + .height(64) + .alignItems(HorizontalAlign.Start) + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundColor($r('app.color.background_shallow_grey')) + } +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/selectMediaType.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/selectMediaType.ets old mode 100755 new mode 100644 index 74dddc4837f32f2461a06964244a3d19d6e640b4..b445b259f732671b57e3417ac58a6ba530279f69 --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/selectMediaType.ets +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/pages/selectMediaType.ets @@ -1,264 +1,264 @@ -/* - * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; -import fs from '@ohos.file.fs'; -import common from '@ohos.app.ability.common'; -import utdDesc from '@ohos.data.uniformTypeDescriptor'; -import { BusinessError } from '@ohos.base'; -import { logger } from '../util/Logger'; - -const TAG: string = 'SelectMediaType'; -// 获取应用文件路径 -let context = getContext(this) as common.UIAbilityContext; -let baseDir = context.filesDir; -let filesDir = baseDir + '/udmf_test'; - -let class2UTD = new Map([ - ["All", "All"], - ["Images", "general.image"], - ["Audios", "general.audio"], - ["Videos", "general.video"] -]); - -class FileInfo { - filename: string; - iconFile: string; - - constructor(fileName: string, iconFile: string) { - this.filename = fileName; - this.iconFile = iconFile; - } -} - -@Entry -@Component -struct selectMediaType { - @State text: string = "Images"; - @State index: number = 1; - @State space: number = 12; - @State arrowPosition: ArrowPosition = ArrowPosition.END; - @State fileNames: string[] = []; - @State selectedFilesInfos: FileInfo[] = []; - private routerBackUrl: string = 'pages/Index'; - private routerNextUrl: string = 'pages/displayMediaFile'; - - getListFile(): string[] { - let files = fs.listFileSync(filesDir); - return files; - } - - UpdateSelectedFiles(): void { - this.fileNames = this.getListFile(); - for (let i = this.selectedFilesInfos.length - 1; i >= 0; i--) { - this.selectedFilesInfos.pop(); - } - this.selectedFilesInfos = []; - logger.info(TAG, "selectText: " + this.text) - for (let i = 0; i < this.fileNames.length; i++) { - let fileName = this.fileNames[i]; - let index = fileName.lastIndexOf('.'); - if (index < 0) { - logger.info(TAG, `fileNames file: ${fileName}`); - if (this.text == "All") { - let fileInfo = new FileInfo(fileName, ""); - this.selectedFilesInfos.push(fileInfo); - } - continue; - } else { - let fileExtension = fileName.substring(index); - let utd = utdDesc.getUniformDataTypeByFilenameExtension(fileExtension); - logger.info(TAG, `fileNames file: ${fileName}, extension: ${fileExtension}, utd: ${utd}`); - try { - if (utd != null) { - let typeObj: utdDesc.TypeDescriptor = utdDesc.getTypeDescriptor(utd); - if (class2UTD.get(this.text) == "All") { - let fileInfo = new FileInfo(fileName, typeObj.iconFile); - this.selectedFilesInfos.push(fileInfo); - logger.info(TAG, `All type: ${fileInfo.filename}, utd: ${utd}, iconFile: ${fileInfo.iconFile}`); - } else { - let ret = typeObj.belongsTo(class2UTD.get(this.text)); - logger.info(TAG, `typeObj.belongsTo: ${fileName}, utd: ${class2UTD.get(this.text)}, ret: ${ret} iconFile: ${typeObj.iconFile}`); - if (ret) { - let fileInfo = new FileInfo(fileName, typeObj.iconFile); - this.selectedFilesInfos.push(fileInfo); - } - } - } else { - if (class2UTD.get(this.text) == "All") { - let fileInfo = new FileInfo(fileName, ""); - this.selectedFilesInfos.push(fileInfo); - logger.info(TAG, `utd null All type: ${fileInfo.filename}, utd: ${utd}, iconFile: ${fileInfo.iconFile}`); - } - } - } - catch (e) { - let error: BusinessError = e as BusinessError; - logger.error(TAG, `belongsTo throws an exception. code is ${error.code}, message is ${error.message}`); - } - } - } - logger.info(TAG, `all files ${JSON.stringify(this.selectedFilesInfos)}}`); - } - - aboutToAppear() { - logger.info(TAG, 'filesDir: ' + filesDir); - this.UpdateSelectedFiles(); - } - - aboutToDisappear() { - for (let i = this.selectedFilesInfos.length - 1; i >= 0; i--) { - this.selectedFilesInfos.pop(); - } - } - - build() { - Column() { - Column() { - Row() { - Image($r('app.media.utdType_back')) - .id('secondPageBack') - .width(24) - .height(24) - .objectFit(ImageFit.Fill) - .visibility(Visibility.Visible) - .alignSelf(ItemAlign.Auto) - .margin({ left: 24, right: 12 }) - .onClick(() => { - router.pushUrl({ url: this.routerBackUrl }, router.RouterMode.Single); - }) - Text($r('app.string.selectMediaType_title')) - .fontStyle(FontStyle.Normal) - .fontSize(20) - .fontWeight(700) - .textAlign(TextAlign.Start) - .id('titleText') - } - .width('100%') - .height(56) - .alignItems(VerticalAlign.Center) - } - .width(280) - .height(56) - .alignItems(HorizontalAlign.Start) - - Column() { - Select([{ value: 'All', icon: $r('app.media.ic_select_option_collection') }, - { value: 'Images', icon: $r('app.media.ic_select_option_collection') }, - { value: 'Audios', icon: $r('app.media.ic_select_option_collection') }, - { value: 'Videos', icon: $r('app.media.ic_select_option_collection') }]) - .selected(this.index) - .value(this.text) - .id('SelectTypeList') - .font({ size: 16, weight: 500 }) - .fontColor('#182431') - .selectedOptionFont({ size: 16, weight: 500 }) - .optionFont({ size: 16, weight: 500 }) - .space(this.space) - .arrowPosition(this.arrowPosition) - .menuAlign(MenuAlignType.START, { dx: 0, dy: 0 }) - .backgroundColor($r('app.color.background_shallow_grey')) - .onSelect((index: number, text?: string | undefined) => { - this.index = index; - if (text) { - this.text = text; - logger.info(TAG, 'Select type:' + text); - this.UpdateSelectedFiles(); - } - }) - } - .margin({ left: 12, right: 12 }) - .height(48) - .width(160) - .alignItems(HorizontalAlign.Start) - .justifyContent(FlexAlign.Center) - - Column() { - List({ space: 2, initialIndex: 0 }) { - ForEach(this.selectedFilesInfos, (item: FileInfo, no: Number) => { - ListItem() { - Row() { - Column() { - Text(item.filename) - .fontSize(16) - .height(46) - .textAlign(TextAlign.Start) - .margin({ left: 12, right: 12 }) - .fontWeight(500) - .id("textFilename_" + no) - .visibility(Visibility.Visible) - .onClick(() => { - logger.info(TAG, `selected file:` + item.filename + `and clicked`); - try { - router.pushUrl({ - url: this.routerNextUrl, - params: { - src: item.filename, - selectIconFile: item.iconFile - } - }, router.RouterMode.Single); - } - catch (e) { - let error: BusinessError = e as BusinessError; - logger.error(TAG, `select file and router exception. code is ${error.code}, message is ${error.message}`); - } - }) - Divider() - .vertical(false) - .height(2) - .color($r('app.color.background_shallow_grey')) - .opacity(0.6) - .margin({ left: 12, right: 12 }) - } - .width('100%') - .height(48) - .justifyContent(FlexAlign.Center) - .alignItems(HorizontalAlign.Start) - } - .width('100%') - .height(48) - .alignItems(VerticalAlign.Center) - } - .id("listItem_" + no) - }) - } - .listDirection(Axis.Vertical) // 排列方向 - .scrollBar(BarState.Auto) - .friction(0.6) - .margin({ left: 12, right: 12 }) - .borderRadius(24) - .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring - .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { - logger.info(TAG, 'first: ' + firstIndex); - logger.info(TAG, 'last: ' + lastIndex); - logger.info(TAG, 'center: ' + centerIndex); - }) - .onScroll((scrollOffset: number, scrollState: ScrollState) => { - logger.info(TAG, `onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset); - }) - .backgroundColor(0xFFFFFF) - } - .width('100%') - .height(680) - .alignItems(HorizontalAlign.Start) - .justifyContent(FlexAlign.Start) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - .alignItems(HorizontalAlign.Start) - .justifyContent(FlexAlign.Center) - } -} +/* + * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; +import fs from '@ohos.file.fs'; +import common from '@ohos.app.ability.common'; +import utdDesc from '@ohos.data.uniformTypeDescriptor'; +import { BusinessError } from '@ohos.base'; +import { logger } from '../util/Logger'; + +const TAG: string = 'SelectMediaType'; +// 获取应用文件路径 +let context = getContext(this) as common.UIAbilityContext; +let baseDir = context.filesDir; +let filesDir = baseDir + '/udmf_test'; + +let class2UTD = new Map([ + ["All", "All"], + ["Images", "general.image"], + ["Audios", "general.audio"], + ["Videos", "general.video"] +]); + +class FileInfo { + filename: string; + iconFile: string; + + constructor(fileName: string, iconFile: string) { + this.filename = fileName; + this.iconFile = iconFile; + } +} + +@Entry +@Component +struct selectMediaType { + @State text: string = "Images"; + @State index: number = 1; + @State space: number = 12; + @State arrowPosition: ArrowPosition = ArrowPosition.END; + @State fileNames: string[] = []; + @State selectedFilesInfos: FileInfo[] = []; + private routerBackUrl: string = 'pages/Index'; + private routerNextUrl: string = 'pages/displayMediaFile'; + + getListFile(): string[] { + let files = fs.listFileSync(filesDir); + return files; + } + + UpdateSelectedFiles(): void { + this.fileNames = this.getListFile(); + for (let i = this.selectedFilesInfos.length - 1; i >= 0; i--) { + this.selectedFilesInfos.pop(); + } + this.selectedFilesInfos = []; + logger.info(TAG, "selectText: " + this.text) + for (let i = 0; i < this.fileNames.length; i++) { + let fileName = this.fileNames[i]; + let index = fileName.lastIndexOf('.'); + if (index < 0) { + logger.info(TAG, `fileNames file: ${fileName}`); + if (this.text == "All") { + let fileInfo = new FileInfo(fileName, ""); + this.selectedFilesInfos.push(fileInfo); + } + continue; + } else { + let fileExtension = fileName.substring(index); + let utd = utdDesc.getUniformDataTypeByFilenameExtension(fileExtension); + logger.info(TAG, `fileNames file: ${fileName}, extension: ${fileExtension}, utd: ${utd}`); + try { + if (utd != null) { + let typeObj: utdDesc.TypeDescriptor = utdDesc.getTypeDescriptor(utd); + if (class2UTD.get(this.text) == "All") { + let fileInfo = new FileInfo(fileName, typeObj.iconFile); + this.selectedFilesInfos.push(fileInfo); + logger.info(TAG, `All type: ${fileInfo.filename}, utd: ${utd}, iconFile: ${fileInfo.iconFile}`); + } else { + let ret = typeObj.belongsTo(class2UTD.get(this.text)); + logger.info(TAG, `typeObj.belongsTo: ${fileName}, utd: ${class2UTD.get(this.text)}, ret: ${ret} iconFile: ${typeObj.iconFile}`); + if (ret) { + let fileInfo = new FileInfo(fileName, typeObj.iconFile); + this.selectedFilesInfos.push(fileInfo); + } + } + } else { + if (class2UTD.get(this.text) == "All") { + let fileInfo = new FileInfo(fileName, ""); + this.selectedFilesInfos.push(fileInfo); + logger.info(TAG, `utd null All type: ${fileInfo.filename}, utd: ${utd}, iconFile: ${fileInfo.iconFile}`); + } + } + } + catch (e) { + let error: BusinessError = e as BusinessError; + logger.error(TAG, `belongsTo throws an exception. code is ${error.code}, message is ${error.message}`); + } + } + } + logger.info(TAG, `all files ${JSON.stringify(this.selectedFilesInfos)}}`); + } + + aboutToAppear() { + logger.info(TAG, 'filesDir: ' + filesDir); + this.UpdateSelectedFiles(); + } + + aboutToDisappear() { + for (let i = this.selectedFilesInfos.length - 1; i >= 0; i--) { + this.selectedFilesInfos.pop(); + } + } + + build() { + Column() { + Column() { + Row() { + Image($r('app.media.utdType_back')) + .id('secondPageBack') + .width(24) + .height(24) + .objectFit(ImageFit.Fill) + .visibility(Visibility.Visible) + .alignSelf(ItemAlign.Auto) + .margin({ left: 24, right: 12 }) + .onClick(() => { + router.pushUrl({ url: this.routerBackUrl }, router.RouterMode.Single); + }) + Text($r('app.string.selectMediaType_title')) + .fontStyle(FontStyle.Normal) + .fontSize(20) + .fontWeight(700) + .textAlign(TextAlign.Start) + .id('titleText') + } + .width('100%') + .height(56) + .alignItems(VerticalAlign.Center) + } + .width(280) + .height(56) + .alignItems(HorizontalAlign.Start) + + Column() { + Select([{ value: 'All', icon: $r('app.media.ic_select_option_collection') }, + { value: 'Images', icon: $r('app.media.ic_select_option_collection') }, + { value: 'Audios', icon: $r('app.media.ic_select_option_collection') }, + { value: 'Videos', icon: $r('app.media.ic_select_option_collection') }]) + .selected(this.index) + .value(this.text) + .id('SelectTypeList') + .font({ size: 16, weight: 500 }) + .fontColor('#182431') + .selectedOptionFont({ size: 16, weight: 500 }) + .optionFont({ size: 16, weight: 500 }) + .space(this.space) + .arrowPosition(this.arrowPosition) + .menuAlign(MenuAlignType.START, { dx: 0, dy: 0 }) + .backgroundColor($r('app.color.background_shallow_grey')) + .onSelect((index: number, text?: string | undefined) => { + this.index = index; + if (text) { + this.text = text; + logger.info(TAG, 'Select type:' + text); + this.UpdateSelectedFiles(); + } + }) + } + .margin({ left: 12, right: 12 }) + .height(48) + .width(160) + .alignItems(HorizontalAlign.Start) + .justifyContent(FlexAlign.Center) + + Column() { + List({ space: 2, initialIndex: 0 }) { + ForEach(this.selectedFilesInfos, (item: FileInfo, no: Number) => { + ListItem() { + Row() { + Column() { + Text(item.filename) + .fontSize(16) + .height(46) + .textAlign(TextAlign.Start) + .margin({ left: 12, right: 12 }) + .fontWeight(500) + .id("textFilename_" + no) + .visibility(Visibility.Visible) + .onClick(() => { + logger.info(TAG, `selected file:` + item.filename + `and clicked`); + try { + router.pushUrl({ + url: this.routerNextUrl, + params: { + src: item.filename, + selectIconFile: item.iconFile + } + }, router.RouterMode.Single); + } + catch (e) { + let error: BusinessError = e as BusinessError; + logger.error(TAG, `select file and router exception. code is ${error.code}, message is ${error.message}`); + } + }) + Divider() + .vertical(false) + .height(2) + .color($r('app.color.background_shallow_grey')) + .opacity(0.6) + .margin({ left: 12, right: 12 }) + } + .width('100%') + .height(48) + .justifyContent(FlexAlign.Center) + .alignItems(HorizontalAlign.Start) + } + .width('100%') + .height(48) + .alignItems(VerticalAlign.Center) + } + .id("listItem_" + no) + }) + } + .listDirection(Axis.Vertical) // 排列方向 + .scrollBar(BarState.Auto) + .friction(0.6) + .margin({ left: 12, right: 12 }) + .borderRadius(24) + .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring + .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { + logger.info(TAG, 'first: ' + firstIndex); + logger.info(TAG, 'last: ' + lastIndex); + logger.info(TAG, 'center: ' + centerIndex); + }) + .onScroll((scrollOffset: number, scrollState: ScrollState) => { + logger.info(TAG, `onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset); + }) + .backgroundColor(0xFFFFFF) + } + .width('100%') + .height(680) + .alignItems(HorizontalAlign.Start) + .justifyContent(FlexAlign.Start) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + .alignItems(HorizontalAlign.Start) + .justifyContent(FlexAlign.Center) + } +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/util/Logger.ts b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/ets/util/Logger.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/module.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/module.json5 old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/element/color.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/file.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/file.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/ic_select_option_collection.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/ic_select_option_collection.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/icon.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/image.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/image.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/myAudio.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/myAudio.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/utdType_back.svg b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/utdType_back.svg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/video.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/media/video.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/en/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/en/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/zh/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/zh/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/Application/TestAbilityStage.ts b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/Application/TestAbilityStage.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/testability/TestAbility.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/testability/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/util/Logger.ts b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/ets/util/Logger.ts old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/module.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/element/color.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/media/icon.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/base/profile/test_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/en/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/en/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/zh/element/string.json b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/entry/src/ohosTest/resources/zh/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigor/hvigor-config.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index 3e204d93247770d06a95af202bfe2c9f11f5a45e..122677b194bc767301ef00a87a4b93c45562fe31 --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "3.0.9", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.9" - } +{ + "hvigorVersion": "3.0.9", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.9" + } } \ No newline at end of file diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigor/hvigor-wrapper.js b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigor/hvigor-wrapper.js old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigorw b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigorw old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigorw.bat b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/hvigorw.bat old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/oh-package.json5 b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/oh-package.json5 old mode 100755 new mode 100644 index 3762fe6b2a97a0e2cfe64c08744a2c2eb59bd5a2..368c840c89b3a0550d4bcb58ce0a86ad228b487c --- a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/oh-package.json5 +++ b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myfile", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "myfile", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/ohosTest.md b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/screenshots/display_file.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/screenshots/display_file.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/screenshots/first.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/screenshots/first.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/screenshots/select_type.png b/code/BasicFeature/DataManagement/UDMF/UniformTypeDescriptor/UTDType/screenshots/select_type.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/app.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/app.json5 index e621231c39bfb930dc721877a2707baaeb2803bf..88e81944882a7b5814c3bd2db1076a5d37a9c018 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/app.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.sensor", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.sensor", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/resources/base/element/string.json b/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/resources/base/element/string.json index 27bc1ff1ff0ecab8166457e5dafe073557ef6deb..3050b880be8741dc98a4a8232fca9fae94652d80 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "Sensor" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "Sensor" + } + ] +} diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/build-profile.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/build-profile.json5 index 7c88aef542571888b8d0231907cdb8cbfde46f9f..6b7e50621e658f015253cc648ca80b70ad5b8c45 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/build-profile.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/build-profile.json5 @@ -1,41 +1,41 @@ -/* - * Copyright (c) 2023 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": { - "compileSdkVersion": 9, - "compatibleSdkVersion": 9, - "products": [ - { - "name": "default", - "signingConfig": "default", - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": { + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/build-profile.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/build-profile.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/oh-package.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/oh-package.json5 index 80997033c906a6c587247cdaf29a174d9212b479..e7aaaec223615df3fef35b07ed52d2fbbc43a0f9 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/oh-package.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "library": "file:../libs/library.har" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "library": "file:../libs/library.har" + } +} diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/ets/entryability/EntryAbility.ts index 202b948c9ed4dd76c512c9225e676899cb8907b8..7370b8f3270dfb1cc5824b1d9fe959f82b7ede74 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/module.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/module.json5 index 4dd6059374f1c75c5562d42f8b09a31082659d40..370d208a19c7f950b63a59f96c9eec8bc2b41c52 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/module.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/module.json5 @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.VIBRATE", - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.VIBRATE", + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/resources/base/element/color.json b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/ohosTest/module.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/ohosTest/module.json5 index 259be9c7d7cd4d0ee34176d052eafa7c3e3f0b6a..237ccad18bb855c80f49912561d2c6cab46eb810 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/hvigor/hvigor-config.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/hvigor/hvigor-config.json5 index 9fa38552b00172f3bd25c8e973caebb4b8e82de0..0450bec27475c1853a73087292c8a8d946880600 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "2.4.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.4.2" - } -} +{ + "hvigorVersion": "2.4.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "2.4.2" + } +} diff --git a/code/BasicFeature/DeviceManagement/Sensor/Capi/oh-package.json5 b/code/BasicFeature/DeviceManagement/Sensor/Capi/oh-package.json5 index 8ce88801dde6f221c4966625d6814e9ad64c094f..4dc65913833eb2c035908863133cdb85e480bd09 100644 --- a/code/BasicFeature/DeviceManagement/Sensor/Capi/oh-package.json5 +++ b/code/BasicFeature/DeviceManagement/Sensor/Capi/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "sensor", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "sensor", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/app.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/app.json5 index 1f9987259b27c3f6a853c720206b24f814f6350b..6c137fcb314a0d38d009e82b6bae63e7d58f6bf1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/app.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/app.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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.haptic", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name", - "distributedNotificationEnabled": true - } -} +/* + * Copyright (c) 2023 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.haptic", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/resources/base/element/string.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/resources/base/element/string.json index b2c6a66807cdaa47974eb3a6145740f74c2509ab..13156d6afcf2082181fdd648c62ff835a4a67389 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "Haptic Sample" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "Haptic Sample" + } + ] +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/build-profile.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/build-profile.json5 index 390b41a9444ff9c8f9fdae6934b65992667fe62f..947c318515daba7da7f38dc0121210ba6d4856c9 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/build-profile.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/build-profile.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/build-profile.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/oh-package.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/oh-package.json5 index 7cee9755d2e97da5568f5cbb4a44896c8c929552..fcff8e1a08dd69ab29d8791a8cb2721d2350ede8 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/oh-package.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "ISC", - "devDependencies": {}, - "name": "entry", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": { - "library": "file:../libs/library.har" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": { + "library": "file:../libs/library.har" + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Battle.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Battle.ets index f7469ab6f1068b2612b77f013e6792b8a5840deb..57b8b4aaa44e443d63f54c24cb201149ded4dfdc 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Battle.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Battle.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageBattleList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct BattleLayout { - @State battleList: ImageDataSource = new ImageDataSource(getImageBattleList()) - @State status: boolean[] = [false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $battleList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageBattleList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct BattleLayout { + @State battleList: ImageDataSource = new ImageDataSource(getImageBattleList()) + @State status: boolean[] = [false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $battleList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Common.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Common.ets index 66c1ee33f0b6da3e3a5220ae9777385429b1b4f4..4e9ebcef1535425cc6b0f566d080e3db8f56e609 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Common.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Common.ets @@ -1,95 +1,95 @@ -/* - * Copyright (c) 2023 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 { playVibrateCustom, getDynamicStates } from '../module/Util' -import { ImageDataSource, ImagesData } from '../module/ImageData' -import AudioPlayer from '../module/AudioPlayer' -import Logger from '../module/Logger' - -const TAG = '[CommonLayout]' - -@Component -export default struct CommonLayout { - @Link dataList: ImageDataSource - @Link status: boolean[] - @Link vibrationIntensity: string - @Link php: string - - build() { - Column({ space: 10 }) { - List() { - LazyForEach(this.dataList, (item: ImagesData) => { - ListItem() { - Row() { - Row() { - Image(item.src) - .width(60) - .height(50) - .borderRadius(5) - .autoResize(false) - } - - Stack({ alignContent: Alignment.Start }) { - Column() { - Text(item.name) - .fontSize(15) - .fontColor(Color.White) - } - .alignItems(HorizontalAlign.Start) - .padding({ left: 20 }) - } - .layoutWeight(7) - - if (item.id !== undefined) { - Image($r("app.media.music")) - .width(15) - .height(15) - .visibility(this.status[item.id] ? Visibility.Visible : Visibility.Hidden) - } - } - .id("audioHaptic") - .width("95%") - .height(70) - .padding({ top: 5, left: 10, right: 10, bottom: 5 }) - .backgroundColor(this.status[item.id!] ? "#1a3e3f56" : "#4d191a32") - .onClick(() => { - this.status = getDynamicStates(this.status, item.id!) - AudioPlayer.playAudio(item.audioName!) - if (this.vibrationIntensity === 'H') { - Logger.info(TAG, "High intensity mode") - playVibrateCustom(item.vibratorFileH!, this.php) - } else if (this.vibrationIntensity === 'M') { - Logger.info(TAG, "Middle intensity mode") - playVibrateCustom(item.vibratorFileM!, this.php) - } else if (this.vibrationIntensity === 'L') { - Logger.info(TAG, "Low intensity mode") - playVibrateCustom(item.vibratorFileL!, this.php) - } else { - Logger.info(TAG, "Vibration mode error") - } - if (item.id) { - Logger.info(TAG, item.id.toString() + ' ' + item.name + ' ' + item.audioName) - } - }) - } - }) // LazyForEach - } - .listDirection(Axis.Vertical) - .divider({ strokeWidth: 3, color: "#00f3f3f3", startMargin: 0, endMargin: 0 }) - .height('50%') - .width('100%') - } - } -} +/* + * Copyright (c) 2023 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 { playVibrateCustom, getDynamicStates } from '../module/Util' +import { ImageDataSource, ImagesData } from '../module/ImageData' +import AudioPlayer from '../module/AudioPlayer' +import Logger from '../module/Logger' + +const TAG = '[CommonLayout]' + +@Component +export default struct CommonLayout { + @Link dataList: ImageDataSource + @Link status: boolean[] + @Link vibrationIntensity: string + @Link php: string + + build() { + Column({ space: 10 }) { + List() { + LazyForEach(this.dataList, (item: ImagesData) => { + ListItem() { + Row() { + Row() { + Image(item.src) + .width(60) + .height(50) + .borderRadius(5) + .autoResize(false) + } + + Stack({ alignContent: Alignment.Start }) { + Column() { + Text(item.name) + .fontSize(15) + .fontColor(Color.White) + } + .alignItems(HorizontalAlign.Start) + .padding({ left: 20 }) + } + .layoutWeight(7) + + if (item.id !== undefined) { + Image($r("app.media.music")) + .width(15) + .height(15) + .visibility(this.status[item.id] ? Visibility.Visible : Visibility.Hidden) + } + } + .id("audioHaptic") + .width("95%") + .height(70) + .padding({ top: 5, left: 10, right: 10, bottom: 5 }) + .backgroundColor(this.status[item.id!] ? "#1a3e3f56" : "#4d191a32") + .onClick(() => { + this.status = getDynamicStates(this.status, item.id!) + AudioPlayer.playAudio(item.audioName!) + if (this.vibrationIntensity === 'H') { + Logger.info(TAG, "High intensity mode") + playVibrateCustom(item.vibratorFileH!, this.php) + } else if (this.vibrationIntensity === 'M') { + Logger.info(TAG, "Middle intensity mode") + playVibrateCustom(item.vibratorFileM!, this.php) + } else if (this.vibrationIntensity === 'L') { + Logger.info(TAG, "Low intensity mode") + playVibrateCustom(item.vibratorFileL!, this.php) + } else { + Logger.info(TAG, "Vibration mode error") + } + if (item.id) { + Logger.info(TAG, item.id.toString() + ' ' + item.name + ' ' + item.audioName) + } + }) + } + }) // LazyForEach + } + .listDirection(Axis.Vertical) + .divider({ strokeWidth: 3, color: "#00f3f3f3", startMargin: 0, endMargin: 0 }) + .height('50%') + .width('100%') + } + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Environment.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Environment.ets index 68cebf3f046fa7b2e73d28c7031f887872742a5c..7ef5240367f61e4b073acbd815e046f2da7a22b8 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Environment.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Environment.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageEnvironmentList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct EnvironmentLayout { - @State environmentList: ImageDataSource = new ImageDataSource(getImageEnvironmentList()) - @State status: boolean[] = [false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $environmentList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageEnvironmentList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct EnvironmentLayout { + @State environmentList: ImageDataSource = new ImageDataSource(getImageEnvironmentList()) + @State status: boolean[] = [false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $environmentList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Exercise.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Exercise.ets index 2de2cb07c83cffd3aff35c4af2184ff1a31c0090..7543a256b9901806bc1458b8c0fb5cdfbf03068e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Exercise.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Exercise.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageExerciseList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct ExerciseLayout { - @State exerciseList: ImageDataSource = new ImageDataSource(getImageExerciseList()) - @State status: boolean[] = [false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $exerciseList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageExerciseList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct ExerciseLayout { + @State exerciseList: ImageDataSource = new ImageDataSource(getImageExerciseList()) + @State status: boolean[] = [false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $exerciseList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Footstep.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Footstep.ets index 56b4e443b9db1b0cf6febbd5558d82328f923cd3..db58ec43d351d23be8713d07d989dd697abd1a55 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Footstep.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Footstep.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageFootstepList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct FootstepLayout { - @State footstepList: ImageDataSource = new ImageDataSource(getImageFootstepList()) - @State status: boolean[] = [false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $footstepList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageFootstepList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct FootstepLayout { + @State footstepList: ImageDataSource = new ImageDataSource(getImageFootstepList()) + @State status: boolean[] = [false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $footstepList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Instrument.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Instrument.ets index 263509737366a3dbdb221445983a387d280c560f..0f4cf857f2eda4d23fab8cafc65f1c17379c4016 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Instrument.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Instrument.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageInstrumentsList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct InstrumentLayout { - @State instrumentList: ImageDataSource = new ImageDataSource(getImageInstrumentsList()) - @State status: boolean[] = [false, false, false, false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $instrumentList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageInstrumentsList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct InstrumentLayout { + @State instrumentList: ImageDataSource = new ImageDataSource(getImageInstrumentsList()) + @State status: boolean[] = [false, false, false, false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $instrumentList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Interaction.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Interaction.ets index 9936c87b1c9ab38c1d7ccf4d2c2e6e16a39bee78..0f11126a628b388f2908aa4057215f6f7decaa00 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Interaction.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Interaction.ets @@ -1,216 +1,216 @@ -/* - * Copyright (c) 2023 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 { playVibrateCustom } from '../module/Util' - -@Component -export default struct InteractionLayout { - @State status: boolean[] = [false, false, false, false] - @State stateSlideLeftRight: AnimationStatus = AnimationStatus.Initial - @State stateSlideUp: AnimationStatus = AnimationStatus.Initial - @State stateSwitchApp: AnimationStatus = AnimationStatus.Initial - @State stateUpSlideStop: AnimationStatus = AnimationStatus.Initial - @State iterations: number = 1 - @Link php: string - - build() { - Column() { - List({ space: 20 }) { - ListItem() { - Row({ space: 30 }) { - Column({ space: 10 }) { - Row() { - ImageAnimator() - .images([ - { src: $r("app.media.Slide_LeftRight1") }, - { src: $r("app.media.Slide_LeftRight2") }, - { src: $r("app.media.Slide_LeftRight3") }, - { src: $r("app.media.Slide_LeftRight4") }, - { src: $r("app.media.Slide_LeftRight5") }, - { src: $r("app.media.Slide_LeftRight6") }, - { src: $r("app.media.Slide_LeftRight7") }, - { src: $r("app.media.Slide_LeftRight8") }, - { src: $r("app.media.Slide_LeftRight9") }, - { src: $r("app.media.Slide_LeftRight10") }, - { src: $r("app.media.Slide_LeftRight11") }, - { src: $r("app.media.Slide_LeftRight12") }, - ]) - .borderRadius(10) - .duration(3000) - .state(this.stateSlideLeftRight) - .fillMode(FillMode.None) - .iterations(this.iterations) - .width("100%") - .height("100%") - .onFinish(() => { - this.stateSlideLeftRight = AnimationStatus.Initial - }) - } - .width('30%') - .borderRadius(20) - .backgroundColor("#66191a32") - .height("60%") - .onClick(() => { - this.stateSlideLeftRight = AnimationStatus.Running - playVibrateCustom("Slide_LeftRight.json", this.php) - }) - - Text($r("app.string.interaction_slide_left_right")) - .fontColor(Color.White) - .fontSize(18) - } - - Column({ space: 10 }) { - Row() { - ImageAnimator() - .images([ - { src: $r("app.media.slide_up1") }, - { src: $r("app.media.slide_up2") }, - { src: $r("app.media.slide_up3") }, - { src: $r("app.media.slide_up4") }, - { src: $r("app.media.slide_up5") }, - { src: $r("app.media.slide_up6") }, - { src: $r("app.media.slide_up7") }, - { src: $r("app.media.slide_up8") }, - { src: $r("app.media.slide_up9") }, - ]) - .borderRadius(10) - .duration(2250) - .state(this.stateSlideUp) - .fillMode(FillMode.None) - .iterations(this.iterations) - .width("100%") - .height("100%") - .onFinish(() => { - this.stateSlideUp = AnimationStatus.Initial - }) - } - .width('30%') - .borderRadius(20) - .backgroundColor("#66191a32") - .height("60%") - .onClick(() => { - this.stateSlideUp = AnimationStatus.Running - playVibrateCustom("Slide_Up.json", this.php) - }) - - Text($r("app.string.interaction_slide_up")) - .fontColor(Color.White) - .fontSize(18) - } - } - .justifyContent(FlexAlign.Center) - } - .margin({ left: "1%" }) - .width("100%") - - ListItem() { - Row({ space: 30 }) { - Column({ space: 10 }) { - Row() { - ImageAnimator() - .images([ - { src: $r("app.media.Switch_App1") }, - { src: $r("app.media.Switch_App2") }, - { src: $r("app.media.Switch_App3") }, - { src: $r("app.media.Switch_App4") }, - { src: $r("app.media.Switch_App5") }, - { src: $r("app.media.Switch_App6") }, - { src: $r("app.media.Switch_App7") }, - { src: $r("app.media.Switch_App8") }, - { src: $r("app.media.Switch_App9") }, - { src: $r("app.media.Switch_App10") }, - { src: $r("app.media.Switch_App11") }, - { src: $r("app.media.Switch_App12") }, - { src: $r("app.media.Switch_App13") }, - { src: $r("app.media.Switch_App14") }, - ]) - .borderRadius(10) - .duration(3500) - .state(this.stateSwitchApp) - .fillMode(FillMode.None) - .iterations(this.iterations) - .width("100%") - .height("100%") - .onFinish(() => { - this.stateSwitchApp = AnimationStatus.Initial - }) - } - .width('30%') - .borderRadius(20) - .backgroundColor("#66191a32") - .height("60%") - .onClick(() => { - this.stateSwitchApp = AnimationStatus.Running - playVibrateCustom("Switch_App.json", this.php) - }) - - Text($r("app.string.interaction_switch_app")) - .fontColor(Color.White) - .fontSize(18) - } - - Column({ space: 10 }) { - Row() { - ImageAnimator() - .images([ - { src: $r("app.media.Upslide_Stop1") }, - { src: $r("app.media.Upslide_Stop2") }, - { src: $r("app.media.Upslide_Stop3") }, - { src: $r("app.media.Upslide_Stop4") }, - { src: $r("app.media.Upslide_Stop5") }, - { src: $r("app.media.Upslide_Stop6") }, - { src: $r("app.media.Upslide_Stop7") }, - { src: $r("app.media.Upslide_Stop8") }, - { src: $r("app.media.Upslide_Stop9") }, - { src: $r("app.media.Upslide_Stop10") }, - { src: $r("app.media.Upslide_Stop11") }, - { src: $r("app.media.Upslide_Stop12") }, - ]) - .borderRadius(10) - .duration(3000) - .state(this.stateUpSlideStop) - .fillMode(FillMode.None) - .iterations(this.iterations) - .width("100%") - .height("100%") - .onFinish(() => { - this.stateUpSlideStop = AnimationStatus.Initial - }) - } - .width('30%') - .borderRadius(20) - .backgroundColor("#66191a32") - .height("60%") - .onClick(() => { - this.stateUpSlideStop = AnimationStatus.Running - playVibrateCustom("UpSlide_Stop.json", this.php) - }) - - Text($r("app.string.interaction_slide_stop")) - .fontColor(Color.White) - .fontSize(18) - } - } - .justifyContent(FlexAlign.Center) - } - .margin({ left: "1%" }) - .width("100%") - } - .height('50%') - .width("100%") - } - } -} +/* + * Copyright (c) 2023 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 { playVibrateCustom } from '../module/Util' + +@Component +export default struct InteractionLayout { + @State status: boolean[] = [false, false, false, false] + @State stateSlideLeftRight: AnimationStatus = AnimationStatus.Initial + @State stateSlideUp: AnimationStatus = AnimationStatus.Initial + @State stateSwitchApp: AnimationStatus = AnimationStatus.Initial + @State stateUpSlideStop: AnimationStatus = AnimationStatus.Initial + @State iterations: number = 1 + @Link php: string + + build() { + Column() { + List({ space: 20 }) { + ListItem() { + Row({ space: 30 }) { + Column({ space: 10 }) { + Row() { + ImageAnimator() + .images([ + { src: $r("app.media.Slide_LeftRight1") }, + { src: $r("app.media.Slide_LeftRight2") }, + { src: $r("app.media.Slide_LeftRight3") }, + { src: $r("app.media.Slide_LeftRight4") }, + { src: $r("app.media.Slide_LeftRight5") }, + { src: $r("app.media.Slide_LeftRight6") }, + { src: $r("app.media.Slide_LeftRight7") }, + { src: $r("app.media.Slide_LeftRight8") }, + { src: $r("app.media.Slide_LeftRight9") }, + { src: $r("app.media.Slide_LeftRight10") }, + { src: $r("app.media.Slide_LeftRight11") }, + { src: $r("app.media.Slide_LeftRight12") }, + ]) + .borderRadius(10) + .duration(3000) + .state(this.stateSlideLeftRight) + .fillMode(FillMode.None) + .iterations(this.iterations) + .width("100%") + .height("100%") + .onFinish(() => { + this.stateSlideLeftRight = AnimationStatus.Initial + }) + } + .width('30%') + .borderRadius(20) + .backgroundColor("#66191a32") + .height("60%") + .onClick(() => { + this.stateSlideLeftRight = AnimationStatus.Running + playVibrateCustom("Slide_LeftRight.json", this.php) + }) + + Text($r("app.string.interaction_slide_left_right")) + .fontColor(Color.White) + .fontSize(18) + } + + Column({ space: 10 }) { + Row() { + ImageAnimator() + .images([ + { src: $r("app.media.slide_up1") }, + { src: $r("app.media.slide_up2") }, + { src: $r("app.media.slide_up3") }, + { src: $r("app.media.slide_up4") }, + { src: $r("app.media.slide_up5") }, + { src: $r("app.media.slide_up6") }, + { src: $r("app.media.slide_up7") }, + { src: $r("app.media.slide_up8") }, + { src: $r("app.media.slide_up9") }, + ]) + .borderRadius(10) + .duration(2250) + .state(this.stateSlideUp) + .fillMode(FillMode.None) + .iterations(this.iterations) + .width("100%") + .height("100%") + .onFinish(() => { + this.stateSlideUp = AnimationStatus.Initial + }) + } + .width('30%') + .borderRadius(20) + .backgroundColor("#66191a32") + .height("60%") + .onClick(() => { + this.stateSlideUp = AnimationStatus.Running + playVibrateCustom("Slide_Up.json", this.php) + }) + + Text($r("app.string.interaction_slide_up")) + .fontColor(Color.White) + .fontSize(18) + } + } + .justifyContent(FlexAlign.Center) + } + .margin({ left: "1%" }) + .width("100%") + + ListItem() { + Row({ space: 30 }) { + Column({ space: 10 }) { + Row() { + ImageAnimator() + .images([ + { src: $r("app.media.Switch_App1") }, + { src: $r("app.media.Switch_App2") }, + { src: $r("app.media.Switch_App3") }, + { src: $r("app.media.Switch_App4") }, + { src: $r("app.media.Switch_App5") }, + { src: $r("app.media.Switch_App6") }, + { src: $r("app.media.Switch_App7") }, + { src: $r("app.media.Switch_App8") }, + { src: $r("app.media.Switch_App9") }, + { src: $r("app.media.Switch_App10") }, + { src: $r("app.media.Switch_App11") }, + { src: $r("app.media.Switch_App12") }, + { src: $r("app.media.Switch_App13") }, + { src: $r("app.media.Switch_App14") }, + ]) + .borderRadius(10) + .duration(3500) + .state(this.stateSwitchApp) + .fillMode(FillMode.None) + .iterations(this.iterations) + .width("100%") + .height("100%") + .onFinish(() => { + this.stateSwitchApp = AnimationStatus.Initial + }) + } + .width('30%') + .borderRadius(20) + .backgroundColor("#66191a32") + .height("60%") + .onClick(() => { + this.stateSwitchApp = AnimationStatus.Running + playVibrateCustom("Switch_App.json", this.php) + }) + + Text($r("app.string.interaction_switch_app")) + .fontColor(Color.White) + .fontSize(18) + } + + Column({ space: 10 }) { + Row() { + ImageAnimator() + .images([ + { src: $r("app.media.Upslide_Stop1") }, + { src: $r("app.media.Upslide_Stop2") }, + { src: $r("app.media.Upslide_Stop3") }, + { src: $r("app.media.Upslide_Stop4") }, + { src: $r("app.media.Upslide_Stop5") }, + { src: $r("app.media.Upslide_Stop6") }, + { src: $r("app.media.Upslide_Stop7") }, + { src: $r("app.media.Upslide_Stop8") }, + { src: $r("app.media.Upslide_Stop9") }, + { src: $r("app.media.Upslide_Stop10") }, + { src: $r("app.media.Upslide_Stop11") }, + { src: $r("app.media.Upslide_Stop12") }, + ]) + .borderRadius(10) + .duration(3000) + .state(this.stateUpSlideStop) + .fillMode(FillMode.None) + .iterations(this.iterations) + .width("100%") + .height("100%") + .onFinish(() => { + this.stateUpSlideStop = AnimationStatus.Initial + }) + } + .width('30%') + .borderRadius(20) + .backgroundColor("#66191a32") + .height("60%") + .onClick(() => { + this.stateUpSlideStop = AnimationStatus.Running + playVibrateCustom("UpSlide_Stop.json", this.php) + }) + + Text($r("app.string.interaction_slide_stop")) + .fontColor(Color.White) + .fontSize(18) + } + } + .justifyContent(FlexAlign.Center) + } + .margin({ left: "1%" }) + .width("100%") + } + .height('50%') + .width("100%") + } + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Racing.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Racing.ets index b6107a202df17e256d8bbdfebd457377ec0ff63d..abdc75438ba481c59a40568275ab9d0addc4a339 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Racing.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Racing.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageRacingList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct RacingLayout { - @State carList: ImageDataSource = new ImageDataSource(getImageRacingList()) - @State status: boolean[] = [false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $carList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageRacingList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct RacingLayout { + @State carList: ImageDataSource = new ImageDataSource(getImageRacingList()) + @State status: boolean[] = [false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $carList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Realistic.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Realistic.ets index 9221a66af13a5f19a6794136236c52dcd5d31c1c..fbd517c398968172db75a6974396d3914f4db520 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Realistic.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Realistic.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageRealisticList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct RealisticLayout { - @State realisticList: ImageDataSource = new ImageDataSource(getImageRealisticList()) - @State status: boolean[] = [false, false, false, false, false, false, false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $realisticList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageRealisticList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct RealisticLayout { + @State realisticList: ImageDataSource = new ImageDataSource(getImageRealisticList()) + @State status: boolean[] = [false, false, false, false, false, false, false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $realisticList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Shooting.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Shooting.ets index 524769f6e64f6eceac881c2ec59f45d36291832b..ccf7589d02dea457a098d9ed3da0d6653a78d704 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Shooting.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/Shooting.ets @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 { getImageShootList, ImageDataSource } from '../module/ImageData' -import CommonLayout from './Common' - -@Component -export default struct ShootLayout { - @State shootList: ImageDataSource = new ImageDataSource(getImageShootList()) - @State status: boolean[] = [false, false, false, false, false, false, false, false, false, false, false, false, false] - @Link vibrationIntensity: string - @Link php: string - - build() { - CommonLayout({ - dataList: $shootList, - status: $status, - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } -} +/* + * Copyright (c) 2023 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 { getImageShootList, ImageDataSource } from '../module/ImageData' +import CommonLayout from './Common' + +@Component +export default struct ShootLayout { + @State shootList: ImageDataSource = new ImageDataSource(getImageShootList()) + @State status: boolean[] = [false, false, false, false, false, false, false, false, false, false, false, false, false] + @Link vibrationIntensity: string + @Link php: string + + build() { + CommonLayout({ + dataList: $shootList, + status: $status, + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/VideoPreview.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/VideoPreview.ets index 2e0e970b7cd3a59a1e1385fe1314a5338064b87a..8bf3176ad31c08662c8dda94d7bc90dc05ddbacd 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/VideoPreview.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/component/VideoPreview.ets @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router' - -@Component -export default struct VideoListLayout { - @State playDis: boolean = false - @Link php: string - - build() { - Scroll() { - Row({ space: 10 }) { - Stack() { - Image($r("app.media.HapticVideoPreview")) - .width("100%") - .height("100%") - .borderRadius(10) - Image($r("app.media.player2")) - .width("30%") - .height("30%") - .visibility(this.playDis ? Visibility.Hidden : Visibility.Visible) - } - .id("videoPreview") - .width("95%") - .height("30%") - .onClick(() => { - this.playDis = true - router.pushUrl({ - url: "module/VideoPlayModule", - params: { - vibrateFileName: "HapticVideo.json", - videoName: 'HapticVideo', - videoSrc: $r("app.media.HapticVideo"), - previewUri: $r("app.media.HapticVideoPreview"), - pages: "Index", - php: this.php - } - }) - }) - .padding({ left: 10 }) - } - } - .scrollable(ScrollDirection.Horizontal).scrollBar(BarState.Off) - } -} +/* + * Copyright (c) 2023 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 router from '@ohos.router' + +@Component +export default struct VideoListLayout { + @State playDis: boolean = false + @Link php: string + + build() { + Scroll() { + Row({ space: 10 }) { + Stack() { + Image($r("app.media.HapticVideoPreview")) + .width("100%") + .height("100%") + .borderRadius(10) + Image($r("app.media.player2")) + .width("30%") + .height("30%") + .visibility(this.playDis ? Visibility.Hidden : Visibility.Visible) + } + .id("videoPreview") + .width("95%") + .height("30%") + .onClick(() => { + this.playDis = true + router.pushUrl({ + url: "module/VideoPlayModule", + params: { + vibrateFileName: "HapticVideo.json", + videoName: 'HapticVideo', + videoSrc: $r("app.media.HapticVideo"), + previewUri: $r("app.media.HapticVideoPreview"), + pages: "Index", + php: this.php + } + }) + }) + .padding({ left: 10 }) + } + } + .scrollable(ScrollDirection.Horizontal).scrollBar(BarState.Off) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/entryability/EntryAbility.ts index d30b8cd46bc9fd93e70e6b01935bd1398a0f2cf4..63f68c7013aa83921a7327e05086450f8ae90c00 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,74 +1,74 @@ -/* - * Copyright (c) 2023 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 Ability from '@ohos.app.ability.UIAbility'; -import type Window from '@ohos.window'; -import vibrator from '@ohos.vibrator'; -import Logger from '../module/Logger'; - -const TAG = '[EntryAbility]'; - -export default class EntryAbility extends Ability { - onCreate(want, launchParam) { - Logger.info(TAG, 'Ability onCreate, want param: %{public}s, launchParam: %{public}s', - JSON.stringify(want) ?? '', JSON.stringify(launchParam) ?? ''); - - vibrator.isSupportEffect('haptic.clock.timer', (error, data) => { - if (data) { - vibrator.startVibration({ - type: 'preset', - effectId: 'haptic.clock.timer', - count: 1, - }, { - usage: 'notification' - }); - } else { - Logger.info(TAG, 'Failed to vibrate onCreate'); - } - }); - } - - onDestroy() { - Logger.info(TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: Window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info(TAG, 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - Logger.info(TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info(TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info(TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info(TAG, '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 Ability from '@ohos.app.ability.UIAbility'; +import type Window from '@ohos.window'; +import vibrator from '@ohos.vibrator'; +import Logger from '../module/Logger'; + +const TAG = '[EntryAbility]'; + +export default class EntryAbility extends Ability { + onCreate(want, launchParam) { + Logger.info(TAG, 'Ability onCreate, want param: %{public}s, launchParam: %{public}s', + JSON.stringify(want) ?? '', JSON.stringify(launchParam) ?? ''); + + vibrator.isSupportEffect('haptic.clock.timer', (error, data) => { + if (data) { + vibrator.startVibration({ + type: 'preset', + effectId: 'haptic.clock.timer', + count: 1, + }, { + usage: 'notification' + }); + } else { + Logger.info(TAG, 'Failed to vibrate onCreate'); + } + }); + } + + onDestroy() { + Logger.info(TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: Window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info(TAG, 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + Logger.info(TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info(TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info(TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info(TAG, '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/DisplayModule.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/DisplayModule.ets index d54b9e410a276e823f7a7b21c561f4d9a7a82d68..dfb985fa149f3709ce064510724761904b8c8d03 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/DisplayModule.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/DisplayModule.ets @@ -1,191 +1,191 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router' -import VideoListLayout from '../component/VideoPreview' -import RacingLayout from '../component/Racing' -import BattleLayout from '../component/Battle' -import ShootLayout from '../component/Shooting' -import InstrumentLayout from '../component/Instrument' -import RealisticLayout from '../component/Realistic' -import FootstepLayout from '../component/Footstep' -import EnvironmentLayout from '../component/Environment' -import ExerciseLayout from '../component/Exercise' -import InteractionLayout from '../component/Interaction' -import Logger from './Logger' -import TabBar from './TabBar' - -const TAG = '[DisplayModule]' - -export enum TabIndex { - RACING = 0, - BATTLE, - SHOOT, - INSTRUMENT, - REALISTIC, - FOOTSTEP, - ENVIRONMENT, - EXERCISE, - INTERACTION, -} - -@Component -export default struct DisplayModule { - @State titleArr: Resource[] = [ - $r("app.string.display_racing"), $r("app.string.display_battle"), $r("app.string.display_shoot"), - $r("app.string.display_instrument"), $r("app.string.display_realistic"), $r("app.string.display_footstep"), - $r("app.string.display_environment"), $r("app.string.display_exercise"), $r("app.string.display_interaction") - ] - @State currentIndex: number = 0 - private swiperController: SwiperController = new SwiperController() - private tabHeight = 50 - @State playDis: boolean = false - @Link vibrationIntensity: string - @Link php: string - private controller: TabsController = new TabsController(); - - build() { - Column({ space: 10 }) { - Row() { - Text($r("app.string.display_haptic_video")) - .width('50%') - .fontSize(24) - .fontColor('#ffffffff') - .fontWeight(FontWeight.Normal) - .textAlign(TextAlign.Start) - .layoutWeight(7) - .padding({ left: 10 }) - Button($r("app.string.display_show_more")) - .id('showMore') - .backgroundColor("#00d613ca") - .layoutWeight(3) - .height(35) - .fontColor('#919191') - .onClick(() => { - Logger.info(TAG, 'Show more pressed') - router.pushUrl({ - url: 'module/VideoListModule', - params: {php: this.php} - }) - }) - } - .padding({ top: 5 }) - - VideoListLayout({php: $php}) - - Text($r("app.string.display_haptic_library")) - .width('100%') - .fontSize(24) - .fontColor('#ffffffff') - .fontWeight(FontWeight.Normal) - .textAlign(TextAlign.Start) - .padding({ left: 10 }) - - Row() { - TabBar({ - titleArr: $titleArr, - currentIndex: $currentIndex, - tabSelected: (position: number, title: string) => { - this.currentIndex = position - Logger.info(TAG, 'onTabSelected position = ' + position + ', title = ' + title) - this.swiperController.showNext() - }, - }) - } - .width('100%') - .height(this.tabHeight) - .zIndex(10) - - Scroll() { - Column() { - Swiper(this.swiperController) { - ForEach(this.titleArr, (item: string) => { - Column() { - if (this.currentIndex === TabIndex.RACING) { - RacingLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.BATTLE) { - BattleLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.SHOOT) { - ShootLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.INSTRUMENT) { - InstrumentLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.REALISTIC) { - RealisticLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.FOOTSTEP) { - FootstepLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.ENVIRONMENT) { - EnvironmentLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.EXERCISE) { - ExerciseLayout({ - vibrationIntensity: $vibrationIntensity, - php: $php - }) - } else if (this.currentIndex === TabIndex.INTERACTION) { - InteractionLayout({ - php: $php - }) - } else { - Text('Please Waiting!') - .fontSize(48) - .fontColor(Color.Black) - .width("100%") - .height("100%") - } - } - }, (item: string) => item) - } - .index(0) - .autoPlay(false) - .indicator(false) - .loop(false) - .vertical(false) - .itemSpace(0) - .index(this.currentIndex) - .flexGrow(1) - .width('100%') - .onChange((index: number) => { - Logger.info(TAG, index.toString()) - this.currentIndex = index - }) - } - } - .scrollBar(BarState.Off) - } - .width('100%') - .height('100%') - .backgroundColor('#f2191a32') - } -} +/* + * Copyright (c) 2023 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 router from '@ohos.router' +import VideoListLayout from '../component/VideoPreview' +import RacingLayout from '../component/Racing' +import BattleLayout from '../component/Battle' +import ShootLayout from '../component/Shooting' +import InstrumentLayout from '../component/Instrument' +import RealisticLayout from '../component/Realistic' +import FootstepLayout from '../component/Footstep' +import EnvironmentLayout from '../component/Environment' +import ExerciseLayout from '../component/Exercise' +import InteractionLayout from '../component/Interaction' +import Logger from './Logger' +import TabBar from './TabBar' + +const TAG = '[DisplayModule]' + +export enum TabIndex { + RACING = 0, + BATTLE, + SHOOT, + INSTRUMENT, + REALISTIC, + FOOTSTEP, + ENVIRONMENT, + EXERCISE, + INTERACTION, +} + +@Component +export default struct DisplayModule { + @State titleArr: Resource[] = [ + $r("app.string.display_racing"), $r("app.string.display_battle"), $r("app.string.display_shoot"), + $r("app.string.display_instrument"), $r("app.string.display_realistic"), $r("app.string.display_footstep"), + $r("app.string.display_environment"), $r("app.string.display_exercise"), $r("app.string.display_interaction") + ] + @State currentIndex: number = 0 + private swiperController: SwiperController = new SwiperController() + private tabHeight = 50 + @State playDis: boolean = false + @Link vibrationIntensity: string + @Link php: string + private controller: TabsController = new TabsController(); + + build() { + Column({ space: 10 }) { + Row() { + Text($r("app.string.display_haptic_video")) + .width('50%') + .fontSize(24) + .fontColor('#ffffffff') + .fontWeight(FontWeight.Normal) + .textAlign(TextAlign.Start) + .layoutWeight(7) + .padding({ left: 10 }) + Button($r("app.string.display_show_more")) + .id('showMore') + .backgroundColor("#00d613ca") + .layoutWeight(3) + .height(35) + .fontColor('#919191') + .onClick(() => { + Logger.info(TAG, 'Show more pressed') + router.pushUrl({ + url: 'module/VideoListModule', + params: {php: this.php} + }) + }) + } + .padding({ top: 5 }) + + VideoListLayout({php: $php}) + + Text($r("app.string.display_haptic_library")) + .width('100%') + .fontSize(24) + .fontColor('#ffffffff') + .fontWeight(FontWeight.Normal) + .textAlign(TextAlign.Start) + .padding({ left: 10 }) + + Row() { + TabBar({ + titleArr: $titleArr, + currentIndex: $currentIndex, + tabSelected: (position: number, title: string) => { + this.currentIndex = position + Logger.info(TAG, 'onTabSelected position = ' + position + ', title = ' + title) + this.swiperController.showNext() + }, + }) + } + .width('100%') + .height(this.tabHeight) + .zIndex(10) + + Scroll() { + Column() { + Swiper(this.swiperController) { + ForEach(this.titleArr, (item: string) => { + Column() { + if (this.currentIndex === TabIndex.RACING) { + RacingLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.BATTLE) { + BattleLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.SHOOT) { + ShootLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.INSTRUMENT) { + InstrumentLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.REALISTIC) { + RealisticLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.FOOTSTEP) { + FootstepLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.ENVIRONMENT) { + EnvironmentLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.EXERCISE) { + ExerciseLayout({ + vibrationIntensity: $vibrationIntensity, + php: $php + }) + } else if (this.currentIndex === TabIndex.INTERACTION) { + InteractionLayout({ + php: $php + }) + } else { + Text('Please Waiting!') + .fontSize(48) + .fontColor(Color.Black) + .width("100%") + .height("100%") + } + } + }, (item: string) => item) + } + .index(0) + .autoPlay(false) + .indicator(false) + .loop(false) + .vertical(false) + .itemSpace(0) + .index(this.currentIndex) + .flexGrow(1) + .width('100%') + .onChange((index: number) => { + Logger.info(TAG, index.toString()) + this.currentIndex = index + }) + } + } + .scrollBar(BarState.Off) + } + .width('100%') + .height('100%') + .backgroundColor('#f2191a32') + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/ImageData.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/ImageData.ets index 2c1d532df3e4610b18adb3bf698837be5143fdf2..5b205c8d05672fb34dbff9fd931affa1acceddcb 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/ImageData.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/ImageData.ets @@ -1,730 +1,730 @@ -/* - * Copyright (c) 2023 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 class ImagesData { - id ?: number - src ?: Resource - name ?: Resource - vibratorFileL ?: string - vibratorFileM ?: string - vibratorFileH ?: string - audioName ?: string -} - -export function getImageRacingList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Racing1"), - name: $r("app.string.display_racing_car_crash"), - vibratorFileL: "CarCrash_l.json", - vibratorFileM: "CarCrash_m.json", - vibratorFileH: "CarCrash_h.json", - audioName: "CarCrash.wav" - }, - { - id: 1, - src: $r("app.media.Racing2"), - name: $r("app.string.display_racing_ignite"), - vibratorFileL: "CarIgnite_l.json", - vibratorFileM: "CarIgnite_m.json", - vibratorFileH: "CarIgnite_h.json", - audioName: "CarIgnite.wav" - }, - { - id: 2, - src: $r("app.media.Racing3"), - name: $r("app.string.display_racing_skid"), - vibratorFileL: "CarSkid_l.json", - vibratorFileM: "CarSkid_m.json", - vibratorFileH: "CarSkid_h.json", - audioName: "CarSkid.wav" - }, - { - id: 3, - src: $r("app.media.Racing4"), - name: $r("app.string.display_racing_drifting_jet"), - vibratorFileL: "DriftingJet_l.json", - vibratorFileM: "DriftingJet_m.json", - vibratorFileH: "DriftingJet_h.json", - audioName: "DriftingJet.wav" - }, - { - id: 4, - src: $r("app.media.Racing5"), - name: $r("app.string.display_racing_jet_n2o"), - vibratorFileL: "JetN2O_l.json", - vibratorFileM: "JetN2O_m.json", - vibratorFileH: "JetN2O_h.json", - audioName: "JetN2O.wav" - }, - { - id: 5, - src: $r("app.media.Racing6"), - name: $r("app.string.display_racing_start"), - vibratorFileL: "RacingStart_l.json", - vibratorFileM: "RacingStart_m.json", - vibratorFileH: "RacingStart_h.json", - audioName: "RacingStart.wav" - }, - { - id: 6, - src: $r("app.media.Racing8"), - name: $r("app.string.display_racing_speed_up"), - vibratorFileL: "SpeedUp_l.json", - vibratorFileM: "SpeedUp_m.json", - vibratorFileH: "SpeedUp_h.json", - audioName: "SpeedUp.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageBattleList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Battle7"), - name: $r("app.string.display_battle_tumble"), - vibratorFileL: "Tumble_l.json", - vibratorFileM: "Tumble_m.json", - vibratorFileH: "Tumble_h.json", - audioName: "Tumble.wav" - }, - { - id: 1, - src: $r("app.media.Battle2"), - name: $r("app.string.display_battle_punch"), - vibratorFileL: "Punch_l.json", - vibratorFileM: "Punch_m.json", - vibratorFileH: "Punch_h.json", - audioName: "Punch.wav" - }, - { - id: 2, - src: $r("app.media.Battle3"), - name: $r("app.string.display_battle_kick"), - vibratorFileL: "Kick_l.json", - vibratorFileM: "Kick_m.json", - vibratorFileH: "Kick_h.json", - audioName: "Kick.wav" - }, - { - id: 3, - src: $r("app.media.Battle4"), - name: $r("app.string.display_battle_hurt"), - vibratorFileL: "Hurt_l.json", - vibratorFileM: "Hurt_m.json", - vibratorFileH: "Hurt_h.json", - audioName: "Hurt.wav" - }, - { - id: 4, - src: $r("app.media.Battle5"), - name: $r("app.string.display_battle_blast"), - vibratorFileL: "Blast_l.json", - vibratorFileM: "Blast_m.json", - vibratorFileH: "Blast_h.json", - audioName: "Blast.wav" - }, - { - id: 5, - src: $r("app.media.Battle6"), - name: $r("app.string.display_battle_bomb"), - vibratorFileL: "Bomb_l.json", - vibratorFileM: "Bomb_m.json", - vibratorFileH: "Bomb_h.json", - audioName: "Bomb.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageShootList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.AK47"), - name: $r("app.string.display_shoot_AK47"), - vibratorFileL: "AK47_l.json", - vibratorFileM: "AK47_m.json", - vibratorFileH: "AK47_h.json", - audioName: "AK47.wav" - }, - { - id: 1, - src: $r("app.media.HK416"), - name: $r("app.string.display_shoot_HK416"), - vibratorFileL: "HK416_l.json", - vibratorFileM: "HK416_m.json", - vibratorFileH: "HK416_h.json", - audioName: "HK416.wav" - }, - { - id: 2, - src: $r("app.media.M4"), - name: $r("app.string.display_shoot_M4"), - vibratorFileL: "M4_l.json", - vibratorFileM: "M4_m.json", - vibratorFileH: "M4_h.json", - audioName: "M4.wav" - }, - { - id: 3, - src: $r("app.media.MP5"), - name: $r("app.string.display_shoot_MP5"), - vibratorFileL: "MP5_l.json", - vibratorFileM: "MP5_m.json", - vibratorFileH: "MP5_h.json", - audioName: "MP5.wav" - }, - { - id: 4, - src: $r("app.media.CZ75"), - name: $r("app.string.display_shoot_CZ75"), - vibratorFileL: "CZ75_l.json", - vibratorFileM: "CZ75_m.json", - vibratorFileH: "CZ75_h.json", - audioName: "CZ75.wav" - }, - { - id: 5, - src: $r("app.media.Winchester"), - name: $r("app.string.display_shoot_winchester"), - vibratorFileL: "Winchester_l.json", - vibratorFileM: "Winchester_m.json", - vibratorFileH: "Winchester_h.json", - audioName: "Winchester.wav" - }, - { - id: 6, - src: $r("app.media.Rifle"), - name: $r("app.string.display_shoot_rifle"), - vibratorFileL: "Rifle_l.json", - vibratorFileM: "Rifle_m.json", - vibratorFileH: "Rifle_h.json", - audioName: "Rifle.wav" - }, - { - id: 7, - src: $r("app.media.AssaultRifle"), - name: $r("app.string.display_shoot_assault_rifle"), - vibratorFileL: "AssaultRifle_l.json", - vibratorFileM: "AssaultRifle_m.json", - vibratorFileH: "AssaultRifle_h.json", - audioName: "AssaultRifle.wav" - }, - { - id: 8, - src: $r("app.media.HitSand"), - name: $r("app.string.display_shoot_hit_sand"), - vibratorFileL: "HitSand_l.json", - vibratorFileM: "HitSand_m.json", - vibratorFileH: "HitSand_h.json", - audioName: "HitSand.wav" - }, - { - id: 9, - src: $r("app.media.HitWater"), - name: $r("app.string.display_shoot_hit_water"), - vibratorFileL: "HitWater_l.json", - vibratorFileM: "HitWater_m.json", - vibratorFileH: "HitWater_h.json", - audioName: "HitWater.wav" - }, - { - id: 10, - src: $r("app.media.HitMetal"), - name: $r("app.string.display_shoot_hit_metal"), - vibratorFileL: "HitMetal_l.json", - vibratorFileM: "HitMetal_m.json", - vibratorFileH: "HitMetal_h.json", - audioName: "HitMetal.wav" - }, - { - id: 11, - src: $r("app.media.HitWood"), - name: $r("app.string.display_shoot_hit_wood"), - vibratorFileL: "HitWood_l.json", - vibratorFileM: "HitWood_m.json", - vibratorFileH: "HitWood_h.json", - audioName: "HitWood.wav" - }, - { - id: 12, - src: $r("app.media.HitGlass"), - name: $r("app.string.display_shoot_hit_glass"), - vibratorFileL: "HitGlass_l.json", - vibratorFileM: "HitGlass_m.json", - vibratorFileH: "HitGlass_h.json", - audioName: "HitGlass.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageInstrumentsList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Cymbals"), - name: $r("app.string.display_instrument_cymbals"), - vibratorFileL: "Cymbals_l.json", - vibratorFileM: "Cymbals_m.json", - vibratorFileH: "Cymbals_h.json", - audioName: "Cymbals.wav" - }, - { - id: 1, - src: $r("app.media.Cymbals2"), - name: $r("app.string.display_instrument_cymbals2"), - vibratorFileL: "Cymbals2_l.json", - vibratorFileM: "Cymbals2_m.json", - vibratorFileH: "Cymbals2_h.json", - audioName: "Cymbals2.wav" - }, - { - id: 2, - src: $r("app.media.KickDrum"), - name: $r("app.string.display_instrument_kick_drum"), - vibratorFileL: "KickDrum_l.json", - vibratorFileM: "KickDrum_m.json", - vibratorFileH: "KickDrum_h.json", - audioName: "KickDrum.wav" - }, - { - id: 3, - src: $r("app.media.KickDrum2"), - name: $r("app.string.display_instrument_kick_drum2"), - vibratorFileL: "KickDrum2_l.json", - vibratorFileM: "KickDrum2_m.json", - vibratorFileH: "KickDrum2_h.json", - audioName: "KickDrum2.wav" - }, - { - id: 4, - src: $r("app.media.Guitar"), - name: $r("app.string.display_instrument_guitar"), - vibratorFileL: "Guitar_l.json", - vibratorFileM: "Guitar_m.json", - vibratorFileH: "Guitar_h.json", - audioName: "Guitar.wav" - }, - { - id: 5, - src: $r("app.media.Tambourine"), - name: $r("app.string.display_instrument_tambourine"), - vibratorFileL: "Tambourine_l.json", - vibratorFileM: "Tambourine_m.json", - vibratorFileH: "Tambourine_h.json", - audioName: "Tambourine.wav" - }, - { - id: 6, - src: $r("app.media.Bell"), - name: $r("app.string.display_instrument_bell"), - vibratorFileL: "bell_l.json", - vibratorFileM: "bell_m.json", - vibratorFileH: "bell_h.json", - audioName: "bell.wav" - }, - { - id: 7, - src: $r("app.media.Claves"), - name: $r("app.string.display_instrument_claves"), - vibratorFileL: "Claves_l.json", - vibratorFileM: "Claves_m.json", - vibratorFileH: "Claves_h.json", - audioName: "Claves.wav" - }, - { - id: 8, - src: $r("app.media.Gong"), - name: $r("app.string.display_instrument_gong"), - vibratorFileL: "Gong_l.json", - vibratorFileM: "Gong_m.json", - vibratorFileH: "Gong_h.json", - audioName: "Gong.wav" - }, - { - id: 9, - src: $r("app.media.Triangle"), - name: $r("app.string.display_instrument_triangle"), - vibratorFileL: "triangle_l.json", - vibratorFileM: "triangle_m.json", - vibratorFileH: "triangle_h.json", - audioName: "triangle.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageRealisticList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Ice"), - name: $r("app.string.display_realistic_ice"), - vibratorFileL: "ice_l.json", - vibratorFileM: "ice_m.json", - vibratorFileH: "ice_h.json", - audioName: "ice.wav" - }, - { - id: 1, - src: $r("app.media.Keyboard"), - name: $r("app.string.display_realistic_keyboard"), - vibratorFileL: "Keyboard_l.json", - vibratorFileM: "Keyboard_m.json", - vibratorFileH: "Keyboard_h.json", - audioName: "Keyboard.wav" - }, - { - id: 2, - src: $r("app.media.Typewriter"), - name: $r("app.string.display_realistic_typewriter"), - vibratorFileL: "Typewriter_l.json", - vibratorFileM: "Typewriter_m.json", - vibratorFileH: "Typewriter_h.json", - audioName: "Typewriter.wav" - }, - { - id: 3, - src: $r("app.media.CoinDrop"), - name: $r("app.string.display_realistic_coin_drop"), - vibratorFileL: "CoinDrop_l.json", - vibratorFileM: "CoinDrop_m.json", - vibratorFileH: "CoinDrop_h.json", - audioName: "CoinDrop.wav" - }, - { - id: 4, - src: $r("app.media.Timer"), - name: $r("app.string.display_realistic_timer"), - vibratorFileL: "timer_l.json", - vibratorFileM: "timer_m.json", - vibratorFileH: "timer_h.json", - audioName: "timer.wav" - }, - { - id: 5, - src: $r("app.media.Walk"), - name: $r("app.string.display_realistic_walk"), - vibratorFileL: "Walk_l.json", - vibratorFileM: "Walk_m.json", - vibratorFileH: "Walk_h.json", - audioName: "Walk.wav" - }, - { - id: 6, - src: $r("app.media.camerashutter"), - name: $r("app.string.display_realistic_camerashutter"), - vibratorFileL: "camerashutter_l.json", - vibratorFileM: "camerashutter_m.json", - vibratorFileH: "camerashutter_h.json", - audioName: "camerashutter.wav" - }, - { - id: 7, - src: $r("app.media.camerashutter2"), - name: $r("app.string.display_realistic_camerashutter2"), - vibratorFileL: "camerashutter2_l.json", - vibratorFileM: "camerashutter2_m.json", - vibratorFileH: "camerashutter2_h.json", - audioName: "camerashutter2.wav" - }, - { - id: 8, - src: $r("app.media.Clock"), - name: $r("app.string.display_realistic_clock"), - vibratorFileL: "clock_l.json", - vibratorFileM: "clock_m.json", - vibratorFileH: "clock_h.json", - audioName: "clock.wav" - }, - { - id: 9, - src: $r("app.media.Water"), - name: $r("app.string.display_realistic_water"), - vibratorFileL: "Water_l.json", - vibratorFileM: "Water_m.json", - vibratorFileH: "Water_h.json", - audioName: "Water.wav" - }, - { - id: 10, - src: $r("app.media.heartbeat"), - name: $r("app.string.display_realistic_heartbeat"), - vibratorFileL: "heartbeat_l.json", - vibratorFileM: "heartbeat_m.json", - vibratorFileH: "heartbeat_h.json", - audioName: "heartbeat.wav" - }, - { - id: 11, - src: $r("app.media.Firework"), - name: $r("app.string.display_realistic_firework"), - vibratorFileL: "Firework_l.json", - vibratorFileM: "Firework_m.json", - vibratorFileH: "Firework_h.json", - audioName: "Firework.wav" - }, - { - id: 12, - src: $r("app.media.Picker"), - name: $r("app.string.display_realistic_picker"), - vibratorFileL: "Picker_l.json", - vibratorFileM: "Picker_m.json", - vibratorFileH: "Picker_h.json", - audioName: "Picker.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageFootstepList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Footstep1"), - name: $r("app.string.display_footstep_on_carpet"), - vibratorFileL: "OnCarpet_l.json", - vibratorFileM: "OnCarpet_m.json", - vibratorFileH: "OnCarpet_h.json", - audioName: "OnCarpet.wav" - }, - { - id: 1, - src: $r("app.media.Footstep2"), - name: $r("app.string.display_footstep_on_concrete"), - vibratorFileL: "OnConcrete_l.json", - vibratorFileM: "OnConcrete_m.json", - vibratorFileH: "OnConcrete_h.json", - audioName: "OnConcrete.wav" - }, - { - id: 2, - src: $r("app.media.Footstep3"), - name: $r("app.string.display_footstep_on_grass"), - vibratorFileL: "OnGrass_l.json", - vibratorFileM: "OnGrass_m.json", - vibratorFileH: "OnGrass_h.json", - audioName: "OnGrass.wav" - }, - { - id: 3, - src: $r("app.media.Footstep4"), - name: $r("app.string.display_footstep_on_board"), - vibratorFileL: "OnWood_l.json", - vibratorFileM: "OnWood_m.json", - vibratorFileH: "OnWood_h.json", - audioName: "OnWood.wav" - }, - { - id: 4, - src: $r("app.media.Footstep5"), - name: $r("app.string.display_footstep_on_gravel"), - vibratorFileL: "OnGravel_l.json", - vibratorFileM: "OnGravel_m.json", - vibratorFileH: "OnGravel_h.json", - audioName: "OnGravel.wav" - }, - { - id: 5, - src: $r("app.media.Footstep6"), - name: $r("app.string.display_footstep_on_mud"), - vibratorFileL: "OnMud_l.json", - vibratorFileM: "OnMud_m.json", - vibratorFileH: "OnMud_h.json", - audioName: "OnMud.wav" - }, - { - id: 6, - src: $r("app.media.Footstep7"), - name: $r("app.string.display_footstep_on_snow"), - vibratorFileL: "OnSnow_l.json", - vibratorFileM: "OnSnow_m.json", - vibratorFileH: "OnSnow_h.json", - audioName: "OnSnow.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageEnvironmentList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Rain"), - name: $r("app.string.display_environment_rain"), - vibratorFileL: "Rain_l.json", - vibratorFileM: "Rain_m.json", - vibratorFileH: "Rain_h.json", - audioName: "Rain.wav" - }, - { - id: 1, - src: $r("app.media.Snowdrift"), - name: $r("app.string.display_environment_snowdrift"), - vibratorFileL: "Snowdrift_l.json", - vibratorFileM: "Snowdrift_m.json", - vibratorFileH: "Snowdrift_h.json", - audioName: "Snowdrift.wav" - }, - { - id: 2, - src: $r("app.media.Campfire"), - name: $r("app.string.display_environment_campfire"), - vibratorFileL: "Campfire_l.json", - vibratorFileM: "Campfire_m.json", - vibratorFileH: "Campfire_h.json", - audioName: "Campfire.wav" - }, - { - id: 3, - src: $r("app.media.Creek"), - name: $r("app.string.display_environment_creek"), - vibratorFileL: "Creek_l.json", - vibratorFileM: "Creek_m.json", - vibratorFileH: "Creek_h.json", - audioName: "Creek.wav" - }, - { - id: 4, - src: $r("app.media.Wave"), - name: $r("app.string.display_environment_wave"), - vibratorFileL: "Wave_l.json", - vibratorFileM: "Wave_m.json", - vibratorFileH: "Wave_h.json", - audioName: "Wave.wav" - }, - { - id: 5, - src: $r("app.media.Wind"), - name: $r("app.string.display_environment_wind"), - vibratorFileL: "Wind_l.json", - vibratorFileM: "Wind_m.json", - vibratorFileH: "Wind_h.json", - audioName: "Wind.wav" - }, - { - id: 6, - src: $r("app.media.Thunder"), - name: $r("app.string.display_environment_thunder"), - vibratorFileL: "Thunder_l.json", - vibratorFileM: "Thunder_m.json", - vibratorFileH: "Thunder_h.json", - audioName: "Thunder.wav" - }, - ] - return ImagesDataArray; -} - -export function getImageExerciseList(): Array { - let ImagesDataArray: Array = [ - { - id: 0, - src: $r("app.media.Badminton"), - name: $r("app.string.display_exercise_badminton"), - vibratorFileL: "Badminton_l.json", - vibratorFileM: "Badminton_m.json", - vibratorFileH: "Badminton_h.json", - audioName: "Badminton.wav" - }, - { - id: 1, - src: $r("app.media.Baseball"), - name: $r("app.string.display_exercise_baseball"), - vibratorFileL: "Baseball_l.json", - vibratorFileM: "Baseball_m.json", - vibratorFileH: "Baseball_h.json", - audioName: "Baseball.wav" - }, - { - id: 2, - src: $r("app.media.Basketball"), - name: $r("app.string.display_exercise_basketball"), - vibratorFileL: "Basketball_l.json", - vibratorFileM: "Basketball_m.json", - vibratorFileH: "Basketball_h.json", - audioName: "Basketball.wav" - }, - { - id: 3, - src: $r("app.media.Skating"), - name: $r("app.string.display_exercise_skating"), - vibratorFileL: "Skating_l.json", - vibratorFileM: "Skating_m.json", - vibratorFileH: "Skating_h.json", - audioName: "Skating.wav" - }, - { - id: 4, - src: $r("app.media.Skiing"), - name: $r("app.string.display_exercise_skiing"), - vibratorFileL: "Skiing_l.json", - vibratorFileM: "Skiing_m.json", - vibratorFileH: "Skiing_h.json", - audioName: "Skiing.wav" - }, - { - id: 5, - src: $r("app.media.TableTennis"), - name: $r("app.string.display_exercise_tabletennis"), - vibratorFileL: "TableTennis_l.json", - vibratorFileM: "TableTennis_m.json", - vibratorFileH: "TableTennis_h.json", - audioName: "TableTennis.wav" - }, - { - id: 6, - src: $r("app.media.Diving"), - name: $r("app.string.display_exercise_diving"), - vibratorFileL: "Diving_l.json", - vibratorFileM: "Diving_m.json", - vibratorFileH: "Diving_h.json", - audioName: "Diving.wav" - }, - ] - return ImagesDataArray; -} - -export abstract class BaseDataSource implements IDataSource { - private mDataSource: T[] = []; - - constructor(dataList: T[]) { - this.mDataSource = dataList; - } - - totalCount(): number { - return this.mDataSource === null ? 0 : this.mDataSource.length - } - - getData(index: number): T | null { - return index >= 0 && index < this.totalCount() ? this.mDataSource[index] : null; - } - - registerDataChangeListener(listener: DataChangeListener) { - } - - unregisterDataChangeListener(listener: DataChangeListener) { - } -} - -export class ImageDataSource extends BaseDataSource { - constructor(students: ImagesData[]) { - super(students) - } -} +/* + * Copyright (c) 2023 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 class ImagesData { + id ?: number + src ?: Resource + name ?: Resource + vibratorFileL ?: string + vibratorFileM ?: string + vibratorFileH ?: string + audioName ?: string +} + +export function getImageRacingList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Racing1"), + name: $r("app.string.display_racing_car_crash"), + vibratorFileL: "CarCrash_l.json", + vibratorFileM: "CarCrash_m.json", + vibratorFileH: "CarCrash_h.json", + audioName: "CarCrash.wav" + }, + { + id: 1, + src: $r("app.media.Racing2"), + name: $r("app.string.display_racing_ignite"), + vibratorFileL: "CarIgnite_l.json", + vibratorFileM: "CarIgnite_m.json", + vibratorFileH: "CarIgnite_h.json", + audioName: "CarIgnite.wav" + }, + { + id: 2, + src: $r("app.media.Racing3"), + name: $r("app.string.display_racing_skid"), + vibratorFileL: "CarSkid_l.json", + vibratorFileM: "CarSkid_m.json", + vibratorFileH: "CarSkid_h.json", + audioName: "CarSkid.wav" + }, + { + id: 3, + src: $r("app.media.Racing4"), + name: $r("app.string.display_racing_drifting_jet"), + vibratorFileL: "DriftingJet_l.json", + vibratorFileM: "DriftingJet_m.json", + vibratorFileH: "DriftingJet_h.json", + audioName: "DriftingJet.wav" + }, + { + id: 4, + src: $r("app.media.Racing5"), + name: $r("app.string.display_racing_jet_n2o"), + vibratorFileL: "JetN2O_l.json", + vibratorFileM: "JetN2O_m.json", + vibratorFileH: "JetN2O_h.json", + audioName: "JetN2O.wav" + }, + { + id: 5, + src: $r("app.media.Racing6"), + name: $r("app.string.display_racing_start"), + vibratorFileL: "RacingStart_l.json", + vibratorFileM: "RacingStart_m.json", + vibratorFileH: "RacingStart_h.json", + audioName: "RacingStart.wav" + }, + { + id: 6, + src: $r("app.media.Racing8"), + name: $r("app.string.display_racing_speed_up"), + vibratorFileL: "SpeedUp_l.json", + vibratorFileM: "SpeedUp_m.json", + vibratorFileH: "SpeedUp_h.json", + audioName: "SpeedUp.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageBattleList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Battle7"), + name: $r("app.string.display_battle_tumble"), + vibratorFileL: "Tumble_l.json", + vibratorFileM: "Tumble_m.json", + vibratorFileH: "Tumble_h.json", + audioName: "Tumble.wav" + }, + { + id: 1, + src: $r("app.media.Battle2"), + name: $r("app.string.display_battle_punch"), + vibratorFileL: "Punch_l.json", + vibratorFileM: "Punch_m.json", + vibratorFileH: "Punch_h.json", + audioName: "Punch.wav" + }, + { + id: 2, + src: $r("app.media.Battle3"), + name: $r("app.string.display_battle_kick"), + vibratorFileL: "Kick_l.json", + vibratorFileM: "Kick_m.json", + vibratorFileH: "Kick_h.json", + audioName: "Kick.wav" + }, + { + id: 3, + src: $r("app.media.Battle4"), + name: $r("app.string.display_battle_hurt"), + vibratorFileL: "Hurt_l.json", + vibratorFileM: "Hurt_m.json", + vibratorFileH: "Hurt_h.json", + audioName: "Hurt.wav" + }, + { + id: 4, + src: $r("app.media.Battle5"), + name: $r("app.string.display_battle_blast"), + vibratorFileL: "Blast_l.json", + vibratorFileM: "Blast_m.json", + vibratorFileH: "Blast_h.json", + audioName: "Blast.wav" + }, + { + id: 5, + src: $r("app.media.Battle6"), + name: $r("app.string.display_battle_bomb"), + vibratorFileL: "Bomb_l.json", + vibratorFileM: "Bomb_m.json", + vibratorFileH: "Bomb_h.json", + audioName: "Bomb.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageShootList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.AK47"), + name: $r("app.string.display_shoot_AK47"), + vibratorFileL: "AK47_l.json", + vibratorFileM: "AK47_m.json", + vibratorFileH: "AK47_h.json", + audioName: "AK47.wav" + }, + { + id: 1, + src: $r("app.media.HK416"), + name: $r("app.string.display_shoot_HK416"), + vibratorFileL: "HK416_l.json", + vibratorFileM: "HK416_m.json", + vibratorFileH: "HK416_h.json", + audioName: "HK416.wav" + }, + { + id: 2, + src: $r("app.media.M4"), + name: $r("app.string.display_shoot_M4"), + vibratorFileL: "M4_l.json", + vibratorFileM: "M4_m.json", + vibratorFileH: "M4_h.json", + audioName: "M4.wav" + }, + { + id: 3, + src: $r("app.media.MP5"), + name: $r("app.string.display_shoot_MP5"), + vibratorFileL: "MP5_l.json", + vibratorFileM: "MP5_m.json", + vibratorFileH: "MP5_h.json", + audioName: "MP5.wav" + }, + { + id: 4, + src: $r("app.media.CZ75"), + name: $r("app.string.display_shoot_CZ75"), + vibratorFileL: "CZ75_l.json", + vibratorFileM: "CZ75_m.json", + vibratorFileH: "CZ75_h.json", + audioName: "CZ75.wav" + }, + { + id: 5, + src: $r("app.media.Winchester"), + name: $r("app.string.display_shoot_winchester"), + vibratorFileL: "Winchester_l.json", + vibratorFileM: "Winchester_m.json", + vibratorFileH: "Winchester_h.json", + audioName: "Winchester.wav" + }, + { + id: 6, + src: $r("app.media.Rifle"), + name: $r("app.string.display_shoot_rifle"), + vibratorFileL: "Rifle_l.json", + vibratorFileM: "Rifle_m.json", + vibratorFileH: "Rifle_h.json", + audioName: "Rifle.wav" + }, + { + id: 7, + src: $r("app.media.AssaultRifle"), + name: $r("app.string.display_shoot_assault_rifle"), + vibratorFileL: "AssaultRifle_l.json", + vibratorFileM: "AssaultRifle_m.json", + vibratorFileH: "AssaultRifle_h.json", + audioName: "AssaultRifle.wav" + }, + { + id: 8, + src: $r("app.media.HitSand"), + name: $r("app.string.display_shoot_hit_sand"), + vibratorFileL: "HitSand_l.json", + vibratorFileM: "HitSand_m.json", + vibratorFileH: "HitSand_h.json", + audioName: "HitSand.wav" + }, + { + id: 9, + src: $r("app.media.HitWater"), + name: $r("app.string.display_shoot_hit_water"), + vibratorFileL: "HitWater_l.json", + vibratorFileM: "HitWater_m.json", + vibratorFileH: "HitWater_h.json", + audioName: "HitWater.wav" + }, + { + id: 10, + src: $r("app.media.HitMetal"), + name: $r("app.string.display_shoot_hit_metal"), + vibratorFileL: "HitMetal_l.json", + vibratorFileM: "HitMetal_m.json", + vibratorFileH: "HitMetal_h.json", + audioName: "HitMetal.wav" + }, + { + id: 11, + src: $r("app.media.HitWood"), + name: $r("app.string.display_shoot_hit_wood"), + vibratorFileL: "HitWood_l.json", + vibratorFileM: "HitWood_m.json", + vibratorFileH: "HitWood_h.json", + audioName: "HitWood.wav" + }, + { + id: 12, + src: $r("app.media.HitGlass"), + name: $r("app.string.display_shoot_hit_glass"), + vibratorFileL: "HitGlass_l.json", + vibratorFileM: "HitGlass_m.json", + vibratorFileH: "HitGlass_h.json", + audioName: "HitGlass.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageInstrumentsList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Cymbals"), + name: $r("app.string.display_instrument_cymbals"), + vibratorFileL: "Cymbals_l.json", + vibratorFileM: "Cymbals_m.json", + vibratorFileH: "Cymbals_h.json", + audioName: "Cymbals.wav" + }, + { + id: 1, + src: $r("app.media.Cymbals2"), + name: $r("app.string.display_instrument_cymbals2"), + vibratorFileL: "Cymbals2_l.json", + vibratorFileM: "Cymbals2_m.json", + vibratorFileH: "Cymbals2_h.json", + audioName: "Cymbals2.wav" + }, + { + id: 2, + src: $r("app.media.KickDrum"), + name: $r("app.string.display_instrument_kick_drum"), + vibratorFileL: "KickDrum_l.json", + vibratorFileM: "KickDrum_m.json", + vibratorFileH: "KickDrum_h.json", + audioName: "KickDrum.wav" + }, + { + id: 3, + src: $r("app.media.KickDrum2"), + name: $r("app.string.display_instrument_kick_drum2"), + vibratorFileL: "KickDrum2_l.json", + vibratorFileM: "KickDrum2_m.json", + vibratorFileH: "KickDrum2_h.json", + audioName: "KickDrum2.wav" + }, + { + id: 4, + src: $r("app.media.Guitar"), + name: $r("app.string.display_instrument_guitar"), + vibratorFileL: "Guitar_l.json", + vibratorFileM: "Guitar_m.json", + vibratorFileH: "Guitar_h.json", + audioName: "Guitar.wav" + }, + { + id: 5, + src: $r("app.media.Tambourine"), + name: $r("app.string.display_instrument_tambourine"), + vibratorFileL: "Tambourine_l.json", + vibratorFileM: "Tambourine_m.json", + vibratorFileH: "Tambourine_h.json", + audioName: "Tambourine.wav" + }, + { + id: 6, + src: $r("app.media.Bell"), + name: $r("app.string.display_instrument_bell"), + vibratorFileL: "bell_l.json", + vibratorFileM: "bell_m.json", + vibratorFileH: "bell_h.json", + audioName: "bell.wav" + }, + { + id: 7, + src: $r("app.media.Claves"), + name: $r("app.string.display_instrument_claves"), + vibratorFileL: "Claves_l.json", + vibratorFileM: "Claves_m.json", + vibratorFileH: "Claves_h.json", + audioName: "Claves.wav" + }, + { + id: 8, + src: $r("app.media.Gong"), + name: $r("app.string.display_instrument_gong"), + vibratorFileL: "Gong_l.json", + vibratorFileM: "Gong_m.json", + vibratorFileH: "Gong_h.json", + audioName: "Gong.wav" + }, + { + id: 9, + src: $r("app.media.Triangle"), + name: $r("app.string.display_instrument_triangle"), + vibratorFileL: "triangle_l.json", + vibratorFileM: "triangle_m.json", + vibratorFileH: "triangle_h.json", + audioName: "triangle.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageRealisticList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Ice"), + name: $r("app.string.display_realistic_ice"), + vibratorFileL: "ice_l.json", + vibratorFileM: "ice_m.json", + vibratorFileH: "ice_h.json", + audioName: "ice.wav" + }, + { + id: 1, + src: $r("app.media.Keyboard"), + name: $r("app.string.display_realistic_keyboard"), + vibratorFileL: "Keyboard_l.json", + vibratorFileM: "Keyboard_m.json", + vibratorFileH: "Keyboard_h.json", + audioName: "Keyboard.wav" + }, + { + id: 2, + src: $r("app.media.Typewriter"), + name: $r("app.string.display_realistic_typewriter"), + vibratorFileL: "Typewriter_l.json", + vibratorFileM: "Typewriter_m.json", + vibratorFileH: "Typewriter_h.json", + audioName: "Typewriter.wav" + }, + { + id: 3, + src: $r("app.media.CoinDrop"), + name: $r("app.string.display_realistic_coin_drop"), + vibratorFileL: "CoinDrop_l.json", + vibratorFileM: "CoinDrop_m.json", + vibratorFileH: "CoinDrop_h.json", + audioName: "CoinDrop.wav" + }, + { + id: 4, + src: $r("app.media.Timer"), + name: $r("app.string.display_realistic_timer"), + vibratorFileL: "timer_l.json", + vibratorFileM: "timer_m.json", + vibratorFileH: "timer_h.json", + audioName: "timer.wav" + }, + { + id: 5, + src: $r("app.media.Walk"), + name: $r("app.string.display_realistic_walk"), + vibratorFileL: "Walk_l.json", + vibratorFileM: "Walk_m.json", + vibratorFileH: "Walk_h.json", + audioName: "Walk.wav" + }, + { + id: 6, + src: $r("app.media.camerashutter"), + name: $r("app.string.display_realistic_camerashutter"), + vibratorFileL: "camerashutter_l.json", + vibratorFileM: "camerashutter_m.json", + vibratorFileH: "camerashutter_h.json", + audioName: "camerashutter.wav" + }, + { + id: 7, + src: $r("app.media.camerashutter2"), + name: $r("app.string.display_realistic_camerashutter2"), + vibratorFileL: "camerashutter2_l.json", + vibratorFileM: "camerashutter2_m.json", + vibratorFileH: "camerashutter2_h.json", + audioName: "camerashutter2.wav" + }, + { + id: 8, + src: $r("app.media.Clock"), + name: $r("app.string.display_realistic_clock"), + vibratorFileL: "clock_l.json", + vibratorFileM: "clock_m.json", + vibratorFileH: "clock_h.json", + audioName: "clock.wav" + }, + { + id: 9, + src: $r("app.media.Water"), + name: $r("app.string.display_realistic_water"), + vibratorFileL: "Water_l.json", + vibratorFileM: "Water_m.json", + vibratorFileH: "Water_h.json", + audioName: "Water.wav" + }, + { + id: 10, + src: $r("app.media.heartbeat"), + name: $r("app.string.display_realistic_heartbeat"), + vibratorFileL: "heartbeat_l.json", + vibratorFileM: "heartbeat_m.json", + vibratorFileH: "heartbeat_h.json", + audioName: "heartbeat.wav" + }, + { + id: 11, + src: $r("app.media.Firework"), + name: $r("app.string.display_realistic_firework"), + vibratorFileL: "Firework_l.json", + vibratorFileM: "Firework_m.json", + vibratorFileH: "Firework_h.json", + audioName: "Firework.wav" + }, + { + id: 12, + src: $r("app.media.Picker"), + name: $r("app.string.display_realistic_picker"), + vibratorFileL: "Picker_l.json", + vibratorFileM: "Picker_m.json", + vibratorFileH: "Picker_h.json", + audioName: "Picker.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageFootstepList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Footstep1"), + name: $r("app.string.display_footstep_on_carpet"), + vibratorFileL: "OnCarpet_l.json", + vibratorFileM: "OnCarpet_m.json", + vibratorFileH: "OnCarpet_h.json", + audioName: "OnCarpet.wav" + }, + { + id: 1, + src: $r("app.media.Footstep2"), + name: $r("app.string.display_footstep_on_concrete"), + vibratorFileL: "OnConcrete_l.json", + vibratorFileM: "OnConcrete_m.json", + vibratorFileH: "OnConcrete_h.json", + audioName: "OnConcrete.wav" + }, + { + id: 2, + src: $r("app.media.Footstep3"), + name: $r("app.string.display_footstep_on_grass"), + vibratorFileL: "OnGrass_l.json", + vibratorFileM: "OnGrass_m.json", + vibratorFileH: "OnGrass_h.json", + audioName: "OnGrass.wav" + }, + { + id: 3, + src: $r("app.media.Footstep4"), + name: $r("app.string.display_footstep_on_board"), + vibratorFileL: "OnWood_l.json", + vibratorFileM: "OnWood_m.json", + vibratorFileH: "OnWood_h.json", + audioName: "OnWood.wav" + }, + { + id: 4, + src: $r("app.media.Footstep5"), + name: $r("app.string.display_footstep_on_gravel"), + vibratorFileL: "OnGravel_l.json", + vibratorFileM: "OnGravel_m.json", + vibratorFileH: "OnGravel_h.json", + audioName: "OnGravel.wav" + }, + { + id: 5, + src: $r("app.media.Footstep6"), + name: $r("app.string.display_footstep_on_mud"), + vibratorFileL: "OnMud_l.json", + vibratorFileM: "OnMud_m.json", + vibratorFileH: "OnMud_h.json", + audioName: "OnMud.wav" + }, + { + id: 6, + src: $r("app.media.Footstep7"), + name: $r("app.string.display_footstep_on_snow"), + vibratorFileL: "OnSnow_l.json", + vibratorFileM: "OnSnow_m.json", + vibratorFileH: "OnSnow_h.json", + audioName: "OnSnow.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageEnvironmentList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Rain"), + name: $r("app.string.display_environment_rain"), + vibratorFileL: "Rain_l.json", + vibratorFileM: "Rain_m.json", + vibratorFileH: "Rain_h.json", + audioName: "Rain.wav" + }, + { + id: 1, + src: $r("app.media.Snowdrift"), + name: $r("app.string.display_environment_snowdrift"), + vibratorFileL: "Snowdrift_l.json", + vibratorFileM: "Snowdrift_m.json", + vibratorFileH: "Snowdrift_h.json", + audioName: "Snowdrift.wav" + }, + { + id: 2, + src: $r("app.media.Campfire"), + name: $r("app.string.display_environment_campfire"), + vibratorFileL: "Campfire_l.json", + vibratorFileM: "Campfire_m.json", + vibratorFileH: "Campfire_h.json", + audioName: "Campfire.wav" + }, + { + id: 3, + src: $r("app.media.Creek"), + name: $r("app.string.display_environment_creek"), + vibratorFileL: "Creek_l.json", + vibratorFileM: "Creek_m.json", + vibratorFileH: "Creek_h.json", + audioName: "Creek.wav" + }, + { + id: 4, + src: $r("app.media.Wave"), + name: $r("app.string.display_environment_wave"), + vibratorFileL: "Wave_l.json", + vibratorFileM: "Wave_m.json", + vibratorFileH: "Wave_h.json", + audioName: "Wave.wav" + }, + { + id: 5, + src: $r("app.media.Wind"), + name: $r("app.string.display_environment_wind"), + vibratorFileL: "Wind_l.json", + vibratorFileM: "Wind_m.json", + vibratorFileH: "Wind_h.json", + audioName: "Wind.wav" + }, + { + id: 6, + src: $r("app.media.Thunder"), + name: $r("app.string.display_environment_thunder"), + vibratorFileL: "Thunder_l.json", + vibratorFileM: "Thunder_m.json", + vibratorFileH: "Thunder_h.json", + audioName: "Thunder.wav" + }, + ] + return ImagesDataArray; +} + +export function getImageExerciseList(): Array { + let ImagesDataArray: Array = [ + { + id: 0, + src: $r("app.media.Badminton"), + name: $r("app.string.display_exercise_badminton"), + vibratorFileL: "Badminton_l.json", + vibratorFileM: "Badminton_m.json", + vibratorFileH: "Badminton_h.json", + audioName: "Badminton.wav" + }, + { + id: 1, + src: $r("app.media.Baseball"), + name: $r("app.string.display_exercise_baseball"), + vibratorFileL: "Baseball_l.json", + vibratorFileM: "Baseball_m.json", + vibratorFileH: "Baseball_h.json", + audioName: "Baseball.wav" + }, + { + id: 2, + src: $r("app.media.Basketball"), + name: $r("app.string.display_exercise_basketball"), + vibratorFileL: "Basketball_l.json", + vibratorFileM: "Basketball_m.json", + vibratorFileH: "Basketball_h.json", + audioName: "Basketball.wav" + }, + { + id: 3, + src: $r("app.media.Skating"), + name: $r("app.string.display_exercise_skating"), + vibratorFileL: "Skating_l.json", + vibratorFileM: "Skating_m.json", + vibratorFileH: "Skating_h.json", + audioName: "Skating.wav" + }, + { + id: 4, + src: $r("app.media.Skiing"), + name: $r("app.string.display_exercise_skiing"), + vibratorFileL: "Skiing_l.json", + vibratorFileM: "Skiing_m.json", + vibratorFileH: "Skiing_h.json", + audioName: "Skiing.wav" + }, + { + id: 5, + src: $r("app.media.TableTennis"), + name: $r("app.string.display_exercise_tabletennis"), + vibratorFileL: "TableTennis_l.json", + vibratorFileM: "TableTennis_m.json", + vibratorFileH: "TableTennis_h.json", + audioName: "TableTennis.wav" + }, + { + id: 6, + src: $r("app.media.Diving"), + name: $r("app.string.display_exercise_diving"), + vibratorFileL: "Diving_l.json", + vibratorFileM: "Diving_m.json", + vibratorFileH: "Diving_h.json", + audioName: "Diving.wav" + }, + ] + return ImagesDataArray; +} + +export abstract class BaseDataSource implements IDataSource { + private mDataSource: T[] = []; + + constructor(dataList: T[]) { + this.mDataSource = dataList; + } + + totalCount(): number { + return this.mDataSource === null ? 0 : this.mDataSource.length + } + + getData(index: number): T | null { + return index >= 0 && index < this.totalCount() ? this.mDataSource[index] : null; + } + + registerDataChangeListener(listener: DataChangeListener) { + } + + unregisterDataChangeListener(listener: DataChangeListener) { + } +} + +export class ImageDataSource extends BaseDataSource { + constructor(students: ImagesData[]) { + super(students) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/MyInfoModule.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/MyInfoModule.ets index 972601945dd29857f307b96251c36bdcd4ce8270..99f666bf13981d42f3296004cc02e0c2762b21d1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/MyInfoModule.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/MyInfoModule.ets @@ -1,228 +1,228 @@ -/* - * Copyright (c) 2023 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 Logger from './Logger' - -const TAG = '[MyInfoModule]' - -@Component -export default struct MyInfoModule { - @State selectContent: Resource = $r("app.string.my_low_mode") - @State selectContent1: Resource = $r("app.string.my_ets") - - @Link vibrationIntensity: string - @Link php: string - - build() { - Column({ space: 30 }) { - Column({ space: 10 }) { - Row({ space: 10 }) { - Image($r("app.media.set")) - .height(20) - .width(20) - Text($r("app.string.my_settings")) - .fontColor(Color.White) - .fontSize(20) - Text(this.selectContent) - .fontSize(16) - .fontColor("#ffcbc2c2") - } - .id('intensitySelect') - .height("100%") - .width("80%") - .onClick(() => { - ActionSheet.show({ - title: $r("app.string.my_settings"), - message: $r("app.string.my_select_msg"), - autoCancel: true, - confirm: { - value: $r("app.string.cancel"), - action: () => { - Logger.info(TAG, 'Get Alert Dialog handled') - } - }, - cancel: () => { - Logger.info(TAG, 'actionSheet canceled') - }, - alignment: DialogAlignment.Bottom, - offset: { dx: 0, dy: -10 }, - sheets: [ - { - icon: $r("app.media.app_icon"), - title: $r("app.string.my_high_mode"), - action: () => { - this.selectContent = $r("app.string.my_high_mode") - this.vibrationIntensity = 'H' - Logger.info(TAG, 'Vibration intensity is high') - } - }, - { - icon: $r("app.media.app_icon"), - title: $r("app.string.my_middle_mode"), - action: () => { - this.selectContent = $r("app.string.my_middle_mode") - this.vibrationIntensity = 'M' - Logger.info(TAG, 'Vibration intensity is middle') - } - }, - { - icon: $r("app.media.app_icon"), - title: $r("app.string.my_low_mode"), - action: () => { - this.selectContent = $r("app.string.my_low_mode") - this.vibrationIntensity = 'L' - Logger.info(TAG, 'Vibration intensity is low') - } - } - ] - }) - }) - .width("80%") - - Row() { - } - .height(1) - .width("85%") - .backgroundColor('#ff404048') - } - - Column({ space: 10 }) { - Row({ space: 10 }) { - Image($r("app.media.select")) - .height(20) - .width(20) - Text($r("app.string.my_php")) - .fontColor(Color.White) - .fontSize(20) - Text(this.selectContent1) - .fontSize(16) - .fontColor("#ffcbc2c2") - } - .id('phpSelect1') - .height("100%") - .width("80%") - .onClick(() => { - ActionSheet.show({ - title: $r("app.string.my_php_select"), - message: $r("app.string.my_linguistic_type"), - autoCancel: true, - confirm: { - value: $r("app.string.cancel"), - action: () => { - Logger.info(TAG, 'Get Alert Dialog handled') - } - }, - cancel: () => { - Logger.info(TAG, 'actionSheet canceled') - }, - alignment: DialogAlignment.Bottom, - offset: { dx: 0, dy: -10 }, - sheets: [ - { - icon: $r("app.media.app_icon"), - title: $r("app.string.my_ets"), - action: () => { - this.selectContent1 = $r("app.string.my_ets") - this.php = 'ets' - } - }, - { - icon: $r("app.media.app_icon"), - title: $r("app.string.my_capi"), - action: () => { - this.selectContent1 = $r("app.string.my_capi") - this.php = 'capi' - } - } - ] - }) - }) - .width("80%") - - Row() { - } - .height(1) - .width("85%") - .backgroundColor('#ff404048') - } - - Column({ space: 10 }) { - Row({ space: 10 }) { - Image($r("app.media.Verison")) - .width(20) - .height(20) - Text($r("app.string.my_version")) - .fontColor(Color.White) - .fontSize(20) - .backgroundColor('#cc191a32') - Text('v1.0') - .fontSize(20) - .fontColor("#ff706666") - } - .width("80%") - - Row() { - } - .height(1) - .width("85%") - .backgroundColor("#ff404048") - } - - Column({ space: 10 }) { - Row({ space: 10 }) { - Image($r("app.media.bangzhu")) - .width(20) - .height(20) - Text($r("app.string.my_help")) - .fontColor(Color.White) - .fontSize(20) - .backgroundColor('#cc191a32') - Text('Please Waiting!') - .fontSize(20) - .fontColor("#ff706666") - } - .width("80%") - - Row() { - } - .height(1) - .width("85%") - .backgroundColor("#ff404048") - } - - Column({ space: 10 }) { - Row({ space: 10 }) { - Image($r("app.media.xinxi")) - .width(20) - .height(20) - Text($r("app.string.my_develop")) - .fontColor(Color.White) - .fontSize(20) - .backgroundColor('#cc191a32') - Text('Please Waiting!') - .fontSize(20) - .fontColor("#ff706666") - } - .width("80%") - - Row() { - } - .height(1) - .width("85%") - .backgroundColor("#ff404048") - } - } - } -} +/* + * Copyright (c) 2023 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 Logger from './Logger' + +const TAG = '[MyInfoModule]' + +@Component +export default struct MyInfoModule { + @State selectContent: Resource = $r("app.string.my_low_mode") + @State selectContent1: Resource = $r("app.string.my_ets") + + @Link vibrationIntensity: string + @Link php: string + + build() { + Column({ space: 30 }) { + Column({ space: 10 }) { + Row({ space: 10 }) { + Image($r("app.media.set")) + .height(20) + .width(20) + Text($r("app.string.my_settings")) + .fontColor(Color.White) + .fontSize(20) + Text(this.selectContent) + .fontSize(16) + .fontColor("#ffcbc2c2") + } + .id('intensitySelect') + .height("100%") + .width("80%") + .onClick(() => { + ActionSheet.show({ + title: $r("app.string.my_settings"), + message: $r("app.string.my_select_msg"), + autoCancel: true, + confirm: { + value: $r("app.string.cancel"), + action: () => { + Logger.info(TAG, 'Get Alert Dialog handled') + } + }, + cancel: () => { + Logger.info(TAG, 'actionSheet canceled') + }, + alignment: DialogAlignment.Bottom, + offset: { dx: 0, dy: -10 }, + sheets: [ + { + icon: $r("app.media.app_icon"), + title: $r("app.string.my_high_mode"), + action: () => { + this.selectContent = $r("app.string.my_high_mode") + this.vibrationIntensity = 'H' + Logger.info(TAG, 'Vibration intensity is high') + } + }, + { + icon: $r("app.media.app_icon"), + title: $r("app.string.my_middle_mode"), + action: () => { + this.selectContent = $r("app.string.my_middle_mode") + this.vibrationIntensity = 'M' + Logger.info(TAG, 'Vibration intensity is middle') + } + }, + { + icon: $r("app.media.app_icon"), + title: $r("app.string.my_low_mode"), + action: () => { + this.selectContent = $r("app.string.my_low_mode") + this.vibrationIntensity = 'L' + Logger.info(TAG, 'Vibration intensity is low') + } + } + ] + }) + }) + .width("80%") + + Row() { + } + .height(1) + .width("85%") + .backgroundColor('#ff404048') + } + + Column({ space: 10 }) { + Row({ space: 10 }) { + Image($r("app.media.select")) + .height(20) + .width(20) + Text($r("app.string.my_php")) + .fontColor(Color.White) + .fontSize(20) + Text(this.selectContent1) + .fontSize(16) + .fontColor("#ffcbc2c2") + } + .id('phpSelect1') + .height("100%") + .width("80%") + .onClick(() => { + ActionSheet.show({ + title: $r("app.string.my_php_select"), + message: $r("app.string.my_linguistic_type"), + autoCancel: true, + confirm: { + value: $r("app.string.cancel"), + action: () => { + Logger.info(TAG, 'Get Alert Dialog handled') + } + }, + cancel: () => { + Logger.info(TAG, 'actionSheet canceled') + }, + alignment: DialogAlignment.Bottom, + offset: { dx: 0, dy: -10 }, + sheets: [ + { + icon: $r("app.media.app_icon"), + title: $r("app.string.my_ets"), + action: () => { + this.selectContent1 = $r("app.string.my_ets") + this.php = 'ets' + } + }, + { + icon: $r("app.media.app_icon"), + title: $r("app.string.my_capi"), + action: () => { + this.selectContent1 = $r("app.string.my_capi") + this.php = 'capi' + } + } + ] + }) + }) + .width("80%") + + Row() { + } + .height(1) + .width("85%") + .backgroundColor('#ff404048') + } + + Column({ space: 10 }) { + Row({ space: 10 }) { + Image($r("app.media.Verison")) + .width(20) + .height(20) + Text($r("app.string.my_version")) + .fontColor(Color.White) + .fontSize(20) + .backgroundColor('#cc191a32') + Text('v1.0') + .fontSize(20) + .fontColor("#ff706666") + } + .width("80%") + + Row() { + } + .height(1) + .width("85%") + .backgroundColor("#ff404048") + } + + Column({ space: 10 }) { + Row({ space: 10 }) { + Image($r("app.media.bangzhu")) + .width(20) + .height(20) + Text($r("app.string.my_help")) + .fontColor(Color.White) + .fontSize(20) + .backgroundColor('#cc191a32') + Text('Please Waiting!') + .fontSize(20) + .fontColor("#ff706666") + } + .width("80%") + + Row() { + } + .height(1) + .width("85%") + .backgroundColor("#ff404048") + } + + Column({ space: 10 }) { + Row({ space: 10 }) { + Image($r("app.media.xinxi")) + .width(20) + .height(20) + Text($r("app.string.my_develop")) + .fontColor(Color.White) + .fontSize(20) + .backgroundColor('#cc191a32') + Text('Please Waiting!') + .fontSize(20) + .fontColor("#ff706666") + } + .width("80%") + + Row() { + } + .height(1) + .width("85%") + .backgroundColor("#ff404048") + } + } + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/TabBar.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/TabBar.ets index 4665acd8382d9cc60893bd377ac6e572e02e2393..3bb7067170a7f0fbbb12194597a12c0705fec522 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/TabBar.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/TabBar.ets @@ -1,86 +1,86 @@ -/* - * Copyright (c) 2023 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 Logger from './Logger' - -const TAG = '[TabBar]' - -export class TabModel { - index ?: number - content ?: Resource - left ?: number - width ?: number -} - -@Component -export default struct TabBar { - private fontSizeNormal = 18 - private tabMargin = 15 - private titleLength = 3 - @Link titleArr: Resource[] - @Link currentIndex: number - private left: number = 0 - private tabSelected: (position: number, title: string) => void = (position: number, title: string) => { - Logger.info(TAG, 'tabSelected position = ' + position + ', title = ' + title) - } - @State private tabDataArr: TabModel[] = [] - private scroller: Scroller = new Scroller() - - aboutToAppear() { - this.tabDataArr = this.titleArr.map((title: Resource, index: number) => { - let tabModel = new TabModel() - tabModel.index = index - tabModel.content = title - tabModel.left = this.left - let width = this.titleLength * this.fontSizeNormal + this.tabMargin * 2 - tabModel.width = width - tabModel.left = this.left - this.left += width - return tabModel - }) - } - - build() { - Scroll(this.scroller) { - Flex({ direction: FlexDirection.Row }) { - ForEach(this.tabDataArr, (item: TabModel) => { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Text(item.content) - .fontSize(this.currentIndex === item.index ? this.fontSizeNormal + 3 : this.fontSizeNormal) - .fontColor(this.currentIndex === item.index ? "#2AEFCC" : Color.White) - .fontWeight(this.currentIndex === item.index ? FontWeight.Bold : FontWeight.Normal) - .textAlign(TextAlign.Center) - Column() - .height(3) - .width(item.width! - this.tabMargin * 2) - .margin({ top: 10 }) - .backgroundColor("#2AEFCC") - .visibility(this.currentIndex === item.index ? Visibility.Visible : Visibility.Hidden) - } - .width(item.width!) - .height('100%') - .backgroundColor("#00002222") - .onClick(() => { - if (item.index !== undefined) { - this.currentIndex = item.index - } - }) - }, (item: TabModel) => item.index!.toString()) - } - } - .scrollable(ScrollDirection.Horizontal) - .scrollBar(BarState.Off) - } -} +/* + * Copyright (c) 2023 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 Logger from './Logger' + +const TAG = '[TabBar]' + +export class TabModel { + index ?: number + content ?: Resource + left ?: number + width ?: number +} + +@Component +export default struct TabBar { + private fontSizeNormal = 18 + private tabMargin = 15 + private titleLength = 3 + @Link titleArr: Resource[] + @Link currentIndex: number + private left: number = 0 + private tabSelected: (position: number, title: string) => void = (position: number, title: string) => { + Logger.info(TAG, 'tabSelected position = ' + position + ', title = ' + title) + } + @State private tabDataArr: TabModel[] = [] + private scroller: Scroller = new Scroller() + + aboutToAppear() { + this.tabDataArr = this.titleArr.map((title: Resource, index: number) => { + let tabModel = new TabModel() + tabModel.index = index + tabModel.content = title + tabModel.left = this.left + let width = this.titleLength * this.fontSizeNormal + this.tabMargin * 2 + tabModel.width = width + tabModel.left = this.left + this.left += width + return tabModel + }) + } + + build() { + Scroll(this.scroller) { + Flex({ direction: FlexDirection.Row }) { + ForEach(this.tabDataArr, (item: TabModel) => { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Text(item.content) + .fontSize(this.currentIndex === item.index ? this.fontSizeNormal + 3 : this.fontSizeNormal) + .fontColor(this.currentIndex === item.index ? "#2AEFCC" : Color.White) + .fontWeight(this.currentIndex === item.index ? FontWeight.Bold : FontWeight.Normal) + .textAlign(TextAlign.Center) + Column() + .height(3) + .width(item.width! - this.tabMargin * 2) + .margin({ top: 10 }) + .backgroundColor("#2AEFCC") + .visibility(this.currentIndex === item.index ? Visibility.Visible : Visibility.Hidden) + } + .width(item.width!) + .height('100%') + .backgroundColor("#00002222") + .onClick(() => { + if (item.index !== undefined) { + this.currentIndex = item.index + } + }) + }, (item: TabModel) => item.index!.toString()) + } + } + .scrollable(ScrollDirection.Horizontal) + .scrollBar(BarState.Off) + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/Util.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/Util.ets index addcbc56982b9238cabc11ce23a942ddf88a8044..33bad70bb0fe5aef8a557aa195b897b6bb1b104c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/Util.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/Util.ets @@ -1,118 +1,118 @@ -/* - * Copyright (c) 2023 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 vibrator from '@ohos.vibrator' -import Window from '@ohos.window' -import Logger from './Logger' -import resourceManager from '@ohos.resourceManager' -import { BusinessError } from '@ohos.base' -import { StartCustom } from 'library'; - -const TAG = '[Util]' - -export function getDynamicStates(dis: boolean[], id: number): boolean[] { - for (let i = 0; i < dis.length; i++) { - i === id ? dis[i] = true : dis[i] = false - Logger.info(TAG, dis[i].toString()) - } - return dis -} - -export async function playVibrateCustom(fileName: string, mode: string) { - let rawFd: resourceManager.RawFileDescriptor | undefined = undefined - await getContext().resourceManager.getRawFd(fileName).then(value => { - rawFd = value - Logger.info(TAG, "rawFd of vibration:" + " fd:" + rawFd.fd + ", offset:" + rawFd.offset + ", length: " + rawFd.length) - }) - if (mode === "ets") { - try { - vibrator.startVibration({ - type: "file", - hapticFd: { fd: rawFd!.fd, offset: rawFd!.offset, length: rawFd!.length } - }, { - usage: "unknown" - }, (error: BusinessError) => { - if (error) { - Logger.info(TAG, 'startVibration failed, type is file, in callback'); - } else { - Logger.info(TAG, 'startVibration successful, type is file, in callback'); - } - }); - } catch (error) { - let err: BusinessError = error as BusinessError; - Logger.info(TAG, 'startVibration failed, type is file, in catch, err code:' + err.code + ' err msg:' + err.message) - } - } else if (mode === "capi"){ - let ret: number - ret = StartCustom(rawFd!.fd, rawFd!.offset, rawFd!.length) - console.info('StartCustom ret', ret); - } -} - -export function changeOrientationInternal(lastWindow: Window.Window, portrait: boolean): void { - if (portrait) { - lastWindow.setPreferredOrientation(Window.Orientation.LANDSCAPE).then(() => { - Logger.info(TAG, "setPreferredOrientation success") - }).catch((error: BusinessError) => { - Logger.info(TAG, "setPreferredOrientation failure" + JSON.stringify(error)) - }) - } else { - lastWindow.setPreferredOrientation(Window.Orientation.PORTRAIT).then(() => { - Logger.info(TAG, "setPreferredOrientation success") - }).catch((error: BusinessError) => { - Logger.info(TAG, "setPreferredOrientation failure: " + JSON.stringify(error)) - }) - } -} - -export function changeOrientation(portrait: boolean): void { - Window.getLastWindow(getContext()).then((lastWindow: Window.Window) => { - changeOrientationInternal(lastWindow, portrait) - }).catch((error: BusinessError) => { - Logger.info(TAG, "getLastWindow error: " + JSON.stringify(error)) - }) -} - -export function hideTitleBar(): void { - Window.getLastWindow(getContext()).then((lastWindow: Window.Window) => { - if (lastWindow) { - lastWindow.setWindowSystemBarEnable([], (err: BusinessError) => { - if (err) { - Logger.info(TAG, "hideTitleBar failed") - } else { - Logger.info(TAG, "hideTitleBar successful") - } - }) - } - }).catch((error: BusinessError) => { - Logger.info(TAG, "getLastWindow error: " + JSON.stringify(error)) - }) -} - -export function showTitleBar(): void { - Window.getLastWindow(getContext()).then((lastWindow: Window.Window) => { - if (lastWindow) { - lastWindow.setWindowSystemBarEnable(['status', 'navigation'], (err: BusinessError) => { - if (err) { - Logger.info(TAG, "showTitleBar failed") - } else { - Logger.info(TAG, "showTitleBar successful") - } - }) - } - }).catch((error: BusinessError) => { - Logger.info(TAG, "getLastWindow error: " + JSON.stringify(error)) - }) -} +/* + * Copyright (c) 2023 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 vibrator from '@ohos.vibrator' +import Window from '@ohos.window' +import Logger from './Logger' +import resourceManager from '@ohos.resourceManager' +import { BusinessError } from '@ohos.base' +import { StartCustom } from 'library'; + +const TAG = '[Util]' + +export function getDynamicStates(dis: boolean[], id: number): boolean[] { + for (let i = 0; i < dis.length; i++) { + i === id ? dis[i] = true : dis[i] = false + Logger.info(TAG, dis[i].toString()) + } + return dis +} + +export async function playVibrateCustom(fileName: string, mode: string) { + let rawFd: resourceManager.RawFileDescriptor | undefined = undefined + await getContext().resourceManager.getRawFd(fileName).then(value => { + rawFd = value + Logger.info(TAG, "rawFd of vibration:" + " fd:" + rawFd.fd + ", offset:" + rawFd.offset + ", length: " + rawFd.length) + }) + if (mode === "ets") { + try { + vibrator.startVibration({ + type: "file", + hapticFd: { fd: rawFd!.fd, offset: rawFd!.offset, length: rawFd!.length } + }, { + usage: "unknown" + }, (error: BusinessError) => { + if (error) { + Logger.info(TAG, 'startVibration failed, type is file, in callback'); + } else { + Logger.info(TAG, 'startVibration successful, type is file, in callback'); + } + }); + } catch (error) { + let err: BusinessError = error as BusinessError; + Logger.info(TAG, 'startVibration failed, type is file, in catch, err code:' + err.code + ' err msg:' + err.message) + } + } else if (mode === "capi"){ + let ret: number + ret = StartCustom(rawFd!.fd, rawFd!.offset, rawFd!.length) + console.info('StartCustom ret', ret); + } +} + +export function changeOrientationInternal(lastWindow: Window.Window, portrait: boolean): void { + if (portrait) { + lastWindow.setPreferredOrientation(Window.Orientation.LANDSCAPE).then(() => { + Logger.info(TAG, "setPreferredOrientation success") + }).catch((error: BusinessError) => { + Logger.info(TAG, "setPreferredOrientation failure" + JSON.stringify(error)) + }) + } else { + lastWindow.setPreferredOrientation(Window.Orientation.PORTRAIT).then(() => { + Logger.info(TAG, "setPreferredOrientation success") + }).catch((error: BusinessError) => { + Logger.info(TAG, "setPreferredOrientation failure: " + JSON.stringify(error)) + }) + } +} + +export function changeOrientation(portrait: boolean): void { + Window.getLastWindow(getContext()).then((lastWindow: Window.Window) => { + changeOrientationInternal(lastWindow, portrait) + }).catch((error: BusinessError) => { + Logger.info(TAG, "getLastWindow error: " + JSON.stringify(error)) + }) +} + +export function hideTitleBar(): void { + Window.getLastWindow(getContext()).then((lastWindow: Window.Window) => { + if (lastWindow) { + lastWindow.setWindowSystemBarEnable([], (err: BusinessError) => { + if (err) { + Logger.info(TAG, "hideTitleBar failed") + } else { + Logger.info(TAG, "hideTitleBar successful") + } + }) + } + }).catch((error: BusinessError) => { + Logger.info(TAG, "getLastWindow error: " + JSON.stringify(error)) + }) +} + +export function showTitleBar(): void { + Window.getLastWindow(getContext()).then((lastWindow: Window.Window) => { + if (lastWindow) { + lastWindow.setWindowSystemBarEnable(['status', 'navigation'], (err: BusinessError) => { + if (err) { + Logger.info(TAG, "showTitleBar failed") + } else { + Logger.info(TAG, "showTitleBar successful") + } + }) + } + }).catch((error: BusinessError) => { + Logger.info(TAG, "getLastWindow error: " + JSON.stringify(error)) + }) +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoListModule.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoListModule.ets index a20194e7833eeca82f418591be912bafa6cd94f5..fb6d6f85c2d06785771a28599b810c09d74804b5 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoListModule.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoListModule.ets @@ -1,94 +1,94 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router' - -@Entry -@Component -struct VideoListModule { - private php: string = (router.getParams() as Record)['php'] - build() { - Column({ space: 20 }) { - Row() { - Button({ type: ButtonType.Normal }) { - Text("<") - .fontColor(Color.White) - .fontSize(28) - } - .backgroundColor('#00191a32') - .padding({ left: 5 }) - .layoutWeight(1) - .onClick(() => { - router.pushUrl({ - url: 'pages/Index' - }) - }) - - Text($r("app.string.back")) - .fontColor(Color.White) - .fontSize(24) - .layoutWeight(7) - .padding({ right: 10 }) - } - .padding({ top: 5 }) - - Column({ space: 20 }) { - List({ space: 10 }) { - ListItem() { - Row() { - Image($r("app.media.HapticVideoPreview")) - .width("50%") - .height(100) - .borderRadius(10) - Column() { - Text($r("app.string.video_list_haptic_video")) - .fontSize(18) - .fontColor(Color.White) - Text($r("app.string.video_list_haptic_video_msg")) - .fontSize(16) - .fontColor("#ff837979") - } - .alignItems(HorizontalAlign.Start) - .padding({ left: 5 }) - .height(100) - } - .width("95%") - .padding({ left: 10 }) - .backgroundColor("#00002222") - .onClick(() => { - router.pushUrl({ - url: "module/VideoPlayModule", - params: { - vibrateFileName: "HapticVideo.json", - videoName: 'HapticVideo', - videoSrc: $r("app.media.HapticVideo"), - previewUri: $r("app.media.HapticVideoPreview"), - pages: "VideoListPage", - php: this.php - } - }) - }) - } - } - .listDirection(Axis.Vertical) - .divider({ strokeWidth: 10, color: "#00f3f3f3", startMargin: 20, endMargin: 20 }) - .height("60%") - } - } - .width('100%') - .height('100%') - .backgroundColor('#f2191a32') - } -} +/* + * Copyright (c) 2023 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 router from '@ohos.router' + +@Entry +@Component +struct VideoListModule { + private php: string = (router.getParams() as Record)['php'] + build() { + Column({ space: 20 }) { + Row() { + Button({ type: ButtonType.Normal }) { + Text("<") + .fontColor(Color.White) + .fontSize(28) + } + .backgroundColor('#00191a32') + .padding({ left: 5 }) + .layoutWeight(1) + .onClick(() => { + router.pushUrl({ + url: 'pages/Index' + }) + }) + + Text($r("app.string.back")) + .fontColor(Color.White) + .fontSize(24) + .layoutWeight(7) + .padding({ right: 10 }) + } + .padding({ top: 5 }) + + Column({ space: 20 }) { + List({ space: 10 }) { + ListItem() { + Row() { + Image($r("app.media.HapticVideoPreview")) + .width("50%") + .height(100) + .borderRadius(10) + Column() { + Text($r("app.string.video_list_haptic_video")) + .fontSize(18) + .fontColor(Color.White) + Text($r("app.string.video_list_haptic_video_msg")) + .fontSize(16) + .fontColor("#ff837979") + } + .alignItems(HorizontalAlign.Start) + .padding({ left: 5 }) + .height(100) + } + .width("95%") + .padding({ left: 10 }) + .backgroundColor("#00002222") + .onClick(() => { + router.pushUrl({ + url: "module/VideoPlayModule", + params: { + vibrateFileName: "HapticVideo.json", + videoName: 'HapticVideo', + videoSrc: $r("app.media.HapticVideo"), + previewUri: $r("app.media.HapticVideoPreview"), + pages: "VideoListPage", + php: this.php + } + }) + }) + } + } + .listDirection(Axis.Vertical) + .divider({ strokeWidth: 10, color: "#00f3f3f3", startMargin: 20, endMargin: 20 }) + .height("60%") + } + } + .width('100%') + .height('100%') + .backgroundColor('#f2191a32') + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoPlayModule.ets b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoPlayModule.ets index df913bb18f68a691c9034027162a20309f61c8b9..adadb757878602f7b8df5ef886ddc2def7dfeea4 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoPlayModule.ets +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/ets/module/VideoPlayModule.ets @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2023 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 vibrator from '@ohos.vibrator'; -import router from '@ohos.router' -import { changeOrientation, showTitleBar, playVibrateCustom, hideTitleBar } from './Util' - -@Entry -@Component -struct VideoPlayModule { - @State videoName: string = (router.getParams() as Record)['videoName'] - private pages: string = (router.getParams() as Record)['pages'] - @State videoSrc: Resource = (router.getParams() as Record)['videoSrc'] - @State previewUri: Resource = (router.getParams() as Record)['previewUri'] - private vibrateFileName: string = (router.getParams() as Record)['vibrateFileName'] - @State portrait: boolean = true - private php: string = (router.getParams() as Record)['php'] - videoController: VideoController = new VideoController() - - build() { - Stack({ alignContent: Alignment.TopStart }) { - Video({ - src: this.videoSrc, - previewUri: this.previewUri, - controller: this.videoController, - }) - .height("100%") - .width('100%') - .objectFit(ImageFit.Auto) - .controls(false) - .onStart(() => { - changeOrientation(false) - hideTitleBar() - playVibrateCustom(this.vibrateFileName, this.php) - }) - .onClick(() => { - this.portrait = !this.portrait - }) - .autoPlay(true) - Row() { - Button('<') - .fontSize(15) - .backgroundColor("#00222222") - .id('videoBack') - .onClick(() => { - changeOrientation(false) - showTitleBar() - vibrator.stopVibration() - router.back() - }) - Text(this.videoName).fontSize(15).fontColor(Color.White) - } - .width("100%") - .height("10%") - .backgroundColor('#80191a32') - .visibility(this.portrait ? Visibility.Visible : Visibility.Hidden) - }.width('100%') - .height('100%') - .backgroundColor('#f2191a32') - } -} +/* + * Copyright (c) 2023 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 vibrator from '@ohos.vibrator'; +import router from '@ohos.router' +import { changeOrientation, showTitleBar, playVibrateCustom, hideTitleBar } from './Util' + +@Entry +@Component +struct VideoPlayModule { + @State videoName: string = (router.getParams() as Record)['videoName'] + private pages: string = (router.getParams() as Record)['pages'] + @State videoSrc: Resource = (router.getParams() as Record)['videoSrc'] + @State previewUri: Resource = (router.getParams() as Record)['previewUri'] + private vibrateFileName: string = (router.getParams() as Record)['vibrateFileName'] + @State portrait: boolean = true + private php: string = (router.getParams() as Record)['php'] + videoController: VideoController = new VideoController() + + build() { + Stack({ alignContent: Alignment.TopStart }) { + Video({ + src: this.videoSrc, + previewUri: this.previewUri, + controller: this.videoController, + }) + .height("100%") + .width('100%') + .objectFit(ImageFit.Auto) + .controls(false) + .onStart(() => { + changeOrientation(false) + hideTitleBar() + playVibrateCustom(this.vibrateFileName, this.php) + }) + .onClick(() => { + this.portrait = !this.portrait + }) + .autoPlay(true) + Row() { + Button('<') + .fontSize(15) + .backgroundColor("#00222222") + .id('videoBack') + .onClick(() => { + changeOrientation(false) + showTitleBar() + vibrator.stopVibration() + router.back() + }) + Text(this.videoName).fontSize(15).fontColor(Color.White) + } + .width("100%") + .height("10%") + .backgroundColor('#80191a32') + .visibility(this.portrait ? Visibility.Visible : Visibility.Hidden) + }.width('100%') + .height('100%') + .backgroundColor('#f2191a32') + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/module.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/module.json5 index 9171640f70b68172594be45cceaeb92216f8e2cb..7ce1388a9c393705b4b5fb20572c0e42dbaa046c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/module.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/module.json5 @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2023 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", - "srcEntrance": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "metadata": [ - { - "name": "ArkTSPartialUpdate", - "value": "true" - }, - { - "name": "partialUpdateStrictCheck", - "value": "warn" - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.VIBRATE" - } - ] - } +/* + * Copyright (c) 2023 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", + "srcEntrance": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "metadata": [ + { + "name": "ArkTSPartialUpdate", + "value": "true" + }, + { + "name": "partialUpdateStrictCheck", + "value": "warn" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.VIBRATE" + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/base/element/color.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_h.json index 6800ed2bb00c54ab763474fee999ace37635dc73..f5c83b76a660d56c6a69b4e1014dbaaf8d09291a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_h.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 147, - "Parameters": { - "Intensity": 100, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 182, - "Parameters": { - "Intensity": 100, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 147, + "Parameters": { + "Intensity": 100, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 182, + "Parameters": { + "Intensity": 100, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_l.json index d518b903f7717a70be3d5e252d3f398d835828ac..de732a7ba21aee8f9c85982e98ec4cd0656f5ade 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_l.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 147, - "Parameters": { - "Intensity": 60, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 182, - "Parameters": { - "Intensity": 60, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 147, + "Parameters": { + "Intensity": 60, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 182, + "Parameters": { + "Intensity": 60, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_m.json index 335d1d3e79c9dea5b1aedc1f759b78b20a6169f5..dfd948738e8e91407c401ea024c9651b18a83f45 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AK47_m.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 147, - "Parameters": { - "Intensity": 80, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 182, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 147, + "Parameters": { + "Intensity": 80, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 182, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_h.json index e0ccf32c6481eddbf0db440d1a6c841b08b79625..091cc5f291a2eef5e53c03a33a66b53814fefd8a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_h.json @@ -1,47 +1,47 @@ -{ - "MetaData": { - "Create": "2020-08-10", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 9, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 35, - "Parameters": { - "Intensity": 100, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 130, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2020-08-10", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 9, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 35, + "Parameters": { + "Intensity": 100, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 130, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_l.json index e69558665f6e22ca9dcc465a11a00aff739be739..1b4aa377bab4d577291c892592409eca1fbe7258 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_l.json @@ -1,47 +1,47 @@ -{ - "MetaData": { - "Create": "2020-08-10", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 5, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 35, - "Parameters": { - "Intensity": 60, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 130, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2020-08-10", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 5, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 35, + "Parameters": { + "Intensity": 60, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 130, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_m.json index 1980176c145778759daab25004bc38f6bcb80637..d3e058f644978dc1f9f4f8d0a159017e0a10e418 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/AssaultRifle_m.json @@ -1,47 +1,47 @@ -{ - "MetaData": { - "Create": "2020-08-10", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 7, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 35, - "Parameters": { - "Intensity": 80, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 130, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2020-08-10", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 7, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 35, + "Parameters": { + "Intensity": 80, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 130, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_h.json index 9b6f55dd12477131b1bbf515adc77c775f019deb..b1b7319a2bc037eccf2e85d039dd9e73cb522dec 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_h.json @@ -1,225 +1,225 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 27, - "Parameters": { - "Intensity": 92, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 49, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 10 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 140, - "StartTime": 78, - "Parameters": { - "Intensity": 65, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 99, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 140, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 548, - "Parameters": { - "Intensity": 60, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 39, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 548, - "Parameters": { - "Intensity": 29, - "Frequency": 65, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 62, - "StartTime": 662, - "Parameters": { - "Intensity": 85, - "Frequency": 75, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 22, - "Intensity": 0.06, - "Frequency": -30 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 20 - }, - { - "Time": 62, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1179, - "Parameters": { - "Intensity": 80, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 110, - "StartTime": 1217, - "Parameters": { - "Intensity": 45, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 77, - "Intensity": 0.66, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 27, + "Parameters": { + "Intensity": 92, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 49, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 10 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 140, + "StartTime": 78, + "Parameters": { + "Intensity": 65, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 99, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 140, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 548, + "Parameters": { + "Intensity": 60, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 39, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 548, + "Parameters": { + "Intensity": 29, + "Frequency": 65, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 62, + "StartTime": 662, + "Parameters": { + "Intensity": 85, + "Frequency": 75, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 22, + "Intensity": 0.06, + "Frequency": -30 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 20 + }, + { + "Time": 62, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1179, + "Parameters": { + "Intensity": 80, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 110, + "StartTime": 1217, + "Parameters": { + "Intensity": 45, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 77, + "Intensity": 0.66, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_l.json index 2dd217e8c572face06b04df8968a007a8ff45cb7..b0df34b91eaf71ebb7152ce8ac1fd52f6cacb4a6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_l.json @@ -1,225 +1,225 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 27, - "Parameters": { - "Intensity": 55, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 49, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 10 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 140, - "StartTime": 78, - "Parameters": { - "Intensity": 39, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 99, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 140, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 548, - "Parameters": { - "Intensity": 36, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 39, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 548, - "Parameters": { - "Intensity": 17, - "Frequency": 65, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 62, - "StartTime": 662, - "Parameters": { - "Intensity": 51, - "Frequency": 75, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 22, - "Intensity": 0.06, - "Frequency": -30 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 20 - }, - { - "Time": 62, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1179, - "Parameters": { - "Intensity": 48, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 110, - "StartTime": 1217, - "Parameters": { - "Intensity": 27, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 77, - "Intensity": 0.66, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 27, + "Parameters": { + "Intensity": 55, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 49, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 10 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 140, + "StartTime": 78, + "Parameters": { + "Intensity": 39, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 99, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 140, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 548, + "Parameters": { + "Intensity": 36, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 39, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 548, + "Parameters": { + "Intensity": 17, + "Frequency": 65, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 62, + "StartTime": 662, + "Parameters": { + "Intensity": 51, + "Frequency": 75, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 22, + "Intensity": 0.06, + "Frequency": -30 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 20 + }, + { + "Time": 62, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1179, + "Parameters": { + "Intensity": 48, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 110, + "StartTime": 1217, + "Parameters": { + "Intensity": 27, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 77, + "Intensity": 0.66, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_m.json index 897da3d77bc83c4bccc11c6cea7c02290cfa1a37..585fa871bfd0f111ea42a7f6cfb27c7ed49a1253 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Badminton_m.json @@ -1,225 +1,225 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 27, - "Parameters": { - "Intensity": 73, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 49, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 10 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 140, - "StartTime": 78, - "Parameters": { - "Intensity": 52, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 99, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 140, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 548, - "Parameters": { - "Intensity": 48, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 39, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 548, - "Parameters": { - "Intensity": 23, - "Frequency": 65, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 62, - "StartTime": 662, - "Parameters": { - "Intensity": 68, - "Frequency": 75, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 22, - "Intensity": 0.06, - "Frequency": -30 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 20 - }, - { - "Time": 62, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1179, - "Parameters": { - "Intensity": 64, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 110, - "StartTime": 1217, - "Parameters": { - "Intensity": 36, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 77, - "Intensity": 0.66, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 27, + "Parameters": { + "Intensity": 73, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 49, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 10 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 140, + "StartTime": 78, + "Parameters": { + "Intensity": 52, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 99, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 140, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 548, + "Parameters": { + "Intensity": 48, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 39, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 548, + "Parameters": { + "Intensity": 23, + "Frequency": 65, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 62, + "StartTime": 662, + "Parameters": { + "Intensity": 68, + "Frequency": 75, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 22, + "Intensity": 0.06, + "Frequency": -30 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 20 + }, + { + "Time": 62, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1179, + "Parameters": { + "Intensity": 64, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 110, + "StartTime": 1217, + "Parameters": { + "Intensity": 36, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 77, + "Intensity": 0.66, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_h.json index 97345e62f753a1807580a6725e1628f6b257ee43..1168c116cbb6a1198a190480e58da7ea52d76086 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_h.json @@ -1,93 +1,93 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 106, - "Parameters": { - "Intensity": 55, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 0.26, - "Frequency": 10 - }, - { - "Time": 86, - "Intensity": 0.59, - "Frequency": 15 - }, - { - "Time": 102, - "Intensity": 0.59, - "Frequency": 10 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 141, - "StartTime": 232, - "Parameters": { - "Intensity": 100, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 10 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 45, - "Intensity": 0.51, - "Frequency": -20 - }, - { - "Time": 141, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 106, + "Parameters": { + "Intensity": 55, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 0.26, + "Frequency": 10 + }, + { + "Time": 86, + "Intensity": 0.59, + "Frequency": 15 + }, + { + "Time": 102, + "Intensity": 0.59, + "Frequency": 10 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 141, + "StartTime": 232, + "Parameters": { + "Intensity": 100, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 10 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 45, + "Intensity": 0.51, + "Frequency": -20 + }, + { + "Time": 141, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_l.json index bae3f24bb34b97f67b1360d5502e10a3cadda698..f6d24b719b789ddbfda360ac553d6ccdaceca162 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_l.json @@ -1,93 +1,93 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 106, - "Parameters": { - "Intensity": 33, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 0.26, - "Frequency": 10 - }, - { - "Time": 86, - "Intensity": 0.59, - "Frequency": 15 - }, - { - "Time": 102, - "Intensity": 0.59, - "Frequency": 10 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 141, - "StartTime": 232, - "Parameters": { - "Intensity": 60, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 10 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 45, - "Intensity": 0.51, - "Frequency": -20 - }, - { - "Time": 141, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 106, + "Parameters": { + "Intensity": 33, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 0.26, + "Frequency": 10 + }, + { + "Time": 86, + "Intensity": 0.59, + "Frequency": 15 + }, + { + "Time": 102, + "Intensity": 0.59, + "Frequency": 10 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 141, + "StartTime": 232, + "Parameters": { + "Intensity": 60, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 10 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 45, + "Intensity": 0.51, + "Frequency": -20 + }, + { + "Time": 141, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_m.json index e2358fdebe1011d6da1871dfdc290f8cf49bd6b4..48570ab26d1510582ab95cd040c2b1f0c1b24159 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Baseball_m.json @@ -1,93 +1,93 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 114, - "StartTime": 106, - "Parameters": { - "Intensity": 44, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 0.26, - "Frequency": 10 - }, - { - "Time": 86, - "Intensity": 0.59, - "Frequency": 15 - }, - { - "Time": 102, - "Intensity": 0.59, - "Frequency": 10 - }, - { - "Time": 114, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 141, - "StartTime": 232, - "Parameters": { - "Intensity": 80, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 10 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 45, - "Intensity": 0.51, - "Frequency": -20 - }, - { - "Time": 141, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 114, + "StartTime": 106, + "Parameters": { + "Intensity": 44, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 0.26, + "Frequency": 10 + }, + { + "Time": 86, + "Intensity": 0.59, + "Frequency": 15 + }, + { + "Time": 102, + "Intensity": 0.59, + "Frequency": 10 + }, + { + "Time": 114, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 141, + "StartTime": 232, + "Parameters": { + "Intensity": 80, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 10 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 45, + "Intensity": 0.51, + "Frequency": -20 + }, + { + "Time": 141, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_h.json index 7497bd0f5e71d171e0666c97236893d275e49b61..573ed0435fc1ece1189dd9adc4a52b1aa481b44c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_h.json @@ -1,362 +1,362 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 221, - "StartTime": 31, - "Parameters": { - "Intensity": 100, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 62, - "Intensity": 0.35, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 221, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 49, - "Parameters": { - "Intensity": 100, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 588, - "Parameters": { - "Intensity": 50, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 240, - "StartTime": 692, - "Parameters": { - "Intensity": 80, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 60, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 168, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 240, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 712, - "Parameters": { - "Intensity": 80, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1073, - "Parameters": { - "Intensity": 40, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 1139, - "Parameters": { - "Intensity": 70, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 61, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1156, - "Parameters": { - "Intensity": 70, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1506, - "Parameters": { - "Intensity": 33, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 1569, - "Parameters": { - "Intensity": 60, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 61, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1586, - "Parameters": { - "Intensity": 60, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1851, - "Parameters": { - "Intensity": 25, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 169, - "StartTime": 1923, - "Parameters": { - "Intensity": 50, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 46, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 53, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 113, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 169, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1935, - "Parameters": { - "Intensity": 50, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2087, - "Parameters": { - "Intensity": 50, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2185, - "Parameters": { - "Intensity": 40, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2289, - "Parameters": { - "Intensity": 40, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2382, - "Parameters": { - "Intensity": 30, - "Frequency": 40 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 221, + "StartTime": 31, + "Parameters": { + "Intensity": 100, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 62, + "Intensity": 0.35, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 221, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 49, + "Parameters": { + "Intensity": 100, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 588, + "Parameters": { + "Intensity": 50, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 240, + "StartTime": 692, + "Parameters": { + "Intensity": 80, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 60, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 168, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 240, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 712, + "Parameters": { + "Intensity": 80, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1073, + "Parameters": { + "Intensity": 40, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 1139, + "Parameters": { + "Intensity": 70, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 61, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1156, + "Parameters": { + "Intensity": 70, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1506, + "Parameters": { + "Intensity": 33, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 1569, + "Parameters": { + "Intensity": 60, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 61, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1586, + "Parameters": { + "Intensity": 60, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1851, + "Parameters": { + "Intensity": 25, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 169, + "StartTime": 1923, + "Parameters": { + "Intensity": 50, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 46, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 53, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 113, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 169, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1935, + "Parameters": { + "Intensity": 50, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2087, + "Parameters": { + "Intensity": 50, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2185, + "Parameters": { + "Intensity": 40, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2289, + "Parameters": { + "Intensity": 40, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2382, + "Parameters": { + "Intensity": 30, + "Frequency": 40 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_l.json index 83beb60d84e2c2682d7ce1eb613eebd68ced83b2..84e078c1390521e257183f43da45837971abeae5 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_l.json @@ -1,362 +1,362 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 221, - "StartTime": 31, - "Parameters": { - "Intensity": 60, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 62, - "Intensity": 0.35, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 221, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 49, - "Parameters": { - "Intensity": 60, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 588, - "Parameters": { - "Intensity": 30, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 240, - "StartTime": 692, - "Parameters": { - "Intensity": 48, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 60, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 168, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 240, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 712, - "Parameters": { - "Intensity": 48, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1073, - "Parameters": { - "Intensity": 24, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 1139, - "Parameters": { - "Intensity": 42, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 61, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1156, - "Parameters": { - "Intensity": 42, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1506, - "Parameters": { - "Intensity": 19, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 1569, - "Parameters": { - "Intensity": 36, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 61, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1586, - "Parameters": { - "Intensity": 36, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1851, - "Parameters": { - "Intensity": 15, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 169, - "StartTime": 1923, - "Parameters": { - "Intensity": 30, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 46, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 53, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 113, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 169, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1935, - "Parameters": { - "Intensity": 30, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2087, - "Parameters": { - "Intensity": 30, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2185, - "Parameters": { - "Intensity": 24, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2289, - "Parameters": { - "Intensity": 24, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2382, - "Parameters": { - "Intensity": 18, - "Frequency": 40 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 221, + "StartTime": 31, + "Parameters": { + "Intensity": 60, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 62, + "Intensity": 0.35, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 221, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 49, + "Parameters": { + "Intensity": 60, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 588, + "Parameters": { + "Intensity": 30, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 240, + "StartTime": 692, + "Parameters": { + "Intensity": 48, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 60, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 168, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 240, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 712, + "Parameters": { + "Intensity": 48, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1073, + "Parameters": { + "Intensity": 24, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 1139, + "Parameters": { + "Intensity": 42, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 61, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1156, + "Parameters": { + "Intensity": 42, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1506, + "Parameters": { + "Intensity": 19, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 1569, + "Parameters": { + "Intensity": 36, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 61, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1586, + "Parameters": { + "Intensity": 36, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1851, + "Parameters": { + "Intensity": 15, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 169, + "StartTime": 1923, + "Parameters": { + "Intensity": 30, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 46, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 53, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 113, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 169, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1935, + "Parameters": { + "Intensity": 30, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2087, + "Parameters": { + "Intensity": 30, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2185, + "Parameters": { + "Intensity": 24, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2289, + "Parameters": { + "Intensity": 24, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2382, + "Parameters": { + "Intensity": 18, + "Frequency": 40 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_m.json index ecf43fafa5b759337ad93f7729ec1e2c108ba0e2..f3827b5e6e96a8f81ab66e9a1e6ef3952c7f5802 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Basketball_m.json @@ -1,362 +1,362 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 221, - "StartTime": 31, - "Parameters": { - "Intensity": 80, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 62, - "Intensity": 0.35, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 221, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 49, - "Parameters": { - "Intensity": 80, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 588, - "Parameters": { - "Intensity": 40, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 240, - "StartTime": 692, - "Parameters": { - "Intensity": 64, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 60, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 168, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 240, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 712, - "Parameters": { - "Intensity": 64, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1073, - "Parameters": { - "Intensity": 32, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 1139, - "Parameters": { - "Intensity": 56, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 61, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1156, - "Parameters": { - "Intensity": 56, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1506, - "Parameters": { - "Intensity": 26, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 1569, - "Parameters": { - "Intensity": 48, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 7, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 55, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 61, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 154, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1586, - "Parameters": { - "Intensity": 48, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1851, - "Parameters": { - "Intensity": 20, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 169, - "StartTime": 1923, - "Parameters": { - "Intensity": 40, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 46, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 53, - "Intensity": 0.36, - "Frequency": -10 - }, - { - "Time": 113, - "Intensity": 0.34, - "Frequency": -15 - }, - { - "Time": 169, - "Intensity": 0, - "Frequency": -10 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1935, - "Parameters": { - "Intensity": 40, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2087, - "Parameters": { - "Intensity": 40, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2185, - "Parameters": { - "Intensity": 32, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2289, - "Parameters": { - "Intensity": 32, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2382, - "Parameters": { - "Intensity": 24, - "Frequency": 40 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 221, + "StartTime": 31, + "Parameters": { + "Intensity": 80, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 62, + "Intensity": 0.35, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 221, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 49, + "Parameters": { + "Intensity": 80, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 588, + "Parameters": { + "Intensity": 40, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 240, + "StartTime": 692, + "Parameters": { + "Intensity": 64, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 60, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 168, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 240, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 712, + "Parameters": { + "Intensity": 64, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1073, + "Parameters": { + "Intensity": 32, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 1139, + "Parameters": { + "Intensity": 56, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 61, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1156, + "Parameters": { + "Intensity": 56, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1506, + "Parameters": { + "Intensity": 26, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 1569, + "Parameters": { + "Intensity": 48, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 7, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 55, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 61, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 154, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1586, + "Parameters": { + "Intensity": 48, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1851, + "Parameters": { + "Intensity": 20, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 169, + "StartTime": 1923, + "Parameters": { + "Intensity": 40, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 46, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 53, + "Intensity": 0.36, + "Frequency": -10 + }, + { + "Time": 113, + "Intensity": 0.34, + "Frequency": -15 + }, + { + "Time": 169, + "Intensity": 0, + "Frequency": -10 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1935, + "Parameters": { + "Intensity": 40, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2087, + "Parameters": { + "Intensity": 40, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2185, + "Parameters": { + "Intensity": 32, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2289, + "Parameters": { + "Intensity": 32, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2382, + "Parameters": { + "Intensity": 24, + "Frequency": 40 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_h.json index 653a4f5d7b0efafb6aed8a9367e2e1d54aa4a243..25832cd2da9b6d41a3f10f5efb9cf7e27f2fd1c7 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_h.json @@ -1,116 +1,116 @@ -{ - "MetaData": { - "Create": "2021-02-23", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 0, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -33 - }, - { - "Time": 44, - "Intensity": 1.0, - "Frequency": 63 - }, - { - "Time": 79, - "Intensity": 1.0, - "Frequency": -5 - }, - { - "Time": 260, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 597, - "StartTime": 265, - "Parameters": { - "Intensity": 81, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 81, - "Intensity": 1.0, - "Frequency": -45 - }, - { - "Time": 534, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 597, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 597, - "StartTime": 867, - "Parameters": { - "Intensity": 63, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 81, - "Intensity": 1.0, - "Frequency": -45 - }, - { - "Time": 423, - "Intensity": 0.31, - "Frequency": -45 - }, - { - "Time": 597, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-02-23", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 0, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -33 + }, + { + "Time": 44, + "Intensity": 1.0, + "Frequency": 63 + }, + { + "Time": 79, + "Intensity": 1.0, + "Frequency": -5 + }, + { + "Time": 260, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 597, + "StartTime": 265, + "Parameters": { + "Intensity": 81, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 81, + "Intensity": 1.0, + "Frequency": -45 + }, + { + "Time": 534, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 597, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 597, + "StartTime": 867, + "Parameters": { + "Intensity": 63, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 81, + "Intensity": 1.0, + "Frequency": -45 + }, + { + "Time": 423, + "Intensity": 0.31, + "Frequency": -45 + }, + { + "Time": 597, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_l.json index d03f9261c546212358d4a1bff82e33647c1e8859..fa30c08b58fb65e92f478e57a80fe4266866a6aa 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_l.json @@ -1,116 +1,116 @@ -{ - "MetaData": { - "Create": "2021-02-23", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -33 - }, - { - "Time": 44, - "Intensity": 1.0, - "Frequency": 63 - }, - { - "Time": 79, - "Intensity": 1.0, - "Frequency": -5 - }, - { - "Time": 260, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 597, - "StartTime": 265, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 81, - "Intensity": 1.0, - "Frequency": -45 - }, - { - "Time": 534, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 597, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 597, - "StartTime": 867, - "Parameters": { - "Intensity": 37, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 81, - "Intensity": 1.0, - "Frequency": -45 - }, - { - "Time": 423, - "Intensity": 0.31, - "Frequency": -45 - }, - { - "Time": 597, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-02-23", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -33 + }, + { + "Time": 44, + "Intensity": 1.0, + "Frequency": 63 + }, + { + "Time": 79, + "Intensity": 1.0, + "Frequency": -5 + }, + { + "Time": 260, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 597, + "StartTime": 265, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 81, + "Intensity": 1.0, + "Frequency": -45 + }, + { + "Time": 534, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 597, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 597, + "StartTime": 867, + "Parameters": { + "Intensity": 37, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 81, + "Intensity": 1.0, + "Frequency": -45 + }, + { + "Time": 423, + "Intensity": 0.31, + "Frequency": -45 + }, + { + "Time": 597, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_m.json index 8a2b86584f542a2acc62496dc5c6bebb749da4c2..66ca31f02a0569cb3def73056af8ffa47bda486d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Blast_m.json @@ -1,116 +1,116 @@ -{ - "MetaData": { - "Create": "2021-02-23", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 0, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -33 - }, - { - "Time": 44, - "Intensity": 1.0, - "Frequency": 63 - }, - { - "Time": 79, - "Intensity": 1.0, - "Frequency": -5 - }, - { - "Time": 260, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 597, - "StartTime": 265, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 81, - "Intensity": 1.0, - "Frequency": -45 - }, - { - "Time": 534, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 597, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 597, - "StartTime": 867, - "Parameters": { - "Intensity": 50, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 81, - "Intensity": 1.0, - "Frequency": -45 - }, - { - "Time": 423, - "Intensity": 0.31, - "Frequency": -45 - }, - { - "Time": 597, - "Intensity": 0.0, - "Frequency": -14 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-02-23", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 0, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -33 + }, + { + "Time": 44, + "Intensity": 1.0, + "Frequency": 63 + }, + { + "Time": 79, + "Intensity": 1.0, + "Frequency": -5 + }, + { + "Time": 260, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 597, + "StartTime": 265, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 81, + "Intensity": 1.0, + "Frequency": -45 + }, + { + "Time": 534, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 597, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 597, + "StartTime": 867, + "Parameters": { + "Intensity": 50, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 81, + "Intensity": 1.0, + "Frequency": -45 + }, + { + "Time": 423, + "Intensity": 0.31, + "Frequency": -45 + }, + { + "Time": 597, + "Intensity": 0.0, + "Frequency": -14 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_h.json index cbc9e4a35f15532a2bc61b59c34fd4bf203b0f03..a504caf3823bf4be340e23cadb8c0a29b4c781b1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_h.json @@ -1,654 +1,654 @@ -{ - "MetaData": { - "Create": "2021-10-18", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 126, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 69.313 - }, - { - "Time": 26, - "Intensity": 0.21, - "Frequency": 69.313 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 67.3027 - }, - { - "Time": 60, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 102, - "Intensity": 1, - "Frequency": 27 - }, - { - "Time": 144, - "Intensity": 1, - "Frequency": 27 - }, - { - "Time": 167, - "Intensity": 0.36219, - "Frequency": 47.0092 - }, - { - "Time": 200, - "Intensity": 0.82, - "Frequency": 8 - }, - { - "Time": 233, - "Intensity": 0.18445, - "Frequency": 47.9644 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 47.9644 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 359, - "Parameters": { - "Intensity": 100, - "Frequency": 48, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 47.9644 - }, - { - "Time": 11, - "Intensity": 0.75, - "Frequency": 26 - }, - { - "Time": 67, - "Intensity": 0.40413, - "Frequency": 46.0884 - }, - { - "Time": 143, - "Intensity": 0.27, - "Frequency": 26.5024 - }, - { - "Time": 212, - "Intensity": 0.51, - "Frequency": 21.0208 - }, - { - "Time": 234, - "Intensity": 0.29322, - "Frequency": 20.638 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 23.1938 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 593, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20.638 - }, - { - "Time": 6, - "Intensity": 0.34, - "Frequency": 23.1938 - }, - { - "Time": 34, - "Intensity": 0.61, - "Frequency": 23.1944 - }, - { - "Time": 50, - "Intensity": 0.21961, - "Frequency": 23.1944 - }, - { - "Time": 109, - "Intensity": 0.42, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 233, - "Intensity": 0.14725, - "Frequency": 17.5734 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.3638 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 826, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 17.5734 - }, - { - "Time": 33, - "Intensity": 0.34455, - "Frequency": 13.7928 - }, - { - "Time": 83, - "Intensity": 0.17566, - "Frequency": 13.2156 - }, - { - "Time": 99, - "Intensity": 0.47, - "Frequency": 13.8843 - }, - { - "Time": 150, - "Intensity": 0.099891, - "Frequency": 16.2494 - }, - { - "Time": 167, - "Intensity": 0.54439, - "Frequency": 16.251 - }, - { - "Time": 183, - "Intensity": 0.20715, - "Frequency": 14.4624 - }, - { - "Time": 217, - "Intensity": 0.083533, - "Frequency": 15.2237 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.4596 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1059, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 15.0306 - }, - { - "Time": 17, - "Intensity": 0.24137, - "Frequency": 14.4596 - }, - { - "Time": 34, - "Intensity": 0.27653, - "Frequency": 14.7438 - }, - { - "Time": 50, - "Intensity": 0.24485, - "Frequency": 19.939 - }, - { - "Time": 67, - "Intensity": 0.20559, - "Frequency": 20.5117 - }, - { - "Time": 84, - "Intensity": 0.11978, - "Frequency": 20.3226 - }, - { - "Time": 100, - "Intensity": 0.32286, - "Frequency": 18.1331 - }, - { - "Time": 117, - "Intensity": 0.21612, - "Frequency": 18.1331 - }, - { - "Time": 134, - "Intensity": 0.49264, - "Frequency": 21.2452 - }, - { - "Time": 150, - "Intensity": 0.18907, - "Frequency": 18.3376 - }, - { - "Time": 167, - "Intensity": 0.14537, - "Frequency": 17.9806 - }, - { - "Time": 184, - "Intensity": 0.26344, - "Frequency": 17.1246 - }, - { - "Time": 200, - "Intensity": 0.35007, - "Frequency": 17.7879 - }, - { - "Time": 217, - "Intensity": 0.14297, - "Frequency": 14.3585 - }, - { - "Time": 234, - "Intensity": 0.21184, - "Frequency": 16.9936 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 15.7556 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1293, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 16.9936 - }, - { - "Time": 16, - "Intensity": 0.2691, - "Frequency": 15.7556 - }, - { - "Time": 33, - "Intensity": 0.1914, - "Frequency": 16.9983 - }, - { - "Time": 50, - "Intensity": 0.14346, - "Frequency": 16.6456 - }, - { - "Time": 66, - "Intensity": 0.093315, - "Frequency": 17.6002 - }, - { - "Time": 83, - "Intensity": 0.13911, - "Frequency": 17.031 - }, - { - "Time": 100, - "Intensity": 0.071573, - "Frequency": 15.6997 - }, - { - "Time": 116, - "Intensity": 0.36325, - "Frequency": 14.6485 - }, - { - "Time": 133, - "Intensity": 0.10331, - "Frequency": 15.2189 - }, - { - "Time": 150, - "Intensity": 0.081988, - "Frequency": 15.2189 - }, - { - "Time": 166, - "Intensity": 0.074824, - "Frequency": 15.4095 - }, - { - "Time": 183, - "Intensity": 0.045809, - "Frequency": 14.5488 - }, - { - "Time": 200, - "Intensity": 0.033725, - "Frequency": 14.6454 - }, - { - "Time": 216, - "Intensity": 0.089506, - "Frequency": 14.2635 - }, - { - "Time": 233, - "Intensity": 0.066092, - "Frequency": 14.743 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.27 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1526, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 14.743 - }, - { - "Time": 17, - "Intensity": 0.085394, - "Frequency": 14.27 - }, - { - "Time": 33, - "Intensity": 0.029442, - "Frequency": 13.9832 - }, - { - "Time": 50, - "Intensity": 0.020521, - "Frequency": 16.1406 - }, - { - "Time": 67, - "Intensity": 0.05142, - "Frequency": 16.5194 - }, - { - "Time": 83, - "Intensity": 0.026311, - "Frequency": 16.6157 - }, - { - "Time": 100, - "Intensity": 0.017077, - "Frequency": 17.2985 - }, - { - "Time": 117, - "Intensity": 0.017877, - "Frequency": 16.7269 - }, - { - "Time": 133, - "Intensity": 0.004579, - "Frequency": 18.9123 - }, - { - "Time": 150, - "Intensity": 0.015018, - "Frequency": 18.3264 - }, - { - "Time": 167, - "Intensity": 0.0063699, - "Frequency": 19.3763 - }, - { - "Time": 183, - "Intensity": 0.003663, - "Frequency": 19.3763 - }, - { - "Time": 200, - "Intensity": 0.0042855, - "Frequency": 3.7525 - }, - { - "Time": 217, - "Intensity": 0.0021302, - "Frequency": 3.847 - }, - { - "Time": 233, - "Intensity": 0.0078309, - "Frequency": 6.7964 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 7.1782 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1759, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 6.7964 - }, - { - "Time": 17, - "Intensity": 0.0035206, - "Frequency": 7.1782 - }, - { - "Time": 34, - "Intensity": 0.0011543, - "Frequency": 6.7993 - }, - { - "Time": 50, - "Intensity": 0.0022953, - "Frequency": 7.3322 - }, - { - "Time": 67, - "Intensity": 0.003826, - "Frequency": 12.0493 - }, - { - "Time": 84, - "Intensity": 0.0012973, - "Frequency": 16.6841 - }, - { - "Time": 100, - "Intensity": 0.0021943, - "Frequency": 20.0356 - }, - { - "Time": 117, - "Intensity": 0.0025446, - "Frequency": 17.6828 - }, - { - "Time": 134, - "Intensity": 0.0013369, - "Frequency": 13.7097 - }, - { - "Time": 150, - "Intensity": 0.00056959, - "Frequency": 7.8294 - }, - { - "Time": 167, - "Intensity": 0.00094861, - "Frequency": 0 - }, - { - "Time": 184, - "Intensity": 0.00058555, - "Frequency": 1 - }, - { - "Time": 200, - "Intensity": 0.00044257, - "Frequency": 3.5058 - }, - { - "Time": 217, - "Intensity": 0.00034451, - "Frequency": 3.5058 - }, - { - "Time": 234, - "Intensity": 0.00010188, - "Frequency": 6.3945 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 5.4841 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 75, - "StartTime": 1993, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 6.3945 - }, - { - "Time": 16, - "Intensity": 5.9868e-05, - "Frequency": 5.4841 - }, - { - "Time": 33, - "Intensity": 6.1123e-05, - "Frequency": 5.4841 - }, - { - "Time": 50, - "Intensity": 1.8783e-05, - "Frequency": 9.5255 - }, - { - "Time": 66, - "Intensity": 5.7126e-06, - "Frequency": 15.0855 - }, - { - "Time": 75, - "Intensity": 0, - "Frequency": 17.5105 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-10-18", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 126, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 69.313 + }, + { + "Time": 26, + "Intensity": 0.21, + "Frequency": 69.313 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 67.3027 + }, + { + "Time": 60, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 102, + "Intensity": 1, + "Frequency": 27 + }, + { + "Time": 144, + "Intensity": 1, + "Frequency": 27 + }, + { + "Time": 167, + "Intensity": 0.36219, + "Frequency": 47.0092 + }, + { + "Time": 200, + "Intensity": 0.82, + "Frequency": 8 + }, + { + "Time": 233, + "Intensity": 0.18445, + "Frequency": 47.9644 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 47.9644 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 359, + "Parameters": { + "Intensity": 100, + "Frequency": 48, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 47.9644 + }, + { + "Time": 11, + "Intensity": 0.75, + "Frequency": 26 + }, + { + "Time": 67, + "Intensity": 0.40413, + "Frequency": 46.0884 + }, + { + "Time": 143, + "Intensity": 0.27, + "Frequency": 26.5024 + }, + { + "Time": 212, + "Intensity": 0.51, + "Frequency": 21.0208 + }, + { + "Time": 234, + "Intensity": 0.29322, + "Frequency": 20.638 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 23.1938 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 593, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20.638 + }, + { + "Time": 6, + "Intensity": 0.34, + "Frequency": 23.1938 + }, + { + "Time": 34, + "Intensity": 0.61, + "Frequency": 23.1944 + }, + { + "Time": 50, + "Intensity": 0.21961, + "Frequency": 23.1944 + }, + { + "Time": 109, + "Intensity": 0.42, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 233, + "Intensity": 0.14725, + "Frequency": 17.5734 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.3638 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 826, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 17.5734 + }, + { + "Time": 33, + "Intensity": 0.34455, + "Frequency": 13.7928 + }, + { + "Time": 83, + "Intensity": 0.17566, + "Frequency": 13.2156 + }, + { + "Time": 99, + "Intensity": 0.47, + "Frequency": 13.8843 + }, + { + "Time": 150, + "Intensity": 0.099891, + "Frequency": 16.2494 + }, + { + "Time": 167, + "Intensity": 0.54439, + "Frequency": 16.251 + }, + { + "Time": 183, + "Intensity": 0.20715, + "Frequency": 14.4624 + }, + { + "Time": 217, + "Intensity": 0.083533, + "Frequency": 15.2237 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.4596 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1059, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 15.0306 + }, + { + "Time": 17, + "Intensity": 0.24137, + "Frequency": 14.4596 + }, + { + "Time": 34, + "Intensity": 0.27653, + "Frequency": 14.7438 + }, + { + "Time": 50, + "Intensity": 0.24485, + "Frequency": 19.939 + }, + { + "Time": 67, + "Intensity": 0.20559, + "Frequency": 20.5117 + }, + { + "Time": 84, + "Intensity": 0.11978, + "Frequency": 20.3226 + }, + { + "Time": 100, + "Intensity": 0.32286, + "Frequency": 18.1331 + }, + { + "Time": 117, + "Intensity": 0.21612, + "Frequency": 18.1331 + }, + { + "Time": 134, + "Intensity": 0.49264, + "Frequency": 21.2452 + }, + { + "Time": 150, + "Intensity": 0.18907, + "Frequency": 18.3376 + }, + { + "Time": 167, + "Intensity": 0.14537, + "Frequency": 17.9806 + }, + { + "Time": 184, + "Intensity": 0.26344, + "Frequency": 17.1246 + }, + { + "Time": 200, + "Intensity": 0.35007, + "Frequency": 17.7879 + }, + { + "Time": 217, + "Intensity": 0.14297, + "Frequency": 14.3585 + }, + { + "Time": 234, + "Intensity": 0.21184, + "Frequency": 16.9936 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 15.7556 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1293, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 16.9936 + }, + { + "Time": 16, + "Intensity": 0.2691, + "Frequency": 15.7556 + }, + { + "Time": 33, + "Intensity": 0.1914, + "Frequency": 16.9983 + }, + { + "Time": 50, + "Intensity": 0.14346, + "Frequency": 16.6456 + }, + { + "Time": 66, + "Intensity": 0.093315, + "Frequency": 17.6002 + }, + { + "Time": 83, + "Intensity": 0.13911, + "Frequency": 17.031 + }, + { + "Time": 100, + "Intensity": 0.071573, + "Frequency": 15.6997 + }, + { + "Time": 116, + "Intensity": 0.36325, + "Frequency": 14.6485 + }, + { + "Time": 133, + "Intensity": 0.10331, + "Frequency": 15.2189 + }, + { + "Time": 150, + "Intensity": 0.081988, + "Frequency": 15.2189 + }, + { + "Time": 166, + "Intensity": 0.074824, + "Frequency": 15.4095 + }, + { + "Time": 183, + "Intensity": 0.045809, + "Frequency": 14.5488 + }, + { + "Time": 200, + "Intensity": 0.033725, + "Frequency": 14.6454 + }, + { + "Time": 216, + "Intensity": 0.089506, + "Frequency": 14.2635 + }, + { + "Time": 233, + "Intensity": 0.066092, + "Frequency": 14.743 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.27 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1526, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 14.743 + }, + { + "Time": 17, + "Intensity": 0.085394, + "Frequency": 14.27 + }, + { + "Time": 33, + "Intensity": 0.029442, + "Frequency": 13.9832 + }, + { + "Time": 50, + "Intensity": 0.020521, + "Frequency": 16.1406 + }, + { + "Time": 67, + "Intensity": 0.05142, + "Frequency": 16.5194 + }, + { + "Time": 83, + "Intensity": 0.026311, + "Frequency": 16.6157 + }, + { + "Time": 100, + "Intensity": 0.017077, + "Frequency": 17.2985 + }, + { + "Time": 117, + "Intensity": 0.017877, + "Frequency": 16.7269 + }, + { + "Time": 133, + "Intensity": 0.004579, + "Frequency": 18.9123 + }, + { + "Time": 150, + "Intensity": 0.015018, + "Frequency": 18.3264 + }, + { + "Time": 167, + "Intensity": 0.0063699, + "Frequency": 19.3763 + }, + { + "Time": 183, + "Intensity": 0.003663, + "Frequency": 19.3763 + }, + { + "Time": 200, + "Intensity": 0.0042855, + "Frequency": 3.7525 + }, + { + "Time": 217, + "Intensity": 0.0021302, + "Frequency": 3.847 + }, + { + "Time": 233, + "Intensity": 0.0078309, + "Frequency": 6.7964 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 7.1782 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1759, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 6.7964 + }, + { + "Time": 17, + "Intensity": 0.0035206, + "Frequency": 7.1782 + }, + { + "Time": 34, + "Intensity": 0.0011543, + "Frequency": 6.7993 + }, + { + "Time": 50, + "Intensity": 0.0022953, + "Frequency": 7.3322 + }, + { + "Time": 67, + "Intensity": 0.003826, + "Frequency": 12.0493 + }, + { + "Time": 84, + "Intensity": 0.0012973, + "Frequency": 16.6841 + }, + { + "Time": 100, + "Intensity": 0.0021943, + "Frequency": 20.0356 + }, + { + "Time": 117, + "Intensity": 0.0025446, + "Frequency": 17.6828 + }, + { + "Time": 134, + "Intensity": 0.0013369, + "Frequency": 13.7097 + }, + { + "Time": 150, + "Intensity": 0.00056959, + "Frequency": 7.8294 + }, + { + "Time": 167, + "Intensity": 0.00094861, + "Frequency": 0 + }, + { + "Time": 184, + "Intensity": 0.00058555, + "Frequency": 1 + }, + { + "Time": 200, + "Intensity": 0.00044257, + "Frequency": 3.5058 + }, + { + "Time": 217, + "Intensity": 0.00034451, + "Frequency": 3.5058 + }, + { + "Time": 234, + "Intensity": 0.00010188, + "Frequency": 6.3945 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 5.4841 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 75, + "StartTime": 1993, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 6.3945 + }, + { + "Time": 16, + "Intensity": 5.9868e-05, + "Frequency": 5.4841 + }, + { + "Time": 33, + "Intensity": 6.1123e-05, + "Frequency": 5.4841 + }, + { + "Time": 50, + "Intensity": 1.8783e-05, + "Frequency": 9.5255 + }, + { + "Time": 66, + "Intensity": 5.7126e-06, + "Frequency": 15.0855 + }, + { + "Time": 75, + "Intensity": 0, + "Frequency": 17.5105 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_l.json index dfdf7d5fc20de6a83a9065e889d33a0ce8976942..96410b5b05d2678e55fca3f18f469c1c0db9ee2e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_l.json @@ -1,654 +1,654 @@ -{ - "MetaData": { - "Create": "2021-10-18", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 126, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 69.313 - }, - { - "Time": 26, - "Intensity": 0.21, - "Frequency": 69.313 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 67.3027 - }, - { - "Time": 60, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 102, - "Intensity": 1, - "Frequency": 27 - }, - { - "Time": 144, - "Intensity": 1, - "Frequency": 27 - }, - { - "Time": 167, - "Intensity": 0.36219, - "Frequency": 47.0092 - }, - { - "Time": 200, - "Intensity": 0.82, - "Frequency": 8 - }, - { - "Time": 233, - "Intensity": 0.18445, - "Frequency": 47.9644 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 47.9644 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 359, - "Parameters": { - "Intensity": 60, - "Frequency": 48, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 47.9644 - }, - { - "Time": 11, - "Intensity": 0.75, - "Frequency": 26 - }, - { - "Time": 67, - "Intensity": 0.40413, - "Frequency": 46.0884 - }, - { - "Time": 143, - "Intensity": 0.27, - "Frequency": 26.5024 - }, - { - "Time": 212, - "Intensity": 0.51, - "Frequency": 21.0208 - }, - { - "Time": 234, - "Intensity": 0.29322, - "Frequency": 20.638 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 23.1938 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 593, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20.638 - }, - { - "Time": 6, - "Intensity": 0.34, - "Frequency": 23.1938 - }, - { - "Time": 34, - "Intensity": 0.61, - "Frequency": 23.1944 - }, - { - "Time": 50, - "Intensity": 0.21961, - "Frequency": 23.1944 - }, - { - "Time": 109, - "Intensity": 0.42, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 233, - "Intensity": 0.14725, - "Frequency": 17.5734 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.3638 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 826, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 17.5734 - }, - { - "Time": 33, - "Intensity": 0.34455, - "Frequency": 13.7928 - }, - { - "Time": 83, - "Intensity": 0.17566, - "Frequency": 13.2156 - }, - { - "Time": 99, - "Intensity": 0.47, - "Frequency": 13.8843 - }, - { - "Time": 150, - "Intensity": 0.099891, - "Frequency": 16.2494 - }, - { - "Time": 167, - "Intensity": 0.54439, - "Frequency": 16.251 - }, - { - "Time": 183, - "Intensity": 0.20715, - "Frequency": 14.4624 - }, - { - "Time": 217, - "Intensity": 0.083533, - "Frequency": 15.2237 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.4596 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1059, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 15.0306 - }, - { - "Time": 17, - "Intensity": 0.24137, - "Frequency": 14.4596 - }, - { - "Time": 34, - "Intensity": 0.27653, - "Frequency": 14.7438 - }, - { - "Time": 50, - "Intensity": 0.24485, - "Frequency": 19.939 - }, - { - "Time": 67, - "Intensity": 0.20559, - "Frequency": 20.5117 - }, - { - "Time": 84, - "Intensity": 0.11978, - "Frequency": 20.3226 - }, - { - "Time": 100, - "Intensity": 0.32286, - "Frequency": 18.1331 - }, - { - "Time": 117, - "Intensity": 0.21612, - "Frequency": 18.1331 - }, - { - "Time": 134, - "Intensity": 0.49264, - "Frequency": 21.2452 - }, - { - "Time": 150, - "Intensity": 0.18907, - "Frequency": 18.3376 - }, - { - "Time": 167, - "Intensity": 0.14537, - "Frequency": 17.9806 - }, - { - "Time": 184, - "Intensity": 0.26344, - "Frequency": 17.1246 - }, - { - "Time": 200, - "Intensity": 0.35007, - "Frequency": 17.7879 - }, - { - "Time": 217, - "Intensity": 0.14297, - "Frequency": 14.3585 - }, - { - "Time": 234, - "Intensity": 0.21184, - "Frequency": 16.9936 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 15.7556 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1293, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 16.9936 - }, - { - "Time": 16, - "Intensity": 0.2691, - "Frequency": 15.7556 - }, - { - "Time": 33, - "Intensity": 0.1914, - "Frequency": 16.9983 - }, - { - "Time": 50, - "Intensity": 0.14346, - "Frequency": 16.6456 - }, - { - "Time": 66, - "Intensity": 0.093315, - "Frequency": 17.6002 - }, - { - "Time": 83, - "Intensity": 0.13911, - "Frequency": 17.031 - }, - { - "Time": 100, - "Intensity": 0.071573, - "Frequency": 15.6997 - }, - { - "Time": 116, - "Intensity": 0.36325, - "Frequency": 14.6485 - }, - { - "Time": 133, - "Intensity": 0.10331, - "Frequency": 15.2189 - }, - { - "Time": 150, - "Intensity": 0.081988, - "Frequency": 15.2189 - }, - { - "Time": 166, - "Intensity": 0.074824, - "Frequency": 15.4095 - }, - { - "Time": 183, - "Intensity": 0.045809, - "Frequency": 14.5488 - }, - { - "Time": 200, - "Intensity": 0.033725, - "Frequency": 14.6454 - }, - { - "Time": 216, - "Intensity": 0.089506, - "Frequency": 14.2635 - }, - { - "Time": 233, - "Intensity": 0.066092, - "Frequency": 14.743 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.27 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1526, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 14.743 - }, - { - "Time": 17, - "Intensity": 0.085394, - "Frequency": 14.27 - }, - { - "Time": 33, - "Intensity": 0.029442, - "Frequency": 13.9832 - }, - { - "Time": 50, - "Intensity": 0.020521, - "Frequency": 16.1406 - }, - { - "Time": 67, - "Intensity": 0.05142, - "Frequency": 16.5194 - }, - { - "Time": 83, - "Intensity": 0.026311, - "Frequency": 16.6157 - }, - { - "Time": 100, - "Intensity": 0.017077, - "Frequency": 17.2985 - }, - { - "Time": 117, - "Intensity": 0.017877, - "Frequency": 16.7269 - }, - { - "Time": 133, - "Intensity": 0.004579, - "Frequency": 18.9123 - }, - { - "Time": 150, - "Intensity": 0.015018, - "Frequency": 18.3264 - }, - { - "Time": 167, - "Intensity": 0.0063699, - "Frequency": 19.3763 - }, - { - "Time": 183, - "Intensity": 0.003663, - "Frequency": 19.3763 - }, - { - "Time": 200, - "Intensity": 0.0042855, - "Frequency": 3.7525 - }, - { - "Time": 217, - "Intensity": 0.0021302, - "Frequency": 3.847 - }, - { - "Time": 233, - "Intensity": 0.0078309, - "Frequency": 6.7964 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 7.1782 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1759, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 6.7964 - }, - { - "Time": 17, - "Intensity": 0.0035206, - "Frequency": 7.1782 - }, - { - "Time": 34, - "Intensity": 0.0011543, - "Frequency": 6.7993 - }, - { - "Time": 50, - "Intensity": 0.0022953, - "Frequency": 7.3322 - }, - { - "Time": 67, - "Intensity": 0.003826, - "Frequency": 12.0493 - }, - { - "Time": 84, - "Intensity": 0.0012973, - "Frequency": 16.6841 - }, - { - "Time": 100, - "Intensity": 0.0021943, - "Frequency": 20.0356 - }, - { - "Time": 117, - "Intensity": 0.0025446, - "Frequency": 17.6828 - }, - { - "Time": 134, - "Intensity": 0.0013369, - "Frequency": 13.7097 - }, - { - "Time": 150, - "Intensity": 0.00056959, - "Frequency": 7.8294 - }, - { - "Time": 167, - "Intensity": 0.00094861, - "Frequency": 0 - }, - { - "Time": 184, - "Intensity": 0.00058555, - "Frequency": 1 - }, - { - "Time": 200, - "Intensity": 0.00044257, - "Frequency": 3.5058 - }, - { - "Time": 217, - "Intensity": 0.00034451, - "Frequency": 3.5058 - }, - { - "Time": 234, - "Intensity": 0.00010188, - "Frequency": 6.3945 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 5.4841 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 75, - "StartTime": 1993, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 6.3945 - }, - { - "Time": 16, - "Intensity": 5.9868e-05, - "Frequency": 5.4841 - }, - { - "Time": 33, - "Intensity": 6.1123e-05, - "Frequency": 5.4841 - }, - { - "Time": 50, - "Intensity": 1.8783e-05, - "Frequency": 9.5255 - }, - { - "Time": 66, - "Intensity": 5.7126e-06, - "Frequency": 15.0855 - }, - { - "Time": 75, - "Intensity": 0, - "Frequency": 17.5105 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-10-18", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 126, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 69.313 + }, + { + "Time": 26, + "Intensity": 0.21, + "Frequency": 69.313 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 67.3027 + }, + { + "Time": 60, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 102, + "Intensity": 1, + "Frequency": 27 + }, + { + "Time": 144, + "Intensity": 1, + "Frequency": 27 + }, + { + "Time": 167, + "Intensity": 0.36219, + "Frequency": 47.0092 + }, + { + "Time": 200, + "Intensity": 0.82, + "Frequency": 8 + }, + { + "Time": 233, + "Intensity": 0.18445, + "Frequency": 47.9644 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 47.9644 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 359, + "Parameters": { + "Intensity": 60, + "Frequency": 48, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 47.9644 + }, + { + "Time": 11, + "Intensity": 0.75, + "Frequency": 26 + }, + { + "Time": 67, + "Intensity": 0.40413, + "Frequency": 46.0884 + }, + { + "Time": 143, + "Intensity": 0.27, + "Frequency": 26.5024 + }, + { + "Time": 212, + "Intensity": 0.51, + "Frequency": 21.0208 + }, + { + "Time": 234, + "Intensity": 0.29322, + "Frequency": 20.638 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 23.1938 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 593, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20.638 + }, + { + "Time": 6, + "Intensity": 0.34, + "Frequency": 23.1938 + }, + { + "Time": 34, + "Intensity": 0.61, + "Frequency": 23.1944 + }, + { + "Time": 50, + "Intensity": 0.21961, + "Frequency": 23.1944 + }, + { + "Time": 109, + "Intensity": 0.42, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 233, + "Intensity": 0.14725, + "Frequency": 17.5734 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.3638 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 826, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 17.5734 + }, + { + "Time": 33, + "Intensity": 0.34455, + "Frequency": 13.7928 + }, + { + "Time": 83, + "Intensity": 0.17566, + "Frequency": 13.2156 + }, + { + "Time": 99, + "Intensity": 0.47, + "Frequency": 13.8843 + }, + { + "Time": 150, + "Intensity": 0.099891, + "Frequency": 16.2494 + }, + { + "Time": 167, + "Intensity": 0.54439, + "Frequency": 16.251 + }, + { + "Time": 183, + "Intensity": 0.20715, + "Frequency": 14.4624 + }, + { + "Time": 217, + "Intensity": 0.083533, + "Frequency": 15.2237 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.4596 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1059, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 15.0306 + }, + { + "Time": 17, + "Intensity": 0.24137, + "Frequency": 14.4596 + }, + { + "Time": 34, + "Intensity": 0.27653, + "Frequency": 14.7438 + }, + { + "Time": 50, + "Intensity": 0.24485, + "Frequency": 19.939 + }, + { + "Time": 67, + "Intensity": 0.20559, + "Frequency": 20.5117 + }, + { + "Time": 84, + "Intensity": 0.11978, + "Frequency": 20.3226 + }, + { + "Time": 100, + "Intensity": 0.32286, + "Frequency": 18.1331 + }, + { + "Time": 117, + "Intensity": 0.21612, + "Frequency": 18.1331 + }, + { + "Time": 134, + "Intensity": 0.49264, + "Frequency": 21.2452 + }, + { + "Time": 150, + "Intensity": 0.18907, + "Frequency": 18.3376 + }, + { + "Time": 167, + "Intensity": 0.14537, + "Frequency": 17.9806 + }, + { + "Time": 184, + "Intensity": 0.26344, + "Frequency": 17.1246 + }, + { + "Time": 200, + "Intensity": 0.35007, + "Frequency": 17.7879 + }, + { + "Time": 217, + "Intensity": 0.14297, + "Frequency": 14.3585 + }, + { + "Time": 234, + "Intensity": 0.21184, + "Frequency": 16.9936 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 15.7556 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1293, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 16.9936 + }, + { + "Time": 16, + "Intensity": 0.2691, + "Frequency": 15.7556 + }, + { + "Time": 33, + "Intensity": 0.1914, + "Frequency": 16.9983 + }, + { + "Time": 50, + "Intensity": 0.14346, + "Frequency": 16.6456 + }, + { + "Time": 66, + "Intensity": 0.093315, + "Frequency": 17.6002 + }, + { + "Time": 83, + "Intensity": 0.13911, + "Frequency": 17.031 + }, + { + "Time": 100, + "Intensity": 0.071573, + "Frequency": 15.6997 + }, + { + "Time": 116, + "Intensity": 0.36325, + "Frequency": 14.6485 + }, + { + "Time": 133, + "Intensity": 0.10331, + "Frequency": 15.2189 + }, + { + "Time": 150, + "Intensity": 0.081988, + "Frequency": 15.2189 + }, + { + "Time": 166, + "Intensity": 0.074824, + "Frequency": 15.4095 + }, + { + "Time": 183, + "Intensity": 0.045809, + "Frequency": 14.5488 + }, + { + "Time": 200, + "Intensity": 0.033725, + "Frequency": 14.6454 + }, + { + "Time": 216, + "Intensity": 0.089506, + "Frequency": 14.2635 + }, + { + "Time": 233, + "Intensity": 0.066092, + "Frequency": 14.743 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.27 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1526, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 14.743 + }, + { + "Time": 17, + "Intensity": 0.085394, + "Frequency": 14.27 + }, + { + "Time": 33, + "Intensity": 0.029442, + "Frequency": 13.9832 + }, + { + "Time": 50, + "Intensity": 0.020521, + "Frequency": 16.1406 + }, + { + "Time": 67, + "Intensity": 0.05142, + "Frequency": 16.5194 + }, + { + "Time": 83, + "Intensity": 0.026311, + "Frequency": 16.6157 + }, + { + "Time": 100, + "Intensity": 0.017077, + "Frequency": 17.2985 + }, + { + "Time": 117, + "Intensity": 0.017877, + "Frequency": 16.7269 + }, + { + "Time": 133, + "Intensity": 0.004579, + "Frequency": 18.9123 + }, + { + "Time": 150, + "Intensity": 0.015018, + "Frequency": 18.3264 + }, + { + "Time": 167, + "Intensity": 0.0063699, + "Frequency": 19.3763 + }, + { + "Time": 183, + "Intensity": 0.003663, + "Frequency": 19.3763 + }, + { + "Time": 200, + "Intensity": 0.0042855, + "Frequency": 3.7525 + }, + { + "Time": 217, + "Intensity": 0.0021302, + "Frequency": 3.847 + }, + { + "Time": 233, + "Intensity": 0.0078309, + "Frequency": 6.7964 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 7.1782 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1759, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 6.7964 + }, + { + "Time": 17, + "Intensity": 0.0035206, + "Frequency": 7.1782 + }, + { + "Time": 34, + "Intensity": 0.0011543, + "Frequency": 6.7993 + }, + { + "Time": 50, + "Intensity": 0.0022953, + "Frequency": 7.3322 + }, + { + "Time": 67, + "Intensity": 0.003826, + "Frequency": 12.0493 + }, + { + "Time": 84, + "Intensity": 0.0012973, + "Frequency": 16.6841 + }, + { + "Time": 100, + "Intensity": 0.0021943, + "Frequency": 20.0356 + }, + { + "Time": 117, + "Intensity": 0.0025446, + "Frequency": 17.6828 + }, + { + "Time": 134, + "Intensity": 0.0013369, + "Frequency": 13.7097 + }, + { + "Time": 150, + "Intensity": 0.00056959, + "Frequency": 7.8294 + }, + { + "Time": 167, + "Intensity": 0.00094861, + "Frequency": 0 + }, + { + "Time": 184, + "Intensity": 0.00058555, + "Frequency": 1 + }, + { + "Time": 200, + "Intensity": 0.00044257, + "Frequency": 3.5058 + }, + { + "Time": 217, + "Intensity": 0.00034451, + "Frequency": 3.5058 + }, + { + "Time": 234, + "Intensity": 0.00010188, + "Frequency": 6.3945 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 5.4841 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 75, + "StartTime": 1993, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 6.3945 + }, + { + "Time": 16, + "Intensity": 5.9868e-05, + "Frequency": 5.4841 + }, + { + "Time": 33, + "Intensity": 6.1123e-05, + "Frequency": 5.4841 + }, + { + "Time": 50, + "Intensity": 1.8783e-05, + "Frequency": 9.5255 + }, + { + "Time": 66, + "Intensity": 5.7126e-06, + "Frequency": 15.0855 + }, + { + "Time": 75, + "Intensity": 0, + "Frequency": 17.5105 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_m.json index 19d73876bd9bcf741bff78a9d5eca4dc4da7e68d..f6a274394a6ce5ea9c753d699f61d77abcd53f29 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Bomb_m.json @@ -1,654 +1,654 @@ -{ - "MetaData": { - "Create": "2021-10-18", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 126, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 69.313 - }, - { - "Time": 26, - "Intensity": 0.21, - "Frequency": 69.313 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 67.3027 - }, - { - "Time": 60, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 102, - "Intensity": 1, - "Frequency": 27 - }, - { - "Time": 144, - "Intensity": 1, - "Frequency": 27 - }, - { - "Time": 167, - "Intensity": 0.36219, - "Frequency": 47.0092 - }, - { - "Time": 200, - "Intensity": 0.82, - "Frequency": 8 - }, - { - "Time": 233, - "Intensity": 0.18445, - "Frequency": 47.9644 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 47.9644 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 359, - "Parameters": { - "Intensity": 80, - "Frequency": 48, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 47.9644 - }, - { - "Time": 11, - "Intensity": 0.75, - "Frequency": 26 - }, - { - "Time": 67, - "Intensity": 0.40413, - "Frequency": 46.0884 - }, - { - "Time": 143, - "Intensity": 0.27, - "Frequency": 26.5024 - }, - { - "Time": 212, - "Intensity": 0.51, - "Frequency": 21.0208 - }, - { - "Time": 234, - "Intensity": 0.29322, - "Frequency": 20.638 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 23.1938 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 593, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20.638 - }, - { - "Time": 6, - "Intensity": 0.34, - "Frequency": 23.1938 - }, - { - "Time": 34, - "Intensity": 0.61, - "Frequency": 23.1944 - }, - { - "Time": 50, - "Intensity": 0.21961, - "Frequency": 23.1944 - }, - { - "Time": 109, - "Intensity": 0.42, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 233, - "Intensity": 0.14725, - "Frequency": 17.5734 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.3638 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 826, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 17.5734 - }, - { - "Time": 33, - "Intensity": 0.34455, - "Frequency": 13.7928 - }, - { - "Time": 83, - "Intensity": 0.17566, - "Frequency": 13.2156 - }, - { - "Time": 99, - "Intensity": 0.47, - "Frequency": 13.8843 - }, - { - "Time": 150, - "Intensity": 0.099891, - "Frequency": 16.2494 - }, - { - "Time": 167, - "Intensity": 0.54439, - "Frequency": 16.251 - }, - { - "Time": 183, - "Intensity": 0.20715, - "Frequency": 14.4624 - }, - { - "Time": 217, - "Intensity": 0.083533, - "Frequency": 15.2237 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.4596 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1059, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 15.0306 - }, - { - "Time": 17, - "Intensity": 0.24137, - "Frequency": 14.4596 - }, - { - "Time": 34, - "Intensity": 0.27653, - "Frequency": 14.7438 - }, - { - "Time": 50, - "Intensity": 0.24485, - "Frequency": 19.939 - }, - { - "Time": 67, - "Intensity": 0.20559, - "Frequency": 20.5117 - }, - { - "Time": 84, - "Intensity": 0.11978, - "Frequency": 20.3226 - }, - { - "Time": 100, - "Intensity": 0.32286, - "Frequency": 18.1331 - }, - { - "Time": 117, - "Intensity": 0.21612, - "Frequency": 18.1331 - }, - { - "Time": 134, - "Intensity": 0.49264, - "Frequency": 21.2452 - }, - { - "Time": 150, - "Intensity": 0.18907, - "Frequency": 18.3376 - }, - { - "Time": 167, - "Intensity": 0.14537, - "Frequency": 17.9806 - }, - { - "Time": 184, - "Intensity": 0.26344, - "Frequency": 17.1246 - }, - { - "Time": 200, - "Intensity": 0.35007, - "Frequency": 17.7879 - }, - { - "Time": 217, - "Intensity": 0.14297, - "Frequency": 14.3585 - }, - { - "Time": 234, - "Intensity": 0.21184, - "Frequency": 16.9936 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 15.7556 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1293, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 16.9936 - }, - { - "Time": 16, - "Intensity": 0.2691, - "Frequency": 15.7556 - }, - { - "Time": 33, - "Intensity": 0.1914, - "Frequency": 16.9983 - }, - { - "Time": 50, - "Intensity": 0.14346, - "Frequency": 16.6456 - }, - { - "Time": 66, - "Intensity": 0.093315, - "Frequency": 17.6002 - }, - { - "Time": 83, - "Intensity": 0.13911, - "Frequency": 17.031 - }, - { - "Time": 100, - "Intensity": 0.071573, - "Frequency": 15.6997 - }, - { - "Time": 116, - "Intensity": 0.36325, - "Frequency": 14.6485 - }, - { - "Time": 133, - "Intensity": 0.10331, - "Frequency": 15.2189 - }, - { - "Time": 150, - "Intensity": 0.081988, - "Frequency": 15.2189 - }, - { - "Time": 166, - "Intensity": 0.074824, - "Frequency": 15.4095 - }, - { - "Time": 183, - "Intensity": 0.045809, - "Frequency": 14.5488 - }, - { - "Time": 200, - "Intensity": 0.033725, - "Frequency": 14.6454 - }, - { - "Time": 216, - "Intensity": 0.089506, - "Frequency": 14.2635 - }, - { - "Time": 233, - "Intensity": 0.066092, - "Frequency": 14.743 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 14.27 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1526, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 14.743 - }, - { - "Time": 17, - "Intensity": 0.085394, - "Frequency": 14.27 - }, - { - "Time": 33, - "Intensity": 0.029442, - "Frequency": 13.9832 - }, - { - "Time": 50, - "Intensity": 0.020521, - "Frequency": 16.1406 - }, - { - "Time": 67, - "Intensity": 0.05142, - "Frequency": 16.5194 - }, - { - "Time": 83, - "Intensity": 0.026311, - "Frequency": 16.6157 - }, - { - "Time": 100, - "Intensity": 0.017077, - "Frequency": 17.2985 - }, - { - "Time": 117, - "Intensity": 0.017877, - "Frequency": 16.7269 - }, - { - "Time": 133, - "Intensity": 0.004579, - "Frequency": 18.9123 - }, - { - "Time": 150, - "Intensity": 0.015018, - "Frequency": 18.3264 - }, - { - "Time": 167, - "Intensity": 0.0063699, - "Frequency": 19.3763 - }, - { - "Time": 183, - "Intensity": 0.003663, - "Frequency": 19.3763 - }, - { - "Time": 200, - "Intensity": 0.0042855, - "Frequency": 3.7525 - }, - { - "Time": 217, - "Intensity": 0.0021302, - "Frequency": 3.847 - }, - { - "Time": 233, - "Intensity": 0.0078309, - "Frequency": 6.7964 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 7.1782 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1759, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 6.7964 - }, - { - "Time": 17, - "Intensity": 0.0035206, - "Frequency": 7.1782 - }, - { - "Time": 34, - "Intensity": 0.0011543, - "Frequency": 6.7993 - }, - { - "Time": 50, - "Intensity": 0.0022953, - "Frequency": 7.3322 - }, - { - "Time": 67, - "Intensity": 0.003826, - "Frequency": 12.0493 - }, - { - "Time": 84, - "Intensity": 0.0012973, - "Frequency": 16.6841 - }, - { - "Time": 100, - "Intensity": 0.0021943, - "Frequency": 20.0356 - }, - { - "Time": 117, - "Intensity": 0.0025446, - "Frequency": 17.6828 - }, - { - "Time": 134, - "Intensity": 0.0013369, - "Frequency": 13.7097 - }, - { - "Time": 150, - "Intensity": 0.00056959, - "Frequency": 7.8294 - }, - { - "Time": 167, - "Intensity": 0.00094861, - "Frequency": 0 - }, - { - "Time": 184, - "Intensity": 0.00058555, - "Frequency": 1 - }, - { - "Time": 200, - "Intensity": 0.00044257, - "Frequency": 3.5058 - }, - { - "Time": 217, - "Intensity": 0.00034451, - "Frequency": 3.5058 - }, - { - "Time": 234, - "Intensity": 0.00010188, - "Frequency": 6.3945 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 5.4841 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 75, - "StartTime": 1993, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 6.3945 - }, - { - "Time": 16, - "Intensity": 5.9868e-05, - "Frequency": 5.4841 - }, - { - "Time": 33, - "Intensity": 6.1123e-05, - "Frequency": 5.4841 - }, - { - "Time": 50, - "Intensity": 1.8783e-05, - "Frequency": 9.5255 - }, - { - "Time": 66, - "Intensity": 5.7126e-06, - "Frequency": 15.0855 - }, - { - "Time": 75, - "Intensity": 0, - "Frequency": 17.5105 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-10-18", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 126, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 69.313 + }, + { + "Time": 26, + "Intensity": 0.21, + "Frequency": 69.313 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 67.3027 + }, + { + "Time": 60, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 102, + "Intensity": 1, + "Frequency": 27 + }, + { + "Time": 144, + "Intensity": 1, + "Frequency": 27 + }, + { + "Time": 167, + "Intensity": 0.36219, + "Frequency": 47.0092 + }, + { + "Time": 200, + "Intensity": 0.82, + "Frequency": 8 + }, + { + "Time": 233, + "Intensity": 0.18445, + "Frequency": 47.9644 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 47.9644 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 359, + "Parameters": { + "Intensity": 80, + "Frequency": 48, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 47.9644 + }, + { + "Time": 11, + "Intensity": 0.75, + "Frequency": 26 + }, + { + "Time": 67, + "Intensity": 0.40413, + "Frequency": 46.0884 + }, + { + "Time": 143, + "Intensity": 0.27, + "Frequency": 26.5024 + }, + { + "Time": 212, + "Intensity": 0.51, + "Frequency": 21.0208 + }, + { + "Time": 234, + "Intensity": 0.29322, + "Frequency": 20.638 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 23.1938 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 593, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20.638 + }, + { + "Time": 6, + "Intensity": 0.34, + "Frequency": 23.1938 + }, + { + "Time": 34, + "Intensity": 0.61, + "Frequency": 23.1944 + }, + { + "Time": 50, + "Intensity": 0.21961, + "Frequency": 23.1944 + }, + { + "Time": 109, + "Intensity": 0.42, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 233, + "Intensity": 0.14725, + "Frequency": 17.5734 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.3638 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 826, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 17.5734 + }, + { + "Time": 33, + "Intensity": 0.34455, + "Frequency": 13.7928 + }, + { + "Time": 83, + "Intensity": 0.17566, + "Frequency": 13.2156 + }, + { + "Time": 99, + "Intensity": 0.47, + "Frequency": 13.8843 + }, + { + "Time": 150, + "Intensity": 0.099891, + "Frequency": 16.2494 + }, + { + "Time": 167, + "Intensity": 0.54439, + "Frequency": 16.251 + }, + { + "Time": 183, + "Intensity": 0.20715, + "Frequency": 14.4624 + }, + { + "Time": 217, + "Intensity": 0.083533, + "Frequency": 15.2237 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.4596 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1059, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 15.0306 + }, + { + "Time": 17, + "Intensity": 0.24137, + "Frequency": 14.4596 + }, + { + "Time": 34, + "Intensity": 0.27653, + "Frequency": 14.7438 + }, + { + "Time": 50, + "Intensity": 0.24485, + "Frequency": 19.939 + }, + { + "Time": 67, + "Intensity": 0.20559, + "Frequency": 20.5117 + }, + { + "Time": 84, + "Intensity": 0.11978, + "Frequency": 20.3226 + }, + { + "Time": 100, + "Intensity": 0.32286, + "Frequency": 18.1331 + }, + { + "Time": 117, + "Intensity": 0.21612, + "Frequency": 18.1331 + }, + { + "Time": 134, + "Intensity": 0.49264, + "Frequency": 21.2452 + }, + { + "Time": 150, + "Intensity": 0.18907, + "Frequency": 18.3376 + }, + { + "Time": 167, + "Intensity": 0.14537, + "Frequency": 17.9806 + }, + { + "Time": 184, + "Intensity": 0.26344, + "Frequency": 17.1246 + }, + { + "Time": 200, + "Intensity": 0.35007, + "Frequency": 17.7879 + }, + { + "Time": 217, + "Intensity": 0.14297, + "Frequency": 14.3585 + }, + { + "Time": 234, + "Intensity": 0.21184, + "Frequency": 16.9936 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 15.7556 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1293, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 16.9936 + }, + { + "Time": 16, + "Intensity": 0.2691, + "Frequency": 15.7556 + }, + { + "Time": 33, + "Intensity": 0.1914, + "Frequency": 16.9983 + }, + { + "Time": 50, + "Intensity": 0.14346, + "Frequency": 16.6456 + }, + { + "Time": 66, + "Intensity": 0.093315, + "Frequency": 17.6002 + }, + { + "Time": 83, + "Intensity": 0.13911, + "Frequency": 17.031 + }, + { + "Time": 100, + "Intensity": 0.071573, + "Frequency": 15.6997 + }, + { + "Time": 116, + "Intensity": 0.36325, + "Frequency": 14.6485 + }, + { + "Time": 133, + "Intensity": 0.10331, + "Frequency": 15.2189 + }, + { + "Time": 150, + "Intensity": 0.081988, + "Frequency": 15.2189 + }, + { + "Time": 166, + "Intensity": 0.074824, + "Frequency": 15.4095 + }, + { + "Time": 183, + "Intensity": 0.045809, + "Frequency": 14.5488 + }, + { + "Time": 200, + "Intensity": 0.033725, + "Frequency": 14.6454 + }, + { + "Time": 216, + "Intensity": 0.089506, + "Frequency": 14.2635 + }, + { + "Time": 233, + "Intensity": 0.066092, + "Frequency": 14.743 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 14.27 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1526, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 14.743 + }, + { + "Time": 17, + "Intensity": 0.085394, + "Frequency": 14.27 + }, + { + "Time": 33, + "Intensity": 0.029442, + "Frequency": 13.9832 + }, + { + "Time": 50, + "Intensity": 0.020521, + "Frequency": 16.1406 + }, + { + "Time": 67, + "Intensity": 0.05142, + "Frequency": 16.5194 + }, + { + "Time": 83, + "Intensity": 0.026311, + "Frequency": 16.6157 + }, + { + "Time": 100, + "Intensity": 0.017077, + "Frequency": 17.2985 + }, + { + "Time": 117, + "Intensity": 0.017877, + "Frequency": 16.7269 + }, + { + "Time": 133, + "Intensity": 0.004579, + "Frequency": 18.9123 + }, + { + "Time": 150, + "Intensity": 0.015018, + "Frequency": 18.3264 + }, + { + "Time": 167, + "Intensity": 0.0063699, + "Frequency": 19.3763 + }, + { + "Time": 183, + "Intensity": 0.003663, + "Frequency": 19.3763 + }, + { + "Time": 200, + "Intensity": 0.0042855, + "Frequency": 3.7525 + }, + { + "Time": 217, + "Intensity": 0.0021302, + "Frequency": 3.847 + }, + { + "Time": 233, + "Intensity": 0.0078309, + "Frequency": 6.7964 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 7.1782 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1759, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 6.7964 + }, + { + "Time": 17, + "Intensity": 0.0035206, + "Frequency": 7.1782 + }, + { + "Time": 34, + "Intensity": 0.0011543, + "Frequency": 6.7993 + }, + { + "Time": 50, + "Intensity": 0.0022953, + "Frequency": 7.3322 + }, + { + "Time": 67, + "Intensity": 0.003826, + "Frequency": 12.0493 + }, + { + "Time": 84, + "Intensity": 0.0012973, + "Frequency": 16.6841 + }, + { + "Time": 100, + "Intensity": 0.0021943, + "Frequency": 20.0356 + }, + { + "Time": 117, + "Intensity": 0.0025446, + "Frequency": 17.6828 + }, + { + "Time": 134, + "Intensity": 0.0013369, + "Frequency": 13.7097 + }, + { + "Time": 150, + "Intensity": 0.00056959, + "Frequency": 7.8294 + }, + { + "Time": 167, + "Intensity": 0.00094861, + "Frequency": 0 + }, + { + "Time": 184, + "Intensity": 0.00058555, + "Frequency": 1 + }, + { + "Time": 200, + "Intensity": 0.00044257, + "Frequency": 3.5058 + }, + { + "Time": 217, + "Intensity": 0.00034451, + "Frequency": 3.5058 + }, + { + "Time": 234, + "Intensity": 0.00010188, + "Frequency": 6.3945 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 5.4841 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 75, + "StartTime": 1993, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 6.3945 + }, + { + "Time": 16, + "Intensity": 5.9868e-05, + "Frequency": 5.4841 + }, + { + "Time": 33, + "Intensity": 6.1123e-05, + "Frequency": 5.4841 + }, + { + "Time": 50, + "Intensity": 1.8783e-05, + "Frequency": 9.5255 + }, + { + "Time": 66, + "Intensity": 5.7126e-06, + "Frequency": 15.0855 + }, + { + "Time": 75, + "Intensity": 0, + "Frequency": 17.5105 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_h.json index 2ce24203653378f4fc84818b8ddd483df5a4c99f..82d3749bc6c7c6bfaf290d360ef0a8e8a6ae5c7a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_h.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 107, - "Parameters": { - "Intensity": 80, - "Frequency": 21 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 161, - "Parameters": { - "Intensity": 100, - "Frequency": 21 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 107, + "Parameters": { + "Intensity": 80, + "Frequency": 21 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 161, + "Parameters": { + "Intensity": 100, + "Frequency": 21 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_l.json index c3ffde424b141c04eeb7df44180c210f1360b98c..53a5b90bbddffb21517c970ba79826143206e3a9 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_l.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 107, - "Parameters": { - "Intensity": 48, - "Frequency": 21 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 161, - "Parameters": { - "Intensity": 60, - "Frequency": 21 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 107, + "Parameters": { + "Intensity": 48, + "Frequency": 21 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 161, + "Parameters": { + "Intensity": 60, + "Frequency": 21 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_m.json index d3b8469f6f3335aa41f91cbc63d7abcbff8da372..f8c61f7cace437cb92b087b0262b2b2696b9aa8f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CZ75_m.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 107, - "Parameters": { - "Intensity": 64, - "Frequency": 21 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 161, - "Parameters": { - "Intensity": 80, - "Frequency": 21 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 107, + "Parameters": { + "Intensity": 64, + "Frequency": 21 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 161, + "Parameters": { + "Intensity": 80, + "Frequency": 21 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_h.json index 90bb9156c8d1126aa87965c689663ed0a0a9cf58..a085857ffa0976aa705fa59a610d674df84038b4 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_h.json @@ -1,278 +1,278 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 923, - "StartTime": 20, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 95, - "Intensity": 0.72, - "Frequency": -15 - }, - { - "Time": 497, - "Intensity": 0.57, - "Frequency": -50 - }, - { - "Time": 782, - "Intensity": 0.77, - "Frequency": -15 - }, - { - "Time": 923, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 185, - "Parameters": { - "Intensity": 46, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 720, - "Parameters": { - "Intensity": 37, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 908, - "Parameters": { - "Intensity": 41, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 3785, - "StartTime": 965, - "Parameters": { - "Intensity": 55, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 204, - "Intensity": 0.64, - "Frequency": -15 - }, - { - "Time": 473, - "Intensity": 0.77, - "Frequency": -50 - }, - { - "Time": 628, - "Intensity": 0.88, - "Frequency": -15 - }, - { - "Time": 946, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 1347, - "Intensity": 0.68, - "Frequency": -15 - }, - { - "Time": 1631, - "Intensity": 0.83, - "Frequency": -50 - }, - { - "Time": 1896, - "Intensity": 0.7, - "Frequency": -15 - }, - { - "Time": 2275, - "Intensity": 0.45, - "Frequency": -50 - }, - { - "Time": 2737, - "Intensity": 0.77, - "Frequency": -15 - }, - { - "Time": 3115, - "Intensity": 0.75, - "Frequency": -50 - }, - { - "Time": 3312, - "Intensity": 0.87, - "Frequency": -15 - }, - { - "Time": 3759, - "Intensity": 0.75, - "Frequency": -15 - }, - { - "Time": 3785, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1008, - "Parameters": { - "Intensity": 59, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1447, - "Parameters": { - "Intensity": 37, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1610, - "Parameters": { - "Intensity": 52, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2105, - "Parameters": { - "Intensity": 45, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2175, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2660, - "Parameters": { - "Intensity": 47, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2993, - "Parameters": { - "Intensity": 64, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3072, - "Parameters": { - "Intensity": 90, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3390, - "Parameters": { - "Intensity": 41, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3960, - "Parameters": { - "Intensity": 50, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4220, - "Parameters": { - "Intensity": 41, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 923, + "StartTime": 20, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 95, + "Intensity": 0.72, + "Frequency": -15 + }, + { + "Time": 497, + "Intensity": 0.57, + "Frequency": -50 + }, + { + "Time": 782, + "Intensity": 0.77, + "Frequency": -15 + }, + { + "Time": 923, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 185, + "Parameters": { + "Intensity": 46, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 720, + "Parameters": { + "Intensity": 37, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 908, + "Parameters": { + "Intensity": 41, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 3785, + "StartTime": 965, + "Parameters": { + "Intensity": 55, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 204, + "Intensity": 0.64, + "Frequency": -15 + }, + { + "Time": 473, + "Intensity": 0.77, + "Frequency": -50 + }, + { + "Time": 628, + "Intensity": 0.88, + "Frequency": -15 + }, + { + "Time": 946, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 1347, + "Intensity": 0.68, + "Frequency": -15 + }, + { + "Time": 1631, + "Intensity": 0.83, + "Frequency": -50 + }, + { + "Time": 1896, + "Intensity": 0.7, + "Frequency": -15 + }, + { + "Time": 2275, + "Intensity": 0.45, + "Frequency": -50 + }, + { + "Time": 2737, + "Intensity": 0.77, + "Frequency": -15 + }, + { + "Time": 3115, + "Intensity": 0.75, + "Frequency": -50 + }, + { + "Time": 3312, + "Intensity": 0.87, + "Frequency": -15 + }, + { + "Time": 3759, + "Intensity": 0.75, + "Frequency": -15 + }, + { + "Time": 3785, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1008, + "Parameters": { + "Intensity": 59, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1447, + "Parameters": { + "Intensity": 37, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1610, + "Parameters": { + "Intensity": 52, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2105, + "Parameters": { + "Intensity": 45, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2175, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2660, + "Parameters": { + "Intensity": 47, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2993, + "Parameters": { + "Intensity": 64, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3072, + "Parameters": { + "Intensity": 90, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3390, + "Parameters": { + "Intensity": 41, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3960, + "Parameters": { + "Intensity": 50, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4220, + "Parameters": { + "Intensity": 41, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_l.json index 5e6b258e3ed361ad5bbc5787ef4911055bda89a8..38d31c8e92383282b85611e694d5ec112d33ad1f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_l.json @@ -1,278 +1,278 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 923, - "StartTime": 20, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 95, - "Intensity": 0.72, - "Frequency": -15 - }, - { - "Time": 497, - "Intensity": 0.57, - "Frequency": -50 - }, - { - "Time": 782, - "Intensity": 0.77, - "Frequency": -15 - }, - { - "Time": 923, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 185, - "Parameters": { - "Intensity": 27, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 720, - "Parameters": { - "Intensity": 22, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 908, - "Parameters": { - "Intensity": 24, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 3785, - "StartTime": 965, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 204, - "Intensity": 0.64, - "Frequency": -15 - }, - { - "Time": 473, - "Intensity": 0.77, - "Frequency": -50 - }, - { - "Time": 628, - "Intensity": 0.88, - "Frequency": -15 - }, - { - "Time": 946, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 1347, - "Intensity": 0.68, - "Frequency": -15 - }, - { - "Time": 1631, - "Intensity": 0.83, - "Frequency": -50 - }, - { - "Time": 1896, - "Intensity": 0.7, - "Frequency": -15 - }, - { - "Time": 2275, - "Intensity": 0.45, - "Frequency": -50 - }, - { - "Time": 2737, - "Intensity": 0.77, - "Frequency": -15 - }, - { - "Time": 3115, - "Intensity": 0.75, - "Frequency": -50 - }, - { - "Time": 3312, - "Intensity": 0.87, - "Frequency": -15 - }, - { - "Time": 3759, - "Intensity": 0.75, - "Frequency": -15 - }, - { - "Time": 3785, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1008, - "Parameters": { - "Intensity": 35, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1447, - "Parameters": { - "Intensity": 22, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1610, - "Parameters": { - "Intensity": 31, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2105, - "Parameters": { - "Intensity": 27, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2175, - "Parameters": { - "Intensity": 36, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2660, - "Parameters": { - "Intensity": 28, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2993, - "Parameters": { - "Intensity": 38, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3072, - "Parameters": { - "Intensity": 54, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3390, - "Parameters": { - "Intensity": 24, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3960, - "Parameters": { - "Intensity": 30, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4220, - "Parameters": { - "Intensity": 24, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 923, + "StartTime": 20, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 95, + "Intensity": 0.72, + "Frequency": -15 + }, + { + "Time": 497, + "Intensity": 0.57, + "Frequency": -50 + }, + { + "Time": 782, + "Intensity": 0.77, + "Frequency": -15 + }, + { + "Time": 923, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 185, + "Parameters": { + "Intensity": 27, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 720, + "Parameters": { + "Intensity": 22, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 908, + "Parameters": { + "Intensity": 24, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 3785, + "StartTime": 965, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 204, + "Intensity": 0.64, + "Frequency": -15 + }, + { + "Time": 473, + "Intensity": 0.77, + "Frequency": -50 + }, + { + "Time": 628, + "Intensity": 0.88, + "Frequency": -15 + }, + { + "Time": 946, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 1347, + "Intensity": 0.68, + "Frequency": -15 + }, + { + "Time": 1631, + "Intensity": 0.83, + "Frequency": -50 + }, + { + "Time": 1896, + "Intensity": 0.7, + "Frequency": -15 + }, + { + "Time": 2275, + "Intensity": 0.45, + "Frequency": -50 + }, + { + "Time": 2737, + "Intensity": 0.77, + "Frequency": -15 + }, + { + "Time": 3115, + "Intensity": 0.75, + "Frequency": -50 + }, + { + "Time": 3312, + "Intensity": 0.87, + "Frequency": -15 + }, + { + "Time": 3759, + "Intensity": 0.75, + "Frequency": -15 + }, + { + "Time": 3785, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1008, + "Parameters": { + "Intensity": 35, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1447, + "Parameters": { + "Intensity": 22, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1610, + "Parameters": { + "Intensity": 31, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2105, + "Parameters": { + "Intensity": 27, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2175, + "Parameters": { + "Intensity": 36, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2660, + "Parameters": { + "Intensity": 28, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2993, + "Parameters": { + "Intensity": 38, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3072, + "Parameters": { + "Intensity": 54, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3390, + "Parameters": { + "Intensity": 24, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3960, + "Parameters": { + "Intensity": 30, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4220, + "Parameters": { + "Intensity": 24, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_m.json index 74a91481c3c7b6b4b50dbfd22ed06a469fc3995a..4a31f6f6423ee5bed299a30904117d1082f382bc 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Campfire_m.json @@ -1,278 +1,278 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 923, - "StartTime": 20, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 95, - "Intensity": 0.72, - "Frequency": -15 - }, - { - "Time": 497, - "Intensity": 0.57, - "Frequency": -50 - }, - { - "Time": 782, - "Intensity": 0.77, - "Frequency": -15 - }, - { - "Time": 923, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 185, - "Parameters": { - "Intensity": 36, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 720, - "Parameters": { - "Intensity": 29, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 908, - "Parameters": { - "Intensity": 32, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 3785, - "StartTime": 965, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 204, - "Intensity": 0.64, - "Frequency": -15 - }, - { - "Time": 473, - "Intensity": 0.77, - "Frequency": -50 - }, - { - "Time": 628, - "Intensity": 0.88, - "Frequency": -15 - }, - { - "Time": 946, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 1347, - "Intensity": 0.68, - "Frequency": -15 - }, - { - "Time": 1631, - "Intensity": 0.83, - "Frequency": -50 - }, - { - "Time": 1896, - "Intensity": 0.7, - "Frequency": -15 - }, - { - "Time": 2275, - "Intensity": 0.45, - "Frequency": -50 - }, - { - "Time": 2737, - "Intensity": 0.77, - "Frequency": -15 - }, - { - "Time": 3115, - "Intensity": 0.75, - "Frequency": -50 - }, - { - "Time": 3312, - "Intensity": 0.87, - "Frequency": -15 - }, - { - "Time": 3759, - "Intensity": 0.75, - "Frequency": -15 - }, - { - "Time": 3785, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1008, - "Parameters": { - "Intensity": 47, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1447, - "Parameters": { - "Intensity": 29, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1610, - "Parameters": { - "Intensity": 41, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2105, - "Parameters": { - "Intensity": 36, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2175, - "Parameters": { - "Intensity": 48, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2660, - "Parameters": { - "Intensity": 37, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2993, - "Parameters": { - "Intensity": 51, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3072, - "Parameters": { - "Intensity": 72, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3390, - "Parameters": { - "Intensity": 32, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3960, - "Parameters": { - "Intensity": 40, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4220, - "Parameters": { - "Intensity": 32, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 923, + "StartTime": 20, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 95, + "Intensity": 0.72, + "Frequency": -15 + }, + { + "Time": 497, + "Intensity": 0.57, + "Frequency": -50 + }, + { + "Time": 782, + "Intensity": 0.77, + "Frequency": -15 + }, + { + "Time": 923, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 185, + "Parameters": { + "Intensity": 36, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 720, + "Parameters": { + "Intensity": 29, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 908, + "Parameters": { + "Intensity": 32, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 3785, + "StartTime": 965, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 204, + "Intensity": 0.64, + "Frequency": -15 + }, + { + "Time": 473, + "Intensity": 0.77, + "Frequency": -50 + }, + { + "Time": 628, + "Intensity": 0.88, + "Frequency": -15 + }, + { + "Time": 946, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 1347, + "Intensity": 0.68, + "Frequency": -15 + }, + { + "Time": 1631, + "Intensity": 0.83, + "Frequency": -50 + }, + { + "Time": 1896, + "Intensity": 0.7, + "Frequency": -15 + }, + { + "Time": 2275, + "Intensity": 0.45, + "Frequency": -50 + }, + { + "Time": 2737, + "Intensity": 0.77, + "Frequency": -15 + }, + { + "Time": 3115, + "Intensity": 0.75, + "Frequency": -50 + }, + { + "Time": 3312, + "Intensity": 0.87, + "Frequency": -15 + }, + { + "Time": 3759, + "Intensity": 0.75, + "Frequency": -15 + }, + { + "Time": 3785, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1008, + "Parameters": { + "Intensity": 47, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1447, + "Parameters": { + "Intensity": 29, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1610, + "Parameters": { + "Intensity": 41, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2105, + "Parameters": { + "Intensity": 36, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2175, + "Parameters": { + "Intensity": 48, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2660, + "Parameters": { + "Intensity": 37, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2993, + "Parameters": { + "Intensity": 51, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3072, + "Parameters": { + "Intensity": 72, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3390, + "Parameters": { + "Intensity": 32, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3960, + "Parameters": { + "Intensity": 40, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4220, + "Parameters": { + "Intensity": 32, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_h.json index 3554aac99d6a96c108de3ed8598dbd0e65f25850..c8cb0d0d34c9932b9522f9601215ea9dcb117fb1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_h.json @@ -1,532 +1,532 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2, - "Parameters": { - "Intensity": 100, - "Frequency": 10, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37 - }, - { - "Time": 30, - "Intensity": 0.08, - "Frequency": 45 - }, - { - "Time": 47, - "Intensity": 0.14, - "Frequency": 47 - }, - { - "Time": 58, - "Intensity": 0.23, - "Frequency": 48 - }, - { - "Time": 75, - "Intensity": 0.52, - "Frequency": 46 - }, - { - "Time": 89, - "Intensity": 0.93, - "Frequency": 48 - }, - { - "Time": 99, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 124, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 1, - "Frequency": 52 - }, - { - "Time": 150, - "Intensity": 0.84, - "Frequency": 54 - }, - { - "Time": 166, - "Intensity": 0.72, - "Frequency": 52 - }, - { - "Time": 183, - "Intensity": 0.59, - "Frequency": 50 - }, - { - "Time": 200, - "Intensity": 0.54, - "Frequency": 49 - }, - { - "Time": 217, - "Intensity": 0.32, - "Frequency": 50 - }, - { - "Time": 233, - "Intensity": 0.34, - "Frequency": 50 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 22 - }, - { - "Time": 30, - "Intensity": 0.08, - "Frequency": 39 - }, - { - "Time": 47, - "Intensity": 0.14, - "Frequency": 36 - }, - { - "Time": 60, - "Intensity": 0.24, - "Frequency": 38 - }, - { - "Time": 75, - "Intensity": 0.52, - "Frequency": 39 - }, - { - "Time": 89, - "Intensity": 0.93, - "Frequency": 42 - }, - { - "Time": 99, - "Intensity": 1, - "Frequency": 39 - }, - { - "Time": 124, - "Intensity": 1, - "Frequency": 40 - }, - { - "Time": 138, - "Intensity": 1, - "Frequency": 42 - }, - { - "Time": 150, - "Intensity": 0.84, - "Frequency": 44 - }, - { - "Time": 166, - "Intensity": 0.72, - "Frequency": 42 - }, - { - "Time": 183, - "Intensity": 0.59, - "Frequency": 40 - }, - { - "Time": 200, - "Intensity": 0.54, - "Frequency": 39 - }, - { - "Time": 217, - "Intensity": 0.32, - "Frequency": 42 - }, - { - "Time": 233, - "Intensity": 0.34, - "Frequency": 40 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 40 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 254, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 17, - "Intensity": 0.15, - "Frequency": 60 - }, - { - "Time": 34, - "Intensity": 0.25, - "Frequency": 57 - }, - { - "Time": 50, - "Intensity": 0.19, - "Frequency": 59 - }, - { - "Time": 67, - "Intensity": 0.22, - "Frequency": 62 - }, - { - "Time": 84, - "Intensity": 0.32, - "Frequency": 66 - }, - { - "Time": 100, - "Intensity": 0.32, - "Frequency": 69 - }, - { - "Time": 117, - "Intensity": 0.18, - "Frequency": 71 - }, - { - "Time": 134, - "Intensity": 0.09, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.16, - "Frequency": 75 - }, - { - "Time": 167, - "Intensity": 0.21, - "Frequency": 76 - }, - { - "Time": 184, - "Intensity": 0.28, - "Frequency": 77 - }, - { - "Time": 200, - "Intensity": 0.12, - "Frequency": 75 - }, - { - "Time": 217, - "Intensity": 0.2, - "Frequency": 73 - }, - { - "Time": 234, - "Intensity": 0.13, - "Frequency": 74 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 75 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 290, - "Parameters": { - "Intensity": 85, - "Frequency": 83 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 342, - "Parameters": { - "Intensity": 69, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 395, - "Parameters": { - "Intensity": 51, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 446, - "Parameters": { - "Intensity": 36, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 483, - "Parameters": { - "Intensity": 27, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 222, - "StartTime": 504, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 74 - }, - { - "Time": 14, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 25, - "Intensity": 0.17, - "Frequency": 75 - }, - { - "Time": 38, - "Intensity": 0.22, - "Frequency": 75 - }, - { - "Time": 58, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 73, - "Intensity": 0.05, - "Frequency": 78 - }, - { - "Time": 88, - "Intensity": 0.07, - "Frequency": 79 - }, - { - "Time": 101, - "Intensity": 0.12, - "Frequency": 81 - }, - { - "Time": 118, - "Intensity": 0.27, - "Frequency": 80 - }, - { - "Time": 132, - "Intensity": 0.22, - "Frequency": 79 - }, - { - "Time": 147, - "Intensity": 0.12, - "Frequency": 79 - }, - { - "Time": 161, - "Intensity": 0.1, - "Frequency": 78 - }, - { - "Time": 176, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 191, - "Intensity": 0.22, - "Frequency": 75 - }, - { - "Time": 202, - "Intensity": 0.18, - "Frequency": 76 - }, - { - "Time": 222, - "Intensity": 0, - "Frequency": 76 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 727, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 17, - "Intensity": 0.07, - "Frequency": 76 - }, - { - "Time": 33, - "Intensity": 0.07, - "Frequency": 76 - }, - { - "Time": 50, - "Intensity": 0.06, - "Frequency": 78 - }, - { - "Time": 67, - "Intensity": 0.03, - "Frequency": 76 - }, - { - "Time": 83, - "Intensity": 0.03, - "Frequency": 76 - }, - { - "Time": 100, - "Intensity": 0.04, - "Frequency": 74 - }, - { - "Time": 116, - "Intensity": 0.11, - "Frequency": 80 - }, - { - "Time": 132, - "Intensity": 0.07, - "Frequency": 81 - }, - { - "Time": 150, - "Intensity": 0.05, - "Frequency": 79 - }, - { - "Time": 167, - "Intensity": 0.02, - "Frequency": 75 - }, - { - "Time": 183, - "Intensity": 0.01, - "Frequency": 73 - }, - { - "Time": 198, - "Intensity": 0.03, - "Frequency": 74 - }, - { - "Time": 216, - "Intensity": 0.06, - "Frequency": 73 - }, - { - "Time": 234, - "Intensity": 0.04, - "Frequency": 73 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 74 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2, + "Parameters": { + "Intensity": 100, + "Frequency": 10, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37 + }, + { + "Time": 30, + "Intensity": 0.08, + "Frequency": 45 + }, + { + "Time": 47, + "Intensity": 0.14, + "Frequency": 47 + }, + { + "Time": 58, + "Intensity": 0.23, + "Frequency": 48 + }, + { + "Time": 75, + "Intensity": 0.52, + "Frequency": 46 + }, + { + "Time": 89, + "Intensity": 0.93, + "Frequency": 48 + }, + { + "Time": 99, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 124, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 1, + "Frequency": 52 + }, + { + "Time": 150, + "Intensity": 0.84, + "Frequency": 54 + }, + { + "Time": 166, + "Intensity": 0.72, + "Frequency": 52 + }, + { + "Time": 183, + "Intensity": 0.59, + "Frequency": 50 + }, + { + "Time": 200, + "Intensity": 0.54, + "Frequency": 49 + }, + { + "Time": 217, + "Intensity": 0.32, + "Frequency": 50 + }, + { + "Time": 233, + "Intensity": 0.34, + "Frequency": 50 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 22 + }, + { + "Time": 30, + "Intensity": 0.08, + "Frequency": 39 + }, + { + "Time": 47, + "Intensity": 0.14, + "Frequency": 36 + }, + { + "Time": 60, + "Intensity": 0.24, + "Frequency": 38 + }, + { + "Time": 75, + "Intensity": 0.52, + "Frequency": 39 + }, + { + "Time": 89, + "Intensity": 0.93, + "Frequency": 42 + }, + { + "Time": 99, + "Intensity": 1, + "Frequency": 39 + }, + { + "Time": 124, + "Intensity": 1, + "Frequency": 40 + }, + { + "Time": 138, + "Intensity": 1, + "Frequency": 42 + }, + { + "Time": 150, + "Intensity": 0.84, + "Frequency": 44 + }, + { + "Time": 166, + "Intensity": 0.72, + "Frequency": 42 + }, + { + "Time": 183, + "Intensity": 0.59, + "Frequency": 40 + }, + { + "Time": 200, + "Intensity": 0.54, + "Frequency": 39 + }, + { + "Time": 217, + "Intensity": 0.32, + "Frequency": 42 + }, + { + "Time": 233, + "Intensity": 0.34, + "Frequency": 40 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 40 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 254, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 17, + "Intensity": 0.15, + "Frequency": 60 + }, + { + "Time": 34, + "Intensity": 0.25, + "Frequency": 57 + }, + { + "Time": 50, + "Intensity": 0.19, + "Frequency": 59 + }, + { + "Time": 67, + "Intensity": 0.22, + "Frequency": 62 + }, + { + "Time": 84, + "Intensity": 0.32, + "Frequency": 66 + }, + { + "Time": 100, + "Intensity": 0.32, + "Frequency": 69 + }, + { + "Time": 117, + "Intensity": 0.18, + "Frequency": 71 + }, + { + "Time": 134, + "Intensity": 0.09, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.16, + "Frequency": 75 + }, + { + "Time": 167, + "Intensity": 0.21, + "Frequency": 76 + }, + { + "Time": 184, + "Intensity": 0.28, + "Frequency": 77 + }, + { + "Time": 200, + "Intensity": 0.12, + "Frequency": 75 + }, + { + "Time": 217, + "Intensity": 0.2, + "Frequency": 73 + }, + { + "Time": 234, + "Intensity": 0.13, + "Frequency": 74 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 75 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 290, + "Parameters": { + "Intensity": 85, + "Frequency": 83 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 342, + "Parameters": { + "Intensity": 69, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 395, + "Parameters": { + "Intensity": 51, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 446, + "Parameters": { + "Intensity": 36, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 483, + "Parameters": { + "Intensity": 27, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 222, + "StartTime": 504, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 74 + }, + { + "Time": 14, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 25, + "Intensity": 0.17, + "Frequency": 75 + }, + { + "Time": 38, + "Intensity": 0.22, + "Frequency": 75 + }, + { + "Time": 58, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 73, + "Intensity": 0.05, + "Frequency": 78 + }, + { + "Time": 88, + "Intensity": 0.07, + "Frequency": 79 + }, + { + "Time": 101, + "Intensity": 0.12, + "Frequency": 81 + }, + { + "Time": 118, + "Intensity": 0.27, + "Frequency": 80 + }, + { + "Time": 132, + "Intensity": 0.22, + "Frequency": 79 + }, + { + "Time": 147, + "Intensity": 0.12, + "Frequency": 79 + }, + { + "Time": 161, + "Intensity": 0.1, + "Frequency": 78 + }, + { + "Time": 176, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 191, + "Intensity": 0.22, + "Frequency": 75 + }, + { + "Time": 202, + "Intensity": 0.18, + "Frequency": 76 + }, + { + "Time": 222, + "Intensity": 0, + "Frequency": 76 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 727, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 17, + "Intensity": 0.07, + "Frequency": 76 + }, + { + "Time": 33, + "Intensity": 0.07, + "Frequency": 76 + }, + { + "Time": 50, + "Intensity": 0.06, + "Frequency": 78 + }, + { + "Time": 67, + "Intensity": 0.03, + "Frequency": 76 + }, + { + "Time": 83, + "Intensity": 0.03, + "Frequency": 76 + }, + { + "Time": 100, + "Intensity": 0.04, + "Frequency": 74 + }, + { + "Time": 116, + "Intensity": 0.11, + "Frequency": 80 + }, + { + "Time": 132, + "Intensity": 0.07, + "Frequency": 81 + }, + { + "Time": 150, + "Intensity": 0.05, + "Frequency": 79 + }, + { + "Time": 167, + "Intensity": 0.02, + "Frequency": 75 + }, + { + "Time": 183, + "Intensity": 0.01, + "Frequency": 73 + }, + { + "Time": 198, + "Intensity": 0.03, + "Frequency": 74 + }, + { + "Time": 216, + "Intensity": 0.06, + "Frequency": 73 + }, + { + "Time": 234, + "Intensity": 0.04, + "Frequency": 73 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 74 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_l.json index d9911761be489bd787d982bc5098599643ea4976..370eaa4c8e399915030d738ff5a8d4c67f8b9a6b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_l.json @@ -1,532 +1,532 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2, - "Parameters": { - "Intensity": 60, - "Frequency": 10, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37 - }, - { - "Time": 30, - "Intensity": 0.08, - "Frequency": 45 - }, - { - "Time": 47, - "Intensity": 0.14, - "Frequency": 47 - }, - { - "Time": 58, - "Intensity": 0.23, - "Frequency": 48 - }, - { - "Time": 75, - "Intensity": 0.52, - "Frequency": 46 - }, - { - "Time": 89, - "Intensity": 0.93, - "Frequency": 48 - }, - { - "Time": 99, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 124, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 1, - "Frequency": 52 - }, - { - "Time": 150, - "Intensity": 0.84, - "Frequency": 54 - }, - { - "Time": 166, - "Intensity": 0.72, - "Frequency": 52 - }, - { - "Time": 183, - "Intensity": 0.59, - "Frequency": 50 - }, - { - "Time": 200, - "Intensity": 0.54, - "Frequency": 49 - }, - { - "Time": 217, - "Intensity": 0.32, - "Frequency": 50 - }, - { - "Time": 233, - "Intensity": 0.34, - "Frequency": 50 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 22 - }, - { - "Time": 30, - "Intensity": 0.08, - "Frequency": 39 - }, - { - "Time": 47, - "Intensity": 0.14, - "Frequency": 36 - }, - { - "Time": 60, - "Intensity": 0.24, - "Frequency": 38 - }, - { - "Time": 75, - "Intensity": 0.52, - "Frequency": 39 - }, - { - "Time": 89, - "Intensity": 0.93, - "Frequency": 42 - }, - { - "Time": 99, - "Intensity": 1, - "Frequency": 39 - }, - { - "Time": 124, - "Intensity": 1, - "Frequency": 40 - }, - { - "Time": 138, - "Intensity": 1, - "Frequency": 42 - }, - { - "Time": 150, - "Intensity": 0.84, - "Frequency": 44 - }, - { - "Time": 166, - "Intensity": 0.72, - "Frequency": 42 - }, - { - "Time": 183, - "Intensity": 0.59, - "Frequency": 40 - }, - { - "Time": 200, - "Intensity": 0.54, - "Frequency": 39 - }, - { - "Time": 217, - "Intensity": 0.32, - "Frequency": 42 - }, - { - "Time": 233, - "Intensity": 0.34, - "Frequency": 40 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 40 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 254, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 17, - "Intensity": 0.15, - "Frequency": 60 - }, - { - "Time": 34, - "Intensity": 0.25, - "Frequency": 57 - }, - { - "Time": 50, - "Intensity": 0.19, - "Frequency": 59 - }, - { - "Time": 67, - "Intensity": 0.22, - "Frequency": 62 - }, - { - "Time": 84, - "Intensity": 0.32, - "Frequency": 66 - }, - { - "Time": 100, - "Intensity": 0.32, - "Frequency": 69 - }, - { - "Time": 117, - "Intensity": 0.18, - "Frequency": 71 - }, - { - "Time": 134, - "Intensity": 0.09, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.16, - "Frequency": 75 - }, - { - "Time": 167, - "Intensity": 0.21, - "Frequency": 76 - }, - { - "Time": 184, - "Intensity": 0.28, - "Frequency": 77 - }, - { - "Time": 200, - "Intensity": 0.12, - "Frequency": 75 - }, - { - "Time": 217, - "Intensity": 0.2, - "Frequency": 73 - }, - { - "Time": 234, - "Intensity": 0.13, - "Frequency": 74 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 75 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 290, - "Parameters": { - "Intensity": 51, - "Frequency": 83 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 342, - "Parameters": { - "Intensity": 41, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 395, - "Parameters": { - "Intensity": 30, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 446, - "Parameters": { - "Intensity": 21, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 483, - "Parameters": { - "Intensity": 16, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 222, - "StartTime": 504, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 74 - }, - { - "Time": 14, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 25, - "Intensity": 0.17, - "Frequency": 75 - }, - { - "Time": 38, - "Intensity": 0.22, - "Frequency": 75 - }, - { - "Time": 58, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 73, - "Intensity": 0.05, - "Frequency": 78 - }, - { - "Time": 88, - "Intensity": 0.07, - "Frequency": 79 - }, - { - "Time": 101, - "Intensity": 0.12, - "Frequency": 81 - }, - { - "Time": 118, - "Intensity": 0.27, - "Frequency": 80 - }, - { - "Time": 132, - "Intensity": 0.22, - "Frequency": 79 - }, - { - "Time": 147, - "Intensity": 0.12, - "Frequency": 79 - }, - { - "Time": 161, - "Intensity": 0.1, - "Frequency": 78 - }, - { - "Time": 176, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 191, - "Intensity": 0.22, - "Frequency": 75 - }, - { - "Time": 202, - "Intensity": 0.18, - "Frequency": 76 - }, - { - "Time": 222, - "Intensity": 0, - "Frequency": 76 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 727, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 17, - "Intensity": 0.07, - "Frequency": 76 - }, - { - "Time": 33, - "Intensity": 0.07, - "Frequency": 76 - }, - { - "Time": 50, - "Intensity": 0.06, - "Frequency": 78 - }, - { - "Time": 67, - "Intensity": 0.03, - "Frequency": 76 - }, - { - "Time": 83, - "Intensity": 0.03, - "Frequency": 76 - }, - { - "Time": 100, - "Intensity": 0.04, - "Frequency": 74 - }, - { - "Time": 116, - "Intensity": 0.11, - "Frequency": 80 - }, - { - "Time": 132, - "Intensity": 0.07, - "Frequency": 81 - }, - { - "Time": 150, - "Intensity": 0.05, - "Frequency": 79 - }, - { - "Time": 167, - "Intensity": 0.02, - "Frequency": 75 - }, - { - "Time": 183, - "Intensity": 0.01, - "Frequency": 73 - }, - { - "Time": 198, - "Intensity": 0.03, - "Frequency": 74 - }, - { - "Time": 216, - "Intensity": 0.06, - "Frequency": 73 - }, - { - "Time": 234, - "Intensity": 0.04, - "Frequency": 73 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 74 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2, + "Parameters": { + "Intensity": 60, + "Frequency": 10, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37 + }, + { + "Time": 30, + "Intensity": 0.08, + "Frequency": 45 + }, + { + "Time": 47, + "Intensity": 0.14, + "Frequency": 47 + }, + { + "Time": 58, + "Intensity": 0.23, + "Frequency": 48 + }, + { + "Time": 75, + "Intensity": 0.52, + "Frequency": 46 + }, + { + "Time": 89, + "Intensity": 0.93, + "Frequency": 48 + }, + { + "Time": 99, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 124, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 1, + "Frequency": 52 + }, + { + "Time": 150, + "Intensity": 0.84, + "Frequency": 54 + }, + { + "Time": 166, + "Intensity": 0.72, + "Frequency": 52 + }, + { + "Time": 183, + "Intensity": 0.59, + "Frequency": 50 + }, + { + "Time": 200, + "Intensity": 0.54, + "Frequency": 49 + }, + { + "Time": 217, + "Intensity": 0.32, + "Frequency": 50 + }, + { + "Time": 233, + "Intensity": 0.34, + "Frequency": 50 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 22 + }, + { + "Time": 30, + "Intensity": 0.08, + "Frequency": 39 + }, + { + "Time": 47, + "Intensity": 0.14, + "Frequency": 36 + }, + { + "Time": 60, + "Intensity": 0.24, + "Frequency": 38 + }, + { + "Time": 75, + "Intensity": 0.52, + "Frequency": 39 + }, + { + "Time": 89, + "Intensity": 0.93, + "Frequency": 42 + }, + { + "Time": 99, + "Intensity": 1, + "Frequency": 39 + }, + { + "Time": 124, + "Intensity": 1, + "Frequency": 40 + }, + { + "Time": 138, + "Intensity": 1, + "Frequency": 42 + }, + { + "Time": 150, + "Intensity": 0.84, + "Frequency": 44 + }, + { + "Time": 166, + "Intensity": 0.72, + "Frequency": 42 + }, + { + "Time": 183, + "Intensity": 0.59, + "Frequency": 40 + }, + { + "Time": 200, + "Intensity": 0.54, + "Frequency": 39 + }, + { + "Time": 217, + "Intensity": 0.32, + "Frequency": 42 + }, + { + "Time": 233, + "Intensity": 0.34, + "Frequency": 40 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 40 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 254, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 17, + "Intensity": 0.15, + "Frequency": 60 + }, + { + "Time": 34, + "Intensity": 0.25, + "Frequency": 57 + }, + { + "Time": 50, + "Intensity": 0.19, + "Frequency": 59 + }, + { + "Time": 67, + "Intensity": 0.22, + "Frequency": 62 + }, + { + "Time": 84, + "Intensity": 0.32, + "Frequency": 66 + }, + { + "Time": 100, + "Intensity": 0.32, + "Frequency": 69 + }, + { + "Time": 117, + "Intensity": 0.18, + "Frequency": 71 + }, + { + "Time": 134, + "Intensity": 0.09, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.16, + "Frequency": 75 + }, + { + "Time": 167, + "Intensity": 0.21, + "Frequency": 76 + }, + { + "Time": 184, + "Intensity": 0.28, + "Frequency": 77 + }, + { + "Time": 200, + "Intensity": 0.12, + "Frequency": 75 + }, + { + "Time": 217, + "Intensity": 0.2, + "Frequency": 73 + }, + { + "Time": 234, + "Intensity": 0.13, + "Frequency": 74 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 75 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 290, + "Parameters": { + "Intensity": 51, + "Frequency": 83 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 342, + "Parameters": { + "Intensity": 41, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 395, + "Parameters": { + "Intensity": 30, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 446, + "Parameters": { + "Intensity": 21, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 483, + "Parameters": { + "Intensity": 16, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 222, + "StartTime": 504, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 74 + }, + { + "Time": 14, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 25, + "Intensity": 0.17, + "Frequency": 75 + }, + { + "Time": 38, + "Intensity": 0.22, + "Frequency": 75 + }, + { + "Time": 58, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 73, + "Intensity": 0.05, + "Frequency": 78 + }, + { + "Time": 88, + "Intensity": 0.07, + "Frequency": 79 + }, + { + "Time": 101, + "Intensity": 0.12, + "Frequency": 81 + }, + { + "Time": 118, + "Intensity": 0.27, + "Frequency": 80 + }, + { + "Time": 132, + "Intensity": 0.22, + "Frequency": 79 + }, + { + "Time": 147, + "Intensity": 0.12, + "Frequency": 79 + }, + { + "Time": 161, + "Intensity": 0.1, + "Frequency": 78 + }, + { + "Time": 176, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 191, + "Intensity": 0.22, + "Frequency": 75 + }, + { + "Time": 202, + "Intensity": 0.18, + "Frequency": 76 + }, + { + "Time": 222, + "Intensity": 0, + "Frequency": 76 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 727, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 17, + "Intensity": 0.07, + "Frequency": 76 + }, + { + "Time": 33, + "Intensity": 0.07, + "Frequency": 76 + }, + { + "Time": 50, + "Intensity": 0.06, + "Frequency": 78 + }, + { + "Time": 67, + "Intensity": 0.03, + "Frequency": 76 + }, + { + "Time": 83, + "Intensity": 0.03, + "Frequency": 76 + }, + { + "Time": 100, + "Intensity": 0.04, + "Frequency": 74 + }, + { + "Time": 116, + "Intensity": 0.11, + "Frequency": 80 + }, + { + "Time": 132, + "Intensity": 0.07, + "Frequency": 81 + }, + { + "Time": 150, + "Intensity": 0.05, + "Frequency": 79 + }, + { + "Time": 167, + "Intensity": 0.02, + "Frequency": 75 + }, + { + "Time": 183, + "Intensity": 0.01, + "Frequency": 73 + }, + { + "Time": 198, + "Intensity": 0.03, + "Frequency": 74 + }, + { + "Time": 216, + "Intensity": 0.06, + "Frequency": 73 + }, + { + "Time": 234, + "Intensity": 0.04, + "Frequency": 73 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 74 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_m.json index d95d9c202003b7d9f8a5148cbb9a532538b287fd..4a6e651ff04a83b119c3bcd1caca96eb1d45fe49 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarCrash_m.json @@ -1,532 +1,532 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2, - "Parameters": { - "Intensity": 80, - "Frequency": 10, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37 - }, - { - "Time": 30, - "Intensity": 0.08, - "Frequency": 45 - }, - { - "Time": 47, - "Intensity": 0.14, - "Frequency": 47 - }, - { - "Time": 58, - "Intensity": 0.23, - "Frequency": 48 - }, - { - "Time": 75, - "Intensity": 0.52, - "Frequency": 46 - }, - { - "Time": 89, - "Intensity": 0.93, - "Frequency": 48 - }, - { - "Time": 99, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 124, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 1, - "Frequency": 52 - }, - { - "Time": 150, - "Intensity": 0.84, - "Frequency": 54 - }, - { - "Time": 166, - "Intensity": 0.72, - "Frequency": 52 - }, - { - "Time": 183, - "Intensity": 0.59, - "Frequency": 50 - }, - { - "Time": 200, - "Intensity": 0.54, - "Frequency": 49 - }, - { - "Time": 217, - "Intensity": 0.32, - "Frequency": 50 - }, - { - "Time": 233, - "Intensity": 0.34, - "Frequency": 50 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 22 - }, - { - "Time": 30, - "Intensity": 0.08, - "Frequency": 39 - }, - { - "Time": 47, - "Intensity": 0.14, - "Frequency": 36 - }, - { - "Time": 60, - "Intensity": 0.24, - "Frequency": 38 - }, - { - "Time": 75, - "Intensity": 0.52, - "Frequency": 39 - }, - { - "Time": 89, - "Intensity": 0.93, - "Frequency": 42 - }, - { - "Time": 99, - "Intensity": 1, - "Frequency": 39 - }, - { - "Time": 124, - "Intensity": 1, - "Frequency": 40 - }, - { - "Time": 138, - "Intensity": 1, - "Frequency": 42 - }, - { - "Time": 150, - "Intensity": 0.84, - "Frequency": 44 - }, - { - "Time": 166, - "Intensity": 0.72, - "Frequency": 42 - }, - { - "Time": 183, - "Intensity": 0.59, - "Frequency": 40 - }, - { - "Time": 200, - "Intensity": 0.54, - "Frequency": 39 - }, - { - "Time": 217, - "Intensity": 0.32, - "Frequency": 42 - }, - { - "Time": 233, - "Intensity": 0.34, - "Frequency": 40 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 40 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 254, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 17, - "Intensity": 0.15, - "Frequency": 60 - }, - { - "Time": 34, - "Intensity": 0.25, - "Frequency": 57 - }, - { - "Time": 50, - "Intensity": 0.19, - "Frequency": 59 - }, - { - "Time": 67, - "Intensity": 0.22, - "Frequency": 62 - }, - { - "Time": 84, - "Intensity": 0.32, - "Frequency": 66 - }, - { - "Time": 100, - "Intensity": 0.32, - "Frequency": 69 - }, - { - "Time": 117, - "Intensity": 0.18, - "Frequency": 71 - }, - { - "Time": 134, - "Intensity": 0.09, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.16, - "Frequency": 75 - }, - { - "Time": 167, - "Intensity": 0.21, - "Frequency": 76 - }, - { - "Time": 184, - "Intensity": 0.28, - "Frequency": 77 - }, - { - "Time": 200, - "Intensity": 0.12, - "Frequency": 75 - }, - { - "Time": 217, - "Intensity": 0.2, - "Frequency": 73 - }, - { - "Time": 234, - "Intensity": 0.13, - "Frequency": 74 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 75 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 290, - "Parameters": { - "Intensity": 68, - "Frequency": 83 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 342, - "Parameters": { - "Intensity": 55, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 395, - "Parameters": { - "Intensity": 40, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 446, - "Parameters": { - "Intensity": 28, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 483, - "Parameters": { - "Intensity": 21, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 222, - "StartTime": 504, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 74 - }, - { - "Time": 14, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 25, - "Intensity": 0.17, - "Frequency": 75 - }, - { - "Time": 38, - "Intensity": 0.22, - "Frequency": 75 - }, - { - "Time": 58, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 73, - "Intensity": 0.05, - "Frequency": 78 - }, - { - "Time": 88, - "Intensity": 0.07, - "Frequency": 79 - }, - { - "Time": 101, - "Intensity": 0.12, - "Frequency": 81 - }, - { - "Time": 118, - "Intensity": 0.27, - "Frequency": 80 - }, - { - "Time": 132, - "Intensity": 0.22, - "Frequency": 79 - }, - { - "Time": 147, - "Intensity": 0.12, - "Frequency": 79 - }, - { - "Time": 161, - "Intensity": 0.1, - "Frequency": 78 - }, - { - "Time": 176, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 191, - "Intensity": 0.22, - "Frequency": 75 - }, - { - "Time": 202, - "Intensity": 0.18, - "Frequency": 76 - }, - { - "Time": 222, - "Intensity": 0, - "Frequency": 76 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 727, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 17, - "Intensity": 0.07, - "Frequency": 76 - }, - { - "Time": 33, - "Intensity": 0.07, - "Frequency": 76 - }, - { - "Time": 50, - "Intensity": 0.06, - "Frequency": 78 - }, - { - "Time": 67, - "Intensity": 0.03, - "Frequency": 76 - }, - { - "Time": 83, - "Intensity": 0.03, - "Frequency": 76 - }, - { - "Time": 100, - "Intensity": 0.04, - "Frequency": 74 - }, - { - "Time": 116, - "Intensity": 0.11, - "Frequency": 80 - }, - { - "Time": 132, - "Intensity": 0.07, - "Frequency": 81 - }, - { - "Time": 150, - "Intensity": 0.05, - "Frequency": 79 - }, - { - "Time": 167, - "Intensity": 0.02, - "Frequency": 75 - }, - { - "Time": 183, - "Intensity": 0.01, - "Frequency": 73 - }, - { - "Time": 198, - "Intensity": 0.03, - "Frequency": 74 - }, - { - "Time": 216, - "Intensity": 0.06, - "Frequency": 73 - }, - { - "Time": 234, - "Intensity": 0.04, - "Frequency": 73 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 74 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2, + "Parameters": { + "Intensity": 80, + "Frequency": 10, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37 + }, + { + "Time": 30, + "Intensity": 0.08, + "Frequency": 45 + }, + { + "Time": 47, + "Intensity": 0.14, + "Frequency": 47 + }, + { + "Time": 58, + "Intensity": 0.23, + "Frequency": 48 + }, + { + "Time": 75, + "Intensity": 0.52, + "Frequency": 46 + }, + { + "Time": 89, + "Intensity": 0.93, + "Frequency": 48 + }, + { + "Time": 99, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 124, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 1, + "Frequency": 52 + }, + { + "Time": 150, + "Intensity": 0.84, + "Frequency": 54 + }, + { + "Time": 166, + "Intensity": 0.72, + "Frequency": 52 + }, + { + "Time": 183, + "Intensity": 0.59, + "Frequency": 50 + }, + { + "Time": 200, + "Intensity": 0.54, + "Frequency": 49 + }, + { + "Time": 217, + "Intensity": 0.32, + "Frequency": 50 + }, + { + "Time": 233, + "Intensity": 0.34, + "Frequency": 50 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 22 + }, + { + "Time": 30, + "Intensity": 0.08, + "Frequency": 39 + }, + { + "Time": 47, + "Intensity": 0.14, + "Frequency": 36 + }, + { + "Time": 60, + "Intensity": 0.24, + "Frequency": 38 + }, + { + "Time": 75, + "Intensity": 0.52, + "Frequency": 39 + }, + { + "Time": 89, + "Intensity": 0.93, + "Frequency": 42 + }, + { + "Time": 99, + "Intensity": 1, + "Frequency": 39 + }, + { + "Time": 124, + "Intensity": 1, + "Frequency": 40 + }, + { + "Time": 138, + "Intensity": 1, + "Frequency": 42 + }, + { + "Time": 150, + "Intensity": 0.84, + "Frequency": 44 + }, + { + "Time": 166, + "Intensity": 0.72, + "Frequency": 42 + }, + { + "Time": 183, + "Intensity": 0.59, + "Frequency": 40 + }, + { + "Time": 200, + "Intensity": 0.54, + "Frequency": 39 + }, + { + "Time": 217, + "Intensity": 0.32, + "Frequency": 42 + }, + { + "Time": 233, + "Intensity": 0.34, + "Frequency": 40 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 40 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 254, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 17, + "Intensity": 0.15, + "Frequency": 60 + }, + { + "Time": 34, + "Intensity": 0.25, + "Frequency": 57 + }, + { + "Time": 50, + "Intensity": 0.19, + "Frequency": 59 + }, + { + "Time": 67, + "Intensity": 0.22, + "Frequency": 62 + }, + { + "Time": 84, + "Intensity": 0.32, + "Frequency": 66 + }, + { + "Time": 100, + "Intensity": 0.32, + "Frequency": 69 + }, + { + "Time": 117, + "Intensity": 0.18, + "Frequency": 71 + }, + { + "Time": 134, + "Intensity": 0.09, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.16, + "Frequency": 75 + }, + { + "Time": 167, + "Intensity": 0.21, + "Frequency": 76 + }, + { + "Time": 184, + "Intensity": 0.28, + "Frequency": 77 + }, + { + "Time": 200, + "Intensity": 0.12, + "Frequency": 75 + }, + { + "Time": 217, + "Intensity": 0.2, + "Frequency": 73 + }, + { + "Time": 234, + "Intensity": 0.13, + "Frequency": 74 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 75 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 290, + "Parameters": { + "Intensity": 68, + "Frequency": 83 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 342, + "Parameters": { + "Intensity": 55, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 395, + "Parameters": { + "Intensity": 40, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 446, + "Parameters": { + "Intensity": 28, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 483, + "Parameters": { + "Intensity": 21, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 222, + "StartTime": 504, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 74 + }, + { + "Time": 14, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 25, + "Intensity": 0.17, + "Frequency": 75 + }, + { + "Time": 38, + "Intensity": 0.22, + "Frequency": 75 + }, + { + "Time": 58, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 73, + "Intensity": 0.05, + "Frequency": 78 + }, + { + "Time": 88, + "Intensity": 0.07, + "Frequency": 79 + }, + { + "Time": 101, + "Intensity": 0.12, + "Frequency": 81 + }, + { + "Time": 118, + "Intensity": 0.27, + "Frequency": 80 + }, + { + "Time": 132, + "Intensity": 0.22, + "Frequency": 79 + }, + { + "Time": 147, + "Intensity": 0.12, + "Frequency": 79 + }, + { + "Time": 161, + "Intensity": 0.1, + "Frequency": 78 + }, + { + "Time": 176, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 191, + "Intensity": 0.22, + "Frequency": 75 + }, + { + "Time": 202, + "Intensity": 0.18, + "Frequency": 76 + }, + { + "Time": 222, + "Intensity": 0, + "Frequency": 76 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 727, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 17, + "Intensity": 0.07, + "Frequency": 76 + }, + { + "Time": 33, + "Intensity": 0.07, + "Frequency": 76 + }, + { + "Time": 50, + "Intensity": 0.06, + "Frequency": 78 + }, + { + "Time": 67, + "Intensity": 0.03, + "Frequency": 76 + }, + { + "Time": 83, + "Intensity": 0.03, + "Frequency": 76 + }, + { + "Time": 100, + "Intensity": 0.04, + "Frequency": 74 + }, + { + "Time": 116, + "Intensity": 0.11, + "Frequency": 80 + }, + { + "Time": 132, + "Intensity": 0.07, + "Frequency": 81 + }, + { + "Time": 150, + "Intensity": 0.05, + "Frequency": 79 + }, + { + "Time": 167, + "Intensity": 0.02, + "Frequency": 75 + }, + { + "Time": 183, + "Intensity": 0.01, + "Frequency": 73 + }, + { + "Time": 198, + "Intensity": 0.03, + "Frequency": 74 + }, + { + "Time": 216, + "Intensity": 0.06, + "Frequency": 73 + }, + { + "Time": 234, + "Intensity": 0.04, + "Frequency": 73 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 74 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_h.json index 05b88416e8afdd2a6682b5b0ea9b607f1ba8851c..771aca2e49aeca07b8cf17cb38a39ce3c2ec8de6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_h.json @@ -1,256 +1,256 @@ -{ - "MetaData": { - "Create": "2022-04-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 672, - "StartTime": 90, - "Parameters": { - "Intensity": 85, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -3 - }, - { - "Time": 26, - "Intensity": 0.87, - "Frequency": 6 - }, - { - "Time": 54, - "Intensity": 0.96, - "Frequency": 9 - }, - { - "Time": 73, - "Intensity": 0.19, - "Frequency": -11 - }, - { - "Time": 110, - "Intensity": 0.79, - "Frequency": -1 - }, - { - "Time": 151, - "Intensity": 0.19, - "Frequency": -9 - }, - { - "Time": 264, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 331, - "Intensity": 0.76, - "Frequency": 0 - }, - { - "Time": 345, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 380, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 425, - "Intensity": 0.7, - "Frequency": 0 - }, - { - "Time": 452, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 499, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 571, - "Intensity": 0.89, - "Frequency": 0 - }, - { - "Time": 599, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 672, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 672, - "StartTime": 96, - "Parameters": { - "Intensity": 85, - "Frequency": 60, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -3 - }, - { - "Time": 26, - "Intensity": 0.87, - "Frequency": 6 - }, - { - "Time": 54, - "Intensity": 0.96, - "Frequency": 9 - }, - { - "Time": 73, - "Intensity": 0.19, - "Frequency": -11 - }, - { - "Time": 110, - "Intensity": 0.79, - "Frequency": -1 - }, - { - "Time": 151, - "Intensity": 0.19, - "Frequency": -9 - }, - { - "Time": 176, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 319, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 672, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1300, - "StartTime": 768, - "Parameters": { - "Intensity": 100, - "Frequency": 57, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -73 - }, - { - "Time": 105, - "Intensity": 0.32, - "Frequency": -58 - }, - { - "Time": 179, - "Intensity": 1, - "Frequency": -8 - }, - { - "Time": 218, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 314, - "Intensity": 0.2, - "Frequency": -10 - }, - { - "Time": 443, - "Intensity": 0.1, - "Frequency": -33 - }, - { - "Time": 547, - "Intensity": 0.08, - "Frequency": 0 - }, - { - "Time": 646, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 729, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 840, - "Intensity": 0.06, - "Frequency": 0 - }, - { - "Time": 906, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 962, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 1005, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 1067, - "Intensity": 0.04, - "Frequency": 0 - }, - { - "Time": 1300, - "Intensity": 0, - "Frequency": -32 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 672, + "StartTime": 90, + "Parameters": { + "Intensity": 85, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -3 + }, + { + "Time": 26, + "Intensity": 0.87, + "Frequency": 6 + }, + { + "Time": 54, + "Intensity": 0.96, + "Frequency": 9 + }, + { + "Time": 73, + "Intensity": 0.19, + "Frequency": -11 + }, + { + "Time": 110, + "Intensity": 0.79, + "Frequency": -1 + }, + { + "Time": 151, + "Intensity": 0.19, + "Frequency": -9 + }, + { + "Time": 264, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 331, + "Intensity": 0.76, + "Frequency": 0 + }, + { + "Time": 345, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 380, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 425, + "Intensity": 0.7, + "Frequency": 0 + }, + { + "Time": 452, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 499, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 571, + "Intensity": 0.89, + "Frequency": 0 + }, + { + "Time": 599, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 672, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 672, + "StartTime": 96, + "Parameters": { + "Intensity": 85, + "Frequency": 60, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -3 + }, + { + "Time": 26, + "Intensity": 0.87, + "Frequency": 6 + }, + { + "Time": 54, + "Intensity": 0.96, + "Frequency": 9 + }, + { + "Time": 73, + "Intensity": 0.19, + "Frequency": -11 + }, + { + "Time": 110, + "Intensity": 0.79, + "Frequency": -1 + }, + { + "Time": 151, + "Intensity": 0.19, + "Frequency": -9 + }, + { + "Time": 176, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 319, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 672, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1300, + "StartTime": 768, + "Parameters": { + "Intensity": 100, + "Frequency": 57, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -73 + }, + { + "Time": 105, + "Intensity": 0.32, + "Frequency": -58 + }, + { + "Time": 179, + "Intensity": 1, + "Frequency": -8 + }, + { + "Time": 218, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 314, + "Intensity": 0.2, + "Frequency": -10 + }, + { + "Time": 443, + "Intensity": 0.1, + "Frequency": -33 + }, + { + "Time": 547, + "Intensity": 0.08, + "Frequency": 0 + }, + { + "Time": 646, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 729, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 840, + "Intensity": 0.06, + "Frequency": 0 + }, + { + "Time": 906, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 962, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 1005, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 1067, + "Intensity": 0.04, + "Frequency": 0 + }, + { + "Time": 1300, + "Intensity": 0, + "Frequency": -32 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_l.json index 61849194202559a7f27c5bd5636a25e03870e9e5..96d98b6903b1c5cd29814c3c2c8b451b758d8b63 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_l.json @@ -1,256 +1,256 @@ -{ - "MetaData": { - "Create": "2022-04-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 672, - "StartTime": 90, - "Parameters": { - "Intensity": 51, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -3 - }, - { - "Time": 26, - "Intensity": 0.87, - "Frequency": 6 - }, - { - "Time": 54, - "Intensity": 0.96, - "Frequency": 9 - }, - { - "Time": 73, - "Intensity": 0.19, - "Frequency": -11 - }, - { - "Time": 110, - "Intensity": 0.79, - "Frequency": -1 - }, - { - "Time": 151, - "Intensity": 0.19, - "Frequency": -9 - }, - { - "Time": 264, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 331, - "Intensity": 0.76, - "Frequency": 0 - }, - { - "Time": 345, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 380, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 425, - "Intensity": 0.7, - "Frequency": 0 - }, - { - "Time": 452, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 499, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 571, - "Intensity": 0.89, - "Frequency": 0 - }, - { - "Time": 599, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 672, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 672, - "StartTime": 96, - "Parameters": { - "Intensity": 51, - "Frequency": 60, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -3 - }, - { - "Time": 26, - "Intensity": 0.87, - "Frequency": 6 - }, - { - "Time": 54, - "Intensity": 0.96, - "Frequency": 9 - }, - { - "Time": 73, - "Intensity": 0.19, - "Frequency": -11 - }, - { - "Time": 110, - "Intensity": 0.79, - "Frequency": -1 - }, - { - "Time": 151, - "Intensity": 0.19, - "Frequency": -9 - }, - { - "Time": 176, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 319, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 672, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1300, - "StartTime": 768, - "Parameters": { - "Intensity": 60, - "Frequency": 57, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -73 - }, - { - "Time": 105, - "Intensity": 0.32, - "Frequency": -58 - }, - { - "Time": 179, - "Intensity": 1, - "Frequency": -8 - }, - { - "Time": 218, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 314, - "Intensity": 0.2, - "Frequency": -10 - }, - { - "Time": 443, - "Intensity": 0.1, - "Frequency": -33 - }, - { - "Time": 547, - "Intensity": 0.08, - "Frequency": 0 - }, - { - "Time": 646, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 729, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 840, - "Intensity": 0.06, - "Frequency": 0 - }, - { - "Time": 906, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 962, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 1005, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 1067, - "Intensity": 0.04, - "Frequency": 0 - }, - { - "Time": 1300, - "Intensity": 0, - "Frequency": -32 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 672, + "StartTime": 90, + "Parameters": { + "Intensity": 51, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -3 + }, + { + "Time": 26, + "Intensity": 0.87, + "Frequency": 6 + }, + { + "Time": 54, + "Intensity": 0.96, + "Frequency": 9 + }, + { + "Time": 73, + "Intensity": 0.19, + "Frequency": -11 + }, + { + "Time": 110, + "Intensity": 0.79, + "Frequency": -1 + }, + { + "Time": 151, + "Intensity": 0.19, + "Frequency": -9 + }, + { + "Time": 264, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 331, + "Intensity": 0.76, + "Frequency": 0 + }, + { + "Time": 345, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 380, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 425, + "Intensity": 0.7, + "Frequency": 0 + }, + { + "Time": 452, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 499, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 571, + "Intensity": 0.89, + "Frequency": 0 + }, + { + "Time": 599, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 672, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 672, + "StartTime": 96, + "Parameters": { + "Intensity": 51, + "Frequency": 60, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -3 + }, + { + "Time": 26, + "Intensity": 0.87, + "Frequency": 6 + }, + { + "Time": 54, + "Intensity": 0.96, + "Frequency": 9 + }, + { + "Time": 73, + "Intensity": 0.19, + "Frequency": -11 + }, + { + "Time": 110, + "Intensity": 0.79, + "Frequency": -1 + }, + { + "Time": 151, + "Intensity": 0.19, + "Frequency": -9 + }, + { + "Time": 176, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 319, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 672, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1300, + "StartTime": 768, + "Parameters": { + "Intensity": 60, + "Frequency": 57, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -73 + }, + { + "Time": 105, + "Intensity": 0.32, + "Frequency": -58 + }, + { + "Time": 179, + "Intensity": 1, + "Frequency": -8 + }, + { + "Time": 218, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 314, + "Intensity": 0.2, + "Frequency": -10 + }, + { + "Time": 443, + "Intensity": 0.1, + "Frequency": -33 + }, + { + "Time": 547, + "Intensity": 0.08, + "Frequency": 0 + }, + { + "Time": 646, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 729, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 840, + "Intensity": 0.06, + "Frequency": 0 + }, + { + "Time": 906, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 962, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 1005, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 1067, + "Intensity": 0.04, + "Frequency": 0 + }, + { + "Time": 1300, + "Intensity": 0, + "Frequency": -32 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_m.json index 898953b9110dfe710f82b481d923f3c5a97b035a..056dce1765809e4f687893e92adbce129e6057bd 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarIgnite_m.json @@ -1,256 +1,256 @@ -{ - "MetaData": { - "Create": "2022-04-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 672, - "StartTime": 90, - "Parameters": { - "Intensity": 68, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -3 - }, - { - "Time": 26, - "Intensity": 0.87, - "Frequency": 6 - }, - { - "Time": 54, - "Intensity": 0.96, - "Frequency": 9 - }, - { - "Time": 73, - "Intensity": 0.19, - "Frequency": -11 - }, - { - "Time": 110, - "Intensity": 0.79, - "Frequency": -1 - }, - { - "Time": 151, - "Intensity": 0.19, - "Frequency": -9 - }, - { - "Time": 264, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 331, - "Intensity": 0.76, - "Frequency": 0 - }, - { - "Time": 345, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 380, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 425, - "Intensity": 0.7, - "Frequency": 0 - }, - { - "Time": 452, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 499, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 571, - "Intensity": 0.89, - "Frequency": 0 - }, - { - "Time": 599, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 672, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 672, - "StartTime": 96, - "Parameters": { - "Intensity": 68, - "Frequency": 60, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -3 - }, - { - "Time": 26, - "Intensity": 0.87, - "Frequency": 6 - }, - { - "Time": 54, - "Intensity": 0.96, - "Frequency": 9 - }, - { - "Time": 73, - "Intensity": 0.19, - "Frequency": -11 - }, - { - "Time": 110, - "Intensity": 0.79, - "Frequency": -1 - }, - { - "Time": 151, - "Intensity": 0.19, - "Frequency": -9 - }, - { - "Time": 176, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 319, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 672, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1300, - "StartTime": 768, - "Parameters": { - "Intensity": 80, - "Frequency": 57, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -73 - }, - { - "Time": 105, - "Intensity": 0.32, - "Frequency": -58 - }, - { - "Time": 179, - "Intensity": 1, - "Frequency": -8 - }, - { - "Time": 218, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 314, - "Intensity": 0.2, - "Frequency": -10 - }, - { - "Time": 443, - "Intensity": 0.1, - "Frequency": -33 - }, - { - "Time": 547, - "Intensity": 0.08, - "Frequency": 0 - }, - { - "Time": 646, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 729, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 840, - "Intensity": 0.06, - "Frequency": 0 - }, - { - "Time": 906, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 962, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 1005, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 1067, - "Intensity": 0.04, - "Frequency": 0 - }, - { - "Time": 1300, - "Intensity": 0, - "Frequency": -32 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 672, + "StartTime": 90, + "Parameters": { + "Intensity": 68, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -3 + }, + { + "Time": 26, + "Intensity": 0.87, + "Frequency": 6 + }, + { + "Time": 54, + "Intensity": 0.96, + "Frequency": 9 + }, + { + "Time": 73, + "Intensity": 0.19, + "Frequency": -11 + }, + { + "Time": 110, + "Intensity": 0.79, + "Frequency": -1 + }, + { + "Time": 151, + "Intensity": 0.19, + "Frequency": -9 + }, + { + "Time": 264, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 331, + "Intensity": 0.76, + "Frequency": 0 + }, + { + "Time": 345, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 380, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 425, + "Intensity": 0.7, + "Frequency": 0 + }, + { + "Time": 452, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 499, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 571, + "Intensity": 0.89, + "Frequency": 0 + }, + { + "Time": 599, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 672, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 672, + "StartTime": 96, + "Parameters": { + "Intensity": 68, + "Frequency": 60, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -3 + }, + { + "Time": 26, + "Intensity": 0.87, + "Frequency": 6 + }, + { + "Time": 54, + "Intensity": 0.96, + "Frequency": 9 + }, + { + "Time": 73, + "Intensity": 0.19, + "Frequency": -11 + }, + { + "Time": 110, + "Intensity": 0.79, + "Frequency": -1 + }, + { + "Time": 151, + "Intensity": 0.19, + "Frequency": -9 + }, + { + "Time": 176, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 319, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 672, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1300, + "StartTime": 768, + "Parameters": { + "Intensity": 80, + "Frequency": 57, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -73 + }, + { + "Time": 105, + "Intensity": 0.32, + "Frequency": -58 + }, + { + "Time": 179, + "Intensity": 1, + "Frequency": -8 + }, + { + "Time": 218, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 314, + "Intensity": 0.2, + "Frequency": -10 + }, + { + "Time": 443, + "Intensity": 0.1, + "Frequency": -33 + }, + { + "Time": 547, + "Intensity": 0.08, + "Frequency": 0 + }, + { + "Time": 646, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 729, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 840, + "Intensity": 0.06, + "Frequency": 0 + }, + { + "Time": 906, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 962, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 1005, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 1067, + "Intensity": 0.04, + "Frequency": 0 + }, + { + "Time": 1300, + "Intensity": 0, + "Frequency": -32 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_h.json index 91f9c35cf1573f896baee1c383b85d41b06671eb..a70ce486a0b0ff2a24d190301afdb4108a4ac8cb 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_h.json @@ -1,203 +1,203 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 4838, - "StartTime": 23, - "Parameters": { - "Intensity": 95, - "Frequency": 44, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.36, - "Frequency": 0 - }, - { - "Time": 339, - "Intensity": 0.76, - "Frequency": 2 - }, - { - "Time": 576, - "Intensity": 0.84, - "Frequency": 0 - }, - { - "Time": 997, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1301, - "Intensity": 0.87, - "Frequency": 0 - }, - { - "Time": 2032, - "Intensity": 0.97, - "Frequency": 3 - }, - { - "Time": 2424, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 2753, - "Intensity": 1, - "Frequency": 4 - }, - { - "Time": 2975, - "Intensity": 0.93, - "Frequency": 5 - }, - { - "Time": 3232, - "Intensity": 0.27, - "Frequency": 0 - }, - { - "Time": 3851, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 4107, - "Intensity": 0.44, - "Frequency": 11 - }, - { - "Time": 4354, - "Intensity": 0.4, - "Frequency": 16 - }, - { - "Time": 4519, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 4838, - "Intensity": 0, - "Frequency": 2 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 4838, - "StartTime": 30, - "Parameters": { - "Intensity": 95, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.36, - "Frequency": 0 - }, - { - "Time": 339, - "Intensity": 0.76, - "Frequency": 2 - }, - { - "Time": 576, - "Intensity": 0.84, - "Frequency": 0 - }, - { - "Time": 997, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1301, - "Intensity": 0.87, - "Frequency": 0 - }, - { - "Time": 2032, - "Intensity": 0.97, - "Frequency": 3 - }, - { - "Time": 2424, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 2758, - "Intensity": 1, - "Frequency": 7 - }, - { - "Time": 3038, - "Intensity": 0.92, - "Frequency": 8 - }, - { - "Time": 3227, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 3851, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 4122, - "Intensity": 0.4, - "Frequency": 9 - }, - { - "Time": 4417, - "Intensity": 0.36, - "Frequency": 5 - }, - { - "Time": 4625, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 4838, - "Intensity": 0, - "Frequency": 2 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 4838, + "StartTime": 23, + "Parameters": { + "Intensity": 95, + "Frequency": 44, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.36, + "Frequency": 0 + }, + { + "Time": 339, + "Intensity": 0.76, + "Frequency": 2 + }, + { + "Time": 576, + "Intensity": 0.84, + "Frequency": 0 + }, + { + "Time": 997, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1301, + "Intensity": 0.87, + "Frequency": 0 + }, + { + "Time": 2032, + "Intensity": 0.97, + "Frequency": 3 + }, + { + "Time": 2424, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 2753, + "Intensity": 1, + "Frequency": 4 + }, + { + "Time": 2975, + "Intensity": 0.93, + "Frequency": 5 + }, + { + "Time": 3232, + "Intensity": 0.27, + "Frequency": 0 + }, + { + "Time": 3851, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 4107, + "Intensity": 0.44, + "Frequency": 11 + }, + { + "Time": 4354, + "Intensity": 0.4, + "Frequency": 16 + }, + { + "Time": 4519, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 4838, + "Intensity": 0, + "Frequency": 2 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 4838, + "StartTime": 30, + "Parameters": { + "Intensity": 95, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.36, + "Frequency": 0 + }, + { + "Time": 339, + "Intensity": 0.76, + "Frequency": 2 + }, + { + "Time": 576, + "Intensity": 0.84, + "Frequency": 0 + }, + { + "Time": 997, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1301, + "Intensity": 0.87, + "Frequency": 0 + }, + { + "Time": 2032, + "Intensity": 0.97, + "Frequency": 3 + }, + { + "Time": 2424, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 2758, + "Intensity": 1, + "Frequency": 7 + }, + { + "Time": 3038, + "Intensity": 0.92, + "Frequency": 8 + }, + { + "Time": 3227, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 3851, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 4122, + "Intensity": 0.4, + "Frequency": 9 + }, + { + "Time": 4417, + "Intensity": 0.36, + "Frequency": 5 + }, + { + "Time": 4625, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 4838, + "Intensity": 0, + "Frequency": 2 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_l.json index dfacbfafd7a69254ae12dc378f20103599ce7182..9ad3327ba2bdb554c9281f989fb1118dc80af0fd 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_l.json @@ -1,203 +1,203 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 4838, - "StartTime": 23, - "Parameters": { - "Intensity": 57, - "Frequency": 44, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.36, - "Frequency": 0 - }, - { - "Time": 339, - "Intensity": 0.76, - "Frequency": 2 - }, - { - "Time": 576, - "Intensity": 0.84, - "Frequency": 0 - }, - { - "Time": 997, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1301, - "Intensity": 0.87, - "Frequency": 0 - }, - { - "Time": 2032, - "Intensity": 0.97, - "Frequency": 3 - }, - { - "Time": 2424, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 2753, - "Intensity": 1, - "Frequency": 4 - }, - { - "Time": 2975, - "Intensity": 0.93, - "Frequency": 5 - }, - { - "Time": 3232, - "Intensity": 0.27, - "Frequency": 0 - }, - { - "Time": 3851, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 4107, - "Intensity": 0.44, - "Frequency": 11 - }, - { - "Time": 4354, - "Intensity": 0.4, - "Frequency": 16 - }, - { - "Time": 4519, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 4838, - "Intensity": 0, - "Frequency": 2 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 4838, - "StartTime": 30, - "Parameters": { - "Intensity": 57, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.36, - "Frequency": 0 - }, - { - "Time": 339, - "Intensity": 0.76, - "Frequency": 2 - }, - { - "Time": 576, - "Intensity": 0.84, - "Frequency": 0 - }, - { - "Time": 997, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1301, - "Intensity": 0.87, - "Frequency": 0 - }, - { - "Time": 2032, - "Intensity": 0.97, - "Frequency": 3 - }, - { - "Time": 2424, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 2758, - "Intensity": 1, - "Frequency": 7 - }, - { - "Time": 3038, - "Intensity": 0.92, - "Frequency": 8 - }, - { - "Time": 3227, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 3851, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 4122, - "Intensity": 0.4, - "Frequency": 9 - }, - { - "Time": 4417, - "Intensity": 0.36, - "Frequency": 5 - }, - { - "Time": 4625, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 4838, - "Intensity": 0, - "Frequency": 2 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 4838, + "StartTime": 23, + "Parameters": { + "Intensity": 57, + "Frequency": 44, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.36, + "Frequency": 0 + }, + { + "Time": 339, + "Intensity": 0.76, + "Frequency": 2 + }, + { + "Time": 576, + "Intensity": 0.84, + "Frequency": 0 + }, + { + "Time": 997, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1301, + "Intensity": 0.87, + "Frequency": 0 + }, + { + "Time": 2032, + "Intensity": 0.97, + "Frequency": 3 + }, + { + "Time": 2424, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 2753, + "Intensity": 1, + "Frequency": 4 + }, + { + "Time": 2975, + "Intensity": 0.93, + "Frequency": 5 + }, + { + "Time": 3232, + "Intensity": 0.27, + "Frequency": 0 + }, + { + "Time": 3851, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 4107, + "Intensity": 0.44, + "Frequency": 11 + }, + { + "Time": 4354, + "Intensity": 0.4, + "Frequency": 16 + }, + { + "Time": 4519, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 4838, + "Intensity": 0, + "Frequency": 2 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 4838, + "StartTime": 30, + "Parameters": { + "Intensity": 57, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.36, + "Frequency": 0 + }, + { + "Time": 339, + "Intensity": 0.76, + "Frequency": 2 + }, + { + "Time": 576, + "Intensity": 0.84, + "Frequency": 0 + }, + { + "Time": 997, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1301, + "Intensity": 0.87, + "Frequency": 0 + }, + { + "Time": 2032, + "Intensity": 0.97, + "Frequency": 3 + }, + { + "Time": 2424, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 2758, + "Intensity": 1, + "Frequency": 7 + }, + { + "Time": 3038, + "Intensity": 0.92, + "Frequency": 8 + }, + { + "Time": 3227, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 3851, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 4122, + "Intensity": 0.4, + "Frequency": 9 + }, + { + "Time": 4417, + "Intensity": 0.36, + "Frequency": 5 + }, + { + "Time": 4625, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 4838, + "Intensity": 0, + "Frequency": 2 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_m.json index 1ef16f9bd9926d13edee62df16ecc3a37971cd16..7d111202177fdaab8d97ad62db893613824b5e81 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CarSkid_m.json @@ -1,203 +1,203 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 4838, - "StartTime": 23, - "Parameters": { - "Intensity": 76, - "Frequency": 44, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.36, - "Frequency": 0 - }, - { - "Time": 339, - "Intensity": 0.76, - "Frequency": 2 - }, - { - "Time": 576, - "Intensity": 0.84, - "Frequency": 0 - }, - { - "Time": 997, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1301, - "Intensity": 0.87, - "Frequency": 0 - }, - { - "Time": 2032, - "Intensity": 0.97, - "Frequency": 3 - }, - { - "Time": 2424, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 2753, - "Intensity": 1, - "Frequency": 4 - }, - { - "Time": 2975, - "Intensity": 0.93, - "Frequency": 5 - }, - { - "Time": 3232, - "Intensity": 0.27, - "Frequency": 0 - }, - { - "Time": 3851, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 4107, - "Intensity": 0.44, - "Frequency": 11 - }, - { - "Time": 4354, - "Intensity": 0.4, - "Frequency": 16 - }, - { - "Time": 4519, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 4838, - "Intensity": 0, - "Frequency": 2 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 4838, - "StartTime": 30, - "Parameters": { - "Intensity": 76, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.36, - "Frequency": 0 - }, - { - "Time": 339, - "Intensity": 0.76, - "Frequency": 2 - }, - { - "Time": 576, - "Intensity": 0.84, - "Frequency": 0 - }, - { - "Time": 997, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1301, - "Intensity": 0.87, - "Frequency": 0 - }, - { - "Time": 2032, - "Intensity": 0.97, - "Frequency": 3 - }, - { - "Time": 2424, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 2758, - "Intensity": 1, - "Frequency": 7 - }, - { - "Time": 3038, - "Intensity": 0.92, - "Frequency": 8 - }, - { - "Time": 3227, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 3851, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 4122, - "Intensity": 0.4, - "Frequency": 9 - }, - { - "Time": 4417, - "Intensity": 0.36, - "Frequency": 5 - }, - { - "Time": 4625, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 4838, - "Intensity": 0, - "Frequency": 2 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 4838, + "StartTime": 23, + "Parameters": { + "Intensity": 76, + "Frequency": 44, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.36, + "Frequency": 0 + }, + { + "Time": 339, + "Intensity": 0.76, + "Frequency": 2 + }, + { + "Time": 576, + "Intensity": 0.84, + "Frequency": 0 + }, + { + "Time": 997, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1301, + "Intensity": 0.87, + "Frequency": 0 + }, + { + "Time": 2032, + "Intensity": 0.97, + "Frequency": 3 + }, + { + "Time": 2424, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 2753, + "Intensity": 1, + "Frequency": 4 + }, + { + "Time": 2975, + "Intensity": 0.93, + "Frequency": 5 + }, + { + "Time": 3232, + "Intensity": 0.27, + "Frequency": 0 + }, + { + "Time": 3851, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 4107, + "Intensity": 0.44, + "Frequency": 11 + }, + { + "Time": 4354, + "Intensity": 0.4, + "Frequency": 16 + }, + { + "Time": 4519, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 4838, + "Intensity": 0, + "Frequency": 2 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 4838, + "StartTime": 30, + "Parameters": { + "Intensity": 76, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.36, + "Frequency": 0 + }, + { + "Time": 339, + "Intensity": 0.76, + "Frequency": 2 + }, + { + "Time": 576, + "Intensity": 0.84, + "Frequency": 0 + }, + { + "Time": 997, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1301, + "Intensity": 0.87, + "Frequency": 0 + }, + { + "Time": 2032, + "Intensity": 0.97, + "Frequency": 3 + }, + { + "Time": 2424, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 2758, + "Intensity": 1, + "Frequency": 7 + }, + { + "Time": 3038, + "Intensity": 0.92, + "Frequency": 8 + }, + { + "Time": 3227, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 3851, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 4122, + "Intensity": 0.4, + "Frequency": 9 + }, + { + "Time": 4417, + "Intensity": 0.36, + "Frequency": 5 + }, + { + "Time": 4625, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 4838, + "Intensity": 0, + "Frequency": 2 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_h.json index 9778004e6877d0c3248e270d9b8b458fcf7bb8cd..b984d8e9d3fd9f048ed1e0760bd0d64e1070e36c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_h.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 8, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 8, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_l.json index b90f5994d4e155e2125a02c6ddace7a168259b0e..e3281ce53f6607a821592c069147e830ced5976c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_l.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 8, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 8, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_m.json index 554b435b35fdf690539d3b066344d408ee7a1fdd..c8503d44ddc48298cb684f84658f502251f8d9b2 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Claves_m.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 8, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 8, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_h.json index ae856f6eb6899626113f6c9086ed2be072d8398a..164f6aa65eb455351b10929435488bf35078f4ee 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_h.json @@ -1,116 +1,116 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 0, - "Parameters": { - "Intensity": 100, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 54, - "StartTime": 40, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 103, - "Parameters": { - "Intensity": 79, - "Frequency": 69 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 180, - "Parameters": { - "Intensity": 53, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 239, - "Parameters": { - "Intensity": 51, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 319, - "Parameters": { - "Intensity": 37, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 350, - "Parameters": { - "Intensity": 24, - "Frequency": 44 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 0, + "Parameters": { + "Intensity": 100, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 54, + "StartTime": 40, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 103, + "Parameters": { + "Intensity": 79, + "Frequency": 69 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 180, + "Parameters": { + "Intensity": 53, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 239, + "Parameters": { + "Intensity": 51, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 319, + "Parameters": { + "Intensity": 37, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 350, + "Parameters": { + "Intensity": 24, + "Frequency": 44 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_l.json index de063457a4549dedba5f95ed7b0e1253a10b6d7a..98a5fab392887e08d0a6a94ffd9000740f6e152d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_l.json @@ -1,116 +1,116 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 54, - "StartTime": 40, - "Parameters": { - "Intensity": 22, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 103, - "Parameters": { - "Intensity": 47, - "Frequency": 69 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 180, - "Parameters": { - "Intensity": 31, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 239, - "Parameters": { - "Intensity": 30, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 319, - "Parameters": { - "Intensity": 22, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 350, - "Parameters": { - "Intensity": 14, - "Frequency": 44 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 54, + "StartTime": 40, + "Parameters": { + "Intensity": 22, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 103, + "Parameters": { + "Intensity": 47, + "Frequency": 69 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 180, + "Parameters": { + "Intensity": 31, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 239, + "Parameters": { + "Intensity": 30, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 319, + "Parameters": { + "Intensity": 22, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 350, + "Parameters": { + "Intensity": 14, + "Frequency": 44 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_m.json index 88b2160afd1046dbb4df2abfab5ee6adf7a4d535..31efc482f7c91bfc3cc20c9ef5f03855c57cabfd 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/CoinDrop_m.json @@ -1,116 +1,116 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 0, - "Parameters": { - "Intensity": 80, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 54, - "StartTime": 40, - "Parameters": { - "Intensity": 30, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 103, - "Parameters": { - "Intensity": 63, - "Frequency": 69 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 180, - "Parameters": { - "Intensity": 42, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 239, - "Parameters": { - "Intensity": 40, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 319, - "Parameters": { - "Intensity": 29, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 350, - "Parameters": { - "Intensity": 19, - "Frequency": 44 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 0, + "Parameters": { + "Intensity": 80, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 54, + "StartTime": 40, + "Parameters": { + "Intensity": 30, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 103, + "Parameters": { + "Intensity": 63, + "Frequency": 69 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 180, + "Parameters": { + "Intensity": 42, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 239, + "Parameters": { + "Intensity": 40, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 319, + "Parameters": { + "Intensity": 29, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 350, + "Parameters": { + "Intensity": 19, + "Frequency": 44 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_h.json index 76106e93d49d036e7ed52f435e99868a513a3ba7..edda5e767fa0908f1173d016c38d83dd93319657 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_h.json @@ -1,1327 +1,1327 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 0, - "Parameters": { - "Intensity": 70, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 12, - "Intensity": 0.59, - "Frequency": -47 - }, - { - "Time": 52, - "Intensity": 0.96, - "Frequency": -44 - }, - { - "Time": 100, - "Intensity": 0.53, - "Frequency": -42 - }, - { - "Time": 133, - "Intensity": 0.94, - "Frequency": -39 - }, - { - "Time": 172, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 210, - "Intensity": 0.38, - "Frequency": -50 - }, - { - "Time": 239, - "Intensity": 0.74, - "Frequency": -45 - }, - { - "Time": 287, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 7, - "Parameters": { - "Intensity": 66, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 18, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 55, - "Intensity": 0.85, - "Frequency": -44 - }, - { - "Time": 106, - "Intensity": 0.64, - "Frequency": -42 - }, - { - "Time": 136, - "Intensity": 0.91, - "Frequency": -39 - }, - { - "Time": 165, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 206, - "Intensity": 0.53, - "Frequency": -50 - }, - { - "Time": 225, - "Intensity": 0.69, - "Frequency": -45 - }, - { - "Time": 294, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 311, - "Parameters": { - "Intensity": 70, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 32, - "Intensity": 0.93, - "Frequency": -50 - }, - { - "Time": 86, - "Intensity": 0.83, - "Frequency": -47 - }, - { - "Time": 145, - "Intensity": 0.43, - "Frequency": -47 - }, - { - "Time": 196, - "Intensity": 1, - "Frequency": -41 - }, - { - "Time": 252, - "Intensity": 0.49, - "Frequency": -50 - }, - { - "Time": 280, - "Intensity": 0.86, - "Frequency": -38 - }, - { - "Time": 322, - "Intensity": 0.57, - "Frequency": -50 - }, - { - "Time": 336, - "Intensity": 0.95, - "Frequency": -38 - }, - { - "Time": 399, - "Intensity": 0.57, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 313, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 9, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 53, - "Intensity": 0.93, - "Frequency": -47 - }, - { - "Time": 114, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 149, - "Intensity": 0.59, - "Frequency": -46 - }, - { - "Time": 190, - "Intensity": 0.94, - "Frequency": -38 - }, - { - "Time": 236, - "Intensity": 0.69, - "Frequency": -50 - }, - { - "Time": 264, - "Intensity": 0.82, - "Frequency": -49 - }, - { - "Time": 310, - "Intensity": 0.74, - "Frequency": -46 - }, - { - "Time": 329, - "Intensity": 1, - "Frequency": -39 - }, - { - "Time": 394, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 714, - "Parameters": { - "Intensity": 71, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 5, - "Intensity": 0.73, - "Frequency": -39 - }, - { - "Time": 52, - "Intensity": 0.54, - "Frequency": -48 - }, - { - "Time": 96, - "Intensity": 0.68, - "Frequency": -50 - }, - { - "Time": 118, - "Intensity": 1, - "Frequency": -43 - }, - { - "Time": 161, - "Intensity": 0.81, - "Frequency": -47 - }, - { - "Time": 217, - "Intensity": 0.43, - "Frequency": -50 - }, - { - "Time": 299, - "Intensity": 0.61, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 716, - "Parameters": { - "Intensity": 65, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 5, - "Intensity": 0.76, - "Frequency": -40 - }, - { - "Time": 47, - "Intensity": 0.76, - "Frequency": -43 - }, - { - "Time": 79, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 119, - "Intensity": 1, - "Frequency": -41 - }, - { - "Time": 166, - "Intensity": 0.82, - "Frequency": -38 - }, - { - "Time": 202, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 296, - "Intensity": 0.65, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1016, - "Parameters": { - "Intensity": 74, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 21, - "Intensity": 0.66, - "Frequency": -44 - }, - { - "Time": 74, - "Intensity": 0.67, - "Frequency": -47 - }, - { - "Time": 102, - "Intensity": 0.83, - "Frequency": -38 - }, - { - "Time": 134, - "Intensity": 0.91, - "Frequency": -39 - }, - { - "Time": 147, - "Intensity": 0.74, - "Frequency": -47 - }, - { - "Time": 195, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 225, - "Intensity": 0.88, - "Frequency": -43 - }, - { - "Time": 295, - "Intensity": 0.7, - "Frequency": -45 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1017, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 14, - "Intensity": 0.69, - "Frequency": -47 - }, - { - "Time": 65, - "Intensity": 0.47, - "Frequency": -42 - }, - { - "Time": 95, - "Intensity": 0.75, - "Frequency": -34 - }, - { - "Time": 130, - "Intensity": 0.97, - "Frequency": -39 - }, - { - "Time": 167, - "Intensity": 0.62, - "Frequency": -50 - }, - { - "Time": 208, - "Intensity": 0.45, - "Frequency": -50 - }, - { - "Time": 226, - "Intensity": 0.99, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1323, - "Parameters": { - "Intensity": 72, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.46, - "Frequency": -39 - }, - { - "Time": 31, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 70, - "Intensity": 0.94, - "Frequency": -50 - }, - { - "Time": 115, - "Intensity": 0.79, - "Frequency": -37 - }, - { - "Time": 134, - "Intensity": 0.6, - "Frequency": -38 - }, - { - "Time": 154, - "Intensity": 0.77, - "Frequency": -47 - }, - { - "Time": 185, - "Intensity": 0.71, - "Frequency": -50 - }, - { - "Time": 217, - "Intensity": 0.57, - "Frequency": -48 - }, - { - "Time": 275, - "Intensity": 0.64, - "Frequency": -46 - }, - { - "Time": 297, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1327, - "Parameters": { - "Intensity": 67, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 2, - "Intensity": 0.42, - "Frequency": -47 - }, - { - "Time": 29, - "Intensity": 0.78, - "Frequency": -50 - }, - { - "Time": 74, - "Intensity": 0.95, - "Frequency": -45 - }, - { - "Time": 108, - "Intensity": 0.65, - "Frequency": -39 - }, - { - "Time": 131, - "Intensity": 0.39, - "Frequency": -45 - }, - { - "Time": 164, - "Intensity": 0.76, - "Frequency": -46 - }, - { - "Time": 194, - "Intensity": 0.69, - "Frequency": -43 - }, - { - "Time": 235, - "Intensity": 0.41, - "Frequency": -46 - }, - { - "Time": 264, - "Intensity": 0.6, - "Frequency": -41 - }, - { - "Time": 295, - "Intensity": 0.49, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1627, - "Parameters": { - "Intensity": 78, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.35, - "Frequency": -46 - }, - { - "Time": 37, - "Intensity": 0.65, - "Frequency": -47 - }, - { - "Time": 84, - "Intensity": 0.41, - "Frequency": -50 - }, - { - "Time": 128, - "Intensity": 0.94, - "Frequency": -46 - }, - { - "Time": 154, - "Intensity": 0.51, - "Frequency": -38 - }, - { - "Time": 179, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 212, - "Intensity": 0.58, - "Frequency": -49 - }, - { - "Time": 238, - "Intensity": 0.86, - "Frequency": -46 - }, - { - "Time": 277, - "Intensity": 0.79, - "Frequency": -39 - }, - { - "Time": 299, - "Intensity": 0.53, - "Frequency": -46 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1628, - "Parameters": { - "Intensity": 72, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 7, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 44, - "Intensity": 0.82, - "Frequency": -47 - }, - { - "Time": 82, - "Intensity": 0.5, - "Frequency": -50 - }, - { - "Time": 124, - "Intensity": 0.85, - "Frequency": -46 - }, - { - "Time": 154, - "Intensity": 0.53, - "Frequency": -38 - }, - { - "Time": 175, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 208, - "Intensity": 0.57, - "Frequency": -49 - }, - { - "Time": 230, - "Intensity": 0.82, - "Frequency": -46 - }, - { - "Time": 278, - "Intensity": 0.78, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 1929, - "Parameters": { - "Intensity": 74, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 24, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 82, - "Intensity": 0.62, - "Frequency": -44 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": -42 - }, - { - "Time": 186, - "Intensity": 0.72, - "Frequency": -39 - }, - { - "Time": 234, - "Intensity": 0.41, - "Frequency": -50 - }, - { - "Time": 278, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 328, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 392, - "Intensity": 0.54, - "Frequency": -47 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 1931, - "Parameters": { - "Intensity": 81, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 24, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 85, - "Intensity": 0.65, - "Frequency": -44 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": -42 - }, - { - "Time": 189, - "Intensity": 0.72, - "Frequency": -39 - }, - { - "Time": 241, - "Intensity": 0.34, - "Frequency": -50 - }, - { - "Time": 278, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 328, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 392, - "Intensity": 0.54, - "Frequency": -47 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 2332, - "Parameters": { - "Intensity": 75, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.39, - "Frequency": -47 - }, - { - "Time": 31, - "Intensity": 0.55, - "Frequency": -42 - }, - { - "Time": 81, - "Intensity": 0.5, - "Frequency": -34 - }, - { - "Time": 96, - "Intensity": 0.84, - "Frequency": -43 - }, - { - "Time": 145, - "Intensity": 0.71, - "Frequency": -50 - }, - { - "Time": 203, - "Intensity": 0.56, - "Frequency": -50 - }, - { - "Time": 242, - "Intensity": 0.84, - "Frequency": -44 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 2334, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 3, - "Intensity": 0.38, - "Frequency": -47 - }, - { - "Time": 18, - "Intensity": 0.7, - "Frequency": -42 - }, - { - "Time": 79, - "Intensity": 0.62, - "Frequency": -34 - }, - { - "Time": 95, - "Intensity": 0.88, - "Frequency": -39 - }, - { - "Time": 148, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 204, - "Intensity": 0.49, - "Frequency": -50 - }, - { - "Time": 242, - "Intensity": 0.84, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 2636, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 9, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 53, - "Intensity": 0.93, - "Frequency": -47 - }, - { - "Time": 105, - "Intensity": 0.62, - "Frequency": -50 - }, - { - "Time": 154, - "Intensity": 0.88, - "Frequency": -46 - }, - { - "Time": 196, - "Intensity": 0.75, - "Frequency": -38 - }, - { - "Time": 230, - "Intensity": 0.52, - "Frequency": -50 - }, - { - "Time": 254, - "Intensity": 0.92, - "Frequency": -49 - }, - { - "Time": 306, - "Intensity": 0.83, - "Frequency": -46 - }, - { - "Time": 329, - "Intensity": 1, - "Frequency": -48 - }, - { - "Time": 394, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 2637, - "Parameters": { - "Intensity": 71, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 17, - "Intensity": 0.44, - "Frequency": -50 - }, - { - "Time": 53, - "Intensity": 0.88, - "Frequency": -47 - }, - { - "Time": 123, - "Intensity": 0.61, - "Frequency": -47 - }, - { - "Time": 169, - "Intensity": 0.8, - "Frequency": -41 - }, - { - "Time": 224, - "Intensity": 0.52, - "Frequency": -50 - }, - { - "Time": 254, - "Intensity": 0.86, - "Frequency": -38 - }, - { - "Time": 311, - "Intensity": 0.68, - "Frequency": -50 - }, - { - "Time": 336, - "Intensity": 0.95, - "Frequency": -46 - }, - { - "Time": 388, - "Intensity": 0.66, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 3040, - "Parameters": { - "Intensity": 67, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 4, - "Intensity": 0.75, - "Frequency": -46 - }, - { - "Time": 49, - "Intensity": 0.52, - "Frequency": -43 - }, - { - "Time": 88, - "Intensity": 0.65, - "Frequency": -50 - }, - { - "Time": 114, - "Intensity": 0.85, - "Frequency": -41 - }, - { - "Time": 163, - "Intensity": 0.74, - "Frequency": -38 - }, - { - "Time": 202, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 296, - "Intensity": 0.65, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 301, - "StartTime": 3044, - "Parameters": { - "Intensity": 74, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 10, - "Intensity": 0.71, - "Frequency": -46 - }, - { - "Time": 46, - "Intensity": 0.47, - "Frequency": -48 - }, - { - "Time": 80, - "Intensity": 0.61, - "Frequency": -50 - }, - { - "Time": 100, - "Intensity": 0.92, - "Frequency": -43 - }, - { - "Time": 156, - "Intensity": 0.76, - "Frequency": -47 - }, - { - "Time": 212, - "Intensity": 0.44, - "Frequency": -50 - }, - { - "Time": 298, - "Intensity": 0.61, - "Frequency": -38 - }, - { - "Time": 301, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 0, + "Parameters": { + "Intensity": 70, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 12, + "Intensity": 0.59, + "Frequency": -47 + }, + { + "Time": 52, + "Intensity": 0.96, + "Frequency": -44 + }, + { + "Time": 100, + "Intensity": 0.53, + "Frequency": -42 + }, + { + "Time": 133, + "Intensity": 0.94, + "Frequency": -39 + }, + { + "Time": 172, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 210, + "Intensity": 0.38, + "Frequency": -50 + }, + { + "Time": 239, + "Intensity": 0.74, + "Frequency": -45 + }, + { + "Time": 287, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 7, + "Parameters": { + "Intensity": 66, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 18, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 55, + "Intensity": 0.85, + "Frequency": -44 + }, + { + "Time": 106, + "Intensity": 0.64, + "Frequency": -42 + }, + { + "Time": 136, + "Intensity": 0.91, + "Frequency": -39 + }, + { + "Time": 165, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 206, + "Intensity": 0.53, + "Frequency": -50 + }, + { + "Time": 225, + "Intensity": 0.69, + "Frequency": -45 + }, + { + "Time": 294, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 311, + "Parameters": { + "Intensity": 70, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 32, + "Intensity": 0.93, + "Frequency": -50 + }, + { + "Time": 86, + "Intensity": 0.83, + "Frequency": -47 + }, + { + "Time": 145, + "Intensity": 0.43, + "Frequency": -47 + }, + { + "Time": 196, + "Intensity": 1, + "Frequency": -41 + }, + { + "Time": 252, + "Intensity": 0.49, + "Frequency": -50 + }, + { + "Time": 280, + "Intensity": 0.86, + "Frequency": -38 + }, + { + "Time": 322, + "Intensity": 0.57, + "Frequency": -50 + }, + { + "Time": 336, + "Intensity": 0.95, + "Frequency": -38 + }, + { + "Time": 399, + "Intensity": 0.57, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 313, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 9, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 53, + "Intensity": 0.93, + "Frequency": -47 + }, + { + "Time": 114, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 149, + "Intensity": 0.59, + "Frequency": -46 + }, + { + "Time": 190, + "Intensity": 0.94, + "Frequency": -38 + }, + { + "Time": 236, + "Intensity": 0.69, + "Frequency": -50 + }, + { + "Time": 264, + "Intensity": 0.82, + "Frequency": -49 + }, + { + "Time": 310, + "Intensity": 0.74, + "Frequency": -46 + }, + { + "Time": 329, + "Intensity": 1, + "Frequency": -39 + }, + { + "Time": 394, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 714, + "Parameters": { + "Intensity": 71, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 5, + "Intensity": 0.73, + "Frequency": -39 + }, + { + "Time": 52, + "Intensity": 0.54, + "Frequency": -48 + }, + { + "Time": 96, + "Intensity": 0.68, + "Frequency": -50 + }, + { + "Time": 118, + "Intensity": 1, + "Frequency": -43 + }, + { + "Time": 161, + "Intensity": 0.81, + "Frequency": -47 + }, + { + "Time": 217, + "Intensity": 0.43, + "Frequency": -50 + }, + { + "Time": 299, + "Intensity": 0.61, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 716, + "Parameters": { + "Intensity": 65, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 5, + "Intensity": 0.76, + "Frequency": -40 + }, + { + "Time": 47, + "Intensity": 0.76, + "Frequency": -43 + }, + { + "Time": 79, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 119, + "Intensity": 1, + "Frequency": -41 + }, + { + "Time": 166, + "Intensity": 0.82, + "Frequency": -38 + }, + { + "Time": 202, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 296, + "Intensity": 0.65, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1016, + "Parameters": { + "Intensity": 74, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 21, + "Intensity": 0.66, + "Frequency": -44 + }, + { + "Time": 74, + "Intensity": 0.67, + "Frequency": -47 + }, + { + "Time": 102, + "Intensity": 0.83, + "Frequency": -38 + }, + { + "Time": 134, + "Intensity": 0.91, + "Frequency": -39 + }, + { + "Time": 147, + "Intensity": 0.74, + "Frequency": -47 + }, + { + "Time": 195, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 225, + "Intensity": 0.88, + "Frequency": -43 + }, + { + "Time": 295, + "Intensity": 0.7, + "Frequency": -45 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1017, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 14, + "Intensity": 0.69, + "Frequency": -47 + }, + { + "Time": 65, + "Intensity": 0.47, + "Frequency": -42 + }, + { + "Time": 95, + "Intensity": 0.75, + "Frequency": -34 + }, + { + "Time": 130, + "Intensity": 0.97, + "Frequency": -39 + }, + { + "Time": 167, + "Intensity": 0.62, + "Frequency": -50 + }, + { + "Time": 208, + "Intensity": 0.45, + "Frequency": -50 + }, + { + "Time": 226, + "Intensity": 0.99, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1323, + "Parameters": { + "Intensity": 72, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.46, + "Frequency": -39 + }, + { + "Time": 31, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 70, + "Intensity": 0.94, + "Frequency": -50 + }, + { + "Time": 115, + "Intensity": 0.79, + "Frequency": -37 + }, + { + "Time": 134, + "Intensity": 0.6, + "Frequency": -38 + }, + { + "Time": 154, + "Intensity": 0.77, + "Frequency": -47 + }, + { + "Time": 185, + "Intensity": 0.71, + "Frequency": -50 + }, + { + "Time": 217, + "Intensity": 0.57, + "Frequency": -48 + }, + { + "Time": 275, + "Intensity": 0.64, + "Frequency": -46 + }, + { + "Time": 297, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1327, + "Parameters": { + "Intensity": 67, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 2, + "Intensity": 0.42, + "Frequency": -47 + }, + { + "Time": 29, + "Intensity": 0.78, + "Frequency": -50 + }, + { + "Time": 74, + "Intensity": 0.95, + "Frequency": -45 + }, + { + "Time": 108, + "Intensity": 0.65, + "Frequency": -39 + }, + { + "Time": 131, + "Intensity": 0.39, + "Frequency": -45 + }, + { + "Time": 164, + "Intensity": 0.76, + "Frequency": -46 + }, + { + "Time": 194, + "Intensity": 0.69, + "Frequency": -43 + }, + { + "Time": 235, + "Intensity": 0.41, + "Frequency": -46 + }, + { + "Time": 264, + "Intensity": 0.6, + "Frequency": -41 + }, + { + "Time": 295, + "Intensity": 0.49, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1627, + "Parameters": { + "Intensity": 78, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.35, + "Frequency": -46 + }, + { + "Time": 37, + "Intensity": 0.65, + "Frequency": -47 + }, + { + "Time": 84, + "Intensity": 0.41, + "Frequency": -50 + }, + { + "Time": 128, + "Intensity": 0.94, + "Frequency": -46 + }, + { + "Time": 154, + "Intensity": 0.51, + "Frequency": -38 + }, + { + "Time": 179, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 212, + "Intensity": 0.58, + "Frequency": -49 + }, + { + "Time": 238, + "Intensity": 0.86, + "Frequency": -46 + }, + { + "Time": 277, + "Intensity": 0.79, + "Frequency": -39 + }, + { + "Time": 299, + "Intensity": 0.53, + "Frequency": -46 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1628, + "Parameters": { + "Intensity": 72, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 7, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 44, + "Intensity": 0.82, + "Frequency": -47 + }, + { + "Time": 82, + "Intensity": 0.5, + "Frequency": -50 + }, + { + "Time": 124, + "Intensity": 0.85, + "Frequency": -46 + }, + { + "Time": 154, + "Intensity": 0.53, + "Frequency": -38 + }, + { + "Time": 175, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 208, + "Intensity": 0.57, + "Frequency": -49 + }, + { + "Time": 230, + "Intensity": 0.82, + "Frequency": -46 + }, + { + "Time": 278, + "Intensity": 0.78, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 1929, + "Parameters": { + "Intensity": 74, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 24, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 82, + "Intensity": 0.62, + "Frequency": -44 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": -42 + }, + { + "Time": 186, + "Intensity": 0.72, + "Frequency": -39 + }, + { + "Time": 234, + "Intensity": 0.41, + "Frequency": -50 + }, + { + "Time": 278, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 328, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 392, + "Intensity": 0.54, + "Frequency": -47 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 1931, + "Parameters": { + "Intensity": 81, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 24, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 85, + "Intensity": 0.65, + "Frequency": -44 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": -42 + }, + { + "Time": 189, + "Intensity": 0.72, + "Frequency": -39 + }, + { + "Time": 241, + "Intensity": 0.34, + "Frequency": -50 + }, + { + "Time": 278, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 328, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 392, + "Intensity": 0.54, + "Frequency": -47 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 2332, + "Parameters": { + "Intensity": 75, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.39, + "Frequency": -47 + }, + { + "Time": 31, + "Intensity": 0.55, + "Frequency": -42 + }, + { + "Time": 81, + "Intensity": 0.5, + "Frequency": -34 + }, + { + "Time": 96, + "Intensity": 0.84, + "Frequency": -43 + }, + { + "Time": 145, + "Intensity": 0.71, + "Frequency": -50 + }, + { + "Time": 203, + "Intensity": 0.56, + "Frequency": -50 + }, + { + "Time": 242, + "Intensity": 0.84, + "Frequency": -44 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 2334, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 3, + "Intensity": 0.38, + "Frequency": -47 + }, + { + "Time": 18, + "Intensity": 0.7, + "Frequency": -42 + }, + { + "Time": 79, + "Intensity": 0.62, + "Frequency": -34 + }, + { + "Time": 95, + "Intensity": 0.88, + "Frequency": -39 + }, + { + "Time": 148, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 204, + "Intensity": 0.49, + "Frequency": -50 + }, + { + "Time": 242, + "Intensity": 0.84, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 2636, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 9, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 53, + "Intensity": 0.93, + "Frequency": -47 + }, + { + "Time": 105, + "Intensity": 0.62, + "Frequency": -50 + }, + { + "Time": 154, + "Intensity": 0.88, + "Frequency": -46 + }, + { + "Time": 196, + "Intensity": 0.75, + "Frequency": -38 + }, + { + "Time": 230, + "Intensity": 0.52, + "Frequency": -50 + }, + { + "Time": 254, + "Intensity": 0.92, + "Frequency": -49 + }, + { + "Time": 306, + "Intensity": 0.83, + "Frequency": -46 + }, + { + "Time": 329, + "Intensity": 1, + "Frequency": -48 + }, + { + "Time": 394, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 2637, + "Parameters": { + "Intensity": 71, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 17, + "Intensity": 0.44, + "Frequency": -50 + }, + { + "Time": 53, + "Intensity": 0.88, + "Frequency": -47 + }, + { + "Time": 123, + "Intensity": 0.61, + "Frequency": -47 + }, + { + "Time": 169, + "Intensity": 0.8, + "Frequency": -41 + }, + { + "Time": 224, + "Intensity": 0.52, + "Frequency": -50 + }, + { + "Time": 254, + "Intensity": 0.86, + "Frequency": -38 + }, + { + "Time": 311, + "Intensity": 0.68, + "Frequency": -50 + }, + { + "Time": 336, + "Intensity": 0.95, + "Frequency": -46 + }, + { + "Time": 388, + "Intensity": 0.66, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 3040, + "Parameters": { + "Intensity": 67, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 4, + "Intensity": 0.75, + "Frequency": -46 + }, + { + "Time": 49, + "Intensity": 0.52, + "Frequency": -43 + }, + { + "Time": 88, + "Intensity": 0.65, + "Frequency": -50 + }, + { + "Time": 114, + "Intensity": 0.85, + "Frequency": -41 + }, + { + "Time": 163, + "Intensity": 0.74, + "Frequency": -38 + }, + { + "Time": 202, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 296, + "Intensity": 0.65, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 301, + "StartTime": 3044, + "Parameters": { + "Intensity": 74, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 10, + "Intensity": 0.71, + "Frequency": -46 + }, + { + "Time": 46, + "Intensity": 0.47, + "Frequency": -48 + }, + { + "Time": 80, + "Intensity": 0.61, + "Frequency": -50 + }, + { + "Time": 100, + "Intensity": 0.92, + "Frequency": -43 + }, + { + "Time": 156, + "Intensity": 0.76, + "Frequency": -47 + }, + { + "Time": 212, + "Intensity": 0.44, + "Frequency": -50 + }, + { + "Time": 298, + "Intensity": 0.61, + "Frequency": -38 + }, + { + "Time": 301, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_l.json index 0aaebbc6d8730d93998f478d65b125c21c0828c4..b126ec6ca1c9f42c9a7be15c284f89351aafe783 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_l.json @@ -1,1327 +1,1327 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 0, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 12, - "Intensity": 0.59, - "Frequency": -47 - }, - { - "Time": 52, - "Intensity": 0.96, - "Frequency": -44 - }, - { - "Time": 100, - "Intensity": 0.53, - "Frequency": -42 - }, - { - "Time": 133, - "Intensity": 0.94, - "Frequency": -39 - }, - { - "Time": 172, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 210, - "Intensity": 0.38, - "Frequency": -50 - }, - { - "Time": 239, - "Intensity": 0.74, - "Frequency": -45 - }, - { - "Time": 287, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 7, - "Parameters": { - "Intensity": 39, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 18, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 55, - "Intensity": 0.85, - "Frequency": -44 - }, - { - "Time": 106, - "Intensity": 0.64, - "Frequency": -42 - }, - { - "Time": 136, - "Intensity": 0.91, - "Frequency": -39 - }, - { - "Time": 165, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 206, - "Intensity": 0.53, - "Frequency": -50 - }, - { - "Time": 225, - "Intensity": 0.69, - "Frequency": -45 - }, - { - "Time": 294, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 311, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 32, - "Intensity": 0.93, - "Frequency": -50 - }, - { - "Time": 86, - "Intensity": 0.83, - "Frequency": -47 - }, - { - "Time": 145, - "Intensity": 0.43, - "Frequency": -47 - }, - { - "Time": 196, - "Intensity": 1, - "Frequency": -41 - }, - { - "Time": 252, - "Intensity": 0.49, - "Frequency": -50 - }, - { - "Time": 280, - "Intensity": 0.86, - "Frequency": -38 - }, - { - "Time": 322, - "Intensity": 0.57, - "Frequency": -50 - }, - { - "Time": 336, - "Intensity": 0.95, - "Frequency": -38 - }, - { - "Time": 399, - "Intensity": 0.57, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 313, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 9, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 53, - "Intensity": 0.93, - "Frequency": -47 - }, - { - "Time": 114, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 149, - "Intensity": 0.59, - "Frequency": -46 - }, - { - "Time": 190, - "Intensity": 0.94, - "Frequency": -38 - }, - { - "Time": 236, - "Intensity": 0.69, - "Frequency": -50 - }, - { - "Time": 264, - "Intensity": 0.82, - "Frequency": -49 - }, - { - "Time": 310, - "Intensity": 0.74, - "Frequency": -46 - }, - { - "Time": 329, - "Intensity": 1, - "Frequency": -39 - }, - { - "Time": 394, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 714, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 5, - "Intensity": 0.73, - "Frequency": -39 - }, - { - "Time": 52, - "Intensity": 0.54, - "Frequency": -48 - }, - { - "Time": 96, - "Intensity": 0.68, - "Frequency": -50 - }, - { - "Time": 118, - "Intensity": 1, - "Frequency": -43 - }, - { - "Time": 161, - "Intensity": 0.81, - "Frequency": -47 - }, - { - "Time": 217, - "Intensity": 0.43, - "Frequency": -50 - }, - { - "Time": 299, - "Intensity": 0.61, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 716, - "Parameters": { - "Intensity": 39, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 5, - "Intensity": 0.76, - "Frequency": -40 - }, - { - "Time": 47, - "Intensity": 0.76, - "Frequency": -43 - }, - { - "Time": 79, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 119, - "Intensity": 1, - "Frequency": -41 - }, - { - "Time": 166, - "Intensity": 0.82, - "Frequency": -38 - }, - { - "Time": 202, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 296, - "Intensity": 0.65, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1016, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 21, - "Intensity": 0.66, - "Frequency": -44 - }, - { - "Time": 74, - "Intensity": 0.67, - "Frequency": -47 - }, - { - "Time": 102, - "Intensity": 0.83, - "Frequency": -38 - }, - { - "Time": 134, - "Intensity": 0.91, - "Frequency": -39 - }, - { - "Time": 147, - "Intensity": 0.74, - "Frequency": -47 - }, - { - "Time": 195, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 225, - "Intensity": 0.88, - "Frequency": -43 - }, - { - "Time": 295, - "Intensity": 0.7, - "Frequency": -45 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1017, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 14, - "Intensity": 0.69, - "Frequency": -47 - }, - { - "Time": 65, - "Intensity": 0.47, - "Frequency": -42 - }, - { - "Time": 95, - "Intensity": 0.75, - "Frequency": -34 - }, - { - "Time": 130, - "Intensity": 0.97, - "Frequency": -39 - }, - { - "Time": 167, - "Intensity": 0.62, - "Frequency": -50 - }, - { - "Time": 208, - "Intensity": 0.45, - "Frequency": -50 - }, - { - "Time": 226, - "Intensity": 0.99, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1323, - "Parameters": { - "Intensity": 43, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.46, - "Frequency": -39 - }, - { - "Time": 31, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 70, - "Intensity": 0.94, - "Frequency": -50 - }, - { - "Time": 115, - "Intensity": 0.79, - "Frequency": -37 - }, - { - "Time": 134, - "Intensity": 0.6, - "Frequency": -38 - }, - { - "Time": 154, - "Intensity": 0.77, - "Frequency": -47 - }, - { - "Time": 185, - "Intensity": 0.71, - "Frequency": -50 - }, - { - "Time": 217, - "Intensity": 0.57, - "Frequency": -48 - }, - { - "Time": 275, - "Intensity": 0.64, - "Frequency": -46 - }, - { - "Time": 297, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1327, - "Parameters": { - "Intensity": 40, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 2, - "Intensity": 0.42, - "Frequency": -47 - }, - { - "Time": 29, - "Intensity": 0.78, - "Frequency": -50 - }, - { - "Time": 74, - "Intensity": 0.95, - "Frequency": -45 - }, - { - "Time": 108, - "Intensity": 0.65, - "Frequency": -39 - }, - { - "Time": 131, - "Intensity": 0.39, - "Frequency": -45 - }, - { - "Time": 164, - "Intensity": 0.76, - "Frequency": -46 - }, - { - "Time": 194, - "Intensity": 0.69, - "Frequency": -43 - }, - { - "Time": 235, - "Intensity": 0.41, - "Frequency": -46 - }, - { - "Time": 264, - "Intensity": 0.6, - "Frequency": -41 - }, - { - "Time": 295, - "Intensity": 0.49, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1627, - "Parameters": { - "Intensity": 46, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.35, - "Frequency": -46 - }, - { - "Time": 37, - "Intensity": 0.65, - "Frequency": -47 - }, - { - "Time": 84, - "Intensity": 0.41, - "Frequency": -50 - }, - { - "Time": 128, - "Intensity": 0.94, - "Frequency": -46 - }, - { - "Time": 154, - "Intensity": 0.51, - "Frequency": -38 - }, - { - "Time": 179, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 212, - "Intensity": 0.58, - "Frequency": -49 - }, - { - "Time": 238, - "Intensity": 0.86, - "Frequency": -46 - }, - { - "Time": 277, - "Intensity": 0.79, - "Frequency": -39 - }, - { - "Time": 299, - "Intensity": 0.53, - "Frequency": -46 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1628, - "Parameters": { - "Intensity": 43, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 7, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 44, - "Intensity": 0.82, - "Frequency": -47 - }, - { - "Time": 82, - "Intensity": 0.5, - "Frequency": -50 - }, - { - "Time": 124, - "Intensity": 0.85, - "Frequency": -46 - }, - { - "Time": 154, - "Intensity": 0.53, - "Frequency": -38 - }, - { - "Time": 175, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 208, - "Intensity": 0.57, - "Frequency": -49 - }, - { - "Time": 230, - "Intensity": 0.82, - "Frequency": -46 - }, - { - "Time": 278, - "Intensity": 0.78, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 1929, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 24, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 82, - "Intensity": 0.62, - "Frequency": -44 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": -42 - }, - { - "Time": 186, - "Intensity": 0.72, - "Frequency": -39 - }, - { - "Time": 234, - "Intensity": 0.41, - "Frequency": -50 - }, - { - "Time": 278, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 328, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 392, - "Intensity": 0.54, - "Frequency": -47 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 1931, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 24, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 85, - "Intensity": 0.65, - "Frequency": -44 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": -42 - }, - { - "Time": 189, - "Intensity": 0.72, - "Frequency": -39 - }, - { - "Time": 241, - "Intensity": 0.34, - "Frequency": -50 - }, - { - "Time": 278, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 328, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 392, - "Intensity": 0.54, - "Frequency": -47 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 2332, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.39, - "Frequency": -47 - }, - { - "Time": 31, - "Intensity": 0.55, - "Frequency": -42 - }, - { - "Time": 81, - "Intensity": 0.5, - "Frequency": -34 - }, - { - "Time": 96, - "Intensity": 0.84, - "Frequency": -43 - }, - { - "Time": 145, - "Intensity": 0.71, - "Frequency": -50 - }, - { - "Time": 203, - "Intensity": 0.56, - "Frequency": -50 - }, - { - "Time": 242, - "Intensity": 0.84, - "Frequency": -44 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 2334, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 3, - "Intensity": 0.38, - "Frequency": -47 - }, - { - "Time": 18, - "Intensity": 0.7, - "Frequency": -42 - }, - { - "Time": 79, - "Intensity": 0.62, - "Frequency": -34 - }, - { - "Time": 95, - "Intensity": 0.88, - "Frequency": -39 - }, - { - "Time": 148, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 204, - "Intensity": 0.49, - "Frequency": -50 - }, - { - "Time": 242, - "Intensity": 0.84, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 2636, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 9, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 53, - "Intensity": 0.93, - "Frequency": -47 - }, - { - "Time": 105, - "Intensity": 0.62, - "Frequency": -50 - }, - { - "Time": 154, - "Intensity": 0.88, - "Frequency": -46 - }, - { - "Time": 196, - "Intensity": 0.75, - "Frequency": -38 - }, - { - "Time": 230, - "Intensity": 0.52, - "Frequency": -50 - }, - { - "Time": 254, - "Intensity": 0.92, - "Frequency": -49 - }, - { - "Time": 306, - "Intensity": 0.83, - "Frequency": -46 - }, - { - "Time": 329, - "Intensity": 1, - "Frequency": -48 - }, - { - "Time": 394, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 2637, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 17, - "Intensity": 0.44, - "Frequency": -50 - }, - { - "Time": 53, - "Intensity": 0.88, - "Frequency": -47 - }, - { - "Time": 123, - "Intensity": 0.61, - "Frequency": -47 - }, - { - "Time": 169, - "Intensity": 0.8, - "Frequency": -41 - }, - { - "Time": 224, - "Intensity": 0.52, - "Frequency": -50 - }, - { - "Time": 254, - "Intensity": 0.86, - "Frequency": -38 - }, - { - "Time": 311, - "Intensity": 0.68, - "Frequency": -50 - }, - { - "Time": 336, - "Intensity": 0.95, - "Frequency": -46 - }, - { - "Time": 388, - "Intensity": 0.66, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 3040, - "Parameters": { - "Intensity": 40, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 4, - "Intensity": 0.75, - "Frequency": -46 - }, - { - "Time": 49, - "Intensity": 0.52, - "Frequency": -43 - }, - { - "Time": 88, - "Intensity": 0.65, - "Frequency": -50 - }, - { - "Time": 114, - "Intensity": 0.85, - "Frequency": -41 - }, - { - "Time": 163, - "Intensity": 0.74, - "Frequency": -38 - }, - { - "Time": 202, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 296, - "Intensity": 0.65, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 301, - "StartTime": 3044, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 10, - "Intensity": 0.71, - "Frequency": -46 - }, - { - "Time": 46, - "Intensity": 0.47, - "Frequency": -48 - }, - { - "Time": 80, - "Intensity": 0.61, - "Frequency": -50 - }, - { - "Time": 100, - "Intensity": 0.92, - "Frequency": -43 - }, - { - "Time": 156, - "Intensity": 0.76, - "Frequency": -47 - }, - { - "Time": 212, - "Intensity": 0.44, - "Frequency": -50 - }, - { - "Time": 298, - "Intensity": 0.61, - "Frequency": -38 - }, - { - "Time": 301, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 0, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 12, + "Intensity": 0.59, + "Frequency": -47 + }, + { + "Time": 52, + "Intensity": 0.96, + "Frequency": -44 + }, + { + "Time": 100, + "Intensity": 0.53, + "Frequency": -42 + }, + { + "Time": 133, + "Intensity": 0.94, + "Frequency": -39 + }, + { + "Time": 172, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 210, + "Intensity": 0.38, + "Frequency": -50 + }, + { + "Time": 239, + "Intensity": 0.74, + "Frequency": -45 + }, + { + "Time": 287, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 7, + "Parameters": { + "Intensity": 39, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 18, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 55, + "Intensity": 0.85, + "Frequency": -44 + }, + { + "Time": 106, + "Intensity": 0.64, + "Frequency": -42 + }, + { + "Time": 136, + "Intensity": 0.91, + "Frequency": -39 + }, + { + "Time": 165, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 206, + "Intensity": 0.53, + "Frequency": -50 + }, + { + "Time": 225, + "Intensity": 0.69, + "Frequency": -45 + }, + { + "Time": 294, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 311, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 32, + "Intensity": 0.93, + "Frequency": -50 + }, + { + "Time": 86, + "Intensity": 0.83, + "Frequency": -47 + }, + { + "Time": 145, + "Intensity": 0.43, + "Frequency": -47 + }, + { + "Time": 196, + "Intensity": 1, + "Frequency": -41 + }, + { + "Time": 252, + "Intensity": 0.49, + "Frequency": -50 + }, + { + "Time": 280, + "Intensity": 0.86, + "Frequency": -38 + }, + { + "Time": 322, + "Intensity": 0.57, + "Frequency": -50 + }, + { + "Time": 336, + "Intensity": 0.95, + "Frequency": -38 + }, + { + "Time": 399, + "Intensity": 0.57, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 313, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 9, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 53, + "Intensity": 0.93, + "Frequency": -47 + }, + { + "Time": 114, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 149, + "Intensity": 0.59, + "Frequency": -46 + }, + { + "Time": 190, + "Intensity": 0.94, + "Frequency": -38 + }, + { + "Time": 236, + "Intensity": 0.69, + "Frequency": -50 + }, + { + "Time": 264, + "Intensity": 0.82, + "Frequency": -49 + }, + { + "Time": 310, + "Intensity": 0.74, + "Frequency": -46 + }, + { + "Time": 329, + "Intensity": 1, + "Frequency": -39 + }, + { + "Time": 394, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 714, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 5, + "Intensity": 0.73, + "Frequency": -39 + }, + { + "Time": 52, + "Intensity": 0.54, + "Frequency": -48 + }, + { + "Time": 96, + "Intensity": 0.68, + "Frequency": -50 + }, + { + "Time": 118, + "Intensity": 1, + "Frequency": -43 + }, + { + "Time": 161, + "Intensity": 0.81, + "Frequency": -47 + }, + { + "Time": 217, + "Intensity": 0.43, + "Frequency": -50 + }, + { + "Time": 299, + "Intensity": 0.61, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 716, + "Parameters": { + "Intensity": 39, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 5, + "Intensity": 0.76, + "Frequency": -40 + }, + { + "Time": 47, + "Intensity": 0.76, + "Frequency": -43 + }, + { + "Time": 79, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 119, + "Intensity": 1, + "Frequency": -41 + }, + { + "Time": 166, + "Intensity": 0.82, + "Frequency": -38 + }, + { + "Time": 202, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 296, + "Intensity": 0.65, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1016, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 21, + "Intensity": 0.66, + "Frequency": -44 + }, + { + "Time": 74, + "Intensity": 0.67, + "Frequency": -47 + }, + { + "Time": 102, + "Intensity": 0.83, + "Frequency": -38 + }, + { + "Time": 134, + "Intensity": 0.91, + "Frequency": -39 + }, + { + "Time": 147, + "Intensity": 0.74, + "Frequency": -47 + }, + { + "Time": 195, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 225, + "Intensity": 0.88, + "Frequency": -43 + }, + { + "Time": 295, + "Intensity": 0.7, + "Frequency": -45 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1017, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 14, + "Intensity": 0.69, + "Frequency": -47 + }, + { + "Time": 65, + "Intensity": 0.47, + "Frequency": -42 + }, + { + "Time": 95, + "Intensity": 0.75, + "Frequency": -34 + }, + { + "Time": 130, + "Intensity": 0.97, + "Frequency": -39 + }, + { + "Time": 167, + "Intensity": 0.62, + "Frequency": -50 + }, + { + "Time": 208, + "Intensity": 0.45, + "Frequency": -50 + }, + { + "Time": 226, + "Intensity": 0.99, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1323, + "Parameters": { + "Intensity": 43, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.46, + "Frequency": -39 + }, + { + "Time": 31, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 70, + "Intensity": 0.94, + "Frequency": -50 + }, + { + "Time": 115, + "Intensity": 0.79, + "Frequency": -37 + }, + { + "Time": 134, + "Intensity": 0.6, + "Frequency": -38 + }, + { + "Time": 154, + "Intensity": 0.77, + "Frequency": -47 + }, + { + "Time": 185, + "Intensity": 0.71, + "Frequency": -50 + }, + { + "Time": 217, + "Intensity": 0.57, + "Frequency": -48 + }, + { + "Time": 275, + "Intensity": 0.64, + "Frequency": -46 + }, + { + "Time": 297, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1327, + "Parameters": { + "Intensity": 40, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 2, + "Intensity": 0.42, + "Frequency": -47 + }, + { + "Time": 29, + "Intensity": 0.78, + "Frequency": -50 + }, + { + "Time": 74, + "Intensity": 0.95, + "Frequency": -45 + }, + { + "Time": 108, + "Intensity": 0.65, + "Frequency": -39 + }, + { + "Time": 131, + "Intensity": 0.39, + "Frequency": -45 + }, + { + "Time": 164, + "Intensity": 0.76, + "Frequency": -46 + }, + { + "Time": 194, + "Intensity": 0.69, + "Frequency": -43 + }, + { + "Time": 235, + "Intensity": 0.41, + "Frequency": -46 + }, + { + "Time": 264, + "Intensity": 0.6, + "Frequency": -41 + }, + { + "Time": 295, + "Intensity": 0.49, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1627, + "Parameters": { + "Intensity": 46, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.35, + "Frequency": -46 + }, + { + "Time": 37, + "Intensity": 0.65, + "Frequency": -47 + }, + { + "Time": 84, + "Intensity": 0.41, + "Frequency": -50 + }, + { + "Time": 128, + "Intensity": 0.94, + "Frequency": -46 + }, + { + "Time": 154, + "Intensity": 0.51, + "Frequency": -38 + }, + { + "Time": 179, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 212, + "Intensity": 0.58, + "Frequency": -49 + }, + { + "Time": 238, + "Intensity": 0.86, + "Frequency": -46 + }, + { + "Time": 277, + "Intensity": 0.79, + "Frequency": -39 + }, + { + "Time": 299, + "Intensity": 0.53, + "Frequency": -46 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1628, + "Parameters": { + "Intensity": 43, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 7, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 44, + "Intensity": 0.82, + "Frequency": -47 + }, + { + "Time": 82, + "Intensity": 0.5, + "Frequency": -50 + }, + { + "Time": 124, + "Intensity": 0.85, + "Frequency": -46 + }, + { + "Time": 154, + "Intensity": 0.53, + "Frequency": -38 + }, + { + "Time": 175, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 208, + "Intensity": 0.57, + "Frequency": -49 + }, + { + "Time": 230, + "Intensity": 0.82, + "Frequency": -46 + }, + { + "Time": 278, + "Intensity": 0.78, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 1929, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 24, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 82, + "Intensity": 0.62, + "Frequency": -44 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": -42 + }, + { + "Time": 186, + "Intensity": 0.72, + "Frequency": -39 + }, + { + "Time": 234, + "Intensity": 0.41, + "Frequency": -50 + }, + { + "Time": 278, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 328, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 392, + "Intensity": 0.54, + "Frequency": -47 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 1931, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 24, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 85, + "Intensity": 0.65, + "Frequency": -44 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": -42 + }, + { + "Time": 189, + "Intensity": 0.72, + "Frequency": -39 + }, + { + "Time": 241, + "Intensity": 0.34, + "Frequency": -50 + }, + { + "Time": 278, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 328, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 392, + "Intensity": 0.54, + "Frequency": -47 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 2332, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.39, + "Frequency": -47 + }, + { + "Time": 31, + "Intensity": 0.55, + "Frequency": -42 + }, + { + "Time": 81, + "Intensity": 0.5, + "Frequency": -34 + }, + { + "Time": 96, + "Intensity": 0.84, + "Frequency": -43 + }, + { + "Time": 145, + "Intensity": 0.71, + "Frequency": -50 + }, + { + "Time": 203, + "Intensity": 0.56, + "Frequency": -50 + }, + { + "Time": 242, + "Intensity": 0.84, + "Frequency": -44 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 2334, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 3, + "Intensity": 0.38, + "Frequency": -47 + }, + { + "Time": 18, + "Intensity": 0.7, + "Frequency": -42 + }, + { + "Time": 79, + "Intensity": 0.62, + "Frequency": -34 + }, + { + "Time": 95, + "Intensity": 0.88, + "Frequency": -39 + }, + { + "Time": 148, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 204, + "Intensity": 0.49, + "Frequency": -50 + }, + { + "Time": 242, + "Intensity": 0.84, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 2636, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 9, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 53, + "Intensity": 0.93, + "Frequency": -47 + }, + { + "Time": 105, + "Intensity": 0.62, + "Frequency": -50 + }, + { + "Time": 154, + "Intensity": 0.88, + "Frequency": -46 + }, + { + "Time": 196, + "Intensity": 0.75, + "Frequency": -38 + }, + { + "Time": 230, + "Intensity": 0.52, + "Frequency": -50 + }, + { + "Time": 254, + "Intensity": 0.92, + "Frequency": -49 + }, + { + "Time": 306, + "Intensity": 0.83, + "Frequency": -46 + }, + { + "Time": 329, + "Intensity": 1, + "Frequency": -48 + }, + { + "Time": 394, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 2637, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 17, + "Intensity": 0.44, + "Frequency": -50 + }, + { + "Time": 53, + "Intensity": 0.88, + "Frequency": -47 + }, + { + "Time": 123, + "Intensity": 0.61, + "Frequency": -47 + }, + { + "Time": 169, + "Intensity": 0.8, + "Frequency": -41 + }, + { + "Time": 224, + "Intensity": 0.52, + "Frequency": -50 + }, + { + "Time": 254, + "Intensity": 0.86, + "Frequency": -38 + }, + { + "Time": 311, + "Intensity": 0.68, + "Frequency": -50 + }, + { + "Time": 336, + "Intensity": 0.95, + "Frequency": -46 + }, + { + "Time": 388, + "Intensity": 0.66, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 3040, + "Parameters": { + "Intensity": 40, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 4, + "Intensity": 0.75, + "Frequency": -46 + }, + { + "Time": 49, + "Intensity": 0.52, + "Frequency": -43 + }, + { + "Time": 88, + "Intensity": 0.65, + "Frequency": -50 + }, + { + "Time": 114, + "Intensity": 0.85, + "Frequency": -41 + }, + { + "Time": 163, + "Intensity": 0.74, + "Frequency": -38 + }, + { + "Time": 202, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 296, + "Intensity": 0.65, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 301, + "StartTime": 3044, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 10, + "Intensity": 0.71, + "Frequency": -46 + }, + { + "Time": 46, + "Intensity": 0.47, + "Frequency": -48 + }, + { + "Time": 80, + "Intensity": 0.61, + "Frequency": -50 + }, + { + "Time": 100, + "Intensity": 0.92, + "Frequency": -43 + }, + { + "Time": 156, + "Intensity": 0.76, + "Frequency": -47 + }, + { + "Time": 212, + "Intensity": 0.44, + "Frequency": -50 + }, + { + "Time": 298, + "Intensity": 0.61, + "Frequency": -38 + }, + { + "Time": 301, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_m.json index f34559e84dcb204d9a6fa48a7049070cd1ca28ee..cafa3346525a6c193cb7f18d42ad89f7f7871718 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Creek_m.json @@ -1,1327 +1,1327 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 0, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 12, - "Intensity": 0.59, - "Frequency": -47 - }, - { - "Time": 52, - "Intensity": 0.96, - "Frequency": -44 - }, - { - "Time": 100, - "Intensity": 0.53, - "Frequency": -42 - }, - { - "Time": 133, - "Intensity": 0.94, - "Frequency": -39 - }, - { - "Time": 172, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 210, - "Intensity": 0.38, - "Frequency": -50 - }, - { - "Time": 239, - "Intensity": 0.74, - "Frequency": -45 - }, - { - "Time": 287, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 7, - "Parameters": { - "Intensity": 52, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 18, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 55, - "Intensity": 0.85, - "Frequency": -44 - }, - { - "Time": 106, - "Intensity": 0.64, - "Frequency": -42 - }, - { - "Time": 136, - "Intensity": 0.91, - "Frequency": -39 - }, - { - "Time": 165, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 206, - "Intensity": 0.53, - "Frequency": -50 - }, - { - "Time": 225, - "Intensity": 0.69, - "Frequency": -45 - }, - { - "Time": 294, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 311, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 32, - "Intensity": 0.93, - "Frequency": -50 - }, - { - "Time": 86, - "Intensity": 0.83, - "Frequency": -47 - }, - { - "Time": 145, - "Intensity": 0.43, - "Frequency": -47 - }, - { - "Time": 196, - "Intensity": 1, - "Frequency": -41 - }, - { - "Time": 252, - "Intensity": 0.49, - "Frequency": -50 - }, - { - "Time": 280, - "Intensity": 0.86, - "Frequency": -38 - }, - { - "Time": 322, - "Intensity": 0.57, - "Frequency": -50 - }, - { - "Time": 336, - "Intensity": 0.95, - "Frequency": -38 - }, - { - "Time": 399, - "Intensity": 0.57, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 313, - "Parameters": { - "Intensity": 51, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 9, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 53, - "Intensity": 0.93, - "Frequency": -47 - }, - { - "Time": 114, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 149, - "Intensity": 0.59, - "Frequency": -46 - }, - { - "Time": 190, - "Intensity": 0.94, - "Frequency": -38 - }, - { - "Time": 236, - "Intensity": 0.69, - "Frequency": -50 - }, - { - "Time": 264, - "Intensity": 0.82, - "Frequency": -49 - }, - { - "Time": 310, - "Intensity": 0.74, - "Frequency": -46 - }, - { - "Time": 329, - "Intensity": 1, - "Frequency": -39 - }, - { - "Time": 394, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 714, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 5, - "Intensity": 0.73, - "Frequency": -39 - }, - { - "Time": 52, - "Intensity": 0.54, - "Frequency": -48 - }, - { - "Time": 96, - "Intensity": 0.68, - "Frequency": -50 - }, - { - "Time": 118, - "Intensity": 1, - "Frequency": -43 - }, - { - "Time": 161, - "Intensity": 0.81, - "Frequency": -47 - }, - { - "Time": 217, - "Intensity": 0.43, - "Frequency": -50 - }, - { - "Time": 299, - "Intensity": 0.61, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 716, - "Parameters": { - "Intensity": 52, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 5, - "Intensity": 0.76, - "Frequency": -40 - }, - { - "Time": 47, - "Intensity": 0.76, - "Frequency": -43 - }, - { - "Time": 79, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 119, - "Intensity": 1, - "Frequency": -41 - }, - { - "Time": 166, - "Intensity": 0.82, - "Frequency": -38 - }, - { - "Time": 202, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 296, - "Intensity": 0.65, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1016, - "Parameters": { - "Intensity": 59, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 21, - "Intensity": 0.66, - "Frequency": -44 - }, - { - "Time": 74, - "Intensity": 0.67, - "Frequency": -47 - }, - { - "Time": 102, - "Intensity": 0.83, - "Frequency": -38 - }, - { - "Time": 134, - "Intensity": 0.91, - "Frequency": -39 - }, - { - "Time": 147, - "Intensity": 0.74, - "Frequency": -47 - }, - { - "Time": 195, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 225, - "Intensity": 0.88, - "Frequency": -43 - }, - { - "Time": 295, - "Intensity": 0.7, - "Frequency": -45 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1017, - "Parameters": { - "Intensity": 51, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 14, - "Intensity": 0.69, - "Frequency": -47 - }, - { - "Time": 65, - "Intensity": 0.47, - "Frequency": -42 - }, - { - "Time": 95, - "Intensity": 0.75, - "Frequency": -34 - }, - { - "Time": 130, - "Intensity": 0.97, - "Frequency": -39 - }, - { - "Time": 167, - "Intensity": 0.62, - "Frequency": -50 - }, - { - "Time": 208, - "Intensity": 0.45, - "Frequency": -50 - }, - { - "Time": 226, - "Intensity": 0.99, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1323, - "Parameters": { - "Intensity": 57, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.46, - "Frequency": -39 - }, - { - "Time": 31, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 70, - "Intensity": 0.94, - "Frequency": -50 - }, - { - "Time": 115, - "Intensity": 0.79, - "Frequency": -37 - }, - { - "Time": 134, - "Intensity": 0.6, - "Frequency": -38 - }, - { - "Time": 154, - "Intensity": 0.77, - "Frequency": -47 - }, - { - "Time": 185, - "Intensity": 0.71, - "Frequency": -50 - }, - { - "Time": 217, - "Intensity": 0.57, - "Frequency": -48 - }, - { - "Time": 275, - "Intensity": 0.64, - "Frequency": -46 - }, - { - "Time": 297, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1327, - "Parameters": { - "Intensity": 53, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 2, - "Intensity": 0.42, - "Frequency": -47 - }, - { - "Time": 29, - "Intensity": 0.78, - "Frequency": -50 - }, - { - "Time": 74, - "Intensity": 0.95, - "Frequency": -45 - }, - { - "Time": 108, - "Intensity": 0.65, - "Frequency": -39 - }, - { - "Time": 131, - "Intensity": 0.39, - "Frequency": -45 - }, - { - "Time": 164, - "Intensity": 0.76, - "Frequency": -46 - }, - { - "Time": 194, - "Intensity": 0.69, - "Frequency": -43 - }, - { - "Time": 235, - "Intensity": 0.41, - "Frequency": -46 - }, - { - "Time": 264, - "Intensity": 0.6, - "Frequency": -41 - }, - { - "Time": 295, - "Intensity": 0.49, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1627, - "Parameters": { - "Intensity": 62, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.35, - "Frequency": -46 - }, - { - "Time": 37, - "Intensity": 0.65, - "Frequency": -47 - }, - { - "Time": 84, - "Intensity": 0.41, - "Frequency": -50 - }, - { - "Time": 128, - "Intensity": 0.94, - "Frequency": -46 - }, - { - "Time": 154, - "Intensity": 0.51, - "Frequency": -38 - }, - { - "Time": 179, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 212, - "Intensity": 0.58, - "Frequency": -49 - }, - { - "Time": 238, - "Intensity": 0.86, - "Frequency": -46 - }, - { - "Time": 277, - "Intensity": 0.79, - "Frequency": -39 - }, - { - "Time": 299, - "Intensity": 0.53, - "Frequency": -46 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 1628, - "Parameters": { - "Intensity": 57, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 7, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 44, - "Intensity": 0.82, - "Frequency": -47 - }, - { - "Time": 82, - "Intensity": 0.5, - "Frequency": -50 - }, - { - "Time": 124, - "Intensity": 0.85, - "Frequency": -46 - }, - { - "Time": 154, - "Intensity": 0.53, - "Frequency": -38 - }, - { - "Time": 175, - "Intensity": 0.81, - "Frequency": -50 - }, - { - "Time": 208, - "Intensity": 0.57, - "Frequency": -49 - }, - { - "Time": 230, - "Intensity": 0.82, - "Frequency": -46 - }, - { - "Time": 278, - "Intensity": 0.78, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 1929, - "Parameters": { - "Intensity": 59, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 24, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 82, - "Intensity": 0.62, - "Frequency": -44 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": -42 - }, - { - "Time": 186, - "Intensity": 0.72, - "Frequency": -39 - }, - { - "Time": 234, - "Intensity": 0.41, - "Frequency": -50 - }, - { - "Time": 278, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 328, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 392, - "Intensity": 0.54, - "Frequency": -47 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 1931, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 24, - "Intensity": 0.55, - "Frequency": -47 - }, - { - "Time": 85, - "Intensity": 0.65, - "Frequency": -44 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": -42 - }, - { - "Time": 189, - "Intensity": 0.72, - "Frequency": -39 - }, - { - "Time": 241, - "Intensity": 0.34, - "Frequency": -50 - }, - { - "Time": 278, - "Intensity": 0.82, - "Frequency": -50 - }, - { - "Time": 328, - "Intensity": 0.64, - "Frequency": -45 - }, - { - "Time": 392, - "Intensity": 0.54, - "Frequency": -47 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 2332, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.39, - "Frequency": -47 - }, - { - "Time": 31, - "Intensity": 0.55, - "Frequency": -42 - }, - { - "Time": 81, - "Intensity": 0.5, - "Frequency": -34 - }, - { - "Time": 96, - "Intensity": 0.84, - "Frequency": -43 - }, - { - "Time": 145, - "Intensity": 0.71, - "Frequency": -50 - }, - { - "Time": 203, - "Intensity": 0.56, - "Frequency": -50 - }, - { - "Time": 242, - "Intensity": 0.84, - "Frequency": -44 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 2334, - "Parameters": { - "Intensity": 51, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 3, - "Intensity": 0.38, - "Frequency": -47 - }, - { - "Time": 18, - "Intensity": 0.7, - "Frequency": -42 - }, - { - "Time": 79, - "Intensity": 0.62, - "Frequency": -34 - }, - { - "Time": 95, - "Intensity": 0.88, - "Frequency": -39 - }, - { - "Time": 148, - "Intensity": 0.73, - "Frequency": -50 - }, - { - "Time": 204, - "Intensity": 0.49, - "Frequency": -50 - }, - { - "Time": 242, - "Intensity": 0.84, - "Frequency": -39 - }, - { - "Time": 296, - "Intensity": 0.72, - "Frequency": -47 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 2636, - "Parameters": { - "Intensity": 51, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 9, - "Intensity": 0.49, - "Frequency": -46 - }, - { - "Time": 53, - "Intensity": 0.93, - "Frequency": -47 - }, - { - "Time": 105, - "Intensity": 0.62, - "Frequency": -50 - }, - { - "Time": 154, - "Intensity": 0.88, - "Frequency": -46 - }, - { - "Time": 196, - "Intensity": 0.75, - "Frequency": -38 - }, - { - "Time": 230, - "Intensity": 0.52, - "Frequency": -50 - }, - { - "Time": 254, - "Intensity": 0.92, - "Frequency": -49 - }, - { - "Time": 306, - "Intensity": 0.83, - "Frequency": -46 - }, - { - "Time": 329, - "Intensity": 1, - "Frequency": -48 - }, - { - "Time": 394, - "Intensity": 0.69, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 400, - "StartTime": 2637, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 17, - "Intensity": 0.44, - "Frequency": -50 - }, - { - "Time": 53, - "Intensity": 0.88, - "Frequency": -47 - }, - { - "Time": 123, - "Intensity": 0.61, - "Frequency": -47 - }, - { - "Time": 169, - "Intensity": 0.8, - "Frequency": -41 - }, - { - "Time": 224, - "Intensity": 0.52, - "Frequency": -50 - }, - { - "Time": 254, - "Intensity": 0.86, - "Frequency": -38 - }, - { - "Time": 311, - "Intensity": 0.68, - "Frequency": -50 - }, - { - "Time": 336, - "Intensity": 0.95, - "Frequency": -46 - }, - { - "Time": 388, - "Intensity": 0.66, - "Frequency": -46 - }, - { - "Time": 400, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 300, - "StartTime": 3040, - "Parameters": { - "Intensity": 53, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 4, - "Intensity": 0.75, - "Frequency": -46 - }, - { - "Time": 49, - "Intensity": 0.52, - "Frequency": -43 - }, - { - "Time": 88, - "Intensity": 0.65, - "Frequency": -50 - }, - { - "Time": 114, - "Intensity": 0.85, - "Frequency": -41 - }, - { - "Time": 163, - "Intensity": 0.74, - "Frequency": -38 - }, - { - "Time": 202, - "Intensity": 0.58, - "Frequency": -50 - }, - { - "Time": 296, - "Intensity": 0.65, - "Frequency": -38 - }, - { - "Time": 300, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 301, - "StartTime": 3044, - "Parameters": { - "Intensity": 59, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 10, - "Intensity": 0.71, - "Frequency": -46 - }, - { - "Time": 46, - "Intensity": 0.47, - "Frequency": -48 - }, - { - "Time": 80, - "Intensity": 0.61, - "Frequency": -50 - }, - { - "Time": 100, - "Intensity": 0.92, - "Frequency": -43 - }, - { - "Time": 156, - "Intensity": 0.76, - "Frequency": -47 - }, - { - "Time": 212, - "Intensity": 0.44, - "Frequency": -50 - }, - { - "Time": 298, - "Intensity": 0.61, - "Frequency": -38 - }, - { - "Time": 301, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 0, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 12, + "Intensity": 0.59, + "Frequency": -47 + }, + { + "Time": 52, + "Intensity": 0.96, + "Frequency": -44 + }, + { + "Time": 100, + "Intensity": 0.53, + "Frequency": -42 + }, + { + "Time": 133, + "Intensity": 0.94, + "Frequency": -39 + }, + { + "Time": 172, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 210, + "Intensity": 0.38, + "Frequency": -50 + }, + { + "Time": 239, + "Intensity": 0.74, + "Frequency": -45 + }, + { + "Time": 287, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 7, + "Parameters": { + "Intensity": 52, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 18, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 55, + "Intensity": 0.85, + "Frequency": -44 + }, + { + "Time": 106, + "Intensity": 0.64, + "Frequency": -42 + }, + { + "Time": 136, + "Intensity": 0.91, + "Frequency": -39 + }, + { + "Time": 165, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 206, + "Intensity": 0.53, + "Frequency": -50 + }, + { + "Time": 225, + "Intensity": 0.69, + "Frequency": -45 + }, + { + "Time": 294, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 311, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 32, + "Intensity": 0.93, + "Frequency": -50 + }, + { + "Time": 86, + "Intensity": 0.83, + "Frequency": -47 + }, + { + "Time": 145, + "Intensity": 0.43, + "Frequency": -47 + }, + { + "Time": 196, + "Intensity": 1, + "Frequency": -41 + }, + { + "Time": 252, + "Intensity": 0.49, + "Frequency": -50 + }, + { + "Time": 280, + "Intensity": 0.86, + "Frequency": -38 + }, + { + "Time": 322, + "Intensity": 0.57, + "Frequency": -50 + }, + { + "Time": 336, + "Intensity": 0.95, + "Frequency": -38 + }, + { + "Time": 399, + "Intensity": 0.57, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 313, + "Parameters": { + "Intensity": 51, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 9, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 53, + "Intensity": 0.93, + "Frequency": -47 + }, + { + "Time": 114, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 149, + "Intensity": 0.59, + "Frequency": -46 + }, + { + "Time": 190, + "Intensity": 0.94, + "Frequency": -38 + }, + { + "Time": 236, + "Intensity": 0.69, + "Frequency": -50 + }, + { + "Time": 264, + "Intensity": 0.82, + "Frequency": -49 + }, + { + "Time": 310, + "Intensity": 0.74, + "Frequency": -46 + }, + { + "Time": 329, + "Intensity": 1, + "Frequency": -39 + }, + { + "Time": 394, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 714, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 5, + "Intensity": 0.73, + "Frequency": -39 + }, + { + "Time": 52, + "Intensity": 0.54, + "Frequency": -48 + }, + { + "Time": 96, + "Intensity": 0.68, + "Frequency": -50 + }, + { + "Time": 118, + "Intensity": 1, + "Frequency": -43 + }, + { + "Time": 161, + "Intensity": 0.81, + "Frequency": -47 + }, + { + "Time": 217, + "Intensity": 0.43, + "Frequency": -50 + }, + { + "Time": 299, + "Intensity": 0.61, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 716, + "Parameters": { + "Intensity": 52, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 5, + "Intensity": 0.76, + "Frequency": -40 + }, + { + "Time": 47, + "Intensity": 0.76, + "Frequency": -43 + }, + { + "Time": 79, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 119, + "Intensity": 1, + "Frequency": -41 + }, + { + "Time": 166, + "Intensity": 0.82, + "Frequency": -38 + }, + { + "Time": 202, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 296, + "Intensity": 0.65, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1016, + "Parameters": { + "Intensity": 59, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 21, + "Intensity": 0.66, + "Frequency": -44 + }, + { + "Time": 74, + "Intensity": 0.67, + "Frequency": -47 + }, + { + "Time": 102, + "Intensity": 0.83, + "Frequency": -38 + }, + { + "Time": 134, + "Intensity": 0.91, + "Frequency": -39 + }, + { + "Time": 147, + "Intensity": 0.74, + "Frequency": -47 + }, + { + "Time": 195, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 225, + "Intensity": 0.88, + "Frequency": -43 + }, + { + "Time": 295, + "Intensity": 0.7, + "Frequency": -45 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1017, + "Parameters": { + "Intensity": 51, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 14, + "Intensity": 0.69, + "Frequency": -47 + }, + { + "Time": 65, + "Intensity": 0.47, + "Frequency": -42 + }, + { + "Time": 95, + "Intensity": 0.75, + "Frequency": -34 + }, + { + "Time": 130, + "Intensity": 0.97, + "Frequency": -39 + }, + { + "Time": 167, + "Intensity": 0.62, + "Frequency": -50 + }, + { + "Time": 208, + "Intensity": 0.45, + "Frequency": -50 + }, + { + "Time": 226, + "Intensity": 0.99, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1323, + "Parameters": { + "Intensity": 57, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.46, + "Frequency": -39 + }, + { + "Time": 31, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 70, + "Intensity": 0.94, + "Frequency": -50 + }, + { + "Time": 115, + "Intensity": 0.79, + "Frequency": -37 + }, + { + "Time": 134, + "Intensity": 0.6, + "Frequency": -38 + }, + { + "Time": 154, + "Intensity": 0.77, + "Frequency": -47 + }, + { + "Time": 185, + "Intensity": 0.71, + "Frequency": -50 + }, + { + "Time": 217, + "Intensity": 0.57, + "Frequency": -48 + }, + { + "Time": 275, + "Intensity": 0.64, + "Frequency": -46 + }, + { + "Time": 297, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1327, + "Parameters": { + "Intensity": 53, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 2, + "Intensity": 0.42, + "Frequency": -47 + }, + { + "Time": 29, + "Intensity": 0.78, + "Frequency": -50 + }, + { + "Time": 74, + "Intensity": 0.95, + "Frequency": -45 + }, + { + "Time": 108, + "Intensity": 0.65, + "Frequency": -39 + }, + { + "Time": 131, + "Intensity": 0.39, + "Frequency": -45 + }, + { + "Time": 164, + "Intensity": 0.76, + "Frequency": -46 + }, + { + "Time": 194, + "Intensity": 0.69, + "Frequency": -43 + }, + { + "Time": 235, + "Intensity": 0.41, + "Frequency": -46 + }, + { + "Time": 264, + "Intensity": 0.6, + "Frequency": -41 + }, + { + "Time": 295, + "Intensity": 0.49, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1627, + "Parameters": { + "Intensity": 62, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.35, + "Frequency": -46 + }, + { + "Time": 37, + "Intensity": 0.65, + "Frequency": -47 + }, + { + "Time": 84, + "Intensity": 0.41, + "Frequency": -50 + }, + { + "Time": 128, + "Intensity": 0.94, + "Frequency": -46 + }, + { + "Time": 154, + "Intensity": 0.51, + "Frequency": -38 + }, + { + "Time": 179, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 212, + "Intensity": 0.58, + "Frequency": -49 + }, + { + "Time": 238, + "Intensity": 0.86, + "Frequency": -46 + }, + { + "Time": 277, + "Intensity": 0.79, + "Frequency": -39 + }, + { + "Time": 299, + "Intensity": 0.53, + "Frequency": -46 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 1628, + "Parameters": { + "Intensity": 57, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 7, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 44, + "Intensity": 0.82, + "Frequency": -47 + }, + { + "Time": 82, + "Intensity": 0.5, + "Frequency": -50 + }, + { + "Time": 124, + "Intensity": 0.85, + "Frequency": -46 + }, + { + "Time": 154, + "Intensity": 0.53, + "Frequency": -38 + }, + { + "Time": 175, + "Intensity": 0.81, + "Frequency": -50 + }, + { + "Time": 208, + "Intensity": 0.57, + "Frequency": -49 + }, + { + "Time": 230, + "Intensity": 0.82, + "Frequency": -46 + }, + { + "Time": 278, + "Intensity": 0.78, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 1929, + "Parameters": { + "Intensity": 59, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 24, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 82, + "Intensity": 0.62, + "Frequency": -44 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": -42 + }, + { + "Time": 186, + "Intensity": 0.72, + "Frequency": -39 + }, + { + "Time": 234, + "Intensity": 0.41, + "Frequency": -50 + }, + { + "Time": 278, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 328, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 392, + "Intensity": 0.54, + "Frequency": -47 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 1931, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 24, + "Intensity": 0.55, + "Frequency": -47 + }, + { + "Time": 85, + "Intensity": 0.65, + "Frequency": -44 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": -42 + }, + { + "Time": 189, + "Intensity": 0.72, + "Frequency": -39 + }, + { + "Time": 241, + "Intensity": 0.34, + "Frequency": -50 + }, + { + "Time": 278, + "Intensity": 0.82, + "Frequency": -50 + }, + { + "Time": 328, + "Intensity": 0.64, + "Frequency": -45 + }, + { + "Time": 392, + "Intensity": 0.54, + "Frequency": -47 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 2332, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.39, + "Frequency": -47 + }, + { + "Time": 31, + "Intensity": 0.55, + "Frequency": -42 + }, + { + "Time": 81, + "Intensity": 0.5, + "Frequency": -34 + }, + { + "Time": 96, + "Intensity": 0.84, + "Frequency": -43 + }, + { + "Time": 145, + "Intensity": 0.71, + "Frequency": -50 + }, + { + "Time": 203, + "Intensity": 0.56, + "Frequency": -50 + }, + { + "Time": 242, + "Intensity": 0.84, + "Frequency": -44 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 2334, + "Parameters": { + "Intensity": 51, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 3, + "Intensity": 0.38, + "Frequency": -47 + }, + { + "Time": 18, + "Intensity": 0.7, + "Frequency": -42 + }, + { + "Time": 79, + "Intensity": 0.62, + "Frequency": -34 + }, + { + "Time": 95, + "Intensity": 0.88, + "Frequency": -39 + }, + { + "Time": 148, + "Intensity": 0.73, + "Frequency": -50 + }, + { + "Time": 204, + "Intensity": 0.49, + "Frequency": -50 + }, + { + "Time": 242, + "Intensity": 0.84, + "Frequency": -39 + }, + { + "Time": 296, + "Intensity": 0.72, + "Frequency": -47 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 2636, + "Parameters": { + "Intensity": 51, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 9, + "Intensity": 0.49, + "Frequency": -46 + }, + { + "Time": 53, + "Intensity": 0.93, + "Frequency": -47 + }, + { + "Time": 105, + "Intensity": 0.62, + "Frequency": -50 + }, + { + "Time": 154, + "Intensity": 0.88, + "Frequency": -46 + }, + { + "Time": 196, + "Intensity": 0.75, + "Frequency": -38 + }, + { + "Time": 230, + "Intensity": 0.52, + "Frequency": -50 + }, + { + "Time": 254, + "Intensity": 0.92, + "Frequency": -49 + }, + { + "Time": 306, + "Intensity": 0.83, + "Frequency": -46 + }, + { + "Time": 329, + "Intensity": 1, + "Frequency": -48 + }, + { + "Time": 394, + "Intensity": 0.69, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 400, + "StartTime": 2637, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 17, + "Intensity": 0.44, + "Frequency": -50 + }, + { + "Time": 53, + "Intensity": 0.88, + "Frequency": -47 + }, + { + "Time": 123, + "Intensity": 0.61, + "Frequency": -47 + }, + { + "Time": 169, + "Intensity": 0.8, + "Frequency": -41 + }, + { + "Time": 224, + "Intensity": 0.52, + "Frequency": -50 + }, + { + "Time": 254, + "Intensity": 0.86, + "Frequency": -38 + }, + { + "Time": 311, + "Intensity": 0.68, + "Frequency": -50 + }, + { + "Time": 336, + "Intensity": 0.95, + "Frequency": -46 + }, + { + "Time": 388, + "Intensity": 0.66, + "Frequency": -46 + }, + { + "Time": 400, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 300, + "StartTime": 3040, + "Parameters": { + "Intensity": 53, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 4, + "Intensity": 0.75, + "Frequency": -46 + }, + { + "Time": 49, + "Intensity": 0.52, + "Frequency": -43 + }, + { + "Time": 88, + "Intensity": 0.65, + "Frequency": -50 + }, + { + "Time": 114, + "Intensity": 0.85, + "Frequency": -41 + }, + { + "Time": 163, + "Intensity": 0.74, + "Frequency": -38 + }, + { + "Time": 202, + "Intensity": 0.58, + "Frequency": -50 + }, + { + "Time": 296, + "Intensity": 0.65, + "Frequency": -38 + }, + { + "Time": 300, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 301, + "StartTime": 3044, + "Parameters": { + "Intensity": 59, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 10, + "Intensity": 0.71, + "Frequency": -46 + }, + { + "Time": 46, + "Intensity": 0.47, + "Frequency": -48 + }, + { + "Time": 80, + "Intensity": 0.61, + "Frequency": -50 + }, + { + "Time": 100, + "Intensity": 0.92, + "Frequency": -43 + }, + { + "Time": 156, + "Intensity": 0.76, + "Frequency": -47 + }, + { + "Time": 212, + "Intensity": 0.44, + "Frequency": -50 + }, + { + "Time": 298, + "Intensity": 0.61, + "Frequency": -38 + }, + { + "Time": 301, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_h.json index d8867502e2d4b0aac462797cfb32246a9d9fcc46..1c097b812927ae6db7ffd9e473dfd28942ca1c8a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_h.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 1617, - "StartTime": 29, - "Parameters": { - "Intensity": 100, - "Frequency": 70, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -59 - }, - { - "Time": 5, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 63 - }, - { - "Time": 1617, - "Intensity": 0.0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 1617, + "StartTime": 29, + "Parameters": { + "Intensity": 100, + "Frequency": 70, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -59 + }, + { + "Time": 5, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 63 + }, + { + "Time": 1617, + "Intensity": 0.0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_l.json index 7298d99657789af541e56b8421630a69884907cf..803c85e87291023bf6d8ea3f841999319dd5edda 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_l.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 1617, - "StartTime": 29, - "Parameters": { - "Intensity": 60, - "Frequency": 70, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -59 - }, - { - "Time": 5, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 63 - }, - { - "Time": 1617, - "Intensity": 0.0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 1617, + "StartTime": 29, + "Parameters": { + "Intensity": 60, + "Frequency": 70, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -59 + }, + { + "Time": 5, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 63 + }, + { + "Time": 1617, + "Intensity": 0.0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_m.json index 7b867cde4a59204dfdfb276e2657811c4a3222e9..30ad2306167ae01c767d7982fdd4a8d0b8dd6e72 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals2_m.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 1617, - "StartTime": 29, - "Parameters": { - "Intensity": 80, - "Frequency": 70, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -59 - }, - { - "Time": 5, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 63 - }, - { - "Time": 1617, - "Intensity": 0.0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 1617, + "StartTime": 29, + "Parameters": { + "Intensity": 80, + "Frequency": 70, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -59 + }, + { + "Time": 5, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 63 + }, + { + "Time": 1617, + "Intensity": 0.0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_h.json index fd86767f1047ca070257fa19ef2774bac7d770ab..2ed96e002edcaff08aef49f2274e7bcf7c49dd5e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_h.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 158, - "StartTime": 0, - "Parameters": { - "Intensity": 100, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1.0, - "Frequency": 40 - }, - { - "Time": 36, - "Intensity": 0.51, - "Frequency": -19 - }, - { - "Time": 158, - "Intensity": 0.0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 158, + "StartTime": 0, + "Parameters": { + "Intensity": 100, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1.0, + "Frequency": 40 + }, + { + "Time": 36, + "Intensity": 0.51, + "Frequency": -19 + }, + { + "Time": 158, + "Intensity": 0.0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_l.json index 3e28cb45905555b224025728a11e61c4b703c847..f5c0015367c697221526cf373b78388960aeef19 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_l.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 158, - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1.0, - "Frequency": 40 - }, - { - "Time": 36, - "Intensity": 0.51, - "Frequency": -19 - }, - { - "Time": 158, - "Intensity": 0.0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 158, + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1.0, + "Frequency": 40 + }, + { + "Time": 36, + "Intensity": 0.51, + "Frequency": -19 + }, + { + "Time": 158, + "Intensity": 0.0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_m.json index a82c7890716ecf13650df19296a119b52b0b2b52..6c85b0a64f06f90609ea586f543c5e4098a4ed0a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Cymbals_m.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 158, - "StartTime": 0, - "Parameters": { - "Intensity": 80, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1.0, - "Frequency": 40 - }, - { - "Time": 36, - "Intensity": 0.51, - "Frequency": -19 - }, - { - "Time": 158, - "Intensity": 0.0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 158, + "StartTime": 0, + "Parameters": { + "Intensity": 80, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1.0, + "Frequency": 40 + }, + { + "Time": 36, + "Intensity": 0.51, + "Frequency": -19 + }, + { + "Time": 158, + "Intensity": 0.0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_h.json index 163f28133224e1166a247d673e5c62ea3766893b..74ec332759aa862ce927c92f451baeefafedf72c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_h.json @@ -1,797 +1,797 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 135, - "StartTime": 110, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 77, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 106, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 135, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 255, - "Parameters": { - "Intensity": 95, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 75, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 80, - "Intensity": 0.43, - "Frequency": -25 - }, - { - "Time": 131, - "Intensity": 0.35, - "Frequency": 20 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 414, - "Parameters": { - "Intensity": 51, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 256, - "StartTime": 474, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 0.46, - "Frequency": 3 - }, - { - "Time": 71, - "Intensity": 0.5, - "Frequency": -5 - }, - { - "Time": 163, - "Intensity": 1, - "Frequency": 3 - }, - { - "Time": 222, - "Intensity": 1, - "Frequency": -3 - }, - { - "Time": 255, - "Intensity": 0.72, - "Frequency": 0 - }, - { - "Time": 256, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 574, - "Parameters": { - "Intensity": 43, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 95, - "Intensity": 0.48, - "Frequency": -6 - }, - { - "Time": 140, - "Intensity": 0.09, - "Frequency": 0 - }, - { - "Time": 170, - "Intensity": 0.89, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 257, - "StartTime": 731, - "Parameters": { - "Intensity": 35, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.88, - "Frequency": 3 - }, - { - "Time": 64, - "Intensity": 0.82, - "Frequency": -5 - }, - { - "Time": 128, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 202, - "Intensity": 0.4, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.31, - "Frequency": -3 - }, - { - "Time": 257, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 990, - "Parameters": { - "Intensity": 70, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 34, - "Intensity": 0.47, - "Frequency": -5 - }, - { - "Time": 76, - "Intensity": 0.52, - "Frequency": 3 - }, - { - "Time": 138, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 208, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.29, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 990, - "Parameters": { - "Intensity": 32, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 102, - "Intensity": 0.72, - "Frequency": -6 - }, - { - "Time": 144, - "Intensity": 0.09, - "Frequency": 8 - }, - { - "Time": 169, - "Intensity": 0.25, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 230, - "Intensity": 0.53, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 298, - "StartTime": 1242, - "Parameters": { - "Intensity": 55, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.39, - "Frequency": 3 - }, - { - "Time": 99, - "Intensity": 0.5, - "Frequency": -5 - }, - { - "Time": 212, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 297, - "Intensity": 0.3, - "Frequency": -3 - }, - { - "Time": 298, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 298, - "StartTime": 1244, - "Parameters": { - "Intensity": 31, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 27, - "Intensity": 0.6, - "Frequency": 5 - }, - { - "Time": 79, - "Intensity": 0.08, - "Frequency": -13 - }, - { - "Time": 101, - "Intensity": 0.81, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.17, - "Frequency": 0 - }, - { - "Time": 202, - "Intensity": 0.24, - "Frequency": -16 - }, - { - "Time": 238, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 277, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 298, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1541, - "Parameters": { - "Intensity": 26, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1542, - "Parameters": { - "Intensity": 59, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.27, - "Frequency": 3 - }, - { - "Time": 40, - "Intensity": 0.39, - "Frequency": -5 - }, - { - "Time": 91, - "Intensity": 0.37, - "Frequency": 0 - }, - { - "Time": 135, - "Intensity": 0.43, - "Frequency": 3 - }, - { - "Time": 201, - "Intensity": 0.37, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.25, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1793, - "Parameters": { - "Intensity": 55, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.28, - "Frequency": 3 - }, - { - "Time": 46, - "Intensity": 0.3, - "Frequency": -5 - }, - { - "Time": 105, - "Intensity": 0.41, - "Frequency": 3 - }, - { - "Time": 162, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 213, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.23, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1793, - "Parameters": { - "Intensity": 20, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 251, - "StartTime": 2043, - "Parameters": { - "Intensity": 30, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.4, - "Frequency": 3 - }, - { - "Time": 81, - "Intensity": 0.71, - "Frequency": -5 - }, - { - "Time": 189, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 212, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 251, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2043, - "Parameters": { - "Intensity": 25, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 135, + "StartTime": 110, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 77, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 106, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 135, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 255, + "Parameters": { + "Intensity": 95, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 75, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 80, + "Intensity": 0.43, + "Frequency": -25 + }, + { + "Time": 131, + "Intensity": 0.35, + "Frequency": 20 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 414, + "Parameters": { + "Intensity": 51, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 256, + "StartTime": 474, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 0.46, + "Frequency": 3 + }, + { + "Time": 71, + "Intensity": 0.5, + "Frequency": -5 + }, + { + "Time": 163, + "Intensity": 1, + "Frequency": 3 + }, + { + "Time": 222, + "Intensity": 1, + "Frequency": -3 + }, + { + "Time": 255, + "Intensity": 0.72, + "Frequency": 0 + }, + { + "Time": 256, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 574, + "Parameters": { + "Intensity": 43, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 95, + "Intensity": 0.48, + "Frequency": -6 + }, + { + "Time": 140, + "Intensity": 0.09, + "Frequency": 0 + }, + { + "Time": 170, + "Intensity": 0.89, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 257, + "StartTime": 731, + "Parameters": { + "Intensity": 35, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.88, + "Frequency": 3 + }, + { + "Time": 64, + "Intensity": 0.82, + "Frequency": -5 + }, + { + "Time": 128, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 202, + "Intensity": 0.4, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.31, + "Frequency": -3 + }, + { + "Time": 257, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 990, + "Parameters": { + "Intensity": 70, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 34, + "Intensity": 0.47, + "Frequency": -5 + }, + { + "Time": 76, + "Intensity": 0.52, + "Frequency": 3 + }, + { + "Time": 138, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 208, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.29, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 990, + "Parameters": { + "Intensity": 32, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 102, + "Intensity": 0.72, + "Frequency": -6 + }, + { + "Time": 144, + "Intensity": 0.09, + "Frequency": 8 + }, + { + "Time": 169, + "Intensity": 0.25, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 230, + "Intensity": 0.53, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 298, + "StartTime": 1242, + "Parameters": { + "Intensity": 55, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.39, + "Frequency": 3 + }, + { + "Time": 99, + "Intensity": 0.5, + "Frequency": -5 + }, + { + "Time": 212, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 297, + "Intensity": 0.3, + "Frequency": -3 + }, + { + "Time": 298, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 298, + "StartTime": 1244, + "Parameters": { + "Intensity": 31, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 27, + "Intensity": 0.6, + "Frequency": 5 + }, + { + "Time": 79, + "Intensity": 0.08, + "Frequency": -13 + }, + { + "Time": 101, + "Intensity": 0.81, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.17, + "Frequency": 0 + }, + { + "Time": 202, + "Intensity": 0.24, + "Frequency": -16 + }, + { + "Time": 238, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 277, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 298, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1541, + "Parameters": { + "Intensity": 26, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1542, + "Parameters": { + "Intensity": 59, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.27, + "Frequency": 3 + }, + { + "Time": 40, + "Intensity": 0.39, + "Frequency": -5 + }, + { + "Time": 91, + "Intensity": 0.37, + "Frequency": 0 + }, + { + "Time": 135, + "Intensity": 0.43, + "Frequency": 3 + }, + { + "Time": 201, + "Intensity": 0.37, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.25, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1793, + "Parameters": { + "Intensity": 55, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.28, + "Frequency": 3 + }, + { + "Time": 46, + "Intensity": 0.3, + "Frequency": -5 + }, + { + "Time": 105, + "Intensity": 0.41, + "Frequency": 3 + }, + { + "Time": 162, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 213, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.23, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1793, + "Parameters": { + "Intensity": 20, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 251, + "StartTime": 2043, + "Parameters": { + "Intensity": 30, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.4, + "Frequency": 3 + }, + { + "Time": 81, + "Intensity": 0.71, + "Frequency": -5 + }, + { + "Time": 189, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 212, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 251, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2043, + "Parameters": { + "Intensity": 25, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_l.json index 60cdf5ccab3a0172120363ff75237ceccdc95856..693b1de4bd10c92be13dba78de81cce0e468adfe 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_l.json @@ -1,797 +1,797 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 135, - "StartTime": 110, - "Parameters": { - "Intensity": 22, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 77, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 106, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 135, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 255, - "Parameters": { - "Intensity": 57, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 75, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 80, - "Intensity": 0.43, - "Frequency": -25 - }, - { - "Time": 131, - "Intensity": 0.35, - "Frequency": 20 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 414, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 256, - "StartTime": 474, - "Parameters": { - "Intensity": 25, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 0.46, - "Frequency": 3 - }, - { - "Time": 71, - "Intensity": 0.5, - "Frequency": -5 - }, - { - "Time": 163, - "Intensity": 1, - "Frequency": 3 - }, - { - "Time": 222, - "Intensity": 1, - "Frequency": -3 - }, - { - "Time": 255, - "Intensity": 0.72, - "Frequency": 0 - }, - { - "Time": 256, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 574, - "Parameters": { - "Intensity": 25, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 95, - "Intensity": 0.48, - "Frequency": -6 - }, - { - "Time": 140, - "Intensity": 0.09, - "Frequency": 0 - }, - { - "Time": 170, - "Intensity": 0.89, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 257, - "StartTime": 731, - "Parameters": { - "Intensity": 21, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.88, - "Frequency": 3 - }, - { - "Time": 64, - "Intensity": 0.82, - "Frequency": -5 - }, - { - "Time": 128, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 202, - "Intensity": 0.4, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.31, - "Frequency": -3 - }, - { - "Time": 257, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 990, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 34, - "Intensity": 0.47, - "Frequency": -5 - }, - { - "Time": 76, - "Intensity": 0.52, - "Frequency": 3 - }, - { - "Time": 138, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 208, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.29, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 990, - "Parameters": { - "Intensity": 19, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 102, - "Intensity": 0.72, - "Frequency": -6 - }, - { - "Time": 144, - "Intensity": 0.09, - "Frequency": 8 - }, - { - "Time": 169, - "Intensity": 0.25, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 230, - "Intensity": 0.53, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 298, - "StartTime": 1242, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.39, - "Frequency": 3 - }, - { - "Time": 99, - "Intensity": 0.5, - "Frequency": -5 - }, - { - "Time": 212, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 297, - "Intensity": 0.3, - "Frequency": -3 - }, - { - "Time": 298, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 298, - "StartTime": 1244, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 27, - "Intensity": 0.6, - "Frequency": 5 - }, - { - "Time": 79, - "Intensity": 0.08, - "Frequency": -13 - }, - { - "Time": 101, - "Intensity": 0.81, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.17, - "Frequency": 0 - }, - { - "Time": 202, - "Intensity": 0.24, - "Frequency": -16 - }, - { - "Time": 238, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 277, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 298, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1541, - "Parameters": { - "Intensity": 15, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1542, - "Parameters": { - "Intensity": 35, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.27, - "Frequency": 3 - }, - { - "Time": 40, - "Intensity": 0.39, - "Frequency": -5 - }, - { - "Time": 91, - "Intensity": 0.37, - "Frequency": 0 - }, - { - "Time": 135, - "Intensity": 0.43, - "Frequency": 3 - }, - { - "Time": 201, - "Intensity": 0.37, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.25, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1793, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.28, - "Frequency": 3 - }, - { - "Time": 46, - "Intensity": 0.3, - "Frequency": -5 - }, - { - "Time": 105, - "Intensity": 0.41, - "Frequency": 3 - }, - { - "Time": 162, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 213, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.23, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1793, - "Parameters": { - "Intensity": 12, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 251, - "StartTime": 2043, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.4, - "Frequency": 3 - }, - { - "Time": 81, - "Intensity": 0.71, - "Frequency": -5 - }, - { - "Time": 189, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 212, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 251, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2043, - "Parameters": { - "Intensity": 15, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 135, + "StartTime": 110, + "Parameters": { + "Intensity": 22, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 77, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 106, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 135, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 255, + "Parameters": { + "Intensity": 57, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 75, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 80, + "Intensity": 0.43, + "Frequency": -25 + }, + { + "Time": 131, + "Intensity": 0.35, + "Frequency": 20 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 414, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 256, + "StartTime": 474, + "Parameters": { + "Intensity": 25, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 0.46, + "Frequency": 3 + }, + { + "Time": 71, + "Intensity": 0.5, + "Frequency": -5 + }, + { + "Time": 163, + "Intensity": 1, + "Frequency": 3 + }, + { + "Time": 222, + "Intensity": 1, + "Frequency": -3 + }, + { + "Time": 255, + "Intensity": 0.72, + "Frequency": 0 + }, + { + "Time": 256, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 574, + "Parameters": { + "Intensity": 25, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 95, + "Intensity": 0.48, + "Frequency": -6 + }, + { + "Time": 140, + "Intensity": 0.09, + "Frequency": 0 + }, + { + "Time": 170, + "Intensity": 0.89, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 257, + "StartTime": 731, + "Parameters": { + "Intensity": 21, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.88, + "Frequency": 3 + }, + { + "Time": 64, + "Intensity": 0.82, + "Frequency": -5 + }, + { + "Time": 128, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 202, + "Intensity": 0.4, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.31, + "Frequency": -3 + }, + { + "Time": 257, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 990, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 34, + "Intensity": 0.47, + "Frequency": -5 + }, + { + "Time": 76, + "Intensity": 0.52, + "Frequency": 3 + }, + { + "Time": 138, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 208, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.29, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 990, + "Parameters": { + "Intensity": 19, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 102, + "Intensity": 0.72, + "Frequency": -6 + }, + { + "Time": 144, + "Intensity": 0.09, + "Frequency": 8 + }, + { + "Time": 169, + "Intensity": 0.25, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 230, + "Intensity": 0.53, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 298, + "StartTime": 1242, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.39, + "Frequency": 3 + }, + { + "Time": 99, + "Intensity": 0.5, + "Frequency": -5 + }, + { + "Time": 212, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 297, + "Intensity": 0.3, + "Frequency": -3 + }, + { + "Time": 298, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 298, + "StartTime": 1244, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 27, + "Intensity": 0.6, + "Frequency": 5 + }, + { + "Time": 79, + "Intensity": 0.08, + "Frequency": -13 + }, + { + "Time": 101, + "Intensity": 0.81, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.17, + "Frequency": 0 + }, + { + "Time": 202, + "Intensity": 0.24, + "Frequency": -16 + }, + { + "Time": 238, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 277, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 298, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1541, + "Parameters": { + "Intensity": 15, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1542, + "Parameters": { + "Intensity": 35, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.27, + "Frequency": 3 + }, + { + "Time": 40, + "Intensity": 0.39, + "Frequency": -5 + }, + { + "Time": 91, + "Intensity": 0.37, + "Frequency": 0 + }, + { + "Time": 135, + "Intensity": 0.43, + "Frequency": 3 + }, + { + "Time": 201, + "Intensity": 0.37, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.25, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1793, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.28, + "Frequency": 3 + }, + { + "Time": 46, + "Intensity": 0.3, + "Frequency": -5 + }, + { + "Time": 105, + "Intensity": 0.41, + "Frequency": 3 + }, + { + "Time": 162, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 213, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.23, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1793, + "Parameters": { + "Intensity": 12, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 251, + "StartTime": 2043, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.4, + "Frequency": 3 + }, + { + "Time": 81, + "Intensity": 0.71, + "Frequency": -5 + }, + { + "Time": 189, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 212, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 251, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2043, + "Parameters": { + "Intensity": 15, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_m.json index ea582b9abebf6d5618414c1c6f3d4ff98d8996ad..c9053b0e5f0375170ea510400778967a61f5f0ee 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Diving_m.json @@ -1,797 +1,797 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 135, - "StartTime": 110, - "Parameters": { - "Intensity": 30, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 77, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 106, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 135, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 255, - "Parameters": { - "Intensity": 76, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 20 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 75, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 80, - "Intensity": 0.43, - "Frequency": -25 - }, - { - "Time": 131, - "Intensity": 0.35, - "Frequency": 20 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 414, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 256, - "StartTime": 474, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 0.46, - "Frequency": 3 - }, - { - "Time": 71, - "Intensity": 0.5, - "Frequency": -5 - }, - { - "Time": 163, - "Intensity": 1, - "Frequency": 3 - }, - { - "Time": 222, - "Intensity": 1, - "Frequency": -3 - }, - { - "Time": 255, - "Intensity": 0.72, - "Frequency": 0 - }, - { - "Time": 256, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 574, - "Parameters": { - "Intensity": 34, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 95, - "Intensity": 0.48, - "Frequency": -6 - }, - { - "Time": 140, - "Intensity": 0.09, - "Frequency": 0 - }, - { - "Time": 170, - "Intensity": 0.89, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 257, - "StartTime": 731, - "Parameters": { - "Intensity": 28, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.88, - "Frequency": 3 - }, - { - "Time": 64, - "Intensity": 0.82, - "Frequency": -5 - }, - { - "Time": 128, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 202, - "Intensity": 0.4, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.31, - "Frequency": -3 - }, - { - "Time": 257, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 990, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 34, - "Intensity": 0.47, - "Frequency": -5 - }, - { - "Time": 76, - "Intensity": 0.52, - "Frequency": 3 - }, - { - "Time": 138, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 208, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.29, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 990, - "Parameters": { - "Intensity": 25, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 102, - "Intensity": 0.72, - "Frequency": -6 - }, - { - "Time": 144, - "Intensity": 0.09, - "Frequency": 8 - }, - { - "Time": 169, - "Intensity": 0.25, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 230, - "Intensity": 0.53, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 298, - "StartTime": 1242, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.39, - "Frequency": 3 - }, - { - "Time": 99, - "Intensity": 0.5, - "Frequency": -5 - }, - { - "Time": 212, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 297, - "Intensity": 0.3, - "Frequency": -3 - }, - { - "Time": 298, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 298, - "StartTime": 1244, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 27, - "Intensity": 0.6, - "Frequency": 5 - }, - { - "Time": 79, - "Intensity": 0.08, - "Frequency": -13 - }, - { - "Time": 101, - "Intensity": 0.81, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.17, - "Frequency": 0 - }, - { - "Time": 202, - "Intensity": 0.24, - "Frequency": -16 - }, - { - "Time": 238, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 277, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 298, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1541, - "Parameters": { - "Intensity": 20, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1542, - "Parameters": { - "Intensity": 47, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.27, - "Frequency": 3 - }, - { - "Time": 40, - "Intensity": 0.39, - "Frequency": -5 - }, - { - "Time": 91, - "Intensity": 0.37, - "Frequency": 0 - }, - { - "Time": 135, - "Intensity": 0.43, - "Frequency": 3 - }, - { - "Time": 201, - "Intensity": 0.37, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.25, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1793, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.28, - "Frequency": 3 - }, - { - "Time": 46, - "Intensity": 0.3, - "Frequency": -5 - }, - { - "Time": 105, - "Intensity": 0.41, - "Frequency": 3 - }, - { - "Time": 162, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 213, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 249, - "Intensity": 0.23, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1793, - "Parameters": { - "Intensity": 16, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 251, - "StartTime": 2043, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.4, - "Frequency": 3 - }, - { - "Time": 81, - "Intensity": 0.71, - "Frequency": -5 - }, - { - "Time": 189, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 212, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 251, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2043, - "Parameters": { - "Intensity": 20, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 135, + "StartTime": 110, + "Parameters": { + "Intensity": 30, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 77, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 106, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 135, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 255, + "Parameters": { + "Intensity": 76, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 20 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 75, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 80, + "Intensity": 0.43, + "Frequency": -25 + }, + { + "Time": 131, + "Intensity": 0.35, + "Frequency": 20 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 414, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 256, + "StartTime": 474, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 0.46, + "Frequency": 3 + }, + { + "Time": 71, + "Intensity": 0.5, + "Frequency": -5 + }, + { + "Time": 163, + "Intensity": 1, + "Frequency": 3 + }, + { + "Time": 222, + "Intensity": 1, + "Frequency": -3 + }, + { + "Time": 255, + "Intensity": 0.72, + "Frequency": 0 + }, + { + "Time": 256, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 574, + "Parameters": { + "Intensity": 34, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 95, + "Intensity": 0.48, + "Frequency": -6 + }, + { + "Time": 140, + "Intensity": 0.09, + "Frequency": 0 + }, + { + "Time": 170, + "Intensity": 0.89, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 257, + "StartTime": 731, + "Parameters": { + "Intensity": 28, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.88, + "Frequency": 3 + }, + { + "Time": 64, + "Intensity": 0.82, + "Frequency": -5 + }, + { + "Time": 128, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 202, + "Intensity": 0.4, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.31, + "Frequency": -3 + }, + { + "Time": 257, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 990, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 34, + "Intensity": 0.47, + "Frequency": -5 + }, + { + "Time": 76, + "Intensity": 0.52, + "Frequency": 3 + }, + { + "Time": 138, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 208, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.29, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 990, + "Parameters": { + "Intensity": 25, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 102, + "Intensity": 0.72, + "Frequency": -6 + }, + { + "Time": 144, + "Intensity": 0.09, + "Frequency": 8 + }, + { + "Time": 169, + "Intensity": 0.25, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 230, + "Intensity": 0.53, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 298, + "StartTime": 1242, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.39, + "Frequency": 3 + }, + { + "Time": 99, + "Intensity": 0.5, + "Frequency": -5 + }, + { + "Time": 212, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 297, + "Intensity": 0.3, + "Frequency": -3 + }, + { + "Time": 298, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 298, + "StartTime": 1244, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 27, + "Intensity": 0.6, + "Frequency": 5 + }, + { + "Time": 79, + "Intensity": 0.08, + "Frequency": -13 + }, + { + "Time": 101, + "Intensity": 0.81, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.17, + "Frequency": 0 + }, + { + "Time": 202, + "Intensity": 0.24, + "Frequency": -16 + }, + { + "Time": 238, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 277, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 298, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1541, + "Parameters": { + "Intensity": 20, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1542, + "Parameters": { + "Intensity": 47, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.27, + "Frequency": 3 + }, + { + "Time": 40, + "Intensity": 0.39, + "Frequency": -5 + }, + { + "Time": 91, + "Intensity": 0.37, + "Frequency": 0 + }, + { + "Time": 135, + "Intensity": 0.43, + "Frequency": 3 + }, + { + "Time": 201, + "Intensity": 0.37, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.25, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1793, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.28, + "Frequency": 3 + }, + { + "Time": 46, + "Intensity": 0.3, + "Frequency": -5 + }, + { + "Time": 105, + "Intensity": 0.41, + "Frequency": 3 + }, + { + "Time": 162, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 213, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 249, + "Intensity": 0.23, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1793, + "Parameters": { + "Intensity": 16, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 251, + "StartTime": 2043, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.4, + "Frequency": 3 + }, + { + "Time": 81, + "Intensity": 0.71, + "Frequency": -5 + }, + { + "Time": 189, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 212, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 251, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2043, + "Parameters": { + "Intensity": 20, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_h.json index 0fb299d90eb18db9686f4548985ccc64db272296..de873e8f3a920729739dda1e771688f4967d313b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_h.json @@ -1,55 +1,55 @@ -{ - "MetaData": { - "Create": "2022-04-15", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 294, - "StartTime": 11, - "Parameters": { - "Intensity": 100, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 63, - "Intensity": 0.3, - "Frequency": -83 - }, - { - "Time": 109, - "Intensity": 1, - "Frequency": -26 - }, - { - "Time": 165, - "Intensity": 0.2, - "Frequency": -58 - }, - { - "Time": 294, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-15", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 294, + "StartTime": 11, + "Parameters": { + "Intensity": 100, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 63, + "Intensity": 0.3, + "Frequency": -83 + }, + { + "Time": 109, + "Intensity": 1, + "Frequency": -26 + }, + { + "Time": 165, + "Intensity": 0.2, + "Frequency": -58 + }, + { + "Time": 294, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_l.json index 8d3d95d30d8c61417d6e49e7e6555c21966c61f2..bf16055636b4486629ced3681b1c81e6176c2df3 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_l.json @@ -1,55 +1,55 @@ -{ - "MetaData": { - "Create": "2022-04-15", - "Discription": "EA json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 294, - "StartTime": 11, - "Parameters": { - "Intensity": 60, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 63, - "Intensity": 0.3, - "Frequency": -83 - }, - { - "Time": 109, - "Intensity": 1, - "Frequency": -26 - }, - { - "Time": 165, - "Intensity": 0.2, - "Frequency": -58 - }, - { - "Time": 294, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-15", + "Discription": "EA json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 294, + "StartTime": 11, + "Parameters": { + "Intensity": 60, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 63, + "Intensity": 0.3, + "Frequency": -83 + }, + { + "Time": 109, + "Intensity": 1, + "Frequency": -26 + }, + { + "Time": 165, + "Intensity": 0.2, + "Frequency": -58 + }, + { + "Time": 294, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_m.json index 9f97b2eeb2de0f6b050a24eea8b5faf2492853b7..5713d4803d7445041940efe30d2b643076374526 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/DriftingJet_m.json @@ -1,55 +1,55 @@ -{ - "MetaData": { - "Create": "2022-04-15", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 294, - "StartTime": 11, - "Parameters": { - "Intensity": 80, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 63, - "Intensity": 0.3, - "Frequency": -83 - }, - { - "Time": 109, - "Intensity": 1, - "Frequency": -26 - }, - { - "Time": 165, - "Intensity": 0.2, - "Frequency": -58 - }, - { - "Time": 294, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-15", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 294, + "StartTime": 11, + "Parameters": { + "Intensity": 80, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 63, + "Intensity": 0.3, + "Frequency": -83 + }, + { + "Time": 109, + "Intensity": 1, + "Frequency": -26 + }, + { + "Time": 165, + "Intensity": 0.2, + "Frequency": -58 + }, + { + "Time": 294, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_h.json index 88eafe36c3bb57ac1cb1e1d7694fd7e3d554ba2a..d8c3cc16625c132dfe8396109c92c306b723afd1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_h.json @@ -1,177 +1,177 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 67, - "Parameters": { - "Intensity": 93, - "Frequency": 61 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 381, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 478, - "Parameters": { - "Intensity": 100, - "Frequency": 69 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 498, - "Parameters": { - "Intensity": 57, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 663, - "Parameters": { - "Intensity": 100, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 726, - "Parameters": { - "Intensity": 48, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 799, - "Parameters": { - "Intensity": 100, - "Frequency": 63 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 846, - "Parameters": { - "Intensity": 89, - "Frequency": 91 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 904, - "Parameters": { - "Intensity": 86, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 928, - "Parameters": { - "Intensity": 77, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 961, - "Parameters": { - "Intensity": 68, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 992, - "Parameters": { - "Intensity": 61, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1038, - "Parameters": { - "Intensity": 53, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1066, - "Parameters": { - "Intensity": 51, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1117, - "Parameters": { - "Intensity": 45, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1161, - "Parameters": { - "Intensity": 30, - "Frequency": 93 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 67, + "Parameters": { + "Intensity": 93, + "Frequency": 61 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 381, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 478, + "Parameters": { + "Intensity": 100, + "Frequency": 69 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 498, + "Parameters": { + "Intensity": 57, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 663, + "Parameters": { + "Intensity": 100, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 726, + "Parameters": { + "Intensity": 48, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 799, + "Parameters": { + "Intensity": 100, + "Frequency": 63 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 846, + "Parameters": { + "Intensity": 89, + "Frequency": 91 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 904, + "Parameters": { + "Intensity": 86, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 928, + "Parameters": { + "Intensity": 77, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 961, + "Parameters": { + "Intensity": 68, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 992, + "Parameters": { + "Intensity": 61, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1038, + "Parameters": { + "Intensity": 53, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1066, + "Parameters": { + "Intensity": 51, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1117, + "Parameters": { + "Intensity": 45, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1161, + "Parameters": { + "Intensity": 30, + "Frequency": 93 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_l.json index da89162a0065e5cf2c0ff14d5ce2112fdd0dee2f..dc23e91a2dfe46c7ad88298e46c0e875d1b82d0e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_l.json @@ -1,177 +1,177 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 67, - "Parameters": { - "Intensity": 55, - "Frequency": 61 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 381, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 478, - "Parameters": { - "Intensity": 60, - "Frequency": 69 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 498, - "Parameters": { - "Intensity": 34, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 663, - "Parameters": { - "Intensity": 60, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 726, - "Parameters": { - "Intensity": 28, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 799, - "Parameters": { - "Intensity": 60, - "Frequency": 63 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 846, - "Parameters": { - "Intensity": 53, - "Frequency": 91 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 904, - "Parameters": { - "Intensity": 51, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 928, - "Parameters": { - "Intensity": 46, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 961, - "Parameters": { - "Intensity": 40, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 992, - "Parameters": { - "Intensity": 36, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1038, - "Parameters": { - "Intensity": 31, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1066, - "Parameters": { - "Intensity": 30, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1117, - "Parameters": { - "Intensity": 27, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1161, - "Parameters": { - "Intensity": 18, - "Frequency": 93 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 67, + "Parameters": { + "Intensity": 55, + "Frequency": 61 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 381, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 478, + "Parameters": { + "Intensity": 60, + "Frequency": 69 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 498, + "Parameters": { + "Intensity": 34, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 663, + "Parameters": { + "Intensity": 60, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 726, + "Parameters": { + "Intensity": 28, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 799, + "Parameters": { + "Intensity": 60, + "Frequency": 63 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 846, + "Parameters": { + "Intensity": 53, + "Frequency": 91 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 904, + "Parameters": { + "Intensity": 51, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 928, + "Parameters": { + "Intensity": 46, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 961, + "Parameters": { + "Intensity": 40, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 992, + "Parameters": { + "Intensity": 36, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1038, + "Parameters": { + "Intensity": 31, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1066, + "Parameters": { + "Intensity": 30, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1117, + "Parameters": { + "Intensity": 27, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1161, + "Parameters": { + "Intensity": 18, + "Frequency": 93 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_m.json index 88eb46a0cd3c3cef092bbe6311ae7230eed3e1b4..08255bc514176158ac3aac7df4e75718f94541de 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Firework_m.json @@ -1,177 +1,177 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 67, - "Parameters": { - "Intensity": 74, - "Frequency": 61 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 381, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 478, - "Parameters": { - "Intensity": 80, - "Frequency": 69 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 498, - "Parameters": { - "Intensity": 45, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 663, - "Parameters": { - "Intensity": 80, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 726, - "Parameters": { - "Intensity": 38, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 799, - "Parameters": { - "Intensity": 80, - "Frequency": 63 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 846, - "Parameters": { - "Intensity": 71, - "Frequency": 91 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 904, - "Parameters": { - "Intensity": 68, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 928, - "Parameters": { - "Intensity": 61, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 961, - "Parameters": { - "Intensity": 54, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 992, - "Parameters": { - "Intensity": 48, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1038, - "Parameters": { - "Intensity": 42, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1066, - "Parameters": { - "Intensity": 40, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1117, - "Parameters": { - "Intensity": 36, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1161, - "Parameters": { - "Intensity": 24, - "Frequency": 93 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 67, + "Parameters": { + "Intensity": 74, + "Frequency": 61 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 381, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 478, + "Parameters": { + "Intensity": 80, + "Frequency": 69 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 498, + "Parameters": { + "Intensity": 45, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 663, + "Parameters": { + "Intensity": 80, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 726, + "Parameters": { + "Intensity": 38, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 799, + "Parameters": { + "Intensity": 80, + "Frequency": 63 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 846, + "Parameters": { + "Intensity": 71, + "Frequency": 91 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 904, + "Parameters": { + "Intensity": 68, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 928, + "Parameters": { + "Intensity": 61, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 961, + "Parameters": { + "Intensity": 54, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 992, + "Parameters": { + "Intensity": 48, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1038, + "Parameters": { + "Intensity": 42, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1066, + "Parameters": { + "Intensity": 40, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1117, + "Parameters": { + "Intensity": 36, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1161, + "Parameters": { + "Intensity": 24, + "Frequency": 93 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gesture_up.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gesture_up.json index a7fbc70bd0d48768953ee426dfae518a3337bdaa..82c89a4c9b278772d29cd5aeb5baac018e3aa8d1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gesture_up.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gesture_up.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-03-03 18:28:51.965244", - "Description": "gesture up", - "Version": 1.0, - "ChannelNumber": 1 - }, - "Channels": [ - { - "Parameters": { - "Index": 1 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 30, - "Parameters": { - "Intensity": 100, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-03-03 18:28:51.965244", + "Description": "gesture up", + "Version": 1.0, + "ChannelNumber": 1 + }, + "Channels": [ + { + "Parameters": { + "Index": 1 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 30, + "Parameters": { + "Intensity": 100, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_h.json index b83577d2cf16b45b108db2ae8e7e1dba6a6ef937..5f6cc431ec124859c137a76eeec865a7630b4cd5 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_h.json @@ -1,70 +1,70 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 5000, - "StartTime": 85, - "Parameters": { - "Intensity": 72, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 11 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 107, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 200, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 314, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1643, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 3164, - "Intensity": 0.24, - "Frequency": 21 - }, - { - "Time": 5000, - "Intensity": 0, - "Frequency": -96 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 5000, + "StartTime": 85, + "Parameters": { + "Intensity": 72, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 11 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 107, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 200, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 314, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1643, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 3164, + "Intensity": 0.24, + "Frequency": 21 + }, + { + "Time": 5000, + "Intensity": 0, + "Frequency": -96 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_l.json index 316c8925621ca8022cdb6737c613a5d31b0f489d..a5ce425bf5785c22ebd7c63df1a907219f0ff049 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_l.json @@ -1,70 +1,70 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 5000, - "StartTime": 85, - "Parameters": { - "Intensity": 43, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 11 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 107, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 200, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 314, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1643, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 3164, - "Intensity": 0.24, - "Frequency": 21 - }, - { - "Time": 5000, - "Intensity": 0, - "Frequency": -96 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 5000, + "StartTime": 85, + "Parameters": { + "Intensity": 43, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 11 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 107, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 200, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 314, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1643, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 3164, + "Intensity": 0.24, + "Frequency": 21 + }, + { + "Time": 5000, + "Intensity": 0, + "Frequency": -96 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_m.json index 219f960785cd919f7ab3ecfd9c79276efc407687..7b2df04f4d70be38a359f7c0eb4e3bd09be59838 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Gong_m.json @@ -1,70 +1,70 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 5000, - "StartTime": 85, - "Parameters": { - "Intensity": 57, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 11 - }, - { - "Time": 29, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 107, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 200, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 314, - "Intensity": 0.6, - "Frequency": 0 - }, - { - "Time": 1643, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 3164, - "Intensity": 0.24, - "Frequency": 21 - }, - { - "Time": 5000, - "Intensity": 0, - "Frequency": -96 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 5000, + "StartTime": 85, + "Parameters": { + "Intensity": 57, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 11 + }, + { + "Time": 29, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 107, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 200, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 314, + "Intensity": 0.6, + "Frequency": 0 + }, + { + "Time": 1643, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 3164, + "Intensity": 0.24, + "Frequency": 21 + }, + { + "Time": 5000, + "Intensity": 0, + "Frequency": -96 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_h.json index cfdb1a01d6e203197850a5f711070484c0bf51ff..db97897d8e6ca72915965a43d2cdb31191edbfc8 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_h.json @@ -1,146 +1,146 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 11, - "Parameters": { - "Intensity": 100, - "Frequency": 89 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 426, - "StartTime": 56, - "Parameters": { - "Intensity": 48, - "Frequency": 94, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 304, - "Intensity": 0.6137255, - "Frequency": -26 - }, - { - "Time": 426, - "Intensity": 0.0, - "Frequency": -22 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 491, - "Parameters": { - "Intensity": 100, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 492, - "StartTime": 535, - "Parameters": { - "Intensity": 54, - "Frequency": 66, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 16, - "Intensity": 0.95490193, - "Frequency": 0 - }, - { - "Time": 221, - "Intensity": 0.7921569, - "Frequency": -29 - }, - { - "Time": 492, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1039, - "Parameters": { - "Intensity": 100, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 694, - "StartTime": 1090, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 487, - "Intensity": 0.73333335, - "Frequency": 0 - }, - { - "Time": 694, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 11, + "Parameters": { + "Intensity": 100, + "Frequency": 89 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 426, + "StartTime": 56, + "Parameters": { + "Intensity": 48, + "Frequency": 94, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 304, + "Intensity": 0.6137255, + "Frequency": -26 + }, + { + "Time": 426, + "Intensity": 0.0, + "Frequency": -22 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 491, + "Parameters": { + "Intensity": 100, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 492, + "StartTime": 535, + "Parameters": { + "Intensity": 54, + "Frequency": 66, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 16, + "Intensity": 0.95490193, + "Frequency": 0 + }, + { + "Time": 221, + "Intensity": 0.7921569, + "Frequency": -29 + }, + { + "Time": 492, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1039, + "Parameters": { + "Intensity": 100, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 694, + "StartTime": 1090, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 487, + "Intensity": 0.73333335, + "Frequency": 0 + }, + { + "Time": 694, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_l.json index e6536878c21ea75fe30bdbeaae4b7d9d1bb0272b..419025dbd4d3f6cb5629201e81055a1f1f101dd1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_l.json @@ -1,146 +1,146 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 11, - "Parameters": { - "Intensity": 60, - "Frequency": 89 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 426, - "StartTime": 56, - "Parameters": { - "Intensity": 28, - "Frequency": 94, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 304, - "Intensity": 0.6137255, - "Frequency": -26 - }, - { - "Time": 426, - "Intensity": 0.0, - "Frequency": -22 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 491, - "Parameters": { - "Intensity": 60, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 492, - "StartTime": 535, - "Parameters": { - "Intensity": 32, - "Frequency": 66, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 16, - "Intensity": 0.95490193, - "Frequency": 0 - }, - { - "Time": 221, - "Intensity": 0.7921569, - "Frequency": -29 - }, - { - "Time": 492, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1039, - "Parameters": { - "Intensity": 60, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 694, - "StartTime": 1090, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 487, - "Intensity": 0.73333335, - "Frequency": 0 - }, - { - "Time": 694, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 11, + "Parameters": { + "Intensity": 60, + "Frequency": 89 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 426, + "StartTime": 56, + "Parameters": { + "Intensity": 28, + "Frequency": 94, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 304, + "Intensity": 0.6137255, + "Frequency": -26 + }, + { + "Time": 426, + "Intensity": 0.0, + "Frequency": -22 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 491, + "Parameters": { + "Intensity": 60, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 492, + "StartTime": 535, + "Parameters": { + "Intensity": 32, + "Frequency": 66, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 16, + "Intensity": 0.95490193, + "Frequency": 0 + }, + { + "Time": 221, + "Intensity": 0.7921569, + "Frequency": -29 + }, + { + "Time": 492, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1039, + "Parameters": { + "Intensity": 60, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 694, + "StartTime": 1090, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 487, + "Intensity": 0.73333335, + "Frequency": 0 + }, + { + "Time": 694, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_m.json index 03ab8b478dd7cfd39c993d05704065a6a0def33f..c8199879a39cf04a865dc29779fa4fddc43a89f2 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Guitar_m.json @@ -1,146 +1,146 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 11, - "Parameters": { - "Intensity": 80, - "Frequency": 89 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 426, - "StartTime": 56, - "Parameters": { - "Intensity": 38, - "Frequency": 94, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 304, - "Intensity": 0.6137255, - "Frequency": -26 - }, - { - "Time": 426, - "Intensity": 0.0, - "Frequency": -22 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 491, - "Parameters": { - "Intensity": 80, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 492, - "StartTime": 535, - "Parameters": { - "Intensity": 43, - "Frequency": 66, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 16, - "Intensity": 0.95490193, - "Frequency": 0 - }, - { - "Time": 221, - "Intensity": 0.7921569, - "Frequency": -29 - }, - { - "Time": 492, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1039, - "Parameters": { - "Intensity": 80, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 694, - "StartTime": 1090, - "Parameters": { - "Intensity": 51, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 487, - "Intensity": 0.73333335, - "Frequency": 0 - }, - { - "Time": 694, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 11, + "Parameters": { + "Intensity": 80, + "Frequency": 89 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 426, + "StartTime": 56, + "Parameters": { + "Intensity": 38, + "Frequency": 94, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 304, + "Intensity": 0.6137255, + "Frequency": -26 + }, + { + "Time": 426, + "Intensity": 0.0, + "Frequency": -22 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 491, + "Parameters": { + "Intensity": 80, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 492, + "StartTime": 535, + "Parameters": { + "Intensity": 43, + "Frequency": 66, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 16, + "Intensity": 0.95490193, + "Frequency": 0 + }, + { + "Time": 221, + "Intensity": 0.7921569, + "Frequency": -29 + }, + { + "Time": 492, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1039, + "Parameters": { + "Intensity": 80, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 694, + "StartTime": 1090, + "Parameters": { + "Intensity": 51, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 487, + "Intensity": 0.73333335, + "Frequency": 0 + }, + { + "Time": 694, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_h.json index 1187798891e0f44669662abf6910c0edf59973f7..f4ec693e924850d8308bbb8dd451ed8509a7d312 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_h.json @@ -1,83 +1,83 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 41, - "StartTime": 130, - "Parameters": { - "Intensity": 70, - "Frequency": 37, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 41, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 55, - "StartTime": 202, - "Parameters": { - "Intensity": 100, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 55, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 41, + "StartTime": 130, + "Parameters": { + "Intensity": 70, + "Frequency": 37, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 41, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 55, + "StartTime": 202, + "Parameters": { + "Intensity": 100, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 55, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_l.json index c7c5a133f9126fd21453d42a4406117e4ab7983a..35c1090b6dc5d7711c4039a981378be56d1fd7e0 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_l.json @@ -1,83 +1,83 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 41, - "StartTime": 130, - "Parameters": { - "Intensity": 42, - "Frequency": 37, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 41, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 55, - "StartTime": 202, - "Parameters": { - "Intensity": 60, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 55, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 41, + "StartTime": 130, + "Parameters": { + "Intensity": 42, + "Frequency": 37, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 41, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 55, + "StartTime": 202, + "Parameters": { + "Intensity": 60, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 55, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_m.json index e3c2fee114135e9a2f5108e0cb2c4c47d631de8e..bee33340583d2aeac8a567f5da675f122ee0287d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HK416_m.json @@ -1,83 +1,83 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 41, - "StartTime": 130, - "Parameters": { - "Intensity": 56, - "Frequency": 37, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 41, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 55, - "StartTime": 202, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 55, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 41, + "StartTime": 130, + "Parameters": { + "Intensity": 56, + "Frequency": 37, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 41, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 55, + "StartTime": 202, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 55, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HapticVideo.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HapticVideo.json index 7e4ea04823fba70d5adecd8da347db5375fe4685..15c7702989af14480151bf739f8ea49f8f2fd579 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HapticVideo.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HapticVideo.json @@ -1,261 +1,261 @@ -{ - "MetaData": { - "Create": "2023-05-25 18:19:52.022145", - "Description": "a json file format demo", - "Version": 1.0, - "ChannelNumber": 1 - }, - "Channels": [ - { - "Parameters": { - "Index": 1 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 414, - "Parameters": { - "Intensity": 38, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 444, - "Parameters": { - "Intensity": 38, - "Frequency": 50 - }, - "Duration": 16 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 460, - "Parameters": { - "Intensity": 100, - "Frequency": 53 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 506, - "Parameters": { - "Intensity": 48, - "Frequency": 53 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 552, - "Parameters": { - "Intensity": 92, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 582, - "Parameters": { - "Intensity": 92, - "Frequency": 53 - }, - "Duration": 16 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 598, - "Parameters": { - "Intensity": 73, - "Frequency": 37 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 644, - "Parameters": { - "Intensity": 42, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 674, - "Parameters": { - "Intensity": 42, - "Frequency": 43 - }, - "Duration": 16 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 690, - "Parameters": { - "Intensity": 40, - "Frequency": 44 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 736, - "Parameters": { - "Intensity": 16, - "Frequency": 44 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 782, - "Parameters": { - "Intensity": 30, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 828, - "Parameters": { - "Intensity": 10, - "Frequency": 44 - }, - "Duration": 92 - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1288, - "Parameters": { - "Intensity": 30, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 1334, - "Parameters": { - "Intensity": 5, - "Frequency": 44 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1610, - "Parameters": { - "Intensity": 30, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2484, - "Parameters": { - "Intensity": 30, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 2530, - "Parameters": { - "Intensity": 4, - "Frequency": 44 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4140, - "Parameters": { - "Intensity": 30, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4968, - "Parameters": { - "Intensity": 30, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 5014, - "Parameters": { - "Intensity": 4, - "Frequency": 44 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 5060, - "Parameters": { - "Intensity": 6, - "Frequency": 44 - }, - "Duration": 46 - } - }, - { - "Event": { - "Type": "continuous", - "StartTime": 5106, - "Parameters": { - "Intensity": 8, - "Frequency": 44 - }, - "Duration": 92 - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-05-25 18:19:52.022145", + "Description": "a json file format demo", + "Version": 1.0, + "ChannelNumber": 1 + }, + "Channels": [ + { + "Parameters": { + "Index": 1 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 414, + "Parameters": { + "Intensity": 38, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 444, + "Parameters": { + "Intensity": 38, + "Frequency": 50 + }, + "Duration": 16 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 460, + "Parameters": { + "Intensity": 100, + "Frequency": 53 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 506, + "Parameters": { + "Intensity": 48, + "Frequency": 53 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 552, + "Parameters": { + "Intensity": 92, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 582, + "Parameters": { + "Intensity": 92, + "Frequency": 53 + }, + "Duration": 16 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 598, + "Parameters": { + "Intensity": 73, + "Frequency": 37 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 644, + "Parameters": { + "Intensity": 42, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 674, + "Parameters": { + "Intensity": 42, + "Frequency": 43 + }, + "Duration": 16 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 690, + "Parameters": { + "Intensity": 40, + "Frequency": 44 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 736, + "Parameters": { + "Intensity": 16, + "Frequency": 44 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 782, + "Parameters": { + "Intensity": 30, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 828, + "Parameters": { + "Intensity": 10, + "Frequency": 44 + }, + "Duration": 92 + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1288, + "Parameters": { + "Intensity": 30, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 1334, + "Parameters": { + "Intensity": 5, + "Frequency": 44 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1610, + "Parameters": { + "Intensity": 30, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2484, + "Parameters": { + "Intensity": 30, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 2530, + "Parameters": { + "Intensity": 4, + "Frequency": 44 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4140, + "Parameters": { + "Intensity": 30, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4968, + "Parameters": { + "Intensity": 30, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 5014, + "Parameters": { + "Intensity": 4, + "Frequency": 44 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 5060, + "Parameters": { + "Intensity": 6, + "Frequency": 44 + }, + "Duration": 46 + } + }, + { + "Event": { + "Type": "continuous", + "StartTime": 5106, + "Parameters": { + "Intensity": 8, + "Frequency": 44 + }, + "Duration": 92 + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_h.json index 9995877a2ee6365808b1f77d951fe2491e814fc0..83473545d8c3b62e456e70652c0955a3aa1a59b4 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_h.json @@ -1,265 +1,265 @@ -{ - "MetaData": { - "Create": "2022-05-25", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 242, - "Parameters": { - "Intensity": 91, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 281, - "Parameters": { - "Intensity": 100, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 302, - "Parameters": { - "Intensity": 0, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 317, - "Parameters": { - "Intensity": 90, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 377, - "Parameters": { - "Intensity": 0, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 392, - "Parameters": { - "Intensity": 37, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 469, - "Parameters": { - "Intensity": 50, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 549, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 642, - "Parameters": { - "Intensity": 73, - "Frequency": 76 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 679, - "Parameters": { - "Intensity": 100, - "Frequency": 46 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 733, - "Parameters": { - "Intensity": 70, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 789, - "Parameters": { - "Intensity": 49, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 847, - "Parameters": { - "Intensity": 33, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 909, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 200, - "StartTime": 963, - "Parameters": { - "Intensity": 100, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 17, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 34, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 84, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 117, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 134, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 167, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 184, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 60 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1013, - "Parameters": { - "Intensity": 47, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1087, - "Parameters": { - "Intensity": 40, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1270, - "Parameters": { - "Intensity": 0, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-25", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 242, + "Parameters": { + "Intensity": 91, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 281, + "Parameters": { + "Intensity": 100, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 302, + "Parameters": { + "Intensity": 0, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 317, + "Parameters": { + "Intensity": 90, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 377, + "Parameters": { + "Intensity": 0, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 392, + "Parameters": { + "Intensity": 37, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 469, + "Parameters": { + "Intensity": 50, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 549, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 642, + "Parameters": { + "Intensity": 73, + "Frequency": 76 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 679, + "Parameters": { + "Intensity": 100, + "Frequency": 46 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 733, + "Parameters": { + "Intensity": 70, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 789, + "Parameters": { + "Intensity": 49, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 847, + "Parameters": { + "Intensity": 33, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 909, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 200, + "StartTime": 963, + "Parameters": { + "Intensity": 100, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 17, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 34, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 84, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 117, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 134, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 167, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 184, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 60 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1013, + "Parameters": { + "Intensity": 47, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1087, + "Parameters": { + "Intensity": 40, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1270, + "Parameters": { + "Intensity": 0, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_l.json index 492a4caf9cdb395d5d7e219e42d727c65226116c..531f1a81b73e222024ecb32d29a4b7f363b29606 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_l.json @@ -1,265 +1,265 @@ -{ - "MetaData": { - "Create": "2022-05-25", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 242, - "Parameters": { - "Intensity": 54, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 281, - "Parameters": { - "Intensity": 60, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 302, - "Parameters": { - "Intensity": 0, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 317, - "Parameters": { - "Intensity": 54, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 377, - "Parameters": { - "Intensity": 0, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 392, - "Parameters": { - "Intensity": 22, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 469, - "Parameters": { - "Intensity": 30, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 549, - "Parameters": { - "Intensity": 23, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 642, - "Parameters": { - "Intensity": 43, - "Frequency": 76 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 679, - "Parameters": { - "Intensity": 60, - "Frequency": 46 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 733, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 789, - "Parameters": { - "Intensity": 29, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 847, - "Parameters": { - "Intensity": 19, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 909, - "Parameters": { - "Intensity": 38, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 200, - "StartTime": 963, - "Parameters": { - "Intensity": 60, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 17, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 34, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 84, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 117, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 134, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 167, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 184, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 60 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1013, - "Parameters": { - "Intensity": 28, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1087, - "Parameters": { - "Intensity": 24, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1270, - "Parameters": { - "Intensity": 0, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-25", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 242, + "Parameters": { + "Intensity": 54, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 281, + "Parameters": { + "Intensity": 60, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 302, + "Parameters": { + "Intensity": 0, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 317, + "Parameters": { + "Intensity": 54, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 377, + "Parameters": { + "Intensity": 0, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 392, + "Parameters": { + "Intensity": 22, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 469, + "Parameters": { + "Intensity": 30, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 549, + "Parameters": { + "Intensity": 23, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 642, + "Parameters": { + "Intensity": 43, + "Frequency": 76 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 679, + "Parameters": { + "Intensity": 60, + "Frequency": 46 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 733, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 789, + "Parameters": { + "Intensity": 29, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 847, + "Parameters": { + "Intensity": 19, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 909, + "Parameters": { + "Intensity": 38, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 200, + "StartTime": 963, + "Parameters": { + "Intensity": 60, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 17, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 34, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 84, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 117, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 134, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 167, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 184, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 60 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1013, + "Parameters": { + "Intensity": 28, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1087, + "Parameters": { + "Intensity": 24, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1270, + "Parameters": { + "Intensity": 0, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_m.json index d74290df9fffb1794249131b012b964047fd7aa0..e619ed8f559b8b5a0706ec8e6cc9088f6066e9c2 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitGlass_m.json @@ -1,265 +1,265 @@ -{ - "MetaData": { - "Create": "2022-05-25", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 242, - "Parameters": { - "Intensity": 72, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 281, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 302, - "Parameters": { - "Intensity": 0, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 317, - "Parameters": { - "Intensity": 72, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 377, - "Parameters": { - "Intensity": 0, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 392, - "Parameters": { - "Intensity": 29, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 469, - "Parameters": { - "Intensity": 40, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 549, - "Parameters": { - "Intensity": 31, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 642, - "Parameters": { - "Intensity": 58, - "Frequency": 76 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 679, - "Parameters": { - "Intensity": 80, - "Frequency": 46 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 733, - "Parameters": { - "Intensity": 56, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 789, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 847, - "Parameters": { - "Intensity": 26, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 909, - "Parameters": { - "Intensity": 51, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 200, - "StartTime": 963, - "Parameters": { - "Intensity": 80, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 17, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 34, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 84, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 117, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 134, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 167, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 184, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 60 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1013, - "Parameters": { - "Intensity": 37, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1087, - "Parameters": { - "Intensity": 32, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1270, - "Parameters": { - "Intensity": 0, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-25", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 242, + "Parameters": { + "Intensity": 72, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 281, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 302, + "Parameters": { + "Intensity": 0, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 317, + "Parameters": { + "Intensity": 72, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 377, + "Parameters": { + "Intensity": 0, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 392, + "Parameters": { + "Intensity": 29, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 469, + "Parameters": { + "Intensity": 40, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 549, + "Parameters": { + "Intensity": 31, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 642, + "Parameters": { + "Intensity": 58, + "Frequency": 76 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 679, + "Parameters": { + "Intensity": 80, + "Frequency": 46 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 733, + "Parameters": { + "Intensity": 56, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 789, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 847, + "Parameters": { + "Intensity": 26, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 909, + "Parameters": { + "Intensity": 51, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 200, + "StartTime": 963, + "Parameters": { + "Intensity": 80, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 17, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 34, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 84, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 117, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 134, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 167, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 184, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 60 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1013, + "Parameters": { + "Intensity": 37, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1087, + "Parameters": { + "Intensity": 32, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1270, + "Parameters": { + "Intensity": 0, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_h.json index a72276d42253c56667473c5e217ad3b10204907a..c2d21f7528139419ba4559db15d9e6de8c192ecc 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_h.json @@ -1,186 +1,186 @@ -{ - "MetaData": { - "Create": "2022-05-28", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 105, - "StartTime": 0, - "Parameters": { - "Intensity": 50, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 43, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 70, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 92, - "Intensity": 0.08, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 105, - "StartTime": 0, - "Parameters": { - "Intensity": 50, - "Frequency": 88, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 43, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 70, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 105, - "Parameters": { - "Intensity": 100, - "Frequency": 62 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 148, - "Parameters": { - "Intensity": 71, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 655, - "StartTime": 160, - "Parameters": { - "Intensity": 96, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.56, - "Frequency": 10 - }, - { - "Time": 42, - "Intensity": 0.66, - "Frequency": 10 - }, - { - "Time": 139, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 231, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 329, - "Intensity": 0.44, - "Frequency": 10 - }, - { - "Time": 445, - "Intensity": 0.24, - "Frequency": -5 - }, - { - "Time": 526, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 583, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 655, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-28", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 105, + "StartTime": 0, + "Parameters": { + "Intensity": 50, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 43, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 70, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 92, + "Intensity": 0.08, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 105, + "StartTime": 0, + "Parameters": { + "Intensity": 50, + "Frequency": 88, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 43, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 70, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 105, + "Parameters": { + "Intensity": 100, + "Frequency": 62 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 148, + "Parameters": { + "Intensity": 71, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 655, + "StartTime": 160, + "Parameters": { + "Intensity": 96, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.56, + "Frequency": 10 + }, + { + "Time": 42, + "Intensity": 0.66, + "Frequency": 10 + }, + { + "Time": 139, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 231, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 329, + "Intensity": 0.44, + "Frequency": 10 + }, + { + "Time": 445, + "Intensity": 0.24, + "Frequency": -5 + }, + { + "Time": 526, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 583, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 655, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_l.json index 0cbb41e6cee1f422a6b680b78d86cb91a276786e..245503fb4863353df45b41d36735b1739a23e8a8 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_l.json @@ -1,186 +1,186 @@ -{ - "MetaData": { - "Create": "2022-05-28", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 105, - "StartTime": 0, - "Parameters": { - "Intensity": 30, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 43, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 70, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 92, - "Intensity": 0.08, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 105, - "StartTime": 0, - "Parameters": { - "Intensity": 30, - "Frequency": 88, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 43, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 70, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 105, - "Parameters": { - "Intensity": 60, - "Frequency": 62 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 148, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 655, - "StartTime": 160, - "Parameters": { - "Intensity": 57, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.56, - "Frequency": 10 - }, - { - "Time": 42, - "Intensity": 0.66, - "Frequency": 10 - }, - { - "Time": 139, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 231, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 329, - "Intensity": 0.44, - "Frequency": 10 - }, - { - "Time": 445, - "Intensity": 0.24, - "Frequency": -5 - }, - { - "Time": 526, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 583, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 655, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-28", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 105, + "StartTime": 0, + "Parameters": { + "Intensity": 30, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 43, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 70, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 92, + "Intensity": 0.08, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 105, + "StartTime": 0, + "Parameters": { + "Intensity": 30, + "Frequency": 88, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 43, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 70, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 105, + "Parameters": { + "Intensity": 60, + "Frequency": 62 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 148, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 655, + "StartTime": 160, + "Parameters": { + "Intensity": 57, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.56, + "Frequency": 10 + }, + { + "Time": 42, + "Intensity": 0.66, + "Frequency": 10 + }, + { + "Time": 139, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 231, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 329, + "Intensity": 0.44, + "Frequency": 10 + }, + { + "Time": 445, + "Intensity": 0.24, + "Frequency": -5 + }, + { + "Time": 526, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 583, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 655, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_m.json index ea2ea78a1602c8c7222d13d30db19ac185e6c0bc..b9d0a19dfdbc141c111e9a82e0da7995ff5fa7d2 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitMetal_m.json @@ -1,186 +1,186 @@ -{ - "MetaData": { - "Create": "2022-05-28", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 105, - "StartTime": 0, - "Parameters": { - "Intensity": 40, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 43, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 70, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 92, - "Intensity": 0.08, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 105, - "StartTime": 0, - "Parameters": { - "Intensity": 40, - "Frequency": 88, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 43, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 70, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 105, - "Parameters": { - "Intensity": 80, - "Frequency": 62 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 148, - "Parameters": { - "Intensity": 56, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 655, - "StartTime": 160, - "Parameters": { - "Intensity": 76, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.56, - "Frequency": 10 - }, - { - "Time": 42, - "Intensity": 0.66, - "Frequency": 10 - }, - { - "Time": 139, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 231, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 329, - "Intensity": 0.44, - "Frequency": 10 - }, - { - "Time": 445, - "Intensity": 0.24, - "Frequency": -5 - }, - { - "Time": 526, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 583, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 655, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-28", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 105, + "StartTime": 0, + "Parameters": { + "Intensity": 40, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 43, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 70, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 92, + "Intensity": 0.08, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 105, + "StartTime": 0, + "Parameters": { + "Intensity": 40, + "Frequency": 88, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 43, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 70, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 105, + "Parameters": { + "Intensity": 80, + "Frequency": 62 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 148, + "Parameters": { + "Intensity": 56, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 655, + "StartTime": 160, + "Parameters": { + "Intensity": 76, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.56, + "Frequency": 10 + }, + { + "Time": 42, + "Intensity": 0.66, + "Frequency": 10 + }, + { + "Time": 139, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 231, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 329, + "Intensity": 0.44, + "Frequency": 10 + }, + { + "Time": 445, + "Intensity": 0.24, + "Frequency": -5 + }, + { + "Time": 526, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 583, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 655, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_h.json index 40bc8a7c9c3d3d5cd49ec6a6a07a358ae2db38c0..7b5f7d0abd0cbad8f60c636a0a04ade9d45796f4 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_h.json @@ -1,158 +1,158 @@ -{ - "MetaData": { - "Create": "2022-05-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 171, - "StartTime": 0, - "Parameters": { - "Intensity": 51, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 26, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 143, - "Intensity": 0.75, - "Frequency": 0 - }, - { - "Time": 171, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 173, - "StartTime": 3, - "Parameters": { - "Intensity": 41, - "Frequency": 49, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 131, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 160, - "Intensity": 0.35, - "Frequency": 36 - }, - { - "Time": 173, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 176, - "Parameters": { - "Intensity": 100, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 304, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 336, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 421, - "Parameters": { - "Intensity": 38, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 475, - "Parameters": { - "Intensity": 33, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 519, - "Parameters": { - "Intensity": 27, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 556, - "Parameters": { - "Intensity": 20, - "Frequency": 78 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 171, + "StartTime": 0, + "Parameters": { + "Intensity": 51, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 26, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 143, + "Intensity": 0.75, + "Frequency": 0 + }, + { + "Time": 171, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 173, + "StartTime": 3, + "Parameters": { + "Intensity": 41, + "Frequency": 49, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 131, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 160, + "Intensity": 0.35, + "Frequency": 36 + }, + { + "Time": 173, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 176, + "Parameters": { + "Intensity": 100, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 304, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 336, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 421, + "Parameters": { + "Intensity": 38, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 475, + "Parameters": { + "Intensity": 33, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 519, + "Parameters": { + "Intensity": 27, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 556, + "Parameters": { + "Intensity": 20, + "Frequency": 78 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_l.json index f8cf239d0a4b200f54af7c58d4a5a1442768eba0..2cf22e52020677290de86cbf9f4cc374e9ae9111 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_l.json @@ -1,158 +1,158 @@ -{ - "MetaData": { - "Create": "2022-05-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 171, - "StartTime": 0, - "Parameters": { - "Intensity": 30, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 26, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 143, - "Intensity": 0.75, - "Frequency": 0 - }, - { - "Time": 171, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 173, - "StartTime": 3, - "Parameters": { - "Intensity": 24, - "Frequency": 49, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 131, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 160, - "Intensity": 0.35, - "Frequency": 36 - }, - { - "Time": 173, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 176, - "Parameters": { - "Intensity": 60, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 304, - "Parameters": { - "Intensity": 25, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 336, - "Parameters": { - "Intensity": 25, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 421, - "Parameters": { - "Intensity": 22, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 475, - "Parameters": { - "Intensity": 19, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 519, - "Parameters": { - "Intensity": 16, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 556, - "Parameters": { - "Intensity": 12, - "Frequency": 78 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 171, + "StartTime": 0, + "Parameters": { + "Intensity": 30, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 26, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 143, + "Intensity": 0.75, + "Frequency": 0 + }, + { + "Time": 171, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 173, + "StartTime": 3, + "Parameters": { + "Intensity": 24, + "Frequency": 49, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 131, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 160, + "Intensity": 0.35, + "Frequency": 36 + }, + { + "Time": 173, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 176, + "Parameters": { + "Intensity": 60, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 304, + "Parameters": { + "Intensity": 25, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 336, + "Parameters": { + "Intensity": 25, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 421, + "Parameters": { + "Intensity": 22, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 475, + "Parameters": { + "Intensity": 19, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 519, + "Parameters": { + "Intensity": 16, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 556, + "Parameters": { + "Intensity": 12, + "Frequency": 78 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_m.json index cd1d36e9613fa6df84a618626440e8f1fe2bbb3a..31a08459cc4f947d102777b022d2d610b2fbea49 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitSand_m.json @@ -1,158 +1,158 @@ -{ - "MetaData": { - "Create": "2022-05-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 171, - "StartTime": 0, - "Parameters": { - "Intensity": 40, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 26, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 143, - "Intensity": 0.75, - "Frequency": 0 - }, - { - "Time": 171, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 173, - "StartTime": 3, - "Parameters": { - "Intensity": 32, - "Frequency": 49, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 131, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 160, - "Intensity": 0.35, - "Frequency": 36 - }, - { - "Time": 173, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 176, - "Parameters": { - "Intensity": 80, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 304, - "Parameters": { - "Intensity": 33, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 336, - "Parameters": { - "Intensity": 33, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 421, - "Parameters": { - "Intensity": 30, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 475, - "Parameters": { - "Intensity": 26, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 519, - "Parameters": { - "Intensity": 21, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 556, - "Parameters": { - "Intensity": 16, - "Frequency": 78 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 171, + "StartTime": 0, + "Parameters": { + "Intensity": 40, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 26, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 143, + "Intensity": 0.75, + "Frequency": 0 + }, + { + "Time": 171, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 173, + "StartTime": 3, + "Parameters": { + "Intensity": 32, + "Frequency": 49, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 131, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 160, + "Intensity": 0.35, + "Frequency": 36 + }, + { + "Time": 173, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 176, + "Parameters": { + "Intensity": 80, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 304, + "Parameters": { + "Intensity": 33, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 336, + "Parameters": { + "Intensity": 33, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 421, + "Parameters": { + "Intensity": 30, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 475, + "Parameters": { + "Intensity": 26, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 519, + "Parameters": { + "Intensity": 21, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 556, + "Parameters": { + "Intensity": 16, + "Frequency": 78 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_h.json index faa9ba58008c4d510856881131e1e50a262d6d4d..c73ea4184add482ac2a5a1e7e32db02c6cf70a76 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_h.json @@ -1,153 +1,153 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 233, - "StartTime": 23, - "Parameters": { - "Intensity": 84, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 28 - }, - { - "Time": 25, - "Intensity": 0.19, - "Frequency": 25 - }, - { - "Time": 75, - "Intensity": 0.32, - "Frequency": 29 - }, - { - "Time": 131, - "Intensity": 0.46, - "Frequency": 43 - }, - { - "Time": 177, - "Intensity": 0.5, - "Frequency": 53 - }, - { - "Time": 198, - "Intensity": 0.2, - "Frequency": 48 - }, - { - "Time": 218, - "Intensity": 0.08, - "Frequency": 41 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 48 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 177, - "Parameters": { - "Intensity": 100, - "Frequency": 46 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 266, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 28 - }, - { - "Time": 27, - "Intensity": 0.19, - "Frequency": 25 - }, - { - "Time": 81, - "Intensity": 0.32, - "Frequency": 29 - }, - { - "Time": 136, - "Intensity": 0.39, - "Frequency": 43 - }, - { - "Time": 187, - "Intensity": 0.32, - "Frequency": 53 - }, - { - "Time": 212, - "Intensity": 0.2, - "Frequency": 48 - }, - { - "Time": 233, - "Intensity": 0.08, - "Frequency": 41 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 48 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 308, - "Parameters": { - "Intensity": 89, - "Frequency": 13 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 382, - "Parameters": { - "Intensity": 81, - "Frequency": 13 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 233, + "StartTime": 23, + "Parameters": { + "Intensity": 84, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 28 + }, + { + "Time": 25, + "Intensity": 0.19, + "Frequency": 25 + }, + { + "Time": 75, + "Intensity": 0.32, + "Frequency": 29 + }, + { + "Time": 131, + "Intensity": 0.46, + "Frequency": 43 + }, + { + "Time": 177, + "Intensity": 0.5, + "Frequency": 53 + }, + { + "Time": 198, + "Intensity": 0.2, + "Frequency": 48 + }, + { + "Time": 218, + "Intensity": 0.08, + "Frequency": 41 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 48 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 177, + "Parameters": { + "Intensity": 100, + "Frequency": 46 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 266, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 28 + }, + { + "Time": 27, + "Intensity": 0.19, + "Frequency": 25 + }, + { + "Time": 81, + "Intensity": 0.32, + "Frequency": 29 + }, + { + "Time": 136, + "Intensity": 0.39, + "Frequency": 43 + }, + { + "Time": 187, + "Intensity": 0.32, + "Frequency": 53 + }, + { + "Time": 212, + "Intensity": 0.2, + "Frequency": 48 + }, + { + "Time": 233, + "Intensity": 0.08, + "Frequency": 41 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 48 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 308, + "Parameters": { + "Intensity": 89, + "Frequency": 13 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 382, + "Parameters": { + "Intensity": 81, + "Frequency": 13 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_l.json index b8d1bb71f60bc202d88fe7ededbde467c835af70..81d5b8d1cea42b713bc8692c0b251be87efb4d4f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_l.json @@ -1,153 +1,153 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 233, - "StartTime": 23, - "Parameters": { - "Intensity": 50, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 28 - }, - { - "Time": 25, - "Intensity": 0.19, - "Frequency": 25 - }, - { - "Time": 75, - "Intensity": 0.32, - "Frequency": 29 - }, - { - "Time": 131, - "Intensity": 0.46, - "Frequency": 43 - }, - { - "Time": 177, - "Intensity": 0.5, - "Frequency": 53 - }, - { - "Time": 198, - "Intensity": 0.2, - "Frequency": 48 - }, - { - "Time": 218, - "Intensity": 0.08, - "Frequency": 41 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 48 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 177, - "Parameters": { - "Intensity": 60, - "Frequency": 46 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 266, - "Parameters": { - "Intensity": 26, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 28 - }, - { - "Time": 27, - "Intensity": 0.19, - "Frequency": 25 - }, - { - "Time": 81, - "Intensity": 0.32, - "Frequency": 29 - }, - { - "Time": 136, - "Intensity": 0.39, - "Frequency": 43 - }, - { - "Time": 187, - "Intensity": 0.32, - "Frequency": 53 - }, - { - "Time": 212, - "Intensity": 0.2, - "Frequency": 48 - }, - { - "Time": 233, - "Intensity": 0.08, - "Frequency": 41 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 48 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 308, - "Parameters": { - "Intensity": 53, - "Frequency": 13 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 382, - "Parameters": { - "Intensity": 48, - "Frequency": 13 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 233, + "StartTime": 23, + "Parameters": { + "Intensity": 50, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 28 + }, + { + "Time": 25, + "Intensity": 0.19, + "Frequency": 25 + }, + { + "Time": 75, + "Intensity": 0.32, + "Frequency": 29 + }, + { + "Time": 131, + "Intensity": 0.46, + "Frequency": 43 + }, + { + "Time": 177, + "Intensity": 0.5, + "Frequency": 53 + }, + { + "Time": 198, + "Intensity": 0.2, + "Frequency": 48 + }, + { + "Time": 218, + "Intensity": 0.08, + "Frequency": 41 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 48 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 177, + "Parameters": { + "Intensity": 60, + "Frequency": 46 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 266, + "Parameters": { + "Intensity": 26, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 28 + }, + { + "Time": 27, + "Intensity": 0.19, + "Frequency": 25 + }, + { + "Time": 81, + "Intensity": 0.32, + "Frequency": 29 + }, + { + "Time": 136, + "Intensity": 0.39, + "Frequency": 43 + }, + { + "Time": 187, + "Intensity": 0.32, + "Frequency": 53 + }, + { + "Time": 212, + "Intensity": 0.2, + "Frequency": 48 + }, + { + "Time": 233, + "Intensity": 0.08, + "Frequency": 41 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 48 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 308, + "Parameters": { + "Intensity": 53, + "Frequency": 13 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 382, + "Parameters": { + "Intensity": 48, + "Frequency": 13 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_m.json index 4b21a8c8e8332decf49d6f4755fdb605233e997f..d735b23abf3ec2f6a253c511e5b67b2bb59f073a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWater_m.json @@ -1,153 +1,153 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 233, - "StartTime": 23, - "Parameters": { - "Intensity": 67, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 28 - }, - { - "Time": 25, - "Intensity": 0.19, - "Frequency": 25 - }, - { - "Time": 75, - "Intensity": 0.32, - "Frequency": 29 - }, - { - "Time": 131, - "Intensity": 0.46, - "Frequency": 43 - }, - { - "Time": 177, - "Intensity": 0.5, - "Frequency": 53 - }, - { - "Time": 198, - "Intensity": 0.2, - "Frequency": 48 - }, - { - "Time": 218, - "Intensity": 0.08, - "Frequency": 41 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 48 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 177, - "Parameters": { - "Intensity": 80, - "Frequency": 46 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 266, - "Parameters": { - "Intensity": 35, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 28 - }, - { - "Time": 27, - "Intensity": 0.19, - "Frequency": 25 - }, - { - "Time": 81, - "Intensity": 0.32, - "Frequency": 29 - }, - { - "Time": 136, - "Intensity": 0.39, - "Frequency": 43 - }, - { - "Time": 187, - "Intensity": 0.32, - "Frequency": 53 - }, - { - "Time": 212, - "Intensity": 0.2, - "Frequency": 48 - }, - { - "Time": 233, - "Intensity": 0.08, - "Frequency": 41 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 48 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 308, - "Parameters": { - "Intensity": 71, - "Frequency": 13 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 382, - "Parameters": { - "Intensity": 64, - "Frequency": 13 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 233, + "StartTime": 23, + "Parameters": { + "Intensity": 67, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 28 + }, + { + "Time": 25, + "Intensity": 0.19, + "Frequency": 25 + }, + { + "Time": 75, + "Intensity": 0.32, + "Frequency": 29 + }, + { + "Time": 131, + "Intensity": 0.46, + "Frequency": 43 + }, + { + "Time": 177, + "Intensity": 0.5, + "Frequency": 53 + }, + { + "Time": 198, + "Intensity": 0.2, + "Frequency": 48 + }, + { + "Time": 218, + "Intensity": 0.08, + "Frequency": 41 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 48 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 177, + "Parameters": { + "Intensity": 80, + "Frequency": 46 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 266, + "Parameters": { + "Intensity": 35, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 28 + }, + { + "Time": 27, + "Intensity": 0.19, + "Frequency": 25 + }, + { + "Time": 81, + "Intensity": 0.32, + "Frequency": 29 + }, + { + "Time": 136, + "Intensity": 0.39, + "Frequency": 43 + }, + { + "Time": 187, + "Intensity": 0.32, + "Frequency": 53 + }, + { + "Time": 212, + "Intensity": 0.2, + "Frequency": 48 + }, + { + "Time": 233, + "Intensity": 0.08, + "Frequency": 41 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 48 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 308, + "Parameters": { + "Intensity": 71, + "Frequency": 13 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 382, + "Parameters": { + "Intensity": 64, + "Frequency": 13 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_h.json index 562378abcb95ade5f51f53d59b1b71917ae7fef6..af64f7a1ee51b15e3ccb579759e0dc2b35518f7e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_h.json @@ -1,168 +1,168 @@ -{ - "MetaData": { - "Create": "2022-05-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 144, - "StartTime": 15, - "Parameters": { - "Intensity": 76, - "Frequency": 19, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 80, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 114, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 134, - "Intensity": 0.15, - "Frequency": 36 - }, - { - "Time": 144, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 124, - "StartTime": 36, - "Parameters": { - "Intensity": 81, - "Frequency": 43, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 12, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 85, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 124, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 160, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 262, - "Parameters": { - "Intensity": 50, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 314, - "Parameters": { - "Intensity": 67, - "Frequency": 53 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 364, - "Parameters": { - "Intensity": 50, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 417, - "Parameters": { - "Intensity": 65, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 496, - "Parameters": { - "Intensity": 43, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 534, - "Parameters": { - "Intensity": 55, - "Frequency": 57 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 603, - "Parameters": { - "Intensity": 40, - "Frequency": 50 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 144, + "StartTime": 15, + "Parameters": { + "Intensity": 76, + "Frequency": 19, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 80, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 114, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 134, + "Intensity": 0.15, + "Frequency": 36 + }, + { + "Time": 144, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 124, + "StartTime": 36, + "Parameters": { + "Intensity": 81, + "Frequency": 43, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 12, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 85, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 124, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 160, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 262, + "Parameters": { + "Intensity": 50, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 314, + "Parameters": { + "Intensity": 67, + "Frequency": 53 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 364, + "Parameters": { + "Intensity": 50, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 417, + "Parameters": { + "Intensity": 65, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 496, + "Parameters": { + "Intensity": 43, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 534, + "Parameters": { + "Intensity": 55, + "Frequency": 57 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 603, + "Parameters": { + "Intensity": 40, + "Frequency": 50 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_l.json index a811d974edceb34a3c3d8eb00fe79ba45edc5b36..aa3281725c997ee238152fadd39f81096a537b24 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_l.json @@ -1,168 +1,168 @@ -{ - "MetaData": { - "Create": "2022-05-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 144, - "StartTime": 15, - "Parameters": { - "Intensity": 45, - "Frequency": 19, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 80, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 114, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 134, - "Intensity": 0.15, - "Frequency": 36 - }, - { - "Time": 144, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 124, - "StartTime": 36, - "Parameters": { - "Intensity": 48, - "Frequency": 43, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 12, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 85, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 124, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 160, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 262, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 314, - "Parameters": { - "Intensity": 40, - "Frequency": 53 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 364, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 417, - "Parameters": { - "Intensity": 39, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 496, - "Parameters": { - "Intensity": 25, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 534, - "Parameters": { - "Intensity": 33, - "Frequency": 57 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 603, - "Parameters": { - "Intensity": 24, - "Frequency": 50 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 144, + "StartTime": 15, + "Parameters": { + "Intensity": 45, + "Frequency": 19, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 80, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 114, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 134, + "Intensity": 0.15, + "Frequency": 36 + }, + { + "Time": 144, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 124, + "StartTime": 36, + "Parameters": { + "Intensity": 48, + "Frequency": 43, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 12, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 85, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 124, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 160, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 262, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 314, + "Parameters": { + "Intensity": 40, + "Frequency": 53 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 364, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 417, + "Parameters": { + "Intensity": 39, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 496, + "Parameters": { + "Intensity": 25, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 534, + "Parameters": { + "Intensity": 33, + "Frequency": 57 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 603, + "Parameters": { + "Intensity": 24, + "Frequency": 50 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_m.json index db1da2e2535688b1a7da7702a708138c67f39477..430c081e9c405ab4ac6a8737e4108d031486a9c5 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/HitWood_m.json @@ -1,168 +1,168 @@ -{ - "MetaData": { - "Create": "2022-05-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 144, - "StartTime": 15, - "Parameters": { - "Intensity": 60, - "Frequency": 19, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 80, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 114, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 134, - "Intensity": 0.15, - "Frequency": 36 - }, - { - "Time": 144, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 124, - "StartTime": 36, - "Parameters": { - "Intensity": 64, - "Frequency": 43, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 12, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 85, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 124, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 160, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 262, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 314, - "Parameters": { - "Intensity": 53, - "Frequency": 53 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 364, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 417, - "Parameters": { - "Intensity": 52, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 496, - "Parameters": { - "Intensity": 34, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 534, - "Parameters": { - "Intensity": 44, - "Frequency": 57 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 603, - "Parameters": { - "Intensity": 32, - "Frequency": 50 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-05-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 144, + "StartTime": 15, + "Parameters": { + "Intensity": 60, + "Frequency": 19, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 80, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 114, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 134, + "Intensity": 0.15, + "Frequency": 36 + }, + { + "Time": 144, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 124, + "StartTime": 36, + "Parameters": { + "Intensity": 64, + "Frequency": 43, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 12, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 85, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 124, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 160, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 262, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 314, + "Parameters": { + "Intensity": 53, + "Frequency": 53 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 364, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 417, + "Parameters": { + "Intensity": 52, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 496, + "Parameters": { + "Intensity": 34, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 534, + "Parameters": { + "Intensity": 44, + "Frequency": 57 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 603, + "Parameters": { + "Intensity": 32, + "Frequency": 50 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_h.json index c310bc29e0d2a83c8d2d9577fadae4bbdf70e509..7c2f5313191804d716a0bc593ee7867a900f565f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_h.json @@ -1,203 +1,203 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 270, - "StartTime": 36, - "Parameters": { - "Intensity": 81, - "Frequency": 39, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.25, - "Frequency": -50 - }, - { - "Time": 101, - "Intensity": 0.83, - "Frequency": 30 - }, - { - "Time": 135, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 168, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 270, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 278, - "Parameters": { - "Intensity": 100, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 74 - }, - { - "Time": 21, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 38, - "Intensity": 0.17, - "Frequency": 75 - }, - { - "Time": 61, - "Intensity": 0.24, - "Frequency": 75 - }, - { - "Time": 89, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 112, - "Intensity": 0.05, - "Frequency": 78 - }, - { - "Time": 135, - "Intensity": 0.07, - "Frequency": 79 - }, - { - "Time": 155, - "Intensity": 0.12, - "Frequency": 81 - }, - { - "Time": 183, - "Intensity": 0.21, - "Frequency": 80 - }, - { - "Time": 203, - "Intensity": 0.15, - "Frequency": 79 - }, - { - "Time": 225, - "Intensity": 0.12, - "Frequency": 79 - }, - { - "Time": 246, - "Intensity": 0.1, - "Frequency": 78 - }, - { - "Time": 269, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 293, - "Intensity": 0.16, - "Frequency": 75 - }, - { - "Time": 308, - "Intensity": 0.11, - "Frequency": 76 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 76 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 370, - "Parameters": { - "Intensity": 24, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 413, - "Parameters": { - "Intensity": 41, - "Frequency": 83 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 462, - "Parameters": { - "Intensity": 32, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 516, - "Parameters": { - "Intensity": 22, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 587, - "Parameters": { - "Intensity": 27, - "Frequency": 82 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 270, + "StartTime": 36, + "Parameters": { + "Intensity": 81, + "Frequency": 39, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.25, + "Frequency": -50 + }, + { + "Time": 101, + "Intensity": 0.83, + "Frequency": 30 + }, + { + "Time": 135, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 168, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 270, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 278, + "Parameters": { + "Intensity": 100, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 74 + }, + { + "Time": 21, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 38, + "Intensity": 0.17, + "Frequency": 75 + }, + { + "Time": 61, + "Intensity": 0.24, + "Frequency": 75 + }, + { + "Time": 89, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 112, + "Intensity": 0.05, + "Frequency": 78 + }, + { + "Time": 135, + "Intensity": 0.07, + "Frequency": 79 + }, + { + "Time": 155, + "Intensity": 0.12, + "Frequency": 81 + }, + { + "Time": 183, + "Intensity": 0.21, + "Frequency": 80 + }, + { + "Time": 203, + "Intensity": 0.15, + "Frequency": 79 + }, + { + "Time": 225, + "Intensity": 0.12, + "Frequency": 79 + }, + { + "Time": 246, + "Intensity": 0.1, + "Frequency": 78 + }, + { + "Time": 269, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 293, + "Intensity": 0.16, + "Frequency": 75 + }, + { + "Time": 308, + "Intensity": 0.11, + "Frequency": 76 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 76 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 370, + "Parameters": { + "Intensity": 24, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 413, + "Parameters": { + "Intensity": 41, + "Frequency": 83 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 462, + "Parameters": { + "Intensity": 32, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 516, + "Parameters": { + "Intensity": 22, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 587, + "Parameters": { + "Intensity": 27, + "Frequency": 82 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_l.json index 69716aa7a8d7a62f1419c1a82f7106fd4e73883f..9a0e02e709a83524e80697fe748100d34bd68912 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_l.json @@ -1,203 +1,203 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 270, - "StartTime": 36, - "Parameters": { - "Intensity": 48, - "Frequency": 39, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.25, - "Frequency": -50 - }, - { - "Time": 101, - "Intensity": 0.83, - "Frequency": 30 - }, - { - "Time": 135, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 168, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 270, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 278, - "Parameters": { - "Intensity": 60, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 74 - }, - { - "Time": 21, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 38, - "Intensity": 0.17, - "Frequency": 75 - }, - { - "Time": 61, - "Intensity": 0.24, - "Frequency": 75 - }, - { - "Time": 89, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 112, - "Intensity": 0.05, - "Frequency": 78 - }, - { - "Time": 135, - "Intensity": 0.07, - "Frequency": 79 - }, - { - "Time": 155, - "Intensity": 0.12, - "Frequency": 81 - }, - { - "Time": 183, - "Intensity": 0.21, - "Frequency": 80 - }, - { - "Time": 203, - "Intensity": 0.15, - "Frequency": 79 - }, - { - "Time": 225, - "Intensity": 0.12, - "Frequency": 79 - }, - { - "Time": 246, - "Intensity": 0.1, - "Frequency": 78 - }, - { - "Time": 269, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 293, - "Intensity": 0.16, - "Frequency": 75 - }, - { - "Time": 308, - "Intensity": 0.11, - "Frequency": 76 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 76 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 370, - "Parameters": { - "Intensity": 14, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 413, - "Parameters": { - "Intensity": 24, - "Frequency": 83 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 462, - "Parameters": { - "Intensity": 19, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 516, - "Parameters": { - "Intensity": 13, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 587, - "Parameters": { - "Intensity": 16, - "Frequency": 82 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 270, + "StartTime": 36, + "Parameters": { + "Intensity": 48, + "Frequency": 39, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.25, + "Frequency": -50 + }, + { + "Time": 101, + "Intensity": 0.83, + "Frequency": 30 + }, + { + "Time": 135, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 168, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 270, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 278, + "Parameters": { + "Intensity": 60, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 74 + }, + { + "Time": 21, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 38, + "Intensity": 0.17, + "Frequency": 75 + }, + { + "Time": 61, + "Intensity": 0.24, + "Frequency": 75 + }, + { + "Time": 89, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 112, + "Intensity": 0.05, + "Frequency": 78 + }, + { + "Time": 135, + "Intensity": 0.07, + "Frequency": 79 + }, + { + "Time": 155, + "Intensity": 0.12, + "Frequency": 81 + }, + { + "Time": 183, + "Intensity": 0.21, + "Frequency": 80 + }, + { + "Time": 203, + "Intensity": 0.15, + "Frequency": 79 + }, + { + "Time": 225, + "Intensity": 0.12, + "Frequency": 79 + }, + { + "Time": 246, + "Intensity": 0.1, + "Frequency": 78 + }, + { + "Time": 269, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 293, + "Intensity": 0.16, + "Frequency": 75 + }, + { + "Time": 308, + "Intensity": 0.11, + "Frequency": 76 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 76 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 370, + "Parameters": { + "Intensity": 14, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 413, + "Parameters": { + "Intensity": 24, + "Frequency": 83 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 462, + "Parameters": { + "Intensity": 19, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 516, + "Parameters": { + "Intensity": 13, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 587, + "Parameters": { + "Intensity": 16, + "Frequency": 82 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_m.json index ccc24a4b6405c6cfe5c76ba22fe47f2ec6b072e9..680c548a0dedce5f9333a6cfe99ecf88eae846fe 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Hurt_m.json @@ -1,203 +1,203 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 270, - "StartTime": 36, - "Parameters": { - "Intensity": 64, - "Frequency": 39, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.25, - "Frequency": -50 - }, - { - "Time": 101, - "Intensity": 0.83, - "Frequency": 30 - }, - { - "Time": 135, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 168, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 270, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 278, - "Parameters": { - "Intensity": 80, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 74 - }, - { - "Time": 21, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 38, - "Intensity": 0.17, - "Frequency": 75 - }, - { - "Time": 61, - "Intensity": 0.24, - "Frequency": 75 - }, - { - "Time": 89, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 112, - "Intensity": 0.05, - "Frequency": 78 - }, - { - "Time": 135, - "Intensity": 0.07, - "Frequency": 79 - }, - { - "Time": 155, - "Intensity": 0.12, - "Frequency": 81 - }, - { - "Time": 183, - "Intensity": 0.21, - "Frequency": 80 - }, - { - "Time": 203, - "Intensity": 0.15, - "Frequency": 79 - }, - { - "Time": 225, - "Intensity": 0.12, - "Frequency": 79 - }, - { - "Time": 246, - "Intensity": 0.1, - "Frequency": 78 - }, - { - "Time": 269, - "Intensity": 0.06, - "Frequency": 76 - }, - { - "Time": 293, - "Intensity": 0.16, - "Frequency": 75 - }, - { - "Time": 308, - "Intensity": 0.11, - "Frequency": 76 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 76 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 370, - "Parameters": { - "Intensity": 19, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 413, - "Parameters": { - "Intensity": 32, - "Frequency": 83 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 462, - "Parameters": { - "Intensity": 25, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 516, - "Parameters": { - "Intensity": 17, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 587, - "Parameters": { - "Intensity": 21, - "Frequency": 82 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 270, + "StartTime": 36, + "Parameters": { + "Intensity": 64, + "Frequency": 39, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.25, + "Frequency": -50 + }, + { + "Time": 101, + "Intensity": 0.83, + "Frequency": 30 + }, + { + "Time": 135, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 168, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 270, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 278, + "Parameters": { + "Intensity": 80, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 74 + }, + { + "Time": 21, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 38, + "Intensity": 0.17, + "Frequency": 75 + }, + { + "Time": 61, + "Intensity": 0.24, + "Frequency": 75 + }, + { + "Time": 89, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 112, + "Intensity": 0.05, + "Frequency": 78 + }, + { + "Time": 135, + "Intensity": 0.07, + "Frequency": 79 + }, + { + "Time": 155, + "Intensity": 0.12, + "Frequency": 81 + }, + { + "Time": 183, + "Intensity": 0.21, + "Frequency": 80 + }, + { + "Time": 203, + "Intensity": 0.15, + "Frequency": 79 + }, + { + "Time": 225, + "Intensity": 0.12, + "Frequency": 79 + }, + { + "Time": 246, + "Intensity": 0.1, + "Frequency": 78 + }, + { + "Time": 269, + "Intensity": 0.06, + "Frequency": 76 + }, + { + "Time": 293, + "Intensity": 0.16, + "Frequency": 75 + }, + { + "Time": 308, + "Intensity": 0.11, + "Frequency": 76 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 76 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 370, + "Parameters": { + "Intensity": 19, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 413, + "Parameters": { + "Intensity": 32, + "Frequency": 83 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 462, + "Parameters": { + "Intensity": 25, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 516, + "Parameters": { + "Intensity": 17, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 587, + "Parameters": { + "Intensity": 21, + "Frequency": 82 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_h.json index 17ec74e8493b829ee30f69bac79df39840733077..aa77836f22dfd49ebdbfe6132b24c5a534bb193e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_h.json @@ -1,196 +1,196 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 2468, - "StartTime": 13, - "Parameters": { - "Intensity": 97, - "Frequency": 34, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -7 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.94, - "Frequency": -4 - }, - { - "Time": 217, - "Intensity": 0.63, - "Frequency": -14 - }, - { - "Time": 763, - "Intensity": 0.53, - "Frequency": -10 - }, - { - "Time": 1125, - "Intensity": 0.48, - "Frequency": -14 - }, - { - "Time": 1503, - "Intensity": 0.42, - "Frequency": -14 - }, - { - "Time": 1858, - "Intensity": 0.39, - "Frequency": -14 - }, - { - "Time": 2295, - "Intensity": 0.34, - "Frequency": -17 - }, - { - "Time": 2448, - "Intensity": 0.21, - "Frequency": -14 - }, - { - "Time": 2468, - "Intensity": 0, - "Frequency": -21 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2468, - "StartTime": 15, - "Parameters": { - "Intensity": 97, - "Frequency": 27, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -7 - }, - { - "Time": 47, - "Intensity": 0.9, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.84, - "Frequency": -4 - }, - { - "Time": 143, - "Intensity": 0.59, - "Frequency": -14 - }, - { - "Time": 183, - "Intensity": 0.16, - "Frequency": -10 - }, - { - "Time": 1081, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 1464, - "Intensity": 0.07, - "Frequency": -14 - }, - { - "Time": 1826, - "Intensity": 0.04, - "Frequency": -14 - }, - { - "Time": 2056, - "Intensity": 0.04, - "Frequency": -17 - }, - { - "Time": 2391, - "Intensity": 0.03, - "Frequency": -14 - }, - { - "Time": 2468, - "Intensity": 0, - "Frequency": -21 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 570, - "StartTime": 2486, - "Parameters": { - "Intensity": 80, - "Frequency": 90, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 127, - "Intensity": 0.09, - "Frequency": -80 - }, - { - "Time": 263, - "Intensity": 0.97, - "Frequency": -34 - }, - { - "Time": 300, - "Intensity": 0.92, - "Frequency": -34 - }, - { - "Time": 464, - "Intensity": 0.16, - "Frequency": -60 - }, - { - "Time": 570, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 2468, + "StartTime": 13, + "Parameters": { + "Intensity": 97, + "Frequency": 34, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -7 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.94, + "Frequency": -4 + }, + { + "Time": 217, + "Intensity": 0.63, + "Frequency": -14 + }, + { + "Time": 763, + "Intensity": 0.53, + "Frequency": -10 + }, + { + "Time": 1125, + "Intensity": 0.48, + "Frequency": -14 + }, + { + "Time": 1503, + "Intensity": 0.42, + "Frequency": -14 + }, + { + "Time": 1858, + "Intensity": 0.39, + "Frequency": -14 + }, + { + "Time": 2295, + "Intensity": 0.34, + "Frequency": -17 + }, + { + "Time": 2448, + "Intensity": 0.21, + "Frequency": -14 + }, + { + "Time": 2468, + "Intensity": 0, + "Frequency": -21 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2468, + "StartTime": 15, + "Parameters": { + "Intensity": 97, + "Frequency": 27, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -7 + }, + { + "Time": 47, + "Intensity": 0.9, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.84, + "Frequency": -4 + }, + { + "Time": 143, + "Intensity": 0.59, + "Frequency": -14 + }, + { + "Time": 183, + "Intensity": 0.16, + "Frequency": -10 + }, + { + "Time": 1081, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 1464, + "Intensity": 0.07, + "Frequency": -14 + }, + { + "Time": 1826, + "Intensity": 0.04, + "Frequency": -14 + }, + { + "Time": 2056, + "Intensity": 0.04, + "Frequency": -17 + }, + { + "Time": 2391, + "Intensity": 0.03, + "Frequency": -14 + }, + { + "Time": 2468, + "Intensity": 0, + "Frequency": -21 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 570, + "StartTime": 2486, + "Parameters": { + "Intensity": 80, + "Frequency": 90, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 127, + "Intensity": 0.09, + "Frequency": -80 + }, + { + "Time": 263, + "Intensity": 0.97, + "Frequency": -34 + }, + { + "Time": 300, + "Intensity": 0.92, + "Frequency": -34 + }, + { + "Time": 464, + "Intensity": 0.16, + "Frequency": -60 + }, + { + "Time": 570, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_l.json index 384cdb88c38540f0e37b8db875ec5ac660517259..764f2127f8085f9285a03067e1d7e1515bf40044 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_l.json @@ -1,196 +1,196 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 2468, - "StartTime": 13, - "Parameters": { - "Intensity": 58, - "Frequency": 34, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -7 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.94, - "Frequency": -4 - }, - { - "Time": 217, - "Intensity": 0.63, - "Frequency": -14 - }, - { - "Time": 763, - "Intensity": 0.53, - "Frequency": -10 - }, - { - "Time": 1125, - "Intensity": 0.48, - "Frequency": -14 - }, - { - "Time": 1503, - "Intensity": 0.42, - "Frequency": -14 - }, - { - "Time": 1858, - "Intensity": 0.39, - "Frequency": -14 - }, - { - "Time": 2295, - "Intensity": 0.34, - "Frequency": -17 - }, - { - "Time": 2448, - "Intensity": 0.21, - "Frequency": -14 - }, - { - "Time": 2468, - "Intensity": 0, - "Frequency": -21 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2468, - "StartTime": 15, - "Parameters": { - "Intensity": 58, - "Frequency": 27, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -7 - }, - { - "Time": 47, - "Intensity": 0.9, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.84, - "Frequency": -4 - }, - { - "Time": 143, - "Intensity": 0.59, - "Frequency": -14 - }, - { - "Time": 183, - "Intensity": 0.16, - "Frequency": -10 - }, - { - "Time": 1081, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 1464, - "Intensity": 0.07, - "Frequency": -14 - }, - { - "Time": 1826, - "Intensity": 0.04, - "Frequency": -14 - }, - { - "Time": 2056, - "Intensity": 0.04, - "Frequency": -17 - }, - { - "Time": 2391, - "Intensity": 0.03, - "Frequency": -14 - }, - { - "Time": 2468, - "Intensity": 0, - "Frequency": -21 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 570, - "StartTime": 2486, - "Parameters": { - "Intensity": 48, - "Frequency": 90, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 127, - "Intensity": 0.09, - "Frequency": -80 - }, - { - "Time": 263, - "Intensity": 0.97, - "Frequency": -34 - }, - { - "Time": 300, - "Intensity": 0.92, - "Frequency": -34 - }, - { - "Time": 464, - "Intensity": 0.16, - "Frequency": -60 - }, - { - "Time": 570, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 2468, + "StartTime": 13, + "Parameters": { + "Intensity": 58, + "Frequency": 34, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -7 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.94, + "Frequency": -4 + }, + { + "Time": 217, + "Intensity": 0.63, + "Frequency": -14 + }, + { + "Time": 763, + "Intensity": 0.53, + "Frequency": -10 + }, + { + "Time": 1125, + "Intensity": 0.48, + "Frequency": -14 + }, + { + "Time": 1503, + "Intensity": 0.42, + "Frequency": -14 + }, + { + "Time": 1858, + "Intensity": 0.39, + "Frequency": -14 + }, + { + "Time": 2295, + "Intensity": 0.34, + "Frequency": -17 + }, + { + "Time": 2448, + "Intensity": 0.21, + "Frequency": -14 + }, + { + "Time": 2468, + "Intensity": 0, + "Frequency": -21 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2468, + "StartTime": 15, + "Parameters": { + "Intensity": 58, + "Frequency": 27, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -7 + }, + { + "Time": 47, + "Intensity": 0.9, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.84, + "Frequency": -4 + }, + { + "Time": 143, + "Intensity": 0.59, + "Frequency": -14 + }, + { + "Time": 183, + "Intensity": 0.16, + "Frequency": -10 + }, + { + "Time": 1081, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 1464, + "Intensity": 0.07, + "Frequency": -14 + }, + { + "Time": 1826, + "Intensity": 0.04, + "Frequency": -14 + }, + { + "Time": 2056, + "Intensity": 0.04, + "Frequency": -17 + }, + { + "Time": 2391, + "Intensity": 0.03, + "Frequency": -14 + }, + { + "Time": 2468, + "Intensity": 0, + "Frequency": -21 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 570, + "StartTime": 2486, + "Parameters": { + "Intensity": 48, + "Frequency": 90, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 127, + "Intensity": 0.09, + "Frequency": -80 + }, + { + "Time": 263, + "Intensity": 0.97, + "Frequency": -34 + }, + { + "Time": 300, + "Intensity": 0.92, + "Frequency": -34 + }, + { + "Time": 464, + "Intensity": 0.16, + "Frequency": -60 + }, + { + "Time": 570, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_m.json index 207ce36352a4ac11916f05886a1975dc856df641..5783f173258428fc46a9bb7b44546e729a278350 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/JetN2O_m.json @@ -1,196 +1,196 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 2468, - "StartTime": 13, - "Parameters": { - "Intensity": 77, - "Frequency": 34, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -7 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.94, - "Frequency": -4 - }, - { - "Time": 217, - "Intensity": 0.63, - "Frequency": -14 - }, - { - "Time": 763, - "Intensity": 0.53, - "Frequency": -10 - }, - { - "Time": 1125, - "Intensity": 0.48, - "Frequency": -14 - }, - { - "Time": 1503, - "Intensity": 0.42, - "Frequency": -14 - }, - { - "Time": 1858, - "Intensity": 0.39, - "Frequency": -14 - }, - { - "Time": 2295, - "Intensity": 0.34, - "Frequency": -17 - }, - { - "Time": 2448, - "Intensity": 0.21, - "Frequency": -14 - }, - { - "Time": 2468, - "Intensity": 0, - "Frequency": -21 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2468, - "StartTime": 15, - "Parameters": { - "Intensity": 77, - "Frequency": 27, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -7 - }, - { - "Time": 47, - "Intensity": 0.9, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.84, - "Frequency": -4 - }, - { - "Time": 143, - "Intensity": 0.59, - "Frequency": -14 - }, - { - "Time": 183, - "Intensity": 0.16, - "Frequency": -10 - }, - { - "Time": 1081, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 1464, - "Intensity": 0.07, - "Frequency": -14 - }, - { - "Time": 1826, - "Intensity": 0.04, - "Frequency": -14 - }, - { - "Time": 2056, - "Intensity": 0.04, - "Frequency": -17 - }, - { - "Time": 2391, - "Intensity": 0.03, - "Frequency": -14 - }, - { - "Time": 2468, - "Intensity": 0, - "Frequency": -21 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 570, - "StartTime": 2486, - "Parameters": { - "Intensity": 64, - "Frequency": 90, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 127, - "Intensity": 0.09, - "Frequency": -80 - }, - { - "Time": 263, - "Intensity": 0.97, - "Frequency": -34 - }, - { - "Time": 300, - "Intensity": 0.92, - "Frequency": -34 - }, - { - "Time": 464, - "Intensity": 0.16, - "Frequency": -60 - }, - { - "Time": 570, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 2468, + "StartTime": 13, + "Parameters": { + "Intensity": 77, + "Frequency": 34, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -7 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.94, + "Frequency": -4 + }, + { + "Time": 217, + "Intensity": 0.63, + "Frequency": -14 + }, + { + "Time": 763, + "Intensity": 0.53, + "Frequency": -10 + }, + { + "Time": 1125, + "Intensity": 0.48, + "Frequency": -14 + }, + { + "Time": 1503, + "Intensity": 0.42, + "Frequency": -14 + }, + { + "Time": 1858, + "Intensity": 0.39, + "Frequency": -14 + }, + { + "Time": 2295, + "Intensity": 0.34, + "Frequency": -17 + }, + { + "Time": 2448, + "Intensity": 0.21, + "Frequency": -14 + }, + { + "Time": 2468, + "Intensity": 0, + "Frequency": -21 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2468, + "StartTime": 15, + "Parameters": { + "Intensity": 77, + "Frequency": 27, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -7 + }, + { + "Time": 47, + "Intensity": 0.9, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.84, + "Frequency": -4 + }, + { + "Time": 143, + "Intensity": 0.59, + "Frequency": -14 + }, + { + "Time": 183, + "Intensity": 0.16, + "Frequency": -10 + }, + { + "Time": 1081, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 1464, + "Intensity": 0.07, + "Frequency": -14 + }, + { + "Time": 1826, + "Intensity": 0.04, + "Frequency": -14 + }, + { + "Time": 2056, + "Intensity": 0.04, + "Frequency": -17 + }, + { + "Time": 2391, + "Intensity": 0.03, + "Frequency": -14 + }, + { + "Time": 2468, + "Intensity": 0, + "Frequency": -21 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 570, + "StartTime": 2486, + "Parameters": { + "Intensity": 64, + "Frequency": 90, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 127, + "Intensity": 0.09, + "Frequency": -80 + }, + { + "Time": 263, + "Intensity": 0.97, + "Frequency": -34 + }, + { + "Time": 300, + "Intensity": 0.92, + "Frequency": -34 + }, + { + "Time": 464, + "Intensity": 0.16, + "Frequency": -60 + }, + { + "Time": 570, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_h.json index 5809f62e5c5599b6c1f6283edd47de5f724322c2..3b5f4ef42c7e73e238e1c6616ca498986fab5031 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_h.json @@ -1,87 +1,87 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 32, - "Parameters": { - "Intensity": 100, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 121, - "Parameters": { - "Intensity": 50, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 206, - "Parameters": { - "Intensity": 100, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 297, - "Parameters": { - "Intensity": 49, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 391, - "Parameters": { - "Intensity": 100, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 474, - "Parameters": { - "Intensity": 49, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 566, - "Parameters": { - "Intensity": 100, - "Frequency": 90 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 32, + "Parameters": { + "Intensity": 100, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 121, + "Parameters": { + "Intensity": 50, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 206, + "Parameters": { + "Intensity": 100, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 297, + "Parameters": { + "Intensity": 49, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 391, + "Parameters": { + "Intensity": 100, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 474, + "Parameters": { + "Intensity": 49, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 566, + "Parameters": { + "Intensity": 100, + "Frequency": 90 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_l.json index b74735fe5dbf2cae8179ae7924c34ed2e0b0d265..8fec407dae59c0be48161286218facb342097c48 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_l.json @@ -1,87 +1,87 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 32, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 121, - "Parameters": { - "Intensity": 30, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 206, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 297, - "Parameters": { - "Intensity": 29, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 391, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 474, - "Parameters": { - "Intensity": 29, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 566, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 32, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 121, + "Parameters": { + "Intensity": 30, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 206, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 297, + "Parameters": { + "Intensity": 29, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 391, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 474, + "Parameters": { + "Intensity": 29, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 566, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_m.json index 7d164294e6701b75099c3bebdafe07bea21dbb1d..141e38f250c6e2b86f2724ee8f2f2f20bf19303d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Keyboard_m.json @@ -1,87 +1,87 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 32, - "Parameters": { - "Intensity": 80, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 121, - "Parameters": { - "Intensity": 40, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 206, - "Parameters": { - "Intensity": 80, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 297, - "Parameters": { - "Intensity": 39, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 391, - "Parameters": { - "Intensity": 80, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 474, - "Parameters": { - "Intensity": 39, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 566, - "Parameters": { - "Intensity": 80, - "Frequency": 90 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 32, + "Parameters": { + "Intensity": 80, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 121, + "Parameters": { + "Intensity": 40, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 206, + "Parameters": { + "Intensity": 80, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 297, + "Parameters": { + "Intensity": 39, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 391, + "Parameters": { + "Intensity": 80, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 474, + "Parameters": { + "Intensity": 39, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 566, + "Parameters": { + "Intensity": 80, + "Frequency": 90 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_h.json index 21e70cfebc51f817d60d4582b875ea331039cef0..e6777614b4011f0ca7dce2a8d1ff02dc0e7bc4bc 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_h.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 76, - "StartTime": 9, - "Parameters": { - "Intensity": 100, - "Frequency": 53, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 6, - "Intensity": 1, - "Frequency": -100 - }, - { - "Time": 57, - "Intensity": 1, - "Frequency": -100 - }, - { - "Time": 76, - "Intensity": 0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 76, + "StartTime": 9, + "Parameters": { + "Intensity": 100, + "Frequency": 53, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 6, + "Intensity": 1, + "Frequency": -100 + }, + { + "Time": 57, + "Intensity": 1, + "Frequency": -100 + }, + { + "Time": 76, + "Intensity": 0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_l.json index 0f2c6e7334c5d8b991a2c9dad8caa676a201f13f..04f05cb08ba1ee44055db8ab3404a5324b76e6db 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_l.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 76, - "StartTime": 9, - "Parameters": { - "Intensity": 60, - "Frequency": 53, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 6, - "Intensity": 1, - "Frequency": -100 - }, - { - "Time": 57, - "Intensity": 1, - "Frequency": -100 - }, - { - "Time": 76, - "Intensity": 0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 76, + "StartTime": 9, + "Parameters": { + "Intensity": 60, + "Frequency": 53, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 6, + "Intensity": 1, + "Frequency": -100 + }, + { + "Time": 57, + "Intensity": 1, + "Frequency": -100 + }, + { + "Time": 76, + "Intensity": 0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_m.json index 32b42b0fd2ed5bcd6ce0eb1c3d7e64e8b8e3cd88..e77899d198dde1d3121b139c28b5be1ab511afc6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum2_m.json @@ -1,50 +1,50 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 76, - "StartTime": 9, - "Parameters": { - "Intensity": 80, - "Frequency": 53, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 6, - "Intensity": 1, - "Frequency": -100 - }, - { - "Time": 57, - "Intensity": 1, - "Frequency": -100 - }, - { - "Time": 76, - "Intensity": 0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 76, + "StartTime": 9, + "Parameters": { + "Intensity": 80, + "Frequency": 53, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 6, + "Intensity": 1, + "Frequency": -100 + }, + { + "Time": 57, + "Intensity": 1, + "Frequency": -100 + }, + { + "Time": 76, + "Intensity": 0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_h.json index 50a37c25f6d419f28da23865ff2f6a45d8308de7..52fa2abd2799f59eb3fb2e78d92f2dacd7b0a584 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_h.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 14, - "Parameters": { - "Intensity": 100, - "Frequency": 15 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 14, + "Parameters": { + "Intensity": 100, + "Frequency": 15 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_l.json index 6687fafbaab851daceb8a8c108ac0b03936bce58..ed618ebb47a4d84d04213db47b165b4cea462800 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_l.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 14, - "Parameters": { - "Intensity": 60, - "Frequency": 15 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 14, + "Parameters": { + "Intensity": 60, + "Frequency": 15 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_m.json index f19f7e3c09d29d8b80f709d16704b03e4586a5d0..c129fe54d7f13cd713bac1ebf3082bb6663adf69 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/KickDrum_m.json @@ -1,27 +1,27 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 14, - "Parameters": { - "Intensity": 80, - "Frequency": 15 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 14, + "Parameters": { + "Intensity": 80, + "Frequency": 15 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_h.json index 16de21e9e69c655431f108ee0e3a4dcb9b80b771..7a3eea6e48e0b15d7fad26c77c8a8b0eebbb1558 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_h.json @@ -1,108 +1,108 @@ -{ - "MetaData": { - "Create": "2022-04-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 224, - "StartTime": 0, - "Parameters": { - "Intensity": 94, - "Frequency": 31, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -22 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": -9 - }, - { - "Time": 126, - "Intensity": 0.76, - "Frequency": -19 - }, - { - "Time": 134, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 170, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 224, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 218, - "StartTime": 224, - "Parameters": { - "Intensity": 86, - "Frequency": 57, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 48, - "Intensity": 0.31, - "Frequency": -83 - }, - { - "Time": 81, - "Intensity": 1, - "Frequency": -8 - }, - { - "Time": 137, - "Intensity": 0.23, - "Frequency": -58 - }, - { - "Time": 218, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 276, - "Parameters": { - "Intensity": 100, - "Frequency": 45 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 224, + "StartTime": 0, + "Parameters": { + "Intensity": 94, + "Frequency": 31, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -22 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": -9 + }, + { + "Time": 126, + "Intensity": 0.76, + "Frequency": -19 + }, + { + "Time": 134, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 170, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 224, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 218, + "StartTime": 224, + "Parameters": { + "Intensity": 86, + "Frequency": 57, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 48, + "Intensity": 0.31, + "Frequency": -83 + }, + { + "Time": 81, + "Intensity": 1, + "Frequency": -8 + }, + { + "Time": 137, + "Intensity": 0.23, + "Frequency": -58 + }, + { + "Time": 218, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 276, + "Parameters": { + "Intensity": 100, + "Frequency": 45 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_l.json index 74795754258c42ac7112310b9ed44253a94f8867..82cdf451fdb3e47ba0f1b636bf06249b910bcbad 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_l.json @@ -1,108 +1,108 @@ -{ - "MetaData": { - "Create": "2022-04-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 224, - "StartTime": 0, - "Parameters": { - "Intensity": 56, - "Frequency": 31, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -22 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": -9 - }, - { - "Time": 126, - "Intensity": 0.76, - "Frequency": -19 - }, - { - "Time": 134, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 170, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 224, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 218, - "StartTime": 224, - "Parameters": { - "Intensity": 51, - "Frequency": 57, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 48, - "Intensity": 0.31, - "Frequency": -83 - }, - { - "Time": 81, - "Intensity": 1, - "Frequency": -8 - }, - { - "Time": 137, - "Intensity": 0.23, - "Frequency": -58 - }, - { - "Time": 218, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 276, - "Parameters": { - "Intensity": 60, - "Frequency": 45 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 224, + "StartTime": 0, + "Parameters": { + "Intensity": 56, + "Frequency": 31, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -22 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": -9 + }, + { + "Time": 126, + "Intensity": 0.76, + "Frequency": -19 + }, + { + "Time": 134, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 170, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 224, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 218, + "StartTime": 224, + "Parameters": { + "Intensity": 51, + "Frequency": 57, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 48, + "Intensity": 0.31, + "Frequency": -83 + }, + { + "Time": 81, + "Intensity": 1, + "Frequency": -8 + }, + { + "Time": 137, + "Intensity": 0.23, + "Frequency": -58 + }, + { + "Time": 218, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 276, + "Parameters": { + "Intensity": 60, + "Frequency": 45 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_m.json index b47833fa6d650b9c9f86a8fcdf731549000dc98c..89e45880b6ff2f1be29a6c239e81dbd3b6b679eb 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Kick_m.json @@ -1,108 +1,108 @@ -{ - "MetaData": { - "Create": "2022-04-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 224, - "StartTime": 0, - "Parameters": { - "Intensity": 75, - "Frequency": 31, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -22 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": -9 - }, - { - "Time": 126, - "Intensity": 0.76, - "Frequency": -19 - }, - { - "Time": 134, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 170, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 224, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 218, - "StartTime": 224, - "Parameters": { - "Intensity": 68, - "Frequency": 57, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 48, - "Intensity": 0.31, - "Frequency": -83 - }, - { - "Time": 81, - "Intensity": 1, - "Frequency": -8 - }, - { - "Time": 137, - "Intensity": 0.23, - "Frequency": -58 - }, - { - "Time": 218, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 276, - "Parameters": { - "Intensity": 80, - "Frequency": 45 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 224, + "StartTime": 0, + "Parameters": { + "Intensity": 75, + "Frequency": 31, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -22 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": -9 + }, + { + "Time": 126, + "Intensity": 0.76, + "Frequency": -19 + }, + { + "Time": 134, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 170, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 224, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 218, + "StartTime": 224, + "Parameters": { + "Intensity": 68, + "Frequency": 57, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 48, + "Intensity": 0.31, + "Frequency": -83 + }, + { + "Time": 81, + "Intensity": 1, + "Frequency": -8 + }, + { + "Time": 137, + "Intensity": 0.23, + "Frequency": -58 + }, + { + "Time": 218, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 276, + "Parameters": { + "Intensity": 80, + "Frequency": 45 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_h.json index 6c6138411306707b8045ab30d072b93df4af0d84..c4994c5d14f276590026137497be9807c6eaa965 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_h.json @@ -1,213 +1,213 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 68 - }, - { - "Time": 117, - "Intensity": 0, - "Frequency": 73 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 73 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 71 - }, - { - "Time": 167, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 38 - }, - { - "Time": 221, - "Intensity": 0.22, - "Frequency": 34 - }, - { - "Time": 233, - "Intensity": 1, - "Frequency": 44 - }, - { - "Time": 238, - "Intensity": 1, - "Frequency": 40 - }, - { - "Time": 244, - "Intensity": 0.06, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 70 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 211, - "Parameters": { - "Intensity": 100, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 231, - "StartTime": 252, - "Parameters": { - "Intensity": 70, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 70 - }, - { - "Time": 16, - "Intensity": 0.17, - "Frequency": 70 - }, - { - "Time": 35, - "Intensity": 0.36, - "Frequency": 74 - }, - { - "Time": 41, - "Intensity": 0.28, - "Frequency": 75 - }, - { - "Time": 62, - "Intensity": 0.31, - "Frequency": 74 - }, - { - "Time": 79, - "Intensity": 0.23, - "Frequency": 73 - }, - { - "Time": 107, - "Intensity": 0.14, - "Frequency": 72 - }, - { - "Time": 128, - "Intensity": 0.12, - "Frequency": 73 - }, - { - "Time": 142, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 159, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 177, - "Intensity": 0.08, - "Frequency": 75 - }, - { - "Time": 202, - "Intensity": 0.05, - "Frequency": 74 - }, - { - "Time": 217, - "Intensity": 0.03, - "Frequency": 75 - }, - { - "Time": 231, - "Intensity": 0, - "Frequency": 74 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 280, - "Parameters": { - "Intensity": 100, - "Frequency": 45 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 68 + }, + { + "Time": 117, + "Intensity": 0, + "Frequency": 73 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 73 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 71 + }, + { + "Time": 167, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 38 + }, + { + "Time": 221, + "Intensity": 0.22, + "Frequency": 34 + }, + { + "Time": 233, + "Intensity": 1, + "Frequency": 44 + }, + { + "Time": 238, + "Intensity": 1, + "Frequency": 40 + }, + { + "Time": 244, + "Intensity": 0.06, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 70 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 211, + "Parameters": { + "Intensity": 100, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 231, + "StartTime": 252, + "Parameters": { + "Intensity": 70, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 70 + }, + { + "Time": 16, + "Intensity": 0.17, + "Frequency": 70 + }, + { + "Time": 35, + "Intensity": 0.36, + "Frequency": 74 + }, + { + "Time": 41, + "Intensity": 0.28, + "Frequency": 75 + }, + { + "Time": 62, + "Intensity": 0.31, + "Frequency": 74 + }, + { + "Time": 79, + "Intensity": 0.23, + "Frequency": 73 + }, + { + "Time": 107, + "Intensity": 0.14, + "Frequency": 72 + }, + { + "Time": 128, + "Intensity": 0.12, + "Frequency": 73 + }, + { + "Time": 142, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 159, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 177, + "Intensity": 0.08, + "Frequency": 75 + }, + { + "Time": 202, + "Intensity": 0.05, + "Frequency": 74 + }, + { + "Time": 217, + "Intensity": 0.03, + "Frequency": 75 + }, + { + "Time": 231, + "Intensity": 0, + "Frequency": 74 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 280, + "Parameters": { + "Intensity": 100, + "Frequency": 45 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_l.json index 6c54dc025e4340fee21090affed6afbd8655be74..36acfef6ebd890e40a42face2bcdfaddea7cc4c2 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_l.json @@ -1,213 +1,213 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1, - "Parameters": { - "Intensity": 36, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 68 - }, - { - "Time": 117, - "Intensity": 0, - "Frequency": 73 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 73 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 71 - }, - { - "Time": 167, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 38 - }, - { - "Time": 221, - "Intensity": 0.22, - "Frequency": 34 - }, - { - "Time": 233, - "Intensity": 1, - "Frequency": 44 - }, - { - "Time": 238, - "Intensity": 1, - "Frequency": 40 - }, - { - "Time": 244, - "Intensity": 0.06, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 70 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 211, - "Parameters": { - "Intensity": 60, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 231, - "StartTime": 252, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 70 - }, - { - "Time": 16, - "Intensity": 0.17, - "Frequency": 70 - }, - { - "Time": 35, - "Intensity": 0.36, - "Frequency": 74 - }, - { - "Time": 41, - "Intensity": 0.28, - "Frequency": 75 - }, - { - "Time": 62, - "Intensity": 0.31, - "Frequency": 74 - }, - { - "Time": 79, - "Intensity": 0.23, - "Frequency": 73 - }, - { - "Time": 107, - "Intensity": 0.14, - "Frequency": 72 - }, - { - "Time": 128, - "Intensity": 0.12, - "Frequency": 73 - }, - { - "Time": 142, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 159, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 177, - "Intensity": 0.08, - "Frequency": 75 - }, - { - "Time": 202, - "Intensity": 0.05, - "Frequency": 74 - }, - { - "Time": 217, - "Intensity": 0.03, - "Frequency": 75 - }, - { - "Time": 231, - "Intensity": 0, - "Frequency": 74 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 280, - "Parameters": { - "Intensity": 60, - "Frequency": 45 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1, + "Parameters": { + "Intensity": 36, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 68 + }, + { + "Time": 117, + "Intensity": 0, + "Frequency": 73 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 73 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 71 + }, + { + "Time": 167, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 38 + }, + { + "Time": 221, + "Intensity": 0.22, + "Frequency": 34 + }, + { + "Time": 233, + "Intensity": 1, + "Frequency": 44 + }, + { + "Time": 238, + "Intensity": 1, + "Frequency": 40 + }, + { + "Time": 244, + "Intensity": 0.06, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 70 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 211, + "Parameters": { + "Intensity": 60, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 231, + "StartTime": 252, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 70 + }, + { + "Time": 16, + "Intensity": 0.17, + "Frequency": 70 + }, + { + "Time": 35, + "Intensity": 0.36, + "Frequency": 74 + }, + { + "Time": 41, + "Intensity": 0.28, + "Frequency": 75 + }, + { + "Time": 62, + "Intensity": 0.31, + "Frequency": 74 + }, + { + "Time": 79, + "Intensity": 0.23, + "Frequency": 73 + }, + { + "Time": 107, + "Intensity": 0.14, + "Frequency": 72 + }, + { + "Time": 128, + "Intensity": 0.12, + "Frequency": 73 + }, + { + "Time": 142, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 159, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 177, + "Intensity": 0.08, + "Frequency": 75 + }, + { + "Time": 202, + "Intensity": 0.05, + "Frequency": 74 + }, + { + "Time": 217, + "Intensity": 0.03, + "Frequency": 75 + }, + { + "Time": 231, + "Intensity": 0, + "Frequency": 74 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 280, + "Parameters": { + "Intensity": 60, + "Frequency": 45 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_m.json index f68a16f4093c1e3432dbd36b36cae6ca6ba794b5..ee0c170cc62cb9706b067cb3545f9d5334b525dd 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/M4_m.json @@ -1,213 +1,213 @@ -{ - "MetaData": { - "Create": "2022-09-26", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 76 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 68 - }, - { - "Time": 117, - "Intensity": 0, - "Frequency": 73 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 73 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 71 - }, - { - "Time": 167, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 69 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 38 - }, - { - "Time": 221, - "Intensity": 0.22, - "Frequency": 34 - }, - { - "Time": 233, - "Intensity": 1, - "Frequency": 44 - }, - { - "Time": 238, - "Intensity": 1, - "Frequency": 40 - }, - { - "Time": 244, - "Intensity": 0.06, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 70 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 211, - "Parameters": { - "Intensity": 80, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 231, - "StartTime": 252, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 70 - }, - { - "Time": 16, - "Intensity": 0.17, - "Frequency": 70 - }, - { - "Time": 35, - "Intensity": 0.36, - "Frequency": 74 - }, - { - "Time": 41, - "Intensity": 0.28, - "Frequency": 75 - }, - { - "Time": 62, - "Intensity": 0.31, - "Frequency": 74 - }, - { - "Time": 79, - "Intensity": 0.23, - "Frequency": 73 - }, - { - "Time": 107, - "Intensity": 0.14, - "Frequency": 72 - }, - { - "Time": 128, - "Intensity": 0.12, - "Frequency": 73 - }, - { - "Time": 142, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 159, - "Intensity": 0.11, - "Frequency": 75 - }, - { - "Time": 177, - "Intensity": 0.08, - "Frequency": 75 - }, - { - "Time": 202, - "Intensity": 0.05, - "Frequency": 74 - }, - { - "Time": 217, - "Intensity": 0.03, - "Frequency": 75 - }, - { - "Time": 231, - "Intensity": 0, - "Frequency": 74 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 280, - "Parameters": { - "Intensity": 80, - "Frequency": 45 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-09-26", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 76 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 68 + }, + { + "Time": 117, + "Intensity": 0, + "Frequency": 73 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 73 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 71 + }, + { + "Time": 167, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 69 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 38 + }, + { + "Time": 221, + "Intensity": 0.22, + "Frequency": 34 + }, + { + "Time": 233, + "Intensity": 1, + "Frequency": 44 + }, + { + "Time": 238, + "Intensity": 1, + "Frequency": 40 + }, + { + "Time": 244, + "Intensity": 0.06, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 70 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 211, + "Parameters": { + "Intensity": 80, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 231, + "StartTime": 252, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 70 + }, + { + "Time": 16, + "Intensity": 0.17, + "Frequency": 70 + }, + { + "Time": 35, + "Intensity": 0.36, + "Frequency": 74 + }, + { + "Time": 41, + "Intensity": 0.28, + "Frequency": 75 + }, + { + "Time": 62, + "Intensity": 0.31, + "Frequency": 74 + }, + { + "Time": 79, + "Intensity": 0.23, + "Frequency": 73 + }, + { + "Time": 107, + "Intensity": 0.14, + "Frequency": 72 + }, + { + "Time": 128, + "Intensity": 0.12, + "Frequency": 73 + }, + { + "Time": 142, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 159, + "Intensity": 0.11, + "Frequency": 75 + }, + { + "Time": 177, + "Intensity": 0.08, + "Frequency": 75 + }, + { + "Time": 202, + "Intensity": 0.05, + "Frequency": 74 + }, + { + "Time": 217, + "Intensity": 0.03, + "Frequency": 75 + }, + { + "Time": 231, + "Intensity": 0, + "Frequency": 74 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 280, + "Parameters": { + "Intensity": 80, + "Frequency": 45 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_h.json index 39544face5458fe79b92cadbc02bedc2ce52952f..88eec903d3cd3ab09cbcc091e4de0be113b598db 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_h.json @@ -1,57 +1,57 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 396, - "Parameters": { - "Intensity": 50, - "Frequency": 8 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 443, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 493, - "Parameters": { - "Intensity": 56, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 524, - "Parameters": { - "Intensity": 41, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 396, + "Parameters": { + "Intensity": 50, + "Frequency": 8 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 443, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 493, + "Parameters": { + "Intensity": 56, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 524, + "Parameters": { + "Intensity": 41, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_l.json index aa1d05a8762205ebe7cd6e521a28f296202b9a16..67e8ae9114ae56a605b6ca89212c28924468e28f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_l.json @@ -1,57 +1,57 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 396, - "Parameters": { - "Intensity": 30, - "Frequency": 8 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 443, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 493, - "Parameters": { - "Intensity": 33, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 524, - "Parameters": { - "Intensity": 24, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 396, + "Parameters": { + "Intensity": 30, + "Frequency": 8 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 443, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 493, + "Parameters": { + "Intensity": 33, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 524, + "Parameters": { + "Intensity": 24, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_m.json index 630995d608162ee4cfc22c65f5795bf751c0fb37..426033da78f8137640a2fb86b5df4a2ad724d610 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/MP5_m.json @@ -1,57 +1,57 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 396, - "Parameters": { - "Intensity": 40, - "Frequency": 8 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 443, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 493, - "Parameters": { - "Intensity": 44, - "Frequency": 82 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 524, - "Parameters": { - "Intensity": 32, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 396, + "Parameters": { + "Intensity": 40, + "Frequency": 8 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 443, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 493, + "Parameters": { + "Intensity": 44, + "Frequency": 82 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 524, + "Parameters": { + "Intensity": 32, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_h.json index 7a6d292b4d9942094b5fd6de45a51893f7c14f26..15fecdf0978fd2694c3cd8e1b7ea04c46617ae5b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_h.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 12, - "Parameters": { - "Intensity": 85, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 10, - "Intensity": 0.76, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 35, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 154, - "Parameters": { - "Intensity": 81, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 583, - "Parameters": { - "Intensity": 83, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 8, - "Intensity": 0.8, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 690, - "Parameters": { - "Intensity": 80, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 1182, - "Parameters": { - "Intensity": 82, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 8, - "Intensity": 0.77, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 10 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1314, - "Parameters": { - "Intensity": 79, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 1786, - "Parameters": { - "Intensity": 72, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 9, - "Intensity": 0.83, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1911, - "Parameters": { - "Intensity": 79, - "Frequency": 35 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 12, + "Parameters": { + "Intensity": 85, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 10, + "Intensity": 0.76, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 35, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 154, + "Parameters": { + "Intensity": 81, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 583, + "Parameters": { + "Intensity": 83, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 8, + "Intensity": 0.8, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 690, + "Parameters": { + "Intensity": 80, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 1182, + "Parameters": { + "Intensity": 82, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 8, + "Intensity": 0.77, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 10 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1314, + "Parameters": { + "Intensity": 79, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 1786, + "Parameters": { + "Intensity": 72, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 9, + "Intensity": 0.83, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1911, + "Parameters": { + "Intensity": 79, + "Frequency": 35 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_l.json index 033a04d680129133aae2328f88eb497a4425d283..773886facec15187313b55845f1d79dc8cabc3ef 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_l.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 12, - "Parameters": { - "Intensity": 51, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 10, - "Intensity": 0.76, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 35, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 154, - "Parameters": { - "Intensity": 48, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 583, - "Parameters": { - "Intensity": 49, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 8, - "Intensity": 0.8, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 690, - "Parameters": { - "Intensity": 48, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 1182, - "Parameters": { - "Intensity": 49, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 8, - "Intensity": 0.77, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 10 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1314, - "Parameters": { - "Intensity": 47, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 1786, - "Parameters": { - "Intensity": 43, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 9, - "Intensity": 0.83, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1911, - "Parameters": { - "Intensity": 47, - "Frequency": 35 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 12, + "Parameters": { + "Intensity": 51, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 10, + "Intensity": 0.76, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 35, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 154, + "Parameters": { + "Intensity": 48, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 583, + "Parameters": { + "Intensity": 49, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 8, + "Intensity": 0.8, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 690, + "Parameters": { + "Intensity": 48, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 1182, + "Parameters": { + "Intensity": 49, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 8, + "Intensity": 0.77, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 10 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1314, + "Parameters": { + "Intensity": 47, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 1786, + "Parameters": { + "Intensity": 43, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 9, + "Intensity": 0.83, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1911, + "Parameters": { + "Intensity": 47, + "Frequency": 35 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_m.json index 5b4dac9562dbe7f75bf6249ba80e34290f509cb1..ff5ca23f6baadc30d6a0dd559a35e7bc4762fdf3 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnCarpet_m.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 12, - "Parameters": { - "Intensity": 68, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 10, - "Intensity": 0.76, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 35, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 154, - "Parameters": { - "Intensity": 64, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 583, - "Parameters": { - "Intensity": 66, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 8, - "Intensity": 0.8, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 690, - "Parameters": { - "Intensity": 64, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 1182, - "Parameters": { - "Intensity": 65, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 8, - "Intensity": 0.77, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 10 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1314, - "Parameters": { - "Intensity": 63, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 74, - "StartTime": 1786, - "Parameters": { - "Intensity": 57, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 9, - "Intensity": 0.83, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 34, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 73, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1911, - "Parameters": { - "Intensity": 63, - "Frequency": 35 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 12, + "Parameters": { + "Intensity": 68, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 10, + "Intensity": 0.76, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 35, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 154, + "Parameters": { + "Intensity": 64, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 583, + "Parameters": { + "Intensity": 66, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 8, + "Intensity": 0.8, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 690, + "Parameters": { + "Intensity": 64, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 1182, + "Parameters": { + "Intensity": 65, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 8, + "Intensity": 0.77, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 10 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1314, + "Parameters": { + "Intensity": 63, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 74, + "StartTime": 1786, + "Parameters": { + "Intensity": 57, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 9, + "Intensity": 0.83, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 34, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 73, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1911, + "Parameters": { + "Intensity": 63, + "Frequency": 35 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_h.json index d57b5f5120d061c5596063c5e5b2fa6c88a6e669..114f8096802ce733ab5da7440736769aa4fa2232 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_h.json @@ -1,401 +1,401 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 6, - "Parameters": { - "Intensity": 100, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 82, - "Parameters": { - "Intensity": 71, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 303, - "Parameters": { - "Intensity": 100, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 27, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 375, - "Parameters": { - "Intensity": 64, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 601, - "Parameters": { - "Intensity": 100, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 27, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 675, - "Parameters": { - "Intensity": 70, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 898, - "Parameters": { - "Intensity": 100, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 980, - "Parameters": { - "Intensity": 74, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 6, + "Parameters": { + "Intensity": 100, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 82, + "Parameters": { + "Intensity": 71, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 303, + "Parameters": { + "Intensity": 100, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 27, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 375, + "Parameters": { + "Intensity": 64, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 601, + "Parameters": { + "Intensity": 100, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 27, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 675, + "Parameters": { + "Intensity": 70, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 898, + "Parameters": { + "Intensity": 100, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 980, + "Parameters": { + "Intensity": 74, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_l.json index a5515897fd3a06037def7e8edb4b9afc01699b28..17d30630026378b24fb6bc4fbaf23d1def1b8767 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_l.json @@ -1,401 +1,401 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 6, - "Parameters": { - "Intensity": 60, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 82, - "Parameters": { - "Intensity": 42, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 303, - "Parameters": { - "Intensity": 60, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 27, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 375, - "Parameters": { - "Intensity": 38, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 601, - "Parameters": { - "Intensity": 60, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 27, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 675, - "Parameters": { - "Intensity": 42, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 898, - "Parameters": { - "Intensity": 60, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 980, - "Parameters": { - "Intensity": 44, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 6, + "Parameters": { + "Intensity": 60, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 82, + "Parameters": { + "Intensity": 42, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 303, + "Parameters": { + "Intensity": 60, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 27, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 375, + "Parameters": { + "Intensity": 38, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 601, + "Parameters": { + "Intensity": 60, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 27, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 675, + "Parameters": { + "Intensity": 42, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 898, + "Parameters": { + "Intensity": 60, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 980, + "Parameters": { + "Intensity": 44, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_m.json index 078945e6c2bbd0b0d1377ab56351179a60d7c784..b1a2f1b295699d685c87d551d726991b62347628 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnConcrete_m.json @@ -1,401 +1,401 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 6, - "Parameters": { - "Intensity": 80, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 82, - "Parameters": { - "Intensity": 56, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 303, - "Parameters": { - "Intensity": 80, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 27, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 375, - "Parameters": { - "Intensity": 51, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 50, - "StartTime": 601, - "Parameters": { - "Intensity": 80, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 23, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 27, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 675, - "Parameters": { - "Intensity": 56, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 898, - "Parameters": { - "Intensity": 80, - "Frequency": 40, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 56, - "StartTime": 980, - "Parameters": { - "Intensity": 59, - "Frequency": 42, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -10 - }, - { - "Time": 1, - "Intensity": 0.47, - "Frequency": -10 - }, - { - "Time": 10, - "Intensity": 1, - "Frequency": 8 - }, - { - "Time": 26, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 30, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 6, + "Parameters": { + "Intensity": 80, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 82, + "Parameters": { + "Intensity": 56, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 303, + "Parameters": { + "Intensity": 80, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 27, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 375, + "Parameters": { + "Intensity": 51, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 50, + "StartTime": 601, + "Parameters": { + "Intensity": 80, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 23, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 27, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 675, + "Parameters": { + "Intensity": 56, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 898, + "Parameters": { + "Intensity": 80, + "Frequency": 40, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 56, + "StartTime": 980, + "Parameters": { + "Intensity": 59, + "Frequency": 42, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -10 + }, + { + "Time": 1, + "Intensity": 0.47, + "Frequency": -10 + }, + { + "Time": 10, + "Intensity": 1, + "Frequency": 8 + }, + { + "Time": 26, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 30, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_h.json index e5671edb478acc8f29d4a3241fc55bf5e38328b5..a19204f1a53b4ec80862a02ad75efeeb16af6402 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_h.json @@ -1,518 +1,518 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 24, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 46, - "Parameters": { - "Intensity": 100, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 104, - "Parameters": { - "Intensity": 78, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 246, - "StartTime": 139, - "Parameters": { - "Intensity": 69, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 0.73, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 177, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 246, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 707, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 729, - "Parameters": { - "Intensity": 100, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 787, - "Parameters": { - "Intensity": 78, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 195, - "StartTime": 821, - "Parameters": { - "Intensity": 90, - "Frequency": 66, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 0 - }, - { - "Time": 97, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 159, - "Intensity": 0.3, - "Frequency": 36 - }, - { - "Time": 195, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1423, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 1445, - "Parameters": { - "Intensity": 100, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 1503, - "Parameters": { - "Intensity": 78, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 129, - "StartTime": 1538, - "Parameters": { - "Intensity": 69, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 11, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 0.71, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 129, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2109, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 2131, - "Parameters": { - "Intensity": 100, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 2178, - "Parameters": { - "Intensity": 78, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 222, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 351, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 129, - "StartTime": 2224, - "Parameters": { - "Intensity": 69, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 11, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 0.71, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 129, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 24, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 46, + "Parameters": { + "Intensity": 100, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 104, + "Parameters": { + "Intensity": 78, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 246, + "StartTime": 139, + "Parameters": { + "Intensity": 69, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 0.73, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 177, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 246, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 707, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 729, + "Parameters": { + "Intensity": 100, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 787, + "Parameters": { + "Intensity": 78, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 195, + "StartTime": 821, + "Parameters": { + "Intensity": 90, + "Frequency": 66, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 0 + }, + { + "Time": 97, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 159, + "Intensity": 0.3, + "Frequency": 36 + }, + { + "Time": 195, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1423, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 1445, + "Parameters": { + "Intensity": 100, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 1503, + "Parameters": { + "Intensity": 78, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 129, + "StartTime": 1538, + "Parameters": { + "Intensity": 69, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 11, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 0.71, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 129, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2109, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 2131, + "Parameters": { + "Intensity": 100, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 2178, + "Parameters": { + "Intensity": 78, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 222, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 351, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 129, + "StartTime": 2224, + "Parameters": { + "Intensity": 69, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 11, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 0.71, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 129, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_l.json index d4d7ec6256a650df2cecd68f033986a4f4b48c6e..a5031649002fa697e590bf1203c6c8692edb6c68 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_l.json @@ -1,518 +1,518 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 24, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 46, - "Parameters": { - "Intensity": 60, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 104, - "Parameters": { - "Intensity": 46, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 246, - "StartTime": 139, - "Parameters": { - "Intensity": 41, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 0.73, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 177, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 246, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 707, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 729, - "Parameters": { - "Intensity": 60, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 787, - "Parameters": { - "Intensity": 46, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 195, - "StartTime": 821, - "Parameters": { - "Intensity": 54, - "Frequency": 66, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 0 - }, - { - "Time": 97, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 159, - "Intensity": 0.3, - "Frequency": 36 - }, - { - "Time": 195, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1423, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 1445, - "Parameters": { - "Intensity": 60, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 1503, - "Parameters": { - "Intensity": 46, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 129, - "StartTime": 1538, - "Parameters": { - "Intensity": 41, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 11, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 0.71, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 129, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2109, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 2131, - "Parameters": { - "Intensity": 60, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 2178, - "Parameters": { - "Intensity": 46, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 222, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 351, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 129, - "StartTime": 2224, - "Parameters": { - "Intensity": 41, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 11, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 0.71, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 129, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 24, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 46, + "Parameters": { + "Intensity": 60, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 104, + "Parameters": { + "Intensity": 46, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 246, + "StartTime": 139, + "Parameters": { + "Intensity": 41, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 0.73, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 177, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 246, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 707, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 729, + "Parameters": { + "Intensity": 60, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 787, + "Parameters": { + "Intensity": 46, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 195, + "StartTime": 821, + "Parameters": { + "Intensity": 54, + "Frequency": 66, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 0 + }, + { + "Time": 97, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 159, + "Intensity": 0.3, + "Frequency": 36 + }, + { + "Time": 195, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1423, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 1445, + "Parameters": { + "Intensity": 60, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 1503, + "Parameters": { + "Intensity": 46, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 129, + "StartTime": 1538, + "Parameters": { + "Intensity": 41, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 11, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 0.71, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 129, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2109, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 2131, + "Parameters": { + "Intensity": 60, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 2178, + "Parameters": { + "Intensity": 46, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 222, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 351, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 129, + "StartTime": 2224, + "Parameters": { + "Intensity": 41, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 11, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 0.71, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 129, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_m.json index 3aafd27d556fc6fad6d27c5ad116f79b55a6b8fc..cb2ebbb2888f26a53c9617d43c3f377580abef57 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGrass_m.json @@ -1,518 +1,518 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 24, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 46, - "Parameters": { - "Intensity": 80, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 104, - "Parameters": { - "Intensity": 62, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 246, - "StartTime": 139, - "Parameters": { - "Intensity": 55, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 0.73, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 177, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 246, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 707, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 729, - "Parameters": { - "Intensity": 80, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 787, - "Parameters": { - "Intensity": 62, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 195, - "StartTime": 821, - "Parameters": { - "Intensity": 72, - "Frequency": 66, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 0 - }, - { - "Time": 97, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 159, - "Intensity": 0.3, - "Frequency": 36 - }, - { - "Time": 195, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1423, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 1445, - "Parameters": { - "Intensity": 80, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 1503, - "Parameters": { - "Intensity": 62, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 230, - "Intensity": 0.44, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 129, - "StartTime": 1538, - "Parameters": { - "Intensity": 55, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 11, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 0.71, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 129, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2109, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 68, - "StartTime": 2131, - "Parameters": { - "Intensity": 80, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 43, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 56, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 68, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 397, - "StartTime": 2178, - "Parameters": { - "Intensity": 62, - "Frequency": 15, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 122, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 222, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 351, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 397, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 129, - "StartTime": 2224, - "Parameters": { - "Intensity": 55, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 11, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 0.71, - "Frequency": 0 - }, - { - "Time": 93, - "Intensity": 0.22, - "Frequency": 36 - }, - { - "Time": 129, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 24, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 46, + "Parameters": { + "Intensity": 80, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 104, + "Parameters": { + "Intensity": 62, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 246, + "StartTime": 139, + "Parameters": { + "Intensity": 55, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 0.73, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 177, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 246, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 707, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 729, + "Parameters": { + "Intensity": 80, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 787, + "Parameters": { + "Intensity": 62, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 195, + "StartTime": 821, + "Parameters": { + "Intensity": 72, + "Frequency": 66, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 0 + }, + { + "Time": 97, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 159, + "Intensity": 0.3, + "Frequency": 36 + }, + { + "Time": 195, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1423, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 1445, + "Parameters": { + "Intensity": 80, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 1503, + "Parameters": { + "Intensity": 62, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 230, + "Intensity": 0.44, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 129, + "StartTime": 1538, + "Parameters": { + "Intensity": 55, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 11, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 0.71, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 129, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2109, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 68, + "StartTime": 2131, + "Parameters": { + "Intensity": 80, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 43, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 56, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 68, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 397, + "StartTime": 2178, + "Parameters": { + "Intensity": 62, + "Frequency": 15, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 122, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 222, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 351, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 397, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 129, + "StartTime": 2224, + "Parameters": { + "Intensity": 55, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 11, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 0.71, + "Frequency": 0 + }, + { + "Time": 93, + "Intensity": 0.22, + "Frequency": 36 + }, + { + "Time": 129, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_h.json index f25a3ee6da7a569d5d7c0d77852de698bb028b8d..dbecb953f76b93b38db811043860455cf152ca39 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_h.json @@ -1,585 +1,585 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 39, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 75, - "Parameters": { - "Intensity": 93, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 346, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 371, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 620, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 649, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 888, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 896, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1163, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1204, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1430, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1471, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1685, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1718, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1957, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1988, - "Parameters": { - "Intensity": 89, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 39, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 75, + "Parameters": { + "Intensity": 93, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 346, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 371, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 620, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 649, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 888, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 896, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1163, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1204, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1430, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1471, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1685, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1718, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1957, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1988, + "Parameters": { + "Intensity": 89, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_l.json index 5f8019d713b6233aec6c75917487eead2ef244e8..6a78d789250d159dc75d18bbd8f88d7ea9b47e26 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_l.json @@ -1,585 +1,585 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 39, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 75, - "Parameters": { - "Intensity": 55, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 346, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 371, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 620, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 649, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 888, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 896, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1163, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1204, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1430, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1471, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1685, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1718, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1957, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1988, - "Parameters": { - "Intensity": 53, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 39, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 75, + "Parameters": { + "Intensity": 55, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 346, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 371, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 620, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 649, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 888, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 896, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1163, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1204, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1430, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1471, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1685, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1718, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1957, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1988, + "Parameters": { + "Intensity": 53, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_m.json index b7e8171ec06f6fa6b6de330382b51cd48c2362ee..ecfaa84bc9e7dec80bfb84eeba384d12ef81e780 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnGravel_m.json @@ -1,585 +1,585 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 39, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 75, - "Parameters": { - "Intensity": 74, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 346, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 371, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 620, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 649, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 888, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 896, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1163, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1204, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1430, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1471, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1685, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1718, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 1957, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 87, - "Intensity": 0.74, - "Frequency": 0 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 136, - "StartTime": 1988, - "Parameters": { - "Intensity": 71, - "Frequency": 25, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 18 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 13 - }, - { - "Time": 83, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 136, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 39, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 75, + "Parameters": { + "Intensity": 74, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 346, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 371, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 620, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 649, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 888, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 896, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1163, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1204, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1430, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1471, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1685, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1718, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 1957, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 87, + "Intensity": 0.74, + "Frequency": 0 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 136, + "StartTime": 1988, + "Parameters": { + "Intensity": 71, + "Frequency": 25, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 18 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 13 + }, + { + "Time": 83, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 136, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_h.json index e9ac8ed0a9525ad62839bb60816e0b0eab1ead58..9f2f11e157f1dafdaefdc1bf488be3feb83e3099 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_h.json @@ -1,369 +1,369 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 48, - "Parameters": { - "Intensity": 88, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 39, - "Intensity": 0.65, - "Frequency": 40 - }, - { - "Time": 127, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 147, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 211, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 280, - "Intensity": 0.61, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 396, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 469, - "Intensity": 0.44, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 596, - "Intensity": 0.1, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 143, - "Parameters": { - "Intensity": 100, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 853, - "StartTime": 1130, - "Parameters": { - "Intensity": 84, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 47, - "Intensity": 0.71, - "Frequency": 40 - }, - { - "Time": 178, - "Intensity": 0.95, - "Frequency": 30 - }, - { - "Time": 188, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 236, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 327, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 439, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 524, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 586, - "Intensity": 0.48, - "Frequency": 10 - }, - { - "Time": 676, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 785, - "Intensity": 0.07, - "Frequency": 10 - }, - { - "Time": 853, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1274, - "Parameters": { - "Intensity": 100, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 2446, - "Parameters": { - "Intensity": 89, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 40 - }, - { - "Time": 66, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 248, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 490, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2525, - "Parameters": { - "Intensity": 100, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2860, - "Parameters": { - "Intensity": 67, - "Frequency": 12 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 3685, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 40 - }, - { - "Time": 66, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 247, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.49, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3780, - "Parameters": { - "Intensity": 100, - "Frequency": 29 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4143, - "Parameters": { - "Intensity": 59, - "Frequency": 16 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 48, + "Parameters": { + "Intensity": 88, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 39, + "Intensity": 0.65, + "Frequency": 40 + }, + { + "Time": 127, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 147, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 211, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 280, + "Intensity": 0.61, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 396, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 469, + "Intensity": 0.44, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 596, + "Intensity": 0.1, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 143, + "Parameters": { + "Intensity": 100, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 853, + "StartTime": 1130, + "Parameters": { + "Intensity": 84, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 47, + "Intensity": 0.71, + "Frequency": 40 + }, + { + "Time": 178, + "Intensity": 0.95, + "Frequency": 30 + }, + { + "Time": 188, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 236, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 327, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 439, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 524, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 586, + "Intensity": 0.48, + "Frequency": 10 + }, + { + "Time": 676, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 785, + "Intensity": 0.07, + "Frequency": 10 + }, + { + "Time": 853, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1274, + "Parameters": { + "Intensity": 100, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 2446, + "Parameters": { + "Intensity": 89, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 40 + }, + { + "Time": 66, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 248, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 490, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2525, + "Parameters": { + "Intensity": 100, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2860, + "Parameters": { + "Intensity": 67, + "Frequency": 12 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 3685, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 40 + }, + { + "Time": 66, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 247, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.49, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3780, + "Parameters": { + "Intensity": 100, + "Frequency": 29 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4143, + "Parameters": { + "Intensity": 59, + "Frequency": 16 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_l.json index aeec0b1057d2e6c9bce2217e3b19735d69ef7993..1891aca832d2a6db97dfaec0ebd4bacc42515f0b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_l.json @@ -1,369 +1,369 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 48, - "Parameters": { - "Intensity": 52, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 39, - "Intensity": 0.65, - "Frequency": 40 - }, - { - "Time": 127, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 147, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 211, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 280, - "Intensity": 0.61, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 396, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 469, - "Intensity": 0.44, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 596, - "Intensity": 0.1, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 143, - "Parameters": { - "Intensity": 60, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 853, - "StartTime": 1130, - "Parameters": { - "Intensity": 50, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 47, - "Intensity": 0.71, - "Frequency": 40 - }, - { - "Time": 178, - "Intensity": 0.95, - "Frequency": 30 - }, - { - "Time": 188, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 236, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 327, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 439, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 524, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 586, - "Intensity": 0.48, - "Frequency": 10 - }, - { - "Time": 676, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 785, - "Intensity": 0.07, - "Frequency": 10 - }, - { - "Time": 853, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1274, - "Parameters": { - "Intensity": 60, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 2446, - "Parameters": { - "Intensity": 53, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 40 - }, - { - "Time": 66, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 248, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 490, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2525, - "Parameters": { - "Intensity": 60, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2860, - "Parameters": { - "Intensity": 40, - "Frequency": 12 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 3685, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 40 - }, - { - "Time": 66, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 247, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.49, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3780, - "Parameters": { - "Intensity": 60, - "Frequency": 29 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4143, - "Parameters": { - "Intensity": 35, - "Frequency": 16 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 48, + "Parameters": { + "Intensity": 52, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 39, + "Intensity": 0.65, + "Frequency": 40 + }, + { + "Time": 127, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 147, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 211, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 280, + "Intensity": 0.61, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 396, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 469, + "Intensity": 0.44, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 596, + "Intensity": 0.1, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 143, + "Parameters": { + "Intensity": 60, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 853, + "StartTime": 1130, + "Parameters": { + "Intensity": 50, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 47, + "Intensity": 0.71, + "Frequency": 40 + }, + { + "Time": 178, + "Intensity": 0.95, + "Frequency": 30 + }, + { + "Time": 188, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 236, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 327, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 439, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 524, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 586, + "Intensity": 0.48, + "Frequency": 10 + }, + { + "Time": 676, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 785, + "Intensity": 0.07, + "Frequency": 10 + }, + { + "Time": 853, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1274, + "Parameters": { + "Intensity": 60, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 2446, + "Parameters": { + "Intensity": 53, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 40 + }, + { + "Time": 66, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 248, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 490, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2525, + "Parameters": { + "Intensity": 60, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2860, + "Parameters": { + "Intensity": 40, + "Frequency": 12 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 3685, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 40 + }, + { + "Time": 66, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 247, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.49, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3780, + "Parameters": { + "Intensity": 60, + "Frequency": 29 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4143, + "Parameters": { + "Intensity": 35, + "Frequency": 16 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_m.json index c61f6153e112a2ecc07c80a6ecc8612212695c73..6058bd02d206870d6e6f0700639f4bfe88bfbd64 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnMud_m.json @@ -1,369 +1,369 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 48, - "Parameters": { - "Intensity": 70, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 39, - "Intensity": 0.65, - "Frequency": 40 - }, - { - "Time": 127, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 147, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 211, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 280, - "Intensity": 0.61, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 396, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 469, - "Intensity": 0.44, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 596, - "Intensity": 0.1, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 143, - "Parameters": { - "Intensity": 80, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 853, - "StartTime": 1130, - "Parameters": { - "Intensity": 67, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 47, - "Intensity": 0.71, - "Frequency": 40 - }, - { - "Time": 178, - "Intensity": 0.95, - "Frequency": 30 - }, - { - "Time": 188, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 236, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 327, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 439, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 524, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 586, - "Intensity": 0.48, - "Frequency": 10 - }, - { - "Time": 676, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 785, - "Intensity": 0.07, - "Frequency": 10 - }, - { - "Time": 853, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1274, - "Parameters": { - "Intensity": 80, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 2446, - "Parameters": { - "Intensity": 71, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 40 - }, - { - "Time": 66, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 248, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 490, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2525, - "Parameters": { - "Intensity": 80, - "Frequency": 45 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2860, - "Parameters": { - "Intensity": 53, - "Frequency": 12 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 3685, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 24, - "Intensity": 0.81, - "Frequency": 40 - }, - { - "Time": 66, - "Intensity": 0.97, - "Frequency": 30 - }, - { - "Time": 101, - "Intensity": 0.36, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 247, - "Intensity": 0.6, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.49, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3780, - "Parameters": { - "Intensity": 80, - "Frequency": 29 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4143, - "Parameters": { - "Intensity": 47, - "Frequency": 16 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 48, + "Parameters": { + "Intensity": 70, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 39, + "Intensity": 0.65, + "Frequency": 40 + }, + { + "Time": 127, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 147, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 211, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 280, + "Intensity": 0.61, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 396, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 469, + "Intensity": 0.44, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 596, + "Intensity": 0.1, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 143, + "Parameters": { + "Intensity": 80, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 853, + "StartTime": 1130, + "Parameters": { + "Intensity": 67, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 47, + "Intensity": 0.71, + "Frequency": 40 + }, + { + "Time": 178, + "Intensity": 0.95, + "Frequency": 30 + }, + { + "Time": 188, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 236, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 327, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 439, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 524, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 586, + "Intensity": 0.48, + "Frequency": 10 + }, + { + "Time": 676, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 785, + "Intensity": 0.07, + "Frequency": 10 + }, + { + "Time": 853, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1274, + "Parameters": { + "Intensity": 80, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 2446, + "Parameters": { + "Intensity": 71, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 40 + }, + { + "Time": 66, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 248, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 490, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2525, + "Parameters": { + "Intensity": 80, + "Frequency": 45 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2860, + "Parameters": { + "Intensity": 53, + "Frequency": 12 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 3685, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 24, + "Intensity": 0.81, + "Frequency": 40 + }, + { + "Time": 66, + "Intensity": 0.97, + "Frequency": 30 + }, + { + "Time": 101, + "Intensity": 0.36, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 247, + "Intensity": 0.6, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.49, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3780, + "Parameters": { + "Intensity": 80, + "Frequency": 29 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4143, + "Parameters": { + "Intensity": 47, + "Frequency": 16 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_h.json index 6eea0b9f403595f9c09a01cf5bfb74d2f9e0febc..80445048a1703d21bc2543402c7625b6f5491fde 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_h.json @@ -1,1053 +1,1053 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 175, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 134, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 310, - "Parameters": { - "Intensity": 76, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 562, - "Parameters": { - "Intensity": 66, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 1332, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 146, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1467, - "Parameters": { - "Intensity": 76, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1719, - "Parameters": { - "Intensity": 68, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 2863, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 134, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2998, - "Parameters": { - "Intensity": 76, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3250, - "Parameters": { - "Intensity": 66, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 4014, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 120, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4149, - "Parameters": { - "Intensity": 76, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4401, - "Parameters": { - "Intensity": 69, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 175, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 134, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 310, + "Parameters": { + "Intensity": 76, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 562, + "Parameters": { + "Intensity": 66, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 1332, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 146, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1467, + "Parameters": { + "Intensity": 76, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1719, + "Parameters": { + "Intensity": 68, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 2863, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 134, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2998, + "Parameters": { + "Intensity": 76, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3250, + "Parameters": { + "Intensity": 66, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 4014, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 120, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4149, + "Parameters": { + "Intensity": 76, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4401, + "Parameters": { + "Intensity": 69, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_l.json index 7af23f77b34c9b04313926c7e801620351870c65..ca863918a1693019f9033ecbbc28372092b37004 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_l.json @@ -1,1053 +1,1053 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 175, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 134, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 310, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 562, - "Parameters": { - "Intensity": 39, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 1332, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 146, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1467, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1719, - "Parameters": { - "Intensity": 40, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 2863, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 134, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2998, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3250, - "Parameters": { - "Intensity": 39, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 4014, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 120, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4149, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4401, - "Parameters": { - "Intensity": 41, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 175, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 134, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 310, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 562, + "Parameters": { + "Intensity": 39, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 1332, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 146, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1467, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1719, + "Parameters": { + "Intensity": 40, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 2863, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 134, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2998, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3250, + "Parameters": { + "Intensity": 39, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 4014, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 120, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4149, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4401, + "Parameters": { + "Intensity": 41, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_m.json index a64fb592500a18ee0723c8187aafeef06cc89d79..5afeddc1a5d1e178d5a4aa8b6a8cf897f151d63a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnSnow_m.json @@ -1,1053 +1,1053 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 175, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 134, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 310, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 562, - "Parameters": { - "Intensity": 52, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 1332, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 146, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1467, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1719, - "Parameters": { - "Intensity": 54, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 2863, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 134, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2998, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3250, - "Parameters": { - "Intensity": 52, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 653, - "StartTime": 4014, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 20, - "Intensity": 0.82, - "Frequency": 40 - }, - { - "Time": 92, - "Intensity": 0.96, - "Frequency": 30 - }, - { - "Time": 120, - "Intensity": 0.41, - "Frequency": 10 - }, - { - "Time": 181, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 253, - "Intensity": 0.38, - "Frequency": 10 - }, - { - "Time": 337, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 439, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 494, - "Intensity": 0.28, - "Frequency": 10 - }, - { - "Time": 555, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 621, - "Intensity": 0.12, - "Frequency": 10 - }, - { - "Time": 653, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4149, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 66 - }, - { - "Time": 17, - "Intensity": 0.38, - "Frequency": 68 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 71 - }, - { - "Time": 48, - "Intensity": 0.57, - "Frequency": 70 - }, - { - "Time": 59, - "Intensity": 0.43, - "Frequency": 69 - }, - { - "Time": 67, - "Intensity": 0.2, - "Frequency": 70 - }, - { - "Time": 83, - "Intensity": 0.4, - "Frequency": 69 - }, - { - "Time": 102, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 125, - "Intensity": 0.34, - "Frequency": 66 - }, - { - "Time": 150, - "Intensity": 0.58, - "Frequency": 68 - }, - { - "Time": 167, - "Intensity": 0.71, - "Frequency": 70 - }, - { - "Time": 183, - "Intensity": 0.45, - "Frequency": 64 - }, - { - "Time": 212, - "Intensity": 0.3, - "Frequency": 59 - }, - { - "Time": 233, - "Intensity": 0.53, - "Frequency": 57 - }, - { - "Time": 240, - "Intensity": 0.2, - "Frequency": 60 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 62 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4401, - "Parameters": { - "Intensity": 55, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 60 - }, - { - "Time": 10, - "Intensity": 0.43, - "Frequency": 62 - }, - { - "Time": 36, - "Intensity": 0.74, - "Frequency": 64 - }, - { - "Time": 49, - "Intensity": 0.35, - "Frequency": 62 - }, - { - "Time": 67, - "Intensity": 0.21, - "Frequency": 64 - }, - { - "Time": 80, - "Intensity": 0.66, - "Frequency": 61 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 67 - }, - { - "Time": 117, - "Intensity": 0.63, - "Frequency": 67 - }, - { - "Time": 134, - "Intensity": 0.07, - "Frequency": 72 - }, - { - "Time": 150, - "Intensity": 0.66, - "Frequency": 72 - }, - { - "Time": 164, - "Intensity": 0.37, - "Frequency": 70 - }, - { - "Time": 184, - "Intensity": 0.07, - "Frequency": 70 - }, - { - "Time": 200, - "Intensity": 0.3, - "Frequency": 66 - }, - { - "Time": 213, - "Intensity": 0.59, - "Frequency": 66 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 61 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 63 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 175, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 134, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 310, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 562, + "Parameters": { + "Intensity": 52, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 1332, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 146, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1467, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1719, + "Parameters": { + "Intensity": 54, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 2863, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 134, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2998, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3250, + "Parameters": { + "Intensity": 52, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 653, + "StartTime": 4014, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 20, + "Intensity": 0.82, + "Frequency": 40 + }, + { + "Time": 92, + "Intensity": 0.96, + "Frequency": 30 + }, + { + "Time": 120, + "Intensity": 0.41, + "Frequency": 10 + }, + { + "Time": 181, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 253, + "Intensity": 0.38, + "Frequency": 10 + }, + { + "Time": 337, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 439, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 494, + "Intensity": 0.28, + "Frequency": 10 + }, + { + "Time": 555, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 621, + "Intensity": 0.12, + "Frequency": 10 + }, + { + "Time": 653, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4149, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 66 + }, + { + "Time": 17, + "Intensity": 0.38, + "Frequency": 68 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 71 + }, + { + "Time": 48, + "Intensity": 0.57, + "Frequency": 70 + }, + { + "Time": 59, + "Intensity": 0.43, + "Frequency": 69 + }, + { + "Time": 67, + "Intensity": 0.2, + "Frequency": 70 + }, + { + "Time": 83, + "Intensity": 0.4, + "Frequency": 69 + }, + { + "Time": 102, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 125, + "Intensity": 0.34, + "Frequency": 66 + }, + { + "Time": 150, + "Intensity": 0.58, + "Frequency": 68 + }, + { + "Time": 167, + "Intensity": 0.71, + "Frequency": 70 + }, + { + "Time": 183, + "Intensity": 0.45, + "Frequency": 64 + }, + { + "Time": 212, + "Intensity": 0.3, + "Frequency": 59 + }, + { + "Time": 233, + "Intensity": 0.53, + "Frequency": 57 + }, + { + "Time": 240, + "Intensity": 0.2, + "Frequency": 60 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 62 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4401, + "Parameters": { + "Intensity": 55, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 60 + }, + { + "Time": 10, + "Intensity": 0.43, + "Frequency": 62 + }, + { + "Time": 36, + "Intensity": 0.74, + "Frequency": 64 + }, + { + "Time": 49, + "Intensity": 0.35, + "Frequency": 62 + }, + { + "Time": 67, + "Intensity": 0.21, + "Frequency": 64 + }, + { + "Time": 80, + "Intensity": 0.66, + "Frequency": 61 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 67 + }, + { + "Time": 117, + "Intensity": 0.63, + "Frequency": 67 + }, + { + "Time": 134, + "Intensity": 0.07, + "Frequency": 72 + }, + { + "Time": 150, + "Intensity": 0.66, + "Frequency": 72 + }, + { + "Time": 164, + "Intensity": 0.37, + "Frequency": 70 + }, + { + "Time": 184, + "Intensity": 0.07, + "Frequency": 70 + }, + { + "Time": 200, + "Intensity": 0.3, + "Frequency": 66 + }, + { + "Time": 213, + "Intensity": 0.59, + "Frequency": 66 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 61 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 63 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_h.json index 3d6ceaeaa8c7c29bd86c6fc0f8f227351e3446b2..5434fa92e995138cb80b1f53ac630a85c6dd0876 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_h.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 14, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 122, - "Parameters": { - "Intensity": 100, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 897, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1040, - "Parameters": { - "Intensity": 100, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1565, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1680, - "Parameters": { - "Intensity": 100, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2313, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 2440, - "Parameters": { - "Intensity": 100, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 14, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 122, + "Parameters": { + "Intensity": 100, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 897, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1040, + "Parameters": { + "Intensity": 100, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1565, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1680, + "Parameters": { + "Intensity": 100, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2313, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 2440, + "Parameters": { + "Intensity": 100, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_l.json index 5c431634ce909b4f5d255bd7afcc863f418e73e0..4c3d771f75e66113354cb6756faf0a8d93bbb16a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_l.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 14, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 122, - "Parameters": { - "Intensity": 60, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 897, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1040, - "Parameters": { - "Intensity": 60, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1565, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1680, - "Parameters": { - "Intensity": 60, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2313, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 2440, - "Parameters": { - "Intensity": 60, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 14, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 122, + "Parameters": { + "Intensity": 60, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 897, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1040, + "Parameters": { + "Intensity": 60, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1565, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1680, + "Parameters": { + "Intensity": 60, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2313, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 2440, + "Parameters": { + "Intensity": 60, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_m.json index ad0fb12239c025b2379e62ae1c9b536c2ee89d33..f3251a91a961df784ac5da10df56ffba851cdc24 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/OnWood_m.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 14, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 122, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 897, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1040, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1565, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1680, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2313, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 2440, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 22, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 29, - "Intensity": 0.38, - "Frequency": -10 - }, - { - "Time": 61, - "Intensity": 0.13, - "Frequency": -30 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 14, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 122, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 897, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1040, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1565, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1680, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2313, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 2440, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 22, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 29, + "Intensity": 0.38, + "Frequency": -10 + }, + { + "Time": 61, + "Intensity": 0.13, + "Frequency": -30 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_h.json index e3d0a1e7992f0b7ef06e38dc9ddd4698647b98db..d2ff03dee2362dd0920d35eb4ae063e79abf6533 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_h.json @@ -1,193 +1,193 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 120, - "Parameters": { - "Intensity": 75, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 172, - "Parameters": { - "Intensity": 73, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 236, - "Parameters": { - "Intensity": 71, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 287, - "Parameters": { - "Intensity": 73, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 317, - "Parameters": { - "Intensity": 66, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 348, - "Parameters": { - "Intensity": 72, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 391, - "Parameters": { - "Intensity": 71, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 420, - "Parameters": { - "Intensity": 69, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 466, - "Parameters": { - "Intensity": 72, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 511, - "Parameters": { - "Intensity": 68, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 553, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 596, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 620, - "Parameters": { - "Intensity": 62, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 648, - "Parameters": { - "Intensity": 70, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 711, - "Parameters": { - "Intensity": 67, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 801, - "Parameters": { - "Intensity": 69, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 120, + "Parameters": { + "Intensity": 75, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 172, + "Parameters": { + "Intensity": 73, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 236, + "Parameters": { + "Intensity": 71, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 287, + "Parameters": { + "Intensity": 73, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 317, + "Parameters": { + "Intensity": 66, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 348, + "Parameters": { + "Intensity": 72, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 391, + "Parameters": { + "Intensity": 71, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 420, + "Parameters": { + "Intensity": 69, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 466, + "Parameters": { + "Intensity": 72, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 511, + "Parameters": { + "Intensity": 68, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 553, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 596, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 620, + "Parameters": { + "Intensity": 62, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 648, + "Parameters": { + "Intensity": 70, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 711, + "Parameters": { + "Intensity": 67, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 801, + "Parameters": { + "Intensity": 69, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_l.json index 42d0c5e92d40cd522dedd129bd38a0b4ba2b5731..735ba10bcdc59faac476d2f4dabec560ea4965b4 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_l.json @@ -1,193 +1,193 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 120, - "Parameters": { - "Intensity": 45, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 172, - "Parameters": { - "Intensity": 43, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 236, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 287, - "Parameters": { - "Intensity": 43, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 317, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 348, - "Parameters": { - "Intensity": 43, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 391, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 420, - "Parameters": { - "Intensity": 41, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 466, - "Parameters": { - "Intensity": 43, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 511, - "Parameters": { - "Intensity": 40, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 553, - "Parameters": { - "Intensity": 38, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 596, - "Parameters": { - "Intensity": 38, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 620, - "Parameters": { - "Intensity": 37, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 648, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 711, - "Parameters": { - "Intensity": 40, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 801, - "Parameters": { - "Intensity": 41, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 120, + "Parameters": { + "Intensity": 45, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 172, + "Parameters": { + "Intensity": 43, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 236, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 287, + "Parameters": { + "Intensity": 43, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 317, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 348, + "Parameters": { + "Intensity": 43, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 391, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 420, + "Parameters": { + "Intensity": 41, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 466, + "Parameters": { + "Intensity": 43, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 511, + "Parameters": { + "Intensity": 40, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 553, + "Parameters": { + "Intensity": 38, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 596, + "Parameters": { + "Intensity": 38, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 620, + "Parameters": { + "Intensity": 37, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 648, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 711, + "Parameters": { + "Intensity": 40, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 801, + "Parameters": { + "Intensity": 41, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_m.json index 1cdc3935aaef4523bb9a0067261eaf1e142e1ebc..3713709aea0268cd870369912bc4af329786865f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Picker_m.json @@ -1,193 +1,193 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 120, - "Parameters": { - "Intensity": 60, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 172, - "Parameters": { - "Intensity": 58, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 236, - "Parameters": { - "Intensity": 56, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 287, - "Parameters": { - "Intensity": 58, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 317, - "Parameters": { - "Intensity": 52, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 348, - "Parameters": { - "Intensity": 57, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 391, - "Parameters": { - "Intensity": 56, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 420, - "Parameters": { - "Intensity": 55, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 466, - "Parameters": { - "Intensity": 57, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 511, - "Parameters": { - "Intensity": 54, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 553, - "Parameters": { - "Intensity": 51, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 596, - "Parameters": { - "Intensity": 51, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 620, - "Parameters": { - "Intensity": 49, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 648, - "Parameters": { - "Intensity": 56, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 711, - "Parameters": { - "Intensity": 53, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 801, - "Parameters": { - "Intensity": 55, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 120, + "Parameters": { + "Intensity": 60, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 172, + "Parameters": { + "Intensity": 58, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 236, + "Parameters": { + "Intensity": 56, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 287, + "Parameters": { + "Intensity": 58, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 317, + "Parameters": { + "Intensity": 52, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 348, + "Parameters": { + "Intensity": 57, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 391, + "Parameters": { + "Intensity": 56, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 420, + "Parameters": { + "Intensity": 55, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 466, + "Parameters": { + "Intensity": 57, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 511, + "Parameters": { + "Intensity": 54, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 553, + "Parameters": { + "Intensity": 51, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 596, + "Parameters": { + "Intensity": 51, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 620, + "Parameters": { + "Intensity": 49, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 648, + "Parameters": { + "Intensity": 56, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 711, + "Parameters": { + "Intensity": 53, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 801, + "Parameters": { + "Intensity": 55, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_h.json index fa1ac4da2e895cee279f4fc423b5f118d3e9b82d..1b7ee07e42ce9f1893f3e87f41195e631560a2d6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_h.json @@ -1,60 +1,60 @@ -{ - "MetaData": { - "Create": "2022-04-21", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 34, - "Parameters": { - "Intensity": 31, - "Frequency": 5 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 63, - "StartTime": 81, - "Parameters": { - "Intensity": 100, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 0.79, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 63, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-21", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 34, + "Parameters": { + "Intensity": 31, + "Frequency": 5 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 63, + "StartTime": 81, + "Parameters": { + "Intensity": 100, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 0.79, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 63, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_l.json index d73d3d2f5032f012f874ced4da38314e858467c0..02c9bf677f518bccddc2f6481daeafd0659e645b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_l.json @@ -1,60 +1,60 @@ -{ - "MetaData": { - "Create": "2022-04-21", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 34, - "Parameters": { - "Intensity": 18, - "Frequency": 5 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 63, - "StartTime": 81, - "Parameters": { - "Intensity": 60, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 0.79, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 63, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-21", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 34, + "Parameters": { + "Intensity": 18, + "Frequency": 5 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 63, + "StartTime": 81, + "Parameters": { + "Intensity": 60, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 0.79, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 63, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_m.json index e9dbdd08e63a4f554d55c877c860450c4e4fa43f..113eadb47a53151dba6ef93561a14d1c4a8f0cb9 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Punch_m.json @@ -1,60 +1,60 @@ -{ - "MetaData": { - "Create": "2022-04-21", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 34, - "Parameters": { - "Intensity": 24, - "Frequency": 5 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 63, - "StartTime": 81, - "Parameters": { - "Intensity": 80, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 0.79, - "Frequency": 0 - }, - { - "Time": 48, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 63, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-21", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 34, + "Parameters": { + "Intensity": 24, + "Frequency": 5 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 63, + "StartTime": 81, + "Parameters": { + "Intensity": 80, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 0.79, + "Frequency": 0 + }, + { + "Time": 48, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 63, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_h.json index f2ba4c8f07d2ca6e3db0c9a50c6915370cf67392..51e9d70ae98ee1b355ccc15fec98890eead9bf8d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_h.json @@ -1,65 +1,65 @@ -{ - "MetaData": { - "Create": "2022-04-15", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 69, - "StartTime": 19, - "Parameters": { - "Intensity": 71, - "Frequency": 90, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 13, - "Intensity": 0.09, - "Frequency": -83 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": -36 - }, - { - "Time": 68, - "Intensity": 0.1, - "Frequency": -58 - }, - { - "Time": 69, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 92, - "Parameters": { - "Intensity": 100, - "Frequency": 61 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-15", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 69, + "StartTime": 19, + "Parameters": { + "Intensity": 71, + "Frequency": 90, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 13, + "Intensity": 0.09, + "Frequency": -83 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": -36 + }, + { + "Time": 68, + "Intensity": 0.1, + "Frequency": -58 + }, + { + "Time": 69, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 92, + "Parameters": { + "Intensity": 100, + "Frequency": 61 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_l.json index b932a84333a79faa57a36352b6b13db78d04a3f8..f396288aee3d752cbc2e5688d963f5cc83537b3f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_l.json @@ -1,65 +1,65 @@ -{ - "MetaData": { - "Create": "2022-04-15", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 69, - "StartTime": 19, - "Parameters": { - "Intensity": 42, - "Frequency": 90, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 13, - "Intensity": 0.09, - "Frequency": -83 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": -36 - }, - { - "Time": 68, - "Intensity": 0.1, - "Frequency": -58 - }, - { - "Time": 69, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 92, - "Parameters": { - "Intensity": 60, - "Frequency": 61 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-15", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 69, + "StartTime": 19, + "Parameters": { + "Intensity": 42, + "Frequency": 90, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 13, + "Intensity": 0.09, + "Frequency": -83 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": -36 + }, + { + "Time": 68, + "Intensity": 0.1, + "Frequency": -58 + }, + { + "Time": 69, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 92, + "Parameters": { + "Intensity": 60, + "Frequency": 61 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_m.json index 8f35ff22476e66f99978606464fc1e1f51837d8a..ba6e756a41325c528da9bacbf2622494ebf88aaa 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/RacingStart_m.json @@ -1,65 +1,65 @@ -{ - "MetaData": { - "Create": "2022-04-15", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 69, - "StartTime": 19, - "Parameters": { - "Intensity": 56, - "Frequency": 90, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -100 - }, - { - "Time": 13, - "Intensity": 0.09, - "Frequency": -83 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": -36 - }, - { - "Time": 68, - "Intensity": 0.1, - "Frequency": -58 - }, - { - "Time": 69, - "Intensity": 0, - "Frequency": -88 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 92, - "Parameters": { - "Intensity": 80, - "Frequency": 61 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-15", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 69, + "StartTime": 19, + "Parameters": { + "Intensity": 56, + "Frequency": 90, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -100 + }, + { + "Time": 13, + "Intensity": 0.09, + "Frequency": -83 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": -36 + }, + { + "Time": 68, + "Intensity": 0.1, + "Frequency": -58 + }, + { + "Time": 69, + "Intensity": 0, + "Frequency": -88 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 92, + "Parameters": { + "Intensity": 80, + "Frequency": 61 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_h.json index 896821a113220df5562d34f32da3a627b7490b94..0e3e289299701665b92d37b7ca70a6fab8630af3 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_h.json @@ -1,1087 +1,1087 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 4, - "Parameters": { - "Intensity": 31, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 39, - "Parameters": { - "Intensity": 42, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 86, - "Parameters": { - "Intensity": 32, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 112, - "Parameters": { - "Intensity": 34, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 156, - "Parameters": { - "Intensity": 40, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 192, - "Parameters": { - "Intensity": 54, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 248, - "Parameters": { - "Intensity": 48, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 304, - "Parameters": { - "Intensity": 31, - "Frequency": 17 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 344, - "Parameters": { - "Intensity": 39, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 368, - "Parameters": { - "Intensity": 35, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 406, - "Parameters": { - "Intensity": 43, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 455, - "Parameters": { - "Intensity": 40, - "Frequency": 17 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 495, - "Parameters": { - "Intensity": 43, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 532, - "Parameters": { - "Intensity": 32, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 565, - "Parameters": { - "Intensity": 34, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 629, - "Parameters": { - "Intensity": 42, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 680, - "Parameters": { - "Intensity": 51, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 723, - "Parameters": { - "Intensity": 37, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 770, - "Parameters": { - "Intensity": 34, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 797, - "Parameters": { - "Intensity": 34, - "Frequency": 21 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 858, - "Parameters": { - "Intensity": 29, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 904, - "Parameters": { - "Intensity": 30, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 965, - "Parameters": { - "Intensity": 32, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 999, - "Parameters": { - "Intensity": 38, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1039, - "Parameters": { - "Intensity": 31, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1078, - "Parameters": { - "Intensity": 48, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1114, - "Parameters": { - "Intensity": 38, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1168, - "Parameters": { - "Intensity": 28, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1205, - "Parameters": { - "Intensity": 46, - "Frequency": 28 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1248, - "Parameters": { - "Intensity": 33, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1315, - "Parameters": { - "Intensity": 37, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1374, - "Parameters": { - "Intensity": 33, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1401, - "Parameters": { - "Intensity": 45, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1439, - "Parameters": { - "Intensity": 30, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1507, - "Parameters": { - "Intensity": 42, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1554, - "Parameters": { - "Intensity": 41, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1581, - "Parameters": { - "Intensity": 35, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1625, - "Parameters": { - "Intensity": 30, - "Frequency": 39 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1664, - "Parameters": { - "Intensity": 33, - "Frequency": 67 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1691, - "Parameters": { - "Intensity": 36, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1739, - "Parameters": { - "Intensity": 31, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1798, - "Parameters": { - "Intensity": 36, - "Frequency": 41 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1838, - "Parameters": { - "Intensity": 29, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1868, - "Parameters": { - "Intensity": 54, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1917, - "Parameters": { - "Intensity": 31, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1959, - "Parameters": { - "Intensity": 35, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2009, - "Parameters": { - "Intensity": 39, - "Frequency": 9 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2068, - "Parameters": { - "Intensity": 35, - "Frequency": 72 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2102, - "Parameters": { - "Intensity": 48, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2151, - "Parameters": { - "Intensity": 34, - "Frequency": 37 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2188, - "Parameters": { - "Intensity": 33, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2229, - "Parameters": { - "Intensity": 36, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2288, - "Parameters": { - "Intensity": 29, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2349, - "Parameters": { - "Intensity": 26, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2389, - "Parameters": { - "Intensity": 31, - "Frequency": 73 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2420, - "Parameters": { - "Intensity": 34, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2462, - "Parameters": { - "Intensity": 49, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2509, - "Parameters": { - "Intensity": 40, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2546, - "Parameters": { - "Intensity": 30, - "Frequency": 22 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2592, - "Parameters": { - "Intensity": 43, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2656, - "Parameters": { - "Intensity": 35, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2718, - "Parameters": { - "Intensity": 29, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2744, - "Parameters": { - "Intensity": 32, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2802, - "Parameters": { - "Intensity": 38, - "Frequency": 37 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2848, - "Parameters": { - "Intensity": 30, - "Frequency": 77 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2881, - "Parameters": { - "Intensity": 51, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2933, - "Parameters": { - "Intensity": 38, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2959, - "Parameters": { - "Intensity": 31, - "Frequency": 32 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3004, - "Parameters": { - "Intensity": 35, - "Frequency": 27 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3051, - "Parameters": { - "Intensity": 38, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3095, - "Parameters": { - "Intensity": 29, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3144, - "Parameters": { - "Intensity": 36, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3182, - "Parameters": { - "Intensity": 33, - "Frequency": 66 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3215, - "Parameters": { - "Intensity": 51, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3275, - "Parameters": { - "Intensity": 37, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3315, - "Parameters": { - "Intensity": 32, - "Frequency": 16 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3363, - "Parameters": { - "Intensity": 28, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3410, - "Parameters": { - "Intensity": 39, - "Frequency": 24 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3451, - "Parameters": { - "Intensity": 32, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3482, - "Parameters": { - "Intensity": 46, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3530, - "Parameters": { - "Intensity": 33, - "Frequency": 62 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3567, - "Parameters": { - "Intensity": 34, - "Frequency": 16 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3614, - "Parameters": { - "Intensity": 52, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3660, - "Parameters": { - "Intensity": 42, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3731, - "Parameters": { - "Intensity": 32, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3770, - "Parameters": { - "Intensity": 36, - "Frequency": 26 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3810, - "Parameters": { - "Intensity": 38, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3851, - "Parameters": { - "Intensity": 36, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3899, - "Parameters": { - "Intensity": 29, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3937, - "Parameters": { - "Intensity": 36, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3965, - "Parameters": { - "Intensity": 49, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4014, - "Parameters": { - "Intensity": 31, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4058, - "Parameters": { - "Intensity": 36, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4090, - "Parameters": { - "Intensity": 32, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4122, - "Parameters": { - "Intensity": 41, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4170, - "Parameters": { - "Intensity": 33, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4213, - "Parameters": { - "Intensity": 30, - "Frequency": 77 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4238, - "Parameters": { - "Intensity": 45, - "Frequency": 26 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4282, - "Parameters": { - "Intensity": 51, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4330, - "Parameters": { - "Intensity": 29, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4375, - "Parameters": { - "Intensity": 40, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4418, - "Parameters": { - "Intensity": 35, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4467, - "Parameters": { - "Intensity": 28, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4495, - "Parameters": { - "Intensity": 36, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4536, - "Parameters": { - "Intensity": 29, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4598, - "Parameters": { - "Intensity": 38, - "Frequency": 22 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4645, - "Parameters": { - "Intensity": 21, - "Frequency": 56 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 4, + "Parameters": { + "Intensity": 31, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 39, + "Parameters": { + "Intensity": 42, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 86, + "Parameters": { + "Intensity": 32, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 112, + "Parameters": { + "Intensity": 34, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 156, + "Parameters": { + "Intensity": 40, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 192, + "Parameters": { + "Intensity": 54, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 248, + "Parameters": { + "Intensity": 48, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 304, + "Parameters": { + "Intensity": 31, + "Frequency": 17 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 344, + "Parameters": { + "Intensity": 39, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 368, + "Parameters": { + "Intensity": 35, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 406, + "Parameters": { + "Intensity": 43, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 455, + "Parameters": { + "Intensity": 40, + "Frequency": 17 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 495, + "Parameters": { + "Intensity": 43, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 532, + "Parameters": { + "Intensity": 32, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 565, + "Parameters": { + "Intensity": 34, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 629, + "Parameters": { + "Intensity": 42, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 680, + "Parameters": { + "Intensity": 51, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 723, + "Parameters": { + "Intensity": 37, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 770, + "Parameters": { + "Intensity": 34, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 797, + "Parameters": { + "Intensity": 34, + "Frequency": 21 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 858, + "Parameters": { + "Intensity": 29, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 904, + "Parameters": { + "Intensity": 30, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 965, + "Parameters": { + "Intensity": 32, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 999, + "Parameters": { + "Intensity": 38, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1039, + "Parameters": { + "Intensity": 31, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1078, + "Parameters": { + "Intensity": 48, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1114, + "Parameters": { + "Intensity": 38, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1168, + "Parameters": { + "Intensity": 28, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1205, + "Parameters": { + "Intensity": 46, + "Frequency": 28 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1248, + "Parameters": { + "Intensity": 33, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1315, + "Parameters": { + "Intensity": 37, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1374, + "Parameters": { + "Intensity": 33, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1401, + "Parameters": { + "Intensity": 45, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1439, + "Parameters": { + "Intensity": 30, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1507, + "Parameters": { + "Intensity": 42, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1554, + "Parameters": { + "Intensity": 41, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1581, + "Parameters": { + "Intensity": 35, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1625, + "Parameters": { + "Intensity": 30, + "Frequency": 39 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1664, + "Parameters": { + "Intensity": 33, + "Frequency": 67 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1691, + "Parameters": { + "Intensity": 36, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1739, + "Parameters": { + "Intensity": 31, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1798, + "Parameters": { + "Intensity": 36, + "Frequency": 41 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1838, + "Parameters": { + "Intensity": 29, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1868, + "Parameters": { + "Intensity": 54, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1917, + "Parameters": { + "Intensity": 31, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1959, + "Parameters": { + "Intensity": 35, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2009, + "Parameters": { + "Intensity": 39, + "Frequency": 9 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2068, + "Parameters": { + "Intensity": 35, + "Frequency": 72 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2102, + "Parameters": { + "Intensity": 48, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2151, + "Parameters": { + "Intensity": 34, + "Frequency": 37 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2188, + "Parameters": { + "Intensity": 33, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2229, + "Parameters": { + "Intensity": 36, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2288, + "Parameters": { + "Intensity": 29, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2349, + "Parameters": { + "Intensity": 26, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2389, + "Parameters": { + "Intensity": 31, + "Frequency": 73 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2420, + "Parameters": { + "Intensity": 34, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2462, + "Parameters": { + "Intensity": 49, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2509, + "Parameters": { + "Intensity": 40, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2546, + "Parameters": { + "Intensity": 30, + "Frequency": 22 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2592, + "Parameters": { + "Intensity": 43, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2656, + "Parameters": { + "Intensity": 35, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2718, + "Parameters": { + "Intensity": 29, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2744, + "Parameters": { + "Intensity": 32, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2802, + "Parameters": { + "Intensity": 38, + "Frequency": 37 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2848, + "Parameters": { + "Intensity": 30, + "Frequency": 77 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2881, + "Parameters": { + "Intensity": 51, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2933, + "Parameters": { + "Intensity": 38, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2959, + "Parameters": { + "Intensity": 31, + "Frequency": 32 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3004, + "Parameters": { + "Intensity": 35, + "Frequency": 27 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3051, + "Parameters": { + "Intensity": 38, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3095, + "Parameters": { + "Intensity": 29, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3144, + "Parameters": { + "Intensity": 36, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3182, + "Parameters": { + "Intensity": 33, + "Frequency": 66 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3215, + "Parameters": { + "Intensity": 51, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3275, + "Parameters": { + "Intensity": 37, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3315, + "Parameters": { + "Intensity": 32, + "Frequency": 16 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3363, + "Parameters": { + "Intensity": 28, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3410, + "Parameters": { + "Intensity": 39, + "Frequency": 24 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3451, + "Parameters": { + "Intensity": 32, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3482, + "Parameters": { + "Intensity": 46, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3530, + "Parameters": { + "Intensity": 33, + "Frequency": 62 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3567, + "Parameters": { + "Intensity": 34, + "Frequency": 16 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3614, + "Parameters": { + "Intensity": 52, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3660, + "Parameters": { + "Intensity": 42, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3731, + "Parameters": { + "Intensity": 32, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3770, + "Parameters": { + "Intensity": 36, + "Frequency": 26 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3810, + "Parameters": { + "Intensity": 38, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3851, + "Parameters": { + "Intensity": 36, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3899, + "Parameters": { + "Intensity": 29, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3937, + "Parameters": { + "Intensity": 36, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3965, + "Parameters": { + "Intensity": 49, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4014, + "Parameters": { + "Intensity": 31, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4058, + "Parameters": { + "Intensity": 36, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4090, + "Parameters": { + "Intensity": 32, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4122, + "Parameters": { + "Intensity": 41, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4170, + "Parameters": { + "Intensity": 33, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4213, + "Parameters": { + "Intensity": 30, + "Frequency": 77 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4238, + "Parameters": { + "Intensity": 45, + "Frequency": 26 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4282, + "Parameters": { + "Intensity": 51, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4330, + "Parameters": { + "Intensity": 29, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4375, + "Parameters": { + "Intensity": 40, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4418, + "Parameters": { + "Intensity": 35, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4467, + "Parameters": { + "Intensity": 28, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4495, + "Parameters": { + "Intensity": 36, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4536, + "Parameters": { + "Intensity": 29, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4598, + "Parameters": { + "Intensity": 38, + "Frequency": 22 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4645, + "Parameters": { + "Intensity": 21, + "Frequency": 56 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_l.json index f0b8fdb77c112bff3e81c9a1da9ef1a5f9ef26ff..c8c4a8c8f7b231f64f036698a4334f2f76d31ab6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_l.json @@ -1,1087 +1,1087 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 4, - "Parameters": { - "Intensity": 18, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 39, - "Parameters": { - "Intensity": 25, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 86, - "Parameters": { - "Intensity": 19, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 112, - "Parameters": { - "Intensity": 20, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 156, - "Parameters": { - "Intensity": 24, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 192, - "Parameters": { - "Intensity": 32, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 248, - "Parameters": { - "Intensity": 28, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 304, - "Parameters": { - "Intensity": 18, - "Frequency": 17 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 344, - "Parameters": { - "Intensity": 23, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 368, - "Parameters": { - "Intensity": 21, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 406, - "Parameters": { - "Intensity": 25, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 455, - "Parameters": { - "Intensity": 24, - "Frequency": 17 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 495, - "Parameters": { - "Intensity": 25, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 532, - "Parameters": { - "Intensity": 19, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 565, - "Parameters": { - "Intensity": 20, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 629, - "Parameters": { - "Intensity": 25, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 680, - "Parameters": { - "Intensity": 30, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 723, - "Parameters": { - "Intensity": 22, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 770, - "Parameters": { - "Intensity": 20, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 797, - "Parameters": { - "Intensity": 20, - "Frequency": 21 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 858, - "Parameters": { - "Intensity": 17, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 904, - "Parameters": { - "Intensity": 18, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 965, - "Parameters": { - "Intensity": 19, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 999, - "Parameters": { - "Intensity": 22, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1039, - "Parameters": { - "Intensity": 18, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1078, - "Parameters": { - "Intensity": 28, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1114, - "Parameters": { - "Intensity": 22, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1168, - "Parameters": { - "Intensity": 16, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1205, - "Parameters": { - "Intensity": 27, - "Frequency": 28 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1248, - "Parameters": { - "Intensity": 19, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1315, - "Parameters": { - "Intensity": 22, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1374, - "Parameters": { - "Intensity": 19, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1401, - "Parameters": { - "Intensity": 27, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1439, - "Parameters": { - "Intensity": 18, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1507, - "Parameters": { - "Intensity": 25, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1554, - "Parameters": { - "Intensity": 24, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1581, - "Parameters": { - "Intensity": 21, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1625, - "Parameters": { - "Intensity": 18, - "Frequency": 39 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1664, - "Parameters": { - "Intensity": 19, - "Frequency": 67 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1691, - "Parameters": { - "Intensity": 21, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1739, - "Parameters": { - "Intensity": 18, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1798, - "Parameters": { - "Intensity": 21, - "Frequency": 41 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1838, - "Parameters": { - "Intensity": 17, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1868, - "Parameters": { - "Intensity": 32, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1917, - "Parameters": { - "Intensity": 18, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1959, - "Parameters": { - "Intensity": 21, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2009, - "Parameters": { - "Intensity": 23, - "Frequency": 9 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2068, - "Parameters": { - "Intensity": 21, - "Frequency": 72 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2102, - "Parameters": { - "Intensity": 28, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2151, - "Parameters": { - "Intensity": 20, - "Frequency": 37 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2188, - "Parameters": { - "Intensity": 19, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2229, - "Parameters": { - "Intensity": 21, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2288, - "Parameters": { - "Intensity": 17, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2349, - "Parameters": { - "Intensity": 15, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2389, - "Parameters": { - "Intensity": 18, - "Frequency": 73 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2420, - "Parameters": { - "Intensity": 20, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2462, - "Parameters": { - "Intensity": 29, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2509, - "Parameters": { - "Intensity": 24, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2546, - "Parameters": { - "Intensity": 18, - "Frequency": 22 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2592, - "Parameters": { - "Intensity": 25, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2656, - "Parameters": { - "Intensity": 21, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2718, - "Parameters": { - "Intensity": 17, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2744, - "Parameters": { - "Intensity": 19, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2802, - "Parameters": { - "Intensity": 22, - "Frequency": 37 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2848, - "Parameters": { - "Intensity": 18, - "Frequency": 77 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2881, - "Parameters": { - "Intensity": 30, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2933, - "Parameters": { - "Intensity": 22, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2959, - "Parameters": { - "Intensity": 18, - "Frequency": 32 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3004, - "Parameters": { - "Intensity": 21, - "Frequency": 27 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3051, - "Parameters": { - "Intensity": 22, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3095, - "Parameters": { - "Intensity": 17, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3144, - "Parameters": { - "Intensity": 21, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3182, - "Parameters": { - "Intensity": 19, - "Frequency": 66 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3215, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3275, - "Parameters": { - "Intensity": 22, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3315, - "Parameters": { - "Intensity": 19, - "Frequency": 16 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3363, - "Parameters": { - "Intensity": 16, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3410, - "Parameters": { - "Intensity": 23, - "Frequency": 24 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3451, - "Parameters": { - "Intensity": 19, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3482, - "Parameters": { - "Intensity": 27, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3530, - "Parameters": { - "Intensity": 19, - "Frequency": 62 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3567, - "Parameters": { - "Intensity": 20, - "Frequency": 16 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3614, - "Parameters": { - "Intensity": 31, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3660, - "Parameters": { - "Intensity": 25, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3731, - "Parameters": { - "Intensity": 19, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3770, - "Parameters": { - "Intensity": 21, - "Frequency": 26 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3810, - "Parameters": { - "Intensity": 22, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3851, - "Parameters": { - "Intensity": 21, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3899, - "Parameters": { - "Intensity": 17, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3937, - "Parameters": { - "Intensity": 21, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3965, - "Parameters": { - "Intensity": 29, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4014, - "Parameters": { - "Intensity": 18, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4058, - "Parameters": { - "Intensity": 21, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4090, - "Parameters": { - "Intensity": 19, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4122, - "Parameters": { - "Intensity": 24, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4170, - "Parameters": { - "Intensity": 19, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4213, - "Parameters": { - "Intensity": 18, - "Frequency": 77 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4238, - "Parameters": { - "Intensity": 27, - "Frequency": 26 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4282, - "Parameters": { - "Intensity": 30, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4330, - "Parameters": { - "Intensity": 17, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4375, - "Parameters": { - "Intensity": 24, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4418, - "Parameters": { - "Intensity": 21, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4467, - "Parameters": { - "Intensity": 16, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4495, - "Parameters": { - "Intensity": 21, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4536, - "Parameters": { - "Intensity": 17, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4598, - "Parameters": { - "Intensity": 22, - "Frequency": 22 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4645, - "Parameters": { - "Intensity": 12, - "Frequency": 56 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 4, + "Parameters": { + "Intensity": 18, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 39, + "Parameters": { + "Intensity": 25, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 86, + "Parameters": { + "Intensity": 19, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 112, + "Parameters": { + "Intensity": 20, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 156, + "Parameters": { + "Intensity": 24, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 192, + "Parameters": { + "Intensity": 32, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 248, + "Parameters": { + "Intensity": 28, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 304, + "Parameters": { + "Intensity": 18, + "Frequency": 17 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 344, + "Parameters": { + "Intensity": 23, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 368, + "Parameters": { + "Intensity": 21, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 406, + "Parameters": { + "Intensity": 25, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 455, + "Parameters": { + "Intensity": 24, + "Frequency": 17 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 495, + "Parameters": { + "Intensity": 25, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 532, + "Parameters": { + "Intensity": 19, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 565, + "Parameters": { + "Intensity": 20, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 629, + "Parameters": { + "Intensity": 25, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 680, + "Parameters": { + "Intensity": 30, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 723, + "Parameters": { + "Intensity": 22, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 770, + "Parameters": { + "Intensity": 20, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 797, + "Parameters": { + "Intensity": 20, + "Frequency": 21 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 858, + "Parameters": { + "Intensity": 17, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 904, + "Parameters": { + "Intensity": 18, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 965, + "Parameters": { + "Intensity": 19, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 999, + "Parameters": { + "Intensity": 22, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1039, + "Parameters": { + "Intensity": 18, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1078, + "Parameters": { + "Intensity": 28, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1114, + "Parameters": { + "Intensity": 22, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1168, + "Parameters": { + "Intensity": 16, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1205, + "Parameters": { + "Intensity": 27, + "Frequency": 28 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1248, + "Parameters": { + "Intensity": 19, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1315, + "Parameters": { + "Intensity": 22, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1374, + "Parameters": { + "Intensity": 19, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1401, + "Parameters": { + "Intensity": 27, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1439, + "Parameters": { + "Intensity": 18, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1507, + "Parameters": { + "Intensity": 25, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1554, + "Parameters": { + "Intensity": 24, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1581, + "Parameters": { + "Intensity": 21, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1625, + "Parameters": { + "Intensity": 18, + "Frequency": 39 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1664, + "Parameters": { + "Intensity": 19, + "Frequency": 67 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1691, + "Parameters": { + "Intensity": 21, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1739, + "Parameters": { + "Intensity": 18, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1798, + "Parameters": { + "Intensity": 21, + "Frequency": 41 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1838, + "Parameters": { + "Intensity": 17, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1868, + "Parameters": { + "Intensity": 32, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1917, + "Parameters": { + "Intensity": 18, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1959, + "Parameters": { + "Intensity": 21, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2009, + "Parameters": { + "Intensity": 23, + "Frequency": 9 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2068, + "Parameters": { + "Intensity": 21, + "Frequency": 72 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2102, + "Parameters": { + "Intensity": 28, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2151, + "Parameters": { + "Intensity": 20, + "Frequency": 37 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2188, + "Parameters": { + "Intensity": 19, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2229, + "Parameters": { + "Intensity": 21, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2288, + "Parameters": { + "Intensity": 17, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2349, + "Parameters": { + "Intensity": 15, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2389, + "Parameters": { + "Intensity": 18, + "Frequency": 73 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2420, + "Parameters": { + "Intensity": 20, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2462, + "Parameters": { + "Intensity": 29, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2509, + "Parameters": { + "Intensity": 24, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2546, + "Parameters": { + "Intensity": 18, + "Frequency": 22 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2592, + "Parameters": { + "Intensity": 25, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2656, + "Parameters": { + "Intensity": 21, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2718, + "Parameters": { + "Intensity": 17, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2744, + "Parameters": { + "Intensity": 19, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2802, + "Parameters": { + "Intensity": 22, + "Frequency": 37 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2848, + "Parameters": { + "Intensity": 18, + "Frequency": 77 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2881, + "Parameters": { + "Intensity": 30, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2933, + "Parameters": { + "Intensity": 22, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2959, + "Parameters": { + "Intensity": 18, + "Frequency": 32 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3004, + "Parameters": { + "Intensity": 21, + "Frequency": 27 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3051, + "Parameters": { + "Intensity": 22, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3095, + "Parameters": { + "Intensity": 17, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3144, + "Parameters": { + "Intensity": 21, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3182, + "Parameters": { + "Intensity": 19, + "Frequency": 66 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3215, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3275, + "Parameters": { + "Intensity": 22, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3315, + "Parameters": { + "Intensity": 19, + "Frequency": 16 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3363, + "Parameters": { + "Intensity": 16, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3410, + "Parameters": { + "Intensity": 23, + "Frequency": 24 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3451, + "Parameters": { + "Intensity": 19, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3482, + "Parameters": { + "Intensity": 27, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3530, + "Parameters": { + "Intensity": 19, + "Frequency": 62 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3567, + "Parameters": { + "Intensity": 20, + "Frequency": 16 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3614, + "Parameters": { + "Intensity": 31, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3660, + "Parameters": { + "Intensity": 25, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3731, + "Parameters": { + "Intensity": 19, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3770, + "Parameters": { + "Intensity": 21, + "Frequency": 26 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3810, + "Parameters": { + "Intensity": 22, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3851, + "Parameters": { + "Intensity": 21, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3899, + "Parameters": { + "Intensity": 17, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3937, + "Parameters": { + "Intensity": 21, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3965, + "Parameters": { + "Intensity": 29, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4014, + "Parameters": { + "Intensity": 18, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4058, + "Parameters": { + "Intensity": 21, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4090, + "Parameters": { + "Intensity": 19, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4122, + "Parameters": { + "Intensity": 24, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4170, + "Parameters": { + "Intensity": 19, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4213, + "Parameters": { + "Intensity": 18, + "Frequency": 77 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4238, + "Parameters": { + "Intensity": 27, + "Frequency": 26 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4282, + "Parameters": { + "Intensity": 30, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4330, + "Parameters": { + "Intensity": 17, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4375, + "Parameters": { + "Intensity": 24, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4418, + "Parameters": { + "Intensity": 21, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4467, + "Parameters": { + "Intensity": 16, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4495, + "Parameters": { + "Intensity": 21, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4536, + "Parameters": { + "Intensity": 17, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4598, + "Parameters": { + "Intensity": 22, + "Frequency": 22 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4645, + "Parameters": { + "Intensity": 12, + "Frequency": 56 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_m.json index b1089886cf25230cc0e772125c460dca8b9deb12..1ee461a669f458e5b528f11e4cd8f06a8241ed40 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rain_m.json @@ -1,1087 +1,1087 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 4, - "Parameters": { - "Intensity": 24, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 39, - "Parameters": { - "Intensity": 33, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 86, - "Parameters": { - "Intensity": 25, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 112, - "Parameters": { - "Intensity": 27, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 156, - "Parameters": { - "Intensity": 32, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 192, - "Parameters": { - "Intensity": 43, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 248, - "Parameters": { - "Intensity": 38, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 304, - "Parameters": { - "Intensity": 24, - "Frequency": 17 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 344, - "Parameters": { - "Intensity": 31, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 368, - "Parameters": { - "Intensity": 28, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 406, - "Parameters": { - "Intensity": 34, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 455, - "Parameters": { - "Intensity": 32, - "Frequency": 17 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 495, - "Parameters": { - "Intensity": 34, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 532, - "Parameters": { - "Intensity": 25, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 565, - "Parameters": { - "Intensity": 27, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 629, - "Parameters": { - "Intensity": 33, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 680, - "Parameters": { - "Intensity": 40, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 723, - "Parameters": { - "Intensity": 29, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 770, - "Parameters": { - "Intensity": 27, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 797, - "Parameters": { - "Intensity": 27, - "Frequency": 21 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 858, - "Parameters": { - "Intensity": 23, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 904, - "Parameters": { - "Intensity": 24, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 965, - "Parameters": { - "Intensity": 25, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 999, - "Parameters": { - "Intensity": 30, - "Frequency": 14 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1039, - "Parameters": { - "Intensity": 24, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1078, - "Parameters": { - "Intensity": 38, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1114, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1168, - "Parameters": { - "Intensity": 22, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1205, - "Parameters": { - "Intensity": 36, - "Frequency": 28 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1248, - "Parameters": { - "Intensity": 26, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1315, - "Parameters": { - "Intensity": 29, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1374, - "Parameters": { - "Intensity": 26, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1401, - "Parameters": { - "Intensity": 36, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1439, - "Parameters": { - "Intensity": 24, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1507, - "Parameters": { - "Intensity": 33, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1554, - "Parameters": { - "Intensity": 32, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1581, - "Parameters": { - "Intensity": 28, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1625, - "Parameters": { - "Intensity": 24, - "Frequency": 39 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1664, - "Parameters": { - "Intensity": 26, - "Frequency": 67 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1691, - "Parameters": { - "Intensity": 28, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1739, - "Parameters": { - "Intensity": 24, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1798, - "Parameters": { - "Intensity": 28, - "Frequency": 41 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1838, - "Parameters": { - "Intensity": 23, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1868, - "Parameters": { - "Intensity": 43, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1917, - "Parameters": { - "Intensity": 24, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1959, - "Parameters": { - "Intensity": 28, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2009, - "Parameters": { - "Intensity": 31, - "Frequency": 9 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2068, - "Parameters": { - "Intensity": 28, - "Frequency": 72 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2102, - "Parameters": { - "Intensity": 38, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2151, - "Parameters": { - "Intensity": 27, - "Frequency": 37 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2188, - "Parameters": { - "Intensity": 26, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2229, - "Parameters": { - "Intensity": 28, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2288, - "Parameters": { - "Intensity": 23, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2349, - "Parameters": { - "Intensity": 20, - "Frequency": 31 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2389, - "Parameters": { - "Intensity": 24, - "Frequency": 73 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2420, - "Parameters": { - "Intensity": 27, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2462, - "Parameters": { - "Intensity": 39, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2509, - "Parameters": { - "Intensity": 32, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2546, - "Parameters": { - "Intensity": 24, - "Frequency": 22 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2592, - "Parameters": { - "Intensity": 34, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2656, - "Parameters": { - "Intensity": 28, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2718, - "Parameters": { - "Intensity": 23, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2744, - "Parameters": { - "Intensity": 25, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2802, - "Parameters": { - "Intensity": 30, - "Frequency": 37 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2848, - "Parameters": { - "Intensity": 24, - "Frequency": 77 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2881, - "Parameters": { - "Intensity": 40, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2933, - "Parameters": { - "Intensity": 30, - "Frequency": 55 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2959, - "Parameters": { - "Intensity": 24, - "Frequency": 32 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3004, - "Parameters": { - "Intensity": 28, - "Frequency": 27 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3051, - "Parameters": { - "Intensity": 30, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3095, - "Parameters": { - "Intensity": 23, - "Frequency": 11 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3144, - "Parameters": { - "Intensity": 28, - "Frequency": 35 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3182, - "Parameters": { - "Intensity": 26, - "Frequency": 66 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3215, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3275, - "Parameters": { - "Intensity": 29, - "Frequency": 36 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3315, - "Parameters": { - "Intensity": 25, - "Frequency": 16 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3363, - "Parameters": { - "Intensity": 22, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3410, - "Parameters": { - "Intensity": 31, - "Frequency": 24 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3451, - "Parameters": { - "Intensity": 25, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3482, - "Parameters": { - "Intensity": 36, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3530, - "Parameters": { - "Intensity": 26, - "Frequency": 62 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3567, - "Parameters": { - "Intensity": 27, - "Frequency": 16 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3614, - "Parameters": { - "Intensity": 41, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3660, - "Parameters": { - "Intensity": 33, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3731, - "Parameters": { - "Intensity": 25, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3770, - "Parameters": { - "Intensity": 28, - "Frequency": 26 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3810, - "Parameters": { - "Intensity": 30, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3851, - "Parameters": { - "Intensity": 28, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3899, - "Parameters": { - "Intensity": 23, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3937, - "Parameters": { - "Intensity": 28, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3965, - "Parameters": { - "Intensity": 39, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4014, - "Parameters": { - "Intensity": 24, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4058, - "Parameters": { - "Intensity": 28, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4090, - "Parameters": { - "Intensity": 25, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4122, - "Parameters": { - "Intensity": 32, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4170, - "Parameters": { - "Intensity": 26, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4213, - "Parameters": { - "Intensity": 24, - "Frequency": 77 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4238, - "Parameters": { - "Intensity": 36, - "Frequency": 26 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4282, - "Parameters": { - "Intensity": 40, - "Frequency": 40 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4330, - "Parameters": { - "Intensity": 23, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4375, - "Parameters": { - "Intensity": 32, - "Frequency": 25 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4418, - "Parameters": { - "Intensity": 28, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4467, - "Parameters": { - "Intensity": 22, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4495, - "Parameters": { - "Intensity": 28, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4536, - "Parameters": { - "Intensity": 23, - "Frequency": 10 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4598, - "Parameters": { - "Intensity": 30, - "Frequency": 22 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4645, - "Parameters": { - "Intensity": 16, - "Frequency": 56 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 4, + "Parameters": { + "Intensity": 24, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 39, + "Parameters": { + "Intensity": 33, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 86, + "Parameters": { + "Intensity": 25, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 112, + "Parameters": { + "Intensity": 27, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 156, + "Parameters": { + "Intensity": 32, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 192, + "Parameters": { + "Intensity": 43, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 248, + "Parameters": { + "Intensity": 38, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 304, + "Parameters": { + "Intensity": 24, + "Frequency": 17 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 344, + "Parameters": { + "Intensity": 31, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 368, + "Parameters": { + "Intensity": 28, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 406, + "Parameters": { + "Intensity": 34, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 455, + "Parameters": { + "Intensity": 32, + "Frequency": 17 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 495, + "Parameters": { + "Intensity": 34, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 532, + "Parameters": { + "Intensity": 25, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 565, + "Parameters": { + "Intensity": 27, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 629, + "Parameters": { + "Intensity": 33, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 680, + "Parameters": { + "Intensity": 40, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 723, + "Parameters": { + "Intensity": 29, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 770, + "Parameters": { + "Intensity": 27, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 797, + "Parameters": { + "Intensity": 27, + "Frequency": 21 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 858, + "Parameters": { + "Intensity": 23, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 904, + "Parameters": { + "Intensity": 24, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 965, + "Parameters": { + "Intensity": 25, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 999, + "Parameters": { + "Intensity": 30, + "Frequency": 14 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1039, + "Parameters": { + "Intensity": 24, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1078, + "Parameters": { + "Intensity": 38, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1114, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1168, + "Parameters": { + "Intensity": 22, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1205, + "Parameters": { + "Intensity": 36, + "Frequency": 28 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1248, + "Parameters": { + "Intensity": 26, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1315, + "Parameters": { + "Intensity": 29, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1374, + "Parameters": { + "Intensity": 26, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1401, + "Parameters": { + "Intensity": 36, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1439, + "Parameters": { + "Intensity": 24, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1507, + "Parameters": { + "Intensity": 33, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1554, + "Parameters": { + "Intensity": 32, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1581, + "Parameters": { + "Intensity": 28, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1625, + "Parameters": { + "Intensity": 24, + "Frequency": 39 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1664, + "Parameters": { + "Intensity": 26, + "Frequency": 67 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1691, + "Parameters": { + "Intensity": 28, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1739, + "Parameters": { + "Intensity": 24, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1798, + "Parameters": { + "Intensity": 28, + "Frequency": 41 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1838, + "Parameters": { + "Intensity": 23, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1868, + "Parameters": { + "Intensity": 43, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1917, + "Parameters": { + "Intensity": 24, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1959, + "Parameters": { + "Intensity": 28, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2009, + "Parameters": { + "Intensity": 31, + "Frequency": 9 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2068, + "Parameters": { + "Intensity": 28, + "Frequency": 72 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2102, + "Parameters": { + "Intensity": 38, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2151, + "Parameters": { + "Intensity": 27, + "Frequency": 37 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2188, + "Parameters": { + "Intensity": 26, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2229, + "Parameters": { + "Intensity": 28, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2288, + "Parameters": { + "Intensity": 23, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2349, + "Parameters": { + "Intensity": 20, + "Frequency": 31 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2389, + "Parameters": { + "Intensity": 24, + "Frequency": 73 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2420, + "Parameters": { + "Intensity": 27, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2462, + "Parameters": { + "Intensity": 39, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2509, + "Parameters": { + "Intensity": 32, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2546, + "Parameters": { + "Intensity": 24, + "Frequency": 22 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2592, + "Parameters": { + "Intensity": 34, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2656, + "Parameters": { + "Intensity": 28, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2718, + "Parameters": { + "Intensity": 23, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2744, + "Parameters": { + "Intensity": 25, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2802, + "Parameters": { + "Intensity": 30, + "Frequency": 37 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2848, + "Parameters": { + "Intensity": 24, + "Frequency": 77 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2881, + "Parameters": { + "Intensity": 40, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2933, + "Parameters": { + "Intensity": 30, + "Frequency": 55 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2959, + "Parameters": { + "Intensity": 24, + "Frequency": 32 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3004, + "Parameters": { + "Intensity": 28, + "Frequency": 27 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3051, + "Parameters": { + "Intensity": 30, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3095, + "Parameters": { + "Intensity": 23, + "Frequency": 11 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3144, + "Parameters": { + "Intensity": 28, + "Frequency": 35 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3182, + "Parameters": { + "Intensity": 26, + "Frequency": 66 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3215, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3275, + "Parameters": { + "Intensity": 29, + "Frequency": 36 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3315, + "Parameters": { + "Intensity": 25, + "Frequency": 16 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3363, + "Parameters": { + "Intensity": 22, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3410, + "Parameters": { + "Intensity": 31, + "Frequency": 24 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3451, + "Parameters": { + "Intensity": 25, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3482, + "Parameters": { + "Intensity": 36, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3530, + "Parameters": { + "Intensity": 26, + "Frequency": 62 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3567, + "Parameters": { + "Intensity": 27, + "Frequency": 16 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3614, + "Parameters": { + "Intensity": 41, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3660, + "Parameters": { + "Intensity": 33, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3731, + "Parameters": { + "Intensity": 25, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3770, + "Parameters": { + "Intensity": 28, + "Frequency": 26 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3810, + "Parameters": { + "Intensity": 30, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3851, + "Parameters": { + "Intensity": 28, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3899, + "Parameters": { + "Intensity": 23, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3937, + "Parameters": { + "Intensity": 28, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3965, + "Parameters": { + "Intensity": 39, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4014, + "Parameters": { + "Intensity": 24, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4058, + "Parameters": { + "Intensity": 28, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4090, + "Parameters": { + "Intensity": 25, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4122, + "Parameters": { + "Intensity": 32, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4170, + "Parameters": { + "Intensity": 26, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4213, + "Parameters": { + "Intensity": 24, + "Frequency": 77 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4238, + "Parameters": { + "Intensity": 36, + "Frequency": 26 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4282, + "Parameters": { + "Intensity": 40, + "Frequency": 40 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4330, + "Parameters": { + "Intensity": 23, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4375, + "Parameters": { + "Intensity": 32, + "Frequency": 25 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4418, + "Parameters": { + "Intensity": 28, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4467, + "Parameters": { + "Intensity": 22, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4495, + "Parameters": { + "Intensity": 28, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4536, + "Parameters": { + "Intensity": 23, + "Frequency": 10 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4598, + "Parameters": { + "Intensity": 30, + "Frequency": 22 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4645, + "Parameters": { + "Intensity": 16, + "Frequency": 56 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_h.json index 6b5ee2b70a522e9ceec7786c6921b97cd063ee1a..b1994b8bf824c629c23dd9415c76346ff347d729 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_h.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2020-08-10", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 35, - "Parameters": { - "Intensity": 100, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2020-08-10", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 35, + "Parameters": { + "Intensity": 100, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_l.json index 6facf8791d8d1e758fd51f5c0cac66b4eb51958f..f72f07b7c4368cc692d43390a216aa5db938fd5e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_l.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2020-08-10", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 35, - "Parameters": { - "Intensity": 60, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2020-08-10", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 35, + "Parameters": { + "Intensity": 60, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_m.json index 2a392fb4eb33233beb5730d641bd79fbce42a0bb..b0759ad0e2e48c205976a3b40aded5791708d0e6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Rifle_m.json @@ -1,37 +1,37 @@ -{ - "MetaData": { - "Create": "2020-08-10", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 35, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2020-08-10", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 35, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_h.json index bb1c88da23e8f21d696a90f12df300cf253e525d..89608bc0acf7bd072b124cb9f6dc18291a9c7d1d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_h.json @@ -1,620 +1,620 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 380, - "StartTime": 100, - "Parameters": { - "Intensity": 34, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 0.48, - "Frequency": 0 - }, - { - "Time": 148, - "Intensity": 0.35, - "Frequency": 0 - }, - { - "Time": 183, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 275, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 320, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 379, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 380, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 385, - "StartTime": 103, - "Parameters": { - "Intensity": 81, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 383, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 385, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 156, - "StartTime": 491, - "Parameters": { - "Intensity": 75, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -25 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": -30 - }, - { - "Time": 46, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 156, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 983, - "Parameters": { - "Intensity": 96, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 69, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 129, - "Intensity": 0.86, - "Frequency": 0 - }, - { - "Time": 163, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 197, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 241, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 278, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 995, - "Parameters": { - "Intensity": 100, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 163, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 197, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1042, - "StartTime": 1518, - "Parameters": { - "Intensity": 55, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 142, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 224, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 297, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 374, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 444, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 510, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 578, - "Intensity": 0.45, - "Frequency": 0 - }, - { - "Time": 709, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 756, - "Intensity": 0.79, - "Frequency": 0 - }, - { - "Time": 815, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 857, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 895, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 984, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 1042, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1042, - "StartTime": 1530, - "Parameters": { - "Intensity": 85, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 653, - "Intensity": 0.41, - "Frequency": 0 - }, - { - "Time": 821, - "Intensity": 0.85, - "Frequency": 0 - }, - { - "Time": 1042, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 469, - "StartTime": 2573, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 78, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 251, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 307, - "Intensity": 0.96, - "Frequency": 6 - }, - { - "Time": 407, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 468, - "Intensity": 0.36, - "Frequency": 5 - }, - { - "Time": 469, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 460, - "StartTime": 2590, - "Parameters": { - "Intensity": 50, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 57, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0.2, - "Frequency": 17 - }, - { - "Time": 166, - "Intensity": 0.51, - "Frequency": 30 - }, - { - "Time": 214, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 280, - "Intensity": 1, - "Frequency": 6 - }, - { - "Time": 327, - "Intensity": 0.69, - "Frequency": 0 - }, - { - "Time": 336, - "Intensity": 0.92, - "Frequency": 10 - }, - { - "Time": 385, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 403, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 459, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 460, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 929, - "StartTime": 3042, - "Parameters": { - "Intensity": 70, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 180, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 290, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 428, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 929, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 900, - "StartTime": 3050, - "Parameters": { - "Intensity": 46, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 98, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 144, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 199, - "Intensity": 0.41, - "Frequency": 0 - }, - { - "Time": 261, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.35, - "Frequency": 0 - }, - { - "Time": 390, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 463, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 492, - "Intensity": 0.48, - "Frequency": 0 - }, - { - "Time": 575, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 602, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 682, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 706, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 900, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 380, + "StartTime": 100, + "Parameters": { + "Intensity": 34, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 0.48, + "Frequency": 0 + }, + { + "Time": 148, + "Intensity": 0.35, + "Frequency": 0 + }, + { + "Time": 183, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 275, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 320, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 379, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 380, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 385, + "StartTime": 103, + "Parameters": { + "Intensity": 81, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 383, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 385, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 156, + "StartTime": 491, + "Parameters": { + "Intensity": 75, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -25 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": -30 + }, + { + "Time": 46, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 156, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 983, + "Parameters": { + "Intensity": 96, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 69, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 129, + "Intensity": 0.86, + "Frequency": 0 + }, + { + "Time": 163, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 197, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 241, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 278, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 995, + "Parameters": { + "Intensity": 100, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 163, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 197, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1042, + "StartTime": 1518, + "Parameters": { + "Intensity": 55, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 142, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 224, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 297, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 374, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 444, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 510, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 578, + "Intensity": 0.45, + "Frequency": 0 + }, + { + "Time": 709, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 756, + "Intensity": 0.79, + "Frequency": 0 + }, + { + "Time": 815, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 857, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 895, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 984, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 1042, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1042, + "StartTime": 1530, + "Parameters": { + "Intensity": 85, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 653, + "Intensity": 0.41, + "Frequency": 0 + }, + { + "Time": 821, + "Intensity": 0.85, + "Frequency": 0 + }, + { + "Time": 1042, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 469, + "StartTime": 2573, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 78, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 251, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 307, + "Intensity": 0.96, + "Frequency": 6 + }, + { + "Time": 407, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 468, + "Intensity": 0.36, + "Frequency": 5 + }, + { + "Time": 469, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 460, + "StartTime": 2590, + "Parameters": { + "Intensity": 50, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 57, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0.2, + "Frequency": 17 + }, + { + "Time": 166, + "Intensity": 0.51, + "Frequency": 30 + }, + { + "Time": 214, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 280, + "Intensity": 1, + "Frequency": 6 + }, + { + "Time": 327, + "Intensity": 0.69, + "Frequency": 0 + }, + { + "Time": 336, + "Intensity": 0.92, + "Frequency": 10 + }, + { + "Time": 385, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 403, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 459, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 460, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 929, + "StartTime": 3042, + "Parameters": { + "Intensity": 70, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 180, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 290, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 428, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 929, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 900, + "StartTime": 3050, + "Parameters": { + "Intensity": 46, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 98, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 144, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 199, + "Intensity": 0.41, + "Frequency": 0 + }, + { + "Time": 261, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.35, + "Frequency": 0 + }, + { + "Time": 390, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 463, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 492, + "Intensity": 0.48, + "Frequency": 0 + }, + { + "Time": 575, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 602, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 682, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 706, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 900, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_l.json index a23ee84959d30008bffd3c7cf44e912bcc66facd..f2b3c06abda2ab73e31ea06d1a71bcdb723a00a4 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_l.json @@ -1,620 +1,620 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 380, - "StartTime": 100, - "Parameters": { - "Intensity": 20, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 0.48, - "Frequency": 0 - }, - { - "Time": 148, - "Intensity": 0.35, - "Frequency": 0 - }, - { - "Time": 183, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 275, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 320, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 379, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 380, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 385, - "StartTime": 103, - "Parameters": { - "Intensity": 48, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 383, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 385, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 156, - "StartTime": 491, - "Parameters": { - "Intensity": 45, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -25 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": -30 - }, - { - "Time": 46, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 156, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 983, - "Parameters": { - "Intensity": 57, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 69, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 129, - "Intensity": 0.86, - "Frequency": 0 - }, - { - "Time": 163, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 197, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 241, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 278, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 995, - "Parameters": { - "Intensity": 60, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 163, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 197, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1042, - "StartTime": 1518, - "Parameters": { - "Intensity": 33, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 142, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 224, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 297, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 374, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 444, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 510, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 578, - "Intensity": 0.45, - "Frequency": 0 - }, - { - "Time": 709, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 756, - "Intensity": 0.79, - "Frequency": 0 - }, - { - "Time": 815, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 857, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 895, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 984, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 1042, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1042, - "StartTime": 1530, - "Parameters": { - "Intensity": 51, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 653, - "Intensity": 0.41, - "Frequency": 0 - }, - { - "Time": 821, - "Intensity": 0.85, - "Frequency": 0 - }, - { - "Time": 1042, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 469, - "StartTime": 2573, - "Parameters": { - "Intensity": 48, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 78, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 251, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 307, - "Intensity": 0.96, - "Frequency": 6 - }, - { - "Time": 407, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 468, - "Intensity": 0.36, - "Frequency": 5 - }, - { - "Time": 469, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 460, - "StartTime": 2590, - "Parameters": { - "Intensity": 30, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 57, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0.2, - "Frequency": 17 - }, - { - "Time": 166, - "Intensity": 0.51, - "Frequency": 30 - }, - { - "Time": 214, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 280, - "Intensity": 1, - "Frequency": 6 - }, - { - "Time": 327, - "Intensity": 0.69, - "Frequency": 0 - }, - { - "Time": 336, - "Intensity": 0.92, - "Frequency": 10 - }, - { - "Time": 385, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 403, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 459, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 460, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 929, - "StartTime": 3042, - "Parameters": { - "Intensity": 42, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 180, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 290, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 428, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 929, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 900, - "StartTime": 3050, - "Parameters": { - "Intensity": 27, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 98, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 144, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 199, - "Intensity": 0.41, - "Frequency": 0 - }, - { - "Time": 261, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.35, - "Frequency": 0 - }, - { - "Time": 390, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 463, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 492, - "Intensity": 0.48, - "Frequency": 0 - }, - { - "Time": 575, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 602, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 682, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 706, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 900, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 380, + "StartTime": 100, + "Parameters": { + "Intensity": 20, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 0.48, + "Frequency": 0 + }, + { + "Time": 148, + "Intensity": 0.35, + "Frequency": 0 + }, + { + "Time": 183, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 275, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 320, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 379, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 380, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 385, + "StartTime": 103, + "Parameters": { + "Intensity": 48, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 383, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 385, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 156, + "StartTime": 491, + "Parameters": { + "Intensity": 45, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -25 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": -30 + }, + { + "Time": 46, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 156, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 983, + "Parameters": { + "Intensity": 57, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 69, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 129, + "Intensity": 0.86, + "Frequency": 0 + }, + { + "Time": 163, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 197, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 241, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 278, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 995, + "Parameters": { + "Intensity": 60, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 163, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 197, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1042, + "StartTime": 1518, + "Parameters": { + "Intensity": 33, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 142, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 224, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 297, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 374, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 444, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 510, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 578, + "Intensity": 0.45, + "Frequency": 0 + }, + { + "Time": 709, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 756, + "Intensity": 0.79, + "Frequency": 0 + }, + { + "Time": 815, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 857, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 895, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 984, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 1042, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1042, + "StartTime": 1530, + "Parameters": { + "Intensity": 51, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 653, + "Intensity": 0.41, + "Frequency": 0 + }, + { + "Time": 821, + "Intensity": 0.85, + "Frequency": 0 + }, + { + "Time": 1042, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 469, + "StartTime": 2573, + "Parameters": { + "Intensity": 48, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 78, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 251, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 307, + "Intensity": 0.96, + "Frequency": 6 + }, + { + "Time": 407, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 468, + "Intensity": 0.36, + "Frequency": 5 + }, + { + "Time": 469, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 460, + "StartTime": 2590, + "Parameters": { + "Intensity": 30, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 57, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0.2, + "Frequency": 17 + }, + { + "Time": 166, + "Intensity": 0.51, + "Frequency": 30 + }, + { + "Time": 214, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 280, + "Intensity": 1, + "Frequency": 6 + }, + { + "Time": 327, + "Intensity": 0.69, + "Frequency": 0 + }, + { + "Time": 336, + "Intensity": 0.92, + "Frequency": 10 + }, + { + "Time": 385, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 403, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 459, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 460, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 929, + "StartTime": 3042, + "Parameters": { + "Intensity": 42, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 180, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 290, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 428, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 929, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 900, + "StartTime": 3050, + "Parameters": { + "Intensity": 27, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 98, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 144, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 199, + "Intensity": 0.41, + "Frequency": 0 + }, + { + "Time": 261, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.35, + "Frequency": 0 + }, + { + "Time": 390, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 463, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 492, + "Intensity": 0.48, + "Frequency": 0 + }, + { + "Time": 575, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 602, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 682, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 706, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 900, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_m.json index f12fa64eb49bee62381b4c36ce9cd26f46e85b3f..3e5fe1fdc0713105de49489abcfb99b0a557ca57 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skating_m.json @@ -1,620 +1,620 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 380, - "StartTime": 100, - "Parameters": { - "Intensity": 27, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 0.48, - "Frequency": 0 - }, - { - "Time": 148, - "Intensity": 0.35, - "Frequency": 0 - }, - { - "Time": 183, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 275, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 320, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 379, - "Intensity": 0.34, - "Frequency": 0 - }, - { - "Time": 380, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 385, - "StartTime": 103, - "Parameters": { - "Intensity": 64, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 383, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 385, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 156, - "StartTime": 491, - "Parameters": { - "Intensity": 60, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -25 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": -30 - }, - { - "Time": 46, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 156, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 983, - "Parameters": { - "Intensity": 76, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 69, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 129, - "Intensity": 0.86, - "Frequency": 0 - }, - { - "Time": 163, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 197, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 241, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 278, - "Intensity": 0.07, - "Frequency": 0 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 340, - "StartTime": 995, - "Parameters": { - "Intensity": 80, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 30 - }, - { - "Time": 163, - "Intensity": 0.93, - "Frequency": 0 - }, - { - "Time": 197, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 340, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1042, - "StartTime": 1518, - "Parameters": { - "Intensity": 44, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 142, - "Intensity": 0.22, - "Frequency": 0 - }, - { - "Time": 224, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 297, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 374, - "Intensity": 0.25, - "Frequency": 0 - }, - { - "Time": 444, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 510, - "Intensity": 0.28, - "Frequency": 0 - }, - { - "Time": 578, - "Intensity": 0.45, - "Frequency": 0 - }, - { - "Time": 709, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 756, - "Intensity": 0.79, - "Frequency": 0 - }, - { - "Time": 815, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 857, - "Intensity": 0.77, - "Frequency": 0 - }, - { - "Time": 895, - "Intensity": 0.21, - "Frequency": 0 - }, - { - "Time": 984, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 1042, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1042, - "StartTime": 1530, - "Parameters": { - "Intensity": 68, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 653, - "Intensity": 0.41, - "Frequency": 0 - }, - { - "Time": 821, - "Intensity": 0.85, - "Frequency": 0 - }, - { - "Time": 1042, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 469, - "StartTime": 2573, - "Parameters": { - "Intensity": 64, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 78, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 251, - "Intensity": 0.47, - "Frequency": 0 - }, - { - "Time": 307, - "Intensity": 0.96, - "Frequency": 6 - }, - { - "Time": 407, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 468, - "Intensity": 0.36, - "Frequency": 5 - }, - { - "Time": 469, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 460, - "StartTime": 2590, - "Parameters": { - "Intensity": 40, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 57, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0.2, - "Frequency": 17 - }, - { - "Time": 166, - "Intensity": 0.51, - "Frequency": 30 - }, - { - "Time": 214, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 280, - "Intensity": 1, - "Frequency": 6 - }, - { - "Time": 327, - "Intensity": 0.69, - "Frequency": 0 - }, - { - "Time": 336, - "Intensity": 0.92, - "Frequency": 10 - }, - { - "Time": 385, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 403, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 459, - "Intensity": 0.3, - "Frequency": 0 - }, - { - "Time": 460, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 929, - "StartTime": 3042, - "Parameters": { - "Intensity": 56, - "Frequency": 80, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.42, - "Frequency": 0 - }, - { - "Time": 180, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 290, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 428, - "Intensity": 0.39, - "Frequency": 0 - }, - { - "Time": 929, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 900, - "StartTime": 3050, - "Parameters": { - "Intensity": 36, - "Frequency": 100, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 98, - "Intensity": 0.33, - "Frequency": 0 - }, - { - "Time": 144, - "Intensity": 0.61, - "Frequency": 0 - }, - { - "Time": 199, - "Intensity": 0.41, - "Frequency": 0 - }, - { - "Time": 261, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.35, - "Frequency": 0 - }, - { - "Time": 390, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 463, - "Intensity": 0.29, - "Frequency": 0 - }, - { - "Time": 492, - "Intensity": 0.48, - "Frequency": 0 - }, - { - "Time": 575, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 602, - "Intensity": 0.32, - "Frequency": 0 - }, - { - "Time": 682, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 706, - "Intensity": 0.23, - "Frequency": 0 - }, - { - "Time": 900, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 380, + "StartTime": 100, + "Parameters": { + "Intensity": 27, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 0.48, + "Frequency": 0 + }, + { + "Time": 148, + "Intensity": 0.35, + "Frequency": 0 + }, + { + "Time": 183, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 275, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 320, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 379, + "Intensity": 0.34, + "Frequency": 0 + }, + { + "Time": 380, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 385, + "StartTime": 103, + "Parameters": { + "Intensity": 64, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 383, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 385, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 156, + "StartTime": 491, + "Parameters": { + "Intensity": 60, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -25 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": -30 + }, + { + "Time": 46, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 156, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 983, + "Parameters": { + "Intensity": 76, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 69, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 129, + "Intensity": 0.86, + "Frequency": 0 + }, + { + "Time": 163, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 197, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 241, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 278, + "Intensity": 0.07, + "Frequency": 0 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 340, + "StartTime": 995, + "Parameters": { + "Intensity": 80, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 30 + }, + { + "Time": 163, + "Intensity": 0.93, + "Frequency": 0 + }, + { + "Time": 197, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 340, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1042, + "StartTime": 1518, + "Parameters": { + "Intensity": 44, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 142, + "Intensity": 0.22, + "Frequency": 0 + }, + { + "Time": 224, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 297, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 374, + "Intensity": 0.25, + "Frequency": 0 + }, + { + "Time": 444, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 510, + "Intensity": 0.28, + "Frequency": 0 + }, + { + "Time": 578, + "Intensity": 0.45, + "Frequency": 0 + }, + { + "Time": 709, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 756, + "Intensity": 0.79, + "Frequency": 0 + }, + { + "Time": 815, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 857, + "Intensity": 0.77, + "Frequency": 0 + }, + { + "Time": 895, + "Intensity": 0.21, + "Frequency": 0 + }, + { + "Time": 984, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 1042, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1042, + "StartTime": 1530, + "Parameters": { + "Intensity": 68, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 653, + "Intensity": 0.41, + "Frequency": 0 + }, + { + "Time": 821, + "Intensity": 0.85, + "Frequency": 0 + }, + { + "Time": 1042, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 469, + "StartTime": 2573, + "Parameters": { + "Intensity": 64, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 78, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 251, + "Intensity": 0.47, + "Frequency": 0 + }, + { + "Time": 307, + "Intensity": 0.96, + "Frequency": 6 + }, + { + "Time": 407, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 468, + "Intensity": 0.36, + "Frequency": 5 + }, + { + "Time": 469, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 460, + "StartTime": 2590, + "Parameters": { + "Intensity": 40, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 57, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0.2, + "Frequency": 17 + }, + { + "Time": 166, + "Intensity": 0.51, + "Frequency": 30 + }, + { + "Time": 214, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 280, + "Intensity": 1, + "Frequency": 6 + }, + { + "Time": 327, + "Intensity": 0.69, + "Frequency": 0 + }, + { + "Time": 336, + "Intensity": 0.92, + "Frequency": 10 + }, + { + "Time": 385, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 403, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 459, + "Intensity": 0.3, + "Frequency": 0 + }, + { + "Time": 460, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 929, + "StartTime": 3042, + "Parameters": { + "Intensity": 56, + "Frequency": 80, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.42, + "Frequency": 0 + }, + { + "Time": 180, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 290, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 428, + "Intensity": 0.39, + "Frequency": 0 + }, + { + "Time": 929, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 900, + "StartTime": 3050, + "Parameters": { + "Intensity": 36, + "Frequency": 100, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 98, + "Intensity": 0.33, + "Frequency": 0 + }, + { + "Time": 144, + "Intensity": 0.61, + "Frequency": 0 + }, + { + "Time": 199, + "Intensity": 0.41, + "Frequency": 0 + }, + { + "Time": 261, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.35, + "Frequency": 0 + }, + { + "Time": 390, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 463, + "Intensity": 0.29, + "Frequency": 0 + }, + { + "Time": 492, + "Intensity": 0.48, + "Frequency": 0 + }, + { + "Time": 575, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 602, + "Intensity": 0.32, + "Frequency": 0 + }, + { + "Time": 682, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 706, + "Intensity": 0.23, + "Frequency": 0 + }, + { + "Time": 900, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_h.json index 6e7d2c3546dc72e58418831f0e85df4d2849aa0d..f00634ac3e43a33823aaddd667ec73388029346f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_h.json @@ -1,490 +1,490 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 1848, - "StartTime": 128, - "Parameters": { - "Intensity": 42, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 364, - "Intensity": 0.81, - "Frequency": 0 - }, - { - "Time": 558, - "Intensity": 0.89, - "Frequency": 5 - }, - { - "Time": 682, - "Intensity": 0.98, - "Frequency": 10 - }, - { - "Time": 806, - "Intensity": 0.79, - "Frequency": 4 - }, - { - "Time": 902, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 1009, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 1190, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 1312, - "Intensity": 0.85, - "Frequency": 4 - }, - { - "Time": 1425, - "Intensity": 0.95, - "Frequency": 10 - }, - { - "Time": 1724, - "Intensity": 0.65, - "Frequency": 2 - }, - { - "Time": 1841, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 1848, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1848, - "StartTime": 135, - "Parameters": { - "Intensity": 29, - "Frequency": 63, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.52, - "Frequency": 0 - }, - { - "Time": 248, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 333, - "Intensity": 0.76, - "Frequency": 0 - }, - { - "Time": 455, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 558, - "Intensity": 0.89, - "Frequency": 5 - }, - { - "Time": 682, - "Intensity": 0.98, - "Frequency": 10 - }, - { - "Time": 848, - "Intensity": 0.73, - "Frequency": 4 - }, - { - "Time": 972, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 1037, - "Intensity": 0.66, - "Frequency": -2 - }, - { - "Time": 1146, - "Intensity": 0.5, - "Frequency": 0 - }, - { - "Time": 1242, - "Intensity": 0.84, - "Frequency": 4 - }, - { - "Time": 1425, - "Intensity": 0.95, - "Frequency": 10 - }, - { - "Time": 1724, - "Intensity": 0.65, - "Frequency": 2 - }, - { - "Time": 1841, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 1848, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 2005, - "Parameters": { - "Intensity": 100, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 104, - "Intensity": 0.97, - "Frequency": 4 - }, - { - "Time": 139, - "Intensity": 1, - "Frequency": 9 - }, - { - "Time": 171, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 241, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 259, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 260, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2220, - "Parameters": { - "Intensity": 54, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2296, - "Parameters": { - "Intensity": 31, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 2378, - "Parameters": { - "Intensity": 69, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 104, - "Intensity": 0.97, - "Frequency": 4 - }, - { - "Time": 139, - "Intensity": 1, - "Frequency": 9 - }, - { - "Time": 171, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 241, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 259, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 260, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2586, - "Parameters": { - "Intensity": 40, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 634, - "StartTime": 2638, - "Parameters": { - "Intensity": 29, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 106, - "Intensity": 0.68, - "Frequency": 5 - }, - { - "Time": 208, - "Intensity": 0.73, - "Frequency": 10 - }, - { - "Time": 277, - "Intensity": 0.67, - "Frequency": 4 - }, - { - "Time": 309, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 408, - "Intensity": 0.52, - "Frequency": 0 - }, - { - "Time": 464, - "Intensity": 0.51, - "Frequency": 4 - }, - { - "Time": 509, - "Intensity": 0.35, - "Frequency": 10 - }, - { - "Time": 569, - "Intensity": 0.26, - "Frequency": 2 - }, - { - "Time": 611, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 634, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 634, - "StartTime": 2640, - "Parameters": { - "Intensity": 19, - "Frequency": 63, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0.75, - "Frequency": 5 - }, - { - "Time": 182, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 232, - "Intensity": 0.69, - "Frequency": 4 - }, - { - "Time": 309, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 408, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 455, - "Intensity": 0.35, - "Frequency": 4 - }, - { - "Time": 515, - "Intensity": 0.24, - "Frequency": 10 - }, - { - "Time": 566, - "Intensity": 0.38, - "Frequency": 2 - }, - { - "Time": 611, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 634, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 1848, + "StartTime": 128, + "Parameters": { + "Intensity": 42, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 364, + "Intensity": 0.81, + "Frequency": 0 + }, + { + "Time": 558, + "Intensity": 0.89, + "Frequency": 5 + }, + { + "Time": 682, + "Intensity": 0.98, + "Frequency": 10 + }, + { + "Time": 806, + "Intensity": 0.79, + "Frequency": 4 + }, + { + "Time": 902, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 1009, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 1190, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 1312, + "Intensity": 0.85, + "Frequency": 4 + }, + { + "Time": 1425, + "Intensity": 0.95, + "Frequency": 10 + }, + { + "Time": 1724, + "Intensity": 0.65, + "Frequency": 2 + }, + { + "Time": 1841, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 1848, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1848, + "StartTime": 135, + "Parameters": { + "Intensity": 29, + "Frequency": 63, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.52, + "Frequency": 0 + }, + { + "Time": 248, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 333, + "Intensity": 0.76, + "Frequency": 0 + }, + { + "Time": 455, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 558, + "Intensity": 0.89, + "Frequency": 5 + }, + { + "Time": 682, + "Intensity": 0.98, + "Frequency": 10 + }, + { + "Time": 848, + "Intensity": 0.73, + "Frequency": 4 + }, + { + "Time": 972, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 1037, + "Intensity": 0.66, + "Frequency": -2 + }, + { + "Time": 1146, + "Intensity": 0.5, + "Frequency": 0 + }, + { + "Time": 1242, + "Intensity": 0.84, + "Frequency": 4 + }, + { + "Time": 1425, + "Intensity": 0.95, + "Frequency": 10 + }, + { + "Time": 1724, + "Intensity": 0.65, + "Frequency": 2 + }, + { + "Time": 1841, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 1848, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 2005, + "Parameters": { + "Intensity": 100, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 104, + "Intensity": 0.97, + "Frequency": 4 + }, + { + "Time": 139, + "Intensity": 1, + "Frequency": 9 + }, + { + "Time": 171, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 241, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 259, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 260, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2220, + "Parameters": { + "Intensity": 54, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2296, + "Parameters": { + "Intensity": 31, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 2378, + "Parameters": { + "Intensity": 69, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 104, + "Intensity": 0.97, + "Frequency": 4 + }, + { + "Time": 139, + "Intensity": 1, + "Frequency": 9 + }, + { + "Time": 171, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 241, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 259, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 260, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2586, + "Parameters": { + "Intensity": 40, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 634, + "StartTime": 2638, + "Parameters": { + "Intensity": 29, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 106, + "Intensity": 0.68, + "Frequency": 5 + }, + { + "Time": 208, + "Intensity": 0.73, + "Frequency": 10 + }, + { + "Time": 277, + "Intensity": 0.67, + "Frequency": 4 + }, + { + "Time": 309, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 408, + "Intensity": 0.52, + "Frequency": 0 + }, + { + "Time": 464, + "Intensity": 0.51, + "Frequency": 4 + }, + { + "Time": 509, + "Intensity": 0.35, + "Frequency": 10 + }, + { + "Time": 569, + "Intensity": 0.26, + "Frequency": 2 + }, + { + "Time": 611, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 634, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 634, + "StartTime": 2640, + "Parameters": { + "Intensity": 19, + "Frequency": 63, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0.75, + "Frequency": 5 + }, + { + "Time": 182, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 232, + "Intensity": 0.69, + "Frequency": 4 + }, + { + "Time": 309, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 408, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 455, + "Intensity": 0.35, + "Frequency": 4 + }, + { + "Time": 515, + "Intensity": 0.24, + "Frequency": 10 + }, + { + "Time": 566, + "Intensity": 0.38, + "Frequency": 2 + }, + { + "Time": 611, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 634, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_l.json index 05bedae3609d6431515f55d76123c55e177ff4bc..12fb05af9324e9aad24c3cbc6bdfe1e45d4a6725 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_l.json @@ -1,490 +1,490 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 1848, - "StartTime": 128, - "Parameters": { - "Intensity": 25, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 364, - "Intensity": 0.81, - "Frequency": 0 - }, - { - "Time": 558, - "Intensity": 0.89, - "Frequency": 5 - }, - { - "Time": 682, - "Intensity": 0.98, - "Frequency": 10 - }, - { - "Time": 806, - "Intensity": 0.79, - "Frequency": 4 - }, - { - "Time": 902, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 1009, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 1190, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 1312, - "Intensity": 0.85, - "Frequency": 4 - }, - { - "Time": 1425, - "Intensity": 0.95, - "Frequency": 10 - }, - { - "Time": 1724, - "Intensity": 0.65, - "Frequency": 2 - }, - { - "Time": 1841, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 1848, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1848, - "StartTime": 135, - "Parameters": { - "Intensity": 17, - "Frequency": 63, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.52, - "Frequency": 0 - }, - { - "Time": 248, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 333, - "Intensity": 0.76, - "Frequency": 0 - }, - { - "Time": 455, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 558, - "Intensity": 0.89, - "Frequency": 5 - }, - { - "Time": 682, - "Intensity": 0.98, - "Frequency": 10 - }, - { - "Time": 848, - "Intensity": 0.73, - "Frequency": 4 - }, - { - "Time": 972, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 1037, - "Intensity": 0.66, - "Frequency": -2 - }, - { - "Time": 1146, - "Intensity": 0.5, - "Frequency": 0 - }, - { - "Time": 1242, - "Intensity": 0.84, - "Frequency": 4 - }, - { - "Time": 1425, - "Intensity": 0.95, - "Frequency": 10 - }, - { - "Time": 1724, - "Intensity": 0.65, - "Frequency": 2 - }, - { - "Time": 1841, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 1848, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 2005, - "Parameters": { - "Intensity": 60, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 104, - "Intensity": 0.97, - "Frequency": 4 - }, - { - "Time": 139, - "Intensity": 1, - "Frequency": 9 - }, - { - "Time": 171, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 241, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 259, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 260, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2220, - "Parameters": { - "Intensity": 32, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2296, - "Parameters": { - "Intensity": 18, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 2378, - "Parameters": { - "Intensity": 41, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 104, - "Intensity": 0.97, - "Frequency": 4 - }, - { - "Time": 139, - "Intensity": 1, - "Frequency": 9 - }, - { - "Time": 171, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 241, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 259, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 260, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2586, - "Parameters": { - "Intensity": 24, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 634, - "StartTime": 2638, - "Parameters": { - "Intensity": 17, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 106, - "Intensity": 0.68, - "Frequency": 5 - }, - { - "Time": 208, - "Intensity": 0.73, - "Frequency": 10 - }, - { - "Time": 277, - "Intensity": 0.67, - "Frequency": 4 - }, - { - "Time": 309, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 408, - "Intensity": 0.52, - "Frequency": 0 - }, - { - "Time": 464, - "Intensity": 0.51, - "Frequency": 4 - }, - { - "Time": 509, - "Intensity": 0.35, - "Frequency": 10 - }, - { - "Time": 569, - "Intensity": 0.26, - "Frequency": 2 - }, - { - "Time": 611, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 634, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 634, - "StartTime": 2640, - "Parameters": { - "Intensity": 11, - "Frequency": 63, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0.75, - "Frequency": 5 - }, - { - "Time": 182, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 232, - "Intensity": 0.69, - "Frequency": 4 - }, - { - "Time": 309, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 408, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 455, - "Intensity": 0.35, - "Frequency": 4 - }, - { - "Time": 515, - "Intensity": 0.24, - "Frequency": 10 - }, - { - "Time": 566, - "Intensity": 0.38, - "Frequency": 2 - }, - { - "Time": 611, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 634, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 1848, + "StartTime": 128, + "Parameters": { + "Intensity": 25, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 364, + "Intensity": 0.81, + "Frequency": 0 + }, + { + "Time": 558, + "Intensity": 0.89, + "Frequency": 5 + }, + { + "Time": 682, + "Intensity": 0.98, + "Frequency": 10 + }, + { + "Time": 806, + "Intensity": 0.79, + "Frequency": 4 + }, + { + "Time": 902, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 1009, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 1190, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 1312, + "Intensity": 0.85, + "Frequency": 4 + }, + { + "Time": 1425, + "Intensity": 0.95, + "Frequency": 10 + }, + { + "Time": 1724, + "Intensity": 0.65, + "Frequency": 2 + }, + { + "Time": 1841, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 1848, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1848, + "StartTime": 135, + "Parameters": { + "Intensity": 17, + "Frequency": 63, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.52, + "Frequency": 0 + }, + { + "Time": 248, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 333, + "Intensity": 0.76, + "Frequency": 0 + }, + { + "Time": 455, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 558, + "Intensity": 0.89, + "Frequency": 5 + }, + { + "Time": 682, + "Intensity": 0.98, + "Frequency": 10 + }, + { + "Time": 848, + "Intensity": 0.73, + "Frequency": 4 + }, + { + "Time": 972, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 1037, + "Intensity": 0.66, + "Frequency": -2 + }, + { + "Time": 1146, + "Intensity": 0.5, + "Frequency": 0 + }, + { + "Time": 1242, + "Intensity": 0.84, + "Frequency": 4 + }, + { + "Time": 1425, + "Intensity": 0.95, + "Frequency": 10 + }, + { + "Time": 1724, + "Intensity": 0.65, + "Frequency": 2 + }, + { + "Time": 1841, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 1848, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 2005, + "Parameters": { + "Intensity": 60, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 104, + "Intensity": 0.97, + "Frequency": 4 + }, + { + "Time": 139, + "Intensity": 1, + "Frequency": 9 + }, + { + "Time": 171, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 241, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 259, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 260, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2220, + "Parameters": { + "Intensity": 32, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2296, + "Parameters": { + "Intensity": 18, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 2378, + "Parameters": { + "Intensity": 41, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 104, + "Intensity": 0.97, + "Frequency": 4 + }, + { + "Time": 139, + "Intensity": 1, + "Frequency": 9 + }, + { + "Time": 171, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 241, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 259, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 260, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2586, + "Parameters": { + "Intensity": 24, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 634, + "StartTime": 2638, + "Parameters": { + "Intensity": 17, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 106, + "Intensity": 0.68, + "Frequency": 5 + }, + { + "Time": 208, + "Intensity": 0.73, + "Frequency": 10 + }, + { + "Time": 277, + "Intensity": 0.67, + "Frequency": 4 + }, + { + "Time": 309, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 408, + "Intensity": 0.52, + "Frequency": 0 + }, + { + "Time": 464, + "Intensity": 0.51, + "Frequency": 4 + }, + { + "Time": 509, + "Intensity": 0.35, + "Frequency": 10 + }, + { + "Time": 569, + "Intensity": 0.26, + "Frequency": 2 + }, + { + "Time": 611, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 634, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 634, + "StartTime": 2640, + "Parameters": { + "Intensity": 11, + "Frequency": 63, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0.75, + "Frequency": 5 + }, + { + "Time": 182, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 232, + "Intensity": 0.69, + "Frequency": 4 + }, + { + "Time": 309, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 408, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 455, + "Intensity": 0.35, + "Frequency": 4 + }, + { + "Time": 515, + "Intensity": 0.24, + "Frequency": 10 + }, + { + "Time": 566, + "Intensity": 0.38, + "Frequency": 2 + }, + { + "Time": 611, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 634, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_m.json index a2f062bbb8ef233d89b0594b3800352607fc54fc..54a2b3a171b2a3bbbbf831a48d0eda89982e103c 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Skiing_m.json @@ -1,490 +1,490 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 1848, - "StartTime": 128, - "Parameters": { - "Intensity": 33, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 364, - "Intensity": 0.81, - "Frequency": 0 - }, - { - "Time": 558, - "Intensity": 0.89, - "Frequency": 5 - }, - { - "Time": 682, - "Intensity": 0.98, - "Frequency": 10 - }, - { - "Time": 806, - "Intensity": 0.79, - "Frequency": 4 - }, - { - "Time": 902, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 1009, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 1190, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 1312, - "Intensity": 0.85, - "Frequency": 4 - }, - { - "Time": 1425, - "Intensity": 0.95, - "Frequency": 10 - }, - { - "Time": 1724, - "Intensity": 0.65, - "Frequency": 2 - }, - { - "Time": 1841, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 1848, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1848, - "StartTime": 135, - "Parameters": { - "Intensity": 23, - "Frequency": 63, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 126, - "Intensity": 0.52, - "Frequency": 0 - }, - { - "Time": 248, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 333, - "Intensity": 0.76, - "Frequency": 0 - }, - { - "Time": 455, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 558, - "Intensity": 0.89, - "Frequency": 5 - }, - { - "Time": 682, - "Intensity": 0.98, - "Frequency": 10 - }, - { - "Time": 848, - "Intensity": 0.73, - "Frequency": 4 - }, - { - "Time": 972, - "Intensity": 0.43, - "Frequency": 0 - }, - { - "Time": 1037, - "Intensity": 0.66, - "Frequency": -2 - }, - { - "Time": 1146, - "Intensity": 0.5, - "Frequency": 0 - }, - { - "Time": 1242, - "Intensity": 0.84, - "Frequency": 4 - }, - { - "Time": 1425, - "Intensity": 0.95, - "Frequency": 10 - }, - { - "Time": 1724, - "Intensity": 0.65, - "Frequency": 2 - }, - { - "Time": 1841, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 1848, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 2005, - "Parameters": { - "Intensity": 80, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 104, - "Intensity": 0.97, - "Frequency": 4 - }, - { - "Time": 139, - "Intensity": 1, - "Frequency": 9 - }, - { - "Time": 171, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 241, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 259, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 260, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2220, - "Parameters": { - "Intensity": 43, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2296, - "Parameters": { - "Intensity": 24, - "Frequency": 15 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 260, - "StartTime": 2378, - "Parameters": { - "Intensity": 55, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.98, - "Frequency": 0 - }, - { - "Time": 61, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 104, - "Intensity": 0.97, - "Frequency": 4 - }, - { - "Time": 139, - "Intensity": 1, - "Frequency": 9 - }, - { - "Time": 171, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 241, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 259, - "Intensity": 0.26, - "Frequency": 0 - }, - { - "Time": 260, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2586, - "Parameters": { - "Intensity": 32, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 634, - "StartTime": 2638, - "Parameters": { - "Intensity": 23, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 106, - "Intensity": 0.68, - "Frequency": 5 - }, - { - "Time": 208, - "Intensity": 0.73, - "Frequency": 10 - }, - { - "Time": 277, - "Intensity": 0.67, - "Frequency": 4 - }, - { - "Time": 309, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 408, - "Intensity": 0.52, - "Frequency": 0 - }, - { - "Time": 464, - "Intensity": 0.51, - "Frequency": 4 - }, - { - "Time": 509, - "Intensity": 0.35, - "Frequency": 10 - }, - { - "Time": 569, - "Intensity": 0.26, - "Frequency": 2 - }, - { - "Time": 611, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 634, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 634, - "StartTime": 2640, - "Parameters": { - "Intensity": 15, - "Frequency": 63, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 110, - "Intensity": 0.75, - "Frequency": 5 - }, - { - "Time": 182, - "Intensity": 0.45, - "Frequency": 10 - }, - { - "Time": 232, - "Intensity": 0.69, - "Frequency": 4 - }, - { - "Time": 309, - "Intensity": 0.51, - "Frequency": 0 - }, - { - "Time": 346, - "Intensity": 0.44, - "Frequency": -2 - }, - { - "Time": 408, - "Intensity": 0.62, - "Frequency": 0 - }, - { - "Time": 455, - "Intensity": 0.35, - "Frequency": 4 - }, - { - "Time": 515, - "Intensity": 0.24, - "Frequency": 10 - }, - { - "Time": 566, - "Intensity": 0.38, - "Frequency": 2 - }, - { - "Time": 611, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 634, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 1848, + "StartTime": 128, + "Parameters": { + "Intensity": 33, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 364, + "Intensity": 0.81, + "Frequency": 0 + }, + { + "Time": 558, + "Intensity": 0.89, + "Frequency": 5 + }, + { + "Time": 682, + "Intensity": 0.98, + "Frequency": 10 + }, + { + "Time": 806, + "Intensity": 0.79, + "Frequency": 4 + }, + { + "Time": 902, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 1009, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 1190, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 1312, + "Intensity": 0.85, + "Frequency": 4 + }, + { + "Time": 1425, + "Intensity": 0.95, + "Frequency": 10 + }, + { + "Time": 1724, + "Intensity": 0.65, + "Frequency": 2 + }, + { + "Time": 1841, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 1848, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1848, + "StartTime": 135, + "Parameters": { + "Intensity": 23, + "Frequency": 63, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 126, + "Intensity": 0.52, + "Frequency": 0 + }, + { + "Time": 248, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 333, + "Intensity": 0.76, + "Frequency": 0 + }, + { + "Time": 455, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 558, + "Intensity": 0.89, + "Frequency": 5 + }, + { + "Time": 682, + "Intensity": 0.98, + "Frequency": 10 + }, + { + "Time": 848, + "Intensity": 0.73, + "Frequency": 4 + }, + { + "Time": 972, + "Intensity": 0.43, + "Frequency": 0 + }, + { + "Time": 1037, + "Intensity": 0.66, + "Frequency": -2 + }, + { + "Time": 1146, + "Intensity": 0.5, + "Frequency": 0 + }, + { + "Time": 1242, + "Intensity": 0.84, + "Frequency": 4 + }, + { + "Time": 1425, + "Intensity": 0.95, + "Frequency": 10 + }, + { + "Time": 1724, + "Intensity": 0.65, + "Frequency": 2 + }, + { + "Time": 1841, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 1848, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 2005, + "Parameters": { + "Intensity": 80, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 104, + "Intensity": 0.97, + "Frequency": 4 + }, + { + "Time": 139, + "Intensity": 1, + "Frequency": 9 + }, + { + "Time": 171, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 241, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 259, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 260, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2220, + "Parameters": { + "Intensity": 43, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2296, + "Parameters": { + "Intensity": 24, + "Frequency": 15 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 260, + "StartTime": 2378, + "Parameters": { + "Intensity": 55, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.98, + "Frequency": 0 + }, + { + "Time": 61, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 104, + "Intensity": 0.97, + "Frequency": 4 + }, + { + "Time": 139, + "Intensity": 1, + "Frequency": 9 + }, + { + "Time": 171, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 241, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 259, + "Intensity": 0.26, + "Frequency": 0 + }, + { + "Time": 260, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2586, + "Parameters": { + "Intensity": 32, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 634, + "StartTime": 2638, + "Parameters": { + "Intensity": 23, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 106, + "Intensity": 0.68, + "Frequency": 5 + }, + { + "Time": 208, + "Intensity": 0.73, + "Frequency": 10 + }, + { + "Time": 277, + "Intensity": 0.67, + "Frequency": 4 + }, + { + "Time": 309, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 408, + "Intensity": 0.52, + "Frequency": 0 + }, + { + "Time": 464, + "Intensity": 0.51, + "Frequency": 4 + }, + { + "Time": 509, + "Intensity": 0.35, + "Frequency": 10 + }, + { + "Time": 569, + "Intensity": 0.26, + "Frequency": 2 + }, + { + "Time": 611, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 634, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 634, + "StartTime": 2640, + "Parameters": { + "Intensity": 15, + "Frequency": 63, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 110, + "Intensity": 0.75, + "Frequency": 5 + }, + { + "Time": 182, + "Intensity": 0.45, + "Frequency": 10 + }, + { + "Time": 232, + "Intensity": 0.69, + "Frequency": 4 + }, + { + "Time": 309, + "Intensity": 0.51, + "Frequency": 0 + }, + { + "Time": 346, + "Intensity": 0.44, + "Frequency": -2 + }, + { + "Time": 408, + "Intensity": 0.62, + "Frequency": 0 + }, + { + "Time": 455, + "Intensity": 0.35, + "Frequency": 4 + }, + { + "Time": 515, + "Intensity": 0.24, + "Frequency": 10 + }, + { + "Time": 566, + "Intensity": 0.38, + "Frequency": 2 + }, + { + "Time": 611, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 634, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_LeftRight.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_LeftRight.json index 4273bc3e484e1a2adbdaab9aa4979bf9e6cae3b0..a74eac3c47392e9a1ee2dd2fed9cc1ee15804bfa 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_LeftRight.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_LeftRight.json @@ -1,45 +1,45 @@ -{ - "Channels" : - [ - { - "Parameters" : - { - "Index" : 1 - }, - "Pattern" : - [ - { - "Event" : - { - "Parameters" : - { - "Frequency" : 100, - "Intensity" : 100 - }, - "StartTime" : 500, - "Type" : "transient" - } - }, - { - "Event" : - { - "Parameters" : - { - "Frequency" : 100, - "Intensity" : 100 - }, - "StartTime" : 2000, - "Type" : "transient" - } - } - ] - } - ], - "MetaData" : - { - "ChannelNumber" : 1, - "Create" : "2023-03-17", - "Discription" : "slide left right", - "Version" : 1.0 - } -} +{ + "Channels" : + [ + { + "Parameters" : + { + "Index" : 1 + }, + "Pattern" : + [ + { + "Event" : + { + "Parameters" : + { + "Frequency" : 100, + "Intensity" : 100 + }, + "StartTime" : 500, + "Type" : "transient" + } + }, + { + "Event" : + { + "Parameters" : + { + "Frequency" : 100, + "Intensity" : 100 + }, + "StartTime" : 2000, + "Type" : "transient" + } + } + ] + } + ], + "MetaData" : + { + "ChannelNumber" : 1, + "Create" : "2023-03-17", + "Discription" : "slide left right", + "Version" : 1.0 + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_Up.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_Up.json index debdcf8af136414ebbc3de31b0490fd67708a664..ab425201ce5e8d6ec4f091473d07dd9aa43e902d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_Up.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Slide_Up.json @@ -1,33 +1,33 @@ -{ - "Channels" : - [ - { - "Parameters" : - { - "Index" : 1 - }, - "Pattern" : - [ - { - "Event" : - { - "Parameters" : - { - "Frequency" : 100, - "Intensity" : 100 - }, - "StartTime" : 1000, - "Type" : "transient" - } - } - ] - } - ], - "MetaData" : - { - "ChannelNumber" : 1, - "Create" : "2023-03-17", - "Discription" : "slide up", - "Version" : 1.0 - } -} +{ + "Channels" : + [ + { + "Parameters" : + { + "Index" : 1 + }, + "Pattern" : + [ + { + "Event" : + { + "Parameters" : + { + "Frequency" : 100, + "Intensity" : 100 + }, + "StartTime" : 1000, + "Type" : "transient" + } + } + ] + } + ], + "MetaData" : + { + "ChannelNumber" : 1, + "Create" : "2023-03-17", + "Discription" : "slide up", + "Version" : 1.0 + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_h.json index 22bfffba9c9ffaea64c9f8d06298fb8f285cb5dc..332c105ea055fb197633539ba798a97a072eebf8 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_h.json @@ -1,377 +1,377 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 433, - "StartTime": 785, - "Parameters": { - "Intensity": 80, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 184, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 190, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 237, - "Intensity": 1, - "Frequency": -10 - }, - { - "Time": 249, - "Intensity": 0.53, - "Frequency": 5 - }, - { - "Time": 433, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1138, - "Parameters": { - "Intensity": 50, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1268, - "Parameters": { - "Intensity": 38, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1343, - "Parameters": { - "Intensity": 36, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1483, - "Parameters": { - "Intensity": 27, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1632, - "Parameters": { - "Intensity": 33, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1390, - "StartTime": 2103, - "Parameters": { - "Intensity": 80, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 591, - "Intensity": 0.38, - "Frequency": -5 - }, - { - "Time": 602, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 717, - "Intensity": 0.94, - "Frequency": 5 - }, - { - "Time": 848, - "Intensity": 0.52, - "Frequency": -10 - }, - { - "Time": 1315, - "Intensity": 0.31, - "Frequency": 5 - }, - { - "Time": 1390, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2200, - "Parameters": { - "Intensity": 37, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2410, - "Parameters": { - "Intensity": 46, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2503, - "Parameters": { - "Intensity": 31, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2548, - "Parameters": { - "Intensity": 50, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3135, - "Parameters": { - "Intensity": 48, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3350, - "Parameters": { - "Intensity": 46, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3490, - "Parameters": { - "Intensity": 30, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3558, - "Parameters": { - "Intensity": 32, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3830, - "Parameters": { - "Intensity": 50, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 3915, - "Parameters": { - "Intensity": 65, - "Frequency": 10, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 143, - "Intensity": 0.82, - "Frequency": 5 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 115, - "StartTime": 4770, - "Parameters": { - "Intensity": 50, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 80, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 115, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 95, - "StartTime": 4910, - "Parameters": { - "Intensity": 65, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 59, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5033, - "Parameters": { - "Intensity": 28, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5080, - "Parameters": { - "Intensity": 33, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5278, - "Parameters": { - "Intensity": 27, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 433, + "StartTime": 785, + "Parameters": { + "Intensity": 80, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 184, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 190, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 237, + "Intensity": 1, + "Frequency": -10 + }, + { + "Time": 249, + "Intensity": 0.53, + "Frequency": 5 + }, + { + "Time": 433, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1138, + "Parameters": { + "Intensity": 50, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1268, + "Parameters": { + "Intensity": 38, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1343, + "Parameters": { + "Intensity": 36, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1483, + "Parameters": { + "Intensity": 27, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1632, + "Parameters": { + "Intensity": 33, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1390, + "StartTime": 2103, + "Parameters": { + "Intensity": 80, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 591, + "Intensity": 0.38, + "Frequency": -5 + }, + { + "Time": 602, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 717, + "Intensity": 0.94, + "Frequency": 5 + }, + { + "Time": 848, + "Intensity": 0.52, + "Frequency": -10 + }, + { + "Time": 1315, + "Intensity": 0.31, + "Frequency": 5 + }, + { + "Time": 1390, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2200, + "Parameters": { + "Intensity": 37, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2410, + "Parameters": { + "Intensity": 46, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2503, + "Parameters": { + "Intensity": 31, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2548, + "Parameters": { + "Intensity": 50, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3135, + "Parameters": { + "Intensity": 48, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3350, + "Parameters": { + "Intensity": 46, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3490, + "Parameters": { + "Intensity": 30, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3558, + "Parameters": { + "Intensity": 32, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3830, + "Parameters": { + "Intensity": 50, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 3915, + "Parameters": { + "Intensity": 65, + "Frequency": 10, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 143, + "Intensity": 0.82, + "Frequency": 5 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 115, + "StartTime": 4770, + "Parameters": { + "Intensity": 50, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 80, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 115, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 95, + "StartTime": 4910, + "Parameters": { + "Intensity": 65, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 59, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5033, + "Parameters": { + "Intensity": 28, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5080, + "Parameters": { + "Intensity": 33, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5278, + "Parameters": { + "Intensity": 27, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_l.json index d9cc8cab0a8b04c383ead76f1c98abdc701a57cd..77cfbb2c7a06ea3e83946e39576802b3e864cf87 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_l.json @@ -1,377 +1,377 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 433, - "StartTime": 785, - "Parameters": { - "Intensity": 48, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 184, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 190, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 237, - "Intensity": 1, - "Frequency": -10 - }, - { - "Time": 249, - "Intensity": 0.53, - "Frequency": 5 - }, - { - "Time": 433, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1138, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1268, - "Parameters": { - "Intensity": 22, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1343, - "Parameters": { - "Intensity": 21, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1483, - "Parameters": { - "Intensity": 16, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1632, - "Parameters": { - "Intensity": 19, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1390, - "StartTime": 2103, - "Parameters": { - "Intensity": 48, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 591, - "Intensity": 0.38, - "Frequency": -5 - }, - { - "Time": 602, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 717, - "Intensity": 0.94, - "Frequency": 5 - }, - { - "Time": 848, - "Intensity": 0.52, - "Frequency": -10 - }, - { - "Time": 1315, - "Intensity": 0.31, - "Frequency": 5 - }, - { - "Time": 1390, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2200, - "Parameters": { - "Intensity": 22, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2410, - "Parameters": { - "Intensity": 27, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2503, - "Parameters": { - "Intensity": 18, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2548, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3135, - "Parameters": { - "Intensity": 28, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3350, - "Parameters": { - "Intensity": 27, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3490, - "Parameters": { - "Intensity": 18, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3558, - "Parameters": { - "Intensity": 19, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3830, - "Parameters": { - "Intensity": 30, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 3915, - "Parameters": { - "Intensity": 39, - "Frequency": 10, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 143, - "Intensity": 0.82, - "Frequency": 5 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 115, - "StartTime": 4770, - "Parameters": { - "Intensity": 30, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 80, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 115, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 95, - "StartTime": 4910, - "Parameters": { - "Intensity": 39, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 59, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5033, - "Parameters": { - "Intensity": 16, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5080, - "Parameters": { - "Intensity": 19, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5278, - "Parameters": { - "Intensity": 16, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 433, + "StartTime": 785, + "Parameters": { + "Intensity": 48, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 184, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 190, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 237, + "Intensity": 1, + "Frequency": -10 + }, + { + "Time": 249, + "Intensity": 0.53, + "Frequency": 5 + }, + { + "Time": 433, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1138, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1268, + "Parameters": { + "Intensity": 22, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1343, + "Parameters": { + "Intensity": 21, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1483, + "Parameters": { + "Intensity": 16, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1632, + "Parameters": { + "Intensity": 19, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1390, + "StartTime": 2103, + "Parameters": { + "Intensity": 48, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 591, + "Intensity": 0.38, + "Frequency": -5 + }, + { + "Time": 602, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 717, + "Intensity": 0.94, + "Frequency": 5 + }, + { + "Time": 848, + "Intensity": 0.52, + "Frequency": -10 + }, + { + "Time": 1315, + "Intensity": 0.31, + "Frequency": 5 + }, + { + "Time": 1390, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2200, + "Parameters": { + "Intensity": 22, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2410, + "Parameters": { + "Intensity": 27, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2503, + "Parameters": { + "Intensity": 18, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2548, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3135, + "Parameters": { + "Intensity": 28, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3350, + "Parameters": { + "Intensity": 27, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3490, + "Parameters": { + "Intensity": 18, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3558, + "Parameters": { + "Intensity": 19, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3830, + "Parameters": { + "Intensity": 30, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 3915, + "Parameters": { + "Intensity": 39, + "Frequency": 10, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 143, + "Intensity": 0.82, + "Frequency": 5 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 115, + "StartTime": 4770, + "Parameters": { + "Intensity": 30, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 80, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 115, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 95, + "StartTime": 4910, + "Parameters": { + "Intensity": 39, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 59, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5033, + "Parameters": { + "Intensity": 16, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5080, + "Parameters": { + "Intensity": 19, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5278, + "Parameters": { + "Intensity": 16, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_m.json index be29158828421e35136256a499d93f736a7b4233..2c2b349422ec8c1fd3c2941925c8ddeba23e899e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Snowdrift_m.json @@ -1,377 +1,377 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 433, - "StartTime": 785, - "Parameters": { - "Intensity": 64, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 184, - "Intensity": 0.54, - "Frequency": 0 - }, - { - "Time": 190, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 237, - "Intensity": 1, - "Frequency": -10 - }, - { - "Time": 249, - "Intensity": 0.53, - "Frequency": 5 - }, - { - "Time": 433, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1138, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1268, - "Parameters": { - "Intensity": 30, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1343, - "Parameters": { - "Intensity": 28, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1483, - "Parameters": { - "Intensity": 21, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1632, - "Parameters": { - "Intensity": 26, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1390, - "StartTime": 2103, - "Parameters": { - "Intensity": 64, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 591, - "Intensity": 0.38, - "Frequency": -5 - }, - { - "Time": 602, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 717, - "Intensity": 0.94, - "Frequency": 5 - }, - { - "Time": 848, - "Intensity": 0.52, - "Frequency": -10 - }, - { - "Time": 1315, - "Intensity": 0.31, - "Frequency": 5 - }, - { - "Time": 1390, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2200, - "Parameters": { - "Intensity": 29, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2410, - "Parameters": { - "Intensity": 36, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2503, - "Parameters": { - "Intensity": 24, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2548, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3135, - "Parameters": { - "Intensity": 38, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3350, - "Parameters": { - "Intensity": 36, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3490, - "Parameters": { - "Intensity": 24, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3558, - "Parameters": { - "Intensity": 25, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3830, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 220, - "StartTime": 3915, - "Parameters": { - "Intensity": 52, - "Frequency": 10, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 17, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 143, - "Intensity": 0.82, - "Frequency": 5 - }, - { - "Time": 220, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 115, - "StartTime": 4770, - "Parameters": { - "Intensity": 40, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 80, - "Intensity": 1, - "Frequency": 10 - }, - { - "Time": 115, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 95, - "StartTime": 4910, - "Parameters": { - "Intensity": 52, - "Frequency": 45, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 59, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5033, - "Parameters": { - "Intensity": 22, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5080, - "Parameters": { - "Intensity": 26, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5278, - "Parameters": { - "Intensity": 21, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 433, + "StartTime": 785, + "Parameters": { + "Intensity": 64, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 184, + "Intensity": 0.54, + "Frequency": 0 + }, + { + "Time": 190, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 237, + "Intensity": 1, + "Frequency": -10 + }, + { + "Time": 249, + "Intensity": 0.53, + "Frequency": 5 + }, + { + "Time": 433, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1138, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1268, + "Parameters": { + "Intensity": 30, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1343, + "Parameters": { + "Intensity": 28, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1483, + "Parameters": { + "Intensity": 21, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1632, + "Parameters": { + "Intensity": 26, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1390, + "StartTime": 2103, + "Parameters": { + "Intensity": 64, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 591, + "Intensity": 0.38, + "Frequency": -5 + }, + { + "Time": 602, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 717, + "Intensity": 0.94, + "Frequency": 5 + }, + { + "Time": 848, + "Intensity": 0.52, + "Frequency": -10 + }, + { + "Time": 1315, + "Intensity": 0.31, + "Frequency": 5 + }, + { + "Time": 1390, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2200, + "Parameters": { + "Intensity": 29, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2410, + "Parameters": { + "Intensity": 36, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2503, + "Parameters": { + "Intensity": 24, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2548, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3135, + "Parameters": { + "Intensity": 38, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3350, + "Parameters": { + "Intensity": 36, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3490, + "Parameters": { + "Intensity": 24, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3558, + "Parameters": { + "Intensity": 25, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3830, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 220, + "StartTime": 3915, + "Parameters": { + "Intensity": 52, + "Frequency": 10, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 17, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 143, + "Intensity": 0.82, + "Frequency": 5 + }, + { + "Time": 220, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 115, + "StartTime": 4770, + "Parameters": { + "Intensity": 40, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 80, + "Intensity": 1, + "Frequency": 10 + }, + { + "Time": 115, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 95, + "StartTime": 4910, + "Parameters": { + "Intensity": 52, + "Frequency": 45, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 59, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5033, + "Parameters": { + "Intensity": 22, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5080, + "Parameters": { + "Intensity": 26, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5278, + "Parameters": { + "Intensity": 21, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_h.json index 9067c09dad3ec87df3b9ec0e6fcec7825b298863..ea981c10a66ae103ef34239fa29e310ce95b564a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_h.json @@ -1,691 +1,691 @@ -{ - "MetaData": { - "Create": "2021-10-18", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 0, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 40.1532 - }, - { - "Time": 11, - "Intensity": 0.38, - "Frequency": 70 - }, - { - "Time": 33, - "Intensity": 0.044387, - "Frequency": 37.3798 - }, - { - "Time": 43, - "Intensity": 0.58, - "Frequency": 37.2261 - }, - { - "Time": 53, - "Intensity": 0.12, - "Frequency": 38.4537 - }, - { - "Time": 84, - "Intensity": 0.93, - "Frequency": 47 - }, - { - "Time": 133, - "Intensity": 0.15797, - "Frequency": 37.8403 - }, - { - "Time": 149, - "Intensity": 1, - "Frequency": 42 - }, - { - "Time": 167, - "Intensity": 0.33416, - "Frequency": 37.8405 - }, - { - "Time": 188, - "Intensity": 1, - "Frequency": 37.9941 - }, - { - "Time": 200, - "Intensity": 0.37425, - "Frequency": 38.3774 - }, - { - "Time": 220, - "Intensity": 1, - "Frequency": 32 - }, - { - "Time": 233, - "Intensity": 0.46612, - "Frequency": 38.0703 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.0703 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 233, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.0703 - }, - { - "Time": 21, - "Intensity": 0.89, - "Frequency": 70 - }, - { - "Time": 50, - "Intensity": 0.2731, - "Frequency": 38.5306 - }, - { - "Time": 73, - "Intensity": 0.89, - "Frequency": 70 - }, - { - "Time": 84, - "Intensity": 0.40483, - "Frequency": 40.1155 - }, - { - "Time": 106, - "Intensity": 1, - "Frequency": 70 - }, - { - "Time": 117, - "Intensity": 0.44912, - "Frequency": 38.1477 - }, - { - "Time": 137, - "Intensity": 1, - "Frequency": 58 - }, - { - "Time": 150, - "Intensity": 0.50406, - "Frequency": 38.4543 - }, - { - "Time": 167, - "Intensity": 0.79268, - "Frequency": 38.1473 - }, - { - "Time": 184, - "Intensity": 0.53455, - "Frequency": 37.9174 - }, - { - "Time": 200, - "Intensity": 1, - "Frequency": 37.9172 - }, - { - "Time": 217, - "Intensity": 0.69526, - "Frequency": 38.1476 - }, - { - "Time": 234, - "Intensity": 0.8526, - "Frequency": 38.2243 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.4541 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 467, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.2243 - }, - { - "Time": 16, - "Intensity": 0.31475, - "Frequency": 38.4541 - }, - { - "Time": 33, - "Intensity": 1, - "Frequency": 38.2232 - }, - { - "Time": 50, - "Intensity": 0.44752, - "Frequency": 38.2232 - }, - { - "Time": 66, - "Intensity": 0.29572, - "Frequency": 37.8401 - }, - { - "Time": 83, - "Intensity": 0.64702, - "Frequency": 37.7634 - }, - { - "Time": 100, - "Intensity": 0.64717, - "Frequency": 37.3793 - }, - { - "Time": 116, - "Intensity": 0.3679, - "Frequency": 37.2258 - }, - { - "Time": 133, - "Intensity": 0.24298, - "Frequency": 37.4567 - }, - { - "Time": 150, - "Intensity": 0.55359, - "Frequency": 37.6872 - }, - { - "Time": 166, - "Intensity": 0.67465, - "Frequency": 37.5334 - }, - { - "Time": 183, - "Intensity": 0.62278, - "Frequency": 37.4566 - }, - { - "Time": 200, - "Intensity": 0.69885, - "Frequency": 37.303 - }, - { - "Time": 216, - "Intensity": 0.32678, - "Frequency": 37.2261 - }, - { - "Time": 233, - "Intensity": 0.535, - "Frequency": 37.0724 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 36.9954 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 700, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37.0724 - }, - { - "Time": 17, - "Intensity": 0.33735, - "Frequency": 36.9954 - }, - { - "Time": 33, - "Intensity": 0.65451, - "Frequency": 37.3029 - }, - { - "Time": 50, - "Intensity": 0.42331, - "Frequency": 37.6869 - }, - { - "Time": 67, - "Intensity": 0.24668, - "Frequency": 37.9943 - }, - { - "Time": 83, - "Intensity": 0.38753, - "Frequency": 37.9943 - }, - { - "Time": 100, - "Intensity": 0.11651, - "Frequency": 38.224 - }, - { - "Time": 117, - "Intensity": 0.1304, - "Frequency": 38.3772 - }, - { - "Time": 133, - "Intensity": 0.49327, - "Frequency": 38.2242 - }, - { - "Time": 150, - "Intensity": 0.22527, - "Frequency": 38.3776 - }, - { - "Time": 167, - "Intensity": 0.21292, - "Frequency": 38.684 - }, - { - "Time": 183, - "Intensity": 0.26452, - "Frequency": 38.9137 - }, - { - "Time": 200, - "Intensity": 0.21029, - "Frequency": 38.9136 - }, - { - "Time": 217, - "Intensity": 0.18462, - "Frequency": 38.6836 - }, - { - "Time": 233, - "Intensity": 0.1114, - "Frequency": 38.7602 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.9133 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 933, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.7602 - }, - { - "Time": 17, - "Intensity": 0.11051, - "Frequency": 38.9133 - }, - { - "Time": 32, - "Intensity": 0.37, - "Frequency": 40.9583 - }, - { - "Time": 50, - "Intensity": 0.080825, - "Frequency": 40.805 - }, - { - "Time": 66, - "Intensity": 0.6, - "Frequency": 40.4219 - }, - { - "Time": 84, - "Intensity": 0.11637, - "Frequency": 38.3007 - }, - { - "Time": 114, - "Intensity": 0.25, - "Frequency": 38.0706 - }, - { - "Time": 150, - "Intensity": 0.084815, - "Frequency": 37.994 - }, - { - "Time": 184, - "Intensity": 0.18, - "Frequency": 38.0707 - }, - { - "Time": 234, - "Intensity": 0.041641, - "Frequency": 38.0707 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.0707 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1167, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.0707 - }, - { - "Time": 16, - "Intensity": 0.23, - "Frequency": 38.0707 - }, - { - "Time": 33, - "Intensity": 0.049233, - "Frequency": 38.0709 - }, - { - "Time": 50, - "Intensity": 0.15, - "Frequency": 37.9175 - }, - { - "Time": 66, - "Intensity": 0.028695, - "Frequency": 37.9173 - }, - { - "Time": 96, - "Intensity": 0.08, - "Frequency": 38.0708 - }, - { - "Time": 133, - "Intensity": 0.046483, - "Frequency": 37.8408 - }, - { - "Time": 150, - "Intensity": 0.037565, - "Frequency": 37.8408 - }, - { - "Time": 166, - "Intensity": 0.037006, - "Frequency": 38.2244 - }, - { - "Time": 183, - "Intensity": 0.031955, - "Frequency": 38.0709 - }, - { - "Time": 200, - "Intensity": 0.043736, - "Frequency": 37.9943 - }, - { - "Time": 216, - "Intensity": 0.025359, - "Frequency": 37.8409 - }, - { - "Time": 233, - "Intensity": 0.027193, - "Frequency": 37.9943 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 37.9942 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1400, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37.9943 - }, - { - "Time": 15, - "Intensity": 0.18, - "Frequency": 37.9942 - }, - { - "Time": 33, - "Intensity": 0.018389, - "Frequency": 37.9942 - }, - { - "Time": 50, - "Intensity": 0.020258, - "Frequency": 37.9942 - }, - { - "Time": 76, - "Intensity": 0.11, - "Frequency": 37.9942 - }, - { - "Time": 117, - "Intensity": 0.016523, - "Frequency": 38.1475 - }, - { - "Time": 136, - "Intensity": 0.14, - "Frequency": 37.9172 - }, - { - "Time": 150, - "Intensity": 0.016324, - "Frequency": 37.8405 - }, - { - "Time": 167, - "Intensity": 0.016409, - "Frequency": 37.9173 - }, - { - "Time": 190, - "Intensity": 0.08, - "Frequency": 37.9173 - }, - { - "Time": 217, - "Intensity": 7.2853e-05, - "Frequency": 38.2236 - }, - { - "Time": 233, - "Intensity": 0.00010155, - "Frequency": 38.1472 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.3008 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 234, - "StartTime": 1633, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.1472 - }, - { - "Time": 17, - "Intensity": 7.2025e-05, - "Frequency": 38.3008 - }, - { - "Time": 34, - "Intensity": 4.4664e-05, - "Frequency": 38.0708 - }, - { - "Time": 50, - "Intensity": 5.4972e-05, - "Frequency": 38.0708 - }, - { - "Time": 67, - "Intensity": 4.9011e-05, - "Frequency": 37.8409 - }, - { - "Time": 84, - "Intensity": 4.0321e-05, - "Frequency": 38.0706 - }, - { - "Time": 100, - "Intensity": 2.647e-05, - "Frequency": 38.1469 - }, - { - "Time": 117, - "Intensity": 1.4281e-05, - "Frequency": 38.0701 - }, - { - "Time": 134, - "Intensity": 5.3637e-06, - "Frequency": 37.917 - }, - { - "Time": 150, - "Intensity": 3.4715e-06, - "Frequency": 37.8405 - }, - { - "Time": 167, - "Intensity": 1.7078e-05, - "Frequency": 37.8406 - }, - { - "Time": 184, - "Intensity": 3.4403e-06, - "Frequency": 37.6101 - }, - { - "Time": 200, - "Intensity": 3.0648e-06, - "Frequency": 36.9629 - }, - { - "Time": 217, - "Intensity": 1.4176e-06, - "Frequency": 36.9629 - }, - { - "Time": 234, - "Intensity": 0, - "Frequency": 34.8347 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-10-18", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 0, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 40.1532 + }, + { + "Time": 11, + "Intensity": 0.38, + "Frequency": 70 + }, + { + "Time": 33, + "Intensity": 0.044387, + "Frequency": 37.3798 + }, + { + "Time": 43, + "Intensity": 0.58, + "Frequency": 37.2261 + }, + { + "Time": 53, + "Intensity": 0.12, + "Frequency": 38.4537 + }, + { + "Time": 84, + "Intensity": 0.93, + "Frequency": 47 + }, + { + "Time": 133, + "Intensity": 0.15797, + "Frequency": 37.8403 + }, + { + "Time": 149, + "Intensity": 1, + "Frequency": 42 + }, + { + "Time": 167, + "Intensity": 0.33416, + "Frequency": 37.8405 + }, + { + "Time": 188, + "Intensity": 1, + "Frequency": 37.9941 + }, + { + "Time": 200, + "Intensity": 0.37425, + "Frequency": 38.3774 + }, + { + "Time": 220, + "Intensity": 1, + "Frequency": 32 + }, + { + "Time": 233, + "Intensity": 0.46612, + "Frequency": 38.0703 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.0703 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 233, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.0703 + }, + { + "Time": 21, + "Intensity": 0.89, + "Frequency": 70 + }, + { + "Time": 50, + "Intensity": 0.2731, + "Frequency": 38.5306 + }, + { + "Time": 73, + "Intensity": 0.89, + "Frequency": 70 + }, + { + "Time": 84, + "Intensity": 0.40483, + "Frequency": 40.1155 + }, + { + "Time": 106, + "Intensity": 1, + "Frequency": 70 + }, + { + "Time": 117, + "Intensity": 0.44912, + "Frequency": 38.1477 + }, + { + "Time": 137, + "Intensity": 1, + "Frequency": 58 + }, + { + "Time": 150, + "Intensity": 0.50406, + "Frequency": 38.4543 + }, + { + "Time": 167, + "Intensity": 0.79268, + "Frequency": 38.1473 + }, + { + "Time": 184, + "Intensity": 0.53455, + "Frequency": 37.9174 + }, + { + "Time": 200, + "Intensity": 1, + "Frequency": 37.9172 + }, + { + "Time": 217, + "Intensity": 0.69526, + "Frequency": 38.1476 + }, + { + "Time": 234, + "Intensity": 0.8526, + "Frequency": 38.2243 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.4541 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 467, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.2243 + }, + { + "Time": 16, + "Intensity": 0.31475, + "Frequency": 38.4541 + }, + { + "Time": 33, + "Intensity": 1, + "Frequency": 38.2232 + }, + { + "Time": 50, + "Intensity": 0.44752, + "Frequency": 38.2232 + }, + { + "Time": 66, + "Intensity": 0.29572, + "Frequency": 37.8401 + }, + { + "Time": 83, + "Intensity": 0.64702, + "Frequency": 37.7634 + }, + { + "Time": 100, + "Intensity": 0.64717, + "Frequency": 37.3793 + }, + { + "Time": 116, + "Intensity": 0.3679, + "Frequency": 37.2258 + }, + { + "Time": 133, + "Intensity": 0.24298, + "Frequency": 37.4567 + }, + { + "Time": 150, + "Intensity": 0.55359, + "Frequency": 37.6872 + }, + { + "Time": 166, + "Intensity": 0.67465, + "Frequency": 37.5334 + }, + { + "Time": 183, + "Intensity": 0.62278, + "Frequency": 37.4566 + }, + { + "Time": 200, + "Intensity": 0.69885, + "Frequency": 37.303 + }, + { + "Time": 216, + "Intensity": 0.32678, + "Frequency": 37.2261 + }, + { + "Time": 233, + "Intensity": 0.535, + "Frequency": 37.0724 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 36.9954 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 700, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37.0724 + }, + { + "Time": 17, + "Intensity": 0.33735, + "Frequency": 36.9954 + }, + { + "Time": 33, + "Intensity": 0.65451, + "Frequency": 37.3029 + }, + { + "Time": 50, + "Intensity": 0.42331, + "Frequency": 37.6869 + }, + { + "Time": 67, + "Intensity": 0.24668, + "Frequency": 37.9943 + }, + { + "Time": 83, + "Intensity": 0.38753, + "Frequency": 37.9943 + }, + { + "Time": 100, + "Intensity": 0.11651, + "Frequency": 38.224 + }, + { + "Time": 117, + "Intensity": 0.1304, + "Frequency": 38.3772 + }, + { + "Time": 133, + "Intensity": 0.49327, + "Frequency": 38.2242 + }, + { + "Time": 150, + "Intensity": 0.22527, + "Frequency": 38.3776 + }, + { + "Time": 167, + "Intensity": 0.21292, + "Frequency": 38.684 + }, + { + "Time": 183, + "Intensity": 0.26452, + "Frequency": 38.9137 + }, + { + "Time": 200, + "Intensity": 0.21029, + "Frequency": 38.9136 + }, + { + "Time": 217, + "Intensity": 0.18462, + "Frequency": 38.6836 + }, + { + "Time": 233, + "Intensity": 0.1114, + "Frequency": 38.7602 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.9133 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 933, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.7602 + }, + { + "Time": 17, + "Intensity": 0.11051, + "Frequency": 38.9133 + }, + { + "Time": 32, + "Intensity": 0.37, + "Frequency": 40.9583 + }, + { + "Time": 50, + "Intensity": 0.080825, + "Frequency": 40.805 + }, + { + "Time": 66, + "Intensity": 0.6, + "Frequency": 40.4219 + }, + { + "Time": 84, + "Intensity": 0.11637, + "Frequency": 38.3007 + }, + { + "Time": 114, + "Intensity": 0.25, + "Frequency": 38.0706 + }, + { + "Time": 150, + "Intensity": 0.084815, + "Frequency": 37.994 + }, + { + "Time": 184, + "Intensity": 0.18, + "Frequency": 38.0707 + }, + { + "Time": 234, + "Intensity": 0.041641, + "Frequency": 38.0707 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.0707 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1167, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.0707 + }, + { + "Time": 16, + "Intensity": 0.23, + "Frequency": 38.0707 + }, + { + "Time": 33, + "Intensity": 0.049233, + "Frequency": 38.0709 + }, + { + "Time": 50, + "Intensity": 0.15, + "Frequency": 37.9175 + }, + { + "Time": 66, + "Intensity": 0.028695, + "Frequency": 37.9173 + }, + { + "Time": 96, + "Intensity": 0.08, + "Frequency": 38.0708 + }, + { + "Time": 133, + "Intensity": 0.046483, + "Frequency": 37.8408 + }, + { + "Time": 150, + "Intensity": 0.037565, + "Frequency": 37.8408 + }, + { + "Time": 166, + "Intensity": 0.037006, + "Frequency": 38.2244 + }, + { + "Time": 183, + "Intensity": 0.031955, + "Frequency": 38.0709 + }, + { + "Time": 200, + "Intensity": 0.043736, + "Frequency": 37.9943 + }, + { + "Time": 216, + "Intensity": 0.025359, + "Frequency": 37.8409 + }, + { + "Time": 233, + "Intensity": 0.027193, + "Frequency": 37.9943 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 37.9942 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1400, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37.9943 + }, + { + "Time": 15, + "Intensity": 0.18, + "Frequency": 37.9942 + }, + { + "Time": 33, + "Intensity": 0.018389, + "Frequency": 37.9942 + }, + { + "Time": 50, + "Intensity": 0.020258, + "Frequency": 37.9942 + }, + { + "Time": 76, + "Intensity": 0.11, + "Frequency": 37.9942 + }, + { + "Time": 117, + "Intensity": 0.016523, + "Frequency": 38.1475 + }, + { + "Time": 136, + "Intensity": 0.14, + "Frequency": 37.9172 + }, + { + "Time": 150, + "Intensity": 0.016324, + "Frequency": 37.8405 + }, + { + "Time": 167, + "Intensity": 0.016409, + "Frequency": 37.9173 + }, + { + "Time": 190, + "Intensity": 0.08, + "Frequency": 37.9173 + }, + { + "Time": 217, + "Intensity": 7.2853e-05, + "Frequency": 38.2236 + }, + { + "Time": 233, + "Intensity": 0.00010155, + "Frequency": 38.1472 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.3008 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 234, + "StartTime": 1633, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.1472 + }, + { + "Time": 17, + "Intensity": 7.2025e-05, + "Frequency": 38.3008 + }, + { + "Time": 34, + "Intensity": 4.4664e-05, + "Frequency": 38.0708 + }, + { + "Time": 50, + "Intensity": 5.4972e-05, + "Frequency": 38.0708 + }, + { + "Time": 67, + "Intensity": 4.9011e-05, + "Frequency": 37.8409 + }, + { + "Time": 84, + "Intensity": 4.0321e-05, + "Frequency": 38.0706 + }, + { + "Time": 100, + "Intensity": 2.647e-05, + "Frequency": 38.1469 + }, + { + "Time": 117, + "Intensity": 1.4281e-05, + "Frequency": 38.0701 + }, + { + "Time": 134, + "Intensity": 5.3637e-06, + "Frequency": 37.917 + }, + { + "Time": 150, + "Intensity": 3.4715e-06, + "Frequency": 37.8405 + }, + { + "Time": 167, + "Intensity": 1.7078e-05, + "Frequency": 37.8406 + }, + { + "Time": 184, + "Intensity": 3.4403e-06, + "Frequency": 37.6101 + }, + { + "Time": 200, + "Intensity": 3.0648e-06, + "Frequency": 36.9629 + }, + { + "Time": 217, + "Intensity": 1.4176e-06, + "Frequency": 36.9629 + }, + { + "Time": 234, + "Intensity": 0, + "Frequency": 34.8347 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_l.json index b354078c03faa97954f0980d812b385056599843..eeb144cb9e61dac5c7c34476fe1e20f91d86d225 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_l.json @@ -1,691 +1,691 @@ -{ - "MetaData": { - "Create": "2021-10-18", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 40.1532 - }, - { - "Time": 11, - "Intensity": 0.38, - "Frequency": 70 - }, - { - "Time": 33, - "Intensity": 0.044387, - "Frequency": 37.3798 - }, - { - "Time": 43, - "Intensity": 0.58, - "Frequency": 37.2261 - }, - { - "Time": 53, - "Intensity": 0.12, - "Frequency": 38.4537 - }, - { - "Time": 84, - "Intensity": 0.93, - "Frequency": 47 - }, - { - "Time": 133, - "Intensity": 0.15797, - "Frequency": 37.8403 - }, - { - "Time": 149, - "Intensity": 1, - "Frequency": 42 - }, - { - "Time": 167, - "Intensity": 0.33416, - "Frequency": 37.8405 - }, - { - "Time": 188, - "Intensity": 1, - "Frequency": 37.9941 - }, - { - "Time": 200, - "Intensity": 0.37425, - "Frequency": 38.3774 - }, - { - "Time": 220, - "Intensity": 1, - "Frequency": 32 - }, - { - "Time": 233, - "Intensity": 0.46612, - "Frequency": 38.0703 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.0703 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 233, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.0703 - }, - { - "Time": 21, - "Intensity": 0.89, - "Frequency": 70 - }, - { - "Time": 50, - "Intensity": 0.2731, - "Frequency": 38.5306 - }, - { - "Time": 73, - "Intensity": 0.89, - "Frequency": 70 - }, - { - "Time": 84, - "Intensity": 0.40483, - "Frequency": 40.1155 - }, - { - "Time": 106, - "Intensity": 1, - "Frequency": 70 - }, - { - "Time": 117, - "Intensity": 0.44912, - "Frequency": 38.1477 - }, - { - "Time": 137, - "Intensity": 1, - "Frequency": 58 - }, - { - "Time": 150, - "Intensity": 0.50406, - "Frequency": 38.4543 - }, - { - "Time": 167, - "Intensity": 0.79268, - "Frequency": 38.1473 - }, - { - "Time": 184, - "Intensity": 0.53455, - "Frequency": 37.9174 - }, - { - "Time": 200, - "Intensity": 1, - "Frequency": 37.9172 - }, - { - "Time": 217, - "Intensity": 0.69526, - "Frequency": 38.1476 - }, - { - "Time": 234, - "Intensity": 0.8526, - "Frequency": 38.2243 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.4541 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 467, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.2243 - }, - { - "Time": 16, - "Intensity": 0.31475, - "Frequency": 38.4541 - }, - { - "Time": 33, - "Intensity": 1, - "Frequency": 38.2232 - }, - { - "Time": 50, - "Intensity": 0.44752, - "Frequency": 38.2232 - }, - { - "Time": 66, - "Intensity": 0.29572, - "Frequency": 37.8401 - }, - { - "Time": 83, - "Intensity": 0.64702, - "Frequency": 37.7634 - }, - { - "Time": 100, - "Intensity": 0.64717, - "Frequency": 37.3793 - }, - { - "Time": 116, - "Intensity": 0.3679, - "Frequency": 37.2258 - }, - { - "Time": 133, - "Intensity": 0.24298, - "Frequency": 37.4567 - }, - { - "Time": 150, - "Intensity": 0.55359, - "Frequency": 37.6872 - }, - { - "Time": 166, - "Intensity": 0.67465, - "Frequency": 37.5334 - }, - { - "Time": 183, - "Intensity": 0.62278, - "Frequency": 37.4566 - }, - { - "Time": 200, - "Intensity": 0.69885, - "Frequency": 37.303 - }, - { - "Time": 216, - "Intensity": 0.32678, - "Frequency": 37.2261 - }, - { - "Time": 233, - "Intensity": 0.535, - "Frequency": 37.0724 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 36.9954 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 700, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37.0724 - }, - { - "Time": 17, - "Intensity": 0.33735, - "Frequency": 36.9954 - }, - { - "Time": 33, - "Intensity": 0.65451, - "Frequency": 37.3029 - }, - { - "Time": 50, - "Intensity": 0.42331, - "Frequency": 37.6869 - }, - { - "Time": 67, - "Intensity": 0.24668, - "Frequency": 37.9943 - }, - { - "Time": 83, - "Intensity": 0.38753, - "Frequency": 37.9943 - }, - { - "Time": 100, - "Intensity": 0.11651, - "Frequency": 38.224 - }, - { - "Time": 117, - "Intensity": 0.1304, - "Frequency": 38.3772 - }, - { - "Time": 133, - "Intensity": 0.49327, - "Frequency": 38.2242 - }, - { - "Time": 150, - "Intensity": 0.22527, - "Frequency": 38.3776 - }, - { - "Time": 167, - "Intensity": 0.21292, - "Frequency": 38.684 - }, - { - "Time": 183, - "Intensity": 0.26452, - "Frequency": 38.9137 - }, - { - "Time": 200, - "Intensity": 0.21029, - "Frequency": 38.9136 - }, - { - "Time": 217, - "Intensity": 0.18462, - "Frequency": 38.6836 - }, - { - "Time": 233, - "Intensity": 0.1114, - "Frequency": 38.7602 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.9133 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 933, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.7602 - }, - { - "Time": 17, - "Intensity": 0.11051, - "Frequency": 38.9133 - }, - { - "Time": 32, - "Intensity": 0.37, - "Frequency": 40.9583 - }, - { - "Time": 50, - "Intensity": 0.080825, - "Frequency": 40.805 - }, - { - "Time": 66, - "Intensity": 0.6, - "Frequency": 40.4219 - }, - { - "Time": 84, - "Intensity": 0.11637, - "Frequency": 38.3007 - }, - { - "Time": 114, - "Intensity": 0.25, - "Frequency": 38.0706 - }, - { - "Time": 150, - "Intensity": 0.084815, - "Frequency": 37.994 - }, - { - "Time": 184, - "Intensity": 0.18, - "Frequency": 38.0707 - }, - { - "Time": 234, - "Intensity": 0.041641, - "Frequency": 38.0707 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.0707 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1167, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.0707 - }, - { - "Time": 16, - "Intensity": 0.23, - "Frequency": 38.0707 - }, - { - "Time": 33, - "Intensity": 0.049233, - "Frequency": 38.0709 - }, - { - "Time": 50, - "Intensity": 0.15, - "Frequency": 37.9175 - }, - { - "Time": 66, - "Intensity": 0.028695, - "Frequency": 37.9173 - }, - { - "Time": 96, - "Intensity": 0.08, - "Frequency": 38.0708 - }, - { - "Time": 133, - "Intensity": 0.046483, - "Frequency": 37.8408 - }, - { - "Time": 150, - "Intensity": 0.037565, - "Frequency": 37.8408 - }, - { - "Time": 166, - "Intensity": 0.037006, - "Frequency": 38.2244 - }, - { - "Time": 183, - "Intensity": 0.031955, - "Frequency": 38.0709 - }, - { - "Time": 200, - "Intensity": 0.043736, - "Frequency": 37.9943 - }, - { - "Time": 216, - "Intensity": 0.025359, - "Frequency": 37.8409 - }, - { - "Time": 233, - "Intensity": 0.027193, - "Frequency": 37.9943 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 37.9942 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1400, - "Parameters": { - "Intensity": 27, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37.9943 - }, - { - "Time": 15, - "Intensity": 0.18, - "Frequency": 37.9942 - }, - { - "Time": 33, - "Intensity": 0.018389, - "Frequency": 37.9942 - }, - { - "Time": 50, - "Intensity": 0.020258, - "Frequency": 37.9942 - }, - { - "Time": 76, - "Intensity": 0.11, - "Frequency": 37.9942 - }, - { - "Time": 117, - "Intensity": 0.016523, - "Frequency": 38.1475 - }, - { - "Time": 136, - "Intensity": 0.14, - "Frequency": 37.9172 - }, - { - "Time": 150, - "Intensity": 0.016324, - "Frequency": 37.8405 - }, - { - "Time": 167, - "Intensity": 0.016409, - "Frequency": 37.9173 - }, - { - "Time": 190, - "Intensity": 0.08, - "Frequency": 37.9173 - }, - { - "Time": 217, - "Intensity": 7.2853e-05, - "Frequency": 38.2236 - }, - { - "Time": 233, - "Intensity": 0.00010155, - "Frequency": 38.1472 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.3008 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 234, - "StartTime": 1633, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.1472 - }, - { - "Time": 17, - "Intensity": 7.2025e-05, - "Frequency": 38.3008 - }, - { - "Time": 34, - "Intensity": 4.4664e-05, - "Frequency": 38.0708 - }, - { - "Time": 50, - "Intensity": 5.4972e-05, - "Frequency": 38.0708 - }, - { - "Time": 67, - "Intensity": 4.9011e-05, - "Frequency": 37.8409 - }, - { - "Time": 84, - "Intensity": 4.0321e-05, - "Frequency": 38.0706 - }, - { - "Time": 100, - "Intensity": 2.647e-05, - "Frequency": 38.1469 - }, - { - "Time": 117, - "Intensity": 1.4281e-05, - "Frequency": 38.0701 - }, - { - "Time": 134, - "Intensity": 5.3637e-06, - "Frequency": 37.917 - }, - { - "Time": 150, - "Intensity": 3.4715e-06, - "Frequency": 37.8405 - }, - { - "Time": 167, - "Intensity": 1.7078e-05, - "Frequency": 37.8406 - }, - { - "Time": 184, - "Intensity": 3.4403e-06, - "Frequency": 37.6101 - }, - { - "Time": 200, - "Intensity": 3.0648e-06, - "Frequency": 36.9629 - }, - { - "Time": 217, - "Intensity": 1.4176e-06, - "Frequency": 36.9629 - }, - { - "Time": 234, - "Intensity": 0, - "Frequency": 34.8347 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-10-18", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 40.1532 + }, + { + "Time": 11, + "Intensity": 0.38, + "Frequency": 70 + }, + { + "Time": 33, + "Intensity": 0.044387, + "Frequency": 37.3798 + }, + { + "Time": 43, + "Intensity": 0.58, + "Frequency": 37.2261 + }, + { + "Time": 53, + "Intensity": 0.12, + "Frequency": 38.4537 + }, + { + "Time": 84, + "Intensity": 0.93, + "Frequency": 47 + }, + { + "Time": 133, + "Intensity": 0.15797, + "Frequency": 37.8403 + }, + { + "Time": 149, + "Intensity": 1, + "Frequency": 42 + }, + { + "Time": 167, + "Intensity": 0.33416, + "Frequency": 37.8405 + }, + { + "Time": 188, + "Intensity": 1, + "Frequency": 37.9941 + }, + { + "Time": 200, + "Intensity": 0.37425, + "Frequency": 38.3774 + }, + { + "Time": 220, + "Intensity": 1, + "Frequency": 32 + }, + { + "Time": 233, + "Intensity": 0.46612, + "Frequency": 38.0703 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.0703 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 233, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.0703 + }, + { + "Time": 21, + "Intensity": 0.89, + "Frequency": 70 + }, + { + "Time": 50, + "Intensity": 0.2731, + "Frequency": 38.5306 + }, + { + "Time": 73, + "Intensity": 0.89, + "Frequency": 70 + }, + { + "Time": 84, + "Intensity": 0.40483, + "Frequency": 40.1155 + }, + { + "Time": 106, + "Intensity": 1, + "Frequency": 70 + }, + { + "Time": 117, + "Intensity": 0.44912, + "Frequency": 38.1477 + }, + { + "Time": 137, + "Intensity": 1, + "Frequency": 58 + }, + { + "Time": 150, + "Intensity": 0.50406, + "Frequency": 38.4543 + }, + { + "Time": 167, + "Intensity": 0.79268, + "Frequency": 38.1473 + }, + { + "Time": 184, + "Intensity": 0.53455, + "Frequency": 37.9174 + }, + { + "Time": 200, + "Intensity": 1, + "Frequency": 37.9172 + }, + { + "Time": 217, + "Intensity": 0.69526, + "Frequency": 38.1476 + }, + { + "Time": 234, + "Intensity": 0.8526, + "Frequency": 38.2243 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.4541 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 467, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.2243 + }, + { + "Time": 16, + "Intensity": 0.31475, + "Frequency": 38.4541 + }, + { + "Time": 33, + "Intensity": 1, + "Frequency": 38.2232 + }, + { + "Time": 50, + "Intensity": 0.44752, + "Frequency": 38.2232 + }, + { + "Time": 66, + "Intensity": 0.29572, + "Frequency": 37.8401 + }, + { + "Time": 83, + "Intensity": 0.64702, + "Frequency": 37.7634 + }, + { + "Time": 100, + "Intensity": 0.64717, + "Frequency": 37.3793 + }, + { + "Time": 116, + "Intensity": 0.3679, + "Frequency": 37.2258 + }, + { + "Time": 133, + "Intensity": 0.24298, + "Frequency": 37.4567 + }, + { + "Time": 150, + "Intensity": 0.55359, + "Frequency": 37.6872 + }, + { + "Time": 166, + "Intensity": 0.67465, + "Frequency": 37.5334 + }, + { + "Time": 183, + "Intensity": 0.62278, + "Frequency": 37.4566 + }, + { + "Time": 200, + "Intensity": 0.69885, + "Frequency": 37.303 + }, + { + "Time": 216, + "Intensity": 0.32678, + "Frequency": 37.2261 + }, + { + "Time": 233, + "Intensity": 0.535, + "Frequency": 37.0724 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 36.9954 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 700, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37.0724 + }, + { + "Time": 17, + "Intensity": 0.33735, + "Frequency": 36.9954 + }, + { + "Time": 33, + "Intensity": 0.65451, + "Frequency": 37.3029 + }, + { + "Time": 50, + "Intensity": 0.42331, + "Frequency": 37.6869 + }, + { + "Time": 67, + "Intensity": 0.24668, + "Frequency": 37.9943 + }, + { + "Time": 83, + "Intensity": 0.38753, + "Frequency": 37.9943 + }, + { + "Time": 100, + "Intensity": 0.11651, + "Frequency": 38.224 + }, + { + "Time": 117, + "Intensity": 0.1304, + "Frequency": 38.3772 + }, + { + "Time": 133, + "Intensity": 0.49327, + "Frequency": 38.2242 + }, + { + "Time": 150, + "Intensity": 0.22527, + "Frequency": 38.3776 + }, + { + "Time": 167, + "Intensity": 0.21292, + "Frequency": 38.684 + }, + { + "Time": 183, + "Intensity": 0.26452, + "Frequency": 38.9137 + }, + { + "Time": 200, + "Intensity": 0.21029, + "Frequency": 38.9136 + }, + { + "Time": 217, + "Intensity": 0.18462, + "Frequency": 38.6836 + }, + { + "Time": 233, + "Intensity": 0.1114, + "Frequency": 38.7602 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.9133 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 933, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.7602 + }, + { + "Time": 17, + "Intensity": 0.11051, + "Frequency": 38.9133 + }, + { + "Time": 32, + "Intensity": 0.37, + "Frequency": 40.9583 + }, + { + "Time": 50, + "Intensity": 0.080825, + "Frequency": 40.805 + }, + { + "Time": 66, + "Intensity": 0.6, + "Frequency": 40.4219 + }, + { + "Time": 84, + "Intensity": 0.11637, + "Frequency": 38.3007 + }, + { + "Time": 114, + "Intensity": 0.25, + "Frequency": 38.0706 + }, + { + "Time": 150, + "Intensity": 0.084815, + "Frequency": 37.994 + }, + { + "Time": 184, + "Intensity": 0.18, + "Frequency": 38.0707 + }, + { + "Time": 234, + "Intensity": 0.041641, + "Frequency": 38.0707 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.0707 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1167, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.0707 + }, + { + "Time": 16, + "Intensity": 0.23, + "Frequency": 38.0707 + }, + { + "Time": 33, + "Intensity": 0.049233, + "Frequency": 38.0709 + }, + { + "Time": 50, + "Intensity": 0.15, + "Frequency": 37.9175 + }, + { + "Time": 66, + "Intensity": 0.028695, + "Frequency": 37.9173 + }, + { + "Time": 96, + "Intensity": 0.08, + "Frequency": 38.0708 + }, + { + "Time": 133, + "Intensity": 0.046483, + "Frequency": 37.8408 + }, + { + "Time": 150, + "Intensity": 0.037565, + "Frequency": 37.8408 + }, + { + "Time": 166, + "Intensity": 0.037006, + "Frequency": 38.2244 + }, + { + "Time": 183, + "Intensity": 0.031955, + "Frequency": 38.0709 + }, + { + "Time": 200, + "Intensity": 0.043736, + "Frequency": 37.9943 + }, + { + "Time": 216, + "Intensity": 0.025359, + "Frequency": 37.8409 + }, + { + "Time": 233, + "Intensity": 0.027193, + "Frequency": 37.9943 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 37.9942 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1400, + "Parameters": { + "Intensity": 27, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37.9943 + }, + { + "Time": 15, + "Intensity": 0.18, + "Frequency": 37.9942 + }, + { + "Time": 33, + "Intensity": 0.018389, + "Frequency": 37.9942 + }, + { + "Time": 50, + "Intensity": 0.020258, + "Frequency": 37.9942 + }, + { + "Time": 76, + "Intensity": 0.11, + "Frequency": 37.9942 + }, + { + "Time": 117, + "Intensity": 0.016523, + "Frequency": 38.1475 + }, + { + "Time": 136, + "Intensity": 0.14, + "Frequency": 37.9172 + }, + { + "Time": 150, + "Intensity": 0.016324, + "Frequency": 37.8405 + }, + { + "Time": 167, + "Intensity": 0.016409, + "Frequency": 37.9173 + }, + { + "Time": 190, + "Intensity": 0.08, + "Frequency": 37.9173 + }, + { + "Time": 217, + "Intensity": 7.2853e-05, + "Frequency": 38.2236 + }, + { + "Time": 233, + "Intensity": 0.00010155, + "Frequency": 38.1472 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.3008 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 234, + "StartTime": 1633, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.1472 + }, + { + "Time": 17, + "Intensity": 7.2025e-05, + "Frequency": 38.3008 + }, + { + "Time": 34, + "Intensity": 4.4664e-05, + "Frequency": 38.0708 + }, + { + "Time": 50, + "Intensity": 5.4972e-05, + "Frequency": 38.0708 + }, + { + "Time": 67, + "Intensity": 4.9011e-05, + "Frequency": 37.8409 + }, + { + "Time": 84, + "Intensity": 4.0321e-05, + "Frequency": 38.0706 + }, + { + "Time": 100, + "Intensity": 2.647e-05, + "Frequency": 38.1469 + }, + { + "Time": 117, + "Intensity": 1.4281e-05, + "Frequency": 38.0701 + }, + { + "Time": 134, + "Intensity": 5.3637e-06, + "Frequency": 37.917 + }, + { + "Time": 150, + "Intensity": 3.4715e-06, + "Frequency": 37.8405 + }, + { + "Time": 167, + "Intensity": 1.7078e-05, + "Frequency": 37.8406 + }, + { + "Time": 184, + "Intensity": 3.4403e-06, + "Frequency": 37.6101 + }, + { + "Time": 200, + "Intensity": 3.0648e-06, + "Frequency": 36.9629 + }, + { + "Time": 217, + "Intensity": 1.4176e-06, + "Frequency": 36.9629 + }, + { + "Time": 234, + "Intensity": 0, + "Frequency": 34.8347 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_m.json index 62b9546c80c7b80c65d5df87d4e3f872a034269c..30e2d9e73a6db967b0bd6d1e2a62a8af89535478 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/SpeedUp_m.json @@ -1,691 +1,691 @@ -{ - "MetaData": { - "Create": "2021-10-18", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 0, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 40.1532 - }, - { - "Time": 11, - "Intensity": 0.38, - "Frequency": 70 - }, - { - "Time": 33, - "Intensity": 0.044387, - "Frequency": 37.3798 - }, - { - "Time": 43, - "Intensity": 0.58, - "Frequency": 37.2261 - }, - { - "Time": 53, - "Intensity": 0.12, - "Frequency": 38.4537 - }, - { - "Time": 84, - "Intensity": 0.93, - "Frequency": 47 - }, - { - "Time": 133, - "Intensity": 0.15797, - "Frequency": 37.8403 - }, - { - "Time": 149, - "Intensity": 1, - "Frequency": 42 - }, - { - "Time": 167, - "Intensity": 0.33416, - "Frequency": 37.8405 - }, - { - "Time": 188, - "Intensity": 1, - "Frequency": 37.9941 - }, - { - "Time": 200, - "Intensity": 0.37425, - "Frequency": 38.3774 - }, - { - "Time": 220, - "Intensity": 1, - "Frequency": 32 - }, - { - "Time": 233, - "Intensity": 0.46612, - "Frequency": 38.0703 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.0703 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 233, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.0703 - }, - { - "Time": 21, - "Intensity": 0.89, - "Frequency": 70 - }, - { - "Time": 50, - "Intensity": 0.2731, - "Frequency": 38.5306 - }, - { - "Time": 73, - "Intensity": 0.89, - "Frequency": 70 - }, - { - "Time": 84, - "Intensity": 0.40483, - "Frequency": 40.1155 - }, - { - "Time": 106, - "Intensity": 1, - "Frequency": 70 - }, - { - "Time": 117, - "Intensity": 0.44912, - "Frequency": 38.1477 - }, - { - "Time": 137, - "Intensity": 1, - "Frequency": 58 - }, - { - "Time": 150, - "Intensity": 0.50406, - "Frequency": 38.4543 - }, - { - "Time": 167, - "Intensity": 0.79268, - "Frequency": 38.1473 - }, - { - "Time": 184, - "Intensity": 0.53455, - "Frequency": 37.9174 - }, - { - "Time": 200, - "Intensity": 1, - "Frequency": 37.9172 - }, - { - "Time": 217, - "Intensity": 0.69526, - "Frequency": 38.1476 - }, - { - "Time": 234, - "Intensity": 0.8526, - "Frequency": 38.2243 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.4541 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 467, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.2243 - }, - { - "Time": 16, - "Intensity": 0.31475, - "Frequency": 38.4541 - }, - { - "Time": 33, - "Intensity": 1, - "Frequency": 38.2232 - }, - { - "Time": 50, - "Intensity": 0.44752, - "Frequency": 38.2232 - }, - { - "Time": 66, - "Intensity": 0.29572, - "Frequency": 37.8401 - }, - { - "Time": 83, - "Intensity": 0.64702, - "Frequency": 37.7634 - }, - { - "Time": 100, - "Intensity": 0.64717, - "Frequency": 37.3793 - }, - { - "Time": 116, - "Intensity": 0.3679, - "Frequency": 37.2258 - }, - { - "Time": 133, - "Intensity": 0.24298, - "Frequency": 37.4567 - }, - { - "Time": 150, - "Intensity": 0.55359, - "Frequency": 37.6872 - }, - { - "Time": 166, - "Intensity": 0.67465, - "Frequency": 37.5334 - }, - { - "Time": 183, - "Intensity": 0.62278, - "Frequency": 37.4566 - }, - { - "Time": 200, - "Intensity": 0.69885, - "Frequency": 37.303 - }, - { - "Time": 216, - "Intensity": 0.32678, - "Frequency": 37.2261 - }, - { - "Time": 233, - "Intensity": 0.535, - "Frequency": 37.0724 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 36.9954 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 700, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37.0724 - }, - { - "Time": 17, - "Intensity": 0.33735, - "Frequency": 36.9954 - }, - { - "Time": 33, - "Intensity": 0.65451, - "Frequency": 37.3029 - }, - { - "Time": 50, - "Intensity": 0.42331, - "Frequency": 37.6869 - }, - { - "Time": 67, - "Intensity": 0.24668, - "Frequency": 37.9943 - }, - { - "Time": 83, - "Intensity": 0.38753, - "Frequency": 37.9943 - }, - { - "Time": 100, - "Intensity": 0.11651, - "Frequency": 38.224 - }, - { - "Time": 117, - "Intensity": 0.1304, - "Frequency": 38.3772 - }, - { - "Time": 133, - "Intensity": 0.49327, - "Frequency": 38.2242 - }, - { - "Time": 150, - "Intensity": 0.22527, - "Frequency": 38.3776 - }, - { - "Time": 167, - "Intensity": 0.21292, - "Frequency": 38.684 - }, - { - "Time": 183, - "Intensity": 0.26452, - "Frequency": 38.9137 - }, - { - "Time": 200, - "Intensity": 0.21029, - "Frequency": 38.9136 - }, - { - "Time": 217, - "Intensity": 0.18462, - "Frequency": 38.6836 - }, - { - "Time": 233, - "Intensity": 0.1114, - "Frequency": 38.7602 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.9133 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 933, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.7602 - }, - { - "Time": 17, - "Intensity": 0.11051, - "Frequency": 38.9133 - }, - { - "Time": 32, - "Intensity": 0.37, - "Frequency": 40.9583 - }, - { - "Time": 50, - "Intensity": 0.080825, - "Frequency": 40.805 - }, - { - "Time": 66, - "Intensity": 0.6, - "Frequency": 40.4219 - }, - { - "Time": 84, - "Intensity": 0.11637, - "Frequency": 38.3007 - }, - { - "Time": 114, - "Intensity": 0.25, - "Frequency": 38.0706 - }, - { - "Time": 150, - "Intensity": 0.084815, - "Frequency": 37.994 - }, - { - "Time": 184, - "Intensity": 0.18, - "Frequency": 38.0707 - }, - { - "Time": 234, - "Intensity": 0.041641, - "Frequency": 38.0707 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.0707 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1167, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.0707 - }, - { - "Time": 16, - "Intensity": 0.23, - "Frequency": 38.0707 - }, - { - "Time": 33, - "Intensity": 0.049233, - "Frequency": 38.0709 - }, - { - "Time": 50, - "Intensity": 0.15, - "Frequency": 37.9175 - }, - { - "Time": 66, - "Intensity": 0.028695, - "Frequency": 37.9173 - }, - { - "Time": 96, - "Intensity": 0.08, - "Frequency": 38.0708 - }, - { - "Time": 133, - "Intensity": 0.046483, - "Frequency": 37.8408 - }, - { - "Time": 150, - "Intensity": 0.037565, - "Frequency": 37.8408 - }, - { - "Time": 166, - "Intensity": 0.037006, - "Frequency": 38.2244 - }, - { - "Time": 183, - "Intensity": 0.031955, - "Frequency": 38.0709 - }, - { - "Time": 200, - "Intensity": 0.043736, - "Frequency": 37.9943 - }, - { - "Time": 216, - "Intensity": 0.025359, - "Frequency": 37.8409 - }, - { - "Time": 233, - "Intensity": 0.027193, - "Frequency": 37.9943 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 37.9942 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1400, - "Parameters": { - "Intensity": 36, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37.9943 - }, - { - "Time": 15, - "Intensity": 0.18, - "Frequency": 37.9942 - }, - { - "Time": 33, - "Intensity": 0.018389, - "Frequency": 37.9942 - }, - { - "Time": 50, - "Intensity": 0.020258, - "Frequency": 37.9942 - }, - { - "Time": 76, - "Intensity": 0.11, - "Frequency": 37.9942 - }, - { - "Time": 117, - "Intensity": 0.016523, - "Frequency": 38.1475 - }, - { - "Time": 136, - "Intensity": 0.14, - "Frequency": 37.9172 - }, - { - "Time": 150, - "Intensity": 0.016324, - "Frequency": 37.8405 - }, - { - "Time": 167, - "Intensity": 0.016409, - "Frequency": 37.9173 - }, - { - "Time": 190, - "Intensity": 0.08, - "Frequency": 37.9173 - }, - { - "Time": 217, - "Intensity": 7.2853e-05, - "Frequency": 38.2236 - }, - { - "Time": 233, - "Intensity": 0.00010155, - "Frequency": 38.1472 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 38.3008 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 234, - "StartTime": 1633, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 38.1472 - }, - { - "Time": 17, - "Intensity": 7.2025e-05, - "Frequency": 38.3008 - }, - { - "Time": 34, - "Intensity": 4.4664e-05, - "Frequency": 38.0708 - }, - { - "Time": 50, - "Intensity": 5.4972e-05, - "Frequency": 38.0708 - }, - { - "Time": 67, - "Intensity": 4.9011e-05, - "Frequency": 37.8409 - }, - { - "Time": 84, - "Intensity": 4.0321e-05, - "Frequency": 38.0706 - }, - { - "Time": 100, - "Intensity": 2.647e-05, - "Frequency": 38.1469 - }, - { - "Time": 117, - "Intensity": 1.4281e-05, - "Frequency": 38.0701 - }, - { - "Time": 134, - "Intensity": 5.3637e-06, - "Frequency": 37.917 - }, - { - "Time": 150, - "Intensity": 3.4715e-06, - "Frequency": 37.8405 - }, - { - "Time": 167, - "Intensity": 1.7078e-05, - "Frequency": 37.8406 - }, - { - "Time": 184, - "Intensity": 3.4403e-06, - "Frequency": 37.6101 - }, - { - "Time": 200, - "Intensity": 3.0648e-06, - "Frequency": 36.9629 - }, - { - "Time": 217, - "Intensity": 1.4176e-06, - "Frequency": 36.9629 - }, - { - "Time": 234, - "Intensity": 0, - "Frequency": 34.8347 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2021-10-18", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 0, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 40.1532 + }, + { + "Time": 11, + "Intensity": 0.38, + "Frequency": 70 + }, + { + "Time": 33, + "Intensity": 0.044387, + "Frequency": 37.3798 + }, + { + "Time": 43, + "Intensity": 0.58, + "Frequency": 37.2261 + }, + { + "Time": 53, + "Intensity": 0.12, + "Frequency": 38.4537 + }, + { + "Time": 84, + "Intensity": 0.93, + "Frequency": 47 + }, + { + "Time": 133, + "Intensity": 0.15797, + "Frequency": 37.8403 + }, + { + "Time": 149, + "Intensity": 1, + "Frequency": 42 + }, + { + "Time": 167, + "Intensity": 0.33416, + "Frequency": 37.8405 + }, + { + "Time": 188, + "Intensity": 1, + "Frequency": 37.9941 + }, + { + "Time": 200, + "Intensity": 0.37425, + "Frequency": 38.3774 + }, + { + "Time": 220, + "Intensity": 1, + "Frequency": 32 + }, + { + "Time": 233, + "Intensity": 0.46612, + "Frequency": 38.0703 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.0703 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 233, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.0703 + }, + { + "Time": 21, + "Intensity": 0.89, + "Frequency": 70 + }, + { + "Time": 50, + "Intensity": 0.2731, + "Frequency": 38.5306 + }, + { + "Time": 73, + "Intensity": 0.89, + "Frequency": 70 + }, + { + "Time": 84, + "Intensity": 0.40483, + "Frequency": 40.1155 + }, + { + "Time": 106, + "Intensity": 1, + "Frequency": 70 + }, + { + "Time": 117, + "Intensity": 0.44912, + "Frequency": 38.1477 + }, + { + "Time": 137, + "Intensity": 1, + "Frequency": 58 + }, + { + "Time": 150, + "Intensity": 0.50406, + "Frequency": 38.4543 + }, + { + "Time": 167, + "Intensity": 0.79268, + "Frequency": 38.1473 + }, + { + "Time": 184, + "Intensity": 0.53455, + "Frequency": 37.9174 + }, + { + "Time": 200, + "Intensity": 1, + "Frequency": 37.9172 + }, + { + "Time": 217, + "Intensity": 0.69526, + "Frequency": 38.1476 + }, + { + "Time": 234, + "Intensity": 0.8526, + "Frequency": 38.2243 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.4541 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 467, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.2243 + }, + { + "Time": 16, + "Intensity": 0.31475, + "Frequency": 38.4541 + }, + { + "Time": 33, + "Intensity": 1, + "Frequency": 38.2232 + }, + { + "Time": 50, + "Intensity": 0.44752, + "Frequency": 38.2232 + }, + { + "Time": 66, + "Intensity": 0.29572, + "Frequency": 37.8401 + }, + { + "Time": 83, + "Intensity": 0.64702, + "Frequency": 37.7634 + }, + { + "Time": 100, + "Intensity": 0.64717, + "Frequency": 37.3793 + }, + { + "Time": 116, + "Intensity": 0.3679, + "Frequency": 37.2258 + }, + { + "Time": 133, + "Intensity": 0.24298, + "Frequency": 37.4567 + }, + { + "Time": 150, + "Intensity": 0.55359, + "Frequency": 37.6872 + }, + { + "Time": 166, + "Intensity": 0.67465, + "Frequency": 37.5334 + }, + { + "Time": 183, + "Intensity": 0.62278, + "Frequency": 37.4566 + }, + { + "Time": 200, + "Intensity": 0.69885, + "Frequency": 37.303 + }, + { + "Time": 216, + "Intensity": 0.32678, + "Frequency": 37.2261 + }, + { + "Time": 233, + "Intensity": 0.535, + "Frequency": 37.0724 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 36.9954 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 700, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37.0724 + }, + { + "Time": 17, + "Intensity": 0.33735, + "Frequency": 36.9954 + }, + { + "Time": 33, + "Intensity": 0.65451, + "Frequency": 37.3029 + }, + { + "Time": 50, + "Intensity": 0.42331, + "Frequency": 37.6869 + }, + { + "Time": 67, + "Intensity": 0.24668, + "Frequency": 37.9943 + }, + { + "Time": 83, + "Intensity": 0.38753, + "Frequency": 37.9943 + }, + { + "Time": 100, + "Intensity": 0.11651, + "Frequency": 38.224 + }, + { + "Time": 117, + "Intensity": 0.1304, + "Frequency": 38.3772 + }, + { + "Time": 133, + "Intensity": 0.49327, + "Frequency": 38.2242 + }, + { + "Time": 150, + "Intensity": 0.22527, + "Frequency": 38.3776 + }, + { + "Time": 167, + "Intensity": 0.21292, + "Frequency": 38.684 + }, + { + "Time": 183, + "Intensity": 0.26452, + "Frequency": 38.9137 + }, + { + "Time": 200, + "Intensity": 0.21029, + "Frequency": 38.9136 + }, + { + "Time": 217, + "Intensity": 0.18462, + "Frequency": 38.6836 + }, + { + "Time": 233, + "Intensity": 0.1114, + "Frequency": 38.7602 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.9133 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 933, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.7602 + }, + { + "Time": 17, + "Intensity": 0.11051, + "Frequency": 38.9133 + }, + { + "Time": 32, + "Intensity": 0.37, + "Frequency": 40.9583 + }, + { + "Time": 50, + "Intensity": 0.080825, + "Frequency": 40.805 + }, + { + "Time": 66, + "Intensity": 0.6, + "Frequency": 40.4219 + }, + { + "Time": 84, + "Intensity": 0.11637, + "Frequency": 38.3007 + }, + { + "Time": 114, + "Intensity": 0.25, + "Frequency": 38.0706 + }, + { + "Time": 150, + "Intensity": 0.084815, + "Frequency": 37.994 + }, + { + "Time": 184, + "Intensity": 0.18, + "Frequency": 38.0707 + }, + { + "Time": 234, + "Intensity": 0.041641, + "Frequency": 38.0707 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.0707 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1167, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.0707 + }, + { + "Time": 16, + "Intensity": 0.23, + "Frequency": 38.0707 + }, + { + "Time": 33, + "Intensity": 0.049233, + "Frequency": 38.0709 + }, + { + "Time": 50, + "Intensity": 0.15, + "Frequency": 37.9175 + }, + { + "Time": 66, + "Intensity": 0.028695, + "Frequency": 37.9173 + }, + { + "Time": 96, + "Intensity": 0.08, + "Frequency": 38.0708 + }, + { + "Time": 133, + "Intensity": 0.046483, + "Frequency": 37.8408 + }, + { + "Time": 150, + "Intensity": 0.037565, + "Frequency": 37.8408 + }, + { + "Time": 166, + "Intensity": 0.037006, + "Frequency": 38.2244 + }, + { + "Time": 183, + "Intensity": 0.031955, + "Frequency": 38.0709 + }, + { + "Time": 200, + "Intensity": 0.043736, + "Frequency": 37.9943 + }, + { + "Time": 216, + "Intensity": 0.025359, + "Frequency": 37.8409 + }, + { + "Time": 233, + "Intensity": 0.027193, + "Frequency": 37.9943 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 37.9942 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1400, + "Parameters": { + "Intensity": 36, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37.9943 + }, + { + "Time": 15, + "Intensity": 0.18, + "Frequency": 37.9942 + }, + { + "Time": 33, + "Intensity": 0.018389, + "Frequency": 37.9942 + }, + { + "Time": 50, + "Intensity": 0.020258, + "Frequency": 37.9942 + }, + { + "Time": 76, + "Intensity": 0.11, + "Frequency": 37.9942 + }, + { + "Time": 117, + "Intensity": 0.016523, + "Frequency": 38.1475 + }, + { + "Time": 136, + "Intensity": 0.14, + "Frequency": 37.9172 + }, + { + "Time": 150, + "Intensity": 0.016324, + "Frequency": 37.8405 + }, + { + "Time": 167, + "Intensity": 0.016409, + "Frequency": 37.9173 + }, + { + "Time": 190, + "Intensity": 0.08, + "Frequency": 37.9173 + }, + { + "Time": 217, + "Intensity": 7.2853e-05, + "Frequency": 38.2236 + }, + { + "Time": 233, + "Intensity": 0.00010155, + "Frequency": 38.1472 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 38.3008 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 234, + "StartTime": 1633, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 38.1472 + }, + { + "Time": 17, + "Intensity": 7.2025e-05, + "Frequency": 38.3008 + }, + { + "Time": 34, + "Intensity": 4.4664e-05, + "Frequency": 38.0708 + }, + { + "Time": 50, + "Intensity": 5.4972e-05, + "Frequency": 38.0708 + }, + { + "Time": 67, + "Intensity": 4.9011e-05, + "Frequency": 37.8409 + }, + { + "Time": 84, + "Intensity": 4.0321e-05, + "Frequency": 38.0706 + }, + { + "Time": 100, + "Intensity": 2.647e-05, + "Frequency": 38.1469 + }, + { + "Time": 117, + "Intensity": 1.4281e-05, + "Frequency": 38.0701 + }, + { + "Time": 134, + "Intensity": 5.3637e-06, + "Frequency": 37.917 + }, + { + "Time": 150, + "Intensity": 3.4715e-06, + "Frequency": 37.8405 + }, + { + "Time": 167, + "Intensity": 1.7078e-05, + "Frequency": 37.8406 + }, + { + "Time": 184, + "Intensity": 3.4403e-06, + "Frequency": 37.6101 + }, + { + "Time": 200, + "Intensity": 3.0648e-06, + "Frequency": 36.9629 + }, + { + "Time": 217, + "Intensity": 1.4176e-06, + "Frequency": 36.9629 + }, + { + "Time": 234, + "Intensity": 0, + "Frequency": 34.8347 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Switch_App.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Switch_App.json index 5aec4af1572d90dc03d637f112080f115cce4390..3158c313a1f6ebc43784a9bde91756665bbfe6aa 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Switch_App.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Switch_App.json @@ -1,45 +1,45 @@ -{ - "Channels" : - [ - { - "Parameters" : - { - "Index" : 1 - }, - "Pattern" : - [ - { - "Event" : - { - "Parameters" : - { - "Frequency" : 100, - "Intensity" : 100 - }, - "StartTime" : 1000, - "Type" : "transient" - } - }, - { - "Event" : - { - "Parameters" : - { - "Frequency" : 100, - "Intensity" : 100 - }, - "StartTime" : 2750, - "Type" : "transient" - } - } - ] - } - ], - "MetaData" : - { - "ChannelNumber" : 1, - "Create" : "2023-03-17", - "Discription" : "A json file format demo", - "Version" : 1.0 - } -} +{ + "Channels" : + [ + { + "Parameters" : + { + "Index" : 1 + }, + "Pattern" : + [ + { + "Event" : + { + "Parameters" : + { + "Frequency" : 100, + "Intensity" : 100 + }, + "StartTime" : 1000, + "Type" : "transient" + } + }, + { + "Event" : + { + "Parameters" : + { + "Frequency" : 100, + "Intensity" : 100 + }, + "StartTime" : 2750, + "Type" : "transient" + } + } + ] + } + ], + "MetaData" : + { + "ChannelNumber" : 1, + "Create" : "2023-03-17", + "Discription" : "A json file format demo", + "Version" : 1.0 + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_h.json index 8483440ee1e7b78a1cc6c6ca11c11a30ef22109d..2ad20b42837391f5999b375f1417fd646529a23b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_h.json @@ -1,97 +1,97 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 76, - "Parameters": { - "Intensity": 50, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 150, - "Parameters": { - "Intensity": 98, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 449, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 617, - "Parameters": { - "Intensity": 98, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 955, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1157, - "Parameters": { - "Intensity": 98, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1346, - "Parameters": { - "Intensity": 60, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1567, - "Parameters": { - "Intensity": 98, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 76, + "Parameters": { + "Intensity": 50, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 150, + "Parameters": { + "Intensity": 98, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 449, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 617, + "Parameters": { + "Intensity": 98, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 955, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1157, + "Parameters": { + "Intensity": 98, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1346, + "Parameters": { + "Intensity": 60, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1567, + "Parameters": { + "Intensity": 98, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_l.json index d5f2ab7938f01db3c2a7e581f5eb079012289357..58b724bf3b9fa3add5520b50fd8da5d83cc1f1bb 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_l.json @@ -1,97 +1,97 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 76, - "Parameters": { - "Intensity": 30, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 150, - "Parameters": { - "Intensity": 58, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 449, - "Parameters": { - "Intensity": 36, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 617, - "Parameters": { - "Intensity": 58, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 955, - "Parameters": { - "Intensity": 36, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1157, - "Parameters": { - "Intensity": 58, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1346, - "Parameters": { - "Intensity": 36, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1567, - "Parameters": { - "Intensity": 58, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 76, + "Parameters": { + "Intensity": 30, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 150, + "Parameters": { + "Intensity": 58, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 449, + "Parameters": { + "Intensity": 36, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 617, + "Parameters": { + "Intensity": 58, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 955, + "Parameters": { + "Intensity": 36, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1157, + "Parameters": { + "Intensity": 58, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1346, + "Parameters": { + "Intensity": 36, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1567, + "Parameters": { + "Intensity": 58, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_m.json index b6dedfbe36377aa1d4a864304eb1adc715f6a023..4cd8439f3e666391113ce0ee217e7a85a4f418f0 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/TableTennis_m.json @@ -1,97 +1,97 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 76, - "Parameters": { - "Intensity": 40, - "Frequency": 30 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 150, - "Parameters": { - "Intensity": 78, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 449, - "Parameters": { - "Intensity": 48, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 617, - "Parameters": { - "Intensity": 78, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 955, - "Parameters": { - "Intensity": 48, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1157, - "Parameters": { - "Intensity": 78, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1346, - "Parameters": { - "Intensity": 48, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1567, - "Parameters": { - "Intensity": 78, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 76, + "Parameters": { + "Intensity": 40, + "Frequency": 30 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 150, + "Parameters": { + "Intensity": 78, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 449, + "Parameters": { + "Intensity": 48, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 617, + "Parameters": { + "Intensity": 78, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 955, + "Parameters": { + "Intensity": 48, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1157, + "Parameters": { + "Intensity": 78, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1346, + "Parameters": { + "Intensity": 48, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1567, + "Parameters": { + "Intensity": 78, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_h.json index 72ac4eaf491704286d10fe17edbe29b5945ca9c5..091dcb83529b7d530560a66d32ad314682f0de4f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_h.json @@ -1,170 +1,170 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 43, - "StartTime": 0, - "Parameters": { - "Intensity": 100, - "Frequency": 59, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": -63 - }, - { - "Time": 37, - "Intensity": 1, - "Frequency": 53 - }, - { - "Time": 43, - "Intensity": 0, - "Frequency": -77 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 64, - "Parameters": { - "Intensity": 100, - "Frequency": 88 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 130, - "Parameters": { - "Intensity": 78, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 163, - "Parameters": { - "Intensity": 46, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 197, - "Parameters": { - "Intensity": 60, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 256, - "Parameters": { - "Intensity": 45, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 280, - "Parameters": { - "Intensity": 23, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 339, - "Parameters": { - "Intensity": 39, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 397, - "Parameters": { - "Intensity": 25, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 585, - "Parameters": { - "Intensity": 49, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 617, - "Parameters": { - "Intensity": 35, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 652, - "Parameters": { - "Intensity": 25, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 687, - "Parameters": { - "Intensity": 18, - "Frequency": 95 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 43, + "StartTime": 0, + "Parameters": { + "Intensity": 100, + "Frequency": 59, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": -63 + }, + { + "Time": 37, + "Intensity": 1, + "Frequency": 53 + }, + { + "Time": 43, + "Intensity": 0, + "Frequency": -77 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 64, + "Parameters": { + "Intensity": 100, + "Frequency": 88 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 130, + "Parameters": { + "Intensity": 78, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 163, + "Parameters": { + "Intensity": 46, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 197, + "Parameters": { + "Intensity": 60, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 256, + "Parameters": { + "Intensity": 45, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 280, + "Parameters": { + "Intensity": 23, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 339, + "Parameters": { + "Intensity": 39, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 397, + "Parameters": { + "Intensity": 25, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 585, + "Parameters": { + "Intensity": 49, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 617, + "Parameters": { + "Intensity": 35, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 652, + "Parameters": { + "Intensity": 25, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 687, + "Parameters": { + "Intensity": 18, + "Frequency": 95 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_l.json index 657576d7c96d77886d789207d5157b5963234dfb..70f1786a5216171922336496092d4548d567c9ee 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_l.json @@ -1,170 +1,170 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 43, - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 59, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": -63 - }, - { - "Time": 37, - "Intensity": 1, - "Frequency": 53 - }, - { - "Time": 43, - "Intensity": 0, - "Frequency": -77 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 64, - "Parameters": { - "Intensity": 60, - "Frequency": 88 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 130, - "Parameters": { - "Intensity": 46, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 163, - "Parameters": { - "Intensity": 27, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 197, - "Parameters": { - "Intensity": 36, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 256, - "Parameters": { - "Intensity": 27, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 280, - "Parameters": { - "Intensity": 13, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 339, - "Parameters": { - "Intensity": 23, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 397, - "Parameters": { - "Intensity": 15, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 585, - "Parameters": { - "Intensity": 29, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 617, - "Parameters": { - "Intensity": 21, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 652, - "Parameters": { - "Intensity": 15, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 687, - "Parameters": { - "Intensity": 10, - "Frequency": 95 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 43, + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 59, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": -63 + }, + { + "Time": 37, + "Intensity": 1, + "Frequency": 53 + }, + { + "Time": 43, + "Intensity": 0, + "Frequency": -77 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 64, + "Parameters": { + "Intensity": 60, + "Frequency": 88 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 130, + "Parameters": { + "Intensity": 46, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 163, + "Parameters": { + "Intensity": 27, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 197, + "Parameters": { + "Intensity": 36, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 256, + "Parameters": { + "Intensity": 27, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 280, + "Parameters": { + "Intensity": 13, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 339, + "Parameters": { + "Intensity": 23, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 397, + "Parameters": { + "Intensity": 15, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 585, + "Parameters": { + "Intensity": 29, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 617, + "Parameters": { + "Intensity": 21, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 652, + "Parameters": { + "Intensity": 15, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 687, + "Parameters": { + "Intensity": 10, + "Frequency": 95 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_m.json index d805be87d0c466355815b5997bf080a3f484a2ae..fb8aa7a894359d4d609da32dcbc59dfb287db3f8 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tambourine_m.json @@ -1,170 +1,170 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 43, - "StartTime": 0, - "Parameters": { - "Intensity": 80, - "Frequency": 59, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": -63 - }, - { - "Time": 37, - "Intensity": 1, - "Frequency": 53 - }, - { - "Time": 43, - "Intensity": 0, - "Frequency": -77 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 64, - "Parameters": { - "Intensity": 80, - "Frequency": 88 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 130, - "Parameters": { - "Intensity": 62, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 163, - "Parameters": { - "Intensity": 36, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 197, - "Parameters": { - "Intensity": 48, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 256, - "Parameters": { - "Intensity": 36, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 280, - "Parameters": { - "Intensity": 18, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 339, - "Parameters": { - "Intensity": 31, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 397, - "Parameters": { - "Intensity": 20, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 585, - "Parameters": { - "Intensity": 39, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 617, - "Parameters": { - "Intensity": 28, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 652, - "Parameters": { - "Intensity": 20, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 687, - "Parameters": { - "Intensity": 14, - "Frequency": 95 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 43, + "StartTime": 0, + "Parameters": { + "Intensity": 80, + "Frequency": 59, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": -63 + }, + { + "Time": 37, + "Intensity": 1, + "Frequency": 53 + }, + { + "Time": 43, + "Intensity": 0, + "Frequency": -77 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 64, + "Parameters": { + "Intensity": 80, + "Frequency": 88 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 130, + "Parameters": { + "Intensity": 62, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 163, + "Parameters": { + "Intensity": 36, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 197, + "Parameters": { + "Intensity": 48, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 256, + "Parameters": { + "Intensity": 36, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 280, + "Parameters": { + "Intensity": 18, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 339, + "Parameters": { + "Intensity": 31, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 397, + "Parameters": { + "Intensity": 20, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 585, + "Parameters": { + "Intensity": 39, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 617, + "Parameters": { + "Intensity": 28, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 652, + "Parameters": { + "Intensity": 20, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 687, + "Parameters": { + "Intensity": 14, + "Frequency": 95 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_h.json index 99d7fac13fe6f8582844cb38f8172b126a6f6356..b8c1c06e3304cf78369a74be52c8995fb3fb65f7 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_h.json @@ -1,989 +1,989 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 145, - "Parameters": { - "Intensity": 60, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 37, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 39, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 220, - "Parameters": { - "Intensity": 53, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 124, - "StartTime": 324, - "Parameters": { - "Intensity": 96, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 65, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 124, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 349, - "Parameters": { - "Intensity": 95, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 123, - "StartTime": 358, - "Parameters": { - "Intensity": 100, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 123, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 533, - "Parameters": { - "Intensity": 92, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 578, - "Parameters": { - "Intensity": 51, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 734, - "Parameters": { - "Intensity": 60, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 756, - "Parameters": { - "Intensity": 97, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 70, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 152, - "StartTime": 786, - "Parameters": { - "Intensity": 100, - "Frequency": 76, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 77, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 152, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 975, - "Parameters": { - "Intensity": 91, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1022, - "Parameters": { - "Intensity": 97, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1076, - "Parameters": { - "Intensity": 81, - "Frequency": 72 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1155, - "Parameters": { - "Intensity": 71, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1185, - "Parameters": { - "Intensity": 86, - "Frequency": 63 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 63, - "StartTime": 1350, - "Parameters": { - "Intensity": 57, - "Frequency": 41, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 26, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 33, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 63, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1418, - "Parameters": { - "Intensity": 68, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 60, - "StartTime": 1561, - "Parameters": { - "Intensity": 57, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 30, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 32, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 60, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1630, - "Parameters": { - "Intensity": 44, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1693, - "Parameters": { - "Intensity": 29, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1830, - "Parameters": { - "Intensity": 25, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 34, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1916, - "Parameters": { - "Intensity": 60, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1958, - "Parameters": { - "Intensity": 29, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 165, - "StartTime": 2072, - "Parameters": { - "Intensity": 100, - "Frequency": 65, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 28, - "Intensity": 0.21, - "Frequency": -30 - }, - { - "Time": 36, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 128, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 165, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 323, - "StartTime": 2249, - "Parameters": { - "Intensity": 100, - "Frequency": 69, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 2, - "Intensity": 0.71, - "Frequency": -30 - }, - { - "Time": 137, - "Intensity": 0.11, - "Frequency": 36 - }, - { - "Time": 323, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2384, - "Parameters": { - "Intensity": 78, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2477, - "Parameters": { - "Intensity": 59, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 103, - "StartTime": 2492, - "Parameters": { - "Intensity": 54, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 51, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 103, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2689, - "Parameters": { - "Intensity": 69, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2761, - "Parameters": { - "Intensity": 56, - "Frequency": 78 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 104, - "StartTime": 2895, - "Parameters": { - "Intensity": 86, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 47, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 104, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3011, - "Parameters": { - "Intensity": 50, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3101, - "Parameters": { - "Intensity": 33, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 3189, - "Parameters": { - "Intensity": 62, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 40, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 101, - "StartTime": 3209, - "Parameters": { - "Intensity": 48, - "Frequency": 53, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 51, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 101, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3388, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3439, - "Parameters": { - "Intensity": 32, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 52, - "StartTime": 3512, - "Parameters": { - "Intensity": 40, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 26, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 52, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3655, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 3755, - "Parameters": { - "Intensity": 91, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 70, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3929, - "Parameters": { - "Intensity": 97, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4024, - "Parameters": { - "Intensity": 65, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 119, - "StartTime": 4133, - "Parameters": { - "Intensity": 100, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 62, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 119, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4134, - "Parameters": { - "Intensity": 88, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4272, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4327, - "Parameters": { - "Intensity": 32, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4484, - "Parameters": { - "Intensity": 39, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4526, - "Parameters": { - "Intensity": 53, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 4613, - "Parameters": { - "Intensity": 40, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 41, - "Intensity": 0.45, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4832, - "Parameters": { - "Intensity": 43, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4863, - "Parameters": { - "Intensity": 31, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5041, - "Parameters": { - "Intensity": 30, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 85, - "StartTime": 5155, - "Parameters": { - "Intensity": 21, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 44, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 85, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 145, + "Parameters": { + "Intensity": 60, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 37, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 39, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 220, + "Parameters": { + "Intensity": 53, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 124, + "StartTime": 324, + "Parameters": { + "Intensity": 96, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 65, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 124, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 349, + "Parameters": { + "Intensity": 95, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 123, + "StartTime": 358, + "Parameters": { + "Intensity": 100, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 123, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 533, + "Parameters": { + "Intensity": 92, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 578, + "Parameters": { + "Intensity": 51, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 734, + "Parameters": { + "Intensity": 60, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 756, + "Parameters": { + "Intensity": 97, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 70, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 152, + "StartTime": 786, + "Parameters": { + "Intensity": 100, + "Frequency": 76, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 77, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 152, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 975, + "Parameters": { + "Intensity": 91, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1022, + "Parameters": { + "Intensity": 97, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1076, + "Parameters": { + "Intensity": 81, + "Frequency": 72 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1155, + "Parameters": { + "Intensity": 71, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1185, + "Parameters": { + "Intensity": 86, + "Frequency": 63 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 63, + "StartTime": 1350, + "Parameters": { + "Intensity": 57, + "Frequency": 41, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 26, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 33, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 63, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1418, + "Parameters": { + "Intensity": 68, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 60, + "StartTime": 1561, + "Parameters": { + "Intensity": 57, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 30, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 32, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 60, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1630, + "Parameters": { + "Intensity": 44, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1693, + "Parameters": { + "Intensity": 29, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1830, + "Parameters": { + "Intensity": 25, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 34, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1916, + "Parameters": { + "Intensity": 60, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1958, + "Parameters": { + "Intensity": 29, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 165, + "StartTime": 2072, + "Parameters": { + "Intensity": 100, + "Frequency": 65, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 28, + "Intensity": 0.21, + "Frequency": -30 + }, + { + "Time": 36, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 128, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 165, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 323, + "StartTime": 2249, + "Parameters": { + "Intensity": 100, + "Frequency": 69, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 2, + "Intensity": 0.71, + "Frequency": -30 + }, + { + "Time": 137, + "Intensity": 0.11, + "Frequency": 36 + }, + { + "Time": 323, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2384, + "Parameters": { + "Intensity": 78, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2477, + "Parameters": { + "Intensity": 59, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 103, + "StartTime": 2492, + "Parameters": { + "Intensity": 54, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 51, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 103, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2689, + "Parameters": { + "Intensity": 69, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2761, + "Parameters": { + "Intensity": 56, + "Frequency": 78 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 104, + "StartTime": 2895, + "Parameters": { + "Intensity": 86, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 47, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 104, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3011, + "Parameters": { + "Intensity": 50, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3101, + "Parameters": { + "Intensity": 33, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 3189, + "Parameters": { + "Intensity": 62, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 40, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 101, + "StartTime": 3209, + "Parameters": { + "Intensity": 48, + "Frequency": 53, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 51, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 101, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3388, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3439, + "Parameters": { + "Intensity": 32, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 52, + "StartTime": 3512, + "Parameters": { + "Intensity": 40, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 26, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 52, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3655, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 3755, + "Parameters": { + "Intensity": 91, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 70, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3929, + "Parameters": { + "Intensity": 97, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4024, + "Parameters": { + "Intensity": 65, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 119, + "StartTime": 4133, + "Parameters": { + "Intensity": 100, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 62, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 119, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4134, + "Parameters": { + "Intensity": 88, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4272, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4327, + "Parameters": { + "Intensity": 32, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4484, + "Parameters": { + "Intensity": 39, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4526, + "Parameters": { + "Intensity": 53, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 4613, + "Parameters": { + "Intensity": 40, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 41, + "Intensity": 0.45, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4832, + "Parameters": { + "Intensity": 43, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4863, + "Parameters": { + "Intensity": 31, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5041, + "Parameters": { + "Intensity": 30, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 85, + "StartTime": 5155, + "Parameters": { + "Intensity": 21, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 44, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 85, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_l.json index 41804cdae87fd48439a35fafa328420283e207c1..882fda7fd32d935086e900683e9820589df4ac18 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_l.json @@ -1,989 +1,989 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 145, - "Parameters": { - "Intensity": 36, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 37, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 39, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 220, - "Parameters": { - "Intensity": 31, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 124, - "StartTime": 324, - "Parameters": { - "Intensity": 57, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 65, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 124, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 349, - "Parameters": { - "Intensity": 57, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 123, - "StartTime": 358, - "Parameters": { - "Intensity": 60, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 123, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 533, - "Parameters": { - "Intensity": 55, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 578, - "Parameters": { - "Intensity": 30, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 734, - "Parameters": { - "Intensity": 36, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 756, - "Parameters": { - "Intensity": 58, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 70, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 152, - "StartTime": 786, - "Parameters": { - "Intensity": 60, - "Frequency": 76, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 77, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 152, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 975, - "Parameters": { - "Intensity": 54, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1022, - "Parameters": { - "Intensity": 58, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1076, - "Parameters": { - "Intensity": 48, - "Frequency": 72 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1155, - "Parameters": { - "Intensity": 42, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1185, - "Parameters": { - "Intensity": 51, - "Frequency": 63 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 63, - "StartTime": 1350, - "Parameters": { - "Intensity": 34, - "Frequency": 41, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 26, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 33, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 63, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1418, - "Parameters": { - "Intensity": 40, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 60, - "StartTime": 1561, - "Parameters": { - "Intensity": 34, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 30, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 32, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 60, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1630, - "Parameters": { - "Intensity": 26, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1693, - "Parameters": { - "Intensity": 17, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1830, - "Parameters": { - "Intensity": 15, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 34, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1916, - "Parameters": { - "Intensity": 36, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1958, - "Parameters": { - "Intensity": 17, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 165, - "StartTime": 2072, - "Parameters": { - "Intensity": 60, - "Frequency": 65, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 28, - "Intensity": 0.21, - "Frequency": -30 - }, - { - "Time": 36, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 128, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 165, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 323, - "StartTime": 2249, - "Parameters": { - "Intensity": 60, - "Frequency": 69, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 2, - "Intensity": 0.71, - "Frequency": -30 - }, - { - "Time": 137, - "Intensity": 0.11, - "Frequency": 36 - }, - { - "Time": 323, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2384, - "Parameters": { - "Intensity": 46, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2477, - "Parameters": { - "Intensity": 35, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 103, - "StartTime": 2492, - "Parameters": { - "Intensity": 32, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 51, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 103, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2689, - "Parameters": { - "Intensity": 41, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2761, - "Parameters": { - "Intensity": 33, - "Frequency": 78 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 104, - "StartTime": 2895, - "Parameters": { - "Intensity": 51, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 47, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 104, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3011, - "Parameters": { - "Intensity": 30, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3101, - "Parameters": { - "Intensity": 19, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 3189, - "Parameters": { - "Intensity": 37, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 40, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 101, - "StartTime": 3209, - "Parameters": { - "Intensity": 28, - "Frequency": 53, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 51, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 101, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3388, - "Parameters": { - "Intensity": 23, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3439, - "Parameters": { - "Intensity": 19, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 52, - "StartTime": 3512, - "Parameters": { - "Intensity": 24, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 26, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 52, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3655, - "Parameters": { - "Intensity": 25, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 3755, - "Parameters": { - "Intensity": 54, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 70, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3929, - "Parameters": { - "Intensity": 58, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4024, - "Parameters": { - "Intensity": 39, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 119, - "StartTime": 4133, - "Parameters": { - "Intensity": 60, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 62, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 119, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4134, - "Parameters": { - "Intensity": 52, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4272, - "Parameters": { - "Intensity": 23, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4327, - "Parameters": { - "Intensity": 19, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4484, - "Parameters": { - "Intensity": 23, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4526, - "Parameters": { - "Intensity": 31, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 4613, - "Parameters": { - "Intensity": 24, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 41, - "Intensity": 0.45, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4832, - "Parameters": { - "Intensity": 25, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4863, - "Parameters": { - "Intensity": 18, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5041, - "Parameters": { - "Intensity": 18, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 85, - "StartTime": 5155, - "Parameters": { - "Intensity": 12, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 44, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 85, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 145, + "Parameters": { + "Intensity": 36, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 37, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 39, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 220, + "Parameters": { + "Intensity": 31, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 124, + "StartTime": 324, + "Parameters": { + "Intensity": 57, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 65, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 124, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 349, + "Parameters": { + "Intensity": 57, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 123, + "StartTime": 358, + "Parameters": { + "Intensity": 60, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 123, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 533, + "Parameters": { + "Intensity": 55, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 578, + "Parameters": { + "Intensity": 30, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 734, + "Parameters": { + "Intensity": 36, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 756, + "Parameters": { + "Intensity": 58, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 70, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 152, + "StartTime": 786, + "Parameters": { + "Intensity": 60, + "Frequency": 76, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 77, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 152, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 975, + "Parameters": { + "Intensity": 54, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1022, + "Parameters": { + "Intensity": 58, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1076, + "Parameters": { + "Intensity": 48, + "Frequency": 72 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1155, + "Parameters": { + "Intensity": 42, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1185, + "Parameters": { + "Intensity": 51, + "Frequency": 63 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 63, + "StartTime": 1350, + "Parameters": { + "Intensity": 34, + "Frequency": 41, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 26, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 33, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 63, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1418, + "Parameters": { + "Intensity": 40, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 60, + "StartTime": 1561, + "Parameters": { + "Intensity": 34, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 30, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 32, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 60, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1630, + "Parameters": { + "Intensity": 26, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1693, + "Parameters": { + "Intensity": 17, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1830, + "Parameters": { + "Intensity": 15, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 34, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1916, + "Parameters": { + "Intensity": 36, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1958, + "Parameters": { + "Intensity": 17, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 165, + "StartTime": 2072, + "Parameters": { + "Intensity": 60, + "Frequency": 65, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 28, + "Intensity": 0.21, + "Frequency": -30 + }, + { + "Time": 36, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 128, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 165, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 323, + "StartTime": 2249, + "Parameters": { + "Intensity": 60, + "Frequency": 69, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 2, + "Intensity": 0.71, + "Frequency": -30 + }, + { + "Time": 137, + "Intensity": 0.11, + "Frequency": 36 + }, + { + "Time": 323, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2384, + "Parameters": { + "Intensity": 46, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2477, + "Parameters": { + "Intensity": 35, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 103, + "StartTime": 2492, + "Parameters": { + "Intensity": 32, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 51, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 103, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2689, + "Parameters": { + "Intensity": 41, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2761, + "Parameters": { + "Intensity": 33, + "Frequency": 78 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 104, + "StartTime": 2895, + "Parameters": { + "Intensity": 51, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 47, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 104, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3011, + "Parameters": { + "Intensity": 30, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3101, + "Parameters": { + "Intensity": 19, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 3189, + "Parameters": { + "Intensity": 37, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 40, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 101, + "StartTime": 3209, + "Parameters": { + "Intensity": 28, + "Frequency": 53, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 51, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 101, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3388, + "Parameters": { + "Intensity": 23, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3439, + "Parameters": { + "Intensity": 19, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 52, + "StartTime": 3512, + "Parameters": { + "Intensity": 24, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 26, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 52, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3655, + "Parameters": { + "Intensity": 25, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 3755, + "Parameters": { + "Intensity": 54, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 70, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3929, + "Parameters": { + "Intensity": 58, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4024, + "Parameters": { + "Intensity": 39, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 119, + "StartTime": 4133, + "Parameters": { + "Intensity": 60, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 62, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 119, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4134, + "Parameters": { + "Intensity": 52, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4272, + "Parameters": { + "Intensity": 23, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4327, + "Parameters": { + "Intensity": 19, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4484, + "Parameters": { + "Intensity": 23, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4526, + "Parameters": { + "Intensity": 31, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 4613, + "Parameters": { + "Intensity": 24, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 41, + "Intensity": 0.45, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4832, + "Parameters": { + "Intensity": 25, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4863, + "Parameters": { + "Intensity": 18, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5041, + "Parameters": { + "Intensity": 18, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 85, + "StartTime": 5155, + "Parameters": { + "Intensity": 12, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 44, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 85, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_m.json index 04bd203808ef1cf38a7f353823c9e191387c08db..78d575bf9e924df5f6443d48fc6428e48d6fcaf3 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Thunder_m.json @@ -1,989 +1,989 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 145, - "Parameters": { - "Intensity": 48, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 37, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 39, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 220, - "Parameters": { - "Intensity": 42, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 124, - "StartTime": 324, - "Parameters": { - "Intensity": 76, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 65, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 124, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 349, - "Parameters": { - "Intensity": 76, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 123, - "StartTime": 358, - "Parameters": { - "Intensity": 80, - "Frequency": 73, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.12, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 123, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 533, - "Parameters": { - "Intensity": 73, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 578, - "Parameters": { - "Intensity": 40, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 734, - "Parameters": { - "Intensity": 48, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 756, - "Parameters": { - "Intensity": 77, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 70, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 152, - "StartTime": 786, - "Parameters": { - "Intensity": 80, - "Frequency": 76, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 77, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 79, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 152, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 975, - "Parameters": { - "Intensity": 72, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1022, - "Parameters": { - "Intensity": 77, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1076, - "Parameters": { - "Intensity": 64, - "Frequency": 72 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1155, - "Parameters": { - "Intensity": 56, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1185, - "Parameters": { - "Intensity": 68, - "Frequency": 63 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 63, - "StartTime": 1350, - "Parameters": { - "Intensity": 45, - "Frequency": 41, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 26, - "Intensity": 0.1, - "Frequency": 0 - }, - { - "Time": 33, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 63, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1418, - "Parameters": { - "Intensity": 54, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 60, - "StartTime": 1561, - "Parameters": { - "Intensity": 45, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 30, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 32, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 60, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1630, - "Parameters": { - "Intensity": 35, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1693, - "Parameters": { - "Intensity": 23, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 64, - "StartTime": 1830, - "Parameters": { - "Intensity": 20, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 33, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 34, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 64, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1916, - "Parameters": { - "Intensity": 48, - "Frequency": 70 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1958, - "Parameters": { - "Intensity": 23, - "Frequency": 65 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 165, - "StartTime": 2072, - "Parameters": { - "Intensity": 80, - "Frequency": 65, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 28, - "Intensity": 0.21, - "Frequency": -30 - }, - { - "Time": 36, - "Intensity": 1, - "Frequency": 5 - }, - { - "Time": 128, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 165, - "Intensity": 0, - "Frequency": -30 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 323, - "StartTime": 2249, - "Parameters": { - "Intensity": 80, - "Frequency": 69, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 2, - "Intensity": 0.71, - "Frequency": -30 - }, - { - "Time": 137, - "Intensity": 0.11, - "Frequency": 36 - }, - { - "Time": 323, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2384, - "Parameters": { - "Intensity": 62, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2477, - "Parameters": { - "Intensity": 47, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 103, - "StartTime": 2492, - "Parameters": { - "Intensity": 43, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 51, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 103, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2689, - "Parameters": { - "Intensity": 55, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2761, - "Parameters": { - "Intensity": 44, - "Frequency": 78 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 104, - "StartTime": 2895, - "Parameters": { - "Intensity": 68, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 47, - "Intensity": 0.2, - "Frequency": 0 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 104, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3011, - "Parameters": { - "Intensity": 40, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3101, - "Parameters": { - "Intensity": 26, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 3189, - "Parameters": { - "Intensity": 49, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 40, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 101, - "StartTime": 3209, - "Parameters": { - "Intensity": 38, - "Frequency": 53, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 51, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 52, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 101, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3388, - "Parameters": { - "Intensity": 31, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3439, - "Parameters": { - "Intensity": 25, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 52, - "StartTime": 3512, - "Parameters": { - "Intensity": 32, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 26, - "Intensity": 0.15, - "Frequency": 0 - }, - { - "Time": 27, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 52, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3655, - "Parameters": { - "Intensity": 33, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 138, - "StartTime": 3755, - "Parameters": { - "Intensity": 72, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 70, - "Intensity": 0.13, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 138, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3929, - "Parameters": { - "Intensity": 77, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4024, - "Parameters": { - "Intensity": 52, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 119, - "StartTime": 4133, - "Parameters": { - "Intensity": 80, - "Frequency": 64, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 54, - "Intensity": 0.11, - "Frequency": 0 - }, - { - "Time": 62, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 119, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4134, - "Parameters": { - "Intensity": 70, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4272, - "Parameters": { - "Intensity": 31, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4327, - "Parameters": { - "Intensity": 25, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4484, - "Parameters": { - "Intensity": 31, - "Frequency": 75 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4526, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 80, - "StartTime": 4613, - "Parameters": { - "Intensity": 32, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 41, - "Intensity": 0.45, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 80, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4832, - "Parameters": { - "Intensity": 34, - "Frequency": 74 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 4863, - "Parameters": { - "Intensity": 24, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 5041, - "Parameters": { - "Intensity": 24, - "Frequency": 56 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 85, - "StartTime": 5155, - "Parameters": { - "Intensity": 16, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 25 - }, - { - "Time": 44, - "Intensity": 0.19, - "Frequency": 0 - }, - { - "Time": 45, - "Intensity": 1, - "Frequency": 50 - }, - { - "Time": 85, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 145, + "Parameters": { + "Intensity": 48, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 37, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 39, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 220, + "Parameters": { + "Intensity": 42, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 124, + "StartTime": 324, + "Parameters": { + "Intensity": 76, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 65, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 124, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 349, + "Parameters": { + "Intensity": 76, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 123, + "StartTime": 358, + "Parameters": { + "Intensity": 80, + "Frequency": 73, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.12, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 123, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 533, + "Parameters": { + "Intensity": 73, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 578, + "Parameters": { + "Intensity": 40, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 734, + "Parameters": { + "Intensity": 48, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 756, + "Parameters": { + "Intensity": 77, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 70, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 152, + "StartTime": 786, + "Parameters": { + "Intensity": 80, + "Frequency": 76, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 77, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 79, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 152, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 975, + "Parameters": { + "Intensity": 72, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1022, + "Parameters": { + "Intensity": 77, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1076, + "Parameters": { + "Intensity": 64, + "Frequency": 72 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1155, + "Parameters": { + "Intensity": 56, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1185, + "Parameters": { + "Intensity": 68, + "Frequency": 63 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 63, + "StartTime": 1350, + "Parameters": { + "Intensity": 45, + "Frequency": 41, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 26, + "Intensity": 0.1, + "Frequency": 0 + }, + { + "Time": 33, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 63, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1418, + "Parameters": { + "Intensity": 54, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 60, + "StartTime": 1561, + "Parameters": { + "Intensity": 45, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 30, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 32, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 60, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1630, + "Parameters": { + "Intensity": 35, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1693, + "Parameters": { + "Intensity": 23, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 64, + "StartTime": 1830, + "Parameters": { + "Intensity": 20, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 33, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 34, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 64, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1916, + "Parameters": { + "Intensity": 48, + "Frequency": 70 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1958, + "Parameters": { + "Intensity": 23, + "Frequency": 65 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 165, + "StartTime": 2072, + "Parameters": { + "Intensity": 80, + "Frequency": 65, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 28, + "Intensity": 0.21, + "Frequency": -30 + }, + { + "Time": 36, + "Intensity": 1, + "Frequency": 5 + }, + { + "Time": 128, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 165, + "Intensity": 0, + "Frequency": -30 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 323, + "StartTime": 2249, + "Parameters": { + "Intensity": 80, + "Frequency": 69, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 2, + "Intensity": 0.71, + "Frequency": -30 + }, + { + "Time": 137, + "Intensity": 0.11, + "Frequency": 36 + }, + { + "Time": 323, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2384, + "Parameters": { + "Intensity": 62, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2477, + "Parameters": { + "Intensity": 47, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 103, + "StartTime": 2492, + "Parameters": { + "Intensity": 43, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 51, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 103, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2689, + "Parameters": { + "Intensity": 55, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2761, + "Parameters": { + "Intensity": 44, + "Frequency": 78 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 104, + "StartTime": 2895, + "Parameters": { + "Intensity": 68, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 47, + "Intensity": 0.2, + "Frequency": 0 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 104, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3011, + "Parameters": { + "Intensity": 40, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3101, + "Parameters": { + "Intensity": 26, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 3189, + "Parameters": { + "Intensity": 49, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 40, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 101, + "StartTime": 3209, + "Parameters": { + "Intensity": 38, + "Frequency": 53, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 51, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 52, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 101, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3388, + "Parameters": { + "Intensity": 31, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3439, + "Parameters": { + "Intensity": 25, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 52, + "StartTime": 3512, + "Parameters": { + "Intensity": 32, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 26, + "Intensity": 0.15, + "Frequency": 0 + }, + { + "Time": 27, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 52, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3655, + "Parameters": { + "Intensity": 33, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 138, + "StartTime": 3755, + "Parameters": { + "Intensity": 72, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 70, + "Intensity": 0.13, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 138, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3929, + "Parameters": { + "Intensity": 77, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4024, + "Parameters": { + "Intensity": 52, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 119, + "StartTime": 4133, + "Parameters": { + "Intensity": 80, + "Frequency": 64, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 54, + "Intensity": 0.11, + "Frequency": 0 + }, + { + "Time": 62, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 119, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4134, + "Parameters": { + "Intensity": 70, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4272, + "Parameters": { + "Intensity": 31, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4327, + "Parameters": { + "Intensity": 25, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4484, + "Parameters": { + "Intensity": 31, + "Frequency": 75 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4526, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 80, + "StartTime": 4613, + "Parameters": { + "Intensity": 32, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 41, + "Intensity": 0.45, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 80, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4832, + "Parameters": { + "Intensity": 34, + "Frequency": 74 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 4863, + "Parameters": { + "Intensity": 24, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 5041, + "Parameters": { + "Intensity": 24, + "Frequency": 56 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 85, + "StartTime": 5155, + "Parameters": { + "Intensity": 16, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 25 + }, + { + "Time": 44, + "Intensity": 0.19, + "Frequency": 0 + }, + { + "Time": 45, + "Intensity": 1, + "Frequency": 50 + }, + { + "Time": 85, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_h.json index d8a4f9ff6c2448f42988476b6dff69218c2ce4b2..1a62e2eb5f2e81133edc6f179aefc0cf8033ddac 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_h.json @@ -1,357 +1,357 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 96, - "Parameters": { - "Intensity": 100, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 37, - "Intensity": 0.94, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.68, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 101, - "StartTime": 193, - "Parameters": { - "Intensity": 69, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.89, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 432, - "StartTime": 298, - "Parameters": { - "Intensity": 70, - "Frequency": 7, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 21, - "Intensity": 0.03, - "Frequency": 31 - }, - { - "Time": 45, - "Intensity": 0.12, - "Frequency": 31 - }, - { - "Time": 74, - "Intensity": 0.26, - "Frequency": 30 - }, - { - "Time": 107, - "Intensity": 0.62, - "Frequency": 30 - }, - { - "Time": 135, - "Intensity": 0.48, - "Frequency": 29 - }, - { - "Time": 166, - "Intensity": 0.23, - "Frequency": 29 - }, - { - "Time": 210, - "Intensity": 0.31, - "Frequency": 30 - }, - { - "Time": 232, - "Intensity": 0.38, - "Frequency": 30 - }, - { - "Time": 265, - "Intensity": 0.15, - "Frequency": 30 - }, - { - "Time": 294, - "Intensity": 0.07, - "Frequency": 30 - }, - { - "Time": 315, - "Intensity": 0.03, - "Frequency": 30 - }, - { - "Time": 340, - "Intensity": 0.01, - "Frequency": 29 - }, - { - "Time": 432, - "Intensity": 0, - "Frequency": 33 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 515, - "Parameters": { - "Intensity": 100, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 16, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 29 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 66, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 116, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 32 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 166, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 216, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 31 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1215, - "Parameters": { - "Intensity": 100, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37 - }, - { - "Time": 16, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 29 - }, - { - "Time": 66, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 32 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 116, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 166, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 216, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 96, + "Parameters": { + "Intensity": 100, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 37, + "Intensity": 0.94, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.68, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 101, + "StartTime": 193, + "Parameters": { + "Intensity": 69, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.89, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 432, + "StartTime": 298, + "Parameters": { + "Intensity": 70, + "Frequency": 7, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 21, + "Intensity": 0.03, + "Frequency": 31 + }, + { + "Time": 45, + "Intensity": 0.12, + "Frequency": 31 + }, + { + "Time": 74, + "Intensity": 0.26, + "Frequency": 30 + }, + { + "Time": 107, + "Intensity": 0.62, + "Frequency": 30 + }, + { + "Time": 135, + "Intensity": 0.48, + "Frequency": 29 + }, + { + "Time": 166, + "Intensity": 0.23, + "Frequency": 29 + }, + { + "Time": 210, + "Intensity": 0.31, + "Frequency": 30 + }, + { + "Time": 232, + "Intensity": 0.38, + "Frequency": 30 + }, + { + "Time": 265, + "Intensity": 0.15, + "Frequency": 30 + }, + { + "Time": 294, + "Intensity": 0.07, + "Frequency": 30 + }, + { + "Time": 315, + "Intensity": 0.03, + "Frequency": 30 + }, + { + "Time": 340, + "Intensity": 0.01, + "Frequency": 29 + }, + { + "Time": 432, + "Intensity": 0, + "Frequency": 33 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 515, + "Parameters": { + "Intensity": 100, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 16, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 29 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 66, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 116, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 32 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 166, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 216, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 31 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1215, + "Parameters": { + "Intensity": 100, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37 + }, + { + "Time": 16, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 29 + }, + { + "Time": 66, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 32 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 116, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 166, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 216, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_l.json index eadaa1ef30fb5d43a44cbf0b351d2d04f1e5d4a4..6f25becea6209a1e9ea105ab766343d8dbfa5308 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_l.json @@ -1,357 +1,357 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 96, - "Parameters": { - "Intensity": 60, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 37, - "Intensity": 0.94, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.68, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 101, - "StartTime": 193, - "Parameters": { - "Intensity": 41, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.89, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 432, - "StartTime": 298, - "Parameters": { - "Intensity": 42, - "Frequency": 7, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 21, - "Intensity": 0.03, - "Frequency": 31 - }, - { - "Time": 45, - "Intensity": 0.12, - "Frequency": 31 - }, - { - "Time": 74, - "Intensity": 0.26, - "Frequency": 30 - }, - { - "Time": 107, - "Intensity": 0.62, - "Frequency": 30 - }, - { - "Time": 135, - "Intensity": 0.48, - "Frequency": 29 - }, - { - "Time": 166, - "Intensity": 0.23, - "Frequency": 29 - }, - { - "Time": 210, - "Intensity": 0.31, - "Frequency": 30 - }, - { - "Time": 232, - "Intensity": 0.38, - "Frequency": 30 - }, - { - "Time": 265, - "Intensity": 0.15, - "Frequency": 30 - }, - { - "Time": 294, - "Intensity": 0.07, - "Frequency": 30 - }, - { - "Time": 315, - "Intensity": 0.03, - "Frequency": 30 - }, - { - "Time": 340, - "Intensity": 0.01, - "Frequency": 29 - }, - { - "Time": 432, - "Intensity": 0, - "Frequency": 33 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 515, - "Parameters": { - "Intensity": 60, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 16, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 29 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 66, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 116, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 32 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 166, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 216, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 31 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1215, - "Parameters": { - "Intensity": 60, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37 - }, - { - "Time": 16, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 29 - }, - { - "Time": 66, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 32 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 116, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 166, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 216, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 96, + "Parameters": { + "Intensity": 60, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 37, + "Intensity": 0.94, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.68, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 101, + "StartTime": 193, + "Parameters": { + "Intensity": 41, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.89, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 432, + "StartTime": 298, + "Parameters": { + "Intensity": 42, + "Frequency": 7, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 21, + "Intensity": 0.03, + "Frequency": 31 + }, + { + "Time": 45, + "Intensity": 0.12, + "Frequency": 31 + }, + { + "Time": 74, + "Intensity": 0.26, + "Frequency": 30 + }, + { + "Time": 107, + "Intensity": 0.62, + "Frequency": 30 + }, + { + "Time": 135, + "Intensity": 0.48, + "Frequency": 29 + }, + { + "Time": 166, + "Intensity": 0.23, + "Frequency": 29 + }, + { + "Time": 210, + "Intensity": 0.31, + "Frequency": 30 + }, + { + "Time": 232, + "Intensity": 0.38, + "Frequency": 30 + }, + { + "Time": 265, + "Intensity": 0.15, + "Frequency": 30 + }, + { + "Time": 294, + "Intensity": 0.07, + "Frequency": 30 + }, + { + "Time": 315, + "Intensity": 0.03, + "Frequency": 30 + }, + { + "Time": 340, + "Intensity": 0.01, + "Frequency": 29 + }, + { + "Time": 432, + "Intensity": 0, + "Frequency": 33 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 515, + "Parameters": { + "Intensity": 60, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 16, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 29 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 66, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 116, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 32 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 166, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 216, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 31 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1215, + "Parameters": { + "Intensity": 60, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37 + }, + { + "Time": 16, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 29 + }, + { + "Time": 66, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 32 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 116, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 166, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 216, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_m.json index 0763f835554352670bf3557b73f583b5d3f42661..1b34dbe8a0a1070eac7ae3e47061027f04db1dc0 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Tumble_m.json @@ -1,357 +1,357 @@ -{ - "MetaData": { - "Create": "2022-04-27", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 96, - "Parameters": { - "Intensity": 80, - "Frequency": 46, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 37, - "Intensity": 0.94, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.68, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 101, - "StartTime": 193, - "Parameters": { - "Intensity": 55, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 25, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.89, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 432, - "StartTime": 298, - "Parameters": { - "Intensity": 56, - "Frequency": 7, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 21, - "Intensity": 0.03, - "Frequency": 31 - }, - { - "Time": 45, - "Intensity": 0.12, - "Frequency": 31 - }, - { - "Time": 74, - "Intensity": 0.26, - "Frequency": 30 - }, - { - "Time": 107, - "Intensity": 0.62, - "Frequency": 30 - }, - { - "Time": 135, - "Intensity": 0.48, - "Frequency": 29 - }, - { - "Time": 166, - "Intensity": 0.23, - "Frequency": 29 - }, - { - "Time": 210, - "Intensity": 0.31, - "Frequency": 30 - }, - { - "Time": 232, - "Intensity": 0.38, - "Frequency": 30 - }, - { - "Time": 265, - "Intensity": 0.15, - "Frequency": 30 - }, - { - "Time": 294, - "Intensity": 0.07, - "Frequency": 30 - }, - { - "Time": 315, - "Intensity": 0.03, - "Frequency": 30 - }, - { - "Time": 340, - "Intensity": 0.01, - "Frequency": 29 - }, - { - "Time": 432, - "Intensity": 0, - "Frequency": 33 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 515, - "Parameters": { - "Intensity": 80, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 16, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 29 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 66, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 116, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 32 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 166, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 216, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 30 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 31 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1215, - "Parameters": { - "Intensity": 80, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 37 - }, - { - "Time": 16, - "Intensity": 0, - "Frequency": 35 - }, - { - "Time": 33, - "Intensity": 0, - "Frequency": 33 - }, - { - "Time": 50, - "Intensity": 0, - "Frequency": 29 - }, - { - "Time": 66, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 83, - "Intensity": 0, - "Frequency": 32 - }, - { - "Time": 100, - "Intensity": 0, - "Frequency": 36 - }, - { - "Time": 116, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 133, - "Intensity": 0, - "Frequency": 34 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 166, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 183, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 200, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 216, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 233, - "Intensity": 0, - "Frequency": 31 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-27", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 96, + "Parameters": { + "Intensity": 80, + "Frequency": 46, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 37, + "Intensity": 0.94, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.68, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 101, + "StartTime": 193, + "Parameters": { + "Intensity": 55, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 25, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.89, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 432, + "StartTime": 298, + "Parameters": { + "Intensity": 56, + "Frequency": 7, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 21, + "Intensity": 0.03, + "Frequency": 31 + }, + { + "Time": 45, + "Intensity": 0.12, + "Frequency": 31 + }, + { + "Time": 74, + "Intensity": 0.26, + "Frequency": 30 + }, + { + "Time": 107, + "Intensity": 0.62, + "Frequency": 30 + }, + { + "Time": 135, + "Intensity": 0.48, + "Frequency": 29 + }, + { + "Time": 166, + "Intensity": 0.23, + "Frequency": 29 + }, + { + "Time": 210, + "Intensity": 0.31, + "Frequency": 30 + }, + { + "Time": 232, + "Intensity": 0.38, + "Frequency": 30 + }, + { + "Time": 265, + "Intensity": 0.15, + "Frequency": 30 + }, + { + "Time": 294, + "Intensity": 0.07, + "Frequency": 30 + }, + { + "Time": 315, + "Intensity": 0.03, + "Frequency": 30 + }, + { + "Time": 340, + "Intensity": 0.01, + "Frequency": 29 + }, + { + "Time": 432, + "Intensity": 0, + "Frequency": 33 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 515, + "Parameters": { + "Intensity": 80, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 16, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 29 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 66, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 116, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 32 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 166, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 216, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 30 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 31 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1215, + "Parameters": { + "Intensity": 80, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 37 + }, + { + "Time": 16, + "Intensity": 0, + "Frequency": 35 + }, + { + "Time": 33, + "Intensity": 0, + "Frequency": 33 + }, + { + "Time": 50, + "Intensity": 0, + "Frequency": 29 + }, + { + "Time": 66, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 83, + "Intensity": 0, + "Frequency": 32 + }, + { + "Time": 100, + "Intensity": 0, + "Frequency": 36 + }, + { + "Time": 116, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 133, + "Intensity": 0, + "Frequency": 34 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 166, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 183, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 200, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 216, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 233, + "Intensity": 0, + "Frequency": 31 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_h.json index 90eec93ba52b1f9a0196bc9ab2f4cf6c643a0ec3..0dcc26ca8c027c5fbaff5543731020c94b715550 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_h.json @@ -1,318 +1,318 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 195, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 88, - "StartTime": 222, - "Parameters": { - "Intensity": 32, - "Frequency": 60, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 49, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 88, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 370, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 85, - "StartTime": 394, - "Parameters": { - "Intensity": 36, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 47, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 85, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 674, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 108, - "StartTime": 799, - "Parameters": { - "Intensity": 34, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 3, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 60, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 108, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 932, - "Parameters": { - "Intensity": 67, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 964, - "Parameters": { - "Intensity": 31, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1105, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 1128, - "Parameters": { - "Intensity": 34, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1258, - "Parameters": { - "Intensity": 64, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 55, - "StartTime": 1279, - "Parameters": { - "Intensity": 27, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 30, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 55, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1358, - "Parameters": { - "Intensity": 35, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 57, - "StartTime": 1388, - "Parameters": { - "Intensity": 18, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.56666666, - "Frequency": 0 - }, - { - "Time": 57, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 195, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 88, + "StartTime": 222, + "Parameters": { + "Intensity": 32, + "Frequency": 60, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 49, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 88, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 370, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 85, + "StartTime": 394, + "Parameters": { + "Intensity": 36, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 47, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 85, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 674, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 108, + "StartTime": 799, + "Parameters": { + "Intensity": 34, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 3, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 60, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 108, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 932, + "Parameters": { + "Intensity": 67, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 964, + "Parameters": { + "Intensity": 31, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1105, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 1128, + "Parameters": { + "Intensity": 34, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1258, + "Parameters": { + "Intensity": 64, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 55, + "StartTime": 1279, + "Parameters": { + "Intensity": 27, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 30, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 55, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1358, + "Parameters": { + "Intensity": 35, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 57, + "StartTime": 1388, + "Parameters": { + "Intensity": 18, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.56666666, + "Frequency": 0 + }, + { + "Time": 57, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_l.json index f877a60837c1ba3bf15a94a476ae06121b2ac5f0..732ed450372d29b2aea361657eea55928ebfe2f1 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_l.json @@ -1,318 +1,318 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 195, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 88, - "StartTime": 222, - "Parameters": { - "Intensity": 19, - "Frequency": 60, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 49, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 88, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 370, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 85, - "StartTime": 394, - "Parameters": { - "Intensity": 21, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 47, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 85, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 674, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 108, - "StartTime": 799, - "Parameters": { - "Intensity": 20, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 3, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 60, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 108, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 932, - "Parameters": { - "Intensity": 40, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 964, - "Parameters": { - "Intensity": 18, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1105, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 1128, - "Parameters": { - "Intensity": 20, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1258, - "Parameters": { - "Intensity": 38, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 55, - "StartTime": 1279, - "Parameters": { - "Intensity": 16, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 30, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 55, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1358, - "Parameters": { - "Intensity": 21, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 57, - "StartTime": 1388, - "Parameters": { - "Intensity": 10, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.56666666, - "Frequency": 0 - }, - { - "Time": 57, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 195, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 88, + "StartTime": 222, + "Parameters": { + "Intensity": 19, + "Frequency": 60, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 49, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 88, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 370, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 85, + "StartTime": 394, + "Parameters": { + "Intensity": 21, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 47, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 85, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 674, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 108, + "StartTime": 799, + "Parameters": { + "Intensity": 20, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 3, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 60, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 108, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 932, + "Parameters": { + "Intensity": 40, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 964, + "Parameters": { + "Intensity": 18, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1105, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 1128, + "Parameters": { + "Intensity": 20, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1258, + "Parameters": { + "Intensity": 38, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 55, + "StartTime": 1279, + "Parameters": { + "Intensity": 16, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 30, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 55, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1358, + "Parameters": { + "Intensity": 21, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 57, + "StartTime": 1388, + "Parameters": { + "Intensity": 10, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.56666666, + "Frequency": 0 + }, + { + "Time": 57, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_m.json index 5d33225fd0412c1edc1c60ec346d8c8a104ad27a..c525dec828f9111989fd8e1b55842b827a6e189b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Typewriter_m.json @@ -1,318 +1,318 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 195, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 88, - "StartTime": 222, - "Parameters": { - "Intensity": 25, - "Frequency": 60, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 49, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 88, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 370, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 85, - "StartTime": 394, - "Parameters": { - "Intensity": 28, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 47, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 85, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 674, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 108, - "StartTime": 799, - "Parameters": { - "Intensity": 27, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 3, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 60, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 108, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 932, - "Parameters": { - "Intensity": 53, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 964, - "Parameters": { - "Intensity": 24, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1105, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 84, - "StartTime": 1128, - "Parameters": { - "Intensity": 27, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 84, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1258, - "Parameters": { - "Intensity": 51, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 55, - "StartTime": 1279, - "Parameters": { - "Intensity": 21, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 30, - "Intensity": 0.39215687, - "Frequency": 0 - }, - { - "Time": 55, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1358, - "Parameters": { - "Intensity": 28, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 57, - "StartTime": 1388, - "Parameters": { - "Intensity": 14, - "Frequency": 58, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.56666666, - "Frequency": 0 - }, - { - "Time": 57, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 195, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 88, + "StartTime": 222, + "Parameters": { + "Intensity": 25, + "Frequency": 60, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 49, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 88, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 370, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 85, + "StartTime": 394, + "Parameters": { + "Intensity": 28, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 47, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 85, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 674, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 108, + "StartTime": 799, + "Parameters": { + "Intensity": 27, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 3, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 60, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 108, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 932, + "Parameters": { + "Intensity": 53, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 964, + "Parameters": { + "Intensity": 24, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1105, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 84, + "StartTime": 1128, + "Parameters": { + "Intensity": 27, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 84, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1258, + "Parameters": { + "Intensity": 51, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 55, + "StartTime": 1279, + "Parameters": { + "Intensity": 21, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 30, + "Intensity": 0.39215687, + "Frequency": 0 + }, + { + "Time": 55, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1358, + "Parameters": { + "Intensity": 28, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 57, + "StartTime": 1388, + "Parameters": { + "Intensity": 14, + "Frequency": 58, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.56666666, + "Frequency": 0 + }, + { + "Time": 57, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/UpSlide_Stop.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/UpSlide_Stop.json index 02dcf36d7daf589c6a7b1b5cd35656114025ccee..81b0d9d85341376956be0bbe20ff4978cf84790f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/UpSlide_Stop.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/UpSlide_Stop.json @@ -1,33 +1,33 @@ -{ - "Channels" : - [ - { - "Parameters" : - { - "Index" : 1 - }, - "Pattern" : - [ - { - "Event" : - { - "Parameters" : - { - "Frequency" : 100, - "Intensity" : 100 - }, - "StartTime" : 1000, - "Type" : "transient" - } - } - ] - } - ], - "MetaData" : - { - "ChannelNumber" : 1, - "Create" : "2023-03-17", - "Discription" : "A json file format demo", - "Version" : 1.0 - } -} +{ + "Channels" : + [ + { + "Parameters" : + { + "Index" : 1 + }, + "Pattern" : + [ + { + "Event" : + { + "Parameters" : + { + "Frequency" : 100, + "Intensity" : 100 + }, + "StartTime" : 1000, + "Type" : "transient" + } + } + ] + } + ], + "MetaData" : + { + "ChannelNumber" : 1, + "Create" : "2023-03-17", + "Discription" : "A json file format demo", + "Version" : 1.0 + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_h.json index 83343aefbe9012333097d90d735d104a80c165ec..6b5dedb43878ccfabfbf03648a25ee7a98197af6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_h.json @@ -1,127 +1,127 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 176, - "Parameters": { - "Intensity": 100, - "Frequency": 73 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 265, - "Parameters": { - "Intensity": 62, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 833, - "Parameters": { - "Intensity": 90, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 890, - "Parameters": { - "Intensity": 51, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1448, - "Parameters": { - "Intensity": 77, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1513, - "Parameters": { - "Intensity": 47, - "Frequency": 1 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2074, - "Parameters": { - "Intensity": 68, - "Frequency": 24 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2148, - "Parameters": { - "Intensity": 41, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2771, - "Parameters": { - "Intensity": 52, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2839, - "Parameters": { - "Intensity": 33, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 176, + "Parameters": { + "Intensity": 100, + "Frequency": 73 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 265, + "Parameters": { + "Intensity": 62, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 833, + "Parameters": { + "Intensity": 90, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 890, + "Parameters": { + "Intensity": 51, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1448, + "Parameters": { + "Intensity": 77, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1513, + "Parameters": { + "Intensity": 47, + "Frequency": 1 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2074, + "Parameters": { + "Intensity": 68, + "Frequency": 24 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2148, + "Parameters": { + "Intensity": 41, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2771, + "Parameters": { + "Intensity": 52, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2839, + "Parameters": { + "Intensity": 33, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_l.json index 8d5e6895b7697b3f450ec202942f7113fc1cd6e5..271f7d01c06fbf363df39efd32a6632e79698b29 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_l.json @@ -1,127 +1,127 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 176, - "Parameters": { - "Intensity": 60, - "Frequency": 73 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 265, - "Parameters": { - "Intensity": 37, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 833, - "Parameters": { - "Intensity": 54, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 890, - "Parameters": { - "Intensity": 30, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1448, - "Parameters": { - "Intensity": 46, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1513, - "Parameters": { - "Intensity": 28, - "Frequency": 1 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2074, - "Parameters": { - "Intensity": 40, - "Frequency": 24 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2148, - "Parameters": { - "Intensity": 24, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2771, - "Parameters": { - "Intensity": 31, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2839, - "Parameters": { - "Intensity": 19, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 176, + "Parameters": { + "Intensity": 60, + "Frequency": 73 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 265, + "Parameters": { + "Intensity": 37, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 833, + "Parameters": { + "Intensity": 54, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 890, + "Parameters": { + "Intensity": 30, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1448, + "Parameters": { + "Intensity": 46, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1513, + "Parameters": { + "Intensity": 28, + "Frequency": 1 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2074, + "Parameters": { + "Intensity": 40, + "Frequency": 24 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2148, + "Parameters": { + "Intensity": 24, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2771, + "Parameters": { + "Intensity": 31, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2839, + "Parameters": { + "Intensity": 19, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_m.json index 0f4f20c61badaca8a1995e9c68f95ec6db1cbbc1..99a0caffa4670779964e3fd9d43a30809f9b913a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Walk_m.json @@ -1,127 +1,127 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 176, - "Parameters": { - "Intensity": 80, - "Frequency": 73 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 265, - "Parameters": { - "Intensity": 49, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 833, - "Parameters": { - "Intensity": 72, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 890, - "Parameters": { - "Intensity": 40, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1448, - "Parameters": { - "Intensity": 61, - "Frequency": 20 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1513, - "Parameters": { - "Intensity": 37, - "Frequency": 1 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2074, - "Parameters": { - "Intensity": 54, - "Frequency": 24 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2148, - "Parameters": { - "Intensity": 32, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2771, - "Parameters": { - "Intensity": 41, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 2839, - "Parameters": { - "Intensity": 26, - "Frequency": 0 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 176, + "Parameters": { + "Intensity": 80, + "Frequency": 73 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 265, + "Parameters": { + "Intensity": 49, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 833, + "Parameters": { + "Intensity": 72, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 890, + "Parameters": { + "Intensity": 40, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1448, + "Parameters": { + "Intensity": 61, + "Frequency": 20 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1513, + "Parameters": { + "Intensity": 37, + "Frequency": 1 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2074, + "Parameters": { + "Intensity": 54, + "Frequency": 24 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2148, + "Parameters": { + "Intensity": 32, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2771, + "Parameters": { + "Intensity": 41, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 2839, + "Parameters": { + "Intensity": 26, + "Frequency": 0 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_h.json index 9a1be2e783fbfe1e2e4056fcccbb1cc6ab72d0cc..99249439d25555b144b95a42267fbf47e027c243 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_h.json @@ -1,136 +1,136 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 45, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 120, - "Parameters": { - "Intensity": 100, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 226, - "StartTime": 167, - "Parameters": { - "Intensity": 89, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 6, - "Intensity": 1.0, - "Frequency": -25 - }, - { - "Time": 50, - "Intensity": 0.52, - "Frequency": -68 - }, - { - "Time": 226, - "Intensity": 0.0, - "Frequency": -100 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 147, - "StartTime": 579, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 0.83, - "Frequency": -31 - }, - { - "Time": 102, - "Intensity": 1.0, - "Frequency": -91 - }, - { - "Time": 147, - "Intensity": 0.0, - "Frequency": -81 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 731, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1.0, - "Frequency": -19 - }, - { - "Time": 71, - "Intensity": 1.0, - "Frequency": -86 - }, - { - "Time": 150, - "Intensity": 0.0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 45, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 120, + "Parameters": { + "Intensity": 100, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 226, + "StartTime": 167, + "Parameters": { + "Intensity": 89, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 6, + "Intensity": 1.0, + "Frequency": -25 + }, + { + "Time": 50, + "Intensity": 0.52, + "Frequency": -68 + }, + { + "Time": 226, + "Intensity": 0.0, + "Frequency": -100 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 147, + "StartTime": 579, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 0.83, + "Frequency": -31 + }, + { + "Time": 102, + "Intensity": 1.0, + "Frequency": -91 + }, + { + "Time": 147, + "Intensity": 0.0, + "Frequency": -81 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 731, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1.0, + "Frequency": -19 + }, + { + "Time": 71, + "Intensity": 1.0, + "Frequency": -86 + }, + { + "Time": 150, + "Intensity": 0.0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_l.json index e852bd9500848aae727ef7b5f2524a5edbc2a340..1ee47e53cc76b2cc286ec85b05b979c3b34c1e57 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_l.json @@ -1,136 +1,136 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 27, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 120, - "Parameters": { - "Intensity": 60, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 226, - "StartTime": 167, - "Parameters": { - "Intensity": 53, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 6, - "Intensity": 1.0, - "Frequency": -25 - }, - { - "Time": 50, - "Intensity": 0.52, - "Frequency": -68 - }, - { - "Time": 226, - "Intensity": 0.0, - "Frequency": -100 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 147, - "StartTime": 579, - "Parameters": { - "Intensity": 19, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 0.83, - "Frequency": -31 - }, - { - "Time": 102, - "Intensity": 1.0, - "Frequency": -91 - }, - { - "Time": 147, - "Intensity": 0.0, - "Frequency": -81 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 731, - "Parameters": { - "Intensity": 28, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1.0, - "Frequency": -19 - }, - { - "Time": 71, - "Intensity": 1.0, - "Frequency": -86 - }, - { - "Time": 150, - "Intensity": 0.0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 27, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 120, + "Parameters": { + "Intensity": 60, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 226, + "StartTime": 167, + "Parameters": { + "Intensity": 53, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 6, + "Intensity": 1.0, + "Frequency": -25 + }, + { + "Time": 50, + "Intensity": 0.52, + "Frequency": -68 + }, + { + "Time": 226, + "Intensity": 0.0, + "Frequency": -100 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 147, + "StartTime": 579, + "Parameters": { + "Intensity": 19, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 0.83, + "Frequency": -31 + }, + { + "Time": 102, + "Intensity": 1.0, + "Frequency": -91 + }, + { + "Time": 147, + "Intensity": 0.0, + "Frequency": -81 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 731, + "Parameters": { + "Intensity": 28, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1.0, + "Frequency": -19 + }, + { + "Time": 71, + "Intensity": 1.0, + "Frequency": -86 + }, + { + "Time": 150, + "Intensity": 0.0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_m.json index 7a5298406fa59a3e8e8c19017b7caab55acc70ab..6a4818928685aa34aaae2d389832d64953af7d0f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Water_m.json @@ -1,136 +1,136 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 0, - "Parameters": { - "Intensity": 36, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 120, - "Parameters": { - "Intensity": 80, - "Frequency": 7 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 226, - "StartTime": 167, - "Parameters": { - "Intensity": 71, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 6, - "Intensity": 1.0, - "Frequency": -25 - }, - { - "Time": 50, - "Intensity": 0.52, - "Frequency": -68 - }, - { - "Time": 226, - "Intensity": 0.0, - "Frequency": -100 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 147, - "StartTime": 579, - "Parameters": { - "Intensity": 26, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 42, - "Intensity": 0.83, - "Frequency": -31 - }, - { - "Time": 102, - "Intensity": 1.0, - "Frequency": -91 - }, - { - "Time": 147, - "Intensity": 0.0, - "Frequency": -81 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 150, - "StartTime": 731, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 18, - "Intensity": 1.0, - "Frequency": -19 - }, - { - "Time": 71, - "Intensity": 1.0, - "Frequency": -86 - }, - { - "Time": 150, - "Intensity": 0.0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 0, + "Parameters": { + "Intensity": 36, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 120, + "Parameters": { + "Intensity": 80, + "Frequency": 7 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 226, + "StartTime": 167, + "Parameters": { + "Intensity": 71, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 6, + "Intensity": 1.0, + "Frequency": -25 + }, + { + "Time": 50, + "Intensity": 0.52, + "Frequency": -68 + }, + { + "Time": 226, + "Intensity": 0.0, + "Frequency": -100 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 147, + "StartTime": 579, + "Parameters": { + "Intensity": 26, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 42, + "Intensity": 0.83, + "Frequency": -31 + }, + { + "Time": 102, + "Intensity": 1.0, + "Frequency": -91 + }, + { + "Time": 147, + "Intensity": 0.0, + "Frequency": -81 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 150, + "StartTime": 731, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 18, + "Intensity": 1.0, + "Frequency": -19 + }, + { + "Time": 71, + "Intensity": 1.0, + "Frequency": -86 + }, + { + "Time": 150, + "Intensity": 0.0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_h.json index 6fa192ad1e143934e3bf7a6f5ce9eb32ceb7e447..7ee72ab110c6253adb41d3638693e2da735d5727 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_h.json @@ -1,2304 +1,2304 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 0, - "Parameters": { - "Intensity": 38, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.32, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.68, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5, - "Parameters": { - "Intensity": 61, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.45, - "Frequency": 3 - }, - { - "Time": 146, - "Intensity": 0.54, - "Frequency": -5 - }, - { - "Time": 223, - "Intensity": 0.67, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.69, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 256, - "Parameters": { - "Intensity": 94, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 3 - }, - { - "Time": 1, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 94, - "Intensity": 0.79, - "Frequency": -5 - }, - { - "Time": 201, - "Intensity": 0.68, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.48, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 258, - "Parameters": { - "Intensity": 77, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 23, - "Intensity": 0.71, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0.48, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 153, - "Intensity": 0.7, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 222, - "Intensity": 0.48, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 506, - "Parameters": { - "Intensity": 77, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.61, - "Frequency": 3 - }, - { - "Time": 95, - "Intensity": 0.18, - "Frequency": -5 - }, - { - "Time": 201, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.65, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 508, - "Parameters": { - "Intensity": 42, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -33 - }, - { - "Time": 33, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 4 - }, - { - "Time": 149, - "Intensity": 0.13, - "Frequency": -13 - }, - { - "Time": 168, - "Intensity": 0.48, - "Frequency": 23 - }, - { - "Time": 194, - "Intensity": 0.22, - "Frequency": -15 - }, - { - "Time": 224, - "Intensity": 0.58, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 758, - "Parameters": { - "Intensity": 53, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 46, - "Intensity": 0.73, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 157, - "Intensity": 0.33, - "Frequency": 5 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 758, - "Parameters": { - "Intensity": 85, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.59, - "Frequency": 3 - }, - { - "Time": 52, - "Intensity": 0.57, - "Frequency": -5 - }, - { - "Time": 103, - "Intensity": 0.62, - "Frequency": 3 - }, - { - "Time": 203, - "Intensity": 0.18, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1008, - "Parameters": { - "Intensity": 24, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.32, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.68, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1008, - "Parameters": { - "Intensity": 55, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 23, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 68, - "Intensity": 0.38, - "Frequency": -5 - }, - { - "Time": 195, - "Intensity": 0.55, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.19, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1258, - "Parameters": { - "Intensity": 82, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 17, - "Intensity": 0.27, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 130, - "Intensity": 0.17, - "Frequency": -15 - }, - { - "Time": 152, - "Intensity": 0.82, - "Frequency": 2 - }, - { - "Time": 191, - "Intensity": 0.19, - "Frequency": -13 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 27 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1258, - "Parameters": { - "Intensity": 100, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.12, - "Frequency": 3 - }, - { - "Time": 85, - "Intensity": 0.23, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.71, - "Frequency": 3 - }, - { - "Time": 231, - "Intensity": 0.86, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1508, - "Parameters": { - "Intensity": 96, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 74, - "Intensity": 0.77, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 157, - "Intensity": 0.61, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1508, - "Parameters": { - "Intensity": 92, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 51, - "Intensity": 0.92, - "Frequency": -5 - }, - { - "Time": 203, - "Intensity": 1, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.8, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1758, - "Parameters": { - "Intensity": 93, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 49, - "Intensity": 0.57, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 92, - "Intensity": 0.75, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.32, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 225, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1758, - "Parameters": { - "Intensity": 96, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.77, - "Frequency": 3 - }, - { - "Time": 82, - "Intensity": 0.67, - "Frequency": -5 - }, - { - "Time": 159, - "Intensity": 0.3, - "Frequency": 3 - }, - { - "Time": 197, - "Intensity": 0.27, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2008, - "Parameters": { - "Intensity": 65, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -33 - }, - { - "Time": 33, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 98, - "Intensity": 0.7, - "Frequency": 5 - }, - { - "Time": 150, - "Intensity": 0.09, - "Frequency": -13 - }, - { - "Time": 167, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 194, - "Intensity": 0.22, - "Frequency": -15 - }, - { - "Time": 224, - "Intensity": 0.58, - "Frequency": 11 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2008, - "Parameters": { - "Intensity": 70, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 58, - "Intensity": 0.36, - "Frequency": 3 - }, - { - "Time": 98, - "Intensity": 0.86, - "Frequency": -5 - }, - { - "Time": 188, - "Intensity": 0.7, - "Frequency": 3 - }, - { - "Time": 246, - "Intensity": 0.28, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2258, - "Parameters": { - "Intensity": 21, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2258, - "Parameters": { - "Intensity": 51, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.25, - "Frequency": 3 - }, - { - "Time": 58, - "Intensity": 0.52, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.63, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.45, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2508, - "Parameters": { - "Intensity": 20, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2508, - "Parameters": { - "Intensity": 52, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.45, - "Frequency": 3 - }, - { - "Time": 53, - "Intensity": 0.46, - "Frequency": -5 - }, - { - "Time": 120, - "Intensity": 0.53, - "Frequency": 3 - }, - { - "Time": 196, - "Intensity": 0.31, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2758, - "Parameters": { - "Intensity": 74, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 22, - "Intensity": 0.36, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 0.53, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.37, - "Frequency": 2 - }, - { - "Time": 187, - "Intensity": 0.09, - "Frequency": -13 - }, - { - "Time": 220, - "Intensity": 0.65, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2758, - "Parameters": { - "Intensity": 85, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 35, - "Intensity": 0.1, - "Frequency": 3 - }, - { - "Time": 83, - "Intensity": 0.15, - "Frequency": -5 - }, - { - "Time": 107, - "Intensity": 0.59, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.81, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3008, - "Parameters": { - "Intensity": 87, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 77, - "Intensity": 0.72, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 178, - "Intensity": 0.78, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3008, - "Parameters": { - "Intensity": 100, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.69, - "Frequency": 3 - }, - { - "Time": 53, - "Intensity": 0.81, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.83, - "Frequency": 3 - }, - { - "Time": 214, - "Intensity": 0.64, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3258, - "Parameters": { - "Intensity": 91, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 35, - "Intensity": 0.19, - "Frequency": 55 - }, - { - "Time": 68, - "Intensity": 0.05, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.23, - "Frequency": 2 - }, - { - "Time": 129, - "Intensity": 0.04, - "Frequency": -15 - }, - { - "Time": 154, - "Intensity": 0.51, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 225, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3258, - "Parameters": { - "Intensity": 81, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.21, - "Frequency": 3 - }, - { - "Time": 164, - "Intensity": 0.69, - "Frequency": -5 - }, - { - "Time": 212, - "Intensity": 0.75, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.58, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3508, - "Parameters": { - "Intensity": 63, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 0.66, - "Frequency": 3 - }, - { - "Time": 76, - "Intensity": 0.75, - "Frequency": -5 - }, - { - "Time": 168, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 211, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3513, - "Parameters": { - "Intensity": 68, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 18, - "Intensity": 0.58, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 96, - "Intensity": 0.25, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.32, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3763, - "Parameters": { - "Intensity": 61, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.38, - "Frequency": 3 - }, - { - "Time": 80, - "Intensity": 0.39, - "Frequency": -5 - }, - { - "Time": 203, - "Intensity": 0.52, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.34, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3765, - "Parameters": { - "Intensity": 19, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4015, - "Parameters": { - "Intensity": 25, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.21, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4015, - "Parameters": { - "Intensity": 61, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.33, - "Frequency": 3 - }, - { - "Time": 50, - "Intensity": 0.67, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.49, - "Frequency": 3 - }, - { - "Time": 225, - "Intensity": 0.46, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4265, - "Parameters": { - "Intensity": 68, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.22, - "Frequency": 3 - }, - { - "Time": 52, - "Intensity": 0.53, - "Frequency": -5 - }, - { - "Time": 183, - "Intensity": 0.56, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.36, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4265, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 16, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.36, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4516, - "Parameters": { - "Intensity": 55, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 48, - "Intensity": 0.64, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.63, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.45, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4518, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 77, - "Intensity": 0.72, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 178, - "Intensity": 0.78, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4768, - "Parameters": { - "Intensity": 20, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4768, - "Parameters": { - "Intensity": 57, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 48, - "Intensity": 0.64, - "Frequency": -5 - }, - { - "Time": 135, - "Intensity": 0.43, - "Frequency": 3 - }, - { - "Time": 247, - "Intensity": 0.29, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5022, - "Parameters": { - "Intensity": 52, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 63, - "Intensity": 0.41, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.57, - "Frequency": 3 - }, - { - "Time": 240, - "Intensity": 0.25, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5024, - "Parameters": { - "Intensity": 16, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 445, - "StartTime": 5274, - "Parameters": { - "Intensity": 30, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 12, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 142, - "Intensity": 0.79, - "Frequency": -5 - }, - { - "Time": 335, - "Intensity": 0.7, - "Frequency": 3 - }, - { - "Time": 376, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 445, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5279, - "Parameters": { - "Intensity": 21, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 0, + "Parameters": { + "Intensity": 38, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.32, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.68, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5, + "Parameters": { + "Intensity": 61, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.45, + "Frequency": 3 + }, + { + "Time": 146, + "Intensity": 0.54, + "Frequency": -5 + }, + { + "Time": 223, + "Intensity": 0.67, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.69, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 256, + "Parameters": { + "Intensity": 94, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 3 + }, + { + "Time": 1, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 94, + "Intensity": 0.79, + "Frequency": -5 + }, + { + "Time": 201, + "Intensity": 0.68, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.48, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 258, + "Parameters": { + "Intensity": 77, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 23, + "Intensity": 0.71, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0.48, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 153, + "Intensity": 0.7, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 222, + "Intensity": 0.48, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 506, + "Parameters": { + "Intensity": 77, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.61, + "Frequency": 3 + }, + { + "Time": 95, + "Intensity": 0.18, + "Frequency": -5 + }, + { + "Time": 201, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.65, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 508, + "Parameters": { + "Intensity": 42, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -33 + }, + { + "Time": 33, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 4 + }, + { + "Time": 149, + "Intensity": 0.13, + "Frequency": -13 + }, + { + "Time": 168, + "Intensity": 0.48, + "Frequency": 23 + }, + { + "Time": 194, + "Intensity": 0.22, + "Frequency": -15 + }, + { + "Time": 224, + "Intensity": 0.58, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 758, + "Parameters": { + "Intensity": 53, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 46, + "Intensity": 0.73, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 157, + "Intensity": 0.33, + "Frequency": 5 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 758, + "Parameters": { + "Intensity": 85, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.59, + "Frequency": 3 + }, + { + "Time": 52, + "Intensity": 0.57, + "Frequency": -5 + }, + { + "Time": 103, + "Intensity": 0.62, + "Frequency": 3 + }, + { + "Time": 203, + "Intensity": 0.18, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1008, + "Parameters": { + "Intensity": 24, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.32, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.68, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1008, + "Parameters": { + "Intensity": 55, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 23, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 68, + "Intensity": 0.38, + "Frequency": -5 + }, + { + "Time": 195, + "Intensity": 0.55, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.19, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1258, + "Parameters": { + "Intensity": 82, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 17, + "Intensity": 0.27, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 130, + "Intensity": 0.17, + "Frequency": -15 + }, + { + "Time": 152, + "Intensity": 0.82, + "Frequency": 2 + }, + { + "Time": 191, + "Intensity": 0.19, + "Frequency": -13 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 27 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1258, + "Parameters": { + "Intensity": 100, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.12, + "Frequency": 3 + }, + { + "Time": 85, + "Intensity": 0.23, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.71, + "Frequency": 3 + }, + { + "Time": 231, + "Intensity": 0.86, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1508, + "Parameters": { + "Intensity": 96, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 74, + "Intensity": 0.77, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 157, + "Intensity": 0.61, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1508, + "Parameters": { + "Intensity": 92, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 51, + "Intensity": 0.92, + "Frequency": -5 + }, + { + "Time": 203, + "Intensity": 1, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.8, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1758, + "Parameters": { + "Intensity": 93, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 49, + "Intensity": 0.57, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 92, + "Intensity": 0.75, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.32, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 225, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1758, + "Parameters": { + "Intensity": 96, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.77, + "Frequency": 3 + }, + { + "Time": 82, + "Intensity": 0.67, + "Frequency": -5 + }, + { + "Time": 159, + "Intensity": 0.3, + "Frequency": 3 + }, + { + "Time": 197, + "Intensity": 0.27, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2008, + "Parameters": { + "Intensity": 65, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -33 + }, + { + "Time": 33, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 98, + "Intensity": 0.7, + "Frequency": 5 + }, + { + "Time": 150, + "Intensity": 0.09, + "Frequency": -13 + }, + { + "Time": 167, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 194, + "Intensity": 0.22, + "Frequency": -15 + }, + { + "Time": 224, + "Intensity": 0.58, + "Frequency": 11 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2008, + "Parameters": { + "Intensity": 70, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 58, + "Intensity": 0.36, + "Frequency": 3 + }, + { + "Time": 98, + "Intensity": 0.86, + "Frequency": -5 + }, + { + "Time": 188, + "Intensity": 0.7, + "Frequency": 3 + }, + { + "Time": 246, + "Intensity": 0.28, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2258, + "Parameters": { + "Intensity": 21, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2258, + "Parameters": { + "Intensity": 51, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.25, + "Frequency": 3 + }, + { + "Time": 58, + "Intensity": 0.52, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.63, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.45, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2508, + "Parameters": { + "Intensity": 20, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2508, + "Parameters": { + "Intensity": 52, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.45, + "Frequency": 3 + }, + { + "Time": 53, + "Intensity": 0.46, + "Frequency": -5 + }, + { + "Time": 120, + "Intensity": 0.53, + "Frequency": 3 + }, + { + "Time": 196, + "Intensity": 0.31, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2758, + "Parameters": { + "Intensity": 74, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 22, + "Intensity": 0.36, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 0.53, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.37, + "Frequency": 2 + }, + { + "Time": 187, + "Intensity": 0.09, + "Frequency": -13 + }, + { + "Time": 220, + "Intensity": 0.65, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2758, + "Parameters": { + "Intensity": 85, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 35, + "Intensity": 0.1, + "Frequency": 3 + }, + { + "Time": 83, + "Intensity": 0.15, + "Frequency": -5 + }, + { + "Time": 107, + "Intensity": 0.59, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.81, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3008, + "Parameters": { + "Intensity": 87, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 77, + "Intensity": 0.72, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 178, + "Intensity": 0.78, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3008, + "Parameters": { + "Intensity": 100, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.69, + "Frequency": 3 + }, + { + "Time": 53, + "Intensity": 0.81, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.83, + "Frequency": 3 + }, + { + "Time": 214, + "Intensity": 0.64, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3258, + "Parameters": { + "Intensity": 91, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 35, + "Intensity": 0.19, + "Frequency": 55 + }, + { + "Time": 68, + "Intensity": 0.05, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.23, + "Frequency": 2 + }, + { + "Time": 129, + "Intensity": 0.04, + "Frequency": -15 + }, + { + "Time": 154, + "Intensity": 0.51, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 225, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3258, + "Parameters": { + "Intensity": 81, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.21, + "Frequency": 3 + }, + { + "Time": 164, + "Intensity": 0.69, + "Frequency": -5 + }, + { + "Time": 212, + "Intensity": 0.75, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.58, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3508, + "Parameters": { + "Intensity": 63, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 0.66, + "Frequency": 3 + }, + { + "Time": 76, + "Intensity": 0.75, + "Frequency": -5 + }, + { + "Time": 168, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 211, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3513, + "Parameters": { + "Intensity": 68, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 18, + "Intensity": 0.58, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 96, + "Intensity": 0.25, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.32, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3763, + "Parameters": { + "Intensity": 61, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.38, + "Frequency": 3 + }, + { + "Time": 80, + "Intensity": 0.39, + "Frequency": -5 + }, + { + "Time": 203, + "Intensity": 0.52, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.34, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3765, + "Parameters": { + "Intensity": 19, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4015, + "Parameters": { + "Intensity": 25, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.21, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4015, + "Parameters": { + "Intensity": 61, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.33, + "Frequency": 3 + }, + { + "Time": 50, + "Intensity": 0.67, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.49, + "Frequency": 3 + }, + { + "Time": 225, + "Intensity": 0.46, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4265, + "Parameters": { + "Intensity": 68, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.22, + "Frequency": 3 + }, + { + "Time": 52, + "Intensity": 0.53, + "Frequency": -5 + }, + { + "Time": 183, + "Intensity": 0.56, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.36, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4265, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 16, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.36, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4516, + "Parameters": { + "Intensity": 55, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 48, + "Intensity": 0.64, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.63, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.45, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4518, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 77, + "Intensity": 0.72, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 178, + "Intensity": 0.78, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4768, + "Parameters": { + "Intensity": 20, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4768, + "Parameters": { + "Intensity": 57, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 48, + "Intensity": 0.64, + "Frequency": -5 + }, + { + "Time": 135, + "Intensity": 0.43, + "Frequency": 3 + }, + { + "Time": 247, + "Intensity": 0.29, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5022, + "Parameters": { + "Intensity": 52, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 63, + "Intensity": 0.41, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.57, + "Frequency": 3 + }, + { + "Time": 240, + "Intensity": 0.25, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5024, + "Parameters": { + "Intensity": 16, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 445, + "StartTime": 5274, + "Parameters": { + "Intensity": 30, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 12, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 142, + "Intensity": 0.79, + "Frequency": -5 + }, + { + "Time": 335, + "Intensity": 0.7, + "Frequency": 3 + }, + { + "Time": 376, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 445, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5279, + "Parameters": { + "Intensity": 21, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_l.json index 13a67187372173366875e92e001bccb9cb6538f5..50c83156c7eb24dfc8ab2d35b86719f8a60d0f3a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_l.json @@ -1,2304 +1,2304 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 0, - "Parameters": { - "Intensity": 22, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.32, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.68, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5, - "Parameters": { - "Intensity": 36, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.45, - "Frequency": 3 - }, - { - "Time": 146, - "Intensity": 0.54, - "Frequency": -5 - }, - { - "Time": 223, - "Intensity": 0.67, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.69, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 256, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 3 - }, - { - "Time": 1, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 94, - "Intensity": 0.79, - "Frequency": -5 - }, - { - "Time": 201, - "Intensity": 0.68, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.48, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 258, - "Parameters": { - "Intensity": 46, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 23, - "Intensity": 0.71, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0.48, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 153, - "Intensity": 0.7, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 222, - "Intensity": 0.48, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 506, - "Parameters": { - "Intensity": 46, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.61, - "Frequency": 3 - }, - { - "Time": 95, - "Intensity": 0.18, - "Frequency": -5 - }, - { - "Time": 201, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.65, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 508, - "Parameters": { - "Intensity": 25, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -33 - }, - { - "Time": 33, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 4 - }, - { - "Time": 149, - "Intensity": 0.13, - "Frequency": -13 - }, - { - "Time": 168, - "Intensity": 0.48, - "Frequency": 23 - }, - { - "Time": 194, - "Intensity": 0.22, - "Frequency": -15 - }, - { - "Time": 224, - "Intensity": 0.58, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 758, - "Parameters": { - "Intensity": 31, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 46, - "Intensity": 0.73, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 157, - "Intensity": 0.33, - "Frequency": 5 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 758, - "Parameters": { - "Intensity": 51, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.59, - "Frequency": 3 - }, - { - "Time": 52, - "Intensity": 0.57, - "Frequency": -5 - }, - { - "Time": 103, - "Intensity": 0.62, - "Frequency": 3 - }, - { - "Time": 203, - "Intensity": 0.18, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1008, - "Parameters": { - "Intensity": 14, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.32, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.68, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1008, - "Parameters": { - "Intensity": 33, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 23, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 68, - "Intensity": 0.38, - "Frequency": -5 - }, - { - "Time": 195, - "Intensity": 0.55, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.19, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1258, - "Parameters": { - "Intensity": 49, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 17, - "Intensity": 0.27, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 130, - "Intensity": 0.17, - "Frequency": -15 - }, - { - "Time": 152, - "Intensity": 0.82, - "Frequency": 2 - }, - { - "Time": 191, - "Intensity": 0.19, - "Frequency": -13 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 27 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1258, - "Parameters": { - "Intensity": 60, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.12, - "Frequency": 3 - }, - { - "Time": 85, - "Intensity": 0.23, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.71, - "Frequency": 3 - }, - { - "Time": 231, - "Intensity": 0.86, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1508, - "Parameters": { - "Intensity": 57, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 74, - "Intensity": 0.77, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 157, - "Intensity": 0.61, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1508, - "Parameters": { - "Intensity": 55, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 51, - "Intensity": 0.92, - "Frequency": -5 - }, - { - "Time": 203, - "Intensity": 1, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.8, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1758, - "Parameters": { - "Intensity": 55, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 49, - "Intensity": 0.57, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 92, - "Intensity": 0.75, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.32, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 225, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1758, - "Parameters": { - "Intensity": 57, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.77, - "Frequency": 3 - }, - { - "Time": 82, - "Intensity": 0.67, - "Frequency": -5 - }, - { - "Time": 159, - "Intensity": 0.3, - "Frequency": 3 - }, - { - "Time": 197, - "Intensity": 0.27, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2008, - "Parameters": { - "Intensity": 39, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -33 - }, - { - "Time": 33, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 98, - "Intensity": 0.7, - "Frequency": 5 - }, - { - "Time": 150, - "Intensity": 0.09, - "Frequency": -13 - }, - { - "Time": 167, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 194, - "Intensity": 0.22, - "Frequency": -15 - }, - { - "Time": 224, - "Intensity": 0.58, - "Frequency": 11 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2008, - "Parameters": { - "Intensity": 42, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 58, - "Intensity": 0.36, - "Frequency": 3 - }, - { - "Time": 98, - "Intensity": 0.86, - "Frequency": -5 - }, - { - "Time": 188, - "Intensity": 0.7, - "Frequency": 3 - }, - { - "Time": 246, - "Intensity": 0.28, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2258, - "Parameters": { - "Intensity": 12, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2258, - "Parameters": { - "Intensity": 30, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.25, - "Frequency": 3 - }, - { - "Time": 58, - "Intensity": 0.52, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.63, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.45, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2508, - "Parameters": { - "Intensity": 12, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2508, - "Parameters": { - "Intensity": 31, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.45, - "Frequency": 3 - }, - { - "Time": 53, - "Intensity": 0.46, - "Frequency": -5 - }, - { - "Time": 120, - "Intensity": 0.53, - "Frequency": 3 - }, - { - "Time": 196, - "Intensity": 0.31, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2758, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 22, - "Intensity": 0.36, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 0.53, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.37, - "Frequency": 2 - }, - { - "Time": 187, - "Intensity": 0.09, - "Frequency": -13 - }, - { - "Time": 220, - "Intensity": 0.65, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2758, - "Parameters": { - "Intensity": 51, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 35, - "Intensity": 0.1, - "Frequency": 3 - }, - { - "Time": 83, - "Intensity": 0.15, - "Frequency": -5 - }, - { - "Time": 107, - "Intensity": 0.59, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.81, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3008, - "Parameters": { - "Intensity": 52, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 77, - "Intensity": 0.72, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 178, - "Intensity": 0.78, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3008, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.69, - "Frequency": 3 - }, - { - "Time": 53, - "Intensity": 0.81, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.83, - "Frequency": 3 - }, - { - "Time": 214, - "Intensity": 0.64, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3258, - "Parameters": { - "Intensity": 54, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 35, - "Intensity": 0.19, - "Frequency": 55 - }, - { - "Time": 68, - "Intensity": 0.05, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.23, - "Frequency": 2 - }, - { - "Time": 129, - "Intensity": 0.04, - "Frequency": -15 - }, - { - "Time": 154, - "Intensity": 0.51, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 225, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3258, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.21, - "Frequency": 3 - }, - { - "Time": 164, - "Intensity": 0.69, - "Frequency": -5 - }, - { - "Time": 212, - "Intensity": 0.75, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.58, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3508, - "Parameters": { - "Intensity": 37, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 0.66, - "Frequency": 3 - }, - { - "Time": 76, - "Intensity": 0.75, - "Frequency": -5 - }, - { - "Time": 168, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 211, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3513, - "Parameters": { - "Intensity": 40, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 18, - "Intensity": 0.58, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 96, - "Intensity": 0.25, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.32, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3763, - "Parameters": { - "Intensity": 36, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.38, - "Frequency": 3 - }, - { - "Time": 80, - "Intensity": 0.39, - "Frequency": -5 - }, - { - "Time": 203, - "Intensity": 0.52, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.34, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3765, - "Parameters": { - "Intensity": 11, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4015, - "Parameters": { - "Intensity": 15, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.21, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4015, - "Parameters": { - "Intensity": 36, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.33, - "Frequency": 3 - }, - { - "Time": 50, - "Intensity": 0.67, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.49, - "Frequency": 3 - }, - { - "Time": 225, - "Intensity": 0.46, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4265, - "Parameters": { - "Intensity": 40, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.22, - "Frequency": 3 - }, - { - "Time": 52, - "Intensity": 0.53, - "Frequency": -5 - }, - { - "Time": 183, - "Intensity": 0.56, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.36, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4265, - "Parameters": { - "Intensity": 14, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 16, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.36, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4516, - "Parameters": { - "Intensity": 33, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 48, - "Intensity": 0.64, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.63, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.45, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4518, - "Parameters": { - "Intensity": 10, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 77, - "Intensity": 0.72, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 178, - "Intensity": 0.78, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4768, - "Parameters": { - "Intensity": 12, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4768, - "Parameters": { - "Intensity": 34, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 48, - "Intensity": 0.64, - "Frequency": -5 - }, - { - "Time": 135, - "Intensity": 0.43, - "Frequency": 3 - }, - { - "Time": 247, - "Intensity": 0.29, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5022, - "Parameters": { - "Intensity": 31, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 63, - "Intensity": 0.41, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.57, - "Frequency": 3 - }, - { - "Time": 240, - "Intensity": 0.25, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5024, - "Parameters": { - "Intensity": 9, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 445, - "StartTime": 5274, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 12, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 142, - "Intensity": 0.79, - "Frequency": -5 - }, - { - "Time": 335, - "Intensity": 0.7, - "Frequency": 3 - }, - { - "Time": 376, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 445, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5279, - "Parameters": { - "Intensity": 12, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 0, + "Parameters": { + "Intensity": 22, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.32, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.68, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5, + "Parameters": { + "Intensity": 36, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.45, + "Frequency": 3 + }, + { + "Time": 146, + "Intensity": 0.54, + "Frequency": -5 + }, + { + "Time": 223, + "Intensity": 0.67, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.69, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 256, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 3 + }, + { + "Time": 1, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 94, + "Intensity": 0.79, + "Frequency": -5 + }, + { + "Time": 201, + "Intensity": 0.68, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.48, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 258, + "Parameters": { + "Intensity": 46, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 23, + "Intensity": 0.71, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0.48, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 153, + "Intensity": 0.7, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 222, + "Intensity": 0.48, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 506, + "Parameters": { + "Intensity": 46, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.61, + "Frequency": 3 + }, + { + "Time": 95, + "Intensity": 0.18, + "Frequency": -5 + }, + { + "Time": 201, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.65, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 508, + "Parameters": { + "Intensity": 25, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -33 + }, + { + "Time": 33, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 4 + }, + { + "Time": 149, + "Intensity": 0.13, + "Frequency": -13 + }, + { + "Time": 168, + "Intensity": 0.48, + "Frequency": 23 + }, + { + "Time": 194, + "Intensity": 0.22, + "Frequency": -15 + }, + { + "Time": 224, + "Intensity": 0.58, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 758, + "Parameters": { + "Intensity": 31, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 46, + "Intensity": 0.73, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 157, + "Intensity": 0.33, + "Frequency": 5 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 758, + "Parameters": { + "Intensity": 51, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.59, + "Frequency": 3 + }, + { + "Time": 52, + "Intensity": 0.57, + "Frequency": -5 + }, + { + "Time": 103, + "Intensity": 0.62, + "Frequency": 3 + }, + { + "Time": 203, + "Intensity": 0.18, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1008, + "Parameters": { + "Intensity": 14, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.32, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.68, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1008, + "Parameters": { + "Intensity": 33, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 23, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 68, + "Intensity": 0.38, + "Frequency": -5 + }, + { + "Time": 195, + "Intensity": 0.55, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.19, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1258, + "Parameters": { + "Intensity": 49, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 17, + "Intensity": 0.27, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 130, + "Intensity": 0.17, + "Frequency": -15 + }, + { + "Time": 152, + "Intensity": 0.82, + "Frequency": 2 + }, + { + "Time": 191, + "Intensity": 0.19, + "Frequency": -13 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 27 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1258, + "Parameters": { + "Intensity": 60, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.12, + "Frequency": 3 + }, + { + "Time": 85, + "Intensity": 0.23, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.71, + "Frequency": 3 + }, + { + "Time": 231, + "Intensity": 0.86, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1508, + "Parameters": { + "Intensity": 57, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 74, + "Intensity": 0.77, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 157, + "Intensity": 0.61, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1508, + "Parameters": { + "Intensity": 55, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 51, + "Intensity": 0.92, + "Frequency": -5 + }, + { + "Time": 203, + "Intensity": 1, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.8, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1758, + "Parameters": { + "Intensity": 55, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 49, + "Intensity": 0.57, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 92, + "Intensity": 0.75, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.32, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 225, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1758, + "Parameters": { + "Intensity": 57, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.77, + "Frequency": 3 + }, + { + "Time": 82, + "Intensity": 0.67, + "Frequency": -5 + }, + { + "Time": 159, + "Intensity": 0.3, + "Frequency": 3 + }, + { + "Time": 197, + "Intensity": 0.27, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2008, + "Parameters": { + "Intensity": 39, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -33 + }, + { + "Time": 33, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 98, + "Intensity": 0.7, + "Frequency": 5 + }, + { + "Time": 150, + "Intensity": 0.09, + "Frequency": -13 + }, + { + "Time": 167, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 194, + "Intensity": 0.22, + "Frequency": -15 + }, + { + "Time": 224, + "Intensity": 0.58, + "Frequency": 11 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2008, + "Parameters": { + "Intensity": 42, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 58, + "Intensity": 0.36, + "Frequency": 3 + }, + { + "Time": 98, + "Intensity": 0.86, + "Frequency": -5 + }, + { + "Time": 188, + "Intensity": 0.7, + "Frequency": 3 + }, + { + "Time": 246, + "Intensity": 0.28, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2258, + "Parameters": { + "Intensity": 12, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2258, + "Parameters": { + "Intensity": 30, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.25, + "Frequency": 3 + }, + { + "Time": 58, + "Intensity": 0.52, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.63, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.45, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2508, + "Parameters": { + "Intensity": 12, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2508, + "Parameters": { + "Intensity": 31, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.45, + "Frequency": 3 + }, + { + "Time": 53, + "Intensity": 0.46, + "Frequency": -5 + }, + { + "Time": 120, + "Intensity": 0.53, + "Frequency": 3 + }, + { + "Time": 196, + "Intensity": 0.31, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2758, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 22, + "Intensity": 0.36, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 0.53, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.37, + "Frequency": 2 + }, + { + "Time": 187, + "Intensity": 0.09, + "Frequency": -13 + }, + { + "Time": 220, + "Intensity": 0.65, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2758, + "Parameters": { + "Intensity": 51, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 35, + "Intensity": 0.1, + "Frequency": 3 + }, + { + "Time": 83, + "Intensity": 0.15, + "Frequency": -5 + }, + { + "Time": 107, + "Intensity": 0.59, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.81, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3008, + "Parameters": { + "Intensity": 52, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 77, + "Intensity": 0.72, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 178, + "Intensity": 0.78, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3008, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.69, + "Frequency": 3 + }, + { + "Time": 53, + "Intensity": 0.81, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.83, + "Frequency": 3 + }, + { + "Time": 214, + "Intensity": 0.64, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3258, + "Parameters": { + "Intensity": 54, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 35, + "Intensity": 0.19, + "Frequency": 55 + }, + { + "Time": 68, + "Intensity": 0.05, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.23, + "Frequency": 2 + }, + { + "Time": 129, + "Intensity": 0.04, + "Frequency": -15 + }, + { + "Time": 154, + "Intensity": 0.51, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 225, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3258, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.21, + "Frequency": 3 + }, + { + "Time": 164, + "Intensity": 0.69, + "Frequency": -5 + }, + { + "Time": 212, + "Intensity": 0.75, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.58, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3508, + "Parameters": { + "Intensity": 37, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 0.66, + "Frequency": 3 + }, + { + "Time": 76, + "Intensity": 0.75, + "Frequency": -5 + }, + { + "Time": 168, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 211, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3513, + "Parameters": { + "Intensity": 40, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 18, + "Intensity": 0.58, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 96, + "Intensity": 0.25, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.32, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3763, + "Parameters": { + "Intensity": 36, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.38, + "Frequency": 3 + }, + { + "Time": 80, + "Intensity": 0.39, + "Frequency": -5 + }, + { + "Time": 203, + "Intensity": 0.52, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.34, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3765, + "Parameters": { + "Intensity": 11, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4015, + "Parameters": { + "Intensity": 15, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.21, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4015, + "Parameters": { + "Intensity": 36, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.33, + "Frequency": 3 + }, + { + "Time": 50, + "Intensity": 0.67, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.49, + "Frequency": 3 + }, + { + "Time": 225, + "Intensity": 0.46, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4265, + "Parameters": { + "Intensity": 40, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.22, + "Frequency": 3 + }, + { + "Time": 52, + "Intensity": 0.53, + "Frequency": -5 + }, + { + "Time": 183, + "Intensity": 0.56, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.36, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4265, + "Parameters": { + "Intensity": 14, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 16, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.36, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4516, + "Parameters": { + "Intensity": 33, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 48, + "Intensity": 0.64, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.63, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.45, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4518, + "Parameters": { + "Intensity": 10, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 77, + "Intensity": 0.72, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 178, + "Intensity": 0.78, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4768, + "Parameters": { + "Intensity": 12, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4768, + "Parameters": { + "Intensity": 34, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 48, + "Intensity": 0.64, + "Frequency": -5 + }, + { + "Time": 135, + "Intensity": 0.43, + "Frequency": 3 + }, + { + "Time": 247, + "Intensity": 0.29, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5022, + "Parameters": { + "Intensity": 31, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 63, + "Intensity": 0.41, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.57, + "Frequency": 3 + }, + { + "Time": 240, + "Intensity": 0.25, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5024, + "Parameters": { + "Intensity": 9, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 445, + "StartTime": 5274, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 12, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 142, + "Intensity": 0.79, + "Frequency": -5 + }, + { + "Time": 335, + "Intensity": 0.7, + "Frequency": 3 + }, + { + "Time": 376, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 445, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5279, + "Parameters": { + "Intensity": 12, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_m.json index f6c959e73efb0500f1828fa8827baf312f07afeb..5b4795eeec7a67db32b681bf2e35ca99646ec432 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wave_m.json @@ -1,2304 +1,2304 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 0, - "Parameters": { - "Intensity": 30, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.32, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.68, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.45, - "Frequency": 3 - }, - { - "Time": 146, - "Intensity": 0.54, - "Frequency": -5 - }, - { - "Time": 223, - "Intensity": 0.67, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.69, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 256, - "Parameters": { - "Intensity": 75, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 3 - }, - { - "Time": 1, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 94, - "Intensity": 0.79, - "Frequency": -5 - }, - { - "Time": 201, - "Intensity": 0.68, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.48, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 258, - "Parameters": { - "Intensity": 61, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 23, - "Intensity": 0.71, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0.48, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 153, - "Intensity": 0.7, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 222, - "Intensity": 0.48, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 506, - "Parameters": { - "Intensity": 61, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.61, - "Frequency": 3 - }, - { - "Time": 95, - "Intensity": 0.18, - "Frequency": -5 - }, - { - "Time": 201, - "Intensity": 0.29, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.65, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 508, - "Parameters": { - "Intensity": 33, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -33 - }, - { - "Time": 33, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 72, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 100, - "Intensity": 0.24, - "Frequency": 4 - }, - { - "Time": 149, - "Intensity": 0.13, - "Frequency": -13 - }, - { - "Time": 168, - "Intensity": 0.48, - "Frequency": 23 - }, - { - "Time": 194, - "Intensity": 0.22, - "Frequency": -15 - }, - { - "Time": 224, - "Intensity": 0.58, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 758, - "Parameters": { - "Intensity": 42, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 46, - "Intensity": 0.73, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 157, - "Intensity": 0.33, - "Frequency": 5 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 758, - "Parameters": { - "Intensity": 68, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.59, - "Frequency": 3 - }, - { - "Time": 52, - "Intensity": 0.57, - "Frequency": -5 - }, - { - "Time": 103, - "Intensity": 0.62, - "Frequency": 3 - }, - { - "Time": 203, - "Intensity": 0.18, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1008, - "Parameters": { - "Intensity": 19, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.32, - "Frequency": -6 - }, - { - "Time": 128, - "Intensity": 0.68, - "Frequency": 8 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1008, - "Parameters": { - "Intensity": 44, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 23, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 68, - "Intensity": 0.38, - "Frequency": -5 - }, - { - "Time": 195, - "Intensity": 0.55, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.19, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1258, - "Parameters": { - "Intensity": 65, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 17, - "Intensity": 0.27, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 95, - "Intensity": 0.41, - "Frequency": 2 - }, - { - "Time": 130, - "Intensity": 0.17, - "Frequency": -15 - }, - { - "Time": 152, - "Intensity": 0.82, - "Frequency": 2 - }, - { - "Time": 191, - "Intensity": 0.19, - "Frequency": -13 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 27 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1258, - "Parameters": { - "Intensity": 80, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.12, - "Frequency": 3 - }, - { - "Time": 85, - "Intensity": 0.23, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.71, - "Frequency": 3 - }, - { - "Time": 231, - "Intensity": 0.86, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1508, - "Parameters": { - "Intensity": 76, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 74, - "Intensity": 0.77, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 157, - "Intensity": 0.61, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1508, - "Parameters": { - "Intensity": 73, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 51, - "Intensity": 0.92, - "Frequency": -5 - }, - { - "Time": 203, - "Intensity": 1, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.8, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1758, - "Parameters": { - "Intensity": 74, - "Frequency": 33, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 49, - "Intensity": 0.57, - "Frequency": 10 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 92, - "Intensity": 0.75, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.32, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 225, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 1758, - "Parameters": { - "Intensity": 76, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.77, - "Frequency": 3 - }, - { - "Time": 82, - "Intensity": 0.67, - "Frequency": -5 - }, - { - "Time": 159, - "Intensity": 0.3, - "Frequency": 3 - }, - { - "Time": 197, - "Intensity": 0.27, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2008, - "Parameters": { - "Intensity": 52, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -33 - }, - { - "Time": 33, - "Intensity": 0.31, - "Frequency": 0 - }, - { - "Time": 50, - "Intensity": 0.1, - "Frequency": -14 - }, - { - "Time": 98, - "Intensity": 0.7, - "Frequency": 5 - }, - { - "Time": 150, - "Intensity": 0.09, - "Frequency": -13 - }, - { - "Time": 167, - "Intensity": 0.49, - "Frequency": 0 - }, - { - "Time": 194, - "Intensity": 0.22, - "Frequency": -15 - }, - { - "Time": 224, - "Intensity": 0.58, - "Frequency": 11 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -5 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2008, - "Parameters": { - "Intensity": 56, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 58, - "Intensity": 0.36, - "Frequency": 3 - }, - { - "Time": 98, - "Intensity": 0.86, - "Frequency": -5 - }, - { - "Time": 188, - "Intensity": 0.7, - "Frequency": 3 - }, - { - "Time": 246, - "Intensity": 0.28, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2258, - "Parameters": { - "Intensity": 16, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2258, - "Parameters": { - "Intensity": 40, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 40, - "Intensity": 0.25, - "Frequency": 3 - }, - { - "Time": 58, - "Intensity": 0.52, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.63, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.45, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2508, - "Parameters": { - "Intensity": 16, - "Frequency": 20, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2508, - "Parameters": { - "Intensity": 41, - "Frequency": 0, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.45, - "Frequency": 3 - }, - { - "Time": 53, - "Intensity": 0.46, - "Frequency": -5 - }, - { - "Time": 120, - "Intensity": 0.53, - "Frequency": 3 - }, - { - "Time": 196, - "Intensity": 0.31, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2758, - "Parameters": { - "Intensity": 59, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 22, - "Intensity": 0.36, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 101, - "Intensity": 0.53, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.37, - "Frequency": 2 - }, - { - "Time": 187, - "Intensity": 0.09, - "Frequency": -13 - }, - { - "Time": 220, - "Intensity": 0.65, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 2758, - "Parameters": { - "Intensity": 68, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 35, - "Intensity": 0.1, - "Frequency": 3 - }, - { - "Time": 83, - "Intensity": 0.15, - "Frequency": -5 - }, - { - "Time": 107, - "Intensity": 0.59, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.81, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3008, - "Parameters": { - "Intensity": 69, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 77, - "Intensity": 0.72, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 178, - "Intensity": 0.78, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3008, - "Parameters": { - "Intensity": 80, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.69, - "Frequency": 3 - }, - { - "Time": 53, - "Intensity": 0.81, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.83, - "Frequency": 3 - }, - { - "Time": 214, - "Intensity": 0.64, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3258, - "Parameters": { - "Intensity": 72, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 35, - "Intensity": 0.19, - "Frequency": 55 - }, - { - "Time": 68, - "Intensity": 0.05, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.23, - "Frequency": 2 - }, - { - "Time": 129, - "Intensity": 0.04, - "Frequency": -15 - }, - { - "Time": 154, - "Intensity": 0.51, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 225, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3258, - "Parameters": { - "Intensity": 64, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.21, - "Frequency": 3 - }, - { - "Time": 164, - "Intensity": 0.69, - "Frequency": -5 - }, - { - "Time": 212, - "Intensity": 0.75, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.58, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3508, - "Parameters": { - "Intensity": 50, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 0.66, - "Frequency": 3 - }, - { - "Time": 76, - "Intensity": 0.75, - "Frequency": -5 - }, - { - "Time": 168, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 211, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3513, - "Parameters": { - "Intensity": 54, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -15 - }, - { - "Time": 18, - "Intensity": 0.58, - "Frequency": 55 - }, - { - "Time": 67, - "Intensity": 0.14, - "Frequency": 0 - }, - { - "Time": 96, - "Intensity": 0.25, - "Frequency": 2 - }, - { - "Time": 131, - "Intensity": 0.11, - "Frequency": -15 - }, - { - "Time": 155, - "Intensity": 0.32, - "Frequency": 2 - }, - { - "Time": 171, - "Intensity": 0.11, - "Frequency": -13 - }, - { - "Time": 234, - "Intensity": 0.33, - "Frequency": 3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -16 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3763, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 28, - "Intensity": 0.38, - "Frequency": 3 - }, - { - "Time": 80, - "Intensity": 0.39, - "Frequency": -5 - }, - { - "Time": 203, - "Intensity": 0.52, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.34, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 3765, - "Parameters": { - "Intensity": 15, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4015, - "Parameters": { - "Intensity": 20, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 120, - "Intensity": 0.21, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4015, - "Parameters": { - "Intensity": 48, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.33, - "Frequency": 3 - }, - { - "Time": 50, - "Intensity": 0.67, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.49, - "Frequency": 3 - }, - { - "Time": 225, - "Intensity": 0.46, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4265, - "Parameters": { - "Intensity": 54, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 21, - "Intensity": 0.22, - "Frequency": 3 - }, - { - "Time": 52, - "Intensity": 0.53, - "Frequency": -5 - }, - { - "Time": 183, - "Intensity": 0.56, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.36, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4265, - "Parameters": { - "Intensity": 19, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 16, - "Intensity": 0.46, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.36, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4516, - "Parameters": { - "Intensity": 44, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 2, - "Intensity": 0.54, - "Frequency": 3 - }, - { - "Time": 48, - "Intensity": 0.64, - "Frequency": -5 - }, - { - "Time": 119, - "Intensity": 0.63, - "Frequency": 3 - }, - { - "Time": 249, - "Intensity": 0.45, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4518, - "Parameters": { - "Intensity": 14, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 33, - "Intensity": 0.08, - "Frequency": -15 - }, - { - "Time": 50, - "Intensity": 0.03, - "Frequency": -13 - }, - { - "Time": 77, - "Intensity": 0.72, - "Frequency": 4 - }, - { - "Time": 97, - "Intensity": 0.22, - "Frequency": -16 - }, - { - "Time": 118, - "Intensity": 0.47, - "Frequency": -4 - }, - { - "Time": 156, - "Intensity": 0.09, - "Frequency": -3 - }, - { - "Time": 178, - "Intensity": 0.78, - "Frequency": 5 - }, - { - "Time": 203, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 235, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4768, - "Parameters": { - "Intensity": 16, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 4768, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 48, - "Intensity": 0.64, - "Frequency": -5 - }, - { - "Time": 135, - "Intensity": 0.43, - "Frequency": 3 - }, - { - "Time": 247, - "Intensity": 0.29, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5022, - "Parameters": { - "Intensity": 41, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 0.35, - "Frequency": 3 - }, - { - "Time": 63, - "Intensity": 0.41, - "Frequency": -5 - }, - { - "Time": 124, - "Intensity": 0.57, - "Frequency": 3 - }, - { - "Time": 240, - "Intensity": 0.25, - "Frequency": -3 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5024, - "Parameters": { - "Intensity": 12, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -19 - }, - { - "Time": 51, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 67, - "Intensity": 0, - "Frequency": -9 - }, - { - "Time": 113, - "Intensity": 0.19, - "Frequency": 2 - }, - { - "Time": 150, - "Intensity": 0, - "Frequency": -17 - }, - { - "Time": 173, - "Intensity": 0.66, - "Frequency": 5 - }, - { - "Time": 205, - "Intensity": 0.38, - "Frequency": 0 - }, - { - "Time": 217, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 238, - "Intensity": 0.16, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -11 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 445, - "StartTime": 5274, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 12, - "Intensity": 0.44, - "Frequency": 3 - }, - { - "Time": 142, - "Intensity": 0.79, - "Frequency": -5 - }, - { - "Time": 335, - "Intensity": 0.7, - "Frequency": 3 - }, - { - "Time": 376, - "Intensity": 0.26, - "Frequency": -3 - }, - { - "Time": 445, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 250, - "StartTime": 5279, - "Parameters": { - "Intensity": 16, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -20 - }, - { - "Time": 17, - "Intensity": 0.45, - "Frequency": 5 - }, - { - "Time": 74, - "Intensity": 0.07, - "Frequency": -13 - }, - { - "Time": 100, - "Intensity": 0.61, - "Frequency": -6 - }, - { - "Time": 130, - "Intensity": 0.8, - "Frequency": 0 - }, - { - "Time": 167, - "Intensity": 0.1, - "Frequency": -16 - }, - { - "Time": 200, - "Intensity": 0.01, - "Frequency": 3 - }, - { - "Time": 232, - "Intensity": 0.18, - "Frequency": 0 - }, - { - "Time": 250, - "Intensity": 0, - "Frequency": -19 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 0, + "Parameters": { + "Intensity": 30, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.32, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.68, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.45, + "Frequency": 3 + }, + { + "Time": 146, + "Intensity": 0.54, + "Frequency": -5 + }, + { + "Time": 223, + "Intensity": 0.67, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.69, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 256, + "Parameters": { + "Intensity": 75, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 3 + }, + { + "Time": 1, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 94, + "Intensity": 0.79, + "Frequency": -5 + }, + { + "Time": 201, + "Intensity": 0.68, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.48, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 258, + "Parameters": { + "Intensity": 61, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 23, + "Intensity": 0.71, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0.48, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 153, + "Intensity": 0.7, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 222, + "Intensity": 0.48, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 506, + "Parameters": { + "Intensity": 61, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.61, + "Frequency": 3 + }, + { + "Time": 95, + "Intensity": 0.18, + "Frequency": -5 + }, + { + "Time": 201, + "Intensity": 0.29, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.65, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 508, + "Parameters": { + "Intensity": 33, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -33 + }, + { + "Time": 33, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 72, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 100, + "Intensity": 0.24, + "Frequency": 4 + }, + { + "Time": 149, + "Intensity": 0.13, + "Frequency": -13 + }, + { + "Time": 168, + "Intensity": 0.48, + "Frequency": 23 + }, + { + "Time": 194, + "Intensity": 0.22, + "Frequency": -15 + }, + { + "Time": 224, + "Intensity": 0.58, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 758, + "Parameters": { + "Intensity": 42, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 46, + "Intensity": 0.73, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 157, + "Intensity": 0.33, + "Frequency": 5 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 758, + "Parameters": { + "Intensity": 68, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.59, + "Frequency": 3 + }, + { + "Time": 52, + "Intensity": 0.57, + "Frequency": -5 + }, + { + "Time": 103, + "Intensity": 0.62, + "Frequency": 3 + }, + { + "Time": 203, + "Intensity": 0.18, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1008, + "Parameters": { + "Intensity": 19, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.32, + "Frequency": -6 + }, + { + "Time": 128, + "Intensity": 0.68, + "Frequency": 8 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1008, + "Parameters": { + "Intensity": 44, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 23, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 68, + "Intensity": 0.38, + "Frequency": -5 + }, + { + "Time": 195, + "Intensity": 0.55, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.19, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1258, + "Parameters": { + "Intensity": 65, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 17, + "Intensity": 0.27, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 95, + "Intensity": 0.41, + "Frequency": 2 + }, + { + "Time": 130, + "Intensity": 0.17, + "Frequency": -15 + }, + { + "Time": 152, + "Intensity": 0.82, + "Frequency": 2 + }, + { + "Time": 191, + "Intensity": 0.19, + "Frequency": -13 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 27 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1258, + "Parameters": { + "Intensity": 80, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.12, + "Frequency": 3 + }, + { + "Time": 85, + "Intensity": 0.23, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.71, + "Frequency": 3 + }, + { + "Time": 231, + "Intensity": 0.86, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1508, + "Parameters": { + "Intensity": 76, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 74, + "Intensity": 0.77, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 157, + "Intensity": 0.61, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1508, + "Parameters": { + "Intensity": 73, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 51, + "Intensity": 0.92, + "Frequency": -5 + }, + { + "Time": 203, + "Intensity": 1, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.8, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1758, + "Parameters": { + "Intensity": 74, + "Frequency": 33, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 49, + "Intensity": 0.57, + "Frequency": 10 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 92, + "Intensity": 0.75, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.32, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 225, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 1758, + "Parameters": { + "Intensity": 76, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.77, + "Frequency": 3 + }, + { + "Time": 82, + "Intensity": 0.67, + "Frequency": -5 + }, + { + "Time": 159, + "Intensity": 0.3, + "Frequency": 3 + }, + { + "Time": 197, + "Intensity": 0.27, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2008, + "Parameters": { + "Intensity": 52, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -33 + }, + { + "Time": 33, + "Intensity": 0.31, + "Frequency": 0 + }, + { + "Time": 50, + "Intensity": 0.1, + "Frequency": -14 + }, + { + "Time": 98, + "Intensity": 0.7, + "Frequency": 5 + }, + { + "Time": 150, + "Intensity": 0.09, + "Frequency": -13 + }, + { + "Time": 167, + "Intensity": 0.49, + "Frequency": 0 + }, + { + "Time": 194, + "Intensity": 0.22, + "Frequency": -15 + }, + { + "Time": 224, + "Intensity": 0.58, + "Frequency": 11 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -5 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2008, + "Parameters": { + "Intensity": 56, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 58, + "Intensity": 0.36, + "Frequency": 3 + }, + { + "Time": 98, + "Intensity": 0.86, + "Frequency": -5 + }, + { + "Time": 188, + "Intensity": 0.7, + "Frequency": 3 + }, + { + "Time": 246, + "Intensity": 0.28, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2258, + "Parameters": { + "Intensity": 16, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2258, + "Parameters": { + "Intensity": 40, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 40, + "Intensity": 0.25, + "Frequency": 3 + }, + { + "Time": 58, + "Intensity": 0.52, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.63, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.45, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2508, + "Parameters": { + "Intensity": 16, + "Frequency": 20, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2508, + "Parameters": { + "Intensity": 41, + "Frequency": 0, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.45, + "Frequency": 3 + }, + { + "Time": 53, + "Intensity": 0.46, + "Frequency": -5 + }, + { + "Time": 120, + "Intensity": 0.53, + "Frequency": 3 + }, + { + "Time": 196, + "Intensity": 0.31, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2758, + "Parameters": { + "Intensity": 59, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 22, + "Intensity": 0.36, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 101, + "Intensity": 0.53, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.37, + "Frequency": 2 + }, + { + "Time": 187, + "Intensity": 0.09, + "Frequency": -13 + }, + { + "Time": 220, + "Intensity": 0.65, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 2758, + "Parameters": { + "Intensity": 68, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 35, + "Intensity": 0.1, + "Frequency": 3 + }, + { + "Time": 83, + "Intensity": 0.15, + "Frequency": -5 + }, + { + "Time": 107, + "Intensity": 0.59, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.81, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3008, + "Parameters": { + "Intensity": 69, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 77, + "Intensity": 0.72, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 178, + "Intensity": 0.78, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3008, + "Parameters": { + "Intensity": 80, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.69, + "Frequency": 3 + }, + { + "Time": 53, + "Intensity": 0.81, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.83, + "Frequency": 3 + }, + { + "Time": 214, + "Intensity": 0.64, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3258, + "Parameters": { + "Intensity": 72, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 35, + "Intensity": 0.19, + "Frequency": 55 + }, + { + "Time": 68, + "Intensity": 0.05, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.23, + "Frequency": 2 + }, + { + "Time": 129, + "Intensity": 0.04, + "Frequency": -15 + }, + { + "Time": 154, + "Intensity": 0.51, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 225, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3258, + "Parameters": { + "Intensity": 64, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.21, + "Frequency": 3 + }, + { + "Time": 164, + "Intensity": 0.69, + "Frequency": -5 + }, + { + "Time": 212, + "Intensity": 0.75, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.58, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3508, + "Parameters": { + "Intensity": 50, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 0.66, + "Frequency": 3 + }, + { + "Time": 76, + "Intensity": 0.75, + "Frequency": -5 + }, + { + "Time": 168, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 211, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3513, + "Parameters": { + "Intensity": 54, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -15 + }, + { + "Time": 18, + "Intensity": 0.58, + "Frequency": 55 + }, + { + "Time": 67, + "Intensity": 0.14, + "Frequency": 0 + }, + { + "Time": 96, + "Intensity": 0.25, + "Frequency": 2 + }, + { + "Time": 131, + "Intensity": 0.11, + "Frequency": -15 + }, + { + "Time": 155, + "Intensity": 0.32, + "Frequency": 2 + }, + { + "Time": 171, + "Intensity": 0.11, + "Frequency": -13 + }, + { + "Time": 234, + "Intensity": 0.33, + "Frequency": 3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -16 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3763, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 28, + "Intensity": 0.38, + "Frequency": 3 + }, + { + "Time": 80, + "Intensity": 0.39, + "Frequency": -5 + }, + { + "Time": 203, + "Intensity": 0.52, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.34, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 3765, + "Parameters": { + "Intensity": 15, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4015, + "Parameters": { + "Intensity": 20, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 120, + "Intensity": 0.21, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4015, + "Parameters": { + "Intensity": 48, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.33, + "Frequency": 3 + }, + { + "Time": 50, + "Intensity": 0.67, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.49, + "Frequency": 3 + }, + { + "Time": 225, + "Intensity": 0.46, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4265, + "Parameters": { + "Intensity": 54, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 21, + "Intensity": 0.22, + "Frequency": 3 + }, + { + "Time": 52, + "Intensity": 0.53, + "Frequency": -5 + }, + { + "Time": 183, + "Intensity": 0.56, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.36, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4265, + "Parameters": { + "Intensity": 19, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 16, + "Intensity": 0.46, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.36, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4516, + "Parameters": { + "Intensity": 44, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 2, + "Intensity": 0.54, + "Frequency": 3 + }, + { + "Time": 48, + "Intensity": 0.64, + "Frequency": -5 + }, + { + "Time": 119, + "Intensity": 0.63, + "Frequency": 3 + }, + { + "Time": 249, + "Intensity": 0.45, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4518, + "Parameters": { + "Intensity": 14, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 33, + "Intensity": 0.08, + "Frequency": -15 + }, + { + "Time": 50, + "Intensity": 0.03, + "Frequency": -13 + }, + { + "Time": 77, + "Intensity": 0.72, + "Frequency": 4 + }, + { + "Time": 97, + "Intensity": 0.22, + "Frequency": -16 + }, + { + "Time": 118, + "Intensity": 0.47, + "Frequency": -4 + }, + { + "Time": 156, + "Intensity": 0.09, + "Frequency": -3 + }, + { + "Time": 178, + "Intensity": 0.78, + "Frequency": 5 + }, + { + "Time": 203, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 235, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4768, + "Parameters": { + "Intensity": 16, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 4768, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 48, + "Intensity": 0.64, + "Frequency": -5 + }, + { + "Time": 135, + "Intensity": 0.43, + "Frequency": 3 + }, + { + "Time": 247, + "Intensity": 0.29, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5022, + "Parameters": { + "Intensity": 41, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 0.35, + "Frequency": 3 + }, + { + "Time": 63, + "Intensity": 0.41, + "Frequency": -5 + }, + { + "Time": 124, + "Intensity": 0.57, + "Frequency": 3 + }, + { + "Time": 240, + "Intensity": 0.25, + "Frequency": -3 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5024, + "Parameters": { + "Intensity": 12, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -19 + }, + { + "Time": 51, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 67, + "Intensity": 0, + "Frequency": -9 + }, + { + "Time": 113, + "Intensity": 0.19, + "Frequency": 2 + }, + { + "Time": 150, + "Intensity": 0, + "Frequency": -17 + }, + { + "Time": 173, + "Intensity": 0.66, + "Frequency": 5 + }, + { + "Time": 205, + "Intensity": 0.38, + "Frequency": 0 + }, + { + "Time": 217, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 238, + "Intensity": 0.16, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -11 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 445, + "StartTime": 5274, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 12, + "Intensity": 0.44, + "Frequency": 3 + }, + { + "Time": 142, + "Intensity": 0.79, + "Frequency": -5 + }, + { + "Time": 335, + "Intensity": 0.7, + "Frequency": 3 + }, + { + "Time": 376, + "Intensity": 0.26, + "Frequency": -3 + }, + { + "Time": 445, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 250, + "StartTime": 5279, + "Parameters": { + "Intensity": 16, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -20 + }, + { + "Time": 17, + "Intensity": 0.45, + "Frequency": 5 + }, + { + "Time": 74, + "Intensity": 0.07, + "Frequency": -13 + }, + { + "Time": 100, + "Intensity": 0.61, + "Frequency": -6 + }, + { + "Time": 130, + "Intensity": 0.8, + "Frequency": 0 + }, + { + "Time": 167, + "Intensity": 0.1, + "Frequency": -16 + }, + { + "Time": 200, + "Intensity": 0.01, + "Frequency": 3 + }, + { + "Time": 232, + "Intensity": 0.18, + "Frequency": 0 + }, + { + "Time": 250, + "Intensity": 0, + "Frequency": -19 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_h.json index 45009d55aaf093064c86df1065564e8256c86558..6aa5ed699e3d84c54c29f7e43622efa5c6a2e83e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_h.json @@ -1,60 +1,60 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 75, - "StartTime": 538, - "Parameters": { - "Intensity": 100, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 75, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 636, - "Parameters": { - "Intensity": 50, - "Frequency": 37 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 75, + "StartTime": 538, + "Parameters": { + "Intensity": 100, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 75, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 636, + "Parameters": { + "Intensity": 50, + "Frequency": 37 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_l.json index 05980341e2016d502a5b9cf667585d32e0c7ad3f..5d1bc935ffa57dae5c52f632e436f9f0c7d2ba72 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_l.json @@ -1,60 +1,60 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 75, - "StartTime": 538, - "Parameters": { - "Intensity": 60, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 75, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 636, - "Parameters": { - "Intensity": 30, - "Frequency": 37 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 75, + "StartTime": 538, + "Parameters": { + "Intensity": 60, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 75, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 636, + "Parameters": { + "Intensity": 30, + "Frequency": 37 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_m.json index 1302c77d4453d734290322d5f05d35dd8f5183a1..38a97f0d277c9029be1ff00aa66ee89c7535f334 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Winchester_m.json @@ -1,60 +1,60 @@ -{ - "MetaData": { - "Create": "2022-04-13", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 75, - "StartTime": 538, - "Parameters": { - "Intensity": 80, - "Frequency": 56, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 1, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 46, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 75, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 636, - "Parameters": { - "Intensity": 40, - "Frequency": 37 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2022-04-13", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 75, + "StartTime": 538, + "Parameters": { + "Intensity": 80, + "Frequency": 56, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 1, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 46, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 75, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 636, + "Parameters": { + "Intensity": 40, + "Frequency": 37 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_h.json index a200efe9e13372b97e9baedcb732798241351eb1..6703e7e083207a1762ee78334889d6544a6b327f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_h.json @@ -1,259 +1,259 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 4460, - "StartTime": 0, - "Parameters": { - "Intensity": 76, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 602, - "Intensity": 0.76, - "Frequency": -20 - }, - { - "Time": 1351, - "Intensity": 0.66, - "Frequency": -50 - }, - { - "Time": 1510, - "Intensity": 1, - "Frequency": -20 - }, - { - "Time": 2377, - "Intensity": 0.69, - "Frequency": -50 - }, - { - "Time": 2457, - "Intensity": 0.95, - "Frequency": 0 - }, - { - "Time": 3287, - "Intensity": 0.67, - "Frequency": -50 - }, - { - "Time": 3381, - "Intensity": 0.93, - "Frequency": -20 - }, - { - "Time": 3898, - "Intensity": 0.65, - "Frequency": -50 - }, - { - "Time": 3985, - "Intensity": 0.91, - "Frequency": -20 - }, - { - "Time": 4456, - "Intensity": 0.63, - "Frequency": -40 - }, - { - "Time": 4460, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 3860, - "StartTime": 5, - "Parameters": { - "Intensity": 65, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 637, - "Intensity": 0.81, - "Frequency": -20 - }, - { - "Time": 1517, - "Intensity": 0.7, - "Frequency": -50 - }, - { - "Time": 1583, - "Intensity": 1, - "Frequency": -20 - }, - { - "Time": 2420, - "Intensity": 0.72, - "Frequency": -50 - }, - { - "Time": 2528, - "Intensity": 0.95, - "Frequency": 0 - }, - { - "Time": 3289, - "Intensity": 0.74, - "Frequency": -50 - }, - { - "Time": 3358, - "Intensity": 0.94, - "Frequency": -20 - }, - { - "Time": 3859, - "Intensity": 0.61, - "Frequency": -40 - }, - { - "Time": 3860, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2668, - "StartTime": 3865, - "Parameters": { - "Intensity": 64, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 152, - "Intensity": 0.84, - "Frequency": -20 - }, - { - "Time": 552, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 819, - "Intensity": 0.74, - "Frequency": -20 - }, - { - "Time": 1706, - "Intensity": 0.35, - "Frequency": -50 - }, - { - "Time": 1817, - "Intensity": 0.54, - "Frequency": -20 - }, - { - "Time": 2449, - "Intensity": 0.25, - "Frequency": -30 - }, - { - "Time": 2668, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2102, - "StartTime": 4460, - "Parameters": { - "Intensity": 71, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.66, - "Frequency": -50 - }, - { - "Time": 273, - "Intensity": 0.75, - "Frequency": -20 - }, - { - "Time": 1118, - "Intensity": 0.37, - "Frequency": -50 - }, - { - "Time": 1222, - "Intensity": 0.54, - "Frequency": -20 - }, - { - "Time": 1924, - "Intensity": 0.27, - "Frequency": -30 - }, - { - "Time": 2102, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 4460, + "StartTime": 0, + "Parameters": { + "Intensity": 76, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 602, + "Intensity": 0.76, + "Frequency": -20 + }, + { + "Time": 1351, + "Intensity": 0.66, + "Frequency": -50 + }, + { + "Time": 1510, + "Intensity": 1, + "Frequency": -20 + }, + { + "Time": 2377, + "Intensity": 0.69, + "Frequency": -50 + }, + { + "Time": 2457, + "Intensity": 0.95, + "Frequency": 0 + }, + { + "Time": 3287, + "Intensity": 0.67, + "Frequency": -50 + }, + { + "Time": 3381, + "Intensity": 0.93, + "Frequency": -20 + }, + { + "Time": 3898, + "Intensity": 0.65, + "Frequency": -50 + }, + { + "Time": 3985, + "Intensity": 0.91, + "Frequency": -20 + }, + { + "Time": 4456, + "Intensity": 0.63, + "Frequency": -40 + }, + { + "Time": 4460, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 3860, + "StartTime": 5, + "Parameters": { + "Intensity": 65, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 637, + "Intensity": 0.81, + "Frequency": -20 + }, + { + "Time": 1517, + "Intensity": 0.7, + "Frequency": -50 + }, + { + "Time": 1583, + "Intensity": 1, + "Frequency": -20 + }, + { + "Time": 2420, + "Intensity": 0.72, + "Frequency": -50 + }, + { + "Time": 2528, + "Intensity": 0.95, + "Frequency": 0 + }, + { + "Time": 3289, + "Intensity": 0.74, + "Frequency": -50 + }, + { + "Time": 3358, + "Intensity": 0.94, + "Frequency": -20 + }, + { + "Time": 3859, + "Intensity": 0.61, + "Frequency": -40 + }, + { + "Time": 3860, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2668, + "StartTime": 3865, + "Parameters": { + "Intensity": 64, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 152, + "Intensity": 0.84, + "Frequency": -20 + }, + { + "Time": 552, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 819, + "Intensity": 0.74, + "Frequency": -20 + }, + { + "Time": 1706, + "Intensity": 0.35, + "Frequency": -50 + }, + { + "Time": 1817, + "Intensity": 0.54, + "Frequency": -20 + }, + { + "Time": 2449, + "Intensity": 0.25, + "Frequency": -30 + }, + { + "Time": 2668, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2102, + "StartTime": 4460, + "Parameters": { + "Intensity": 71, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.66, + "Frequency": -50 + }, + { + "Time": 273, + "Intensity": 0.75, + "Frequency": -20 + }, + { + "Time": 1118, + "Intensity": 0.37, + "Frequency": -50 + }, + { + "Time": 1222, + "Intensity": 0.54, + "Frequency": -20 + }, + { + "Time": 1924, + "Intensity": 0.27, + "Frequency": -30 + }, + { + "Time": 2102, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_l.json index eee1c8044c559cb304d9d26bbb1ea7c9c2684bfa..2fdc69159844dc1488be5702404aacffda5ae14e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_l.json @@ -1,259 +1,259 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 4460, - "StartTime": 0, - "Parameters": { - "Intensity": 45, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 602, - "Intensity": 0.76, - "Frequency": -20 - }, - { - "Time": 1351, - "Intensity": 0.66, - "Frequency": -50 - }, - { - "Time": 1510, - "Intensity": 1, - "Frequency": -20 - }, - { - "Time": 2377, - "Intensity": 0.69, - "Frequency": -50 - }, - { - "Time": 2457, - "Intensity": 0.95, - "Frequency": 0 - }, - { - "Time": 3287, - "Intensity": 0.67, - "Frequency": -50 - }, - { - "Time": 3381, - "Intensity": 0.93, - "Frequency": -20 - }, - { - "Time": 3898, - "Intensity": 0.65, - "Frequency": -50 - }, - { - "Time": 3985, - "Intensity": 0.91, - "Frequency": -20 - }, - { - "Time": 4456, - "Intensity": 0.63, - "Frequency": -40 - }, - { - "Time": 4460, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 3860, - "StartTime": 5, - "Parameters": { - "Intensity": 39, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 637, - "Intensity": 0.81, - "Frequency": -20 - }, - { - "Time": 1517, - "Intensity": 0.7, - "Frequency": -50 - }, - { - "Time": 1583, - "Intensity": 1, - "Frequency": -20 - }, - { - "Time": 2420, - "Intensity": 0.72, - "Frequency": -50 - }, - { - "Time": 2528, - "Intensity": 0.95, - "Frequency": 0 - }, - { - "Time": 3289, - "Intensity": 0.74, - "Frequency": -50 - }, - { - "Time": 3358, - "Intensity": 0.94, - "Frequency": -20 - }, - { - "Time": 3859, - "Intensity": 0.61, - "Frequency": -40 - }, - { - "Time": 3860, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2668, - "StartTime": 3865, - "Parameters": { - "Intensity": 38, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 152, - "Intensity": 0.84, - "Frequency": -20 - }, - { - "Time": 552, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 819, - "Intensity": 0.74, - "Frequency": -20 - }, - { - "Time": 1706, - "Intensity": 0.35, - "Frequency": -50 - }, - { - "Time": 1817, - "Intensity": 0.54, - "Frequency": -20 - }, - { - "Time": 2449, - "Intensity": 0.25, - "Frequency": -30 - }, - { - "Time": 2668, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2102, - "StartTime": 4460, - "Parameters": { - "Intensity": 42, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.66, - "Frequency": -50 - }, - { - "Time": 273, - "Intensity": 0.75, - "Frequency": -20 - }, - { - "Time": 1118, - "Intensity": 0.37, - "Frequency": -50 - }, - { - "Time": 1222, - "Intensity": 0.54, - "Frequency": -20 - }, - { - "Time": 1924, - "Intensity": 0.27, - "Frequency": -30 - }, - { - "Time": 2102, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 4460, + "StartTime": 0, + "Parameters": { + "Intensity": 45, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 602, + "Intensity": 0.76, + "Frequency": -20 + }, + { + "Time": 1351, + "Intensity": 0.66, + "Frequency": -50 + }, + { + "Time": 1510, + "Intensity": 1, + "Frequency": -20 + }, + { + "Time": 2377, + "Intensity": 0.69, + "Frequency": -50 + }, + { + "Time": 2457, + "Intensity": 0.95, + "Frequency": 0 + }, + { + "Time": 3287, + "Intensity": 0.67, + "Frequency": -50 + }, + { + "Time": 3381, + "Intensity": 0.93, + "Frequency": -20 + }, + { + "Time": 3898, + "Intensity": 0.65, + "Frequency": -50 + }, + { + "Time": 3985, + "Intensity": 0.91, + "Frequency": -20 + }, + { + "Time": 4456, + "Intensity": 0.63, + "Frequency": -40 + }, + { + "Time": 4460, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 3860, + "StartTime": 5, + "Parameters": { + "Intensity": 39, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 637, + "Intensity": 0.81, + "Frequency": -20 + }, + { + "Time": 1517, + "Intensity": 0.7, + "Frequency": -50 + }, + { + "Time": 1583, + "Intensity": 1, + "Frequency": -20 + }, + { + "Time": 2420, + "Intensity": 0.72, + "Frequency": -50 + }, + { + "Time": 2528, + "Intensity": 0.95, + "Frequency": 0 + }, + { + "Time": 3289, + "Intensity": 0.74, + "Frequency": -50 + }, + { + "Time": 3358, + "Intensity": 0.94, + "Frequency": -20 + }, + { + "Time": 3859, + "Intensity": 0.61, + "Frequency": -40 + }, + { + "Time": 3860, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2668, + "StartTime": 3865, + "Parameters": { + "Intensity": 38, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 152, + "Intensity": 0.84, + "Frequency": -20 + }, + { + "Time": 552, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 819, + "Intensity": 0.74, + "Frequency": -20 + }, + { + "Time": 1706, + "Intensity": 0.35, + "Frequency": -50 + }, + { + "Time": 1817, + "Intensity": 0.54, + "Frequency": -20 + }, + { + "Time": 2449, + "Intensity": 0.25, + "Frequency": -30 + }, + { + "Time": 2668, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2102, + "StartTime": 4460, + "Parameters": { + "Intensity": 42, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.66, + "Frequency": -50 + }, + { + "Time": 273, + "Intensity": 0.75, + "Frequency": -20 + }, + { + "Time": 1118, + "Intensity": 0.37, + "Frequency": -50 + }, + { + "Time": 1222, + "Intensity": 0.54, + "Frequency": -20 + }, + { + "Time": 1924, + "Intensity": 0.27, + "Frequency": -30 + }, + { + "Time": 2102, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_m.json index b0138b1ddf9bce7e59dd423da8540ada44de435e..135fea6864538d58310dc8c877b7b3ef8700f175 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/Wind_m.json @@ -1,259 +1,259 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 4460, - "StartTime": 0, - "Parameters": { - "Intensity": 60, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 602, - "Intensity": 0.76, - "Frequency": -20 - }, - { - "Time": 1351, - "Intensity": 0.66, - "Frequency": -50 - }, - { - "Time": 1510, - "Intensity": 1, - "Frequency": -20 - }, - { - "Time": 2377, - "Intensity": 0.69, - "Frequency": -50 - }, - { - "Time": 2457, - "Intensity": 0.95, - "Frequency": 0 - }, - { - "Time": 3287, - "Intensity": 0.67, - "Frequency": -50 - }, - { - "Time": 3381, - "Intensity": 0.93, - "Frequency": -20 - }, - { - "Time": 3898, - "Intensity": 0.65, - "Frequency": -50 - }, - { - "Time": 3985, - "Intensity": 0.91, - "Frequency": -20 - }, - { - "Time": 4456, - "Intensity": 0.63, - "Frequency": -40 - }, - { - "Time": 4460, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 3860, - "StartTime": 5, - "Parameters": { - "Intensity": 52, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 637, - "Intensity": 0.81, - "Frequency": -20 - }, - { - "Time": 1517, - "Intensity": 0.7, - "Frequency": -50 - }, - { - "Time": 1583, - "Intensity": 1, - "Frequency": -20 - }, - { - "Time": 2420, - "Intensity": 0.72, - "Frequency": -50 - }, - { - "Time": 2528, - "Intensity": 0.95, - "Frequency": 0 - }, - { - "Time": 3289, - "Intensity": 0.74, - "Frequency": -50 - }, - { - "Time": 3358, - "Intensity": 0.94, - "Frequency": -20 - }, - { - "Time": 3859, - "Intensity": 0.61, - "Frequency": -40 - }, - { - "Time": 3860, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2668, - "StartTime": 3865, - "Parameters": { - "Intensity": 51, - "Frequency": 35, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.56, - "Frequency": 0 - }, - { - "Time": 152, - "Intensity": 0.84, - "Frequency": -20 - }, - { - "Time": 552, - "Intensity": 0.6, - "Frequency": -50 - }, - { - "Time": 819, - "Intensity": 0.74, - "Frequency": -20 - }, - { - "Time": 1706, - "Intensity": 0.35, - "Frequency": -50 - }, - { - "Time": 1817, - "Intensity": 0.54, - "Frequency": -20 - }, - { - "Time": 2449, - "Intensity": 0.25, - "Frequency": -30 - }, - { - "Time": 2668, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 2102, - "StartTime": 4460, - "Parameters": { - "Intensity": 56, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": -50 - }, - { - "Time": 1, - "Intensity": 0.66, - "Frequency": -50 - }, - { - "Time": 273, - "Intensity": 0.75, - "Frequency": -20 - }, - { - "Time": 1118, - "Intensity": 0.37, - "Frequency": -50 - }, - { - "Time": 1222, - "Intensity": 0.54, - "Frequency": -20 - }, - { - "Time": 1924, - "Intensity": 0.27, - "Frequency": -30 - }, - { - "Time": 2102, - "Intensity": 0, - "Frequency": -50 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 4460, + "StartTime": 0, + "Parameters": { + "Intensity": 60, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 602, + "Intensity": 0.76, + "Frequency": -20 + }, + { + "Time": 1351, + "Intensity": 0.66, + "Frequency": -50 + }, + { + "Time": 1510, + "Intensity": 1, + "Frequency": -20 + }, + { + "Time": 2377, + "Intensity": 0.69, + "Frequency": -50 + }, + { + "Time": 2457, + "Intensity": 0.95, + "Frequency": 0 + }, + { + "Time": 3287, + "Intensity": 0.67, + "Frequency": -50 + }, + { + "Time": 3381, + "Intensity": 0.93, + "Frequency": -20 + }, + { + "Time": 3898, + "Intensity": 0.65, + "Frequency": -50 + }, + { + "Time": 3985, + "Intensity": 0.91, + "Frequency": -20 + }, + { + "Time": 4456, + "Intensity": 0.63, + "Frequency": -40 + }, + { + "Time": 4460, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 3860, + "StartTime": 5, + "Parameters": { + "Intensity": 52, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 637, + "Intensity": 0.81, + "Frequency": -20 + }, + { + "Time": 1517, + "Intensity": 0.7, + "Frequency": -50 + }, + { + "Time": 1583, + "Intensity": 1, + "Frequency": -20 + }, + { + "Time": 2420, + "Intensity": 0.72, + "Frequency": -50 + }, + { + "Time": 2528, + "Intensity": 0.95, + "Frequency": 0 + }, + { + "Time": 3289, + "Intensity": 0.74, + "Frequency": -50 + }, + { + "Time": 3358, + "Intensity": 0.94, + "Frequency": -20 + }, + { + "Time": 3859, + "Intensity": 0.61, + "Frequency": -40 + }, + { + "Time": 3860, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2668, + "StartTime": 3865, + "Parameters": { + "Intensity": 51, + "Frequency": 35, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.56, + "Frequency": 0 + }, + { + "Time": 152, + "Intensity": 0.84, + "Frequency": -20 + }, + { + "Time": 552, + "Intensity": 0.6, + "Frequency": -50 + }, + { + "Time": 819, + "Intensity": 0.74, + "Frequency": -20 + }, + { + "Time": 1706, + "Intensity": 0.35, + "Frequency": -50 + }, + { + "Time": 1817, + "Intensity": 0.54, + "Frequency": -20 + }, + { + "Time": 2449, + "Intensity": 0.25, + "Frequency": -30 + }, + { + "Time": 2668, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 2102, + "StartTime": 4460, + "Parameters": { + "Intensity": 56, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": -50 + }, + { + "Time": 1, + "Intensity": 0.66, + "Frequency": -50 + }, + { + "Time": 273, + "Intensity": 0.75, + "Frequency": -20 + }, + { + "Time": 1118, + "Intensity": 0.37, + "Frequency": -50 + }, + { + "Time": 1222, + "Intensity": 0.54, + "Frequency": -20 + }, + { + "Time": 1924, + "Intensity": 0.27, + "Frequency": -30 + }, + { + "Time": 2102, + "Intensity": 0, + "Frequency": -50 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_h.json index b50bbb7d72640d4049b7fc93810f30dad8b38aee..15532ff8c3d31f12af370664f37d66c6c9cb121f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_h.json @@ -1,61 +1,61 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 60, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1281, - "StartTime": 84, - "Parameters": { - "Intensity": 53, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.9122486114501953, - "Frequency": 20 - }, - { - "Time": 218, - "Intensity": 0.6803921461105347, - "Frequency": -27 - }, - { - "Time": 1281, - "Intensity": 0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 60, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1281, + "StartTime": 84, + "Parameters": { + "Intensity": 53, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.9122486114501953, + "Frequency": 20 + }, + { + "Time": 218, + "Intensity": 0.6803921461105347, + "Frequency": -27 + }, + { + "Time": 1281, + "Intensity": 0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_l.json index 8a68fc2de51ef7282791b91f4144a48859be7913..0ce041ba424c6869589225b663d872828821f65f 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_l.json @@ -1,61 +1,61 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 60, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1281, - "StartTime": 84, - "Parameters": { - "Intensity": 31, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.9122486114501953, - "Frequency": 20 - }, - { - "Time": 218, - "Intensity": 0.6803921461105347, - "Frequency": -27 - }, - { - "Time": 1281, - "Intensity": 0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 60, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1281, + "StartTime": 84, + "Parameters": { + "Intensity": 31, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.9122486114501953, + "Frequency": 20 + }, + { + "Time": 218, + "Intensity": 0.6803921461105347, + "Frequency": -27 + }, + { + "Time": 1281, + "Intensity": 0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_m.json index 9fc1255ea87d431974f091f3cf9ae6a3c74e54a2..6d2932184af01b4224f480dc565d4524416f465d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/bell_m.json @@ -1,61 +1,61 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 60, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1281, - "StartTime": 84, - "Parameters": { - "Intensity": 42, - "Frequency": 67, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 0.9122486114501953, - "Frequency": 20 - }, - { - "Time": 218, - "Intensity": 0.6803921461105347, - "Frequency": -27 - }, - { - "Time": 1281, - "Intensity": 0, - "Frequency": -100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 60, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1281, + "StartTime": 84, + "Parameters": { + "Intensity": 42, + "Frequency": 67, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 0.9122486114501953, + "Frequency": 20 + }, + { + "Time": 218, + "Intensity": 0.6803921461105347, + "Frequency": -27 + }, + { + "Time": 1281, + "Intensity": 0, + "Frequency": -100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_h.json index 17d4414077766e074d1db6e53f7281f1adace4be..ca121d3cbd16b29be1345b3d108686c2a571661d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_h.json @@ -1,93 +1,93 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 133, - "StartTime": 30, - "Parameters": { - "Intensity": 67, - "Frequency": 36, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -35 - }, - { - "Time": 65, - "Intensity": 0.35490197, - "Frequency": -26 - }, - { - "Time": 126, - "Intensity": 1.0, - "Frequency": 52 - }, - { - "Time": 133, - "Intensity": 0.0, - "Frequency": 54 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 177, - "Parameters": { - "Intensity": 100, - "Frequency": 58 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 200, - "StartTime": 325, - "Parameters": { - "Intensity": 19, - "Frequency": 83, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 159, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 200, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 133, + "StartTime": 30, + "Parameters": { + "Intensity": 67, + "Frequency": 36, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -35 + }, + { + "Time": 65, + "Intensity": 0.35490197, + "Frequency": -26 + }, + { + "Time": 126, + "Intensity": 1.0, + "Frequency": 52 + }, + { + "Time": 133, + "Intensity": 0.0, + "Frequency": 54 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 177, + "Parameters": { + "Intensity": 100, + "Frequency": 58 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 200, + "StartTime": 325, + "Parameters": { + "Intensity": 19, + "Frequency": 83, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 159, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 200, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_l.json index 89b0bbc2050841eb92c18a812b87990b31a82aa9..807e92a95f1d96dfe409cfb05744e596eddd1e98 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_l.json @@ -1,93 +1,93 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 133, - "StartTime": 30, - "Parameters": { - "Intensity": 40, - "Frequency": 36, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -35 - }, - { - "Time": 65, - "Intensity": 0.35490197, - "Frequency": -26 - }, - { - "Time": 126, - "Intensity": 1.0, - "Frequency": 52 - }, - { - "Time": 133, - "Intensity": 0.0, - "Frequency": 54 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 177, - "Parameters": { - "Intensity": 60, - "Frequency": 58 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 200, - "StartTime": 325, - "Parameters": { - "Intensity": 11, - "Frequency": 83, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 159, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 200, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 133, + "StartTime": 30, + "Parameters": { + "Intensity": 40, + "Frequency": 36, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -35 + }, + { + "Time": 65, + "Intensity": 0.35490197, + "Frequency": -26 + }, + { + "Time": 126, + "Intensity": 1.0, + "Frequency": 52 + }, + { + "Time": 133, + "Intensity": 0.0, + "Frequency": 54 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 177, + "Parameters": { + "Intensity": 60, + "Frequency": 58 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 200, + "StartTime": 325, + "Parameters": { + "Intensity": 11, + "Frequency": 83, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 159, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 200, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_m.json index 7ee849aebd7df4f67aea346bc2d3192eb7fc83ff..558172a5a61663ab53734fcf8ad3e12b378fc9a0 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter2_m.json @@ -1,93 +1,93 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 133, - "StartTime": 30, - "Parameters": { - "Intensity": 53, - "Frequency": 36, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": -35 - }, - { - "Time": 65, - "Intensity": 0.35490197, - "Frequency": -26 - }, - { - "Time": 126, - "Intensity": 1.0, - "Frequency": 52 - }, - { - "Time": 133, - "Intensity": 0.0, - "Frequency": 54 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 177, - "Parameters": { - "Intensity": 80, - "Frequency": 58 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 200, - "StartTime": 325, - "Parameters": { - "Intensity": 15, - "Frequency": 83, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 159, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 200, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 133, + "StartTime": 30, + "Parameters": { + "Intensity": 53, + "Frequency": 36, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": -35 + }, + { + "Time": 65, + "Intensity": 0.35490197, + "Frequency": -26 + }, + { + "Time": 126, + "Intensity": 1.0, + "Frequency": 52 + }, + { + "Time": 133, + "Intensity": 0.0, + "Frequency": 54 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 177, + "Parameters": { + "Intensity": 80, + "Frequency": 58 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 200, + "StartTime": 325, + "Parameters": { + "Intensity": 15, + "Frequency": 83, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 159, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 200, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_h.json index 940d279c1d0fa30657244e0ba13c4cfeb180649b..93275702e9bbf4f7d5a525c1af94b1fb83c7a492 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_h.json @@ -1,173 +1,173 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 90, - "Parameters": { - "Intensity": 100, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 185, - "Parameters": { - "Intensity": 65, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 216, - "Parameters": { - "Intensity": 46, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 244, - "Parameters": { - "Intensity": 65, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 277, - "Parameters": { - "Intensity": 46, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 983, - "Parameters": { - "Intensity": 64, - "Frequency": 66 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1042, - "Parameters": { - "Intensity": 78, - "Frequency": 76 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1091, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 132, - "StartTime": 1114, - "Parameters": { - "Intensity": 32, - "Frequency": 71, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 132, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1283, - "Parameters": { - "Intensity": 74, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 97, - "StartTime": 1312, - "Parameters": { - "Intensity": 30, - "Frequency": 71, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 3, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 97, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 90, + "Parameters": { + "Intensity": 100, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 185, + "Parameters": { + "Intensity": 65, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 216, + "Parameters": { + "Intensity": 46, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 244, + "Parameters": { + "Intensity": 65, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 277, + "Parameters": { + "Intensity": 46, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 983, + "Parameters": { + "Intensity": 64, + "Frequency": 66 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1042, + "Parameters": { + "Intensity": 78, + "Frequency": 76 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1091, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 132, + "StartTime": 1114, + "Parameters": { + "Intensity": 32, + "Frequency": 71, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 132, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1283, + "Parameters": { + "Intensity": 74, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 97, + "StartTime": 1312, + "Parameters": { + "Intensity": 30, + "Frequency": 71, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 3, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 97, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_l.json index 6faf72b988ccc5872e49c6d7268e249a61dff752..98216c61655f79606b55cdab6f18baba2a0f0a62 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_l.json @@ -1,173 +1,173 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 90, - "Parameters": { - "Intensity": 60, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 185, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 216, - "Parameters": { - "Intensity": 27, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 244, - "Parameters": { - "Intensity": 39, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 277, - "Parameters": { - "Intensity": 27, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 983, - "Parameters": { - "Intensity": 38, - "Frequency": 66 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1042, - "Parameters": { - "Intensity": 46, - "Frequency": 76 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1091, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 132, - "StartTime": 1114, - "Parameters": { - "Intensity": 19, - "Frequency": 71, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 132, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1283, - "Parameters": { - "Intensity": 44, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 97, - "StartTime": 1312, - "Parameters": { - "Intensity": 18, - "Frequency": 71, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 3, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 97, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 90, + "Parameters": { + "Intensity": 60, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 185, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 216, + "Parameters": { + "Intensity": 27, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 244, + "Parameters": { + "Intensity": 39, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 277, + "Parameters": { + "Intensity": 27, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 983, + "Parameters": { + "Intensity": 38, + "Frequency": 66 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1042, + "Parameters": { + "Intensity": 46, + "Frequency": 76 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1091, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 132, + "StartTime": 1114, + "Parameters": { + "Intensity": 19, + "Frequency": 71, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 132, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1283, + "Parameters": { + "Intensity": 44, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 97, + "StartTime": 1312, + "Parameters": { + "Intensity": 18, + "Frequency": 71, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 3, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 97, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_m.json index 625fa5c6ea0d917013b3d2c6222bdea734a2f2cb..a06052f550a965a1b6d9072ea0da2b62fdb52565 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/camerashutter_m.json @@ -1,173 +1,173 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 90, - "Parameters": { - "Intensity": 80, - "Frequency": 38 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 185, - "Parameters": { - "Intensity": 52, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 216, - "Parameters": { - "Intensity": 36, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 244, - "Parameters": { - "Intensity": 52, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 277, - "Parameters": { - "Intensity": 36, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 983, - "Parameters": { - "Intensity": 51, - "Frequency": 66 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1042, - "Parameters": { - "Intensity": 62, - "Frequency": 76 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1091, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 132, - "StartTime": 1114, - "Parameters": { - "Intensity": 25, - "Frequency": 71, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 5, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 74, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 132, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1283, - "Parameters": { - "Intensity": 59, - "Frequency": 90 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 97, - "StartTime": 1312, - "Parameters": { - "Intensity": 24, - "Frequency": 71, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 3, - "Intensity": 1, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.57, - "Frequency": 0 - }, - { - "Time": 97, - "Intensity": 0, - "Frequency": 0 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 90, + "Parameters": { + "Intensity": 80, + "Frequency": 38 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 185, + "Parameters": { + "Intensity": 52, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 216, + "Parameters": { + "Intensity": 36, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 244, + "Parameters": { + "Intensity": 52, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 277, + "Parameters": { + "Intensity": 36, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 983, + "Parameters": { + "Intensity": 51, + "Frequency": 66 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1042, + "Parameters": { + "Intensity": 62, + "Frequency": 76 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1091, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 132, + "StartTime": 1114, + "Parameters": { + "Intensity": 25, + "Frequency": 71, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 5, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 74, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 132, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1283, + "Parameters": { + "Intensity": 59, + "Frequency": 90 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 97, + "StartTime": 1312, + "Parameters": { + "Intensity": 24, + "Frequency": 71, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 3, + "Intensity": 1, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.57, + "Frequency": 0 + }, + { + "Time": 97, + "Intensity": 0, + "Frequency": 0 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_h.json index 58ee0fbf5c7ae2b8491ce771e023d77df8f966da..74b5a01a560c460f3ee0ce71986f14c241d4929e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_h.json @@ -1,146 +1,146 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 109, - "StartTime": 48, - "Parameters": { - "Intensity": 35, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 109, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 167, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 109, - "StartTime": 1057, - "Parameters": { - "Intensity": 32, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 109, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1182, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 108, - "StartTime": 2019, - "Parameters": { - "Intensity": 33, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 104, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 108, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2138, - "Parameters": { - "Intensity": 100, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 109, + "StartTime": 48, + "Parameters": { + "Intensity": 35, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 109, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 167, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 109, + "StartTime": 1057, + "Parameters": { + "Intensity": 32, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 109, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1182, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 108, + "StartTime": 2019, + "Parameters": { + "Intensity": 33, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 104, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 108, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2138, + "Parameters": { + "Intensity": 100, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_l.json index 62e421e185dd44663539f967e70132d488ba21c0..3ba61dcb3492e4745f51719e078124da4ae10108 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_l.json @@ -1,146 +1,146 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 109, - "StartTime": 48, - "Parameters": { - "Intensity": 21, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 109, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 167, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 109, - "StartTime": 1057, - "Parameters": { - "Intensity": 19, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 109, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1182, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 108, - "StartTime": 2019, - "Parameters": { - "Intensity": 19, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 104, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 108, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2138, - "Parameters": { - "Intensity": 60, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 109, + "StartTime": 48, + "Parameters": { + "Intensity": 21, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 109, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 167, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 109, + "StartTime": 1057, + "Parameters": { + "Intensity": 19, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 109, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1182, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 108, + "StartTime": 2019, + "Parameters": { + "Intensity": 19, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 104, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 108, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2138, + "Parameters": { + "Intensity": 60, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_m.json index 91a785bd7988e8306978768d6c8840fc7ea5c288..c852fed48c2aff0f69fdfec68f57f5ca527e5778 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/clock_m.json @@ -1,146 +1,146 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "continuous", - "Duration": 109, - "StartTime": 48, - "Parameters": { - "Intensity": 28, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 109, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 167, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 109, - "StartTime": 1057, - "Parameters": { - "Intensity": 25, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 54, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 105, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 109, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1182, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 108, - "StartTime": 2019, - "Parameters": { - "Intensity": 26, - "Frequency": 81, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 53, - "Intensity": 0.32941177, - "Frequency": 0 - }, - { - "Time": 104, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 108, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2138, - "Parameters": { - "Intensity": 80, - "Frequency": 60 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "continuous", + "Duration": 109, + "StartTime": 48, + "Parameters": { + "Intensity": 28, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 109, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 167, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 109, + "StartTime": 1057, + "Parameters": { + "Intensity": 25, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 54, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 105, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 109, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1182, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 108, + "StartTime": 2019, + "Parameters": { + "Intensity": 26, + "Frequency": 81, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 53, + "Intensity": 0.32941177, + "Frequency": 0 + }, + { + "Time": 104, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 108, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2138, + "Parameters": { + "Intensity": 80, + "Frequency": 60 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_h.json index 11b80ce6a7e5e6b7f9d57f05eea37191352df911..03446b53604da78a54dc1f7b80d7bd193668a3da 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_h.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 40, - "Parameters": { - "Intensity": 100, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 407, - "Parameters": { - "Intensity": 75, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 119, - "StartTime": 445, - "Parameters": { - "Intensity": 31, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 66, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 119, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1112, - "Parameters": { - "Intensity": 100, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1470, - "Parameters": { - "Intensity": 75, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 117, - "StartTime": 1513, - "Parameters": { - "Intensity": 31, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 6, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 117, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2127, - "Parameters": { - "Intensity": 100, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2475, - "Parameters": { - "Intensity": 60, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 185, - "StartTime": 2516, - "Parameters": { - "Intensity": 31, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 185, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3143, - "Parameters": { - "Intensity": 100, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3482, - "Parameters": { - "Intensity": 68, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 185, - "StartTime": 3544, - "Parameters": { - "Intensity": 31, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 185, - "Intensity": 0.0, - "Frequency": 30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 40, + "Parameters": { + "Intensity": 100, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 407, + "Parameters": { + "Intensity": 75, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 119, + "StartTime": 445, + "Parameters": { + "Intensity": 31, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 66, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 119, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1112, + "Parameters": { + "Intensity": 100, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1470, + "Parameters": { + "Intensity": 75, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 117, + "StartTime": 1513, + "Parameters": { + "Intensity": 31, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 6, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 117, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2127, + "Parameters": { + "Intensity": 100, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2475, + "Parameters": { + "Intensity": 60, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 185, + "StartTime": 2516, + "Parameters": { + "Intensity": 31, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 185, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3143, + "Parameters": { + "Intensity": 100, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3482, + "Parameters": { + "Intensity": 68, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 185, + "StartTime": 3544, + "Parameters": { + "Intensity": 31, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 185, + "Intensity": 0.0, + "Frequency": 30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_l.json index 2dedccf6cb1c4181505e91cc022bd0ab412d8a79..dd6334051f29067c67ba728cb596491580651ab6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_l.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 40, - "Parameters": { - "Intensity": 60, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 407, - "Parameters": { - "Intensity": 45, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 119, - "StartTime": 445, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 66, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 119, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1112, - "Parameters": { - "Intensity": 60, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1470, - "Parameters": { - "Intensity": 45, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 117, - "StartTime": 1513, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 6, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 117, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2127, - "Parameters": { - "Intensity": 60, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2475, - "Parameters": { - "Intensity": 36, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 185, - "StartTime": 2516, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 185, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3143, - "Parameters": { - "Intensity": 60, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3482, - "Parameters": { - "Intensity": 40, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 185, - "StartTime": 3544, - "Parameters": { - "Intensity": 18, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 185, - "Intensity": 0.0, - "Frequency": 30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 40, + "Parameters": { + "Intensity": 60, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 407, + "Parameters": { + "Intensity": 45, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 119, + "StartTime": 445, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 66, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 119, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1112, + "Parameters": { + "Intensity": 60, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1470, + "Parameters": { + "Intensity": 45, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 117, + "StartTime": 1513, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 6, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 117, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2127, + "Parameters": { + "Intensity": 60, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2475, + "Parameters": { + "Intensity": 36, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 185, + "StartTime": 2516, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 185, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3143, + "Parameters": { + "Intensity": 60, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3482, + "Parameters": { + "Intensity": 40, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 185, + "StartTime": 3544, + "Parameters": { + "Intensity": 18, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 185, + "Intensity": 0.0, + "Frequency": 30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_m.json index 71d7b815a914c7463e817b9fae5680141b6edb05..cc09f48489d086d5eeec275dcaeb5efebf9138db 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/heartbeat_m.json @@ -1,229 +1,229 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "StartTime": 40, - "Parameters": { - "Intensity": 80, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 407, - "Parameters": { - "Intensity": 60, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 119, - "StartTime": 445, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 7, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 66, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 119, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1112, - "Parameters": { - "Intensity": 80, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 1470, - "Parameters": { - "Intensity": 60, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 117, - "StartTime": 1513, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 6, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 64, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 117, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2127, - "Parameters": { - "Intensity": 80, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 2475, - "Parameters": { - "Intensity": 48, - "Frequency": 6 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 185, - "StartTime": 2516, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 185, - "Intensity": 0.0, - "Frequency": 0 - } - ] - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3143, - "Parameters": { - "Intensity": 80, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 3482, - "Parameters": { - "Intensity": 54, - "Frequency": 0 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 185, - "StartTime": 3544, - "Parameters": { - "Intensity": 24, - "Frequency": 30, - "Curve": [ - { - "Time": 0, - "Intensity": 0.0, - "Frequency": 0 - }, - { - "Time": 8, - "Intensity": 1.0, - "Frequency": 0 - }, - { - "Time": 100, - "Intensity": 0.31176472, - "Frequency": 0 - }, - { - "Time": 185, - "Intensity": 0.0, - "Frequency": 30 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "StartTime": 40, + "Parameters": { + "Intensity": 80, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 407, + "Parameters": { + "Intensity": 60, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 119, + "StartTime": 445, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 7, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 66, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 119, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1112, + "Parameters": { + "Intensity": 80, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 1470, + "Parameters": { + "Intensity": 60, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 117, + "StartTime": 1513, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 6, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 64, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 117, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2127, + "Parameters": { + "Intensity": 80, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 2475, + "Parameters": { + "Intensity": 48, + "Frequency": 6 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 185, + "StartTime": 2516, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 185, + "Intensity": 0.0, + "Frequency": 0 + } + ] + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3143, + "Parameters": { + "Intensity": 80, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 3482, + "Parameters": { + "Intensity": 54, + "Frequency": 0 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 185, + "StartTime": 3544, + "Parameters": { + "Intensity": 24, + "Frequency": 30, + "Curve": [ + { + "Time": 0, + "Intensity": 0.0, + "Frequency": 0 + }, + { + "Time": 8, + "Intensity": 1.0, + "Frequency": 0 + }, + { + "Time": 100, + "Intensity": 0.31176472, + "Frequency": 0 + }, + { + "Time": 185, + "Intensity": 0.0, + "Frequency": 30 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_h.json index fe535bcce808904c655819855aee14054c594048..224d59646a0ab66578dc97adbe3fc98d95a67011 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_h.json @@ -1,102 +1,102 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 68, - "Parameters": { - "Intensity": 23, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 103, - "Parameters": { - "Intensity": 52, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 140, - "Parameters": { - "Intensity": 100, - "Frequency": 94 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 157, - "Parameters": { - "Intensity": 7, - "Frequency": 85 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 175, - "Parameters": { - "Intensity": 60, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 195, - "Parameters": { - "Intensity": 30, - "Frequency": 99 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 245, - "Parameters": { - "Intensity": 53, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 268, - "Parameters": { - "Intensity": 16, - "Frequency": 53 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 68, + "Parameters": { + "Intensity": 23, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 103, + "Parameters": { + "Intensity": 52, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 140, + "Parameters": { + "Intensity": 100, + "Frequency": 94 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 157, + "Parameters": { + "Intensity": 7, + "Frequency": 85 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 175, + "Parameters": { + "Intensity": 60, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 195, + "Parameters": { + "Intensity": 30, + "Frequency": 99 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 245, + "Parameters": { + "Intensity": 53, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 268, + "Parameters": { + "Intensity": 16, + "Frequency": 53 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_l.json index a1394c87845b845ef44c072c1b26033576c3bf0a..32617791024af9500c1232e6f2d37688256ecd27 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_l.json @@ -1,102 +1,102 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 68, - "Parameters": { - "Intensity": 13, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 103, - "Parameters": { - "Intensity": 31, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 140, - "Parameters": { - "Intensity": 60, - "Frequency": 94 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 157, - "Parameters": { - "Intensity": 4, - "Frequency": 85 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 175, - "Parameters": { - "Intensity": 36, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 195, - "Parameters": { - "Intensity": 18, - "Frequency": 99 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 245, - "Parameters": { - "Intensity": 31, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 268, - "Parameters": { - "Intensity": 9, - "Frequency": 53 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 68, + "Parameters": { + "Intensity": 13, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 103, + "Parameters": { + "Intensity": 31, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 140, + "Parameters": { + "Intensity": 60, + "Frequency": 94 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 157, + "Parameters": { + "Intensity": 4, + "Frequency": 85 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 175, + "Parameters": { + "Intensity": 36, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 195, + "Parameters": { + "Intensity": 18, + "Frequency": 99 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 245, + "Parameters": { + "Intensity": 31, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 268, + "Parameters": { + "Intensity": 9, + "Frequency": 53 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_m.json index 04027152d4486236ddf1437f665cb58b7ed1201c..3eaa2b5ac427a9c333dd3698b818e8deaef0c97e 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/ice_m.json @@ -1,102 +1,102 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 68, - "Parameters": { - "Intensity": 18, - "Frequency": 60 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 103, - "Parameters": { - "Intensity": 41, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 140, - "Parameters": { - "Intensity": 80, - "Frequency": 94 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 157, - "Parameters": { - "Intensity": 5, - "Frequency": 85 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 175, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "StartTime": 195, - "Parameters": { - "Intensity": 24, - "Frequency": 99 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 245, - "Parameters": { - "Intensity": 42, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 268, - "Parameters": { - "Intensity": 12, - "Frequency": 53 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 68, + "Parameters": { + "Intensity": 18, + "Frequency": 60 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 103, + "Parameters": { + "Intensity": 41, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 140, + "Parameters": { + "Intensity": 80, + "Frequency": 94 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 157, + "Parameters": { + "Intensity": 5, + "Frequency": 85 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 175, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "StartTime": 195, + "Parameters": { + "Intensity": 24, + "Frequency": 99 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 245, + "Parameters": { + "Intensity": 42, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 268, + "Parameters": { + "Intensity": 12, + "Frequency": 53 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_h.json index 43ffbe686ed89e020e6a06a69929cf3765ce01a1..9f0f3db7ff11fb5978386451392a2655898ced21 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_h.json @@ -1,182 +1,182 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 0, - "Parameters": { - "Intensity": 36, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 131, - "Parameters": { - "Intensity": 78, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 243, - "Parameters": { - "Intensity": 36, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 360, - "Parameters": { - "Intensity": 78, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 465, - "Parameters": { - "Intensity": 36, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 569, - "Parameters": { - "Intensity": 81, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 677, - "Parameters": { - "Intensity": 36, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 779, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 890, - "Parameters": { - "Intensity": 36, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1001, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1107, - "Parameters": { - "Intensity": 37, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1219, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1330, - "Parameters": { - "Intensity": 36, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1439, - "Parameters": { - "Intensity": 80, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1543, - "Parameters": { - "Intensity": 35, - "Frequency": 82 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 0, + "Parameters": { + "Intensity": 36, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 131, + "Parameters": { + "Intensity": 78, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 243, + "Parameters": { + "Intensity": 36, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 360, + "Parameters": { + "Intensity": 78, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 465, + "Parameters": { + "Intensity": 36, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 569, + "Parameters": { + "Intensity": 81, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 677, + "Parameters": { + "Intensity": 36, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 779, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 890, + "Parameters": { + "Intensity": 36, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1001, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1107, + "Parameters": { + "Intensity": 37, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1219, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1330, + "Parameters": { + "Intensity": 36, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1439, + "Parameters": { + "Intensity": 80, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1543, + "Parameters": { + "Intensity": 35, + "Frequency": 82 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_l.json index 05b6293d1662214a8956b0176f2e5c8e86a6712c..392b190d7b81e9b15d6fc32cf67505f9a23830b5 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_l.json @@ -1,182 +1,182 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 0, - "Parameters": { - "Intensity": 21, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 131, - "Parameters": { - "Intensity": 46, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 243, - "Parameters": { - "Intensity": 21, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 360, - "Parameters": { - "Intensity": 46, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 465, - "Parameters": { - "Intensity": 21, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 569, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 677, - "Parameters": { - "Intensity": 21, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 779, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 890, - "Parameters": { - "Intensity": 21, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1001, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1107, - "Parameters": { - "Intensity": 22, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1219, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1330, - "Parameters": { - "Intensity": 21, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1439, - "Parameters": { - "Intensity": 48, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1543, - "Parameters": { - "Intensity": 21, - "Frequency": 82 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 0, + "Parameters": { + "Intensity": 21, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 131, + "Parameters": { + "Intensity": 46, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 243, + "Parameters": { + "Intensity": 21, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 360, + "Parameters": { + "Intensity": 46, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 465, + "Parameters": { + "Intensity": 21, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 569, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 677, + "Parameters": { + "Intensity": 21, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 779, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 890, + "Parameters": { + "Intensity": 21, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1001, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1107, + "Parameters": { + "Intensity": 22, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1219, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1330, + "Parameters": { + "Intensity": 21, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1439, + "Parameters": { + "Intensity": 48, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1543, + "Parameters": { + "Intensity": 21, + "Frequency": 82 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_m.json index c96972cc2855f0ede5f50f8b91a3e0042036b379..f8d4fb7c25cb21870ff1d1e8d01f5070cd1491a6 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/timer_m.json @@ -1,182 +1,182 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 0, - "Parameters": { - "Intensity": 28, - "Frequency": 93 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 131, - "Parameters": { - "Intensity": 62, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 243, - "Parameters": { - "Intensity": 28, - "Frequency": 80 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 360, - "Parameters": { - "Intensity": 62, - "Frequency": 95 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 465, - "Parameters": { - "Intensity": 28, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 569, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 677, - "Parameters": { - "Intensity": 28, - "Frequency": 79 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 779, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 890, - "Parameters": { - "Intensity": 28, - "Frequency": 84 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1001, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1107, - "Parameters": { - "Intensity": 29, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1219, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1330, - "Parameters": { - "Intensity": 28, - "Frequency": 81 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1439, - "Parameters": { - "Intensity": 64, - "Frequency": 100 - } - } - }, - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 1543, - "Parameters": { - "Intensity": 28, - "Frequency": 82 - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 0, + "Parameters": { + "Intensity": 28, + "Frequency": 93 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 131, + "Parameters": { + "Intensity": 62, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 243, + "Parameters": { + "Intensity": 28, + "Frequency": 80 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 360, + "Parameters": { + "Intensity": 62, + "Frequency": 95 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 465, + "Parameters": { + "Intensity": 28, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 569, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 677, + "Parameters": { + "Intensity": 28, + "Frequency": 79 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 779, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 890, + "Parameters": { + "Intensity": 28, + "Frequency": 84 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1001, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1107, + "Parameters": { + "Intensity": 29, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1219, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1330, + "Parameters": { + "Intensity": 28, + "Frequency": 81 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1439, + "Parameters": { + "Intensity": 64, + "Frequency": 100 + } + } + }, + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 1543, + "Parameters": { + "Intensity": 28, + "Frequency": 82 + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_h.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_h.json index fbc8cf10c2149b76605c807927b7a15b9cd1a343..98be5f04175bd8c2cde1d9a243e3b9d68036178a 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_h.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_h.json @@ -1,61 +1,61 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 42, - "Parameters": { - "Intensity": 100, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1277, - "StartTime": 66, - "Parameters": { - "Intensity": 33, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 63 - }, - { - "Time": 650, - "Intensity": 0.44509804248809814, - "Frequency": 93 - }, - { - "Time": 1277, - "Intensity": 0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 42, + "Parameters": { + "Intensity": 100, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1277, + "StartTime": 66, + "Parameters": { + "Intensity": 33, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 63 + }, + { + "Time": 650, + "Intensity": 0.44509804248809814, + "Frequency": 93 + }, + { + "Time": 1277, + "Intensity": 0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_l.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_l.json index 8a22e936a64463d9604986101237ebe5bca5f27c..d5bc2d37edbfb07dfcbf8ccc51f92cd697d6306d 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_l.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_l.json @@ -1,61 +1,61 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 42, - "Parameters": { - "Intensity": 60, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1277, - "StartTime": 66, - "Parameters": { - "Intensity": 19, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 63 - }, - { - "Time": 650, - "Intensity": 0.44509804248809814, - "Frequency": 93 - }, - { - "Time": 1277, - "Intensity": 0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 42, + "Parameters": { + "Intensity": 60, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1277, + "StartTime": 66, + "Parameters": { + "Intensity": 19, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 63 + }, + { + "Time": 650, + "Intensity": 0.44509804248809814, + "Frequency": 93 + }, + { + "Time": 1277, + "Intensity": 0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_m.json b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_m.json index 28fdc45f3cf09f9f5211ab826a16dfbd5dea6469..76eecaf0fb6b5024def16cf35ba5bb587b3d5304 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_m.json +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/main/resources/rawfile/triangle_m.json @@ -1,61 +1,61 @@ -{ - "MetaData": { - "Create": "2023-11-29", - "Discription": "A json file effect", - "ChannelNumber": 1, - "Version": 1.0 - }, - "Channels": [ - { - "Parameters": { - "Index": 0 - }, - "Pattern": [ - { - "Event": { - "Type": "transient", - "Duration": 0, - "StartTime": 42, - "Parameters": { - "Intensity": 80, - "Frequency": 50 - } - } - }, - { - "Event": { - "Type": "continuous", - "Duration": 1277, - "StartTime": 66, - "Parameters": { - "Intensity": 26, - "Frequency": 50, - "Curve": [ - { - "Time": 0, - "Intensity": 0, - "Frequency": 0 - }, - { - "Time": 9, - "Intensity": 1, - "Frequency": 63 - }, - { - "Time": 650, - "Intensity": 0.44509804248809814, - "Frequency": 93 - }, - { - "Time": 1277, - "Intensity": 0, - "Frequency": 100 - } - ] - } - } - } - ] - } - ] +{ + "MetaData": { + "Create": "2023-11-29", + "Discription": "A json file effect", + "ChannelNumber": 1, + "Version": 1.0 + }, + "Channels": [ + { + "Parameters": { + "Index": 0 + }, + "Pattern": [ + { + "Event": { + "Type": "transient", + "Duration": 0, + "StartTime": 42, + "Parameters": { + "Intensity": 80, + "Frequency": 50 + } + } + }, + { + "Event": { + "Type": "continuous", + "Duration": 1277, + "StartTime": 66, + "Parameters": { + "Intensity": 26, + "Frequency": 50, + "Curve": [ + { + "Time": 0, + "Intensity": 0, + "Frequency": 0 + }, + { + "Time": 9, + "Intensity": 1, + "Frequency": 63 + }, + { + "Time": 650, + "Intensity": 0.44509804248809814, + "Frequency": 93 + }, + { + "Time": 1277, + "Intensity": 0, + "Frequency": 100 + } + ] + } + } + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/ohosTest/module.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/ohosTest/module.json5 index 741bfbf578fbe34a741c12bea708bb5aa27bcaf1..22e2c611f379dbb0fddf452b259ef27c508d058b 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/hvigor/hvigor-config.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/hvigor/hvigor-config.json5 index ac737cf85f090c5de41b44bb39986e423bdc39fa..e75281b258e8cec776a34fd96a3c117c58afb9cb 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - } +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/oh-package.json5 b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/oh-package.json5 index 04a043b233007ebc1180cfc83187762c9a1a6c7b..f39b6b66fcce37b317d534793e4b95286d49cec9 100644 --- a/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/oh-package.json5 +++ b/code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "ISC", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "name": "Haptic Sample", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "name": "Haptic Sample", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Graphics/DisplaySoloist/AppScope/app.json5 b/code/BasicFeature/Graphics/DisplaySoloist/AppScope/app.json5 index 396fc27e52af4122daf5327274585c5a02fd4fa4..3669dcf81377fae2f59683a6efc67b04cbcc7656 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/AppScope/app.json5 +++ b/code/BasicFeature/Graphics/DisplaySoloist/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.DisplaySoloist", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.DisplaySoloist", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Graphics/DisplaySoloist/AppScope/resources/base/element/string.json b/code/BasicFeature/Graphics/DisplaySoloist/AppScope/resources/base/element/string.json index cf0ed8b5283b6b6d122726b29e2393f4bee145c5..8f27bbd6363b153e19eb343ee29e37f4a2813c8e 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Graphics/DisplaySoloist/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DisplaySoloist" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "DisplaySoloist" + } + ] +} diff --git a/code/BasicFeature/Graphics/DisplaySoloist/build-profile.json5 b/code/BasicFeature/Graphics/DisplaySoloist/build-profile.json5 index ab02bd0c01d97c0f60366094a655bc1b100e1203..43737f836ed528ca3a9e15a7d8963761c2252478 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/build-profile.json5 +++ b/code/BasicFeature/Graphics/DisplaySoloist/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 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": [ - { - "compileSdkVersion": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony", - "name": "default", - "signingConfig": "default", - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": [ + { + "compileSdkVersion": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony", + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySoloist/entry/build-profile.json5 b/code/BasicFeature/Graphics/DisplaySoloist/entry/build-profile.json5 index 34df5bd5bfa6776f05660adc1a2d94d698677e67..cf2a53fd98273c6fa793ec8c6c2cdc74ddfbb8a0 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/entry/build-profile.json5 +++ b/code/BasicFeature/Graphics/DisplaySoloist/entry/build-profile.json5 @@ -1,35 +1,35 @@ -/* - * Copyright (c) 2024 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", - } - ] +/* + * Copyright (c) 2024 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", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySoloist/entry/oh-package.json5 b/code/BasicFeature/Graphics/DisplaySoloist/entry/oh-package.json5 index 0186d686344891edaa4c790d3150d113323071d3..0b39ac1a9a150b20ad9efa47be9c1eb0eda93434 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/entry/oh-package.json5 +++ b/code/BasicFeature/Graphics/DisplaySoloist/entry/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - } -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} diff --git a/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/pages/Index.ets index 7f71e4a8439d533c58b9f147a25c7617a19e6b4e..dab5d6ff77ca82c6b6e6c7259b6155e2f0a42f2f 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/pages/Index.ets @@ -1,147 +1,147 @@ -/* - * Copyright (c) 2024 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 XComponentContext from '../interface/XComponentContext'; -import Logger from '../utils/Logger'; - -const TAG = '[XComponentDisplaySoloist]'; -const START = 'Start'; -const STOP = 'Stop'; - -@Entry -@Component -struct Index { - @State status1: string = START; - @State isOn1: boolean = false; - @State status2: string = START; - @State isOn2: boolean = false; - @State status3: string = START; - @State isOn3: boolean = false; - private xComponentContext1: XComponentContext | undefined = undefined; - private xComponentContext2: XComponentContext | undefined = undefined; - private xComponentContext3: XComponentContext | undefined = undefined; - - aboutToDisappear(): void { - // 离开当前页面时解除注册的回调,销毁申请的DisplaySoloist - Logger.info(TAG, 'aboutToDisappear'); - if (this.xComponentContext1) { - this.xComponentContext1.unregister(); - this.xComponentContext1.destroy(); - } - if (this.xComponentContext2) { - this.xComponentContext2.unregister(); - this.xComponentContext2.destroy(); - } - if (this.xComponentContext3) { - this.xComponentContext3.unregister(); - this.xComponentContext3.destroy(); - } - } - - Execute(component: XComponentContext, flg: boolean): string { - if (flg) { - // 注册回调函数并开启每帧回调 - component.register(); - return STOP; - } else { - // 解注册回调函数并停止启每帧回调 - component.unregister(); - return START; - } - } - - build() { - Column() { - Row() { - Text('30hz') - .fontWeight(FontWeight.Bold) - .fontSize(12) - .fontColor(Color.Red) - .textAlign(TextAlign.End) - .width(40) - .height(30) - - Button(this.status1) - .id('Start30') - .controlSize(ControlSize.SMALL) - .onClick((): void => { - if (this.xComponentContext1) { - // 每次点击切换按钮上的显示Start/Stop - this.isOn1 = !(this.isOn1); - this.status1 = this.Execute(this.xComponentContext1, this.isOn1); - } - }).margin(4) - - XComponent({ id: 'xcomponentId30', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext1 = xComponentContext as XComponentContext; - }).width('640px') - .backgroundColor(Color.White); - }.height('30%') - - Row() { - Text('60hz') - .fontWeight(FontWeight.Bold) - .fontSize(12) - .fontColor(Color.Red) - .textAlign(TextAlign.End) - .width(40) - .height(30) - - Button(this.status2) - .id('Start60') - .controlSize(ControlSize.SMALL) - .onClick((): void => { - if (this.xComponentContext2) { - this.isOn2 = !(this.isOn2); - this.status2 = this.Execute(this.xComponentContext2, this.isOn2); - } - }).margin(4) - - XComponent({ id: 'xcomponentId60', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext2 = xComponentContext as XComponentContext; - }).width('640px') - .backgroundColor(Color.White); - }.height('30%') - - Row() { - Text('120hz') - .fontWeight(FontWeight.Bold) - .fontSize(12) - .fontColor(Color.Red) - .textAlign(TextAlign.End) - .width(40) - .height(30) - - Button(this.status3) - .id('Start120') - .controlSize(ControlSize.SMALL) - .onClick((): void => { - if (this.xComponentContext3) { - this.isOn3 = !(this.isOn3); - this.status3 = this.Execute(this.xComponentContext3, this.isOn3); - } - }).margin(4) - - XComponent({ id: 'xcomponentId120', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext3 = xComponentContext as XComponentContext; - }).width('640px') - .backgroundColor(Color.White); - }.height('30%') - } - } +/* + * Copyright (c) 2024 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 XComponentContext from '../interface/XComponentContext'; +import Logger from '../utils/Logger'; + +const TAG = '[XComponentDisplaySoloist]'; +const START = 'Start'; +const STOP = 'Stop'; + +@Entry +@Component +struct Index { + @State status1: string = START; + @State isOn1: boolean = false; + @State status2: string = START; + @State isOn2: boolean = false; + @State status3: string = START; + @State isOn3: boolean = false; + private xComponentContext1: XComponentContext | undefined = undefined; + private xComponentContext2: XComponentContext | undefined = undefined; + private xComponentContext3: XComponentContext | undefined = undefined; + + aboutToDisappear(): void { + // 离开当前页面时解除注册的回调,销毁申请的DisplaySoloist + Logger.info(TAG, 'aboutToDisappear'); + if (this.xComponentContext1) { + this.xComponentContext1.unregister(); + this.xComponentContext1.destroy(); + } + if (this.xComponentContext2) { + this.xComponentContext2.unregister(); + this.xComponentContext2.destroy(); + } + if (this.xComponentContext3) { + this.xComponentContext3.unregister(); + this.xComponentContext3.destroy(); + } + } + + Execute(component: XComponentContext, flg: boolean): string { + if (flg) { + // 注册回调函数并开启每帧回调 + component.register(); + return STOP; + } else { + // 解注册回调函数并停止启每帧回调 + component.unregister(); + return START; + } + } + + build() { + Column() { + Row() { + Text('30hz') + .fontWeight(FontWeight.Bold) + .fontSize(12) + .fontColor(Color.Red) + .textAlign(TextAlign.End) + .width(40) + .height(30) + + Button(this.status1) + .id('Start30') + .controlSize(ControlSize.SMALL) + .onClick((): void => { + if (this.xComponentContext1) { + // 每次点击切换按钮上的显示Start/Stop + this.isOn1 = !(this.isOn1); + this.status1 = this.Execute(this.xComponentContext1, this.isOn1); + } + }).margin(4) + + XComponent({ id: 'xcomponentId30', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext1 = xComponentContext as XComponentContext; + }).width('640px') + .backgroundColor(Color.White); + }.height('30%') + + Row() { + Text('60hz') + .fontWeight(FontWeight.Bold) + .fontSize(12) + .fontColor(Color.Red) + .textAlign(TextAlign.End) + .width(40) + .height(30) + + Button(this.status2) + .id('Start60') + .controlSize(ControlSize.SMALL) + .onClick((): void => { + if (this.xComponentContext2) { + this.isOn2 = !(this.isOn2); + this.status2 = this.Execute(this.xComponentContext2, this.isOn2); + } + }).margin(4) + + XComponent({ id: 'xcomponentId60', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext2 = xComponentContext as XComponentContext; + }).width('640px') + .backgroundColor(Color.White); + }.height('30%') + + Row() { + Text('120hz') + .fontWeight(FontWeight.Bold) + .fontSize(12) + .fontColor(Color.Red) + .textAlign(TextAlign.End) + .width(40) + .height(30) + + Button(this.status3) + .id('Start120') + .controlSize(ControlSize.SMALL) + .onClick((): void => { + if (this.xComponentContext3) { + this.isOn3 = !(this.isOn3); + this.status3 = this.Execute(this.xComponentContext3, this.isOn3); + } + }).margin(4) + + XComponent({ id: 'xcomponentId120', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext3 = xComponentContext as XComponentContext; + }).width('640px') + .backgroundColor(Color.White); + }.height('30%') + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/utils/Logger.ets b/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/utils/Logger.ets index 221770b87590a3fedb0580dc481fa9c4ce134858..517c8134a93796f5deb554eef31d92c391df9b17 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/utils/Logger.ets +++ b/code/BasicFeature/Graphics/DisplaySoloist/entry/src/main/ets/utils/Logger.ets @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_DisplaySync]'); \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySoloist/entry/src/ohosTest/ets/utils/Logger.ets b/code/BasicFeature/Graphics/DisplaySoloist/entry/src/ohosTest/ets/utils/Logger.ets index 342d683b170596f5e1b2e2b4c2e68d74d43e62de..687ca76b70124c6398f5d60b017979645dbc774a 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/entry/src/ohosTest/ets/utils/Logger.ets +++ b/code/BasicFeature/Graphics/DisplaySoloist/entry/src/ohosTest/ets/utils/Logger.ets @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number = 0xF811; - private prefix: string = ''; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number = 0xF811; + private prefix: string = ''; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_DisplaySync]'); \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySoloist/hvigor/hvigor-config.json5 b/code/BasicFeature/Graphics/DisplaySoloist/hvigor/hvigor-config.json5 index e1b617db91f338598ae6d118b6866a33cba4042d..0b5647c97e634a2746cae72de8f7b6a26692fd87 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Graphics/DisplaySoloist/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySoloist/oh-package.json5 b/code/BasicFeature/Graphics/DisplaySoloist/oh-package.json5 index 28368a2c2e4fc94599bcb7670014a57250cf6956..d5793d0d26238cefefbb0e8177f43e083bbd0c83 100644 --- a/code/BasicFeature/Graphics/DisplaySoloist/oh-package.json5 +++ b/code/BasicFeature/Graphics/DisplaySoloist/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "drawing", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "drawing", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Graphics/DisplaySync/AppScope/app.json5 b/code/BasicFeature/Graphics/DisplaySync/AppScope/app.json5 index bdbb7e8f6ba3b64c0ffb54f3024c259fdc2a12d8..2832c10c722570010d5980541fe6a72f973f5f4c 100644 --- a/code/BasicFeature/Graphics/DisplaySync/AppScope/app.json5 +++ b/code/BasicFeature/Graphics/DisplaySync/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.displaySync", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.displaySync", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Graphics/DisplaySync/AppScope/resources/base/element/string.json b/code/BasicFeature/Graphics/DisplaySync/AppScope/resources/base/element/string.json index 0daf22fb0a24f17889889070ca43b854a16b3376..ba13327659cfcbc5e31f01e3ab118d7c90683ef4 100644 --- a/code/BasicFeature/Graphics/DisplaySync/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Graphics/DisplaySync/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DisplaySync" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "DisplaySync" + } + ] +} diff --git a/code/BasicFeature/Graphics/DisplaySync/build-profile.json5 b/code/BasicFeature/Graphics/DisplaySync/build-profile.json5 index 5f507fb19d9ae4faf2d87cdc470b0687a3e0269c..6da2ab8c3f7082baf8bed39a61b1bc77884080c8 100644 --- a/code/BasicFeature/Graphics/DisplaySync/build-profile.json5 +++ b/code/BasicFeature/Graphics/DisplaySync/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/entry/build-profile.json5 b/code/BasicFeature/Graphics/DisplaySync/entry/build-profile.json5 index 29f75c6b413f12e9a52157381418a146ed4865c8..c011db99b4e23f8b10bc589660c1851c5e6ea3bc 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/build-profile.json5 +++ b/code/BasicFeature/Graphics/DisplaySync/entry/build-profile.json5 @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2023-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", - "armeabi-v7a" - ] - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023-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", + "armeabi-v7a" + ] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/entry/oh-package.json5 b/code/BasicFeature/Graphics/DisplaySync/entry/oh-package.json5 index b9c1d4cca76ac664388dd6b1cf96697184c5133b..54cb066266f9993f5a023f2ac5a8dfc5d2574643 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/oh-package.json5 +++ b/code/BasicFeature/Graphics/DisplaySync/entry/oh-package.json5 @@ -1,11 +1,11 @@ -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - } +{ + "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/Graphics/DisplaySync/entry/src/main/ets/pages/CustomDrawDisplaySync.ets b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/CustomDrawDisplaySync.ets index 190c139e6ae3a7202058357d06b54f51fda016d5..17f65dcaaf5d49704a754268f40183b2e10e6303 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/CustomDrawDisplaySync.ets +++ b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/CustomDrawDisplaySync.ets @@ -1,190 +1,190 @@ -/* - * Copyright (c) 2023 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 displaySync from '@ohos.graphics.displaySync'; -import router from '@ohos.router'; -import Logger from '../utils/Logger'; -const TAG = '[CustomDrawDisplaySync]'; - -@Entry -@Component -struct Index { - @State drawFirstSize: number = 25; - @State drawSecondSize: number = 25; - private backDisplaySyncSlow: displaySync.DisplaySync | undefined = undefined; - private backDisplaySyncFast: displaySync.DisplaySync | undefined = undefined; - private isBigger_30:boolean = true; - private isBigger_60:boolean = true; - - @Builder doSomeRenderFirst() { - Text('30') - .fontSize(this.drawFirstSize) - } - - @Builder doSomeRenderSecond() { - Text('60') - .fontSize(this.drawSecondSize) - } - - CreateDisplaySyncSlow() { - let range : ExpectedFrameRateRange = { - expected: 30, - min: 0, - max: 120 - }; - - let draw30 = (ii: displaySync.IntervalInfo) => { - if (this.isBigger_30) { - this.drawFirstSize += 1; - if (this.drawFirstSize > 150) { - this.isBigger_30 = false; - } - } else { - this.drawFirstSize -= 1; - if (this.drawFirstSize < 25) { - this.isBigger_30 = true; - } - } - Logger.info(TAG, '[Draw30] Timestamp:' + ii.timestamp + ' TargetTimeStamp: ' + ii.targetTimestamp); - }; - - this.backDisplaySyncSlow = displaySync.create(); - this.backDisplaySyncSlow.setExpectedFrameRateRange(range); - this.backDisplaySyncSlow.on("frame", draw30); - } - - CreateDisplaySyncFast() { - let range : ExpectedFrameRateRange = { - expected: 60, - min: 0, - max: 120 - }; - - let draw60 = (ii: displaySync.IntervalInfo) => { - if (this.isBigger_60) { - this.drawSecondSize += 1; - if (this.drawSecondSize > 150) { - this.isBigger_60 = false; - } - } else { - this.drawSecondSize -= 1; - if (this.drawSecondSize < 25) { - this.isBigger_60 = true; - } - } - - Logger.info(TAG, '[Draw60] Timestamp:' + ii.timestamp + ' TargetTimeStamp: ' + ii.targetTimestamp); - }; - - this.backDisplaySyncFast= displaySync.create(); - this.backDisplaySyncFast.setExpectedFrameRateRange(range); - this.backDisplaySyncFast.on("frame", draw60); - } - - aboutToDisappear() { - if (this.backDisplaySyncSlow) { - this.backDisplaySyncSlow.stop(); - this.backDisplaySyncSlow = undefined; - } - if (this.backDisplaySyncFast) { - this.backDisplaySyncFast.stop(); - this.backDisplaySyncFast = undefined; - } - - Logger.info(TAG, 'DisplaySyncDestructor set all displaySync null'); - } - - build() { - Column() { - Row() { - this.doSomeRenderFirst(); - } - .height('40%') - - Row() { - this.doSomeRenderSecond(); - } - .height('40%') - - Row() { - Button('Start') - .id('CustomDrawStart') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 10, left: 5 }) - .fontColor(Color.White) - .onClick((): void => { - if (this.backDisplaySyncSlow == undefined) { - this.CreateDisplaySyncSlow(); - } - if (this.backDisplaySyncFast == undefined) { - this.CreateDisplaySyncFast(); - } - if (this.backDisplaySyncSlow) { - this.backDisplaySyncSlow.start(); - } - if (this.backDisplaySyncFast) { - this.backDisplaySyncFast.start(); - } - }) - .width('20%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - - Button('Stop') - .id('CustomDrawStop') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 10, left: 5 }) - .fontColor(Color.White) - .onClick((): void => { - if (this.backDisplaySyncSlow) { - this.backDisplaySyncSlow.stop(); - } - if (this.backDisplaySyncFast) { - this.backDisplaySyncFast.stop(); - } - }) - .width('20%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - - Button('Back') - .id('CustomDrawBack') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 10, left: 5 }) - .fontColor(Color.White) - .onClick((): void => { - if (this.backDisplaySyncSlow) { - this.backDisplaySyncSlow.stop(); - } - if (this.backDisplaySyncFast) { - this.backDisplaySyncFast.stop(); - } - router.back(); - }) - .width('20%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - } - .width('100%') - .justifyContent(FlexAlign.Center) - .shadow(ShadowStyle.OUTER_DEFAULT_SM) - .alignItems(VerticalAlign.Bottom) - .layoutWeight(1) - } - } +/* + * Copyright (c) 2023 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 displaySync from '@ohos.graphics.displaySync'; +import router from '@ohos.router'; +import Logger from '../utils/Logger'; +const TAG = '[CustomDrawDisplaySync]'; + +@Entry +@Component +struct Index { + @State drawFirstSize: number = 25; + @State drawSecondSize: number = 25; + private backDisplaySyncSlow: displaySync.DisplaySync | undefined = undefined; + private backDisplaySyncFast: displaySync.DisplaySync | undefined = undefined; + private isBigger_30:boolean = true; + private isBigger_60:boolean = true; + + @Builder doSomeRenderFirst() { + Text('30') + .fontSize(this.drawFirstSize) + } + + @Builder doSomeRenderSecond() { + Text('60') + .fontSize(this.drawSecondSize) + } + + CreateDisplaySyncSlow() { + let range : ExpectedFrameRateRange = { + expected: 30, + min: 0, + max: 120 + }; + + let draw30 = (ii: displaySync.IntervalInfo) => { + if (this.isBigger_30) { + this.drawFirstSize += 1; + if (this.drawFirstSize > 150) { + this.isBigger_30 = false; + } + } else { + this.drawFirstSize -= 1; + if (this.drawFirstSize < 25) { + this.isBigger_30 = true; + } + } + Logger.info(TAG, '[Draw30] Timestamp:' + ii.timestamp + ' TargetTimeStamp: ' + ii.targetTimestamp); + }; + + this.backDisplaySyncSlow = displaySync.create(); + this.backDisplaySyncSlow.setExpectedFrameRateRange(range); + this.backDisplaySyncSlow.on("frame", draw30); + } + + CreateDisplaySyncFast() { + let range : ExpectedFrameRateRange = { + expected: 60, + min: 0, + max: 120 + }; + + let draw60 = (ii: displaySync.IntervalInfo) => { + if (this.isBigger_60) { + this.drawSecondSize += 1; + if (this.drawSecondSize > 150) { + this.isBigger_60 = false; + } + } else { + this.drawSecondSize -= 1; + if (this.drawSecondSize < 25) { + this.isBigger_60 = true; + } + } + + Logger.info(TAG, '[Draw60] Timestamp:' + ii.timestamp + ' TargetTimeStamp: ' + ii.targetTimestamp); + }; + + this.backDisplaySyncFast= displaySync.create(); + this.backDisplaySyncFast.setExpectedFrameRateRange(range); + this.backDisplaySyncFast.on("frame", draw60); + } + + aboutToDisappear() { + if (this.backDisplaySyncSlow) { + this.backDisplaySyncSlow.stop(); + this.backDisplaySyncSlow = undefined; + } + if (this.backDisplaySyncFast) { + this.backDisplaySyncFast.stop(); + this.backDisplaySyncFast = undefined; + } + + Logger.info(TAG, 'DisplaySyncDestructor set all displaySync null'); + } + + build() { + Column() { + Row() { + this.doSomeRenderFirst(); + } + .height('40%') + + Row() { + this.doSomeRenderSecond(); + } + .height('40%') + + Row() { + Button('Start') + .id('CustomDrawStart') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 10, left: 5 }) + .fontColor(Color.White) + .onClick((): void => { + if (this.backDisplaySyncSlow == undefined) { + this.CreateDisplaySyncSlow(); + } + if (this.backDisplaySyncFast == undefined) { + this.CreateDisplaySyncFast(); + } + if (this.backDisplaySyncSlow) { + this.backDisplaySyncSlow.start(); + } + if (this.backDisplaySyncFast) { + this.backDisplaySyncFast.start(); + } + }) + .width('20%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + + Button('Stop') + .id('CustomDrawStop') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 10, left: 5 }) + .fontColor(Color.White) + .onClick((): void => { + if (this.backDisplaySyncSlow) { + this.backDisplaySyncSlow.stop(); + } + if (this.backDisplaySyncFast) { + this.backDisplaySyncFast.stop(); + } + }) + .width('20%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + + Button('Back') + .id('CustomDrawBack') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 10, left: 5 }) + .fontColor(Color.White) + .onClick((): void => { + if (this.backDisplaySyncSlow) { + this.backDisplaySyncSlow.stop(); + } + if (this.backDisplaySyncFast) { + this.backDisplaySyncFast.stop(); + } + router.back(); + }) + .width('20%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + } + .width('100%') + .justifyContent(FlexAlign.Center) + .shadow(ShadowStyle.OUTER_DEFAULT_SM) + .alignItems(VerticalAlign.Bottom) + .layoutWeight(1) + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/PropertyAnimationDisplaySync.ets b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/PropertyAnimationDisplaySync.ets index 11d325c75bebd192aa393aefc34d265c15b7c141..be1503ae3eadaa2c7872eb38252a1059800fc2cf 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/PropertyAnimationDisplaySync.ets +++ b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/PropertyAnimationDisplaySync.ets @@ -1,158 +1,158 @@ -/* - * Copyright (c) 2023 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 curves from '@ohos.curves'; -import router from '@ohos.router'; - -@Entry -@Component -struct AnimationToAnimationDemo { - @State isAnimation: boolean = false; - @State translateX1: number = -100; - @State translateX2: number = -100; - @State translateX3: number = -100; - uiContext: UIContext | undefined = undefined; - - aboutToAppear() { - this.uiContext = this.getUIContext(); - if (!this.uiContext) { - console.warn('no uiContext'); - return; - } - } - - build() { - Column() { - Row() { - Text('30') - .fontWeight(FontWeight.Bold) - .fontSize(16) - .fontColor(Color.White) - .textAlign(TextAlign.Center) - .borderRadius(10) - .backgroundColor(0xF56C6C) - .width(80) - .height(80) - .translate({ x: this.translateX1 }) - } - .height('20%') - - Row() { - Text('40') - .fontWeight(FontWeight.Bold) - .fontSize(16) - .fontColor(Color.White) - .textAlign(TextAlign.Center) - .borderRadius(10) - .backgroundColor(0x2E8B57) - .width(80) - .height(80) - .translate({ x: this.translateX2 }) - } - .height('20%') - - Row() { - Text('60') - .fontWeight(FontWeight.Bold) - .fontSize(16) - .fontColor(Color.White) - .textAlign(TextAlign.Center) - .borderRadius(10) - .backgroundColor(0x008B8B) - .width(80) - .height(80) - .translate({ x: this.translateX3 }) - .animation({ - duration: 1200, - iterations: 10, - curve: curves.springMotion(), - playMode: PlayMode.AlternateReverse, - expectedFrameRateRange: { - expected: 60, - min: 0, - max: 120 - }, - }) - } - .height('20%') - - Row() { - Button('Start') - .id('PropertyAnimationStart') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 10, left: 5 }) - .fontColor(Color.White) - .onClick(() => { - this.isAnimation = !this.isAnimation; - this.translateX3 = this.isAnimation ? 100 : -100; - - this.uiContext?.animateTo({ - duration: 1200, - iterations: 10, - curve: curves.springMotion(), - playMode: PlayMode.AlternateReverse, - expectedFrameRateRange: { - expected: 30, - min: 0, - max: 120, - }, - }, () => { - this.translateX1 = this.isAnimation ? 100 : -100; - }) - - this.uiContext?.animateTo({ - duration: 1200, - iterations: 10, - curve: curves.springMotion(), - playMode: PlayMode.AlternateReverse, - expectedFrameRateRange: { - expected: 40, - min: 0, - max: 120, - }, - }, () => { - this.translateX2 = this.isAnimation ? 100 : -100; - }) - }) - .width('40%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - - Button('Back') - .id('PropertyAnimationBack') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 10, left: 5 }) - .fontColor(Color.White) - .onClick((): void => { - router.back(); - }) - .width('40%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - } - .width('100%') - .justifyContent(FlexAlign.Center) - .shadow(ShadowStyle.OUTER_DEFAULT_SM) - .alignItems(VerticalAlign.Bottom) - .layoutWeight(1) - } - .width('100%') - .justifyContent(FlexAlign.Center) - .shadow(ShadowStyle.OUTER_DEFAULT_SM) - .layoutWeight(1) - } +/* + * Copyright (c) 2023 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 curves from '@ohos.curves'; +import router from '@ohos.router'; + +@Entry +@Component +struct AnimationToAnimationDemo { + @State isAnimation: boolean = false; + @State translateX1: number = -100; + @State translateX2: number = -100; + @State translateX3: number = -100; + uiContext: UIContext | undefined = undefined; + + aboutToAppear() { + this.uiContext = this.getUIContext(); + if (!this.uiContext) { + console.warn('no uiContext'); + return; + } + } + + build() { + Column() { + Row() { + Text('30') + .fontWeight(FontWeight.Bold) + .fontSize(16) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0xF56C6C) + .width(80) + .height(80) + .translate({ x: this.translateX1 }) + } + .height('20%') + + Row() { + Text('40') + .fontWeight(FontWeight.Bold) + .fontSize(16) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0x2E8B57) + .width(80) + .height(80) + .translate({ x: this.translateX2 }) + } + .height('20%') + + Row() { + Text('60') + .fontWeight(FontWeight.Bold) + .fontSize(16) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0x008B8B) + .width(80) + .height(80) + .translate({ x: this.translateX3 }) + .animation({ + duration: 1200, + iterations: 10, + curve: curves.springMotion(), + playMode: PlayMode.AlternateReverse, + expectedFrameRateRange: { + expected: 60, + min: 0, + max: 120 + }, + }) + } + .height('20%') + + Row() { + Button('Start') + .id('PropertyAnimationStart') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 10, left: 5 }) + .fontColor(Color.White) + .onClick(() => { + this.isAnimation = !this.isAnimation; + this.translateX3 = this.isAnimation ? 100 : -100; + + this.uiContext?.animateTo({ + duration: 1200, + iterations: 10, + curve: curves.springMotion(), + playMode: PlayMode.AlternateReverse, + expectedFrameRateRange: { + expected: 30, + min: 0, + max: 120, + }, + }, () => { + this.translateX1 = this.isAnimation ? 100 : -100; + }) + + this.uiContext?.animateTo({ + duration: 1200, + iterations: 10, + curve: curves.springMotion(), + playMode: PlayMode.AlternateReverse, + expectedFrameRateRange: { + expected: 40, + min: 0, + max: 120, + }, + }, () => { + this.translateX2 = this.isAnimation ? 100 : -100; + }) + }) + .width('40%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + + Button('Back') + .id('PropertyAnimationBack') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 10, left: 5 }) + .fontColor(Color.White) + .onClick((): void => { + router.back(); + }) + .width('40%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + } + .width('100%') + .justifyContent(FlexAlign.Center) + .shadow(ShadowStyle.OUTER_DEFAULT_SM) + .alignItems(VerticalAlign.Bottom) + .layoutWeight(1) + } + .width('100%') + .justifyContent(FlexAlign.Center) + .shadow(ShadowStyle.OUTER_DEFAULT_SM) + .layoutWeight(1) + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/XComponentDisplaySync.ets b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/XComponentDisplaySync.ets index 396007ed69d4112913262e806a902626dca4cf81..627256c2edb93e4430ef6aecfb9d29807fa36c30 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/XComponentDisplaySync.ets +++ b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/pages/XComponentDisplaySync.ets @@ -1,128 +1,128 @@ -/* - * Copyright (c) 2023 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 XComponentContext from '../interface/XComponentContext'; -import router from '@ohos.router'; -import Logger from '../utils/Logger'; -const TAG = '[XComponentDisplaySync]'; - -@Entry -@Component -struct Index { - private xComponentContext1: XComponentContext | undefined = undefined; - private xComponentContext2: XComponentContext | undefined = undefined; - - build() { - Column() { - Row() { - Text('30fps') - .fontWeight(FontWeight.Bold) - .fontSize(12) - .fontColor(Color.Red) - .textAlign(TextAlign.End) - .width(40) - .height(30) - - XComponent({ id: 'xcomponentId_30', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext1 = xComponentContext as XComponentContext; - }).width('80%') - }.height('40%') - - Row() { - Text('120fps') - .fontWeight(FontWeight.Bold) - .fontSize(12) - .fontColor(Color.Red) - .textAlign(TextAlign.End) - .width(40) - .height(30) - - XComponent({ id: 'xcomponentId_120', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext2 = xComponentContext as XComponentContext; - }).width('80%')// Multiples of 64 - }.height('40%') - - Row() { - Button('Start') - .id('Start') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 20, right: 6, left: 6 }) - .onClick(() => { - Logger.info(TAG, "Start click"); - if (this.xComponentContext1) { - Logger.info(TAG, "Register1"); - this.xComponentContext1.register(); - } - if (this.xComponentContext2) { - Logger.info(TAG, "Register2"); - this.xComponentContext2.register(); - } - }) - .width('30%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - - Button('Stop') - .id('Stop') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 20, left: 6 }) - .onClick(() => { - Logger.info(TAG, "Stop click"); - if (this.xComponentContext1) { - Logger.info(TAG, "Unregister1"); - this.xComponentContext1.unregister(); - } - if (this.xComponentContext2) { - Logger.info(TAG, "Unregister2"); - this.xComponentContext2.unregister(); - } - }) - .width('30%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - - // 返回按钮 - Button('Back') - .id('Back') - .fontSize(14) - .fontWeight(500) - .margin({ bottom: 20, left: 6 }) - .onClick((): void => { - if (this.xComponentContext1) { - Logger.info(TAG, "Unregister1"); - this.xComponentContext1.unregister(); - } - if (this.xComponentContext2) { - Logger.info(TAG, "Unregister2"); - this.xComponentContext2.unregister(); - } - router.back(); - }) - .width('30%') - .height(40) - .shadow(ShadowStyle.OUTER_DEFAULT_LG) - } - .width('100%') - .justifyContent(FlexAlign.Center) - .shadow(ShadowStyle.OUTER_DEFAULT_SM) - .alignItems(VerticalAlign.Bottom) - .layoutWeight(1) - } - } +/* + * Copyright (c) 2023 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 XComponentContext from '../interface/XComponentContext'; +import router from '@ohos.router'; +import Logger from '../utils/Logger'; +const TAG = '[XComponentDisplaySync]'; + +@Entry +@Component +struct Index { + private xComponentContext1: XComponentContext | undefined = undefined; + private xComponentContext2: XComponentContext | undefined = undefined; + + build() { + Column() { + Row() { + Text('30fps') + .fontWeight(FontWeight.Bold) + .fontSize(12) + .fontColor(Color.Red) + .textAlign(TextAlign.End) + .width(40) + .height(30) + + XComponent({ id: 'xcomponentId_30', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext1 = xComponentContext as XComponentContext; + }).width('80%') + }.height('40%') + + Row() { + Text('120fps') + .fontWeight(FontWeight.Bold) + .fontSize(12) + .fontColor(Color.Red) + .textAlign(TextAlign.End) + .width(40) + .height(30) + + XComponent({ id: 'xcomponentId_120', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext2 = xComponentContext as XComponentContext; + }).width('80%')// Multiples of 64 + }.height('40%') + + Row() { + Button('Start') + .id('Start') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 20, right: 6, left: 6 }) + .onClick(() => { + Logger.info(TAG, "Start click"); + if (this.xComponentContext1) { + Logger.info(TAG, "Register1"); + this.xComponentContext1.register(); + } + if (this.xComponentContext2) { + Logger.info(TAG, "Register2"); + this.xComponentContext2.register(); + } + }) + .width('30%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + + Button('Stop') + .id('Stop') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 20, left: 6 }) + .onClick(() => { + Logger.info(TAG, "Stop click"); + if (this.xComponentContext1) { + Logger.info(TAG, "Unregister1"); + this.xComponentContext1.unregister(); + } + if (this.xComponentContext2) { + Logger.info(TAG, "Unregister2"); + this.xComponentContext2.unregister(); + } + }) + .width('30%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + + // 返回按钮 + Button('Back') + .id('Back') + .fontSize(14) + .fontWeight(500) + .margin({ bottom: 20, left: 6 }) + .onClick((): void => { + if (this.xComponentContext1) { + Logger.info(TAG, "Unregister1"); + this.xComponentContext1.unregister(); + } + if (this.xComponentContext2) { + Logger.info(TAG, "Unregister2"); + this.xComponentContext2.unregister(); + } + router.back(); + }) + .width('30%') + .height(40) + .shadow(ShadowStyle.OUTER_DEFAULT_LG) + } + .width('100%') + .justifyContent(FlexAlign.Center) + .shadow(ShadowStyle.OUTER_DEFAULT_SM) + .alignItems(VerticalAlign.Bottom) + .layoutWeight(1) + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/utils/Logger.ets b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/utils/Logger.ets index 813142fade26ac98098abbd5797014cde91bbe70..ded8133070ab5c8bd56a242635389c59588ddac6 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/utils/Logger.ets +++ b/code/BasicFeature/Graphics/DisplaySync/entry/src/main/ets/utils/Logger.ets @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_DisplaySync]'); \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/entry/src/ohosTest/ets/utils/Logger.ets b/code/BasicFeature/Graphics/DisplaySync/entry/src/ohosTest/ets/utils/Logger.ets index e67695fe1618780b65ebf22b338a7f17b48b7ba7..cfc014b72ce533358365b9d3fbb8151a45f4454f 100644 --- a/code/BasicFeature/Graphics/DisplaySync/entry/src/ohosTest/ets/utils/Logger.ets +++ b/code/BasicFeature/Graphics/DisplaySync/entry/src/ohosTest/ets/utils/Logger.ets @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number = 0xF811; - private prefix: string = ''; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number = 0xF811; + private prefix: string = ''; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_DisplaySync]'); \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/hvigor/hvigor-config.json5 b/code/BasicFeature/Graphics/DisplaySync/hvigor/hvigor-config.json5 index d9d361de48771019ff391224622239f7e75f90db..58e6423f411590bdd8716452e9d2f32cd566b523 100644 --- a/code/BasicFeature/Graphics/DisplaySync/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Graphics/DisplaySync/hvigor/hvigor-config.json5 @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2023-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. - */ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +/* + * Copyright (c) 2023-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. + */ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/DisplaySync/oh-package.json5 b/code/BasicFeature/Graphics/DisplaySync/oh-package.json5 index 28368a2c2e4fc94599bcb7670014a57250cf6956..d5793d0d26238cefefbb0e8177f43e083bbd0c83 100644 --- a/code/BasicFeature/Graphics/DisplaySync/oh-package.json5 +++ b/code/BasicFeature/Graphics/DisplaySync/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "drawing", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "drawing", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/app.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/app.json5 index 42cb3ab085416c20d1ab056526104f16f3134b6c..95df481dfc3246527375c7e9f693a4265fabcb58 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/app.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.expandtext", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.expandtext", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/resources/base/element/string.json b/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/resources/base/element/string.json index a1cd6e41c90e2e66c20ebd9947ea8dcfa89276a0..72048ed2b2209e6349a878034164a38c1c4b1515 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ExpandText" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ExpandText" + } + ] +} diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/build-profile.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/build-profile.json5 index ea6d3ca20839c0b83e4605102164820c289d5d70..6ae38bd2fb623625b0ec1588ce196c16bbc33f53 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/build-profile.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/build-profile.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/build-profile.json5 index 7cae4209665ead1081c9a04e2706ec9e8ce043d9..0cd53ca64377586e3183ad6ea0080a938779cbbf 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/build-profile.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/oh-package.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/oh-package.json5 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..4e54d14e1b444a338b2c922f94a4fe4deed5be45 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/oh-package.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": {} -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entryability/EntryAbility.ets index aecc7ce5560b46e9af2c62b501d653613b82eaaa..5b89ce6e3e9414b747986add6edbf9238b96dda6 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2024 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/TextCollapseEtsDemo', (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'); - } -} +/* + * Copyright (c) 2024 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/TextCollapseEtsDemo', (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/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 560fce1497b6e2942e88e1f57fc32b9aa2877a87..9afbfdf88d6ace08efa1db1e3f36c9f62f4722be 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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)); - } +/* + * Copyright (c) 2024 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/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/pages/TextCollapseEtsDemo.ets b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/pages/TextCollapseEtsDemo.ets index 00492d00b6e0fddf15d8c054870606e9a21f9319..018efcb4e2c2916be3244e4860cab5828328baa2 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/pages/TextCollapseEtsDemo.ets +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/ets/pages/TextCollapseEtsDemo.ets @@ -1,345 +1,345 @@ -/* - * Copyright (c) 2024 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 image from '@ohos.multimedia.image'; -import drawing from '@ohos.graphics.drawing'; -import font from '@ohos.font'; -import { text } from '@kit.ArkGraphics2D'; - -class TextViewModel { - public type: number = 0; - public content: string = ''; - public fontSize: number = 0; - public fontColor: Color = Color.Black; - public width: number = 0; - public height: number = 0; -} - -class Results { - public index: number = 0; - public lineCount: number = 0; -} - -@Entry -@Component -struct TextCollapseTest { - @State suffixStr: string = ''; - @State suffixStr2: string = ''; - EXPAND_STR: string = this.resourceToString($r('app.string.expand_str')); - COLLAPSE_STR: string = this.resourceToString($r('app.string.collapse_str')); - - expanded: Boolean = true; - needProcess: boolean = true; - lineCount: number = 0; - collapseIndex: number = 0; - @State pixelMap: image.PixelMap | undefined = undefined; - - originViewModelList: TextViewModel[] = [ - { - type: 0, - content: this.resourceToString($r('app.string.list_content1')), - fontSize: 8, - fontColor: Color.Black, - width: 0, - height: 0 - }, - { - type: 0, - content: this.resourceToString($r('app.string.list_content2')), - fontSize: 12, - fontColor: Color.Black, - width: 0, - height: 0 - }, - { - type: 1, - content: 'app.media.icon', - fontSize: 12, - fontColor: Color.Black, - width: 20, - height: 20 - }, - { - type: 0, - content: this.resourceToString($r('app.string.list_content3')), - fontSize: 12, - fontColor: Color.Black, - width: 0, - height: 0 - }, - { - type: 1, - content: 'app.media.icon', - fontSize: 12, - fontColor: Color.Black, - width: 20, - height: 20 - }, - ] - collapseViewModelList: TextViewModel[] = [] - @State textViewModelList: TextViewModel[] = [] - - aboutToAppear(): void { - this.getResultFromNdk(); - this.process(); - - font.registerFont({ // 自定义字体 - familyName: 'stxingka123', - familySrc: $rawfile('STXINGKA.ttf') // rawfile下 - }) - } - - resourceToString(resource: Resource): string { - return getContext(this).resourceManager.getStringSync(resource); - } - - layoutText() { - const color: ArrayBuffer = new ArrayBuffer(160000); - let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 } }; - this.pixelMap = image.createPixelMapSync(color, opts); - let canvas = new drawing.Canvas(this.pixelMap); - let myTextStyle: text.TextStyle = { - color: { - alpha: 255, - red: 255, - green: 0, - blue: 0 - }, - fontSize: 33, - }; - let myParagraphStyle: text.ParagraphStyle = { - textStyle: myTextStyle, - align: 3, - } - let fontCollection = text.FontCollection.getGlobalInstance(); - let paragraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection); - paragraphGraphBuilder.pushStyle(myTextStyle); - paragraphGraphBuilder.addText('12312'); - paragraphGraphBuilder.pushStyle(myTextStyle); - paragraphGraphBuilder.addText('afdsss'); - - let paragraph = paragraphGraphBuilder.build(); - paragraph.layoutSync(100); - let maxWidth = paragraph.getMaxWidth(); - let height = paragraph.getHeight(); - let longestLine = paragraph.getLongestLine(); - let minIntrinsicWidth = paragraph.getMinIntrinsicWidth(); - let maxIntrinsicWidth = paragraph.getMaxIntrinsicWidth(); - let alphabeticBaseline = paragraph.getAlphabeticBaseline(); - let ideographicBaseline = paragraph.getIdeographicBaseline(); - let range: text.Range = { start: 0, end: 1 }; - let rects = paragraph.getRectsForRange(range, text.RectWidthStyle.TIGHT, text.RectHeightStyle.TIGHT); - let placeholderRects = paragraph.getRectsForPlaceholders(); - let positionWidthAffinity = paragraph.getGlyphPositionAtCoordinate(0, 0); - let wordRange = paragraph.getWordBoundary(0); - let lineCount = paragraph.getLineCount(); - if (lineCount > 0) { - let lineHeight = paragraph.getLineHeight(0); - let lineWidth = paragraph.getLineWidth(0); - } - let didExceed = paragraph.didExceedMaxLines(); - let lines = paragraph.getTextLines(); - paragraph.paint(canvas, 0, 0); - } - - GetSumbleLen() { - let myTextStyle: text.TextStyle = { - fontSize: 12*3.25, - }; - let myParagraphStyle: text.ParagraphStyle = { - textStyle: myTextStyle, - }; - let fontCollection = new text.FontCollection(); - let paragraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection); - paragraphGraphBuilder.pushStyle(myTextStyle); - paragraphGraphBuilder.addText(this.EXPAND_STR); - let paragraph = paragraphGraphBuilder.build(); - paragraph.layoutSync(200*3.25); - return paragraph.getLineWidth(0); - } - - getFoldIndex() { - let myTextStyle: text.TextStyle = { - color: { - alpha: 255, - red: 255, - green: 0, - blue: 0 - } - }; - let myParagraphStyle: text.ParagraphStyle = { - textStyle: myTextStyle, - }; - let fontCollection = text.FontCollection.getGlobalInstance(); - fontCollection.loadFontSync('123222', $rawfile('FZBWKSJW.TTF')); - let paragraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection); - for (let i = 0; i < 5; i++) { - let ret: TextViewModel = this.originViewModelList[i]; - let type: number = ret.type; - let content: string = ret.content; - let fontSize: number = ret.fontSize; - let width: number = ret.width; - let height: number = ret.height; - - if (type == 0) { - myTextStyle.fontSize = fontSize * 3.25; - paragraphGraphBuilder.pushStyle(myTextStyle); - paragraphGraphBuilder.addText(content); - } else if (type == 1) { - let myPlaceholderSpan: text.PlaceholderSpan = { - width: width * 3.25, - height: height * 3.25, - align: text.PlaceholderAlignment.ABOVE_BASELINE, - baseline: text.TextBaseline.ALPHABETIC, - baselineOffset: 0 - }; - paragraphGraphBuilder.addPlaceholder(myPlaceholderSpan); - } - } - let paragraph = paragraphGraphBuilder.build(); - paragraph.layoutSync(650); - let curWidth = this.GetSumbleLen(); - let i: number = 53; - if (paragraph.getLineCount() > 2) { - let x = 650 - curWidth; - let y = paragraph.getLineHeight(0) + paragraph.getLineHeight(1)/2; - let positionWithAffinity = paragraph.getGlyphPositionAtCoordinate(x, y); - if (positionWithAffinity.affinity == text.Affinity.UPSTREAM) { - i = positionWithAffinity.position; - } else { - i = positionWithAffinity.position + 1; - } - } - - const color: ArrayBuffer = new ArrayBuffer(650 * 300 * 4); - let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 300, width: 650 } } - this.pixelMap = image.createPixelMapSync(color, opts); - let canvas = new drawing.Canvas(this.pixelMap); - paragraph.paint(canvas, 0, 0); - - let ret: Results = { - index: i, - lineCount: paragraph.getLineCount(), - } - return ret; - } - - getResultFromNdk(): void { - let result: Results = this.getFoldIndex(); - console.log('GetFoldIndex result: ' + JSON.stringify(result)); - this.lineCount = result.lineCount; - this.collapseIndex = result.index; - if (this.lineCount <= 2) { - this.needProcess = false; - this.textViewModelList = this.originViewModelList; - return; - } - // 裁剪 - let currentIndex = 0; - for (let i = 0; i < this.originViewModelList.length; i++) { - let viewModel: TextViewModel = JSON.parse(JSON.stringify(this.originViewModelList[i])); - if (viewModel.type === 0) { - currentIndex += viewModel.content.length; - } else if (viewModel.type === 1) { - currentIndex += 1; - } - if (currentIndex < this.collapseIndex) { - this.collapseViewModelList.push(viewModel); - } else { - if (viewModel.type === 1) { - break; - } - let subLen = this.collapseIndex - (currentIndex - viewModel.content.length); - viewModel.content = viewModel.content.substring(0, subLen - 1); - this.collapseViewModelList.push(viewModel); - break; - } - } - } - - process(): void { - if (this.expanded) { - this.collapseText(); - } else { - this.expandText(); - } - } - - // 展开文本 - expandText(): void { - if (!this.needProcess) { - return; - } - this.expanded = true; - this.textViewModelList = this.originViewModelList; - this.suffixStr = this.COLLAPSE_STR; - this.suffixStr2 = ''; - } - - // 收起文本 - collapseText(): void { - if (!this.needProcess) { - return; - } - this.expanded = false; - this.textViewModelList = this.collapseViewModelList; - this.suffixStr = this.EXPAND_STR; - this.suffixStr2 = this.EXPAND_STR; - } - build() { - Row() { - Column() { - Text() { - ForEach(this.textViewModelList, (item: TextViewModel) => { - if (item.type === 0) { - Span(item.content) - .fontSize(item.fontSize) - .fontColor(item.height) - } else if (item.type === 1) { - ImageSpan($r(item.content)) - .height(item.height) - .width(item.width) - } - }) - if (this.needProcess) { - if (this.suffixStr == this.COLLAPSE_STR) { - Span('\n'); - } - Span(this.suffixStr) - .fontColor(Color.Orange) - .id('span_click') - .onClick(() => { - this.process(); - }) - } - } - .width('640px') - .borderWidth(1) - .id('text_click') - .onClick(() => { - this.process(); - }) - - Image(this.pixelMap) - .width('640px') - .height('300px') - .borderWidth(1) - .margin(50) - } - .width('100%') - } - .height('100%') - } +/* + * Copyright (c) 2024 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 image from '@ohos.multimedia.image'; +import drawing from '@ohos.graphics.drawing'; +import font from '@ohos.font'; +import { text } from '@kit.ArkGraphics2D'; + +class TextViewModel { + public type: number = 0; + public content: string = ''; + public fontSize: number = 0; + public fontColor: Color = Color.Black; + public width: number = 0; + public height: number = 0; +} + +class Results { + public index: number = 0; + public lineCount: number = 0; +} + +@Entry +@Component +struct TextCollapseTest { + @State suffixStr: string = ''; + @State suffixStr2: string = ''; + EXPAND_STR: string = this.resourceToString($r('app.string.expand_str')); + COLLAPSE_STR: string = this.resourceToString($r('app.string.collapse_str')); + + expanded: Boolean = true; + needProcess: boolean = true; + lineCount: number = 0; + collapseIndex: number = 0; + @State pixelMap: image.PixelMap | undefined = undefined; + + originViewModelList: TextViewModel[] = [ + { + type: 0, + content: this.resourceToString($r('app.string.list_content1')), + fontSize: 8, + fontColor: Color.Black, + width: 0, + height: 0 + }, + { + type: 0, + content: this.resourceToString($r('app.string.list_content2')), + fontSize: 12, + fontColor: Color.Black, + width: 0, + height: 0 + }, + { + type: 1, + content: 'app.media.icon', + fontSize: 12, + fontColor: Color.Black, + width: 20, + height: 20 + }, + { + type: 0, + content: this.resourceToString($r('app.string.list_content3')), + fontSize: 12, + fontColor: Color.Black, + width: 0, + height: 0 + }, + { + type: 1, + content: 'app.media.icon', + fontSize: 12, + fontColor: Color.Black, + width: 20, + height: 20 + }, + ] + collapseViewModelList: TextViewModel[] = [] + @State textViewModelList: TextViewModel[] = [] + + aboutToAppear(): void { + this.getResultFromNdk(); + this.process(); + + font.registerFont({ // 自定义字体 + familyName: 'stxingka123', + familySrc: $rawfile('STXINGKA.ttf') // rawfile下 + }) + } + + resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } + + layoutText() { + const color: ArrayBuffer = new ArrayBuffer(160000); + let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 } }; + this.pixelMap = image.createPixelMapSync(color, opts); + let canvas = new drawing.Canvas(this.pixelMap); + let myTextStyle: text.TextStyle = { + color: { + alpha: 255, + red: 255, + green: 0, + blue: 0 + }, + fontSize: 33, + }; + let myParagraphStyle: text.ParagraphStyle = { + textStyle: myTextStyle, + align: 3, + } + let fontCollection = text.FontCollection.getGlobalInstance(); + let paragraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection); + paragraphGraphBuilder.pushStyle(myTextStyle); + paragraphGraphBuilder.addText('12312'); + paragraphGraphBuilder.pushStyle(myTextStyle); + paragraphGraphBuilder.addText('afdsss'); + + let paragraph = paragraphGraphBuilder.build(); + paragraph.layoutSync(100); + let maxWidth = paragraph.getMaxWidth(); + let height = paragraph.getHeight(); + let longestLine = paragraph.getLongestLine(); + let minIntrinsicWidth = paragraph.getMinIntrinsicWidth(); + let maxIntrinsicWidth = paragraph.getMaxIntrinsicWidth(); + let alphabeticBaseline = paragraph.getAlphabeticBaseline(); + let ideographicBaseline = paragraph.getIdeographicBaseline(); + let range: text.Range = { start: 0, end: 1 }; + let rects = paragraph.getRectsForRange(range, text.RectWidthStyle.TIGHT, text.RectHeightStyle.TIGHT); + let placeholderRects = paragraph.getRectsForPlaceholders(); + let positionWidthAffinity = paragraph.getGlyphPositionAtCoordinate(0, 0); + let wordRange = paragraph.getWordBoundary(0); + let lineCount = paragraph.getLineCount(); + if (lineCount > 0) { + let lineHeight = paragraph.getLineHeight(0); + let lineWidth = paragraph.getLineWidth(0); + } + let didExceed = paragraph.didExceedMaxLines(); + let lines = paragraph.getTextLines(); + paragraph.paint(canvas, 0, 0); + } + + GetSumbleLen() { + let myTextStyle: text.TextStyle = { + fontSize: 12*3.25, + }; + let myParagraphStyle: text.ParagraphStyle = { + textStyle: myTextStyle, + }; + let fontCollection = new text.FontCollection(); + let paragraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection); + paragraphGraphBuilder.pushStyle(myTextStyle); + paragraphGraphBuilder.addText(this.EXPAND_STR); + let paragraph = paragraphGraphBuilder.build(); + paragraph.layoutSync(200*3.25); + return paragraph.getLineWidth(0); + } + + getFoldIndex() { + let myTextStyle: text.TextStyle = { + color: { + alpha: 255, + red: 255, + green: 0, + blue: 0 + } + }; + let myParagraphStyle: text.ParagraphStyle = { + textStyle: myTextStyle, + }; + let fontCollection = text.FontCollection.getGlobalInstance(); + fontCollection.loadFontSync('123222', $rawfile('FZBWKSJW.TTF')); + let paragraphGraphBuilder = new text.ParagraphBuilder(myParagraphStyle, fontCollection); + for (let i = 0; i < 5; i++) { + let ret: TextViewModel = this.originViewModelList[i]; + let type: number = ret.type; + let content: string = ret.content; + let fontSize: number = ret.fontSize; + let width: number = ret.width; + let height: number = ret.height; + + if (type == 0) { + myTextStyle.fontSize = fontSize * 3.25; + paragraphGraphBuilder.pushStyle(myTextStyle); + paragraphGraphBuilder.addText(content); + } else if (type == 1) { + let myPlaceholderSpan: text.PlaceholderSpan = { + width: width * 3.25, + height: height * 3.25, + align: text.PlaceholderAlignment.ABOVE_BASELINE, + baseline: text.TextBaseline.ALPHABETIC, + baselineOffset: 0 + }; + paragraphGraphBuilder.addPlaceholder(myPlaceholderSpan); + } + } + let paragraph = paragraphGraphBuilder.build(); + paragraph.layoutSync(650); + let curWidth = this.GetSumbleLen(); + let i: number = 53; + if (paragraph.getLineCount() > 2) { + let x = 650 - curWidth; + let y = paragraph.getLineHeight(0) + paragraph.getLineHeight(1)/2; + let positionWithAffinity = paragraph.getGlyphPositionAtCoordinate(x, y); + if (positionWithAffinity.affinity == text.Affinity.UPSTREAM) { + i = positionWithAffinity.position; + } else { + i = positionWithAffinity.position + 1; + } + } + + const color: ArrayBuffer = new ArrayBuffer(650 * 300 * 4); + let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 300, width: 650 } } + this.pixelMap = image.createPixelMapSync(color, opts); + let canvas = new drawing.Canvas(this.pixelMap); + paragraph.paint(canvas, 0, 0); + + let ret: Results = { + index: i, + lineCount: paragraph.getLineCount(), + } + return ret; + } + + getResultFromNdk(): void { + let result: Results = this.getFoldIndex(); + console.log('GetFoldIndex result: ' + JSON.stringify(result)); + this.lineCount = result.lineCount; + this.collapseIndex = result.index; + if (this.lineCount <= 2) { + this.needProcess = false; + this.textViewModelList = this.originViewModelList; + return; + } + // 裁剪 + let currentIndex = 0; + for (let i = 0; i < this.originViewModelList.length; i++) { + let viewModel: TextViewModel = JSON.parse(JSON.stringify(this.originViewModelList[i])); + if (viewModel.type === 0) { + currentIndex += viewModel.content.length; + } else if (viewModel.type === 1) { + currentIndex += 1; + } + if (currentIndex < this.collapseIndex) { + this.collapseViewModelList.push(viewModel); + } else { + if (viewModel.type === 1) { + break; + } + let subLen = this.collapseIndex - (currentIndex - viewModel.content.length); + viewModel.content = viewModel.content.substring(0, subLen - 1); + this.collapseViewModelList.push(viewModel); + break; + } + } + } + + process(): void { + if (this.expanded) { + this.collapseText(); + } else { + this.expandText(); + } + } + + // 展开文本 + expandText(): void { + if (!this.needProcess) { + return; + } + this.expanded = true; + this.textViewModelList = this.originViewModelList; + this.suffixStr = this.COLLAPSE_STR; + this.suffixStr2 = ''; + } + + // 收起文本 + collapseText(): void { + if (!this.needProcess) { + return; + } + this.expanded = false; + this.textViewModelList = this.collapseViewModelList; + this.suffixStr = this.EXPAND_STR; + this.suffixStr2 = this.EXPAND_STR; + } + build() { + Row() { + Column() { + Text() { + ForEach(this.textViewModelList, (item: TextViewModel) => { + if (item.type === 0) { + Span(item.content) + .fontSize(item.fontSize) + .fontColor(item.height) + } else if (item.type === 1) { + ImageSpan($r(item.content)) + .height(item.height) + .width(item.width) + } + }) + if (this.needProcess) { + if (this.suffixStr == this.COLLAPSE_STR) { + Span('\n'); + } + Span(this.suffixStr) + .fontColor(Color.Orange) + .id('span_click') + .onClick(() => { + this.process(); + }) + } + } + .width('640px') + .borderWidth(1) + .id('text_click') + .onClick(() => { + this.process(); + }) + + Image(this.pixelMap) + .width('640px') + .height('300px') + .borderWidth(1) + .margin(50) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/module.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/module.json5 index f8f53507464bbf335eef68f70e300ad62526f14b..53d9f8844fec68eedd1ea32b538f4885828a84f5 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/module.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/module.json5 @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2024 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" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EntryBackupAbility", - "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ] - } +/* + * Copyright (c) 2024 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" + ] + } + ] + } + ], + "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/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/profile/backup_config.json +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/hvigor/hvigor-config.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/hvigor/hvigor-config.json5 index 1a924e923033181799686b35a88ff6c00de08b90..efe6aee6c8ce43917b37c93876f7f94a670284d4 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/hvigor/hvigor-config.json5 @@ -1,22 +1,22 @@ -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - }, - "execution": { - // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ - // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ - } +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + }, + "execution": { + // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ + // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ + } } \ No newline at end of file diff --git a/code/BasicFeature/Graphics/Graphics2d/ExpandText/oh-package.json5 b/code/BasicFeature/Graphics/Graphics2d/ExpandText/oh-package.json5 index d645a02be51ec3ec6bec2da93c5350d0b80b935f..a941f4458316c00220a8f9a3b0c15342b6b6255b 100644 --- a/code/BasicFeature/Graphics/Graphics2d/ExpandText/oh-package.json5 +++ b/code/BasicFeature/Graphics/Graphics2d/ExpandText/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.18", - "@ohos/hamock": "1.0.0" - } -} +/* + * Copyright (c) 2024 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.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/Media/AVSession/VideoPlayer/ohosTest.md b/code/BasicFeature/Media/AVSession/VideoPlayer/ohosTest.md index 16890c14717f4baadaca20e9eb1d1539aa509e6c..d802dfabecbc8f867e5e83b55295e9684c71cfbe 100644 --- a/code/BasicFeature/Media/AVSession/VideoPlayer/ohosTest.md +++ b/code/BasicFeature/Media/AVSession/VideoPlayer/ohosTest.md @@ -1,14 +1,14 @@ -# VideoPlayer 测试用例归档 - -## 用例表 - -|测试功能|预置条件|输入|预期输出|测试结果| -|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| -|拉起应用| 设备正常运行| |成功拉起应用|Pass| -|主页信息展示| 位于主页| |展示当前正在播放的视频信息|Pass| -|主页按钮展示| 位于主页| |展示上一个、下一个、播放暂停按钮|Pass| -|主页进度条展示| 位于主页| |展示播放当前位置时间、视频总时间、进度条|Pass| -|播放| 位于主页| 点击播放按钮| 应用进入播放状态|Pass| -|暂停| 位于主页| 点击暂停按钮| 应用进入暂停状态|Pass| -|上一个| 位于主页| 点击上一个按钮| 开始播放上一个视频|Pass| +# VideoPlayer 测试用例归档 + +## 用例表 + +|测试功能|预置条件|输入|预期输出|测试结果| +|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| +|拉起应用| 设备正常运行| |成功拉起应用|Pass| +|主页信息展示| 位于主页| |展示当前正在播放的视频信息|Pass| +|主页按钮展示| 位于主页| |展示上一个、下一个、播放暂停按钮|Pass| +|主页进度条展示| 位于主页| |展示播放当前位置时间、视频总时间、进度条|Pass| +|播放| 位于主页| 点击播放按钮| 应用进入播放状态|Pass| +|暂停| 位于主页| 点击暂停按钮| 应用进入暂停状态|Pass| +|上一个| 位于主页| 点击上一个按钮| 开始播放上一个视频|Pass| |下一个| 位于主页| 点击下一个按钮| 开始播放下一个视频|Pass| \ No newline at end of file diff --git a/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/LiveCapturer.ets b/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/LiveCapturer.ets index db5a7c1b7c5a6cadbedc357ca2c4db1b34b690f4..fabcf288978095bc315bf6ad3d2d405558b2197b 100644 --- a/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/LiveCapturer.ets +++ b/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/LiveCapturer.ets @@ -1,676 +1,676 @@ -/* -* 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 audio from '@ohos.multimedia.audio'; -import fs from '@ohos.file.fs'; -import router from '@ohos.router'; -import { BusinessError } from '@ohos.base'; -import Logger from '../../../ohosTest/ets/utils/Logger'; - -const MIN_RECORD_SECOND = 5; -const TOTAL_SECOND = 30; -const RANDOM_NUM = 10000; -const INTERVAL_TIME = 1000; -const READ_TIME_OUT = 0; -class Options { - offset: number = 0; - length: number = 0; -} - -@Entry -@Component -struct LiveCapturer { - @State fontColor: string = '#182431'; - @State selectedFontColor: string = '#007DFF'; - @State currentIndex: number = 2; - private audioCapturer?: audio.AudioCapturer; - private audioRenderer?: audio.AudioRenderer; - @State recordState: string = 'init'; // [init,started,continued,paused,stoped]; - private audioCapturerOptions: audio.AudioCapturerOptions = { - streamInfo: { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, - channels: audio.AudioChannel.CHANNEL_2, - sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, - encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW - }, - capturerInfo: { - source: audio.SourceType.SOURCE_TYPE_LIVE, - capturerFlags: 0 - } - }; - private audioRendererOptions: audio.AudioRendererOptions = { - streamInfo: { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, - channels: audio.AudioChannel.CHANNEL_2, - sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, - encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW - }, - rendererInfo: { - content: audio.ContentType.CONTENT_TYPE_MUSIC, - usage: audio.StreamUsage.STREAM_USAGE_MEDIA, - rendererFlags: 0 - } - }; - @State title: string = ''; - @State date: string = ''; - @State playSec: number = 0; - @State renderState: number = 0; - @State recordSec: number = 0; - @State showTime: string = '00:00:00'; - private interval: number = 0; - private bufferSize = 0; - private path = ``; - private fd = 0; - @State isRecordOver: boolean = false; - @State start: number = 0; - @State capturerOffsetStart: number = 0; - - @Builder TabBuilder(index: number, btnId: string) { - Column() { - Text(index === 0 ? $r('app.string.NORMAL_CAPTURER') : - index === 1 ? $r('app.string.PARALLEL_CAPTURER') : - $r('app.string.LIVE_CAPTURER')) - .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) - .opacity(this.currentIndex === index ? 1 : 0.6) - .fontSize(16) - .fontWeight(this.currentIndex === index ? 500 : 400) - .lineHeight(22) - .margin({ top: 17, bottom: 7 }); - Divider() - .strokeWidth(2) - .color('#007DFF') - .opacity(this.currentIndex === index ? 1 : 0); - }.width(78).id('btn_' + btnId); - } - - async aboutToAppear(): Promise { - Logger.info('LiveCapturer aboutToAppear'); - await this.initResource(); - } - - async initResource(): Promise { - try { - let isSupportAec = audio.getAudioManager().getStreamManager() - .isAcousticEchoCancelerSupported(audio.SourceType.SOURCE_TYPE_LIVE); - if (!isSupportAec) { //not support echo cancellation, requiring implementation at the application layer - this.audioCapturerOptions.capturerInfo.source = audio.SourceType.SOURCE_TYPE_MIC; - } - this.audioCapturer = await audio.createAudioCapturer(this.audioCapturerOptions); - this.bufferSize = await this.audioCapturer.getBufferSize(); - this.recordState = 'init'; - this.title = `${this.getDate(2)}_${Math.floor(Math.random() * RANDOM_NUM)}`; - this.path = `/data/storage/el2/base/haps/entry/files/live_capturer_${this.title}.pcm`; - this.date = this.getDate(1); - await this.openFile(this.path); - } catch (err) { - let error = err as BusinessError; - Logger.error(`LiveCapturer:createAudioCapturer err=${JSON.stringify(error)}`); - } - } - - async releseResource(): Promise { - if (this.fd > 0) { - this.closeFile(); - this.fd = 0; - } - if (this.interval) { - clearInterval(this.interval); - } - if (this.audioCapturer) { - Logger.info('LiveCapturer,audioCapturer released'); - await this.audioCapturer.release(); - this.audioCapturer = undefined; - this.recordState = 'init'; - clearInterval(this.interval); - } - if (this.audioRenderer) { - Logger.info('LiveCapturer,audioRenderer released'); - await this.audioRenderer.release(); - this.audioRenderer = undefined; - } - } - - async aboutToDisappear(): Promise { - Logger.info('LiveCapturer,aboutToDisappear is called'); - await this.releseResource(); - } - - async openFile(path: string): Promise { - Logger.info(path); - try { - await fs.open(path, 0o100); - Logger.info('file created success'); - } catch (err) { - let error = err as BusinessError; - Logger.error('file created err:' + JSON.stringify(error)); - return; - } - - try { - let file = await fs.open(path, 0o2); - this.fd = file.fd; - Logger.info(`file open success for read and write mode,fd=${file.fd}`); - } catch (err) { - let error = err as BusinessError; - Logger.error('file open err:' + JSON.stringify(error)); - return; - } - } - - async closeFile(): Promise { - try { - await fs.close(this.fd); - Logger.info('file close success'); - } catch (err) { - let error = err as BusinessError; - Logger.error('file close err:' + JSON.stringify(error)); - return; - } - } - - async capturerStart(): Promise { - if (!this.audioCapturer) { - Logger.error(`LiveCapturer,capturerStart:audioCapturer is null`); - return; - } - - try { - await this.audioCapturer.start(); - // when start,init recordSec - this.recordSec = 0; - this.recordState = 'started'; - Logger.info('audioCapturer start ok'); - clearInterval(this.interval); - this.interval = setInterval(async () => { - if (this.recordSec >= TOTAL_SECOND) { - // over TOTAL_SECOND,need to stop auto - clearInterval(this.interval); - if (this.audioCapturer && this.audioCapturer.state === audio.AudioState.STATE_RUNNING) { - await this.capturerStop(); - } - return; - } - this.recordSec++; - this.showTime = this.getTimesBySecond(this.recordSec); - - }, INTERVAL_TIME); - setTimeout(async () => { - await this.readCapturer(); - }, READ_TIME_OUT); - } catch (err) { - let error = err as BusinessError; - Logger.error(`LiveCapturer:audioCapturer start err=${JSON.stringify(error)}`); - } - } - - async renderCreate(): Promise { - try { - this.audioRenderer = await audio.createAudioRenderer(this.audioRendererOptions); - this.renderState = this.audioRenderer.state; - this.audioRenderer.on('stateChange', (state) => { - this.renderState = state; - }); - } catch (err) { - let error = err as BusinessError; - Logger.error(`createAudioRenderer err=${JSON.stringify(error)}`); - } - } - - async renderStart(): Promise { - if (!this.audioRenderer) { - return; - } - let bufferSize = 0; - try { - bufferSize = await this.audioRenderer.getBufferSize(); - await this.audioRenderer.start(); - } catch (err) { - let error = err as BusinessError; - Logger.error(`start err:${JSON.stringify(error)}`); - } - - try { - let stat = await fs.stat(this.path); - let buf = new ArrayBuffer(bufferSize); - Logger.info(`audioRenderer write start..........`); - let startOffset = this.start; - while (startOffset <= stat.size) { - if (this.audioRenderer.state === audio.AudioState.STATE_PAUSED) { - break; - } - // change tag,to stop - if (this.audioRenderer.state === audio.AudioState.STATE_STOPPED) { - break; - } - if (this.audioRenderer.state === audio.AudioState.STATE_RELEASED) { - return; - } - let options: Options = { - offset: startOffset, - length: bufferSize - }; - Logger.info('renderStart,options=' + JSON.stringify(options)); - - await fs.read(this.fd, buf, options); - await this.audioRenderer.write(buf); - this.playSec = Math.round(startOffset / stat.size * this.recordSec); - startOffset = startOffset + bufferSize; - this.start = startOffset; - } - Logger.info(`audioRenderer write end..........`) - if (this.audioRenderer.state === audio.AudioState.STATE_RUNNING) { - this.start = 0; - await this.renderStop(); - } - } catch (err) { - let error = err as BusinessError; - Logger.error(`write err:${JSON.stringify(error)}`); - } - } - - async renderPause(): Promise { - if (!this.audioRenderer) { - return; - } - try { - await this.audioRenderer.pause(); - } catch (err) { - let error = err as BusinessError; - Logger.error(`pause err:${JSON.stringify(error)}`); - } - } - - async renderStop(): Promise { - if (!this.audioRenderer) { - return; - } - try { - await this.audioRenderer.stop(); - this.start = 0; - } catch (err) { - let error = err as BusinessError; - Logger.error(`stop err:${JSON.stringify(error)}`); - } - } - - async releaseStop(): Promise { - if (!this.audioRenderer) { - return; - } - try { - await this.audioRenderer.release(); - } catch (err) { - let error = err as BusinessError; - Logger.error(`release err:${JSON.stringify(error)}`); - } - } - - async capturerContinue(): Promise { - if (!this.audioCapturer) { - Logger.error(`LiveCapturer,capturerContinue:audioCapturer is null`); - return; - } - - try { - await this.audioCapturer.start() - this.recordState = 'continued'; - Logger.info('audioCapturer start ok'); - this.interval = setInterval(async () => { - if (this.recordSec >= TOTAL_SECOND) { - // over TOTAL_SECOND,need to stop auto - clearInterval(this.interval); - if (this.audioCapturer && this.audioCapturer.state === audio.AudioState.STATE_RUNNING) { - await this.capturerStop(); - } - return; - } - this.recordSec++; - this.showTime = this.getTimesBySecond(this.recordSec); - }, INTERVAL_TIME); - setTimeout(async () => { - await this.readCapturer(); - }, READ_TIME_OUT); - } catch (err) { - let error = err as BusinessError; - Logger.error(`LiveCapturer:audioCapturer start err=${JSON.stringify(error)}`); - } - } - - async capturerStop(): Promise { - if (!this.audioCapturer) { - Logger.error(`LiveCapturer,capturerStop:audioCapturer is null`); - return; - } - if (this.recordSec < MIN_RECORD_SECOND) { - return; - } - - try { - await this.audioCapturer.stop(); - // when recordState is started or continued - this.recordState = 'stopped'; - clearInterval(this.interval); - } catch (err) { - let error = err as BusinessError; - // when recordState is paused - this.recordState = 'stopped'; - Logger.info(`LiveCapturer:audioCapturer stop err=${JSON.stringify(error)}`); - } - this.isRecordOver = true; - await this.renderCreate(); - } - - async capturerPause(): Promise { - if (!this.audioCapturer) { - Logger.error(`LiveCapturer,capturerPause:audioCapturer is null`); - return; - } - - try { - await this.audioCapturer.stop(); - this.recordState = 'paused'; - - clearInterval(this.interval); - } catch (err) { - let error = err as BusinessError; - Logger.error(`LiveCapturer:audioCapturer stop err=${JSON.stringify(error)}`); - return; - } - } - - async readCapturer(): Promise { - Logger.info('LiveCapturer:readCapturer enter'); - if (!this.audioCapturer) { - Logger.error(`LiveCapturer,readCapturer:audioCapturer is null`); - return; - } - - try { - let startOffset = this.capturerOffsetStart; - while (true) { - if (this.audioCapturer.state === audio.AudioState.STATE_STOPPED) { - Logger.info('state is changed to be stopped'); - break; - } - let buffer = await this.audioCapturer.read(this.bufferSize, true); - Logger.info('LiveCapturer:readCapturer read success'); - let options: Options = { - offset: startOffset, - length: this.bufferSize - }; - let writen = await fs.write(this.fd, buffer, options); - Logger.info(`LiveCapturer:readCapturer,startOffset=${startOffset},writen=${writen}`); - startOffset += this.bufferSize; - this.capturerOffsetStart = startOffset; - } - } catch (err) { - let error = err as BusinessError; - Logger.error(`readCapturer err=${JSON.stringify(error)}`); - } - } - - formatNumber(num: number): string { - if (num <= 9) { - return '0' + num; - } else { - return '' + num; - } - } - - getDate(mode: number): string { - let date = new Date(); - if (mode === 1) { - return `${date.getFullYear()}/${this.formatNumber(date.getMonth() + 1)}/${this.formatNumber(date.getDate())}`; - } else { - return `${date.getFullYear()}${this.formatNumber(date.getMonth() + 1)}${this.formatNumber(date.getDate())}`; - } - } - - getTimesBySecond(t: number): string { - let h = Math.floor(t / 60 / 60 % 24); - let m = Math.floor(t / 60 % 60); - let s = Math.floor(t % 60); - let hs = h < 10 ? '0' + h : h; - let ms = m < 10 ? '0' + m : m; - let ss = s < 10 ? '0' + s : s; - return `${hs}:${ms}:${ss}`; - } - - @Builder InitRecord() { - Column() { - Image($r('app.media.ic_record')).width(56).height(56); - } - .width('100%') - .height(56) - .position({ y: 60 }) - .id('live_start_record_btn') - .onClick(() => { - this.capturerStart(); - }); - } - - @Builder StartedRecord() { - Column() { - Text(this.showTime).fontSize(21).fontWeight(500).margin({ bottom: 8 }) - }.width('100%').height(66).position({ y: 30 }).id('live_show_time_txt'); - - - Column() { - Image($r('app.media.ic_recording')).width(56).height(56); - } - .width('100%') - .height(56) - .position({ y: 60 }) - .id('live_stop_record_btn') - .onClick(() => { - this.capturerStop(); - }); - - Column() { - Image($r('app.media.ic_record_pause')).width(24).height(24); - Text($r('app.string.PAUSE')).fontSize(12).fontWeight(400).id('live_pause_record_btn').margin({ top: 2 }); - } - .height(56) - .width(56) - .position({ x: '80%', y: 60 }) - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .onClick(() => { - this.capturerPause(); - }); - } - - @Builder PausedRecord() { - Column() { - Text(this.showTime).fontSize(21).fontWeight(500).margin({ bottom: 8 }); - }.width('100%').height(66).position({ y: 30 }); - - Column() { - Image($r('app.media.ic_recording')).width(56).height(56); - }.width('100%').height(56).position({ y: 60 }) - .onClick(() => { - this.capturerStop(); - }); - - Column() { - Image($r('app.media.ic_record_continue')).width(24).height(24); - Text($r('app.string.CONTINUE')).fontSize(12).fontWeight(400).margin({ top: 2 }); - } - .height(56) - .width(56) - .position({ x: '80%', y: 60 }) - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .id('live_continue_record_btn') - .onClick(() => { - this.capturerContinue(); - }); - } - - @Builder FinishedRecord() { - Column() { - Image($r('app.media.ic_record')).width(56).height(56); - } - .width('100%') - .height(56) - .position({ y: 60 }) - .opacity(0.4) - .id('disalbe_btn'); - } - - build() { - Column() { - Column() { - Navigation() { - } - .width('100%') - .height('100%') - .hideBackButton(false) - .titleMode(NavigationTitleMode.Mini) - .title($r('app.string.AUDIO_CAPTURER')) - .mode(NavigationMode.Stack) - .backgroundColor('#F1F3F5'); - } - .id('live_capturer_back_btn') - .width('100%') - .height(56) - .onClick(async () => { - await router.replaceUrl({ url: 'pages/Index' }); - }); - - Column() { - Tabs({ barPosition: BarPosition.Start, index: 2 }) { - TabContent().tabBar(this.TabBuilder(0, 'normal_capturer')); - TabContent().tabBar(this.TabBuilder(1, 'parallel_capturer')); - TabContent().tabBar(this.TabBuilder(2, 'live_capturer')); - } - .vertical(false) - .barMode(BarMode.Fixed) - .barWidth(360) - .barHeight(56) - .animationDuration(400) - .onChange((index: number) => { - this.currentIndex = index; - if (this.currentIndex === 0) { - router.replaceUrl({ url: 'pages/NormalCapturer' }); - } else if (this.currentIndex === 1) { - router.replaceUrl({ url: 'pages/ParallelCapturer' }); - } - }) - .width('100%') - .height(56) - }.padding({ left: 12, right: 12 }); - - - if (this.isRecordOver === true) { - Column() { - Row() { - Text(this.title) - .fontSize(16) - .fontWeight(500) - .fontColor('#182431') - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')); - if (this.renderState === audio.AudioState.STATE_RUNNING) { - Image($r('app.media.ic_record_playing')).width(24).height(24).id('playing_state'); - } else { - Image($r('app.media.ic_record_paused')).width(24).height(24).id('paused_state'); - } - - }.width('100%').height(24).justifyContent(FlexAlign.SpaceBetween).margin({ top: 16 }); - - Row() { - Text(this.date) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - .opacity(0.6) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')); - Text(this.getTimesBySecond(this.recordSec) + '') - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - .opacity(0.6) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')); - }.width('100%').height(24).justifyContent(FlexAlign.SpaceBetween).margin({ top: 4 }); - - Row() { - Progress({ value: this.playSec, total: this.recordSec, type: ProgressType.Linear }) - .color('#007DFF') - .value(this.playSec) - .width('100%') - .height(4) - }.margin({ top: 23, bottom: 3 }); - - Row() { - Text(this.getTimesBySecond(this.playSec) + '') - .fontSize(12) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .fontColor('#182431') - .opacity(0.6) - .fontWeight(400); - Text(this.getTimesBySecond(this.recordSec) + '') - .fontSize(12) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .fontColor('#182431') - .opacity(0.6) - .fontWeight(400); - }.justifyContent(FlexAlign.SpaceBetween).width('100%'); - } - .width('100%') - .height(126) - .backgroundColor(Color.White) - .borderRadius(24) - .margin({ top: 12 }) - .padding({ left: 12, right: 12 }) - .id('live_player') - .onClick(() => { - if (this.renderState === audio.AudioState.STATE_PREPARED) { - this.renderStart(); - } - if (this.renderState === audio.AudioState.STATE_RUNNING) { - this.renderPause(); - } - if (this.renderState === audio.AudioState.STATE_PAUSED) { - this.renderStart(); - } - if (this.renderState === audio.AudioState.STATE_STOPPED) { - this.renderStart(); - } - }); - } - Row() { - if (this.recordState === 'init') { - this.InitRecord(); - } else if (this.recordState === 'started') { - this.StartedRecord(); - } else if (this.recordState === 'paused') { - this.PausedRecord(); - } else if (this.recordState === 'continued') { - this.StartedRecord(); - } else if (this.recordState === 'stopped') { - this.FinishedRecord(); - } - } - .width('100%') - .alignItems(VerticalAlign.Center) - .height(116) - .position({ y: '82%' }); - } - .width('100%') - .height('100%') - .justifyContent(FlexAlign.Start) - .backgroundColor('#F1F3F5') - .padding({ left: 12, right: 12 }); - } -} +/* +* 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 audio from '@ohos.multimedia.audio'; +import fs from '@ohos.file.fs'; +import router from '@ohos.router'; +import { BusinessError } from '@ohos.base'; +import Logger from '../../../ohosTest/ets/utils/Logger'; + +const MIN_RECORD_SECOND = 5; +const TOTAL_SECOND = 30; +const RANDOM_NUM = 10000; +const INTERVAL_TIME = 1000; +const READ_TIME_OUT = 0; +class Options { + offset: number = 0; + length: number = 0; +} + +@Entry +@Component +struct LiveCapturer { + @State fontColor: string = '#182431'; + @State selectedFontColor: string = '#007DFF'; + @State currentIndex: number = 2; + private audioCapturer?: audio.AudioCapturer; + private audioRenderer?: audio.AudioRenderer; + @State recordState: string = 'init'; // [init,started,continued,paused,stoped]; + private audioCapturerOptions: audio.AudioCapturerOptions = { + streamInfo: { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + channels: audio.AudioChannel.CHANNEL_2, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW + }, + capturerInfo: { + source: audio.SourceType.SOURCE_TYPE_LIVE, + capturerFlags: 0 + } + }; + private audioRendererOptions: audio.AudioRendererOptions = { + streamInfo: { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + channels: audio.AudioChannel.CHANNEL_2, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW + }, + rendererInfo: { + content: audio.ContentType.CONTENT_TYPE_MUSIC, + usage: audio.StreamUsage.STREAM_USAGE_MEDIA, + rendererFlags: 0 + } + }; + @State title: string = ''; + @State date: string = ''; + @State playSec: number = 0; + @State renderState: number = 0; + @State recordSec: number = 0; + @State showTime: string = '00:00:00'; + private interval: number = 0; + private bufferSize = 0; + private path = ``; + private fd = 0; + @State isRecordOver: boolean = false; + @State start: number = 0; + @State capturerOffsetStart: number = 0; + + @Builder TabBuilder(index: number, btnId: string) { + Column() { + Text(index === 0 ? $r('app.string.NORMAL_CAPTURER') : + index === 1 ? $r('app.string.PARALLEL_CAPTURER') : + $r('app.string.LIVE_CAPTURER')) + .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) + .opacity(this.currentIndex === index ? 1 : 0.6) + .fontSize(16) + .fontWeight(this.currentIndex === index ? 500 : 400) + .lineHeight(22) + .margin({ top: 17, bottom: 7 }); + Divider() + .strokeWidth(2) + .color('#007DFF') + .opacity(this.currentIndex === index ? 1 : 0); + }.width(78).id('btn_' + btnId); + } + + async aboutToAppear(): Promise { + Logger.info('LiveCapturer aboutToAppear'); + await this.initResource(); + } + + async initResource(): Promise { + try { + let isSupportAec = audio.getAudioManager().getStreamManager() + .isAcousticEchoCancelerSupported(audio.SourceType.SOURCE_TYPE_LIVE); + if (!isSupportAec) { //not support echo cancellation, requiring implementation at the application layer + this.audioCapturerOptions.capturerInfo.source = audio.SourceType.SOURCE_TYPE_MIC; + } + this.audioCapturer = await audio.createAudioCapturer(this.audioCapturerOptions); + this.bufferSize = await this.audioCapturer.getBufferSize(); + this.recordState = 'init'; + this.title = `${this.getDate(2)}_${Math.floor(Math.random() * RANDOM_NUM)}`; + this.path = `/data/storage/el2/base/haps/entry/files/live_capturer_${this.title}.pcm`; + this.date = this.getDate(1); + await this.openFile(this.path); + } catch (err) { + let error = err as BusinessError; + Logger.error(`LiveCapturer:createAudioCapturer err=${JSON.stringify(error)}`); + } + } + + async releseResource(): Promise { + if (this.fd > 0) { + this.closeFile(); + this.fd = 0; + } + if (this.interval) { + clearInterval(this.interval); + } + if (this.audioCapturer) { + Logger.info('LiveCapturer,audioCapturer released'); + await this.audioCapturer.release(); + this.audioCapturer = undefined; + this.recordState = 'init'; + clearInterval(this.interval); + } + if (this.audioRenderer) { + Logger.info('LiveCapturer,audioRenderer released'); + await this.audioRenderer.release(); + this.audioRenderer = undefined; + } + } + + async aboutToDisappear(): Promise { + Logger.info('LiveCapturer,aboutToDisappear is called'); + await this.releseResource(); + } + + async openFile(path: string): Promise { + Logger.info(path); + try { + await fs.open(path, 0o100); + Logger.info('file created success'); + } catch (err) { + let error = err as BusinessError; + Logger.error('file created err:' + JSON.stringify(error)); + return; + } + + try { + let file = await fs.open(path, 0o2); + this.fd = file.fd; + Logger.info(`file open success for read and write mode,fd=${file.fd}`); + } catch (err) { + let error = err as BusinessError; + Logger.error('file open err:' + JSON.stringify(error)); + return; + } + } + + async closeFile(): Promise { + try { + await fs.close(this.fd); + Logger.info('file close success'); + } catch (err) { + let error = err as BusinessError; + Logger.error('file close err:' + JSON.stringify(error)); + return; + } + } + + async capturerStart(): Promise { + if (!this.audioCapturer) { + Logger.error(`LiveCapturer,capturerStart:audioCapturer is null`); + return; + } + + try { + await this.audioCapturer.start(); + // when start,init recordSec + this.recordSec = 0; + this.recordState = 'started'; + Logger.info('audioCapturer start ok'); + clearInterval(this.interval); + this.interval = setInterval(async () => { + if (this.recordSec >= TOTAL_SECOND) { + // over TOTAL_SECOND,need to stop auto + clearInterval(this.interval); + if (this.audioCapturer && this.audioCapturer.state === audio.AudioState.STATE_RUNNING) { + await this.capturerStop(); + } + return; + } + this.recordSec++; + this.showTime = this.getTimesBySecond(this.recordSec); + + }, INTERVAL_TIME); + setTimeout(async () => { + await this.readCapturer(); + }, READ_TIME_OUT); + } catch (err) { + let error = err as BusinessError; + Logger.error(`LiveCapturer:audioCapturer start err=${JSON.stringify(error)}`); + } + } + + async renderCreate(): Promise { + try { + this.audioRenderer = await audio.createAudioRenderer(this.audioRendererOptions); + this.renderState = this.audioRenderer.state; + this.audioRenderer.on('stateChange', (state) => { + this.renderState = state; + }); + } catch (err) { + let error = err as BusinessError; + Logger.error(`createAudioRenderer err=${JSON.stringify(error)}`); + } + } + + async renderStart(): Promise { + if (!this.audioRenderer) { + return; + } + let bufferSize = 0; + try { + bufferSize = await this.audioRenderer.getBufferSize(); + await this.audioRenderer.start(); + } catch (err) { + let error = err as BusinessError; + Logger.error(`start err:${JSON.stringify(error)}`); + } + + try { + let stat = await fs.stat(this.path); + let buf = new ArrayBuffer(bufferSize); + Logger.info(`audioRenderer write start..........`); + let startOffset = this.start; + while (startOffset <= stat.size) { + if (this.audioRenderer.state === audio.AudioState.STATE_PAUSED) { + break; + } + // change tag,to stop + if (this.audioRenderer.state === audio.AudioState.STATE_STOPPED) { + break; + } + if (this.audioRenderer.state === audio.AudioState.STATE_RELEASED) { + return; + } + let options: Options = { + offset: startOffset, + length: bufferSize + }; + Logger.info('renderStart,options=' + JSON.stringify(options)); + + await fs.read(this.fd, buf, options); + await this.audioRenderer.write(buf); + this.playSec = Math.round(startOffset / stat.size * this.recordSec); + startOffset = startOffset + bufferSize; + this.start = startOffset; + } + Logger.info(`audioRenderer write end..........`) + if (this.audioRenderer.state === audio.AudioState.STATE_RUNNING) { + this.start = 0; + await this.renderStop(); + } + } catch (err) { + let error = err as BusinessError; + Logger.error(`write err:${JSON.stringify(error)}`); + } + } + + async renderPause(): Promise { + if (!this.audioRenderer) { + return; + } + try { + await this.audioRenderer.pause(); + } catch (err) { + let error = err as BusinessError; + Logger.error(`pause err:${JSON.stringify(error)}`); + } + } + + async renderStop(): Promise { + if (!this.audioRenderer) { + return; + } + try { + await this.audioRenderer.stop(); + this.start = 0; + } catch (err) { + let error = err as BusinessError; + Logger.error(`stop err:${JSON.stringify(error)}`); + } + } + + async releaseStop(): Promise { + if (!this.audioRenderer) { + return; + } + try { + await this.audioRenderer.release(); + } catch (err) { + let error = err as BusinessError; + Logger.error(`release err:${JSON.stringify(error)}`); + } + } + + async capturerContinue(): Promise { + if (!this.audioCapturer) { + Logger.error(`LiveCapturer,capturerContinue:audioCapturer is null`); + return; + } + + try { + await this.audioCapturer.start() + this.recordState = 'continued'; + Logger.info('audioCapturer start ok'); + this.interval = setInterval(async () => { + if (this.recordSec >= TOTAL_SECOND) { + // over TOTAL_SECOND,need to stop auto + clearInterval(this.interval); + if (this.audioCapturer && this.audioCapturer.state === audio.AudioState.STATE_RUNNING) { + await this.capturerStop(); + } + return; + } + this.recordSec++; + this.showTime = this.getTimesBySecond(this.recordSec); + }, INTERVAL_TIME); + setTimeout(async () => { + await this.readCapturer(); + }, READ_TIME_OUT); + } catch (err) { + let error = err as BusinessError; + Logger.error(`LiveCapturer:audioCapturer start err=${JSON.stringify(error)}`); + } + } + + async capturerStop(): Promise { + if (!this.audioCapturer) { + Logger.error(`LiveCapturer,capturerStop:audioCapturer is null`); + return; + } + if (this.recordSec < MIN_RECORD_SECOND) { + return; + } + + try { + await this.audioCapturer.stop(); + // when recordState is started or continued + this.recordState = 'stopped'; + clearInterval(this.interval); + } catch (err) { + let error = err as BusinessError; + // when recordState is paused + this.recordState = 'stopped'; + Logger.info(`LiveCapturer:audioCapturer stop err=${JSON.stringify(error)}`); + } + this.isRecordOver = true; + await this.renderCreate(); + } + + async capturerPause(): Promise { + if (!this.audioCapturer) { + Logger.error(`LiveCapturer,capturerPause:audioCapturer is null`); + return; + } + + try { + await this.audioCapturer.stop(); + this.recordState = 'paused'; + + clearInterval(this.interval); + } catch (err) { + let error = err as BusinessError; + Logger.error(`LiveCapturer:audioCapturer stop err=${JSON.stringify(error)}`); + return; + } + } + + async readCapturer(): Promise { + Logger.info('LiveCapturer:readCapturer enter'); + if (!this.audioCapturer) { + Logger.error(`LiveCapturer,readCapturer:audioCapturer is null`); + return; + } + + try { + let startOffset = this.capturerOffsetStart; + while (true) { + if (this.audioCapturer.state === audio.AudioState.STATE_STOPPED) { + Logger.info('state is changed to be stopped'); + break; + } + let buffer = await this.audioCapturer.read(this.bufferSize, true); + Logger.info('LiveCapturer:readCapturer read success'); + let options: Options = { + offset: startOffset, + length: this.bufferSize + }; + let writen = await fs.write(this.fd, buffer, options); + Logger.info(`LiveCapturer:readCapturer,startOffset=${startOffset},writen=${writen}`); + startOffset += this.bufferSize; + this.capturerOffsetStart = startOffset; + } + } catch (err) { + let error = err as BusinessError; + Logger.error(`readCapturer err=${JSON.stringify(error)}`); + } + } + + formatNumber(num: number): string { + if (num <= 9) { + return '0' + num; + } else { + return '' + num; + } + } + + getDate(mode: number): string { + let date = new Date(); + if (mode === 1) { + return `${date.getFullYear()}/${this.formatNumber(date.getMonth() + 1)}/${this.formatNumber(date.getDate())}`; + } else { + return `${date.getFullYear()}${this.formatNumber(date.getMonth() + 1)}${this.formatNumber(date.getDate())}`; + } + } + + getTimesBySecond(t: number): string { + let h = Math.floor(t / 60 / 60 % 24); + let m = Math.floor(t / 60 % 60); + let s = Math.floor(t % 60); + let hs = h < 10 ? '0' + h : h; + let ms = m < 10 ? '0' + m : m; + let ss = s < 10 ? '0' + s : s; + return `${hs}:${ms}:${ss}`; + } + + @Builder InitRecord() { + Column() { + Image($r('app.media.ic_record')).width(56).height(56); + } + .width('100%') + .height(56) + .position({ y: 60 }) + .id('live_start_record_btn') + .onClick(() => { + this.capturerStart(); + }); + } + + @Builder StartedRecord() { + Column() { + Text(this.showTime).fontSize(21).fontWeight(500).margin({ bottom: 8 }) + }.width('100%').height(66).position({ y: 30 }).id('live_show_time_txt'); + + + Column() { + Image($r('app.media.ic_recording')).width(56).height(56); + } + .width('100%') + .height(56) + .position({ y: 60 }) + .id('live_stop_record_btn') + .onClick(() => { + this.capturerStop(); + }); + + Column() { + Image($r('app.media.ic_record_pause')).width(24).height(24); + Text($r('app.string.PAUSE')).fontSize(12).fontWeight(400).id('live_pause_record_btn').margin({ top: 2 }); + } + .height(56) + .width(56) + .position({ x: '80%', y: 60 }) + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .onClick(() => { + this.capturerPause(); + }); + } + + @Builder PausedRecord() { + Column() { + Text(this.showTime).fontSize(21).fontWeight(500).margin({ bottom: 8 }); + }.width('100%').height(66).position({ y: 30 }); + + Column() { + Image($r('app.media.ic_recording')).width(56).height(56); + }.width('100%').height(56).position({ y: 60 }) + .onClick(() => { + this.capturerStop(); + }); + + Column() { + Image($r('app.media.ic_record_continue')).width(24).height(24); + Text($r('app.string.CONTINUE')).fontSize(12).fontWeight(400).margin({ top: 2 }); + } + .height(56) + .width(56) + .position({ x: '80%', y: 60 }) + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .id('live_continue_record_btn') + .onClick(() => { + this.capturerContinue(); + }); + } + + @Builder FinishedRecord() { + Column() { + Image($r('app.media.ic_record')).width(56).height(56); + } + .width('100%') + .height(56) + .position({ y: 60 }) + .opacity(0.4) + .id('disalbe_btn'); + } + + build() { + Column() { + Column() { + Navigation() { + } + .width('100%') + .height('100%') + .hideBackButton(false) + .titleMode(NavigationTitleMode.Mini) + .title($r('app.string.AUDIO_CAPTURER')) + .mode(NavigationMode.Stack) + .backgroundColor('#F1F3F5'); + } + .id('live_capturer_back_btn') + .width('100%') + .height(56) + .onClick(async () => { + await router.replaceUrl({ url: 'pages/Index' }); + }); + + Column() { + Tabs({ barPosition: BarPosition.Start, index: 2 }) { + TabContent().tabBar(this.TabBuilder(0, 'normal_capturer')); + TabContent().tabBar(this.TabBuilder(1, 'parallel_capturer')); + TabContent().tabBar(this.TabBuilder(2, 'live_capturer')); + } + .vertical(false) + .barMode(BarMode.Fixed) + .barWidth(360) + .barHeight(56) + .animationDuration(400) + .onChange((index: number) => { + this.currentIndex = index; + if (this.currentIndex === 0) { + router.replaceUrl({ url: 'pages/NormalCapturer' }); + } else if (this.currentIndex === 1) { + router.replaceUrl({ url: 'pages/ParallelCapturer' }); + } + }) + .width('100%') + .height(56) + }.padding({ left: 12, right: 12 }); + + + if (this.isRecordOver === true) { + Column() { + Row() { + Text(this.title) + .fontSize(16) + .fontWeight(500) + .fontColor('#182431') + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')); + if (this.renderState === audio.AudioState.STATE_RUNNING) { + Image($r('app.media.ic_record_playing')).width(24).height(24).id('playing_state'); + } else { + Image($r('app.media.ic_record_paused')).width(24).height(24).id('paused_state'); + } + + }.width('100%').height(24).justifyContent(FlexAlign.SpaceBetween).margin({ top: 16 }); + + Row() { + Text(this.date) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + .opacity(0.6) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')); + Text(this.getTimesBySecond(this.recordSec) + '') + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + .opacity(0.6) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')); + }.width('100%').height(24).justifyContent(FlexAlign.SpaceBetween).margin({ top: 4 }); + + Row() { + Progress({ value: this.playSec, total: this.recordSec, type: ProgressType.Linear }) + .color('#007DFF') + .value(this.playSec) + .width('100%') + .height(4) + }.margin({ top: 23, bottom: 3 }); + + Row() { + Text(this.getTimesBySecond(this.playSec) + '') + .fontSize(12) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .fontColor('#182431') + .opacity(0.6) + .fontWeight(400); + Text(this.getTimesBySecond(this.recordSec) + '') + .fontSize(12) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .fontColor('#182431') + .opacity(0.6) + .fontWeight(400); + }.justifyContent(FlexAlign.SpaceBetween).width('100%'); + } + .width('100%') + .height(126) + .backgroundColor(Color.White) + .borderRadius(24) + .margin({ top: 12 }) + .padding({ left: 12, right: 12 }) + .id('live_player') + .onClick(() => { + if (this.renderState === audio.AudioState.STATE_PREPARED) { + this.renderStart(); + } + if (this.renderState === audio.AudioState.STATE_RUNNING) { + this.renderPause(); + } + if (this.renderState === audio.AudioState.STATE_PAUSED) { + this.renderStart(); + } + if (this.renderState === audio.AudioState.STATE_STOPPED) { + this.renderStart(); + } + }); + } + Row() { + if (this.recordState === 'init') { + this.InitRecord(); + } else if (this.recordState === 'started') { + this.StartedRecord(); + } else if (this.recordState === 'paused') { + this.PausedRecord(); + } else if (this.recordState === 'continued') { + this.StartedRecord(); + } else if (this.recordState === 'stopped') { + this.FinishedRecord(); + } + } + .width('100%') + .alignItems(VerticalAlign.Center) + .height(116) + .position({ y: '82%' }); + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Start) + .backgroundColor('#F1F3F5') + .padding({ left: 12, right: 12 }); + } +} diff --git a/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/SpatialAudio.ets b/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/SpatialAudio.ets index 59887fe93b3b9e8ac8228f69b53cc48317b3da46..e38e6859556f7b368e3ddf73dcd6507c0257a9c6 100644 --- a/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/SpatialAudio.ets +++ b/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/SpatialAudio.ets @@ -1,452 +1,452 @@ -/* -* 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 Logger from '../../../ohosTest/ets/utils/Logger'; -import common from '@ohos.app.ability.common'; -import fs from '@ohos.file.fs'; -import router from '@ohos.router'; -import audio from '@ohos.multimedia.audio'; -import promptAction from '@ohos.promptAction' -import { BusinessError } from '@ohos.base'; - -@Entry -@Component -struct SpatialAudio { - private audioRenderers: audio.AudioRenderer[] = []; - private audioRendererOptions: audio.AudioRendererOptions[] = [ - { - streamInfo: { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, - channels: audio.AudioChannel.CHANNEL_2, - sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, - encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW, - channelLayout: audio.AudioChannelLayout.CH_LAYOUT_STEREO - }, - - rendererInfo: { - usage: audio.StreamUsage.STREAM_USAGE_MUSIC, - rendererFlags: 0 - } - }, - { - streamInfo: { - samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, - channels: audio.AudioChannel.CHANNEL_6, - sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, - encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW, - channelLayout: audio.AudioChannelLayout.CH_LAYOUT_5POINT1 - }, - rendererInfo: { - usage: audio.StreamUsage.STREAM_USAGE_MOVIE, - rendererFlags: 0 - } - } - ]; - - private appContext?: common.Context; - private audioSources = ['/2p0.pcm', '/5p1.pcm']; - private audioSpatializationManager?: audio.AudioSpatializationManager; - private audioRoutingManager?: audio.AudioRoutingManager; - private curPos: number[] = [0, 0] - @State supportState: boolean = false; - @State spatializationEnabled: boolean = false; - @State musicState1: boolean = false; - @State musicState2: boolean = false; - - @Builder press2PlayDemo1() { - Image($r('app.media.ic_pause_spa')) - .height(36) - .width(36) - .margin({ right: 16 }) - .id('2P0_play_btn') - .fillColor('#182431') - .onClick(async () => { - this.musicState1 = !this.musicState1; - await this.playAudio(0); - }) - } - - @Builder press2PauseDemo1() { - Image($r('app.media.ic_play_spa')) - .height(36) - .width(36) - .margin({ right: 16 }) - .id('2P0_pause_btn') - .onClick(async () => { - this.musicState1 = !this.musicState1; - await this.pauseAudio(0); - }) - } - - @Builder press2PlayDemo2() { - Image($r('app.media.ic_pause_spa')) - .height(36) - .width(36) - .margin({ right: 16 }) - .id('5P1_play_btn') - .fillColor('#182431') - .onClick(async () => { - if (this.spatializationEnabled === true) { - this.musicState2 = !this.musicState2; - await this.playAudio(1); - } else { - promptAction.showToast({ - duration: 3000, - message: ('请开启空间音频') - }); - } - }) - } - - @Builder press2PauseDemo2() { - Image($r('app.media.ic_play_spa')) - .height(36) - .width(36) - .margin({ right: 16 }) - .id('5P1_pause_btn') - .onClick(async () => { - this.musicState2 = !this.musicState2; - await this.pauseAudio(1); - }) - - } - - @Builder audioVividIfNotSupport() { - Text($r('app.string.5P1_MUSIC')) - .fontSize(20) - .fontWeight(500) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .fontColor(Color.Grey) - .margin({ top: 21, bottom: 21, left: 16.5 }) - - Image($r('app.media.ic_pause_spa')) - .height(36) - .width(36) - .margin({ right: 16 }) - .id('5P1_play_btn') - } - - @Builder audioVividIfSupport() { - Text($r('app.string.5P1_MUSIC')) - .fontSize(20) - .fontWeight(500) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .margin({ top: 21, bottom: 21, left: 16.5 }) - } - - @Builder dIYTitle() { - Row() { - Text($r('app.string.SPATIAL_AUDIO')) - .fontWeight(700) - .fontSize(20) - } - .height('100%') - .justifyContent(FlexAlign.Center) - } - - showToastBySpatialEnabled(): void { - if (this.spatializationEnabled === true) { - promptAction.showToast({ - duration: 6000, - message: ('空间音频已开启') - }); - } else { - promptAction.showToast({ - duration: 6000, - message: ('空间音频已关闭') - }); - } - } - - updateSupportStateUI(): void { - this.supportState = this.supportStateQuery(); - if (this.audioSpatializationManager) { - try { - this.spatializationEnabled = this.audioSpatializationManager.isSpatializationEnabledForCurrentDevice(); - } catch (err) { - Logger.error(`update Support State UI failed ,Error: ${JSON.stringify(err)}`); - return; - } - } - } - - supportStateQuery(): boolean { - if (this.audioRoutingManager) { - let audioDeviceDescriptors: audio.AudioDeviceDescriptors = - this.audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(this.audioRendererOptions[0].rendererInfo); - audioDeviceDescriptors.forEach(audioDeviceDescriptor => { - Logger.info("Device Role:" + audioDeviceDescriptor.deviceRole + ", device Type:" + - audioDeviceDescriptor.deviceType + ", Macaddress:" + audioDeviceDescriptor.address + - ", Support:" + audioDeviceDescriptor.spatializationSupported); - }) - - let isSpaSupported: boolean = false; - if (this.audioSpatializationManager) { - try { - isSpaSupported = audioDeviceDescriptors[0].spatializationSupported as boolean; - } catch (err) { - Logger.error(`supportStateQuery ,Error: ${JSON.stringify(err)}`); - } - } else { - Logger.info('Get manager failed.'); - } - return isSpaSupported; - } - return false; - } - - async init(): Promise { - if (this.appContext) { - return; - } - this.appContext = getContext(this); - - for (let index = 0; index < 2; index++) { - try { - let renderer = await audio.createAudioRenderer(this.audioRendererOptions[index]); - Logger.info('Create renderer success'); - this.audioRenderers.push(renderer); - } catch (err) { - Logger.error(`audioRenderer_${index} create ,Error: ${JSON.stringify(err)}`); - return; - } - } - - let audioManager = audio.getAudioManager(); - try { - this.audioSpatializationManager = audioManager.getSpatializationManager(); - } catch (err) { - Logger.error(`Get Spatialization Manager failed, Error: ${JSON.stringify(err)}`); - return; - } - - this.audioRoutingManager = audioManager.getRoutingManager(); - this.updateSupportStateUI(); - let t_audioRendererInfo: audio.AudioRendererInfo = { - usage: audio.StreamUsage.STREAM_USAGE_MUSIC, - rendererFlags: 0 - } - if (this.audioRoutingManager) { - this.audioRoutingManager.on("preferOutputDeviceChangeForRendererInfo", t_audioRendererInfo, () => { - Logger.info('Output device changed'); - this.updateSupportStateUI(); - if (this.audioRenderers[1] && this.audioRenderers[1].state === audio.AudioState.STATE_RUNNING) { - this.audioRenderers[1].pause(); - this.musicState2 = false; - } - }) - } - if (this.audioSpatializationManager) { - this.audioSpatializationManager.on("spatializationEnabledChangeForCurrentDevice", (res) => { - this.spatializationEnabled = res; - this.showToastBySpatialEnabled(); - }) - } - } - - async over(): Promise { - this.appContext = undefined; - try { - this.audioRenderers[0].stop(); - this.audioRenderers[0].release(); - this.audioRenderers[1].stop(); - this.audioRenderers[1].release(); - } catch (err) { - let error = err as BusinessError; - Logger.error(`AudioRenderer stop or release : Error: ${JSON.stringify(error)}`); - return; - } - this.audioRenderers = []; - - if (this.audioRoutingManager) { - this.audioRoutingManager.off("deviceChange"); - } - - if (this.audioSpatializationManager) { - this.audioSpatializationManager.off("spatializationEnabledChangeForCurrentDevice"); - } - } - - async playAudio(index: number): Promise { - if (this.audioRenderers[index] === null) { - return; - } - - let bufferSize: number = 0; - try { - bufferSize = await this.audioRenderers[index].getBufferSize(); - await this.audioRenderers[index].start(); - } catch (err) { - let error = err as BusinessError; - Logger.error(`AudioRenderer start : Error: ${JSON.stringify(error)}`); - return; - } - - let buf = new ArrayBuffer(bufferSize); - let filePath: string = ""; - if (this.appContext) { - filePath = this.appContext.filesDir + this.audioSources[index]; - } - let stat = await fs.stat(filePath); - let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1); - let file = await fs.open(filePath, 0o0); - let i: number = this.curPos[index] - - while (true) { - if (!this.audioRenderers[index]) { - break; - } - Logger.info('start write'); - while (i < len) { - if (this.audioRenderers[index].state === audio.AudioState.STATE_RELEASED) { - return; - } - if (this.audioRenderers[index].state === audio.AudioState.STATE_PAUSED) { - this.curPos[index] = i; - return; - } - - class options { - offset: number = 0 - length: number = 0 - } - - let readOptions: options = { - offset: i * bufferSize, - length: bufferSize - } - await fs.read(file.fd, buf, readOptions); - await this.audioRenderers[index].write(buf); - i += 1; - } - i = 0; - } - - } - - async pauseAudio(index: number): Promise { - try { - if (this.audioRenderers[index]) { - await this.audioRenderers[index].pause(); - } - } catch (err) { - Logger.error(`Pause Error: ${JSON.stringify(err)}`); - return; - } - } - - async aboutToAppear(): Promise { - await this.init(); - } - - aboutToDisappear(): void { - this.over(); - } - - onPageShow(): void { - if (this.audioSpatializationManager === undefined) { - return; - } - this.updateSupportStateUI() - Logger.info('Page show'); - } - - onPageHide(): void { - Logger.info('Page Hide'); - if (this.audioRenderers[0] && this.audioRenderers[0].state === audio.AudioState.STATE_RUNNING) { - this.audioRenderers[0].pause(); - this.musicState1 = false; - } - if (this.audioRenderers[1] && this.audioRenderers[1].state === audio.AudioState.STATE_RUNNING) { - this.audioRenderers[1].pause(); - this.musicState2 = false; - } - } - - build() { - Column() { - Column() { - Row() { - Navigation() { - } - .hideBackButton(false) - .titleMode(NavigationTitleMode.Mini) - .title(this.dIYTitle()) - .mode(NavigationMode.Stack) - } - .height(56) - .width(360) - .id('spatial_audio_back_btn') - .onClick(async () => { - await router.replaceUrl({ url: 'pages/Index' }); - }) - - Row() { - Row() { - Text($r('app.string.2P0_MUSIC')) - .fontSize(20) - .fontWeight(500) - .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) - .margin({ top: 21, bottom: 21, left: 16.5 }) - if (!this.musicState1) { - this.press2PlayDemo1(); - } else { - this.press2PauseDemo1(); - } - } - .height('100%') - .width(336) - .backgroundColor('#FFFFFF') - .justifyContent(FlexAlign.SpaceBetween) - .borderRadius(24) - } - .justifyContent(FlexAlign.SpaceAround) - .height(68) - .width('100%') - .margin({ top: 8 }) - - Row() { - Row() { - if (this.supportState === false) { - this.audioVividIfNotSupport(); - } else { - this.audioVividIfSupport(); - if (!this.musicState2) { - this.press2PlayDemo2(); - } else { - this.press2PauseDemo2(); - } - } - } - .height('100%') - .width(336) - .backgroundColor('#FFFFFF') - .justifyContent(FlexAlign.SpaceBetween) - .borderRadius(24) - } - .justifyContent(FlexAlign.SpaceAround) - .height(68) - .width('100%') - .margin({ top: 12 }) - } - .width('100%') - .justifyContent(FlexAlign.Start) - } - .height('100%') - .width('100%') - .backgroundColor('#f1f3f5') - .justifyContent(FlexAlign.SpaceBetween) - } +/* +* 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 Logger from '../../../ohosTest/ets/utils/Logger'; +import common from '@ohos.app.ability.common'; +import fs from '@ohos.file.fs'; +import router from '@ohos.router'; +import audio from '@ohos.multimedia.audio'; +import promptAction from '@ohos.promptAction' +import { BusinessError } from '@ohos.base'; + +@Entry +@Component +struct SpatialAudio { + private audioRenderers: audio.AudioRenderer[] = []; + private audioRendererOptions: audio.AudioRendererOptions[] = [ + { + streamInfo: { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, + channels: audio.AudioChannel.CHANNEL_2, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW, + channelLayout: audio.AudioChannelLayout.CH_LAYOUT_STEREO + }, + + rendererInfo: { + usage: audio.StreamUsage.STREAM_USAGE_MUSIC, + rendererFlags: 0 + } + }, + { + streamInfo: { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000, + channels: audio.AudioChannel.CHANNEL_6, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW, + channelLayout: audio.AudioChannelLayout.CH_LAYOUT_5POINT1 + }, + rendererInfo: { + usage: audio.StreamUsage.STREAM_USAGE_MOVIE, + rendererFlags: 0 + } + } + ]; + + private appContext?: common.Context; + private audioSources = ['/2p0.pcm', '/5p1.pcm']; + private audioSpatializationManager?: audio.AudioSpatializationManager; + private audioRoutingManager?: audio.AudioRoutingManager; + private curPos: number[] = [0, 0] + @State supportState: boolean = false; + @State spatializationEnabled: boolean = false; + @State musicState1: boolean = false; + @State musicState2: boolean = false; + + @Builder press2PlayDemo1() { + Image($r('app.media.ic_pause_spa')) + .height(36) + .width(36) + .margin({ right: 16 }) + .id('2P0_play_btn') + .fillColor('#182431') + .onClick(async () => { + this.musicState1 = !this.musicState1; + await this.playAudio(0); + }) + } + + @Builder press2PauseDemo1() { + Image($r('app.media.ic_play_spa')) + .height(36) + .width(36) + .margin({ right: 16 }) + .id('2P0_pause_btn') + .onClick(async () => { + this.musicState1 = !this.musicState1; + await this.pauseAudio(0); + }) + } + + @Builder press2PlayDemo2() { + Image($r('app.media.ic_pause_spa')) + .height(36) + .width(36) + .margin({ right: 16 }) + .id('5P1_play_btn') + .fillColor('#182431') + .onClick(async () => { + if (this.spatializationEnabled === true) { + this.musicState2 = !this.musicState2; + await this.playAudio(1); + } else { + promptAction.showToast({ + duration: 3000, + message: ('请开启空间音频') + }); + } + }) + } + + @Builder press2PauseDemo2() { + Image($r('app.media.ic_play_spa')) + .height(36) + .width(36) + .margin({ right: 16 }) + .id('5P1_pause_btn') + .onClick(async () => { + this.musicState2 = !this.musicState2; + await this.pauseAudio(1); + }) + + } + + @Builder audioVividIfNotSupport() { + Text($r('app.string.5P1_MUSIC')) + .fontSize(20) + .fontWeight(500) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .fontColor(Color.Grey) + .margin({ top: 21, bottom: 21, left: 16.5 }) + + Image($r('app.media.ic_pause_spa')) + .height(36) + .width(36) + .margin({ right: 16 }) + .id('5P1_play_btn') + } + + @Builder audioVividIfSupport() { + Text($r('app.string.5P1_MUSIC')) + .fontSize(20) + .fontWeight(500) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .margin({ top: 21, bottom: 21, left: 16.5 }) + } + + @Builder dIYTitle() { + Row() { + Text($r('app.string.SPATIAL_AUDIO')) + .fontWeight(700) + .fontSize(20) + } + .height('100%') + .justifyContent(FlexAlign.Center) + } + + showToastBySpatialEnabled(): void { + if (this.spatializationEnabled === true) { + promptAction.showToast({ + duration: 6000, + message: ('空间音频已开启') + }); + } else { + promptAction.showToast({ + duration: 6000, + message: ('空间音频已关闭') + }); + } + } + + updateSupportStateUI(): void { + this.supportState = this.supportStateQuery(); + if (this.audioSpatializationManager) { + try { + this.spatializationEnabled = this.audioSpatializationManager.isSpatializationEnabledForCurrentDevice(); + } catch (err) { + Logger.error(`update Support State UI failed ,Error: ${JSON.stringify(err)}`); + return; + } + } + } + + supportStateQuery(): boolean { + if (this.audioRoutingManager) { + let audioDeviceDescriptors: audio.AudioDeviceDescriptors = + this.audioRoutingManager.getPreferredOutputDeviceForRendererInfoSync(this.audioRendererOptions[0].rendererInfo); + audioDeviceDescriptors.forEach(audioDeviceDescriptor => { + Logger.info("Device Role:" + audioDeviceDescriptor.deviceRole + ", device Type:" + + audioDeviceDescriptor.deviceType + ", Macaddress:" + audioDeviceDescriptor.address + + ", Support:" + audioDeviceDescriptor.spatializationSupported); + }) + + let isSpaSupported: boolean = false; + if (this.audioSpatializationManager) { + try { + isSpaSupported = audioDeviceDescriptors[0].spatializationSupported as boolean; + } catch (err) { + Logger.error(`supportStateQuery ,Error: ${JSON.stringify(err)}`); + } + } else { + Logger.info('Get manager failed.'); + } + return isSpaSupported; + } + return false; + } + + async init(): Promise { + if (this.appContext) { + return; + } + this.appContext = getContext(this); + + for (let index = 0; index < 2; index++) { + try { + let renderer = await audio.createAudioRenderer(this.audioRendererOptions[index]); + Logger.info('Create renderer success'); + this.audioRenderers.push(renderer); + } catch (err) { + Logger.error(`audioRenderer_${index} create ,Error: ${JSON.stringify(err)}`); + return; + } + } + + let audioManager = audio.getAudioManager(); + try { + this.audioSpatializationManager = audioManager.getSpatializationManager(); + } catch (err) { + Logger.error(`Get Spatialization Manager failed, Error: ${JSON.stringify(err)}`); + return; + } + + this.audioRoutingManager = audioManager.getRoutingManager(); + this.updateSupportStateUI(); + let t_audioRendererInfo: audio.AudioRendererInfo = { + usage: audio.StreamUsage.STREAM_USAGE_MUSIC, + rendererFlags: 0 + } + if (this.audioRoutingManager) { + this.audioRoutingManager.on("preferOutputDeviceChangeForRendererInfo", t_audioRendererInfo, () => { + Logger.info('Output device changed'); + this.updateSupportStateUI(); + if (this.audioRenderers[1] && this.audioRenderers[1].state === audio.AudioState.STATE_RUNNING) { + this.audioRenderers[1].pause(); + this.musicState2 = false; + } + }) + } + if (this.audioSpatializationManager) { + this.audioSpatializationManager.on("spatializationEnabledChangeForCurrentDevice", (res) => { + this.spatializationEnabled = res; + this.showToastBySpatialEnabled(); + }) + } + } + + async over(): Promise { + this.appContext = undefined; + try { + this.audioRenderers[0].stop(); + this.audioRenderers[0].release(); + this.audioRenderers[1].stop(); + this.audioRenderers[1].release(); + } catch (err) { + let error = err as BusinessError; + Logger.error(`AudioRenderer stop or release : Error: ${JSON.stringify(error)}`); + return; + } + this.audioRenderers = []; + + if (this.audioRoutingManager) { + this.audioRoutingManager.off("deviceChange"); + } + + if (this.audioSpatializationManager) { + this.audioSpatializationManager.off("spatializationEnabledChangeForCurrentDevice"); + } + } + + async playAudio(index: number): Promise { + if (this.audioRenderers[index] === null) { + return; + } + + let bufferSize: number = 0; + try { + bufferSize = await this.audioRenderers[index].getBufferSize(); + await this.audioRenderers[index].start(); + } catch (err) { + let error = err as BusinessError; + Logger.error(`AudioRenderer start : Error: ${JSON.stringify(error)}`); + return; + } + + let buf = new ArrayBuffer(bufferSize); + let filePath: string = ""; + if (this.appContext) { + filePath = this.appContext.filesDir + this.audioSources[index]; + } + let stat = await fs.stat(filePath); + let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1); + let file = await fs.open(filePath, 0o0); + let i: number = this.curPos[index] + + while (true) { + if (!this.audioRenderers[index]) { + break; + } + Logger.info('start write'); + while (i < len) { + if (this.audioRenderers[index].state === audio.AudioState.STATE_RELEASED) { + return; + } + if (this.audioRenderers[index].state === audio.AudioState.STATE_PAUSED) { + this.curPos[index] = i; + return; + } + + class options { + offset: number = 0 + length: number = 0 + } + + let readOptions: options = { + offset: i * bufferSize, + length: bufferSize + } + await fs.read(file.fd, buf, readOptions); + await this.audioRenderers[index].write(buf); + i += 1; + } + i = 0; + } + + } + + async pauseAudio(index: number): Promise { + try { + if (this.audioRenderers[index]) { + await this.audioRenderers[index].pause(); + } + } catch (err) { + Logger.error(`Pause Error: ${JSON.stringify(err)}`); + return; + } + } + + async aboutToAppear(): Promise { + await this.init(); + } + + aboutToDisappear(): void { + this.over(); + } + + onPageShow(): void { + if (this.audioSpatializationManager === undefined) { + return; + } + this.updateSupportStateUI() + Logger.info('Page show'); + } + + onPageHide(): void { + Logger.info('Page Hide'); + if (this.audioRenderers[0] && this.audioRenderers[0].state === audio.AudioState.STATE_RUNNING) { + this.audioRenderers[0].pause(); + this.musicState1 = false; + } + if (this.audioRenderers[1] && this.audioRenderers[1].state === audio.AudioState.STATE_RUNNING) { + this.audioRenderers[1].pause(); + this.musicState2 = false; + } + } + + build() { + Column() { + Column() { + Row() { + Navigation() { + } + .hideBackButton(false) + .titleMode(NavigationTitleMode.Mini) + .title(this.dIYTitle()) + .mode(NavigationMode.Stack) + } + .height(56) + .width(360) + .id('spatial_audio_back_btn') + .onClick(async () => { + await router.replaceUrl({ url: 'pages/Index' }); + }) + + Row() { + Row() { + Text($r('app.string.2P0_MUSIC')) + .fontSize(20) + .fontWeight(500) + .fontFamily($r('sys.string.ohos_id_text_font_family_medium')) + .margin({ top: 21, bottom: 21, left: 16.5 }) + if (!this.musicState1) { + this.press2PlayDemo1(); + } else { + this.press2PauseDemo1(); + } + } + .height('100%') + .width(336) + .backgroundColor('#FFFFFF') + .justifyContent(FlexAlign.SpaceBetween) + .borderRadius(24) + } + .justifyContent(FlexAlign.SpaceAround) + .height(68) + .width('100%') + .margin({ top: 8 }) + + Row() { + Row() { + if (this.supportState === false) { + this.audioVividIfNotSupport(); + } else { + this.audioVividIfSupport(); + if (!this.musicState2) { + this.press2PlayDemo2(); + } else { + this.press2PauseDemo2(); + } + } + } + .height('100%') + .width(336) + .backgroundColor('#FFFFFF') + .justifyContent(FlexAlign.SpaceBetween) + .borderRadius(24) + } + .justifyContent(FlexAlign.SpaceAround) + .height(68) + .width('100%') + .margin({ top: 12 }) + } + .width('100%') + .justifyContent(FlexAlign.Start) + } + .height('100%') + .width('100%') + .backgroundColor('#f1f3f5') + .justifyContent(FlexAlign.SpaceBetween) + } } \ No newline at end of file diff --git a/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/VolumePanel.ets b/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/VolumePanel.ets index 741cab891d3419b2ea445b80a92446c48bceae71..9de568e387282ddf3f3b526e9ed3eea501ac797b 100644 --- a/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/VolumePanel.ets +++ b/code/BasicFeature/Media/Audio/entry/src/main/ets/pages/VolumePanel.ets @@ -1,82 +1,82 @@ -/* -* Copyright (C) 2024 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 router from '@ohos.router'; -import audio from '@ohos.multimedia.audio'; -import display from '@ohos.display'; -import { AVVolumePanel } from '@ohos.multimedia.avVolumePanel'; - -@Entry -@Component -struct VolumePanel { - @State private curMediaVolume: number = 0; - private audioManager: audio.AudioManager = audio.getAudioManager(); - private audioVolumeManager: audio.AudioVolumeManager | undefined = undefined; - - aboutToAppear(): void { - this.audioVolumeManager = this.audioManager.getVolumeManager(); - this.audioVolumeManager?.on('volumeChange', async (data) => { - let event: audio.VolumeEvent = data; - this.curMediaVolume = event.volume; - }) - } - - build() { - Column() { - Row() { - Navigation() { - NavRouter() { - NavDestination() { - } - } - } - .height('100%') - .width('100%') - .hideBackButton(false) - .titleMode(NavigationTitleMode.Mini) - .title($r('app.string.AVVOLUME_PANEL_TITLE')) - .mode(NavigationMode.Stack); - }.height(56).width('100%').id('back_btn_focus') - .onClick(async () => { - await router.pushUrl({ url: 'pages/Index' }); - }); - - Column() { - Row() { - Button() { - Text($r('app.string.VOLUME_UP')).fontSize(22).fontColor(Color.White) - }.width('49%').height(60).onClick(() => { - this.curMediaVolume++; - }) - - Button() { - Text($r('app.string.VOLUME_DOWN')).fontSize(22).fontColor(Color.White) - }.width('49%').height(60).onClick(() => { - this.curMediaVolume--; - }) - }.margin(({ top: 10 })).width('100%').justifyContent(FlexAlign.SpaceBetween) - - AVVolumePanel({ - volumeLevel: this.curMediaVolume, - volumeParameter: { - position: { - x: display.getDefaultDisplaySync().width / 2 - vp2px(20), - y: display.getDefaultDisplaySync().height / 2 - vp2px(83) - } - } - }) - } - } - } +/* +* Copyright (C) 2024 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 router from '@ohos.router'; +import audio from '@ohos.multimedia.audio'; +import display from '@ohos.display'; +import { AVVolumePanel } from '@ohos.multimedia.avVolumePanel'; + +@Entry +@Component +struct VolumePanel { + @State private curMediaVolume: number = 0; + private audioManager: audio.AudioManager = audio.getAudioManager(); + private audioVolumeManager: audio.AudioVolumeManager | undefined = undefined; + + aboutToAppear(): void { + this.audioVolumeManager = this.audioManager.getVolumeManager(); + this.audioVolumeManager?.on('volumeChange', async (data) => { + let event: audio.VolumeEvent = data; + this.curMediaVolume = event.volume; + }) + } + + build() { + Column() { + Row() { + Navigation() { + NavRouter() { + NavDestination() { + } + } + } + .height('100%') + .width('100%') + .hideBackButton(false) + .titleMode(NavigationTitleMode.Mini) + .title($r('app.string.AVVOLUME_PANEL_TITLE')) + .mode(NavigationMode.Stack); + }.height(56).width('100%').id('back_btn_focus') + .onClick(async () => { + await router.pushUrl({ url: 'pages/Index' }); + }); + + Column() { + Row() { + Button() { + Text($r('app.string.VOLUME_UP')).fontSize(22).fontColor(Color.White) + }.width('49%').height(60).onClick(() => { + this.curMediaVolume++; + }) + + Button() { + Text($r('app.string.VOLUME_DOWN')).fontSize(22).fontColor(Color.White) + }.width('49%').height(60).onClick(() => { + this.curMediaVolume--; + }) + }.margin(({ top: 10 })).width('100%').justifyContent(FlexAlign.SpaceBetween) + + AVVolumePanel({ + volumeLevel: this.curMediaVolume, + volumeParameter: { + position: { + x: display.getDefaultDisplaySync().width / 2 - vp2px(20), + y: display.getDefaultDisplaySync().height / 2 - vp2px(83) + } + } + }) + } + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Media/Camera/README.md b/code/BasicFeature/Media/Camera/README.md index 2b9b279add33623a0b3c88624ec8b8c0e1307208..91504c75133ba0f04624b4044af5cf68ea74bca4 100644 --- a/code/BasicFeature/Media/Camera/README.md +++ b/code/BasicFeature/Media/Camera/README.md @@ -1,141 +1,141 @@ - -# 相机 - -### 介绍 - -本示例主要展示了相机的相关功能,使用[libohcamera.so] -当前版本sample仅用作联调,最新sdk未带相机c接口头文件。 -接口实现相机的预览、拍照、录像、前后置摄像头切换进行拍照、录像,以及闪光灯、变焦、对焦、曝光等控制类功能。 - -### 效果预览 - -| 相机权限 | 图片和视频权限 | 麦克风权限 | 预览界面 | -|----------------------------|----------------------------|----------------------------|---------------------------------| -| ![auth](app_pic/auth1.jpg) | ![auth](app_pic/auth2.jpg) | ![auth](app_pic/auth3.jpg) | ![preview](app_pic/preview.jpg) | - -使用说明 -(因RK3568设备硬件能力,现仅支持验证1、2、3、9、10、13) -1. 弹出是否允许“CameraSample”使用相机?点击“允许” -2. 弹出是否允许“CameraSample”访问图片和视频?点击“允许” -3. 弹出是否允许“CameraSample”使用麦克风?点击“允许” -4. 进入预览界面,预览正常,滑动变焦按钮,同一画面远近变焦效果明显 -5. 进入预览界面,预览正常,点击画面模糊处,点击处画面会变得清晰,对焦效果明显 -6. 进入预览界面,预览正常,上下滑动屏幕,屏幕场景亮度发生变化,曝光效果明显 -7. 进入预览界面,预览正常,点击闪光灯按钮,打开闪光灯,闪光灯正常打开 -8. 进入预览界面,预览正常,点击闪光灯按钮,关闭闪光灯,闪光灯关闭 -9. 进入预览界面,预览正常,进入拍照模式,点击拍照按钮,拍照正常,左下角会生成照片缩略图,点击左下角缩略图,能够跳转到图库,图片保存正常,打开图片显示正常 -10. 进入预览界面,预览正常,切换到录像模式,点击录像,开始录像,再点击停止录像按钮,录像成功,左下角会生成视频缩略图,点击左下角缩略图,能够跳转到图库,录像文件保存正常,播放录像文件正常 -11. 进入预览界面,预览正常,切换到前置摄像头,点击拍照按钮,拍照正常,左下角会生成照片缩略图,点击左下角缩略图,能够跳转到图库,图片保存正常,打开图片显示正常 -12. 进入预览界面,预览正常,切换到前置摄像头,切换到录像模式,点击录像,开始录像,再点击停止录像按钮,录像成功,左下角会生成视频缩略图,点击左下角缩略图,能够跳转到图库,录像文件保存正常,播放录像文件正常 -13. 点击设置按钮,会弹出设置页面,仅验证UI。 - -### 工程目录 - -``` -entry/src/main -|-- cpp -| |-- CMakeLists.txt // Cmake打包配置文件,编译工程动态库脚本,依赖头文件、cpp以及相关依赖 -| |-- camera_manager.cpp // 相机基本功能接口定义cpp实现侧 -| |-- camera_manager.h // 相机基本功能接口定义头文件 -| |-- main.cpp // NAPI实现JS与C++通信的接口 -| |-- types -| `-- libentry -| |-- index.d.ts // 导入NAPI接口供JS调用 -| `-- oh-package.json5 // 接口注册配置文件 -|-- ets -| |-- Dialog -| | |-- mainDialog.ets // 打开相机APP弹出的网络权限设置 -| | `-- settingDialog.ets // 相机APP设置界面布局 -| |-- MainAbility -| | `-- MainAbility.ts // 对Ability生命周期管理 -| |-- common -| | |-- Constants.ts // 基本参数枚举:纵横比、设备类型、视频帧数 -| | |-- DisplayCalculator.ts // 计算界面宽高显示数值 -| | |-- settingItem.ets // 设置栏 -| | |-- settingPublicLayout.ets // 设置栏公共区域 -| | `-- settingRightLayout.ets // 设置栏右边区域 -| |-- entryability -| | `-- EntryAbility.ts // Ability的生命周期回调内容 -| |-- model -| | |-- DateTimeUtil.ts // 日期工具 -| | |-- Logger.ts // 日志工具 -| | `-- MediaUtils.ts // 媒体工具 -| |-- pages -| | `-- Index.ets // Ability实现的应用的入口页面,相机APP首页 -| `-- views -| |-- CountdownPage.ets // 倒计时UI页面布局 -| |-- FlashingLightPage.ets // 闪光灯UI界面布局 -| |-- SlidePage.ets // 滑动滑块UI界面布局 -| |-- dividerPage.ets // 分割线UI布局 -| |-- focusAreaPage.ets // 对焦区域设置(焦点、侧光点)、单指竖直方向拖动触发曝光补偿设置 -| |-- focusPage.ets // 变焦、对焦、曝光、刻度的图标设置、值的设置 -| `-- modeSwitchPage.ets // 相机功能模式切换,开启预览、拍照、录像 - -``` - -### 具体实现 -* 相机功能接口实现在CameraManager.cpp中,源码参考:[CameraManager.cpp](entry/src/main/cpp/camera_manager.cpp) - * 在NDKCamera构造函数里完成一个相机生命周期初始化的过程,包括调用OH_Camera_GetCameraMananger获取CameraMananger,调用OH_CameraManager_CreateCaptureSession创建CaptureSession,调用CaptureSessionRegisterCallback创建CaptureSession注册回调,调用GetSupportedCameras获取支持的camera设备,调用GetSupportedOutputCapability获取支持的camera设备能力集,调用CreatePreviewOutput创建预览输出,调用CreateCameraInput创建相机输入,调用CameraInputOpen打开相机输入,调用CameraManagerRegisterCallback创建CameraManager注册回调,最后调用SessionFlowFn开启Session。 - * 其中SessionFlowFn是一个开启预览的动作,主要流程包括:调用OH_CaptureSession_BeginConfig开始配置会话,调用OH_CaptureSession_AddInput把CameraInput加入到会话,调用OH_CaptureSession_AddPreviewOutput把previewOutput加入到会话,调用OH_CaptureSession_CommitConfig提交配置信息,调用OH_CaptureSession_Start开始会话工作,还有一步是在开启预览的同时调用IsFocusMode启动对焦功能,这边后面会涉及到。 - * 在NDKCamera析构函数里完成对相机生命周期释放的过程,调用OH_CameraManager_DeleteSupportedCameras删除支持的camera设备,调用OH_CameraManager_DeleteSupportedCameraOutputCapability删除支持的camera设备能力集,调用OH_Camera_DeleteCameraMananger删除camera manager。 - * 拍照功能相关接口封装在StartPhoto接口中,主要包含以下流程:调用SessionStop关闭session,调用SessionBegin做session的一个预置动作,调用CreatePhotoOutput创建相机输出,调用OH_CaptureSession_AddPhotoOutput将hotoOutput添加至session中,调用SessionCommitConfig提交session,在调用SessionStart开启session,最后调用TakePicture接口开启拍照动作。 - * 录像功能相关接口封装在StartVideo接口中,主要包含以下流程:调用SessionStop关闭session,调用SessionBegin做session的一个预置动作,调用OH_CaptureSession_RemovePhotoOutput移除相机拍照输出,再调用CreatePhotoOutput创建相机输出,调用AddPhotoOutput将相机输出添加至session中,调用CreateVideoOutput创建录像输出,调用AddVideoOutput将录像输出添加至session中,然后再调用SessionCommitConfig、SessionStart对session进行提交和开启,最后调用VideoOutputRegisterCallback对VideoOutput注册回调。 - * 闪光灯功能相关接口封装在HasFlashFn接口中,主要包含以下流程:调用OH_CaptureSession_HasFlash检测是否支持闪光灯设备,再调用OH_CaptureSession_IsFlashModeSupported检测闪光灯模式是否支持,然后调用OH_CaptureSession_SetFlashMode设置闪光灯模式,最后调用OH_CaptureSession_GetFlashMode获取当前设备的闪光灯模式。 - * 变焦功能相关接口封装在setZoomRatioFn接口中,主要包含以下流程:调用OH_CaptureSession_GetZoomRatioRange获取支持的变焦范围,调用OH_CaptureSession_SetZoomRatio设置变焦,调用OH_CaptureSession_GetZoomRatio获取当前设备的变焦值。 - * 曝光功能相关接口封装在IsExposureModeSupportedFn接口中,主要包含以下流程:调用OH_CaptureSession_IsExposureModeSupported判断是否支持曝光模式,然后调用OH_CaptureSession_SetExposureMode设置曝光模式,调用OH_CaptureSession_GetExposureMode获取设置后的曝光模式。调用IsExposureBiasRange接口获取曝光补偿,其中包含调用OH_CaptureSession_GetExposureBiasRange获取曝光补偿的范围,调用OH_CaptureSession_SetExposureBias设置曝光点,调用OH_CaptureSession_GetExposureBias获取曝光点。 - * 对焦功能相关接口封装在IsFocusMode接口中,主要包含以下流程:调用OH_CaptureSession_IsFocusModeSupported判断是否支持对焦模式,调用OH_CaptureSession_SetFocusMode设置对焦模式,调用OH_CaptureSession_GetFocusMode获取设置后的对焦模式。调用IsFocusPoint接口获取对焦点,其中包括调用OH_CaptureSession_SetFocusPoint获取JS侧下发来的对焦点位,然后调用OH_CaptureSession_GetFocusPoint获取设置后的对焦点位。 - * 视频防抖功能相关接口封装在IsVideoStabilizationModeSupportedFn接口中,主要包含以下流程:调用OH_CaptureSession_IsVideoStabilizationModeSupported接口查询是否支持指定的视频防抖模式,调用OH_CaptureSession_SetVideoStabilizationMode设置视频防抖,调用OH_CaptureSession_GetVideoStabilizationMode获取设置后的视频防抖模式。 - - * 回调接口设置: - * CameraManagerRegisterCallback:监听相机状态回调,在打开、退出相机,相机摄像头切换时会触发 - * CameraInputRegisterCallback:相机输入发生错误时触发回调 - * PreviewOutputRegisterCallback:开启预览流时触发回调 - * PhotoOutputRegisterCallback:开启拍照时触发回调 - * VideoOutputRegisterCallback:开启录像模式时触发回调 - * MetadataOutputRegisterCallback:有metadata流输出时触发回调 - * CaptureSessionRegisterCallback:session出现异常时以及开启对焦模式时触发回调 - - -* 相机预览、拍照、录像功能、前后置切换功能实现调用侧位于Index.ets,modeSwitchPage.ets,main.cpp中,源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets),[ModeSwitchPage.ets](entry/src/main/ets/views/ModeSwitchPage.ets),[main.cpp](entry/src/main/cpp/main.cpp) - * 预览:开启预览位于Index.ets下的onPageShow接口,其中调用cameraDemo.initCamera接口,将预览的surfaceId,对焦模式的值,以及是前置还是后置摄像头设备作为入参啊传下去,实际调用的是main.cpp下的InitCamera接口,InitCamera接口将JS侧拿到的参数进行转换再传入cameraManager.cpp中的构造函数里去,完成开启相机的操作,开启预览并设置好对焦模式。 - * 拍照和录像:开启拍照位于ModeSwitchPage.ets下的isVideoPhotoFn接口,通过判断modelBagCol的值是photo还是video,将modelBagCol的值,videoId,拍照的surfaceID或者录像的surfaceId传入接口startPhotoOrVideo。如果是拍照模式,则通过modeSwitchPage.ets下的getPhotoSurfaceID接口获取photo surfaceId,跳转到main.cpp中的StartPhotoOrVideo接口,将传下来的参数进行格式转换,再调用CameraManager对象下的StartPhoto接口开启拍照操作;如果是录像模式,则通过modeSwitchPage.ets下的getVideoSurfaceID接口获取video surfaceId,跳转到main.cpp中的StartPhotoOrVideo接口,将传下来的参数进行格式转换,再调用CameraManager对象下的StartVideo接口开启录像操作 - * 前后置切换:前后置摄像头切换接口位于ModeSwitchPage.ets,切换cameraDeviceIndex,将先前的session配置释放,调用cameraDemo.releaseSession接口,实际上是main.cpp下的ReleaseSession接口,最终调用到CameraMangaer.cpp下的ReleaseSession接口。然后将预览的surfaceId,对焦模式的值以及cameraDeviceIndex传入cameraDemo.initCamera接口中,逻辑和预览一致。 - - -* 相机闪光灯、变焦、对焦、曝光功能实现调用侧位于FlashingLightPage.ets,SlidePage.ets,focusAreaPage.ets中,源码参考:[FlashingLightPage.ets](entry/src/main/ets/views/FlashingLightPage.ets),[SlidePage.ets](entry/src/main/ets/views/SlidePage.ets),[FocusAreaPage.ets](entry/src/main/ets/views/FocusAreaPage.ets),[main.cpp](entry/src/main/cpp/main.cpp) - * 闪光灯:闪光灯功能位于FlashingLightPage.ets,getImageDefault接口用作在点击闪光灯图标之后选择闪光灯模式,0代表关闭,1代表打开,2是自动,3是常亮。然后在build中通过cameraDemo.hasFlash接口调用到main.cpp中的HasFlash接口,最终调到CameraManager.cpp中的HasFlashFn接口,完成闪光灯功能的实现。 - * 变焦:变焦功能位于SlidePage.ets,通过调用slideChange接口设置slide滑块的值,目前只支持1-6.然后调用cameraDemo.setZoomRatio接口调用到main.cpp中的SetZoomRatio接口,最终调到CameraManager.cpp中的setZoomRatioFn接口,完成变焦功能的实现。 - * 对焦:对焦功能位于FocusAreaPage.ets,通过在build中将对焦焦点下发到cpp侧,在CameraManager.cpp文件中的SessionFlowFn函数中,会调用IsFocusMode接口来判断是否支持对焦模式,然后通过onTouch的方式将对焦点位通过cameraDemo.isFocusPoint接口下发到main.cpp侧的IsFocusPoint接口,最终调到CameraManager.cpp中的IsFocusPoint接口。以及调用OH_CaptureSession_SetFocusMode拿到对焦点位来设置对焦模式,最后调用OH_CaptureSession_GetFocusMode来获取对焦模式,完成对焦功能实现。 - * 曝光:曝光功能位于FocusAreaPage.ets,通过在build中将侧光点位下发到cpp侧,然后通过onTouch的方式将对焦点位以及侧光点位通过cameraDemo.isFocusPoint接口下发到main.cpp侧的isMeteringPoint接口,最终调到CameraManager.cpp中的IsMeteringPoint接口。然后设置曝光补偿,单指竖直方向拖动触发该手势事件,调用gesture中的cameraDemo.isExposureBiasRange接口将曝光值下发到main.cpp中的IsExposureBiasRange,然后经过napi转换后将值传到CameraManager.cpp中的IsExposureBiasRange接口,之后从native侧发到曝光补偿的范围,再调用OH_CaptureSession_SetExposureBias设置曝光值,最后调用OH_CaptureSession_GetExposureBias接口获取曝光值,完成曝光功能。 - -### 相关权限 - -[ohos.permission.CAMERA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-camera-kit/js-apis-camera.md) - -[ohos.permission.MICROPHONE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmicrophone) - -[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_media) - -[ohos.permission.WRITE_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionwrite_media) - -### 依赖 - -不涉及 - -### 约束与限制 - -1. 本示例支持标准系统上运行,支持设备:RK3568; -2. 本示例为Stage模型,已适配API version 12版本SDK,SDK版本号(API Version 12 Release),镜像版本号(5.0Release); -3. 本示例需要使用DevEco Studio 版本号(5.0)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/Media/Camera > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master + +# 相机 + +### 介绍 + +本示例主要展示了相机的相关功能,使用[libohcamera.so] +当前版本sample仅用作联调,最新sdk未带相机c接口头文件。 +接口实现相机的预览、拍照、录像、前后置摄像头切换进行拍照、录像,以及闪光灯、变焦、对焦、曝光等控制类功能。 + +### 效果预览 + +| 相机权限 | 图片和视频权限 | 麦克风权限 | 预览界面 | +|----------------------------|----------------------------|----------------------------|---------------------------------| +| ![auth](app_pic/auth1.jpg) | ![auth](app_pic/auth2.jpg) | ![auth](app_pic/auth3.jpg) | ![preview](app_pic/preview.jpg) | + +使用说明 +(因RK3568设备硬件能力,现仅支持验证1、2、3、9、10、13) +1. 弹出是否允许“CameraSample”使用相机?点击“允许” +2. 弹出是否允许“CameraSample”访问图片和视频?点击“允许” +3. 弹出是否允许“CameraSample”使用麦克风?点击“允许” +4. 进入预览界面,预览正常,滑动变焦按钮,同一画面远近变焦效果明显 +5. 进入预览界面,预览正常,点击画面模糊处,点击处画面会变得清晰,对焦效果明显 +6. 进入预览界面,预览正常,上下滑动屏幕,屏幕场景亮度发生变化,曝光效果明显 +7. 进入预览界面,预览正常,点击闪光灯按钮,打开闪光灯,闪光灯正常打开 +8. 进入预览界面,预览正常,点击闪光灯按钮,关闭闪光灯,闪光灯关闭 +9. 进入预览界面,预览正常,进入拍照模式,点击拍照按钮,拍照正常,左下角会生成照片缩略图,点击左下角缩略图,能够跳转到图库,图片保存正常,打开图片显示正常 +10. 进入预览界面,预览正常,切换到录像模式,点击录像,开始录像,再点击停止录像按钮,录像成功,左下角会生成视频缩略图,点击左下角缩略图,能够跳转到图库,录像文件保存正常,播放录像文件正常 +11. 进入预览界面,预览正常,切换到前置摄像头,点击拍照按钮,拍照正常,左下角会生成照片缩略图,点击左下角缩略图,能够跳转到图库,图片保存正常,打开图片显示正常 +12. 进入预览界面,预览正常,切换到前置摄像头,切换到录像模式,点击录像,开始录像,再点击停止录像按钮,录像成功,左下角会生成视频缩略图,点击左下角缩略图,能够跳转到图库,录像文件保存正常,播放录像文件正常 +13. 点击设置按钮,会弹出设置页面,仅验证UI。 + +### 工程目录 + +``` +entry/src/main +|-- cpp +| |-- CMakeLists.txt // Cmake打包配置文件,编译工程动态库脚本,依赖头文件、cpp以及相关依赖 +| |-- camera_manager.cpp // 相机基本功能接口定义cpp实现侧 +| |-- camera_manager.h // 相机基本功能接口定义头文件 +| |-- main.cpp // NAPI实现JS与C++通信的接口 +| |-- types +| `-- libentry +| |-- index.d.ts // 导入NAPI接口供JS调用 +| `-- oh-package.json5 // 接口注册配置文件 +|-- ets +| |-- Dialog +| | |-- mainDialog.ets // 打开相机APP弹出的网络权限设置 +| | `-- settingDialog.ets // 相机APP设置界面布局 +| |-- MainAbility +| | `-- MainAbility.ts // 对Ability生命周期管理 +| |-- common +| | |-- Constants.ts // 基本参数枚举:纵横比、设备类型、视频帧数 +| | |-- DisplayCalculator.ts // 计算界面宽高显示数值 +| | |-- settingItem.ets // 设置栏 +| | |-- settingPublicLayout.ets // 设置栏公共区域 +| | `-- settingRightLayout.ets // 设置栏右边区域 +| |-- entryability +| | `-- EntryAbility.ts // Ability的生命周期回调内容 +| |-- model +| | |-- DateTimeUtil.ts // 日期工具 +| | |-- Logger.ts // 日志工具 +| | `-- MediaUtils.ts // 媒体工具 +| |-- pages +| | `-- Index.ets // Ability实现的应用的入口页面,相机APP首页 +| `-- views +| |-- CountdownPage.ets // 倒计时UI页面布局 +| |-- FlashingLightPage.ets // 闪光灯UI界面布局 +| |-- SlidePage.ets // 滑动滑块UI界面布局 +| |-- dividerPage.ets // 分割线UI布局 +| |-- focusAreaPage.ets // 对焦区域设置(焦点、侧光点)、单指竖直方向拖动触发曝光补偿设置 +| |-- focusPage.ets // 变焦、对焦、曝光、刻度的图标设置、值的设置 +| `-- modeSwitchPage.ets // 相机功能模式切换,开启预览、拍照、录像 + +``` + +### 具体实现 +* 相机功能接口实现在CameraManager.cpp中,源码参考:[CameraManager.cpp](entry/src/main/cpp/camera_manager.cpp) + * 在NDKCamera构造函数里完成一个相机生命周期初始化的过程,包括调用OH_Camera_GetCameraMananger获取CameraMananger,调用OH_CameraManager_CreateCaptureSession创建CaptureSession,调用CaptureSessionRegisterCallback创建CaptureSession注册回调,调用GetSupportedCameras获取支持的camera设备,调用GetSupportedOutputCapability获取支持的camera设备能力集,调用CreatePreviewOutput创建预览输出,调用CreateCameraInput创建相机输入,调用CameraInputOpen打开相机输入,调用CameraManagerRegisterCallback创建CameraManager注册回调,最后调用SessionFlowFn开启Session。 + * 其中SessionFlowFn是一个开启预览的动作,主要流程包括:调用OH_CaptureSession_BeginConfig开始配置会话,调用OH_CaptureSession_AddInput把CameraInput加入到会话,调用OH_CaptureSession_AddPreviewOutput把previewOutput加入到会话,调用OH_CaptureSession_CommitConfig提交配置信息,调用OH_CaptureSession_Start开始会话工作,还有一步是在开启预览的同时调用IsFocusMode启动对焦功能,这边后面会涉及到。 + * 在NDKCamera析构函数里完成对相机生命周期释放的过程,调用OH_CameraManager_DeleteSupportedCameras删除支持的camera设备,调用OH_CameraManager_DeleteSupportedCameraOutputCapability删除支持的camera设备能力集,调用OH_Camera_DeleteCameraMananger删除camera manager。 + * 拍照功能相关接口封装在StartPhoto接口中,主要包含以下流程:调用SessionStop关闭session,调用SessionBegin做session的一个预置动作,调用CreatePhotoOutput创建相机输出,调用OH_CaptureSession_AddPhotoOutput将hotoOutput添加至session中,调用SessionCommitConfig提交session,在调用SessionStart开启session,最后调用TakePicture接口开启拍照动作。 + * 录像功能相关接口封装在StartVideo接口中,主要包含以下流程:调用SessionStop关闭session,调用SessionBegin做session的一个预置动作,调用OH_CaptureSession_RemovePhotoOutput移除相机拍照输出,再调用CreatePhotoOutput创建相机输出,调用AddPhotoOutput将相机输出添加至session中,调用CreateVideoOutput创建录像输出,调用AddVideoOutput将录像输出添加至session中,然后再调用SessionCommitConfig、SessionStart对session进行提交和开启,最后调用VideoOutputRegisterCallback对VideoOutput注册回调。 + * 闪光灯功能相关接口封装在HasFlashFn接口中,主要包含以下流程:调用OH_CaptureSession_HasFlash检测是否支持闪光灯设备,再调用OH_CaptureSession_IsFlashModeSupported检测闪光灯模式是否支持,然后调用OH_CaptureSession_SetFlashMode设置闪光灯模式,最后调用OH_CaptureSession_GetFlashMode获取当前设备的闪光灯模式。 + * 变焦功能相关接口封装在setZoomRatioFn接口中,主要包含以下流程:调用OH_CaptureSession_GetZoomRatioRange获取支持的变焦范围,调用OH_CaptureSession_SetZoomRatio设置变焦,调用OH_CaptureSession_GetZoomRatio获取当前设备的变焦值。 + * 曝光功能相关接口封装在IsExposureModeSupportedFn接口中,主要包含以下流程:调用OH_CaptureSession_IsExposureModeSupported判断是否支持曝光模式,然后调用OH_CaptureSession_SetExposureMode设置曝光模式,调用OH_CaptureSession_GetExposureMode获取设置后的曝光模式。调用IsExposureBiasRange接口获取曝光补偿,其中包含调用OH_CaptureSession_GetExposureBiasRange获取曝光补偿的范围,调用OH_CaptureSession_SetExposureBias设置曝光点,调用OH_CaptureSession_GetExposureBias获取曝光点。 + * 对焦功能相关接口封装在IsFocusMode接口中,主要包含以下流程:调用OH_CaptureSession_IsFocusModeSupported判断是否支持对焦模式,调用OH_CaptureSession_SetFocusMode设置对焦模式,调用OH_CaptureSession_GetFocusMode获取设置后的对焦模式。调用IsFocusPoint接口获取对焦点,其中包括调用OH_CaptureSession_SetFocusPoint获取JS侧下发来的对焦点位,然后调用OH_CaptureSession_GetFocusPoint获取设置后的对焦点位。 + * 视频防抖功能相关接口封装在IsVideoStabilizationModeSupportedFn接口中,主要包含以下流程:调用OH_CaptureSession_IsVideoStabilizationModeSupported接口查询是否支持指定的视频防抖模式,调用OH_CaptureSession_SetVideoStabilizationMode设置视频防抖,调用OH_CaptureSession_GetVideoStabilizationMode获取设置后的视频防抖模式。 + + * 回调接口设置: + * CameraManagerRegisterCallback:监听相机状态回调,在打开、退出相机,相机摄像头切换时会触发 + * CameraInputRegisterCallback:相机输入发生错误时触发回调 + * PreviewOutputRegisterCallback:开启预览流时触发回调 + * PhotoOutputRegisterCallback:开启拍照时触发回调 + * VideoOutputRegisterCallback:开启录像模式时触发回调 + * MetadataOutputRegisterCallback:有metadata流输出时触发回调 + * CaptureSessionRegisterCallback:session出现异常时以及开启对焦模式时触发回调 + + +* 相机预览、拍照、录像功能、前后置切换功能实现调用侧位于Index.ets,modeSwitchPage.ets,main.cpp中,源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets),[ModeSwitchPage.ets](entry/src/main/ets/views/ModeSwitchPage.ets),[main.cpp](entry/src/main/cpp/main.cpp) + * 预览:开启预览位于Index.ets下的onPageShow接口,其中调用cameraDemo.initCamera接口,将预览的surfaceId,对焦模式的值,以及是前置还是后置摄像头设备作为入参啊传下去,实际调用的是main.cpp下的InitCamera接口,InitCamera接口将JS侧拿到的参数进行转换再传入cameraManager.cpp中的构造函数里去,完成开启相机的操作,开启预览并设置好对焦模式。 + * 拍照和录像:开启拍照位于ModeSwitchPage.ets下的isVideoPhotoFn接口,通过判断modelBagCol的值是photo还是video,将modelBagCol的值,videoId,拍照的surfaceID或者录像的surfaceId传入接口startPhotoOrVideo。如果是拍照模式,则通过modeSwitchPage.ets下的getPhotoSurfaceID接口获取photo surfaceId,跳转到main.cpp中的StartPhotoOrVideo接口,将传下来的参数进行格式转换,再调用CameraManager对象下的StartPhoto接口开启拍照操作;如果是录像模式,则通过modeSwitchPage.ets下的getVideoSurfaceID接口获取video surfaceId,跳转到main.cpp中的StartPhotoOrVideo接口,将传下来的参数进行格式转换,再调用CameraManager对象下的StartVideo接口开启录像操作 + * 前后置切换:前后置摄像头切换接口位于ModeSwitchPage.ets,切换cameraDeviceIndex,将先前的session配置释放,调用cameraDemo.releaseSession接口,实际上是main.cpp下的ReleaseSession接口,最终调用到CameraMangaer.cpp下的ReleaseSession接口。然后将预览的surfaceId,对焦模式的值以及cameraDeviceIndex传入cameraDemo.initCamera接口中,逻辑和预览一致。 + + +* 相机闪光灯、变焦、对焦、曝光功能实现调用侧位于FlashingLightPage.ets,SlidePage.ets,focusAreaPage.ets中,源码参考:[FlashingLightPage.ets](entry/src/main/ets/views/FlashingLightPage.ets),[SlidePage.ets](entry/src/main/ets/views/SlidePage.ets),[FocusAreaPage.ets](entry/src/main/ets/views/FocusAreaPage.ets),[main.cpp](entry/src/main/cpp/main.cpp) + * 闪光灯:闪光灯功能位于FlashingLightPage.ets,getImageDefault接口用作在点击闪光灯图标之后选择闪光灯模式,0代表关闭,1代表打开,2是自动,3是常亮。然后在build中通过cameraDemo.hasFlash接口调用到main.cpp中的HasFlash接口,最终调到CameraManager.cpp中的HasFlashFn接口,完成闪光灯功能的实现。 + * 变焦:变焦功能位于SlidePage.ets,通过调用slideChange接口设置slide滑块的值,目前只支持1-6.然后调用cameraDemo.setZoomRatio接口调用到main.cpp中的SetZoomRatio接口,最终调到CameraManager.cpp中的setZoomRatioFn接口,完成变焦功能的实现。 + * 对焦:对焦功能位于FocusAreaPage.ets,通过在build中将对焦焦点下发到cpp侧,在CameraManager.cpp文件中的SessionFlowFn函数中,会调用IsFocusMode接口来判断是否支持对焦模式,然后通过onTouch的方式将对焦点位通过cameraDemo.isFocusPoint接口下发到main.cpp侧的IsFocusPoint接口,最终调到CameraManager.cpp中的IsFocusPoint接口。以及调用OH_CaptureSession_SetFocusMode拿到对焦点位来设置对焦模式,最后调用OH_CaptureSession_GetFocusMode来获取对焦模式,完成对焦功能实现。 + * 曝光:曝光功能位于FocusAreaPage.ets,通过在build中将侧光点位下发到cpp侧,然后通过onTouch的方式将对焦点位以及侧光点位通过cameraDemo.isFocusPoint接口下发到main.cpp侧的isMeteringPoint接口,最终调到CameraManager.cpp中的IsMeteringPoint接口。然后设置曝光补偿,单指竖直方向拖动触发该手势事件,调用gesture中的cameraDemo.isExposureBiasRange接口将曝光值下发到main.cpp中的IsExposureBiasRange,然后经过napi转换后将值传到CameraManager.cpp中的IsExposureBiasRange接口,之后从native侧发到曝光补偿的范围,再调用OH_CaptureSession_SetExposureBias设置曝光值,最后调用OH_CaptureSession_GetExposureBias接口获取曝光值,完成曝光功能。 + +### 相关权限 + +[ohos.permission.CAMERA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-camera-kit/js-apis-camera.md) + +[ohos.permission.MICROPHONE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmicrophone) + +[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_media) + +[ohos.permission.WRITE_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionwrite_media) + +### 依赖 + +不涉及 + +### 约束与限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; +2. 本示例为Stage模型,已适配API version 12版本SDK,SDK版本号(API Version 12 Release),镜像版本号(5.0Release); +3. 本示例需要使用DevEco Studio 版本号(5.0)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/Media/Camera > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/BasicFeature/Media/Camera/entry/oh-package.json5 b/code/BasicFeature/Media/Camera/entry/oh-package.json5 index 27af2fbb686712167569abf90d14e39d02ce08de..2ceaf0b016afc0af67d8fd6a4774a7bf88404445 100644 --- a/code/BasicFeature/Media/Camera/entry/oh-package.json5 +++ b/code/BasicFeature/Media/Camera/entry/oh-package.json5 @@ -1,11 +1,11 @@ -{ - "license": "ISC", - "devDependencies": { - "@types/libentry.so": "file:./src/main/cpp/types/libentry" - }, - "name": "entry", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "ISC", + "devDependencies": { + "@types/libentry.so": "file:./src/main/cpp/types/libentry" + }, + "name": "entry", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Media/Camera/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Media/Camera/entry/src/main/cpp/types/libentry/oh-package.json5 index 35079f7a3f02bb4ee4ea1035367982286880e78b..9c6929b0b231dd038b2c1c515f49d3bcca48f154 100644 --- a/code/BasicFeature/Media/Camera/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/Media/Camera/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,6 +1,6 @@ -{ - "types": "./index.d.ts", - "name": "libentry.so", - "description": "", - "version": "" +{ + "types": "./index.d.ts", + "name": "libentry.so", + "description": "", + "version": "" } \ No newline at end of file diff --git a/code/BasicFeature/Media/Camera/entry/src/ohosTest/ets/test/Logger.ts b/code/BasicFeature/Media/Camera/entry/src/ohosTest/ets/test/Logger.ts index 27b576b2c72f302156824abffcd1f1f01d972422..2837750d0ee81fa2d080cefd7f99fbf046b4ba4e 100644 --- a/code/BasicFeature/Media/Camera/entry/src/ohosTest/ets/test/Logger.ts +++ b/code/BasicFeature/Media/Camera/entry/src/ohosTest/ets/test/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -const DOMAIN: number = 0xF811; - -class Logger { - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - } - - debug(...args: string[]): void { - hilog.debug(DOMAIN, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(DOMAIN, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(DOMAIN, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(DOMAIN, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +const DOMAIN: number = 0xF811; + +class Logger { + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(DOMAIN, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(DOMAIN, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(DOMAIN, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(DOMAIN, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_Camera]'); \ No newline at end of file diff --git a/code/BasicFeature/Media/Camera/hvigor/hvigor-config.json5 b/code/BasicFeature/Media/Camera/hvigor/hvigor-config.json5 index 78fdbce3b0d7c3b4b372aee3eede6c200d229e1f..cef1321d4c0a417219c7c64a9f6c1101b850b89d 100644 --- a/code/BasicFeature/Media/Camera/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Media/Camera/hvigor/hvigor-config.json5 @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2024 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": { - } +/* + * Copyright (c) 2024 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": { + } } \ No newline at end of file diff --git a/code/BasicFeature/Media/Camera/oh-package.json5 b/code/BasicFeature/Media/Camera/oh-package.json5 index 81fb75240cf8c9e1c3d65859a08ffc7f96d22b7b..d083bc9bd876153fb9aca9b0f99893594be03143 100644 --- a/code/BasicFeature/Media/Camera/oh-package.json5 +++ b/code/BasicFeature/Media/Camera/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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", - "license": "ISC", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "name": "camerasample", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} +/* + * Copyright (c) 2024 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", + "license": "ISC", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "name": "camerasample", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/BasicFeature/Media/VideoPlay/entry/src/main/resources/rawfile/test1.srt b/code/BasicFeature/Media/VideoPlay/entry/src/main/resources/rawfile/test1.srt index e7f5575c788e6ae3577e912f06cfa75f8f5ad23c..4c4c12f32fedf9c4f1209116947d4aa6f3addf0c 100644 --- a/code/BasicFeature/Media/VideoPlay/entry/src/main/resources/rawfile/test1.srt +++ b/code/BasicFeature/Media/VideoPlay/entry/src/main/resources/rawfile/test1.srt @@ -1,123 +1,123 @@ -1 -00:00:00,470 --> 00:00:07,480 -(在空心地球的某处) - -2 -00:00:09,460 --> 00:00:12,670 -在大部分人类文明中 - -3 -00:00:13,840 --> 00:00:15,550 -我们都认为人类是地球上的优势物种 - -4 -00:00:15,920 --> 00:00:16,890 -更相信生命只能存在于地球表面 - -5 -00:00:16,890 --> 00:00:18,970 -但在某个时刻,大家一定会想 - -6 -00:00:19,140 --> 00:00:20,220 -(君主计划金刚研究负责人 艾琳安德鲁博士) - -7 -00:00:21,310 --> 00:00:23,140 -我们的认知还有哪些错误? - -8 -00:00:20,400 --> 00:00:24,690 -我们目前只探勘了空心地球 不到百分之五的区域 - -9 -00:00:25,280 --> 00:00:30,160 -但地表上下 生态系统的关系紧密超乎想像 - -10 -00:00:30,910 --> 00:00:34,160 -这不是两个不同世界,而是一体的 - -11 -00:00:34,330 --> 00:00:35,580 -(发现空心地球新入口) - -12 -00:00:37,540 --> 00:00:39,130 -金刚已在空心地球定居 - -13 -00:00:39,210 --> 00:00:39,960 -(金刚移居新栖地) - -14 -00:00:40,040 --> 00:00:42,210 -所以,这位大家伙喜欢它的新家 - -15 -00:00:42,500 --> 00:00:43,550 -应该没错 - -16 -00:00:44,010 --> 00:00:45,970 -它是高度社会化的物种 - -17 -00:00:46,550 --> 00:00:49,680 -金刚如此孤单并不正常 - -18 -00:00:52,470 --> 00:00:54,020 -它是同类中的最后一只 - -19 -00:00:54,180 --> 00:00:57,690 -它每天都在寻找永远找不到的家人 - -20 -00:00:59,730 --> 00:01:00,900 -那哥斯拉呢? - -21 -00:01:00,980 --> 00:01:01,650 -(哥斯拉领地) - -22 -00:01:01,730 --> 00:01:03,690 -哥斯拉在地表,金刚在地心 - -23 -00:01:03,780 --> 00:01:04,320 -(金刚领地) - -24 -00:01:04,400 --> 00:01:06,700 -只要它们不冒险进入对方领地 - -25 -00:01:06,820 --> 00:01:08,410 -就没什么好担心的 - -26 -00:01:08,910 --> 00:01:11,780 -我们很幸运有哥斯拉扞卫人类世界 - -27 -00:01:11,950 --> 00:01:12,780 -(罗马,泰坦24号) - -28 -00:01:17,870 --> 00:01:20,330 -(意大利,罗马) - -29 -00:01:22,860 --> 00:01:25,570 -部分论点批评君主计划 花费纳税人数十亿美元 - -30 -00:01:26,780 --> 00:01:28,120 -(君主一号基地,金刚观测站) - -31 -00:01:29,180 --> 00:01:49,120 +1 +00:00:00,470 --> 00:00:07,480 +(在空心地球的某处) + +2 +00:00:09,460 --> 00:00:12,670 +在大部分人类文明中 + +3 +00:00:13,840 --> 00:00:15,550 +我们都认为人类是地球上的优势物种 + +4 +00:00:15,920 --> 00:00:16,890 +更相信生命只能存在于地球表面 + +5 +00:00:16,890 --> 00:00:18,970 +但在某个时刻,大家一定会想 + +6 +00:00:19,140 --> 00:00:20,220 +(君主计划金刚研究负责人 艾琳安德鲁博士) + +7 +00:00:21,310 --> 00:00:23,140 +我们的认知还有哪些错误? + +8 +00:00:20,400 --> 00:00:24,690 +我们目前只探勘了空心地球 不到百分之五的区域 + +9 +00:00:25,280 --> 00:00:30,160 +但地表上下 生态系统的关系紧密超乎想像 + +10 +00:00:30,910 --> 00:00:34,160 +这不是两个不同世界,而是一体的 + +11 +00:00:34,330 --> 00:00:35,580 +(发现空心地球新入口) + +12 +00:00:37,540 --> 00:00:39,130 +金刚已在空心地球定居 + +13 +00:00:39,210 --> 00:00:39,960 +(金刚移居新栖地) + +14 +00:00:40,040 --> 00:00:42,210 +所以,这位大家伙喜欢它的新家 + +15 +00:00:42,500 --> 00:00:43,550 +应该没错 + +16 +00:00:44,010 --> 00:00:45,970 +它是高度社会化的物种 + +17 +00:00:46,550 --> 00:00:49,680 +金刚如此孤单并不正常 + +18 +00:00:52,470 --> 00:00:54,020 +它是同类中的最后一只 + +19 +00:00:54,180 --> 00:00:57,690 +它每天都在寻找永远找不到的家人 + +20 +00:00:59,730 --> 00:01:00,900 +那哥斯拉呢? + +21 +00:01:00,980 --> 00:01:01,650 +(哥斯拉领地) + +22 +00:01:01,730 --> 00:01:03,690 +哥斯拉在地表,金刚在地心 + +23 +00:01:03,780 --> 00:01:04,320 +(金刚领地) + +24 +00:01:04,400 --> 00:01:06,700 +只要它们不冒险进入对方领地 + +25 +00:01:06,820 --> 00:01:08,410 +就没什么好担心的 + +26 +00:01:08,910 --> 00:01:11,780 +我们很幸运有哥斯拉扞卫人类世界 + +27 +00:01:11,950 --> 00:01:12,780 +(罗马,泰坦24号) + +28 +00:01:17,870 --> 00:01:20,330 +(意大利,罗马) + +29 +00:01:22,860 --> 00:01:25,570 +部分论点批评君主计划 花费纳税人数十亿美元 + +30 +00:01:26,780 --> 00:01:28,120 +(君主一号基地,金刚观测站) + +31 +00:01:29,180 --> 00:01:49,120 结束 \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/AppScope/app.json5 b/code/BasicFeature/Native/NdkNativeImage/AppScope/app.json5 index e99fd41e564146a96fc828317ca1bdc4824aa739..9e311fe1d8f277c8b5e0136881ef5b9b8989427a 100644 --- a/code/BasicFeature/Native/NdkNativeImage/AppScope/app.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.ndknativeimage", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.ndknativeimage", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/NdkNativeImage/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/NdkNativeImage/AppScope/resources/base/element/string.json index 0165b1d0bc896dd230547bdabe050612680e0ccd..017dab4f47f43e939f224bcea9c4892b8321735c 100644 --- a/code/BasicFeature/Native/NdkNativeImage/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Native/NdkNativeImage/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NdkNativeImage" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NdkNativeImage" + } + ] +} diff --git a/code/BasicFeature/Native/NdkNativeImage/build-profile.json5 b/code/BasicFeature/Native/NdkNativeImage/build-profile.json5 index c764cdfce8a17e87989f658c9caa3e64d63299f3..60c9bfd9fb98b84d3178f79ce6c2c89607c5b824 100644 --- a/code/BasicFeature/Native/NdkNativeImage/build-profile.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/build-profile.json5 @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2024 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": 12, - // 指定OpenHarmony应用/服务编译时的版本 - "compatibleSdkVersion": 12, - // 指定OpenHarmony应用/服务兼容的最低版本。 - "targetSdkVersion": 12, - // 指定OpenHarmony应用/服务目标版本。若没有设置,默认为compatibleSdkVersion - "runtimeOS": "OpenHarmony", - // 指定为OpenHarmony - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": 12, + // 指定OpenHarmony应用/服务编译时的版本 + "compatibleSdkVersion": 12, + // 指定OpenHarmony应用/服务兼容的最低版本。 + "targetSdkVersion": 12, + // 指定OpenHarmony应用/服务目标版本。若没有设置,默认为compatibleSdkVersion + "runtimeOS": "OpenHarmony", + // 指定为OpenHarmony + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/build-profile.json5 b/code/BasicFeature/Native/NdkNativeImage/entry/build-profile.json5 index 34df5bd5bfa6776f05660adc1a2d94d698677e67..cf2a53fd98273c6fa793ec8c6c2cdc74ddfbb8a0 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/build-profile.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/entry/build-profile.json5 @@ -1,35 +1,35 @@ -/* - * Copyright (c) 2024 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", - } - ] +/* + * Copyright (c) 2024 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", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/oh-package.json5 b/code/BasicFeature/Native/NdkNativeImage/entry/oh-package.json5 index 08d95ed1865b27caa55de7e82bfe9d08bb7340a7..a2e022f5487848bc99e592cd0f2d778260fcf046 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/entry/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2024 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" - } +/* + * Copyright (c) 2024 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/NdkNativeImage/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/CMakeLists.txt index 54bf859f347dddd92f272cb74e1b6fae0f810b92..1164df16f9c998904f9ec4076caa14ccf011d044 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/CMakeLists.txt @@ -1,37 +1,37 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NdkNativeImage) - -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 - render/image_render.cpp - render/native_render.cpp - render/render_engine.cpp -) - -target_link_libraries(entry PUBLIC - libace_napi.z.so - libace_ndk.z.so - libnative_buffer.so - libhilog_ndk.z.so - librawfile.z.so - libnative_vsync.so - ${native-drawing-lib} - ${native-window-lib} - ${hilog-lib} - ${libace-lib} - ${libnapi-lib} - libEGL.so - libGLESv3.so - libnative_image.so - libnative_window.so - libnative_buffer.so +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NdkNativeImage) + +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 + render/image_render.cpp + render/native_render.cpp + render/render_engine.cpp +) + +target_link_libraries(entry PUBLIC + libace_napi.z.so + libace_ndk.z.so + libnative_buffer.so + libhilog_ndk.z.so + librawfile.z.so + libnative_vsync.so + ${native-drawing-lib} + ${native-window-lib} + ${hilog-lib} + ${libace-lib} + ${libnapi-lib} + libEGL.so + libGLESv3.so + libnative_image.so + libnative_window.so + libnative_buffer.so ) \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/napi_init.cpp b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/napi_init.cpp index b3a0883e62cf13d504035b53b7db9106fe6afe25..56cd9650b94798d8f6ed4f904becccb3a25d29d1 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/napi_init.cpp +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/napi_init.cpp @@ -1,136 +1,136 @@ -/* - * Copyright (c) 2024 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 -#include -#include "napi/native_api.h" -#include -#include -#include "common/common.h" -#include "render/image_render.h" -#include "render/render_engine.h" - -OH_NativeXComponent_Callback renderCallback_; -OH_NativeXComponent *g_nativeXComponent; -std::unique_ptr g_renderEngine = nullptr; -void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "OnSurfaceCreatedCB"); - if ((component == nullptr) || (window == nullptr)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", - "OnSurfaceCreatedCB: component or window is null"); - return; - } - - uint64_t width; - uint64_t height; - int32_t xSize = OH_NativeXComponent_GetXComponentSize(component, window, &width, &height); - if (xSize != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", - "OnSurfaceCreatedCB: Unable to get XComponent size"); - return; - } - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", - "OnSurfaceCreatedCB: width = %{public}llu, height = %{public}llu", width, height); - - // 创建 ImageRender 实例 - std::shared_ptr imageRender = std::make_shared(); - - // 初始化 RenderEngine - g_renderEngine = std::make_unique(imageRender, width, height, window); - g_renderEngine->OnAppResume(); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "RenderEngine started"); -} - -void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "OnSurfaceChangedCB"); - if ((component == nullptr) || (window == nullptr)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", - "OnSurfaceChangedCB: component or window is null"); - return; - } - - uint64_t width; - uint64_t height; - int32_t xSize = OH_NativeXComponent_GetXComponentSize(component, window, &width, &height); - if (xSize != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", - "OnSurfaceChangedCB: Unable to get XComponent size"); - return; - } - - if (g_renderEngine) { - g_renderEngine->OnSurfaceChanged(width, height); - } -} - -void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "OnSurfaceDestroyedCB"); - if (g_renderEngine) { - g_renderEngine->OnAppPause(); - } -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "napi_init", "init start"); - napi_property_descriptor desc[] = {}; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - napi_value exportInstance = nullptr; - if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "napi_init", "Export: napi_get_named_property fail"); - return nullptr; - } - - OH_NativeXComponent *nativeXComponent = nullptr; - if (napi_unwrap(env, exportInstance, reinterpret_cast(&nativeXComponent)) != napi_ok) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "napi_init", "Export: napi_unwrap fail"); - return nullptr; - } - g_nativeXComponent = nativeXComponent; - char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {'\0'}; - uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1; - if (OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize) != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "napi_init", - "Export: OH_NativeXComponent_GetXComponentId fail"); - return nullptr; - } - - renderCallback_.OnSurfaceCreated = OnSurfaceCreatedCB; - renderCallback_.OnSurfaceChanged = OnSurfaceChangedCB; - renderCallback_.OnSurfaceDestroyed = OnSurfaceDestroyedCB; - OH_NativeXComponent_RegisterCallback(nativeXComponent, &renderCallback_); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "napi_init", "init end"); - 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); -} +/* + * Copyright (c) 2024 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 +#include +#include "napi/native_api.h" +#include +#include +#include "common/common.h" +#include "render/image_render.h" +#include "render/render_engine.h" + +OH_NativeXComponent_Callback renderCallback_; +OH_NativeXComponent *g_nativeXComponent; +std::unique_ptr g_renderEngine = nullptr; +void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "OnSurfaceCreatedCB"); + if ((component == nullptr) || (window == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", + "OnSurfaceCreatedCB: component or window is null"); + return; + } + + uint64_t width; + uint64_t height; + int32_t xSize = OH_NativeXComponent_GetXComponentSize(component, window, &width, &height); + if (xSize != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", + "OnSurfaceCreatedCB: Unable to get XComponent size"); + return; + } + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", + "OnSurfaceCreatedCB: width = %{public}llu, height = %{public}llu", width, height); + + // 创建 ImageRender 实例 + std::shared_ptr imageRender = std::make_shared(); + + // 初始化 RenderEngine + g_renderEngine = std::make_unique(imageRender, width, height, window); + g_renderEngine->OnAppResume(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "RenderEngine started"); +} + +void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "OnSurfaceChangedCB"); + if ((component == nullptr) || (window == nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", + "OnSurfaceChangedCB: component or window is null"); + return; + } + + uint64_t width; + uint64_t height; + int32_t xSize = OH_NativeXComponent_GetXComponentSize(component, window, &width, &height); + if (xSize != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "Callback", + "OnSurfaceChangedCB: Unable to get XComponent size"); + return; + } + + if (g_renderEngine) { + g_renderEngine->OnSurfaceChanged(width, height); + } +} + +void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Callback", "OnSurfaceDestroyedCB"); + if (g_renderEngine) { + g_renderEngine->OnAppPause(); + } +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "napi_init", "init start"); + napi_property_descriptor desc[] = {}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + napi_value exportInstance = nullptr; + if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "napi_init", "Export: napi_get_named_property fail"); + return nullptr; + } + + OH_NativeXComponent *nativeXComponent = nullptr; + if (napi_unwrap(env, exportInstance, reinterpret_cast(&nativeXComponent)) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "napi_init", "Export: napi_unwrap fail"); + return nullptr; + } + g_nativeXComponent = nativeXComponent; + char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {'\0'}; + uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1; + if (OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize) != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "napi_init", + "Export: OH_NativeXComponent_GetXComponentId fail"); + return nullptr; + } + + renderCallback_.OnSurfaceCreated = OnSurfaceCreatedCB; + renderCallback_.OnSurfaceChanged = OnSurfaceChangedCB; + renderCallback_.OnSurfaceDestroyed = OnSurfaceDestroyedCB; + OH_NativeXComponent_RegisterCallback(nativeXComponent, &renderCallback_); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "napi_init", "init end"); + 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/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.cpp b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.cpp index 5e736a5c5d625fb995f02447a28021d4fced813e..c73828fb10514078651daad67e71d8f9e840672e 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.cpp +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.cpp @@ -1,368 +1,368 @@ -/* - * Copyright (c) 2024 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 "image_render.h" -#include "common/common.h" -#include -#include -#include -#include -#include -#include - -namespace { - constexpr int MATRIX_SIZE = 16; - constexpr int MATRIX_DIAGONAL_STEP = 5; - constexpr float IDENTITY_DIAGONAL = 1.0f; - constexpr float IDENTITY_OTHER = 0.0f; - constexpr uint32_t NUM_VERTICES = 4; - constexpr uint32_t POSITION_COMPONENT_COUNT = 3; - constexpr uint32_t TEX_COORD_COMPONENT_COUNT = 2; - constexpr uint32_t STRIDE = (POSITION_COMPONENT_COUNT + TEX_COORD_COMPONENT_COUNT) * sizeof(GLfloat); - const char* g_vertexShaderSource = R"( - attribute vec4 aPosition; - attribute vec2 aTexCoord; - varying vec2 vTexCoord; - uniform mat4 uTransformMatrix; - void main() { - gl_Position = aPosition; - vTexCoord = (uTransformMatrix * vec4(aTexCoord, 0.0, 1.0)).xy; - } - )"; - - const char* g_fragmentShaderSource = R"( - #extension GL_OES_EGL_image_external : require - precision mediump float; - uniform samplerExternalOES uTexture; - varying vec2 vTexCoord; - void main() { - gl_FragColor = texture2D(uTexture, vTexCoord); - } - )"; -} - -ImageRender::ImageRender() -{ - // Initialize transformMatrix_ as an identity matrix - for (int i = 0; i < MATRIX_SIZE; ++i) { - transformMatrix_[i] = (i % MATRIX_DIAGONAL_STEP == 0) ? IDENTITY_DIAGONAL : IDENTITY_OTHER; - } -} - -ImageRender::~ImageRender() -{ - Cleanup(); -} - -bool ImageRender::InitEGL(EGLNativeWindowType window, uint64_t width, uint64_t height) -{ - window_ = window; - width_ = width; - height_ = height; - - if (!InitializeEGLDisplay() || !ChooseEGLConfig() || !CreateEGLContext() || !CreateEGLSurface()) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to initialize EGL"); - return false; - } - - if (!MakeCurrentContext()) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to make EGL context current"); - return false; - } - - if (!CompileAndLinkShaders()) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to compile and link shaders"); - return false; - } - - UpdateViewport(); - - return true; -} - -void ImageRender::UpdateWindowInfo(uint64_t width, uint64_t height) -{ - width_ = width; - height_ = height; -} - -bool ImageRender::InitializeEGLDisplay() -{ - display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (display_ == EGL_NO_DISPLAY) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to get EGL display"); - return false; - } - - if (!eglInitialize(display_, nullptr, nullptr)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to initialize EGL"); - return false; - } - - return true; -} - -bool ImageRender::ChooseEGLConfig() -{ - const EGLint attribs[] = { - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_NONE - }; - - EGLint numConfigs; - if (!eglChooseConfig(display_, attribs, &config_, 1, &numConfigs) || numConfigs == 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to choose EGL config"); - return false; - } - return true; -} - -bool ImageRender::CreateEGLContext() -{ - const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; - context_ = eglCreateContext(display_, config_, EGL_NO_CONTEXT, contextAttribs); - if (context_ == EGL_NO_CONTEXT) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to create EGL context"); - return false; - } - return true; -} - -bool ImageRender::CreateEGLSurface() -{ - surface_ = eglCreateWindowSurface(display_, config_, window_, nullptr); - if (surface_ == EGL_NO_SURFACE) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to create EGL surface"); - return false; - } - return true; -} - -bool ImageRender::MakeCurrentContext() -{ - if (!eglMakeCurrent(display_, surface_, surface_, context_)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to make EGL context current"); - return false; - } - return true; -} - -void ImageRender::UpdateViewport() -{ - glViewport(0, 0, static_cast(width_), static_cast(height_)); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ImageRender", - "Viewport updated to %{public}llu x %{public}llu", width_, height_); -} - -bool ImageRender::CompileAndLinkShaders() -{ - GLuint vertexShader = CompileShader(GL_VERTEX_SHADER, g_vertexShaderSource); - if (vertexShader == 0) { - return false; - } - - GLuint fragmentShader = CompileShader(GL_FRAGMENT_SHADER, g_fragmentShaderSource); - if (fragmentShader == 0) { - glDeleteShader(vertexShader); - return false; - } - - shaderProgram_ = glCreateProgram(); - glAttachShader(shaderProgram_, vertexShader); - glAttachShader(shaderProgram_, fragmentShader); - glLinkProgram(shaderProgram_); - - GLint linked; - glGetProgramiv(shaderProgram_, GL_LINK_STATUS, &linked); - if (!linked) { - PrintProgramLinkError(shaderProgram_); - glDeleteProgram(shaderProgram_); - glDeleteShader(vertexShader); - glDeleteShader(fragmentShader); - return false; - } - - glUseProgram(shaderProgram_); - - positionAttrib_ = glGetAttribLocation(shaderProgram_, "aPosition"); - texCoordAttrib_ = glGetAttribLocation(shaderProgram_, "aTexCoord"); - textureUniform_ = glGetUniformLocation(shaderProgram_, "uTexture"); - - glDeleteShader(vertexShader); - glDeleteShader(fragmentShader); - - return true; -} - -void ImageRender::PrintProgramLinkError(GLuint program) -{ - GLint infoLen = 0; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen); - if (infoLen > 1) { - std::unique_ptr infoLog = std::make_unique(infoLen); - glGetProgramInfoLog(program, infoLen, nullptr, infoLog.get()); - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, - "ImageRender", "Error linking program: %{public}s", infoLog.get()); - } -} - -void ImageRender::SetTransformMatrix(const float matrix[MATRIX_SIZE]) -{ - std::copy(matrix, matrix + MATRIX_SIZE, transformMatrix_); -} - -void ImageRender::SetTexture(GLuint textureId, GLuint textureTarget) -{ - textureId_ = textureId; - textureTarget_ = textureTarget; -} - -void ImageRender::SetupVertexAttributes() -{ - static const GLfloat vertices[] = { - -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // 左下 - 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // 右下 - -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // 左上 - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f // 右上 - }; - - // Enable and set the position attribute - glEnableVertexAttribArray(positionAttrib_); - glVertexAttribPointer(positionAttrib_, POSITION_COMPONENT_COUNT, GL_FLOAT, GL_FALSE, - STRIDE, vertices); - - // Enable and set the texture coordinate attribute - glEnableVertexAttribArray(texCoordAttrib_); - glVertexAttribPointer(texCoordAttrib_, TEX_COORD_COMPONENT_COUNT, GL_FLOAT, GL_FALSE, - STRIDE, vertices + POSITION_COMPONENT_COUNT); -} - -void ImageRender::DisableVertexAttributes() -{ - // Disable the vertex attribute arrays after rendering - glDisableVertexAttribArray(positionAttrib_); - glDisableVertexAttribArray(texCoordAttrib_); -} - -void ImageRender::Render() -{ - if (surface_ == EGL_NO_SURFACE) { - return; - } - - if (!eglMakeCurrent(display_, surface_, surface_, context_)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to make context current in Render"); - return; - } - - // Clear the color buffer - glClearColor(0.0f, 1.0f, 1.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - // Use the shader program - glUseProgram(shaderProgram_); - - // Bind the texture - glActiveTexture(GL_TEXTURE0); - glBindTexture(textureTarget_, textureId_); - - // Set the texture sampler to texture unit 0 - glUniform1i(textureUniform_, 0); - - // Set the transformation matrix - GLint matrixLocation = glGetUniformLocation(shaderProgram_, "uTransformMatrix"); - if (matrixLocation != -1) { - glUniformMatrix4fv(matrixLocation, 1, GL_FALSE, transformMatrix_); - } - - // Set up vertex attributes - SetupVertexAttributes(); - - // Draw the textured quad - glDrawArrays(GL_TRIANGLE_STRIP, 0, NUM_VERTICES); - - // Disable vertex attributes - DisableVertexAttributes(); - - // Swap the buffers to display the rendered image - if (!eglSwapBuffers(display_, surface_)) { - EGLint error = eglGetError(); - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", - "eglSwapBuffers failed with error: %d", error); - } -} - -void ImageRender::Cleanup() -{ - if (display_ != EGL_NO_DISPLAY) { - eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - if (context_ != EGL_NO_CONTEXT) { - eglDestroyContext(display_, context_); - context_ = EGL_NO_CONTEXT; - } - - if (surface_ != EGL_NO_SURFACE) { - eglDestroySurface(display_, surface_); - surface_ = EGL_NO_SURFACE; - } - - eglTerminate(display_); - display_ = EGL_NO_DISPLAY; - } - - if (shaderProgram_ != 0) { - glDeleteProgram(shaderProgram_); - shaderProgram_ = 0; - } -} - -GLuint ImageRender::CompileShader(GLenum type, const char* source) -{ - GLuint shader = glCreateShader(type); - if (shader == 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to create shader."); - return 0; - } - - glShaderSource(shader, 1, &source, nullptr); - glCompileShader(shader); - - GLint compiled; - glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if (!compiled) { - PrintShaderCompileError(shader); - glDeleteShader(shader); - return 0; - } - return shader; -} - -void ImageRender::PrintShaderCompileError(GLuint shader) -{ - GLint infoLen = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); - if (infoLen > 1) { - auto infoLog = std::make_unique(infoLen); - glGetShaderInfoLog(shader, infoLen, nullptr, infoLog.get()); - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", - "Error compiling shader: %{public}s", infoLog.get()); - } -} +/* + * Copyright (c) 2024 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 "image_render.h" +#include "common/common.h" +#include +#include +#include +#include +#include +#include + +namespace { + constexpr int MATRIX_SIZE = 16; + constexpr int MATRIX_DIAGONAL_STEP = 5; + constexpr float IDENTITY_DIAGONAL = 1.0f; + constexpr float IDENTITY_OTHER = 0.0f; + constexpr uint32_t NUM_VERTICES = 4; + constexpr uint32_t POSITION_COMPONENT_COUNT = 3; + constexpr uint32_t TEX_COORD_COMPONENT_COUNT = 2; + constexpr uint32_t STRIDE = (POSITION_COMPONENT_COUNT + TEX_COORD_COMPONENT_COUNT) * sizeof(GLfloat); + const char* g_vertexShaderSource = R"( + attribute vec4 aPosition; + attribute vec2 aTexCoord; + varying vec2 vTexCoord; + uniform mat4 uTransformMatrix; + void main() { + gl_Position = aPosition; + vTexCoord = (uTransformMatrix * vec4(aTexCoord, 0.0, 1.0)).xy; + } + )"; + + const char* g_fragmentShaderSource = R"( + #extension GL_OES_EGL_image_external : require + precision mediump float; + uniform samplerExternalOES uTexture; + varying vec2 vTexCoord; + void main() { + gl_FragColor = texture2D(uTexture, vTexCoord); + } + )"; +} + +ImageRender::ImageRender() +{ + // Initialize transformMatrix_ as an identity matrix + for (int i = 0; i < MATRIX_SIZE; ++i) { + transformMatrix_[i] = (i % MATRIX_DIAGONAL_STEP == 0) ? IDENTITY_DIAGONAL : IDENTITY_OTHER; + } +} + +ImageRender::~ImageRender() +{ + Cleanup(); +} + +bool ImageRender::InitEGL(EGLNativeWindowType window, uint64_t width, uint64_t height) +{ + window_ = window; + width_ = width; + height_ = height; + + if (!InitializeEGLDisplay() || !ChooseEGLConfig() || !CreateEGLContext() || !CreateEGLSurface()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to initialize EGL"); + return false; + } + + if (!MakeCurrentContext()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to make EGL context current"); + return false; + } + + if (!CompileAndLinkShaders()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to compile and link shaders"); + return false; + } + + UpdateViewport(); + + return true; +} + +void ImageRender::UpdateWindowInfo(uint64_t width, uint64_t height) +{ + width_ = width; + height_ = height; +} + +bool ImageRender::InitializeEGLDisplay() +{ + display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (display_ == EGL_NO_DISPLAY) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to get EGL display"); + return false; + } + + if (!eglInitialize(display_, nullptr, nullptr)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to initialize EGL"); + return false; + } + + return true; +} + +bool ImageRender::ChooseEGLConfig() +{ + const EGLint attribs[] = { + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_NONE + }; + + EGLint numConfigs; + if (!eglChooseConfig(display_, attribs, &config_, 1, &numConfigs) || numConfigs == 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to choose EGL config"); + return false; + } + return true; +} + +bool ImageRender::CreateEGLContext() +{ + const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + context_ = eglCreateContext(display_, config_, EGL_NO_CONTEXT, contextAttribs); + if (context_ == EGL_NO_CONTEXT) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to create EGL context"); + return false; + } + return true; +} + +bool ImageRender::CreateEGLSurface() +{ + surface_ = eglCreateWindowSurface(display_, config_, window_, nullptr); + if (surface_ == EGL_NO_SURFACE) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to create EGL surface"); + return false; + } + return true; +} + +bool ImageRender::MakeCurrentContext() +{ + if (!eglMakeCurrent(display_, surface_, surface_, context_)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to make EGL context current"); + return false; + } + return true; +} + +void ImageRender::UpdateViewport() +{ + glViewport(0, 0, static_cast(width_), static_cast(height_)); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ImageRender", + "Viewport updated to %{public}llu x %{public}llu", width_, height_); +} + +bool ImageRender::CompileAndLinkShaders() +{ + GLuint vertexShader = CompileShader(GL_VERTEX_SHADER, g_vertexShaderSource); + if (vertexShader == 0) { + return false; + } + + GLuint fragmentShader = CompileShader(GL_FRAGMENT_SHADER, g_fragmentShaderSource); + if (fragmentShader == 0) { + glDeleteShader(vertexShader); + return false; + } + + shaderProgram_ = glCreateProgram(); + glAttachShader(shaderProgram_, vertexShader); + glAttachShader(shaderProgram_, fragmentShader); + glLinkProgram(shaderProgram_); + + GLint linked; + glGetProgramiv(shaderProgram_, GL_LINK_STATUS, &linked); + if (!linked) { + PrintProgramLinkError(shaderProgram_); + glDeleteProgram(shaderProgram_); + glDeleteShader(vertexShader); + glDeleteShader(fragmentShader); + return false; + } + + glUseProgram(shaderProgram_); + + positionAttrib_ = glGetAttribLocation(shaderProgram_, "aPosition"); + texCoordAttrib_ = glGetAttribLocation(shaderProgram_, "aTexCoord"); + textureUniform_ = glGetUniformLocation(shaderProgram_, "uTexture"); + + glDeleteShader(vertexShader); + glDeleteShader(fragmentShader); + + return true; +} + +void ImageRender::PrintProgramLinkError(GLuint program) +{ + GLint infoLen = 0; + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen); + if (infoLen > 1) { + std::unique_ptr infoLog = std::make_unique(infoLen); + glGetProgramInfoLog(program, infoLen, nullptr, infoLog.get()); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "ImageRender", "Error linking program: %{public}s", infoLog.get()); + } +} + +void ImageRender::SetTransformMatrix(const float matrix[MATRIX_SIZE]) +{ + std::copy(matrix, matrix + MATRIX_SIZE, transformMatrix_); +} + +void ImageRender::SetTexture(GLuint textureId, GLuint textureTarget) +{ + textureId_ = textureId; + textureTarget_ = textureTarget; +} + +void ImageRender::SetupVertexAttributes() +{ + static const GLfloat vertices[] = { + -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // 左下 + 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // 右下 + -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // 左上 + 1.0f, 1.0f, 0.0f, 1.0f, 1.0f // 右上 + }; + + // Enable and set the position attribute + glEnableVertexAttribArray(positionAttrib_); + glVertexAttribPointer(positionAttrib_, POSITION_COMPONENT_COUNT, GL_FLOAT, GL_FALSE, + STRIDE, vertices); + + // Enable and set the texture coordinate attribute + glEnableVertexAttribArray(texCoordAttrib_); + glVertexAttribPointer(texCoordAttrib_, TEX_COORD_COMPONENT_COUNT, GL_FLOAT, GL_FALSE, + STRIDE, vertices + POSITION_COMPONENT_COUNT); +} + +void ImageRender::DisableVertexAttributes() +{ + // Disable the vertex attribute arrays after rendering + glDisableVertexAttribArray(positionAttrib_); + glDisableVertexAttribArray(texCoordAttrib_); +} + +void ImageRender::Render() +{ + if (surface_ == EGL_NO_SURFACE) { + return; + } + + if (!eglMakeCurrent(display_, surface_, surface_, context_)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to make context current in Render"); + return; + } + + // Clear the color buffer + glClearColor(0.0f, 1.0f, 1.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + // Use the shader program + glUseProgram(shaderProgram_); + + // Bind the texture + glActiveTexture(GL_TEXTURE0); + glBindTexture(textureTarget_, textureId_); + + // Set the texture sampler to texture unit 0 + glUniform1i(textureUniform_, 0); + + // Set the transformation matrix + GLint matrixLocation = glGetUniformLocation(shaderProgram_, "uTransformMatrix"); + if (matrixLocation != -1) { + glUniformMatrix4fv(matrixLocation, 1, GL_FALSE, transformMatrix_); + } + + // Set up vertex attributes + SetupVertexAttributes(); + + // Draw the textured quad + glDrawArrays(GL_TRIANGLE_STRIP, 0, NUM_VERTICES); + + // Disable vertex attributes + DisableVertexAttributes(); + + // Swap the buffers to display the rendered image + if (!eglSwapBuffers(display_, surface_)) { + EGLint error = eglGetError(); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", + "eglSwapBuffers failed with error: %d", error); + } +} + +void ImageRender::Cleanup() +{ + if (display_ != EGL_NO_DISPLAY) { + eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + if (context_ != EGL_NO_CONTEXT) { + eglDestroyContext(display_, context_); + context_ = EGL_NO_CONTEXT; + } + + if (surface_ != EGL_NO_SURFACE) { + eglDestroySurface(display_, surface_); + surface_ = EGL_NO_SURFACE; + } + + eglTerminate(display_); + display_ = EGL_NO_DISPLAY; + } + + if (shaderProgram_ != 0) { + glDeleteProgram(shaderProgram_); + shaderProgram_ = 0; + } +} + +GLuint ImageRender::CompileShader(GLenum type, const char* source) +{ + GLuint shader = glCreateShader(type); + if (shader == 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", "Failed to create shader."); + return 0; + } + + glShaderSource(shader, 1, &source, nullptr); + glCompileShader(shader); + + GLint compiled; + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + if (!compiled) { + PrintShaderCompileError(shader); + glDeleteShader(shader); + return 0; + } + return shader; +} + +void ImageRender::PrintShaderCompileError(GLuint shader) +{ + GLint infoLen = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); + if (infoLen > 1) { + auto infoLog = std::make_unique(infoLen); + glGetShaderInfoLog(shader, infoLen, nullptr, infoLog.get()); + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ImageRender", + "Error compiling shader: %{public}s", infoLog.get()); + } +} diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.h b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.h index 9c6d016da26d0a0fde5301e2ea4de735e696f066..1636c5b6f4808d55cba58cbed4664e9e566825d5 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.h +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/image_render.h @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2024 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 IMAGE_RENDER_H -#define IMAGE_RENDER_H - -#include -#include - -class ImageRender { -public: - ImageRender(); - ~ImageRender(); - - bool InitEGL(EGLNativeWindowType window, uint64_t width, uint64_t height); - bool MakeCurrentContext(); - void UpdateViewport(); - void UpdateWindowInfo(uint64_t width, uint64_t height); - void SetTexture(GLuint textureId, GLuint textureTarget); - void Render(); - void Cleanup(); - void SetTransformMatrix(const float matrix[16]); - -private: - void SetupVertexAttributes(); - void DisableVertexAttributes(); - bool InitializeEGLDisplay(); - bool ChooseEGLConfig(); - bool CreateEGLContext(); - bool CreateEGLSurface(); - bool CompileAndLinkShaders(); - void PrintProgramLinkError(GLuint program); - GLuint CompileShader(GLenum type, const char* source); - void PrintShaderCompileError(GLuint shader); - - EGLDisplay display_ = EGL_NO_DISPLAY; - EGLSurface surface_ = EGL_NO_SURFACE; - EGLContext context_ = EGL_NO_CONTEXT; - EGLConfig config_ = nullptr; - EGLNativeWindowType window_ = 0; - uint64_t width_ = 0; - uint64_t height_ = 0; - GLuint shaderProgram_ = 0; - GLint positionAttrib_ = -1; - GLint texCoordAttrib_ = -1; - GLint textureUniform_ = -1; - GLuint textureId_ = 0; - GLuint textureTarget_ = 0; - float transformMatrix_[16] = { 0.0f }; -}; - -#endif // IMAGE_RENDER_H +/* + * Copyright (c) 2024 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 IMAGE_RENDER_H +#define IMAGE_RENDER_H + +#include +#include + +class ImageRender { +public: + ImageRender(); + ~ImageRender(); + + bool InitEGL(EGLNativeWindowType window, uint64_t width, uint64_t height); + bool MakeCurrentContext(); + void UpdateViewport(); + void UpdateWindowInfo(uint64_t width, uint64_t height); + void SetTexture(GLuint textureId, GLuint textureTarget); + void Render(); + void Cleanup(); + void SetTransformMatrix(const float matrix[16]); + +private: + void SetupVertexAttributes(); + void DisableVertexAttributes(); + bool InitializeEGLDisplay(); + bool ChooseEGLConfig(); + bool CreateEGLContext(); + bool CreateEGLSurface(); + bool CompileAndLinkShaders(); + void PrintProgramLinkError(GLuint program); + GLuint CompileShader(GLenum type, const char* source); + void PrintShaderCompileError(GLuint shader); + + EGLDisplay display_ = EGL_NO_DISPLAY; + EGLSurface surface_ = EGL_NO_SURFACE; + EGLContext context_ = EGL_NO_CONTEXT; + EGLConfig config_ = nullptr; + EGLNativeWindowType window_ = 0; + uint64_t width_ = 0; + uint64_t height_ = 0; + GLuint shaderProgram_ = 0; + GLint positionAttrib_ = -1; + GLint texCoordAttrib_ = -1; + GLint textureUniform_ = -1; + GLuint textureId_ = 0; + GLuint textureTarget_ = 0; + float transformMatrix_[16] = { 0.0f }; +}; + +#endif // IMAGE_RENDER_H diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.cpp b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.cpp index 2a00c38b26b4cb5417ead436e68a90c67a418e24..22288506689372ab49c18b5207a0be973fb7fd01 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.cpp +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.cpp @@ -1,223 +1,223 @@ -/* - * Copyright (c) 2024 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 "native_render.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - // 动画相关 - constexpr double ANIMATION_SPEED_INCREMENT = 0.6; // 动画速度增量 - - // 文件描述符和轮询相关 - constexpr int INVALID_FD = -1; // 无效的文件描述符 - constexpr uint32_t POLL_TIMEOUT_MS = 3000; // poll 超时时间(毫秒) - constexpr nfds_t NUM_POLL_FDS = 1; // poll 的文件描述符数量 - constexpr int NO_FENCE = -1; // 无同步栅栏 - constexpr int MAX_RETRY = 3; // 最大重试次数 - - // 返回状态码 - constexpr int SUCCESS = 0; // 成功返回码 - constexpr int FAILURE = -1; // 失败返回码 - - // 颜色和像素相关 - constexpr uint8_t MAX_COLOR_VALUE = 255; // 颜色分量的最大值 - constexpr int32_t BYTES_PER_PIXEL = 4; // 每个像素的字节数 - - // 颜色通道位移 - constexpr uint8_t ALPHA_SHIFT = 24; // Alpha 通道位移 - constexpr uint8_t RED_SHIFT = 16; // Red 通道位移 - constexpr uint8_t GREEN_SHIFT = 8; // Green 通道位移 - constexpr uint8_t BLUE_SHIFT = 0; // Blue 通道位移 - - // 强度相关 - constexpr double MAX_INTENSITY = 1.0; // 最大强度值 - constexpr double MIN_INTENSITY = 0.5; // 最小强度值 - constexpr double INTENSITY_MULTIPLIER = 2.0; // 强度乘数 - constexpr double INTENSITY_LIMIT = 1.0; // 强度限制 - - // 箭头绘制相关 - constexpr int ARROW_SIZE_DIVISOR = 2; // 箭头大小的除数 - constexpr int STEM_WIDTH_DIVISOR = 6; // 箭头柄宽度的除数 - constexpr int HEAD_WIDTH_DIVISOR = 2; // 箭头头部宽度的除数 - constexpr int HEAD_LENGTH_DIVISOR = 3; // 箭头头部长度的除数 - constexpr double HEAD_SLOPE_MULTIPLIER = 0.5; // 箭头头部斜率的乘数 -} - -OHNativeRender::~OHNativeRender() -{ - if (nativeWindow_ != nullptr) { - (void)OH_NativeWindow_NativeObjectUnreference(nativeWindow_); - nativeWindow_ = nullptr; - } -} - -bool OHNativeRender::SetSurfaceWidthAndHeight(OH_NativeImage* image, uint64_t surfaceId, uint64_t width, uint64_t height) -{ - if (nativeWindow_ != nullptr) { - (void)OH_NativeWindow_NativeObjectUnreference(nativeWindow_); - nativeWindow_ = nullptr; - } - - // 保存宽度和高度 - width_ = width; - height_ = height; - //方式一: 从 NativeImage 创建 NativeWindow - nativeWindow_ = OH_NativeImage_AcquireNativeWindow(image); - //方式二: 从 SurfaceId 创建 NativeWindow - int ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &nativeWindow_); - if (ret != SUCCESS) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", - "Failed to create NativeWindow from SurfaceId."); - return false; - } - (void)OH_NativeWindow_NativeObjectReference(nativeWindow_); - - // 设置缓冲区的大小等属性 - int32_t result = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, SET_BUFFER_GEOMETRY, - static_cast(width_), static_cast(height_)); - if (result != SUCCESS) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to set buffer geometry."); - return false; - } - - return true; -} - -void OHNativeRender::RenderFrame() -{ - OHNativeWindowBuffer *buffer = nullptr; - int releaseFenceFd = INVALID_FD; - int32_t result = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer, &releaseFenceFd); - if (result != SUCCESS || buffer == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, - "OHNativeRender", "Failed to request buffer, ret : %{public}d.", result); - return; - } - - int retCode = FAILURE; - uint32_t timeout = POLL_TIMEOUT_MS; - if (releaseFenceFd != INVALID_FD) { - struct pollfd pollfds = {}; - pollfds.fd = releaseFenceFd; - pollfds.events = POLLIN; - - int retryCount = 0; - - do { - retCode = poll(&pollfds, NUM_POLL_FDS, POLL_TIMEOUT_MS); - retryCount++; - - // 超过最大重试次数则退出 - if (retryCount >= MAX_RETRY) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, - "OHNativeRender", "Poll reached maximum retry count."); - break; - } - } while (retCode == FAILURE && (errno == EINTR || errno == EAGAIN)); - - close(releaseFenceFd); - } - - BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer); - if (handle == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to get buffer handle."); - return; - } - - // 使用 mmap 获取虚拟地址 - void *mappedAddr = mmap(nullptr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0); - if (mappedAddr == MAP_FAILED) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to mmap buffer."); - return; - } - - // 获取像素指针 - uint32_t *pixel = static_cast(mappedAddr); - - // 调用封装的函数来绘制渐变 - DrawGradient(pixel, handle->stride / BYTES_PER_PIXEL, height_); - - // 解除内存映射 - result = munmap(mappedAddr, handle->size); - if (result == FAILURE) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to munmap buffer."); - } - - std::lock_guard lock(mutex_); - // 设置刷新区域 - Region region{nullptr, 0}; - // 提交给消费者 - result = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer, NO_FENCE, region); - if (result != SUCCESS) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, - "OHNativeRender", "Failed to flush buffer, result : %{public}d.", result); - } -} - -void OHNativeRender::DrawGradient(uint32_t* pixel, uint64_t width, uint64_t height) -{ - static double time = 0.0; - time += ANIMATION_SPEED_INCREMENT; - double offset = (sin(time) + MAX_INTENSITY) / INTENSITY_MULTIPLIER; - - // 箭头参数 - const int arrowSize = std::min(width, height) / ARROW_SIZE_DIVISOR; - const int arrowX = width / ARROW_SIZE_DIVISOR; - const int arrowY = height / ARROW_SIZE_DIVISOR; - const int stemWidth = arrowSize / STEM_WIDTH_DIVISOR; - const int headWidth = arrowSize / HEAD_WIDTH_DIVISOR; - const int headLength = arrowSize / HEAD_LENGTH_DIVISOR; - const int stemStart = arrowX - arrowSize / ARROW_SIZE_DIVISOR; - const int stemEnd = arrowX + arrowSize / ARROW_SIZE_DIVISOR - headLength; - - for (uint64_t y = 0; y < height; y++) { - for (uint64_t x = 0; x < width; x++) { - double normalizedX = static_cast(x) / static_cast(width - 1); - bool isArrow = false; - - if ((x >= stemStart && x <= stemEnd && y >= arrowY - stemWidth * HEAD_SLOPE_MULTIPLIER && - y <= arrowY + stemWidth * HEAD_SLOPE_MULTIPLIER) || (x >= stemEnd && x <= stemEnd + headLength && - fabs(static_cast(y - arrowY)) <= (headWidth * HEAD_SLOPE_MULTIPLIER) * - (1.0 - static_cast(x - stemEnd) / headLength))) { - isArrow = true; - } - - uint8_t red = static_cast((1.0 - normalizedX) * MAX_COLOR_VALUE); - uint8_t blue = static_cast(normalizedX * MAX_COLOR_VALUE); - uint8_t green = 0; - uint8_t alpha = MAX_COLOR_VALUE; - if (isArrow) { - red = green = blue = MAX_COLOR_VALUE; - } - double intensity = fabs(normalizedX - offset); - intensity = MAX_INTENSITY - std::min(INTENSITY_MULTIPLIER * intensity, INTENSITY_LIMIT); - intensity = std::max(intensity, MIN_INTENSITY); - - red = static_cast(red * intensity); - green = static_cast(green * intensity); - blue = static_cast(blue * intensity); - - *pixel++ = (static_cast(alpha) << ALPHA_SHIFT) | (static_cast(red) << RED_SHIFT) | - (static_cast(green) << GREEN_SHIFT) | (static_cast(blue) << BLUE_SHIFT); - } - } +/* + * Copyright (c) 2024 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 "native_render.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + // 动画相关 + constexpr double ANIMATION_SPEED_INCREMENT = 0.6; // 动画速度增量 + + // 文件描述符和轮询相关 + constexpr int INVALID_FD = -1; // 无效的文件描述符 + constexpr uint32_t POLL_TIMEOUT_MS = 3000; // poll 超时时间(毫秒) + constexpr nfds_t NUM_POLL_FDS = 1; // poll 的文件描述符数量 + constexpr int NO_FENCE = -1; // 无同步栅栏 + constexpr int MAX_RETRY = 3; // 最大重试次数 + + // 返回状态码 + constexpr int SUCCESS = 0; // 成功返回码 + constexpr int FAILURE = -1; // 失败返回码 + + // 颜色和像素相关 + constexpr uint8_t MAX_COLOR_VALUE = 255; // 颜色分量的最大值 + constexpr int32_t BYTES_PER_PIXEL = 4; // 每个像素的字节数 + + // 颜色通道位移 + constexpr uint8_t ALPHA_SHIFT = 24; // Alpha 通道位移 + constexpr uint8_t RED_SHIFT = 16; // Red 通道位移 + constexpr uint8_t GREEN_SHIFT = 8; // Green 通道位移 + constexpr uint8_t BLUE_SHIFT = 0; // Blue 通道位移 + + // 强度相关 + constexpr double MAX_INTENSITY = 1.0; // 最大强度值 + constexpr double MIN_INTENSITY = 0.5; // 最小强度值 + constexpr double INTENSITY_MULTIPLIER = 2.0; // 强度乘数 + constexpr double INTENSITY_LIMIT = 1.0; // 强度限制 + + // 箭头绘制相关 + constexpr int ARROW_SIZE_DIVISOR = 2; // 箭头大小的除数 + constexpr int STEM_WIDTH_DIVISOR = 6; // 箭头柄宽度的除数 + constexpr int HEAD_WIDTH_DIVISOR = 2; // 箭头头部宽度的除数 + constexpr int HEAD_LENGTH_DIVISOR = 3; // 箭头头部长度的除数 + constexpr double HEAD_SLOPE_MULTIPLIER = 0.5; // 箭头头部斜率的乘数 +} + +OHNativeRender::~OHNativeRender() +{ + if (nativeWindow_ != nullptr) { + (void)OH_NativeWindow_NativeObjectUnreference(nativeWindow_); + nativeWindow_ = nullptr; + } +} + +bool OHNativeRender::SetSurfaceWidthAndHeight(OH_NativeImage* image, uint64_t surfaceId, uint64_t width, uint64_t height) +{ + if (nativeWindow_ != nullptr) { + (void)OH_NativeWindow_NativeObjectUnreference(nativeWindow_); + nativeWindow_ = nullptr; + } + + // 保存宽度和高度 + width_ = width; + height_ = height; + //方式一: 从 NativeImage 创建 NativeWindow + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(image); + //方式二: 从 SurfaceId 创建 NativeWindow + int ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &nativeWindow_); + if (ret != SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", + "Failed to create NativeWindow from SurfaceId."); + return false; + } + (void)OH_NativeWindow_NativeObjectReference(nativeWindow_); + + // 设置缓冲区的大小等属性 + int32_t result = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, SET_BUFFER_GEOMETRY, + static_cast(width_), static_cast(height_)); + if (result != SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to set buffer geometry."); + return false; + } + + return true; +} + +void OHNativeRender::RenderFrame() +{ + OHNativeWindowBuffer *buffer = nullptr; + int releaseFenceFd = INVALID_FD; + int32_t result = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow_, &buffer, &releaseFenceFd); + if (result != SUCCESS || buffer == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "OHNativeRender", "Failed to request buffer, ret : %{public}d.", result); + return; + } + + int retCode = FAILURE; + uint32_t timeout = POLL_TIMEOUT_MS; + if (releaseFenceFd != INVALID_FD) { + struct pollfd pollfds = {}; + pollfds.fd = releaseFenceFd; + pollfds.events = POLLIN; + + int retryCount = 0; + + do { + retCode = poll(&pollfds, NUM_POLL_FDS, POLL_TIMEOUT_MS); + retryCount++; + + // 超过最大重试次数则退出 + if (retryCount >= MAX_RETRY) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "OHNativeRender", "Poll reached maximum retry count."); + break; + } + } while (retCode == FAILURE && (errno == EINTR || errno == EAGAIN)); + + close(releaseFenceFd); + } + + BufferHandle *handle = OH_NativeWindow_GetBufferHandleFromNative(buffer); + if (handle == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to get buffer handle."); + return; + } + + // 使用 mmap 获取虚拟地址 + void *mappedAddr = mmap(nullptr, handle->size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd, 0); + if (mappedAddr == MAP_FAILED) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to mmap buffer."); + return; + } + + // 获取像素指针 + uint32_t *pixel = static_cast(mappedAddr); + + // 调用封装的函数来绘制渐变 + DrawGradient(pixel, handle->stride / BYTES_PER_PIXEL, height_); + + // 解除内存映射 + result = munmap(mappedAddr, handle->size); + if (result == FAILURE) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "OHNativeRender", "Failed to munmap buffer."); + } + + std::lock_guard lock(mutex_); + // 设置刷新区域 + Region region{nullptr, 0}; + // 提交给消费者 + result = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow_, buffer, NO_FENCE, region); + if (result != SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "OHNativeRender", "Failed to flush buffer, result : %{public}d.", result); + } +} + +void OHNativeRender::DrawGradient(uint32_t* pixel, uint64_t width, uint64_t height) +{ + static double time = 0.0; + time += ANIMATION_SPEED_INCREMENT; + double offset = (sin(time) + MAX_INTENSITY) / INTENSITY_MULTIPLIER; + + // 箭头参数 + const int arrowSize = std::min(width, height) / ARROW_SIZE_DIVISOR; + const int arrowX = width / ARROW_SIZE_DIVISOR; + const int arrowY = height / ARROW_SIZE_DIVISOR; + const int stemWidth = arrowSize / STEM_WIDTH_DIVISOR; + const int headWidth = arrowSize / HEAD_WIDTH_DIVISOR; + const int headLength = arrowSize / HEAD_LENGTH_DIVISOR; + const int stemStart = arrowX - arrowSize / ARROW_SIZE_DIVISOR; + const int stemEnd = arrowX + arrowSize / ARROW_SIZE_DIVISOR - headLength; + + for (uint64_t y = 0; y < height; y++) { + for (uint64_t x = 0; x < width; x++) { + double normalizedX = static_cast(x) / static_cast(width - 1); + bool isArrow = false; + + if ((x >= stemStart && x <= stemEnd && y >= arrowY - stemWidth * HEAD_SLOPE_MULTIPLIER && + y <= arrowY + stemWidth * HEAD_SLOPE_MULTIPLIER) || (x >= stemEnd && x <= stemEnd + headLength && + fabs(static_cast(y - arrowY)) <= (headWidth * HEAD_SLOPE_MULTIPLIER) * + (1.0 - static_cast(x - stemEnd) / headLength))) { + isArrow = true; + } + + uint8_t red = static_cast((1.0 - normalizedX) * MAX_COLOR_VALUE); + uint8_t blue = static_cast(normalizedX * MAX_COLOR_VALUE); + uint8_t green = 0; + uint8_t alpha = MAX_COLOR_VALUE; + if (isArrow) { + red = green = blue = MAX_COLOR_VALUE; + } + double intensity = fabs(normalizedX - offset); + intensity = MAX_INTENSITY - std::min(INTENSITY_MULTIPLIER * intensity, INTENSITY_LIMIT); + intensity = std::max(intensity, MIN_INTENSITY); + + red = static_cast(red * intensity); + green = static_cast(green * intensity); + blue = static_cast(blue * intensity); + + *pixel++ = (static_cast(alpha) << ALPHA_SHIFT) | (static_cast(red) << RED_SHIFT) | + (static_cast(green) << GREEN_SHIFT) | (static_cast(blue) << BLUE_SHIFT); + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.h b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.h index eed4ec671f04806414f3b45118113d3ddf0d6bcf..33b7d498e383b9a2d1e61e55fd5b88f369171634 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.h +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/native_render.h @@ -1,40 +1,40 @@ -/* - * Copyright (c) 2024 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 NATIVE_IMAGE_NATIVE_RENDER_H -#define NATIVE_IMAGE_NATIVE_RENDER_H -#include -#include -#include -#include -#include - -class OHNativeRender { -public: - OHNativeRender() = default; - ~OHNativeRender(); - - bool SetSurfaceWidthAndHeight(OH_NativeImage* image, uint64_t surfaceId, uint64_t width, uint64_t height); - void RenderFrame(); - -private: - void DrawGradient(uint32_t* pixel, uint64_t width, uint64_t height); - - OHNativeWindow* nativeWindow_ = nullptr; - std::mutex mutex_; - uint64_t width_ = 0; - uint64_t height_ = 0; -}; -#endif // NATIVE_IMAGE_NATIVE_RENDER_H +/* + * Copyright (c) 2024 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 NATIVE_IMAGE_NATIVE_RENDER_H +#define NATIVE_IMAGE_NATIVE_RENDER_H +#include +#include +#include +#include +#include + +class OHNativeRender { +public: + OHNativeRender() = default; + ~OHNativeRender(); + + bool SetSurfaceWidthAndHeight(OH_NativeImage* image, uint64_t surfaceId, uint64_t width, uint64_t height); + void RenderFrame(); + +private: + void DrawGradient(uint32_t* pixel, uint64_t width, uint64_t height); + + OHNativeWindow* nativeWindow_ = nullptr; + std::mutex mutex_; + uint64_t width_ = 0; + uint64_t height_ = 0; +}; +#endif // NATIVE_IMAGE_NATIVE_RENDER_H diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.cpp b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.cpp index b3ac18e564ea87c61f5176abf9bab0e57b8f7ede..bdb99a1332c0045927a358dfa8f64675cff3252e 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.cpp +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.cpp @@ -1,400 +1,400 @@ -/* - * Copyright (c) 2024 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 "render_engine.h" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - constexpr int FRAME_RATE = 60; // 目标帧率 - constexpr int NANOSECONDS_IN_A_SECOND = 1000000000; // 一秒中的纳秒数 -} - -RenderEngine::RenderEngine(std::shared_ptr imageRender, uint64_t width, uint64_t height, void *window) - : imageRender_(std::move(imageRender)), width_(width), height_(height), window_(window) -{ - Start(); -} - -RenderEngine::~RenderEngine() -{ - Stop(); -} - -void RenderEngine::Start() -{ - if (running_) { - return; - } - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "start."); - running_ = true; - - thread_ = std::thread([this]() { - if (!imageRender_->InitEGL(reinterpret_cast(window_), width_, height_)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to initialize EGL"); - return; - } - if (!InitNativeVsync()) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to initialize VSync"); - return; - } - if (!CreateNativeImage()) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to create Native Image"); - return; - } - if (!StartNativeRenderThread()) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to start NativeRender thread"); - return; - } - MainLoop(); - CleanupResources(); - }); -} - -void RenderEngine::CleanupResources() -{ - StopNativeRenderThread(); - DestroyNativeImage(); - DestroyNativeVsync(); - imageRender_->Cleanup(); -} - -void RenderEngine::Stop() -{ - if (!running_) { - return; - } - - running_ = false; - - if (thread_.joinable()) { - thread_.join(); - } - - CleanupResources(); -} - -void RenderEngine::UpdateNativeWindow(uint64_t width, uint64_t height) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "UpdateNativeWindow."); - PostTask([this, width, height](std::shared_ptr imageRender) { - imageRender->UpdateWindowInfo(width, height); - imageRender->UpdateViewport(); - }); -} - -void RenderEngine::MainLoop() -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "MainLoop start."); - - threadId_ = std::this_thread::get_id(); - - while (running_) { - WaitForNewFrame(); - if (!isPaused_) { - ExecuteRenderTasks(); - UpdateSurfaceImage(); - } - } - - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "MainLoop end."); -} - -void RenderEngine::WaitForNewFrame() -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Waiting for new frame."); - std::unique_lock lock(frameMutex_); - frameCond_.wait(lock, [this] { return availableFrameCnt_ > 0 || !running_; }); -} - -void RenderEngine::WaitForVsync() -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Waiting for vsync."); - std::unique_lock lock(wakeUpMutex_); - wakeUpCond_.wait(lock, [this]() { return wakeUp_ || vSyncCnt_ > 0; }); - wakeUp_ = false; - if (vSyncCnt_ > 0) { - vSyncCnt_--; - (void)OH_NativeVSync_RequestFrame(nativeVsync_, &RenderEngine::OnVsync, this); - OH_NativeVSync_GetPeriod(nativeVsync_, &period); - } -} - -void RenderEngine::OnVsync(long long timestamp, void *data) -{ - OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_PRINT_DOMAIN, "RenderEngine", "OnVsync %{public}lld.", timestamp); - auto renderEngine = reinterpret_cast(data); - if (renderEngine == nullptr) { - return; - } - - renderEngine->vSyncCnt_++; - renderEngine->wakeUpCond_.notify_one(); -} - -bool RenderEngine::InitNativeVsync() -{ - const char* demoName = "NativeImageSample"; - nativeVsync_ = OH_NativeVSync_Create(demoName, strlen(demoName)); - if (nativeVsync_ == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Create NativeVSync failed."); - return false; - } - (void)OH_NativeVSync_RequestFrame(nativeVsync_, &RenderEngine::OnVsync, this); - return true; -} - -void RenderEngine::DestroyNativeVsync() -{ - if (nativeVsync_ != nullptr) { - OH_NativeVSync_Destroy(nativeVsync_); - nativeVsync_ = nullptr; - } -} - -void RenderEngine::ExecuteRenderTasks() -{ - std::vector tasks; - { - std::lock_guard lock(taskMutex_); - tasks.swap(tasks_); - } - for (const auto &task : tasks) { - task(imageRender_); - } -} - -void RenderEngine::UpdateSurfaceImage() -{ - if (availableFrameCnt_ <= 0) { - return; - } - - if (!nativeImage_) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Native Image is null"); - return; - } - - int32_t ret = OH_NativeImage_UpdateSurfaceImage(nativeImage_); - if (ret != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", - "OH_NativeImage_UpdateSurfaceImage failed, ret: %{public}d, texId: %{public}u", - ret, nativeImageTexId_); - return; - } - - UpdateTextureMatrix(); - if (imageRender_) { - imageRender_->Render(); - } else { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "ImageRender is null"); - } - availableFrameCnt_--; -} - -void RenderEngine::UpdateTextureMatrix() -{ - float matrix[16]; - int32_t ret = OH_NativeImage_GetTransformMatrixV2(nativeImage_, matrix); - if (ret != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", - "OH_NativeImage_GetTransformMatrix failed, ret: %{public}d", ret); - return; - } - imageRender_->SetTransformMatrix(matrix); -} - -bool RenderEngine::CreateNativeImage() -{ - if (!GenerateTexture() || !CreateNativeImageObject() || !AttachContextAndGetSurfaceId()) { - return false; - } - - if (!SetFrameAvailableListener()) { - return false; - } - - imageRender_->SetTexture(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES); - - return true; -} - -bool RenderEngine::GenerateTexture() -{ - glGenTextures(1, &nativeImageTexId_); - glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - return true; -} - -bool RenderEngine::CreateNativeImageObject() -{ - nativeImage_ = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES); - if (nativeImage_ == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to create Native Image"); - return false; - } - return true; -} - -bool RenderEngine::AttachContextAndGetSurfaceId() -{ - int ret = OH_NativeImage_AttachContext(nativeImage_, nativeImageTexId_); - if (ret != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", - "AttachContext failed for textureId: %{public}u, ret: %{public}d", nativeImageTexId_, ret); - return false; - } - - std::lock_guard lock(nativeImageSurfaceIdMutex_); - ret = OH_NativeImage_GetSurfaceId(nativeImage_, &nativeImageSurfaceId_); - if (ret != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", - "OH_NativeImage_GetSurfaceId failed, ret: %{public}d", ret); - return false; - } - return true; -} - -bool RenderEngine::SetFrameAvailableListener() -{ - nativeImageFrameAvailableListener_.context = this; - nativeImageFrameAvailableListener_.onFrameAvailable = &RenderEngine::OnNativeImageFrameAvailable; - int ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage_, nativeImageFrameAvailableListener_); - if (ret != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", - "OH_NativeImage_SetOnFrameAvailableListener failed, ret: %{public}d", ret); - return false; - } - return true; -} - -void RenderEngine::PostTask(const RenderTask &task) -{ - if (!running_) { - OH_LOG_Print(LOG_APP, LOG_WARN, LOG_PRINT_DOMAIN, "RenderEngine", - "PostTask failed: RenderEngine is not running"); - return; - } - - { - std::lock_guard lock(taskMutex_); - tasks_.push_back(task); - } - - frameCond_.notify_one(); -} - -void RenderEngine::OnNativeImageFrameAvailable(void *data) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "OnNativeImageFrameAvailable."); - auto renderEngine = reinterpret_cast(data); - if (renderEngine == nullptr) { - return; - } - { - std::lock_guard lock(renderEngine->frameMutex_); - renderEngine->availableFrameCnt_++; - } - renderEngine->frameCond_.notify_one(); -} - -void RenderEngine::DestroyNativeImage() -{ - if (nativeImageTexId_ != 0U) { - glDeleteTextures(1, &nativeImageTexId_); - nativeImageTexId_ = 0U; - } - - if (nativeImage_ != nullptr) { - OH_NativeImage_DetachContext(nativeImage_); - (void)OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); - OH_NativeImage_Destroy(&nativeImage_); - nativeImage_ = nullptr; - } -} - -bool RenderEngine::StartNativeRenderThread() -{ - if (!nativeRender_) { - nativeRender_ = std::make_shared(); - } - - { - std::lock_guard lock(nativeImageSurfaceIdMutex_); - if (nativeImageSurfaceId_ == 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Invalid nativeImageSurfaceId_"); - return false; - } - - if (!nativeRender_->SetSurfaceWidthAndHeight(nativeImage_, nativeImageSurfaceId_, width_, height_)) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, - "RenderEngine", "Failed to set SurfaceId for NativeRender"); - return false; - } - } - - nativeRenderThread_ = std::thread([this]() { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Native Render Thread started"); - while (running_) { - // 等待 VSync 信号 - WaitForVsync(); - if (!isPaused_ && nativeRender_) { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Rendering Frame"); - nativeRender_->RenderFrame(); - } - } - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Native Render Thread ended"); - }); - - return true; -} - -void RenderEngine::StopNativeRenderThread() -{ - if (nativeRenderThread_.joinable()) { - nativeRenderThread_.join(); - } -} - -void RenderEngine::OnSurfaceChanged(uint64_t width, uint64_t height) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", - "Surface changed to %{public}llu x %{public}lu", width, height); - - UpdateNativeWindow(width, height); -} - -void RenderEngine::OnAppResume() -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "App resumed"); - isPaused_ = false; -} - -void RenderEngine::OnAppPause() -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "App paused"); - isPaused_ = true; -} +/* + * Copyright (c) 2024 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 "render_engine.h" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + constexpr int FRAME_RATE = 60; // 目标帧率 + constexpr int NANOSECONDS_IN_A_SECOND = 1000000000; // 一秒中的纳秒数 +} + +RenderEngine::RenderEngine(std::shared_ptr imageRender, uint64_t width, uint64_t height, void *window) + : imageRender_(std::move(imageRender)), width_(width), height_(height), window_(window) +{ + Start(); +} + +RenderEngine::~RenderEngine() +{ + Stop(); +} + +void RenderEngine::Start() +{ + if (running_) { + return; + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "start."); + running_ = true; + + thread_ = std::thread([this]() { + if (!imageRender_->InitEGL(reinterpret_cast(window_), width_, height_)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to initialize EGL"); + return; + } + if (!InitNativeVsync()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to initialize VSync"); + return; + } + if (!CreateNativeImage()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to create Native Image"); + return; + } + if (!StartNativeRenderThread()) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to start NativeRender thread"); + return; + } + MainLoop(); + CleanupResources(); + }); +} + +void RenderEngine::CleanupResources() +{ + StopNativeRenderThread(); + DestroyNativeImage(); + DestroyNativeVsync(); + imageRender_->Cleanup(); +} + +void RenderEngine::Stop() +{ + if (!running_) { + return; + } + + running_ = false; + + if (thread_.joinable()) { + thread_.join(); + } + + CleanupResources(); +} + +void RenderEngine::UpdateNativeWindow(uint64_t width, uint64_t height) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "UpdateNativeWindow."); + PostTask([this, width, height](std::shared_ptr imageRender) { + imageRender->UpdateWindowInfo(width, height); + imageRender->UpdateViewport(); + }); +} + +void RenderEngine::MainLoop() +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "MainLoop start."); + + threadId_ = std::this_thread::get_id(); + + while (running_) { + WaitForNewFrame(); + if (!isPaused_) { + ExecuteRenderTasks(); + UpdateSurfaceImage(); + } + } + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "MainLoop end."); +} + +void RenderEngine::WaitForNewFrame() +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Waiting for new frame."); + std::unique_lock lock(frameMutex_); + frameCond_.wait(lock, [this] { return availableFrameCnt_ > 0 || !running_; }); +} + +void RenderEngine::WaitForVsync() +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Waiting for vsync."); + std::unique_lock lock(wakeUpMutex_); + wakeUpCond_.wait(lock, [this]() { return wakeUp_ || vSyncCnt_ > 0; }); + wakeUp_ = false; + if (vSyncCnt_ > 0) { + vSyncCnt_--; + (void)OH_NativeVSync_RequestFrame(nativeVsync_, &RenderEngine::OnVsync, this); + OH_NativeVSync_GetPeriod(nativeVsync_, &period); + } +} + +void RenderEngine::OnVsync(long long timestamp, void *data) +{ + OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_PRINT_DOMAIN, "RenderEngine", "OnVsync %{public}lld.", timestamp); + auto renderEngine = reinterpret_cast(data); + if (renderEngine == nullptr) { + return; + } + + renderEngine->vSyncCnt_++; + renderEngine->wakeUpCond_.notify_one(); +} + +bool RenderEngine::InitNativeVsync() +{ + const char* demoName = "NativeImageSample"; + nativeVsync_ = OH_NativeVSync_Create(demoName, strlen(demoName)); + if (nativeVsync_ == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Create NativeVSync failed."); + return false; + } + (void)OH_NativeVSync_RequestFrame(nativeVsync_, &RenderEngine::OnVsync, this); + return true; +} + +void RenderEngine::DestroyNativeVsync() +{ + if (nativeVsync_ != nullptr) { + OH_NativeVSync_Destroy(nativeVsync_); + nativeVsync_ = nullptr; + } +} + +void RenderEngine::ExecuteRenderTasks() +{ + std::vector tasks; + { + std::lock_guard lock(taskMutex_); + tasks.swap(tasks_); + } + for (const auto &task : tasks) { + task(imageRender_); + } +} + +void RenderEngine::UpdateSurfaceImage() +{ + if (availableFrameCnt_ <= 0) { + return; + } + + if (!nativeImage_) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Native Image is null"); + return; + } + + int32_t ret = OH_NativeImage_UpdateSurfaceImage(nativeImage_); + if (ret != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", + "OH_NativeImage_UpdateSurfaceImage failed, ret: %{public}d, texId: %{public}u", + ret, nativeImageTexId_); + return; + } + + UpdateTextureMatrix(); + if (imageRender_) { + imageRender_->Render(); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "ImageRender is null"); + } + availableFrameCnt_--; +} + +void RenderEngine::UpdateTextureMatrix() +{ + float matrix[16]; + int32_t ret = OH_NativeImage_GetTransformMatrixV2(nativeImage_, matrix); + if (ret != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", + "OH_NativeImage_GetTransformMatrix failed, ret: %{public}d", ret); + return; + } + imageRender_->SetTransformMatrix(matrix); +} + +bool RenderEngine::CreateNativeImage() +{ + if (!GenerateTexture() || !CreateNativeImageObject() || !AttachContextAndGetSurfaceId()) { + return false; + } + + if (!SetFrameAvailableListener()) { + return false; + } + + imageRender_->SetTexture(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES); + + return true; +} + +bool RenderEngine::GenerateTexture() +{ + glGenTextures(1, &nativeImageTexId_); + glBindTexture(GL_TEXTURE_EXTERNAL_OES, nativeImageTexId_); + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + return true; +} + +bool RenderEngine::CreateNativeImageObject() +{ + nativeImage_ = OH_NativeImage_Create(nativeImageTexId_, GL_TEXTURE_EXTERNAL_OES); + if (nativeImage_ == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Failed to create Native Image"); + return false; + } + return true; +} + +bool RenderEngine::AttachContextAndGetSurfaceId() +{ + int ret = OH_NativeImage_AttachContext(nativeImage_, nativeImageTexId_); + if (ret != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", + "AttachContext failed for textureId: %{public}u, ret: %{public}d", nativeImageTexId_, ret); + return false; + } + + std::lock_guard lock(nativeImageSurfaceIdMutex_); + ret = OH_NativeImage_GetSurfaceId(nativeImage_, &nativeImageSurfaceId_); + if (ret != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", + "OH_NativeImage_GetSurfaceId failed, ret: %{public}d", ret); + return false; + } + return true; +} + +bool RenderEngine::SetFrameAvailableListener() +{ + nativeImageFrameAvailableListener_.context = this; + nativeImageFrameAvailableListener_.onFrameAvailable = &RenderEngine::OnNativeImageFrameAvailable; + int ret = OH_NativeImage_SetOnFrameAvailableListener(nativeImage_, nativeImageFrameAvailableListener_); + if (ret != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", + "OH_NativeImage_SetOnFrameAvailableListener failed, ret: %{public}d", ret); + return false; + } + return true; +} + +void RenderEngine::PostTask(const RenderTask &task) +{ + if (!running_) { + OH_LOG_Print(LOG_APP, LOG_WARN, LOG_PRINT_DOMAIN, "RenderEngine", + "PostTask failed: RenderEngine is not running"); + return; + } + + { + std::lock_guard lock(taskMutex_); + tasks_.push_back(task); + } + + frameCond_.notify_one(); +} + +void RenderEngine::OnNativeImageFrameAvailable(void *data) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "OnNativeImageFrameAvailable."); + auto renderEngine = reinterpret_cast(data); + if (renderEngine == nullptr) { + return; + } + { + std::lock_guard lock(renderEngine->frameMutex_); + renderEngine->availableFrameCnt_++; + } + renderEngine->frameCond_.notify_one(); +} + +void RenderEngine::DestroyNativeImage() +{ + if (nativeImageTexId_ != 0U) { + glDeleteTextures(1, &nativeImageTexId_); + nativeImageTexId_ = 0U; + } + + if (nativeImage_ != nullptr) { + OH_NativeImage_DetachContext(nativeImage_); + (void)OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); + OH_NativeImage_Destroy(&nativeImage_); + nativeImage_ = nullptr; + } +} + +bool RenderEngine::StartNativeRenderThread() +{ + if (!nativeRender_) { + nativeRender_ = std::make_shared(); + } + + { + std::lock_guard lock(nativeImageSurfaceIdMutex_); + if (nativeImageSurfaceId_ == 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "RenderEngine", "Invalid nativeImageSurfaceId_"); + return false; + } + + if (!nativeRender_->SetSurfaceWidthAndHeight(nativeImage_, nativeImageSurfaceId_, width_, height_)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, + "RenderEngine", "Failed to set SurfaceId for NativeRender"); + return false; + } + } + + nativeRenderThread_ = std::thread([this]() { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Native Render Thread started"); + while (running_) { + // 等待 VSync 信号 + WaitForVsync(); + if (!isPaused_ && nativeRender_) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Rendering Frame"); + nativeRender_->RenderFrame(); + } + } + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "Native Render Thread ended"); + }); + + return true; +} + +void RenderEngine::StopNativeRenderThread() +{ + if (nativeRenderThread_.joinable()) { + nativeRenderThread_.join(); + } +} + +void RenderEngine::OnSurfaceChanged(uint64_t width, uint64_t height) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", + "Surface changed to %{public}llu x %{public}lu", width, height); + + UpdateNativeWindow(width, height); +} + +void RenderEngine::OnAppResume() +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "App resumed"); + isPaused_ = false; +} + +void RenderEngine::OnAppPause() +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "RenderEngine", "App paused"); + isPaused_ = true; +} diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.h b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.h index b2a57b8a57d03a1a8efae6a5b81e222213586286..14ef2567dd68665e98cad98fef3ec1f19816c3f2 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.h +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/render/render_engine.h @@ -1,131 +1,131 @@ -/* - * Copyright (c) 2024 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 RENDER_ENGINE_H -#define RENDER_ENGINE_H - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include "image_render.h" -#include "native_render.h" - -class RenderEngine { -public: - using RenderTask = std::function render)>; - - RenderEngine(std::shared_ptr imageRender, uint64_t width, uint64_t height, void *window); - ~RenderEngine(); - - // 禁用拷贝和移动 - RenderEngine(const RenderEngine &other) = delete; - RenderEngine &operator=(const RenderEngine &other) = delete; - RenderEngine(RenderEngine &&other) = delete; - RenderEngine &operator=(RenderEngine &&other) = delete; - - // 启动渲染引擎 - void Start(); - - // 停止渲染引擎 - void Stop(); - - // 发布任务到渲染线程 - void PostTask(const RenderTask &task); - - // 更新 NativeWindow - void UpdateNativeWindow(uint64_t width, uint64_t height); - void OnSurfaceChanged(uint64_t width, uint64_t height); - void OnAppResume(); - void OnAppPause(); -private: - static void OnNativeImageFrameAvailable(void *data); - // Vsync 相关 - bool InitNativeVsync(); - void DestroyNativeVsync(); - static void OnVsync(long long timestamp, void *data); - - // 主循环 - void MainLoop(); - - // 渲染线程初始化 - void InitializeRendering(); - void CleanupResources(); - - // 渲染流程任务 - void WaitForNewFrame(); - void WaitForVsync(); - void ExecuteRenderTasks(); - void UpdateSurfaceImage(); - void UpdateTextureMatrix(); - - // 创建与销毁 NativeImage - bool CreateNativeImage(); - bool StartNativeRenderThread(); - void StopNativeRenderThread(); - void DestroyNativeImage(); - - bool GenerateTexture(); - bool CreateNativeImageObject(); - bool AttachContextAndGetSurfaceId(); - bool SetFrameAvailableListener(); - - // NativeRender 相关 - std::shared_ptr nativeRender_; - std::thread nativeRenderThread_; - - // NativeImage 相关 - OH_OnFrameAvailableListener nativeImageFrameAvailableListener_{}; - OH_NativeImage *nativeImage_ = nullptr; - GLuint nativeImageTexId_ = 0U; - std::mutex nativeImageSurfaceIdMutex_; - uint64_t nativeImageSurfaceId_ = 0; - std::atomic availableFrameCnt_{0}; - std::condition_variable frameCond_; - std::mutex frameMutex_; - - // 渲染引擎运行状态 - std::atomic running_{false}; - std::thread thread_; - std::thread::id threadId_; - - // 同步和任务队列 - std::mutex taskMutex_; - std::vector tasks_; - mutable std::mutex wakeUpMutex_; - std::condition_variable wakeUpCond_; - bool wakeUp_ = false; - std::atomic vSyncCnt_{0}; - OH_NativeVSync *nativeVsync_ = nullptr; - - // 关联的 ImageRender 实例 - std::shared_ptr imageRender_; - void *window_ = nullptr; - uint64_t width_ = 0; - uint64_t height_ = 0; - long long period = 0; - // 其他状态变量 - std::atomic isPaused_{false}; -}; - -#endif // RENDER_ENGINE_H +/* + * Copyright (c) 2024 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 RENDER_ENGINE_H +#define RENDER_ENGINE_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "image_render.h" +#include "native_render.h" + +class RenderEngine { +public: + using RenderTask = std::function render)>; + + RenderEngine(std::shared_ptr imageRender, uint64_t width, uint64_t height, void *window); + ~RenderEngine(); + + // 禁用拷贝和移动 + RenderEngine(const RenderEngine &other) = delete; + RenderEngine &operator=(const RenderEngine &other) = delete; + RenderEngine(RenderEngine &&other) = delete; + RenderEngine &operator=(RenderEngine &&other) = delete; + + // 启动渲染引擎 + void Start(); + + // 停止渲染引擎 + void Stop(); + + // 发布任务到渲染线程 + void PostTask(const RenderTask &task); + + // 更新 NativeWindow + void UpdateNativeWindow(uint64_t width, uint64_t height); + void OnSurfaceChanged(uint64_t width, uint64_t height); + void OnAppResume(); + void OnAppPause(); +private: + static void OnNativeImageFrameAvailable(void *data); + // Vsync 相关 + bool InitNativeVsync(); + void DestroyNativeVsync(); + static void OnVsync(long long timestamp, void *data); + + // 主循环 + void MainLoop(); + + // 渲染线程初始化 + void InitializeRendering(); + void CleanupResources(); + + // 渲染流程任务 + void WaitForNewFrame(); + void WaitForVsync(); + void ExecuteRenderTasks(); + void UpdateSurfaceImage(); + void UpdateTextureMatrix(); + + // 创建与销毁 NativeImage + bool CreateNativeImage(); + bool StartNativeRenderThread(); + void StopNativeRenderThread(); + void DestroyNativeImage(); + + bool GenerateTexture(); + bool CreateNativeImageObject(); + bool AttachContextAndGetSurfaceId(); + bool SetFrameAvailableListener(); + + // NativeRender 相关 + std::shared_ptr nativeRender_; + std::thread nativeRenderThread_; + + // NativeImage 相关 + OH_OnFrameAvailableListener nativeImageFrameAvailableListener_{}; + OH_NativeImage *nativeImage_ = nullptr; + GLuint nativeImageTexId_ = 0U; + std::mutex nativeImageSurfaceIdMutex_; + uint64_t nativeImageSurfaceId_ = 0; + std::atomic availableFrameCnt_{0}; + std::condition_variable frameCond_; + std::mutex frameMutex_; + + // 渲染引擎运行状态 + std::atomic running_{false}; + std::thread thread_; + std::thread::id threadId_; + + // 同步和任务队列 + std::mutex taskMutex_; + std::vector tasks_; + mutable std::mutex wakeUpMutex_; + std::condition_variable wakeUpCond_; + bool wakeUp_ = false; + std::atomic vSyncCnt_{0}; + OH_NativeVSync *nativeVsync_ = nullptr; + + // 关联的 ImageRender 实例 + std::shared_ptr imageRender_; + void *window_ = nullptr; + uint64_t width_ = 0; + uint64_t height_ = 0; + long long period = 0; + // 其他状态变量 + std::atomic isPaused_{false}; +}; + +#endif // RENDER_ENGINE_H diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/types/libentry/oh-package.json5 index 581938141597ab7ecd0595b7c52a7657ed22324e..05fea1c071b5ffa8d2e3fb34b4094a5c224f4bab 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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." +/* + * Copyright (c) 2024 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/NdkNativeImage/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/entryability/EntryAbility.ets index ca45f401138c56d8646e0d1312c10cbbd9577d2e..d96a7e268e388ab61498dd2109d5f2cc666000fd 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,41 +1,41 @@ -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'); - } -}; +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/NdkNativeImage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index b72fc477d96447e221cf45c9c6671c8018ae05f3..dc55c03d3eea7ce53d5346c732a39ce9bf5267e1 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,12 +1,12 @@ -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)); - } +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/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/pages/Index.ets index 030a410d21c355616bbcbfe61b0a35a71c6fbd03..c843f4f5847f3978e9abc13e9e3f2f2222ed75dd 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/ets/pages/Index.ets @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 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'; - -@Entry -@Component -struct Index { - xComponentContext: XComponentController = new XComponentController() - xComponentAttrs: XComponentAttrs = { - id: 'xcomponentId', - type: XComponentType.SURFACE, - libraryname: 'entry' - } - - build() { - Column() { - XComponent(this.xComponentAttrs) - .onLoad((context: XComponentController) => { - this.xComponentContext = context; - }) - .padding(16) - } - } -} - -interface XComponentAttrs { - id: string; - type: number; - libraryname: string; +/* + * Copyright (c) 2024 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'; + +@Entry +@Component +struct Index { + xComponentContext: XComponentController = new XComponentController() + xComponentAttrs: XComponentAttrs = { + id: 'xcomponentId', + type: XComponentType.SURFACE, + libraryname: 'entry' + } + + build() { + Column() { + XComponent(this.xComponentAttrs) + .onLoad((context: XComponentController) => { + this.xComponentContext = context; + }) + .padding(16) + } + } +} + +interface XComponentAttrs { + id: string; + type: number; + libraryname: string; } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/module.json5 b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/module.json5 index b541792385cb5a1a925f93ae8c9242b9596ec27e..cb5df2316a385286bf09b1aab230f0bf56d8b993 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/module.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/module.json5 @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2024 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" - } - ] - } - ] - } +/* + * Copyright (c) 2024 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/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/profile/backup_config.json +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/ets/test/NdkNativeImage.test.ets b/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/ets/test/NdkNativeImage.test.ets index b6f8c04314adca0d2eea87943d8ceb5b5862e812..576a7116668d03cb7428ccc524252b9896f908c6 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/ets/test/NdkNativeImage.test.ets +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/ets/test/NdkNativeImage.test.ets @@ -1,46 +1,46 @@ -/* - * Copyright (c) 2024 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, it, expect } from '@ohos/hypium'; -import { Driver, ON } from '@ohos.UiTest'; - -const TAG = '[Sample_NdkNativeImageAPI]'; - -export default function abilityTest() { - - describe('ActsAbilityTest', () => { - /** - * 打开应用 - */ - it('StartAbility_001', 0, async (done: Function) => { - console.info(TAG, 'StartAbility_001 begin'); - let driver = Driver.create(); - let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - try { - await abilityDelegator.startAbility({ - bundleName: 'com.samples.ndknativeimage', - abilityName: 'EntryAbility' - }); - } catch (exception) { - console.info(TAG, `StartAbility_001 exception = ${JSON.stringify(exception)}`); - expect().assertFail(); - } - await driver.delayMs(10000); - done(); - console.info(TAG, 'StartAbility_001 end'); - }) - }) +/* + * Copyright (c) 2024 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, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; + +const TAG = '[Sample_NdkNativeImageAPI]'; + +export default function abilityTest() { + + describe('ActsAbilityTest', () => { + /** + * 打开应用 + */ + it('StartAbility_001', 0, async (done: Function) => { + console.info(TAG, 'StartAbility_001 begin'); + let driver = Driver.create(); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + try { + await abilityDelegator.startAbility({ + bundleName: 'com.samples.ndknativeimage', + abilityName: 'EntryAbility' + }); + } catch (exception) { + console.info(TAG, `StartAbility_001 exception = ${JSON.stringify(exception)}`); + expect().assertFail(); + } + await driver.delayMs(10000); + done(); + console.info(TAG, 'StartAbility_001 end'); + }) + }) } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/module.json5 b/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/module.json5 index 1f646ea03f584d15f4a5406ea548af0214a093d4..5f63462032245655b8df990c83c5d7312015c089 100644 --- a/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/entry/src/ohosTest/module.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/NdkNativeImage/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/NdkNativeImage/hvigor/hvigor-config.json5 index e0bd0d82696bcd6337fc106180834b6a9ac56a5d..06b2783670a348f95533b352c1ceda909a842bbc 100644 --- a/code/BasicFeature/Native/NdkNativeImage/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/hvigor/hvigor-config.json5 @@ -1,22 +1,22 @@ -{ - "modelVersion": "5.0.0", - "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*/ - } -} +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/BasicFeature/Native/NdkNativeImage/oh-package.json5 b/code/BasicFeature/Native/NdkNativeImage/oh-package.json5 index fb70d168e165b1212a708f14edd3945c775d6543..d7622199b7ba60be5983122081f71ae9ebef0c4b 100644 --- a/code/BasicFeature/Native/NdkNativeImage/oh-package.json5 +++ b/code/BasicFeature/Native/NdkNativeImage/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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" - } -} +/* + * Copyright (c) 2024 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/NdkNativeWindow/AppScope/app.json5 b/code/BasicFeature/Native/NdkNativeWindow/AppScope/app.json5 index 291c099713f0c3306a1df7658599f1330d779738..6bc912cf462a6e1d2cb998fb6ffcd09bb655687f 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/AppScope/app.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.nativewindow", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.nativewindow", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/NdkNativeWindow/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/NdkNativeWindow/AppScope/resources/base/element/string.json index 60d4f01fbce87e606f4d9b828f8e6b5ea8a61b6b..0baed5e08b22c91e9a0d80a6f4c4523841009a25 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Native/NdkNativeWindow/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NdkNativeWindow" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NdkNativeWindow" + } + ] +} diff --git a/code/BasicFeature/Native/NdkNativeWindow/build-profile.json5 b/code/BasicFeature/Native/NdkNativeWindow/build-profile.json5 index 4a6f21f792fc0fc64f738d032513190c239af6c7..2d6762ac073c0ee46977fb9f0d64dd4a12e003d0 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/build-profile.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023-2024 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": 14, - "compatibleSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023-2024 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": 14, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/build-profile.json5 b/code/BasicFeature/Native/NdkNativeWindow/entry/build-profile.json5 index 423fe9012046aabf93d2f0ed569765f87a00005e..d6c9f348d4f6ebba93d1c7b22d2a5e872706a179 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/build-profile.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/build-profile.json5 @@ -1,35 +1,35 @@ -/* - * Copyright (c) 2023 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", - } - ] +/* + * Copyright (c) 2023 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", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/oh-package.json5 b/code/BasicFeature/Native/NdkNativeWindow/entry/oh-package.json5 index 0186d686344891edaa4c790d3150d113323071d3..0b39ac1a9a150b20ad9efa47be9c1eb0eda93434 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - } -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/CMakeLists.txt index bb496351119db64f18c3c934891394d66b0780a3..12428439790bbc8bdfcee90dc0e1df750eb463f4 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/CMakeLists.txt @@ -1,30 +1,30 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(NdkNativeWindow) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -include_directories(${NATIVERENDER_ROOT_PATH} - ${NATIVERENDER_ROOT_PATH}/include) -find_library( # Sets the name of the path variable. - hilog-lib - # Specifies the name of the NDK library that - # you want CMake to locate. - hilog_ndk.z ) -find_library( # Sets the name of the path variable. - libnapi-lib - # Specifies the name of the NDK library that - # you want CMake to locate. - ace_napi.z ) - -find_library( # Sets the name of the path variable. - libace-lib - # Specifies the name of the NDK library that - # you want CMake to locate. - ace_ndk.z ) -add_library(nativerender SHARED - plugin.cpp - NativeRender.cpp - NativeImageAdaptor.cpp) - +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(NdkNativeWindow) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) +find_library( # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z ) +find_library( # Sets the name of the path variable. + libnapi-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_napi.z ) + +find_library( # Sets the name of the path variable. + libace-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + ace_ndk.z ) +add_library(nativerender SHARED + plugin.cpp + NativeRender.cpp + NativeImageAdaptor.cpp) + target_link_libraries(nativerender PUBLIC ${hilog-lib} ${libnapi-lib} ${libace-lib} libnative_buffer.so libnative_window.so libnative_image.so libEGL.so libGLESv3.so libipc_capi.so) \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/types/libentry/oh-package.json5 index 124352dc7f48fca1b4b74c4d459e9060f1a8d65b..8c49cae229917b627c5b40b536d6e8115b59f080 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,6 +1,6 @@ -{ - "name": "libentry.so", - "types": "./index.d.ts", - "version": "", - "description": "Please describe the basic information." +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/entryability/EntryAbility.ts index 14b525aba9ebcef928dd72e040a92f34b6161d13..4504c55460d642403c98973198bd7805b53eb43d 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -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, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - 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'); - } -}; +/* + * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +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, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + 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/NdkNativeWindow/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets index ff69360f918b713f0d3a3ea141aa2f19c6572881..fdcaeb0de066b91df5a21ae09111c94ed9e2e02e 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/ets/pages/Index.ets @@ -1,185 +1,185 @@ -/* - * Copyright (c) 2023 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 NativeWindowContext from "../interface/NativeWindowContext"; -const TAG = '[Sample_NativeWindowAPI]'; - -@Entry -@Component -struct Index { - @State msg: string = 'OnFrameAvailable count:' - @State frameAvailableCount: number = 0; - @State producerCacheBufferCount: number = 0; - @State cacheBufferCount: number = 3; - @State bufferQueueSize: number = 3; - @State attachedBufferCount: number = 0; - @State frameFlushedCount: number = 0; - @State frameConsumerCount: number = 0; - @State isAutoConsumer: boolean = false; - private nativeWindowContext: NativeWindowContext | undefined = undefined; - private debounceTimer: number | null = null; - - // 防抖函数 - private debounceClick( action: () => void, delay: number = 500 ) { - if (this.debounceTimer) { - clearTimeout(this.debounceTimer); - } - this.debounceTimer = setTimeout(() => { - action(); - this.debounceTimer = null; - }, delay); - } - - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Row() { - Button('Change Color') - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.nativeWindowContext.DrawColor(); - } - }) - .width('40%') - Button('Change ScalingMode') - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.nativeWindowContext.ChangeScalingMode(); - } - }) - .width('50%') - } - Column() { - Row() { - XComponent({ id: 'xcomponentId', type: 'texture', libraryname: 'nativerender' }) - .margin({ bottom: 26 }) - .onLoad((nativeWindowContext) => { - this.nativeWindowContext = nativeWindowContext as NativeWindowContext; - }) - } - } - .width('512px') - .height('50%') - Button(`produce buffer count=${this.frameFlushedCount}`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - this.debounceClick(() => { - if (this.nativeWindowContext) { - console.log(TAG, "Produce Buffer"); - if (this.nativeWindowContext.ProduceBuffer() == 0) { - this.frameFlushedCount++; - } - setTimeout("GetCount", 1000); - } - }); - - }) - .height(40) - Row() { - Button(`auto consumer=${this.isAutoConsumer}`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.isAutoConsumer = this.nativeWindowContext.ChangeIsAutoConsumer(); - } - }) - .height(40) - Button(`consumer buffer count=${this.frameConsumerCount}`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - console.log(TAG, "Consumer Buffer"); - if (this.nativeWindowContext.ConsumerBuffer() == 0) { - this.frameConsumerCount++; - } - setTimeout("GetCount", 1000); - } - }) - .height(40) - } - Button(`update available buffer count=${this.frameAvailableCount}`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - console.log(TAG, "GetAvailableCount"); - this.frameAvailableCount = this.nativeWindowContext.GetAvailableCount(); - } - }) - .height(40) - Button() { - Column() { - Row() { - Text(`update bufferqueuesize =${this.bufferQueueSize}`) - .fontSize('14fp') - .fontWeight(500) - .fontColor(Color.White) - .margin({ bottom: 8 }) - } - Row() { - Text(`attachedbuffer =${this.attachedBufferCount},cachebuffer=${this.cacheBufferCount}`) - .fontSize('14fp') - .fontWeight(500) - .fontColor(Color.White) - } - } - .margin({ left: 12, right: 12, top: 8, bottom: 8 }) - } - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.bufferQueueSize = this.nativeWindowContext.GetBufferQueueSize(); - this.attachedBufferCount = this.nativeWindowContext.GetAttachBufferCount(); - this.cacheBufferCount = this.nativeWindowContext.GetCacheBufferCount(); - } - }) - .height(60) - Button(`attach buffer`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.nativeWindowContext.AttachBuffer(); - } - }) - .height(40) - Button(`dettach buffer`) - .fontSize('14fp') - .fontWeight(500) - .margin({ bottom: 24 }) - .onClick(() => { - if (this.nativeWindowContext) { - this.nativeWindowContext.DettachBuffer(); - } - }) - .height(40) - } - .width('100%') - .height('100%') - } -} +/* + * Copyright (c) 2023 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 NativeWindowContext from "../interface/NativeWindowContext"; +const TAG = '[Sample_NativeWindowAPI]'; + +@Entry +@Component +struct Index { + @State msg: string = 'OnFrameAvailable count:' + @State frameAvailableCount: number = 0; + @State producerCacheBufferCount: number = 0; + @State cacheBufferCount: number = 3; + @State bufferQueueSize: number = 3; + @State attachedBufferCount: number = 0; + @State frameFlushedCount: number = 0; + @State frameConsumerCount: number = 0; + @State isAutoConsumer: boolean = false; + private nativeWindowContext: NativeWindowContext | undefined = undefined; + private debounceTimer: number | null = null; + + // 防抖函数 + private debounceClick( action: () => void, delay: number = 500 ) { + if (this.debounceTimer) { + clearTimeout(this.debounceTimer); + } + this.debounceTimer = setTimeout(() => { + action(); + this.debounceTimer = null; + }, delay); + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Row() { + Button('Change Color') + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.nativeWindowContext.DrawColor(); + } + }) + .width('40%') + Button('Change ScalingMode') + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.nativeWindowContext.ChangeScalingMode(); + } + }) + .width('50%') + } + Column() { + Row() { + XComponent({ id: 'xcomponentId', type: 'texture', libraryname: 'nativerender' }) + .margin({ bottom: 26 }) + .onLoad((nativeWindowContext) => { + this.nativeWindowContext = nativeWindowContext as NativeWindowContext; + }) + } + } + .width('512px') + .height('50%') + Button(`produce buffer count=${this.frameFlushedCount}`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + this.debounceClick(() => { + if (this.nativeWindowContext) { + console.log(TAG, "Produce Buffer"); + if (this.nativeWindowContext.ProduceBuffer() == 0) { + this.frameFlushedCount++; + } + setTimeout("GetCount", 1000); + } + }); + + }) + .height(40) + Row() { + Button(`auto consumer=${this.isAutoConsumer}`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.isAutoConsumer = this.nativeWindowContext.ChangeIsAutoConsumer(); + } + }) + .height(40) + Button(`consumer buffer count=${this.frameConsumerCount}`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + console.log(TAG, "Consumer Buffer"); + if (this.nativeWindowContext.ConsumerBuffer() == 0) { + this.frameConsumerCount++; + } + setTimeout("GetCount", 1000); + } + }) + .height(40) + } + Button(`update available buffer count=${this.frameAvailableCount}`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + console.log(TAG, "GetAvailableCount"); + this.frameAvailableCount = this.nativeWindowContext.GetAvailableCount(); + } + }) + .height(40) + Button() { + Column() { + Row() { + Text(`update bufferqueuesize =${this.bufferQueueSize}`) + .fontSize('14fp') + .fontWeight(500) + .fontColor(Color.White) + .margin({ bottom: 8 }) + } + Row() { + Text(`attachedbuffer =${this.attachedBufferCount},cachebuffer=${this.cacheBufferCount}`) + .fontSize('14fp') + .fontWeight(500) + .fontColor(Color.White) + } + } + .margin({ left: 12, right: 12, top: 8, bottom: 8 }) + } + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.bufferQueueSize = this.nativeWindowContext.GetBufferQueueSize(); + this.attachedBufferCount = this.nativeWindowContext.GetAttachBufferCount(); + this.cacheBufferCount = this.nativeWindowContext.GetCacheBufferCount(); + } + }) + .height(60) + Button(`attach buffer`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.nativeWindowContext.AttachBuffer(); + } + }) + .height(40) + Button(`dettach buffer`) + .fontSize('14fp') + .fontWeight(500) + .margin({ bottom: 24 }) + .onClick(() => { + if (this.nativeWindowContext) { + this.nativeWindowContext.DettachBuffer(); + } + }) + .height(40) + } + .width('100%') + .height('100%') + } +} diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/module.json5 b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/module.json5 index 1354ce3a83200219232663cdef50028f9cca326b..b2099192e9b1dc8014676adca6447c1c0cd7e452 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/module.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/entry/src/ohosTest/module.json5 b/code/BasicFeature/Native/NdkNativeWindow/entry/src/ohosTest/module.json5 index 7e44e83cf9b7428c7a916f5782b9a6d85bf6d7da..e6a499c49efe53f1a5bab25638ce6b00f612a7d8 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Native/NdkNativeWindow/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/NdkNativeWindow/hvigor/hvigor-config.json5 index 9576f51e281cba55b809fb5aebbf1d9ac2dbba87..b38f010922f989038e9a6ee4007d658125e323d6 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/hvigor/hvigor-config.json5 @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2023-2024 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": { - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +/* + * Copyright (c) 2023-2024 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": { + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkNativeWindow/oh-package.json5 b/code/BasicFeature/Native/NdkNativeWindow/oh-package.json5 index 155173103a6a1f36bfa7b5a1c099e19a024aecfc..b0052ea878142c610715bdb76493274f9609a079 100644 --- a/code/BasicFeature/Native/NdkNativeWindow/oh-package.json5 +++ b/code/BasicFeature/Native/NdkNativeWindow/oh-package.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023-2024 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", - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.11" - }, - "author": "", - "name": "ndknativewindow", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} +/* + * Copyright (c) 2023-2024 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", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.11" + }, + "author": "", + "name": "ndknativewindow", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/AppScope/app.json5 b/code/BasicFeature/Native/NdkOpenGL/AppScope/app.json5 index f0cb834a0d74a90801e5a22d760549f558125d23..f6876c43a8fcad20cef83925310790de58f00993 100644 --- a/code/BasicFeature/Native/NdkOpenGL/AppScope/app.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.ndkopengl", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.ndkopengl", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/NdkOpenGL/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/NdkOpenGL/AppScope/resources/base/element/string.json index adcddd67a38e709abcbd7aa2c861acea6b85e5cc..d93de68f4f75ab156a67bb250c97a03fdeba7dbe 100644 --- a/code/BasicFeature/Native/NdkOpenGL/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Native/NdkOpenGL/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NdkOpenGL" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NdkOpenGL" + } + ] +} diff --git a/code/BasicFeature/Native/NdkOpenGL/build-profile.json5 b/code/BasicFeature/Native/NdkOpenGL/build-profile.json5 index e521599d362272f38dd7bd88b894e49be03365ba..11ce79f476ee89ea528243d4144120305a5421a2 100644 --- a/code/BasicFeature/Native/NdkOpenGL/build-profile.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/build-profile.json5 b/code/BasicFeature/Native/NdkOpenGL/entry/build-profile.json5 index 012ddb732c298113d2551030f23fc0884ac185c4..378d8419685ef4b08650a75c44da7be4b7cb583d 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/build-profile.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/entry/build-profile.json5 @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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": "", - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": "", + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/oh-package.json5 b/code/BasicFeature/Native/NdkOpenGL/entry/oh-package.json5 index f2c2bfc9a0613457310478e3aa6cec6d2a72e0bf..2bb0dcbd761f83568851671a295649c76e37df4e 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/entry/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@types/libtriangles_napi.so": "file:./src/main/cpp/type/libentry" - }, - "author": "AlgoIdeas", - "name": "entry", - "description": "Please describe the basic information.", - "main": "1.0.0", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@types/libtriangles_napi.so": "file:./src/main/cpp/type/libentry" + }, + "author": "AlgoIdeas", + "name": "entry", + "description": "Please describe the basic information.", + "main": "1.0.0", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/CMakeLists.txt index 89dd4165cd88f020ab9331e218f804351c3fee58..97bd6d04c187888e5d15487c18d2ee1904a5d682 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/CMakeLists.txt @@ -1,46 +1,46 @@ -# -# Copyright (c) 2023 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. -# - -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) - -# project -project(Tetrahedron) - -set(NATIVE_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -# include directory -include_directories(${NATIVE_ROOT_PATH} - ${NATIVE_ROOT_PATH}/include - ${NATIVE_ROOT_PATH}/include/util) - -# build shared library -add_library(tetrahedron_napi SHARED - module.cpp - app_napi.cpp - tetrahedron.cpp - napi_manager.cpp - napi_util.cpp) - -# link OpenHarmony native library (Use OpenGL) -target_link_libraries(tetrahedron_napi PUBLIC EGL) -target_link_libraries(tetrahedron_napi PUBLIC GLESv3) -target_link_libraries(tetrahedron_napi PUBLIC hilog_ndk.z) -target_link_libraries(tetrahedron_napi PUBLIC ace_ndk.z) -target_link_libraries(tetrahedron_napi PUBLIC ace_napi.z) -target_link_libraries(tetrahedron_napi PUBLIC libc++.a) -target_link_libraries(tetrahedron_napi PUBLIC z) -target_link_libraries(tetrahedron_napi PUBLIC uv) -target_link_libraries(tetrahedron_napi PUBLIC libace_napi.z.so) +# +# Copyright (c) 2023 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. +# + +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) + +# project +project(Tetrahedron) + +set(NATIVE_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +# include directory +include_directories(${NATIVE_ROOT_PATH} + ${NATIVE_ROOT_PATH}/include + ${NATIVE_ROOT_PATH}/include/util) + +# build shared library +add_library(tetrahedron_napi SHARED + module.cpp + app_napi.cpp + tetrahedron.cpp + napi_manager.cpp + napi_util.cpp) + +# link OpenHarmony native library (Use OpenGL) +target_link_libraries(tetrahedron_napi PUBLIC EGL) +target_link_libraries(tetrahedron_napi PUBLIC GLESv3) +target_link_libraries(tetrahedron_napi PUBLIC hilog_ndk.z) +target_link_libraries(tetrahedron_napi PUBLIC ace_ndk.z) +target_link_libraries(tetrahedron_napi PUBLIC ace_napi.z) +target_link_libraries(tetrahedron_napi PUBLIC libc++.a) +target_link_libraries(tetrahedron_napi PUBLIC z) +target_link_libraries(tetrahedron_napi PUBLIC uv) +target_link_libraries(tetrahedron_napi PUBLIC libace_napi.z.so) diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/tetrahedron.h b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/tetrahedron.h index 1d533b9ec1551a02f3ddda6e9443fc9f6cd290fa..87c10a04dd7fb5a91b768bdca761e542f2ac9532 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/tetrahedron.h +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/tetrahedron.h @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2023 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 TETRAHEDRON_H -#define TETRAHEDRON_H - -#include -#include -#include - -#include -#include - -#define TRIANGLES_POINT 3 -#define TETRAHEDRON_POINT 12 - -class Tetrahedron { -public: - explicit Tetrahedron(std::string& id) : id(id) {}; - int32_t Init(void* windowHandle, int windowWidth, int windowHeight); - void Update(float angleXOffset, float angleYOffset); - float GetAngleX(void); - float GetAngleY(void); - int32_t Quit(void); - -public: - std::string id; - -private: - GLuint LoadShader(GLenum type, const char *shaderSrc); - GLuint CreateProgram(const char *vertexShader, const char *fragShader); - - EGLNativeWindowType mEglWindow; - EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; - EGLConfig mEGLConfig = nullptr; - EGLContext mEGLContext = EGL_NO_CONTEXT; - EGLContext mSharedEGLContext = EGL_NO_CONTEXT; - EGLSurface mEGLSurface = nullptr; - GLuint mProgramHandle; - float angleX = 30.0; /* default X angle */ - float angleY = 45.0; /* default Y angle */ - - GLint mRotationLocation; - GLint mTranslationLocation; - GLint mMoveOriginLocation; -}; - -#endif /* TETRAHEDRON_H */ +/* + * Copyright (c) 2023 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 TETRAHEDRON_H +#define TETRAHEDRON_H + +#include +#include +#include + +#include +#include + +#define TRIANGLES_POINT 3 +#define TETRAHEDRON_POINT 12 + +class Tetrahedron { +public: + explicit Tetrahedron(std::string& id) : id(id) {}; + int32_t Init(void* windowHandle, int windowWidth, int windowHeight); + void Update(float angleXOffset, float angleYOffset); + float GetAngleX(void); + float GetAngleY(void); + int32_t Quit(void); + +public: + std::string id; + +private: + GLuint LoadShader(GLenum type, const char *shaderSrc); + GLuint CreateProgram(const char *vertexShader, const char *fragShader); + + EGLNativeWindowType mEglWindow; + EGLDisplay mEGLDisplay = EGL_NO_DISPLAY; + EGLConfig mEGLConfig = nullptr; + EGLContext mEGLContext = EGL_NO_CONTEXT; + EGLContext mSharedEGLContext = EGL_NO_CONTEXT; + EGLSurface mEGLSurface = nullptr; + GLuint mProgramHandle; + float angleX = 30.0; /* default X angle */ + float angleY = 45.0; /* default Y angle */ + + GLint mRotationLocation; + GLint mTranslationLocation; + GLint mMoveOriginLocation; +}; + +#endif /* TETRAHEDRON_H */ diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/log.h b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/log.h index 774fe5979cb770209ed960073f96f7c782e7227c..05e5df65d7ffb5c598b78fffeb4776e7bd054503 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/log.h +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/log.h @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2023 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 LOG_H -#define LOG_H - -#include - -#ifndef LOGI -#define LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) -#endif - -#ifndef LOGD -#define LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) -#endif - -#ifndef LOGW -#define LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) -#endif - -#ifndef LOGE -#define LOGE(...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) -#endif +/* + * Copyright (c) 2023 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 LOG_H +#define LOG_H + +#include + +#ifndef LOGI +#define LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) +#endif + +#ifndef LOGD +#define LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) +#endif + +#ifndef LOGW +#define LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) +#endif + +#ifndef LOGE +#define LOGE(...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "[OpenGL]", __VA_ARGS__)) +#endif #endif // _LOG_H_ \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/napi_manager.h b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/napi_manager.h index 0f8176d991bd6c33d3076cbfaedef254bdb682d0..de81eee3e1e9524efbaa15c9b735445a163f4ac9 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/napi_manager.h +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/include/util/napi_manager.h @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2023 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 NAPI_MANAGER_H -#define NAPI_MANAGER_H - -#include -#include - -#include -#include -#include - -#include "native_common.h" -#include "app_napi.h" - -class NapiManager { -public: - ~NapiManager() {} - - static NapiManager* GetInstance() - { - return &NapiManager::manager_; - } - - static napi_value GetContext(napi_env env, napi_callback_info info); - - /**APP Lifecycle**/ - static napi_value NapiOnCreate(napi_env env, napi_callback_info info); - static napi_value NapiOnShow(napi_env env, napi_callback_info info); - static napi_value NapiOnHide(napi_env env, napi_callback_info info); - static napi_value NapiOnDestroy(napi_env env, napi_callback_info info); - - void OnCreateNative(napi_env env, uv_loop_t* loop); - void OnShowNative(); - void OnHideNative(); - void OnDestroyNative(); - - /**JS Page Lifecycle**/ - static napi_value NapiOnPageShow(napi_env env, napi_callback_info info); - static napi_value NapiOnPageHide(napi_env env, napi_callback_info info); - - void OnPageShowNative(); - void OnPageHideNative(); - - OH_NativeXComponent* GetNativeXComponent(std::string& id); - void SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent); - AppNapi* GetApp(std::string& id); - -public: - // Napi export - bool Export(napi_env env, napi_value exports); - -public: - napi_env mainEnv_ = nullptr; - uv_loop_t* mainLoop_ = nullptr; - uv_async_t mainOnMessageSignal_ {}; - -private: - static void MainOnMessage(const uv_async_t* req); - static NapiManager manager_; - - std::string id_; - std::unordered_map nativeXComponentMap_; - std::unordered_map appNapiMap_; -}; - -#endif // PLUGIN_MANAGER_H +/* + * Copyright (c) 2023 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 NAPI_MANAGER_H +#define NAPI_MANAGER_H + +#include +#include + +#include +#include +#include + +#include "native_common.h" +#include "app_napi.h" + +class NapiManager { +public: + ~NapiManager() {} + + static NapiManager* GetInstance() + { + return &NapiManager::manager_; + } + + static napi_value GetContext(napi_env env, napi_callback_info info); + + /**APP Lifecycle**/ + static napi_value NapiOnCreate(napi_env env, napi_callback_info info); + static napi_value NapiOnShow(napi_env env, napi_callback_info info); + static napi_value NapiOnHide(napi_env env, napi_callback_info info); + static napi_value NapiOnDestroy(napi_env env, napi_callback_info info); + + void OnCreateNative(napi_env env, uv_loop_t* loop); + void OnShowNative(); + void OnHideNative(); + void OnDestroyNative(); + + /**JS Page Lifecycle**/ + static napi_value NapiOnPageShow(napi_env env, napi_callback_info info); + static napi_value NapiOnPageHide(napi_env env, napi_callback_info info); + + void OnPageShowNative(); + void OnPageHideNative(); + + OH_NativeXComponent* GetNativeXComponent(std::string& id); + void SetNativeXComponent(std::string& id, OH_NativeXComponent* nativeXComponent); + AppNapi* GetApp(std::string& id); + +public: + // Napi export + bool Export(napi_env env, napi_value exports); + +public: + napi_env mainEnv_ = nullptr; + uv_loop_t* mainLoop_ = nullptr; + uv_async_t mainOnMessageSignal_ {}; + +private: + static void MainOnMessage(const uv_async_t* req); + static NapiManager manager_; + + std::string id_; + std::unordered_map nativeXComponentMap_; + std::unordered_map appNapiMap_; +}; + +#endif // PLUGIN_MANAGER_H diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/tetrahedron.cpp b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/tetrahedron.cpp index 828f60eb75ed98e6ebfc1847878cbd0f331bd84c..c1e077cb3c70f8dd6a6742632f9d97f46410f3ef 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/tetrahedron.cpp +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/tetrahedron.cpp @@ -1,349 +1,349 @@ -/* - * Copyright (c) 2023 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 -#include -#include -#include "log.h" -#include "tetrahedron.h" - -static char g_vertexShader[] = - "attribute vec4 a_pos;\n" - "attribute vec4 a_color;\n" - "attribute vec4 a_normal;\n" - "uniform vec3 u_lightColor;\n" - "uniform vec3 u_lightDirection;\n" - "uniform mat4 a_mx;\n" - "uniform mat4 a_my;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " float radian = radians(30.0);\n" - " float cos = cos(radian);\n" - " float sin = sin(radian);\n" - " gl_Position = a_mx * a_my * vec4(a_pos.x, a_pos.y, a_pos.z, 1.0);\n" - " vec3 normal = normalize((a_mx * a_my * a_normal).xyz);\n" - " float dot = max(dot(u_lightDirection, normal), 0.0);\n" - " vec3 reflectedLight = u_lightColor * a_color.rgb * dot;\n" - " v_color = vec4(reflectedLight, a_color.a);\n" - "}\n\0"; - -static char g_fragmentShader[] = - "precision mediump float;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " gl_FragColor = v_color;\n" - "}\n\0"; - -/* 创建顶点位置数据数组vertexData */ -static float g_vertexData[] = { - -0.75, -0.50, -0.43, 0.75, -0.50, -0.43, 0.00, -0.50, 0.87, 0.75, -0.50, -0.43, - 0.00, -0.50, 0.87, 0.00, 1.00, 0.00, 0.00, -0.50, 0.87, 0.00, 1.00, 0.00, - -0.75, -0.50, -0.43, 0.00, 1.00, 0.00, -0.75, -0.50, -0.43, 0.75, -0.50, -0.43, -}; - -/* 创建顶点颜色数组colorData */ -static float g_colorData[] = { - 1, 0, 0, 1, 0, 0, 1, 0, 0, /* 红色——面1 */ - 1, 0, 0, 1, 0, 0, 1, 0, 0, /* 红色——面2 */ - 1, 0, 0, 1, 0, 0, 1, 0, 0, /* 红色——面3 */ - 1, 0, 0, 1, 0, 0, 1, 0, 0 /* 红色——面4 */ -}; - -/* 顶点法向量数组normalData */ -static float g_normalData[] = { - 0.00, -1.00, 0.00, 0.00, -1.00, 0.00, 0.00, -1.00, 0.00, -0.83, -0.28, -0.48, - -0.83, -0.28, -0.48, -0.83, -0.28, -0.48, -0.83, 0.28, 0.48, -0.83, 0.28, 0.48, - -0.83, 0.28, 0.48, 0.00, -0.28, 0.96, 0.00, -0.28, 0.96, 0.00, -0.28, 0.96, -}; - -namespace { - EGLConfig getConfig(int version, EGLDisplay eglDisplay) - { - int attribList[] = { - EGL_SURFACE_TYPE, - EGL_WINDOW_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_RENDERABLE_TYPE, - EGL_OPENGL_ES2_BIT, - EGL_NONE - }; - EGLConfig configs = NULL; - int configsNum; - - if (!eglChooseConfig(eglDisplay, attribList, &configs, 1, &configsNum)) { - LOGE("eglChooseConfig ERROR"); - return NULL; - } - - return configs; - } - - void enableVertexAttrib(GLuint index, float *data, int32_t len) - { - GLuint buffer; - glGenBuffers(1, &buffer); - glBindBuffer(GL_ARRAY_BUFFER, buffer); - glBufferData(GL_ARRAY_BUFFER, len, data, GL_STATIC_DRAW); - glVertexAttribPointer(index, TRIANGLES_POINT, GL_FLOAT, GL_FALSE, 0, 0); - glEnableVertexAttribArray(index); - return; - } -} - -GLuint Tetrahedron::LoadShader(GLenum type, const char *shaderSrc) -{ - GLuint shader; - GLint compiled; - - shader = glCreateShader(type); - if (shader == 0) { - LOGE("LoadShader shader error"); - return 0; - } - - glShaderSource(shader, 1, &shaderSrc, nullptr); - glCompileShader(shader); - - glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - - if (!compiled) { - GLint infoLen = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); - - if (infoLen > 1) { - std::string infoLog(infoLen, '\0'); - glGetShaderInfoLog(shader, infoLen, nullptr, (GLchar *)&infoLog); - LOGE("Error compiling shader:%{public}s\n", infoLog.c_str()); - } - - glDeleteShader(shader); - return 0; - } - - return shader; -} - -GLuint Tetrahedron::CreateProgram(const char *vertexShader, const char *fragShader) -{ - GLuint vertex; - GLuint fragment; - GLuint program; - GLint linked; - - vertex = LoadShader(GL_VERTEX_SHADER, vertexShader); - if (vertex == 0) { - LOGE("LoadShader: vertexShader error"); - return 0; - } - - fragment = LoadShader(GL_FRAGMENT_SHADER, fragShader); - if (fragment == 0) { - LOGE("LoadShader: fragShader error"); - glDeleteShader(vertex); - return 0; - } - - program = glCreateProgram(); - if (program == 0) { - LOGE("CreateProgram program error"); - glDeleteShader(vertex); - glDeleteShader(fragment); - return 0; - } - - glAttachShader(program, vertex); - glAttachShader(program, fragment); - glLinkProgram(program); - glGetProgramiv(program, GL_LINK_STATUS, &linked); - - if (!linked) { - LOGE("CreateProgram linked error"); - GLint infoLen = 0; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen); - if (infoLen > 1) { - std::string infoLog(infoLen, '\0'); - glGetProgramInfoLog(program, infoLen, nullptr, (GLchar *)&infoLog); - LOGE("Error linking program:%{public}s\n", infoLog.c_str()); - } - glDeleteShader(vertex); - glDeleteShader(fragment); - glDeleteProgram(program); - return 0; - } - glDeleteShader(vertex); - glDeleteShader(fragment); - - return program; -} - -int32_t Tetrahedron::Init(void *window, int32_t width, int32_t height) -{ - LOGI("Init window = %{public}p, w = %{public}d, h = %{public}d.", window, width, height); - mEglWindow = reinterpret_cast(window); - - mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (mEGLDisplay == EGL_NO_DISPLAY) { - LOGE("unable to get EGL display."); - return -1; - } - - EGLint eglMajVers, eglMinVers; - if (!eglInitialize(mEGLDisplay, &eglMajVers, &eglMinVers)) { - mEGLDisplay = EGL_NO_DISPLAY; - LOGE("unable to initialize display"); - return -1; - } - - int version = 3; - mEGLConfig = getConfig(version, mEGLDisplay); - if (mEGLConfig == nullptr) { - LOGE("GLContextInit config ERROR"); - return -1; - } - - EGLint winAttribs[] = {EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR, EGL_NONE}; - if (mEglWindow) { - mEGLSurface = eglCreateWindowSurface(mEGLDisplay, mEGLConfig, mEglWindow, winAttribs); - if (mEGLSurface == nullptr) { - LOGE("eglCreateContext eglSurface is null"); - return -1; - } - } - - /* Create EGLContext from */ - int attrib3_list[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - - mEGLContext = eglCreateContext(mEGLDisplay, mEGLConfig, mSharedEGLContext, attrib3_list); - if (!eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) { - LOGE("eglMakeCurrent error = %{public}d", eglGetError()); - } - - mProgramHandle = CreateProgram(g_vertexShader, g_fragmentShader); - if (!mProgramHandle) { - LOGE("Could not create CreateProgram"); - return -1; - } - - LOGI("Init success."); - - return 0; -} - -void Tetrahedron::Update(float angleXOffset, float angleYOffset) -{ - const float pi = 3.141592; - - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - glUseProgram(mProgramHandle); - - GLint aPos = glGetAttribLocation(mProgramHandle, "a_pos"); - GLint aColor = glGetAttribLocation(mProgramHandle, "a_color"); - GLint aNormal = glGetAttribLocation(mProgramHandle, "a_normal"); - GLint uLightColor = glGetUniformLocation(mProgramHandle, "u_lightColor"); - GLint uLightDirection = glGetUniformLocation(mProgramHandle, "u_lightDirection"); - GLint aMx = glGetUniformLocation(mProgramHandle, "a_mx"); - GLint aMy = glGetUniformLocation(mProgramHandle, "a_my"); - - angleX = angleXOffset; - angleY = angleYOffset; - - /* y轴旋转度 */ - float radianY = (angleY * pi) / 180.0; - float cosY = cosf(radianY); - float sinY = sinf(radianY); - float myArr[] = { - cosY, 0, -sinY, 0, - 0, 1, 0, 0, - sinY, 0, cosY, 0, - 0, 0, 0, 1 - }; - - glUniformMatrix4fv(aMy, 1, false, myArr); - - /* x轴旋转度 */ - float radianX = (angleX * pi) / 180.0; - float cosX = cosf(radianX); - float sinX = sinf(radianX); - float mxArr[] = { - 1, 0, 0, 0, 0, cosX, -sinX, 0, 0, sinX, cosX, 0, 0, 0, 0, 1 - }; - - glUniformMatrix4fv(aMx, 1, false, mxArr); - - /* 给平行光传入颜色和方向数据,RGB(1,1,1),单位向量(x,y,z) */ - glUniform3f(uLightColor, 1.0, 1.0, 1.0); - - /* 保证向量(x,y,z)的长度为1,即单位向量 */ - float x = 2.0 / sqrt(15); - float y = 2.0 / sqrt(15); - float z = 3.0 / sqrt(15); - - glUniform3f(uLightDirection, x, -y, z); - - /* 创建缓冲区buffer,传入顶点位置数据g_vertexData */ - enableVertexAttrib(aPos, g_vertexData, sizeof(g_vertexData)); - enableVertexAttrib(aNormal, g_normalData, sizeof(g_normalData)); - /* 创建缓冲区colorBuffer,传入顶点颜色数据g_colorData */ - enableVertexAttrib(aColor, g_colorData, sizeof(g_colorData)); - - /* 执行绘制之前,一定要开启深度测试,以免颜色混乱 */ - glEnable(GL_DEPTH_TEST); - - /* 执行绘制并更新 */ - glDrawArrays(GL_TRIANGLES, 0, TETRAHEDRON_POINT); - eglSwapBuffers(mEGLDisplay, mEGLSurface); -} - -float Tetrahedron::GetAngleX() -{ - return angleX; -} - -float Tetrahedron::GetAngleY() -{ - return angleY; -} - -int32_t Tetrahedron::Quit(void) -{ - EGLBoolean ret = eglDestroySurface(mEGLDisplay, mEGLSurface); - if (!ret) { - LOGW("eglDestroySurface failure."); - } - - ret = eglDestroyContext(mEGLDisplay, mEGLContext); - if (!ret) { - LOGW("eglDestroyContext failure."); - } - - ret = eglTerminate(mEGLDisplay); - if (!ret) { - LOGW("eglTerminate failure."); - } - - mEGLSurface = NULL; - mEGLContext = NULL; - mEGLDisplay = NULL; - - LOGE("Quit success."); - return 0; -} +/* + * Copyright (c) 2023 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 +#include +#include +#include "log.h" +#include "tetrahedron.h" + +static char g_vertexShader[] = + "attribute vec4 a_pos;\n" + "attribute vec4 a_color;\n" + "attribute vec4 a_normal;\n" + "uniform vec3 u_lightColor;\n" + "uniform vec3 u_lightDirection;\n" + "uniform mat4 a_mx;\n" + "uniform mat4 a_my;\n" + "varying vec4 v_color;\n" + "void main() {\n" + " float radian = radians(30.0);\n" + " float cos = cos(radian);\n" + " float sin = sin(radian);\n" + " gl_Position = a_mx * a_my * vec4(a_pos.x, a_pos.y, a_pos.z, 1.0);\n" + " vec3 normal = normalize((a_mx * a_my * a_normal).xyz);\n" + " float dot = max(dot(u_lightDirection, normal), 0.0);\n" + " vec3 reflectedLight = u_lightColor * a_color.rgb * dot;\n" + " v_color = vec4(reflectedLight, a_color.a);\n" + "}\n\0"; + +static char g_fragmentShader[] = + "precision mediump float;\n" + "varying vec4 v_color;\n" + "void main() {\n" + " gl_FragColor = v_color;\n" + "}\n\0"; + +/* 创建顶点位置数据数组vertexData */ +static float g_vertexData[] = { + -0.75, -0.50, -0.43, 0.75, -0.50, -0.43, 0.00, -0.50, 0.87, 0.75, -0.50, -0.43, + 0.00, -0.50, 0.87, 0.00, 1.00, 0.00, 0.00, -0.50, 0.87, 0.00, 1.00, 0.00, + -0.75, -0.50, -0.43, 0.00, 1.00, 0.00, -0.75, -0.50, -0.43, 0.75, -0.50, -0.43, +}; + +/* 创建顶点颜色数组colorData */ +static float g_colorData[] = { + 1, 0, 0, 1, 0, 0, 1, 0, 0, /* 红色——面1 */ + 1, 0, 0, 1, 0, 0, 1, 0, 0, /* 红色——面2 */ + 1, 0, 0, 1, 0, 0, 1, 0, 0, /* 红色——面3 */ + 1, 0, 0, 1, 0, 0, 1, 0, 0 /* 红色——面4 */ +}; + +/* 顶点法向量数组normalData */ +static float g_normalData[] = { + 0.00, -1.00, 0.00, 0.00, -1.00, 0.00, 0.00, -1.00, 0.00, -0.83, -0.28, -0.48, + -0.83, -0.28, -0.48, -0.83, -0.28, -0.48, -0.83, 0.28, 0.48, -0.83, 0.28, 0.48, + -0.83, 0.28, 0.48, 0.00, -0.28, 0.96, 0.00, -0.28, 0.96, 0.00, -0.28, 0.96, +}; + +namespace { + EGLConfig getConfig(int version, EGLDisplay eglDisplay) + { + int attribList[] = { + EGL_SURFACE_TYPE, + EGL_WINDOW_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_RENDERABLE_TYPE, + EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + EGLConfig configs = NULL; + int configsNum; + + if (!eglChooseConfig(eglDisplay, attribList, &configs, 1, &configsNum)) { + LOGE("eglChooseConfig ERROR"); + return NULL; + } + + return configs; + } + + void enableVertexAttrib(GLuint index, float *data, int32_t len) + { + GLuint buffer; + glGenBuffers(1, &buffer); + glBindBuffer(GL_ARRAY_BUFFER, buffer); + glBufferData(GL_ARRAY_BUFFER, len, data, GL_STATIC_DRAW); + glVertexAttribPointer(index, TRIANGLES_POINT, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(index); + return; + } +} + +GLuint Tetrahedron::LoadShader(GLenum type, const char *shaderSrc) +{ + GLuint shader; + GLint compiled; + + shader = glCreateShader(type); + if (shader == 0) { + LOGE("LoadShader shader error"); + return 0; + } + + glShaderSource(shader, 1, &shaderSrc, nullptr); + glCompileShader(shader); + + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); + + if (!compiled) { + GLint infoLen = 0; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); + + if (infoLen > 1) { + std::string infoLog(infoLen, '\0'); + glGetShaderInfoLog(shader, infoLen, nullptr, (GLchar *)&infoLog); + LOGE("Error compiling shader:%{public}s\n", infoLog.c_str()); + } + + glDeleteShader(shader); + return 0; + } + + return shader; +} + +GLuint Tetrahedron::CreateProgram(const char *vertexShader, const char *fragShader) +{ + GLuint vertex; + GLuint fragment; + GLuint program; + GLint linked; + + vertex = LoadShader(GL_VERTEX_SHADER, vertexShader); + if (vertex == 0) { + LOGE("LoadShader: vertexShader error"); + return 0; + } + + fragment = LoadShader(GL_FRAGMENT_SHADER, fragShader); + if (fragment == 0) { + LOGE("LoadShader: fragShader error"); + glDeleteShader(vertex); + return 0; + } + + program = glCreateProgram(); + if (program == 0) { + LOGE("CreateProgram program error"); + glDeleteShader(vertex); + glDeleteShader(fragment); + return 0; + } + + glAttachShader(program, vertex); + glAttachShader(program, fragment); + glLinkProgram(program); + glGetProgramiv(program, GL_LINK_STATUS, &linked); + + if (!linked) { + LOGE("CreateProgram linked error"); + GLint infoLen = 0; + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLen); + if (infoLen > 1) { + std::string infoLog(infoLen, '\0'); + glGetProgramInfoLog(program, infoLen, nullptr, (GLchar *)&infoLog); + LOGE("Error linking program:%{public}s\n", infoLog.c_str()); + } + glDeleteShader(vertex); + glDeleteShader(fragment); + glDeleteProgram(program); + return 0; + } + glDeleteShader(vertex); + glDeleteShader(fragment); + + return program; +} + +int32_t Tetrahedron::Init(void *window, int32_t width, int32_t height) +{ + LOGI("Init window = %{public}p, w = %{public}d, h = %{public}d.", window, width, height); + mEglWindow = reinterpret_cast(window); + + mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (mEGLDisplay == EGL_NO_DISPLAY) { + LOGE("unable to get EGL display."); + return -1; + } + + EGLint eglMajVers, eglMinVers; + if (!eglInitialize(mEGLDisplay, &eglMajVers, &eglMinVers)) { + mEGLDisplay = EGL_NO_DISPLAY; + LOGE("unable to initialize display"); + return -1; + } + + int version = 3; + mEGLConfig = getConfig(version, mEGLDisplay); + if (mEGLConfig == nullptr) { + LOGE("GLContextInit config ERROR"); + return -1; + } + + EGLint winAttribs[] = {EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR, EGL_NONE}; + if (mEglWindow) { + mEGLSurface = eglCreateWindowSurface(mEGLDisplay, mEGLConfig, mEglWindow, winAttribs); + if (mEGLSurface == nullptr) { + LOGE("eglCreateContext eglSurface is null"); + return -1; + } + } + + /* Create EGLContext from */ + int attrib3_list[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + mEGLContext = eglCreateContext(mEGLDisplay, mEGLConfig, mSharedEGLContext, attrib3_list); + if (!eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) { + LOGE("eglMakeCurrent error = %{public}d", eglGetError()); + } + + mProgramHandle = CreateProgram(g_vertexShader, g_fragmentShader); + if (!mProgramHandle) { + LOGE("Could not create CreateProgram"); + return -1; + } + + LOGI("Init success."); + + return 0; +} + +void Tetrahedron::Update(float angleXOffset, float angleYOffset) +{ + const float pi = 3.141592; + + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + glUseProgram(mProgramHandle); + + GLint aPos = glGetAttribLocation(mProgramHandle, "a_pos"); + GLint aColor = glGetAttribLocation(mProgramHandle, "a_color"); + GLint aNormal = glGetAttribLocation(mProgramHandle, "a_normal"); + GLint uLightColor = glGetUniformLocation(mProgramHandle, "u_lightColor"); + GLint uLightDirection = glGetUniformLocation(mProgramHandle, "u_lightDirection"); + GLint aMx = glGetUniformLocation(mProgramHandle, "a_mx"); + GLint aMy = glGetUniformLocation(mProgramHandle, "a_my"); + + angleX = angleXOffset; + angleY = angleYOffset; + + /* y轴旋转度 */ + float radianY = (angleY * pi) / 180.0; + float cosY = cosf(radianY); + float sinY = sinf(radianY); + float myArr[] = { + cosY, 0, -sinY, 0, + 0, 1, 0, 0, + sinY, 0, cosY, 0, + 0, 0, 0, 1 + }; + + glUniformMatrix4fv(aMy, 1, false, myArr); + + /* x轴旋转度 */ + float radianX = (angleX * pi) / 180.0; + float cosX = cosf(radianX); + float sinX = sinf(radianX); + float mxArr[] = { + 1, 0, 0, 0, 0, cosX, -sinX, 0, 0, sinX, cosX, 0, 0, 0, 0, 1 + }; + + glUniformMatrix4fv(aMx, 1, false, mxArr); + + /* 给平行光传入颜色和方向数据,RGB(1,1,1),单位向量(x,y,z) */ + glUniform3f(uLightColor, 1.0, 1.0, 1.0); + + /* 保证向量(x,y,z)的长度为1,即单位向量 */ + float x = 2.0 / sqrt(15); + float y = 2.0 / sqrt(15); + float z = 3.0 / sqrt(15); + + glUniform3f(uLightDirection, x, -y, z); + + /* 创建缓冲区buffer,传入顶点位置数据g_vertexData */ + enableVertexAttrib(aPos, g_vertexData, sizeof(g_vertexData)); + enableVertexAttrib(aNormal, g_normalData, sizeof(g_normalData)); + /* 创建缓冲区colorBuffer,传入顶点颜色数据g_colorData */ + enableVertexAttrib(aColor, g_colorData, sizeof(g_colorData)); + + /* 执行绘制之前,一定要开启深度测试,以免颜色混乱 */ + glEnable(GL_DEPTH_TEST); + + /* 执行绘制并更新 */ + glDrawArrays(GL_TRIANGLES, 0, TETRAHEDRON_POINT); + eglSwapBuffers(mEGLDisplay, mEGLSurface); +} + +float Tetrahedron::GetAngleX() +{ + return angleX; +} + +float Tetrahedron::GetAngleY() +{ + return angleY; +} + +int32_t Tetrahedron::Quit(void) +{ + EGLBoolean ret = eglDestroySurface(mEGLDisplay, mEGLSurface); + if (!ret) { + LOGW("eglDestroySurface failure."); + } + + ret = eglDestroyContext(mEGLDisplay, mEGLContext); + if (!ret) { + LOGW("eglDestroyContext failure."); + } + + ret = eglTerminate(mEGLDisplay); + if (!ret) { + LOGW("eglTerminate failure."); + } + + mEGLSurface = NULL; + mEGLContext = NULL; + mEGLDisplay = NULL; + + LOGE("Quit success."); + return 0; +} diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/oh-package.json5 b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/oh-package.json5 index ed7780160f55c912801b56c5c5d40ccfa2aeb36c..02724aa41e71153520a5830c05dc8392d9cd6cf1 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/oh-package.json5 @@ -1,6 +1,6 @@ -{ - "name": "libtetrahedron_napi.so", - "types": "./tetrahedron_napi.d.ts", - "version": "", - "description": "Please describe the basic information." +{ + "name": "libtetrahedron_napi.so", + "types": "./tetrahedron_napi.d.ts", + "version": "", + "description": "Please describe the basic information." } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/tetrahedron_napi.d.ts b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/tetrahedron_napi.d.ts index 1c3ec45f997942eeea747b54a10c42c707edfb9a..c307b401986ce3d4777fe7c2a579035734188217 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/tetrahedron_napi.d.ts +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/cpp/type/libentry/tetrahedron_napi.d.ts @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2023 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. - */ - -//传入x,y偏移量并返回x,y旋转角 +/* + * Copyright (c) 2023 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. + */ + +//传入x,y偏移量并返回x,y旋转角 export const updateAngle:(offsetX:number, offsetY:number)=>Array; \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/pages/Index.ets index 5654e55f0f203979f2440682a3fb6accbd971cf2..83339274648b710f90a9c5ebbb0871bad62c5cae 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/pages/Index.ets @@ -1,96 +1,96 @@ -/* - * Copyright (c) 2023 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 { Logger } from '../utils/Logger'; -import tetrahedron_napi from 'libtetrahedron_napi.so' - -@Entry -@Component -struct Index { - @State angleArray: Array = new Array(); - @State shaftRotation: string = ''; - private xcomponentId = 'tetrahedron'; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.All }); - - async aboutToAppear() { - Logger.info('aboutToAppear'); - this.angleArray[0] = 30; - this.angleArray[1] = 45; - let resourceManager = getContext(this).resourceManager; - this.shaftRotation = await resourceManager.getStringValue($r('app.string.shaftRotation').id); - } - - build() { - Column() { - Text($r('app.string.EntryAbility_desc')) - .fontSize($r('app.float.head_font_24')) - .lineHeight($r('app.float.wh_value_33')) - .fontFamily('HarmonyHeiTi-Bold') - .fontWeight(FontWeight.Bold) - .fontColor($r('app.color.font_color_182431')) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .textAlign(TextAlign.Start) - .margin({ top: $r('app.float.wh_value_13'), bottom: $r('app.float.wh_value_15') }) - - Text('X ' + this.shaftRotation + ':' + this.angleArray[0].toString() - + '°\nY ' + this.shaftRotation + ':' + this.angleArray[1].toString() + '°') - .fontSize($r('app.float.head_font_24')) - .lineHeight($r('app.float.wh_value_33')) - .fontFamily('HarmonyHeiTi-Bold') - .fontWeight(FontWeight.Bold) - .fontColor($r('app.color.font_color_182431')) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .textAlign(TextAlign.Start) - .margin({ top: $r('app.float.wh_value_13'), bottom: $r('app.float.wh_value_15') }) - - Column() { - XComponent({ id: this.xcomponentId, type: 'surface', libraryname: 'tetrahedron_napi' }) - .onLoad(() => { - Logger.info('onLoad'); - }) - .width($r('app.float.wh_value_360')) - .height($r('app.float.wh_value_360')) - .key('tetrahedron') - .onDestroy(() => { - Logger.info('onDestroy'); - }) - .id('xComponent') - .backgroundColor(Color.White) - } - .justifyContent(FlexAlign.SpaceAround) - .alignItems(HorizontalAlign.Center) - .height('80%') - .width('100%') - .backgroundColor(Color.White) - .borderRadius(24) - } - .gesture( - PanGesture(this.panOption) - .onActionStart((event: GestureEvent) => { - Logger.info('Gesture onActionStart'); - }) - .onActionUpdate((event: GestureEvent) => { - this.angleArray = tetrahedron_napi.updateAngle(event.offsetX, event.offsetY); - Logger.info('Gesture onActionUpdate : offSet ' + event.offsetX + ',' + event.offsetY); - }) - .onActionEnd(() => { - Logger.info('Gesture onActionEnd'); - }) - ) - .padding(12) - .backgroundColor('#f1f3f5') - .height('100%') - } -} +/* + * Copyright (c) 2023 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 { Logger } from '../utils/Logger'; +import tetrahedron_napi from 'libtetrahedron_napi.so' + +@Entry +@Component +struct Index { + @State angleArray: Array = new Array(); + @State shaftRotation: string = ''; + private xcomponentId = 'tetrahedron'; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.All }); + + async aboutToAppear() { + Logger.info('aboutToAppear'); + this.angleArray[0] = 30; + this.angleArray[1] = 45; + let resourceManager = getContext(this).resourceManager; + this.shaftRotation = await resourceManager.getStringValue($r('app.string.shaftRotation').id); + } + + build() { + Column() { + Text($r('app.string.EntryAbility_desc')) + .fontSize($r('app.float.head_font_24')) + .lineHeight($r('app.float.wh_value_33')) + .fontFamily('HarmonyHeiTi-Bold') + .fontWeight(FontWeight.Bold) + .fontColor($r('app.color.font_color_182431')) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .textAlign(TextAlign.Start) + .margin({ top: $r('app.float.wh_value_13'), bottom: $r('app.float.wh_value_15') }) + + Text('X ' + this.shaftRotation + ':' + this.angleArray[0].toString() + + '°\nY ' + this.shaftRotation + ':' + this.angleArray[1].toString() + '°') + .fontSize($r('app.float.head_font_24')) + .lineHeight($r('app.float.wh_value_33')) + .fontFamily('HarmonyHeiTi-Bold') + .fontWeight(FontWeight.Bold) + .fontColor($r('app.color.font_color_182431')) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .textAlign(TextAlign.Start) + .margin({ top: $r('app.float.wh_value_13'), bottom: $r('app.float.wh_value_15') }) + + Column() { + XComponent({ id: this.xcomponentId, type: 'surface', libraryname: 'tetrahedron_napi' }) + .onLoad(() => { + Logger.info('onLoad'); + }) + .width($r('app.float.wh_value_360')) + .height($r('app.float.wh_value_360')) + .key('tetrahedron') + .onDestroy(() => { + Logger.info('onDestroy'); + }) + .id('xComponent') + .backgroundColor(Color.White) + } + .justifyContent(FlexAlign.SpaceAround) + .alignItems(HorizontalAlign.Center) + .height('80%') + .width('100%') + .backgroundColor(Color.White) + .borderRadius(24) + } + .gesture( + PanGesture(this.panOption) + .onActionStart((event: GestureEvent) => { + Logger.info('Gesture onActionStart'); + }) + .onActionUpdate((event: GestureEvent) => { + this.angleArray = tetrahedron_napi.updateAngle(event.offsetX, event.offsetY); + Logger.info('Gesture onActionUpdate : offSet ' + event.offsetX + ',' + event.offsetY); + }) + .onActionEnd(() => { + Logger.info('Gesture onActionEnd'); + }) + ) + .padding(12) + .backgroundColor('#f1f3f5') + .height('100%') + } +} diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/utils/Logger.ets b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/utils/Logger.ets index ae067ff53158a590a507b3df2142124095fb03f4..623661658880b6761f2fde19416402892a7e946b 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/utils/Logger.ets +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/ets/utils/Logger.ets @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class LoggerModel { - private domain: number - private prefix: string - private format: string = '%{public}s' - - constructor(prefix: string) { - this.prefix = prefix - this.domain = 0xFF00 - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args) - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args) - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args) - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args) - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class LoggerModel { + private domain: number + private prefix: string + private format: string = '%{public}s' + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xFF00 + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args) + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args) + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args) + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args) + } +} + export let Logger = new LoggerModel('[Sample_OpenGL]') \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/module.json5 b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/module.json5 index eed2be5236b8c50c4c4f0e56017369fc5db2f58e..9e973ce568047421c487dd12cefa24bad70c4023 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/module.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/resources/base/element/color.json index 721b881014fd057b2b96d8cd2c58786b98d17980..9974d136eea4cf62e78ccc91e6b249341b69b437 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/main/resources/base/element/color.json @@ -1,92 +1,92 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "color_333333_grey", - "value": "#333333" - }, - { - "name": "color_666666_grey", - "value": "#666666" - }, - { - "name": "color_999999_grey", - "value": "#999999" - }, - { - "name": "color_E3E3E3_grey", - "value": "#E3E3E3" - }, - { - "name": "color_D8D8D8_grey", - "value": "#D8D8D8" - }, - { - "name": "color_button_grey", - "value": "#1824310D" - }, - { - "name": "color_00000000_transparent", - "value": "#00000000" - }, - { - "name": "volume_bg_color", - "value": "#CCFFFFFF" - }, - { - "name": "white_bg_color", - "value": "#FFFFFF" - }, - { - "name": "font_color_182431", - "value": "#182431" - }, - { - "name": "font_color_007DFF", - "value": "#007DFF" - }, - { - "name": "toggle_selected_color_007DFF", - "value": "#007DFF" - }, - { - "name": "search_no_result_text_color", - "value": "$color:font_color_182431" - }, - { - "name": "search_result_text_color", - "value": "$color:font_color_182431" - }, - { - "name": "search_result_text_color_highlight", - "value": "$color:font_color_007DFF" - }, - { - "name": "bluetooth_text_color_highlight", - "value": "$color:font_color_007DFF" - }, - { - "name": "FAFAFA", - "value": "#FAFAFA" - }, - { - "name": "DCEAF9", - "value": "#DCEAF9" - }, - { - "name": "4C89F0", - "value": "#4C89F0" - }, - { - "name": "D1D0DB", - "value": "#D1D0DB" - }, - { - "name": "white", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "color_333333_grey", + "value": "#333333" + }, + { + "name": "color_666666_grey", + "value": "#666666" + }, + { + "name": "color_999999_grey", + "value": "#999999" + }, + { + "name": "color_E3E3E3_grey", + "value": "#E3E3E3" + }, + { + "name": "color_D8D8D8_grey", + "value": "#D8D8D8" + }, + { + "name": "color_button_grey", + "value": "#1824310D" + }, + { + "name": "color_00000000_transparent", + "value": "#00000000" + }, + { + "name": "volume_bg_color", + "value": "#CCFFFFFF" + }, + { + "name": "white_bg_color", + "value": "#FFFFFF" + }, + { + "name": "font_color_182431", + "value": "#182431" + }, + { + "name": "font_color_007DFF", + "value": "#007DFF" + }, + { + "name": "toggle_selected_color_007DFF", + "value": "#007DFF" + }, + { + "name": "search_no_result_text_color", + "value": "$color:font_color_182431" + }, + { + "name": "search_result_text_color", + "value": "$color:font_color_182431" + }, + { + "name": "search_result_text_color_highlight", + "value": "$color:font_color_007DFF" + }, + { + "name": "bluetooth_text_color_highlight", + "value": "$color:font_color_007DFF" + }, + { + "name": "FAFAFA", + "value": "#FAFAFA" + }, + { + "name": "DCEAF9", + "value": "#DCEAF9" + }, + { + "name": "4C89F0", + "value": "#4C89F0" + }, + { + "name": "D1D0DB", + "value": "#D1D0DB" + }, + { + "name": "white", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/entry/src/ohosTest/module.json5 b/code/BasicFeature/Native/NdkOpenGL/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/BasicFeature/Native/NdkOpenGL/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Native/NdkOpenGL/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/NdkOpenGL/hvigor/hvigor-config.json5 index ac737cf85f090c5de41b44bb39986e423bdc39fa..e75281b258e8cec776a34fd96a3c117c58afb9cb 100644 --- a/code/BasicFeature/Native/NdkOpenGL/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - } +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkOpenGL/oh-package.json5 b/code/BasicFeature/Native/NdkOpenGL/oh-package.json5 index d2e3b280b049edb21cfa9deab1bdfcd44a309bc0..567e91cea6cf9021ee1d6c4fc133fc10bb5d7016 100644 --- a/code/BasicFeature/Native/NdkOpenGL/oh-package.json5 +++ b/code/BasicFeature/Native/NdkOpenGL/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "NdkOpenGL", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "NdkOpenGL", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Native/NdkQoS/AppScope/app.json5 b/code/BasicFeature/Native/NdkQoS/AppScope/app.json5 index 835f4a6ae309839a1127a809bbc298815a576e16..677efa72eb9db1e8570f0badac590daa4fed2dc4 100644 --- a/code/BasicFeature/Native/NdkQoS/AppScope/app.json5 +++ b/code/BasicFeature/Native/NdkQoS/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.qossample", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.qossample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/NdkQoS/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/NdkQoS/AppScope/resources/base/element/string.json index 92f05a126af3e3bdaa63e58e1684d7782ed26d94..71f7d544aadc59a299e26532be96853152283cc3 100644 --- a/code/BasicFeature/Native/NdkQoS/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Native/NdkQoS/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "QoSSample" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "QoSSample" + } + ] +} diff --git a/code/BasicFeature/Native/NdkQoS/build-profile.json5 b/code/BasicFeature/Native/NdkQoS/build-profile.json5 index 6752bb170434e5ffcaefd52701dadad53d1f141f..0a3aa13e21be4c5a696e3d62ee824d295e3bfe37 100644 --- a/code/BasicFeature/Native/NdkQoS/build-profile.json5 +++ b/code/BasicFeature/Native/NdkQoS/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/* + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/BasicFeature/Native/NdkQoS/entry/build-profile.json5 b/code/BasicFeature/Native/NdkQoS/entry/build-profile.json5 index 1ee14651533f87a806fd52efd53d9105261fdf8e..43c59a2208ab2776cdcb0f71f08b3580cc087f57 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/build-profile.json5 +++ b/code/BasicFeature/Native/NdkQoS/entry/build-profile.json5 @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2024 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": [ - "armeabi-v7a", "arm64-v8a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} +/* + * Copyright (c) 2024 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": [ + "armeabi-v7a", "arm64-v8a" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} diff --git a/code/BasicFeature/Native/NdkQoS/entry/oh-package.json5 b/code/BasicFeature/Native/NdkQoS/entry/oh-package.json5 index b9c1d4cca76ac664388dd6b1cf96697184c5133b..54cb066266f9993f5a023f2ac5a8dfc5d2574643 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkQoS/entry/oh-package.json5 @@ -1,11 +1,11 @@ -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - } +{ + "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/NdkQoS/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/CMakeLists.txt index f2595825a79e823b1f95e995abcd71e57edbf0bf..9bcaac120f1c2f6fbb73c1c73691166589c054a7 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(rtbandwidth) - -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 main.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(rtbandwidth) + +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 main.cpp) target_link_libraries(entry libace_napi.z.so libqos.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/main.cpp b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/main.cpp index 759457b8e1dcf0af3998cc6897158ccaa767b916..8084c4f9d586eb731acbd4885f545215d231097f 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/main.cpp +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/main.cpp @@ -1,209 +1,209 @@ -/* - * Copyright (c) 2024 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 -#include -#include -#include -#include -#include -#include "napi/native_api.h" -#include "qos/qos.h" - -const unsigned int LOG_PRINT_DOMAIN = 0xFF00; -constexpr int DEPTH = 34; -constexpr int TASKS = 6; // 负载线程个数 -constexpr long long ONE = 1; -constexpr long long TWO = 2; -constexpr int BOUND = 20000; - -constexpr int MASK = 2; -constexpr int CPUS = 4; - -static bool g_addLoad = false; // 负载线程是否加载 -static double g_durationTime = 0; // 计算任务耗时时间 - -// 执行 斐波那契数列 计算 -long long DoFib(double n) -{ - if (n == ONE) { - return ONE; - } - - if (n == TWO) { - return TWO; - } - return DoFib(n - ONE) + DoFib(n - TWO); -} - -void SetQoS(QoS_Level level) -{ - // 设置当前线程的QoS等级为level - int ret = OH_QoS_SetThreadQoS(level); - if (!ret) { // ret等于0说明设置成功 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "set qos level success."); - // 查询当前的qos等级 - QoS_Level queryLevel = QoS_Level::QOS_DEFAULT; - ret = OH_QoS_GetThreadQoS(&queryLevel); - if (!ret) { // ret等于0说明查询成功 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "the qos level of current thread : %{public}d", - queryLevel); - } else { // 否则说明查询失败 - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "get qos level failed."); - return; - } - } else { // ret不等于0说明设置失败 - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "get level qos failed!"); - return; - } - - // 绑定到特定cpu - cpu_set_t mask; - CPU_SET(MASK, &mask); - if (sched_setaffinity(0, sizeof(mask), &mask) != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "bind work thread failed"); - } else { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "bind work thread success."); - } - - // 执行斐波那契数列计算任务 - auto startTime = std::chrono::system_clock::now(); - long long res = DoFib(DEPTH); // 执行斐波那契数列计算任务 - auto endTime = std::chrono::system_clock::now(); - g_durationTime = std::chrono::duration(endTime - startTime).count(); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "calculate res is: %{public}llu", res); - - // 重置线程QoS等级 - ret = OH_QoS_ResetThreadQoS(); - if (!ret) { // ret等于0说明重置成功 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "reset qos level success."); - } else { // 否则说明重置失败 - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "reset qos level failed!"); - return; - } - - // 在重置QoS后,再次查询,此时查询会失败 - QoS_Level queryLevelTwo; - ret = OH_QoS_GetThreadQoS(&queryLevelTwo); - if (!ret) { // 正常路径 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "the qos level after: %{public}d", queryLevelTwo); - return; - } else { // 异常路径 - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "query qos level failed after reset."); - return; - } -} - -// 负载任务 -void AddLoads(int n) -{ - int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_BACKGROUND); // 设置负载线程的QoS等级 - if (ret) { // ret不等于0说明设置失败 - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "set load thread QoS level failed."); - return; - } - - // 绑定到特定cpu - cpu_set_t mask; - CPU_SET(n, &mask); - if (sched_setaffinity(0, sizeof(mask), &mask) != 0) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "bind load thread failed"); - return; - } else { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "bind load threads success."); - } - - // 执行负载计算 - for (int i = 0; i < BOUND; i++) { - for (int j = 0; j < BOUND; j++) { - int x = (i + j) - n; - printf("%d", x); - } - } - // 重新初始化负载线程 - g_addLoad = false; -} - -static napi_value highQoSCalculate(napi_env env, napi_callback_info info) -{ - g_durationTime = 0; - // 没有加载系统负载的情况下,开启TASKS个线程模拟系统负载 - if (!g_addLoad) { - std::vector loadThreads; - for (int i = 0; i < TASKS; i++) { - // 开启线程执行负载任务 - loadThreads.emplace_back(std::thread(AddLoads, i % CPUS)); - loadThreads[i].detach(); - } - g_addLoad = true; - } - // 开启 QOS_USER_INTERACTIVE 高 QoS 线程进行计算 - QoS_Level level = QoS_Level::QOS_USER_INTERACTIVE; - std::thread task(SetQoS, level); - task.join(); - - // 返回计算耗时 - napi_value res; - napi_create_double(env, g_durationTime, &res); - return res; -} - -static napi_value lowQoSCalculate(napi_env env, napi_callback_info info) -{ - g_durationTime = 0; - // 没有加载系统负载的情况下,开启TASKS个线程模拟系统负载 - if (!g_addLoad) { - std::vector loadThreads; - for (int i = 0; i < TASKS; i++) { - // 开启线程执行负载任务 - loadThreads.emplace_back(std::thread(AddLoads, i % CPUS)); - loadThreads[i].detach(); - } - g_addLoad = true; - } - - // 开启 QOS_BACKGROUND 低 QoS 线程进行计算 - QoS_Level level = QoS_Level::QOS_BACKGROUND; - std::thread task(SetQoS, level); - task.join(); - - // 返回计算耗时 - napi_value res; - napi_create_double(env, g_durationTime, &res); - return res; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"useHighQos", nullptr, highQoSCalculate, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"useLowQos", nullptr, lowQoSCalculate, 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); } +/* + * Copyright (c) 2024 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 +#include +#include +#include +#include +#include +#include "napi/native_api.h" +#include "qos/qos.h" + +const unsigned int LOG_PRINT_DOMAIN = 0xFF00; +constexpr int DEPTH = 34; +constexpr int TASKS = 6; // 负载线程个数 +constexpr long long ONE = 1; +constexpr long long TWO = 2; +constexpr int BOUND = 20000; + +constexpr int MASK = 2; +constexpr int CPUS = 4; + +static bool g_addLoad = false; // 负载线程是否加载 +static double g_durationTime = 0; // 计算任务耗时时间 + +// 执行 斐波那契数列 计算 +long long DoFib(double n) +{ + if (n == ONE) { + return ONE; + } + + if (n == TWO) { + return TWO; + } + return DoFib(n - ONE) + DoFib(n - TWO); +} + +void SetQoS(QoS_Level level) +{ + // 设置当前线程的QoS等级为level + int ret = OH_QoS_SetThreadQoS(level); + if (!ret) { // ret等于0说明设置成功 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "set qos level success."); + // 查询当前的qos等级 + QoS_Level queryLevel = QoS_Level::QOS_DEFAULT; + ret = OH_QoS_GetThreadQoS(&queryLevel); + if (!ret) { // ret等于0说明查询成功 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "the qos level of current thread : %{public}d", + queryLevel); + } else { // 否则说明查询失败 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "get qos level failed."); + return; + } + } else { // ret不等于0说明设置失败 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "get level qos failed!"); + return; + } + + // 绑定到特定cpu + cpu_set_t mask; + CPU_SET(MASK, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "bind work thread failed"); + } else { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "bind work thread success."); + } + + // 执行斐波那契数列计算任务 + auto startTime = std::chrono::system_clock::now(); + long long res = DoFib(DEPTH); // 执行斐波那契数列计算任务 + auto endTime = std::chrono::system_clock::now(); + g_durationTime = std::chrono::duration(endTime - startTime).count(); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "calculate res is: %{public}llu", res); + + // 重置线程QoS等级 + ret = OH_QoS_ResetThreadQoS(); + if (!ret) { // ret等于0说明重置成功 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "reset qos level success."); + } else { // 否则说明重置失败 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "reset qos level failed!"); + return; + } + + // 在重置QoS后,再次查询,此时查询会失败 + QoS_Level queryLevelTwo; + ret = OH_QoS_GetThreadQoS(&queryLevelTwo); + if (!ret) { // 正常路径 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "the qos level after: %{public}d", queryLevelTwo); + return; + } else { // 异常路径 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "query qos level failed after reset."); + return; + } +} + +// 负载任务 +void AddLoads(int n) +{ + int ret = OH_QoS_SetThreadQoS(QoS_Level::QOS_BACKGROUND); // 设置负载线程的QoS等级 + if (ret) { // ret不等于0说明设置失败 + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "set load thread QoS level failed."); + return; + } + + // 绑定到特定cpu + cpu_set_t mask; + CPU_SET(n, &mask); + if (sched_setaffinity(0, sizeof(mask), &mask) != 0) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "QoS", "bind load thread failed"); + return; + } else { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "QoS", "bind load threads success."); + } + + // 执行负载计算 + for (int i = 0; i < BOUND; i++) { + for (int j = 0; j < BOUND; j++) { + int x = (i + j) - n; + printf("%d", x); + } + } + // 重新初始化负载线程 + g_addLoad = false; +} + +static napi_value highQoSCalculate(napi_env env, napi_callback_info info) +{ + g_durationTime = 0; + // 没有加载系统负载的情况下,开启TASKS个线程模拟系统负载 + if (!g_addLoad) { + std::vector loadThreads; + for (int i = 0; i < TASKS; i++) { + // 开启线程执行负载任务 + loadThreads.emplace_back(std::thread(AddLoads, i % CPUS)); + loadThreads[i].detach(); + } + g_addLoad = true; + } + // 开启 QOS_USER_INTERACTIVE 高 QoS 线程进行计算 + QoS_Level level = QoS_Level::QOS_USER_INTERACTIVE; + std::thread task(SetQoS, level); + task.join(); + + // 返回计算耗时 + napi_value res; + napi_create_double(env, g_durationTime, &res); + return res; +} + +static napi_value lowQoSCalculate(napi_env env, napi_callback_info info) +{ + g_durationTime = 0; + // 没有加载系统负载的情况下,开启TASKS个线程模拟系统负载 + if (!g_addLoad) { + std::vector loadThreads; + for (int i = 0; i < TASKS; i++) { + // 开启线程执行负载任务 + loadThreads.emplace_back(std::thread(AddLoads, i % CPUS)); + loadThreads[i].detach(); + } + g_addLoad = true; + } + + // 开启 QOS_BACKGROUND 低 QoS 线程进行计算 + QoS_Level level = QoS_Level::QOS_BACKGROUND; + std::thread task(SetQoS, level); + task.join(); + + // 返回计算耗时 + napi_value res; + napi_create_double(env, g_durationTime, &res); + return res; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"useHighQos", nullptr, highQoSCalculate, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"useLowQos", nullptr, lowQoSCalculate, 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/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/index.d.ts b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/index.d.ts index 4cffcf618e9d646ea7844d8edd4671b27840766f..ec633cf8508d718521e36eef79f722f0ae8a8b95 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2024 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 useHighQos: () => number; +/* + * Copyright (c) 2024 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 useHighQos: () => number; export const useLowQos: () => number; \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/oh-package.json5 index 124352dc7f48fca1b4b74c4d459e9060f1a8d65b..8c49cae229917b627c5b40b536d6e8115b59f080 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,6 +1,6 @@ -{ - "name": "libentry.so", - "types": "./index.d.ts", - "version": "", - "description": "Please describe the basic information." +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/entryability/EntryAbility.ets index 14b525aba9ebcef928dd72e040a92f34b6161d13..4504c55460d642403c98973198bd7805b53eb43d 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -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, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - 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'); - } -}; +/* + * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +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, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + 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/NdkQoS/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/pages/Index.ets index d85db4a7d61b3714bd5886528b07262a2b3d0c61..36522ed927474b9f400d750e481fd32837a29c91 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/ets/pages/Index.ets @@ -1,78 +1,78 @@ -/* - * Copyright (c) 2024 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 { - @State message: string = 'QoS Sample'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - - Button('High level QoS test', { type: ButtonType.Normal }) - .margin({ top: 50 }) - .height('6%') - .width('50%') - .borderRadius(8) - .fontWeight(FontWeight.Bold) - .backgroundColor('#aabbcc') - .onClick(() => { - let ret: string = testNapi.useHighQos().toString(); - AlertDialog.show({ - title: this.message, - message: "High-level QoS calculation time: " + ret + " ms", - alignment: DialogAlignment.Center, - confirm: { - value: "OK", - action: () => { - console.info("High-QoS done") - } - } - }) - }) - - Button('Low level QoS test', { type: ButtonType.Normal }) - .margin({ top: 50 }) - .height('6%') - .borderRadius(8) - .width('50%') - .backgroundColor('#aabbcc') - .fontWeight(FontWeight.Bold) - .onClick(() => { - let ret: string = testNapi.useLowQos().toString(); - AlertDialog.show({ - title: this.message, - message: "Low-level QoS calculation time: " + ret + " ms", - alignment: DialogAlignment.Center, - confirm: { - value: "OK", - action: () => { - console.info("Low-QoS done") - } - } - }) - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2024 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 { + @State message: string = 'QoS Sample'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + + Button('High level QoS test', { type: ButtonType.Normal }) + .margin({ top: 50 }) + .height('6%') + .width('50%') + .borderRadius(8) + .fontWeight(FontWeight.Bold) + .backgroundColor('#aabbcc') + .onClick(() => { + let ret: string = testNapi.useHighQos().toString(); + AlertDialog.show({ + title: this.message, + message: "High-level QoS calculation time: " + ret + " ms", + alignment: DialogAlignment.Center, + confirm: { + value: "OK", + action: () => { + console.info("High-QoS done") + } + } + }) + }) + + Button('Low level QoS test', { type: ButtonType.Normal }) + .margin({ top: 50 }) + .height('6%') + .borderRadius(8) + .width('50%') + .backgroundColor('#aabbcc') + .fontWeight(FontWeight.Bold) + .onClick(() => { + let ret: string = testNapi.useLowQos().toString(); + AlertDialog.show({ + title: this.message, + message: "Low-level QoS calculation time: " + ret + " ms", + alignment: DialogAlignment.Center, + confirm: { + value: "OK", + action: () => { + console.info("Low-QoS done") + } + } + }) + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/BasicFeature/Native/NdkQoS/entry/src/main/module.json5 b/code/BasicFeature/Native/NdkQoS/entry/src/main/module.json5 index fa5c9744597b44c73781b9f68cca945c602f9e40..d8838feb856bb135d089c4aa3fe1973673f48259 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/module.json5 +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2024 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:icon", + "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/NdkQoS/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Native/NdkQoS/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkQoS/entry/src/ohosTest/module.json5 b/code/BasicFeature/Native/NdkQoS/entry/src/ohosTest/module.json5 index 3613514e70e0916ece5f7bc2b650d8a3991e457d..7690747eb4c20a802f3a53ad2b493201d03d0659 100644 --- a/code/BasicFeature/Native/NdkQoS/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Native/NdkQoS/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Native/NdkQoS/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/NdkQoS/hvigor/hvigor-config.json5 index 55ef7472649a047d1219e02bcdd639bc497cddaa..eb0d70fb0067a664cc331bd11c0f4bbef95a2fd4 100644 --- a/code/BasicFeature/Native/NdkQoS/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Native/NdkQoS/hvigor/hvigor-config.json5 @@ -1,22 +1,22 @@ -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - }, - "execution": { - // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ - // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ - } -} +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + }, + "execution": { + // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ + // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ + } +} diff --git a/code/BasicFeature/Native/NdkQoS/oh-package.json5 b/code/BasicFeature/Native/NdkQoS/oh-package.json5 index 445b6f11ea6958c6d2ac5a3bd4ea1139b0b10818..a364590a1d79633b080d1bcaad8ee10482fbf32e 100644 --- a/code/BasicFeature/Native/NdkQoS/oh-package.json5 +++ b/code/BasicFeature/Native/NdkQoS/oh-package.json5 @@ -1,14 +1,14 @@ -{ - "name": "qossample", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.15", - "@ohos/hamock": "1.0.0-rc" - } -} +{ + "name": "qossample", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.15", + "@ohos/hamock": "1.0.0-rc" + } +} diff --git a/code/BasicFeature/Native/NdkRawfile/AppScope/app.json5 b/code/BasicFeature/Native/NdkRawfile/AppScope/app.json5 index 6d1ff9f9db2b8418d9b00a086cfe92f263563884..e2675d587b11d4e5d8830a61108fe72888bd265b 100644 --- a/code/BasicFeature/Native/NdkRawfile/AppScope/app.json5 +++ b/code/BasicFeature/Native/NdkRawfile/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.ndkrawfile", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.ndkrawfile", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/NdkRawfile/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/NdkRawfile/AppScope/resources/base/element/string.json index b53f80dae84e51888c69e81524d19e4ec3e2ff43..bfde41be5a4657e88c079ab9f9774baed67983db 100644 --- a/code/BasicFeature/Native/NdkRawfile/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Native/NdkRawfile/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NdkRawfile" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NdkRawfile" + } + ] +} diff --git a/code/BasicFeature/Native/NdkRawfile/build-profile.json5 b/code/BasicFeature/Native/NdkRawfile/build-profile.json5 index 75bc91290ceec5b1fb8088e6472e927561ad297c..f799f82b02184fc9d27b795b0f79fbdaff892e3f 100644 --- a/code/BasicFeature/Native/NdkRawfile/build-profile.json5 +++ b/code/BasicFeature/Native/NdkRawfile/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 15, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 15, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/build-profile.json5 b/code/BasicFeature/Native/NdkRawfile/entry/build-profile.json5 index 7744ea3a053e0af7a4038dbb0d17391432a97190..fb84cfb682d06e3dff90eb647aff70fc1833d6cf 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/build-profile.json5 +++ b/code/BasicFeature/Native/NdkRawfile/entry/build-profile.json5 @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2023 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" - ] - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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" + ] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/oh-package.json5 b/code/BasicFeature/Native/NdkRawfile/entry/oh-package.json5 index 1636ca03c123e5efd1f4725aca12e1dec621619a..df841c792e2c0c6a80748423d5a41cb696536a77 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkRawfile/entry/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/CMakeLists.txt b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/CMakeLists.txt index 015bce56dfe0cd0f839f97d7cf7e32957b834119..3fbb8db58ebaf031ecf7db040e461d0d4490bc04 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/CMakeLists.txt +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/CMakeLists.txt @@ -1,11 +1,11 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(NdkRawfile2) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -include_directories(${NATIVERENDER_ROOT_PATH} - ${NATIVERENDER_ROOT_PATH}/include) - -add_library(entry SHARED rawfile_demo.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(NdkRawfile2) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED rawfile_demo.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so librawfile.z.so) \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/rawfile_demo.cpp b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/rawfile_demo.cpp index f936b505846c9b6fe1766b2c09048c90030aed45..9321257f7bff2a0307678da490edcfdc4e532644 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/rawfile_demo.cpp +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/rawfile_demo.cpp @@ -1,365 +1,365 @@ -/* - * Copyright (c) 2023 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 -#include -#include -#include -#include -#include "napi/native_api.h" -#include "rawfile/raw_file_manager.h" -#include "rawfile/raw_file.h" -#include "rawfile/raw_dir.h" -#include "hilog/log.h" - -const int GLOBAL_RESMGR = 0xFF00; -const char *TAG = "[Sample_rawfile]"; -static napi_value GetFileList(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileList Begin"); - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - size_t strSize; - char strBuf[256]; - napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); - std::string filename(strBuf, strSize); - RawDir *rawDir = OH_ResourceManager_OpenRawDir(mNativeResMgr, filename.c_str()); - int count = OH_ResourceManager_GetRawFileCount(rawDir); - std::vector tempArray; - for (int i = 0; i < count; i++) { - std::string filename = OH_ResourceManager_GetRawFileName(rawDir, i); - tempArray.emplace_back(filename); - } - - napi_value fileList; - napi_create_array(env, &fileList); - for (size_t i = 0; i < tempArray.size(); i++) { - napi_value jsString; - napi_create_string_utf8(env, tempArray[i].c_str(), NAPI_AUTO_LENGTH, &jsString); - napi_set_element(env, fileList, i, jsString); - } - OH_ResourceManager_CloseRawDir(rawDir); - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - return fileList; -} - -namespace { - napi_value CreateJsArrayValue(napi_env env, std::unique_ptr &data, long length) - { - napi_value buffer; - napi_status status = napi_create_external_arraybuffer( - env, data.get(), length, - [](napi_env env, void *data, void *hint) { - delete[] static_cast(data); - }, - nullptr, &buffer); - if (status != napi_ok) { - OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "Failed to create external array buffer"); - return nullptr; - } - napi_value result = nullptr; - status = napi_create_typedarray(env, napi_uint8_array, length, buffer, 0, &result); - if (status != napi_ok) { - OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "Failed to create media typed array"); - return nullptr; - } - data.release(); - return result; - } -} - - -static napi_value GetRawFileContent(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent Begin"); - size_t argc = 4; - napi_value argv[4] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - size_t strSize; - char strBuf[256]; - napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); - std::string filename(strBuf, strSize); - int64_t offset = 0; - int64_t length = 0; - napi_get_value_int64(env, argv[2], &offset); - napi_get_value_int64(env, argv[3], &length); - - RawFile *rawFile = OH_ResourceManager_OpenRawFile(mNativeResMgr, filename.c_str()); - if (rawFile != nullptr) { - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile success"); - } - long fileSize = OH_ResourceManager_GetRawFileSize(rawFile); - long readLen = fileSize; - if (offset + length <= fileSize) { - OH_ResourceManager_SeekRawFile(rawFile, offset, 0); - if (length != 0) { - readLen = length; - } - long currentOffset = OH_ResourceManager_GetRawFileOffset(rawFile); - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent, current rawfile offset = %{public}ld", - currentOffset); - } - std::unique_ptr data = std::make_unique(readLen); - int res = OH_ResourceManager_ReadRawFile(rawFile, data.get(), readLen); - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent, read size = %{public}d", res); - OH_ResourceManager_CloseRawFile(rawFile); - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - return CreateJsArrayValue(env, data, fileSize); -} - -static napi_value GetRawFileContent64(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileContent64 Begin"); - size_t argc = 4; - napi_value argv[4] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - size_t strSize; - char strBuf[256]; - napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); - std::string filename(strBuf, strSize); - int64_t offset = 0; - int64_t length = 0; - napi_get_value_int64(env, argv[2], &offset); - napi_get_value_int64(env, argv[3], &length); - - RawFile64 *rawFile = OH_ResourceManager_OpenRawFile64(mNativeResMgr, filename.c_str()); - if (rawFile != nullptr) { - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile64 success"); - } - long fileSize = OH_ResourceManager_GetRawFileSize64(rawFile); - long readLen = fileSize; - if (offset + length <= fileSize) { - OH_ResourceManager_SeekRawFile64(rawFile, offset, 0); - if (length != 0) { - readLen = length; - } - long currentOffset = OH_ResourceManager_GetRawFileOffset64(rawFile); - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileContent64, current rawfile offset = %{public}ld", - currentOffset); - } - std::unique_ptr data = std::make_unique(readLen); - int res = OH_ResourceManager_ReadRawFile64(rawFile, data.get(), readLen); - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileContent64, read size = %{public}d", res); - OH_ResourceManager_CloseRawFile64(rawFile); - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - return CreateJsArrayValue(env, data, fileSize); -} - -namespace { - napi_value createJsFileDescriptor(napi_env env, int navtieFd, int64_t nativeOffset, int64_t nativeLength) - { - napi_value result; - napi_status status = napi_create_object(env, &result); - if (status != napi_ok) { - return result; - } - - napi_value fd; - status = napi_create_int32(env, navtieFd, &fd); - if (status != napi_ok) { - return result; - } - status = napi_set_named_property(env, result, "fd", fd); - if (status != napi_ok) { - return result; - } - - napi_value offset; - status = napi_create_int64(env, nativeOffset, &offset); - if (status != napi_ok) { - return result; - } - status = napi_set_named_property(env, result, "offset", offset); - if (status != napi_ok) { - return result; - } - - napi_value length; - status = napi_create_int64(env, nativeLength, &length); - if (status != napi_ok) { - return result; - } - status = napi_set_named_property(env, result, "length", length); - if (status != napi_ok) { - return result; - } - return result; - } -} - -static napi_value GetRawFileDescriptor(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileDescriptor Begin"); - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - size_t strSize; - char strBuf[256]; - napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); - std::string filename(strBuf, strSize); - RawFile *rawFile = OH_ResourceManager_OpenRawFile(mNativeResMgr, filename.c_str()); - if (rawFile != nullptr) { - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile success"); - } - RawFileDescriptor descriptor; - OH_ResourceManager_GetRawFileDescriptor(rawFile, descriptor); - - OH_ResourceManager_CloseRawFile(rawFile); - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - return createJsFileDescriptor(env, descriptor.fd, descriptor.start, descriptor.length); -} - -static napi_value GetRawFileDescriptor64(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileDescriptor64 Begin"); - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - size_t strSize; - char strBuf[256]; - napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); - std::string filename(strBuf, strSize); - RawFile64 *rawFile = OH_ResourceManager_OpenRawFile64(mNativeResMgr, filename.c_str()); - if (rawFile != nullptr) { - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile64 success"); - } - RawFileDescriptor64 descriptor; - OH_ResourceManager_GetRawFileDescriptor64(rawFile, &descriptor); - - OH_ResourceManager_CloseRawFile64(rawFile); - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - return createJsFileDescriptor(env, descriptor.fd, descriptor.start, descriptor.length); -} - -namespace { - napi_valuetype GetValueType(napi_env env, napi_value value) - { - napi_valuetype valueType = napi_valuetype::napi_undefined; - napi_typeof(env, value, &valueType); - return valueType; - } - - void GetRawFileDescritorObject(napi_env env, napi_value value, int &nativeFd, int64_t &nativeOffset, - int64_t &nativeLength) - { - napi_value fd; - napi_status status = napi_get_named_property(env, value, "fd", &fd); - if (status == napi_ok && fd != nullptr && GetValueType(env, fd) == napi_number) { - napi_get_value_int32(env, fd, &nativeFd); - } - - napi_value offset; - status = napi_get_named_property(env, value, "offset", &offset); - if (status == napi_ok && offset != nullptr && GetValueType(env, offset) == napi_number) { - napi_get_value_int64(env, offset, &nativeOffset); - } - - napi_value length; - status = napi_get_named_property(env, value, "length", &length); - if (status == napi_ok && length != nullptr && GetValueType(env, length) == napi_number) { - napi_get_value_int64(env, length, &nativeLength); - } - } -} - -static napi_value ReleaseRawFileDescriptor(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "ReleaseRawFileDescriptor Begin"); - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - bool succeed = false; - if (GetValueType(env, argv[1]) == napi_object) { - RawFileDescriptor descriptor; - int64_t offset = 0; - int64_t length = 0; - GetRawFileDescritorObject(env, argv[1], descriptor.fd, offset, length); - descriptor.start = static_cast(offset); - descriptor.length = static_cast(length); - succeed = OH_ResourceManager_ReleaseRawFileDescriptor(descriptor); - } - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - napi_value result; - napi_get_boolean(env, succeed, &result); - return result; -} - -static napi_value ReleaseRawFileDescriptor64(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "ReleaseRawFileDescriptor64 Begin"); - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - - bool succeed = false; - if (GetValueType(env, argv[1]) == napi_object) { - RawFileDescriptor64 descriptor; - GetRawFileDescritorObject(env, argv[1], descriptor.fd, descriptor.start, descriptor.length); - succeed = OH_ResourceManager_ReleaseRawFileDescriptor64(&descriptor); - } - OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); - napi_value result; - napi_get_boolean(env, succeed, &result); - return result; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getFileList", nullptr, GetFileList, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getRawFileContent", nullptr, GetRawFileContent, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getRawFileContent64", nullptr, GetRawFileContent64, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getRawFileDescriptor", nullptr, GetRawFileDescriptor, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getRawFileDescriptor64", nullptr, GetRawFileDescriptor64, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"releaseRawFileDescriptor", nullptr, ReleaseRawFileDescriptor, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"releaseRawFileDescriptor64", nullptr, ReleaseRawFileDescriptor64, 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); -} +/* + * Copyright (c) 2023 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 +#include +#include +#include +#include +#include "napi/native_api.h" +#include "rawfile/raw_file_manager.h" +#include "rawfile/raw_file.h" +#include "rawfile/raw_dir.h" +#include "hilog/log.h" + +const int GLOBAL_RESMGR = 0xFF00; +const char *TAG = "[Sample_rawfile]"; +static napi_value GetFileList(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileList Begin"); + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + RawDir *rawDir = OH_ResourceManager_OpenRawDir(mNativeResMgr, filename.c_str()); + int count = OH_ResourceManager_GetRawFileCount(rawDir); + std::vector tempArray; + for (int i = 0; i < count; i++) { + std::string filename = OH_ResourceManager_GetRawFileName(rawDir, i); + tempArray.emplace_back(filename); + } + + napi_value fileList; + napi_create_array(env, &fileList); + for (size_t i = 0; i < tempArray.size(); i++) { + napi_value jsString; + napi_create_string_utf8(env, tempArray[i].c_str(), NAPI_AUTO_LENGTH, &jsString); + napi_set_element(env, fileList, i, jsString); + } + OH_ResourceManager_CloseRawDir(rawDir); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return fileList; +} + +namespace { + napi_value CreateJsArrayValue(napi_env env, std::unique_ptr &data, long length) + { + napi_value buffer; + napi_status status = napi_create_external_arraybuffer( + env, data.get(), length, + [](napi_env env, void *data, void *hint) { + delete[] static_cast(data); + }, + nullptr, &buffer); + if (status != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "Failed to create external array buffer"); + return nullptr; + } + napi_value result = nullptr; + status = napi_create_typedarray(env, napi_uint8_array, length, buffer, 0, &result); + if (status != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, GLOBAL_RESMGR, TAG, "Failed to create media typed array"); + return nullptr; + } + data.release(); + return result; + } +} + + +static napi_value GetRawFileContent(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent Begin"); + size_t argc = 4; + napi_value argv[4] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + int64_t offset = 0; + int64_t length = 0; + napi_get_value_int64(env, argv[2], &offset); + napi_get_value_int64(env, argv[3], &length); + + RawFile *rawFile = OH_ResourceManager_OpenRawFile(mNativeResMgr, filename.c_str()); + if (rawFile != nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile success"); + } + long fileSize = OH_ResourceManager_GetRawFileSize(rawFile); + long readLen = fileSize; + if (offset + length <= fileSize) { + OH_ResourceManager_SeekRawFile(rawFile, offset, 0); + if (length != 0) { + readLen = length; + } + long currentOffset = OH_ResourceManager_GetRawFileOffset(rawFile); + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent, current rawfile offset = %{public}ld", + currentOffset); + } + std::unique_ptr data = std::make_unique(readLen); + int res = OH_ResourceManager_ReadRawFile(rawFile, data.get(), readLen); + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetFileContent, read size = %{public}d", res); + OH_ResourceManager_CloseRawFile(rawFile); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return CreateJsArrayValue(env, data, fileSize); +} + +static napi_value GetRawFileContent64(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileContent64 Begin"); + size_t argc = 4; + napi_value argv[4] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + int64_t offset = 0; + int64_t length = 0; + napi_get_value_int64(env, argv[2], &offset); + napi_get_value_int64(env, argv[3], &length); + + RawFile64 *rawFile = OH_ResourceManager_OpenRawFile64(mNativeResMgr, filename.c_str()); + if (rawFile != nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile64 success"); + } + long fileSize = OH_ResourceManager_GetRawFileSize64(rawFile); + long readLen = fileSize; + if (offset + length <= fileSize) { + OH_ResourceManager_SeekRawFile64(rawFile, offset, 0); + if (length != 0) { + readLen = length; + } + long currentOffset = OH_ResourceManager_GetRawFileOffset64(rawFile); + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileContent64, current rawfile offset = %{public}ld", + currentOffset); + } + std::unique_ptr data = std::make_unique(readLen); + int res = OH_ResourceManager_ReadRawFile64(rawFile, data.get(), readLen); + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileContent64, read size = %{public}d", res); + OH_ResourceManager_CloseRawFile64(rawFile); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return CreateJsArrayValue(env, data, fileSize); +} + +namespace { + napi_value createJsFileDescriptor(napi_env env, int navtieFd, int64_t nativeOffset, int64_t nativeLength) + { + napi_value result; + napi_status status = napi_create_object(env, &result); + if (status != napi_ok) { + return result; + } + + napi_value fd; + status = napi_create_int32(env, navtieFd, &fd); + if (status != napi_ok) { + return result; + } + status = napi_set_named_property(env, result, "fd", fd); + if (status != napi_ok) { + return result; + } + + napi_value offset; + status = napi_create_int64(env, nativeOffset, &offset); + if (status != napi_ok) { + return result; + } + status = napi_set_named_property(env, result, "offset", offset); + if (status != napi_ok) { + return result; + } + + napi_value length; + status = napi_create_int64(env, nativeLength, &length); + if (status != napi_ok) { + return result; + } + status = napi_set_named_property(env, result, "length", length); + if (status != napi_ok) { + return result; + } + return result; + } +} + +static napi_value GetRawFileDescriptor(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileDescriptor Begin"); + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + RawFile *rawFile = OH_ResourceManager_OpenRawFile(mNativeResMgr, filename.c_str()); + if (rawFile != nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile success"); + } + RawFileDescriptor descriptor; + OH_ResourceManager_GetRawFileDescriptor(rawFile, descriptor); + + OH_ResourceManager_CloseRawFile(rawFile); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return createJsFileDescriptor(env, descriptor.fd, descriptor.start, descriptor.length); +} + +static napi_value GetRawFileDescriptor64(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "GetRawFileDescriptor64 Begin"); + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + size_t strSize; + char strBuf[256]; + napi_get_value_string_utf8(env, argv[1], strBuf, sizeof(strBuf), &strSize); + std::string filename(strBuf, strSize); + RawFile64 *rawFile = OH_ResourceManager_OpenRawFile64(mNativeResMgr, filename.c_str()); + if (rawFile != nullptr) { + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "OH_ResourceManager_OpenRawFile64 success"); + } + RawFileDescriptor64 descriptor; + OH_ResourceManager_GetRawFileDescriptor64(rawFile, &descriptor); + + OH_ResourceManager_CloseRawFile64(rawFile); + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + return createJsFileDescriptor(env, descriptor.fd, descriptor.start, descriptor.length); +} + +namespace { + napi_valuetype GetValueType(napi_env env, napi_value value) + { + napi_valuetype valueType = napi_valuetype::napi_undefined; + napi_typeof(env, value, &valueType); + return valueType; + } + + void GetRawFileDescritorObject(napi_env env, napi_value value, int &nativeFd, int64_t &nativeOffset, + int64_t &nativeLength) + { + napi_value fd; + napi_status status = napi_get_named_property(env, value, "fd", &fd); + if (status == napi_ok && fd != nullptr && GetValueType(env, fd) == napi_number) { + napi_get_value_int32(env, fd, &nativeFd); + } + + napi_value offset; + status = napi_get_named_property(env, value, "offset", &offset); + if (status == napi_ok && offset != nullptr && GetValueType(env, offset) == napi_number) { + napi_get_value_int64(env, offset, &nativeOffset); + } + + napi_value length; + status = napi_get_named_property(env, value, "length", &length); + if (status == napi_ok && length != nullptr && GetValueType(env, length) == napi_number) { + napi_get_value_int64(env, length, &nativeLength); + } + } +} + +static napi_value ReleaseRawFileDescriptor(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "ReleaseRawFileDescriptor Begin"); + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + bool succeed = false; + if (GetValueType(env, argv[1]) == napi_object) { + RawFileDescriptor descriptor; + int64_t offset = 0; + int64_t length = 0; + GetRawFileDescritorObject(env, argv[1], descriptor.fd, offset, length); + descriptor.start = static_cast(offset); + descriptor.length = static_cast(length); + succeed = OH_ResourceManager_ReleaseRawFileDescriptor(descriptor); + } + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + napi_value result; + napi_get_boolean(env, succeed, &result); + return result; +} + +static napi_value ReleaseRawFileDescriptor64(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, TAG, "ReleaseRawFileDescriptor64 Begin"); + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + NativeResourceManager *mNativeResMgr = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + + bool succeed = false; + if (GetValueType(env, argv[1]) == napi_object) { + RawFileDescriptor64 descriptor; + GetRawFileDescritorObject(env, argv[1], descriptor.fd, descriptor.start, descriptor.length); + succeed = OH_ResourceManager_ReleaseRawFileDescriptor64(&descriptor); + } + OH_ResourceManager_ReleaseNativeResourceManager(mNativeResMgr); + napi_value result; + napi_get_boolean(env, succeed, &result); + return result; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getFileList", nullptr, GetFileList, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getRawFileContent", nullptr, GetRawFileContent, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getRawFileContent64", nullptr, GetRawFileContent64, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getRawFileDescriptor", nullptr, GetRawFileDescriptor, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getRawFileDescriptor64", nullptr, GetRawFileDescriptor64, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"releaseRawFileDescriptor", nullptr, ReleaseRawFileDescriptor, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"releaseRawFileDescriptor64", nullptr, ReleaseRawFileDescriptor64, 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/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/index.d.ts b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/index.d.ts index 422a08e6bbd9c405698b7d8e8adbcd12f304d47d..20bbd4be0b7cb229bdd55283c72ec38fe9dd3a45 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2023 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 resourceManager from '@ohos.resourceManager'; - -export const getFileList: (resmgr: resourceManager.ResourceManager, path: string) => Array; - -export const getRawFileContent: (resmgr: resourceManager.ResourceManager, path: string, offset?: number, - length?: number) => Uint8Array; - -export const getRawFileContent64: (resmgr: resourceManager.ResourceManager, path: string, offset?: number, - length?: number) => Uint8Array; - -export const getRawFileDescriptor: (resmgr: resourceManager.ResourceManager, - path: string) => resourceManager.RawFileDescriptor; - -export const getRawFileDescriptor64: (resmgr: resourceManager.ResourceManager, - path: string) => resourceManager.RawFileDescriptor; - -export const releaseRawFileDescriptor: (resmgr: resourceManager.ResourceManager, - fd: resourceManager.RawFileDescriptor) => boolean; - -export const releaseRawFileDescriptor64: (resmgr: resourceManager.ResourceManager, +/* + * Copyright (c) 2023 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 resourceManager from '@ohos.resourceManager'; + +export const getFileList: (resmgr: resourceManager.ResourceManager, path: string) => Array; + +export const getRawFileContent: (resmgr: resourceManager.ResourceManager, path: string, offset?: number, + length?: number) => Uint8Array; + +export const getRawFileContent64: (resmgr: resourceManager.ResourceManager, path: string, offset?: number, + length?: number) => Uint8Array; + +export const getRawFileDescriptor: (resmgr: resourceManager.ResourceManager, + path: string) => resourceManager.RawFileDescriptor; + +export const getRawFileDescriptor64: (resmgr: resourceManager.ResourceManager, + path: string) => resourceManager.RawFileDescriptor; + +export const releaseRawFileDescriptor: (resmgr: resourceManager.ResourceManager, + fd: resourceManager.RawFileDescriptor) => boolean; + +export const releaseRawFileDescriptor64: (resmgr: resourceManager.ResourceManager, fd: resourceManager.RawFileDescriptor) => boolean; \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/oh-package.json5 index ed45298dd95caff89be7ba1778a74b88f4b4693f..59c44391499bf74d415d205922bf541dc74eb87a 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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." +/* + * Copyright (c) 2023 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/NdkRawfile/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/entryability/EntryAbility.ets index 1e60fbb8de85fcee839c5eb1c2f0b3fadb4c8b62..90055cc7ff73132b951b155c19b846926da1a3db 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import { Logger } from '../utils/Logger'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - Logger.info('Ability onCreate'); - } - - onDestroy() { - Logger.info('Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info('Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error('Failed to load the content. Cause: ' + JSON.stringify(err)); - return; - } - Logger.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info('Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info('Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info('Ability onBackground'); - } -}; +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import { Logger } from '../utils/Logger'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + Logger.info('Ability onCreate'); + } + + onDestroy() { + Logger.info('Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info('Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error('Failed to load the content. Cause: ' + JSON.stringify(err)); + return; + } + Logger.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info('Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info('Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info('Ability onBackground'); + } +}; diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/pages/Index.ets index 89bee28fc40ecf32112b7cb72d697ca9db6b1e81..5e11e2ddc8c784e20384ff380da3c2234e12d086 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/pages/Index.ets @@ -1,139 +1,139 @@ -/* - * Copyright (c) 2023 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 resourceManager from '@ohos.resourceManager'; -import { util } from '@kit.ArkTS'; -import { Logger } from '../utils/Logger'; - -@Entry -@Component -struct Index { - private resMgr: resourceManager.ResourceManager = getContext().resourceManager; - private rawFileList: string = ''; - private rawFileContent: string = ''; - private rawFileDescriptor: resourceManager.RawFileDescriptor | undefined = undefined; - private rawFileContentWithOffset: string = ''; - private rawFileContent64: string = ''; - private rawFileDescriptor64: resourceManager.RawFileDescriptor | undefined = undefined; - private rawFileContentWithOffset64: string = ''; - - aboutToAppear() { - let textDecoder = new util.TextDecoder(); - // get raw file list - this.rawFileList = JSON.stringify(testNapi.getFileList(this.resMgr, '')); - - // get content of rawfile.txt - let rawFileArray = testNapi.getRawFileContent(this.resMgr, 'rawfile.txt'); - this.rawFileContent = textDecoder.decodeToString(rawFileArray); - - // get raw file descriptor of rawfile.txt - this.rawFileDescriptor = testNapi.getRawFileDescriptor(this.resMgr, 'rawfile.txt'); - - // get content of rawfile.txt with offset 3 - rawFileArray = testNapi.getRawFileContent(this.resMgr, 'rawfile.txt', 3); - this.rawFileContentWithOffset = textDecoder.decodeToString(rawFileArray); - - // get content of rawfile1.txt by getRawFileContent64 - rawFileArray = testNapi.getRawFileContent64(this.resMgr, 'rawfile1.txt'); - this.rawFileContent64 = textDecoder.decodeToString(rawFileArray); - - // get raw file descriptor of rawfile1.txt by getRawFileDescriptor64 - this.rawFileDescriptor64 = testNapi.getRawFileDescriptor64(this.resMgr, 'rawfile1.txt'); - - // get content of rawfile1.txt by getRawFileContent64 with offset 6 - rawFileArray = testNapi.getRawFileContent64(this.resMgr, 'rawfile1.txt', 8); - this.rawFileContentWithOffset64 = textDecoder.decodeToString(rawFileArray); - } - - aboutToDisappear(): boolean | void { - Logger.info('aboutToDisappear'); - if (this.rawFileDescriptor) { - let result = testNapi.releaseRawFileDescriptor(this.resMgr, this.rawFileDescriptor); - Logger.info(`releaseRawFileDescriptor: ${result}`); - } - - if (this.rawFileDescriptor64) { - let result = testNapi.releaseRawFileDescriptor64(this.resMgr, this.rawFileDescriptor64); - Logger.info(`releaseRawFileDescriptor64: ${result}`); - } - } - - build() { - Row() { - Column() { - Text('file list: ' + this.rawFileList) - .id('raw_file_list') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt content: ' + this.rawFileContent) - .id('raw_file_content') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt content with offset: ' + this.rawFileContentWithOffset) - .id('raw_file_content_offset') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt fd: ' + this.rawFileDescriptor?.fd) - .id('raw_file_fd') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt fd.offset: ' + this.rawFileDescriptor?.offset) - .id('raw_file_fd_offset') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt fd.length: ' + this.rawFileDescriptor?.length) - .id('raw_file_fd_length') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - - Text('rawfile.txt content64: ' + this.rawFileContent64) - .id('raw_file_content64') - .fontSize(20) - .width('100%') - .margin({ bottom: 15, top: 15 }) - Text('rawfile.txt content with offset64: ' + this.rawFileContentWithOffset64) - .id('raw_file_content_offset64') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt fd64: ' + this.rawFileDescriptor64?.fd) - .id('raw_file_fd64') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt fd.offset64: ' + this.rawFileDescriptor64?.offset) - .id('raw_file_fd_offset64') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - Text('rawfile.txt fd.length64: ' + this.rawFileDescriptor64?.length) - .id('raw_file_fd_length64') - .fontSize(20) - .width('100%') - .margin({ bottom: 15 }) - } - .padding({ left: 15, right: 15 }) - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2023 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 resourceManager from '@ohos.resourceManager'; +import { util } from '@kit.ArkTS'; +import { Logger } from '../utils/Logger'; + +@Entry +@Component +struct Index { + private resMgr: resourceManager.ResourceManager = getContext().resourceManager; + private rawFileList: string = ''; + private rawFileContent: string = ''; + private rawFileDescriptor: resourceManager.RawFileDescriptor | undefined = undefined; + private rawFileContentWithOffset: string = ''; + private rawFileContent64: string = ''; + private rawFileDescriptor64: resourceManager.RawFileDescriptor | undefined = undefined; + private rawFileContentWithOffset64: string = ''; + + aboutToAppear() { + let textDecoder = new util.TextDecoder(); + // get raw file list + this.rawFileList = JSON.stringify(testNapi.getFileList(this.resMgr, '')); + + // get content of rawfile.txt + let rawFileArray = testNapi.getRawFileContent(this.resMgr, 'rawfile.txt'); + this.rawFileContent = textDecoder.decodeToString(rawFileArray); + + // get raw file descriptor of rawfile.txt + this.rawFileDescriptor = testNapi.getRawFileDescriptor(this.resMgr, 'rawfile.txt'); + + // get content of rawfile.txt with offset 3 + rawFileArray = testNapi.getRawFileContent(this.resMgr, 'rawfile.txt', 3); + this.rawFileContentWithOffset = textDecoder.decodeToString(rawFileArray); + + // get content of rawfile1.txt by getRawFileContent64 + rawFileArray = testNapi.getRawFileContent64(this.resMgr, 'rawfile1.txt'); + this.rawFileContent64 = textDecoder.decodeToString(rawFileArray); + + // get raw file descriptor of rawfile1.txt by getRawFileDescriptor64 + this.rawFileDescriptor64 = testNapi.getRawFileDescriptor64(this.resMgr, 'rawfile1.txt'); + + // get content of rawfile1.txt by getRawFileContent64 with offset 6 + rawFileArray = testNapi.getRawFileContent64(this.resMgr, 'rawfile1.txt', 8); + this.rawFileContentWithOffset64 = textDecoder.decodeToString(rawFileArray); + } + + aboutToDisappear(): boolean | void { + Logger.info('aboutToDisappear'); + if (this.rawFileDescriptor) { + let result = testNapi.releaseRawFileDescriptor(this.resMgr, this.rawFileDescriptor); + Logger.info(`releaseRawFileDescriptor: ${result}`); + } + + if (this.rawFileDescriptor64) { + let result = testNapi.releaseRawFileDescriptor64(this.resMgr, this.rawFileDescriptor64); + Logger.info(`releaseRawFileDescriptor64: ${result}`); + } + } + + build() { + Row() { + Column() { + Text('file list: ' + this.rawFileList) + .id('raw_file_list') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt content: ' + this.rawFileContent) + .id('raw_file_content') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt content with offset: ' + this.rawFileContentWithOffset) + .id('raw_file_content_offset') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt fd: ' + this.rawFileDescriptor?.fd) + .id('raw_file_fd') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt fd.offset: ' + this.rawFileDescriptor?.offset) + .id('raw_file_fd_offset') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt fd.length: ' + this.rawFileDescriptor?.length) + .id('raw_file_fd_length') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + + Text('rawfile.txt content64: ' + this.rawFileContent64) + .id('raw_file_content64') + .fontSize(20) + .width('100%') + .margin({ bottom: 15, top: 15 }) + Text('rawfile.txt content with offset64: ' + this.rawFileContentWithOffset64) + .id('raw_file_content_offset64') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt fd64: ' + this.rawFileDescriptor64?.fd) + .id('raw_file_fd64') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt fd.offset64: ' + this.rawFileDescriptor64?.offset) + .id('raw_file_fd_offset64') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + Text('rawfile.txt fd.length64: ' + this.rawFileDescriptor64?.length) + .id('raw_file_fd_length64') + .fontSize(20) + .width('100%') + .margin({ bottom: 15 }) + } + .padding({ left: 15, right: 15 }) + .width('100%') + } + .height('100%') + } +} diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/utils/Logger.ets b/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/utils/Logger.ets index 92d6c87204350e5483a8ae1a2bdcc96c5b2cf60a..727e11a9fe4570d97c0275f79cf4ec9e995296eb 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/utils/Logger.ets +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/ets/utils/Logger.ets @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class LoggerModel { - private domain: number - private prefix: string - - constructor(prefix: string) { - this.prefix = prefix - this.domain = 0xFF00 - } - - debug(message: string): void { - hilog.debug(this.domain, this.prefix, message) - } - - info(message: string): void { - hilog.info(this.domain, this.prefix, message) - } - - warn(message: string): void { - hilog.warn(this.domain, this.prefix, message) - } - - error(message: string): void { - hilog.error(this.domain, this.prefix, message) - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class LoggerModel { + private domain: number + private prefix: string + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xFF00 + } + + debug(message: string): void { + hilog.debug(this.domain, this.prefix, message) + } + + info(message: string): void { + hilog.info(this.domain, this.prefix, message) + } + + warn(message: string): void { + hilog.warn(this.domain, this.prefix, message) + } + + error(message: string): void { + hilog.error(this.domain, this.prefix, message) + } +} + export let Logger = new LoggerModel('[Sample_rawfile]') \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/module.json5 b/code/BasicFeature/Native/NdkRawfile/entry/src/main/module.json5 index d0ae81f7824a8dd306da3ec891818ce8c0f13138..7dadb239554a46de79a68f02701da35bee06492c 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/module.json5 +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Native/NdkRawfile/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/entry/src/ohosTest/module.json5 b/code/BasicFeature/Native/NdkRawfile/entry/src/ohosTest/module.json5 index 404ccf0b4cdd9785cdc8c50d709e5c98cfc84fe5..fb9aa4387110756938771e76566e75c94122c08c 100644 --- a/code/BasicFeature/Native/NdkRawfile/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Native/NdkRawfile/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Native/NdkRawfile/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/NdkRawfile/hvigor/hvigor-config.json5 index b4886e292b5c51a798793e64804b56fd936d4f45..f70ecd4112d94f9aa555adf898d53f18bf58f3e9 100644 --- a/code/BasicFeature/Native/NdkRawfile/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Native/NdkRawfile/hvigor/hvigor-config.json5 @@ -1,5 +1,5 @@ -{ - "modelVersion": "5.0.0", - "dependencies": { - } +{ + "modelVersion": "5.0.0", + "dependencies": { + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/NdkRawfile/oh-package.json5 b/code/BasicFeature/Native/NdkRawfile/oh-package.json5 index 1471fd41765e115e9b962f9630004a4ea1c3321c..3aace6cb347472a9aace174e9ea4e0e54b0b33f8 100644 --- a/code/BasicFeature/Native/NdkRawfile/oh-package.json5 +++ b/code/BasicFeature/Native/NdkRawfile/oh-package.json5 @@ -1,13 +1,13 @@ -{ - "modelVersion": "5.0.0", - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "ndkrawfile", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {}, +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "ndkrawfile", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {}, } \ No newline at end of file diff --git a/code/BasicFeature/Native/XComponent/AppScope/app.json5 b/code/BasicFeature/Native/XComponent/AppScope/app.json5 index 0a8fcde3dec4368f788c49a1ba138e5c1ae0c58c..2db2ac3fc126043a69af791a20b082bea5f1f0bb 100644 --- a/code/BasicFeature/Native/XComponent/AppScope/app.json5 +++ b/code/BasicFeature/Native/XComponent/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.xcomponent", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.xcomponent", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Native/XComponent/AppScope/resources/base/element/string.json b/code/BasicFeature/Native/XComponent/AppScope/resources/base/element/string.json index 2e13d1ee4a8f77d1c9b7edd547d08743fe43bea2..001dc15a006a3fd043a055beb26d3c6c2a021949 100644 --- a/code/BasicFeature/Native/XComponent/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Native/XComponent/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "XComponent" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "XComponent" + } + ] +} diff --git a/code/BasicFeature/Native/XComponent/build-profile.json5 b/code/BasicFeature/Native/XComponent/build-profile.json5 index e521599d362272f38dd7bd88b894e49be03365ba..11ce79f476ee89ea528243d4144120305a5421a2 100644 --- a/code/BasicFeature/Native/XComponent/build-profile.json5 +++ b/code/BasicFeature/Native/XComponent/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/XComponent/entry/build-profile.json5 b/code/BasicFeature/Native/XComponent/entry/build-profile.json5 index 197f714fe6625f2e370eba13cf159a4aa4e6b369..5e7f93790e048be554bd7419f3aae29b6b3e4175 100644 --- a/code/BasicFeature/Native/XComponent/entry/build-profile.json5 +++ b/code/BasicFeature/Native/XComponent/entry/build-profile.json5 @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2023-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", - "armeabi-v7a" - ] - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023-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", + "armeabi-v7a" + ] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Native/XComponent/entry/oh-package.json5 b/code/BasicFeature/Native/XComponent/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/BasicFeature/Native/XComponent/entry/oh-package.json5 +++ b/code/BasicFeature/Native/XComponent/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Native/XComponent/entry/src/main/module.json5 b/code/BasicFeature/Native/XComponent/entry/src/main/module.json5 index a61f5cbf7c93e99ea7adb05d04f9bf9a4c3e3756..bac72d95926679c3199ad00b9457707b6970fe38 100644 --- a/code/BasicFeature/Native/XComponent/entry/src/main/module.json5 +++ b/code/BasicFeature/Native/XComponent/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/XComponent/hvigor/hvigor-config.json5 b/code/BasicFeature/Native/XComponent/hvigor/hvigor-config.json5 index 2e97c542886b3a400b21582dc62d628ad25243f1..a2eb20c67c35c8b1b6d7f34b63dfd44d5d09505e 100644 --- a/code/BasicFeature/Native/XComponent/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Native/XComponent/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/Native/XComponent/oh-package.json5 b/code/BasicFeature/Native/XComponent/oh-package.json5 index f1a08086d6746ffd44ff13dfe2a3c33e8567112d..179cf11eec3ecf8533d458417617f92d70ce3543 100644 --- a/code/BasicFeature/Native/XComponent/oh-package.json5 +++ b/code/BasicFeature/Native/XComponent/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "ndkxcomponent", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "ndkxcomponent", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Notification/CustomCommonEvent/README_zh.md b/code/BasicFeature/Notification/CustomCommonEvent/README_zh.md index c33d04bc0e930b506c2a559ad0947a036dc9a931..998a78331684f728110d4d84062be213623225c9 100644 --- a/code/BasicFeature/Notification/CustomCommonEvent/README_zh.md +++ b/code/BasicFeature/Notification/CustomCommonEvent/README_zh.md @@ -1,167 +1,167 @@ -# 事件的订阅和发布 - -### 介绍 - -本示例主要展示了公共事件相关的功能,实现了一个检测用户部分行为的应用。具体而言实现了如下几点功能: - -1.通过订阅系统公共事件,实现对用户操作行为(亮灭屏、锁屏和解锁屏幕、断联网)的监测; - -2.通过在用户主动停止监测行为时发布自定义有序公共事件,实现对用户主动触发监听行为的持久化记录; - -3.通过在用户设置对某一事件的监听状态时发布粘性事件,记录下本次应用运行期间允许监听的事件列表,同时在应用退出时将临时允许的修改为不允许; - -4.打开自定义订阅事件页面需先安装[CardEvent](lib/CardEvent-1.0.0.hap)应用,通过订阅指定应用事件,实现用户对指定卡片发送事件的监听。 - -### 效果预览 - -##### 订阅系统公共事件,主动停止监听行为及对某一事件的监听状态时发布粘性事件 - -| 主页 | 监控页面 | 设置页面 | 自定义订阅事件页面 | -| ------------------------------------ | ---------------------------------- | -------------------------------------- | ----------------------------------- | -| | | | | - -使用说明: - -1.安装编译生成的hap包,依赖包hap,桌面上显示应用图标如下,点击图标即可进入应用。 - - - - - -2.进入应用显示菜单页,可选择“进入”,“历史”,“设置”及“关于”几个选项。 - -3.点击“进入”后跳转至主页面,点击主页面“开始监控”按钮,将开始监听系统公共事件,并进行计时,此时按钮内容变更为“停止监听”;点击停止监听按钮,页面上将显示本次监听时长及监听期间收到的干扰信息汇总,并在页面右下角显示“查看详情”按钮,点击按钮将跳转至详情页,显示监听期间收到的干扰信息,应用当前仅监听了亮灭屏、锁屏和解锁屏幕、断联网等用户可操作的系统公共事件,后续可根据需求快速扩展。 - -4.返回至应用菜单页面,点击“历史”可查看用户操作监听的历史记录,当前支持每次运行期间最多存储10条历史记录,超过10条后将删除历史数据。 - -5.返回至应用菜单页面,点击“设置”可进行具体系统事件的监听配置,应用提供了“一直”、“仅本次”及“从不”三个选项,其中“仅本次”选项是指本次应用运行期间将监听特定系统公共事件,应用退出后该选项将自动调整为“从不”。 - -6.在设置页面,点击“自定义事件定向订阅”进入订阅页面, - -- 点击”订阅“按钮进行订阅事件,同时订阅指定本应用事件和订阅非指定应用事件。 - -- 点击应用内卡片发送事件或点击应用外卡片发送事件。 - -- 点击应用内卡片发送事件后,指定应用事件和非指定应用事件均会接收到卡片所发送的事件 ;点击应用外卡片发送事件后,非指定应用事件会被接收,指定应用事件不会被接收。 - -- 点击”取消订阅“ 页面中会提示当前事件取消订阅。 - -7.返回至应用菜单页面,点击“关于”可查看应用版本信息及本示例的说明。 - -### 工程目录 - -**CustomCommonEvent** - -``` -entry/src/main/ets/ -|---Application -| |---MyAbilityStage.ts -|---component -| |---Header.ets // 头部组件 -|---entryformability -| |---EntryFormAbility.ts // 卡片提供方 -|---feature -| |---HistoryFeature.ts -| |---LaunchFeature.ts -| |---MainFeature.ts -| |---SettingFeature.ts -|---LauncherAbility -| |---LauncherAbility.ts -|---MainAbility -| |---MainAbility.ts -|---model -| |---Consts.ts // 数据定义 -| |---Logger.ts // 日志打印 -| |---SurveillanceEventsManager.ts // 公共事件模块 -| |---Utils.ts -|---pages -| |---About.ets // 关于页面 -| |---Detail.ets // 详情页面 -| |---History.ets // 历史页面 -| |---jumpToCommonEvent.ets // 自定义订阅事件页面 -| |---Launch.ets // 发起页面 -| |---Main.ets // 进入页面 -| |---Setting.ets // 设置页面 -|---publishcard -| |---pages -| | |---PublishCard.ets // 卡片页面 -``` - -**CustomCommonEventRely** - -``` -entry/src/main/ets/ -|---entryformability -| |---EntryFormAbility.ts // 发布事件 -|---pages -| |---Index.ets -|---widget -| |---pages -| | |---PublishCard.ets // 发布事件的卡片 -``` - - - -### 具体实现 - -* 该示例entry部分分为五个模块: - * 进入模块 - * 使用到应用文上下文,createSubscriber方法创建订阅者,getCurrentTime获取获取自Unix纪元以来经过的时间进行对用户操作行为的监测功能页面开发。 - * 源码链接:[Consts.ts](entry/src/main/ets/module/Consts.ts),[LaunchFeature.ts](entry/src/main/ets/feature/LaunchFeature.ts),[LauncherAbility.ts](entry/src/main/ets/LauncherAbility/LauncherAbility.ts),[SurveillanceEventsManager.ts](entry/src/main/ets/module/SurveillanceEventsManager.ts) - * 参考接口:[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md),[@ohos.commonEventManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEventManager.md),[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md),[@ohos.commonEvent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEvent.md),[@ohos.router](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-router.md),[@ohos.systemTime](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-system-timer-sys.md) - - * 历史模块 - * 使用到应用文上下文,getPreferences方法获取Preferences实例,组件Header进行历史页面开发。 - * 源码链接:[Header.ets](entry/src/main/ets/component/Header.ets),[Consts.ts](entry/src/main/ets/module/Consts.ts),[HistoryFeature.ts](entry/src/main/ets/feature/HistoryFeature.ts) - * 参考接口:[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md),[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md) - - * 设置模块 - * 本模块分为三个事件,分别为记录联网事件,记录灭屏事件,记录亮屏事件,进行锁屏事件、进行解锁屏幕事件,每一个事件都可进行一直,仅本次和从不的单项选择,使用到应用文上下文吗,CommonEvent.publish发布公共事件,getPreferences方法获取Preferences实例进行功能页面开发。 - * 源码链接:[Header.ets](entry/src/main/ets/component/Header.ets),[Consts.ts](entry/src/main/ets/module/Consts.ts),[SettingFeature.ts](entry/src/main/ets/feature/SettingFeature.ts),[SurveillanceEventsManager.ts](entry/src/main/ets/module/SurveillanceEventsManager.ts) - * 参考接口:[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md),[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md),[@ohos.commonEvent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEvent.md),[@ohos.router](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-router.md),[@ohos.commonEvent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEvent.md) - - * 关于模块 - * 该模块开发主要介绍了本示例的功能作用以及说明了什么情况下不能使用。 - * 源码链接:[Header.ets](https://gitee.com/openharmony/applications_app_samples/blob/master/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/component/Header.ets),[Consts.ts](https://gitee.com/openharmony/applications_app_samples/blob/master/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/module/Consts.ts) - - - 设置中订阅事件模块 - - 本模块主要支持指定应用订阅自定义事件。subScribeInfo新增可选属性publisherBundleName,创建订阅对象时可指定PublisherBundlerName,事件发布时,获取订阅者信息,增加校验bundleName是否等于publisherBundlerName,相等则加入事件回调方,达成只接收指定发布方发布的事件的效果。 - - 源码链接:[EntryFormAbility.ts](entry/src/main/ets/entryformability/EntryFormAbility.ts),[Main.ets](entry/src/main/ets/pages/Main.ets),[PublishCard.ets](entry/src/main/ets/publishcard/pages/PublishCard.ets) - - 参考接口:[@ohos.commonEventManager](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEventManager.md),[@ohos.hilog](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-performance-analysis-kit/js-apis-hilog.md),[@ohos.app.form.formInfo](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formInfo.md),[@ohos.app.form.formBindingData](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formBindingData.md),[@ohos.app.form.FormExtensionAbility](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formExtensionAbility.md) - - - -### 相关权限 - -[ohos.permission.COMMONEVENT_STICKY](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioncommonevent_sticky) - -[ohos.permission.REQUIRE_FORM](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionrequire_form) - -[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged) - -### 依赖 - -本应用依赖[CustomCommonEventRely](../CustomCommonEventRely)应用进行运行。 - - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.3.1; - -3.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; - -4.本示例涉及[ohos.permission.REQUIRE_FORM](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionrequire_form)和[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged)权限为system_basic级别,需要配置高权限签名; - -### 下载 - -如需单独下载本工程,执行如下命令: -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/Notification/CustomCommonEvent/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master - +# 事件的订阅和发布 + +### 介绍 + +本示例主要展示了公共事件相关的功能,实现了一个检测用户部分行为的应用。具体而言实现了如下几点功能: + +1.通过订阅系统公共事件,实现对用户操作行为(亮灭屏、锁屏和解锁屏幕、断联网)的监测; + +2.通过在用户主动停止监测行为时发布自定义有序公共事件,实现对用户主动触发监听行为的持久化记录; + +3.通过在用户设置对某一事件的监听状态时发布粘性事件,记录下本次应用运行期间允许监听的事件列表,同时在应用退出时将临时允许的修改为不允许; + +4.打开自定义订阅事件页面需先安装[CardEvent](lib/CardEvent-1.0.0.hap)应用,通过订阅指定应用事件,实现用户对指定卡片发送事件的监听。 + +### 效果预览 + +##### 订阅系统公共事件,主动停止监听行为及对某一事件的监听状态时发布粘性事件 + +| 主页 | 监控页面 | 设置页面 | 自定义订阅事件页面 | +| ------------------------------------ | ---------------------------------- | -------------------------------------- | ----------------------------------- | +| | | | | + +使用说明: + +1.安装编译生成的hap包,依赖包hap,桌面上显示应用图标如下,点击图标即可进入应用。 + + + + + +2.进入应用显示菜单页,可选择“进入”,“历史”,“设置”及“关于”几个选项。 + +3.点击“进入”后跳转至主页面,点击主页面“开始监控”按钮,将开始监听系统公共事件,并进行计时,此时按钮内容变更为“停止监听”;点击停止监听按钮,页面上将显示本次监听时长及监听期间收到的干扰信息汇总,并在页面右下角显示“查看详情”按钮,点击按钮将跳转至详情页,显示监听期间收到的干扰信息,应用当前仅监听了亮灭屏、锁屏和解锁屏幕、断联网等用户可操作的系统公共事件,后续可根据需求快速扩展。 + +4.返回至应用菜单页面,点击“历史”可查看用户操作监听的历史记录,当前支持每次运行期间最多存储10条历史记录,超过10条后将删除历史数据。 + +5.返回至应用菜单页面,点击“设置”可进行具体系统事件的监听配置,应用提供了“一直”、“仅本次”及“从不”三个选项,其中“仅本次”选项是指本次应用运行期间将监听特定系统公共事件,应用退出后该选项将自动调整为“从不”。 + +6.在设置页面,点击“自定义事件定向订阅”进入订阅页面, + +- 点击”订阅“按钮进行订阅事件,同时订阅指定本应用事件和订阅非指定应用事件。 + +- 点击应用内卡片发送事件或点击应用外卡片发送事件。 + +- 点击应用内卡片发送事件后,指定应用事件和非指定应用事件均会接收到卡片所发送的事件 ;点击应用外卡片发送事件后,非指定应用事件会被接收,指定应用事件不会被接收。 + +- 点击”取消订阅“ 页面中会提示当前事件取消订阅。 + +7.返回至应用菜单页面,点击“关于”可查看应用版本信息及本示例的说明。 + +### 工程目录 + +**CustomCommonEvent** + +``` +entry/src/main/ets/ +|---Application +| |---MyAbilityStage.ts +|---component +| |---Header.ets // 头部组件 +|---entryformability +| |---EntryFormAbility.ts // 卡片提供方 +|---feature +| |---HistoryFeature.ts +| |---LaunchFeature.ts +| |---MainFeature.ts +| |---SettingFeature.ts +|---LauncherAbility +| |---LauncherAbility.ts +|---MainAbility +| |---MainAbility.ts +|---model +| |---Consts.ts // 数据定义 +| |---Logger.ts // 日志打印 +| |---SurveillanceEventsManager.ts // 公共事件模块 +| |---Utils.ts +|---pages +| |---About.ets // 关于页面 +| |---Detail.ets // 详情页面 +| |---History.ets // 历史页面 +| |---jumpToCommonEvent.ets // 自定义订阅事件页面 +| |---Launch.ets // 发起页面 +| |---Main.ets // 进入页面 +| |---Setting.ets // 设置页面 +|---publishcard +| |---pages +| | |---PublishCard.ets // 卡片页面 +``` + +**CustomCommonEventRely** + +``` +entry/src/main/ets/ +|---entryformability +| |---EntryFormAbility.ts // 发布事件 +|---pages +| |---Index.ets +|---widget +| |---pages +| | |---PublishCard.ets // 发布事件的卡片 +``` + + + +### 具体实现 + +* 该示例entry部分分为五个模块: + * 进入模块 + * 使用到应用文上下文,createSubscriber方法创建订阅者,getCurrentTime获取获取自Unix纪元以来经过的时间进行对用户操作行为的监测功能页面开发。 + * 源码链接:[Consts.ts](entry/src/main/ets/module/Consts.ts),[LaunchFeature.ts](entry/src/main/ets/feature/LaunchFeature.ts),[LauncherAbility.ts](entry/src/main/ets/LauncherAbility/LauncherAbility.ts),[SurveillanceEventsManager.ts](entry/src/main/ets/module/SurveillanceEventsManager.ts) + * 参考接口:[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md),[@ohos.commonEventManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEventManager.md),[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md),[@ohos.commonEvent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEvent.md),[@ohos.router](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-router.md),[@ohos.systemTime](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-system-timer-sys.md) + + * 历史模块 + * 使用到应用文上下文,getPreferences方法获取Preferences实例,组件Header进行历史页面开发。 + * 源码链接:[Header.ets](entry/src/main/ets/component/Header.ets),[Consts.ts](entry/src/main/ets/module/Consts.ts),[HistoryFeature.ts](entry/src/main/ets/feature/HistoryFeature.ts) + * 参考接口:[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md),[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md) + + * 设置模块 + * 本模块分为三个事件,分别为记录联网事件,记录灭屏事件,记录亮屏事件,进行锁屏事件、进行解锁屏幕事件,每一个事件都可进行一直,仅本次和从不的单项选择,使用到应用文上下文吗,CommonEvent.publish发布公共事件,getPreferences方法获取Preferences实例进行功能页面开发。 + * 源码链接:[Header.ets](entry/src/main/ets/component/Header.ets),[Consts.ts](entry/src/main/ets/module/Consts.ts),[SettingFeature.ts](entry/src/main/ets/feature/SettingFeature.ts),[SurveillanceEventsManager.ts](entry/src/main/ets/module/SurveillanceEventsManager.ts) + * 参考接口:[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md),[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkdata/js-apis-data-preferences.md),[@ohos.commonEvent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEvent.md),[@ohos.router](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-router.md),[@ohos.commonEvent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEvent.md) + + * 关于模块 + * 该模块开发主要介绍了本示例的功能作用以及说明了什么情况下不能使用。 + * 源码链接:[Header.ets](https://gitee.com/openharmony/applications_app_samples/blob/master/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/component/Header.ets),[Consts.ts](https://gitee.com/openharmony/applications_app_samples/blob/master/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/module/Consts.ts) + + - 设置中订阅事件模块 + - 本模块主要支持指定应用订阅自定义事件。subScribeInfo新增可选属性publisherBundleName,创建订阅对象时可指定PublisherBundlerName,事件发布时,获取订阅者信息,增加校验bundleName是否等于publisherBundlerName,相等则加入事件回调方,达成只接收指定发布方发布的事件的效果。 + - 源码链接:[EntryFormAbility.ts](entry/src/main/ets/entryformability/EntryFormAbility.ts),[Main.ets](entry/src/main/ets/pages/Main.ets),[PublishCard.ets](entry/src/main/ets/publishcard/pages/PublishCard.ets) + - 参考接口:[@ohos.commonEventManager](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-commonEventManager.md),[@ohos.hilog](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-performance-analysis-kit/js-apis-hilog.md),[@ohos.app.form.formInfo](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formInfo.md),[@ohos.app.form.formBindingData](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formBindingData.md),[@ohos.app.form.FormExtensionAbility](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formExtensionAbility.md) + + + +### 相关权限 + +[ohos.permission.COMMONEVENT_STICKY](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioncommonevent_sticky) + +[ohos.permission.REQUIRE_FORM](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionrequire_form) + +[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged) + +### 依赖 + +本应用依赖[CustomCommonEventRely](../CustomCommonEventRely)应用进行运行。 + + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.3.1; + +3.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; + +4.本示例涉及[ohos.permission.REQUIRE_FORM](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionrequire_form)和[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged)权限为system_basic级别,需要配置高权限签名; + +### 下载 + +如需单独下载本工程,执行如下命令: +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/Notification/CustomCommonEvent/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master + ``` \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/entryformability/EntryFormAbility.ts b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/entryformability/EntryFormAbility.ts index f9904eb38e929feaed3cfbc951e3cc0e5fdc375e..a30071081904fd9d1ec2b1cec539a87b6af2c7cd 100644 --- a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/entryformability/EntryFormAbility.ts +++ b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/entryformability/EntryFormAbility.ts @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2023 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 formInfo from '@ohos.app.form.formInfo'; -import formBindingData from '@ohos.app.form.formBindingData'; -import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; -import commonEvent from '@ohos.commonEventManager'; -import Logger from '../module/Logger'; - -export default class EntryFormAbility extends FormExtensionAbility { - onAddForm(want) { - // Called to return a FormBindingData object. - let formData = {}; - return formBindingData.createFormBindingData(formData); - } - - onCastToNormalForm(formId) { - // Called when the form provider is notified that a temporary form is successfully - // converted to a normal form. - } - - onUpdateForm(formId) { - // Called to notify the form provider to update a specified form. - } - - onChangeFormVisibility(newStatus) { - // Called when the form provider receives form events from the system. - } - - onFormEvent(formId, message) { - let options = { - data: 'InApp' - }; - commonEvent.publish('Acts_CommonEvent_Test', options, async () => { - Logger.info('publish Acts_CommonEvent_Test InApp'); - }); - // Called when a specified message event defined by the form provider is triggered. - } - - onRemoveForm(formId) { - // Called to notify the form provider that a specified form has been destroyed. - } - - onAcquireFormState(want) { - // Called to return a {@link FormState} object. - return formInfo.FormState.READY; - } +/* + * Copyright (c) 2023 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 formInfo from '@ohos.app.form.formInfo'; +import formBindingData from '@ohos.app.form.formBindingData'; +import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; +import commonEvent from '@ohos.commonEventManager'; +import Logger from '../module/Logger'; + +export default class EntryFormAbility extends FormExtensionAbility { + onAddForm(want) { + // Called to return a FormBindingData object. + let formData = {}; + return formBindingData.createFormBindingData(formData); + } + + onCastToNormalForm(formId) { + // Called when the form provider is notified that a temporary form is successfully + // converted to a normal form. + } + + onUpdateForm(formId) { + // Called to notify the form provider to update a specified form. + } + + onChangeFormVisibility(newStatus) { + // Called when the form provider receives form events from the system. + } + + onFormEvent(formId, message) { + let options = { + data: 'InApp' + }; + commonEvent.publish('Acts_CommonEvent_Test', options, async () => { + Logger.info('publish Acts_CommonEvent_Test InApp'); + }); + // Called when a specified message event defined by the form provider is triggered. + } + + onRemoveForm(formId) { + // Called to notify the form provider that a specified form has been destroyed. + } + + onAcquireFormState(want) { + // Called to return a {@link FormState} object. + return formInfo.FormState.READY; + } }; \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/publishcard/pages/PublishCard.ets b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/publishcard/pages/PublishCard.ets index 3431c1472933f373708a1815ef3e5059dae1ab64..1b8ede6adc92a8b35e1fee7f54e1aae592f65739 100644 --- a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/publishcard/pages/PublishCard.ets +++ b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/ets/publishcard/pages/PublishCard.ets @@ -1,124 +1,124 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct WidgetCard { - /* - * The title. - */ - readonly TITLE: Resource = $r('app.string.FormTitle'); - /* - * The subtext. - */ - readonly SUBTEXT: Resource = $r('app.string.FormThemes'); - /* - * The action topic. - */ - readonly TOPIC: Resource = $r('app.string.Topic'); - /* - * The action topic. - */ - readonly TOPIC_AGAIN: Resource = $r('app.string.Topic_Again'); - /* - * The action type. - */ - readonly ACTION_TYPE: string = 'message'; - /* - * The message. - */ - readonly MESSAGE: string = 'message'; - /* - * The width percentage setting. - */ - readonly FULL_WIDTH_PERCENT: string = '100%'; - /* - * The height percentage setting. - */ - readonly FULL_HEIGHT_PERCENT: string = '100%'; - @State isClick: Boolean = false - - build() { - Row() { - Column() { - Row() { - Column() { - Text(this.TITLE) - .fontColor($r('app.color.fount_color')) - .fontSize($r('app.float.16fp')) - .width($r('app.float.240vp')) - .height($r('app.float.22vp')) - .fontWeight(500) - .textAlign(TextAlign.Start) - .margin({ - top: $r('app.float.14vp') - }) - Text(this.SUBTEXT) - .fontColor($r('app.color.fount_color')) - .opacity(0.6) - .fontSize($r('app.float.14fp')) - .width($r('app.float.240vp')) - .height($r('app.float.19vp')) - .fontWeight(400) - .textAlign(TextAlign.Start) - .margin({ - top: $r('app.float.2vp'), - bottom: $r('app.float.15vp') - }) - } - .margin({ - left: $r('app.float.12vp') - }) - - Column() { - if (this.isClick) { - Button(this.TOPIC_AGAIN) - .backgroundColor($r('app.color.subscribe_events_background')) - .fontSize($r('app.float.button_fount_size')) - .fontColor($r('app.color.subscribe_events_fount')) - .width($r('app.float.72vp')) - .height($r('app.float.28vp')) - .margin({ - right: $r('app.float.12vp') - }) - } else { - Button(this.TOPIC) - .backgroundColor($r('app.color.subscribe_events_background')) - .fontSize($r('app.float.button_fount_size')) - .fontColor($r('app.color.subscribe_events_fount')) - .width($r('app.float.72vp')) - .height($r('app.float.28vp')) - .margin({ - right: $r('app.float.12vp') - }) - } - } - } - } - .backgroundColor($r('app.color.start_window_background')) - .width(this.FULL_WIDTH_PERCENT) - } - .height(this.FULL_HEIGHT_PERCENT) - .onClick(() => { - this.isClick = true - postCardAction(this, { - 'action': this.ACTION_TYPE, - 'params': { - message: this.MESSAGE - } - }); - }) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct WidgetCard { + /* + * The title. + */ + readonly TITLE: Resource = $r('app.string.FormTitle'); + /* + * The subtext. + */ + readonly SUBTEXT: Resource = $r('app.string.FormThemes'); + /* + * The action topic. + */ + readonly TOPIC: Resource = $r('app.string.Topic'); + /* + * The action topic. + */ + readonly TOPIC_AGAIN: Resource = $r('app.string.Topic_Again'); + /* + * The action type. + */ + readonly ACTION_TYPE: string = 'message'; + /* + * The message. + */ + readonly MESSAGE: string = 'message'; + /* + * The width percentage setting. + */ + readonly FULL_WIDTH_PERCENT: string = '100%'; + /* + * The height percentage setting. + */ + readonly FULL_HEIGHT_PERCENT: string = '100%'; + @State isClick: Boolean = false + + build() { + Row() { + Column() { + Row() { + Column() { + Text(this.TITLE) + .fontColor($r('app.color.fount_color')) + .fontSize($r('app.float.16fp')) + .width($r('app.float.240vp')) + .height($r('app.float.22vp')) + .fontWeight(500) + .textAlign(TextAlign.Start) + .margin({ + top: $r('app.float.14vp') + }) + Text(this.SUBTEXT) + .fontColor($r('app.color.fount_color')) + .opacity(0.6) + .fontSize($r('app.float.14fp')) + .width($r('app.float.240vp')) + .height($r('app.float.19vp')) + .fontWeight(400) + .textAlign(TextAlign.Start) + .margin({ + top: $r('app.float.2vp'), + bottom: $r('app.float.15vp') + }) + } + .margin({ + left: $r('app.float.12vp') + }) + + Column() { + if (this.isClick) { + Button(this.TOPIC_AGAIN) + .backgroundColor($r('app.color.subscribe_events_background')) + .fontSize($r('app.float.button_fount_size')) + .fontColor($r('app.color.subscribe_events_fount')) + .width($r('app.float.72vp')) + .height($r('app.float.28vp')) + .margin({ + right: $r('app.float.12vp') + }) + } else { + Button(this.TOPIC) + .backgroundColor($r('app.color.subscribe_events_background')) + .fontSize($r('app.float.button_fount_size')) + .fontColor($r('app.color.subscribe_events_fount')) + .width($r('app.float.72vp')) + .height($r('app.float.28vp')) + .margin({ + right: $r('app.float.12vp') + }) + } + } + } + } + .backgroundColor($r('app.color.start_window_background')) + .width(this.FULL_WIDTH_PERCENT) + } + .height(this.FULL_HEIGHT_PERCENT) + .onClick(() => { + this.isClick = true + postCardAction(this, { + 'action': this.ACTION_TYPE, + 'params': { + message: this.MESSAGE + } + }); + }) + } } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/element/float.json b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/element/float.json index 92e4b4475185b3ad9b7ce3216ce4890eaecc8044..23e7abcf9e697834343e18867e8753d898d7fbd8 100644 --- a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/element/float.json +++ b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/element/float.json @@ -1,116 +1,116 @@ -{ - "float": [ - { - "name": "font_size", - "value": "14fp" - }, - { - "name": "subtext_size", - "value": "12fp" - }, - { - "name": "title_size", - "value": "20fp" - }, - { - "name": "button_fount_size", - "value": "12fp" - }, - { - "name": "button_card_fount_size", - "value": "12fp" - }, - { - "name": "button_margin", - "value": "15" - }, - { - "name": "button_width", - "value": "200" - }, - { - "name": "2vp", - "value": "2px" - }, - { - "name": "22vp", - "value": "44px" - }, - { - "name": "19vp", - "value": "38px" - }, - { - "name": "14fp", - "value": "14fp" - }, - { - "name": "16fp", - "value": "16fp" - }, - { - "name": "312vp", - "value": "624px" - }, - { - "name": "336vp", - "value": "672px" - }, - { - "name": "72vp", - "value": "144px" - }, - { - "name": "12vp", - "value": "24px" - }, - { - "name": "14vp", - "value": "28px" - }, - { - "name": "15vp", - "value": "30px" - }, - { - "name": "33vp", - "value": "66px" - }, - { - "name": "4vp", - "value": "8px" - }, - { - "name": "240vp", - "value": "480px" - }, - { - "name": "64vp", - "value": "128px" - }, - { - "name": "28vp", - "value": "56px" - }, - { - "name": "6vp", - "value": "12px" - }, - { - "name": "8vp", - "value": "16px" - }, - { - "name": "24vp", - "value": "48px" - }, - { - "name": "24fp", - "value": "24fp" - }, - { - "name": "11vp", - "value": "22px" - } - ] +{ + "float": [ + { + "name": "font_size", + "value": "14fp" + }, + { + "name": "subtext_size", + "value": "12fp" + }, + { + "name": "title_size", + "value": "20fp" + }, + { + "name": "button_fount_size", + "value": "12fp" + }, + { + "name": "button_card_fount_size", + "value": "12fp" + }, + { + "name": "button_margin", + "value": "15" + }, + { + "name": "button_width", + "value": "200" + }, + { + "name": "2vp", + "value": "2px" + }, + { + "name": "22vp", + "value": "44px" + }, + { + "name": "19vp", + "value": "38px" + }, + { + "name": "14fp", + "value": "14fp" + }, + { + "name": "16fp", + "value": "16fp" + }, + { + "name": "312vp", + "value": "624px" + }, + { + "name": "336vp", + "value": "672px" + }, + { + "name": "72vp", + "value": "144px" + }, + { + "name": "12vp", + "value": "24px" + }, + { + "name": "14vp", + "value": "28px" + }, + { + "name": "15vp", + "value": "30px" + }, + { + "name": "33vp", + "value": "66px" + }, + { + "name": "4vp", + "value": "8px" + }, + { + "name": "240vp", + "value": "480px" + }, + { + "name": "64vp", + "value": "128px" + }, + { + "name": "28vp", + "value": "56px" + }, + { + "name": "6vp", + "value": "12px" + }, + { + "name": "8vp", + "value": "16px" + }, + { + "name": "24vp", + "value": "48px" + }, + { + "name": "24fp", + "value": "24fp" + }, + { + "name": "11vp", + "value": "22px" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/profile/form_config.json b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/profile/form_config.json index 6b9cc2e44c3debe6dc211158ebbaaa5cff655202..9cbf66c9a21748fb09342fcc8162fb27dcdfa59e 100644 --- a/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/profile/form_config.json +++ b/code/BasicFeature/Notification/CustomCommonEvent/entry/src/main/resources/base/profile/form_config.json @@ -1,23 +1,23 @@ -{ - "forms": [ - { - "name": "publishCard", - "description": "This is a service widget.", - "src": "./ets/publishcard/pages/PublishCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "publishCard", + "description": "This is a service widget.", + "src": "./ets/publishcard/pages/PublishCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/app.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/app.json5 index 0a1b1a3500f0771bb1bdbe3bf904aa582282890a..942f44ac1704e24663cce7daa365a9988feb0d66 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/app.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.customcommoneventrely", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.customcommoneventrely", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/resources/base/element/string.json b/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/resources/base/element/string.json index 1b25b22303f2f4a79a665f04469c33343f84fe48..1565f4c4b0575bafde61e4348dabea597fa7fb7c 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Notification/CustomCommonEventRely/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "CustomCommonEventRely" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "CustomCommonEventRely" + } + ] +} diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/build-profile.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/build-profile.json5 index 0c2b0b857b5e02f91164212414cb1e13936a02d7..5a3b9287e909ef791eaf576759a7467055be96ab 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/build-profile.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/build-profile.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/build-profile.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/oh-package.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/oh-package.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryability/EntryAbility.ts index 202b948c9ed4dd76c512c9225e676899cb8907b8..7370b8f3270dfb1cc5824b1d9fe959f82b7ede74 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryformability/EntryFormAbility.ts b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryformability/EntryFormAbility.ts index f566199b108062d44cfa0cb6391cc8cfa26151c6..f71a47e36a06a18ebf65f55ffd01d2d4fe2149c6 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryformability/EntryFormAbility.ts +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/entryformability/EntryFormAbility.ts @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 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 formInfo from '@ohos.app.form.formInfo'; -import formBindingData from '@ohos.app.form.formBindingData'; -import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; -import commonEvent from '@ohos.commonEventManager'; -import hilog from '@ohos.hilog'; - -export default class EntryFormAbility extends FormExtensionAbility { - onAddForm(want) { - // Called to return a FormBindingData object. - let formData = {}; - return formBindingData.createFormBindingData(formData); - } - - onCastToNormalForm(formId) { - // Called when the form provider is notified that a temporary form is successfully - // converted to a normal form. - } - - onUpdateForm(formId) { - // Called to notify the form provider to update a specified form. - } - - onChangeFormVisibility(newStatus) { - // Called when the form provider receives form events from the system. - } - - onFormEvent(formId, message) { - // Called when a specified message event defined by the form provider is triggered. - let options = { - data: 'OutApp' - }; - commonEvent.publish('Acts_CommonEvent_Test', options, async () => {}); - } - - onRemoveForm(formId) { - // Called to notify the form provider that a specified form has been destroyed. - } - - onAcquireFormState(want) { - // Called to return a {@link FormState} object. - return formInfo.FormState.READY; - } +/* + * Copyright (c) 2023 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 formInfo from '@ohos.app.form.formInfo'; +import formBindingData from '@ohos.app.form.formBindingData'; +import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; +import commonEvent from '@ohos.commonEventManager'; +import hilog from '@ohos.hilog'; + +export default class EntryFormAbility extends FormExtensionAbility { + onAddForm(want) { + // Called to return a FormBindingData object. + let formData = {}; + return formBindingData.createFormBindingData(formData); + } + + onCastToNormalForm(formId) { + // Called when the form provider is notified that a temporary form is successfully + // converted to a normal form. + } + + onUpdateForm(formId) { + // Called to notify the form provider to update a specified form. + } + + onChangeFormVisibility(newStatus) { + // Called when the form provider receives form events from the system. + } + + onFormEvent(formId, message) { + // Called when a specified message event defined by the form provider is triggered. + let options = { + data: 'OutApp' + }; + commonEvent.publish('Acts_CommonEvent_Test', options, async () => {}); + } + + onRemoveForm(formId) { + // Called to notify the form provider that a specified form has been destroyed. + } + + onAcquireFormState(want) { + // Called to return a {@link FormState} object. + return formInfo.FormState.READY; + } }; \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/widget/pages/PublishCard.ets b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/widget/pages/PublishCard.ets index 0ab4cecad26f38132d82ee55c1b84fd49682f205..683f935ac91902d38535c12574ab6ad59ad14d4f 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/widget/pages/PublishCard.ets +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/ets/widget/pages/PublishCard.ets @@ -1,124 +1,124 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct WidgetCard { - /* - * The title. - */ - readonly TITLE: Resource = $r('app.string.FormTitle'); - /* - * The subtext. - */ - readonly SUBTEXT: Resource = $r('app.string.FormThemes'); - /* - * The action type. - */ - readonly ACTION_TYPE: string = 'message'; - /* - * The action topic. - */ - readonly TOPIC: Resource = $r('app.string.Topic'); - /* - * The action topic. - */ - readonly TOPIC_AGAIN: Resource = $r('app.string.Topic_Again'); - /* - * The message. - */ - readonly MESSAGE: string = 'message'; - /* - * The width percentage setting. - */ - readonly FULL_WIDTH_PERCENT: string = '100%'; - /* - * The height percentage setting. - */ - readonly FULL_HEIGHT_PERCENT: string = '100%'; - @State isClick: Boolean = false - - build() { - Row() { - Column() { - Row() { - Column() { - Text(this.TITLE) - .fontColor($r('app.color.fount_color')) - .fontSize($r('app.float.16fp')) - .height($r('app.float.22vp')) - .width($r('app.float.240vp')) - .fontWeight(500) - .textAlign(TextAlign.Start) - .margin({ - top: $r('app.float.14vp') - }) - Text(this.SUBTEXT) - .fontColor($r('app.color.fount_color')) - .opacity(0.6) - .fontSize($r('app.float.14fp')) - .width($r('app.float.240vp')) - .height($r('app.float.19vp')) - .fontWeight(400) - .textAlign(TextAlign.Start) - .margin({ - top: $r('app.float.2vp'), - bottom: $r('app.float.15vp') - }) - } - .margin({ - left: $r('app.float.12vp') - }) - - Column() { - if (this.isClick) { - Button(this.TOPIC_AGAIN) - .backgroundColor($r('app.color.subscribe_events_background')) - .fontSize($r('app.float.button_fount_size')) - .fontColor($r('app.color.subscribe_events_fount')) - .width($r('app.float.72vp')) - .height($r('app.float.28vp')) - .margin({ - right: $r('app.float.12vp') - }) - } else { - Button(this.TOPIC) - .backgroundColor($r('app.color.subscribe_events_background')) - .fontSize($r('app.float.button_fount_size')) - .fontColor($r('app.color.subscribe_events_fount')) - .width($r('app.float.72vp')) - .height($r('app.float.28vp')) - .margin({ - right: $r('app.float.12vp') - }) - } - } - } - } - .backgroundColor($r('app.color.start_window_background')) - .width(this.FULL_WIDTH_PERCENT) - } - .height(this.FULL_HEIGHT_PERCENT) - .onClick(() => { - this.isClick = true - postCardAction(this, { - 'action': this.ACTION_TYPE, - 'params': { - message: this.MESSAGE - } - }); - }) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct WidgetCard { + /* + * The title. + */ + readonly TITLE: Resource = $r('app.string.FormTitle'); + /* + * The subtext. + */ + readonly SUBTEXT: Resource = $r('app.string.FormThemes'); + /* + * The action type. + */ + readonly ACTION_TYPE: string = 'message'; + /* + * The action topic. + */ + readonly TOPIC: Resource = $r('app.string.Topic'); + /* + * The action topic. + */ + readonly TOPIC_AGAIN: Resource = $r('app.string.Topic_Again'); + /* + * The message. + */ + readonly MESSAGE: string = 'message'; + /* + * The width percentage setting. + */ + readonly FULL_WIDTH_PERCENT: string = '100%'; + /* + * The height percentage setting. + */ + readonly FULL_HEIGHT_PERCENT: string = '100%'; + @State isClick: Boolean = false + + build() { + Row() { + Column() { + Row() { + Column() { + Text(this.TITLE) + .fontColor($r('app.color.fount_color')) + .fontSize($r('app.float.16fp')) + .height($r('app.float.22vp')) + .width($r('app.float.240vp')) + .fontWeight(500) + .textAlign(TextAlign.Start) + .margin({ + top: $r('app.float.14vp') + }) + Text(this.SUBTEXT) + .fontColor($r('app.color.fount_color')) + .opacity(0.6) + .fontSize($r('app.float.14fp')) + .width($r('app.float.240vp')) + .height($r('app.float.19vp')) + .fontWeight(400) + .textAlign(TextAlign.Start) + .margin({ + top: $r('app.float.2vp'), + bottom: $r('app.float.15vp') + }) + } + .margin({ + left: $r('app.float.12vp') + }) + + Column() { + if (this.isClick) { + Button(this.TOPIC_AGAIN) + .backgroundColor($r('app.color.subscribe_events_background')) + .fontSize($r('app.float.button_fount_size')) + .fontColor($r('app.color.subscribe_events_fount')) + .width($r('app.float.72vp')) + .height($r('app.float.28vp')) + .margin({ + right: $r('app.float.12vp') + }) + } else { + Button(this.TOPIC) + .backgroundColor($r('app.color.subscribe_events_background')) + .fontSize($r('app.float.button_fount_size')) + .fontColor($r('app.color.subscribe_events_fount')) + .width($r('app.float.72vp')) + .height($r('app.float.28vp')) + .margin({ + right: $r('app.float.12vp') + }) + } + } + } + } + .backgroundColor($r('app.color.start_window_background')) + .width(this.FULL_WIDTH_PERCENT) + } + .height(this.FULL_HEIGHT_PERCENT) + .onClick(() => { + this.isClick = true + postCardAction(this, { + 'action': this.ACTION_TYPE, + 'params': { + message: this.MESSAGE + } + }); + }) + } } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/module.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/module.json5 index 0642f436c55a381fa062e60f812cd6bb5ac5293d..8decf3d2798b57ed47da855689b88fb6d6d2bde2 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/module.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/module.json5 @@ -1,74 +1,74 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EntryFormAbility", - "srcEntry": "./ets/entryformability/EntryFormAbility.ts", - "label": "$string:EntryFormAbility_label", - "description": "$string:EntryFormAbility_desc", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.REQUIRE_FORM" - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryFormAbility", + "srcEntry": "./ets/entryformability/EntryFormAbility.ts", + "label": "$string:EntryFormAbility_label", + "description": "$string:EntryFormAbility_desc", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/color.json index cf2fe10d4feb7aec851afd297bd158c40ce0e1a7..5b7399050a4e7bac52540f49919d1d231b72f831 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "item_title_font", - "value": "#E6000000" - }, - { - "name": "fount_color", - "value": "#FF182431" - }, - { - "name": "subscribe_events_background", - "value": "#FF007DFF" - }, - { - "name": "subscribe_events_fount", - "value": "#FFFFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "item_title_font", + "value": "#E6000000" + }, + { + "name": "fount_color", + "value": "#FF182431" + }, + { + "name": "subscribe_events_background", + "value": "#FF007DFF" + }, + { + "name": "subscribe_events_fount", + "value": "#FFFFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/float.json b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/float.json index 9b58c97d1b2e762bdb66c05f86dfae8201d2f788..e3f77cb6c358359c3bd2fde157946f3981d0d100 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/float.json +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/element/float.json @@ -1,60 +1,60 @@ -{ - "float": [ - { - "name": "title_size", - "value": "20fp" - }, - { - "name": "22vp", - "value": "44px" - }, - { - "name": "14fp", - "value": "14fp" - }, - { - "name": "240vp", - "value": "480px" - }, - { - "name": "14vp", - "value": "28px" - }, - { - "name": "16fp", - "value": "16fp" - }, - { - "name": "2vp", - "value": "4px" - }, - { - "name": "5vp", - "value": "10px" - }, - { - "name": "19vp", - "value": "38px" - }, - { - "name": "15vp", - "value": "30px" - }, - { - "name": "72vp", - "value": "144px" - }, - { - "name": "28vp", - "value": "56px" - }, - { - "name": "12vp", - "value": "24px" - }, - { - "name": "button_fount_size", - "value": "12fp" - } - ] +{ + "float": [ + { + "name": "title_size", + "value": "20fp" + }, + { + "name": "22vp", + "value": "44px" + }, + { + "name": "14fp", + "value": "14fp" + }, + { + "name": "240vp", + "value": "480px" + }, + { + "name": "14vp", + "value": "28px" + }, + { + "name": "16fp", + "value": "16fp" + }, + { + "name": "2vp", + "value": "4px" + }, + { + "name": "5vp", + "value": "10px" + }, + { + "name": "19vp", + "value": "38px" + }, + { + "name": "15vp", + "value": "30px" + }, + { + "name": "72vp", + "value": "144px" + }, + { + "name": "28vp", + "value": "56px" + }, + { + "name": "12vp", + "value": "24px" + }, + { + "name": "button_fount_size", + "value": "12fp" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/profile/form_config.json b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/profile/form_config.json index afe032d13e3f55ba69c908229c594f461367e335..07725f60a937ac259fc0071fbcccf1d9431c4752 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/profile/form_config.json +++ b/code/BasicFeature/Notification/CustomCommonEventRely/entry/src/main/resources/base/profile/form_config.json @@ -1,23 +1,23 @@ -{ - "forms": [ - { - "name": "publishCard", - "description": "This is a service widget.", - "src": "./ets/widget/pages/PublishCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "publishCard", + "description": "This is a service widget.", + "src": "./ets/widget/pages/PublishCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/hvigor/hvigor-config.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/hvigor/hvigor-config.json5 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/BasicFeature/Notification/CustomCommonEventRely/oh-package.json5 b/code/BasicFeature/Notification/CustomCommonEventRely/oh-package.json5 index c2bd3ab5bbfeef0d17a2e97a161d18e2eabd6713..032a2c1f4defab9de70aac356e149a7f300b245e 100644 --- a/code/BasicFeature/Notification/CustomCommonEventRely/oh-package.json5 +++ b/code/BasicFeature/Notification/CustomCommonEventRely/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "customcommoneventrely", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "customcommoneventrely", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/app.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/app.json5 index 9585610ca8ec36ad9cfa124f268b0e0c8b4b26cb..6c54ddbb93af110dded361cdcb4f7c29608f45f0 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/app.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.scannapiinterfacedemo", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.scannapiinterfacedemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/resources/base/element/string.json b/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/resources/base/element/string.json index 2d59d2015ee9ee9a5b406417634f6c190d4ce595..e1a3abcd1c40be098e341918b18f763d375ea0e5 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ScanNapiInterfaceDemo" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ScanNapiInterfaceDemo" + } + ] +} diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/README_zh.md b/code/BasicFeature/Print/ScanNapiInterfaceDemo/README_zh.md index 66a22277e031178ac03f6b7511d41ddbdecea21e..4e812996e9ba8ae2ee27fb512d82dc0d7004953e 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/README_zh.md +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/README_zh.md @@ -1,134 +1,134 @@ -# 扫描仪应用demo - -### 介绍 -本示例使用@ohos.scan接口拉起[打印框架](https://gitee.com/openharmony/print_print_fwk)下的扫描服务,由扫描服务加载扫描仪驱动,完成扫描仪的发现与连接、获取扫描仪选项、设置扫描仪参数、启动扫描仪、获取扫描图片进度、取消扫描的功能。 - -### 界面预览 -![扫描demo](sceenshots/scandemo.png) - -使用说明 - -1.本示例是测试扫描框架接口能力,扫描仪驱动基于sane-backends开发。 - -2.首页的按钮点击后调用扫描框架对应的接口。 - -3.启动扫描后,可以通过图片预览按钮查看扫描出的图片。 - -### 工程目录 - -``` -ScanNapiInterfaceDemo -├── AppScope -│ └── app.json5 //APP信息配置文件 -├── entry/src/main -│ ├── ets -│ │ ├── entryability -│ │ ├── scan -│ │ │ ├── log.ts //日志库 -│ │ │ ├── scan.ts //扫描接口库 -│ │ ├── pages -│ │ │ ├── Index.ets //应用界面 -│ └── module.json5 -│ -├── entry/src/ohosTest //测试用例 -│ ├── ets/test -│ │ ├── Ability.test.ets -│ │ ├── List.test.ets //测试列表 -│ │ ├── Scan.test.ets //扫描接口测试 -│ └── module.json5 -``` - -### 具体实现 - -* 该示例分为7个接口: - * 搜索扫描仪 - * 使用@ohos.scan中API 12接口scan.on注册发现回调函数,然后调用@ohos.scan中的scan.getScannerList接口开启扫描仪搜索,当发现到扫描仪时,会通过on注册的回调函数,将扫描仪设备信息回调到应用。 - * 源码链接:[scan.ts](./entry/src/main/ets/scan/scan.ts) - * 参考接口:[@ohos.scan] - - * 连接扫描仪 - - * 使用@ohos.scan中API 12接口scan.openScanner连接扫描仪,传入的参数是扫描仪的id。 - * 源码链接:[scan.ts](./entry/src/main/ets/scan/scan.ts) - * 参考接口:[@ohos.scan] - - * 启动扫描仪 - - * 使用@ohos.scan中API 12接口scan.startScan启动扫描任务,传入的参数是扫描仪的id和是否开启批处理扫描模式。 - - * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) - - * 参考接口:[@ohos.scan] - - * 取消扫描 - - * 使用@ohos.scan中API 12接口scan.cancelScan取消扫描任务,传入的参数是扫描仪的id。 - - * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) - - * 参考接口:[@ohos.scan] - * 查询扫描进度 - - * 使用@ohos.scan中API 12接口scan.getScanProgress查询扫描仪扫描图片的进度。 - - * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) - - * 参考接口:@ohos.scan - * 获取扫描仪选项 - - * 使用@ohos.scan中API 12接口scan.getScanOption查询扫描仪有多少个选项,getScanOptionDesc获取每一个选项具体的描述信息。 - - * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) - - * 参考接口:@ohos.scan - * 设置扫描仪参数 - - * 使用@ohos.scan中API 12接口scan.setScanOption设置某一台扫描仪的选项参数。 - - * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) - - * 参考接口:@ohos.scan - -### 相关权限 - -[ohos.permission.PRINT] - -[ohos.permission.MANAGE_PRINT_JOB] - -### 依赖 - -1.API12版本SDK的@ohos.scan接口。 - -2.基于[sane-backends](https://gitee.com/openharmony-sig/third_party_backends)开发的扫描仪驱动以及对应厂商型号的扫描仪设备。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12),镜像版本号(5.0) - -3.本示例需要使用DevEco Studio 版本号(5.0.3.403)及以上版本才可编译运行。 - -4.运行本示例需要连接扫描仪,下载扫描仪对应的驱动。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/Print/ScanNapiInterfaceDemo/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull -``` - -### 构建说明 - -1.需要基于[sane-backends](https://gitee.com/openharmony-sig/third_party_backends/)完成扫描仪驱动的开发。 - -2.扫描仪驱动通过驱动安装应用安装到指定路径。 - -3.本工程通过Build Hap(s)/APP(s)完成编译构建,然后安装。 - +# 扫描仪应用demo + +### 介绍 +本示例使用@ohos.scan接口拉起[打印框架](https://gitee.com/openharmony/print_print_fwk)下的扫描服务,由扫描服务加载扫描仪驱动,完成扫描仪的发现与连接、获取扫描仪选项、设置扫描仪参数、启动扫描仪、获取扫描图片进度、取消扫描的功能。 + +### 界面预览 +![扫描demo](sceenshots/scandemo.png) + +使用说明 + +1.本示例是测试扫描框架接口能力,扫描仪驱动基于sane-backends开发。 + +2.首页的按钮点击后调用扫描框架对应的接口。 + +3.启动扫描后,可以通过图片预览按钮查看扫描出的图片。 + +### 工程目录 + +``` +ScanNapiInterfaceDemo +├── AppScope +│ └── app.json5 //APP信息配置文件 +├── entry/src/main +│ ├── ets +│ │ ├── entryability +│ │ ├── scan +│ │ │ ├── log.ts //日志库 +│ │ │ ├── scan.ts //扫描接口库 +│ │ ├── pages +│ │ │ ├── Index.ets //应用界面 +│ └── module.json5 +│ +├── entry/src/ohosTest //测试用例 +│ ├── ets/test +│ │ ├── Ability.test.ets +│ │ ├── List.test.ets //测试列表 +│ │ ├── Scan.test.ets //扫描接口测试 +│ └── module.json5 +``` + +### 具体实现 + +* 该示例分为7个接口: + * 搜索扫描仪 + * 使用@ohos.scan中API 12接口scan.on注册发现回调函数,然后调用@ohos.scan中的scan.getScannerList接口开启扫描仪搜索,当发现到扫描仪时,会通过on注册的回调函数,将扫描仪设备信息回调到应用。 + * 源码链接:[scan.ts](./entry/src/main/ets/scan/scan.ts) + * 参考接口:[@ohos.scan] + + * 连接扫描仪 + + * 使用@ohos.scan中API 12接口scan.openScanner连接扫描仪,传入的参数是扫描仪的id。 + * 源码链接:[scan.ts](./entry/src/main/ets/scan/scan.ts) + * 参考接口:[@ohos.scan] + + * 启动扫描仪 + + * 使用@ohos.scan中API 12接口scan.startScan启动扫描任务,传入的参数是扫描仪的id和是否开启批处理扫描模式。 + + * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) + + * 参考接口:[@ohos.scan] + + * 取消扫描 + + * 使用@ohos.scan中API 12接口scan.cancelScan取消扫描任务,传入的参数是扫描仪的id。 + + * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) + + * 参考接口:[@ohos.scan] + * 查询扫描进度 + + * 使用@ohos.scan中API 12接口scan.getScanProgress查询扫描仪扫描图片的进度。 + + * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) + + * 参考接口:@ohos.scan + * 获取扫描仪选项 + + * 使用@ohos.scan中API 12接口scan.getScanOption查询扫描仪有多少个选项,getScanOptionDesc获取每一个选项具体的描述信息。 + + * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) + + * 参考接口:@ohos.scan + * 设置扫描仪参数 + + * 使用@ohos.scan中API 12接口scan.setScanOption设置某一台扫描仪的选项参数。 + + * 源码链接,[scan.ts](./entry/src/main/ets/scan/scan.ts) + + * 参考接口:@ohos.scan + +### 相关权限 + +[ohos.permission.PRINT] + +[ohos.permission.MANAGE_PRINT_JOB] + +### 依赖 + +1.API12版本SDK的@ohos.scan接口。 + +2.基于[sane-backends](https://gitee.com/openharmony-sig/third_party_backends)开发的扫描仪驱动以及对应厂商型号的扫描仪设备。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API12版本SDK,SDK版本号(API Version 12),镜像版本号(5.0) + +3.本示例需要使用DevEco Studio 版本号(5.0.3.403)及以上版本才可编译运行。 + +4.运行本示例需要连接扫描仪,下载扫描仪对应的驱动。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/Print/ScanNapiInterfaceDemo/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull +``` + +### 构建说明 + +1.需要基于[sane-backends](https://gitee.com/openharmony-sig/third_party_backends/)完成扫描仪驱动的开发。 + +2.扫描仪驱动通过驱动安装应用安装到指定路径。 + +3.本工程通过Build Hap(s)/APP(s)完成编译构建,然后安装。 + 4.通过局域网或有线等物理方式连接扫描仪后即可通过主界面的相关按钮实现扫描仪的发现和连接等功能。 \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/build-profile.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/build-profile.json5 index 1cfea753aa1a39122eb74e171892be18469cba97..82472ef2cf412d966bccea56239eed3cea6e148d 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/build-profile.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/build-profile.json5 @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2024 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", - "compatibleSdkVersion": 12, - "compileSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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", + "compatibleSdkVersion": 12, + "compileSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/build-profile.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/build-profile.json5 index 97f563b45aac28e7e3ae336f7c0eb06b7b789179..63b88fb1a0053e40acb2391457a7e9d71af748fe 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/build-profile.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entryability/EntryAbility.ets index eaf0e1105c420a3138e6ff467315e544c4bd3de2..a32a8361c7fcad66acf12208583e198fc4e68dab 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,55 +1,55 @@ -/* - * Copyright (c) 2024 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'); - } -} +/* + * Copyright (c) 2024 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/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 14b37a853791836b58966f7d20c9a56dca417f53..be794f48ccffc46278e76ce3493088a647b0d470 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2024 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)); - } +/* + * Copyright (c) 2024 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/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/log.ts b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/log.ts index 6b3a6f77e0e03e63b4b2e9dc4152b15976fb75f5..b39805830e93802f7acc13d4dddfb5ff0fcc6239 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/log.ts +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/log.ts @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -export class ScanLog { - private static readonly SETTING_DOMAIN:number = 0x0000; - static debug(msg) :void { - hilog.debug(ScanLog.SETTING_DOMAIN, 'scanDemo',msg); - } - static info(msg) :void { - hilog.info(ScanLog.SETTING_DOMAIN,'scanDemo',msg); - } - static warn(msg) :void{ - hilog.warn(ScanLog.SETTING_DOMAIN,'scanDemo',msg); - } - static fatal(msg) :void{ - hilog.fatal(ScanLog.SETTING_DOMAIN,'scanDemo',msg); - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +export class ScanLog { + private static readonly SETTING_DOMAIN:number = 0x0000; + static debug(msg) :void { + hilog.debug(ScanLog.SETTING_DOMAIN, 'scanDemo',msg); + } + static info(msg) :void { + hilog.info(ScanLog.SETTING_DOMAIN,'scanDemo',msg); + } + static warn(msg) :void{ + hilog.warn(ScanLog.SETTING_DOMAIN,'scanDemo',msg); + } + static fatal(msg) :void{ + hilog.fatal(ScanLog.SETTING_DOMAIN,'scanDemo',msg); + } +} diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/scan.ts b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/scan.ts index b4f6fef9c423308c4335dff89604378ec959e12f..bcf5ebea9202761e2896899cd3d33cb15fe20beb 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/scan.ts +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/ets/scan/scan.ts @@ -1,162 +1,162 @@ -/* - * Copyright (c) 2024 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. - */ - -// @ts-ignore -import scan from '@ohos.scan' -import { BusinessError} from '@kit.BasicServicesKit'; -import { ScanLog } from './log'; - -export interface ScannerDevice { - deviceId : string, - manufacturer :string, - deviceType : string, - deviceState : string, - discoverMode : string, - serialNumber : string, - address : string, - deviceName : string, -} - -export interface ScanProgress { - progress : number, - pictureFd :number, - isFinal : boolean, -} - -export interface ScanOptionValue { - valueType:number, - valueSize:number, - numValue?:number, - numListValue?:Array, - strValue?:string, - boolValue?:boolean, -} - -export enum ScanOptionValueType { - SCAN_VALUE_NONE, - SCAN_VALUE_NUM, - SCAN_VALUE_NUM_LIST, - SCAN_VALUE_STR, - SCAN_VALUE_BOOL, -} - -export class Scan { - static initScan():Promise{ - return new Promise((resolve,reject)=>{ - scan.initScan().then((data:number)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static exitScan():Promise{ - return new Promise((resolve,reject)=>{ - scan.exitScan().then((data:number)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static openScanner(scannerId:string):Promise{ - return new Promise((resolve,reject)=>{ - scan.openScanner(scannerId).then((data:number)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static closeScanner(scannerId:string):Promise{ - return new Promise((resolve,reject)=>{ - scan.closeScanner(scannerId).then((data:number)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static startScan(scannerId:string, isBatch:boolean):Promise{ - return new Promise((resolve,reject)=>{ - scan.startScan(scannerId, isBatch).then((data:number)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static getScannerList():Promise{ - return new Promise((resolve,reject)=>{ - scan.getScannerList().then((data:boolean)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static on(type:string, callBackRef):void{ - try { - scan.on(type, callBackRef); - } catch (error) { - ScanLog.warn('scan on error'); - } - } - static cancelScan(scannerId :string):Promise{ - return new Promise((resolve,reject)=>{ - scan.cancelScan(scannerId).then((data:boolean)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static getProgress(scannerId :string):Promise { - return new Promise((resolve,reject)=>{ - scan.getScanProgress(scannerId).then((data:ScanProgress)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static setScanOption(scannerId :string, optionIndex : number, optionValue : ScanOptionValue):Promise { - return new Promise((resolve,reject)=>{ - scan.setScanOption(scannerId, optionIndex, optionValue).then((data:boolean)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static getScanOption(scannerId :string, optionIndex : number, optionValueType : ScanOptionValueType, valueSize : number):Promise { - return new Promise((resolve,reject)=>{ - scan.getScanOption(scannerId, optionIndex, optionValueType, valueSize).then((data)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } - static getScanOptionDesc(scannerId :string, optionIndex : number):Promise { - return new Promise((resolve,reject)=>{ - scan.getScanOptionDesc(scannerId, optionIndex).then((data)=>{ - resolve(data); - }).catch((error:BusinessError)=>{ - reject(error); - }) - }); - } -} +/* + * Copyright (c) 2024 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. + */ + +// @ts-ignore +import scan from '@ohos.scan' +import { BusinessError} from '@kit.BasicServicesKit'; +import { ScanLog } from './log'; + +export interface ScannerDevice { + deviceId : string, + manufacturer :string, + deviceType : string, + deviceState : string, + discoverMode : string, + serialNumber : string, + address : string, + deviceName : string, +} + +export interface ScanProgress { + progress : number, + pictureFd :number, + isFinal : boolean, +} + +export interface ScanOptionValue { + valueType:number, + valueSize:number, + numValue?:number, + numListValue?:Array, + strValue?:string, + boolValue?:boolean, +} + +export enum ScanOptionValueType { + SCAN_VALUE_NONE, + SCAN_VALUE_NUM, + SCAN_VALUE_NUM_LIST, + SCAN_VALUE_STR, + SCAN_VALUE_BOOL, +} + +export class Scan { + static initScan():Promise{ + return new Promise((resolve,reject)=>{ + scan.initScan().then((data:number)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static exitScan():Promise{ + return new Promise((resolve,reject)=>{ + scan.exitScan().then((data:number)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static openScanner(scannerId:string):Promise{ + return new Promise((resolve,reject)=>{ + scan.openScanner(scannerId).then((data:number)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static closeScanner(scannerId:string):Promise{ + return new Promise((resolve,reject)=>{ + scan.closeScanner(scannerId).then((data:number)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static startScan(scannerId:string, isBatch:boolean):Promise{ + return new Promise((resolve,reject)=>{ + scan.startScan(scannerId, isBatch).then((data:number)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static getScannerList():Promise{ + return new Promise((resolve,reject)=>{ + scan.getScannerList().then((data:boolean)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static on(type:string, callBackRef):void{ + try { + scan.on(type, callBackRef); + } catch (error) { + ScanLog.warn('scan on error'); + } + } + static cancelScan(scannerId :string):Promise{ + return new Promise((resolve,reject)=>{ + scan.cancelScan(scannerId).then((data:boolean)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static getProgress(scannerId :string):Promise { + return new Promise((resolve,reject)=>{ + scan.getScanProgress(scannerId).then((data:ScanProgress)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static setScanOption(scannerId :string, optionIndex : number, optionValue : ScanOptionValue):Promise { + return new Promise((resolve,reject)=>{ + scan.setScanOption(scannerId, optionIndex, optionValue).then((data:boolean)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static getScanOption(scannerId :string, optionIndex : number, optionValueType : ScanOptionValueType, valueSize : number):Promise { + return new Promise((resolve,reject)=>{ + scan.getScanOption(scannerId, optionIndex, optionValueType, valueSize).then((data)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } + static getScanOptionDesc(scannerId :string, optionIndex : number):Promise { + return new Promise((resolve,reject)=>{ + scan.getScanOptionDesc(scannerId, optionIndex).then((data)=>{ + resolve(data); + }).catch((error:BusinessError)=>{ + reject(error); + }) + }); + } +} diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/module.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/module.json5 index 5ec48b140af6ff501c08a5b71bae387fc130d3bb..f170a2a47b0e057cb7d2903dae39b2f7adbe5cc7 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/module.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2024 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" - } - ] - } - ], - "requestPermissions": [ - { - "name" : "ohos.permission.MANAGE_PRINT_JOB" - } - ] - } +/* + * Copyright (c) 2024 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" + } + ] + } + ], + "requestPermissions": [ + { + "name" : "ohos.permission.MANAGE_PRINT_JOB" + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/profile/backup_config.json b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/profile/backup_config.json +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/ets/test/Scan.test.ets b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/ets/test/Scan.test.ets index b8524411855e75da6bff8dfbf190b8859270429d..4567fb489cb73ef57265a2676000e1f7073f3213 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/ets/test/Scan.test.ets +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/ets/test/Scan.test.ets @@ -1,115 +1,115 @@ -/* - * Copyright (c) 2024 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 { Scan } from '../../../main/ets/scan/scan' -import { ScanLog } from '../../../main/ets/scan/log' -import { ScannerDevice } from '../../../main/ets/scan/scan' -import { ScanOptionValue } from '../../../main/ets/scan/scan' -export function scanTest() { - describe('ScanAbilityTest', () => { - it('ScanTest_000', 0, ()=>{ - Scan.initScan().then((data:number)=>{ - ScanLog.info('init scan successful') - }).catch(() => { - ScanLog.warn('init scan error') - }) - }); - it('ScanTest_001', 0, ()=>{ - Scan.exitScan().then(()=>{ - ScanLog.info('exitScan scan successful') - }).catch(() => { - ScanLog.warn('exitScan scan error') - }) - }); - it('ScanTest_002', 0, ()=>{ - let scannerId : string = ""; - Scan.openScanner(scannerId).then(()=>{ - ScanLog.info('openScanner scan successful') - }).catch(() => { - ScanLog.warn('openScanner scan error') - }) - }); - it('ScanTest_003', 0, ()=>{ - let scannerId : string = ""; - Scan.closeScanner(scannerId).then(()=>{ - ScanLog.info('closeScanner scan successful') - }).catch(() => { - ScanLog.warn('closeScanner scan error') - }) - }); - it('ScanTest_004', 0, ()=>{ - let scannerId : string = "" - Scan.startScan(scannerId, false).then(()=>{ - ScanLog.info('startScan scan successful') - }).catch(() => { - ScanLog.warn('startScan scan error') - }) - }); - it('ScanTest_005', 0, ()=>{ - let scannerId : string = ""; - Scan.cancelScan(scannerId).then(()=>{ - ScanLog.info('cancelScan scan successful') - }).catch(() => { - ScanLog.warn('cancelScan scan error') - }) - }); - it('ScanTest_006', 0, ()=>{ - let scannerId : string = ""; - Scan.getProgress(scannerId).then(()=>{ - ScanLog.info('getProgress scan successful') - }).catch(() => { - ScanLog.warn('getProgress scan error') - }) - }); - it('ScanTest_007', 0, ()=>{ - let scannerId : string = ""; - let value : ScanOptionValue = { - valueType : 3, - valueSize : 0, - strValue : 'Automatic Document Feeder', - }; - Scan.setScanOption(scannerId, 6, value).then(()=>{ - ScanLog.info('getProgress scan successful') - }).catch(() => { - ScanLog.warn('getProgress scan error') - }) - }); - it('ScanTest_008', 0, ()=>{ - let scannerId : string = ""; - Scan.getScanOption(scannerId, 0 ,1, 4).then(() => { - }).catch(() => { - ScanLog.warn('scan getScanOption error'); - }) - }); - it('ScanTest_009', 0, ()=>{ - Scan.on('scanDeviceFound', (device: ScannerDevice | string) => { - ScanLog.info('scanner info : ' + JSON.stringify(device)); - }) - Scan.getScannerList().then(() => { - ScanLog.info('scan getScannerList successful'); - }).catch(() => { - ScanLog.warn('scan getScannerList error') - }) - }); - it('ScanTest_010', 0, ()=>{ - let scannerId : string = ""; - Scan.getScanOptionDesc(scannerId, 0).then(() => { - ScanLog.info('scan getScanOptionDesc successful'); - }).catch(() => { - ScanLog.warn('scan getScanOptionDesc error') - }) - }); - }) +/* + * Copyright (c) 2024 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 { Scan } from '../../../main/ets/scan/scan' +import { ScanLog } from '../../../main/ets/scan/log' +import { ScannerDevice } from '../../../main/ets/scan/scan' +import { ScanOptionValue } from '../../../main/ets/scan/scan' +export function scanTest() { + describe('ScanAbilityTest', () => { + it('ScanTest_000', 0, ()=>{ + Scan.initScan().then((data:number)=>{ + ScanLog.info('init scan successful') + }).catch(() => { + ScanLog.warn('init scan error') + }) + }); + it('ScanTest_001', 0, ()=>{ + Scan.exitScan().then(()=>{ + ScanLog.info('exitScan scan successful') + }).catch(() => { + ScanLog.warn('exitScan scan error') + }) + }); + it('ScanTest_002', 0, ()=>{ + let scannerId : string = ""; + Scan.openScanner(scannerId).then(()=>{ + ScanLog.info('openScanner scan successful') + }).catch(() => { + ScanLog.warn('openScanner scan error') + }) + }); + it('ScanTest_003', 0, ()=>{ + let scannerId : string = ""; + Scan.closeScanner(scannerId).then(()=>{ + ScanLog.info('closeScanner scan successful') + }).catch(() => { + ScanLog.warn('closeScanner scan error') + }) + }); + it('ScanTest_004', 0, ()=>{ + let scannerId : string = "" + Scan.startScan(scannerId, false).then(()=>{ + ScanLog.info('startScan scan successful') + }).catch(() => { + ScanLog.warn('startScan scan error') + }) + }); + it('ScanTest_005', 0, ()=>{ + let scannerId : string = ""; + Scan.cancelScan(scannerId).then(()=>{ + ScanLog.info('cancelScan scan successful') + }).catch(() => { + ScanLog.warn('cancelScan scan error') + }) + }); + it('ScanTest_006', 0, ()=>{ + let scannerId : string = ""; + Scan.getProgress(scannerId).then(()=>{ + ScanLog.info('getProgress scan successful') + }).catch(() => { + ScanLog.warn('getProgress scan error') + }) + }); + it('ScanTest_007', 0, ()=>{ + let scannerId : string = ""; + let value : ScanOptionValue = { + valueType : 3, + valueSize : 0, + strValue : 'Automatic Document Feeder', + }; + Scan.setScanOption(scannerId, 6, value).then(()=>{ + ScanLog.info('getProgress scan successful') + }).catch(() => { + ScanLog.warn('getProgress scan error') + }) + }); + it('ScanTest_008', 0, ()=>{ + let scannerId : string = ""; + Scan.getScanOption(scannerId, 0 ,1, 4).then(() => { + }).catch(() => { + ScanLog.warn('scan getScanOption error'); + }) + }); + it('ScanTest_009', 0, ()=>{ + Scan.on('scanDeviceFound', (device: ScannerDevice | string) => { + ScanLog.info('scanner info : ' + JSON.stringify(device)); + }) + Scan.getScannerList().then(() => { + ScanLog.info('scan getScannerList successful'); + }).catch(() => { + ScanLog.warn('scan getScannerList error') + }) + }); + it('ScanTest_010', 0, ()=>{ + let scannerId : string = ""; + Scan.getScanOptionDesc(scannerId, 0).then(() => { + ScanLog.info('scan getScanOptionDesc successful'); + }).catch(() => { + ScanLog.warn('scan getScanOptionDesc error') + }) + }); + }) } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/module.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/module.json5 index 20226beba81da3bcfe437c01ea84dbe96e74497b..944ed99859bbc89eac2d57af2b3600881bb5a47c 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/entry/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/Print/ScanNapiInterfaceDemo/hvigor/hvigor-config.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/hvigor/hvigor-config.json5 index 7dbbeb138ab63ecbfa5f2966d18db9c1b537f745..87990affc4f62f7c76c246428c40272d3be0a7c7 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/hvigor/hvigor-config.json5 @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2024 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": { - }, - "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*/ - } -} +/* + * Copyright (c) 2024 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": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package-lock.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package-lock.json5 index fb9ffcf195c30152ee5718f401ccd315ef64ad42..90b58fc0fdfb9c64e1077e98251f4bf6a9cb730f 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package-lock.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package-lock.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "meta": { - "stableOrder": true - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", - "@ohos/hypium@1.0.18": "@ohos/hypium@1.0.18" - }, - "packages": { - "@ohos/hamock@1.0.0": { - "name": "@ohos/hamock", - "version": "1.0.0", - "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", - "registryType": "ohpm" - }, - "@ohos/hypium@1.0.18": { - "name": "@ohos/hypium", - "version": "1.0.18", - "integrity": "sha512-RGe/iLGdeywdQilMWZsHKUoiE9OJ+9QxQsorF92R2ImLNVHVhbpSePNITGpW7TnvLgOIP/jscOqfIOhk6X7XRQ==", - "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.18.har", - "registryType": "ohpm" - } - } +/* + * Copyright (c) 2024 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. + */ + +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.18": "@ohos/hypium@1.0.18" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.18": { + "name": "@ohos/hypium", + "version": "1.0.18", + "integrity": "sha512-RGe/iLGdeywdQilMWZsHKUoiE9OJ+9QxQsorF92R2ImLNVHVhbpSePNITGpW7TnvLgOIP/jscOqfIOhk6X7XRQ==", + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.18.har", + "registryType": "ohpm" + } + } } \ No newline at end of file diff --git a/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package.json5 b/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package.json5 index 55feb3193be5329739f93616934888e079eaf7ee..d1294a3e3670a8a18770f379ff556977777c98d8 100644 --- a/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package.json5 +++ b/code/BasicFeature/Print/ScanNapiInterfaceDemo/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2024 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.18", - "@ohos/hamock": "1.0.0" - } -} +/* + * Copyright (c) 2024 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.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/BasicFeature/Resource/ResourceManager/entry/src/main/ets/entryability/EntryAbility.ets b/code/BasicFeature/Resource/ResourceManager/entry/src/main/ets/entryability/EntryAbility.ets index caf1535339a0ca795c1b949e0e4abdccc5bbee85..c619b99702eda98ec06fc527bbde24972f970af2 100644 --- a/code/BasicFeature/Resource/ResourceManager/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/BasicFeature/Resource/ResourceManager/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -const TAG = '[Sample_ResourceManager]'; -const DOMAIN = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +const TAG = '[Sample_ResourceManager]'; +const DOMAIN = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/build-profile.json5 b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/build-profile.json5 index 571f75bc54b40e6fe66dd5a6f43eb2966abf1256..71198c168f48c18dddb4e64f49647d6ee6d0d864 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/build-profile.json5 +++ b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/build-profile.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default" - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/oh-package.json5 b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/oh-package.json5 index ab614db178564e91a078ff36237002553f61f391..c3805d3263be216d22e475077c5ca1b2f52f0898 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/oh-package.json5 +++ b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "libraryoverlay", - "description": "Please describe the basic information.", - "main": "./src/main/ets/Index.ets", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "libraryoverlay", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/ets/Index.ets b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/ets/Index.ets index f022fd889a2248fb6d5d5857bff9f6df5f609f73..8c3af06cb8a1f9f7b73f84d262e09bb7cb0ff9d3 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/ets/Index.ets +++ b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/ets/Index.ets @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 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. - */ - +/* + * Copyright (c) 2023 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 { add } from "./utils/Calc" \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/module.json5 b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/module.json5 index 5b0b8ce38fe6edace4116b07bc3d2b32cb983725..8957711d47f16e303edcc7af17fd3558e95ef37a 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/module.json5 +++ b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/module.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": "libraryOverlay", - "type": "shared", - "description": "$string:shared_desc", - "targetModuleName":"entry", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "pages": "$profile:main_pages" - } +/* + * Copyright (c) 2023 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": "libraryOverlay", + "type": "shared", + "description": "$string:shared_desc", + "targetModuleName":"entry", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } } \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/resources/base/element/string.json b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/resources/base/element/string.json index 8ff4fc989c899f0db87436de16a37ef3f60072c9..e5e5574f732b85e60e36335fcc849273953e1c7e 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/resources/base/element/string.json +++ b/code/BasicFeature/Resource/ResourceManager/libraryOverlay/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "shared_desc", - "value": "description" - }, - { - "name": "test_string", - "value": "base_overlay_test" - } - ] +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + }, + { + "name": "test_string", + "value": "base_overlay_test" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/build-profile.json5 b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/build-profile.json5 index 571f75bc54b40e6fe66dd5a6f43eb2966abf1256..71198c168f48c18dddb4e64f49647d6ee6d0d864 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/build-profile.json5 +++ b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/build-profile.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default" - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/oh-package.json5 b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/oh-package.json5 index 977be1c13ecf514738320677eae34f7acb6adcf0..606c415bd572ac8b0eb92bae3558a3bfbc0e97bd 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/oh-package.json5 +++ b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "libraryruntimeoverlay", - "description": "Please describe the basic information.", - "main": "./src/main/ets/Index.ets", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "libraryruntimeoverlay", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/ets/Index.ets b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/ets/Index.ets index f022fd889a2248fb6d5d5857bff9f6df5f609f73..8c3af06cb8a1f9f7b73f84d262e09bb7cb0ff9d3 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/ets/Index.ets +++ b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/ets/Index.ets @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 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. - */ - +/* + * Copyright (c) 2023 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 { add } from "./utils/Calc" \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/module.json5 b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/module.json5 index e24f6cb56b7956814939cf48b6bb0bf3a8731c0f..f8615ef2e9a3afdc43fce3621966059ca8336155 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/module.json5 +++ b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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": "libraryRuntimeOverlay", - "type": "shared", - "description": "$string:shared_desc", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "pages": "$profile:main_pages" - } +/* + * Copyright (c) 2023 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": "libraryRuntimeOverlay", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } } \ No newline at end of file diff --git a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/resources/base/element/string.json b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/resources/base/element/string.json index 6175c8ac06a81be44a917fe60af4e712715309f3..999663191370eba1f0ce98b600336e16bbe83eaa 100644 --- a/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/resources/base/element/string.json +++ b/code/BasicFeature/Resource/ResourceManager/libraryRuntimeOverlay/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "shared_desc", - "value": "description" - }, - { - "name": "test_string", - "value": "en_US_overlay_RUNTIME" - } - ] +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + }, + { + "name": "test_string", + "value": "en_US_overlay_RUNTIME" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/.gitignore b/code/BasicFeature/Security/Asset/.gitignore old mode 100755 new mode 100644 index f11a3ee29a5ef1ae57676e71019f86b386410956..0e158c3f26319059b259982c0f05f4537e86b13f --- a/code/BasicFeature/Security/Asset/.gitignore +++ b/code/BasicFeature/Security/Asset/.gitignore @@ -1,11 +1,11 @@ -/node_modules -/oh_modules -/local.properties -/.idea -**/build -/.hvigor -.cxx -/.clangd -/.clang-format -/.clang-tidy -**/.test +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test diff --git a/code/BasicFeature/Security/Asset/AppScope/app.json5 b/code/BasicFeature/Security/Asset/AppScope/app.json5 old mode 100755 new mode 100644 index bd5d03e2edd6077b157762bce073b36d7bd1b21e..4defd2d32e3ba5db357be956fbab28d09c3c3b4e --- a/code/BasicFeature/Security/Asset/AppScope/app.json5 +++ b/code/BasicFeature/Security/Asset/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.asset_sample", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.asset_sample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/BasicFeature/Security/Asset/AppScope/resources/base/element/string.json b/code/BasicFeature/Security/Asset/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 8c7764091f0c535a62ff772c3bba37076a09ae72..416dd17f2be294b52a07f7669f477ca944b0f3c4 --- a/code/BasicFeature/Security/Asset/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Security/Asset/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "asset_sample" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "asset_sample" + } + ] +} diff --git a/code/BasicFeature/Security/Asset/AppScope/resources/base/media/app_icon.png b/code/BasicFeature/Security/Asset/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/AppScope/resources/base/media/back.png b/code/BasicFeature/Security/Asset/AppScope/resources/base/media/back.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/AppScope/resources/base/media/forward.png b/code/BasicFeature/Security/Asset/AppScope/resources/base/media/forward.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/README_zh.md b/code/BasicFeature/Security/Asset/README_zh.md old mode 100755 new mode 100644 index e006f1c7bba2af6b6cd0d8758e4f752174f98171..aaef098d85bd276f73a60050b4648fe42443d322 --- a/code/BasicFeature/Security/Asset/README_zh.md +++ b/code/BasicFeature/Security/Asset/README_zh.md @@ -1,110 +1,110 @@ -# 关键资产存储服务 -## 介绍 -本示例使用[@kit.AssetStoreKit](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/security/AssetStoreKit)相关接口实现了对敏感数据的保存、更新、查询、删除操作。 - -实现场景如下: - -1)用户使用本应用保存密码或信用卡号。 - -2)用户更新本应用管理的密码或信用卡号。 - -3)用户查询本应用管理的密码或信用卡号。 - -4)用户删除本应用管理的密码或信用卡号。 - -## 效果预览 -| **保存页面** | **删除页面** | **更新列表页面** | **更新编辑页面** | -|---------|----------|------------|----------| -|![](screenshots/save.jpeg)|![](screenshots/delete.jpeg)|![](screenshots/update_list.jpeg)|![](screenshots/update_edit.jpeg)| -| **查询页面** | **批量查询结果页面** | **单个查询结果页面** | -![](screenshots/query.jpeg)|![](screenshots/batch_query_result.jpeg)|![](screenshots/single_query_result.jpeg)| - -使用说明: -* 保存敏感数据: - * 输入账号、密码、标签,其中标签可以填写多个,但不超过4个 - * 点击“保存”按钮 - -* 删除敏感数据,可使用以下任意一种方式删除: - * 批量删除:不输入任何信息,或输入单个或多个标签),点击“删除”按钮 - * 单个删除:输入账号、标签(可选),点击“删除”按钮 -* 更新敏感数据: - * 点击标题栏的“更新”,进入更新页面 - * 在显示的账号列表中,点击待更新的账号 - * 输入锁屏密码,进入编辑界面 - * 输入更新后的密码和标签,点击“更新” -* 查询敏感数据,可使用以下任意一种方式删除: - * 批量查询:不输入任何信息,或输入单个或多个标签),点击“查询”按钮,显示保存的信息列表,不含“密码/信用卡号” - * 单个查询:输入账号、标签(可选),点击“查询”按钮,输入锁屏密码,显示该账号详细信息,含“密码/信用卡号” - -## 工程目录 -``` -entry/src/main/ets/ -|---entryAbility -| |---EntryAbility.ts -|---model -| |---AssetModel.ets // 关键资产存储模型文件 -|---pages -| |---Index.ets // 主页面 -| |---QueryResultPage.ets // 查询结果界面 -| |---UpdatePage.ets // 更新页面 -``` -## 具体实现 -本应用分为四个主页面:保存、删除、更新、查询,通过TabBuilder组件实现页面直接的切换。 -* **保存页面**:解析用户输入的账号、密码、标签信息,传入@kit.AssetStoreKit提供的add接口,从而实现将短敏感数据存储到关键资产存储服务中。 - -* **删除页面**:解析用户输入的账号、标签信息,传入@kit.AssetStoreKit提供的remove接口,删除满足条件的短敏感数据。 - -* **更新页面**: - - 1)调用@kit.AssetStoreKit提供的query接口,查询关键资产中存储的全量账号。 - - 2)调用@kit.AssetStoreKit提供的preQuery接口,将返回的challenge传给@kit.UserAuthenticationKit提供的on接口。 - - 3)待用户输入锁屏密码后,将onResult接口返回的AuthToken传给@kit.AssetStoreKit提供的query接口,用以查询旧的敏感数据明文。 - - 4)解析用户输入的账号、标签信息,传入@kit.AssetStoreKit提供的update接口,更新关键资产存储服务中存储的敏感数据。 - - 5)退出更新界面时,调用@kit.AssetStoreKit提供的postQuery接口清理资源 - -* **查询页面**: - - 用户未输入账号: - - 解析用户输入的标签信息,传入@kit.AssetStoreKit提供的query接口,查询关键资产存储服务中存储的账号、标签。 - - 用户输入了账号: - - 1)调用@kit.AssetStoreKit提供的preQuery接口,将返回的challenge传给@kit.UserAuthenticationKit提供的on接口。 - - 2)待用户输入锁屏密码后,将onResult接口返回的AuthToken、用户输入的账号、标签信息传给@kit.AssetStoreKit提供的query接口,用以查询敏感数据明文。 - - 3)调用@kit.AssetStoreKit提供的postQuery接口清理资源。 - -## 相关权限 -[ohos.permission.ACCESS_BIOMETRIC](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccess_biometric) - -[ohos.permission.STORE_PERSISTENT_DATA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionstore_persistent_data) - -## 依赖 -不涉及 - -## 约束与限制 -1.本示例仅支持标准系统上运行。 - -2.本示例支持API11版本SDK,SDK版本号(API Version 11 Release), 镜像版本号(4.1Release)。 - -3.本示例需要使用DevEco Studio版本号(4.1Release)及以上版本才可编译运行。 - -4.本示例需要在设备设置锁屏密码后使用。其中,更新、查询结果页面输入锁屏密码方可进入。 - -## 下载 -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/Security/Asset/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master - +# 关键资产存储服务 +## 介绍 +本示例使用[@kit.AssetStoreKit](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/security/AssetStoreKit)相关接口实现了对敏感数据的保存、更新、查询、删除操作。 + +实现场景如下: + +1)用户使用本应用保存密码或信用卡号。 + +2)用户更新本应用管理的密码或信用卡号。 + +3)用户查询本应用管理的密码或信用卡号。 + +4)用户删除本应用管理的密码或信用卡号。 + +## 效果预览 +| **保存页面** | **删除页面** | **更新列表页面** | **更新编辑页面** | +|---------|----------|------------|----------| +|![](screenshots/save.jpeg)|![](screenshots/delete.jpeg)|![](screenshots/update_list.jpeg)|![](screenshots/update_edit.jpeg)| +| **查询页面** | **批量查询结果页面** | **单个查询结果页面** | +![](screenshots/query.jpeg)|![](screenshots/batch_query_result.jpeg)|![](screenshots/single_query_result.jpeg)| + +使用说明: +* 保存敏感数据: + * 输入账号、密码、标签,其中标签可以填写多个,但不超过4个 + * 点击“保存”按钮 + +* 删除敏感数据,可使用以下任意一种方式删除: + * 批量删除:不输入任何信息,或输入单个或多个标签),点击“删除”按钮 + * 单个删除:输入账号、标签(可选),点击“删除”按钮 +* 更新敏感数据: + * 点击标题栏的“更新”,进入更新页面 + * 在显示的账号列表中,点击待更新的账号 + * 输入锁屏密码,进入编辑界面 + * 输入更新后的密码和标签,点击“更新” +* 查询敏感数据,可使用以下任意一种方式删除: + * 批量查询:不输入任何信息,或输入单个或多个标签),点击“查询”按钮,显示保存的信息列表,不含“密码/信用卡号” + * 单个查询:输入账号、标签(可选),点击“查询”按钮,输入锁屏密码,显示该账号详细信息,含“密码/信用卡号” + +## 工程目录 +``` +entry/src/main/ets/ +|---entryAbility +| |---EntryAbility.ts +|---model +| |---AssetModel.ets // 关键资产存储模型文件 +|---pages +| |---Index.ets // 主页面 +| |---QueryResultPage.ets // 查询结果界面 +| |---UpdatePage.ets // 更新页面 +``` +## 具体实现 +本应用分为四个主页面:保存、删除、更新、查询,通过TabBuilder组件实现页面直接的切换。 +* **保存页面**:解析用户输入的账号、密码、标签信息,传入@kit.AssetStoreKit提供的add接口,从而实现将短敏感数据存储到关键资产存储服务中。 + +* **删除页面**:解析用户输入的账号、标签信息,传入@kit.AssetStoreKit提供的remove接口,删除满足条件的短敏感数据。 + +* **更新页面**: + + 1)调用@kit.AssetStoreKit提供的query接口,查询关键资产中存储的全量账号。 + + 2)调用@kit.AssetStoreKit提供的preQuery接口,将返回的challenge传给@kit.UserAuthenticationKit提供的on接口。 + + 3)待用户输入锁屏密码后,将onResult接口返回的AuthToken传给@kit.AssetStoreKit提供的query接口,用以查询旧的敏感数据明文。 + + 4)解析用户输入的账号、标签信息,传入@kit.AssetStoreKit提供的update接口,更新关键资产存储服务中存储的敏感数据。 + + 5)退出更新界面时,调用@kit.AssetStoreKit提供的postQuery接口清理资源 + +* **查询页面**: + + 用户未输入账号: + + 解析用户输入的标签信息,传入@kit.AssetStoreKit提供的query接口,查询关键资产存储服务中存储的账号、标签。 + + 用户输入了账号: + + 1)调用@kit.AssetStoreKit提供的preQuery接口,将返回的challenge传给@kit.UserAuthenticationKit提供的on接口。 + + 2)待用户输入锁屏密码后,将onResult接口返回的AuthToken、用户输入的账号、标签信息传给@kit.AssetStoreKit提供的query接口,用以查询敏感数据明文。 + + 3)调用@kit.AssetStoreKit提供的postQuery接口清理资源。 + +## 相关权限 +[ohos.permission.ACCESS_BIOMETRIC](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccess_biometric) + +[ohos.permission.STORE_PERSISTENT_DATA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionstore_persistent_data) + +## 依赖 +不涉及 + +## 约束与限制 +1.本示例仅支持标准系统上运行。 + +2.本示例支持API11版本SDK,SDK版本号(API Version 11 Release), 镜像版本号(4.1Release)。 + +3.本示例需要使用DevEco Studio版本号(4.1Release)及以上版本才可编译运行。 + +4.本示例需要在设备设置锁屏密码后使用。其中,更新、查询结果页面输入锁屏密码方可进入。 + +## 下载 +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/Security/Asset/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master + ``` \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/build-profile.json5 b/code/BasicFeature/Security/Asset/build-profile.json5 old mode 100755 new mode 100644 index bba5ac612ef0f88e071483e2d20cbc56e6084c7c..4ed303e76d2642cbcb7bf7658f28209325ee2723 --- a/code/BasicFeature/Security/Asset/build-profile.json5 +++ b/code/BasicFeature/Security/Asset/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/* + * Copyright (c) 2024 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/BasicFeature/Security/Asset/entry/.gitignore b/code/BasicFeature/Security/Asset/entry/.gitignore old mode 100755 new mode 100644 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..e2713a2779c5a3e0eb879efe6115455592caeea5 --- a/code/BasicFeature/Security/Asset/entry/.gitignore +++ b/code/BasicFeature/Security/Asset/entry/.gitignore @@ -1,6 +1,6 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx +/node_modules +/oh_modules +/.preview +/build +/.cxx /.test \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/build-profile.json5 b/code/BasicFeature/Security/Asset/entry/build-profile.json5 old mode 100755 new mode 100644 index 8830cfe9f6f8523161bcf2c2821ac5a87374f7ee..ba27ce5b7896224c86a5d3a58cd57523022e1160 --- a/code/BasicFeature/Security/Asset/entry/build-profile.json5 +++ b/code/BasicFeature/Security/Asset/entry/build-profile.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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', - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 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', + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/hvigorfile.ts b/code/BasicFeature/Security/Asset/entry/hvigorfile.ts old mode 100755 new mode 100644 index ba9480d0a9291ab74ff5856e77634a1c05d027a9..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- a/code/BasicFeature/Security/Asset/entry/hvigorfile.ts +++ b/code/BasicFeature/Security/Asset/entry/hvigorfile.ts @@ -1,6 +1,6 @@ -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. */ -} +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/Security/Asset/entry/oh-package.json5 b/code/BasicFeature/Security/Asset/entry/oh-package.json5 old mode 100755 new mode 100644 index 7dca654ad829fb63b53c360d09f536e20bb0c9bd..f18954a32b5a92fe55665dfcb3b63412a2a45963 --- a/code/BasicFeature/Security/Asset/entry/oh-package.json5 +++ b/code/BasicFeature/Security/Asset/entry/oh-package.json5 @@ -1,11 +1,11 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dynamicDependencies": {}, - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dynamicDependencies": {}, + "dependencies": {} +} diff --git a/code/BasicFeature/Security/Asset/entry/src/main/ets/common/Logger.ts b/code/BasicFeature/Security/Asset/entry/src/main/ets/common/Logger.ts old mode 100755 new mode 100644 index c4389eead56641d396b7f97926cd298d9cd39b6e..e434dc8aa9a1bc0d45e28c67dd31621de41d4811 --- a/code/BasicFeature/Security/Asset/entry/src/main/ets/common/Logger.ts +++ b/code/BasicFeature/Security/Asset/entry/src/main/ets/common/Logger.ts @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import hilog from '@ohos.hilog'; - -/** - * Common log for all features. - */ -export class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - } - - isLoggable(level: number): void { - hilog.isLoggable(this.domain, this.prefix, level); - } -} - -export let logger = new Logger('[Sample_FileManager]'); - -export function myparseInt(s: string, n: number) { - return parseInt(s, n) +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import hilog from '@ohos.hilog'; + +/** + * Common log for all features. + */ +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } + + isLoggable(level: number): void { + hilog.isLoggable(this.domain, this.prefix, level); + } +} + +export let logger = new Logger('[Sample_FileManager]'); + +export function myparseInt(s: string, n: number) { + return parseInt(s, n) } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/Security/Asset/entry/src/main/ets/entryability/EntryAbility.ts old mode 100755 new mode 100644 index ebb6ff604ef1b5cbe5d8a430ac33b50a1d429160..83b1c4540d75e5a591da4d9be1a3eab4444d2853 --- a/code/BasicFeature/Security/Asset/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/Security/Asset/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2024 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 } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { UIAbility } from '@kit.AbilityKit'; -import { Want } from '@kit.AbilityKit'; -import { window } from '@kit.ArkUI'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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 } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { UIAbility } from '@kit.AbilityKit'; +import { Want } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/Security/Asset/entry/src/main/ets/model/AssetModel.ets b/code/BasicFeature/Security/Asset/entry/src/main/ets/model/AssetModel.ets old mode 100755 new mode 100644 index 9d0f2b701c056f20c4e753487474ade72c568aca..f61218649af53893aa55325231af144b62fa181e --- a/code/BasicFeature/Security/Asset/entry/src/main/ets/model/AssetModel.ets +++ b/code/BasicFeature/Security/Asset/entry/src/main/ets/model/AssetModel.ets @@ -1,333 +1,333 @@ -/* - * Copyright (c) 2024 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 { asset } from '@kit.AssetStoreKit'; -import { promptAction } from '@kit.ArkUI'; -import { util } from '@kit.ArkTS'; -import { logger } from '../common/Logger'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - -let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - -function removeDuplicateAndSort(arr: string[]): string[] { - let newArr = new Array(); - for (let i = 0; i < arr.length; i++) { - if (newArr.indexOf(arr[i]) === -1 && arr[i] != '') { - newArr.push(arr[i]); - } - } - return newArr.sort(); -} - -export function log(resource: Resource) { - promptAction.showToast({ message: resource }) - logger.info(getContext().resourceManager.getStringSync(resource)); -} - -export function stringToArray(str: string): Uint8Array { - let textEncoder = new util.TextEncoder(); - return textEncoder.encodeInto(str); -} - -function newNullArray(): Uint8Array { - return new Uint8Array([0]); -} - -function arrayToString(arr: Uint8Array): string { - let textDecoder = util.TextDecoder.create("utf-8", { - ignoreBOM: true - }); - let str = textDecoder.decodeWithStream(arr, { - stream: false - }) - return str; -} - -export async function addAssetPromise(account: string, password: string, label: string) { - let labelList: Array = label.split(';'); - labelList = removeDuplicateAndSort(labelList); - if (labelList.length > 4) { - log($r('app.string.save_failed_for_label')) - return; - } - let attr: asset.AssetMap = new Map(); - attr.set(asset.Tag.ALIAS, stringToArray(account)) - attr.set(asset.Tag.SECRET, stringToArray(password)) - if (labelList[0]) { - attr.set(asset.Tag.DATA_LABEL_NORMAL_1, stringToArray(labelList[0])) - } - if (labelList[1]) { - attr.set(asset.Tag.DATA_LABEL_NORMAL_2, stringToArray(labelList[1])) - } - if (labelList[2]) { - attr.set(asset.Tag.DATA_LABEL_NORMAL_3, stringToArray(labelList[2])) - } - if (labelList[3]) { - attr.set(asset.Tag.DATA_LABEL_NORMAL_4, stringToArray(labelList[3])) - } - attr.set(asset.Tag.AUTH_TYPE, asset.AuthType.ANY) - attr.set(asset.Tag.IS_PERSISTENT, true) - try { - await asset.add(attr); - log($r('app.string.save_success')) - } catch (error) { - if (error.code === 24000003) { - log($r('app.string.save_failed_for_account_exist')); - } else { - log($r('app.string.save_failed')) - } - } -} - -export async function removeAssetPromise(deleteAccount: string, deleteLabel: string) { - let attr: asset.AssetMap = new Map(); - if (deleteAccount.length > 0) { - attr.set(asset.Tag.ALIAS, stringToArray(deleteAccount)) - } - if (deleteLabel.length == 0) { - try { - await asset.remove(attr); - log($r('app.string.remove_success')) - } catch (error) { - if (error.code === 24000002) { - log($r('app.string.remove_failed_for_account_not_exist')); - } else { - log($r('app.string.remove_failed')) - } - } - } else { - let labelList = deleteLabel.split(';'); - labelList = removeDuplicateAndSort(labelList); - let assetList: asset.AssetMap[] = await getArrangedMap(deleteAccount, labelList) - if (assetList.length == 0) { - log($r('app.string.remove_failed_for_account_not_exist')); - return; - } - let map: Map = new Map(); - for (let i = 0; i < assetList.length; i++) { - map.set(asset.Tag.ALIAS, assetList[i].get(asset.Tag.ALIAS) as Uint8Array); - try { - await asset.remove(map) - } catch (error) { - log($r('app.string.remove_failed')) - return; - } - } - log($r('app.string.remove_success')) - } -} - -function compareArray(array1: Uint8Array, array2: Uint8Array): boolean { - return JSON.stringify(array1) == JSON.stringify(array2); -} - -function addLabelInfo(label: string, tag: asset.Tag, account: asset.AssetMap, emptyArray: Uint8Array): string { - if (account.has(tag) && !compareArray(account.get(tag) as Uint8Array, emptyArray)) { - label += arrayToString(account.get(tag) as Uint8Array) + ';' - } - return label; -} - -function addElement(attr: asset.AssetMap, label: string, key: asset.Tag) { - if (label){ - attr.set(key, stringToArray(label)) - } else { - attr.set(key, newNullArray()) - } -} - -let normalLabelList: Array = new Array(asset.Tag.DATA_LABEL_NORMAL_1, - asset.Tag.DATA_LABEL_NORMAL_2, asset.Tag.DATA_LABEL_NORMAL_3, asset.Tag.DATA_LABEL_NORMAL_4); - -// asset获取的map转换为显示map -function convertAssetList(assetList: asset.AssetMap[], accountList: Map[]): Array> { - for (let account of assetList) { - let map: Map = new Map(); - let alias = arrayToString(account.get(asset.Tag.ALIAS) as Uint8Array); - if (account.has(asset.Tag.SECRET)) { - let secret = arrayToString(account.get(asset.Tag.SECRET) as Uint8Array); - map.set('secret', secret); - } - let label = '' - let emptyArray = newNullArray(); - for (let currentLabel of normalLabelList) { - label = addLabelInfo(label, currentLabel, account, emptyArray); - } - label = label.slice(0, label.length - 1) - map.set('alias', alias); - map.set('label', label) - accountList.push(map); - } - return accountList; -} - -export async function updateAssetPromise(reserveAccount: string, reservePassword: string, reserveLabel: string) { - let labelList = reserveLabel.split(';'); - labelList = removeDuplicateAndSort(labelList); - if (labelList.length > 4) { - log($r('app.string.update_failed_for_label_over_4')) - return; - } - - let attr: asset.AssetMap = new Map(); - attr.set(asset.Tag.SECRET, stringToArray(reservePassword)) - normalLabelList.forEach((element: asset.Tag, index: number) => { - addElement(attr, labelList[index], element); - }); - - let attr2: asset.AssetMap = new Map(); - attr2.set(asset.Tag.ALIAS, stringToArray(reserveAccount)) - - try { - await asset.update(attr2, attr) - log($r('app.string.update_success')) - } catch (error) { - log($r('app.string.update_failed')); - } -} - -async function getFirstQuery(alias: string, label: string): Promise -{ - let res: Array = new Array(); - let options: asset.Tag[] = [ asset.Tag.DATA_LABEL_NORMAL_1, asset.Tag.DATA_LABEL_NORMAL_2, - asset.Tag.DATA_LABEL_NORMAL_3, asset.Tag.DATA_LABEL_NORMAL_4 ]; - for (let i = 0; i < options.length; i++) { - let map: asset.AssetMap = new Map(); - if (alias.length > 0) { - map.set(asset.Tag.ALIAS, stringToArray(alias)); - map.set(asset.Tag.RETURN_TYPE, asset.ReturnType.ALL) - } - map.set(options[i], stringToArray(label)); - try { - let temp: Array = await asset.query(map) - res = res.concat(temp); - } catch(e) { - // skip the error: not found - } - } - return res; -} - -function getLabelList(input: asset.AssetMap): Array -{ - let tmp = new Array(); - if (input.has(asset.Tag.DATA_LABEL_NORMAL_1)) { - tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_1) as Uint8Array)); - } - if (input.has(asset.Tag.DATA_LABEL_NORMAL_2)) { - tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_2) as Uint8Array)); - } - if (input.has(asset.Tag.DATA_LABEL_NORMAL_3)) { - tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_3) as Uint8Array)); - } - if (input.has(asset.Tag.DATA_LABEL_NORMAL_4)) { - tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_4) as Uint8Array)); - } - return tmp; -} - -async function getArrangedMap(alias: string, labels: string[]): Promise -{ - let first_query: asset.AssetMap[] = await getFirstQuery(alias, labels[0]); - let res: asset.AssetMap[] = first_query.filter((map: asset.AssetMap) => { - let list: Array = getLabelList(map); - for (let i = 1; i < labels.length; i++) { - if (list.indexOf(labels[i]) < 0) { - return false; - } - } - return true; - }); - return res; -} - -export async function queryAssetPromise(checkAccount: string, checkLabel: string): Promise>> { - let accountList: Map[] = new Array>(); - let assetMap: asset.AssetMap = new Map(); - if (checkAccount.length > 0) { - assetMap.set(asset.Tag.ALIAS, stringToArray(checkAccount)) - assetMap.set(asset.Tag.RETURN_TYPE, asset.ReturnType.ALL) - } - if (checkLabel.length == 0) { // query condition do not contain label. - try { - let assetList: Array = await asset.query(assetMap); - return convertAssetList(assetList, accountList); - } catch (error) { - if (error.code === 24000002) { - log($r('app.string.query_no_result')); - } else { - log($r('app.string.query_failed')); - } - return new Array>(); - } - } else { - let labelList: Array = checkLabel.split(';'); - labelList = removeDuplicateAndSort(labelList); - let assetList: asset.AssetMap[] = await getArrangedMap(checkAccount, labelList) - if (assetList.length == 0) { - log($r('app.string.query_no_result')); - return new Array>(); - } - return convertAssetList(assetList, accountList); - } -} - -export async function preQueryAssetPromise(checkAccount: string): Promise { - let assetMap: asset.AssetMap = new Map(); - assetMap.set(asset.Tag.AUTH_VALIDITY_PERIOD, 10 * 60) - assetMap.set(asset.Tag.AUTH_TYPE, asset.AuthType.ANY) - if (checkAccount.length > 0) { - assetMap.set(asset.Tag.ALIAS, stringToArray(checkAccount)) - } - try { - return await asset.preQuery(assetMap) - } catch (error) { - return new Uint8Array(0) - } -} - -export async function queryAuthAssetPromise(checkAccount: string, challenge: Uint8Array, - authToken: Uint8Array): Promise> { - let attr: asset.AssetMap = new Map(); - let account: Map = new Map(); - if (checkAccount.length > 0) { - attr.set(asset.Tag.ALIAS, stringToArray(checkAccount)); - attr.set(asset.Tag.RETURN_TYPE, asset.ReturnType.ALL); - attr.set(asset.Tag.AUTH_CHALLENGE, challenge); - attr.set(asset.Tag.AUTH_TOKEN, authToken) - } - try { - let data: Array = await asset.query(attr); - let accountList: Map[] = new Array>(); - accountList = convertAssetList(data, accountList); - return accountList[0] - } catch (error) { - if (error.code === 24000002) { - log($r('app.string.query_no_result')); - } else { - log($r('app.string.query_failed')); - } - return account; - } -} - -export async function postQueryAssetPromise(challenge: Uint8Array) { - let attr: asset.AssetMap = new Map(); - attr.set(asset.Tag.AUTH_CHALLENGE, challenge); - try { - await asset.postQuery(attr); - } catch (error) { - } -} +/* + * Copyright (c) 2024 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 { asset } from '@kit.AssetStoreKit'; +import { promptAction } from '@kit.ArkUI'; +import { util } from '@kit.ArkTS'; +import { logger } from '../common/Logger'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + +function removeDuplicateAndSort(arr: string[]): string[] { + let newArr = new Array(); + for (let i = 0; i < arr.length; i++) { + if (newArr.indexOf(arr[i]) === -1 && arr[i] != '') { + newArr.push(arr[i]); + } + } + return newArr.sort(); +} + +export function log(resource: Resource) { + promptAction.showToast({ message: resource }) + logger.info(getContext().resourceManager.getStringSync(resource)); +} + +export function stringToArray(str: string): Uint8Array { + let textEncoder = new util.TextEncoder(); + return textEncoder.encodeInto(str); +} + +function newNullArray(): Uint8Array { + return new Uint8Array([0]); +} + +function arrayToString(arr: Uint8Array): string { + let textDecoder = util.TextDecoder.create("utf-8", { + ignoreBOM: true + }); + let str = textDecoder.decodeWithStream(arr, { + stream: false + }) + return str; +} + +export async function addAssetPromise(account: string, password: string, label: string) { + let labelList: Array = label.split(';'); + labelList = removeDuplicateAndSort(labelList); + if (labelList.length > 4) { + log($r('app.string.save_failed_for_label')) + return; + } + let attr: asset.AssetMap = new Map(); + attr.set(asset.Tag.ALIAS, stringToArray(account)) + attr.set(asset.Tag.SECRET, stringToArray(password)) + if (labelList[0]) { + attr.set(asset.Tag.DATA_LABEL_NORMAL_1, stringToArray(labelList[0])) + } + if (labelList[1]) { + attr.set(asset.Tag.DATA_LABEL_NORMAL_2, stringToArray(labelList[1])) + } + if (labelList[2]) { + attr.set(asset.Tag.DATA_LABEL_NORMAL_3, stringToArray(labelList[2])) + } + if (labelList[3]) { + attr.set(asset.Tag.DATA_LABEL_NORMAL_4, stringToArray(labelList[3])) + } + attr.set(asset.Tag.AUTH_TYPE, asset.AuthType.ANY) + attr.set(asset.Tag.IS_PERSISTENT, true) + try { + await asset.add(attr); + log($r('app.string.save_success')) + } catch (error) { + if (error.code === 24000003) { + log($r('app.string.save_failed_for_account_exist')); + } else { + log($r('app.string.save_failed')) + } + } +} + +export async function removeAssetPromise(deleteAccount: string, deleteLabel: string) { + let attr: asset.AssetMap = new Map(); + if (deleteAccount.length > 0) { + attr.set(asset.Tag.ALIAS, stringToArray(deleteAccount)) + } + if (deleteLabel.length == 0) { + try { + await asset.remove(attr); + log($r('app.string.remove_success')) + } catch (error) { + if (error.code === 24000002) { + log($r('app.string.remove_failed_for_account_not_exist')); + } else { + log($r('app.string.remove_failed')) + } + } + } else { + let labelList = deleteLabel.split(';'); + labelList = removeDuplicateAndSort(labelList); + let assetList: asset.AssetMap[] = await getArrangedMap(deleteAccount, labelList) + if (assetList.length == 0) { + log($r('app.string.remove_failed_for_account_not_exist')); + return; + } + let map: Map = new Map(); + for (let i = 0; i < assetList.length; i++) { + map.set(asset.Tag.ALIAS, assetList[i].get(asset.Tag.ALIAS) as Uint8Array); + try { + await asset.remove(map) + } catch (error) { + log($r('app.string.remove_failed')) + return; + } + } + log($r('app.string.remove_success')) + } +} + +function compareArray(array1: Uint8Array, array2: Uint8Array): boolean { + return JSON.stringify(array1) == JSON.stringify(array2); +} + +function addLabelInfo(label: string, tag: asset.Tag, account: asset.AssetMap, emptyArray: Uint8Array): string { + if (account.has(tag) && !compareArray(account.get(tag) as Uint8Array, emptyArray)) { + label += arrayToString(account.get(tag) as Uint8Array) + ';' + } + return label; +} + +function addElement(attr: asset.AssetMap, label: string, key: asset.Tag) { + if (label){ + attr.set(key, stringToArray(label)) + } else { + attr.set(key, newNullArray()) + } +} + +let normalLabelList: Array = new Array(asset.Tag.DATA_LABEL_NORMAL_1, + asset.Tag.DATA_LABEL_NORMAL_2, asset.Tag.DATA_LABEL_NORMAL_3, asset.Tag.DATA_LABEL_NORMAL_4); + +// asset获取的map转换为显示map +function convertAssetList(assetList: asset.AssetMap[], accountList: Map[]): Array> { + for (let account of assetList) { + let map: Map = new Map(); + let alias = arrayToString(account.get(asset.Tag.ALIAS) as Uint8Array); + if (account.has(asset.Tag.SECRET)) { + let secret = arrayToString(account.get(asset.Tag.SECRET) as Uint8Array); + map.set('secret', secret); + } + let label = '' + let emptyArray = newNullArray(); + for (let currentLabel of normalLabelList) { + label = addLabelInfo(label, currentLabel, account, emptyArray); + } + label = label.slice(0, label.length - 1) + map.set('alias', alias); + map.set('label', label) + accountList.push(map); + } + return accountList; +} + +export async function updateAssetPromise(reserveAccount: string, reservePassword: string, reserveLabel: string) { + let labelList = reserveLabel.split(';'); + labelList = removeDuplicateAndSort(labelList); + if (labelList.length > 4) { + log($r('app.string.update_failed_for_label_over_4')) + return; + } + + let attr: asset.AssetMap = new Map(); + attr.set(asset.Tag.SECRET, stringToArray(reservePassword)) + normalLabelList.forEach((element: asset.Tag, index: number) => { + addElement(attr, labelList[index], element); + }); + + let attr2: asset.AssetMap = new Map(); + attr2.set(asset.Tag.ALIAS, stringToArray(reserveAccount)) + + try { + await asset.update(attr2, attr) + log($r('app.string.update_success')) + } catch (error) { + log($r('app.string.update_failed')); + } +} + +async function getFirstQuery(alias: string, label: string): Promise +{ + let res: Array = new Array(); + let options: asset.Tag[] = [ asset.Tag.DATA_LABEL_NORMAL_1, asset.Tag.DATA_LABEL_NORMAL_2, + asset.Tag.DATA_LABEL_NORMAL_3, asset.Tag.DATA_LABEL_NORMAL_4 ]; + for (let i = 0; i < options.length; i++) { + let map: asset.AssetMap = new Map(); + if (alias.length > 0) { + map.set(asset.Tag.ALIAS, stringToArray(alias)); + map.set(asset.Tag.RETURN_TYPE, asset.ReturnType.ALL) + } + map.set(options[i], stringToArray(label)); + try { + let temp: Array = await asset.query(map) + res = res.concat(temp); + } catch(e) { + // skip the error: not found + } + } + return res; +} + +function getLabelList(input: asset.AssetMap): Array +{ + let tmp = new Array(); + if (input.has(asset.Tag.DATA_LABEL_NORMAL_1)) { + tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_1) as Uint8Array)); + } + if (input.has(asset.Tag.DATA_LABEL_NORMAL_2)) { + tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_2) as Uint8Array)); + } + if (input.has(asset.Tag.DATA_LABEL_NORMAL_3)) { + tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_3) as Uint8Array)); + } + if (input.has(asset.Tag.DATA_LABEL_NORMAL_4)) { + tmp.push(arrayToString(input.get(asset.Tag.DATA_LABEL_NORMAL_4) as Uint8Array)); + } + return tmp; +} + +async function getArrangedMap(alias: string, labels: string[]): Promise +{ + let first_query: asset.AssetMap[] = await getFirstQuery(alias, labels[0]); + let res: asset.AssetMap[] = first_query.filter((map: asset.AssetMap) => { + let list: Array = getLabelList(map); + for (let i = 1; i < labels.length; i++) { + if (list.indexOf(labels[i]) < 0) { + return false; + } + } + return true; + }); + return res; +} + +export async function queryAssetPromise(checkAccount: string, checkLabel: string): Promise>> { + let accountList: Map[] = new Array>(); + let assetMap: asset.AssetMap = new Map(); + if (checkAccount.length > 0) { + assetMap.set(asset.Tag.ALIAS, stringToArray(checkAccount)) + assetMap.set(asset.Tag.RETURN_TYPE, asset.ReturnType.ALL) + } + if (checkLabel.length == 0) { // query condition do not contain label. + try { + let assetList: Array = await asset.query(assetMap); + return convertAssetList(assetList, accountList); + } catch (error) { + if (error.code === 24000002) { + log($r('app.string.query_no_result')); + } else { + log($r('app.string.query_failed')); + } + return new Array>(); + } + } else { + let labelList: Array = checkLabel.split(';'); + labelList = removeDuplicateAndSort(labelList); + let assetList: asset.AssetMap[] = await getArrangedMap(checkAccount, labelList) + if (assetList.length == 0) { + log($r('app.string.query_no_result')); + return new Array>(); + } + return convertAssetList(assetList, accountList); + } +} + +export async function preQueryAssetPromise(checkAccount: string): Promise { + let assetMap: asset.AssetMap = new Map(); + assetMap.set(asset.Tag.AUTH_VALIDITY_PERIOD, 10 * 60) + assetMap.set(asset.Tag.AUTH_TYPE, asset.AuthType.ANY) + if (checkAccount.length > 0) { + assetMap.set(asset.Tag.ALIAS, stringToArray(checkAccount)) + } + try { + return await asset.preQuery(assetMap) + } catch (error) { + return new Uint8Array(0) + } +} + +export async function queryAuthAssetPromise(checkAccount: string, challenge: Uint8Array, + authToken: Uint8Array): Promise> { + let attr: asset.AssetMap = new Map(); + let account: Map = new Map(); + if (checkAccount.length > 0) { + attr.set(asset.Tag.ALIAS, stringToArray(checkAccount)); + attr.set(asset.Tag.RETURN_TYPE, asset.ReturnType.ALL); + attr.set(asset.Tag.AUTH_CHALLENGE, challenge); + attr.set(asset.Tag.AUTH_TOKEN, authToken) + } + try { + let data: Array = await asset.query(attr); + let accountList: Map[] = new Array>(); + accountList = convertAssetList(data, accountList); + return accountList[0] + } catch (error) { + if (error.code === 24000002) { + log($r('app.string.query_no_result')); + } else { + log($r('app.string.query_failed')); + } + return account; + } +} + +export async function postQueryAssetPromise(challenge: Uint8Array) { + let attr: asset.AssetMap = new Map(); + attr.set(asset.Tag.AUTH_CHALLENGE, challenge); + try { + await asset.postQuery(attr); + } catch (error) { + } +} diff --git a/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/Index.ets b/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 1a72b1df8d4de1648dd19b3d584209dd6830145c..ad01ccfdce4ae2f48e7a9c97af9ad922074d8f71 --- a/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/Index.ets +++ b/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/Index.ets @@ -1,700 +1,700 @@ -/* - * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; -import { promptAction } from '@kit.ArkUI'; -import { userAuth } from '@kit.UserAuthenticationKit'; -import { logger } from '../common/Logger'; -import { addAssetPromise, removeAssetPromise, queryAssetPromise, queryAuthAssetPromise, preQueryAssetPromise, log, - postQueryAssetPromise } from '../model/AssetModel'; - -interface AssetItem { - alias: string; - secret: string; - dataLabel: string; -} - -function isReserveClickable(reserveAccount: string, reservePassword: string, reserveLabel: string): boolean { - return reserveAccount !== '' && reservePassword !== '' && reserveLabel != ''; -} - -async function getAuthTokenCallback(challenge: Uint8Array, - callback: (isSuccess: boolean, challenge: Uint8Array) => void) { - const authParam: userAuth.AuthParam = { - challenge: challenge, - authType: [userAuth.UserAuthType.PIN,userAuth.UserAuthType.FACE,userAuth.UserAuthType.FINGERPRINT], - authTrustLevel: userAuth.AuthTrustLevel.ATL1, - }; - const widgetParam: userAuth.WidgetParam = { - title: '请输入锁屏密码', - }; - try { - let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); - userAuthInstance.on('result', { - onResult(result) { - logger.info('userAuthInstance callback result = ' + JSON.stringify(result)); - if (result.result == 12500000) { - logger.info('userAuthInstance callback result success'); - callback(true, result.token) - } else if (result.result == 12500010) { - promptAction.showToast({ message: $r('app.string.please_set_pwd') }) - callback(false, new Uint8Array(0)) - } - } - }); - userAuthInstance.start(); - } catch (error) { - logger.info('auth catch error: ' + JSON.stringify(error)); - promptAction.showToast({ message: $r('app.string.auth_failed') }) - callback(false, new Uint8Array(0)) - } -} - -function convertMapArrayToMapItem(array: Array>): Array -{ - let res = new Array(); - for (let dataElement of array) { - let tmp: AssetItem = { - alias: dataElement.get('alias') as string, - secret: dataElement.get('secret') as string, - dataLabel: dataElement.get('label') as string, - }; - res.push(tmp) - } - return res; -} - -@Entry -@Component -struct Page { - private challenge: Uint8Array = new Uint8Array; - private authToken: Uint8Array = new Uint8Array; - @State reserveAccount: string = ''; - @State reservePassword: string = ''; - @State reserveLabel: string = ''; - @State deleteAccount: string = ''; - @State deleteLabel: string = ''; - @State checkAccount: string = ''; - @State checkLabel: string = ''; - @State eventType: string = '' - @State index: number = 0 - @State assetArr: string[] = new Array(); - private tabsController: TabsController = new TabsController(); - @State view: Visibility[] = [Visibility.Hidden, Visibility.Visible, Visibility.None]; - @State indexView: number = 0 - - @Builder TabBuilder(index: number, name: string) { - Column() { - Row().height(this.index === index ? 8 : 17) - Text(name) - .fontColor(0x182413) - .fontSize(this.index === index ? 30 : 20) - .fontWeight(this.index === index ? 700 : 500) - .lineHeight(this.index === index ? 41 : 28) - .opacity(this.index === index ? 1 : 0.7) - .fontFamily(this.index === index ? 'HarmonyHeiTi-Bold' : 'HarmonyHeiTi-Medium') - .margin(this.index == 0 ? {left: 24} : {left: 0}) - Row().height(this.index === index ? 7 : 11) - } - .width('100%') - } - - build() { - Tabs({ - index: 0, - controller: this.tabsController }) { - /* 保存页面 */ - TabContent() { - Column() { - Column() { - /* 账号 */ - Row() { - Text("*").fontColor(0xFFE84026) - Text($r('app.string.account')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .margin({ top: "2.3%", bottom: "1.1%" }) - } - .width('86.7%').height('7.14%') - .margin({ top: 4 }) - - /* 账号输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_account') }) - .fontColor(0x182431) - .defaultFocus(false) - .id('account_input') - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0.00px' }) - .backgroundColor(Color.Transparent) - .borderRadius(0) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.reserveAccount = value; - }) - .onEditChange((isEditing: boolean) => { - if (isEditing === true) { - this.eventType = 'Down1'; - } - }) - } - .width('86.7%').height('7.14%') - - if (this.eventType === 'Down1') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: 12, - right: 12 - }) - .backgroundColor(0x182431) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - } - - /* 密码 */ - Row() { - Text("*").fontColor(0xFFE84026) - Text($r('app.string.secret_or_card_num')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .fontWeight(500) - .margin({ top: "2.3%", bottom: "1.1%" }) - } - .width('86.7%').height('7.14%') - - /* 密码输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_secret_or_card_num') }) - .type(InputType.Password) - .defaultFocus(false) - .id('secret_input') - .fontColor(0x182431) - .padding({ top: '1.70%', right: '0', bottom: '1.70%', left: '0.00px' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.reservePassword = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down2'; - } - }) - .margin({ top: '0.00vp', right: '-12vp', bottom: '4.00vp', left: '0.00vp' }) - } - .width('86.7%').height('7.14%') - if (this.eventType === 'Down2') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - } - - /* 标签 */ - Row() { - Text("*").fontColor(0xFFE84026) - Text($r('app.string.label')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .fontWeight(500) - .id('label') - .margin({ top: "2.3%", bottom: "1.1%" }) - } - .width('86.7%').height('7.14%') - - /* 标签输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_label') }) - .fontColor(0x182431) - .defaultFocus(false) - .id('label_input') - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0.00px' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.reserveLabel = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down3'; - } - }) - } - .width('86.7%').height('7.14%') - if (this.eventType === 'Down3') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431).margin({ bottom: 4}) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431').margin({ bottom: 4}) - } - } - .backgroundColor(0xFFFFFF).borderRadius(16) - - Blank() - - Row() { - /* 底部按钮 */ - Button($r('app.string.save'), { type: ButtonType.Capsule, stateEffect: false }) - .backgroundColor(0x007DFF).fontColor('white') - .borderRadius(20) - .width('86.7%') - .height(40) - .id('save') - .enabled(isReserveClickable(this.reserveAccount, this.reservePassword, this.reserveLabel)) - .onClick(() => { - addAssetPromise(this.reserveAccount, this.reservePassword, this.reserveLabel) - }) - } - .margin({ bottom: '8.1%' }) - } - .height('100%') - } - .tabBar(this.TabBuilder(0, "保存")) - - /* 删除页面 */ - TabContent() { - Column() { - Column() { - /* 账号 */ - Row() { - Text($r('app.string.account')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('7.14%') - .margin({ top: 4 }) - - /* 用户名输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_account') }) - .fontColor(0x182431) - .defaultFocus(false) - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.deleteAccount = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down4'; - } - }) - } - .width('86.7%').height('7.14%') - - if (this.eventType === 'Down4') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - } - - /* 标签 */ - Row() { - Text($r('app.string.label')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .fontWeight(500) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('7.14%') - - /* 标签输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_label') }) - .fontColor(0x182431) - .defaultFocus(false) - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.deleteLabel = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down5'; - } - }) - } - .width('86.7%').height('7.14%') - - if (this.eventType === 'Down5') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431).margin({ bottom: 4}) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431').margin({ bottom: 4}) - } - } - .backgroundColor(0xFFFFFF).borderRadius(16) - - Blank() - Row() { - /* 底部按钮 */ - Button($r('app.string.delete'), { type: ButtonType.Capsule, stateEffect: false }) - .backgroundColor(0x007DFF).fontColor('white') - .borderRadius(20) - .width('86.7%') - .height(40) - .onClick(() => { - removeAssetPromise(this.deleteAccount, this.deleteLabel) - }) - } - .margin({ bottom: '8.1%' }) - } - .height('100%') - } - .tabBar(this.TabBuilder(1, "删除")) - - /* 更新页面 */ - TabContent() { - Column() { - Column() { - List({ space: 0, initialIndex: 0 }) { // 查询列表 - ForEach(this.assetArr, (item: string) => { - ListItem() { - Column() { - /* 账号 */ - Row() { - Row() { - Text(item) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .textAlign(TextAlign.Start) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - - Blank() - Row() { - Image($r('app.media.forward')) - .height(18) - .width(9) - .fillColor('#182431') - } - } - .width('100%').height('7.14%') - .onClick(async () => { - let account = await queryAuthAssetPromise(item, this.challenge, this.authToken); - router.pushUrl({ - url: 'pages/UpdatePage', - params: { name: item, pwd: account.get('secret'), label: account.get("label") } - }, router.RouterMode.Standard, (err) => { - if (err) { - logger.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - }); - }); - } - .margin({ right: 12, left: 12 }) - } - }, (item: string) => item) - } - .listDirection(Axis.Vertical) // 排列方向 - .divider({ strokeWidth: 1, color: '#0D182431', startMargin: 12, endMargin: 12 }) // 每行之间的分界线 - .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果 - } - .margin({ right: 12, left: 12 }) - .backgroundColor(0xFFFFFF).borderRadius(16) - } - .height('100%') - } - .tabBar(this.TabBuilder(2, "更新")) - - /* 查询页面 */ - TabContent() { - Column() { - Column() { - /* 账号 */ - Row() { - Text($r('app.string.account')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .textAlign(TextAlign.Start) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('7.14%') - .margin({ top: 4 }) - - /* 用户名输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_account') }) - .fontColor(0x182431) - .defaultFocus(false) - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.checkAccount = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down6'; - } - }) - } - .width('86.7%').height('7.14%') - - if (this.eventType === 'Down6') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - } - - /* 标签 */ - Row() { - Text($r('app.string.label')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .textAlign(TextAlign.Start) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('7.14%') - - /* 标签输入 */ - Row() { - TextInput({ placeholder: $r('app.string.please_input_label') }) - .fontColor(0x182431) - .defaultFocus(false) - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.checkLabel = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down7'; - } - }) - } - .width('86.7%').height('7.14%') - - if (this.eventType === 'Down7') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431).margin({bottom: 4}) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431').margin({bottom: 4}) - } - } - .backgroundColor(0xFFFFFF).borderRadius(16) - - Blank() - Row() { - /* 底部按钮 */ - Button($r('app.string.search'), { type: ButtonType.Capsule, stateEffect: false }) - .backgroundColor(0x007DFF) - .borderRadius(20) - .width('86.7%') - .height(40) - .id('search') - .onClick(async () => { - // 需要执行的操作 - // 如果查询的时候输入了账号 则表示精确查询 进行二次访问控制 - if (this.checkAccount.length > 0) { - let challenge = await preQueryAssetPromise(this.checkAccount); - if (challenge.length == 0) { - log($r('app.string.query_failed')) - return - } - this.challenge = challenge - getAuthTokenCallback(this.challenge, async (isSuccess: boolean, authToken: Uint8Array) => { - if (isSuccess) { - logger.info('get auth token success!') - this.authToken = authToken - - let account = await queryAuthAssetPromise(this.checkAccount, this.challenge, this.authToken); - postQueryAssetPromise(this.challenge) - this.challenge = new Uint8Array; - this.authToken = new Uint8Array; - router.pushUrl({ - url: 'pages/QueryResultPage', - params: { - data_array_map: convertMapArrayToMapItem(new Array>(account)) - } - }, router.RouterMode.Standard, (err) => { - if (err) { - logger.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - }); - } - }); - } - else { - let accountList = queryAssetPromise(this.checkAccount, this.checkLabel); - accountList.then(data => { - router.pushUrl({ - url: 'pages/QueryResultPage', // 目标url - params: { - data_array_map: convertMapArrayToMapItem(data) - } - }, router.RouterMode.Standard, (err) => { - if (err) { - logger.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - logger.info('Invoke pushUrl succeeded.'); - }); - }) - } - }) - } - .margin({ bottom: '8.1%' }) - } - .height('100%') - - } - .tabBar(this.TabBuilder(3, "查询")) - } - .scrollable(true) - .backgroundColor(0xf1f3f5) - .barMode(BarMode.Fixed) - .barHeight(56) - .onChange(async (index: number) => { - if (index == 2 && this.index != 2) { - let challenge = await preQueryAssetPromise(""); - logger.info('get challenge success!') - this.challenge = challenge - // get auth token - getAuthTokenCallback(this.challenge, async (isSuccess: boolean, authToken: Uint8Array) => { - if (isSuccess) { - logger.info('get auth token success!') - this.authToken = authToken - let resultList = await queryAssetPromise('', ''); - for (let accountListElement of resultList) { - let str = accountListElement.get('alias'); - if (str !== undefined) { - this.assetArr.push(str) - } - } - } - }); - } else if (this.challenge.length > 0) { - postQueryAssetPromise(this.challenge) - this.challenge = new Uint8Array; - this.authToken = new Uint8Array; - this.assetArr = new Array(); - } - this.index = index; - }) - } -} +/* + * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; +import { promptAction } from '@kit.ArkUI'; +import { userAuth } from '@kit.UserAuthenticationKit'; +import { logger } from '../common/Logger'; +import { addAssetPromise, removeAssetPromise, queryAssetPromise, queryAuthAssetPromise, preQueryAssetPromise, log, + postQueryAssetPromise } from '../model/AssetModel'; + +interface AssetItem { + alias: string; + secret: string; + dataLabel: string; +} + +function isReserveClickable(reserveAccount: string, reservePassword: string, reserveLabel: string): boolean { + return reserveAccount !== '' && reservePassword !== '' && reserveLabel != ''; +} + +async function getAuthTokenCallback(challenge: Uint8Array, + callback: (isSuccess: boolean, challenge: Uint8Array) => void) { + const authParam: userAuth.AuthParam = { + challenge: challenge, + authType: [userAuth.UserAuthType.PIN,userAuth.UserAuthType.FACE,userAuth.UserAuthType.FINGERPRINT], + authTrustLevel: userAuth.AuthTrustLevel.ATL1, + }; + const widgetParam: userAuth.WidgetParam = { + title: '请输入锁屏密码', + }; + try { + let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam); + userAuthInstance.on('result', { + onResult(result) { + logger.info('userAuthInstance callback result = ' + JSON.stringify(result)); + if (result.result == 12500000) { + logger.info('userAuthInstance callback result success'); + callback(true, result.token) + } else if (result.result == 12500010) { + promptAction.showToast({ message: $r('app.string.please_set_pwd') }) + callback(false, new Uint8Array(0)) + } + } + }); + userAuthInstance.start(); + } catch (error) { + logger.info('auth catch error: ' + JSON.stringify(error)); + promptAction.showToast({ message: $r('app.string.auth_failed') }) + callback(false, new Uint8Array(0)) + } +} + +function convertMapArrayToMapItem(array: Array>): Array +{ + let res = new Array(); + for (let dataElement of array) { + let tmp: AssetItem = { + alias: dataElement.get('alias') as string, + secret: dataElement.get('secret') as string, + dataLabel: dataElement.get('label') as string, + }; + res.push(tmp) + } + return res; +} + +@Entry +@Component +struct Page { + private challenge: Uint8Array = new Uint8Array; + private authToken: Uint8Array = new Uint8Array; + @State reserveAccount: string = ''; + @State reservePassword: string = ''; + @State reserveLabel: string = ''; + @State deleteAccount: string = ''; + @State deleteLabel: string = ''; + @State checkAccount: string = ''; + @State checkLabel: string = ''; + @State eventType: string = '' + @State index: number = 0 + @State assetArr: string[] = new Array(); + private tabsController: TabsController = new TabsController(); + @State view: Visibility[] = [Visibility.Hidden, Visibility.Visible, Visibility.None]; + @State indexView: number = 0 + + @Builder TabBuilder(index: number, name: string) { + Column() { + Row().height(this.index === index ? 8 : 17) + Text(name) + .fontColor(0x182413) + .fontSize(this.index === index ? 30 : 20) + .fontWeight(this.index === index ? 700 : 500) + .lineHeight(this.index === index ? 41 : 28) + .opacity(this.index === index ? 1 : 0.7) + .fontFamily(this.index === index ? 'HarmonyHeiTi-Bold' : 'HarmonyHeiTi-Medium') + .margin(this.index == 0 ? {left: 24} : {left: 0}) + Row().height(this.index === index ? 7 : 11) + } + .width('100%') + } + + build() { + Tabs({ + index: 0, + controller: this.tabsController }) { + /* 保存页面 */ + TabContent() { + Column() { + Column() { + /* 账号 */ + Row() { + Text("*").fontColor(0xFFE84026) + Text($r('app.string.account')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .margin({ top: "2.3%", bottom: "1.1%" }) + } + .width('86.7%').height('7.14%') + .margin({ top: 4 }) + + /* 账号输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_account') }) + .fontColor(0x182431) + .defaultFocus(false) + .id('account_input') + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0.00px' }) + .backgroundColor(Color.Transparent) + .borderRadius(0) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.reserveAccount = value; + }) + .onEditChange((isEditing: boolean) => { + if (isEditing === true) { + this.eventType = 'Down1'; + } + }) + } + .width('86.7%').height('7.14%') + + if (this.eventType === 'Down1') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: 12, + right: 12 + }) + .backgroundColor(0x182431) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + } + + /* 密码 */ + Row() { + Text("*").fontColor(0xFFE84026) + Text($r('app.string.secret_or_card_num')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .fontWeight(500) + .margin({ top: "2.3%", bottom: "1.1%" }) + } + .width('86.7%').height('7.14%') + + /* 密码输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_secret_or_card_num') }) + .type(InputType.Password) + .defaultFocus(false) + .id('secret_input') + .fontColor(0x182431) + .padding({ top: '1.70%', right: '0', bottom: '1.70%', left: '0.00px' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.reservePassword = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down2'; + } + }) + .margin({ top: '0.00vp', right: '-12vp', bottom: '4.00vp', left: '0.00vp' }) + } + .width('86.7%').height('7.14%') + if (this.eventType === 'Down2') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + } + + /* 标签 */ + Row() { + Text("*").fontColor(0xFFE84026) + Text($r('app.string.label')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .fontWeight(500) + .id('label') + .margin({ top: "2.3%", bottom: "1.1%" }) + } + .width('86.7%').height('7.14%') + + /* 标签输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_label') }) + .fontColor(0x182431) + .defaultFocus(false) + .id('label_input') + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0.00px' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.reserveLabel = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down3'; + } + }) + } + .width('86.7%').height('7.14%') + if (this.eventType === 'Down3') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431).margin({ bottom: 4}) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431').margin({ bottom: 4}) + } + } + .backgroundColor(0xFFFFFF).borderRadius(16) + + Blank() + + Row() { + /* 底部按钮 */ + Button($r('app.string.save'), { type: ButtonType.Capsule, stateEffect: false }) + .backgroundColor(0x007DFF).fontColor('white') + .borderRadius(20) + .width('86.7%') + .height(40) + .id('save') + .enabled(isReserveClickable(this.reserveAccount, this.reservePassword, this.reserveLabel)) + .onClick(() => { + addAssetPromise(this.reserveAccount, this.reservePassword, this.reserveLabel) + }) + } + .margin({ bottom: '8.1%' }) + } + .height('100%') + } + .tabBar(this.TabBuilder(0, "保存")) + + /* 删除页面 */ + TabContent() { + Column() { + Column() { + /* 账号 */ + Row() { + Text($r('app.string.account')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('7.14%') + .margin({ top: 4 }) + + /* 用户名输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_account') }) + .fontColor(0x182431) + .defaultFocus(false) + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.deleteAccount = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down4'; + } + }) + } + .width('86.7%').height('7.14%') + + if (this.eventType === 'Down4') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + } + + /* 标签 */ + Row() { + Text($r('app.string.label')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .fontWeight(500) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('7.14%') + + /* 标签输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_label') }) + .fontColor(0x182431) + .defaultFocus(false) + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.deleteLabel = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down5'; + } + }) + } + .width('86.7%').height('7.14%') + + if (this.eventType === 'Down5') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431).margin({ bottom: 4}) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431').margin({ bottom: 4}) + } + } + .backgroundColor(0xFFFFFF).borderRadius(16) + + Blank() + Row() { + /* 底部按钮 */ + Button($r('app.string.delete'), { type: ButtonType.Capsule, stateEffect: false }) + .backgroundColor(0x007DFF).fontColor('white') + .borderRadius(20) + .width('86.7%') + .height(40) + .onClick(() => { + removeAssetPromise(this.deleteAccount, this.deleteLabel) + }) + } + .margin({ bottom: '8.1%' }) + } + .height('100%') + } + .tabBar(this.TabBuilder(1, "删除")) + + /* 更新页面 */ + TabContent() { + Column() { + Column() { + List({ space: 0, initialIndex: 0 }) { // 查询列表 + ForEach(this.assetArr, (item: string) => { + ListItem() { + Column() { + /* 账号 */ + Row() { + Row() { + Text(item) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .textAlign(TextAlign.Start) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + + Blank() + Row() { + Image($r('app.media.forward')) + .height(18) + .width(9) + .fillColor('#182431') + } + } + .width('100%').height('7.14%') + .onClick(async () => { + let account = await queryAuthAssetPromise(item, this.challenge, this.authToken); + router.pushUrl({ + url: 'pages/UpdatePage', + params: { name: item, pwd: account.get('secret'), label: account.get("label") } + }, router.RouterMode.Standard, (err) => { + if (err) { + logger.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + }); + }); + } + .margin({ right: 12, left: 12 }) + } + }, (item: string) => item) + } + .listDirection(Axis.Vertical) // 排列方向 + .divider({ strokeWidth: 1, color: '#0D182431', startMargin: 12, endMargin: 12 }) // 每行之间的分界线 + .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果 + } + .margin({ right: 12, left: 12 }) + .backgroundColor(0xFFFFFF).borderRadius(16) + } + .height('100%') + } + .tabBar(this.TabBuilder(2, "更新")) + + /* 查询页面 */ + TabContent() { + Column() { + Column() { + /* 账号 */ + Row() { + Text($r('app.string.account')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .textAlign(TextAlign.Start) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('7.14%') + .margin({ top: 4 }) + + /* 用户名输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_account') }) + .fontColor(0x182431) + .defaultFocus(false) + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.checkAccount = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down6'; + } + }) + } + .width('86.7%').height('7.14%') + + if (this.eventType === 'Down6') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + } + + /* 标签 */ + Row() { + Text($r('app.string.label')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .textAlign(TextAlign.Start) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('7.14%') + + /* 标签输入 */ + Row() { + TextInput({ placeholder: $r('app.string.please_input_label') }) + .fontColor(0x182431) + .defaultFocus(false) + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.checkLabel = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down7'; + } + }) + } + .width('86.7%').height('7.14%') + + if (this.eventType === 'Down7') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431).margin({bottom: 4}) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431').margin({bottom: 4}) + } + } + .backgroundColor(0xFFFFFF).borderRadius(16) + + Blank() + Row() { + /* 底部按钮 */ + Button($r('app.string.search'), { type: ButtonType.Capsule, stateEffect: false }) + .backgroundColor(0x007DFF) + .borderRadius(20) + .width('86.7%') + .height(40) + .id('search') + .onClick(async () => { + // 需要执行的操作 + // 如果查询的时候输入了账号 则表示精确查询 进行二次访问控制 + if (this.checkAccount.length > 0) { + let challenge = await preQueryAssetPromise(this.checkAccount); + if (challenge.length == 0) { + log($r('app.string.query_failed')) + return + } + this.challenge = challenge + getAuthTokenCallback(this.challenge, async (isSuccess: boolean, authToken: Uint8Array) => { + if (isSuccess) { + logger.info('get auth token success!') + this.authToken = authToken + + let account = await queryAuthAssetPromise(this.checkAccount, this.challenge, this.authToken); + postQueryAssetPromise(this.challenge) + this.challenge = new Uint8Array; + this.authToken = new Uint8Array; + router.pushUrl({ + url: 'pages/QueryResultPage', + params: { + data_array_map: convertMapArrayToMapItem(new Array>(account)) + } + }, router.RouterMode.Standard, (err) => { + if (err) { + logger.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + }); + } + }); + } + else { + let accountList = queryAssetPromise(this.checkAccount, this.checkLabel); + accountList.then(data => { + router.pushUrl({ + url: 'pages/QueryResultPage', // 目标url + params: { + data_array_map: convertMapArrayToMapItem(data) + } + }, router.RouterMode.Standard, (err) => { + if (err) { + logger.error(`Invoke pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + logger.info('Invoke pushUrl succeeded.'); + }); + }) + } + }) + } + .margin({ bottom: '8.1%' }) + } + .height('100%') + + } + .tabBar(this.TabBuilder(3, "查询")) + } + .scrollable(true) + .backgroundColor(0xf1f3f5) + .barMode(BarMode.Fixed) + .barHeight(56) + .onChange(async (index: number) => { + if (index == 2 && this.index != 2) { + let challenge = await preQueryAssetPromise(""); + logger.info('get challenge success!') + this.challenge = challenge + // get auth token + getAuthTokenCallback(this.challenge, async (isSuccess: boolean, authToken: Uint8Array) => { + if (isSuccess) { + logger.info('get auth token success!') + this.authToken = authToken + let resultList = await queryAssetPromise('', ''); + for (let accountListElement of resultList) { + let str = accountListElement.get('alias'); + if (str !== undefined) { + this.assetArr.push(str) + } + } + } + }); + } else if (this.challenge.length > 0) { + postQueryAssetPromise(this.challenge) + this.challenge = new Uint8Array; + this.authToken = new Uint8Array; + this.assetArr = new Array(); + } + this.index = index; + }) + } +} diff --git a/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/QueryResultPage.ets b/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/QueryResultPage.ets old mode 100755 new mode 100644 index 1dddce07a7532bb62e76a06fec58c4f3331d1b45..feffc8072bd3ea96807a68d9978e09ca5fe9adcf --- a/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/QueryResultPage.ets +++ b/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/QueryResultPage.ets @@ -1,182 +1,182 @@ -/* - * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; - -interface AssetItem { - alias: string; - secret: string; - dataLabel: string; -} - -@Entry -@Component -struct QueryResultPage { - @State param: Record> = router.getParams() as Record>; - @State data: Array = this.param.data_array_map as Array; - - build() { - Column() { - Row() { - Image($r('app.media.back')) - .height(18) - .width(20) - .onClick(() => { - // 返回到上一页面,相当于pop操作 - router.back(); - }) - - Text($r('app.string.search_result')) - .fontFamily("HarmonyHeiTi") - .fontSize(20) - .fontColor(0x182431) - .lineHeight(28) - .fontWeight(700) - .margin({ left: '5%' }) - .textAlign(TextAlign.Center) - } - .width('86.7%').height(56) - - Column() { - List({ space: 0, initialIndex: 0 }) { - ForEach(this.data, (item: AssetItem) => { - ListItem() { - Column() { - Row() { - Row() { - Text($r('app.string.account')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - Blank() - Row() { - Text(item.alias.toString()) - .opacity(0.6) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(19) - .fontWeight(400) - .baselineOffset(0) - .margin({ top: '2.3%', bottom: '1.1%' }) - } - } - .width('86.7%').height('7.14%') - - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - - /* 密码/信用卡号 */ - if (item.secret) { - Row() { - Row() { - Text($r('app.string.secret_or_card_num')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .textAlign(TextAlign.Start) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - - Blank() - Row() { - Text(item.secret.toString()) - .opacity(0.6) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(19) - .fontWeight(400) - .textAlign(TextAlign.End) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - }.width('86.7%').height('6.7%') - } - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - /* 标签 */ - Row() { - Row() { - Text($r('app.string.label2')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .baselineOffset(0) - .textAlign(TextAlign.Start) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - - Blank() - Row() { - Text(item.dataLabel.toString()) - .opacity(0.6) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(19) - .fontWeight(400) - .baselineOffset(0) - .textAlign(TextAlign.End) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - }.width('86.7%').height('7.14%') - } - .margin({ left: 12, right: -12, bottom: 12 }) - .backgroundColor(0xFFFFFF).borderRadius(16) - } - }, (item: AssetItem) => JSON.stringify(item)) - } - .listDirection(Axis.Vertical) // 排列方向 - .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果 - } - } - .width("100%").height("100%").backgroundColor(0xf1f3f5) - } - - pageTransition() { - // 定义页面进入时的效果,从右侧滑入,时长为1000ms,页面栈发生push操作时该效果才生效 - PageTransitionEnter({ type: RouteType.Push, duration: 300 }) - .slide(SlideEffect.Right) - // 定义页面进入时的效果,从左侧滑入,时长为1000ms,页面栈发生pop操作时该效果才生效 - PageTransitionEnter({ type: RouteType.Pop, duration: 300 }) - .slide(SlideEffect.Left) - // 定义页面退出时的效果,向左侧滑出,时长为1000ms,页面栈发生push操作时该效果才生效 - PageTransitionExit({ type: RouteType.Push, duration: 300 }) - .slide(SlideEffect.Left) - // 定义页面退出时的效果,向右侧滑出,时长为1000ms,页面栈发生pop操作时该效果才生效 - PageTransitionExit({ type: RouteType.Pop, duration: 300 }) - .slide(SlideEffect.Right) - } +/* + * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; + +interface AssetItem { + alias: string; + secret: string; + dataLabel: string; +} + +@Entry +@Component +struct QueryResultPage { + @State param: Record> = router.getParams() as Record>; + @State data: Array = this.param.data_array_map as Array; + + build() { + Column() { + Row() { + Image($r('app.media.back')) + .height(18) + .width(20) + .onClick(() => { + // 返回到上一页面,相当于pop操作 + router.back(); + }) + + Text($r('app.string.search_result')) + .fontFamily("HarmonyHeiTi") + .fontSize(20) + .fontColor(0x182431) + .lineHeight(28) + .fontWeight(700) + .margin({ left: '5%' }) + .textAlign(TextAlign.Center) + } + .width('86.7%').height(56) + + Column() { + List({ space: 0, initialIndex: 0 }) { + ForEach(this.data, (item: AssetItem) => { + ListItem() { + Column() { + Row() { + Row() { + Text($r('app.string.account')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + Blank() + Row() { + Text(item.alias.toString()) + .opacity(0.6) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(19) + .fontWeight(400) + .baselineOffset(0) + .margin({ top: '2.3%', bottom: '1.1%' }) + } + } + .width('86.7%').height('7.14%') + + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + + /* 密码/信用卡号 */ + if (item.secret) { + Row() { + Row() { + Text($r('app.string.secret_or_card_num')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .textAlign(TextAlign.Start) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + + Blank() + Row() { + Text(item.secret.toString()) + .opacity(0.6) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(19) + .fontWeight(400) + .textAlign(TextAlign.End) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + }.width('86.7%').height('6.7%') + } + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + /* 标签 */ + Row() { + Row() { + Text($r('app.string.label2')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .baselineOffset(0) + .textAlign(TextAlign.Start) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + + Blank() + Row() { + Text(item.dataLabel.toString()) + .opacity(0.6) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(19) + .fontWeight(400) + .baselineOffset(0) + .textAlign(TextAlign.End) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + }.width('86.7%').height('7.14%') + } + .margin({ left: 12, right: -12, bottom: 12 }) + .backgroundColor(0xFFFFFF).borderRadius(16) + } + }, (item: AssetItem) => JSON.stringify(item)) + } + .listDirection(Axis.Vertical) // 排列方向 + .edgeEffect(EdgeEffect.Spring) // 滑动到边缘无效果 + } + } + .width("100%").height("100%").backgroundColor(0xf1f3f5) + } + + pageTransition() { + // 定义页面进入时的效果,从右侧滑入,时长为1000ms,页面栈发生push操作时该效果才生效 + PageTransitionEnter({ type: RouteType.Push, duration: 300 }) + .slide(SlideEffect.Right) + // 定义页面进入时的效果,从左侧滑入,时长为1000ms,页面栈发生pop操作时该效果才生效 + PageTransitionEnter({ type: RouteType.Pop, duration: 300 }) + .slide(SlideEffect.Left) + // 定义页面退出时的效果,向左侧滑出,时长为1000ms,页面栈发生push操作时该效果才生效 + PageTransitionExit({ type: RouteType.Push, duration: 300 }) + .slide(SlideEffect.Left) + // 定义页面退出时的效果,向右侧滑出,时长为1000ms,页面栈发生pop操作时该效果才生效 + PageTransitionExit({ type: RouteType.Pop, duration: 300 }) + .slide(SlideEffect.Right) + } } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/UpdatePage.ets b/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/UpdatePage.ets old mode 100755 new mode 100644 index fc578515cf7de878220a6e082350d1a8cf374605..521eb2e66604657dc92912f9aefa7c01cf046133 --- a/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/UpdatePage.ets +++ b/code/BasicFeature/Security/Asset/entry/src/main/ets/pages/UpdatePage.ets @@ -1,220 +1,220 @@ -/* - * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; -import { updateAssetPromise } from '../model/AssetModel'; - -function isUpdateClickable(reservePassword: string): boolean { - return reservePassword !== ''; -} - -@Entry -@Component -struct UpdatePage { - @State params: Record = router.getParams() as Record; - @State user: string = this.params.name as string; - @State pwd: string = this.params.pwd as string; - @State label: string = this.params.label as string; - @State reservePassword: string = this.pwd; - @State reserveLabel: string = this.label; - @State eventType: string = '' - - build() { - Column() { - Row() { - Image($r('app.media.back')) - .height(18) - .width(20) - .onClick(() => { - // 返回到上一页面,相当于pop操作 - router.back(); - }) - Text($r('app.string.update')) - .fontFamily("HarmonyHeiTi") - .fontSize(20) - .fontColor(0x182431) - .lineHeight(28) - .fontWeight(700) - .margin({ left: '5%' }) - .textAlign(TextAlign.Center) - }.width('86.7%').height(56) - - Column() { - /* 账号 */ - Row() { - Text($r('app.string.account')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .textAlign(TextAlign.Start) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('6.7%') - - /* 用户名输入 */ - Row() { - Text(this.user) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .opacity(0.6) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(400) - .textAlign(TextAlign.Start) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('6.7%') - - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - - /* 密码 */ - Row() { - Text("*").fontColor(0xFFE84026) - Text($r('app.string.secret_or_card_num')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('6.7%') - - /* 密码输入 */ - Row() { - TextInput({ text: this.pwd }) - .type(InputType.Password) - .defaultFocus(false) - .fontColor(0x182431) - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) - .backgroundColor(Color.Transparent) - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.reservePassword = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down9'; - } - }) - .margin({ right: -12 }) - } - .width('86.7%').height('6.7%') - - if (this.eventType === 'Down9') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431') - } - - /* 标签 */ - Row() { - Text($r('app.string.label')) - .fontFamily("HarmonyHeiTi") - .fontSize(16) - .fontColor(0x182431) - .lineHeight(22) - .fontWeight(500) - .baselineOffset(0) - .textAlign(TextAlign.Start) - .padding({ top: '2.3%', bottom: '1.1%' }) - } - .width('86.7%').height('6.7%') - - /* 标签输入 */ - Row() { - TextInput({ text: this.label }) - .defaultFocus(false) - .fontColor(0x182431) - .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) - .backgroundColor(Color.Transparent) - .id('label_input') - .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) - .onChange((value: string) => { - this.reserveLabel = value; - }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.eventType = 'Down10'; - } - }) - } - .width('86.7%').height('6.7%') - - if (this.eventType === 'Down10') { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor(0x182431).margin({ bottom: 4 }) - } else { - Line() - .width('86.7%') - .height('0.5vp') - .margin({ - left: '12vp', - right: '12vp' - }) - .backgroundColor('#0D182431').margin({ bottom: 4 }) - } - } - .backgroundColor(0xFFFFFF).borderRadius(16) - - Blank() - Row() { - /* 底部按钮 */ - Button($r('app.string.update'), { type: ButtonType.Capsule, stateEffect: false }) - .backgroundColor(0x007DFF).fontColor('white') - .borderRadius(20) - .width('86.7%') - .height(40) - .id('update_button') - .enabled(isUpdateClickable(this.reservePassword)) - .onClick(() => { - updateAssetPromise(this.user, this.reservePassword, this.reserveLabel) - }) - } - .margin({ bottom: '8.1%' }) - } - // .margin({ right: 12, left: 12 }) - .width("100%").height('100%').backgroundColor(0xf1f3f5) - } +/* + * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; +import { updateAssetPromise } from '../model/AssetModel'; + +function isUpdateClickable(reservePassword: string): boolean { + return reservePassword !== ''; +} + +@Entry +@Component +struct UpdatePage { + @State params: Record = router.getParams() as Record; + @State user: string = this.params.name as string; + @State pwd: string = this.params.pwd as string; + @State label: string = this.params.label as string; + @State reservePassword: string = this.pwd; + @State reserveLabel: string = this.label; + @State eventType: string = '' + + build() { + Column() { + Row() { + Image($r('app.media.back')) + .height(18) + .width(20) + .onClick(() => { + // 返回到上一页面,相当于pop操作 + router.back(); + }) + Text($r('app.string.update')) + .fontFamily("HarmonyHeiTi") + .fontSize(20) + .fontColor(0x182431) + .lineHeight(28) + .fontWeight(700) + .margin({ left: '5%' }) + .textAlign(TextAlign.Center) + }.width('86.7%').height(56) + + Column() { + /* 账号 */ + Row() { + Text($r('app.string.account')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .textAlign(TextAlign.Start) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('6.7%') + + /* 用户名输入 */ + Row() { + Text(this.user) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .opacity(0.6) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(400) + .textAlign(TextAlign.Start) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('6.7%') + + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + + /* 密码 */ + Row() { + Text("*").fontColor(0xFFE84026) + Text($r('app.string.secret_or_card_num')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('6.7%') + + /* 密码输入 */ + Row() { + TextInput({ text: this.pwd }) + .type(InputType.Password) + .defaultFocus(false) + .fontColor(0x182431) + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.reservePassword = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down9'; + } + }) + .margin({ right: -12 }) + } + .width('86.7%').height('6.7%') + + if (this.eventType === 'Down9') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431') + } + + /* 标签 */ + Row() { + Text($r('app.string.label')) + .fontFamily("HarmonyHeiTi") + .fontSize(16) + .fontColor(0x182431) + .lineHeight(22) + .fontWeight(500) + .baselineOffset(0) + .textAlign(TextAlign.Start) + .padding({ top: '2.3%', bottom: '1.1%' }) + } + .width('86.7%').height('6.7%') + + /* 标签输入 */ + Row() { + TextInput({ text: this.label }) + .defaultFocus(false) + .fontColor(0x182431) + .padding({ top: '1.70%', right: '48.00px', bottom: '1.70%', left: '0' }) + .backgroundColor(Color.Transparent) + .id('label_input') + .placeholderFont({ size: 16, weight: 400, family: 'HarmonyHeiTi', style: FontStyle.Normal }) + .onChange((value: string) => { + this.reserveLabel = value; + }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down10'; + } + }) + } + .width('86.7%').height('6.7%') + + if (this.eventType === 'Down10') { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor(0x182431).margin({ bottom: 4 }) + } else { + Line() + .width('86.7%') + .height('0.5vp') + .margin({ + left: '12vp', + right: '12vp' + }) + .backgroundColor('#0D182431').margin({ bottom: 4 }) + } + } + .backgroundColor(0xFFFFFF).borderRadius(16) + + Blank() + Row() { + /* 底部按钮 */ + Button($r('app.string.update'), { type: ButtonType.Capsule, stateEffect: false }) + .backgroundColor(0x007DFF).fontColor('white') + .borderRadius(20) + .width('86.7%') + .height(40) + .id('update_button') + .enabled(isUpdateClickable(this.reservePassword)) + .onClick(() => { + updateAssetPromise(this.user, this.reservePassword, this.reserveLabel) + }) + } + .margin({ bottom: '8.1%' }) + } + // .margin({ right: 12, left: 12 }) + .width("100%").height('100%').backgroundColor(0xf1f3f5) + } } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/module.json5 b/code/BasicFeature/Security/Asset/entry/src/main/module.json5 old mode 100755 new mode 100644 index 1b25b5ea0b407474d143227c89e320c793e67b39..6d653a18b3631f2716b7abe7ebedeb9b10a72e17 --- a/code/BasicFeature/Security/Asset/entry/src/main/module.json5 +++ b/code/BasicFeature/Security/Asset/entry/src/main/module.json5 @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2024 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:app_icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:app_icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.ACCESS_BIOMETRIC" - }, - { - "name": "ohos.permission.STORE_PERSISTENT_DATA" - } - ] - } +/* + * Copyright (c) 2024 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:app_icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:app_icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_BIOMETRIC" + }, + { + "name": "ohos.permission.STORE_PERSISTENT_DATA" + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index 9cd507c238d722034f8bf1ea330390bbb597ebcf..8a31531e1fd375f3e9d854bdd65543c66e3f8dd2 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/color.json @@ -1,32 +1,32 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "column_background_color", - "value": "#F5F5F5" - }, - { - "name": "custom_color", - "value": "#182431" - }, - { - "name": "custom_button_color", - "value": "#007DFF" - }, - { - "name": "custom_blank_color", - "value": "#F2F2F2" - }, - { - "name": "place_color", - "value": "#99000000" - }, - { - "name": "divider_color", - "value": "#0D182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "column_background_color", + "value": "#F5F5F5" + }, + { + "name": "custom_color", + "value": "#182431" + }, + { + "name": "custom_button_color", + "value": "#007DFF" + }, + { + "name": "custom_blank_color", + "value": "#F2F2F2" + }, + { + "name": "place_color", + "value": "#99000000" + }, + { + "name": "divider_color", + "value": "#0D182431" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/float.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/float.json old mode 100755 new mode 100644 index bab9e1ffcd8daaca34d1b52e892f7bbd641c8445..e4140f7cac4a0f591364a6af618cfbea4acc6ed5 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/float.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/float.json @@ -1,188 +1,188 @@ -{ - "float": [ - { - "name": "image_back_size", - "value": "26vp" - }, - { - "name": "avatar_size", - "value": "56vp" - }, - { - "name": "personal_font_size", - "value": "16fp" - }, - { - "name": "title_hobbies_size", - "value": "20fp" - }, - { - "name": "title_line_height", - "value": "28vp" - }, - { - "name": "label_size", - "value": "16fp" - }, - { - "name": "options_height", - "value": "22vp" - }, - { - "name": "toggle_size", - "value": "20vp" - }, - { - "name": "options_top_distance", - "value": "13vp" - }, - { - "name": "options_bottom_distance", - "value": "13vp" - }, - { - "name": "divider_height", - "value": "0.5vp" - }, - { - "name": "list_top_distance", - "value": "14vp" - }, - { - "name": "list_bottom_distance", - "value": "8vp" - }, - { - "name": "options_list_height", - "value": "242vp" - }, - { - "name": "blank_width", - "value": "1vp" - }, - { - "name": "blank_opacity", - "value": "1vp" - }, - { - "name": "blank_height", - "value": "25vp" - }, - { - "name": "dialog_radius", - "value": "32vp" - }, - { - "name": "title_left_distance", - "value": "24vp" - }, - { - "name": "label_left_distance", - "value": "24vp" - }, - { - "name": "dialog_left_distance", - "value": "24vp" - }, - { - "name": "dialog_top_distance", - "value": "14vp" - }, - { - "name": "toggle_right_distance", - "value": "24vp" - }, - { - "name": "dialog_bottom_distance", - "value": "16vp" - }, - { - "name": "button_text_size", - "value": "16fp" - }, - { - "name": "button_height", - "value": "40vp" - }, - { - "name": "text_image_size", - "value": "24vp" - }, - { - "name": "image_left_distance", - "value": "12vp" - }, - { - "name": "text_size", - "value": "16vp" - }, - { - "name": "content_left_distance", - "value": "16vp" - }, - { - "name": "content_right_distance", - "value": "7vp" - }, - { - "name": "arrow_image_width", - "value": "12vp" - }, - { - "name": "arrow_image_height", - "value": "24vp" - }, - { - "name": "arrow_right_distance", - "value": "14vp" - }, - { - "name": "row_top_distance", - "value": "24vp" - }, - { - "name": "row_radius", - "value": "24vp" - }, - { - "name": "row_height", - "value": "64vp" - }, - { - "name": "input_image_size", - "value": "24vp" - }, - { - "name": "input_image_left", - "value": "12vp" - }, - { - "name": "input_text_size", - "value": "16fp" - }, - { - "name": "input_left_inside", - "value": "12vp" - }, - { - "name": "input_right_inside", - "value": "32vp" - }, - { - "name": "text_input_height", - "value": "48vp" - }, - { - "name": "input_row_top", - "value": "24vp" - }, - { - "name": "input_row_radius", - "value": "24vp" - }, - { - "name": "input_row_height", - "value": "64vp" - } - ] +{ + "float": [ + { + "name": "image_back_size", + "value": "26vp" + }, + { + "name": "avatar_size", + "value": "56vp" + }, + { + "name": "personal_font_size", + "value": "16fp" + }, + { + "name": "title_hobbies_size", + "value": "20fp" + }, + { + "name": "title_line_height", + "value": "28vp" + }, + { + "name": "label_size", + "value": "16fp" + }, + { + "name": "options_height", + "value": "22vp" + }, + { + "name": "toggle_size", + "value": "20vp" + }, + { + "name": "options_top_distance", + "value": "13vp" + }, + { + "name": "options_bottom_distance", + "value": "13vp" + }, + { + "name": "divider_height", + "value": "0.5vp" + }, + { + "name": "list_top_distance", + "value": "14vp" + }, + { + "name": "list_bottom_distance", + "value": "8vp" + }, + { + "name": "options_list_height", + "value": "242vp" + }, + { + "name": "blank_width", + "value": "1vp" + }, + { + "name": "blank_opacity", + "value": "1vp" + }, + { + "name": "blank_height", + "value": "25vp" + }, + { + "name": "dialog_radius", + "value": "32vp" + }, + { + "name": "title_left_distance", + "value": "24vp" + }, + { + "name": "label_left_distance", + "value": "24vp" + }, + { + "name": "dialog_left_distance", + "value": "24vp" + }, + { + "name": "dialog_top_distance", + "value": "14vp" + }, + { + "name": "toggle_right_distance", + "value": "24vp" + }, + { + "name": "dialog_bottom_distance", + "value": "16vp" + }, + { + "name": "button_text_size", + "value": "16fp" + }, + { + "name": "button_height", + "value": "40vp" + }, + { + "name": "text_image_size", + "value": "24vp" + }, + { + "name": "image_left_distance", + "value": "12vp" + }, + { + "name": "text_size", + "value": "16vp" + }, + { + "name": "content_left_distance", + "value": "16vp" + }, + { + "name": "content_right_distance", + "value": "7vp" + }, + { + "name": "arrow_image_width", + "value": "12vp" + }, + { + "name": "arrow_image_height", + "value": "24vp" + }, + { + "name": "arrow_right_distance", + "value": "14vp" + }, + { + "name": "row_top_distance", + "value": "24vp" + }, + { + "name": "row_radius", + "value": "24vp" + }, + { + "name": "row_height", + "value": "64vp" + }, + { + "name": "input_image_size", + "value": "24vp" + }, + { + "name": "input_image_left", + "value": "12vp" + }, + { + "name": "input_text_size", + "value": "16fp" + }, + { + "name": "input_left_inside", + "value": "12vp" + }, + { + "name": "input_right_inside", + "value": "32vp" + }, + { + "name": "text_input_height", + "value": "48vp" + }, + { + "name": "input_row_top", + "value": "24vp" + }, + { + "name": "input_row_radius", + "value": "24vp" + }, + { + "name": "input_row_height", + "value": "64vp" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/images.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/images.json old mode 100755 new mode 100644 index 882cd74e445d9c587c9a2160fd4f4d1cfcc9a1a5..75452889f20a409b493c4e37e6cdb86dcf9395f7 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/images.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/images.json @@ -1,8 +1,8 @@ -{ - "boolean": [ - { - "name": "boolean_1", - "value": true - } - ] +{ + "boolean": [ + { + "name": "boolean_1", + "value": true + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/string.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 index c7e9aa74c34b2569d3078c01739e1bd578ed3ee2..d4172851bc28f588add2ce559bad9d6226150404 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/string.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/string.json @@ -1,120 +1,120 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "Main program entry" - }, - { - "name": "EntryAbility_label", - "value": "MultipleWindow" - }, - { - "name": "please_set_pwd", - "value": "please set screen password" - }, - { - "name": "auth_failed", - "value": "auth failed" - }, - { - "name": "account", - "value": "account" - }, - { - "name": "please_input_account", - "value": "please input account" - }, - { - "name": "secret_or_card_num", - "value": "secret or card number" - }, - { - "name": "please_input_secret_or_card_num", - "value": "please input secret or card number" - }, - { - "name": "label", - "value": "label(max 4, split by ;)" - }, - { - "name": "label2", - "value": "label" - }, - { - "name": "please_input_label", - "value": "please input label" - }, - { - "name": "save", - "value": "save" - }, - { - "name": "delete", - "value": "delete" - }, - { - "name": "search", - "value": "search" - }, - { - "name": "search_result", - "value": "search result" - }, - { - "name": "update", - "value": "update" - }, - { - "name": "save_failed_for_label", - "value": "save failed, label num over 4" - }, - { - "name": "save_success", - "value": "save success" - }, - { - "name": "save_failed_for_account_exist", - "value": "save failed for account exist" - }, - { - "name": "save_failed", - "value": "save failed" - }, - { - "name": "remove_success", - "value": "remove success" - }, - { - "name": "remove_failed_for_account_not_exist", - "value": "remove failed for account not exist" - }, - { - "name": "remove_failed", - "value": "remove failed" - }, - { - "name": "update_failed", - "value": "update failed" - }, - { - "name": "update_success", - "value": "update success" - }, - { - "name": "update_failed_for_label_over_4", - "value": "update failed for label over 4" - }, - { - "name": "query_no_result", - "value": "query no result" - }, - { - "name": "query_failed", - "value": "query failed" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "Main program entry" + }, + { + "name": "EntryAbility_label", + "value": "MultipleWindow" + }, + { + "name": "please_set_pwd", + "value": "please set screen password" + }, + { + "name": "auth_failed", + "value": "auth failed" + }, + { + "name": "account", + "value": "account" + }, + { + "name": "please_input_account", + "value": "please input account" + }, + { + "name": "secret_or_card_num", + "value": "secret or card number" + }, + { + "name": "please_input_secret_or_card_num", + "value": "please input secret or card number" + }, + { + "name": "label", + "value": "label(max 4, split by ;)" + }, + { + "name": "label2", + "value": "label" + }, + { + "name": "please_input_label", + "value": "please input label" + }, + { + "name": "save", + "value": "save" + }, + { + "name": "delete", + "value": "delete" + }, + { + "name": "search", + "value": "search" + }, + { + "name": "search_result", + "value": "search result" + }, + { + "name": "update", + "value": "update" + }, + { + "name": "save_failed_for_label", + "value": "save failed, label num over 4" + }, + { + "name": "save_success", + "value": "save success" + }, + { + "name": "save_failed_for_account_exist", + "value": "save failed for account exist" + }, + { + "name": "save_failed", + "value": "save failed" + }, + { + "name": "remove_success", + "value": "remove success" + }, + { + "name": "remove_failed_for_account_not_exist", + "value": "remove failed for account not exist" + }, + { + "name": "remove_failed", + "value": "remove failed" + }, + { + "name": "update_failed", + "value": "update failed" + }, + { + "name": "update_success", + "value": "update success" + }, + { + "name": "update_failed_for_label_over_4", + "value": "update failed for label over 4" + }, + { + "name": "query_no_result", + "value": "query no result" + }, + { + "name": "query_failed", + "value": "query failed" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/stringarray.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/stringarray.json old mode 100755 new mode 100644 index 1e5f24381c81c2c1ebf73076db01ba56ce258c36..d94f89c6f464adcd79c103aae619e78a5300ca9c --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/stringarray.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/element/stringarray.json @@ -1,35 +1,35 @@ -{ - "strarray": [ - { - "name": "sex_array", - "value": [ - { - "value": "male" - }, - { - "value": "female" - } - ] - }, - { - "name": "hobbies_data", - "value": [ - { - "value": "Soccer" - }, - { - "value": "Badminton" - }, - { - "value": "Travelling" - }, - { - "value": "Playing games" - }, - { - "value": "Reading books" - } - ] - } - ] +{ + "strarray": [ + { + "name": "sex_array", + "value": [ + { + "value": "male" + }, + { + "value": "female" + } + ] + }, + { + "name": "hobbies_data", + "value": [ + { + "value": "Soccer" + }, + { + "value": "Badminton" + }, + { + "value": "Travelling" + }, + { + "value": "Playing games" + }, + { + "value": "Reading books" + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/profile/main_pages.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 index 3b2fc05da7558ae5d0b48bc040d9eef1e22d015a..2a125db99d30375ac8efaceb28d7c9475602d491 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/base/profile/main_pages.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,7 @@ -{ - "src": [ - "pages/Index", - "pages/QueryResultPage", - "pages/UpdatePage" - ] -} +{ + "src": [ + "pages/Index", + "pages/QueryResultPage", + "pages/UpdatePage" + ] +} diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/en_US/element/string.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 index 63ea3ee50b282b12fa99457e2541f277a619a54a..6f3c0f004d33391a9a47b274160a5d8054861ad4 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/en_US/element/string.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/en_US/element/string.json @@ -1,120 +1,120 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "please_set_pwd", - "value": "please set screen password" - }, - { - "name": "auth_failed", - "value": "auth failed" - }, - { - "name": "account", - "value": "account" - }, - { - "name": "please_input_account", - "value": "please input account" - }, - { - "name": "secret_or_card_num", - "value": "secret or card number" - }, - { - "name": "please_input_secret_or_card_num", - "value": "please input secret or card number" - }, - { - "name": "label", - "value": "label(max 4, split by ;)" - }, - { - "name": "label2", - "value": "label" - }, - { - "name": "please_input_label", - "value": "please input label" - }, - { - "name": "save", - "value": "save" - }, - { - "name": "delete", - "value": "delete" - }, - { - "name": "search", - "value": "search" - }, - { - "name": "search_result", - "value": "search result" - }, - { - "name": "update", - "value": "update" - }, - { - "name": "save_failed_for_label", - "value": "save failed, label num over 4" - }, - { - "name": "save_success", - "value": "save success" - }, - { - "name": "save_failed_for_account_exist", - "value": "save failed for account exist" - }, - { - "name": "save_failed", - "value": "save failed" - }, - { - "name": "remove_success", - "value": "remove success" - }, - { - "name": "remove_failed_for_account_not_exist", - "value": "remove failed for account not exist" - }, - { - "name": "remove_failed", - "value": "remove failed" - }, - { - "name": "update_failed", - "value": "update failed" - }, - { - "name": "update_success", - "value": "update success" - }, - { - "name": "update_failed_for_label_over_4", - "value": "update failed for label over 4" - }, - { - "name": "query_no_result", - "value": "query no result" - }, - { - "name": "query_failed", - "value": "query failed" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "please_set_pwd", + "value": "please set screen password" + }, + { + "name": "auth_failed", + "value": "auth failed" + }, + { + "name": "account", + "value": "account" + }, + { + "name": "please_input_account", + "value": "please input account" + }, + { + "name": "secret_or_card_num", + "value": "secret or card number" + }, + { + "name": "please_input_secret_or_card_num", + "value": "please input secret or card number" + }, + { + "name": "label", + "value": "label(max 4, split by ;)" + }, + { + "name": "label2", + "value": "label" + }, + { + "name": "please_input_label", + "value": "please input label" + }, + { + "name": "save", + "value": "save" + }, + { + "name": "delete", + "value": "delete" + }, + { + "name": "search", + "value": "search" + }, + { + "name": "search_result", + "value": "search result" + }, + { + "name": "update", + "value": "update" + }, + { + "name": "save_failed_for_label", + "value": "save failed, label num over 4" + }, + { + "name": "save_success", + "value": "save success" + }, + { + "name": "save_failed_for_account_exist", + "value": "save failed for account exist" + }, + { + "name": "save_failed", + "value": "save failed" + }, + { + "name": "remove_success", + "value": "remove success" + }, + { + "name": "remove_failed_for_account_not_exist", + "value": "remove failed for account not exist" + }, + { + "name": "remove_failed", + "value": "remove failed" + }, + { + "name": "update_failed", + "value": "update failed" + }, + { + "name": "update_success", + "value": "update success" + }, + { + "name": "update_failed_for_label_over_4", + "value": "update failed for label over 4" + }, + { + "name": "query_no_result", + "value": "query no result" + }, + { + "name": "query_failed", + "value": "query failed" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/main/resources/zh_CN/element/string.json b/code/BasicFeature/Security/Asset/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 index f31c7688c069a70faf2c56b07cef4f13eccf6ff8..12438c7377131913433632b918d288e5a4c47343 --- a/code/BasicFeature/Security/Asset/entry/src/main/resources/zh_CN/element/string.json +++ b/code/BasicFeature/Security/Asset/entry/src/main/resources/zh_CN/element/string.json @@ -1,120 +1,120 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "please_set_pwd", - "value": "请设置锁屏密码" - }, - { - "name": "auth_failed", - "value": "认证失败" - }, - { - "name": "account", - "value": "账号" - }, - { - "name": "please_input_account", - "value": "请输入账号" - }, - { - "name": "secret_or_card_num", - "value": "密码/信用卡号" - }, - { - "name": "please_input_secret_or_card_num", - "value": "请输入密码/信用卡号" - }, - { - "name": "label", - "value": "标签(最多4个,以;分隔)" - }, - { - "name": "label2", - "value": "标签" - }, - { - "name": "please_input_label", - "value": "请输入标签名称" - }, - { - "name": "save", - "value": "保存" - }, - { - "name": "delete", - "value": "删除" - }, - { - "name": "search", - "value": "查询" - }, - { - "name": "search_result", - "value": "查询结果" - }, - { - "name": "update", - "value": "更新" - }, - { - "name": "save_failed_for_label", - "value": "保存失败,标签数量超过4个" - }, - { - "name": "save_success", - "value": "保存成功" - }, - { - "name": "save_failed_for_account_exist", - "value": "保存失败,账号已存在" - }, - { - "name": "save_failed", - "value": "保存失败" - }, - { - "name": "remove_success", - "value": "删除成功" - }, - { - "name": "remove_failed_for_account_not_exist", - "value": "删除失败,账号不存在" - }, - { - "name": "remove_failed", - "value": "删除失败" - }, - { - "name": "update_failed", - "value": "更新失败" - }, - { - "name": "update_success", - "value": "更新成功" - }, - { - "name": "update_failed_for_label_over_4", - "value": "更新失败,标签数量超过4个" - }, - { - "name": "query_no_result", - "value": "未查询到结果" - }, - { - "name": "query_failed", - "value": "查询失败" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "please_set_pwd", + "value": "请设置锁屏密码" + }, + { + "name": "auth_failed", + "value": "认证失败" + }, + { + "name": "account", + "value": "账号" + }, + { + "name": "please_input_account", + "value": "请输入账号" + }, + { + "name": "secret_or_card_num", + "value": "密码/信用卡号" + }, + { + "name": "please_input_secret_or_card_num", + "value": "请输入密码/信用卡号" + }, + { + "name": "label", + "value": "标签(最多4个,以;分隔)" + }, + { + "name": "label2", + "value": "标签" + }, + { + "name": "please_input_label", + "value": "请输入标签名称" + }, + { + "name": "save", + "value": "保存" + }, + { + "name": "delete", + "value": "删除" + }, + { + "name": "search", + "value": "查询" + }, + { + "name": "search_result", + "value": "查询结果" + }, + { + "name": "update", + "value": "更新" + }, + { + "name": "save_failed_for_label", + "value": "保存失败,标签数量超过4个" + }, + { + "name": "save_success", + "value": "保存成功" + }, + { + "name": "save_failed_for_account_exist", + "value": "保存失败,账号已存在" + }, + { + "name": "save_failed", + "value": "保存失败" + }, + { + "name": "remove_success", + "value": "删除成功" + }, + { + "name": "remove_failed_for_account_not_exist", + "value": "删除失败,账号不存在" + }, + { + "name": "remove_failed", + "value": "删除失败" + }, + { + "name": "update_failed", + "value": "更新失败" + }, + { + "name": "update_success", + "value": "更新成功" + }, + { + "name": "update_failed_for_label_over_4", + "value": "更新失败,标签数量超过4个" + }, + { + "name": "query_no_result", + "value": "未查询到结果" + }, + { + "name": "query_failed", + "value": "查询失败" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/test/Ability.test.ets b/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/test/List.test.ets b/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/testability/TestAbility.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/testability/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets b/code/BasicFeature/Security/Asset/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ets old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/module.json5 b/code/BasicFeature/Security/Asset/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 271c8c41aef33eafa0a920acf0be5622351214dd..a7685a59ea27672ae8074c984c4699bd73f36a5b --- a/code/BasicFeature/Security/Asset/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Security/Asset/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/element/color.json b/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/element/string.json b/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/media/icon.png b/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/BasicFeature/Security/Asset/entry/src/ohosTest/resources/base/profile/test_pages.json old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/hvigor/hvigor-config.json5 b/code/BasicFeature/Security/Asset/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index 2e24124434e6e72604cc002280ff688a90cedd4b..ead0794f85176659fc2cd2f48c8ec4c9366a83bc --- a/code/BasicFeature/Security/Asset/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Security/Asset/hvigor/hvigor-config.json5 @@ -1,18 +1,18 @@ -{ - "hvigorVersion": "4.0.1", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.1" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +{ + "hvigorVersion": "4.0.1", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.1" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/hvigor/hvigor-wrapper.js b/code/BasicFeature/Security/Asset/hvigor/hvigor-wrapper.js old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/hvigorfile.ts b/code/BasicFeature/Security/Asset/hvigorfile.ts old mode 100755 new mode 100644 index 159890e9ee8c4dc8cfff2a03e6207edb86abb0b5..f3cb9f1a87a81687554a76283af8df27d8bda775 --- a/code/BasicFeature/Security/Asset/hvigorfile.ts +++ b/code/BasicFeature/Security/Asset/hvigorfile.ts @@ -1,6 +1,6 @@ -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. */ -} +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/Security/Asset/hvigorw b/code/BasicFeature/Security/Asset/hvigorw old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/hvigorw.bat b/code/BasicFeature/Security/Asset/hvigorw.bat old mode 100755 new mode 100644 index afaca73582a7e11adb8b65881e0deaa269fee543..40079ee7bf944988f3be36136d41be02430a76da --- a/code/BasicFeature/Security/Asset/hvigorw.bat +++ b/code/BasicFeature/Security/Asset/hvigorw.bat @@ -1,77 +1,77 @@ -:: Copyright (c) 2024 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. - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Hvigor startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js -set NODE_EXE=node.exe - -goto start - -:start -@rem Find node.exe -if defined NODE_HOME goto findNodeFromNodeHome - -%NODE_EXE% --version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:findNodeFromNodeHome -set NODE_HOME=%NODE_HOME:"=% -set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% - -if exist "%NODE_EXE_PATH%" goto execute -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:execute -@rem Execute hvigor -"%NODE_EXE%" "%WRAPPER_MODULE_PATH%" %* - -if "%ERRORLEVEL%" == "0" goto hvigorwEnd - -:fail -exit /b 1 - -:hvigorwEnd -if "%OS%" == "Windows_NT" endlocal - -:end +:: Copyright (c) 2024 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. + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Hvigor startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js +set NODE_EXE=node.exe + +goto start + +:start +@rem Find node.exe +if defined NODE_HOME goto findNodeFromNodeHome + +%NODE_EXE% --version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. +echo. +echo Please set the NODE_HOME variable in your environment to match the +echo location of your NodeJs installation. + +goto fail + +:findNodeFromNodeHome +set NODE_HOME=%NODE_HOME:"=% +set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% + +if exist "%NODE_EXE_PATH%" goto execute +echo. +echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. +echo. +echo Please set the NODE_HOME variable in your environment to match the +echo location of your NodeJs installation. + +goto fail + +:execute +@rem Execute hvigor +"%NODE_EXE%" "%WRAPPER_MODULE_PATH%" %* + +if "%ERRORLEVEL%" == "0" goto hvigorwEnd + +:fail +exit /b 1 + +:hvigorwEnd +if "%OS%" == "Windows_NT" endlocal + +:end diff --git a/code/BasicFeature/Security/Asset/oh-package.json5 b/code/BasicFeature/Security/Asset/oh-package.json5 old mode 100755 new mode 100644 index bb904bde41adc10b19f1442086f4b5ec4fb2b96b..e1ab3339210c129361d5b1949257d4b51678a11b --- a/code/BasicFeature/Security/Asset/oh-package.json5 +++ b/code/BasicFeature/Security/Asset/oh-package.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "asset_sample", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dynamicDependencies": {}, - "dependencies": {} -} +/* + * Copyright (c) 2024 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "asset_sample", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dynamicDependencies": {}, + "dependencies": {} +} diff --git a/code/BasicFeature/Security/Asset/ohosTest.md b/code/BasicFeature/Security/Asset/ohosTest.md old mode 100755 new mode 100644 index 0bf4f5abcb9025d439062c055fa30e21820afdab..17e38556d18dce58507819f5c8c2fa0600f52dfd --- a/code/BasicFeature/Security/Asset/ohosTest.md +++ b/code/BasicFeature/Security/Asset/ohosTest.md @@ -1,11 +1,11 @@ -# 关键资产存储服务测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 |是否自动|测试结果| -|------|---------------|-------------------------------------|----------------------------|--------------------------------|--------------------------------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 |是|Pass| -| 添加数据 | 成功拉起应用 | 输入账号密码以及标签 | 弹出保存成功 |是|Pass| -| 更新数据 | 成功拉起应用并存入一条数据 | 点击更新页签,输入锁屏密码,进入其中一条查询结果,修改标签信息,点击保存 | 弹出更新成功 |是|Pass| -| 查询数据 | 成功拉起应用并存入一条数据| 点击查询页签,点击底下的查询按钮 | 跳转到查询页面并且显示查询结果,包含账号标签至少一条 |是|Pass| +# 关键资产存储服务测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 |是否自动|测试结果| +|------|---------------|-------------------------------------|----------------------------|--------------------------------|--------------------------------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 |是|Pass| +| 添加数据 | 成功拉起应用 | 输入账号密码以及标签 | 弹出保存成功 |是|Pass| +| 更新数据 | 成功拉起应用并存入一条数据 | 点击更新页签,输入锁屏密码,进入其中一条查询结果,修改标签信息,点击保存 | 弹出更新成功 |是|Pass| +| 查询数据 | 成功拉起应用并存入一条数据| 点击查询页签,点击底下的查询按钮 | 跳转到查询页面并且显示查询结果,包含账号标签至少一条 |是|Pass| | 删除数据 | 成功拉起应用并存入一条数据| 点击删除页签,点击底下的删除按钮 | 弹出删除成功 |是|Pass| \ No newline at end of file diff --git a/code/BasicFeature/Security/Asset/screenshots/batch_query_result.jpeg b/code/BasicFeature/Security/Asset/screenshots/batch_query_result.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/screenshots/delete.jpeg b/code/BasicFeature/Security/Asset/screenshots/delete.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/screenshots/query.jpeg b/code/BasicFeature/Security/Asset/screenshots/query.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/screenshots/save.jpeg b/code/BasicFeature/Security/Asset/screenshots/save.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/screenshots/single_query_result.jpeg b/code/BasicFeature/Security/Asset/screenshots/single_query_result.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/screenshots/update_edit.jpeg b/code/BasicFeature/Security/Asset/screenshots/update_edit.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/Asset/screenshots/update_list.jpeg b/code/BasicFeature/Security/Asset/screenshots/update_list.jpeg old mode 100755 new mode 100644 diff --git a/code/BasicFeature/Security/CryptoFramework/AppScope/app.json5 b/code/BasicFeature/Security/CryptoFramework/AppScope/app.json5 index 50f2e32383533f0f81fe74a943de5682ddf60433..eaf26bde085114af041ef9bf67f7098277eef0f5 100644 --- a/code/BasicFeature/Security/CryptoFramework/AppScope/app.json5 +++ b/code/BasicFeature/Security/CryptoFramework/AppScope/app.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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.cryptoframework", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name", - "distributedNotificationEnabled": true - } -} +/* + * Copyright (c) 2023 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.cryptoframework", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/AppScope/resources/base/element/string.json b/code/BasicFeature/Security/CryptoFramework/AppScope/resources/base/element/string.json index 45d2fa5fde910dac3bc789b8dfd91a7c77f6f88b..5f3defbb3fc70d7a4bc3ae18438c3ba1d8a1cb31 100644 --- a/code/BasicFeature/Security/CryptoFramework/AppScope/resources/base/element/string.json +++ b/code/BasicFeature/Security/CryptoFramework/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "cryptoFramework" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "cryptoFramework" + } + ] +} diff --git a/code/BasicFeature/Security/CryptoFramework/README.md b/code/BasicFeature/Security/CryptoFramework/README.md index 2fd9930f916ed2fc79e98f5e168f775c3d45c174..0e7ffad35c208e917616ac6ef42d2d33a0763221 100644 --- a/code/BasicFeature/Security/CryptoFramework/README.md +++ b/code/BasicFeature/Security/CryptoFramework/README.md @@ -1,52 +1,52 @@ -# Crypto Framework - -### Introduction - -This sample shows how [@ohos.security.cryptoFramework](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md) works to implement the function of encrypting, decrypting, signing and verifying text file. The implementation scenario is as follows: - -1. The software needs to encrypt and store the local text file, and it needs to call Crypto Framework to select the key text file and encrypt the local text file, among which the key text file can be generated by Crypto Framework. - -2. The software needs to decrypt and store the local text file, and needs to call Crypto Framework to select the key text file and decrypt the local text file, where the key text file can be generated by Crypto Framework. - -3. The software needs to sign the stored local text file, call the encryption and Crypto Framework to select the key text file, and sign the integrity of the local text file, among which the key text file can be generated by Crypto Framework. - -4. The software needs to verify the signature integrity of the stored local text file, and needs to call Crypto Framework to select the key text file and the signature file, and verify and sign the file, among which the key text file can be generated by Crypto Framework. - -### Usage - -1. Click **Encrypted** in the tab bar of the main page, click **Open File** in the encrypt interface, select the text file through the file chooser, and automatically return to the encrypt interface after selection. - Its contents are displayed in the **File Content** text box, - Click **Select Key** to select the key file, if there is no key file, you can generate and save the key file through the file chooser by clicking **Generate AES Key Randomly** on the encryption interface. - After selecting the text file and key file, click the **Encrypt** button to complete the encryption and save the ciphertext file through the file chooser.s - The encrypted message content is displayed in the **Encrypted Content** text box below. - -2. Click **Decrypt** in the tab bar of the main page, click **Open File** on the decrypt interface, select the text file through the file chooser, and automatically return to the decrypt interface after selection. - Its contents are displayed in the **File Content** text box, - Click **Select Key** to select the same key file as Encryption. - After selecting the text file and key file, click the **Decrypt** button to complete the decryption and save the plaintext file through the file chooser. - The decrypted message content is displayed in the **Decrypted Content** text box below. - -3. Click **Signature** in the tab bar of the main page, click **Open File** on the sign interface, select the text file through the file chooser, and automatically return to the sign interface after selection. - Its contents are displayed in the **File Content** text box, - Click **Select Key** to select the key file, if there is no key file, you can generate and save the key file through the file selector by clicking **Generate RSA Key Randomly** on the signature interface, note that RSA key generation takes a long time. - After selecting the text file and key file, click the **Sign** button to complete the integrity signature and save the signature file through the file chooser. - -4. Click the **Verify** tab bar of the main page, click **Open File** on the verify interface, select the text file through the file chooser, and automatically return to the verify interface after selection. - Its contents are displayed in the **File Content** text box, - Click **Select Key** to select a key file that matches the signature. Click **Select Signature File** to select the signature file saved when signing through the file chooser, - After selecting the text file, key file, and signature file, click the **Verify** button to complete the signature verification. - -### Dependency - -* filePicker[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) -* fileManager[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) -* UI Ability Context[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md) - -### Constraints - -1. This sample can only be run on standard-system devices. -2. This sample has been adapted to the API version 9 SDK, version number 3.2.12.2. -3. This sample requires DevEco Studio 3.1 Release(Build Version: 3.1.0.500) to compile and run. -4. This sample uses filePicker to select file, the files saved with filePicker, such as new keys generated, can be updated in real time, but the files directly pushed to the folder, they requires reboot the device and refresh the display. -5. This sample supports text file currently only English characters, and as a demonstration, the length of text that can be used successfully does not exceed 8,000 bytes. - +# Crypto Framework + +### Introduction + +This sample shows how [@ohos.security.cryptoFramework](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-crypto-architecture-kit/js-apis-cryptoFramework.md) works to implement the function of encrypting, decrypting, signing and verifying text file. The implementation scenario is as follows: + +1. The software needs to encrypt and store the local text file, and it needs to call Crypto Framework to select the key text file and encrypt the local text file, among which the key text file can be generated by Crypto Framework. + +2. The software needs to decrypt and store the local text file, and needs to call Crypto Framework to select the key text file and decrypt the local text file, where the key text file can be generated by Crypto Framework. + +3. The software needs to sign the stored local text file, call the encryption and Crypto Framework to select the key text file, and sign the integrity of the local text file, among which the key text file can be generated by Crypto Framework. + +4. The software needs to verify the signature integrity of the stored local text file, and needs to call Crypto Framework to select the key text file and the signature file, and verify and sign the file, among which the key text file can be generated by Crypto Framework. + +### Usage + +1. Click **Encrypted** in the tab bar of the main page, click **Open File** in the encrypt interface, select the text file through the file chooser, and automatically return to the encrypt interface after selection. + Its contents are displayed in the **File Content** text box, + Click **Select Key** to select the key file, if there is no key file, you can generate and save the key file through the file chooser by clicking **Generate AES Key Randomly** on the encryption interface. + After selecting the text file and key file, click the **Encrypt** button to complete the encryption and save the ciphertext file through the file chooser.s + The encrypted message content is displayed in the **Encrypted Content** text box below. + +2. Click **Decrypt** in the tab bar of the main page, click **Open File** on the decrypt interface, select the text file through the file chooser, and automatically return to the decrypt interface after selection. + Its contents are displayed in the **File Content** text box, + Click **Select Key** to select the same key file as Encryption. + After selecting the text file and key file, click the **Decrypt** button to complete the decryption and save the plaintext file through the file chooser. + The decrypted message content is displayed in the **Decrypted Content** text box below. + +3. Click **Signature** in the tab bar of the main page, click **Open File** on the sign interface, select the text file through the file chooser, and automatically return to the sign interface after selection. + Its contents are displayed in the **File Content** text box, + Click **Select Key** to select the key file, if there is no key file, you can generate and save the key file through the file selector by clicking **Generate RSA Key Randomly** on the signature interface, note that RSA key generation takes a long time. + After selecting the text file and key file, click the **Sign** button to complete the integrity signature and save the signature file through the file chooser. + +4. Click the **Verify** tab bar of the main page, click **Open File** on the verify interface, select the text file through the file chooser, and automatically return to the verify interface after selection. + Its contents are displayed in the **File Content** text box, + Click **Select Key** to select a key file that matches the signature. Click **Select Signature File** to select the signature file saved when signing through the file chooser, + After selecting the text file, key file, and signature file, click the **Verify** button to complete the signature verification. + +### Dependency + +* filePicker[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) +* fileManager[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) +* UI Ability Context[@ohos.app.ability.common](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis-ability-kit/js-apis-app-ability-common.md) + +### Constraints + +1. This sample can only be run on standard-system devices. +2. This sample has been adapted to the API version 9 SDK, version number 3.2.12.2. +3. This sample requires DevEco Studio 3.1 Release(Build Version: 3.1.0.500) to compile and run. +4. This sample uses filePicker to select file, the files saved with filePicker, such as new keys generated, can be updated in real time, but the files directly pushed to the folder, they requires reboot the device and refresh the display. +5. This sample supports text file currently only English characters, and as a demonstration, the length of text that can be used successfully does not exceed 8,000 bytes. + diff --git a/code/BasicFeature/Security/CryptoFramework/build-profile.json5 b/code/BasicFeature/Security/CryptoFramework/build-profile.json5 index cd63244ded7cae6beffa713e7b4c2f4a1ccd27f3..4a54f2a9a58cbc2b8aa5df6968f26cae6c925cc6 100644 --- a/code/BasicFeature/Security/CryptoFramework/build-profile.json5 +++ b/code/BasicFeature/Security/CryptoFramework/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 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": [], - "compileSdkVersion": 9, - "compatibleSdkVersion": 9, - "products": [ - { - "name": "default", - "signingConfig": "default" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": [], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/CryptoFramework/entry/build-profile.json5 b/code/BasicFeature/Security/CryptoFramework/entry/build-profile.json5 index 3c09a4cef27ba0f5a407de0d029f2740e9ab488b..ddd6e5f1ac23a18a1d1d0d8d7470c6d4726ef66e 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/build-profile.json5 +++ b/code/BasicFeature/Security/CryptoFramework/entry/build-profile.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/CryptoFramework/entry/oh-package.json5 b/code/BasicFeature/Security/CryptoFramework/entry/oh-package.json5 index 46187dd2f705fbf7a316a1a1caa3e667563bc825..907d65a0ae8875e2e4edf794a0b25c1be29bb392 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/oh-package.json5 +++ b/code/BasicFeature/Security/CryptoFramework/entry/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "ISC", - "devDependencies": {}, - "name": "entry", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/cryptoframework/CryptoOperation.ts b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/cryptoframework/CryptoOperation.ts index d1a5c995a81f8640ac8e0f3a0157726d051be60e..7b3ddc2d32994968261bcb5cf204e4cca05e3600 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/cryptoframework/CryptoOperation.ts +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/cryptoframework/CryptoOperation.ts @@ -1,385 +1,385 @@ -/* - * Copyright (c) 2023 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 cryptoFramework from '@ohos.security.cryptoFramework'; -import promptAction from '@ohos.promptAction'; -import Logger from '../util/Logger'; - -const TAG: string = '[Crypto_Framework]'; -const BASE_16: number = 16; -const SLICE_NUMBER: number = -2; - -// 字节流以16进制字符串输出 -function uint8ArrayToShowStr(uint8Array: Uint8Array): string { - let ret: string = Array.prototype.map - .call(uint8Array, (x) => ('00' + x.toString(BASE_16)).slice(SLICE_NUMBER)).join(''); - return ret; -} - -// 16进制字符串转字节流 -function fromHexString(hexString: string): Uint8Array { - let ret: Uint8Array = new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, BASE_16))); - return ret; -} - - -// 字节流转字符串 -function arrayBufferToString(buffer: ArrayBuffer): string { - let ret: string = String.fromCharCode.apply(null, new Uint8Array(buffer)); - return ret; -} - -// 可理解的字符串转成字节流 -function stringToUint8Array(str: string): Uint8Array { - let arr = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - let ret: Uint8Array = new Uint8Array(arr); - return ret; -} - -function genGcmParamsSpec(): cryptoFramework.GcmParamsSpec { - let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 12 bytes - let dataIv = new Uint8Array(arr); - let ivBlob = { data: dataIv }; - - arr = [0, 0, 0, 0, 0, 0, 0, 0]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob = { data: dataAad }; - - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob = { data: dataTag }; // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - - let gcmParamsSpec = { iv: ivBlob, aad: aadBlob, authTag: tagBlob, algName: 'GcmParamsSpec' }; - return gcmParamsSpec; -} - -export class CryptoOperation { - async generateAesKey(): Promise { - let symKeyGenerator; - let encodedKey; - // 创建对称密钥生成器 - try { - symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); - } catch (error) { - Logger.error(TAG, 'create generator failed'); - return null; - } - - // 通过密钥生成器随机生成对称密钥 - try { - let symKey = await symKeyGenerator.generateSymKey(); - // 获取对称密钥的二进制数据,输出长度为256bit的字节流 - encodedKey = symKey.getEncoded(); - let data: Uint8Array = encodedKey.data; - Logger.info('success, key bytes: ' + data); - Logger.info('success, key hex:' + uint8ArrayToShowStr(data)); - // 将二进制数据转为16进制string。 - return uint8ArrayToShowStr(data); - } catch (error) { - Logger.error(TAG, 'create symKey failed'); - return null; - } - } - - async convertAesKey(aesKeyBlobString: string): Promise { - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); - Logger.info(TAG, 'success, read key string' + aesKeyBlobString); - Logger.info(TAG, 'success, blob key ' + fromHexString(aesKeyBlobString)); - let symKeyBlob = { data: fromHexString(aesKeyBlobString) }; - try { - let key = await symKeyGenerator.convertKey(symKeyBlob); - let aesKey: cryptoFramework.SymKey = key; - return aesKey; - } catch (error) { - Logger.error(TAG, `convert aes key failed, ${error.code}, ${error.message}`); - return null; - } - } - - async aesGcmEncrypt(globalKey, textString: string): Promise { - let cipherAlgName = 'AES256|GCM|PKCS7'; - let cipher; - let cipherText: string; - let globalGcmParams = genGcmParamsSpec(); - let aesEncryptJsonStr = null; - try { - cipher = cryptoFramework.createCipher(cipherAlgName); - Logger.info(TAG, `cipher algName: ${cipher.algName}`); - } catch (error) { - Logger.error(TAG, `createCipher failed, ${error.code}, ${error.message}`); - return aesEncryptJsonStr; - } - let mode = cryptoFramework.CryptoMode.ENCRYPT_MODE; - try { - await cipher.init(mode, globalKey, globalGcmParams); - } catch (error) { - Logger.error(TAG, `init cipher failed, ${error.code}, ${error.message}`); - return aesEncryptJsonStr; - } - let plainText = { data: stringToUint8Array(textString) }; - Logger.info(TAG, `plain text: ${plainText.data}`); - try { - let cipherTextBlob = await cipher.update(plainText); - let tmpArr: Uint8Array = cipherTextBlob.data; - cipherText = uint8ArrayToShowStr(tmpArr); - Logger.info(TAG, `cipher text: ${cipherText}`); - } catch (error) { - Logger.error(TAG, `update cipher failed, ${error.code}, ${error.message}`); - return aesEncryptJsonStr; - } - try { - let authTag = await cipher.doFinal(null); - let tmoTagArr: Uint8Array = authTag.data; - let aesEncryptJson = ({ aesGcmTag: uint8ArrayToShowStr(tmoTagArr), encryptedText: cipherText }); - aesEncryptJsonStr = JSON.stringify(aesEncryptJson); - Logger.info(TAG, `success, authTag blob ${authTag.data}`); - Logger.info(TAG, `success, authTag blob.length = ${authTag.data.length}`); - return aesEncryptJsonStr; - } catch (error) { - Logger.error(TAG, `doFinal cipher failed, ${error.code}, ${error.message}`); - return aesEncryptJsonStr; - } - } - - async aesGcmDecrypt(globalKey, aesEncryptJsonStr: string): Promise { - let cipherAlgName = 'AES256|GCM|PKCS7'; - let decode; - let plainTextBlob; - let plainText: string; - let aesEncryptJson; - try { - aesEncryptJson = JSON.parse(aesEncryptJsonStr); - } catch (error) { - Logger.error(TAG, `trans from json string failed, ${error.code}, ${error.message}`); - return null; - } - let authTagStr: string = aesEncryptJson.aesGcmTag; - let textString: string = aesEncryptJson.encryptedText; - let globalGcmParams = genGcmParamsSpec(); - globalGcmParams.authTag = { data: fromHexString(authTagStr) }; - Logger.info(TAG, 'success, decrypt authTag string' + authTagStr); - Logger.info(TAG, 'success, decrypt authTag blob' + globalGcmParams.authTag.data); - Logger.info(TAG, 'success, decrypt authTag blob.length = ' + globalGcmParams.authTag.data.length); - try { - decode = cryptoFramework.createCipher(cipherAlgName); - } catch (error) { - Logger.error(TAG, `createCipher failed, ${error.code}, ${error.message}`); - return null; - } - let mode = cryptoFramework.CryptoMode.DECRYPT_MODE; - try { - await decode.init(mode, globalKey, globalGcmParams); - } catch (error) { - Logger.error(TAG, `init decode failed, ${error.code}, ${error.message}`); - return null; - } - let cipherText = { data: fromHexString(textString) }; - Logger.info(TAG, `success, cipher text: ${cipherText.data}`); - try { - plainTextBlob = await decode.update(cipherText); - let tmpArr: Uint8Array = plainTextBlob.data; - plainText = arrayBufferToString(tmpArr); - Logger.info(TAG, `success, plain text: ${plainText}`); - } catch (error) { - Logger.error(TAG, `update decode failed, ${error.code}, ${error.message}`); - return null; - } - try { - let finalOut = await decode.doFinal(null); - } catch (error) { - Logger.error(TAG, `doFinal decode failed, ${error.code}, ${error.message}`); - return null; - } - return plainText; - } - - async aesConvertAndEncrypt(aesKeyBlobString: string, textString: string): Promise { - let aesEncryptJsonStr = ''; - try { - let key = await this.convertAesKey(aesKeyBlobString); - try { - aesEncryptJsonStr = await this.aesGcmEncrypt(key, textString); - } catch (error) { - Logger.error(TAG, `encrypt error, ${error.code}, ${error.message}`); - } - } catch (error) { - Logger.error(TAG, `convert key error, ${error.code}, ${error.message}`); - return null; - } - return aesEncryptJsonStr; - } - - async aesConvertAndDecrypt(aesKeyBlobString: string, textString: string): Promise { - let plainText = ''; - try { - let key = await this.convertAesKey(aesKeyBlobString); - try { - plainText = await this.aesGcmDecrypt(key, textString); - } catch (error) { - Logger.error(TAG, `encrypt error, ${error.code}, ${error.message}`); - } - } catch (error) { - Logger.error(TAG, `convert key error, ${error.code}, ${error.message}`); - return null; - } - return plainText; - } - - async generateRsaKey(): Promise { - // 创建非对称密钥生成器 - let rsaKeyGenerator; - let jsonStr; - // 创建对称密钥生成器 - try { - rsaKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA3072'); - } catch (error) { - Logger.error(TAG, 'create generator failed'); - return null; - } - // 通过密钥生成器随机生成非对称密钥 - try { - // 通过密钥生成器随机生成非对称密钥 - let keyPair = await rsaKeyGenerator.generateKeyPair(); - // 获取非对称密钥的二进制数据 - let encodedPriKey = keyPair.priKey.getEncoded(); - let priKeyData: Uint8Array = encodedPriKey.data; - let encodedPubKey = keyPair.pubKey.getEncoded(); - let pubKeyData: Uint8Array = encodedPubKey.data; - let rsaKeyJson = ({ priKey: uint8ArrayToShowStr(priKeyData), pubKey: uint8ArrayToShowStr(pubKeyData) }); - jsonStr = JSON.stringify(rsaKeyJson); - Logger.info(TAG, 'success, key string: ' + jsonStr.length); - return jsonStr; - } catch (error) { - Logger.error(TAG, 'create symKey failed'); - return null; - } - } - - async convertRsaKey(rsaJsonString: string): Promise { - let rsaKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA3072'); - Logger.info(TAG, 'success, read key string' + rsaJsonString.length); - let jsonRsaKeyBlob; - try { - jsonRsaKeyBlob = JSON.parse(rsaJsonString); - } catch (error) { - Logger.error(TAG, `trans from json string failed, ${error.code}, ${error.message}`); - return null; - } - let priKeyStr: string = jsonRsaKeyBlob.priKey; - let pubKeyStr: string = jsonRsaKeyBlob.pubKey; - Logger.info(TAG, 'success, read rsa pri str ' + priKeyStr.length); - Logger.info(TAG, 'success, read rsa pub str ' + pubKeyStr.length); - let priKeyBlob = fromHexString(priKeyStr); - let pubKeyBlob = fromHexString(pubKeyStr); - Logger.info(TAG, 'success, read rsa pri blob key ' + priKeyBlob.length); - Logger.info(TAG, 'success, read rsa pub blob key ' + pubKeyBlob.length); - try { - let key: cryptoFramework.KeyPair = await rsaKeyGenerator.convertKey({ data: pubKeyBlob }, { data: priKeyBlob }); - return key; - Logger.info(TAG, 'success, read and convert key'); - } catch (error) { - Logger.error(TAG, `convert rsa key failed, ${error.code}, ${error.message}`); - return null; - } - } - - async rsaSign(globalKey, textString: string): Promise { - let signer = cryptoFramework.createSign('RSA3072|PKCS1|SHA256'); - let keyPair = globalKey; - try { - await signer.init(keyPair.priKey); - let signBlob = stringToUint8Array(textString); - try { - let signedBlob = await signer.sign({ data: signBlob }); - let tmpArr: Uint8Array = signedBlob.data; - Logger.info(TAG, 'success,RSA sign output is' + signedBlob.data.length); - let rsaSignedBlobString = uint8ArrayToShowStr(tmpArr); - Logger.info(TAG, 'success,RSA sign string is' + rsaSignedBlobString); - return rsaSignedBlobString; - } catch (error1) { - Logger.error(TAG, `sign text failed, ${error1.code}, ${error1.message}`); - return null; - } - } catch (error) { - Logger.error(TAG, `sign init failed, ${error.code}, ${error.message}`); - return null; - } - } - - async rsaVerify(globalKey, textString: string, rsaSignedText: string): Promise { - let verifyer = cryptoFramework.createVerify('RSA3072|PKCS1|SHA256'); - let keyPair = globalKey; - let signBlob = stringToUint8Array(textString); - let signedBlob = fromHexString(rsaSignedText); - Logger.info('success,RSA sign input is ' + signBlob); - Logger.info('success,RSA signed file length ' + signedBlob.length); - try { - await verifyer.init(keyPair.pubKey); - try { - let result: Boolean = await verifyer.verify({ data: signBlob }, { data: signedBlob }); - if (result === false) { - // flag = false; - Logger.error(TAG, 'RSA Verify result = fail'); - } else { - Logger.info(TAG, 'success, RSA Verify result = success'); - } - return result; - } catch (error) { - Logger.error(TAG, `verify dofinal failed, ${error.code}, ${error.message}`); - } - } catch (err) { - Logger.error(TAG, `verify init failed, ${err.code}, ${err.message}`); - } - return null; - } - - async rsaConvertAndSign(rsaJsonString: string, textString: string): Promise { - let rsaSignString; - try { - let key = await this.convertRsaKey(rsaJsonString); - try { - rsaSignString = await this.rsaSign(key, textString); - } catch (error) { - Logger.error(TAG, `sign error, ${error.code}, ${error.message}`); - return null; - } - } catch (error) { - Logger.error(TAG, `convert rsa key error, ${error.code}, ${error.message}`); - return null; - } - return rsaSignString; - } - - async rsaConvertAndVerify(rsaJsonString: string, textString: string, rsaSignedText: string): Promise { - let rsaVerifyRes; - try { - let key = await this.convertRsaKey(rsaJsonString); - try { - rsaVerifyRes = await this.rsaVerify(key, textString, rsaSignedText); - } catch (error) { - Logger.error(TAG, `sign error, ${error.code}, ${error.message}`); - return null; - } - } catch (error) { - Logger.error(TAG, `convert rsa key error, ${error.code}, ${error.message}`); - return null; - } - return rsaVerifyRes; - } -} - +/* + * Copyright (c) 2023 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 cryptoFramework from '@ohos.security.cryptoFramework'; +import promptAction from '@ohos.promptAction'; +import Logger from '../util/Logger'; + +const TAG: string = '[Crypto_Framework]'; +const BASE_16: number = 16; +const SLICE_NUMBER: number = -2; + +// 字节流以16进制字符串输出 +function uint8ArrayToShowStr(uint8Array: Uint8Array): string { + let ret: string = Array.prototype.map + .call(uint8Array, (x) => ('00' + x.toString(BASE_16)).slice(SLICE_NUMBER)).join(''); + return ret; +} + +// 16进制字符串转字节流 +function fromHexString(hexString: string): Uint8Array { + let ret: Uint8Array = new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, BASE_16))); + return ret; +} + + +// 字节流转字符串 +function arrayBufferToString(buffer: ArrayBuffer): string { + let ret: string = String.fromCharCode.apply(null, new Uint8Array(buffer)); + return ret; +} + +// 可理解的字符串转成字节流 +function stringToUint8Array(str: string): Uint8Array { + let arr = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + let ret: Uint8Array = new Uint8Array(arr); + return ret; +} + +function genGcmParamsSpec(): cryptoFramework.GcmParamsSpec { + let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 12 bytes + let dataIv = new Uint8Array(arr); + let ivBlob = { data: dataIv }; + + arr = [0, 0, 0, 0, 0, 0, 0, 0]; // 8 bytes + let dataAad = new Uint8Array(arr); + let aadBlob = { data: dataAad }; + + arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes + let dataTag = new Uint8Array(arr); + let tagBlob = { data: dataTag }; // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + + let gcmParamsSpec = { iv: ivBlob, aad: aadBlob, authTag: tagBlob, algName: 'GcmParamsSpec' }; + return gcmParamsSpec; +} + +export class CryptoOperation { + async generateAesKey(): Promise { + let symKeyGenerator; + let encodedKey; + // 创建对称密钥生成器 + try { + symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); + } catch (error) { + Logger.error(TAG, 'create generator failed'); + return null; + } + + // 通过密钥生成器随机生成对称密钥 + try { + let symKey = await symKeyGenerator.generateSymKey(); + // 获取对称密钥的二进制数据,输出长度为256bit的字节流 + encodedKey = symKey.getEncoded(); + let data: Uint8Array = encodedKey.data; + Logger.info('success, key bytes: ' + data); + Logger.info('success, key hex:' + uint8ArrayToShowStr(data)); + // 将二进制数据转为16进制string。 + return uint8ArrayToShowStr(data); + } catch (error) { + Logger.error(TAG, 'create symKey failed'); + return null; + } + } + + async convertAesKey(aesKeyBlobString: string): Promise { + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); + Logger.info(TAG, 'success, read key string' + aesKeyBlobString); + Logger.info(TAG, 'success, blob key ' + fromHexString(aesKeyBlobString)); + let symKeyBlob = { data: fromHexString(aesKeyBlobString) }; + try { + let key = await symKeyGenerator.convertKey(symKeyBlob); + let aesKey: cryptoFramework.SymKey = key; + return aesKey; + } catch (error) { + Logger.error(TAG, `convert aes key failed, ${error.code}, ${error.message}`); + return null; + } + } + + async aesGcmEncrypt(globalKey, textString: string): Promise { + let cipherAlgName = 'AES256|GCM|PKCS7'; + let cipher; + let cipherText: string; + let globalGcmParams = genGcmParamsSpec(); + let aesEncryptJsonStr = null; + try { + cipher = cryptoFramework.createCipher(cipherAlgName); + Logger.info(TAG, `cipher algName: ${cipher.algName}`); + } catch (error) { + Logger.error(TAG, `createCipher failed, ${error.code}, ${error.message}`); + return aesEncryptJsonStr; + } + let mode = cryptoFramework.CryptoMode.ENCRYPT_MODE; + try { + await cipher.init(mode, globalKey, globalGcmParams); + } catch (error) { + Logger.error(TAG, `init cipher failed, ${error.code}, ${error.message}`); + return aesEncryptJsonStr; + } + let plainText = { data: stringToUint8Array(textString) }; + Logger.info(TAG, `plain text: ${plainText.data}`); + try { + let cipherTextBlob = await cipher.update(plainText); + let tmpArr: Uint8Array = cipherTextBlob.data; + cipherText = uint8ArrayToShowStr(tmpArr); + Logger.info(TAG, `cipher text: ${cipherText}`); + } catch (error) { + Logger.error(TAG, `update cipher failed, ${error.code}, ${error.message}`); + return aesEncryptJsonStr; + } + try { + let authTag = await cipher.doFinal(null); + let tmoTagArr: Uint8Array = authTag.data; + let aesEncryptJson = ({ aesGcmTag: uint8ArrayToShowStr(tmoTagArr), encryptedText: cipherText }); + aesEncryptJsonStr = JSON.stringify(aesEncryptJson); + Logger.info(TAG, `success, authTag blob ${authTag.data}`); + Logger.info(TAG, `success, authTag blob.length = ${authTag.data.length}`); + return aesEncryptJsonStr; + } catch (error) { + Logger.error(TAG, `doFinal cipher failed, ${error.code}, ${error.message}`); + return aesEncryptJsonStr; + } + } + + async aesGcmDecrypt(globalKey, aesEncryptJsonStr: string): Promise { + let cipherAlgName = 'AES256|GCM|PKCS7'; + let decode; + let plainTextBlob; + let plainText: string; + let aesEncryptJson; + try { + aesEncryptJson = JSON.parse(aesEncryptJsonStr); + } catch (error) { + Logger.error(TAG, `trans from json string failed, ${error.code}, ${error.message}`); + return null; + } + let authTagStr: string = aesEncryptJson.aesGcmTag; + let textString: string = aesEncryptJson.encryptedText; + let globalGcmParams = genGcmParamsSpec(); + globalGcmParams.authTag = { data: fromHexString(authTagStr) }; + Logger.info(TAG, 'success, decrypt authTag string' + authTagStr); + Logger.info(TAG, 'success, decrypt authTag blob' + globalGcmParams.authTag.data); + Logger.info(TAG, 'success, decrypt authTag blob.length = ' + globalGcmParams.authTag.data.length); + try { + decode = cryptoFramework.createCipher(cipherAlgName); + } catch (error) { + Logger.error(TAG, `createCipher failed, ${error.code}, ${error.message}`); + return null; + } + let mode = cryptoFramework.CryptoMode.DECRYPT_MODE; + try { + await decode.init(mode, globalKey, globalGcmParams); + } catch (error) { + Logger.error(TAG, `init decode failed, ${error.code}, ${error.message}`); + return null; + } + let cipherText = { data: fromHexString(textString) }; + Logger.info(TAG, `success, cipher text: ${cipherText.data}`); + try { + plainTextBlob = await decode.update(cipherText); + let tmpArr: Uint8Array = plainTextBlob.data; + plainText = arrayBufferToString(tmpArr); + Logger.info(TAG, `success, plain text: ${plainText}`); + } catch (error) { + Logger.error(TAG, `update decode failed, ${error.code}, ${error.message}`); + return null; + } + try { + let finalOut = await decode.doFinal(null); + } catch (error) { + Logger.error(TAG, `doFinal decode failed, ${error.code}, ${error.message}`); + return null; + } + return plainText; + } + + async aesConvertAndEncrypt(aesKeyBlobString: string, textString: string): Promise { + let aesEncryptJsonStr = ''; + try { + let key = await this.convertAesKey(aesKeyBlobString); + try { + aesEncryptJsonStr = await this.aesGcmEncrypt(key, textString); + } catch (error) { + Logger.error(TAG, `encrypt error, ${error.code}, ${error.message}`); + } + } catch (error) { + Logger.error(TAG, `convert key error, ${error.code}, ${error.message}`); + return null; + } + return aesEncryptJsonStr; + } + + async aesConvertAndDecrypt(aesKeyBlobString: string, textString: string): Promise { + let plainText = ''; + try { + let key = await this.convertAesKey(aesKeyBlobString); + try { + plainText = await this.aesGcmDecrypt(key, textString); + } catch (error) { + Logger.error(TAG, `encrypt error, ${error.code}, ${error.message}`); + } + } catch (error) { + Logger.error(TAG, `convert key error, ${error.code}, ${error.message}`); + return null; + } + return plainText; + } + + async generateRsaKey(): Promise { + // 创建非对称密钥生成器 + let rsaKeyGenerator; + let jsonStr; + // 创建对称密钥生成器 + try { + rsaKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA3072'); + } catch (error) { + Logger.error(TAG, 'create generator failed'); + return null; + } + // 通过密钥生成器随机生成非对称密钥 + try { + // 通过密钥生成器随机生成非对称密钥 + let keyPair = await rsaKeyGenerator.generateKeyPair(); + // 获取非对称密钥的二进制数据 + let encodedPriKey = keyPair.priKey.getEncoded(); + let priKeyData: Uint8Array = encodedPriKey.data; + let encodedPubKey = keyPair.pubKey.getEncoded(); + let pubKeyData: Uint8Array = encodedPubKey.data; + let rsaKeyJson = ({ priKey: uint8ArrayToShowStr(priKeyData), pubKey: uint8ArrayToShowStr(pubKeyData) }); + jsonStr = JSON.stringify(rsaKeyJson); + Logger.info(TAG, 'success, key string: ' + jsonStr.length); + return jsonStr; + } catch (error) { + Logger.error(TAG, 'create symKey failed'); + return null; + } + } + + async convertRsaKey(rsaJsonString: string): Promise { + let rsaKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA3072'); + Logger.info(TAG, 'success, read key string' + rsaJsonString.length); + let jsonRsaKeyBlob; + try { + jsonRsaKeyBlob = JSON.parse(rsaJsonString); + } catch (error) { + Logger.error(TAG, `trans from json string failed, ${error.code}, ${error.message}`); + return null; + } + let priKeyStr: string = jsonRsaKeyBlob.priKey; + let pubKeyStr: string = jsonRsaKeyBlob.pubKey; + Logger.info(TAG, 'success, read rsa pri str ' + priKeyStr.length); + Logger.info(TAG, 'success, read rsa pub str ' + pubKeyStr.length); + let priKeyBlob = fromHexString(priKeyStr); + let pubKeyBlob = fromHexString(pubKeyStr); + Logger.info(TAG, 'success, read rsa pri blob key ' + priKeyBlob.length); + Logger.info(TAG, 'success, read rsa pub blob key ' + pubKeyBlob.length); + try { + let key: cryptoFramework.KeyPair = await rsaKeyGenerator.convertKey({ data: pubKeyBlob }, { data: priKeyBlob }); + return key; + Logger.info(TAG, 'success, read and convert key'); + } catch (error) { + Logger.error(TAG, `convert rsa key failed, ${error.code}, ${error.message}`); + return null; + } + } + + async rsaSign(globalKey, textString: string): Promise { + let signer = cryptoFramework.createSign('RSA3072|PKCS1|SHA256'); + let keyPair = globalKey; + try { + await signer.init(keyPair.priKey); + let signBlob = stringToUint8Array(textString); + try { + let signedBlob = await signer.sign({ data: signBlob }); + let tmpArr: Uint8Array = signedBlob.data; + Logger.info(TAG, 'success,RSA sign output is' + signedBlob.data.length); + let rsaSignedBlobString = uint8ArrayToShowStr(tmpArr); + Logger.info(TAG, 'success,RSA sign string is' + rsaSignedBlobString); + return rsaSignedBlobString; + } catch (error1) { + Logger.error(TAG, `sign text failed, ${error1.code}, ${error1.message}`); + return null; + } + } catch (error) { + Logger.error(TAG, `sign init failed, ${error.code}, ${error.message}`); + return null; + } + } + + async rsaVerify(globalKey, textString: string, rsaSignedText: string): Promise { + let verifyer = cryptoFramework.createVerify('RSA3072|PKCS1|SHA256'); + let keyPair = globalKey; + let signBlob = stringToUint8Array(textString); + let signedBlob = fromHexString(rsaSignedText); + Logger.info('success,RSA sign input is ' + signBlob); + Logger.info('success,RSA signed file length ' + signedBlob.length); + try { + await verifyer.init(keyPair.pubKey); + try { + let result: Boolean = await verifyer.verify({ data: signBlob }, { data: signedBlob }); + if (result === false) { + // flag = false; + Logger.error(TAG, 'RSA Verify result = fail'); + } else { + Logger.info(TAG, 'success, RSA Verify result = success'); + } + return result; + } catch (error) { + Logger.error(TAG, `verify dofinal failed, ${error.code}, ${error.message}`); + } + } catch (err) { + Logger.error(TAG, `verify init failed, ${err.code}, ${err.message}`); + } + return null; + } + + async rsaConvertAndSign(rsaJsonString: string, textString: string): Promise { + let rsaSignString; + try { + let key = await this.convertRsaKey(rsaJsonString); + try { + rsaSignString = await this.rsaSign(key, textString); + } catch (error) { + Logger.error(TAG, `sign error, ${error.code}, ${error.message}`); + return null; + } + } catch (error) { + Logger.error(TAG, `convert rsa key error, ${error.code}, ${error.message}`); + return null; + } + return rsaSignString; + } + + async rsaConvertAndVerify(rsaJsonString: string, textString: string, rsaSignedText: string): Promise { + let rsaVerifyRes; + try { + let key = await this.convertRsaKey(rsaJsonString); + try { + rsaVerifyRes = await this.rsaVerify(key, textString, rsaSignedText); + } catch (error) { + Logger.error(TAG, `sign error, ${error.code}, ${error.message}`); + return null; + } + } catch (error) { + Logger.error(TAG, `convert rsa key error, ${error.code}, ${error.message}`); + return null; + } + return rsaVerifyRes; + } +} + diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/entryability/EntryAbility.ts b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/entryability/EntryAbility.ts index 202b948c9ed4dd76c512c9225e676899cb8907b8..7370b8f3270dfb1cc5824b1d9fe959f82b7ede74 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Decrypt.ets b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Decrypt.ets index 2e505fabbedd8028495aa3fbb69b72a8955417fb..f6b8e62bfbcae73cc52295adc2869e5d4fd2e613 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Decrypt.ets +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Decrypt.ets @@ -1,330 +1,330 @@ -/* - * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; -import Logger from '../util/Logger'; -import picker from '@ohos.file.picker'; -import { CryptoOperation } from '../cryptoframework/CryptoOperation'; -import TextFileManager from '../textfilemanager/TextFileManager'; -import common from '@ohos.app.ability.common'; - -const TAG: string = '[Crypto_Framework]'; - -@Component -export struct Decrypt { - @State keyFileName: string = ''; - @State keyFileUri: string = ''; - @State textFileUri: string = ''; - @State textFileName: string = ''; - @State keyString: string = ''; - @State cipherText: string = ''; - @State plainText: string = ''; - @State message: string = ''; - @State decryptedFileUri: string = ''; - private CryptoOperation: CryptoOperation = new CryptoOperation(); - - build() { - Stack({ alignContent: Alignment.Center }) { - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - List() { - ListItem() { - Row() { - Text($r('app.string.open_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('52vp') - .padding({ top: 4, left: 12, right: 12 }) - }.onClick(() => { - this.selectTextFileAndRead(); - }) - - ListItem() { - Row() { - Text($r('app.string.select_key_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('48vp') - .padding({ left: 12, right: 12 }) - }.onClick(() => { - this.selectAesKeyFileAndRead(); - }) - } - .width('100%') - .height('100%') - .borderRadius(16) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.text_context')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.cipherText) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.decrypted_context')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.plainText) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Column() { - Button() { - Text($r('app.string.decrypt')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .borderRadius(20) - .id('decryptionBtn') - .type(ButtonType.Capsule) - .margin({ left: 24, right: 24 }) - .width('100%') - .height('40vp') - .backgroundColor('#007DFF') - .onClick(() => { - if (this.textFileUri === '' || this.keyFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - } else { - this.decryptFunc(); - } - }); - } - } - }.margin({ left: 24, right: 24 }) - }.width('100%').height('296vp').justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - } - } - - async selectAesKeyFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到密钥文档文件的URI - this.keyFileUri = result.want.parameters.select_item_list.toString(); - // 获取到密钥文档文件的文件名称 - this.keyFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.keyFileUri); - this.keyString = TextFileManager.getString(); - } - - async selectTextFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到文档文件的URI - this.textFileUri = result.want.parameters.select_item_list.toString(); - // 获取到文档文件的文件名称 - this.textFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.textFileUri); - this.cipherText = TextFileManager.getString(); - } - - async createTextFileAndWrite() { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['plainText.txt']; - let documentPicker = new picker.DocumentViewPicker(); - let documentSaveResult = await documentPicker.save(documentSaveOptions); - this.decryptedFileUri = documentSaveResult[0]; - await TextFileManager.writeTextFile(this.decryptedFileUri, this.plainText); - } - - async decryptFunc() { - if (this.cipherText === '' || this.keyFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - return; - } - try { - this.plainText = await this.CryptoOperation.aesConvertAndDecrypt(this.keyString, this.cipherText); - } catch (error) { - Logger.error(TAG, `decrypt failed, ${error.code}, ${error.message}`); - promptAction.showToast({ - message: $r('app.string.decrypt_fail') - }); - return; - } - if (this.plainText === '' || this.plainText === null || this.plainText === undefined) { - promptAction.showToast({ - message: $r('app.string.decrypt_fail') - }); - return; - } else { - try { - await this.createTextFileAndWrite(); - } catch (error) { - Logger.error(TAG, `decrypt failed, ${error.code}, ${error.message}`); - } - } - if (this.decryptedFileUri === '' || typeof (this.decryptedFileUri) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.decrypt_fail') - }); - } else { - promptAction.showToast({ - message: $r('app.string.decrypt_success') - }); - } - } -} +/* + * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; +import Logger from '../util/Logger'; +import picker from '@ohos.file.picker'; +import { CryptoOperation } from '../cryptoframework/CryptoOperation'; +import TextFileManager from '../textfilemanager/TextFileManager'; +import common from '@ohos.app.ability.common'; + +const TAG: string = '[Crypto_Framework]'; + +@Component +export struct Decrypt { + @State keyFileName: string = ''; + @State keyFileUri: string = ''; + @State textFileUri: string = ''; + @State textFileName: string = ''; + @State keyString: string = ''; + @State cipherText: string = ''; + @State plainText: string = ''; + @State message: string = ''; + @State decryptedFileUri: string = ''; + private CryptoOperation: CryptoOperation = new CryptoOperation(); + + build() { + Stack({ alignContent: Alignment.Center }) { + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + List() { + ListItem() { + Row() { + Text($r('app.string.open_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('52vp') + .padding({ top: 4, left: 12, right: 12 }) + }.onClick(() => { + this.selectTextFileAndRead(); + }) + + ListItem() { + Row() { + Text($r('app.string.select_key_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('48vp') + .padding({ left: 12, right: 12 }) + }.onClick(() => { + this.selectAesKeyFileAndRead(); + }) + } + .width('100%') + .height('100%') + .borderRadius(16) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.text_context')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.cipherText) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.decrypted_context')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.plainText) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Column() { + Button() { + Text($r('app.string.decrypt')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .borderRadius(20) + .id('decryptionBtn') + .type(ButtonType.Capsule) + .margin({ left: 24, right: 24 }) + .width('100%') + .height('40vp') + .backgroundColor('#007DFF') + .onClick(() => { + if (this.textFileUri === '' || this.keyFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + } else { + this.decryptFunc(); + } + }); + } + } + }.margin({ left: 24, right: 24 }) + }.width('100%').height('296vp').justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + } + } + + async selectAesKeyFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到密钥文档文件的URI + this.keyFileUri = result.want.parameters.select_item_list.toString(); + // 获取到密钥文档文件的文件名称 + this.keyFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.keyFileUri); + this.keyString = TextFileManager.getString(); + } + + async selectTextFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到文档文件的URI + this.textFileUri = result.want.parameters.select_item_list.toString(); + // 获取到文档文件的文件名称 + this.textFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.textFileUri); + this.cipherText = TextFileManager.getString(); + } + + async createTextFileAndWrite() { + let documentSaveOptions = new picker.DocumentSaveOptions(); + documentSaveOptions.newFileNames = ['plainText.txt']; + let documentPicker = new picker.DocumentViewPicker(); + let documentSaveResult = await documentPicker.save(documentSaveOptions); + this.decryptedFileUri = documentSaveResult[0]; + await TextFileManager.writeTextFile(this.decryptedFileUri, this.plainText); + } + + async decryptFunc() { + if (this.cipherText === '' || this.keyFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + return; + } + try { + this.plainText = await this.CryptoOperation.aesConvertAndDecrypt(this.keyString, this.cipherText); + } catch (error) { + Logger.error(TAG, `decrypt failed, ${error.code}, ${error.message}`); + promptAction.showToast({ + message: $r('app.string.decrypt_fail') + }); + return; + } + if (this.plainText === '' || this.plainText === null || this.plainText === undefined) { + promptAction.showToast({ + message: $r('app.string.decrypt_fail') + }); + return; + } else { + try { + await this.createTextFileAndWrite(); + } catch (error) { + Logger.error(TAG, `decrypt failed, ${error.code}, ${error.message}`); + } + } + if (this.decryptedFileUri === '' || typeof (this.decryptedFileUri) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.decrypt_fail') + }); + } else { + promptAction.showToast({ + message: $r('app.string.decrypt_success') + }); + } + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Encrypt.ets b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Encrypt.ets index 48788fceebce2378e995eaa8fe1baed78de63537..ebccaae38ef5260e57d8409052f8744eca28ee31 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Encrypt.ets +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Encrypt.ets @@ -1,381 +1,381 @@ -/* - * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; -import Logger from '../util/Logger'; -import picker from '@ohos.file.picker'; -import { CryptoOperation } from '../cryptoframework/CryptoOperation'; -import TextFileManager from '../textfilemanager/TextFileManager'; -import common from '@ohos.app.ability.common'; - -const TAG: string = '[Crypto_Framework]'; - -@Component -export struct Encrypt { - @State keyFileName: string = ''; - @State keyFileUri: string = ''; - @State textFileUri: string = ''; - @State textFileName: string = ''; - @State keyString: string = ''; - @State cipherText: string = ''; - @State plainText: string = ''; - @State message: string = ''; - @State createKeyUri: string = ''; - @State encryptedFileUri: string = ''; - private CryptoOperation: CryptoOperation = new CryptoOperation(); - - build() { - Stack({ alignContent: Alignment.Center }) { - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - List() { - ListItem() { - Row() { - Text($r('app.string.open_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('52vp') - .padding({ top: 4, left: 12, right: 12 }) - }.onClick(() => { - this.selectTextFileAndRead(); - }) - - ListItem() { - Row() { - Text($r('app.string.select_key_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('48vp') - .padding({ left: 12, right: 12 }) - }.onClick(() => { - this.selectAesKeyFileAndRead(); - }) - } - .width('100%') - .height('100%') - .borderRadius(16) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.text_context')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.plainText) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.encrypted_context')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.cipherText) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Column() { - Button() { - Text($r('app.string.generate_aes_key_randomly')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .id('encryptAesGenKey') - .borderRadius(20) - .type(ButtonType.Capsule) - .width('100%') - .height('40vp') - .margin({ bottom: 16 }) - .backgroundColor('#007DFF') - .onClick(() => { - this.genAesKey(); - }); - - Button() { - Text($r('app.string.encrypt')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .borderRadius(20) - .id('encryptionBtn') - .type(ButtonType.Capsule) - .margin({ left: 24, right: 24 }) - .width('100%') - .height('40vp') - .backgroundColor('#007DFF') - .onClick(() => { - if (this.textFileUri === '' || this.keyFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - } else { - this.encryptFunc(); - } - }); - } - } - }.margin({ left: 24, right: 24 }) - }.width('100%').height('296vp').justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - } - } - - async selectAesKeyFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到密钥文档文件的URI - this.keyFileUri = result.want.parameters.select_item_list.toString(); - // 获取到密钥文档文件的文件名称 - this.keyFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.keyFileUri); - this.keyString = TextFileManager.getString(); - } - - async selectTextFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到文档文件的URI - this.textFileUri = result.want.parameters.select_item_list.toString(); - // 获取到文档文件的文件名称 - this.textFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.textFileUri); - this.plainText = TextFileManager.getString(); - } - - async createTextFileAndWrite() { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['cipherText.txt']; - let documentPicker = new picker.DocumentViewPicker(); - let documentSaveResult = await documentPicker.save(documentSaveOptions); - this.encryptedFileUri = documentSaveResult[0]; - await TextFileManager.writeTextFile(this.encryptedFileUri, this.cipherText); - } - - async createKeyFileAndWrite() { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['aesKey.txt']; - let documentPicker = new picker.DocumentViewPicker(); - let documentSaveResult = await documentPicker.save(documentSaveOptions); - this.createKeyUri = documentSaveResult[0]; - await TextFileManager.writeTextFile(this.createKeyUri, this.keyString); - } - - async encryptFunc() { - if (this.plainText === '' || this.keyFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - return; - } - try { - this.cipherText = await this.CryptoOperation.aesConvertAndEncrypt(this.keyString, this.plainText); - } catch (error) { - Logger.error(TAG, `encrypt failed, ${error.code}, ${error.message}`); - promptAction.showToast({ - message: $r('app.string.encrypt_fail') - }); - } - if (this.cipherText === '' || this.cipherText === undefined || this.cipherText === null) { - promptAction.showToast({ - message: $r('app.string.encrypt_fail') - }); - return; - } else { - try { - await this.createTextFileAndWrite(); - } catch (error) { - Logger.error(TAG, `encrypt failed, ${error.code}, ${error.message}`); - } - } - if (this.encryptedFileUri === '' || typeof (this.encryptedFileUri) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.encrypt_fail') - }); - } else { - promptAction.showToast({ - message: $r('app.string.encrypt_success') - }); - } - } - - async genAesKey() { - try { - this.keyString = await this.CryptoOperation.generateAesKey(); - } catch (error) { - Logger.error(TAG, `gen aes key failed, ${error.code}, ${error.message}`); - } - if (this.keyString === '' || typeof (this.keyString) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.gen_key_fail') - }); - return; - } else { - try { - await this.createKeyFileAndWrite(); - } catch (error) { - Logger.error(TAG, `write aes key failed, ${error.code}, ${error.message}`); - } - } - if (this.createKeyUri === '' || typeof (this.createKeyUri) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.gen_key_fail') - }); - } else { - promptAction.showToast({ - message: $r('app.string.gen_key_success') - }); - } - } -} - +/* + * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; +import Logger from '../util/Logger'; +import picker from '@ohos.file.picker'; +import { CryptoOperation } from '../cryptoframework/CryptoOperation'; +import TextFileManager from '../textfilemanager/TextFileManager'; +import common from '@ohos.app.ability.common'; + +const TAG: string = '[Crypto_Framework]'; + +@Component +export struct Encrypt { + @State keyFileName: string = ''; + @State keyFileUri: string = ''; + @State textFileUri: string = ''; + @State textFileName: string = ''; + @State keyString: string = ''; + @State cipherText: string = ''; + @State plainText: string = ''; + @State message: string = ''; + @State createKeyUri: string = ''; + @State encryptedFileUri: string = ''; + private CryptoOperation: CryptoOperation = new CryptoOperation(); + + build() { + Stack({ alignContent: Alignment.Center }) { + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + List() { + ListItem() { + Row() { + Text($r('app.string.open_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('52vp') + .padding({ top: 4, left: 12, right: 12 }) + }.onClick(() => { + this.selectTextFileAndRead(); + }) + + ListItem() { + Row() { + Text($r('app.string.select_key_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('48vp') + .padding({ left: 12, right: 12 }) + }.onClick(() => { + this.selectAesKeyFileAndRead(); + }) + } + .width('100%') + .height('100%') + .borderRadius(16) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.text_context')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.plainText) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.encrypted_context')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.cipherText) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Column() { + Button() { + Text($r('app.string.generate_aes_key_randomly')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .id('encryptAesGenKey') + .borderRadius(20) + .type(ButtonType.Capsule) + .width('100%') + .height('40vp') + .margin({ bottom: 16 }) + .backgroundColor('#007DFF') + .onClick(() => { + this.genAesKey(); + }); + + Button() { + Text($r('app.string.encrypt')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .borderRadius(20) + .id('encryptionBtn') + .type(ButtonType.Capsule) + .margin({ left: 24, right: 24 }) + .width('100%') + .height('40vp') + .backgroundColor('#007DFF') + .onClick(() => { + if (this.textFileUri === '' || this.keyFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + } else { + this.encryptFunc(); + } + }); + } + } + }.margin({ left: 24, right: 24 }) + }.width('100%').height('296vp').justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + } + } + + async selectAesKeyFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到密钥文档文件的URI + this.keyFileUri = result.want.parameters.select_item_list.toString(); + // 获取到密钥文档文件的文件名称 + this.keyFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.keyFileUri); + this.keyString = TextFileManager.getString(); + } + + async selectTextFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到文档文件的URI + this.textFileUri = result.want.parameters.select_item_list.toString(); + // 获取到文档文件的文件名称 + this.textFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.textFileUri); + this.plainText = TextFileManager.getString(); + } + + async createTextFileAndWrite() { + let documentSaveOptions = new picker.DocumentSaveOptions(); + documentSaveOptions.newFileNames = ['cipherText.txt']; + let documentPicker = new picker.DocumentViewPicker(); + let documentSaveResult = await documentPicker.save(documentSaveOptions); + this.encryptedFileUri = documentSaveResult[0]; + await TextFileManager.writeTextFile(this.encryptedFileUri, this.cipherText); + } + + async createKeyFileAndWrite() { + let documentSaveOptions = new picker.DocumentSaveOptions(); + documentSaveOptions.newFileNames = ['aesKey.txt']; + let documentPicker = new picker.DocumentViewPicker(); + let documentSaveResult = await documentPicker.save(documentSaveOptions); + this.createKeyUri = documentSaveResult[0]; + await TextFileManager.writeTextFile(this.createKeyUri, this.keyString); + } + + async encryptFunc() { + if (this.plainText === '' || this.keyFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + return; + } + try { + this.cipherText = await this.CryptoOperation.aesConvertAndEncrypt(this.keyString, this.plainText); + } catch (error) { + Logger.error(TAG, `encrypt failed, ${error.code}, ${error.message}`); + promptAction.showToast({ + message: $r('app.string.encrypt_fail') + }); + } + if (this.cipherText === '' || this.cipherText === undefined || this.cipherText === null) { + promptAction.showToast({ + message: $r('app.string.encrypt_fail') + }); + return; + } else { + try { + await this.createTextFileAndWrite(); + } catch (error) { + Logger.error(TAG, `encrypt failed, ${error.code}, ${error.message}`); + } + } + if (this.encryptedFileUri === '' || typeof (this.encryptedFileUri) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.encrypt_fail') + }); + } else { + promptAction.showToast({ + message: $r('app.string.encrypt_success') + }); + } + } + + async genAesKey() { + try { + this.keyString = await this.CryptoOperation.generateAesKey(); + } catch (error) { + Logger.error(TAG, `gen aes key failed, ${error.code}, ${error.message}`); + } + if (this.keyString === '' || typeof (this.keyString) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.gen_key_fail') + }); + return; + } else { + try { + await this.createKeyFileAndWrite(); + } catch (error) { + Logger.error(TAG, `write aes key failed, ${error.code}, ${error.message}`); + } + } + if (this.createKeyUri === '' || typeof (this.createKeyUri) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.gen_key_fail') + }); + } else { + promptAction.showToast({ + message: $r('app.string.gen_key_success') + }); + } + } +} + diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Sign.ets b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Sign.ets index bc0fd76d696a8db044006fdab8fd3a26d8df7ce2..a446d7af3accf5e3bb3ff42c6335f9f745915c84 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Sign.ets +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Sign.ets @@ -1,352 +1,352 @@ -/* - * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; -import Logger from '../util/Logger'; -import picker from '@ohos.file.picker'; -import { CryptoOperation } from '../cryptoframework/CryptoOperation'; -import TextFileManager from '../textfilemanager/TextFileManager'; -import common from '@ohos.app.ability.common'; - -const TAG: string = '[Crypto_Framework]'; - -@Component -export struct Sign { - @State keyFileName: string = ''; - @State keyFileUri: string = ''; - @State textFileUri: string = ''; - @State textFileName: string = ''; - @State keyString: string = ''; - @State cipherText: string = ''; - @State plainText: string = ''; - @State message: string = ''; - @State signFileUri: string = ''; - @State createKeyUri: string = ''; - private CryptoOperation: CryptoOperation = new CryptoOperation(); - - build() { - Stack({ alignContent: Alignment.Center }) { - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - List() { - ListItem() { - Row() { - Text($r('app.string.open_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('52vp') - .padding({ top: 4, left: 12, right: 12 }) - }.onClick(() => { - this.selectTextFileAndRead(); - }) - - ListItem() { - Row() { - Text($r('app.string.select_key_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('48vp') - .padding({ left: 12, right: 12 }) - }.onClick(() => { - this.selectRsaKeyFileAndRead(); - }) - } - .width('100%') - .height('100%') - .borderRadius(16) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.text_context')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.plainText) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Column() { - Button() { - Text($r('app.string.generate_rsa_key_randomly')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .id('encryptRsaGenKey') - .borderRadius(20) - .type(ButtonType.Capsule) - .width('100%') - .height('40vp') - .margin({ bottom: 16 }) - .backgroundColor('#007DFF') - .onClick(() => { - this.genRsaKey(); - }); - - Button() { - Text($r('app.string.sign')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .borderRadius(20) - .id('signBtn') - .type(ButtonType.Capsule) - .margin({ left: 24, right: 24 }) - .width('100%') - .height('40vp') - .backgroundColor('#007DFF') - .onClick(() => { - if (this.textFileUri === '' || this.keyFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - } else { - this.signFunc(); - } - }); - } - } - }.margin({ left: 24, right: 24 }) - }.width('100%').height('412vp').justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - } - } - - async selectRsaKeyFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到密钥文档文件的URI - this.keyFileUri = result.want.parameters.select_item_list.toString(); - // 获取到密钥文档文件的文件名称 - this.keyFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.keyFileUri); - this.keyString = TextFileManager.getString(); - } - - async selectTextFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到文档文件的URI - this.textFileUri = result.want.parameters.select_item_list.toString(); - // 获取到文档文件的文件名称 - this.textFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.textFileUri); - this.plainText = TextFileManager.getString(); - } - - async createTextFileAndWrite() { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['signText.txt']; - let documentPicker = new picker.DocumentViewPicker(); - let documentSaveResult = await documentPicker.save(documentSaveOptions); - this.signFileUri = documentSaveResult[0]; - await TextFileManager.writeTextFile(this.signFileUri, this.cipherText); - } - - async createKeyFileAndWrite() { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['rsaKey.txt']; - let documentPicker = new picker.DocumentViewPicker(); - try { - let documentSaveResult = await documentPicker.save(documentSaveOptions); - this.createKeyUri = documentSaveResult[0]; - await TextFileManager.writeTextFile(this.createKeyUri, this.keyString); - } catch (error) { - Logger.error(TAG, `save key failed, ${error.code}, ${error.message}`); - } - - } - - async signFunc() { - if (this.plainText === '' || this.keyFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - return; - } - try { - this.cipherText = await this.CryptoOperation.rsaConvertAndSign(this.keyString, this.plainText); - } catch (error) { - promptAction.showToast({ - message: $r('app.string.sign_fail') - }); - Logger.error(TAG, `sign failed, ${error.code}, ${error.message}`); - } - if (this.cipherText === '' || this.cipherText === null || this.cipherText === undefined) { - promptAction.showToast({ - message: $r('app.string.sign_fail') - }); - return; - } else { - await this.createTextFileAndWrite(); - } - if (this.signFileUri === '' || typeof (this.signFileUri) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.sign_fail') - }); - } else { - promptAction.showToast({ - message: $r('app.string.sign_success') - }); - } - } - - async genRsaKey() { - promptAction.showToast({ - message: $r('app.string.slow_rsa_key_gen') - }); - try { - this.keyString = await this.CryptoOperation.generateRsaKey(); - } catch (error) { - Logger.error(TAG, `gen rsa key failed, ${error.code}, ${error.message}`); - } - if (this.keyString === '' || typeof (this.keyString) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.gen_key_fail') - }); - return; - } else { - try { - await this.createKeyFileAndWrite(); - } catch (error) { - Logger.error(TAG, `write rsa key failed, ${error.code}, ${error.message}`); - } - } - if (this.createKeyUri === '' || typeof (this.createKeyUri) == 'undefined') { - promptAction.showToast({ - message: $r('app.string.gen_key_fail') - }); - } else { - promptAction.showToast({ - message: $r('app.string.gen_key_success') - }); - } - - } -} +/* + * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; +import Logger from '../util/Logger'; +import picker from '@ohos.file.picker'; +import { CryptoOperation } from '../cryptoframework/CryptoOperation'; +import TextFileManager from '../textfilemanager/TextFileManager'; +import common from '@ohos.app.ability.common'; + +const TAG: string = '[Crypto_Framework]'; + +@Component +export struct Sign { + @State keyFileName: string = ''; + @State keyFileUri: string = ''; + @State textFileUri: string = ''; + @State textFileName: string = ''; + @State keyString: string = ''; + @State cipherText: string = ''; + @State plainText: string = ''; + @State message: string = ''; + @State signFileUri: string = ''; + @State createKeyUri: string = ''; + private CryptoOperation: CryptoOperation = new CryptoOperation(); + + build() { + Stack({ alignContent: Alignment.Center }) { + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + List() { + ListItem() { + Row() { + Text($r('app.string.open_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('52vp') + .padding({ top: 4, left: 12, right: 12 }) + }.onClick(() => { + this.selectTextFileAndRead(); + }) + + ListItem() { + Row() { + Text($r('app.string.select_key_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('48vp') + .padding({ left: 12, right: 12 }) + }.onClick(() => { + this.selectRsaKeyFileAndRead(); + }) + } + .width('100%') + .height('100%') + .borderRadius(16) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.text_context')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.plainText) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Column() { + Button() { + Text($r('app.string.generate_rsa_key_randomly')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .id('encryptRsaGenKey') + .borderRadius(20) + .type(ButtonType.Capsule) + .width('100%') + .height('40vp') + .margin({ bottom: 16 }) + .backgroundColor('#007DFF') + .onClick(() => { + this.genRsaKey(); + }); + + Button() { + Text($r('app.string.sign')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .borderRadius(20) + .id('signBtn') + .type(ButtonType.Capsule) + .margin({ left: 24, right: 24 }) + .width('100%') + .height('40vp') + .backgroundColor('#007DFF') + .onClick(() => { + if (this.textFileUri === '' || this.keyFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + } else { + this.signFunc(); + } + }); + } + } + }.margin({ left: 24, right: 24 }) + }.width('100%').height('412vp').justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + } + } + + async selectRsaKeyFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到密钥文档文件的URI + this.keyFileUri = result.want.parameters.select_item_list.toString(); + // 获取到密钥文档文件的文件名称 + this.keyFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.keyFileUri); + this.keyString = TextFileManager.getString(); + } + + async selectTextFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到文档文件的URI + this.textFileUri = result.want.parameters.select_item_list.toString(); + // 获取到文档文件的文件名称 + this.textFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.textFileUri); + this.plainText = TextFileManager.getString(); + } + + async createTextFileAndWrite() { + let documentSaveOptions = new picker.DocumentSaveOptions(); + documentSaveOptions.newFileNames = ['signText.txt']; + let documentPicker = new picker.DocumentViewPicker(); + let documentSaveResult = await documentPicker.save(documentSaveOptions); + this.signFileUri = documentSaveResult[0]; + await TextFileManager.writeTextFile(this.signFileUri, this.cipherText); + } + + async createKeyFileAndWrite() { + let documentSaveOptions = new picker.DocumentSaveOptions(); + documentSaveOptions.newFileNames = ['rsaKey.txt']; + let documentPicker = new picker.DocumentViewPicker(); + try { + let documentSaveResult = await documentPicker.save(documentSaveOptions); + this.createKeyUri = documentSaveResult[0]; + await TextFileManager.writeTextFile(this.createKeyUri, this.keyString); + } catch (error) { + Logger.error(TAG, `save key failed, ${error.code}, ${error.message}`); + } + + } + + async signFunc() { + if (this.plainText === '' || this.keyFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + return; + } + try { + this.cipherText = await this.CryptoOperation.rsaConvertAndSign(this.keyString, this.plainText); + } catch (error) { + promptAction.showToast({ + message: $r('app.string.sign_fail') + }); + Logger.error(TAG, `sign failed, ${error.code}, ${error.message}`); + } + if (this.cipherText === '' || this.cipherText === null || this.cipherText === undefined) { + promptAction.showToast({ + message: $r('app.string.sign_fail') + }); + return; + } else { + await this.createTextFileAndWrite(); + } + if (this.signFileUri === '' || typeof (this.signFileUri) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.sign_fail') + }); + } else { + promptAction.showToast({ + message: $r('app.string.sign_success') + }); + } + } + + async genRsaKey() { + promptAction.showToast({ + message: $r('app.string.slow_rsa_key_gen') + }); + try { + this.keyString = await this.CryptoOperation.generateRsaKey(); + } catch (error) { + Logger.error(TAG, `gen rsa key failed, ${error.code}, ${error.message}`); + } + if (this.keyString === '' || typeof (this.keyString) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.gen_key_fail') + }); + return; + } else { + try { + await this.createKeyFileAndWrite(); + } catch (error) { + Logger.error(TAG, `write rsa key failed, ${error.code}, ${error.message}`); + } + } + if (this.createKeyUri === '' || typeof (this.createKeyUri) == 'undefined') { + promptAction.showToast({ + message: $r('app.string.gen_key_fail') + }); + } else { + promptAction.showToast({ + message: $r('app.string.gen_key_success') + }); + } + + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Verify.ets b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Verify.ets index b273311c1816d994d3cb0ef1887eabb42c41d6bb..cd9ea39ee0d45bb67067ba302750991181eeafce 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Verify.ets +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/tab/Verify.ets @@ -1,358 +1,358 @@ -/* - * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; -import Logger from '../util/Logger'; -import picker from '@ohos.file.picker'; -import { CryptoOperation } from '../cryptoframework/CryptoOperation'; -import TextFileManager from '../textfilemanager/TextFileManager'; -import common from '@ohos.app.ability.common'; - -const TAG: string = '[Crypto_Framework]'; - -@Component -export struct Verify { - @State keyFileName: string = ''; - @State keyFileUri: string = ''; - @State textFileUri: string = ''; - @State textFileName: string = ''; - @State keyString: string = ''; - @State plainText: string = ''; - @State message: string = ''; - @State signFileUri: string = ''; - @State signFileName: string = ''; - @State signText: string = ''; - @State createKeyUri: string = ''; - private CryptoOperation: CryptoOperation = new CryptoOperation(); - - build() { - Stack({ alignContent: Alignment.Center }) { - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - List() { - ListItem() { - Row() { - Text($r('app.string.open_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('52vp') - .padding({ top: 4, left: 12, right: 12 }) - }.onClick(() => { - this.selectTextFileAndRead(); - }) - - ListItem() { - Row() { - Text($r('app.string.select_key_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('48vp') - .padding({ left: 12, right: 12 }) - }.onClick(() => { - this.selectRsaKeyFileAndRead(); - }) - } - .width('100%') - .height('100%') - .borderRadius(16) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - List() { - ListItem() { - Row() { - Text($r('app.string.select_signature_file')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - - Blank() - - Text(this.signFileName === '' ? $r('app.string.please_choose') : this.signFileName) - .fontSize(14) - .textAlign(TextAlign.Start) - .lineHeight(19) - - Image($r('app.media.right_arrow')) - .height('19vp') - .width('10vp') - .margin({ left: 9, right: 9, top: 6, bottom: 6 }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('56vp') - .padding({ left: 12, right: 12, top: 4, bottom: 4 }) - }.onClick(() => { - this.selectSignFileAndRead(); - }) - } - .width('100%') - .borderRadius(16) - } - } - } - .height('56vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.text_context')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.plainText) - .fontSize(16) - .fontWeight(400) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Column() { - Button() { - Text($r('app.string.verify')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .borderRadius(20) - .id('verifyBtn') - .type(ButtonType.Capsule) - .margin({ left: 24, right: 24 }) - .width('100%') - .height('40vp') - .backgroundColor('#007DFF') - .onClick(() => { - if (this.textFileUri === '' || this.keyFileUri === '' || this.signFileUri === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - } else { - this.verifyFunc(); - } - }); - } - } - }.margin({ left: 24, right: 24 }) - }.width('100%').height('340vp').justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - } - } - - async selectRsaKeyFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到密钥文档文件的URI - this.keyFileUri = result.want.parameters.select_item_list.toString(); - // 获取到密钥文档文件的文件名称 - this.keyFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.keyFileUri); - this.keyString = TextFileManager.getString(); - } - - async selectTextFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到文档文件的URI - this.textFileUri = result.want.parameters.select_item_list.toString(); - // 获取到文档文件的文件名称 - this.textFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.textFileUri); - this.plainText = TextFileManager.getString(); - } - - async selectSignFileAndRead() { - let config = { - action: 'ohos.want.action.OPEN_FILE', - parameters: { - startMode: 'choose', - } - } - let context = getContext(this) as common.UIAbilityContext; - let result = await context.startAbilityForResult(config); - if (result === null || result === undefined) { - Logger.error(TAG, `result is null or undefined!`); - return; - } - if (result.resultCode !== 0) { - Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); - return; - } - if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { - Logger.error(TAG, `result uri is null or undefined!`); - return; - } - if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { - Logger.error(TAG, `result file name is null or undefined!`); - return; - } - // 获取到文档文件的URI - this.signFileUri = result.want.parameters.select_item_list.toString(); - // 获取到文档文件的文件名称 - this.signFileName = result.want.parameters.file_name_list.toString(); - await TextFileManager.readTextFile(this.signFileUri); - this.signText = TextFileManager.getString(); - } - - async createKeyFileAndWrite() { - let documentSaveOptions = new picker.DocumentSaveOptions(); - documentSaveOptions.newFileNames = ['rsaKey.txt']; - let documentPicker = new picker.DocumentViewPicker(); - try { - let documentSaveResult = await documentPicker.save(documentSaveOptions); - this.createKeyUri = documentSaveResult[0]; - await TextFileManager.writeTextFile(this.createKeyUri, this.keyString); - } catch (error) { - Logger.error(TAG, `save key failed, ${error.code}, ${error.message}`); - } - - } - - async verifyFunc() { - let verifyRes; - if (this.plainText === '' || this.keyFileUri === '' || this.signText === '') { - promptAction.showToast({ - message: $r('app.string.null_message') - }); - return; - } - try { - verifyRes = await this.CryptoOperation.rsaConvertAndVerify(this.keyString, this.plainText, this.signText); - } catch (error) { - Logger.error(TAG, `verify failed, ${error.code}, ${error.message}`); - } - if (verifyRes != true) { - promptAction.showToast({ - message: $r('app.string.verify_fail') - }); - return; - } else { - promptAction.showToast({ - message: $r('app.string.verify_success') - }); - } - } -} +/* + * Copyright (c) 2023 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 promptAction from '@ohos.promptAction'; +import Logger from '../util/Logger'; +import picker from '@ohos.file.picker'; +import { CryptoOperation } from '../cryptoframework/CryptoOperation'; +import TextFileManager from '../textfilemanager/TextFileManager'; +import common from '@ohos.app.ability.common'; + +const TAG: string = '[Crypto_Framework]'; + +@Component +export struct Verify { + @State keyFileName: string = ''; + @State keyFileUri: string = ''; + @State textFileUri: string = ''; + @State textFileName: string = ''; + @State keyString: string = ''; + @State plainText: string = ''; + @State message: string = ''; + @State signFileUri: string = ''; + @State signFileName: string = ''; + @State signText: string = ''; + @State createKeyUri: string = ''; + private CryptoOperation: CryptoOperation = new CryptoOperation(); + + build() { + Stack({ alignContent: Alignment.Center }) { + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + List() { + ListItem() { + Row() { + Text($r('app.string.open_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.textFileName === '' ? $r('app.string.please_choose') : this.textFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('52vp') + .padding({ top: 4, left: 12, right: 12 }) + }.onClick(() => { + this.selectTextFileAndRead(); + }) + + ListItem() { + Row() { + Text($r('app.string.select_key_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.keyFileName === '' ? $r('app.string.please_choose') : this.keyFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('48vp') + .padding({ left: 12, right: 12 }) + }.onClick(() => { + this.selectRsaKeyFileAndRead(); + }) + } + .width('100%') + .height('100%') + .borderRadius(16) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + List() { + ListItem() { + Row() { + Text($r('app.string.select_signature_file')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + + Blank() + + Text(this.signFileName === '' ? $r('app.string.please_choose') : this.signFileName) + .fontSize(14) + .textAlign(TextAlign.Start) + .lineHeight(19) + + Image($r('app.media.right_arrow')) + .height('19vp') + .width('10vp') + .margin({ left: 9, right: 9, top: 6, bottom: 6 }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('56vp') + .padding({ left: 12, right: 12, top: 4, bottom: 4 }) + }.onClick(() => { + this.selectSignFileAndRead(); + }) + } + .width('100%') + .borderRadius(16) + } + } + } + .height('56vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.text_context')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.plainText) + .fontSize(16) + .fontWeight(400) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Column() { + Button() { + Text($r('app.string.verify')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .borderRadius(20) + .id('verifyBtn') + .type(ButtonType.Capsule) + .margin({ left: 24, right: 24 }) + .width('100%') + .height('40vp') + .backgroundColor('#007DFF') + .onClick(() => { + if (this.textFileUri === '' || this.keyFileUri === '' || this.signFileUri === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + } else { + this.verifyFunc(); + } + }); + } + } + }.margin({ left: 24, right: 24 }) + }.width('100%').height('340vp').justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + } + } + + async selectRsaKeyFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到密钥文档文件的URI + this.keyFileUri = result.want.parameters.select_item_list.toString(); + // 获取到密钥文档文件的文件名称 + this.keyFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.keyFileUri); + this.keyString = TextFileManager.getString(); + } + + async selectTextFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到文档文件的URI + this.textFileUri = result.want.parameters.select_item_list.toString(); + // 获取到文档文件的文件名称 + this.textFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.textFileUri); + this.plainText = TextFileManager.getString(); + } + + async selectSignFileAndRead() { + let config = { + action: 'ohos.want.action.OPEN_FILE', + parameters: { + startMode: 'choose', + } + } + let context = getContext(this) as common.UIAbilityContext; + let result = await context.startAbilityForResult(config); + if (result === null || result === undefined) { + Logger.error(TAG, `result is null or undefined!`); + return; + } + if (result.resultCode !== 0) { + Logger.error(TAG, `DocumentPicker.select failed, code is ${result.resultCode}, message is ${result.want.parameters.message}`); + return; + } + if (result.want.parameters.select_item_list === null || result.want.parameters.select_item_list === undefined) { + Logger.error(TAG, `result uri is null or undefined!`); + return; + } + if (result.want.parameters.file_name_list === null || result.want.parameters.file_name_list === undefined) { + Logger.error(TAG, `result file name is null or undefined!`); + return; + } + // 获取到文档文件的URI + this.signFileUri = result.want.parameters.select_item_list.toString(); + // 获取到文档文件的文件名称 + this.signFileName = result.want.parameters.file_name_list.toString(); + await TextFileManager.readTextFile(this.signFileUri); + this.signText = TextFileManager.getString(); + } + + async createKeyFileAndWrite() { + let documentSaveOptions = new picker.DocumentSaveOptions(); + documentSaveOptions.newFileNames = ['rsaKey.txt']; + let documentPicker = new picker.DocumentViewPicker(); + try { + let documentSaveResult = await documentPicker.save(documentSaveOptions); + this.createKeyUri = documentSaveResult[0]; + await TextFileManager.writeTextFile(this.createKeyUri, this.keyString); + } catch (error) { + Logger.error(TAG, `save key failed, ${error.code}, ${error.message}`); + } + + } + + async verifyFunc() { + let verifyRes; + if (this.plainText === '' || this.keyFileUri === '' || this.signText === '') { + promptAction.showToast({ + message: $r('app.string.null_message') + }); + return; + } + try { + verifyRes = await this.CryptoOperation.rsaConvertAndVerify(this.keyString, this.plainText, this.signText); + } catch (error) { + Logger.error(TAG, `verify failed, ${error.code}, ${error.message}`); + } + if (verifyRes != true) { + promptAction.showToast({ + message: $r('app.string.verify_fail') + }); + return; + } else { + promptAction.showToast({ + message: $r('app.string.verify_success') + }); + } + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/textfilemanager/TextFileManager.ts b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/textfilemanager/TextFileManager.ts index 0e1fae674218e1c950ac4cd3497cf881fe1b527b..dfdbabd34972eda2f8f13c0aa91e4716c78342c4 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/textfilemanager/TextFileManager.ts +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/textfilemanager/TextFileManager.ts @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2023 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 fs from '@ohos.file.fs'; -import Logger from '../util/Logger'; - -const TAG: string = '[Crypto_Framework]'; -const FILE_SLEEP_TIME: number = 100; -const TEXT_MAX_READ_LEN: number = 8192; -// filePicker和文件管理,在OH 4.0.8.2镜像版本,读取uri后,无法直接read、write文件内容,需要sleep几十ms,这里sleep100毫秒 -function sleep(time: number): Promise { - return new Promise((resolve) => setTimeout(resolve, time)); -} - -class TextFileManager { - public static readString: string = ''; - public static readResult: number = 0; - public static writeResult: number = 0; - - async readTextFile(textFileUri: string): Promise { - await sleep(FILE_SLEEP_TIME); - try { - // 读取 - let file = fs.openSync(textFileUri, fs.OpenMode.READ_ONLY); - Logger.info(TAG, 'success, read only file ' + file.fd); - // 从文件读取一段内容,限制最大长度为8192 - let buf = new ArrayBuffer(TEXT_MAX_READ_LEN); - try { - let readLen: number = fs.readSync(file.fd, buf, { offset: 0 }); - TextFileManager.readString = String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))); - TextFileManager.readResult = readLen; - } catch (error1) { - Logger.error(TAG, `file read failed, ${error1.code}, ${error1.message}`); - } - fs.closeSync(file); - } catch (error) { - Logger.error(TAG, `file open failed, ${error.code}, ${error.message}`); - return; - } - } - - async writeTextFile(textFileUri: string, textString: string): Promise { - await sleep(FILE_SLEEP_TIME); - try { - // 读写 - let file = fs.openSync(textFileUri, fs.OpenMode.READ_WRITE); - Logger.info(TAG, 'success, read write file' + file.fd); - try { - // 写入 - let writeLen = fs.writeSync(file.fd, textString); - Logger.info(TAG, 'success, The length of str is: ' + writeLen); - TextFileManager.writeResult = writeLen; - } catch (error1) { - Logger.error(TAG, `file write failed, ${error1.code}, ${error1.message}`); - } - fs.closeSync(file); - } catch (error) { - Logger.error(TAG, `file open failed, ${error.code}, ${error.message}`); - return; - } - } - - getString(): string { - return TextFileManager.readString; - } -} - +/* + * Copyright (c) 2023 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 fs from '@ohos.file.fs'; +import Logger from '../util/Logger'; + +const TAG: string = '[Crypto_Framework]'; +const FILE_SLEEP_TIME: number = 100; +const TEXT_MAX_READ_LEN: number = 8192; +// filePicker和文件管理,在OH 4.0.8.2镜像版本,读取uri后,无法直接read、write文件内容,需要sleep几十ms,这里sleep100毫秒 +function sleep(time: number): Promise { + return new Promise((resolve) => setTimeout(resolve, time)); +} + +class TextFileManager { + public static readString: string = ''; + public static readResult: number = 0; + public static writeResult: number = 0; + + async readTextFile(textFileUri: string): Promise { + await sleep(FILE_SLEEP_TIME); + try { + // 读取 + let file = fs.openSync(textFileUri, fs.OpenMode.READ_ONLY); + Logger.info(TAG, 'success, read only file ' + file.fd); + // 从文件读取一段内容,限制最大长度为8192 + let buf = new ArrayBuffer(TEXT_MAX_READ_LEN); + try { + let readLen: number = fs.readSync(file.fd, buf, { offset: 0 }); + TextFileManager.readString = String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))); + TextFileManager.readResult = readLen; + } catch (error1) { + Logger.error(TAG, `file read failed, ${error1.code}, ${error1.message}`); + } + fs.closeSync(file); + } catch (error) { + Logger.error(TAG, `file open failed, ${error.code}, ${error.message}`); + return; + } + } + + async writeTextFile(textFileUri: string, textString: string): Promise { + await sleep(FILE_SLEEP_TIME); + try { + // 读写 + let file = fs.openSync(textFileUri, fs.OpenMode.READ_WRITE); + Logger.info(TAG, 'success, read write file' + file.fd); + try { + // 写入 + let writeLen = fs.writeSync(file.fd, textString); + Logger.info(TAG, 'success, The length of str is: ' + writeLen); + TextFileManager.writeResult = writeLen; + } catch (error1) { + Logger.error(TAG, `file write failed, ${error1.code}, ${error1.message}`); + } + fs.closeSync(file); + } catch (error) { + Logger.error(TAG, `file open failed, ${error.code}, ${error.message}`); + return; + } + } + + getString(): string { + return TextFileManager.readString; + } +} + export default new TextFileManager(); \ No newline at end of file diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/util/Logger.ts b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/util/Logger.ts index 835b34e2ebb880ce7e94c45f724b1e3b950d8747..3a7c27e4339f51b24619c64b87eeff99b003f591 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/util/Logger.ts +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/ets/util/Logger.ts @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - return; - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - return; - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - return; - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - return; - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - return; - } - - isLoggable(level: number): void { - hilog.isLoggable(this.domain, this.prefix, level); - return; - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + return; + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + return; + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + return; + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + return; + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + return; + } + + isLoggable(level: number): void { + hilog.isLoggable(this.domain, this.prefix, level); + return; + } +} + export default new Logger('[Sample_Crypto_framework]'); \ No newline at end of file diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/module.json5 b/code/BasicFeature/Security/CryptoFramework/entry/src/main/module.json5 index e8105a75058798cd4c5d30f587f0652a238c109d..8377d805fa9acab4fe63df19e30655941df1e930 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/module.json5 +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "srcEntrance": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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", + "srcEntrance": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/main/resources/base/element/color.json b/code/BasicFeature/Security/CryptoFramework/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/main/resources/base/element/color.json +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/BasicFeature/Security/CryptoFramework/entry/src/ohosTest/module.json5 b/code/BasicFeature/Security/CryptoFramework/entry/src/ohosTest/module.json5 index 741bfbf578fbe34a741c12bea708bb5aa27bcaf1..22e2c611f379dbb0fddf452b259ef27c508d058b 100644 --- a/code/BasicFeature/Security/CryptoFramework/entry/src/ohosTest/module.json5 +++ b/code/BasicFeature/Security/CryptoFramework/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/hvigor/hvigor-config.json5 b/code/BasicFeature/Security/CryptoFramework/hvigor/hvigor-config.json5 index 32f6d6f5120560123d6354b787f812f3be4adbc1..6128b5c55e60e4884ccaf7ceb15defb8ca1fc8b3 100644 --- a/code/BasicFeature/Security/CryptoFramework/hvigor/hvigor-config.json5 +++ b/code/BasicFeature/Security/CryptoFramework/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "hvigorVersion": "2.1.1", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.1.1" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "hvigorVersion": "2.1.1", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "2.1.1" + } +} diff --git a/code/BasicFeature/Security/CryptoFramework/oh-package.json5 b/code/BasicFeature/Security/CryptoFramework/oh-package.json5 index 5616a894a7342b94859cc2b7cd913a8ea6c21a09..0634a0476233835d7d819f3cdc7e1ec8d48edb92 100644 --- a/code/BasicFeature/Security/CryptoFramework/oh-package.json5 +++ b/code/BasicFeature/Security/CryptoFramework/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "ISC", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "name": "com.samples.cryptoFramework", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "name": "com.samples.cryptoFramework", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/BasicFeature/Security/CryptoFramework/ohosTest.md b/code/BasicFeature/Security/CryptoFramework/ohosTest.md index a6457f84e3fa985883ec18f36dfce107c8272aa9..127df7c7ecc8ba0629b84c781365ba07b450bae8 100644 --- a/code/BasicFeature/Security/CryptoFramework/ohosTest.md +++ b/code/BasicFeature/Security/CryptoFramework/ohosTest.md @@ -1,25 +1,25 @@ -# CryptoFramework 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 |是否自动|测试结果| -|--------------|--------------------------|-----------------------------------------------------------------|---------------------------------|--------------------------------|--------------------------------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 |是|Pass| -| 主页tabs选择 | 成功拉起应用 | 点击加密tab | 跳转至加密页面 |是|Pass| -| 主页tabs选择 | 成功拉起应用 | 点击解密tab | 跳转至解密页面 |是|Pass| -| 主页tabs选择 | 成功拉起应用 | 点击签名tab | 跳转至签名页面 |是|Pass| -| 主页tabs选择 | 成功拉起应用 | 点击验签tab | 跳转至签名页面 |是|Pass| -| 加密按钮点击 | 位于加密页面 | 不选择文件、密钥,点击加密按钮 | 提示文件或密钥为空 |是|Pass| -| 解密按钮点击 | 位于解密页面 | 不选择文件、密钥,点击解密按钮 | 提示文件或密钥为空 |是|Pass| -| 签名按钮点击 | 位于签名页面 | 不选择文件、密钥,点击签名按钮 | 提示文件或密钥为空 |是|Pass| -| 验签按钮点击 | 位于验签页面 | 不选择文件、密钥、签名文件,点击验签按钮 | 提示文件或密钥为空 |是|Pass| -| 加密功能,生成AES密钥 | 位于加密页面 | 点击随机生成AES密钥按钮,跳转至filepicker界面,默认密钥文件名为aesKey,可自定义文件命名,点击确认 | 提示已生成AES密钥 |否|Pass| -| 签名功能,生成RSA密钥 | 位于签名页面 | 点击随机生成RSA密钥按钮,然后跳转至filepicker界面,默认密钥文件名为rsaKey,可自定义文件命名,点击确认 | 先提示"RSA密钥生成较慢,请稍等", 再提示已生成RSA密钥 |否|Pass| -| 选择密钥 | 位于加密、解密、签名、验签页面 | 点击选择密钥按钮,跳转至filepicker界面,选择密钥文本文件,加密解密采用aes密钥,签名验签采用rsa密钥 | 文本栏显示选择的密钥文件名 |否|Pass| -| 打开文件 | 位于加密、解密、签名、验签页面 | 点击选择文件按钮,跳转至filepicker界面,选择文本文件 | 文本栏显示选择的文本文件名 |否|Pass| -| 选择签名文件 | 位于验签页面 | 点击选择签名文件按钮,跳转至filepicker界面,选择签名文本文件 | 文本栏显示选择的签名文本文件名 |否|Pass| -| 加密功能 | 位于加密页面,已选择文件、密钥 | 点击加密按钮,跳转至filepicker界面,默认加密得到的密文文本文件名为cipherText,可自定义文件命名,点击确认 | 提示加密成功,加密内容文本栏显示密文文本内容 |否|Pass| -| 解密功能 | 位于解密页面,已选择正确的文件、密钥 | 点击解密按钮,跳转至filepicker界面,默认解密得到的明文文本文件名为plainText,可自定义文件命名,点击确认 | 提示解密成功,解密内容文本栏显示明文文本内容 |否|Pass| -| 签名功能 | 位于签名页面,已选择文件、密钥 | 点击签名按钮,跳转至filepicker界面,默认签名得到的签名文本文件名为signText,可自定义文件命名,点击确认 | 提示签名成功 |否|Pass| -| 验签功能 | 位于验签页面,已选择正确的文件、密钥、签名文件 | 点击验签按钮 | 提示验签成功 |否|Pass| +# CryptoFramework 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 |是否自动|测试结果| +|--------------|--------------------------|-----------------------------------------------------------------|---------------------------------|--------------------------------|--------------------------------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 |是|Pass| +| 主页tabs选择 | 成功拉起应用 | 点击加密tab | 跳转至加密页面 |是|Pass| +| 主页tabs选择 | 成功拉起应用 | 点击解密tab | 跳转至解密页面 |是|Pass| +| 主页tabs选择 | 成功拉起应用 | 点击签名tab | 跳转至签名页面 |是|Pass| +| 主页tabs选择 | 成功拉起应用 | 点击验签tab | 跳转至签名页面 |是|Pass| +| 加密按钮点击 | 位于加密页面 | 不选择文件、密钥,点击加密按钮 | 提示文件或密钥为空 |是|Pass| +| 解密按钮点击 | 位于解密页面 | 不选择文件、密钥,点击解密按钮 | 提示文件或密钥为空 |是|Pass| +| 签名按钮点击 | 位于签名页面 | 不选择文件、密钥,点击签名按钮 | 提示文件或密钥为空 |是|Pass| +| 验签按钮点击 | 位于验签页面 | 不选择文件、密钥、签名文件,点击验签按钮 | 提示文件或密钥为空 |是|Pass| +| 加密功能,生成AES密钥 | 位于加密页面 | 点击随机生成AES密钥按钮,跳转至filepicker界面,默认密钥文件名为aesKey,可自定义文件命名,点击确认 | 提示已生成AES密钥 |否|Pass| +| 签名功能,生成RSA密钥 | 位于签名页面 | 点击随机生成RSA密钥按钮,然后跳转至filepicker界面,默认密钥文件名为rsaKey,可自定义文件命名,点击确认 | 先提示"RSA密钥生成较慢,请稍等", 再提示已生成RSA密钥 |否|Pass| +| 选择密钥 | 位于加密、解密、签名、验签页面 | 点击选择密钥按钮,跳转至filepicker界面,选择密钥文本文件,加密解密采用aes密钥,签名验签采用rsa密钥 | 文本栏显示选择的密钥文件名 |否|Pass| +| 打开文件 | 位于加密、解密、签名、验签页面 | 点击选择文件按钮,跳转至filepicker界面,选择文本文件 | 文本栏显示选择的文本文件名 |否|Pass| +| 选择签名文件 | 位于验签页面 | 点击选择签名文件按钮,跳转至filepicker界面,选择签名文本文件 | 文本栏显示选择的签名文本文件名 |否|Pass| +| 加密功能 | 位于加密页面,已选择文件、密钥 | 点击加密按钮,跳转至filepicker界面,默认加密得到的密文文本文件名为cipherText,可自定义文件命名,点击确认 | 提示加密成功,加密内容文本栏显示密文文本内容 |否|Pass| +| 解密功能 | 位于解密页面,已选择正确的文件、密钥 | 点击解密按钮,跳转至filepicker界面,默认解密得到的明文文本文件名为plainText,可自定义文件命名,点击确认 | 提示解密成功,解密内容文本栏显示明文文本内容 |否|Pass| +| 签名功能 | 位于签名页面,已选择文件、密钥 | 点击签名按钮,跳转至filepicker界面,默认签名得到的签名文本文件名为signText,可自定义文件命名,点击确认 | 提示签名成功 |否|Pass| +| 验签功能 | 位于验签页面,已选择正确的文件、密钥、签名文件 | 点击验签按钮 | 提示验签成功 |否|Pass| **** \ No newline at end of file diff --git a/code/BasicFeature/Security/Huks/entry/src/main/ets/common/MinAccessControl.ets b/code/BasicFeature/Security/Huks/entry/src/main/ets/common/MinAccessControl.ets index 199f47be4e4899351e851b85698a9e9e2bd42948..b02706984ade4025434e7145369bda1451576ff2 100644 --- a/code/BasicFeature/Security/Huks/entry/src/main/ets/common/MinAccessControl.ets +++ b/code/BasicFeature/Security/Huks/entry/src/main/ets/common/MinAccessControl.ets @@ -1,220 +1,220 @@ -/* - * Copyright (c) 2023 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 prompt from '@ohos.prompt' -import Logger from '../model/Logger' -import { HuksModel } from '../model/HuksModel' - -const TAG: string = '[HUKS]' - -@Component -export struct MinAccessControl { - @State cipherTextinfo: string = '' - @State plainTextinfo: string = '' - @State inputPassword: string = '' - huksModel: HuksModel = new HuksModel() - - build() { - Stack({ alignContent: Alignment.Center }) { - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - List() { - ListItem() { - Row() { - Text($r('app.string.input_save_password')) - .fontSize(16) - .textAlign(TextAlign.Start) - .lineHeight(22) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('52vp') - .padding({ top: 4, left: 12, right: 12 }) - } - - ListItem() { - Row() { - TextInput() - .enableKeyboardOnFocus(false) - .margin(4) - .width('90%') - .id('passwordInput') - .fontSize(16) - .textAlign(TextAlign.Start) - .onChange((value: string) => { - this.inputPassword = value - }) - } - .backgroundColor(0xFFFFFF) - .width('100%') - .height('48vp') - .padding({ left: 12, right: 12 }) - } - } - .width('100%') - .height('100%') - .borderRadius(16) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.cipher_text')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.cipherTextinfo) - .fontSize(16) - .fontWeight(400) - .fontColor(0x808080) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - .id('cipherTextinfo') - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - Column() { - Row() { - Text($r('app.string.plain_text')) - .fontSize(16) - .textAlign(TextAlign.Start) - .fontWeight(500) - .lineHeight(22) - } - .padding({ left: 12, right: 12 }) - .width('100%') - .height('48vp') - - Row() { - Text() { - Span(this.plainTextinfo) - .fontSize(16) - .fontWeight(400) - .fontColor(0x808080) - .fontColor('#182431') - }.textAlign(TextAlign.Start) - .id('plainTextinfo') - } - .padding({ left: 12, right: 12, bottom: 4 }) - .width('100%') - .height('52vp') - } - .borderRadius(16) - .width('100%') - .height('100') - .backgroundColor(0xFFFFFF) - } - } - } - .height('100vp') - .margin({ left: 12, right: 12, bottom: 12 }) - - Column() { - GridRow() { - GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { - Column() { - Button() { - Text($r('app.string.save_password')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .id('save_password') - .borderRadius(20) - .type(ButtonType.Capsule) - .width('100%') - .height('40vp') - .margin({ bottom: 16 }) - .backgroundColor('#007DFF') - .onClick(() => { - if (this.inputPassword === '') { - prompt.showToast({ - message: 'This message is null.' - }) - } else { - this.huksModel.encryptDataUseSm2(this.inputPassword, (result: string) => { - Logger.info(TAG, `this result = ${result}`) - this.cipherTextinfo = `${result}` - }) - } - }); - - Button() { - Text($r('app.string.read_password')).fontSize(16).fontWeight(500) - .lineHeight(22) - .fontColor('#FFFFFF') - } - .borderRadius(20) - .id('read_password') - .type(ButtonType.Capsule) - .margin({ left: 24, right: 24 }) - .width('100%') - .height('40vp') - .backgroundColor('#007DFF') - .onClick(() => { - - if (this.inputPassword === '') { - prompt.showToast({ - message: 'This message is null.' - }) - } else { - this.huksModel.decryptDataUseSm2((result: string) => { - Logger.info(TAG, `this result = ${result}`) - this.plainTextinfo = `${result}` - }) - } - - }); - } - } - }.margin({ left: 24, right: 24 }) - }.width('100%').height('296vp').justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - } - } -} - +/* + * Copyright (c) 2023 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 prompt from '@ohos.prompt' +import Logger from '../model/Logger' +import { HuksModel } from '../model/HuksModel' + +const TAG: string = '[HUKS]' + +@Component +export struct MinAccessControl { + @State cipherTextinfo: string = '' + @State plainTextinfo: string = '' + @State inputPassword: string = '' + huksModel: HuksModel = new HuksModel() + + build() { + Stack({ alignContent: Alignment.Center }) { + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + List() { + ListItem() { + Row() { + Text($r('app.string.input_save_password')) + .fontSize(16) + .textAlign(TextAlign.Start) + .lineHeight(22) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('52vp') + .padding({ top: 4, left: 12, right: 12 }) + } + + ListItem() { + Row() { + TextInput() + .enableKeyboardOnFocus(false) + .margin(4) + .width('90%') + .id('passwordInput') + .fontSize(16) + .textAlign(TextAlign.Start) + .onChange((value: string) => { + this.inputPassword = value + }) + } + .backgroundColor(0xFFFFFF) + .width('100%') + .height('48vp') + .padding({ left: 12, right: 12 }) + } + } + .width('100%') + .height('100%') + .borderRadius(16) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.cipher_text')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.cipherTextinfo) + .fontSize(16) + .fontWeight(400) + .fontColor(0x808080) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + .id('cipherTextinfo') + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Column() { + Row() { + Text($r('app.string.plain_text')) + .fontSize(16) + .textAlign(TextAlign.Start) + .fontWeight(500) + .lineHeight(22) + } + .padding({ left: 12, right: 12 }) + .width('100%') + .height('48vp') + + Row() { + Text() { + Span(this.plainTextinfo) + .fontSize(16) + .fontWeight(400) + .fontColor(0x808080) + .fontColor('#182431') + }.textAlign(TextAlign.Start) + .id('plainTextinfo') + } + .padding({ left: 12, right: 12, bottom: 4 }) + .width('100%') + .height('52vp') + } + .borderRadius(16) + .width('100%') + .height('100') + .backgroundColor(0xFFFFFF) + } + } + } + .height('100vp') + .margin({ left: 12, right: 12, bottom: 12 }) + + Column() { + GridRow() { + GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) { + Column() { + Button() { + Text($r('app.string.save_password')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .id('save_password') + .borderRadius(20) + .type(ButtonType.Capsule) + .width('100%') + .height('40vp') + .margin({ bottom: 16 }) + .backgroundColor('#007DFF') + .onClick(() => { + if (this.inputPassword === '') { + prompt.showToast({ + message: 'This message is null.' + }) + } else { + this.huksModel.encryptDataUseSm2(this.inputPassword, (result: string) => { + Logger.info(TAG, `this result = ${result}`) + this.cipherTextinfo = `${result}` + }) + } + }); + + Button() { + Text($r('app.string.read_password')).fontSize(16).fontWeight(500) + .lineHeight(22) + .fontColor('#FFFFFF') + } + .borderRadius(20) + .id('read_password') + .type(ButtonType.Capsule) + .margin({ left: 24, right: 24 }) + .width('100%') + .height('40vp') + .backgroundColor('#007DFF') + .onClick(() => { + + if (this.inputPassword === '') { + prompt.showToast({ + message: 'This message is null.' + }) + } else { + this.huksModel.decryptDataUseSm2((result: string) => { + Logger.info(TAG, `this result = ${result}`) + this.plainTextinfo = `${result}` + }) + } + + }); + } + } + }.margin({ left: 24, right: 24 }) + }.width('100%').height('296vp').justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + } + } +} + diff --git a/code/DocsSample/Ability/Performance/Startup/AppScope/app.json5 b/code/DocsSample/Ability/Performance/Startup/AppScope/app.json5 index a1e316bd0da9eede64646b2224f33d3412b7fe2b..cca1228f507fea783168fee4e008af5537b63e95 100644 --- a/code/DocsSample/Ability/Performance/Startup/AppScope/app.json5 +++ b/code/DocsSample/Ability/Performance/Startup/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.startup", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.startup", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Ability/Performance/Startup/AppScope/resources/base/element/string.json b/code/DocsSample/Ability/Performance/Startup/AppScope/resources/base/element/string.json index 6dbee75ce95d09f596414555160cb2e3d86aedc1..e2c5787e95f39878b328fc3a0bb0169c6091df5b 100644 --- a/code/DocsSample/Ability/Performance/Startup/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Ability/Performance/Startup/AppScope/resources/base/element/string.json @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "string": [ - { - "name": "app_name", - "value": "startup" - } - ] -} +/* + * Copyright (c) 2023 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. + */ + +{ + "string": [ + { + "name": "app_name", + "value": "startup" + } + ] +} diff --git a/code/DocsSample/Ability/Performance/Startup/README_zh.md b/code/DocsSample/Ability/Performance/Startup/README_zh.md index bb5023963a8f046a446d30fae0d80eb78a7922bc..47518692dd44ec5183f6a3ccc3d0994988e47d55 100644 --- a/code/DocsSample/Ability/Performance/Startup/README_zh.md +++ b/code/DocsSample/Ability/Performance/Startup/README_zh.md @@ -1,230 +1,230 @@ -# 提升应用冷启动速度示例 - -### 介绍 - -本示例展示了[提升应用冷启动速度](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md)的五种方式: - -1. 缩短应用进程创建&初始化阶段耗时; -2. 缩短Application&Ability初始化阶段耗时; -3. 缩短AbilityStage生命周期阶段耗时; -4. 缩短Ability生命周期阶段耗时; -5. 缩短加载绘制首页阶段耗时。 - -### 效果预览 - -| 应用初始页面 | 任务完成界面 | -| ------------------------------- | --------------------------------- | -| ![](screenshots/helloworld.png) | ![](screenshots/taskcomplete.png) | - -使用说明 - -应用在启动后显示文本"hello world";几秒后耗时操作完成,文本变更为"task complete"。 - -### 工程目录 -``` -entry/src/main/ -├── ets -│   ├── common -│   │   └── Logger.ts // 日志工具 -│   ├── entryability -│   │   └── EntryAbility.ts // UIAbility类 -│   ├── myabilitystage -│   │   └── MyAbilityStage.ts // AbilityStage类 -│   └── pages -│   └── Index.ets // 首页 -├── module.json5 -└── resources - ├── base - │   ├── element - │   │   ├── color.json - │   │   └── string.json - │   ├── media - │   │   ├── highResolutionIcon.png // 高分辨率图标 - │   │   ├── icon.png - │   │   └── startIcon.png - │   └── profile - │   └── main_pages.json - ├── en_US - │   └── element - │   └── string.json - └── zh_CN - └── element - └── string.json - -``` -### 具体实现 - -#### 1. 缩短应用进程创建&初始化阶段耗时 - -通过设置合适分辨率的startWindowIcon,缩短应用进程创建&初始化阶段耗时,进而提升应用冷启动速度。 - -entry/src/main/module.json5 - -```json -{ - "module": { - "name": "entry", - "type": "entry", - "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", // 优化前为"$media:highResolutionIcon" - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } -} -``` - -详情可参见:[设置合适分辨率的startWindowIcon](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#设置合适分辨率的startwindowicon) - -#### 2. 缩短Application&Ability初始化阶段耗时 - -通过减少import的模块,可以缩短Application&Ability初始化阶段耗时,进而提升应用冷启动速度。 - -entry/src/main/ets/entryability/EntryAbility.ts - -```ts -// 优化减少import的模块 -// import ability from '@ohos.ability.ability'; -// import dataUriUtils from '@ohos.ability.dataUriUtils'; -// import errorCode from '@ohos.ability.errorCode'; -// import featureAbility from '@ohos.ability.featureAbility'; -// import particleAbility from '@ohos.ability.particleAbility'; -// import wantConstant from '@ohos.ability.wantConstant'; -// import common from '@ohos.app.ability.common'; -// import Configuration from '@ohos.app.ability.Configuration'; -// import contextConstant from '@ohos.app.ability.contextConstant'; -// import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; -// import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; -// import GesturePath from '@ohos.accessibility.GesturePath'; -// import GesturePoint from '@ohos.accessibility.GesturePoint'; -// import distributedAccount from '@ohos.account.distributedAccount'; -// import osAccount from '@ohos.account.osAccount'; - -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import logger from '../common/Logger'; -``` - -详情可参见:[减少import的模块](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#减少import的模块) - -#### 3. 缩短AbilityStage生命周期阶段耗时 - -通过将AbilityStage生命周期回调接口中的耗时操作改为异步延迟执行,可以缩短AbilityStage生命周期阶段耗时,进而提升应用冷启动速度。 - -entry/src/main/ets/myabilitystage/MyAbilityStage.ts - -```ts -export default class MyAbilityStage extends AbilityStage { - onCreate(): void { - // 应用的HAP在首次加载的时,为该Module初始化操作 - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - } - // ... -} -``` - -详情可参见:[避免在AbilityStage生命周期回调接口进行耗时操作](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#避免在abilitystage生命周期回调接口进行耗时操作) - -#### 4. 缩短Ability生命周期阶段耗时 - -通过将Ability生命周期回调接口中的耗时操作改为异步延迟执行,可以缩短Ability生命周期阶段耗时,进而提升应用冷启动速度。 - -通常与应用冷启动速度相关的生命周期回调为onCreate、onWindowStageCreate和onForeground,以下以onCreate为例进行说明。 - -entry/src/main/ets/entryability/EntryAbility.ts - -```ts -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - logger.info('Ability onCreate'); - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - } - // ... -} -``` - -详情可参见:[避免在Ability生命周期回调接口进行耗时操作](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#避免在ability生命周期回调接口进行耗时操作) - -#### 5. 缩短加载绘制首页阶段耗时 - -通过将自定义组件的生命周期回调接口中的耗时操作改为异步延迟执行,可以缩短加载绘制首页阶段耗时,进而提升应用冷启动速度。 - -entry/src/main/ets/pages/Index.ets - -```ts -@Entry -@Component -struct Index { - // ... - aboutToAppear() { - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - let context = getContext(this) as Context; - this.text = context.resourceManager.getStringSync($r('app.string.startup_text')); - } - // ... -} -``` - -详情可参见:[自定义组件生命周期回调接口里避免耗时操作](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#自定义组件生命周期回调接口里避免耗时操作) - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例已适配API version 10版本SDK,版本号:4.0.10.13。 - -3.本示例需要使用DevEco Studio 4.0 (Build Version: 4.0.0.600 构建 2023年10月17日)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/DocsSample/Ability/Performance/Startup/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 提升应用冷启动速度示例 + +### 介绍 + +本示例展示了[提升应用冷启动速度](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md)的五种方式: + +1. 缩短应用进程创建&初始化阶段耗时; +2. 缩短Application&Ability初始化阶段耗时; +3. 缩短AbilityStage生命周期阶段耗时; +4. 缩短Ability生命周期阶段耗时; +5. 缩短加载绘制首页阶段耗时。 + +### 效果预览 + +| 应用初始页面 | 任务完成界面 | +| ------------------------------- | --------------------------------- | +| ![](screenshots/helloworld.png) | ![](screenshots/taskcomplete.png) | + +使用说明 + +应用在启动后显示文本"hello world";几秒后耗时操作完成,文本变更为"task complete"。 + +### 工程目录 +``` +entry/src/main/ +├── ets +│   ├── common +│   │   └── Logger.ts // 日志工具 +│   ├── entryability +│   │   └── EntryAbility.ts // UIAbility类 +│   ├── myabilitystage +│   │   └── MyAbilityStage.ts // AbilityStage类 +│   └── pages +│   └── Index.ets // 首页 +├── module.json5 +└── resources + ├── base + │   ├── element + │   │   ├── color.json + │   │   └── string.json + │   ├── media + │   │   ├── highResolutionIcon.png // 高分辨率图标 + │   │   ├── icon.png + │   │   └── startIcon.png + │   └── profile + │   └── main_pages.json + ├── en_US + │   └── element + │   └── string.json + └── zh_CN + └── element + └── string.json + +``` +### 具体实现 + +#### 1. 缩短应用进程创建&初始化阶段耗时 + +通过设置合适分辨率的startWindowIcon,缩短应用进程创建&初始化阶段耗时,进而提升应用冷启动速度。 + +entry/src/main/module.json5 + +```json +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", // 优化前为"$media:highResolutionIcon" + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} +``` + +详情可参见:[设置合适分辨率的startWindowIcon](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#设置合适分辨率的startwindowicon) + +#### 2. 缩短Application&Ability初始化阶段耗时 + +通过减少import的模块,可以缩短Application&Ability初始化阶段耗时,进而提升应用冷启动速度。 + +entry/src/main/ets/entryability/EntryAbility.ts + +```ts +// 优化减少import的模块 +// import ability from '@ohos.ability.ability'; +// import dataUriUtils from '@ohos.ability.dataUriUtils'; +// import errorCode from '@ohos.ability.errorCode'; +// import featureAbility from '@ohos.ability.featureAbility'; +// import particleAbility from '@ohos.ability.particleAbility'; +// import wantConstant from '@ohos.ability.wantConstant'; +// import common from '@ohos.app.ability.common'; +// import Configuration from '@ohos.app.ability.Configuration'; +// import contextConstant from '@ohos.app.ability.contextConstant'; +// import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; +// import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; +// import GesturePath from '@ohos.accessibility.GesturePath'; +// import GesturePoint from '@ohos.accessibility.GesturePoint'; +// import distributedAccount from '@ohos.account.distributedAccount'; +// import osAccount from '@ohos.account.osAccount'; + +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import logger from '../common/Logger'; +``` + +详情可参见:[减少import的模块](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#减少import的模块) + +#### 3. 缩短AbilityStage生命周期阶段耗时 + +通过将AbilityStage生命周期回调接口中的耗时操作改为异步延迟执行,可以缩短AbilityStage生命周期阶段耗时,进而提升应用冷启动速度。 + +entry/src/main/ets/myabilitystage/MyAbilityStage.ts + +```ts +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + // 应用的HAP在首次加载的时,为该Module初始化操作 + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + } + // ... +} +``` + +详情可参见:[避免在AbilityStage生命周期回调接口进行耗时操作](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#避免在abilitystage生命周期回调接口进行耗时操作) + +#### 4. 缩短Ability生命周期阶段耗时 + +通过将Ability生命周期回调接口中的耗时操作改为异步延迟执行,可以缩短Ability生命周期阶段耗时,进而提升应用冷启动速度。 + +通常与应用冷启动速度相关的生命周期回调为onCreate、onWindowStageCreate和onForeground,以下以onCreate为例进行说明。 + +entry/src/main/ets/entryability/EntryAbility.ts + +```ts +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + logger.info('Ability onCreate'); + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + } + // ... +} +``` + +详情可参见:[避免在Ability生命周期回调接口进行耗时操作](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#避免在ability生命周期回调接口进行耗时操作) + +#### 5. 缩短加载绘制首页阶段耗时 + +通过将自定义组件的生命周期回调接口中的耗时操作改为异步延迟执行,可以缩短加载绘制首页阶段耗时,进而提升应用冷启动速度。 + +entry/src/main/ets/pages/Index.ets + +```ts +@Entry +@Component +struct Index { + // ... + aboutToAppear() { + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + let context = getContext(this) as Context; + this.text = context.resourceManager.getStringSync($r('app.string.startup_text')); + } + // ... +} +``` + +详情可参见:[自定义组件生命周期回调接口里避免耗时操作](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/performance/improve-application-cold-start-speed.md/#自定义组件生命周期回调接口里避免耗时操作) + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例已适配API version 10版本SDK,版本号:4.0.10.13。 + +3.本示例需要使用DevEco Studio 4.0 (Build Version: 4.0.0.600 构建 2023年10月17日)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Ability/Performance/Startup/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/build-profile.json5 b/code/DocsSample/Ability/Performance/Startup/build-profile.json5 index f095c27219d8c9ffa6360d8442c7b84c10a59b10..31a7e1deb58d3fabc295cc009421a21a0a260c1b 100644 --- a/code/DocsSample/Ability/Performance/Startup/build-profile.json5 +++ b/code/DocsSample/Ability/Performance/Startup/build-profile.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "targetSdkVersion": 10, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "targetSdkVersion": 10, + "runtimeOS": "OpenHarmony", + } + ], + "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/Ability/Performance/Startup/entry/build-profile.json5 b/code/DocsSample/Ability/Performance/Startup/entry/build-profile.json5 index 2eabd9fec317c1bfc530e2676f009dded401ee5d..8e1d0657b6e6528c2a83891933deafcb3dbb0a99 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/build-profile.json5 +++ b/code/DocsSample/Ability/Performance/Startup/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/entry/oh-package.json5 b/code/DocsSample/Ability/Performance/Startup/entry/oh-package.json5 index 3dbfd8cb9312a5d6e4cd11e4c99838a7a20d1c13..1423587fdb9b90c2b9be33141d102dfc523abfe5 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/oh-package.json5 +++ b/code/DocsSample/Ability/Performance/Startup/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Application launch example.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Application launch example.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/common/Logger.ts b/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/common/Logger.ts index 065783fc2c1734adb699e515a31164af0c3ce10e..b4b85d3857b7fd472abb4f8b3b3606d5fd021fcd 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/common/Logger.ts +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/common/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: any[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: any[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: any[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: any[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: any[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: any[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: any[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: any[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_Startup]'); \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/entryability/EntryAbility.ts index 969b454a9c054db196e5972acd3a857acf77172c..6ca4e1f1d4e4c6ebdbe213f08c9c172dd51ecef2 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,102 +1,102 @@ -/* - * Copyright (c) 2023 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. - */ - -// EntryAbility.ets - -// import ability from '@ohos.ability.ability'; -// import dataUriUtils from '@ohos.ability.dataUriUtils'; -// import errorCode from '@ohos.ability.errorCode'; -// import featureAbility from '@ohos.ability.featureAbility'; -// import particleAbility from '@ohos.ability.particleAbility'; -// import wantConstant from '@ohos.ability.wantConstant'; -// import common from '@ohos.app.ability.common'; -// import Configuration from '@ohos.app.ability.Configuration'; -// import contextConstant from '@ohos.app.ability.contextConstant'; -// import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; -// import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; -// import GesturePath from '@ohos.accessibility.GesturePath'; -// import GesturePoint from '@ohos.accessibility.GesturePoint'; -// import distributedAccount from '@ohos.account.distributedAccount'; -// import osAccount from '@ohos.account.osAccount'; - -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import logger from '../common/Logger'; - -const LARGE_NUMBER = 10000000; -const DELAYED_TIME = 1000; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - logger.info('Ability onCreate'); - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - } - - onDestroy(): void { - logger.info('Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - logger.info('Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - logger.error('Failed to load the content. Cause: ' + JSON.stringify(err) ?? ''); - return; - } - logger.info('Succeeded in loading the content. Data: ' + JSON.stringify(data) ?? ''); - }); - - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - logger.info('Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - logger.info('Ability onForeground'); - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - } - - onBackground(): void { - // Ability has back to background - logger.info('Ability onBackground'); - } - - computeTask(): void { - let count = 0; - while (count < LARGE_NUMBER) { - count++; - } - } - - private computeTaskAsync(): void { - setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 - this.computeTask(); - }, DELAYED_TIME); - } -} +/* + * Copyright (c) 2023 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. + */ + +// EntryAbility.ets + +// import ability from '@ohos.ability.ability'; +// import dataUriUtils from '@ohos.ability.dataUriUtils'; +// import errorCode from '@ohos.ability.errorCode'; +// import featureAbility from '@ohos.ability.featureAbility'; +// import particleAbility from '@ohos.ability.particleAbility'; +// import wantConstant from '@ohos.ability.wantConstant'; +// import common from '@ohos.app.ability.common'; +// import Configuration from '@ohos.app.ability.Configuration'; +// import contextConstant from '@ohos.app.ability.contextConstant'; +// import ConfigurationConstant from '@ohos.app.ability.ConfigurationConstant'; +// import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; +// import GesturePath from '@ohos.accessibility.GesturePath'; +// import GesturePoint from '@ohos.accessibility.GesturePoint'; +// import distributedAccount from '@ohos.account.distributedAccount'; +// import osAccount from '@ohos.account.osAccount'; + +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import logger from '../common/Logger'; + +const LARGE_NUMBER = 10000000; +const DELAYED_TIME = 1000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + logger.info('Ability onCreate'); + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + } + + onDestroy(): void { + logger.info('Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + logger.info('Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + logger.error('Failed to load the content. Cause: ' + JSON.stringify(err) ?? ''); + return; + } + logger.info('Succeeded in loading the content. Data: ' + JSON.stringify(data) ?? ''); + }); + + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + logger.info('Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + logger.info('Ability onForeground'); + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + } + + onBackground(): void { + // Ability has back to background + logger.info('Ability onBackground'); + } + + computeTask(): void { + let count = 0; + while (count < LARGE_NUMBER) { + count++; + } + } + + private computeTaskAsync(): void { + setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 + this.computeTask(); + }, DELAYED_TIME); + } +} diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/myabilitystage/MyAbilityStage.ts b/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/myabilitystage/MyAbilityStage.ts index 90795eb76a4ef6a6c45987cd29419bba04c10a87..9d0813219eb3d4470a787dacfc51e9c8d2694f7d 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/myabilitystage/MyAbilityStage.ts +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/main/ets/myabilitystage/MyAbilityStage.ts @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2023 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 AbilityStage from '@ohos.app.ability.AbilityStage'; -import type Want from '@ohos.app.ability.Want'; - -const LARGE_NUMBER = 10000000; -const DELAYED_TIME = 1000; - -export default class MyAbilityStage extends AbilityStage { - onCreate(): void { - // 应用的HAP在首次加载的时,为该Module初始化操作 - // 耗时操作 - // this.computeTask(); - this.computeTaskAsync(); // 异步任务 - } - - onAcceptWant(want: Want): string { - // 仅specified模式下触发 - return 'MyAbilityStage'; - } - - computeTask(): void { - let count = 0; - while (count < LARGE_NUMBER) { - count++; - } - } - - private computeTaskAsync(): void { - setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 - this.computeTask(); - }, DELAYED_TIME); - } +/* + * Copyright (c) 2023 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 AbilityStage from '@ohos.app.ability.AbilityStage'; +import type Want from '@ohos.app.ability.Want'; + +const LARGE_NUMBER = 10000000; +const DELAYED_TIME = 1000; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + // 应用的HAP在首次加载的时,为该Module初始化操作 + // 耗时操作 + // this.computeTask(); + this.computeTaskAsync(); // 异步任务 + } + + onAcceptWant(want: Want): string { + // 仅specified模式下触发 + return 'MyAbilityStage'; + } + + computeTask(): void { + let count = 0; + while (count < LARGE_NUMBER) { + count++; + } + } + + private computeTaskAsync(): void { + setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 + this.computeTask(); + }, DELAYED_TIME); + } } \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/main/module.json5 b/code/DocsSample/Ability/Performance/Startup/entry/src/main/module.json5 index eada4f9ead2850b8502d265058e8de7ac9d36b2f..219bdf4d5bfd9148d38f99c7346938469a9d473f 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/main/module.json5 +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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", + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/main/resources/base/element/color.json b/code/DocsSample/Ability/Performance/Startup/entry/src/main/resources/base/element/color.json index 47181af10985a6400be6e7ca8c05ee4bd6f7f066..0c30b0d30c60d0498bb861ba863f19bf3d2b75b4 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/main/resources/base/element/color.json @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +/* + * Copyright (c) 2023 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. + */ + +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/ets/util/Logger.ts b/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/ets/util/Logger.ts index be87e331dbe038cc7bf1c34b95bf92e33c43cb34..1b35c2f2b30d9df0d52efa65be6ddd73bef68c3e 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/ets/util/Logger.ts +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/ets/util/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export const logger = new Logger('[Sample_Startup]'); \ No newline at end of file diff --git a/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/module.json5 b/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Ability/Performance/Startup/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/Ability/Performance/Startup/hvigor/hvigor-config.json5 b/code/DocsSample/Ability/Performance/Startup/hvigor/hvigor-config.json5 index f5310200cf9c95270e5d93ad0759f43696f57ef9..efd98bc3758099d5ab17735a50c44253a7142a78 100644 --- a/code/DocsSample/Ability/Performance/Startup/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Ability/Performance/Startup/hvigor/hvigor-config.json5 @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "hvigorVersion": "3.0.9", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.9" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "hvigorVersion": "3.0.9", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.9" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } +} diff --git a/code/DocsSample/Ability/Performance/Startup/oh-package.json5 b/code/DocsSample/Ability/Performance/Startup/oh-package.json5 index 0754c4cd2bdc64f706306009c88ecc02831abd13..f049d0975343e0999cae5af854e029ba1f1c24a5 100644 --- a/code/DocsSample/Ability/Performance/Startup/oh-package.json5 +++ b/code/DocsSample/Ability/Performance/Startup/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.11" - }, - "author": "", - "name": "startup", - "description": "Application launch example.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.11" + }, + "author": "", + "name": "startup", + "description": "Application launch example.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/Ability/Performance/Startup/ohosTest.md b/code/DocsSample/Ability/Performance/Startup/ohosTest.md index e8e4ff4fe94355984557bafc2182c04aa5d9c03c..4b4c6761897108006b820e246ba3bbceb32f26db 100644 --- a/code/DocsSample/Ability/Performance/Startup/ohosTest.md +++ b/code/DocsSample/Ability/Performance/Startup/ohosTest.md @@ -1,8 +1,8 @@ -# 提升应用冷启动速度示例测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------- | ------------ | ---- | ------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | - +# 提升应用冷启动速度示例测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | ---- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | + diff --git a/code/DocsSample/Account/DomainAccount/.gitignore b/code/DocsSample/Account/DomainAccount/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/AppScope/app.json5 b/code/DocsSample/Account/DomainAccount/AppScope/app.json5 old mode 100755 new mode 100644 index 2daf34b8353fcfe05098873b7826fd87711e6c4e..4055b54e63ab301b6a6c48c98e0d5ba269d332a9 --- a/code/DocsSample/Account/DomainAccount/AppScope/app.json5 +++ b/code/DocsSample/Account/DomainAccount/AppScope/app.json5 @@ -1,25 +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.domainaccount", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.domainaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 1cbfc016cbd9684ea1c1bbc44c328dbed4b7e279..da3774353bb1eda7bd7c9347d91900a3ad64f52b --- a/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DomainAccount" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "DomainAccount" + } + ] +} diff --git a/code/DocsSample/Account/DomainAccount/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/DomainAccount/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/README.md b/code/DocsSample/Account/DomainAccount/README.md index df95cacd348ada7fd9e859067237a75cde510f9d..66af6c93d3f28966c1b7c70df777b753f5846a6a 100644 --- a/code/DocsSample/Account/DomainAccount/README.md +++ b/code/DocsSample/Account/DomainAccount/README.md @@ -1,92 +1,92 @@ -# DomainAccount - -### 介绍 - -用户可以在系统中添加域账号,后续可以使用该账号登录、使用系统。 - -当需要验证域账号身份(比如屏幕解锁、登录会话失效等场景)时,可以使用系统提供的接口对域账号进行身份认证。 - -OEM厂商可以采用插件方式定制化域账号管理能力,系统提供了域账号插件注册和注销能能力。 - -实现对以下指南文件中[管理域账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-domain-account.md) [域账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/auth-domain-account.md) [管理域账号插件](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-domain-plugin.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 - -### 效果预览 - -| 首页 | 域账号插件管理页面 | 注册插件及结果 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | ------------------------------------------------------------ | -| | | | -| 注销插件及结果 | 域账号管理页面 | 判断指定域账号是否存在及结果 | -| | | | -| 添加域账号及结果 | 删除域账号及结果 | 查询域账号信息和认证结果 | -| | | | -| 域账号认证页面 | 使用密码认证域账号及结果 | 弹窗验证域账号及结果 | -| | | | - -### 使用说明 - -1. 在主界面,点击ManageDomainAccountsPlugin,进入域账号插件管理页面。 -2. 点击注册插件按钮,进行插件注册。 -3. 进入管理域账号管理页面。 -4. 点击判断指定域账号是否存在。 -5. 点击添加域账号。 -6. 点击删除域账号。 -7. 点击查询域账号信息。 -8. 进入认证域账号界面。 -9. 点击使用密码认证域账号。 -10. 点击使用弹窗验证域账号。 -11. 回到域账号插件管理页面。 -12. 点击注销插件按钮,进行注销插件。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - | | ├──DomainAccount - | | | ├──AuthenticationDomainAccount // 域账号管理示例代码 - | | | ├──ManageDomainAccounts // 域处理示例代码 - | | | └──ManageDomainAccountsPlugin // 域账号插件示例代码 - │ │ ├── Index.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagelocalaccounts) - -[ohos.permission.GET_DOMAIN_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissiongetdomainaccounts) - -[ohos.permission.ACCESS_USER_AUTH_INTERNAL](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccessuserauthinternal) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Account/DomainAccount > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# DomainAccount + +### 介绍 + +用户可以在系统中添加域账号,后续可以使用该账号登录、使用系统。 + +当需要验证域账号身份(比如屏幕解锁、登录会话失效等场景)时,可以使用系统提供的接口对域账号进行身份认证。 + +OEM厂商可以采用插件方式定制化域账号管理能力,系统提供了域账号插件注册和注销能能力。 + +实现对以下指南文件中[管理域账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-domain-account.md) [域账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/auth-domain-account.md) [管理域账号插件](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-domain-plugin.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | 域账号插件管理页面 | 注册插件及结果 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | ------------------------------------------------------------ | +| | | | +| 注销插件及结果 | 域账号管理页面 | 判断指定域账号是否存在及结果 | +| | | | +| 添加域账号及结果 | 删除域账号及结果 | 查询域账号信息和认证结果 | +| | | | +| 域账号认证页面 | 使用密码认证域账号及结果 | 弹窗验证域账号及结果 | +| | | | + +### 使用说明 + +1. 在主界面,点击ManageDomainAccountsPlugin,进入域账号插件管理页面。 +2. 点击注册插件按钮,进行插件注册。 +3. 进入管理域账号管理页面。 +4. 点击判断指定域账号是否存在。 +5. 点击添加域账号。 +6. 点击删除域账号。 +7. 点击查询域账号信息。 +8. 进入认证域账号界面。 +9. 点击使用密码认证域账号。 +10. 点击使用弹窗验证域账号。 +11. 回到域账号插件管理页面。 +12. 点击注销插件按钮,进行注销插件。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + | | ├──DomainAccount + | | | ├──AuthenticationDomainAccount // 域账号管理示例代码 + | | | ├──ManageDomainAccounts // 域处理示例代码 + | | | └──ManageDomainAccountsPlugin // 域账号插件示例代码 + │ │ ├── Index.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagelocalaccounts) + +[ohos.permission.GET_DOMAIN_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissiongetdomainaccounts) + +[ohos.permission.ACCESS_USER_AUTH_INTERNAL](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccessuserauthinternal) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Account/DomainAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/build-profile.json5 b/code/DocsSample/Account/DomainAccount/build-profile.json5 old mode 100755 new mode 100644 index a33a4782e91c9280a45ec05115ebd546882ce072..3777455b48034621ad97fa23e7d60dde63795bd1 --- a/code/DocsSample/Account/DomainAccount/build-profile.json5 +++ b/code/DocsSample/Account/DomainAccount/build-profile.json5 @@ -1,58 +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", - "compatibleSdkVersion": 14, - "compileSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/code-linter.json5 b/code/DocsSample/Account/DomainAccount/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/.gitignore b/code/DocsSample/Account/DomainAccount/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/build-profile.json5 b/code/DocsSample/Account/DomainAccount/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Account/DomainAccount/entry/build-profile.json5 +++ b/code/DocsSample/Account/DomainAccount/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/hvigorfile.ts b/code/DocsSample/Account/DomainAccount/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/obfuscation-rules.txt b/code/DocsSample/Account/DomainAccount/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/oh-package.json5 b/code/DocsSample/Account/DomainAccount/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Account/DomainAccount/entry/oh-package.json5 +++ b/code/DocsSample/Account/DomainAccount/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets old mode 100755 new mode 100644 index 280fd3861e03b70137c4829d8e1e329cde2323da..c60dd43216d71a1c79864e22e151eaf4af314457 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/AuthenticationDomainAccount.ets @@ -1,97 +1,97 @@ -/* - * 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 { osAccount } from '@kit.BasicServicesKit'; -import { router } from '@kit.ArkUI'; - -@Entry -@Component -struct AuthenticationDomainAccount { - @State message: string = 'No Message'; - - private async passwordAuthenticateDomainAccount(): Promise { - let domainAccountInfo: osAccount.DomainAccountInfo = { - domain: 'CHINA', - accountName: 'zhangsan' - }; - let credential: Uint8Array = new Uint8Array([0]); - let callback: osAccount.IUserAuthCallback = { - onResult: (resultCode: number, authResult: osAccount.AuthResult) => { - console.log('auth resultCode = ' + resultCode); - console.log('auth authResult = ' + JSON.stringify(authResult)); - if(resultCode == 0) { - this.message = 'Successfully authenticated domain account using password'; - } else { - this.message = 'Failed to authenticate domain account using password: ' + resultCode; - } - - } - }; - try { - osAccount.DomainAccountManager.auth(domainAccountInfo, credential, callback); - } catch (err) { - console.error('auth exception = ' + JSON.stringify(err)); - } - } - - private async popupAuthenticateDomainAccount(): Promise { - let callback: osAccount.IUserAuthCallback = { - onResult: (resultCode: number, authResult: osAccount.AuthResult) => { - console.log('authWithPopup resultCode = ' + resultCode); - console.log('authWithPopup authResult = ' + JSON.stringify(authResult)); - if(resultCode == 0) { - this.message = 'Successfully authenticated domain account using popup'; - } else if(resultCode == 12300003) { - this.message = 'No domain account is bound'; - } else { - this.message = 'Failed to authenticate domain account using popup: ' + resultCode; - } - } - } - try { - osAccount.DomainAccountManager.authWithPopup(callback) - } catch (err) { - console.error('authWithPopup exception = ' + JSON.stringify(err)); - this.message = 'Exception occurred during popup authentication: ' + JSON.stringify(err); - } - } - - build() { - Column() { - Text(this.message) - .id('show') - .fontSize(36) - .fontWeight(FontWeight.Bold) - Button($r('app.string.Domain1')) - .margin(10) - .id('button1') - .onClick(() => this.passwordAuthenticateDomainAccount()) - Button($r('app.string.Domain2')) - .margin(10) - .id('button2') - .onClick(() => this.popupAuthenticateDomainAccount()) - Button('Go to plugin') - .margin(10) - .id('button3') - .onClick(() => { - router.pushUrl({ - url: 'pages/DomainAccount/ManageDomainAccountsPlugin' - }) - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { osAccount } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct AuthenticationDomainAccount { + @State message: string = 'No Message'; + + private async passwordAuthenticateDomainAccount(): Promise { + let domainAccountInfo: osAccount.DomainAccountInfo = { + domain: 'CHINA', + accountName: 'zhangsan' + }; + let credential: Uint8Array = new Uint8Array([0]); + let callback: osAccount.IUserAuthCallback = { + onResult: (resultCode: number, authResult: osAccount.AuthResult) => { + console.log('auth resultCode = ' + resultCode); + console.log('auth authResult = ' + JSON.stringify(authResult)); + if(resultCode == 0) { + this.message = 'Successfully authenticated domain account using password'; + } else { + this.message = 'Failed to authenticate domain account using password: ' + resultCode; + } + + } + }; + try { + osAccount.DomainAccountManager.auth(domainAccountInfo, credential, callback); + } catch (err) { + console.error('auth exception = ' + JSON.stringify(err)); + } + } + + private async popupAuthenticateDomainAccount(): Promise { + let callback: osAccount.IUserAuthCallback = { + onResult: (resultCode: number, authResult: osAccount.AuthResult) => { + console.log('authWithPopup resultCode = ' + resultCode); + console.log('authWithPopup authResult = ' + JSON.stringify(authResult)); + if(resultCode == 0) { + this.message = 'Successfully authenticated domain account using popup'; + } else if(resultCode == 12300003) { + this.message = 'No domain account is bound'; + } else { + this.message = 'Failed to authenticate domain account using popup: ' + resultCode; + } + } + } + try { + osAccount.DomainAccountManager.authWithPopup(callback) + } catch (err) { + console.error('authWithPopup exception = ' + JSON.stringify(err)); + this.message = 'Exception occurred during popup authentication: ' + JSON.stringify(err); + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Domain1')) + .margin(10) + .id('button1') + .onClick(() => this.passwordAuthenticateDomainAccount()) + Button($r('app.string.Domain2')) + .margin(10) + .id('button2') + .onClick(() => this.popupAuthenticateDomainAccount()) + Button('Go to plugin') + .margin(10) + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/ManageDomainAccountsPlugin' + }) + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets old mode 100755 new mode 100644 index fe45b632df0a8f6d861a31bbd4fccef7ec29539f..49498fa6377266631bd85ea09febd8a288013712 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccounts.ets @@ -1,144 +1,144 @@ -/* - * 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 { osAccount, BusinessError } from '@kit.BasicServicesKit'; -import { router } from '@kit.ArkUI'; - -let osAccountMgr = osAccount.getAccountManager(); - -@Entry -@Component -struct ManageDomainAccounts { - @State message: string = 'Hello World'; - - private async domainAccountExists(): Promise { - let domainAccountInfo: osAccount.DomainAccountInfo = { - accountName: 'testAccountName', - domain: 'testDomain' - } - - let isAccountExisted: boolean = await osAccount.DomainAccountManager.hasAccount(domainAccountInfo); - console.log('domainAccount isAccountExisted:' + isAccountExisted); - if(isAccountExisted) { - this.message = 'Domain account already exists'; - } else { - this.message = 'Domain account does not exist'; - } - } - - private async createDomainAccount(): Promise { - let domainInfo: osAccount.DomainAccountInfo = { - domain: 'testDomain', - accountName: 'testAccountName' - }; - - try { - osAccountMgr.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, - (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ - console.log('createOsAccountForDomain err:' + JSON.stringify(err)); - console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); - this.message = 'Account creation information: ' + JSON.stringify(osAccountInfo.localName); - }); - } catch (e) { - console.error('createOsAccountForDomain exception: ' + JSON.stringify(e)); - this.message = 'Account creation failed: ' + JSON.stringify(e); - } - } - - private async deleteDomainAccount(): Promise { - let domainInfo: osAccount.DomainAccountInfo = { - domain: 'testDomain', - accountName: 'testAccountName' - }; - let localId: number = 0; - try { - localId = await osAccountMgr.getOsAccountLocalIdForDomain(domainInfo); - } catch (err) { - console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); - this.message = 'Failed to get account deletion information: ' + JSON.stringify(err); - } - try { - osAccountMgr.removeOsAccount(localId, (err: BusinessError)=>{ - if (err) { - console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); - this.message = 'Failed to delete account: ' + JSON.stringify(err); - } else { - console.log('removeOsAccount successfully'); - this.message = 'Successfully deleted account'; - } - }); - } catch (err) { - console.error('removeOsAccount exception: ' + JSON.stringify(err)); - } - - } - - private async queryDomainAccount(): Promise { - let options: osAccount.GetDomainAccountInfoOptions = { - domain: 'testDomain', - accountName: 'testAccountName' - } - try { - osAccount.DomainAccountManager.getAccountInfo(options, - (err: BusinessError, result: osAccount.DomainAccountInfo) => { - if (err) { - console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); - this.message = 'Query failed: ' + JSON.stringify(err); - } else { - console.log('getAccountInfo result: ' + result); - this.message = 'Queried account information: ' + JSON.stringify(result.accountName); - } - }); - } catch (err) { - console.error('getAccountInfo exception = ' + JSON.stringify(err)); - this.message = 'Failed to query account information: ' + JSON.stringify(err); - } - } - - build() { - Column() { - Text(this.message) - .id('show') - .fontSize(36) - .fontWeight(FontWeight.Bold) - Button($r('app.string.Domain5')) - .margin(10) - .id('button1') - .onClick(() => this.domainAccountExists()) - Button($r('app.string.Domain6')) - .margin(10) - .id('button2') - .onClick(() => this.createDomainAccount()) - Button($r('app.string.Domain7')) - .margin(10) - .id('button3') - .onClick(() => this.deleteDomainAccount()) - Button($r('app.string.Domain8')) - .margin(10) - .id('button4') - .onClick(() => this.queryDomainAccount()) - Button('Go to AuthenticationDomainAccount') - .margin(10) - .id('button5') - .onClick(() => { - router.pushUrl({ - url: 'pages/DomainAccount/AuthenticationDomainAccount' - }) - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { osAccount, BusinessError } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +let osAccountMgr = osAccount.getAccountManager(); + +@Entry +@Component +struct ManageDomainAccounts { + @State message: string = 'Hello World'; + + private async domainAccountExists(): Promise { + let domainAccountInfo: osAccount.DomainAccountInfo = { + accountName: 'testAccountName', + domain: 'testDomain' + } + + let isAccountExisted: boolean = await osAccount.DomainAccountManager.hasAccount(domainAccountInfo); + console.log('domainAccount isAccountExisted:' + isAccountExisted); + if(isAccountExisted) { + this.message = 'Domain account already exists'; + } else { + this.message = 'Domain account does not exist'; + } + } + + private async createDomainAccount(): Promise { + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + + try { + osAccountMgr.createOsAccountForDomain(osAccount.OsAccountType.NORMAL, domainInfo, + (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ + console.log('createOsAccountForDomain err:' + JSON.stringify(err)); + console.log('createOsAccountForDomain osAccountInfo:' + JSON.stringify(osAccountInfo)); + this.message = 'Account creation information: ' + JSON.stringify(osAccountInfo.localName); + }); + } catch (e) { + console.error('createOsAccountForDomain exception: ' + JSON.stringify(e)); + this.message = 'Account creation failed: ' + JSON.stringify(e); + } + } + + private async deleteDomainAccount(): Promise { + let domainInfo: osAccount.DomainAccountInfo = { + domain: 'testDomain', + accountName: 'testAccountName' + }; + let localId: number = 0; + try { + localId = await osAccountMgr.getOsAccountLocalIdForDomain(domainInfo); + } catch (err) { + console.error('getOsAccountLocalIdForDomain exception: ' + JSON.stringify(err)); + this.message = 'Failed to get account deletion information: ' + JSON.stringify(err); + } + try { + osAccountMgr.removeOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.log('removeOsAccount failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to delete account: ' + JSON.stringify(err); + } else { + console.log('removeOsAccount successfully'); + this.message = 'Successfully deleted account'; + } + }); + } catch (err) { + console.error('removeOsAccount exception: ' + JSON.stringify(err)); + } + + } + + private async queryDomainAccount(): Promise { + let options: osAccount.GetDomainAccountInfoOptions = { + domain: 'testDomain', + accountName: 'testAccountName' + } + try { + osAccount.DomainAccountManager.getAccountInfo(options, + (err: BusinessError, result: osAccount.DomainAccountInfo) => { + if (err) { + console.log('call getAccountInfo failed, error: ' + JSON.stringify(err)); + this.message = 'Query failed: ' + JSON.stringify(err); + } else { + console.log('getAccountInfo result: ' + result); + this.message = 'Queried account information: ' + JSON.stringify(result.accountName); + } + }); + } catch (err) { + console.error('getAccountInfo exception = ' + JSON.stringify(err)); + this.message = 'Failed to query account information: ' + JSON.stringify(err); + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Domain5')) + .margin(10) + .id('button1') + .onClick(() => this.domainAccountExists()) + Button($r('app.string.Domain6')) + .margin(10) + .id('button2') + .onClick(() => this.createDomainAccount()) + Button($r('app.string.Domain7')) + .margin(10) + .id('button3') + .onClick(() => this.deleteDomainAccount()) + Button($r('app.string.Domain8')) + .margin(10) + .id('button4') + .onClick(() => this.queryDomainAccount()) + Button('Go to AuthenticationDomainAccount') + .margin(10) + .id('button5') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/AuthenticationDomainAccount' + }) + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets index 8aa1d204519d9515993319d27a201e52324979d3..f3115faf759efae809abd6c7c55955975e0125bb 100644 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/DomainAccount/ManageDomainAccountsPlugin.ets @@ -1,191 +1,191 @@ -/* - * 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 { osAccount, AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; -import { router } from '@kit.ArkUI'; - -let plugin: osAccount.DomainPlugin = { - auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, - callback: osAccount.IUserAuthCallback) => { - console.info('plugin auth domain' + domainAccountInfo.domain); - console.info('plugin auth accountName' + domainAccountInfo.accountName); - console.info('plugin auth accountId' + domainAccountInfo.accountId); - - let result: osAccount.AuthResult = { - token: new Uint8Array([0]), - remainTimes: 5, - freezingTime: 0 - }; - callback.onResult(0, result); - }, - authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, - callback: osAccount.IUserAuthCallback) => { - console.info('plugin authWithPopup domain' + domainAccountInfo.domain); - console.info('plugin authWithPopup accountName' + domainAccountInfo.accountName); - console.info('plugin authWithPopup accountId' + domainAccountInfo.accountId); - - let result: osAccount.AuthResult = { - token: new Uint8Array([0]), - remainTimes: 5, - freezingTime: 0 - }; - callback.onResult(0, result); - }, - authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, - token: Uint8Array, callback: osAccount.IUserAuthCallback) => { - console.info('plugin authWithToken domain' + domainAccountInfo.domain); - console.info('plugin authWithToken accountName' + domainAccountInfo.accountName); - console.info('plugin authWithToken accountId' + domainAccountInfo.accountId); - let result: osAccount.AuthResult = { - token: new Uint8Array([0]), - remainTimes: 5, - freezingTime: 0 - }; - callback.onResult(0, result); - }, - getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, - callback: AsyncCallback) => { - console.info('plugin getAccountInfo domain'); - let domainAccountId = Date.now().toString(); - let code: BusinessError = { - code: 0, - name: 'mock_name', - message: 'mock_message' - }; - let domainStr: string = ''; - if (options.domain != undefined) { - domainStr = options.domain - } - let accountInfo: osAccount.DomainAccountInfo = { - domain: domainStr, - accountName: options.accountName, - accountId: domainAccountId, - isAuthenticated: false - }; - callback(code, accountInfo); - }, - getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, - callback: AsyncCallback) => { - - console.info('plugin getAuthStatusInfo domain' + domainAccountInfo.domain); - console.info('plugin getAuthStatusInfo accountName' + domainAccountInfo.accountName); - console.info('plugin getAuthStatusInfo accountId' + domainAccountInfo.accountId); - - let code: BusinessError = { - code: 0, - name: 'mock_name', - message: 'mock_message' - }; - let statusInfo: osAccount.AuthStatusInfo = { - remainTimes: 5, - freezingTime: 0 - }; - callback(code, statusInfo); - }, - bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, - callback: AsyncCallback) => { - console.info('plugin bindAccount domain' + domainAccountInfo.domain); - console.info('plugin bindAccount accountName' + domainAccountInfo.accountName); - console.info('plugin bindAccount accountId' + domainAccountInfo.accountId); - let code: BusinessError = { - code: 0, - name: 'mock_name', - message: 'mock_message' - }; - callback(code); - }, - unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback) => { - console.info('plugin unbindAccount domain' + domainAccountInfo.domain); - console.info('plugin unbindAccount accountName' + domainAccountInfo.accountName); - console.info('plugin unbindAccount accountId' + domainAccountInfo.accountId); - }, - isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, - callback: AsyncCallback) => { - console.info('plugin isAccountTokenValid domain' + domainAccountInfo.domain); - console.info('plugin isAccountTokenValid accountName' + domainAccountInfo.accountName); - console.info('plugin isAccountTokenValid accountId' + domainAccountInfo.accountId); - let code: BusinessError = { - code: 0, - name: 'mock_name', - message: 'mock_message' - }; - callback(code, true); - }, - getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback) => { - console.info('plugin getAccessToken domain') - let code: BusinessError = { - code: 0, - name: 'mock_name', - message: 'mock_message' - }; - let token: Uint8Array = new Uint8Array([0]); - callback(code, token); - } -} - - -@Entry -@Component -struct ManageDomainAccountsPlugin { - @State message: string = 'Manage domain account plugin'; - - private async registrationPlugin(): Promise { - try { - osAccount.DomainAccountManager.registerPlugin(plugin) - console.info('registerPlugin success'); - this.message = 'Successfully registered plugin'; - } catch (err) { - console.error('registerPlugin err: ' + JSON.stringify(err)); - this.message = 'Failed to register plugin: ' + JSON.stringify(err); - } - } - - private async logoutPlugin(): Promise { - try { - osAccount.DomainAccountManager.unregisterPlugin(); - console.log('unregisterPlugin success.'); - this.message = 'unregisterPlugin success'; - } catch(err) { - console.error('unregisterPlugin err:' + JSON.stringify(err)); - this.message = 'Failed to unregister plugin: ' + JSON.stringify(err); - } - } - - build() { - Column() { - Text(this.message) - .id('show') - .fontSize(36) - .fontWeight(FontWeight.Bold) - Button($r('app.string.Domain3')) - .margin(10) - .id('button1') - .onClick(() => this.registrationPlugin()) - Button($r('app.string.Domain4')) - .margin(10) - .id('button2') - .onClick(() => this.logoutPlugin()) - Button('Return back') - .id('button3') - .onClick(() => { - router.pushUrl({ - url: 'pages/DomainAccount/ManageDomainAccounts' - }) - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { osAccount, AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +let plugin: osAccount.DomainPlugin = { + auth: (domainAccountInfo: osAccount.DomainAccountInfo, credential: Uint8Array, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin auth domain' + domainAccountInfo.domain); + console.info('plugin auth accountName' + domainAccountInfo.accountName); + console.info('plugin auth accountId' + domainAccountInfo.accountId); + + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + authWithPopup: (domainAccountInfo: osAccount.DomainAccountInfo, + callback: osAccount.IUserAuthCallback) => { + console.info('plugin authWithPopup domain' + domainAccountInfo.domain); + console.info('plugin authWithPopup accountName' + domainAccountInfo.accountName); + console.info('plugin authWithPopup accountId' + domainAccountInfo.accountId); + + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + authWithToken: (domainAccountInfo: osAccount.DomainAccountInfo, + token: Uint8Array, callback: osAccount.IUserAuthCallback) => { + console.info('plugin authWithToken domain' + domainAccountInfo.domain); + console.info('plugin authWithToken accountName' + domainAccountInfo.accountName); + console.info('plugin authWithToken accountId' + domainAccountInfo.accountId); + let result: osAccount.AuthResult = { + token: new Uint8Array([0]), + remainTimes: 5, + freezingTime: 0 + }; + callback.onResult(0, result); + }, + getAccountInfo: (options: osAccount.GetDomainAccountInfoPluginOptions, + callback: AsyncCallback) => { + console.info('plugin getAccountInfo domain'); + let domainAccountId = Date.now().toString(); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let domainStr: string = ''; + if (options.domain != undefined) { + domainStr = options.domain + } + let accountInfo: osAccount.DomainAccountInfo = { + domain: domainStr, + accountName: options.accountName, + accountId: domainAccountId, + isAuthenticated: false + }; + callback(code, accountInfo); + }, + getAuthStatusInfo: (domainAccountInfo: osAccount.DomainAccountInfo, + callback: AsyncCallback) => { + + console.info('plugin getAuthStatusInfo domain' + domainAccountInfo.domain); + console.info('plugin getAuthStatusInfo accountName' + domainAccountInfo.accountName); + console.info('plugin getAuthStatusInfo accountId' + domainAccountInfo.accountId); + + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let statusInfo: osAccount.AuthStatusInfo = { + remainTimes: 5, + freezingTime: 0 + }; + callback(code, statusInfo); + }, + bindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, localId: number, + callback: AsyncCallback) => { + console.info('plugin bindAccount domain' + domainAccountInfo.domain); + console.info('plugin bindAccount accountName' + domainAccountInfo.accountName); + console.info('plugin bindAccount accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + callback(code); + }, + unbindAccount: (domainAccountInfo: osAccount.DomainAccountInfo, callback: AsyncCallback) => { + console.info('plugin unbindAccount domain' + domainAccountInfo.domain); + console.info('plugin unbindAccount accountName' + domainAccountInfo.accountName); + console.info('plugin unbindAccount accountId' + domainAccountInfo.accountId); + }, + isAccountTokenValid: (domainAccountInfo: osAccount.DomainAccountInfo, token: Uint8Array, + callback: AsyncCallback) => { + console.info('plugin isAccountTokenValid domain' + domainAccountInfo.domain); + console.info('plugin isAccountTokenValid accountName' + domainAccountInfo.accountName); + console.info('plugin isAccountTokenValid accountId' + domainAccountInfo.accountId); + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + callback(code, true); + }, + getAccessToken: (options: osAccount.GetDomainAccessTokenOptions, callback: AsyncCallback) => { + console.info('plugin getAccessToken domain') + let code: BusinessError = { + code: 0, + name: 'mock_name', + message: 'mock_message' + }; + let token: Uint8Array = new Uint8Array([0]); + callback(code, token); + } +} + + +@Entry +@Component +struct ManageDomainAccountsPlugin { + @State message: string = 'Manage domain account plugin'; + + private async registrationPlugin(): Promise { + try { + osAccount.DomainAccountManager.registerPlugin(plugin) + console.info('registerPlugin success'); + this.message = 'Successfully registered plugin'; + } catch (err) { + console.error('registerPlugin err: ' + JSON.stringify(err)); + this.message = 'Failed to register plugin: ' + JSON.stringify(err); + } + } + + private async logoutPlugin(): Promise { + try { + osAccount.DomainAccountManager.unregisterPlugin(); + console.log('unregisterPlugin success.'); + this.message = 'unregisterPlugin success'; + } catch(err) { + console.error('unregisterPlugin err:' + JSON.stringify(err)); + this.message = 'Failed to unregister plugin: ' + JSON.stringify(err); + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Domain3')) + .margin(10) + .id('button1') + .onClick(() => this.registrationPlugin()) + Button($r('app.string.Domain4')) + .margin(10) + .id('button2') + .onClick(() => this.logoutPlugin()) + Button('Return back') + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/DomainAccount/ManageDomainAccounts' + }) + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/Account/DomainAccount/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 b/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 old mode 100755 new mode 100644 index 269eca939a3da98eab53814e2eef0c9f6f53c5bb..ce3f0e85821a4dc336fd017edcfe24d2eb3db174 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/module.json5 @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "requestPermissions": [{ - "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", - }, - { - "name": "ohos.permission.GET_DOMAIN_ACCOUNTS", - }, - { - "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL", - }], - "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" - } - ], - } - ] - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", + }, + { + "name": "ohos.permission.GET_DOMAIN_ACCOUNTS", + }, + { + "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL", + }], + "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/Account/DomainAccount/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Account/DomainAccount/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Account/DomainAccount/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/DomainAccount/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index c8bd24faff0ff0064a57435f74662f1db5865f88..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- a/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Account/DomainAccount/entry/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Account/DomainAccount/entry/src/test/List.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/DomainAccount/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/hvigor/hvigor-config.json5 b/code/DocsSample/Account/DomainAccount/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Account/DomainAccount/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Account/DomainAccount/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Account/DomainAccount/hvigorfile.ts b/code/DocsSample/Account/DomainAccount/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/oh-package.json5 b/code/DocsSample/Account/DomainAccount/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Account/DomainAccount/oh-package.json5 +++ b/code/DocsSample/Account/DomainAccount/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Account/DomainAccount/ohosTest.md b/code/DocsSample/Account/DomainAccount/ohosTest.md old mode 100755 new mode 100644 index 3145d43fc6fb2626a0ecb7730c6cc3b3f6bab8ab..0631be022a69ff140f92cbb98a30aeb4eb4ef348 --- a/code/DocsSample/Account/DomainAccount/ohosTest.md +++ b/code/DocsSample/Account/DomainAccount/ohosTest.md @@ -1,15 +1,15 @@ -# DomainAccount 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------- | ----------------------------------------------- | ----------------------------- | --------------------------------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 注册插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘Register plugin’ | 页面显示“Successfully registered plugin” | 是 | Pass | -| 注销插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘Register plugin’ | 页面显示“unregisterPlugin success“ | 是 | Pass | -| Check if the specified domain account exists | 位于ManageDomainAccounts页面,已注册插件 | 点击‘ Check if the specified domain account exists’ | 页面显示“Domain account already exists“ | 是 | Pass | -| Add domain account | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Add domain account’ | 页面显示“Account creation information: "testAccountName"“ | 是 | Pass | -| Delete domain account | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Delete domain account’ | 页面显示“Successfully deleted account“ | 是 | Pass | -| Query domain account information | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Query domain account information’ | 页面显示“Queried account information: "testAccountName"“ | 是 | Pass | -| Authenticate domain account using password | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘使用密码进行认证’ | 页面显示“Successfully authenticated domain account using password“ | 是 | Pass | +# DomainAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------- | ----------------------------------------------- | ----------------------------- | --------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 注册插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘Register plugin’ | 页面显示“Successfully registered plugin” | 是 | Pass | +| 注销插件 | 位于ManageDomainAccountsPlugin页面 | 点击‘Register plugin’ | 页面显示“unregisterPlugin success“ | 是 | Pass | +| Check if the specified domain account exists | 位于ManageDomainAccounts页面,已注册插件 | 点击‘ Check if the specified domain account exists’ | 页面显示“Domain account already exists“ | 是 | Pass | +| Add domain account | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Add domain account’ | 页面显示“Account creation information: "testAccountName"“ | 是 | Pass | +| Delete domain account | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Delete domain account’ | 页面显示“Successfully deleted account“ | 是 | Pass | +| Query domain account information | 位于ManageDomainAccounts页面,已注册插件 | 点击‘Query domain account information’ | 页面显示“Queried account information: "testAccountName"“ | 是 | Pass | +| Authenticate domain account using password | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘使用密码进行认证’ | 页面显示“Successfully authenticated domain account using password“ | 是 | Pass | | Authenticate domain account using popup | 位于AuthenticationDomainAccount页面,已注册插件 | 点击‘Authenticate domain account using popup’ | 页面显示"No domain account is bound" | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_1.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_10.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_10.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_11.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_11.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_12.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_12.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_2.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_3.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_4.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_4.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_5.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_5.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_6.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_6.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_7.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_7.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_8.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_8.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_9.png b/code/DocsSample/Account/DomainAccount/screenshots/DomainAccount_9.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/.gitignore b/code/DocsSample/Account/ManageDistributedAccount/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/AppScope/app.json5 b/code/DocsSample/Account/ManageDistributedAccount/AppScope/app.json5 old mode 100755 new mode 100644 index d6cb5185f09411c25d82165401b5cc82b134a637..c95d19eb6503146663065560369c424e00886939 --- a/code/DocsSample/Account/ManageDistributedAccount/AppScope/app.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/AppScope/app.json5 @@ -1,25 +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.managedistributedaccount", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managedistributedaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json b/code/DocsSample/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 975d8e8814253333cdc926c9c61809fb63ef2808..9d32d7a58a3f857d71cfb988c01ffb3b1914e134 --- a/code/DocsSample/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Account/ManageDistributedAccount/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManageDistributedAccount" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManageDistributedAccount" + } + ] +} diff --git a/code/DocsSample/Account/ManageDistributedAccount/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/ManageDistributedAccount/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/README.md b/code/DocsSample/Account/ManageDistributedAccount/README.md index 1bfe0aeada5c91243a5d0add4064b0915f8fe738..bdbf9664ff7cb33dcfdcd933d0c6e14ede5a8e9e 100644 --- a/code/DocsSample/Account/ManageDistributedAccount/README.md +++ b/code/DocsSample/Account/ManageDistributedAccount/README.md @@ -1,71 +1,71 @@ -# 管理分布式账号(仅对系统应用开放) - -### 介绍 - -1.OEM厂商可以通过[分布式账号SDK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-distributed-account.md)将自有账号与本地系统账号建立关联关系。 - -2.实现对以下指南文档中 [管理分布式账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-distributed-account.md) 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 - -### 效果预览 - -| 首页 | 执行Log in and bind distributed account on the current system account | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | -| **执行Log out and unbind distributed account on the current system account** | **执行Log in and bind distributed account on the specified system account** | -| | | -| **执行Log out and unbind distributed account on the specified system account** | | -| | | - -### 使用说明 - -1. 在主界面,点击'Log in and bind distributed account on the current system account',执行Log in and bind distributed account on the current system account。 -2. 点击'Log out and unbind distributed account on the current system account',执行Log out and unbind distributed account on the current system account。 -3. 点击'Log in and bind distributed account on the specified system account',执行Log in and bind distributed account on the specified system account。 -4. 点击'Log out and unbind distributed account on the specified system account',执行Log out and unbind distributed account on the specified system account。 -5. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ └── pages - │ │ └── Index.ets // 管理分布式账号示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ └── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -[ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagedistributedaccounts) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Account/ManageDistributedAccount > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 管理分布式账号(仅对系统应用开放) + +### 介绍 + +1.OEM厂商可以通过[分布式账号SDK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-distributed-account.md)将自有账号与本地系统账号建立关联关系。 + +2.实现对以下指南文档中 [管理分布式账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-distributed-account.md) 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | 执行Log in and bind distributed account on the current system account | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| **执行Log out and unbind distributed account on the current system account** | **执行Log in and bind distributed account on the specified system account** | +| | | +| **执行Log out and unbind distributed account on the specified system account** | | +| | | + +### 使用说明 + +1. 在主界面,点击'Log in and bind distributed account on the current system account',执行Log in and bind distributed account on the current system account。 +2. 点击'Log out and unbind distributed account on the current system account',执行Log out and unbind distributed account on the current system account。 +3. 点击'Log in and bind distributed account on the specified system account',执行Log in and bind distributed account on the specified system account。 +4. 点击'Log out and unbind distributed account on the specified system account',执行Log out and unbind distributed account on the specified system account。 +5. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ └── pages + │ │ └── Index.ets // 管理分布式账号示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ └── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagedistributedaccounts) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Account/ManageDistributedAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Account/ManageDistributedAccount/build-profile.json5 b/code/DocsSample/Account/ManageDistributedAccount/build-profile.json5 old mode 100755 new mode 100644 index 3c1dc3a4c625f2ec0629fbb2c33a841fa39111e6..5f84e07910e435c25299194dc4abd35d815ff629 --- a/code/DocsSample/Account/ManageDistributedAccount/build-profile.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 14, - "compileSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/Account/ManageDistributedAccount/code-linter.json5 b/code/DocsSample/Account/ManageDistributedAccount/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/.gitignore b/code/DocsSample/Account/ManageDistributedAccount/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/build-profile.json5 b/code/DocsSample/Account/ManageDistributedAccount/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/build-profile.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/hvigorfile.ts b/code/DocsSample/Account/ManageDistributedAccount/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/obfuscation-rules.txt b/code/DocsSample/Account/ManageDistributedAccount/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/oh-package.json5 b/code/DocsSample/Account/ManageDistributedAccount/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Account/ManageDistributedAccount/entry/oh-package.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Account/ManageDistributedAccount/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/module.json5 b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/module.json5 old mode 100755 new mode 100644 index f16c302eb9b102129bdf2e58d32b7cbafa81a453..a54bd3996ebbf5070ccb992e43508237a1d847e3 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/module.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/module.json5 @@ -1,70 +1,70 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "requestPermissions": [{ - "name": "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS", - }], - "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" - } - ], - } - ] - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS", + }], + "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/Account/ManageDistributedAccount/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/ManageDistributedAccount/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/ManageDistributedAccount/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index c8bd24faff0ff0064a57435f74662f1db5865f88..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- a/code/DocsSample/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/entry/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/test/List.test.ets b/code/DocsSample/Account/ManageDistributedAccount/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/ManageDistributedAccount/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 b/code/DocsSample/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Account/ManageDistributedAccount/hvigorfile.ts b/code/DocsSample/Account/ManageDistributedAccount/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/oh-package.json5 b/code/DocsSample/Account/ManageDistributedAccount/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Account/ManageDistributedAccount/oh-package.json5 +++ b/code/DocsSample/Account/ManageDistributedAccount/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Account/ManageDistributedAccount/ohosTest.md b/code/DocsSample/Account/ManageDistributedAccount/ohosTest.md old mode 100755 new mode 100644 index 6a829ef97b3f8ea0e27a48a09dcfe95d56207b8f..364f669fd15bf085ee67f498bf7b4916c8ec14e0 --- a/code/DocsSample/Account/ManageDistributedAccount/ohosTest.md +++ b/code/DocsSample/Account/ManageDistributedAccount/ohosTest.md @@ -1,11 +1,11 @@ -# ManageDistributedAccount 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------ | ------------ | ------------------------------------------ | -------------------------------------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| Log in and bind distributed account on the current system account | 位于首页 | 点击'Log in and bind distributed account on the current system account' | 页面显示'Bind distributed account: ZhangSan' | 是 | Pass | -| Log out and unbind distributed account on the current system account | 位于首页 | 点击'Log out and unbind distributed account on the current system account' | 页面显示'Successfully unbound distributed account' | 是 | Pass | -| Log in and bind distributed account on the specified system account | 位于首页 | 点击'Log in and bind distributed account on the specified system account' | 页面显示'指定的系统账号上Bind distributed account: ZhangSan' | 是 | Pass | +# ManageDistributedAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------ | ------------ | ------------------------------------------ | -------------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Log in and bind distributed account on the current system account | 位于首页 | 点击'Log in and bind distributed account on the current system account' | 页面显示'Bind distributed account: ZhangSan' | 是 | Pass | +| Log out and unbind distributed account on the current system account | 位于首页 | 点击'Log out and unbind distributed account on the current system account' | 页面显示'Successfully unbound distributed account' | 是 | Pass | +| Log in and bind distributed account on the specified system account | 位于首页 | 点击'Log in and bind distributed account on the specified system account' | 页面显示'指定的系统账号上Bind distributed account: ZhangSan' | 是 | Pass | | Log out and unbind distributed account on the specified system account | 位于首页 | 点击'Log out and unbind distributed account on the specified system account' | 页面显示'指定系统账号上登出Successfully unbound distributed account' | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_1.png b/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_2.png b/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_3.png b/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_4.png b/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_4.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_5.png b/code/DocsSample/Account/ManageDistributedAccount/screenshots/ManageDistributedAccount_5.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/.gitignore b/code/DocsSample/Account/ManageSystemAccountCredentials/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/app.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/app.json5 old mode 100755 new mode 100644 index d3142d219c5e3f970aada650575ba0d522c8f662..67a573f30005c9281a33397b362463e39aeb9519 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/app.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/app.json5 @@ -1,25 +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.managesystemaccountcredentials", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managesystemaccountcredentials", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index ed0031b2726f87930b679a0c78da46f749d2e031..249189f1407c54943f0b7ba0a94be9e83b9784da --- a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManageSystemAccountCredentials" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManageSystemAccountCredentials" + } + ] +} diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/ManageSystemAccountCredentials/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/README.md b/code/DocsSample/Account/ManageSystemAccountCredentials/README.md index cda2b5fac4212b5db22e682bf11626b42ca64da2..d136ff0b615ee454713cda89b77a821482d2e50b 100644 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/README.md +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/README.md @@ -1,80 +1,80 @@ -# 管理系统账号凭据 - -### 介绍 - -凭据可用于认证用户的身份,本文档将介绍如何录入、认证、更新、查询和删除指定系统账号的凭据。 - -该工程中展示的代码详细描述可查如下链接: - -- [ 管理系统账号凭据](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-os-account-credential.md) - -### 效果预览 - -| 首页 | 执行录入PIN码 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | -| 执行认证PIN码 | 执行更新凭据 | -| | | -| 执行查询凭据信息 | 执行删除凭据 | -| | | - -### 使用说明 - -1. 在主界面,点击'Enter PIN code',执行录入PIN码。 -2. 点击'Authenticate PIN code',执行认证PIN码。 -3. 点击'Update credentials',执行更新凭据。 -4. 点击'Query credential information',执行查询凭据信息。 -5. 点击'Delete credentials',执行删除凭据。 -6. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 管理系统账号凭据示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -[ohos.permission.MANAGE_USER_IDM](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanageuseridm) - -[ohos.permission.ACCESS_PIN_AUTH](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccesspinauth) - -[ohos.permission.ACCESS_USER_AUTH_INTERNAL](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccessuserauthinternal) - -[ohos.permission.USE_USER_IDM](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionuseuseridm) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Account/ManageSystemAccountCredentials > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 管理系统账号凭据 + +### 介绍 + +凭据可用于认证用户的身份,本文档将介绍如何录入、认证、更新、查询和删除指定系统账号的凭据。 + +该工程中展示的代码详细描述可查如下链接: + +- [ 管理系统账号凭据](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-os-account-credential.md) + +### 效果预览 + +| 首页 | 执行录入PIN码 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| 执行认证PIN码 | 执行更新凭据 | +| | | +| 执行查询凭据信息 | 执行删除凭据 | +| | | + +### 使用说明 + +1. 在主界面,点击'Enter PIN code',执行录入PIN码。 +2. 点击'Authenticate PIN code',执行认证PIN码。 +3. 点击'Update credentials',执行更新凭据。 +4. 点击'Query credential information',执行查询凭据信息。 +5. 点击'Delete credentials',执行删除凭据。 +6. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 管理系统账号凭据示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_USER_IDM](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanageuseridm) + +[ohos.permission.ACCESS_PIN_AUTH](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccesspinauth) + +[ohos.permission.ACCESS_USER_AUTH_INTERNAL](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccessuserauthinternal) + +[ohos.permission.USE_USER_IDM](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionuseuseridm) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Account/ManageSystemAccountCredentials > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/build-profile.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/build-profile.json5 old mode 100755 new mode 100644 index a33a4782e91c9280a45ec05115ebd546882ce072..3777455b48034621ad97fa23e7d60dde63795bd1 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/build-profile.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/build-profile.json5 @@ -1,58 +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", - "compatibleSdkVersion": 14, - "compileSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/code-linter.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/.gitignore b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/build-profile.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/build-profile.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/obfuscation-rules.txt b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/oh-package.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/oh-package.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 index 347fa0676cef852b0f57f55390103e74977efb5e..8cd8b933e3f3cb6ea2d019c4b46cd0617c22a55f 100644 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/module.json5 @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "requestPermissions": [{ - "name": "ohos.permission.MANAGE_USER_IDM", - }, - { - "name": "ohos.permission.ACCESS_PIN_AUTH", - }, - { - "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL", - }, - { - "name": "ohos.permission.USE_USER_IDM", - } - ], - "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" - } - ] - } - ] - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_USER_IDM", + }, + { + "name": "ohos.permission.ACCESS_PIN_AUTH", + }, + { + "name": "ohos.permission.ACCESS_USER_AUTH_INTERNAL", + }, + { + "name": "ohos.permission.USE_USER_IDM", + } + ], + "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/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index c8bd24faff0ff0064a57435f74662f1db5865f88..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/List.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/ManageSystemAccountCredentials/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Account/ManageSystemAccountCredentials/hvigorfile.ts b/code/DocsSample/Account/ManageSystemAccountCredentials/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/oh-package.json5 b/code/DocsSample/Account/ManageSystemAccountCredentials/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Account/ManageSystemAccountCredentials/oh-package.json5 +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Account/ManageSystemAccountCredentials/ohosTest.md b/code/DocsSample/Account/ManageSystemAccountCredentials/ohosTest.md old mode 100755 new mode 100644 index 8cb7ede0ab2aab3c52f317f4d3ed9e0efb8f0565..2268c1c90558dd8a0b4a58c161f5e0747c9c3d4c --- a/code/DocsSample/Account/ManageSystemAccountCredentials/ohosTest.md +++ b/code/DocsSample/Account/ManageSystemAccountCredentials/ohosTest.md @@ -1,12 +1,12 @@ -# ManageSystemAccountCredentials 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------ | ------------ | ------------------ | --------------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| Enter PIN code | 位于首页 | 点击'Enter PIN code' | 页面显示“PIN code entry successful” | 是 | Pass | -| Authenticate PIN code | 位于首页 | 点击'Authenticate PIN code' | 页面显示“PIN code entry successful” | 是 | Pass | -| Update credentials | 位于首页 | 点击'Update credentials' | 页面显示“Successfully updated PIN code credentials” | 是 | Pass | -| Query credential information | 位于首页 | 点击'Query credential information' | 页面显示“Query information length:1” | 是 | Pass | +# ManageSystemAccountCredentials 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------------ | --------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Enter PIN code | 位于首页 | 点击'Enter PIN code' | 页面显示“PIN code entry successful” | 是 | Pass | +| Authenticate PIN code | 位于首页 | 点击'Authenticate PIN code' | 页面显示“PIN code entry successful” | 是 | Pass | +| Update credentials | 位于首页 | 点击'Update credentials' | 页面显示“Successfully updated PIN code credentials” | 是 | Pass | +| Query credential information | 位于首页 | 点击'Query credential information' | 页面显示“Query information length:1” | 是 | Pass | | Delete credentials | 位于首页 | 点击'Delete credentials' | 页面显示“Successfully deleted PIN code credentials” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_4.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_5.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_6.png b/code/DocsSample/Account/ManageSystemAccountCredentials/screenshots/AccountCredentials_6.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/.gitignore b/code/DocsSample/Account/ManagerApplicationAccount/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/AppScope/app.json5 b/code/DocsSample/Account/ManagerApplicationAccount/AppScope/app.json5 old mode 100755 new mode 100644 index 04e9307b8b3c5ebfe8acc7a1f561f5089198695c..aeff47f52adeccb1ff3512d5603808211a189be0 --- a/code/DocsSample/Account/ManagerApplicationAccount/AppScope/app.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/AppScope/app.json5 @@ -1,25 +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.managerapplicationaccount", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managerapplicationaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json b/code/DocsSample/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 4e396ec1fbd7340b3154078890610ee490dff4da..f6d7ea24284e3dcce83c0dbe00eb3c0a991889ae --- a/code/DocsSample/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Account/ManagerApplicationAccount/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManagerApplicationAccount" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManagerApplicationAccount" + } + ] +} diff --git a/code/DocsSample/Account/ManagerApplicationAccount/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/ManagerApplicationAccount/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/README.md b/code/DocsSample/Account/ManagerApplicationAccount/README.md old mode 100755 new mode 100644 index 0f4ea32c21f94d3230b7b77426f87a21ed31ad60..c496eeb3d6c0c84d50afcc1fd6efbd6ff548a0e0 --- a/code/DocsSample/Account/ManagerApplicationAccount/README.md +++ b/code/DocsSample/Account/ManagerApplicationAccount/README.md @@ -1,77 +1,77 @@ -# 管理应用账号 - -### 介绍 - -1.应用开发者可以使用[应用账号SDK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-appAccount.md)管理本应用的账号数据。 - -能力限制:应用卸载场景下,被卸载应用的账号数据会被删除;本地账号删除场景下,被删除本地账号下的所有应用的账号数据会被删除。 - -2.实现对以下指南文件中 [管理应用账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-application-account.md#/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-appAccount.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 - -### 效果预览 - -| 首页 | **执行创建应用账号** | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | -| **执行查询应用账号** | **执行存取账号的凭据** | -| | | -| **执行存取账号的自定义数据** | **执行存取账号的授权令牌** | -| | | -| **执行删除应用账号** | | -| | | - -### 使用说明 - -1. 在主界面,可以点击’Create application account‘,创建应用账号。 -2. 点击’Query application account‘,查询应用账号。 -3. 点击’Access account credentials‘,存取账号的凭据。 -4. 点击’Access custom data of the account‘,存取账号的自定义数据。 -5. 点击’Access account authorization token‘,存取账号的授权令牌。 -6. 点击’Delete application account‘,删除应用账号。 -7. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ └── pages - │ │ └── Index.ets // 管理应用账号示例代码 - │ ├── module.json5 - │ └── resources - └── ohosTest - └── ets - └── test - └── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Account/ApplicationAccount > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 管理应用账号 + +### 介绍 + +1.应用开发者可以使用[应用账号SDK](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-appAccount.md)管理本应用的账号数据。 + +能力限制:应用卸载场景下,被卸载应用的账号数据会被删除;本地账号删除场景下,被删除本地账号下的所有应用的账号数据会被删除。 + +2.实现对以下指南文件中 [管理应用账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-application-account.md#/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-appAccount.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | **执行创建应用账号** | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| **执行查询应用账号** | **执行存取账号的凭据** | +| | | +| **执行存取账号的自定义数据** | **执行存取账号的授权令牌** | +| | | +| **执行删除应用账号** | | +| | | + +### 使用说明 + +1. 在主界面,可以点击’Create application account‘,创建应用账号。 +2. 点击’Query application account‘,查询应用账号。 +3. 点击’Access account credentials‘,存取账号的凭据。 +4. 点击’Access custom data of the account‘,存取账号的自定义数据。 +5. 点击’Access account authorization token‘,存取账号的授权令牌。 +6. 点击’Delete application account‘,删除应用账号。 +7. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ └── pages + │ │ └── Index.ets // 管理应用账号示例代码 + │ ├── module.json5 + │ └── resources + └── ohosTest + └── ets + └── test + └── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Account/ApplicationAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/build-profile.json5 b/code/DocsSample/Account/ManagerApplicationAccount/build-profile.json5 old mode 100755 new mode 100644 index a33a4782e91c9280a45ec05115ebd546882ce072..3777455b48034621ad97fa23e7d60dde63795bd1 --- a/code/DocsSample/Account/ManagerApplicationAccount/build-profile.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/build-profile.json5 @@ -1,58 +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", - "compatibleSdkVersion": 14, - "compileSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/code-linter.json5 b/code/DocsSample/Account/ManagerApplicationAccount/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/.gitignore b/code/DocsSample/Account/ManagerApplicationAccount/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/build-profile.json5 b/code/DocsSample/Account/ManagerApplicationAccount/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/build-profile.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/hvigorfile.ts b/code/DocsSample/Account/ManagerApplicationAccount/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/obfuscation-rules.txt b/code/DocsSample/Account/ManagerApplicationAccount/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/oh-package.json5 b/code/DocsSample/Account/ManagerApplicationAccount/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/oh-package.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Account/ManagerApplicationAccount/entry/src/main/module.json5 b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/module.json5 old mode 100755 new mode 100644 index dece7db447b686c5afc03a0ed853c0cf4c87c3a2..9bed6e6fd262f8e7273a9ff5dfdf67d826492b07 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/module.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/module.json5 @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:layered_image", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EntryBackupAbility", - "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ], - } - ] - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "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/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index c8bd24faff0ff0064a57435f74662f1db5865f88..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/test/List.test.ets b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/ManagerApplicationAccount/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 b/code/DocsSample/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Account/ManagerApplicationAccount/hvigorfile.ts b/code/DocsSample/Account/ManagerApplicationAccount/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/oh-package.json5 b/code/DocsSample/Account/ManagerApplicationAccount/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Account/ManagerApplicationAccount/oh-package.json5 +++ b/code/DocsSample/Account/ManagerApplicationAccount/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Account/ManagerApplicationAccount/ohosTest.md b/code/DocsSample/Account/ManagerApplicationAccount/ohosTest.md old mode 100755 new mode 100644 index d2d8495a3d0575addd5d4e8bb2501c9259ae7b58..cad8a8315a9af47212c7353e59eb6c21690d0c08 --- a/code/DocsSample/Account/ManagerApplicationAccount/ohosTest.md +++ b/code/DocsSample/Account/ManagerApplicationAccount/ohosTest.md @@ -1,13 +1,13 @@ -# AsyncConcurrencyOverview 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------- | ------------ | -------------------------- | --------------------------------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| Create application account | 位于首页 | 点击'Create application account' | 页面显示'Account creation successful' | 是 | Pass | -| Query application account | 位于首页 | 点击'Query application account' | 页面显示'Query account result: ZhangSan' | 是 | Pass | -| Access account credentials | 位于首页 | 点击'Access account credentials' | 页面显示'Successfully set account credentials: xxxxxx' | 是 | Pass | -| Access custom data of the account | 位于首页 | 点击'Access custom data of the account’ | 页面显示'Successfully set custom account credentials, age is 12‘ | 是 | Pass | -| Access account authorization token | 位于首页 | 点击'Access account authorization token’ | 页面显示'Successfully stored account authorization token: xxxxxx‘ | 是 | Pass | +# AsyncConcurrencyOverview 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------- | ------------ | -------------------------- | --------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Create application account | 位于首页 | 点击'Create application account' | 页面显示'Account creation successful' | 是 | Pass | +| Query application account | 位于首页 | 点击'Query application account' | 页面显示'Query account result: ZhangSan' | 是 | Pass | +| Access account credentials | 位于首页 | 点击'Access account credentials' | 页面显示'Successfully set account credentials: xxxxxx' | 是 | Pass | +| Access custom data of the account | 位于首页 | 点击'Access custom data of the account’ | 页面显示'Successfully set custom account credentials, age is 12‘ | 是 | Pass | +| Access account authorization token | 位于首页 | 点击'Access account authorization token’ | 页面显示'Successfully stored account authorization token: xxxxxx‘ | 是 | Pass | | Delete application account | 位于首页 | 点击'Delete application account’ | 页面显示'removeAccount successfully‘ | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_1.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_2.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_3.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_4.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_4.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_5.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_5.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_6.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_6.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_7.png b/code/DocsSample/Account/ManagerApplicationAccount/screenshots/ManagerApplicationAccount_7.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/.gitignore b/code/DocsSample/Account/SystemAccount/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/AppScope/app.json5 b/code/DocsSample/Account/SystemAccount/AppScope/app.json5 old mode 100755 new mode 100644 index c35b144d7b6477671dc306481203795a0ea03c59..ffb36aacd699e82211fc965fc66e1a4dd6e42120 --- a/code/DocsSample/Account/SystemAccount/AppScope/app.json5 +++ b/code/DocsSample/Account/SystemAccount/AppScope/app.json5 @@ -1,25 +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.systemaccount", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.systemaccount", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Account/SystemAccount/AppScope/resources/base/element/string.json b/code/DocsSample/Account/SystemAccount/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index baaa541dcbd4e47043e2a5670f557375fd3790ba..4b7f6c149123aef13cf93622c8c390011b23c951 --- a/code/DocsSample/Account/SystemAccount/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Account/SystemAccount/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SystemAccount" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SystemAccount" + } + ] +} diff --git a/code/DocsSample/Account/SystemAccount/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Account/SystemAccount/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/README.md b/code/DocsSample/Account/SystemAccount/README.md index c9fdd597ca8182c2e8b7707ace14f5154d8809ec..0de44739d87814bd49dc61b34642ffa5ff0f1da3 100644 --- a/code/DocsSample/Account/SystemAccount/README.md +++ b/code/DocsSample/Account/SystemAccount/README.md @@ -1,95 +1,95 @@ -# 系统账号 (管理系统账号和使用约束管控系统账号) - -### 介绍 - -1.管理系统账号: - -系统提供了用于管理系统账号的接口。 系统应用开发者在申请对应的权限后,可以创建、激活、修改和删除系统账号,实现对系统账号的生命周期管理;三方应用开发者可以查询系统账号的基本信息,以完成与系统账号相关的业务逻辑开发。 - -2.使用约束管控系统账号: - -账号管理模块提供了基于角色的访问控制机制,用户可以为系统账号设置约束,以限制目标账号的行为。 - -预定义的账号约束条件,可以参考 :[系统账号约束列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-osAccount.md#系统账号约束列表) - -3.实现对以下指南文件中 [管理系统账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-os-account.md) [使用约束管控系统账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/control-os-account-by-constraints.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 - -### 效果预览 - -| 首页 | 使用约束管控系统账号页面 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | -| 执行Set the constraint list for the specified system account | 执行Determine if the specified constraint for the target system account is enabled | -| | | -| 管理系统账号首页 | 执行Create system account | -| | | -| 执行Query all system accounts | 执行Query specified system account information | -| | | -| 执行Modify system account avatar | 执行Modify system account nickname | -| | | -| 执行Delete system account | | -| | | - -### 使用说明 - -1. 在主界面,点击’UseConstraintManagementSystemAccount‘,进入约束管控系统账号页面。 -2. 点击’Set the constraint list for the specified system account‘,Set the constraint list for the specified system account。 -3. 点击’Determine if the specified constraint for the target system account is enabled‘,Determine if the specified constraint for the target system account is enabled。 -4. 点击’Go to ManageSystem‘,进入管理系统账号首页。 -5. 点击’Create system account‘,Create system account。 -6. 点击’Query all system accounts‘,Query all system accounts。 -7. 点击’Query specified system account information‘,Query specified system account information。 -8. 点击’Modify system account avatar‘,Modify system account avatar。 -9. 点击’Modify system account nickname‘,Modify system account nickname。 -10. 点击’Delete system account‘,Delete system account。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ └── pages - | | ├──SystemAccount - | | | ├── ManageSystemAccounts // 管理系统账号示例代码 - | | | └── UseConstraintManagementSystemAccount // 使用约束管控系统账号示例代码 - │ │ └── Index.ets // 系统账号首页 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ └── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagelocalaccounts) - -[ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissioninteractacrosslocalaccountsextension) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Account/SystemAccount > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 系统账号 (管理系统账号和使用约束管控系统账号) + +### 介绍 + +1.管理系统账号: + +系统提供了用于管理系统账号的接口。 系统应用开发者在申请对应的权限后,可以创建、激活、修改和删除系统账号,实现对系统账号的生命周期管理;三方应用开发者可以查询系统账号的基本信息,以完成与系统账号相关的业务逻辑开发。 + +2.使用约束管控系统账号: + +账号管理模块提供了基于角色的访问控制机制,用户可以为系统账号设置约束,以限制目标账号的行为。 + +预定义的账号约束条件,可以参考 :[系统账号约束列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-osAccount.md#系统账号约束列表) + +3.实现对以下指南文件中 [管理系统账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/manage-os-account.md) [使用约束管控系统账号](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/basic-services/account/control-os-account-by-constraints.md) 示例代码片段的工程化。保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 首页 | 使用约束管控系统账号页面 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | +| 执行Set the constraint list for the specified system account | 执行Determine if the specified constraint for the target system account is enabled | +| | | +| 管理系统账号首页 | 执行Create system account | +| | | +| 执行Query all system accounts | 执行Query specified system account information | +| | | +| 执行Modify system account avatar | 执行Modify system account nickname | +| | | +| 执行Delete system account | | +| | | + +### 使用说明 + +1. 在主界面,点击’UseConstraintManagementSystemAccount‘,进入约束管控系统账号页面。 +2. 点击’Set the constraint list for the specified system account‘,Set the constraint list for the specified system account。 +3. 点击’Determine if the specified constraint for the target system account is enabled‘,Determine if the specified constraint for the target system account is enabled。 +4. 点击’Go to ManageSystem‘,进入管理系统账号首页。 +5. 点击’Create system account‘,Create system account。 +6. 点击’Query all system accounts‘,Query all system accounts。 +7. 点击’Query specified system account information‘,Query specified system account information。 +8. 点击’Modify system account avatar‘,Modify system account avatar。 +9. 点击’Modify system account nickname‘,Modify system account nickname。 +10. 点击’Delete system account‘,Delete system account。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ └── pages + | | ├──SystemAccount + | | | ├── ManageSystemAccounts // 管理系统账号示例代码 + | | | └── UseConstraintManagementSystemAccount // 使用约束管控系统账号示例代码 + │ │ └── Index.ets // 系统账号首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ └── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanagelocalaccounts) + +[ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissioninteractacrosslocalaccountsextension) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Account/SystemAccount > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/build-profile.json5 b/code/DocsSample/Account/SystemAccount/build-profile.json5 old mode 100755 new mode 100644 index a33a4782e91c9280a45ec05115ebd546882ce072..3777455b48034621ad97fa23e7d60dde63795bd1 --- a/code/DocsSample/Account/SystemAccount/build-profile.json5 +++ b/code/DocsSample/Account/SystemAccount/build-profile.json5 @@ -1,58 +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", - "compatibleSdkVersion": 14, - "compileSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/code-linter.json5 b/code/DocsSample/Account/SystemAccount/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/.gitignore b/code/DocsSample/Account/SystemAccount/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/build-profile.json5 b/code/DocsSample/Account/SystemAccount/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Account/SystemAccount/entry/build-profile.json5 +++ b/code/DocsSample/Account/SystemAccount/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/entry/hvigorfile.ts b/code/DocsSample/Account/SystemAccount/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/obfuscation-rules.txt b/code/DocsSample/Account/SystemAccount/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/oh-package.json5 b/code/DocsSample/Account/SystemAccount/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Account/SystemAccount/entry/oh-package.json5 +++ b/code/DocsSample/Account/SystemAccount/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Account/SystemAccount/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets old mode 100755 new mode 100644 index 8a74171a47d1cb37bc6ee0fc6600111ee4f0c0c6..dee69cc5c2409d35a99920daf9b2b4e8dc137e86 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/ManageSystemAccounts.ets @@ -1,166 +1,166 @@ -/* - * 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 { osAccount, BusinessError } from '@kit.BasicServicesKit'; - -let accountManager = osAccount.getAccountManager(); - -@Entry -@Component -struct ManageSystemAccounts { - @State message: string = 'No work done'; - @State createLocalId: number = -1; - - private async createOsAccount(): Promise { - let name: string = 'Bob'; - let type: osAccount.OsAccountType = osAccount.OsAccountType.NORMAL; - - accountManager.createOsAccount(name, type, (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ - console.log('createOsAccount err:' + JSON.stringify(err)); - console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); - if (!err) { - this.message = 'Account creation successful. Account name: ' + JSON.stringify(osAccountInfo.localName); - this.createLocalId = osAccountInfo.localId; - } else { - this.message = 'Failed to create account: ' + JSON.stringify(err); - } - }); - } - - private async findAllOsAccount(): Promise { - accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: osAccount.OsAccountInfo[])=>{ - console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); - console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); - if (!err) { - this.message = 'Query account successful. Account name:' + JSON.stringify(accountArr[0].localName); - } else { - this.message = 'Query account failed: ' + JSON.stringify(err); - } - }); - } - - private async findOsAccount(): Promise { - let localId: number = 100; - accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: osAccount.OsAccountInfo)=>{ - console.log('queryOsAccountById err:' + JSON.stringify(err)); - console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); - if (!err) { - this.message = 'Query account successful. Account name for account 100: ' + JSON.stringify(accountInfo.localName); - } else { - this.message = 'Query account failed: ' + JSON.stringify(err); - } - }); - } - - private async changeOsAccountHead(): Promise { - let localId: number = 100; - localId = this.createLocalId; - let newPhoto: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ - 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ - 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ - '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' - - accountManager.setOsAccountProfilePhoto(localId, newPhoto, (err: BusinessError)=>{ - console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); - if(!err) { - this.message = 'Successfully updated system account avatar' - } else { - this.message = 'Failed to update system account avatar: ' + JSON.stringify(err); - } - }); - } - - private async changeOsAccountName(): Promise { - let localId: number = 100; - localId = this.createLocalId; - let newName: string = 'Tom'; - accountManager.setOsAccountName(localId, newName, (err: BusinessError) => { - if (err) { - console.error('setOsAccountName failed, error: ' + JSON.stringify(err)); - this.message = 'Failed to modify system account name: ' + JSON.stringify(err); - } else { - console.log('setOsAccountName successfully'); - this.message = 'Successfully modified system account name'; - } - }); - } - - private async activateOsAccount(): Promise { - let localId: number = 101; - localId = this.createLocalId; - accountManager.activateOsAccount(localId, (err: BusinessError)=>{ - if (err) { - console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); - this.message = 'Failed to activate system account: ' + err.code; - } else { - console.log('activateOsAccount successfully'); - this.message = 'Successfully activated system account' - } - }); - } - - private async deleteOsAccount(): Promise { - let localId: number = 101; - localId = this.createLocalId; - accountManager.removeOsAccount(localId, (err: BusinessError)=>{ - if (err) { - console.error('removeOsAccount failed, error: ' + JSON.stringify(err)); - this.message = 'Failed to delete system account: ' + JSON.stringify(err); - } else { - console.log('removeOsAccount successfully'); - this.message = 'Successfully deleted system account' - } - }); - } - - build() { - Column() { - Text(this.message) - .id('show') - .fontSize(36) - .fontWeight(FontWeight.Bold) - Button($r('app.string.Manager1')) - .margin(10) - .id('button1') - .onClick(() => this.createOsAccount()) - Button($r('app.string.Manager2')) - .margin(10) - .id('button2') - .onClick(() => this.findAllOsAccount()) - Button($r('app.string.Manager3')) - .margin(10) - .id('button3') - .onClick(() => this.findOsAccount()) - Button($r('app.string.Manager4')) - .margin(10) - .id('button4') - .onClick(() => this.changeOsAccountHead()) - Button($r('app.string.Manager5')) - .margin(10) - .id('button5') - .onClick(() => this.changeOsAccountName()) - Button($r('app.string.Manager6')) - .margin(10) - .id('button6') - .onClick(() => this.activateOsAccount()) - Button($r('app.string.Manager7')) - .margin(10) - .id('button7') - .onClick(() => this.deleteOsAccount()) - } - .height('100%') - .width('100%') - } +/* + * 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 { osAccount, BusinessError } from '@kit.BasicServicesKit'; + +let accountManager = osAccount.getAccountManager(); + +@Entry +@Component +struct ManageSystemAccounts { + @State message: string = 'No work done'; + @State createLocalId: number = -1; + + private async createOsAccount(): Promise { + let name: string = 'Bob'; + let type: osAccount.OsAccountType = osAccount.OsAccountType.NORMAL; + + accountManager.createOsAccount(name, type, (err: BusinessError, osAccountInfo: osAccount.OsAccountInfo)=>{ + console.log('createOsAccount err:' + JSON.stringify(err)); + console.log('createOsAccount osAccountInfo:' + JSON.stringify(osAccountInfo)); + if (!err) { + this.message = 'Account creation successful. Account name: ' + JSON.stringify(osAccountInfo.localName); + this.createLocalId = osAccountInfo.localId; + } else { + this.message = 'Failed to create account: ' + JSON.stringify(err); + } + }); + } + + private async findAllOsAccount(): Promise { + accountManager.queryAllCreatedOsAccounts((err: BusinessError, accountArr: osAccount.OsAccountInfo[])=>{ + console.log('queryAllCreatedOsAccounts err:' + JSON.stringify(err)); + console.log('queryAllCreatedOsAccounts accountArr:' + JSON.stringify(accountArr)); + if (!err) { + this.message = 'Query account successful. Account name:' + JSON.stringify(accountArr[0].localName); + } else { + this.message = 'Query account failed: ' + JSON.stringify(err); + } + }); + } + + private async findOsAccount(): Promise { + let localId: number = 100; + accountManager.queryOsAccountById(localId, (err: BusinessError, accountInfo: osAccount.OsAccountInfo)=>{ + console.log('queryOsAccountById err:' + JSON.stringify(err)); + console.log('queryOsAccountById accountInfo:' + JSON.stringify(accountInfo)); + if (!err) { + this.message = 'Query account successful. Account name for account 100: ' + JSON.stringify(accountInfo.localName); + } else { + this.message = 'Query account failed: ' + JSON.stringify(err); + } + }); + } + + private async changeOsAccountHead(): Promise { + let localId: number = 100; + localId = this.createLocalId; + let newPhoto: string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA'+ + 'Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y'+ + 'q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo'+ + '+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==' + + accountManager.setOsAccountProfilePhoto(localId, newPhoto, (err: BusinessError)=>{ + console.log('setOsAccountProfilePhoto err:' + JSON.stringify(err)); + if(!err) { + this.message = 'Successfully updated system account avatar' + } else { + this.message = 'Failed to update system account avatar: ' + JSON.stringify(err); + } + }); + } + + private async changeOsAccountName(): Promise { + let localId: number = 100; + localId = this.createLocalId; + let newName: string = 'Tom'; + accountManager.setOsAccountName(localId, newName, (err: BusinessError) => { + if (err) { + console.error('setOsAccountName failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to modify system account name: ' + JSON.stringify(err); + } else { + console.log('setOsAccountName successfully'); + this.message = 'Successfully modified system account name'; + } + }); + } + + private async activateOsAccount(): Promise { + let localId: number = 101; + localId = this.createLocalId; + accountManager.activateOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.error(`activateOsAccount failed, code is ${err.code}, message is ${err.message}`); + this.message = 'Failed to activate system account: ' + err.code; + } else { + console.log('activateOsAccount successfully'); + this.message = 'Successfully activated system account' + } + }); + } + + private async deleteOsAccount(): Promise { + let localId: number = 101; + localId = this.createLocalId; + accountManager.removeOsAccount(localId, (err: BusinessError)=>{ + if (err) { + console.error('removeOsAccount failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to delete system account: ' + JSON.stringify(err); + } else { + console.log('removeOsAccount successfully'); + this.message = 'Successfully deleted system account' + } + }); + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Manager1')) + .margin(10) + .id('button1') + .onClick(() => this.createOsAccount()) + Button($r('app.string.Manager2')) + .margin(10) + .id('button2') + .onClick(() => this.findAllOsAccount()) + Button($r('app.string.Manager3')) + .margin(10) + .id('button3') + .onClick(() => this.findOsAccount()) + Button($r('app.string.Manager4')) + .margin(10) + .id('button4') + .onClick(() => this.changeOsAccountHead()) + Button($r('app.string.Manager5')) + .margin(10) + .id('button5') + .onClick(() => this.changeOsAccountName()) + Button($r('app.string.Manager6')) + .margin(10) + .id('button6') + .onClick(() => this.activateOsAccount()) + Button($r('app.string.Manager7')) + .margin(10) + .id('button7') + .onClick(() => this.deleteOsAccount()) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets old mode 100755 new mode 100644 index 3a5acacc09fcd027a548498c66ac124bf390312f..59cf19dcc4b1206c1381c850c26a39ad083d4656 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/pages/SystemAccount/UseConstraintManagementSystemAccount.ets @@ -1,77 +1,77 @@ -/* - * 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 { osAccount } from '@kit.BasicServicesKit'; -import { router } from '@kit.ArkUI'; - -let accountManager = osAccount.getAccountManager(); - -@Entry -@Component -struct UseConstraintManagementSystemAccount { - @State message: string = 'No work done'; - - private async setOsAccountConstraints(): Promise { - let localId: number = 100; - let constraint: string[] = [ 'constraint.wifi.set' ]; - try { - accountManager.setOsAccountConstraints(localId, constraint, true); - console.log('setOsAccountConstraints successfully'); - this.message = 'Successfully set the constraint list for the specified system account'; - } catch (err) { - console.error('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); - this.message = 'Failed to set the constraint list for the specified system account'; - } - } - - private async isOsAccountConstraintEnabled(): Promise { - let localId: number = 100; - let constraint: string = 'constraint.wifi.set'; - let isEnabled: boolean = await accountManager.isOsAccountConstraintEnabled(localId, constraint); - if (isEnabled) { - // your business logic - this.message = 'Set the constraint list for the specified system account'; - } else { - this.message = 'Can not set the constraint list for the specified system account'; - } - } - - build() { - Column() { - Text(this.message) - .id('show') - .fontSize(36) - .fontWeight(FontWeight.Bold) - Button($r('app.string.Use1')) - .margin(10) - .id('button1') - .onClick(() => this.setOsAccountConstraints()) - Button($r('app.string.Use2')) - .margin(10) - .id('button2') - .onClick(() => this.isOsAccountConstraintEnabled()) - Button($r('app.string.Use3')) - .margin(10) - .id('button3') - .onClick(() => { - router.pushUrl({ - url: 'pages/SystemAccount/ManageSystemAccounts' - }) - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { osAccount } from '@kit.BasicServicesKit'; +import { router } from '@kit.ArkUI'; + +let accountManager = osAccount.getAccountManager(); + +@Entry +@Component +struct UseConstraintManagementSystemAccount { + @State message: string = 'No work done'; + + private async setOsAccountConstraints(): Promise { + let localId: number = 100; + let constraint: string[] = [ 'constraint.wifi.set' ]; + try { + accountManager.setOsAccountConstraints(localId, constraint, true); + console.log('setOsAccountConstraints successfully'); + this.message = 'Successfully set the constraint list for the specified system account'; + } catch (err) { + console.error('setOsAccountConstraints failed, error: ' + JSON.stringify(err)); + this.message = 'Failed to set the constraint list for the specified system account'; + } + } + + private async isOsAccountConstraintEnabled(): Promise { + let localId: number = 100; + let constraint: string = 'constraint.wifi.set'; + let isEnabled: boolean = await accountManager.isOsAccountConstraintEnabled(localId, constraint); + if (isEnabled) { + // your business logic + this.message = 'Set the constraint list for the specified system account'; + } else { + this.message = 'Can not set the constraint list for the specified system account'; + } + } + + build() { + Column() { + Text(this.message) + .id('show') + .fontSize(36) + .fontWeight(FontWeight.Bold) + Button($r('app.string.Use1')) + .margin(10) + .id('button1') + .onClick(() => this.setOsAccountConstraints()) + Button($r('app.string.Use2')) + .margin(10) + .id('button2') + .onClick(() => this.isOsAccountConstraintEnabled()) + Button($r('app.string.Use3')) + .margin(10) + .id('button3') + .onClick(() => { + router.pushUrl({ + url: 'pages/SystemAccount/ManageSystemAccounts' + }) + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/Account/SystemAccount/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/module.json5 b/code/DocsSample/Account/SystemAccount/entry/src/main/module.json5 old mode 100755 new mode 100644 index 08ab0350ec9eb491073140ceb3b5d994ef2568bb..909bed2772d5208f1ea5782dfa610fb36ec73e3b --- a/code/DocsSample/Account/SystemAccount/entry/src/main/module.json5 +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/module.json5 @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "requestPermissions": [{ - "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", - }, - { - "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION", - }], - "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" - } - ], - } - ] - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "requestPermissions": [{ + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS", + }, + { + "name": "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION", + }], + "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/Account/SystemAccount/entry/src/main/resources/base/element/color.json b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/element/string.json b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/background.png b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Account/SystemAccount/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Account/SystemAccount/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/entry/src/mock/mock-config.json5 b/code/DocsSample/Account/SystemAccount/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Account/SystemAccount/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/ohosTest/module.json5 b/code/DocsSample/Account/SystemAccount/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index c8bd24faff0ff0064a57435f74662f1db5865f88..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- a/code/DocsSample/Account/SystemAccount/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Account/SystemAccount/entry/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Account/SystemAccount/entry/src/test/List.test.ets b/code/DocsSample/Account/SystemAccount/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Account/SystemAccount/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/hvigor/hvigor-config.json5 b/code/DocsSample/Account/SystemAccount/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Account/SystemAccount/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Account/SystemAccount/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Account/SystemAccount/hvigorfile.ts b/code/DocsSample/Account/SystemAccount/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/oh-package.json5 b/code/DocsSample/Account/SystemAccount/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Account/SystemAccount/oh-package.json5 +++ b/code/DocsSample/Account/SystemAccount/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Account/SystemAccount/ohosTest.md b/code/DocsSample/Account/SystemAccount/ohosTest.md old mode 100755 new mode 100644 index 8d85ddec9590bb6f96f95f53b8305fed0420df88..95675252d0409de4a70ee9c4a27fbabfca69feca --- a/code/DocsSample/Account/SystemAccount/ohosTest.md +++ b/code/DocsSample/Account/SystemAccount/ohosTest.md @@ -1,15 +1,15 @@ -# SystemAccount 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------- | -------------------------------------------- | ---------------------------------------- | -------------------------------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| Set the constraint list for the specified system account | 位于UseConstraintManagementSystemAccount页面 | 点击'Set the constraint list for the specified system account' | 页面显示“Successfully set the constraint list for the specified system account” | 是 | Pass | -| Determine if the specified constraint for the target system account is enabled | 位于UseConstraintManagementSystemAccount页面 | 点击'Determine if the specified constraint for the target system account is enabled' | 页面显示“Set the constraint list for the specified system account” | 是 | Pass | -| Create system account | 位于ManageSystemAccounts页面 | 点击'Create system account' | 页面显示“Account creation successful. Account name:: "Bob"” | 是 | Pass | -| Query all system accounts | 位于ManageSystemAccounts页面 | 点击'Query all system accounts' | 页面显示“Query account successful. Account name:"user"” | 是 | Pass | -| Query specified system account information | 位于ManageSystemAccounts页面 | 点击'Query specified system account information' | 页面显示“Query account successful. Account name for account 100: "user"” | 是 | Pass | -| Modify system account avatar | 位于ManageSystemAccounts页面 | 点击'Modify system account avatar' | 页面显示“Successfully updated system account avatar” | 是 | Pass | -| Modify system account nickname | 位于ManageSystemAccounts页面 | 点击'Modify system account nickname' | 页面显示“Successfully modified system account name” | 是 | Pass | +# SystemAccount 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------- | -------------------------------------------- | ---------------------------------------- | -------------------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Set the constraint list for the specified system account | 位于UseConstraintManagementSystemAccount页面 | 点击'Set the constraint list for the specified system account' | 页面显示“Successfully set the constraint list for the specified system account” | 是 | Pass | +| Determine if the specified constraint for the target system account is enabled | 位于UseConstraintManagementSystemAccount页面 | 点击'Determine if the specified constraint for the target system account is enabled' | 页面显示“Set the constraint list for the specified system account” | 是 | Pass | +| Create system account | 位于ManageSystemAccounts页面 | 点击'Create system account' | 页面显示“Account creation successful. Account name:: "Bob"” | 是 | Pass | +| Query all system accounts | 位于ManageSystemAccounts页面 | 点击'Query all system accounts' | 页面显示“Query account successful. Account name:"user"” | 是 | Pass | +| Query specified system account information | 位于ManageSystemAccounts页面 | 点击'Query specified system account information' | 页面显示“Query account successful. Account name for account 100: "user"” | 是 | Pass | +| Modify system account avatar | 位于ManageSystemAccounts页面 | 点击'Modify system account avatar' | 页面显示“Successfully updated system account avatar” | 是 | Pass | +| Modify system account nickname | 位于ManageSystemAccounts页面 | 点击'Modify system account nickname' | 页面显示“Successfully modified system account name” | 是 | Pass | | Delete system account | 位于ManageSystemAccounts页面 | 点击'Delete system account' | 页面显示“Successfully deleted system account” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_1.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_10.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_10.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_11.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_11.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_2.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_3.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_4.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_4.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_5.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_5.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_6.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_6.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_7.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_7.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_8.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_8.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_9.png b/code/DocsSample/Account/SystemAccount/screenshots/SystemAccount_9.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/app.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/app.json5 index a03139a0d8bf599f24012798d82097e63dad4cb6..be11a102a5f1647031619fe5bc06d137b63f6c51 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/app.json5 @@ -1,26 +1,26 @@ -/* -* Copyright (c) 2024 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.implicitstartbytyperely", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name", - "distributedNotificationEnabled": true - } -} +/* +* Copyright (c) 2024 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.implicitstartbytyperely", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/resources/base/element/string.json index d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4..1080233f01384411ec684b58955cb8808746fdd3 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MyApplication" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/build-profile.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/build-profile.json5 index ee5fc3b62c9a1fdbb8e4313597b6fe0e4c829422..eff176287051b2cb66266fe3a75c5f090cbb2fa3 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/build-profile.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (c) 2024 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* Copyright (c) 2024 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/build-profile.json5 index f6cbf2f1e1662bf11f099bb743387f0eebe953d4..85d986b1fcb577c8016bc56ef1577c4d509626ee 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/build-profile.json5 @@ -1,28 +1,28 @@ -/* -* Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/oh-package.json5 index beb2ba7c83351598daacc939ce83f8243faab0f6..a7afd4ec1017198e9d8017e9f28e8e1d786a9e39 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/oh-package.json5 @@ -1,9 +1,9 @@ -{ - "license": "ISC", - "devDependencies": {}, - "name": "entry", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/ets/entryability/EntryAbility.ts index 6d1d184dbb2a09eb7deced82f98e8fe2f04c8ddb..1fea9577f6b415c422850ebb71d9e554d95d5d4f 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,59 +1,59 @@ -/* -* Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; -import type Want from '@ohos.app.ability.Want'; -import type AbilityConstant from '@ohos.app.ability.AbilityConstant'; - -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, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - 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'); - } - -} +/* +* Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; +import type Want from '@ohos.app.ability.Want'; +import type AbilityConstant from '@ohos.app.ability.AbilityConstant'; + +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, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + 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/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/module.json5 index 3a7f1d0279a1d688dcc553d1404d85f1252c0535..082405f6ed7a99a4c7849302154079ec177750cd 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/module.json5 @@ -1,68 +1,68 @@ -/* -* Copyright (c) 2024 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", - "srcEntrance": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home", - 'entity.system.browsable' - ], - "actions": [ - "action.system.home", - 'ohos.want.action.search', - 'ohos.want.action.viewData' - ], - "uris": [ - { - "scheme": "https", - "host": "www.test.com", - "port": "8080", - // prefix matching - "pathStartWith": "query", - "type": "application/http" - }, - { - "scheme": "http", - } - ] - } - ] - } - ] - } +/* +* Copyright (c) 2024 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", + "srcEntrance": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home", + 'entity.system.browsable' + ], + "actions": [ + "action.system.home", + 'ohos.want.action.search', + 'ohos.want.action.viewData' + ], + "uris": [ + { + "scheme": "https", + "host": "www.test.com", + "port": "8080", + // prefix matching + "pathStartWith": "query", + "type": "application/http" + }, + { + "scheme": "http", + } + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/hvigor/hvigor-config.json5 index d3c66f0a45201a9142682c8f8971dcf11f6be13b..a9a23b0b2e50ef8bb0850553dffc93802ff82aa9 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* -* Copyright (c) 2024 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. -*/ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - } +/* +* Copyright (c) 2024 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. +*/ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/oh-package.json5 b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/oh-package.json5 index bccaf227d742eb64d5331ce0450de100dd6dcb02..37453be12b18ddaafb3bf4a01db2a58bc4155ba1 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartByTypeRely/oh-package.json5 @@ -1,11 +1,11 @@ -{ - "license": "ISC", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "name": "myapplication", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "ISC", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "name": "myapplication", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/app.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/app.json5 index 0f21f2197ac0377890bfd78979e5e486d0b0d6dc..02489bdb8163c51d6404808ea1f4c48d68e330e8 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2024 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.implicitstartrely", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* +* Copyright (c) 2024 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.implicitstartrely", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/resources/base/element/string.json index dde739a8ab3608645f4c71b307270dc59f23502f..e279195f0eed8b1fd93af92070cb0d9aceab0d34 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "browser" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "browser" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/build-profile.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/build-profile.json5 index ee5fc3b62c9a1fdbb8e4313597b6fe0e4c829422..eff176287051b2cb66266fe3a75c5f090cbb2fa3 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/build-profile.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (c) 2024 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* Copyright (c) 2024 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/build-profile.json5 index a39f19549a4ab93c70f8d21d778277591ad3a814..9ac1d52c56537ca6bc00e1a702ee9545762e7985 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* -* Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/ets/entryability/EntryAbility.ts index 5de02b4dca21fc1831b6e4fb4296e22884ce81b4..7597d44bace3210346f17db08cbdedcceb8a42c6 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,58 +1,58 @@ -/* -* Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; -import type Want from '@ohos.app.ability.Want'; -import type AbilityConstant from '@ohos.app.ability.AbilityConstant'; - -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, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - 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'); - } -} +/* +* Copyright (c) 2024 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; +import type Want from '@ohos.app.ability.Want'; +import type AbilityConstant from '@ohos.app.ability.AbilityConstant'; + +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, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + 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/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/module.json5 index 131be46d84a2031147630ee27471662153617060..45469511384221cd6607cb450915e52eac503945 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/module.json5 @@ -1,65 +1,65 @@ -/* -* Copyright (c) 2024 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home", - 'entity.system.browsable' - ], - "actions": [ - "action.system.home", - 'ohos.want.action.viewData' - ], - "uris": [ - { - "scheme": "https", - "host": "www.test.com", - "port": "8080", - "pathStartWith": "query", - }, - { - "scheme": "http", - } - ] - } - ] - } - ] - } +/* +* Copyright (c) 2024 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home", + 'entity.system.browsable' + ], + "actions": [ + "action.system.home", + 'ohos.want.action.viewData' + ], + "uris": [ + { + "scheme": "https", + "host": "www.test.com", + "port": "8080", + "pathStartWith": "query", + }, + { + "scheme": "http", + } + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/hvigor/hvigor-config.json5 index d3c66f0a45201a9142682c8f8971dcf11f6be13b..a9a23b0b2e50ef8bb0850553dffc93802ff82aa9 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* -* Copyright (c) 2024 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. -*/ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - } +/* +* Copyright (c) 2024 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. +*/ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/ImplicitStartRely/oh-package.json5 b/code/DocsSample/ApplicationModels/ImplicitStartRely/oh-package.json5 index bac4c43f05d46d150301eea666f2cda71ce11f56..3313a2cb077e0a44bca8dd3dd409e0d44e04dfe1 100644 --- a/code/DocsSample/ApplicationModels/ImplicitStartRely/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/ImplicitStartRely/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "browser", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "browser", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/app.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/app.json5 index 0de07f31f5e2d218c94bf11c09a9395519e11de0..9aee09e72bcdce8aeb040867a92fa629a0ab936b 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2024 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.mindsporelitearktsdemo", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* +* Copyright (c) 2024 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.mindsporelitearktsdemo", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/resources/base/element/string.json index 7d862f19d5bd4b210c2cdd82d0dc2273e5871004..d26dc6c578f005f74a3c1d3fc0fe88664577a541 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MindSporeLiteArkTSDemo" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MindSporeLiteArkTSDemo" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/README_zh.md b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/README_zh.md index 2b0a8c1723155b43fd5c89352611d779e760fdcc..51539f53cb5863066dae23e9c1fc15fa55782f8b 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/README_zh.md +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/README_zh.md @@ -1,76 +1,76 @@ -# **基于ArkTS接口的MindSpore Lite应用开发** - -### 介绍 - -本文基于MindSpore Lite提供的ArkTS API,实现“端侧图像分类”示例程序,来演示端侧部署的流程。 - -1. 选择图像分类模型。 -2. 将模型转换成MindSpore Lite模型格式。 -3. 在端侧使用MindSpore Lite推理模型,显示出可能的分类结果。 - -### 效果预览 - -| 主页 | -|-----------------------------------------------------| -| | - -#### 使用说明 - -1. 在主界面,可以点击photo按钮,进入相册选择图片界面; -2. 在相册界面,选择图片,点击确定按钮; -3. 自动进行选择图片的图像分类模型推理,部分推理结果显示在主界面。 - -### 工程目录 - -``` -entry -├── src/main -│   ├── etc# -|   |   └── pages -|   |       └── Index.ets // 首页,获取图片及预处理 -|   |       └── model.ets // 推理 -│   ├── resources // 资源文件 -|   |   └── rawfile -|   |       └── mobilenetv2.ms // 存放的模型文件 -``` - -### 具体实现 - -* 本示例程序中使用的终端图像分类模型文件为mobilenetv2.ms,放置在entry\src\main\resources\rawfile工程目录下。 - - 注:开发者可按需手工下载[MindSpore Model Zoo中图像分类模型](https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/1.5/mobilenetv2.ms)。 - -* 调用[@ohos.file.picker](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) (图片文件选择)、[@ohos.multimedia.image](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-image-kit/js-apis-image.md) (图片处理效果)、[@ohos.file.fs](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) (基础文件操作) 等API实现相册图片获取及图片处理。完整代码请参见Index.ets - -* 调用[@ohos.ai.mindSporeLite](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-mindspore-lite-kit/js-apis-mindSporeLite.md) (推理能力) API实现端侧推理。完整代码请参见model.ets - -* 调用推理函数并处理结果。完整代码请参见Index.ets - -### 相关权限 - -ohos.permission.READ_IMAGEVIDEO - -### 依赖 - -无。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568; - -2.本示例为Stage模型,已适配API version 11版本SDK; - -3.本示例需要使用DevEco Studio 4.1 Release及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/ApplicationModels/MindSporeLiteArkTSDemo/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# **基于ArkTS接口的MindSpore Lite应用开发** + +### 介绍 + +本文基于MindSpore Lite提供的ArkTS API,实现“端侧图像分类”示例程序,来演示端侧部署的流程。 + +1. 选择图像分类模型。 +2. 将模型转换成MindSpore Lite模型格式。 +3. 在端侧使用MindSpore Lite推理模型,显示出可能的分类结果。 + +### 效果预览 + +| 主页 | +|-----------------------------------------------------| +| | + +#### 使用说明 + +1. 在主界面,可以点击photo按钮,进入相册选择图片界面; +2. 在相册界面,选择图片,点击确定按钮; +3. 自动进行选择图片的图像分类模型推理,部分推理结果显示在主界面。 + +### 工程目录 + +``` +entry +├── src/main +│   ├── etc# +|   |   └── pages +|   |       └── Index.ets // 首页,获取图片及预处理 +|   |       └── model.ets // 推理 +│   ├── resources // 资源文件 +|   |   └── rawfile +|   |       └── mobilenetv2.ms // 存放的模型文件 +``` + +### 具体实现 + +* 本示例程序中使用的终端图像分类模型文件为mobilenetv2.ms,放置在entry\src\main\resources\rawfile工程目录下。 + + 注:开发者可按需手工下载[MindSpore Model Zoo中图像分类模型](https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/1.5/mobilenetv2.ms)。 + +* 调用[@ohos.file.picker](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) (图片文件选择)、[@ohos.multimedia.image](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-image-kit/js-apis-image.md) (图片处理效果)、[@ohos.file.fs](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) (基础文件操作) 等API实现相册图片获取及图片处理。完整代码请参见Index.ets + +* 调用[@ohos.ai.mindSporeLite](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-mindspore-lite-kit/js-apis-mindSporeLite.md) (推理能力) API实现端侧推理。完整代码请参见model.ets + +* 调用推理函数并处理结果。完整代码请参见Index.ets + +### 相关权限 + +ohos.permission.READ_IMAGEVIDEO + +### 依赖 + +无。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568; + +2.本示例为Stage模型,已适配API version 11版本SDK; + +3.本示例需要使用DevEco Studio 4.1 Release及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/ApplicationModels/MindSporeLiteArkTSDemo/ > .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/ApplicationModels/MindSporeLiteArkTSDemo/build-profile.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/build-profile.json5 index db00d928f7e7bb2953063b2a547a5f8ed33c15c4..04f968869fee66e0b06e31da6e1dcef62d0ec334 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/build-profile.json5 @@ -1,52 +1,52 @@ -/* -* Copyright (c) 2024 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 11, - "compileSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 11, + "compileSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ], + "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/ApplicationModels/MindSporeLiteArkTSDemo/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/build-profile.json5 index b2ad240f2a7b7e0e46b32ab3c9bd63269317abcd..609159dd695196228aa8b42009b00225d044da2e 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (c) 2024 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/oh-package.json5 index 2959d78c50285f912adb2cdff9f613df9a503b44..248c3b7541a589682a250f86a6d3ecf7414d2d6a 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/entryability/EntryAbility.ets index 58056ae24532a3848b65321a2fb6ab4148c21acf..8335b7692d4cac1f8b5d78ce7bc1c45a453d563e 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,41 +1,41 @@ -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'); - } -} +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/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/pages/model.ets b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/pages/model.ets index 7fb05a8730ecf56bbd6227d743b2954279064dbd..cdc00f3c4edb5595da6f3b463dbe1db1833bfc6c 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/pages/model.ets +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/ets/pages/model.ets @@ -1,34 +1,34 @@ -import { mindSporeLite } from '@kit.MindSporeLiteKit' - -export default async function modelPredict( - modelBuffer: ArrayBuffer, inputsBuffer: ArrayBuffer[]): Promise { - - //1.创建上下文 - let context: mindSporeLite.Context = {}; - context.target = ['cpu']; - context.cpu = {} - context.cpu.threadNum = 2; - context.cpu.threadAffinityMode = 1; - context.cpu.precisionMode = 'enforce_fp32'; - - //2.加载模型 - let msLiteModel: mindSporeLite.Model = await mindSporeLite.loadModelFromBuffer(modelBuffer, context); - - //3.设置输入数据 - let modelInputs: mindSporeLite.MSTensor[] = msLiteModel.getInputs(); - - // 本模型不支持其他shape resize - for (let i = 0; i < inputsBuffer.length; i++) { - let inputBuffer = inputsBuffer[i]; - if (inputBuffer != null) { - modelInputs[i].setData(inputBuffer as ArrayBuffer); - } - } - - //4.执行推理 - console.info('=========MS_LITE_LOG: MS_LITE predict start====='); - let modelOutputs: mindSporeLite.MSTensor[] = await msLiteModel.predict(modelInputs); - return modelOutputs; -} - - +import { mindSporeLite } from '@kit.MindSporeLiteKit' + +export default async function modelPredict( + modelBuffer: ArrayBuffer, inputsBuffer: ArrayBuffer[]): Promise { + + //1.创建上下文 + let context: mindSporeLite.Context = {}; + context.target = ['cpu']; + context.cpu = {} + context.cpu.threadNum = 2; + context.cpu.threadAffinityMode = 1; + context.cpu.precisionMode = 'enforce_fp32'; + + //2.加载模型 + let msLiteModel: mindSporeLite.Model = await mindSporeLite.loadModelFromBuffer(modelBuffer, context); + + //3.设置输入数据 + let modelInputs: mindSporeLite.MSTensor[] = msLiteModel.getInputs(); + + // 本模型不支持其他shape resize + for (let i = 0; i < inputsBuffer.length; i++) { + let inputBuffer = inputsBuffer[i]; + if (inputBuffer != null) { + modelInputs[i].setData(inputBuffer as ArrayBuffer); + } + } + + //4.执行推理 + console.info('=========MS_LITE_LOG: MS_LITE predict start====='); + let modelOutputs: mindSporeLite.MSTensor[] = await msLiteModel.predict(modelInputs); + return modelOutputs; +} + + diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/module.json5 index fcd2d37ece5edb6356de08fd29f184904f33adbb..07bd623c859e38eaf6db4fb50915d3d2392cd304 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/module.json5 @@ -1,61 +1,61 @@ -/* -* Copyright (c) 2024-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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.READ_IMAGEVIDEO", - "reason": "$string:read_image_video_permission", - "usedScene": { - "when": "inuse" - } - } - ] - } +/* +* Copyright (c) 2024-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:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.READ_IMAGEVIDEO", + "reason": "$string:read_image_video_permission", + "usedScene": { + "when": "inuse" + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/Logger.ts b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/Logger.ts index 533c3b5b8cfa2034cbd8af5b47aa979357d9347a..db37c299365ac7befdd008f3131adb2a374a02a8 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/Logger.ts +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('Sample_Image'); \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets index 409105549384762ca4605b5f493487d0af529e66..15057e0141279a413f3b852992b408ccf879683e 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets @@ -1,23 +1,23 @@ -/* -* Copyright (c) 2024 Hunan OpenValley Digital Industry Development 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'; - -const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); - -export function getString(resourceData: Resource): string { - let manage = delegator.getAppContext().resourceManager - return manage.getStringSync(resourceData) +/* +* Copyright (c) 2024 Hunan OpenValley Digital Industry Development 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'; + +const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); + +export function getString(resourceData: Resource): string { + let manage = delegator.getAppContext().resourceManager + return manage.getStringSync(resourceData) } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/module.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/module.json5 index adc1f0eda95d1fefceec0b4c2636732a9cd43d95..141839900c450d28ca3fcf4ad00c85d03d880e55 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* -* Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* +* Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/resources/base/element/string.json b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/resources/base/element/string.json index c3f097d6be02cf3ff9f478f9d4803ab2c3fe3237..5955cede45230a0d21762a57af8717d6955ded40 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/entry/src/ohosTest/resources/base/element/string.json @@ -1,24 +1,24 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - }, - { - "name": "completed", - "value": "完成" - }, - { - "name": "allow", - "value": "允许" - } - ] +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "completed", + "value": "完成" + }, + { + "name": "allow", + "value": "允许" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/hvigor/hvigor-config.json5 index 940738da0462ba11f81339fd69596998af587c7f..2fcddb4906de7749404fc70d2370d60d4d3867ff 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/hvigor/hvigor-config.json5 @@ -1,37 +1,37 @@ -/* -* Copyright (c) 2024 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. -*/ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - }, - "execution": { - // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ - // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ - } -} +/* +* Copyright (c) 2024 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. +*/ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + }, + "execution": { + // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ + // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/oh-package.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/oh-package.json5 index e843e3734dd93e7d216048a9be5269fdaf09b0ab..0fa5a5b641579efe46577e2ffca69a3d7cefda7c 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/oh-package.json5 @@ -1,29 +1,29 @@ -/* -* Copyright (c) 2024 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": "mindsporelitearktsdemo", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.16", - "@ohos/hamock": "1.0.0" - } -} +/* +* Copyright (c) 2024 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": "mindsporelitearktsdemo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.16", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/ohosTest.md b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/ohosTest.md index bdac6d7a13f35b811d41b5f86212268ece2d6a16..095f1d955b756cf4d5d8467da601f845698789e5 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/ohosTest.md +++ b/code/DocsSample/ApplicationModels/MindSporeLiteArkTSDemo/ohosTest.md @@ -1,9 +1,9 @@ -# MindSporeLiteArkTSDemo 测试用例归档 - -## 用例表 - -|测试功能|预置条件|输入|预期输出|是否自动|测试结果| -|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| -|拉起应用| 设备正常运行| |成功拉起应用|是|Pass| -|查看预览界面Text和Button| 进入预览界面 | |预览界面存在Text和Button|是|Pass| +# MindSporeLiteArkTSDemo 测试用例归档 + +## 用例表 + +|测试功能|预置条件|输入|预期输出|是否自动|测试结果| +|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| +|拉起应用| 设备正常运行| |成功拉起应用|是|Pass| +|查看预览界面Text和Button| 进入预览界面 | |预览界面存在Text和Button|是|Pass| |选取图片推理功能测试| 进入预览界面 | 点击photo按钮 |选取图片后进行推理|是|Pass| \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/app.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/app.json5 index f61e2c4034cf1d197c4ff62fa579b5e59f0aa886..91270bcf39ac2d0bdaf53b5de2345985577ae552 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2024 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.mindsporelitecdemo", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* +* Copyright (c) 2024 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.mindsporelitecdemo", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/resources/base/element/string.json index fd9fe25b380fd7d0cb268ef439f2c2e2c96c5e3b..8621f2cb1ffab4ad01f456206c2dc8be37bf0e25 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MindSporeLiteCDemo" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MindSporeLiteCDemo" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/README_zh.md b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/README_zh.md index 23d9dd4a55b33ac0dfce2e4c1d2479c6cad25cdb..cc5fcea02f5edcfea604162f91f35672761c0d39 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/README_zh.md +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/README_zh.md @@ -1,85 +1,85 @@ -# **基于**Native**接口的MindSpore Lite应用开发** - -### 介绍 - -本文基于MindSpore Lite提供的[Native API](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-mindspore-lite-kit/_mind_spore.md),实现“图像分类”示例程序,来演示端侧部署的流程。 - -1. 选择图像分类模型。 -2. 将模型转换成MindSpore Lite模型格式。 -3. 使用MindSpore Lite推理模型,显示出可能的分类结果。 - -### 效果预览 - -| 主页 | -| -------------------------------------------------- | -| | - -#### 使用说明 - -1. 在主界面,可以点击photo按钮,进入相册选择图片界面; -2. 在相册界面,选择图片,点击确定按钮; -3. 自动进行选择图片的图像分类模型推理,部分推理结果显示在主界面。 - -### 工程目录 - -``` -entry -├── src/main -│   ├── etc -|   |   └── pages -|   |       └── Index.ets // 首页,获取图片及预处理 -│   ├── cpp -|   |   └── mslite_napi.cpp // 推理函数 -|   |   └── CMakeLists.txt // 编译脚本 -|   |   └── types -|   |   └── libentry -|   |       └── Index.t.ts // 将C++动态库封装成JS模块 -│   ├── resources // 资源文件 -|   |   └── rawfile -|   |       └── mobilenetv2.ms // 存放的模型文件 -``` - -### 具体实现 - -* 本示例程序中使用的终端图像分类模型文件为mobilenetv2.ms,放置在entry\src\main\resources\rawfile工程目录下。 - - 注:开发者可按需手工下载[MindSpore Model Zoo中图像分类模型](https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/1.5/mobilenetv2.ms)。 - -* 调用[@ohos.file.picker](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) (图片文件选择)、[@ohos.multimedia.image](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-image-kit/js-apis-image.md) (图片处理效果)、[@ohos.file.fs](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) (基础文件操作) 等API实现相册图片获取及图片处理。完整代码请参见Index.ets。 - -* 调用[MindSpore Lite Native API](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-mindspore-lite-kit/_mind_spore.md)实现推理。完整代码请参见mslite_napi.cpp。 - -* 编写CMake脚本。链接MindSpore Lite动态库,完整代码请参见CMakeLists.txt。 - -* 使用N-API将C++动态库封装成JS模块。在 entry/src/main/cpp/types/libentry/index.d.ts,定义JS接口`runDemo()` 。 - -* 调用推理函数并处理结果。完整代码请参见Index.ets - -### 相关权限 - -ohos.permission.READ_IMAGEVIDEO - -### 依赖 - -无。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,测试设备:RK3568; - -2.本示例为Stage模型,已适配API version 11版本SDK; - -3.本示例需要使用DevEco Studio 4.1 Release及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/BasicFeature/ApplicationModels/MindSporeLiteCDemo/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# **基于**Native**接口的MindSpore Lite应用开发** + +### 介绍 + +本文基于MindSpore Lite提供的[Native API](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-mindspore-lite-kit/_mind_spore.md),实现“图像分类”示例程序,来演示端侧部署的流程。 + +1. 选择图像分类模型。 +2. 将模型转换成MindSpore Lite模型格式。 +3. 使用MindSpore Lite推理模型,显示出可能的分类结果。 + +### 效果预览 + +| 主页 | +| -------------------------------------------------- | +| | + +#### 使用说明 + +1. 在主界面,可以点击photo按钮,进入相册选择图片界面; +2. 在相册界面,选择图片,点击确定按钮; +3. 自动进行选择图片的图像分类模型推理,部分推理结果显示在主界面。 + +### 工程目录 + +``` +entry +├── src/main +│   ├── etc +|   |   └── pages +|   |       └── Index.ets // 首页,获取图片及预处理 +│   ├── cpp +|   |   └── mslite_napi.cpp // 推理函数 +|   |   └── CMakeLists.txt // 编译脚本 +|   |   └── types +|   |   └── libentry +|   |       └── Index.t.ts // 将C++动态库封装成JS模块 +│   ├── resources // 资源文件 +|   |   └── rawfile +|   |       └── mobilenetv2.ms // 存放的模型文件 +``` + +### 具体实现 + +* 本示例程序中使用的终端图像分类模型文件为mobilenetv2.ms,放置在entry\src\main\resources\rawfile工程目录下。 + + 注:开发者可按需手工下载[MindSpore Model Zoo中图像分类模型](https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_openimage_lite/1.5/mobilenetv2.ms)。 + +* 调用[@ohos.file.picker](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md) (图片文件选择)、[@ohos.multimedia.image](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-image-kit/js-apis-image.md) (图片处理效果)、[@ohos.file.fs](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) (基础文件操作) 等API实现相册图片获取及图片处理。完整代码请参见Index.ets。 + +* 调用[MindSpore Lite Native API](https://docs.openharmony.cn/pages/v4.1/zh-cn/application-dev/reference/apis-mindspore-lite-kit/_mind_spore.md)实现推理。完整代码请参见mslite_napi.cpp。 + +* 编写CMake脚本。链接MindSpore Lite动态库,完整代码请参见CMakeLists.txt。 + +* 使用N-API将C++动态库封装成JS模块。在 entry/src/main/cpp/types/libentry/index.d.ts,定义JS接口`runDemo()` 。 + +* 调用推理函数并处理结果。完整代码请参见Index.ets + +### 相关权限 + +ohos.permission.READ_IMAGEVIDEO + +### 依赖 + +无。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,测试设备:RK3568; + +2.本示例为Stage模型,已适配API version 11版本SDK; + +3.本示例需要使用DevEco Studio 4.1 Release及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/BasicFeature/ApplicationModels/MindSporeLiteCDemo/ > .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/ApplicationModels/MindSporeLiteCDemo/build-profile.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/build-profile.json5 index db00d928f7e7bb2953063b2a547a5f8ed33c15c4..04f968869fee66e0b06e31da6e1dcef62d0ec334 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/build-profile.json5 @@ -1,52 +1,52 @@ -/* -* Copyright (c) 2024 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 11, - "compileSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 11, + "compileSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ], + "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/ApplicationModels/MindSporeLiteCDemo/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/build-profile.json5 index 88ef1ccf3cf5766d17e6ddbfe5b5c2da65444aa8..a3270534644d4282b978ba19e605dfb33c62ce6b 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/build-profile.json5 @@ -1,55 +1,55 @@ -/* -* Copyright (c) 2024 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", - "abiFilters": ['arm64-v8a', 'armeabi-v7a', 'x86_64'], - "arguments": "", - "cppFlags": "", - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2024 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", + "abiFilters": ['arm64-v8a', 'armeabi-v7a', 'x86_64'], + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "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/ApplicationModels/MindSporeLiteCDemo/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/oh-package.json5 index b9c1d4cca76ac664388dd6b1cf96697184c5133b..54cb066266f9993f5a023f2ac5a8dfc5d2574643 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/oh-package.json5 @@ -1,11 +1,11 @@ -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - } +{ + "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/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/CMakeLists.txt index 879e35c6e032f4ce8589ad21ba344bc475e45a30..f7c8404bac35d13e95902a8b4a87ce0a6d6eb42b 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/CMakeLists.txt @@ -1,18 +1,18 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(MindSporeLiteCDemo) - -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 mslite_napi.cpp) -target_link_libraries(entry PUBLIC mindspore_lite_ndk) -target_link_libraries(entry PUBLIC hilog_ndk.z) -target_link_libraries(entry PUBLIC rawfile.z) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(MindSporeLiteCDemo) + +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 mslite_napi.cpp) +target_link_libraries(entry PUBLIC mindspore_lite_ndk) +target_link_libraries(entry PUBLIC hilog_ndk.z) +target_link_libraries(entry PUBLIC rawfile.z) target_link_libraries(entry PUBLIC ace_napi.z) \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/mslite_napi.cpp b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/mslite_napi.cpp index b3680d153557d6c8ffaf227e0bf641e5ae4d104d..25128b15aa5408ec975f1802f7f1a1406306f520 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/mslite_napi.cpp +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/mslite_napi.cpp @@ -1,230 +1,230 @@ -/* - * Copyright (c) 2024 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) -#define LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) -#define LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) -#define LOGE(...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) - -constexpr int K_NUM_PRINT_OF_OUT_DATA = 20; - -int FillInputTensor(OH_AI_TensorHandle input, std::vector input_data) -{ - if (OH_AI_TensorGetDataType(input) == OH_AI_DATATYPE_NUMBERTYPE_FLOAT32) { - float *data = (float *)OH_AI_TensorGetMutableData(input); - for (size_t i = 0; i < OH_AI_TensorGetElementNum(input); i++) { - data[i] = input_data[i]; - } - return OH_AI_STATUS_SUCCESS; - } else { - return OH_AI_STATUS_LITE_ERROR; - } -} - -void *ReadModelFile(NativeResourceManager *nativeResourceManager, const std::string &modelName, size_t *modelSize) -{ - auto rawFile = OH_ResourceManager_OpenRawFile(nativeResourceManager, modelName.c_str()); - if (rawFile == nullptr) { - LOGE("MS_LITE_ERR: Open model file failed"); - return nullptr; - } - long fileSize = OH_ResourceManager_GetRawFileSize(rawFile); - if (fileSize <= 0) { - LOGE("MS_LITE_ERR: FileSize not correct"); - } - void *modelBuffer = malloc(fileSize); - if (modelBuffer == nullptr) { - LOGE("MS_LITE_ERR: OH_ResourceManager_ReadRawFile failed"); - } - int ret = OH_ResourceManager_ReadRawFile(rawFile, modelBuffer, fileSize); - if (ret == 0) { - LOGI("MS_LITE_LOG: OH_ResourceManager_ReadRawFile failed"); - OH_ResourceManager_CloseRawFile(rawFile); - return nullptr; - } - OH_ResourceManager_CloseRawFile(rawFile); - *modelSize = fileSize; - return modelBuffer; -} - -void DestroyModelBuffer(void **buffer) -{ - if (buffer == nullptr) { - return; - } - free(*buffer); - *buffer = nullptr; -} - -OH_AI_ModelHandle CreateMSLiteModel(void *modelBuffer, size_t modelSize) -{ - // Set executing context for model. - auto context = OH_AI_ContextCreate(); - if (context == nullptr) { - DestroyModelBuffer(&modelBuffer); - LOGE("MS_LITE_ERR: Create MSLite context failed.\n"); - return nullptr; - } - auto cpu_device_info = OH_AI_DeviceInfoCreate(OH_AI_DEVICETYPE_CPU); - OH_AI_DeviceInfoSetEnableFP16(cpu_device_info, true); - OH_AI_ContextAddDeviceInfo(context, cpu_device_info); - - // Create model - auto model = OH_AI_ModelCreate(); - if (model == nullptr) { - DestroyModelBuffer(&modelBuffer); - LOGE("MS_LITE_ERR: Allocate MSLite Model failed.\n"); - return nullptr; - } - - // Build model object - auto build_ret = OH_AI_ModelBuild(model, modelBuffer, modelSize, OH_AI_MODELTYPE_MINDIR, context); - DestroyModelBuffer(&modelBuffer); - if (build_ret != OH_AI_STATUS_SUCCESS) { - OH_AI_ModelDestroy(&model); - LOGE("MS_LITE_ERR: Build MSLite model failed.\n"); - return nullptr; - } - LOGI("MS_LITE_LOG: Build MSLite model success.\n"); - return model; -} - -int RunMSLiteModel(OH_AI_ModelHandle model, std::vector input_data) -{ - // Set input data for model. - auto inputs = OH_AI_ModelGetInputs(model); - auto ret = FillInputTensor(inputs.handle_list[0], input_data); - if (ret != OH_AI_STATUS_SUCCESS) { - LOGE("MS_LITE_ERR: RunMSLiteModel set input error.\n"); - return OH_AI_STATUS_LITE_ERROR; - } - - // Get model output. - auto outputs = OH_AI_ModelGetOutputs(model); - - // Predict model. - auto predict_ret = OH_AI_ModelPredict(model, inputs, &outputs, nullptr, nullptr); - if (predict_ret != OH_AI_STATUS_SUCCESS) { - OH_AI_ModelDestroy(&model); - LOGE("MS_LITE_ERR: MSLite Predict error.\n"); - return OH_AI_STATUS_LITE_ERROR; - } - LOGI("MS_LITE_LOG: Run MSLite model Predict success.\n"); - - // Print output tensor data. - LOGI("MS_LITE_LOG: Get model outputs:\n"); - for (size_t i = 0; i < outputs.handle_num; i++) { - auto tensor = outputs.handle_list[i]; - LOGI("MS_LITE_LOG: - Tensor %{public}d name is: %{public}s.\n", static_cast(i), - OH_AI_TensorGetName(tensor)); - LOGI("MS_LITE_LOG: - Tensor %{public}d size is: %{public}d.\n", static_cast(i), - (int)OH_AI_TensorGetDataSize(tensor)); - LOGI("MS_LITE_LOG: - Tensor data is:\n"); - auto out_data = reinterpret_cast(OH_AI_TensorGetData(tensor)); - std::stringstream outStr; - for (int i = 0; (i < OH_AI_TensorGetElementNum(tensor)) && (i <= K_NUM_PRINT_OF_OUT_DATA); i++) { - outStr << out_data[i] << " "; - } - LOGI("MS_LITE_LOG: %{public}s", outStr.str().c_str()); - } - return OH_AI_STATUS_SUCCESS; -} - -static napi_value RunDemo(napi_env env, napi_callback_info info) -{ - // run demo - napi_value error_ret; - napi_create_int32(env, -1, &error_ret); - // 传入数据处理 - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - bool isArray = false; - napi_is_array(env, argv[0], &isArray); - uint32_t length = 0; - // 获取数组的长度 - napi_get_array_length(env, argv[0], &length); - std::vector input_data; - double param = 0; - for (int i = 0; i < length; i++) { - napi_value value; - napi_get_element(env, argv[0], i, &value); - napi_get_value_double(env, value, ¶m); - input_data.push_back(static_cast(param)); - } - std::stringstream outstr; - for (int i = 0; i < K_NUM_PRINT_OF_OUT_DATA; i++) { - outstr << input_data[i] << " "; - } - // Read model file - const std::string modelName = "mobilenetv2.ms"; - size_t modelSize; - auto resourcesManager = OH_ResourceManager_InitNativeResourceManager(env, argv[1]); - auto modelBuffer = ReadModelFile(resourcesManager, modelName, &modelSize); - if (modelBuffer == nullptr) { - return error_ret; - } - auto model = CreateMSLiteModel(modelBuffer, modelSize); - int ret = RunMSLiteModel(model, input_data); - if (ret != OH_AI_STATUS_SUCCESS) { - OH_AI_ModelDestroy(&model); - return error_ret; - } - napi_value out_data; - napi_create_array(env, &out_data); - auto outputs = OH_AI_ModelGetOutputs(model); - OH_AI_TensorHandle output_0 = outputs.handle_list[0]; - float *output0Data = reinterpret_cast(OH_AI_TensorGetMutableData(output_0)); - for (size_t i = 0; i < OH_AI_TensorGetElementNum(output_0); i++) { - napi_value element; - napi_create_double(env, static_cast(output0Data[i]), &element); - napi_set_element(env, out_data, i, element); - } - OH_AI_ModelDestroy(&model); - return out_data; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"runDemo", nullptr, RunDemo, 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); } +/* + * Copyright (c) 2024 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) +#define LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) +#define LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) +#define LOGE(...) ((void)OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "[MSLiteNapi]", __VA_ARGS__)) + +constexpr int K_NUM_PRINT_OF_OUT_DATA = 20; + +int FillInputTensor(OH_AI_TensorHandle input, std::vector input_data) +{ + if (OH_AI_TensorGetDataType(input) == OH_AI_DATATYPE_NUMBERTYPE_FLOAT32) { + float *data = (float *)OH_AI_TensorGetMutableData(input); + for (size_t i = 0; i < OH_AI_TensorGetElementNum(input); i++) { + data[i] = input_data[i]; + } + return OH_AI_STATUS_SUCCESS; + } else { + return OH_AI_STATUS_LITE_ERROR; + } +} + +void *ReadModelFile(NativeResourceManager *nativeResourceManager, const std::string &modelName, size_t *modelSize) +{ + auto rawFile = OH_ResourceManager_OpenRawFile(nativeResourceManager, modelName.c_str()); + if (rawFile == nullptr) { + LOGE("MS_LITE_ERR: Open model file failed"); + return nullptr; + } + long fileSize = OH_ResourceManager_GetRawFileSize(rawFile); + if (fileSize <= 0) { + LOGE("MS_LITE_ERR: FileSize not correct"); + } + void *modelBuffer = malloc(fileSize); + if (modelBuffer == nullptr) { + LOGE("MS_LITE_ERR: OH_ResourceManager_ReadRawFile failed"); + } + int ret = OH_ResourceManager_ReadRawFile(rawFile, modelBuffer, fileSize); + if (ret == 0) { + LOGI("MS_LITE_LOG: OH_ResourceManager_ReadRawFile failed"); + OH_ResourceManager_CloseRawFile(rawFile); + return nullptr; + } + OH_ResourceManager_CloseRawFile(rawFile); + *modelSize = fileSize; + return modelBuffer; +} + +void DestroyModelBuffer(void **buffer) +{ + if (buffer == nullptr) { + return; + } + free(*buffer); + *buffer = nullptr; +} + +OH_AI_ModelHandle CreateMSLiteModel(void *modelBuffer, size_t modelSize) +{ + // Set executing context for model. + auto context = OH_AI_ContextCreate(); + if (context == nullptr) { + DestroyModelBuffer(&modelBuffer); + LOGE("MS_LITE_ERR: Create MSLite context failed.\n"); + return nullptr; + } + auto cpu_device_info = OH_AI_DeviceInfoCreate(OH_AI_DEVICETYPE_CPU); + OH_AI_DeviceInfoSetEnableFP16(cpu_device_info, true); + OH_AI_ContextAddDeviceInfo(context, cpu_device_info); + + // Create model + auto model = OH_AI_ModelCreate(); + if (model == nullptr) { + DestroyModelBuffer(&modelBuffer); + LOGE("MS_LITE_ERR: Allocate MSLite Model failed.\n"); + return nullptr; + } + + // Build model object + auto build_ret = OH_AI_ModelBuild(model, modelBuffer, modelSize, OH_AI_MODELTYPE_MINDIR, context); + DestroyModelBuffer(&modelBuffer); + if (build_ret != OH_AI_STATUS_SUCCESS) { + OH_AI_ModelDestroy(&model); + LOGE("MS_LITE_ERR: Build MSLite model failed.\n"); + return nullptr; + } + LOGI("MS_LITE_LOG: Build MSLite model success.\n"); + return model; +} + +int RunMSLiteModel(OH_AI_ModelHandle model, std::vector input_data) +{ + // Set input data for model. + auto inputs = OH_AI_ModelGetInputs(model); + auto ret = FillInputTensor(inputs.handle_list[0], input_data); + if (ret != OH_AI_STATUS_SUCCESS) { + LOGE("MS_LITE_ERR: RunMSLiteModel set input error.\n"); + return OH_AI_STATUS_LITE_ERROR; + } + + // Get model output. + auto outputs = OH_AI_ModelGetOutputs(model); + + // Predict model. + auto predict_ret = OH_AI_ModelPredict(model, inputs, &outputs, nullptr, nullptr); + if (predict_ret != OH_AI_STATUS_SUCCESS) { + OH_AI_ModelDestroy(&model); + LOGE("MS_LITE_ERR: MSLite Predict error.\n"); + return OH_AI_STATUS_LITE_ERROR; + } + LOGI("MS_LITE_LOG: Run MSLite model Predict success.\n"); + + // Print output tensor data. + LOGI("MS_LITE_LOG: Get model outputs:\n"); + for (size_t i = 0; i < outputs.handle_num; i++) { + auto tensor = outputs.handle_list[i]; + LOGI("MS_LITE_LOG: - Tensor %{public}d name is: %{public}s.\n", static_cast(i), + OH_AI_TensorGetName(tensor)); + LOGI("MS_LITE_LOG: - Tensor %{public}d size is: %{public}d.\n", static_cast(i), + (int)OH_AI_TensorGetDataSize(tensor)); + LOGI("MS_LITE_LOG: - Tensor data is:\n"); + auto out_data = reinterpret_cast(OH_AI_TensorGetData(tensor)); + std::stringstream outStr; + for (int i = 0; (i < OH_AI_TensorGetElementNum(tensor)) && (i <= K_NUM_PRINT_OF_OUT_DATA); i++) { + outStr << out_data[i] << " "; + } + LOGI("MS_LITE_LOG: %{public}s", outStr.str().c_str()); + } + return OH_AI_STATUS_SUCCESS; +} + +static napi_value RunDemo(napi_env env, napi_callback_info info) +{ + // run demo + napi_value error_ret; + napi_create_int32(env, -1, &error_ret); + // 传入数据处理 + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + bool isArray = false; + napi_is_array(env, argv[0], &isArray); + uint32_t length = 0; + // 获取数组的长度 + napi_get_array_length(env, argv[0], &length); + std::vector input_data; + double param = 0; + for (int i = 0; i < length; i++) { + napi_value value; + napi_get_element(env, argv[0], i, &value); + napi_get_value_double(env, value, ¶m); + input_data.push_back(static_cast(param)); + } + std::stringstream outstr; + for (int i = 0; i < K_NUM_PRINT_OF_OUT_DATA; i++) { + outstr << input_data[i] << " "; + } + // Read model file + const std::string modelName = "mobilenetv2.ms"; + size_t modelSize; + auto resourcesManager = OH_ResourceManager_InitNativeResourceManager(env, argv[1]); + auto modelBuffer = ReadModelFile(resourcesManager, modelName, &modelSize); + if (modelBuffer == nullptr) { + return error_ret; + } + auto model = CreateMSLiteModel(modelBuffer, modelSize); + int ret = RunMSLiteModel(model, input_data); + if (ret != OH_AI_STATUS_SUCCESS) { + OH_AI_ModelDestroy(&model); + return error_ret; + } + napi_value out_data; + napi_create_array(env, &out_data); + auto outputs = OH_AI_ModelGetOutputs(model); + OH_AI_TensorHandle output_0 = outputs.handle_list[0]; + float *output0Data = reinterpret_cast(OH_AI_TensorGetMutableData(output_0)); + for (size_t i = 0; i < OH_AI_TensorGetElementNum(output_0); i++) { + napi_value element; + napi_create_double(env, static_cast(output0Data[i]), &element); + napi_set_element(env, out_data, i, element); + } + OH_AI_ModelDestroy(&model); + return out_data; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"runDemo", nullptr, RunDemo, 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/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/index.d.ts index 62f0867c03364a32cb58b185b50db648e7d4fe8b..9a1eb15f2c952d8c48131d02771bfe5f3864fd31 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +1,16 @@ -/* -* Copyright (c) 2024 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. -*/ - +/* +* Copyright (c) 2024 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 runDemo: (a: number[], b:Object) => Array; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/oh-package.json5 index b1ec375f51989cdc877a184f5d34efe6fd8b96ba..87f95d0079d8a4d748f409380bfd703bb0f114c1 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,6 +1,6 @@ -{ - "name": "libentry.so", - "types": "./index.d.ts", - "version": "", - "description": "MindSpore Lite inference module" +{ + "name": "libentry.so", + "types": "./index.d.ts", + "version": "", + "description": "MindSpore Lite inference module" } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/entryability/EntryAbility.ets index ca45f401138c56d8646e0d1312c10cbbd9577d2e..d96a7e268e388ab61498dd2109d5f2cc666000fd 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,41 +1,41 @@ -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'); - } -}; +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/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/pages/Index.ets index 3beb044cd439b7fc2557552b62b459890f22bff1..e03f7051b4cdb3593bcaa556e2ed0498f4127f75 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/ets/pages/Index.ets @@ -1,299 +1,299 @@ -/* -* Copyright (c) 2024-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 resourceManager from '@ohos.resourceManager' -import fileIo from '@ohos.file.fs'; -import msliteNapi from 'libentry.so' -import { photoAccessHelper } from '@kit.MediaLibraryKit'; -import { BusinessError } from '@ohos.base'; -import image from '@ohos.multimedia.image'; -import { abilityAccessCtrl, Permissions } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG = 'MindSporeLite'; -const PERMISSIONS: Permissions[] = ['ohos.permission.READ_IMAGEVIDEO']; - -@Entry -@Component -struct Index { - @State message: string = 'MindSporeLite C Demo'; - @State modelName: string = 'mobilenetv2.ms'; - @State modelInputHeight: number = 224; - @State modelInputWidth: number = 224; - @State uris: Array = []; - @State max: number = 0; - @State maxIndex: number = 0; - @State maxArray: Array = []; - @State maxIndexArray: Array = []; - @State labelsNameMap: string[] = [ - 'Herd', 'Safari', 'Bangle', 'Cushion', 'Countertop', - 'Prom', 'Branch', 'Sports', 'Sky', 'Community', - 'Wheel', 'Cola', 'Tuxedo', 'Flowerpot', 'Team', - 'Computer', 'Unicycle', 'Brig', 'Aerospace engineering', 'Scuba diving', - 'Goggles', 'Fruit', 'Badminton', 'Horse', 'Sunglasses', - 'Fun', 'Prairie', 'Poster', 'Flag', 'Speedboat', - 'Eyelash', 'Veil', 'Mobile phone', 'Wheelbarrow', 'Saucer', - 'Leather', 'Drawer', 'Paper', 'Pier', 'Waterfowl', - 'Tights', 'Rickshaw', 'Vegetable', 'Handrail', 'Ice', - 'Metal', 'Flower', 'Wing', 'Silverware', 'Event', - 'Skyline', 'Money', 'Comics', 'Handbag', 'Porcelain', - 'Rodeo', 'Curtain', 'Tile', 'Human mouth', 'Army', - 'Menu', 'Boat', 'Snowboarding', 'Cairn terrier', 'Net', - 'Pasteles', 'Cup', 'Rugby', 'Pho', 'Cap', - 'Human hair', 'Surfing', 'Loveseat', 'Museum', 'Shipwreck', - 'Trunk (Tree)', 'Plush', 'Monochrome', 'Volcano', 'Rock', - 'Pillow', 'Presentation', 'Nebula', 'Subwoofer', 'Lake', - 'Sledding', 'Bangs', 'Tablecloth', 'Necklace', 'Swimwear', - 'Standing', 'Jeans', 'Carnival', 'Softball', 'Centrepiece', - 'Skateboarder', 'Cake', 'Dragon', 'Aurora', 'Skiing', - 'Bathroom', 'Dog', 'Needlework', 'Umbrella', 'Church', - 'Fire', 'Piano', 'Denim', 'Bridle', 'Cabinetry', - 'Lipstick', 'Ring', 'Television', 'Roller', 'Seal', - 'Concert', 'Product', 'News', 'Fast food', 'Horn (Animal)', - 'Tattoo', 'Bird', 'Bridegroom', 'Love', 'Helmet', - 'Dinosaur', 'Icing', 'Miniature', 'Tire', 'Toy', - 'Icicle', 'Jacket', 'Coffee', 'Mosque', 'Rowing', - 'Wetsuit', 'Camping', 'Underwater', 'Christmas', 'Gelato', - 'Whiteboard', 'Field', 'Ragdoll', 'Construction', 'Lampshade', - 'Palace', 'Meal', 'Factory', 'Cage', 'Clipper (Boat)', - 'Gymnastics', 'Turtle', 'Human foot', 'Marriage', 'Web page', - 'Human beard', 'Fog', 'Wool', 'Cappuccino', 'Lighthouse', - 'Lego', 'Sparkler', 'Sari', 'Model', 'Temple', - 'Beanie', 'Building', 'Waterfall', 'Penguin', 'Cave', - 'Stadium', 'Smile', 'Human hand', 'Park', 'Desk', - 'Shetland sheepdog', 'Bar', 'Eating', 'Neon', 'Dalmatian', - 'Crocodile', 'Wakeboarding', 'Longboard', 'Road', 'Race', - 'Kitchen', 'Odometer', 'Cliff', 'Fiction', 'School', - 'Interaction', 'Bullfighting', 'Boxer', 'Gown', 'Aquarium', - 'Superhero', 'Pie', 'Asphalt', 'Surfboard', 'Cheeseburger', - 'Screenshot', 'Supper', 'Laugh', 'Lunch', 'Party ', - 'Glacier', 'Bench', 'Grandparent', 'Sink', 'Pomacentridae', - 'Blazer', 'Brick', 'Space', 'Backpacking', 'Stuffed toy', - 'Sushi', 'Glitter', 'Bonfire', 'Castle', 'Marathon', - 'Pizza', 'Beach', 'Human ear', 'Racing', 'Sitting', - 'Iceberg', 'Shelf', 'Vehicle', 'Pop music', 'Playground', - 'Clown', 'Car', 'Rein', 'Fur', 'Musician', - 'Casino', 'Baby', 'Alcohol', 'Strap', 'Reef', - 'Balloon', 'Outerwear', 'Cathedral', 'Competition', 'Joker', - 'Blackboard', 'Bunk bed', 'Bear', 'Moon', 'Archery', - 'Polo', 'River', 'Fishing', 'Ferris wheel', 'Mortarboard', - 'Bracelet', 'Flesh', 'Statue', 'Farm', 'Desert', - 'Chain', 'Aircraft', 'Textile', 'Hot dog', 'Knitting', - 'Singer', 'Juice', 'Circus', 'Chair', 'Musical instrument', - 'Room', 'Crochet', 'Sailboat', 'Newspaper', 'Santa claus', - 'Swamp', 'Skyscraper', 'Skin', 'Rocket', 'Aviation', - 'Airliner', 'Garden', 'Ruins', 'Storm', 'Glasses', - 'Balance', 'Nail (Body part)', 'Rainbow', 'Soil ', 'Vacation ', - 'Moustache', 'Doily', 'Food', 'Bride ', 'Cattle', - 'Pocket', 'Infrastructure', 'Train', 'Gerbil', 'Fireworks', - 'Pet', 'Dam', 'Crew', 'Couch', 'Bathing', - 'Quilting', 'Motorcycle', 'Butterfly', 'Sled', 'Watercolor paint', - 'Rafting', 'Monument', 'Lightning', 'Sunset', 'Bumper', - 'Shoe', 'Waterskiing', 'Sneakers', 'Tower', 'Insect', - 'Pool', 'Placemat', 'Airplane', 'Plant', 'Jungle', - 'Armrest', 'Duck', 'Dress', 'Tableware', 'Petal', - 'Bus', 'Hanukkah', 'Forest', 'Hat', 'Barn', - 'Tubing', 'Snorkeling', 'Cool', 'Cookware and bakeware', 'Cycling', - 'Swing (Seat)', 'Muscle', 'Cat', 'Skateboard', 'Star', - 'Toe', 'Junk', 'Bicycle', 'Bedroom', 'Person', - 'Sand', 'Canyon', 'Tie', 'Twig', 'Sphynx', - 'Supervillain', 'Nightclub', 'Ranch', 'Pattern', 'Shorts', - 'Himalayan', 'Wall', 'Leggings', 'Windsurfing', 'Deejay', - 'Dance', 'Van', 'Bento', 'Sleep', 'Wine', - 'Picnic', 'Leisure', 'Dune', 'Crowd', 'Kayak', - 'Ballroom', 'Selfie', 'Graduation', 'Frigate', 'Mountain', - 'Dude', 'Windshield', 'Skiff', 'Class', 'Scarf', - 'Bull', 'Soccer', 'Bag', 'Basset hound', 'Tractor', - 'Swimming', 'Running', 'Track', 'Helicopter', 'Pitch', - 'Clock', 'Song', 'Jersey', 'Stairs', 'Flap', - 'Jewellery', 'Bridge', 'Cuisine', 'Bread', 'Caving', - 'Shell', 'Wreath', 'Roof', 'Cookie', 'Canoe' - ]; - - aboutToAppear() { - abilityAccessCtrl.createAtManager().requestPermissionsFromUser(getContext(this), PERMISSIONS).then((data) => { - if (data.authResults[0] == 0) { - hilog.info(0xFF00, TAG, '%{public}s', 'request permission success'); - } else { - hilog.info(0xFF00, TAG, '%{public}s', 'user rejected'); - } - }).catch((err: BusinessError) => { - hilog.error(0xFF00, TAG, '%{public}s', - `request permission failed, error message: ${(err as BusinessError).message}`); - }); - } - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .fontWeight(FontWeight.Bold); - //图片显示 - Image(this.uris[0]).width(320).height(540).margin(15) - //显示分类最大值 - if (this.max) { - Text(this.labelsNameMap[this.maxIndexArray[0]] + - ': ' + - (this.maxArray[0] / 100).toString() + - '%\n' + - this.labelsNameMap[this.maxIndexArray[1]] + - ': ' + - (this.maxArray[1] / 100).toString() + - '%\n' + - this.labelsNameMap[this.maxIndexArray[2]] + - ': ' + - (this.maxArray[2] / 100).toString() + - '%\n' + - this.labelsNameMap[this.maxIndexArray[3]] + - ': ' + - (this.maxArray[3] / 100).toString() + - '%').focusable(true).fontSize(20) - } - Button() { - Text('photo') - .fontSize(30) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('40%') - .height('5%') - .onClick(() => { - let resMgr: resourceManager.ResourceManager = getContext().getApplicationContext().resourceManager; - - //获取相册图片 - //1.创建图片-视频类型文件选择选项实例 - let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); - - //2.选择媒体文件类型和选择媒体文件的最大数目 - PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE - PhotoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目 - - //3.创建图库选择器实例,调用select()接口拉起图库界面进行文件选择。文件选择成功后,返回 photoSelectResult 结果集。 - let photoPicker = new photoAccessHelper.PhotoViewPicker(); - photoPicker.select(PhotoSelectOptions, - async (err: BusinessError, photoSelectResult: photoAccessHelper.PhotoSelectResult) => { - if (err) { - console.error('MS_LITE_ERR: PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); - return; - } - console.info('MS_LITE_LOG: PhotoViewPicker.select successfully, photoSelectResult uri: ' + - JSON.stringify(photoSelectResult)); - this.uris = photoSelectResult.photoUris; - console.info('MS_LITE_LOG: uri: ' + this.uris); - try { - // 预处理图片数据 - // 1.使用fs.openSync接口,通过uri打开这个文件得到fd - let file = fileIo.openSync(this.uris[0], fileIo.OpenMode.READ_ONLY); - console.info('MS_LITE_LOG: file fd: ' + file.fd); - - // 2.通过fd使用fs.readSync接口读取这个文件内的数据 - let inputBuffer = new ArrayBuffer(4096000); - let readLen = fileIo.readSync(file.fd, inputBuffer); - console.info('MS_LITE_LOG: readSync data to file succeed and inputBuffer size is:' + readLen); - - // 3.通过 PixelMap 预处理 - let imageSource = image.createImageSource(file.fd); - let pixelMap = await imageSource.createPixelMap({ editable: true }); - let info = await pixelMap.getImageInfo(); - console.info('MS_LITE_LOG: info.width = ' + info.size.width); - console.info('MS_LITE_LOG: info.height = ' + info.size.height); - - // 4. 获取图片buffer数据readBuffer,并进行处理 - pixelMap.scale(256.0 / info.size.width, 256.0 / info.size.height).then(() => { - pixelMap.crop({ - x: 16, - y: 16, - size: { height: this.modelInputHeight, width: this.modelInputWidth } - }) - .then(async () => { - let info = await pixelMap.getImageInfo(); - console.info('MS_LITE_LOG: crop info.width = ' + info.size.width); - console.info('MS_LITE_LOG: crop info.height = ' + info.size.height); - // 需要创建的像素buffer大小 - let readBuffer = new ArrayBuffer(this.modelInputHeight * this.modelInputWidth * 4); - await pixelMap.readPixelsToBuffer(readBuffer); - console.info('MS_LITE_LOG: Succeeded in reading image pixel data, buffer: ' + readBuffer.byteLength); - - // 处理readBuffer - const imageArr = - new Uint8Array(readBuffer.slice(0, this.modelInputHeight * this.modelInputWidth * 4)); - console.info('MS_LITE_LOG: imageArr length: ' + imageArr.length); - let means = [0.485, 0.456, 0.406]; - let stds = [0.229, 0.224, 0.225]; - let float32View = new Float32Array(this.modelInputHeight * this.modelInputWidth * 3); - let index = 0; - for (let i = 0; i < imageArr.length; i++) { - if ((i + 1) % 4 == 0) { - float32View[index] = (imageArr[i - 3] / 255.0 - means[0]) / stds[0]; // B - float32View[index+1] = (imageArr[i - 2] / 255.0 - means[1]) / stds[1]; // G - float32View[index+2] = (imageArr[i - 1] / 255.0 - means[2]) / stds[2]; // R - index += 3; - } - } - console.info('MS_LITE_LOG: float32View length: ' + float32View.length); - let printStr = 'float32View data:'; - for (let i = 0; i < 20; i++) { - printStr += ' ' + float32View[i]; - } - console.info('MS_LITE_LOG: float32View data: ' + printStr); - - // 调用c++的runDemo - console.info('MS_LITE_LOG: *** Start MSLite Demo ***'); - let output: Array = msliteNapi.runDemo(Array.from(float32View), resMgr); - console.warn('MS_LITE_WARN: output length = ', output.length, ';value = ', output.slice(0, 20)); - - // 取分类最大值top5 - this.max = 0; - this.maxIndex = 0; - this.maxArray = []; - this.maxIndexArray = []; - let newArray = output.filter(value => value !== this.max); - for (let n = 0; n < 5; n++) { - this.max = output[0]; - this.maxIndex = 0; - // 取最大值 - for (let m = 0; m < newArray.length; m++) { - if (newArray[m] > this.max) { - this.max = newArray[m]; - this.maxIndex = m; - } - } - this.maxArray.push(Math.round(this.max * 10000)); - this.maxIndexArray.push(this.maxIndex); - // filter函数 数组过滤函数 - newArray = newArray.filter(value => value !== this.max); - } - console.info('MS_LITE_LOG: max:' + this.maxArray); - console.info('MS_LITE_LOG: maxIndex:' + this.maxIndexArray); - console.info('MS_LITE_LOG: *** Finished MSLite Demo ***'); - }) - }) - // 5.关闭文件 - fileIo.closeSync(file); - } catch (err) { - console.error('MS_LITE_LOG: uri: open file fd failed.' + err); - } - }) - }) - }.width('100%') - } - .height('100%') - } +/* +* Copyright (c) 2024-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 resourceManager from '@ohos.resourceManager' +import fileIo from '@ohos.file.fs'; +import msliteNapi from 'libentry.so' +import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { BusinessError } from '@ohos.base'; +import image from '@ohos.multimedia.image'; +import { abilityAccessCtrl, Permissions } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG = 'MindSporeLite'; +const PERMISSIONS: Permissions[] = ['ohos.permission.READ_IMAGEVIDEO']; + +@Entry +@Component +struct Index { + @State message: string = 'MindSporeLite C Demo'; + @State modelName: string = 'mobilenetv2.ms'; + @State modelInputHeight: number = 224; + @State modelInputWidth: number = 224; + @State uris: Array = []; + @State max: number = 0; + @State maxIndex: number = 0; + @State maxArray: Array = []; + @State maxIndexArray: Array = []; + @State labelsNameMap: string[] = [ + 'Herd', 'Safari', 'Bangle', 'Cushion', 'Countertop', + 'Prom', 'Branch', 'Sports', 'Sky', 'Community', + 'Wheel', 'Cola', 'Tuxedo', 'Flowerpot', 'Team', + 'Computer', 'Unicycle', 'Brig', 'Aerospace engineering', 'Scuba diving', + 'Goggles', 'Fruit', 'Badminton', 'Horse', 'Sunglasses', + 'Fun', 'Prairie', 'Poster', 'Flag', 'Speedboat', + 'Eyelash', 'Veil', 'Mobile phone', 'Wheelbarrow', 'Saucer', + 'Leather', 'Drawer', 'Paper', 'Pier', 'Waterfowl', + 'Tights', 'Rickshaw', 'Vegetable', 'Handrail', 'Ice', + 'Metal', 'Flower', 'Wing', 'Silverware', 'Event', + 'Skyline', 'Money', 'Comics', 'Handbag', 'Porcelain', + 'Rodeo', 'Curtain', 'Tile', 'Human mouth', 'Army', + 'Menu', 'Boat', 'Snowboarding', 'Cairn terrier', 'Net', + 'Pasteles', 'Cup', 'Rugby', 'Pho', 'Cap', + 'Human hair', 'Surfing', 'Loveseat', 'Museum', 'Shipwreck', + 'Trunk (Tree)', 'Plush', 'Monochrome', 'Volcano', 'Rock', + 'Pillow', 'Presentation', 'Nebula', 'Subwoofer', 'Lake', + 'Sledding', 'Bangs', 'Tablecloth', 'Necklace', 'Swimwear', + 'Standing', 'Jeans', 'Carnival', 'Softball', 'Centrepiece', + 'Skateboarder', 'Cake', 'Dragon', 'Aurora', 'Skiing', + 'Bathroom', 'Dog', 'Needlework', 'Umbrella', 'Church', + 'Fire', 'Piano', 'Denim', 'Bridle', 'Cabinetry', + 'Lipstick', 'Ring', 'Television', 'Roller', 'Seal', + 'Concert', 'Product', 'News', 'Fast food', 'Horn (Animal)', + 'Tattoo', 'Bird', 'Bridegroom', 'Love', 'Helmet', + 'Dinosaur', 'Icing', 'Miniature', 'Tire', 'Toy', + 'Icicle', 'Jacket', 'Coffee', 'Mosque', 'Rowing', + 'Wetsuit', 'Camping', 'Underwater', 'Christmas', 'Gelato', + 'Whiteboard', 'Field', 'Ragdoll', 'Construction', 'Lampshade', + 'Palace', 'Meal', 'Factory', 'Cage', 'Clipper (Boat)', + 'Gymnastics', 'Turtle', 'Human foot', 'Marriage', 'Web page', + 'Human beard', 'Fog', 'Wool', 'Cappuccino', 'Lighthouse', + 'Lego', 'Sparkler', 'Sari', 'Model', 'Temple', + 'Beanie', 'Building', 'Waterfall', 'Penguin', 'Cave', + 'Stadium', 'Smile', 'Human hand', 'Park', 'Desk', + 'Shetland sheepdog', 'Bar', 'Eating', 'Neon', 'Dalmatian', + 'Crocodile', 'Wakeboarding', 'Longboard', 'Road', 'Race', + 'Kitchen', 'Odometer', 'Cliff', 'Fiction', 'School', + 'Interaction', 'Bullfighting', 'Boxer', 'Gown', 'Aquarium', + 'Superhero', 'Pie', 'Asphalt', 'Surfboard', 'Cheeseburger', + 'Screenshot', 'Supper', 'Laugh', 'Lunch', 'Party ', + 'Glacier', 'Bench', 'Grandparent', 'Sink', 'Pomacentridae', + 'Blazer', 'Brick', 'Space', 'Backpacking', 'Stuffed toy', + 'Sushi', 'Glitter', 'Bonfire', 'Castle', 'Marathon', + 'Pizza', 'Beach', 'Human ear', 'Racing', 'Sitting', + 'Iceberg', 'Shelf', 'Vehicle', 'Pop music', 'Playground', + 'Clown', 'Car', 'Rein', 'Fur', 'Musician', + 'Casino', 'Baby', 'Alcohol', 'Strap', 'Reef', + 'Balloon', 'Outerwear', 'Cathedral', 'Competition', 'Joker', + 'Blackboard', 'Bunk bed', 'Bear', 'Moon', 'Archery', + 'Polo', 'River', 'Fishing', 'Ferris wheel', 'Mortarboard', + 'Bracelet', 'Flesh', 'Statue', 'Farm', 'Desert', + 'Chain', 'Aircraft', 'Textile', 'Hot dog', 'Knitting', + 'Singer', 'Juice', 'Circus', 'Chair', 'Musical instrument', + 'Room', 'Crochet', 'Sailboat', 'Newspaper', 'Santa claus', + 'Swamp', 'Skyscraper', 'Skin', 'Rocket', 'Aviation', + 'Airliner', 'Garden', 'Ruins', 'Storm', 'Glasses', + 'Balance', 'Nail (Body part)', 'Rainbow', 'Soil ', 'Vacation ', + 'Moustache', 'Doily', 'Food', 'Bride ', 'Cattle', + 'Pocket', 'Infrastructure', 'Train', 'Gerbil', 'Fireworks', + 'Pet', 'Dam', 'Crew', 'Couch', 'Bathing', + 'Quilting', 'Motorcycle', 'Butterfly', 'Sled', 'Watercolor paint', + 'Rafting', 'Monument', 'Lightning', 'Sunset', 'Bumper', + 'Shoe', 'Waterskiing', 'Sneakers', 'Tower', 'Insect', + 'Pool', 'Placemat', 'Airplane', 'Plant', 'Jungle', + 'Armrest', 'Duck', 'Dress', 'Tableware', 'Petal', + 'Bus', 'Hanukkah', 'Forest', 'Hat', 'Barn', + 'Tubing', 'Snorkeling', 'Cool', 'Cookware and bakeware', 'Cycling', + 'Swing (Seat)', 'Muscle', 'Cat', 'Skateboard', 'Star', + 'Toe', 'Junk', 'Bicycle', 'Bedroom', 'Person', + 'Sand', 'Canyon', 'Tie', 'Twig', 'Sphynx', + 'Supervillain', 'Nightclub', 'Ranch', 'Pattern', 'Shorts', + 'Himalayan', 'Wall', 'Leggings', 'Windsurfing', 'Deejay', + 'Dance', 'Van', 'Bento', 'Sleep', 'Wine', + 'Picnic', 'Leisure', 'Dune', 'Crowd', 'Kayak', + 'Ballroom', 'Selfie', 'Graduation', 'Frigate', 'Mountain', + 'Dude', 'Windshield', 'Skiff', 'Class', 'Scarf', + 'Bull', 'Soccer', 'Bag', 'Basset hound', 'Tractor', + 'Swimming', 'Running', 'Track', 'Helicopter', 'Pitch', + 'Clock', 'Song', 'Jersey', 'Stairs', 'Flap', + 'Jewellery', 'Bridge', 'Cuisine', 'Bread', 'Caving', + 'Shell', 'Wreath', 'Roof', 'Cookie', 'Canoe' + ]; + + aboutToAppear() { + abilityAccessCtrl.createAtManager().requestPermissionsFromUser(getContext(this), PERMISSIONS).then((data) => { + if (data.authResults[0] == 0) { + hilog.info(0xFF00, TAG, '%{public}s', 'request permission success'); + } else { + hilog.info(0xFF00, TAG, '%{public}s', 'user rejected'); + } + }).catch((err: BusinessError) => { + hilog.error(0xFF00, TAG, '%{public}s', + `request permission failed, error message: ${(err as BusinessError).message}`); + }); + } + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold); + //图片显示 + Image(this.uris[0]).width(320).height(540).margin(15) + //显示分类最大值 + if (this.max) { + Text(this.labelsNameMap[this.maxIndexArray[0]] + + ': ' + + (this.maxArray[0] / 100).toString() + + '%\n' + + this.labelsNameMap[this.maxIndexArray[1]] + + ': ' + + (this.maxArray[1] / 100).toString() + + '%\n' + + this.labelsNameMap[this.maxIndexArray[2]] + + ': ' + + (this.maxArray[2] / 100).toString() + + '%\n' + + this.labelsNameMap[this.maxIndexArray[3]] + + ': ' + + (this.maxArray[3] / 100).toString() + + '%').focusable(true).fontSize(20) + } + Button() { + Text('photo') + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('40%') + .height('5%') + .onClick(() => { + let resMgr: resourceManager.ResourceManager = getContext().getApplicationContext().resourceManager; + + //获取相册图片 + //1.创建图片-视频类型文件选择选项实例 + let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + + //2.选择媒体文件类型和选择媒体文件的最大数目 + PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE + PhotoSelectOptions.maxSelectNumber = 1; // 选择媒体文件的最大数目 + + //3.创建图库选择器实例,调用select()接口拉起图库界面进行文件选择。文件选择成功后,返回 photoSelectResult 结果集。 + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + photoPicker.select(PhotoSelectOptions, + async (err: BusinessError, photoSelectResult: photoAccessHelper.PhotoSelectResult) => { + if (err) { + console.error('MS_LITE_ERR: PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); + return; + } + console.info('MS_LITE_LOG: PhotoViewPicker.select successfully, photoSelectResult uri: ' + + JSON.stringify(photoSelectResult)); + this.uris = photoSelectResult.photoUris; + console.info('MS_LITE_LOG: uri: ' + this.uris); + try { + // 预处理图片数据 + // 1.使用fs.openSync接口,通过uri打开这个文件得到fd + let file = fileIo.openSync(this.uris[0], fileIo.OpenMode.READ_ONLY); + console.info('MS_LITE_LOG: file fd: ' + file.fd); + + // 2.通过fd使用fs.readSync接口读取这个文件内的数据 + let inputBuffer = new ArrayBuffer(4096000); + let readLen = fileIo.readSync(file.fd, inputBuffer); + console.info('MS_LITE_LOG: readSync data to file succeed and inputBuffer size is:' + readLen); + + // 3.通过 PixelMap 预处理 + let imageSource = image.createImageSource(file.fd); + let pixelMap = await imageSource.createPixelMap({ editable: true }); + let info = await pixelMap.getImageInfo(); + console.info('MS_LITE_LOG: info.width = ' + info.size.width); + console.info('MS_LITE_LOG: info.height = ' + info.size.height); + + // 4. 获取图片buffer数据readBuffer,并进行处理 + pixelMap.scale(256.0 / info.size.width, 256.0 / info.size.height).then(() => { + pixelMap.crop({ + x: 16, + y: 16, + size: { height: this.modelInputHeight, width: this.modelInputWidth } + }) + .then(async () => { + let info = await pixelMap.getImageInfo(); + console.info('MS_LITE_LOG: crop info.width = ' + info.size.width); + console.info('MS_LITE_LOG: crop info.height = ' + info.size.height); + // 需要创建的像素buffer大小 + let readBuffer = new ArrayBuffer(this.modelInputHeight * this.modelInputWidth * 4); + await pixelMap.readPixelsToBuffer(readBuffer); + console.info('MS_LITE_LOG: Succeeded in reading image pixel data, buffer: ' + readBuffer.byteLength); + + // 处理readBuffer + const imageArr = + new Uint8Array(readBuffer.slice(0, this.modelInputHeight * this.modelInputWidth * 4)); + console.info('MS_LITE_LOG: imageArr length: ' + imageArr.length); + let means = [0.485, 0.456, 0.406]; + let stds = [0.229, 0.224, 0.225]; + let float32View = new Float32Array(this.modelInputHeight * this.modelInputWidth * 3); + let index = 0; + for (let i = 0; i < imageArr.length; i++) { + if ((i + 1) % 4 == 0) { + float32View[index] = (imageArr[i - 3] / 255.0 - means[0]) / stds[0]; // B + float32View[index+1] = (imageArr[i - 2] / 255.0 - means[1]) / stds[1]; // G + float32View[index+2] = (imageArr[i - 1] / 255.0 - means[2]) / stds[2]; // R + index += 3; + } + } + console.info('MS_LITE_LOG: float32View length: ' + float32View.length); + let printStr = 'float32View data:'; + for (let i = 0; i < 20; i++) { + printStr += ' ' + float32View[i]; + } + console.info('MS_LITE_LOG: float32View data: ' + printStr); + + // 调用c++的runDemo + console.info('MS_LITE_LOG: *** Start MSLite Demo ***'); + let output: Array = msliteNapi.runDemo(Array.from(float32View), resMgr); + console.warn('MS_LITE_WARN: output length = ', output.length, ';value = ', output.slice(0, 20)); + + // 取分类最大值top5 + this.max = 0; + this.maxIndex = 0; + this.maxArray = []; + this.maxIndexArray = []; + let newArray = output.filter(value => value !== this.max); + for (let n = 0; n < 5; n++) { + this.max = output[0]; + this.maxIndex = 0; + // 取最大值 + for (let m = 0; m < newArray.length; m++) { + if (newArray[m] > this.max) { + this.max = newArray[m]; + this.maxIndex = m; + } + } + this.maxArray.push(Math.round(this.max * 10000)); + this.maxIndexArray.push(this.maxIndex); + // filter函数 数组过滤函数 + newArray = newArray.filter(value => value !== this.max); + } + console.info('MS_LITE_LOG: max:' + this.maxArray); + console.info('MS_LITE_LOG: maxIndex:' + this.maxIndexArray); + console.info('MS_LITE_LOG: *** Finished MSLite Demo ***'); + }) + }) + // 5.关闭文件 + fileIo.closeSync(file); + } catch (err) { + console.error('MS_LITE_LOG: uri: open file fd failed.' + err); + } + }) + }) + }.width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/module.json5 index fcd2d37ece5edb6356de08fd29f184904f33adbb..07bd623c859e38eaf6db4fb50915d3d2392cd304 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/module.json5 @@ -1,61 +1,61 @@ -/* -* Copyright (c) 2024-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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.READ_IMAGEVIDEO", - "reason": "$string:read_image_video_permission", - "usedScene": { - "when": "inuse" - } - } - ] - } +/* +* Copyright (c) 2024-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:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.READ_IMAGEVIDEO", + "reason": "$string:read_image_video_permission", + "usedScene": { + "when": "inuse" + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets index 974d871dde9c26c1371874241ff783b958a0edcb..02ea87bfcb433b11aee3a6d1a92a53d92582baa1 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/ets/utils/ResourceUtil.ets @@ -1,23 +1,23 @@ -/* -* Copyright (c) 2024 Hunan OpenValley Digital Industry Development 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'; - -const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); - -export function getString(resourceData: Resource): string { - let manage = delegator.getAppContext().resourceManager; - return manage.getStringSync(resourceData); +/* +* Copyright (c) 2024 Hunan OpenValley Digital Industry Development 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'; + +const delegator = AbilityDelegatorRegistry.getAbilityDelegator(); + +export function getString(resourceData: Resource): string { + let manage = delegator.getAppContext().resourceManager; + return manage.getStringSync(resourceData); } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/module.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/module.json5 index adc1f0eda95d1fefceec0b4c2636732a9cd43d95..141839900c450d28ca3fcf4ad00c85d03d880e55 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* -* Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* +* Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/resources/base/element/string.json b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/resources/base/element/string.json index c3f097d6be02cf3ff9f478f9d4803ab2c3fe3237..5955cede45230a0d21762a57af8717d6955ded40 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/entry/src/ohosTest/resources/base/element/string.json @@ -1,24 +1,24 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - }, - { - "name": "completed", - "value": "完成" - }, - { - "name": "allow", - "value": "允许" - } - ] +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "completed", + "value": "完成" + }, + { + "name": "allow", + "value": "允许" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/hvigor/hvigor-config.json5 index 940738da0462ba11f81339fd69596998af587c7f..2fcddb4906de7749404fc70d2370d60d4d3867ff 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/hvigor/hvigor-config.json5 @@ -1,37 +1,37 @@ -/* -* Copyright (c) 2024 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. -*/ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - }, - "execution": { - // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ - // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ - } -} +/* +* Copyright (c) 2024 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. +*/ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + }, + "execution": { + // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */ + // "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": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */ + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/oh-package.json5 b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/oh-package.json5 index 506c2e28d783dba535a6f18af7301541f16a3222..46a1e640b576bdca23821cfb4b9ac3328645fd2c 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/oh-package.json5 @@ -1,29 +1,29 @@ -/* -* Copyright (c) 2024 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": "mindsporelitecdemo", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.16", - "@ohos/hamock": "1.0.0" - } -} +/* +* Copyright (c) 2024 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": "mindsporelitecdemo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.16", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/ohosTest.md b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/ohosTest.md index d05c51db3e190418386f6e2c83dd195b586dcbe9..4adddf549920776d178c4c37f63bdade7e813000 100644 --- a/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/ohosTest.md +++ b/code/DocsSample/ApplicationModels/MindSporeLiteCDemo/ohosTest.md @@ -1,9 +1,9 @@ -# MindSporeLiteCDemo 测试用例归档 - -## 用例表 - -|测试功能|预置条件|输入|预期输出|是否自动|测试结果| -|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| -|拉起应用| 设备正常运行| |成功拉起应用|是|Pass| -|查看预览界面Text和Button| 进入预览界面 | |预览界面存在Text和Button|是|Pass| +# MindSporeLiteCDemo 测试用例归档 + +## 用例表 + +|测试功能|预置条件|输入|预期输出|是否自动|测试结果| +|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------|--------------------------------| +|拉起应用| 设备正常运行| |成功拉起应用|是|Pass| +|查看预览界面Text和Button| 进入预览界面 | |预览界面存在Text和Button|是|Pass| |选取图片推理功能测试| 进入预览界面 | 点击photo按钮 |选取图片后进行推理|是|Pass| \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/app.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/app.json5 index 2492cc660ede4e638bbcd7c47615d5448f1bb956..3c846ef8bdc142b6199debb50e69814ed917312e 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.stagemodelabilitydevelop", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.stagemodelabilitydevelop", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/resources/base/element/string.json index a7353b08cda821698e3d000d43d95a972d32eb10..86a92ba52c0ca5cd1c2178f95878227feadafb95 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "StageModelAbilityDevelop" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "StageModelAbilityDevelop" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/build-profile.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/build-profile.json5 index b4ed08ad14b5ee78273c12abf7e1008511ed5ed0..9ab0a5df27801ebd16de2be7123dd7b40b3fb172 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/build-profile.json5 @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [ - - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/build-profile.json5 index 32345d66a3a76a65572893298ab9c48eb6a42c7c..8296d8e04da0bc5eb3a05c8e1e2c214645a82bea 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/oh-package.json5 index 60d792bb92f1a5b2723a5cc253e44842373b42ac..413a75299a923ac4b576b93e25422bd2c4086097 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts index dfe2d1244714051fbae39f60ea5ae7a213865870..f597be317de20abe76b218d56f734e40a4e17e53 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2023 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 default interface IIdlServiceExt { - processData(data: number, callback: ProcessDataCallback): void; - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void; -} - -export type ProcessDataCallback = (errCode: number, returnValue: number) => void; - -export type InsertDataToMapCallback = (errCode: number) => void; +/* + * Copyright (c) 2023 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 default interface IIdlServiceExt { + processData(data: number, callback: ProcessDataCallback): void; + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void; +} + +export type ProcessDataCallback = (errCode: number, returnValue: number) => void; + +export type InsertDataToMapCallback = (errCode: number) => void; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts index bf39e5c408b70f1a36b9167f7b56292643b61244..729991942b4902de163201432b777ccc852e1d3c 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2023 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 abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import bundleManager from '@ohos.bundle.bundleManager'; -import IdlServiceExtStub from './idl_service_ext_stub'; -import hilog from '@ohos.hilog'; -import rpc from '@ohos.rpc'; -import type { BusinessError } from '@ohos.base'; -import type { InsertDataToMapCallback } from './i_idl_service_ext'; -import type { ProcessDataCallback } from './i_idl_service_ext'; - -const ERR_OK = 0; -const TAG: string = '[IdlServiceExtImpl]'; -const DOMAIN_NUMBER: number = 0xFF00; -const ERR_DENY = -1; - -// 开发者需要在这个类型里对接口进行实现 -export default class ServiceExtImpl extends IdlServiceExtStub { - processData(data: number, callback: ProcessDataCallback): void { - // 开发者自行实现业务逻辑 - hilog.info(DOMAIN_NUMBER, TAG, `processData: ${data}`); - - let callerUid = rpc.IPCSkeleton.getCallingUid(); - bundleManager.getBundleNameByUid(callerUid).then((callerBundleName) => { - hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid: ' + callerBundleName); - // 对客户端包名进行识别 - if (callerBundleName !== 'com.samples.stagemodelabilitydevelop') { // 识别不通过 - hilog.info(DOMAIN_NUMBER, TAG, 'The caller bundle is not in trustlist, reject'); - return; - } - // 识别通过,执行正常业务逻辑 - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid failed: ' + err.message); - }); - - let callerTokenId = rpc.IPCSkeleton.getCallingTokenId(); - let accessManger = abilityAccessCtrl.createAtManager(); - // 所校验的具体权限由开发者自行选择,此处ohos.permission.GET_BUNDLE_INFO_PRIVILEGED只作为示例 - let grantStatus = accessManger.verifyAccessTokenSync(callerTokenId, 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'); - if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { - hilog.info(DOMAIN_NUMBER, TAG, 'PERMISSION_DENIED'); - callback(ERR_DENY, data); // 鉴权失败,返回错误 - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'verify access token success.'); - callback(ERR_OK, data + 1); // 鉴权通过,执行正常业务逻辑 - }; - - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { - // 开发者自行实现业务逻辑 - hilog.info(DOMAIN_NUMBER, TAG, `insertDataToMap, key: ${key} val: ${val}`); - callback(ERR_OK); - }; +/* + * Copyright (c) 2023 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 abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundleManager from '@ohos.bundle.bundleManager'; +import IdlServiceExtStub from './idl_service_ext_stub'; +import hilog from '@ohos.hilog'; +import rpc from '@ohos.rpc'; +import type { BusinessError } from '@ohos.base'; +import type { InsertDataToMapCallback } from './i_idl_service_ext'; +import type { ProcessDataCallback } from './i_idl_service_ext'; + +const ERR_OK = 0; +const TAG: string = '[IdlServiceExtImpl]'; +const DOMAIN_NUMBER: number = 0xFF00; +const ERR_DENY = -1; + +// 开发者需要在这个类型里对接口进行实现 +export default class ServiceExtImpl extends IdlServiceExtStub { + processData(data: number, callback: ProcessDataCallback): void { + // 开发者自行实现业务逻辑 + hilog.info(DOMAIN_NUMBER, TAG, `processData: ${data}`); + + let callerUid = rpc.IPCSkeleton.getCallingUid(); + bundleManager.getBundleNameByUid(callerUid).then((callerBundleName) => { + hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid: ' + callerBundleName); + // 对客户端包名进行识别 + if (callerBundleName !== 'com.samples.stagemodelabilitydevelop') { // 识别不通过 + hilog.info(DOMAIN_NUMBER, TAG, 'The caller bundle is not in trustlist, reject'); + return; + } + // 识别通过,执行正常业务逻辑 + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid failed: ' + err.message); + }); + + let callerTokenId = rpc.IPCSkeleton.getCallingTokenId(); + let accessManger = abilityAccessCtrl.createAtManager(); + // 所校验的具体权限由开发者自行选择,此处ohos.permission.GET_BUNDLE_INFO_PRIVILEGED只作为示例 + let grantStatus = accessManger.verifyAccessTokenSync(callerTokenId, 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'); + if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { + hilog.info(DOMAIN_NUMBER, TAG, 'PERMISSION_DENIED'); + callback(ERR_DENY, data); // 鉴权失败,返回错误 + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'verify access token success.'); + callback(ERR_OK, data + 1); // 鉴权通过,执行正常业务逻辑 + }; + + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { + // 开发者自行实现业务逻辑 + hilog.info(DOMAIN_NUMBER, TAG, `insertDataToMap, key: ${key} val: ${val}`); + callback(ERR_OK); + }; }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts index cffa32373c5c03e9855a05d88f02d20075810406..d77773020683b003b01566165fcf5b7ebbc24d5b 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts @@ -1,81 +1,81 @@ -/* - * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; -import type { InsertDataToMapCallback } from './i_idl_service_ext'; -import type IIdlServiceExt from './i_idl_service_ext'; -import hilog from '@ohos.hilog'; -import rpc from '@ohos.rpc'; - -const TAG: string = '[IdlServiceExtProxy]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class IdlServiceExtProxy implements IIdlServiceExt { - static readonly COMMAND_PROCESS_DATA = 1; - static readonly COMMAND_INSERT_DATA_TO_MAP = 2; - private proxy; - - constructor(proxy) { - this.proxy = proxy; - }; - - processData(data: number, callback: ProcessDataCallback): void { - let option = new rpc.MessageOption(); - let dataSequence = rpc.MessageSequence.create(); - let replySequence = rpc.MessageSequence.create(); - try { - dataSequence.writeInt(data); - this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_PROCESS_DATA, dataSequence, replySequence, option).then(function (result) { - if (result.errCode === 0) { - let errCodeVar = result.reply.readInt(); - if (errCodeVar !== 0) { - let returnValueVar = undefined; - callback(errCodeVar, returnValueVar); - return; - } - let returnValueVar = result.reply.readInt(); - callback(errCodeVar, returnValueVar); - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); - } - }); - } finally { - dataSequence.reclaim(); - replySequence.reclaim(); - }; - }; - - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { - let option = new rpc.MessageOption(); - let dataSequence = rpc.MessageSequence.create(); - let replySequence = rpc.MessageSequence.create(); - try { - dataSequence.writeString(key); - dataSequence.writeInt(val); - this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_INSERT_DATA_TO_MAP, dataSequence, replySequence, option).then(function (result) { - if (result.errCode === 0) { - let errCodeVar = result.reply.readInt(); - callback(errCodeVar); - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); - } - }); - } finally { - dataSequence.reclaim(); - replySequence.reclaim(); - }; - }; -}; - +/* + * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; +import type { InsertDataToMapCallback } from './i_idl_service_ext'; +import type IIdlServiceExt from './i_idl_service_ext'; +import hilog from '@ohos.hilog'; +import rpc from '@ohos.rpc'; + +const TAG: string = '[IdlServiceExtProxy]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class IdlServiceExtProxy implements IIdlServiceExt { + static readonly COMMAND_PROCESS_DATA = 1; + static readonly COMMAND_INSERT_DATA_TO_MAP = 2; + private proxy; + + constructor(proxy) { + this.proxy = proxy; + }; + + processData(data: number, callback: ProcessDataCallback): void { + let option = new rpc.MessageOption(); + let dataSequence = rpc.MessageSequence.create(); + let replySequence = rpc.MessageSequence.create(); + try { + dataSequence.writeInt(data); + this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_PROCESS_DATA, dataSequence, replySequence, option).then(function (result) { + if (result.errCode === 0) { + let errCodeVar = result.reply.readInt(); + if (errCodeVar !== 0) { + let returnValueVar = undefined; + callback(errCodeVar, returnValueVar); + return; + } + let returnValueVar = result.reply.readInt(); + callback(errCodeVar, returnValueVar); + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); + } + }); + } finally { + dataSequence.reclaim(); + replySequence.reclaim(); + }; + }; + + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { + let option = new rpc.MessageOption(); + let dataSequence = rpc.MessageSequence.create(); + let replySequence = rpc.MessageSequence.create(); + try { + dataSequence.writeString(key); + dataSequence.writeInt(val); + this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_INSERT_DATA_TO_MAP, dataSequence, replySequence, option).then(function (result) { + if (result.errCode === 0) { + let errCodeVar = result.reply.readInt(); + callback(errCodeVar); + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); + } + }); + } finally { + dataSequence.reclaim(); + replySequence.reclaim(); + }; + }; +}; + diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts index 9d200b23271a3565f5de2f39c5ae6efa41bc02a3..5a20eae5c8628025b26852d9dbb1b4e8e2591fd4 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts @@ -1,75 +1,75 @@ -/* - * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; -import type { InsertDataToMapCallback } from './i_idl_service_ext'; -import type IIdlServiceExt from './i_idl_service_ext'; -import hilog from '@ohos.hilog'; -import rpc from '@ohos.rpc'; - -const TAG: string = '[IdlServiceExtStub]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class IdlServiceExtStub extends rpc.RemoteObject implements IIdlServiceExt { - constructor(des: string) { - super(des); - }; - - async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise { - hilog.info(DOMAIN_NUMBER, TAG, 'onRemoteMessageRequest called, code = ' + code); - switch (code) { - case IdlServiceExtStub.COMMAND_PROCESS_DATA: { - let dataVar = data.readInt(); - let promise = new Promise((resolve, reject) => { - this.processData(dataVar, (errCode, returnValue) => { - reply.writeInt(errCode); - if (errCode === 0) { - reply.writeInt(returnValue); - } - resolve(); - }); - }); - await promise; - return true; - }; - case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: { - let keyVar = data.readString(); - let valVar = data.readInt(); - let promise = new Promise((resolve, reject) => { - this.insertDataToMap(keyVar, valVar, (errCode) => { - reply.writeInt(errCode); - resolve(); - }); - }); - await promise; - return true; - }; - default: { - hilog.info(DOMAIN_NUMBER, TAG, 'invalid request code' + code); - break; - } - } - return false; - } - - processData(data: number, callback: ProcessDataCallback): void { - }; - - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { - }; - - static readonly COMMAND_PROCESS_DATA = 1; - static readonly COMMAND_INSERT_DATA_TO_MAP = 2; +/* + * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; +import type { InsertDataToMapCallback } from './i_idl_service_ext'; +import type IIdlServiceExt from './i_idl_service_ext'; +import hilog from '@ohos.hilog'; +import rpc from '@ohos.rpc'; + +const TAG: string = '[IdlServiceExtStub]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class IdlServiceExtStub extends rpc.RemoteObject implements IIdlServiceExt { + constructor(des: string) { + super(des); + }; + + async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise { + hilog.info(DOMAIN_NUMBER, TAG, 'onRemoteMessageRequest called, code = ' + code); + switch (code) { + case IdlServiceExtStub.COMMAND_PROCESS_DATA: { + let dataVar = data.readInt(); + let promise = new Promise((resolve, reject) => { + this.processData(dataVar, (errCode, returnValue) => { + reply.writeInt(errCode); + if (errCode === 0) { + reply.writeInt(returnValue); + } + resolve(); + }); + }); + await promise; + return true; + }; + case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: { + let keyVar = data.readString(); + let valVar = data.readInt(); + let promise = new Promise((resolve, reject) => { + this.insertDataToMap(keyVar, valVar, (errCode) => { + reply.writeInt(errCode); + resolve(); + }); + }); + await promise; + return true; + }; + default: { + hilog.info(DOMAIN_NUMBER, TAG, 'invalid request code' + code); + break; + } + } + return false; + } + + processData(data: number, callback: ProcessDataCallback): void { + }; + + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { + }; + + static readonly COMMAND_PROCESS_DATA = 1; + static readonly COMMAND_INSERT_DATA_TO_MAP = 2; }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/collaborateability/CollaborateAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/collaborateability/CollaborateAbility.ts index 078734e912d9cd4779e80ca530d873e4931b6f63..bd938d896a74ecaf2dc5c17be4e76db9daeffa1b 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/collaborateability/CollaborateAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/collaborateability/CollaborateAbility.ts @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type window from '@ohos.window'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import type { BusinessError } from '@ohos.base'; -import type { Context } from '@ohos.abilityAccessCtrl'; -import type { PermissionRequestResult } from '@ohos.abilityAccessCtrl'; -import type { Permissions } from '@ohos.abilityAccessCtrl'; - -const permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; - -const TAG: string = '[CollaborateAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class CollaborateAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - // Main window is created, set main page for this ability - let context: Context = this.context; - let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); - // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 - atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => { - let grantStatus: Array = data.authResults; - let length: number = grantStatus.length; - for (let i = 0; i < length; i++) { - if (grantStatus[i] === 0) { - // 用户授权,可以继续访问目标操作 - } else { - // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 - return; - } - } - // 授权成功 - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); - }); - }; - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/page_collaborateability/Page_CollaborateAbility', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - }; -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type window from '@ohos.window'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import type { BusinessError } from '@ohos.base'; +import type { Context } from '@ohos.abilityAccessCtrl'; +import type { PermissionRequestResult } from '@ohos.abilityAccessCtrl'; +import type { Permissions } from '@ohos.abilityAccessCtrl'; + +const permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; + +const TAG: string = '[CollaborateAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class CollaborateAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + // Main window is created, set main page for this ability + let context: Context = this.context; + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 + atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => { + let grantStatus: Array = data.authResults; + let length: number = grantStatus.length; + for (let i = 0; i < length; i++) { + if (grantStatus[i] === 0) { + // 用户授权,可以继续访问目标操作 + } else { + // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 + return; + } + } + // 授权成功 + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); + }); + }; + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/page_collaborateability/Page_CollaborateAbility', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + }; +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/MultitonAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/MultitonAbility.ts index b2aed9ae4d73b82ddaae4286b9ea4c7b215c2e9e..8afc4d47bfd1566da28f5cd06f9f04628cd82ac5 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/MultitonAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/MultitonAbility.ts @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -const TAG: string = '[MultitonAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class MultitonAbility extends UIAbility { - onCreate(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/page_startupability/Page_Multiton', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } -}; +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +const TAG: string = '[MultitonAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class MultitonAbility extends UIAbility { + onCreate(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/page_startupability/Page_Multiton', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SingletonAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SingletonAbility.ts index f27bf7a6898addc17d70e343f233760344bad604..6ca907f7518b5210cf59fecb729641980f376de8 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SingletonAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SingletonAbility.ts @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -const TAG: string = '[SingletonAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class SingletonAbility extends UIAbility { - onCreate(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/page_startupability/Page_Singleton', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } -}; +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +const TAG: string = '[SingletonAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class SingletonAbility extends UIAbility { + onCreate(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/page_startupability/Page_Singleton', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedFirstAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedFirstAbility.ts index a97f18a3289c40c355cdc66f78f3dd57496e2e4f..233b088557dd956ad320ece4db01fbd11011bb02 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedFirstAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedFirstAbility.ts @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -export default class SpecifiedFirstAbility extends UIAbility { - - onWindowStageCreate(windowStage: window.WindowStage): void { - // 设置UI加载 - windowStage.loadContent('pages/page_startupability/Page_Specified_First', (err, data) => { - }); - } +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +export default class SpecifiedFirstAbility extends UIAbility { + + onWindowStageCreate(windowStage: window.WindowStage): void { + // 设置UI加载 + windowStage.loadContent('pages/page_startupability/Page_Specified_First', (err, data) => { + }); + } }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedSecondAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedSecondAbility.ts index 493b77bd22dd4d259c43e22f24871746081b2b53..aad0077087820b5aea34728f3d91b18c38382709 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedSecondAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/componentstartupability/SpecifiedSecondAbility.ts @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -export default class SpecifiedSecondAbility extends UIAbility { - - onWindowStageCreate(windowStage: window.WindowStage): void { - // 设置UI加载 - windowStage.loadContent('pages/page_startupability/Page_Specified_Second', (err, data) => { - }); - } +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +export default class SpecifiedSecondAbility extends UIAbility { + + onWindowStageCreate(windowStage: window.WindowStage): void { + // 设置UI加载 + windowStage.loadContent('pages/page_startupability/Page_Specified_Second', (err, data) => { + }); + } }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/contextability/ContextAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/contextability/ContextAbility.ts index cf3278aacf00fc7db58ffaecb0d9fc56ac1e81f1..a8e30282bc5a26ddd73936842bc22d8a8a3885db 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/contextability/ContextAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/contextability/ContextAbility.ts @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type window from '@ohos.window'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import type { Context } from '@ohos.abilityAccessCtrl'; -import type { PermissionRequestResult } from '@ohos.abilityAccessCtrl'; -import type { Permissions } from '@ohos.abilityAccessCtrl'; -import type { BusinessError } from '@ohos.base'; - -const permissions: Array = ['ohos.permission.GET_BUNDLE_INFO_PRIVILEGED']; -const TAG: string = '[ContextAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class ContextAbility extends UIAbility { - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.loadContent('pages/page_contextability/Page_ContextAbility', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - - // Main window is created, set main page for this ability - let context: Context = this.context; - let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); - // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 - atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => { - let grantStatus: Array = data.authResults; - let length: number = grantStatus.length; - for (let i = 0; i < length; i++) { - if (grantStatus[i] === 0) { - // 用户授权,可以继续访问目标操作 - } else { - // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 - return; - } - } - // 授权成功 - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); - }); - } -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type window from '@ohos.window'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import type { Context } from '@ohos.abilityAccessCtrl'; +import type { PermissionRequestResult } from '@ohos.abilityAccessCtrl'; +import type { Permissions } from '@ohos.abilityAccessCtrl'; +import type { BusinessError } from '@ohos.base'; + +const permissions: Array = ['ohos.permission.GET_BUNDLE_INFO_PRIVILEGED']; +const TAG: string = '[ContextAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class ContextAbility extends UIAbility { + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/page_contextability/Page_ContextAbility', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + + // Main window is created, set main page for this ability + let context: Context = this.context; + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 + atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => { + let grantStatus: Array = data.authResults; + let length: number = grantStatus.length; + for (let i = 0; i < length; i++) { + if (grantStatus[i] === 0) { + // 用户授权,可以继续访问目标操作 + } else { + // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 + return; + } + } + // 授权成功 + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/entryability/EntryAbility.ts index 082e8ee9d62ac223b6adb1573ab2608f216edab8..7105fbba709adc93a170b2b00d2d12890374c3f3 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,122 +1,122 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import type { BusinessError } from '@ohos.base'; -import type { Configuration } from '@ohos.app.ability.Configuration'; - -const TAG: string = '[EntryAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -let systemLanguage: string | undefined; // 系统当前语言 - -export default class EntryAbility extends UIAbility { - windowStage: window.WindowStage | undefined = undefined; - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - // Main window is created, set main page for this ability - let uiAbilityContext = this.context; - let applicationContext = this.context.getApplicationContext(); - systemLanguage = this.context.config.language; // UIAbility实例首次加载时,获取系统当前语言 - hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage is ${systemLanguage}`); - } - - onDestroy(): void { - // 系统资源的释放、数据的保存等 - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - this.windowStage = windowStage; - // 设置WindowStage的事件订阅(获焦/失焦、可见/不可见) - try { - windowStage.on('windowStageEvent', (data) => { - let stageEventType: window.WindowStageEventType = data; - switch (stageEventType) { - case window.WindowStageEventType.SHOWN: // 切到前台 - hilog.info(DOMAIN_NUMBER, TAG, 'windowStage foreground.'); - break; - case window.WindowStageEventType.ACTIVE: // 获焦状态 - hilog.info(DOMAIN_NUMBER, TAG, 'windowStage active.'); - break; - case window.WindowStageEventType.INACTIVE: // 失焦状态 - hilog.info(DOMAIN_NUMBER, TAG, 'windowStage inactive.'); - break; - case window.WindowStageEventType.HIDDEN: // 切到后台 - hilog.info(DOMAIN_NUMBER, TAG, 'windowStage background.'); - break; - default: - break; - } - }); - } catch (exception) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to enable the listener for window stage event changes. Cause:' + JSON.stringify(exception)); - }; - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - // 设置UI加载 - // Main window is created, set main page for this ability - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - // 释放UI资源 - // 例如在onWindowStageDestroy()中注销获焦/失焦等WindowStage事件 - try { - if (this.windowStage) { - this.windowStage.off('windowStageEvent'); - } - } catch (err) { - let code = (err as BusinessError).code; - let message = (err as BusinessError).message; - hilog.error(DOMAIN_NUMBER, TAG, `Failed to disable the listener for windowStageEvent. Code is ${code}, message is ${message}`); - }; - } - - onForeground(): void { - // 申请系统需要的资源,或者重新申请在onBackground()中释放的资源 - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // 释放UI不可见时无用的资源,或者在此回调中执行较为耗时的操作 - // 例如状态保存等 - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); - } - - onConfigurationUpdate(newConfig: Configuration): void { - hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); - - if (systemLanguage !== newConfig.language) { - hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); - systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 - } - } -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import type { BusinessError } from '@ohos.base'; +import type { Configuration } from '@ohos.app.ability.Configuration'; + +const TAG: string = '[EntryAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let systemLanguage: string | undefined; // 系统当前语言 + +export default class EntryAbility extends UIAbility { + windowStage: window.WindowStage | undefined = undefined; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + // Main window is created, set main page for this ability + let uiAbilityContext = this.context; + let applicationContext = this.context.getApplicationContext(); + systemLanguage = this.context.config.language; // UIAbility实例首次加载时,获取系统当前语言 + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage is ${systemLanguage}`); + } + + onDestroy(): void { + // 系统资源的释放、数据的保存等 + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + this.windowStage = windowStage; + // 设置WindowStage的事件订阅(获焦/失焦、可见/不可见) + try { + windowStage.on('windowStageEvent', (data) => { + let stageEventType: window.WindowStageEventType = data; + switch (stageEventType) { + case window.WindowStageEventType.SHOWN: // 切到前台 + hilog.info(DOMAIN_NUMBER, TAG, 'windowStage foreground.'); + break; + case window.WindowStageEventType.ACTIVE: // 获焦状态 + hilog.info(DOMAIN_NUMBER, TAG, 'windowStage active.'); + break; + case window.WindowStageEventType.INACTIVE: // 失焦状态 + hilog.info(DOMAIN_NUMBER, TAG, 'windowStage inactive.'); + break; + case window.WindowStageEventType.HIDDEN: // 切到后台 + hilog.info(DOMAIN_NUMBER, TAG, 'windowStage background.'); + break; + default: + break; + } + }); + } catch (exception) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to enable the listener for window stage event changes. Cause:' + JSON.stringify(exception)); + }; + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + // 设置UI加载 + // Main window is created, set main page for this ability + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + // 释放UI资源 + // 例如在onWindowStageDestroy()中注销获焦/失焦等WindowStage事件 + try { + if (this.windowStage) { + this.windowStage.off('windowStageEvent'); + } + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(DOMAIN_NUMBER, TAG, `Failed to disable the listener for windowStageEvent. Code is ${code}, message is ${message}`); + }; + } + + onForeground(): void { + // 申请系统需要的资源,或者重新申请在onBackground()中释放的资源 + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // 释放UI不可见时无用的资源,或者在此回调中执行较为耗时的操作 + // 例如状态保存等 + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); + } + + onConfigurationUpdate(newConfig: Configuration): void { + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); + + if (systemLanguage !== newConfig.language) { + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); + systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 + } + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/eventability/EventAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/eventability/EventAbility.ts index 34175f6a1bd2e235c71ad861225555430dd5d882..d39e41e3faf88c172fe09929db77caa204ca4764 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/eventability/EventAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/eventability/EventAbility.ts @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; -import type Want from '@ohos.app.ability.Want'; -import type { Context } from '@ohos.abilityAccessCtrl'; - -const TAG: string = '[EventAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EventAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - // 获取UIAbility实例的上下文 - let context = this.context; - // 获取eventHub - let eventhub = this.context.eventHub; - // 执行订阅操作 - eventhub.on('event1', this.eventFunc); - eventhub.on('event1', (data: string) => { - // 触发事件,完成相应的业务操作 - }); - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Page_EventHub', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - eventFunc(argOne: Context, argTwo: Context): void { - hilog.info(DOMAIN_NUMBER, TAG, '1. ' + `${argOne}, ${argTwo}`); - return; - } -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; +import type Want from '@ohos.app.ability.Want'; +import type { Context } from '@ohos.abilityAccessCtrl'; + +const TAG: string = '[EventAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EventAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 获取UIAbility实例的上下文 + let context = this.context; + // 获取eventHub + let eventhub = this.context.eventHub; + // 执行订阅操作 + eventhub.on('event1', this.eventFunc); + eventhub.on('event1', (data: string) => { + // 触发事件,完成相应的业务操作 + }); + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Page_EventHub', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + eventFunc(argOne: Context, argTwo: Context): void { + hilog.info(DOMAIN_NUMBER, TAG, '1. ' + `${argOne}, ${argTwo}`); + return; + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityA.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityA.ts index 0bf0b7e1212b2724ad19ecf91f0ff8a69d246846..54c7737bf5b953b8405cec101e73bb9a22badc79 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityA.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityA.ts @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; -import type Want from '@ohos.app.ability.Want'; - -export default class FuncAbilityA extends UIAbility { - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - // 接收调用方UIAbility传过来的参数 - let funcAbilityWant = want; - let info = funcAbilityWant?.parameters?.info; - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // 设置UI加载 - windowStage.loadContent('pages/page_funcability/Page_FuncAbilityA', (err, data) => { - }); - } -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; +import type Want from '@ohos.app.ability.Want'; + +export default class FuncAbilityA extends UIAbility { + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 接收调用方UIAbility传过来的参数 + let funcAbilityWant = want; + let info = funcAbilityWant?.parameters?.info; + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // 设置UI加载 + windowStage.loadContent('pages/page_funcability/Page_FuncAbilityA', (err, data) => { + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityB.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityB.ts index ea9e64845f7fa388470bb663e08494c4f74e6120..327885f7cfc8e504e4f643fcb5391e3c0ddfcddd 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityB.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/funcability/FuncAbilityB.ts @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -export default class FuncAbilityB extends UIAbility { - onWindowStageCreate(windowStage: window.WindowStage): void { - // 设置UI加载 - windowStage.loadContent('pages/page_funcability/Page_FuncAbilityB', (err, data) => { - }); - } -}; +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +export default class FuncAbilityB extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage): void { + // 设置UI加载 + windowStage.loadContent('pages/page_funcability/Page_FuncAbilityB', (err, data) => { + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/lifecycleability/LifecycleAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/lifecycleability/LifecycleAbility.ts index 8fc5a9312c71d4f63180e7ac7620b2af78e507a9..e00ecf84bff5f88cb527fc2520dfd16f685a37a0 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/lifecycleability/LifecycleAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/lifecycleability/LifecycleAbility.ts @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import type AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type window from '@ohos.window'; - -const TAG: string = '[LifecycleAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class LifecycleAbility extends UIAbility { - // 定义生命周期ID - lifecycleId: number = -1; - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - // 定义生命周期回调对象 - let abilityLifecycleCallback: AbilityLifecycleCallback = { - // 当UIAbility创建时被调用 - onAbilityCreate(uiAbility) { - hilog.info(DOMAIN_NUMBER, TAG, `onAbilityCreate uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - }, - // 当窗口创建时被调用 - onWindowStageCreate(uiAbility, windowStage: window.WindowStage) { - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageCreate uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageCreate windowStage: ${JSON.stringify(windowStage)}`); - }, - // 当窗口处于活动状态时被调用 - onWindowStageActive(uiAbility, windowStage: window.WindowStage) { - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageActive uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageActive windowStage: ${JSON.stringify(windowStage)}`); - }, - // 当窗口处于非活动状态时被调用 - onWindowStageInactive(uiAbility, windowStage: window.WindowStage) { - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageInactive uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageInactive windowStage: ${JSON.stringify(windowStage)}`); - }, - // 当窗口被销毁时被调用 - onWindowStageDestroy(uiAbility, windowStage: window.WindowStage) { - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageDestroy uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageDestroy windowStage: ${JSON.stringify(windowStage)}`); - }, - // 当UIAbility被销毁时被调用 - onAbilityDestroy(uiAbility) { - hilog.info(DOMAIN_NUMBER, TAG, `onAbilityDestroy uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - }, - // 当UIAbility从后台转到前台时触发回调 - onAbilityForeground(uiAbility) { - hilog.info(DOMAIN_NUMBER, TAG, `onAbilityForeground uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - }, - // 当UIAbility从前台转到后台时触发回调 - onAbilityBackground(uiAbility) { - hilog.info(DOMAIN_NUMBER, TAG, `onAbilityBackground uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - }, - // 当UIAbility迁移时被调用 - onAbilityContinue(uiAbility) { - hilog.info(DOMAIN_NUMBER, TAG, `onAbilityContinue uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); - } - }; - // 获取应用上下文 - let applicationContext = this.context.getApplicationContext(); - // 注册应用内生命周期回调 - this.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback); - hilog.info(DOMAIN_NUMBER, TAG, `register callback number: ${this.lifecycleId}`); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // 设置UI加载 - windowStage.loadContent('pages/page_funcability/Page_FuncAbilityA', (err, data) => { - }); - } - - onDestroy() : void { - // 获取应用上下文 - let applicationContext = this.context.getApplicationContext(); - // 取消应用内生命周期回调 - applicationContext.off('abilityLifecycle', this.lifecycleId); - } -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import type AbilityLifecycleCallback from '@ohos.app.ability.AbilityLifecycleCallback'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type window from '@ohos.window'; + +const TAG: string = '[LifecycleAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class LifecycleAbility extends UIAbility { + // 定义生命周期ID + lifecycleId: number = -1; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 定义生命周期回调对象 + let abilityLifecycleCallback: AbilityLifecycleCallback = { + // 当UIAbility创建时被调用 + onAbilityCreate(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityCreate uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当窗口创建时被调用 + onWindowStageCreate(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageCreate uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageCreate windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当窗口处于活动状态时被调用 + onWindowStageActive(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageActive uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageActive windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当窗口处于非活动状态时被调用 + onWindowStageInactive(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageInactive uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageInactive windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当窗口被销毁时被调用 + onWindowStageDestroy(uiAbility, windowStage: window.WindowStage) { + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageDestroy uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + hilog.info(DOMAIN_NUMBER, TAG, `onWindowStageDestroy windowStage: ${JSON.stringify(windowStage)}`); + }, + // 当UIAbility被销毁时被调用 + onAbilityDestroy(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityDestroy uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当UIAbility从后台转到前台时触发回调 + onAbilityForeground(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityForeground uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当UIAbility从前台转到后台时触发回调 + onAbilityBackground(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityBackground uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + }, + // 当UIAbility迁移时被调用 + onAbilityContinue(uiAbility) { + hilog.info(DOMAIN_NUMBER, TAG, `onAbilityContinue uiAbility.launchWant: ${JSON.stringify(uiAbility.launchWant)}`); + } + }; + // 获取应用上下文 + let applicationContext = this.context.getApplicationContext(); + // 注册应用内生命周期回调 + this.lifecycleId = applicationContext.on('abilityLifecycle', abilityLifecycleCallback); + hilog.info(DOMAIN_NUMBER, TAG, `register callback number: ${this.lifecycleId}`); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // 设置UI加载 + windowStage.loadContent('pages/page_funcability/Page_FuncAbilityA', (err, data) => { + }); + } + + onDestroy() : void { + // 获取应用上下文 + let applicationContext = this.context.getApplicationContext(); + // 取消应用内生命周期回调 + applicationContext.off('abilityLifecycle', this.lifecycleId); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/migrationability/MigrationAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/migrationability/MigrationAbility.ts index db20d3fc371b35627716b57a9c9395b36e4fc174..d4f0a9ea1e345fad7221b4147742e80f5f973b97 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/migrationability/MigrationAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/migrationability/MigrationAbility.ts @@ -1,142 +1,142 @@ -/* - * Copyright (c) 2023-2024 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import wantConstant from '@ohos.app.ability.wantConstant'; -import type window from '@ohos.window'; -import type { Context, PermissionRequestResult, Permissions } from '@ohos.abilityAccessCtrl'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import type { BusinessError } from '@ohos.base'; - -const permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; -const TAG: string = '[MigrationAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class MigrationAbility extends UIAbility { - storage: LocalStorage = new LocalStorage(); - - // 对端恢复 - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - - // 获取分布式数据 - if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { - // 将want保存的数据取出恢复 - let continueInput = ''; - if (want.parameters !== undefined) { - continueInput = JSON.stringify(want.parameters.data); - hilog.info(DOMAIN_NUMBER, TAG, `continue input ${continueInput}`); - } - // 将数据显示当前页面 - this.context.restoreWindowStage(this.storage); - } - // 调用原因为迁移时,设置状态为可迁移,应对冷启动情况 - this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { - hilog.info(DOMAIN_NUMBER, TAG, `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); - }); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/page_migrationability/Page_MigrationAbilityFirst', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - // Main window is created, set main page for this ability - let context: Context = this.context; - let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); - // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 - atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => { - let grantStatus: Array = data.authResults; - let length: number = grantStatus.length; - for (let i = 0; i < length; i++) { - if (grantStatus[i] === 0) { - // 用户授权,可以继续访问目标操作 - } else { - // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 - return; - } - } - // 授权成功 - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); - }); - } - - // 源端保存 - onContinue(wantParam: Record): AbilityConstant.OnContinueResult { - let version = wantParam.version; - let targetDevice = wantParam.targetDevice; - hilog.info(DOMAIN_NUMBER, TAG, `onContinue version = ${version}, targetDevice: ${targetDevice}`); // 准备迁移数据 - - // 获取源端版本号 - let versionSrc: number = -1; // 请填充具体获取版本号的代码 - - // 兼容性校验 - if (version !== versionSrc) { - // 在兼容性校验不通过时返回MISMATCH - return AbilityConstant.OnContinueResult.MISMATCH; - } - - // 将要迁移的数据保存在wantParam的自定义字段(例如data)中 - const continueInput = '迁移的数据'; - wantParam['data'] = continueInput; - - //设置不迁移页面栈&迁移后源端不退出 - wantParam[wantConstant.Params.SUPPORT_CONTINUE_PAGE_STACK_KEY] = false; - wantParam[wantConstant.Params.SUPPORT_CONTINUE_SOURCE_EXIT_KEY] = false; - - return AbilityConstant.OnContinueResult.AGREE; - } - - onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onNewWant'); - - if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { - // get user data from want params - let continueInput = ''; - if (want.parameters !== undefined) { - continueInput = JSON.stringify(want.parameters.data); - hilog.info(DOMAIN_NUMBER, TAG, `continue input ${JSON.stringify(continueInput)}`); - } - this.context.restoreWindowStage(this.storage); - } - - // 调用原因为迁移时,设置状态为可迁移,应对热启动情况 - if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { - this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { - hilog.info(DOMAIN_NUMBER, TAG, `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); - }); - } - } - - onWindowStageRestore(windowStage: window.WindowStage): void { - // 若不需要自动迁移页面栈信息,则需要在此处设置应用迁移后进入的页面 - windowStage.loadContent('pages/page_migrationability/Page_MigrationAbilityThird', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - }); - } -}; +/* + * Copyright (c) 2023-2024 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import type window from '@ohos.window'; +import type { Context, PermissionRequestResult, Permissions } from '@ohos.abilityAccessCtrl'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import type { BusinessError } from '@ohos.base'; + +const permissions: Array = ['ohos.permission.DISTRIBUTED_DATASYNC']; +const TAG: string = '[MigrationAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class MigrationAbility extends UIAbility { + storage: LocalStorage = new LocalStorage(); + + // 对端恢复 + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + + // 获取分布式数据 + if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { + // 将want保存的数据取出恢复 + let continueInput = ''; + if (want.parameters !== undefined) { + continueInput = JSON.stringify(want.parameters.data); + hilog.info(DOMAIN_NUMBER, TAG, `continue input ${continueInput}`); + } + // 将数据显示当前页面 + this.context.restoreWindowStage(this.storage); + } + // 调用原因为迁移时,设置状态为可迁移,应对冷启动情况 + this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { + hilog.info(DOMAIN_NUMBER, TAG, `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); + }); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/page_migrationability/Page_MigrationAbilityFirst', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + // Main window is created, set main page for this ability + let context: Context = this.context; + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + // requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗 + atManager.requestPermissionsFromUser(context, permissions).then((data: PermissionRequestResult) => { + let grantStatus: Array = data.authResults; + let length: number = grantStatus.length; + for (let i = 0; i < length; i++) { + if (grantStatus[i] === 0) { + // 用户授权,可以继续访问目标操作 + } else { + // 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限 + return; + } + } + // 授权成功 + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, `Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`); + }); + } + + // 源端保存 + onContinue(wantParam: Record): AbilityConstant.OnContinueResult { + let version = wantParam.version; + let targetDevice = wantParam.targetDevice; + hilog.info(DOMAIN_NUMBER, TAG, `onContinue version = ${version}, targetDevice: ${targetDevice}`); // 准备迁移数据 + + // 获取源端版本号 + let versionSrc: number = -1; // 请填充具体获取版本号的代码 + + // 兼容性校验 + if (version !== versionSrc) { + // 在兼容性校验不通过时返回MISMATCH + return AbilityConstant.OnContinueResult.MISMATCH; + } + + // 将要迁移的数据保存在wantParam的自定义字段(例如data)中 + const continueInput = '迁移的数据'; + wantParam['data'] = continueInput; + + //设置不迁移页面栈&迁移后源端不退出 + wantParam[wantConstant.Params.SUPPORT_CONTINUE_PAGE_STACK_KEY] = false; + wantParam[wantConstant.Params.SUPPORT_CONTINUE_SOURCE_EXIT_KEY] = false; + + return AbilityConstant.OnContinueResult.AGREE; + } + + onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onNewWant'); + + if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { + // get user data from want params + let continueInput = ''; + if (want.parameters !== undefined) { + continueInput = JSON.stringify(want.parameters.data); + hilog.info(DOMAIN_NUMBER, TAG, `continue input ${JSON.stringify(continueInput)}`); + } + this.context.restoreWindowStage(this.storage); + } + + // 调用原因为迁移时,设置状态为可迁移,应对热启动情况 + if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { + this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { + hilog.info(DOMAIN_NUMBER, TAG, `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); + }); + } + } + + onWindowStageRestore(windowStage: window.WindowStage): void { + // 若不需要自动迁移页面栈信息,则需要在此处设置应用迁移后进入的页面 + windowStage.loadContent('pages/page_migrationability/Page_MigrationAbilityThird', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/myabilitystage/MyAbilityStage.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/myabilitystage/MyAbilityStage.ts index b9ce6c70719818e967f988302900999f203501d7..d7738ef4b06345837b31feb6f8b60e75c5fa7d13 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/myabilitystage/MyAbilityStage.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/myabilitystage/MyAbilityStage.ts @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2023 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 AbilityStage from '@ohos.app.ability.AbilityStage'; -import type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import type Want from '@ohos.app.ability.Want'; -import type { Configuration } from '@ohos.app.ability.Configuration'; - -const TAG: string = '[MyAbilityStage]'; -const DOMAIN_NUMBER: number = 0xFF00; - -let systemLanguage: string | undefined; // 系统当前语言 - -export default class MyAbilityStage extends AbilityStage { - onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, `onNewWant, want: ${want.abilityName}`); - hilog.info(DOMAIN_NUMBER, TAG, `onNewWant, launchParam: ${JSON.stringify(launchParam)}`); - } - onCreate(): void { - // 应用的HAP在首次加载的时,为该Module初始化操作 - systemLanguage = this.context.config.language; // Module首次加载时,获取系统当前语言 - hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage is ${systemLanguage}`); - let abilityStageContext = this.context; - } - onAcceptWant(want: Want): string { - // 仅specified模式下触发 - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting SpecifiedAbility'); - // 在被调用方的AbilityStage中,针对启动模式为specified的UIAbility返回一个UIAbility实例对应的一个Key值 - // 当前示例指的是module1 Module的SpecifiedAbility - if (want.abilityName === 'SpecifiedFirstAbility' || want.abilityName === 'SpecifiedSecondAbility') { - // 返回的字符串Key标识为自定义拼接的字符串内容 - if (want.parameters) { - return `SpecifiedAbilityInstance_${want.parameters.instanceKey}`; - } - } - return 'MyAbilityStage'; - } - onMemoryLevel(level: AbilityConstant.MemoryLevel): void { - // 根据系统可用内存的变化情况,释放不必要的内存 - } - onConfigurationUpdate(newConfig: Configuration): void { - hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdate, language: ${newConfig.language}`); - hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); - - if (systemLanguage !== newConfig.language) { - hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); - systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 - } - } -}; +/* + * Copyright (c) 2023 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 AbilityStage from '@ohos.app.ability.AbilityStage'; +import type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import type Want from '@ohos.app.ability.Want'; +import type { Configuration } from '@ohos.app.ability.Configuration'; + +const TAG: string = '[MyAbilityStage]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let systemLanguage: string | undefined; // 系统当前语言 + +export default class MyAbilityStage extends AbilityStage { + onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, `onNewWant, want: ${want.abilityName}`); + hilog.info(DOMAIN_NUMBER, TAG, `onNewWant, launchParam: ${JSON.stringify(launchParam)}`); + } + onCreate(): void { + // 应用的HAP在首次加载的时,为该Module初始化操作 + systemLanguage = this.context.config.language; // Module首次加载时,获取系统当前语言 + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage is ${systemLanguage}`); + let abilityStageContext = this.context; + } + onAcceptWant(want: Want): string { + // 仅specified模式下触发 + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting SpecifiedAbility'); + // 在被调用方的AbilityStage中,针对启动模式为specified的UIAbility返回一个UIAbility实例对应的一个Key值 + // 当前示例指的是module1 Module的SpecifiedAbility + if (want.abilityName === 'SpecifiedFirstAbility' || want.abilityName === 'SpecifiedSecondAbility') { + // 返回的字符串Key标识为自定义拼接的字符串内容 + if (want.parameters) { + return `SpecifiedAbilityInstance_${want.parameters.instanceKey}`; + } + } + return 'MyAbilityStage'; + } + onMemoryLevel(level: AbilityConstant.MemoryLevel): void { + // 根据系统可用内存的变化情况,释放不必要的内存 + } + onConfigurationUpdate(newConfig: Configuration): void { + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdate, language: ${newConfig.language}`); + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); + + if (systemLanguage !== newConfig.language) { + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); + systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 + } + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_Context.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_Context.ets index 7b35f87160795cbeb0b7d1e3c61b3f60305b9db6..898658313c866fc9b0def90e1acaf888028c03d4 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_Context.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_Context.ets @@ -1,274 +1,274 @@ -/* - * Copyright (c) 2023 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 contextConstant from '@ohos.app.ability.contextConstant'; -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction' -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; - -const TAG: string = '[Page_Context]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_Context { - - private context = getContext(this) as common.UIAbilityContext; - - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.Context01')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.MethodOneForObtainingApplicationFilePath')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let applicationContext = this.context.getApplicationContext(); - let cacheDir = applicationContext.cacheDir; - let tempDir = applicationContext.tempDir; - let filesDir = applicationContext.filesDir; - let databaseDir = applicationContext.databaseDir; - let bundleCodeDir = applicationContext.bundleCodeDir; - let distributedFilesDir = applicationContext.distributedFilesDir; - let preferencesDir = applicationContext.preferencesDir; - // 获取应用文件路径 - let filePath = tempDir + 'test.txt'; - hilog.info(DOMAIN_NUMBER, TAG, `filePath: ${filePath}`); - if (filePath !== null) { - promptAction.showToast({ - message: filePath - }); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.MethodOneTwoObtainingApplicationFilePath')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let cacheDir = this.context.cacheDir; - let tempDir = this.context.tempDir; - let filesDir = this.context.filesDir; - let databaseDir = this.context.databaseDir; - let bundleCodeDir = this.context.bundleCodeDir; - let distributedFilesDir = this.context.distributedFilesDir; - let preferencesDir = this.context.preferencesDir; - // 获取应用文件路径 - let filePath = tempDir + 'test.txt'; - hilog.info(DOMAIN_NUMBER, TAG, `filePath: ${filePath}`); - if (filePath !== null) { - promptAction.showToast({ - message: filePath - }); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.SwitchToEL1')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - // 存储普通信息前,切换到EL1设备级加密 - if (this.context.area === contextConstant.AreaMode.EL2) { // 获取area - this.context.area = contextConstant.AreaMode.EL1; // 修改area - promptAction.showToast({ - message: $r('app.string.SwitchToEL1') - }); - } - // 存储普通信息 - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.SwitchToEL2')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - // 存储敏感信息前,切换到EL2用户级加密 - if (this.context.area === contextConstant.AreaMode.EL1) { // 获取area - this.context.area = contextConstant.AreaMode.EL2; // 修改area - promptAction.showToast({ - message: $r('app.string.SwitchToEL2') - }); - } - // 存储敏感信息 - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.Context04')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(304) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'ContextAbility', - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ContextAbility.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ContextAbility. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.Context05')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(304) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'LifecycleAbility', - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting LifecycleAbility.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start LifecycleAbility. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 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 contextConstant from '@ohos.app.ability.contextConstant'; +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction' +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; + +const TAG: string = '[Page_Context]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_Context { + + private context = getContext(this) as common.UIAbilityContext; + + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.Context01')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.MethodOneForObtainingApplicationFilePath')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let applicationContext = this.context.getApplicationContext(); + let cacheDir = applicationContext.cacheDir; + let tempDir = applicationContext.tempDir; + let filesDir = applicationContext.filesDir; + let databaseDir = applicationContext.databaseDir; + let bundleCodeDir = applicationContext.bundleCodeDir; + let distributedFilesDir = applicationContext.distributedFilesDir; + let preferencesDir = applicationContext.preferencesDir; + // 获取应用文件路径 + let filePath = tempDir + 'test.txt'; + hilog.info(DOMAIN_NUMBER, TAG, `filePath: ${filePath}`); + if (filePath !== null) { + promptAction.showToast({ + message: filePath + }); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.MethodOneTwoObtainingApplicationFilePath')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let cacheDir = this.context.cacheDir; + let tempDir = this.context.tempDir; + let filesDir = this.context.filesDir; + let databaseDir = this.context.databaseDir; + let bundleCodeDir = this.context.bundleCodeDir; + let distributedFilesDir = this.context.distributedFilesDir; + let preferencesDir = this.context.preferencesDir; + // 获取应用文件路径 + let filePath = tempDir + 'test.txt'; + hilog.info(DOMAIN_NUMBER, TAG, `filePath: ${filePath}`); + if (filePath !== null) { + promptAction.showToast({ + message: filePath + }); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.SwitchToEL1')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + // 存储普通信息前,切换到EL1设备级加密 + if (this.context.area === contextConstant.AreaMode.EL2) { // 获取area + this.context.area = contextConstant.AreaMode.EL1; // 修改area + promptAction.showToast({ + message: $r('app.string.SwitchToEL1') + }); + } + // 存储普通信息 + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.SwitchToEL2')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + // 存储敏感信息前,切换到EL2用户级加密 + if (this.context.area === contextConstant.AreaMode.EL1) { // 获取area + this.context.area = contextConstant.AreaMode.EL2; // 修改area + promptAction.showToast({ + message: $r('app.string.SwitchToEL2') + }); + } + // 存储敏感信息 + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.Context04')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(304) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'ContextAbility', + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ContextAbility.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ContextAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.Context05')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(304) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'LifecycleAbility', + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting LifecycleAbility.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start LifecycleAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_EventHub.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_EventHub.ets index 27617c561430817469218eba7670884011e0ae00..57ef928ae6f5d12b613b4d6b7767e175d00b81c9 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_EventHub.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_EventHub.ets @@ -1,127 +1,127 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import promptAction from '@ohos.promptAction' -import Want from '@ohos.app.ability.Want'; - -@Entry -@Component -struct Page_EventHub { - - private context = getContext(this) as common.UIAbilityContext; - - eventHubFunc() : void { - // 不带参数触发自定义“event1”事件 - this.context.eventHub.emit('event1'); - // 带1个参数触发自定义“event1”事件 - this.context.eventHub.emit('event1', 1); - // 带2个参数触发自定义“event1”事件 - this.context.eventHub.emit('event1', 2, 'test'); - // 开发者可以根据实际的业务场景设计事件传递的参数 - } - - startAbilityTest() : void { - let want: Want = { - // Want参数信息 - }; - this.context.startAbility(want); - } - - // 页面展示 - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.DataSynchronization')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.EventHubFuncA')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - this.eventHubFunc(); - promptAction.showToast({ - message: $r('app.string.EventHubFuncA') - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.EventHubFuncB')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - // context为UIAbility实例的AbilityContext - this.context.eventHub.off('event1'); - promptAction.showToast({ - message: $r('app.string.EventHubFuncB') - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import promptAction from '@ohos.promptAction' +import Want from '@ohos.app.ability.Want'; + +@Entry +@Component +struct Page_EventHub { + + private context = getContext(this) as common.UIAbilityContext; + + eventHubFunc() : void { + // 不带参数触发自定义“event1”事件 + this.context.eventHub.emit('event1'); + // 带1个参数触发自定义“event1”事件 + this.context.eventHub.emit('event1', 1); + // 带2个参数触发自定义“event1”事件 + this.context.eventHub.emit('event1', 2, 'test'); + // 开发者可以根据实际的业务场景设计事件传递的参数 + } + + startAbilityTest() : void { + let want: Want = { + // Want参数信息 + }; + this.context.startAbility(want); + } + + // 页面展示 + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.DataSynchronization')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.EventHubFuncA')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + this.eventHubFunc(); + promptAction.showToast({ + message: $r('app.string.EventHubFuncA') + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.EventHubFuncB')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + // context为UIAbility实例的AbilityContext + this.context.eventHub.off('event1'); + promptAction.showToast({ + message: $r('app.string.EventHubFuncB') + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_ServiceExtensionAbility.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_ServiceExtensionAbility.ets index 29228d1554004692fb43baab0e7ff4dac5bad4b9..94a433b750bf5be99e71738af3303c5234c8f78d 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_ServiceExtensionAbility.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_ServiceExtensionAbility.ets @@ -1,295 +1,295 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import deviceManager from '@ohos.distributedDeviceManager'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction'; -import rpc from '@ohos.rpc'; -import Want from '@ohos.app.ability.Want'; -// 客户端需要将服务端对外提供的idl_service_ext_proxy.ts导入到本地工程中 -import IdlServiceExtProxy from '../IdlServiceExt/idl_service_ext_proxy'; - -import { BusinessError } from '@ohos.base'; - -const TAG: string = '[Page_ServiceExtensionAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -let connectionId: number; -let dmClass: deviceManager.DeviceManager; - -let want: Want = { - deviceId: '', - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'ServiceExtAbility' -}; - -let options: common.ConnectOptions = { - onConnect(elementName, remote: rpc.IRemoteObject): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onConnect callback'); - if (remote === null) { - hilog.info(DOMAIN_NUMBER, TAG, `onConnect remote is null`); - return; - } - let serviceExtProxy: IdlServiceExtProxy = new IdlServiceExtProxy(remote); - // 通过接口调用的方式进行通信,屏蔽了RPC通信的细节,简洁明了 - serviceExtProxy.processData(1, (errorCode: number, retVal: number) => { - hilog.info(DOMAIN_NUMBER, TAG, `processData, errorCode: ${errorCode}, retVal: ${retVal}`); - }); - serviceExtProxy.insertDataToMap('theKey', 1, (errorCode: number) => { - hilog.info(DOMAIN_NUMBER, TAG, `insertDataToMap, errorCode: ${errorCode}`); - }) - }, - onDisconnect(elementName): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect callback'); - }, - onFailed(code: number): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onFailed callback', JSON.stringify(code)); - } -}; - -function getRemoteDeviceId(): string | undefined { - if (typeof dmClass === 'object' && dmClass !== null) { - let list = dmClass.getAvailableDeviceListSync(); - hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(dmClass), JSON.stringify(list)); - if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { - hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: list is null'); - return; - } - if (list.length === 0) { - hilog.info(DOMAIN_NUMBER, TAG, `getRemoteDeviceId err: list is empty`); - return; - } - return list[0].networkId; - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: dmClass is null'); - return; - } -} - -@Entry -@Component -struct Page_ServiceExtensionAbility { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.ServiceExtension')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row() { - Text($r('app.string.StartBackendService')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'ServiceExtAbility' - }; - context.startServiceExtensionAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ServiceExtensionAbility.'); - // 成功启动后台服务 - promptAction.showToast({ - message: $r('app.string.SuccessfullyStartBackendService') - }); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.StopStartedBackendService')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'ServiceExtAbility' - }; - context.stopServiceExtensionAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in stopping ServiceExtensionAbility.'); - promptAction.showToast({ - message: $r('app.string.SuccessfullyStoppedAStartedBackendService') - }); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to stop ServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.StopBackendServices')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - context.terminateSelf().then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in terminating self.'); - // 成功停止当前后台服务 - promptAction.showToast({ - message: $r('app.string.SuccessfullyStopStartedBackendService') - }); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.ConnectBackendService')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - // 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入 - connectionId = context.connectServiceExtensionAbility(want, options); - // 成功连接后台服务 - promptAction.showToast({ - message: $r('app.string.SuccessfullyConnectBackendService') - }); - // connectionId = context.connectAbility(want, options); - hilog.info(DOMAIN_NUMBER, TAG, `connectionId is : ${connectionId}`); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.DisconnectBackendService')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - // connectionId为调用connectServiceExtensionAbility接口时的返回值,需开发者自行维护 - context.disconnectServiceExtensionAbility(connectionId).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility success'); - // 成功断连后台服务 - promptAction.showToast({ - message: $r('app.string.SuccessfullyDisconnectBackendService') - }); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility failed'); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import deviceManager from '@ohos.distributedDeviceManager'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction'; +import rpc from '@ohos.rpc'; +import Want from '@ohos.app.ability.Want'; +// 客户端需要将服务端对外提供的idl_service_ext_proxy.ts导入到本地工程中 +import IdlServiceExtProxy from '../IdlServiceExt/idl_service_ext_proxy'; + +import { BusinessError } from '@ohos.base'; + +const TAG: string = '[Page_ServiceExtensionAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +let connectionId: number; +let dmClass: deviceManager.DeviceManager; + +let want: Want = { + deviceId: '', + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'ServiceExtAbility' +}; + +let options: common.ConnectOptions = { + onConnect(elementName, remote: rpc.IRemoteObject): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onConnect callback'); + if (remote === null) { + hilog.info(DOMAIN_NUMBER, TAG, `onConnect remote is null`); + return; + } + let serviceExtProxy: IdlServiceExtProxy = new IdlServiceExtProxy(remote); + // 通过接口调用的方式进行通信,屏蔽了RPC通信的细节,简洁明了 + serviceExtProxy.processData(1, (errorCode: number, retVal: number) => { + hilog.info(DOMAIN_NUMBER, TAG, `processData, errorCode: ${errorCode}, retVal: ${retVal}`); + }); + serviceExtProxy.insertDataToMap('theKey', 1, (errorCode: number) => { + hilog.info(DOMAIN_NUMBER, TAG, `insertDataToMap, errorCode: ${errorCode}`); + }) + }, + onDisconnect(elementName): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect callback'); + }, + onFailed(code: number): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onFailed callback', JSON.stringify(code)); + } +}; + +function getRemoteDeviceId(): string | undefined { + if (typeof dmClass === 'object' && dmClass !== null) { + let list = dmClass.getAvailableDeviceListSync(); + hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(dmClass), JSON.stringify(list)); + if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { + hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: list is null'); + return; + } + if (list.length === 0) { + hilog.info(DOMAIN_NUMBER, TAG, `getRemoteDeviceId err: list is empty`); + return; + } + return list[0].networkId; + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: dmClass is null'); + return; + } +} + +@Entry +@Component +struct Page_ServiceExtensionAbility { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.ServiceExtension')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row() { + Text($r('app.string.StartBackendService')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'ServiceExtAbility' + }; + context.startServiceExtensionAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ServiceExtensionAbility.'); + // 成功启动后台服务 + promptAction.showToast({ + message: $r('app.string.SuccessfullyStartBackendService') + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.StopStartedBackendService')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'ServiceExtAbility' + }; + context.stopServiceExtensionAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in stopping ServiceExtensionAbility.'); + promptAction.showToast({ + message: $r('app.string.SuccessfullyStoppedAStartedBackendService') + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to stop ServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.StopBackendServices')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + context.terminateSelf().then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in terminating self.'); + // 成功停止当前后台服务 + promptAction.showToast({ + message: $r('app.string.SuccessfullyStopStartedBackendService') + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.ConnectBackendService')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + // 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入 + connectionId = context.connectServiceExtensionAbility(want, options); + // 成功连接后台服务 + promptAction.showToast({ + message: $r('app.string.SuccessfullyConnectBackendService') + }); + // connectionId = context.connectAbility(want, options); + hilog.info(DOMAIN_NUMBER, TAG, `connectionId is : ${connectionId}`); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.DisconnectBackendService')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + // connectionId为调用connectServiceExtensionAbility接口时的返回值,需开发者自行维护 + context.disconnectServiceExtensionAbility(connectionId).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility success'); + // 成功断连后台服务 + promptAction.showToast({ + message: $r('app.string.SuccessfullyDisconnectBackendService') + }); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility failed'); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartFAModel.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartFAModel.ets index 70602401991983db575ea5422f4e6cf44aa43812..b36a7138e623a7c1056deba295ccb50f03c5c4ee 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartFAModel.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartFAModel.ets @@ -1,208 +1,208 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction' -import Want from '@ohos.app.ability.Want'; - -import { BusinessError } from '@ohos.base'; - -const TAG: string = '[Page_StartFAModel]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_StartFAModel { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.StageModelinteractiveWithFAModel')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.StartFAModel')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - bundleName: 'com.samples.famodelabilitydevelop', - abilityName: 'com.samples.famodelabilitydevelop.MainAbility' - }; - this.context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Start Ability successfully.'); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Ability failed: ` + JSON.stringify(error)); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.StartFAModelWithResult')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - bundleName: 'com.samples.famodelabilitydevelop', - abilityName: 'com.samples.famodelabilitydevelop.MainAbility', - }; - this.context.startAbilityForResult(want).then((result) => { - hilog.info(DOMAIN_NUMBER, TAG, 'Ability verify result: ' + JSON.stringify(result)); - if (result !== null) { - promptAction.showToast({ - message : JSON.stringify(result) - }); - } - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Ability failed: ` + JSON.stringify(error)); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.ServiceAbility')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(304) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - let want: Want = { - bundleName: 'com.samples.famodelabilitydevelop', - abilityName: 'com.samples.famodelabilitydevelop.ServiceAbility', - } - let options: common.ConnectOptions = { - onConnect: (elementName, proxy) => { - hilog.info(DOMAIN_NUMBER, TAG, 'onConnect called.'); - promptAction.showToast({ - message: $r('app.string.ConnectFAServiceAbility') - }); - }, - onDisconnect: (elementName) => { - hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect called.'); - }, - onFailed: (code) => { - hilog.info(DOMAIN_NUMBER, TAG, 'onFailed code is: ' + code); - } - }; - let connectionId = this.context.connectServiceExtensionAbility(want, options); - hilog.info(DOMAIN_NUMBER, TAG, 'connectionId is ' + JSON.stringify(connectionId)); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.PageAbility')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(304) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - let want: Want = { - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'ServiceExtAbility', - parameters:{ - key: 'ConnectFaPageAbility' - } - } - this.context.startServiceExtensionAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'startServiceExtensionAbility successfully'); - }).catch((err: BusinessError) =>{ - hilog.info(DOMAIN_NUMBER, TAG, 'startServiceExtensionAbility fail, err is: ' + JSON.stringify(err)); - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction' +import Want from '@ohos.app.ability.Want'; + +import { BusinessError } from '@ohos.base'; + +const TAG: string = '[Page_StartFAModel]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_StartFAModel { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.StageModelinteractiveWithFAModel')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.StartFAModel')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + bundleName: 'com.samples.famodelabilitydevelop', + abilityName: 'com.samples.famodelabilitydevelop.MainAbility' + }; + this.context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Start Ability successfully.'); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Ability failed: ` + JSON.stringify(error)); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.StartFAModelWithResult')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + bundleName: 'com.samples.famodelabilitydevelop', + abilityName: 'com.samples.famodelabilitydevelop.MainAbility', + }; + this.context.startAbilityForResult(want).then((result) => { + hilog.info(DOMAIN_NUMBER, TAG, 'Ability verify result: ' + JSON.stringify(result)); + if (result !== null) { + promptAction.showToast({ + message : JSON.stringify(result) + }); + } + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Ability failed: ` + JSON.stringify(error)); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.ServiceAbility')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(304) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + let want: Want = { + bundleName: 'com.samples.famodelabilitydevelop', + abilityName: 'com.samples.famodelabilitydevelop.ServiceAbility', + } + let options: common.ConnectOptions = { + onConnect: (elementName, proxy) => { + hilog.info(DOMAIN_NUMBER, TAG, 'onConnect called.'); + promptAction.showToast({ + message: $r('app.string.ConnectFAServiceAbility') + }); + }, + onDisconnect: (elementName) => { + hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect called.'); + }, + onFailed: (code) => { + hilog.info(DOMAIN_NUMBER, TAG, 'onFailed code is: ' + code); + } + }; + let connectionId = this.context.connectServiceExtensionAbility(want, options); + hilog.info(DOMAIN_NUMBER, TAG, 'connectionId is ' + JSON.stringify(connectionId)); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.PageAbility')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(304) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + let want: Want = { + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'ServiceExtAbility', + parameters:{ + key: 'ConnectFaPageAbility' + } + } + this.context.startServiceExtensionAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'startServiceExtensionAbility successfully'); + }).catch((err: BusinessError) =>{ + hilog.info(DOMAIN_NUMBER, TAG, 'startServiceExtensionAbility fail, err is: ' + JSON.stringify(err)); + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartModel.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartModel.ets index 8eb88c16185a15f41450e437f939a0962faa8410..e31eb766396408509a0a43cbedb0eb9e498a632b 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartModel.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_StartModel.ets @@ -1,213 +1,213 @@ -/* - * Copyright (c) 2023 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. - */ - -// 在启动指定实例模式的UIAbility时,给每一个UIAbility实例配置一个独立的Key标识 -// 例如在文档使用场景中,可以用文档路径作为Key标识 -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; - -const TAG: string = '[Page_StartModel]'; -const DOMAIN_NUMBER: number = 0xFF00; - -function getInstance() : string { - return 'KEY'; -} - -@Entry -@Component -struct Page_StartModel { - private KEY_NEW = 'KEY'; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityComponentsStartModel')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.singleton')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'SingletonAbility', - moduleName: 'entry', // moduleName非必选 - }; - context.startAbility(want).then(() => { - }).catch((err: BusinessError) => { - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.multiton')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'MultitonAbility', - moduleName: 'entry', // moduleName非必选 - }; - context.startAbility(want).then(() => { - }).catch((err: BusinessError) => { - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.SpecifiedA')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - // context为调用方UIAbility的UIAbilityContext; - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'SpecifiedFirstAbility', - moduleName: 'entry', // moduleName非必选 - parameters: { // 自定义信息 - instanceKey: this.KEY_NEW - } - }; - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting SpecifiedAbility.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start SpecifiedAbility. Code is ${err.code}, message is ${err.message}`); - }); - this.KEY_NEW = this.KEY_NEW + 'a'; - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.SpecifiedB')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - // context为调用方UIAbility的UIAbilityContext; - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'SpecifiedSecondAbility', - moduleName: 'entry', // moduleName非必选 - parameters: { // 自定义信息 - instanceKey: getInstance() - } - }; - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting SpecifiedAbility.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start SpecifiedAbility. Code is ${err.code}, message is ${err.message}`); - }); - this.KEY_NEW = this.KEY_NEW + 'a'; - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 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. + */ + +// 在启动指定实例模式的UIAbility时,给每一个UIAbility实例配置一个独立的Key标识 +// 例如在文档使用场景中,可以用文档路径作为Key标识 +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; + +const TAG: string = '[Page_StartModel]'; +const DOMAIN_NUMBER: number = 0xFF00; + +function getInstance() : string { + return 'KEY'; +} + +@Entry +@Component +struct Page_StartModel { + private KEY_NEW = 'KEY'; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityComponentsStartModel')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.singleton')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'SingletonAbility', + moduleName: 'entry', // moduleName非必选 + }; + context.startAbility(want).then(() => { + }).catch((err: BusinessError) => { + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.multiton')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'MultitonAbility', + moduleName: 'entry', // moduleName非必选 + }; + context.startAbility(want).then(() => { + }).catch((err: BusinessError) => { + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.SpecifiedA')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + // context为调用方UIAbility的UIAbilityContext; + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'SpecifiedFirstAbility', + moduleName: 'entry', // moduleName非必选 + parameters: { // 自定义信息 + instanceKey: this.KEY_NEW + } + }; + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting SpecifiedAbility.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start SpecifiedAbility. Code is ${err.code}, message is ${err.message}`); + }); + this.KEY_NEW = this.KEY_NEW + 'a'; + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.SpecifiedB')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + // context为调用方UIAbility的UIAbilityContext; + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'SpecifiedSecondAbility', + moduleName: 'entry', // moduleName非必选 + parameters: { // 自定义信息 + instanceKey: getInstance() + } + }; + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting SpecifiedAbility.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start SpecifiedAbility. Code is ${err.code}, message is ${err.message}`); + }); + this.KEY_NEW = this.KEY_NEW + 'a'; + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsBasicUsage.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsBasicUsage.ets index 649b07f8c2eb49d35988c6ce41b85b5713467a7a..457f91f088153a5107ec62da596f18111f958f73 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsBasicUsage.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsBasicUsage.ets @@ -1,89 +1,89 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import EnvironmentCallback from '@ohos.app.ability.EnvironmentCallback'; -import hilog from '@ohos.hilog'; -import Want from '@ohos.app.ability.Want'; -import { Configuration } from '@ohos.app.ability.Configuration'; - -const TAG: string = '[Page_UIAbilityComponentsBasicUsage]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_UIAbilityComponentsBasicUsage { - private context = getContext(this) as common.UIAbilityContext; - private callbackId: number = 0; // 注册订阅系统环境变化的ID - - startAbilityTest(): void { - let context = getContext(this) as common.UIAbilityContext; - let want: Want = { - // Want参数信息 - }; - context.startAbility(want); - } - - subscribeConfigurationUpdate(): void { - let systemLanguage: string | undefined = this.context.config.language; // 获取系统当前语言 - // 1.获取ApplicationContext - let applicationContext = this.context.getApplicationContext(); - // 2.通过applicationContext订阅环境变量变化 - let environmentCallback: EnvironmentCallback = { - onConfigurationUpdated(newConfig: Configuration): void { - hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); - if (this.systemLanguage !== newConfig.language) { - hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); - systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 - } - }, - onMemoryLevel(level): void { - hilog.info(DOMAIN_NUMBER, TAG, `onMemoryLevel level: ${level}`); - } - } - this.callbackId = applicationContext.on('environment', environmentCallback); - } - - // 页面展示 - build() { - Column() { - Row() { - Text($r('app.string.UIAbilityComponentsBasicUsage')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224 }) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8, bottom: 317, right: 152, left: 152 }) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import EnvironmentCallback from '@ohos.app.ability.EnvironmentCallback'; +import hilog from '@ohos.hilog'; +import Want from '@ohos.app.ability.Want'; +import { Configuration } from '@ohos.app.ability.Configuration'; + +const TAG: string = '[Page_UIAbilityComponentsBasicUsage]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_UIAbilityComponentsBasicUsage { + private context = getContext(this) as common.UIAbilityContext; + private callbackId: number = 0; // 注册订阅系统环境变化的ID + + startAbilityTest(): void { + let context = getContext(this) as common.UIAbilityContext; + let want: Want = { + // Want参数信息 + }; + context.startAbility(want); + } + + subscribeConfigurationUpdate(): void { + let systemLanguage: string | undefined = this.context.config.language; // 获取系统当前语言 + // 1.获取ApplicationContext + let applicationContext = this.context.getApplicationContext(); + // 2.通过applicationContext订阅环境变量变化 + let environmentCallback: EnvironmentCallback = { + onConfigurationUpdated(newConfig: Configuration): void { + hilog.info(DOMAIN_NUMBER, TAG, `onConfigurationUpdated systemLanguage is ${systemLanguage}, newConfig: ${JSON.stringify(newConfig)}`); + if (this.systemLanguage !== newConfig.language) { + hilog.info(DOMAIN_NUMBER, TAG, `systemLanguage from ${systemLanguage} changed to ${newConfig.language}`); + systemLanguage = newConfig.language; // 将变化之后的系统语言保存,作为下一次变化前的系统语言 + } + }, + onMemoryLevel(level): void { + hilog.info(DOMAIN_NUMBER, TAG, `onMemoryLevel level: ${level}`); + } + } + this.callbackId = applicationContext.on('environment', environmentCallback); + } + + // 页面展示 + build() { + Column() { + Row() { + Text($r('app.string.UIAbilityComponentsBasicUsage')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224 }) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8, bottom: 317, right: 152, left: 152 }) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsInteractive.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsInteractive.ets index 496b3131e5c59bc54f8c37b3cf0bb8af0d810c7f..58d6e718f46208be670729456f322d080cd07f9d 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsInteractive.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/Page_UIAbilityComponentsInteractive.ets @@ -1,516 +1,516 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction' -import Want from '@ohos.app.ability.Want'; -import StartOptions from '@ohos.app.ability.StartOptions'; -import { BusinessError } from '@ohos.base'; -import { Caller } from '@ohos.app.ability.UIAbility'; - -const TAG: string = '[Page_UIAbilityComponentsInteractive]'; -const DOMAIN_NUMBER: number = 0xFF00; - - -@Entry -@Component -struct Page_UIAbilityComponentsInteractive { - private context = getContext(this) as common.UIAbilityContext; - private callbackId: number = 0; // 注册订阅系统环境变化的ID - - unsubscribeConfigurationUpdate() { - let applicationContext = this.context.getApplicationContext(); - applicationContext.off('environment', this.callbackId); - } - - caller: Caller | undefined = undefined; - // 注册caller的release监听 - private regOnRelease(caller: Caller): void { - hilog.info(DOMAIN_NUMBER, TAG, `caller is ${caller}`); - try { - caller.on('release', (msg: string) => { - hilog.info(DOMAIN_NUMBER, TAG, `caller onRelease is called ${msg}`); - }) - hilog.info(DOMAIN_NUMBER, TAG, 'succeeded in registering on release.'); - } catch (err) { - let code = (err as BusinessError).code; - let message = (err as BusinessError).message; - hilog.error(DOMAIN_NUMBER, TAG, `Failed to caller register on release. Code is ${code}, message is ${message}`); - }; - }; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityComponentsInteractive')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionA')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - // context为Ability对象的成员,在非Ability对象内部调用需要 - // 将Context对象传递过去 - let wantInfo: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - moduleName: 'entry', // moduleName非必选 - abilityName: 'FuncAbilityA', - parameters: { // 自定义信息 - info: '来自EntryAbility Page_UIAbilityComponentsInteractive页面' - }, - }; - // context为调用方UIAbility的UIAbilityContext - this.context.startAbility(wantInfo).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.'); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, 'startAbility failed.'); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionB')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(304) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - const RESULT_CODE: number = 1001; - - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - moduleName: 'entry', // moduleName非必选 - abilityName: 'FuncAbilityA', - parameters: { // 自定义信息 - info: '来自EntryAbility UIAbilityComponentsInteractive页面' - } - }; - context.startAbilityForResult(want).then((data) => { - if (data?.resultCode === RESULT_CODE) { - // 解析被调用方UIAbility返回的信息 - let info = data.want?.parameters?.info; - hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(info) ?? ''); - if (info !== null) { - promptAction.showToast({ - message : JSON.stringify(info) - }); - } - } - hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(data.resultCode) ?? ''); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability for result. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionC')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - // uncomment line below if wish to implicitly query only in the specific bundle. - // bundleName: 'com.samples.stagemodelabilityinteraction', - action: 'ohos.want.action.viewData', - // entities can be omitted. - entities: ['entity.system.default'] - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting FuncAbility.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start FuncAbility. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionE')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilitydevelop', - moduleName: 'entry', // moduleName非必选 - abilityName: 'FuncAbilityB', - parameters: { // 自定义信息 - info: '来自EntryAbility Index页面' - } - }; - let options: StartOptions = { - windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want, options).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionF')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilityinteraction', - moduleName: 'entry', // moduleName非必选 - abilityName: 'FuncAbility', - parameters: { // 自定义参数传递页面信息 - router: 'FuncA' - } - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionG')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context = getContext(this) as common.UIAbilityContext; - let wantInfo: Want = { - // uncomment line below if wish to implicitly query only in the specific bundle. - // bundleName: 'com.samples.stagemodelabilityinteraction', - action: 'ohos.want.action.viewData', - // entities can be omitted. - entities: ['entity.system.browsable'], - uri: 'https://www.test.com:8080/query/student' - }; - context.startAbility(wantInfo).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting TUri.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start Uri. Code is ${err.code}, message is ${err.message}`); - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionH')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context = getContext(this) as common.UIAbilityContext; - let wantInfo: Want = { - // uncomment line below if wish to implicitly query only in the specific bundle. - // bundleName: 'com.samples.stagemodelabilityinteraction', - action: 'ohos.want.action.search', - // entities can be omitted. - entities: ['entity.system.browsable'], - uri: 'https://www.test.com:8080/query/student', - type: 'application/http' - }; - context.startAbility(wantInfo).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting tjyUri.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start Uri. Code is ${err.code}, message is ${err.message}`); - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionOnCreate')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilityinteraction', - moduleName: 'entry', // moduleName非必选 - abilityName: 'EntryAbility', - parameters: { // 自定义参数传递页面信息 - router: 'funcA' - } - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.'); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.UIAbilityComponentsInteractionOnNewWant')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.stagemodelabilityinteraction', - moduleName: 'entry', // moduleName非必选 - abilityName: 'EntryAbility', - parameters: { // 自定义参数传递页面信息 - router: 'funcB' - } - }; - // context为调用方UIAbility的UIAbilityContext - context.startAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in starting ability.`); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row(){ - Text($r('app.string.Caller')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - let want: Want = { - bundleName: 'com.samples.stagemodelabilityinteraction', - abilityName: 'CalleeAbility', - parameters: { // 自定义信息 - info: 'CallSendMsg' - } - }; - - context.startAbilityByCall(want).then((caller: Caller) => { - hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in starting ability.Code is ${caller}`); - if (caller === undefined) { - hilog.info(DOMAIN_NUMBER, TAG, 'get caller failed'); - return; - } - else { - hilog.info(DOMAIN_NUMBER, TAG, 'get caller success'); - this.regOnRelease(caller); - promptAction.showToast({ - message: $r('app.string.CallerSuccess') - }); - try { - caller.release(); - } catch (releaseErr) { - console.log('Caller.release catch error, error.code: ' + JSON.stringify(releaseErr.code) + - ' error.message: ' + JSON.stringify(releaseErr.message)); - } - } - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction' +import Want from '@ohos.app.ability.Want'; +import StartOptions from '@ohos.app.ability.StartOptions'; +import { BusinessError } from '@ohos.base'; +import { Caller } from '@ohos.app.ability.UIAbility'; + +const TAG: string = '[Page_UIAbilityComponentsInteractive]'; +const DOMAIN_NUMBER: number = 0xFF00; + + +@Entry +@Component +struct Page_UIAbilityComponentsInteractive { + private context = getContext(this) as common.UIAbilityContext; + private callbackId: number = 0; // 注册订阅系统环境变化的ID + + unsubscribeConfigurationUpdate() { + let applicationContext = this.context.getApplicationContext(); + applicationContext.off('environment', this.callbackId); + } + + caller: Caller | undefined = undefined; + // 注册caller的release监听 + private regOnRelease(caller: Caller): void { + hilog.info(DOMAIN_NUMBER, TAG, `caller is ${caller}`); + try { + caller.on('release', (msg: string) => { + hilog.info(DOMAIN_NUMBER, TAG, `caller onRelease is called ${msg}`); + }) + hilog.info(DOMAIN_NUMBER, TAG, 'succeeded in registering on release.'); + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(DOMAIN_NUMBER, TAG, `Failed to caller register on release. Code is ${code}, message is ${message}`); + }; + }; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityComponentsInteractive')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionA')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + // context为Ability对象的成员,在非Ability对象内部调用需要 + // 将Context对象传递过去 + let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + moduleName: 'entry', // moduleName非必选 + abilityName: 'FuncAbilityA', + parameters: { // 自定义信息 + info: '来自EntryAbility Page_UIAbilityComponentsInteractive页面' + }, + }; + // context为调用方UIAbility的UIAbilityContext + this.context.startAbility(wantInfo).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'startAbility success.'); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'startAbility failed.'); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionB')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(304) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + const RESULT_CODE: number = 1001; + + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + moduleName: 'entry', // moduleName非必选 + abilityName: 'FuncAbilityA', + parameters: { // 自定义信息 + info: '来自EntryAbility UIAbilityComponentsInteractive页面' + } + }; + context.startAbilityForResult(want).then((data) => { + if (data?.resultCode === RESULT_CODE) { + // 解析被调用方UIAbility返回的信息 + let info = data.want?.parameters?.info; + hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(info) ?? ''); + if (info !== null) { + promptAction.showToast({ + message : JSON.stringify(info) + }); + } + } + hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(data.resultCode) ?? ''); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability for result. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionC')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + // uncomment line below if wish to implicitly query only in the specific bundle. + // bundleName: 'com.samples.stagemodelabilityinteraction', + action: 'ohos.want.action.viewData', + // entities can be omitted. + entities: ['entity.system.default'] + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting FuncAbility.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start FuncAbility. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionE')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilitydevelop', + moduleName: 'entry', // moduleName非必选 + abilityName: 'FuncAbilityB', + parameters: { // 自定义信息 + info: '来自EntryAbility Index页面' + } + }; + let options: StartOptions = { + windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want, options).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionF')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilityinteraction', + moduleName: 'entry', // moduleName非必选 + abilityName: 'FuncAbility', + parameters: { // 自定义参数传递页面信息 + router: 'FuncA' + } + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionG')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context = getContext(this) as common.UIAbilityContext; + let wantInfo: Want = { + // uncomment line below if wish to implicitly query only in the specific bundle. + // bundleName: 'com.samples.stagemodelabilityinteraction', + action: 'ohos.want.action.viewData', + // entities can be omitted. + entities: ['entity.system.browsable'], + uri: 'https://www.test.com:8080/query/student' + }; + context.startAbility(wantInfo).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting TUri.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start Uri. Code is ${err.code}, message is ${err.message}`); + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionH')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context = getContext(this) as common.UIAbilityContext; + let wantInfo: Want = { + // uncomment line below if wish to implicitly query only in the specific bundle. + // bundleName: 'com.samples.stagemodelabilityinteraction', + action: 'ohos.want.action.search', + // entities can be omitted. + entities: ['entity.system.browsable'], + uri: 'https://www.test.com:8080/query/student', + type: 'application/http' + }; + context.startAbility(wantInfo).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting tjyUri.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start Uri. Code is ${err.code}, message is ${err.message}`); + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionOnCreate')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilityinteraction', + moduleName: 'entry', // moduleName非必选 + abilityName: 'EntryAbility', + parameters: { // 自定义参数传递页面信息 + router: 'funcA' + } + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in starting ability.'); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.UIAbilityComponentsInteractionOnNewWant')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.stagemodelabilityinteraction', + moduleName: 'entry', // moduleName非必选 + abilityName: 'EntryAbility', + parameters: { // 自定义参数传递页面信息 + router: 'funcB' + } + }; + // context为调用方UIAbility的UIAbilityContext + context.startAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in starting ability.`); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row(){ + Text($r('app.string.Caller')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + let want: Want = { + bundleName: 'com.samples.stagemodelabilityinteraction', + abilityName: 'CalleeAbility', + parameters: { // 自定义信息 + info: 'CallSendMsg' + } + }; + + context.startAbilityByCall(want).then((caller: Caller) => { + hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in starting ability.Code is ${caller}`); + if (caller === undefined) { + hilog.info(DOMAIN_NUMBER, TAG, 'get caller failed'); + return; + } + else { + hilog.info(DOMAIN_NUMBER, TAG, 'get caller success'); + this.regOnRelease(caller); + promptAction.showToast({ + message: $r('app.string.CallerSuccess') + }); + try { + caller.release(); + } catch (releaseErr) { + console.log('Caller.release catch error, error.code: ' + JSON.stringify(releaseErr.code) + + ' error.message: ' + JSON.stringify(releaseErr.message)); + } + } + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ability. Code is ${err.code}, message is ${err.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_collaborateability/Page_CollaborateAbility.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_collaborateability/Page_CollaborateAbility.ets index 50767a94c309613994ea30037439c4187a7bacff..b72a0c883244865975d519a02365eaecf572a38e 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_collaborateability/Page_CollaborateAbility.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_collaborateability/Page_CollaborateAbility.ets @@ -1,446 +1,446 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import deviceManager from '@ohos.distributedDeviceManager'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction'; -import rpc from '@ohos.rpc'; -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; -import { Caller } from '@ohos.app.ability.UIAbility'; - -const TAG: string = '[Page_CollaborateAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; -const REQUEST_CODE = 1; - -let dmClass: deviceManager.DeviceManager; - -let connectionId: number; -let options: common.ConnectOptions = { - onConnect(elementName, remote): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onConnect callback'); - if (remote === null) { - hilog.info(DOMAIN_NUMBER, TAG, `onConnect remote is null`); - return; - } - let option = new rpc.MessageOption(); - let data = new rpc.MessageSequence(); - let reply = new rpc.MessageSequence(); - data.writeInt(99); - // 开发者可发送data到目标端应用进行相应操作 - // @param code 表示客户端发送的服务请求代码。 - // @param data 表示客户端发送的{@link MessageSequence}对象。 - // @param reply 表示远程服务发送的响应消息对象。 - // @param options 指示操作是同步的还是异步的。 - // @return 如果操作成功返回{@code true}; 否则返回 {@code false}。 - remote.sendMessageRequest(REQUEST_CODE, data, reply, option).then((ret: rpc.RequestResult) => { - let errCode = reply.readInt(); // 在成功连接的情况下,会收到来自目标端返回的信息(100) - let msg: number = 0; - if (errCode === 0) { - msg = reply.readInt(); - } - hilog.info(DOMAIN_NUMBER, TAG, `sendRequest msg:${msg}`); - // 成功连接后台服务 - promptAction.showToast({ - message: `sendRequest msg:${msg}` - }); - }).catch((error: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, `sendRequest failed, ${JSON.stringify(error)}`); - }); - }, - onDisconnect(elementName): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect callback'); - }, - onFailed(code): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onFailed callback'); - } -}; - -function initDmClass(): void { - // 其中createDeviceManager接口为系统API - try { - dmClass = deviceManager.createDeviceManager('com.samples.stagemodelabilitydevelop'); - hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(dmClass) ?? ''); - promptAction.showToast({ - message: $r('app.string.InitializedSuccessfully') - }); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, 'createDeviceManager err: ' + JSON.stringify(err)); - }; -}; - -function getRemoteDeviceId(): string | undefined { - if (typeof dmClass === 'object' && dmClass !== null) { - let list = dmClass.getAvailableDeviceListSync(); - hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(dmClass), JSON.stringify(list)); - if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { - hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: list is null'); - return; - } - if (list.length === 0) { - hilog.info(DOMAIN_NUMBER, TAG, `getRemoteDeviceId err: list is empty`); - return; - } - return list[0].networkId; - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: dmClass is null'); - return; - } -}; - -@Entry -@Component -struct Page_CollaborateAbility { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.MultiDeviceCollaboration')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.CollaborativeInitialization')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - initDmClass() - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.MultiDeviceCollaborationWithoutReturningData')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - deviceId: getRemoteDeviceId(), - bundleName: 'com.samples.stagemodelabilityinteraction', - abilityName: 'CollaborateAbility' - }; - this.context.startAbility(want).then(() => { - promptAction.showToast({ - message: $r('app.string.SuccessfulCollaboration') - }); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `startAbility err: ` + JSON.stringify(err)); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.MultiDeviceCollaborationWithReturningData')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - deviceId: getRemoteDeviceId(), - bundleName: 'com.samples.stagemodelabilityinteraction', - abilityName: 'CollaborateAbility', - moduleName: 'entry' // moduleName非必选 - }; - const RESULT_CODE: number = 1001; - // context为调用方UIAbility的UIAbilityContext - this.context.startAbilityForResult(want).then((data) => { - if (data?.resultCode === RESULT_CODE) { - // 解析目标端UIAbility返回的信息 - let info = data.want?.parameters?.info; - hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(info) ?? ''); - if (info !== null) { - promptAction.showToast({ - message : JSON.stringify(info) - }); - } - } - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `startAbilityForResult err: ` + JSON.stringify(error)); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.StartServiceExtensionAbility')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - deviceId: getRemoteDeviceId(), - bundleName: 'com.samples.stagemodelabilityinteraction', - abilityName: 'ServiceExtAbility', - moduleName: 'entry' // moduleName非必选 - }; - // context为发起端UIAbility的AbilityContext - this.context.startAbility(want).then(() => { - // ... - promptAction.showToast({ - message: $r('app.string.SuccessfullyStart') - }); - }).catch((err: BusinessError) => { - // ... - hilog.error(DOMAIN_NUMBER, TAG, `startAbility err: ` + JSON.stringify(err)); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.StopServiceExtensionAbility')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - deviceId: getRemoteDeviceId(), - bundleName: 'com.samples.stagemodelabilityinteraction', - abilityName: 'ServiceExtAbility', - moduleName: 'entry' // moduleName非必选 - }; - // 退出由startAbility接口启动的ServiceExtensionAbility - this.context.stopServiceExtensionAbility(want).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, "stop service extension ability success") - promptAction.showToast({ - message: $r('app.string.SuccessfullyStop') - }); - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `stop service extension ability err is ` + JSON.stringify(err)); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.Caller')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let caller: Caller | undefined; - let context = this.context; - - context.startAbilityByCall({ - deviceId: getRemoteDeviceId(), - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'CollaborateAbility', - }).then((data) => { - if (data !== null) { - caller = data; - hilog.info(DOMAIN_NUMBER, TAG, 'get remote caller success'); - // 注册caller的release监听 - caller.onRelease((msg) => { - hilog.info(DOMAIN_NUMBER, TAG, `remote caller onRelease is called ${msg}`); - }); - hilog.info(DOMAIN_NUMBER, TAG, 'remote caller register OnRelease succeed'); - promptAction.showToast({ - message: $r('app.string.CallerSuccess') - }); - // 注册caller的协同场景下跨设备组件状态变化监听通知 - try { - caller.onRemoteStateChange((str) => { - hilog.info(DOMAIN_NUMBER, TAG, 'Remote state changed ' + str); - }); - } catch (error) { - hilog.info(DOMAIN_NUMBER, TAG, `Caller.onRemoteStateChange catch error, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}`); - }; - } - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `get remote caller failed with ${error}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.ConnectBackendService')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let want: Want = { - 'deviceId': getRemoteDeviceId(), - 'bundleName': 'com.samples.stagemodelabilityinteraction', - 'abilityName': 'ServiceExtAbility' - }; - // 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入 - connectionId = this.context.connectServiceExtensionAbility(want, options); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.DisconnectBackendService')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - this.context.disconnectServiceExtensionAbility(connectionId).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility success'); - // 成功断连后台服务 - promptAction.showToast({ - message: $r('app.string.SuccessfullyDisconnectBackendService') - }) - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility failed'); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import deviceManager from '@ohos.distributedDeviceManager'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction'; +import rpc from '@ohos.rpc'; +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; +import { Caller } from '@ohos.app.ability.UIAbility'; + +const TAG: string = '[Page_CollaborateAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; +const REQUEST_CODE = 1; + +let dmClass: deviceManager.DeviceManager; + +let connectionId: number; +let options: common.ConnectOptions = { + onConnect(elementName, remote): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onConnect callback'); + if (remote === null) { + hilog.info(DOMAIN_NUMBER, TAG, `onConnect remote is null`); + return; + } + let option = new rpc.MessageOption(); + let data = new rpc.MessageSequence(); + let reply = new rpc.MessageSequence(); + data.writeInt(99); + // 开发者可发送data到目标端应用进行相应操作 + // @param code 表示客户端发送的服务请求代码。 + // @param data 表示客户端发送的{@link MessageSequence}对象。 + // @param reply 表示远程服务发送的响应消息对象。 + // @param options 指示操作是同步的还是异步的。 + // @return 如果操作成功返回{@code true}; 否则返回 {@code false}。 + remote.sendMessageRequest(REQUEST_CODE, data, reply, option).then((ret: rpc.RequestResult) => { + let errCode = reply.readInt(); // 在成功连接的情况下,会收到来自目标端返回的信息(100) + let msg: number = 0; + if (errCode === 0) { + msg = reply.readInt(); + } + hilog.info(DOMAIN_NUMBER, TAG, `sendRequest msg:${msg}`); + // 成功连接后台服务 + promptAction.showToast({ + message: `sendRequest msg:${msg}` + }); + }).catch((error: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, `sendRequest failed, ${JSON.stringify(error)}`); + }); + }, + onDisconnect(elementName): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onDisconnect callback'); + }, + onFailed(code): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onFailed callback'); + } +}; + +function initDmClass(): void { + // 其中createDeviceManager接口为系统API + try { + dmClass = deviceManager.createDeviceManager('com.samples.stagemodelabilitydevelop'); + hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(dmClass) ?? ''); + promptAction.showToast({ + message: $r('app.string.InitializedSuccessfully') + }); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, 'createDeviceManager err: ' + JSON.stringify(err)); + }; +}; + +function getRemoteDeviceId(): string | undefined { + if (typeof dmClass === 'object' && dmClass !== null) { + let list = dmClass.getAvailableDeviceListSync(); + hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(dmClass), JSON.stringify(list)); + if (typeof (list) === 'undefined' || typeof (list.length) === 'undefined') { + hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: list is null'); + return; + } + if (list.length === 0) { + hilog.info(DOMAIN_NUMBER, TAG, `getRemoteDeviceId err: list is empty`); + return; + } + return list[0].networkId; + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'getRemoteDeviceId err: dmClass is null'); + return; + } +}; + +@Entry +@Component +struct Page_CollaborateAbility { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.MultiDeviceCollaboration')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.CollaborativeInitialization')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + initDmClass() + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.MultiDeviceCollaborationWithoutReturningData')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + deviceId: getRemoteDeviceId(), + bundleName: 'com.samples.stagemodelabilityinteraction', + abilityName: 'CollaborateAbility' + }; + this.context.startAbility(want).then(() => { + promptAction.showToast({ + message: $r('app.string.SuccessfulCollaboration') + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `startAbility err: ` + JSON.stringify(err)); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.MultiDeviceCollaborationWithReturningData')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + deviceId: getRemoteDeviceId(), + bundleName: 'com.samples.stagemodelabilityinteraction', + abilityName: 'CollaborateAbility', + moduleName: 'entry' // moduleName非必选 + }; + const RESULT_CODE: number = 1001; + // context为调用方UIAbility的UIAbilityContext + this.context.startAbilityForResult(want).then((data) => { + if (data?.resultCode === RESULT_CODE) { + // 解析目标端UIAbility返回的信息 + let info = data.want?.parameters?.info; + hilog.info(DOMAIN_NUMBER, TAG, JSON.stringify(info) ?? ''); + if (info !== null) { + promptAction.showToast({ + message : JSON.stringify(info) + }); + } + } + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `startAbilityForResult err: ` + JSON.stringify(error)); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.StartServiceExtensionAbility')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + deviceId: getRemoteDeviceId(), + bundleName: 'com.samples.stagemodelabilityinteraction', + abilityName: 'ServiceExtAbility', + moduleName: 'entry' // moduleName非必选 + }; + // context为发起端UIAbility的AbilityContext + this.context.startAbility(want).then(() => { + // ... + promptAction.showToast({ + message: $r('app.string.SuccessfullyStart') + }); + }).catch((err: BusinessError) => { + // ... + hilog.error(DOMAIN_NUMBER, TAG, `startAbility err: ` + JSON.stringify(err)); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.StopServiceExtensionAbility')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + deviceId: getRemoteDeviceId(), + bundleName: 'com.samples.stagemodelabilityinteraction', + abilityName: 'ServiceExtAbility', + moduleName: 'entry' // moduleName非必选 + }; + // 退出由startAbility接口启动的ServiceExtensionAbility + this.context.stopServiceExtensionAbility(want).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, "stop service extension ability success") + promptAction.showToast({ + message: $r('app.string.SuccessfullyStop') + }); + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `stop service extension ability err is ` + JSON.stringify(err)); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.Caller')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let caller: Caller | undefined; + let context = this.context; + + context.startAbilityByCall({ + deviceId: getRemoteDeviceId(), + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'CollaborateAbility', + }).then((data) => { + if (data !== null) { + caller = data; + hilog.info(DOMAIN_NUMBER, TAG, 'get remote caller success'); + // 注册caller的release监听 + caller.onRelease((msg) => { + hilog.info(DOMAIN_NUMBER, TAG, `remote caller onRelease is called ${msg}`); + }); + hilog.info(DOMAIN_NUMBER, TAG, 'remote caller register OnRelease succeed'); + promptAction.showToast({ + message: $r('app.string.CallerSuccess') + }); + // 注册caller的协同场景下跨设备组件状态变化监听通知 + try { + caller.onRemoteStateChange((str) => { + hilog.info(DOMAIN_NUMBER, TAG, 'Remote state changed ' + str); + }); + } catch (error) { + hilog.info(DOMAIN_NUMBER, TAG, `Caller.onRemoteStateChange catch error, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}`); + }; + } + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `get remote caller failed with ${error}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.ConnectBackendService')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let want: Want = { + 'deviceId': getRemoteDeviceId(), + 'bundleName': 'com.samples.stagemodelabilityinteraction', + 'abilityName': 'ServiceExtAbility' + }; + // 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入 + connectionId = this.context.connectServiceExtensionAbility(want, options); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.DisconnectBackendService')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + this.context.disconnectServiceExtensionAbility(connectionId).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility success'); + // 成功断连后台服务 + promptAction.showToast({ + message: $r('app.string.SuccessfullyDisconnectBackendService') + }) + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'disconnectServiceExtensionAbility failed'); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_contextability/Page_ContextAbility.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_contextability/Page_ContextAbility.ets index a7676b7306ccb3ac7fd0c5b66f2a7ae6a2ae443d..e82a9825533b9e9f636f045727648e7cf8ce9e3d 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_contextability/Page_ContextAbility.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_contextability/Page_ContextAbility.ets @@ -1,152 +1,152 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction' - -const TAG: string = '[Page_ContextAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_ContextAbility { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.Context04')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row() { - Text($r('app.string.CreateContextMethodOne')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let bundleName2: string = 'com.samples.stagemodelabilityinteraction'; - let bundleContext: Context = this.context.createBundleContext(bundleName2); - let label2: string = bundleContext.applicationInfo.label; - hilog.info(DOMAIN_NUMBER, TAG, `bundleContext is : ${JSON.stringify(bundleContext.createBundleContext(bundleName2))}`); - hilog.info(DOMAIN_NUMBER, TAG, `label2 is : ${JSON.stringify(label2)}`); - if (bundleContext && label2 !== null) { - promptAction.showToast({ - message: ('成功获取Context') - }); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.CreateContextMethodTwo')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let bundleName2: string = 'com.samples.stagemodelabilityinteraction'; - let moduleName2: string = 'entry'; - let moduleContext: Context = this.context.createModuleContext(bundleName2, moduleName2); - if (moduleContext !== null) { - promptAction.showToast({ - message: ('成功获取Context') - }); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.CreateContextMethodThree')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let moduleName2: string = 'entry'; - let moduleContext: Context = this.context.createModuleContext(moduleName2); - if (moduleContext !== null) { - promptAction.showToast({ - message: ('成功获取Context') - }); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction' + +const TAG: string = '[Page_ContextAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_ContextAbility { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.Context04')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row() { + Text($r('app.string.CreateContextMethodOne')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let bundleName2: string = 'com.samples.stagemodelabilityinteraction'; + let bundleContext: Context = this.context.createBundleContext(bundleName2); + let label2: string = bundleContext.applicationInfo.label; + hilog.info(DOMAIN_NUMBER, TAG, `bundleContext is : ${JSON.stringify(bundleContext.createBundleContext(bundleName2))}`); + hilog.info(DOMAIN_NUMBER, TAG, `label2 is : ${JSON.stringify(label2)}`); + if (bundleContext && label2 !== null) { + promptAction.showToast({ + message: ('成功获取Context') + }); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.CreateContextMethodTwo')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let bundleName2: string = 'com.samples.stagemodelabilityinteraction'; + let moduleName2: string = 'entry'; + let moduleContext: Context = this.context.createModuleContext(bundleName2, moduleName2); + if (moduleContext !== null) { + promptAction.showToast({ + message: ('成功获取Context') + }); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.CreateContextMethodThree')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let moduleName2: string = 'entry'; + let moduleContext: Context = this.context.createModuleContext(moduleName2); + if (moduleContext !== null) { + promptAction.showToast({ + message: ('成功获取Context') + }); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityA.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityA.ets index b996b650d371cf25c48222f896d1cc70119d51b7..f8fadd48b6419bc286ec99ad4bb838120dac9190 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityA.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityA.ets @@ -1,139 +1,139 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; - -const TAG: string = '[Page_FuncAbilityA]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_FuncAbilityA { - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.SpecifiedPageA')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.CloseSpecifiedPage')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - const RESULT_CODE: number = 1001; - let abilityResult: common.AbilityResult = { - resultCode: RESULT_CODE, - want: { - bundleName: 'com.samples.stagemodelabilitydevelop', - moduleName: 'entry', // moduleName非必选 - abilityName: 'FuncAbilityB', - parameters: { - info: '来自FuncAbility Index页面' - }, - }, - }; - context.terminateSelfWithResult(abilityResult, (err) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self with result. Code is ${err.code}, message is ${err.message}`); - return; - } - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row(){ - Text($r('app.string.CloseSpecifiedPageA')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - const RESULT_CODE: number = 1001; - let abilityResult: common.AbilityResult = { - resultCode: RESULT_CODE, - want: { - bundleName: 'com.samples.stagemodelabilitydevelop', - moduleName: 'entry', // moduleName非必选 - abilityName: 'FuncAbilityB', - parameters: { - info: '来自FuncAbility Index页面' - }, - }, - }; - context.terminateSelfWithResult(abilityResult, (err) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self with result. Code is ${err.code}, message is ${err.message}`); - return; - } - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; + +const TAG: string = '[Page_FuncAbilityA]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_FuncAbilityA { + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.SpecifiedPageA')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.CloseSpecifiedPage')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + const RESULT_CODE: number = 1001; + let abilityResult: common.AbilityResult = { + resultCode: RESULT_CODE, + want: { + bundleName: 'com.samples.stagemodelabilitydevelop', + moduleName: 'entry', // moduleName非必选 + abilityName: 'FuncAbilityB', + parameters: { + info: '来自FuncAbility Index页面' + }, + }, + }; + context.terminateSelfWithResult(abilityResult, (err) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self with result. Code is ${err.code}, message is ${err.message}`); + return; + } + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row(){ + Text($r('app.string.CloseSpecifiedPageA')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + const RESULT_CODE: number = 1001; + let abilityResult: common.AbilityResult = { + resultCode: RESULT_CODE, + want: { + bundleName: 'com.samples.stagemodelabilitydevelop', + moduleName: 'entry', // moduleName非必选 + abilityName: 'FuncAbilityB', + parameters: { + info: '来自FuncAbility Index页面' + }, + }, + }; + context.terminateSelfWithResult(abilityResult, (err) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self with result. Code is ${err.code}, message is ${err.message}`); + return; + } + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityB.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityB.ets index 835d35ff9950aa8ec66c8e1802a3ffe41cd5526e..73975c6c83ea1b90072594629d05d8878064b6ae 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityB.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_funcability/Page_FuncAbilityB.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_FuncAbilityB { - - build() { - Column() { - Row() { - Text($r('app.string.SpecifiedPageC')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_FuncAbilityB { + + build() { + Column() { + Row() { + Text($r('app.string.SpecifiedPageC')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_lifecycleability/Page_LifecycleAbility.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_lifecycleability/Page_LifecycleAbility.ets index 26558c4629e942a541fcc4cb65e0df8eba58ac1b..1c5dcbba590814f74649f908d32e3b4ef4a942f3 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_lifecycleability/Page_LifecycleAbility.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_lifecycleability/Page_LifecycleAbility.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_LifecycleAbility { - - build() { - Column() { - Row() { - Text($r('app.string.Context05')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_LifecycleAbility { + + build() { + Column() { + Row() { + Text($r('app.string.Context05')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityFirst.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityFirst.ets index 90ea8848c9644d9e05c18db06416d715e91ddc78..0ee5ad1504b91c8c698f084613dff943f668a313 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityFirst.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityFirst.ets @@ -1,149 +1,149 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import promptAction from '@ohos.promptAction' -import router from '@ohos.router'; - -const TAG: string = '[MigrationAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_MigrationAbilityFirst { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.DeviceCrossMigration')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row() { - Text($r('app.string.Page_MigrationAbilitySecond')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - router.pushUrl({ - url: 'pages/page_migrationability/Page_MigrationAbilitySecond' - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.Page_MigrationAbilityThird')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - router.pushUrl({ - url: 'pages/page_migrationability/Page_MigrationAbilityThird' - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.Page_MigrationAbilityFourth')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 12 }) - } - .onClick(() => { - // 点击该按钮时,将应用设置为可迁移状态 - this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); - promptAction.showToast({ - message: $r('app.string.Success') - }); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } - - onPageShow(){ - // 进入该页面时,将应用设置为可迁移状态 - this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); - }); - } +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import promptAction from '@ohos.promptAction' +import router from '@ohos.router'; + +const TAG: string = '[MigrationAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_MigrationAbilityFirst { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.DeviceCrossMigration')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row() { + Text($r('app.string.Page_MigrationAbilitySecond')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + router.pushUrl({ + url: 'pages/page_migrationability/Page_MigrationAbilitySecond' + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.Page_MigrationAbilityThird')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + router.pushUrl({ + url: 'pages/page_migrationability/Page_MigrationAbilityThird' + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.Page_MigrationAbilityFourth')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 12 }) + } + .onClick(() => { + // 点击该按钮时,将应用设置为可迁移状态 + this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); + promptAction.showToast({ + message: $r('app.string.Success') + }); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } + + onPageShow(){ + // 进入该页面时,将应用设置为可迁移状态 + this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `setMissionContinueState ACTIVE result: ${JSON.stringify(result)}`); + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilitySecond.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilitySecond.ets index 1e7a1412c45dea28a4a9eafcad013c49314bba38..6491b85c0cf0ceac7bbb3c66e7fa6a360ca1ba41 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilitySecond.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilitySecond.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_MigrationAbilityTSecond { - - build() { - Column() { - Row() { - Text($r('app.string.Page_MigrationAbilitySecond')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_MigrationAbilityTSecond { + + build() { + Column() { + Row() { + Text($r('app.string.Page_MigrationAbilitySecond')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityThird.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityThird.ets index f62e88536d837cd0d615fc2728052850647cc66f..de96fb337b910eabf7e045aa68b73bc163e68730 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityThird.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_migrationability/Page_MigrationAbilityThird.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_MigrationAbilityThird { - - build() { - Column() { - Row() { - Text($r('app.string.Page_MigrationAbilityThird')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_MigrationAbilityThird { + + build() { + Column() { + Row() { + Text($r('app.string.Page_MigrationAbilityThird')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Multiton.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Multiton.ets index d365e06d8384cdf8ca9da1b7aa2d0a2417014bfc..7554b9c83d54551e3a5de2d7c16a065a44bacc25 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Multiton.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Multiton.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_multiton { - - build() { - Column() { - Row() { - Text($r('app.string.multiton')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_multiton { + + build() { + Column() { + Row() { + Text($r('app.string.multiton')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Singleton.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Singleton.ets index 15bc6d4c04d8bb463144b30c21673eb391f99219..a8b246cf4139b2c0cb186d155e7ff241e792585c 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Singleton.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Singleton.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_singleton { - - build() { - Column() { - Row() { - Text($r('app.string.singleton')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_singleton { + + build() { + Column() { + Row() { + Text($r('app.string.singleton')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_First.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_First.ets index fc5e79ecbd13ba3171585a259a3e4b3034a1b30c..9378ec52061445bd95ff74a5155281056725ca14 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_First.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_First.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_Specified { - - build() { - Column() { - Row() { - Text($r('app.string.Newpage')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_Specified { + + build() { + Column() { + Row() { + Text($r('app.string.Newpage')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_Second.ets b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_Second.ets index 64989ddc69ef18b577441b8f19f7f757e514bb65..5f8a159b079034ab78653fa25b7dac202dde2f52 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_Second.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/pages/page_startupability/Page_Specified_Second.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_Specified_Second { - - build() { - Column() { - Row() { - Text($r('app.string.Savedpage')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224}) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_Specified_Second { + + build() { + Column() { + Row() { + Text($r('app.string.Savedpage')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224}) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8 , bottom: 317 , right: 152 , left: 152}) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/utils/Logger.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/utils/Logger.ts index 3168d4e7a9d47d275f124a67652072ec2e7ed356..c0d05b9282166cd2543d909a27abc00a52cc3e89 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/utils/Logger.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/ets/utils/Logger.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - /** - * debug - * @param args - */ - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - /** - * info - * @param args - */ - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - /** - * warn - * @param args - */ - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - /** - * error - * @param args - */ - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + /** + * debug + * @param args + */ + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + /** + * info + * @param args + */ + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + /** + * warn + * @param args + */ + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + /** + * error + * @param args + */ + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[stageuiabilitydevelop]'); \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/module.json5 index ead18a2c36439d242a81b911b98ce2528350adf6..0870234a4950215c6f546b5c36b26fe5a3dea43e 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/module.json5 @@ -1,223 +1,223 @@ -/* - * Copyright (c) 2024 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", - "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - // UIAbility组件的名称 - "srcEntry": "./ets/entryability/EntryAbility.ts", - // UIAbility组件的代码路径 - "description": "$string:EntryAbility_desc", - // UIAbility组件的描述信息 - "icon": "$media:icon", - // UIAbility组件的图标 - "label": "$string:EntryAbility_label", - // UIAbility组件的标签 - "startWindowIcon": "$media:icon", - // UIAbility组件启动页面图标资源文件的索引 - "startWindowBackground": "$color:start_window_background", - // UIAbility组件启动页面背景颜色资源文件的索引 - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "ohos.want.action.home" - ] - } - ] - }, - { - "name": "SingletonAbility", - "srcEntry": "./ets/componentstartupability/SingletonAbility.ts", - "description": "$string:SingletonAbility_desc", - "icon": "$media:icon", - "label": "$string:SingletonAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "launchType": "singleton" - }, - { - "name": "MultitonAbility", - "srcEntry": "./ets/componentstartupability/MultitonAbility.ts", - "description": "$string:SingletonAbility_desc", - "icon": "$media:icon", - "label": "$string:SingletonAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "launchType": "multiton" - }, - { - "name": "SpecifiedFirstAbility", - "srcEntry": "./ets/componentstartupability/SpecifiedFirstAbility.ts", - "description": "$string:SingletonAbility_desc", - "icon": "$media:icon", - "label": "$string:SingletonAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "launchType": "specified" - }, - { - "name": "SpecifiedSecondAbility", - "srcEntry": "./ets/componentstartupability/SpecifiedSecondAbility.ts", - "description": "$string:SingletonAbility_desc", - "icon": "$media:icon", - "label": "$string:SingletonAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "launchType": "specified" - }, - { - "name": "MyAbilityStage", - "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", - "description": "$string:MyAbilityStage_desc", - "icon": "$media:icon", - "label": "$string:MyAbilityStage_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "launchType": "specified" - }, - { - "name": "EventAbility", - "srcEntry": "./ets/eventability/EventAbility.ts", - "description": "$string:EventAbility_desc", - "icon": "$media:icon", - "label": "$string:EventAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "FuncAbilityA", - "srcEntry": "./ets/funcability/FuncAbilityA.ts", - "description": "$string:FuncAbility_desc", - "icon": "$media:icon", - "label": "$string:FuncAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "FuncAbilityB", - "srcEntry": "./ets/funcability/FuncAbilityB.ts", - "description": "$string:FuncAbility_desc", - "icon": "$media:icon", - "label": "$string:FuncAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "supportWindowMode": [ - "floating" - ] - }, - { - "name": "LifecycleAbility", - "srcEntry": "./ets/lifecycleability/LifecycleAbility.ts", - "description": "$string:LifecycleAbility_desc", - "icon": "$media:icon", - "label": "$string:LifecycleAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "ContextAbility", - "srcEntry": "./ets/contextability/ContextAbility.ts", - "description": "$string:ContextAbility_desc", - "icon": "$media:icon", - "label": "$string:ContextAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "MigrationAbility", - "srcEntry": "./ets/migrationability/MigrationAbility.ts", - "description": "$string:MigrationAbility_desc", - "icon": "$media:icon", - "label": "$string:MigrationAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "continuable": true - // 配置UIAbility支持迁移 - }, - { - "name": "CollaborateAbility", - "srcEntry": "./ets/collaborateability/CollaborateAbility.ts", - "description": "$string:CollaborateAbility_desc", - "icon": "$media:icon", - "label": "$string:CollaborateAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.DISTRIBUTED_DATASYNC", - "reason": "$string:DISTRIBUTED_DATASYNC", - "usedScene": { - "abilities": [ - "MigrationAbility", - "CollaborateAbility" - ], - "when": "inuse" - } - }, - { - "name": "ohos.permission.READ_CALENDAR", - "reason": "$string:READ_CALENDAR", - "usedScene": { - "abilities": [ - "MigrationAbility" - ], - "when": "inuse" - } - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - }, - { - "name": "ohos.permission.START_INVISIBLE_ABILITY", - }, - { - "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", - }, - { - "name": "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION", - } - ], - "extensionAbilities": [ - { - "name": "ServiceExtAbility", - "srcEntry": "./ets/serviceextability/ServiceExtAbility.ts", - "description": "$string:ServiceExtAbility_desc", - "label": "$string:ServiceExtAbility_label", - "type": "service" - } - ] - } +/* + * Copyright (c) 2024 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", + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + // UIAbility组件的名称 + "srcEntry": "./ets/entryability/EntryAbility.ts", + // UIAbility组件的代码路径 + "description": "$string:EntryAbility_desc", + // UIAbility组件的描述信息 + "icon": "$media:icon", + // UIAbility组件的图标 + "label": "$string:EntryAbility_label", + // UIAbility组件的标签 + "startWindowIcon": "$media:icon", + // UIAbility组件启动页面图标资源文件的索引 + "startWindowBackground": "$color:start_window_background", + // UIAbility组件启动页面背景颜色资源文件的索引 + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "ohos.want.action.home" + ] + } + ] + }, + { + "name": "SingletonAbility", + "srcEntry": "./ets/componentstartupability/SingletonAbility.ts", + "description": "$string:SingletonAbility_desc", + "icon": "$media:icon", + "label": "$string:SingletonAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "singleton" + }, + { + "name": "MultitonAbility", + "srcEntry": "./ets/componentstartupability/MultitonAbility.ts", + "description": "$string:SingletonAbility_desc", + "icon": "$media:icon", + "label": "$string:SingletonAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "multiton" + }, + { + "name": "SpecifiedFirstAbility", + "srcEntry": "./ets/componentstartupability/SpecifiedFirstAbility.ts", + "description": "$string:SingletonAbility_desc", + "icon": "$media:icon", + "label": "$string:SingletonAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "specified" + }, + { + "name": "SpecifiedSecondAbility", + "srcEntry": "./ets/componentstartupability/SpecifiedSecondAbility.ts", + "description": "$string:SingletonAbility_desc", + "icon": "$media:icon", + "label": "$string:SingletonAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "specified" + }, + { + "name": "MyAbilityStage", + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ts", + "description": "$string:MyAbilityStage_desc", + "icon": "$media:icon", + "label": "$string:MyAbilityStage_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "specified" + }, + { + "name": "EventAbility", + "srcEntry": "./ets/eventability/EventAbility.ts", + "description": "$string:EventAbility_desc", + "icon": "$media:icon", + "label": "$string:EventAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "FuncAbilityA", + "srcEntry": "./ets/funcability/FuncAbilityA.ts", + "description": "$string:FuncAbility_desc", + "icon": "$media:icon", + "label": "$string:FuncAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "FuncAbilityB", + "srcEntry": "./ets/funcability/FuncAbilityB.ts", + "description": "$string:FuncAbility_desc", + "icon": "$media:icon", + "label": "$string:FuncAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "supportWindowMode": [ + "floating" + ] + }, + { + "name": "LifecycleAbility", + "srcEntry": "./ets/lifecycleability/LifecycleAbility.ts", + "description": "$string:LifecycleAbility_desc", + "icon": "$media:icon", + "label": "$string:LifecycleAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "ContextAbility", + "srcEntry": "./ets/contextability/ContextAbility.ts", + "description": "$string:ContextAbility_desc", + "icon": "$media:icon", + "label": "$string:ContextAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "MigrationAbility", + "srcEntry": "./ets/migrationability/MigrationAbility.ts", + "description": "$string:MigrationAbility_desc", + "icon": "$media:icon", + "label": "$string:MigrationAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "continuable": true + // 配置UIAbility支持迁移 + }, + { + "name": "CollaborateAbility", + "srcEntry": "./ets/collaborateability/CollaborateAbility.ts", + "description": "$string:CollaborateAbility_desc", + "icon": "$media:icon", + "label": "$string:CollaborateAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "$string:DISTRIBUTED_DATASYNC", + "usedScene": { + "abilities": [ + "MigrationAbility", + "CollaborateAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.READ_CALENDAR", + "reason": "$string:READ_CALENDAR", + "usedScene": { + "abilities": [ + "MigrationAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + }, + { + "name": "ohos.permission.START_INVISIBLE_ABILITY", + }, + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", + }, + { + "name": "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION", + } + ], + "extensionAbilities": [ + { + "name": "ServiceExtAbility", + "srcEntry": "./ets/serviceextability/ServiceExtAbility.ts", + "description": "$string:ServiceExtAbility_desc", + "label": "$string:ServiceExtAbility_label", + "type": "service" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/resources/base/element/color.json index 940b8e80b740675551969422468b395b70c04c37..eb1a630dc398f79c67003a6f2dc14c55b0cf3119 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#f1f3f5" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - }, - { - "name": "button_color", - "value": "#027DFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#f1f3f5" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#182431" + }, + { + "name": "button_color", + "value": "#027DFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/ets/utils/Logger.ts b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/ets/utils/Logger.ts index 3168d4e7a9d47d275f124a67652072ec2e7ed356..c0d05b9282166cd2543d909a27abc00a52cc3e89 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/ets/utils/Logger.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/ets/utils/Logger.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - /** - * debug - * @param args - */ - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - /** - * info - * @param args - */ - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - /** - * warn - * @param args - */ - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - /** - * error - * @param args - */ - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + /** + * debug + * @param args + */ + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + /** + * info + * @param args + */ + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + /** + * warn + * @param args + */ + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + /** + * error + * @param args + */ + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[stageuiabilitydevelop]'); \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/module.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/module.json5 index 0bea9afb74243ca60480a53d47e356de3327a394..038f15faf5e3817e0cd925401c619941ff1f7c61 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/hvigor/hvigor-config.json5 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/oh-package.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/oh-package.json5 index 844aa70c4365f4e4b2b33ebacf7bb7a4ab8974ea..c337cd08b02e0570afc69d06dc306a9998523288 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityDevelop/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "stagemodelabilitydevelop", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "stagemodelabilitydevelop", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/app.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/app.json5 index ae3f80fc67a089a503a68cafc5a43a46b776689a..a2220d43c17ffe6ecbb54e6fc5b39bc2f7a8dcf6 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.stagemodelabilityinteraction", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.stagemodelabilityinteraction", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/resources/base/element/string.json index 1700d67d6d7351b62ac4e11e1ffbca47d4dce93f..35a81dba98ef741f5784dfb04f6bd12c3b55d4f1 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "StageModelAbilityInteraction" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "StageModelAbilityInteraction" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/build-profile.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/build-profile.json5 index b4ed08ad14b5ee78273c12abf7e1008511ed5ed0..9ab0a5df27801ebd16de2be7123dd7b40b3fb172 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/build-profile.json5 @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [ - - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/build-profile.json5 index 32345d66a3a76a65572893298ab9c48eb6a42c7c..8296d8e04da0bc5eb3a05c8e1e2c214645a82bea 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/oh-package.json5 index 60d792bb92f1a5b2723a5cc253e44842373b42ac..413a75299a923ac4b576b93e25422bd2c4086097 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts index dfe2d1244714051fbae39f60ea5ae7a213865870..f597be317de20abe76b218d56f734e40a4e17e53 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/i_idl_service_ext.ts @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2023 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 default interface IIdlServiceExt { - processData(data: number, callback: ProcessDataCallback): void; - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void; -} - -export type ProcessDataCallback = (errCode: number, returnValue: number) => void; - -export type InsertDataToMapCallback = (errCode: number) => void; +/* + * Copyright (c) 2023 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 default interface IIdlServiceExt { + processData(data: number, callback: ProcessDataCallback): void; + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void; +} + +export type ProcessDataCallback = (errCode: number, returnValue: number) => void; + +export type InsertDataToMapCallback = (errCode: number) => void; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts index aa665b7dc69926ea61084d002faed4abe66b2c20..cdb00c7c7d86590f80b085a7f5ccf2df5413ab04 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_impl.ts @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2023 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 abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import bundleManager from '@ohos.bundle.bundleManager'; -import IdlServiceExtStub from './idl_service_ext_stub'; -import rpc from '@ohos.rpc'; -import type { BusinessError } from '@ohos.base'; -import type { InsertDataToMapCallback } from './i_idl_service_ext'; -import type { ProcessDataCallback } from './i_idl_service_ext'; -import hilog from '@ohos.hilog'; - -const ERR_OK = 0; -const TAG: string = '[IdlServiceExtImpl]'; -const ERR_DENY = -1; -const DOMAIN_NUMBER: number = 0xFF00; - -// 开发者需要在这个类型里对接口进行实现 -export default class ServiceExtImpl extends IdlServiceExtStub { - processData(data: number, callback: ProcessDataCallback): void { - // 开发者自行实现业务逻辑 - hilog.info(DOMAIN_NUMBER, TAG, `processData: ${data}`); - - let callerUid = rpc.IPCSkeleton.getCallingUid(); - bundleManager.getBundleNameByUid(callerUid).then((callerBundleName) => { - hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid: ' + callerBundleName); - // 对客户端包名进行识别 - if (callerBundleName !== 'com.samples.stagemodelabilitydevelop') { // 识别不通过 - hilog.info(DOMAIN_NUMBER, TAG, 'The caller bundle is not in trustlist, reject'); - return; - } - // 识别通过,执行正常业务逻辑 - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid failed: ' + err.message); - }); - - let callerTokenId = rpc.IPCSkeleton.getCallingTokenId(); - let accessManger = abilityAccessCtrl.createAtManager(); - // 所校验的具体权限由开发者自行选择,此处ohos.permission.GET_BUNDLE_INFO_PRIVILEGED只作为示例 - let grantStatus = accessManger.verifyAccessTokenSync(callerTokenId, 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'); - if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { - hilog.info(DOMAIN_NUMBER, TAG, 'PERMISSION_DENIED'); - callback(ERR_DENY, data); // 鉴权失败,返回错误 - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'verify access token success.'); - callback(ERR_OK, data + 1); // 鉴权通过,执行正常业务逻辑 - }; - - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { - // 开发者自行实现业务逻辑 - hilog.info(DOMAIN_NUMBER, TAG, `insertDataToMap, key: ${key} val: ${val}`); - callback(ERR_OK); - }; +/* + * Copyright (c) 2023 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 abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundleManager from '@ohos.bundle.bundleManager'; +import IdlServiceExtStub from './idl_service_ext_stub'; +import rpc from '@ohos.rpc'; +import type { BusinessError } from '@ohos.base'; +import type { InsertDataToMapCallback } from './i_idl_service_ext'; +import type { ProcessDataCallback } from './i_idl_service_ext'; +import hilog from '@ohos.hilog'; + +const ERR_OK = 0; +const TAG: string = '[IdlServiceExtImpl]'; +const ERR_DENY = -1; +const DOMAIN_NUMBER: number = 0xFF00; + +// 开发者需要在这个类型里对接口进行实现 +export default class ServiceExtImpl extends IdlServiceExtStub { + processData(data: number, callback: ProcessDataCallback): void { + // 开发者自行实现业务逻辑 + hilog.info(DOMAIN_NUMBER, TAG, `processData: ${data}`); + + let callerUid = rpc.IPCSkeleton.getCallingUid(); + bundleManager.getBundleNameByUid(callerUid).then((callerBundleName) => { + hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid: ' + callerBundleName); + // 对客户端包名进行识别 + if (callerBundleName !== 'com.samples.stagemodelabilitydevelop') { // 识别不通过 + hilog.info(DOMAIN_NUMBER, TAG, 'The caller bundle is not in trustlist, reject'); + return; + } + // 识别通过,执行正常业务逻辑 + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'getBundleNameByUid failed: ' + err.message); + }); + + let callerTokenId = rpc.IPCSkeleton.getCallingTokenId(); + let accessManger = abilityAccessCtrl.createAtManager(); + // 所校验的具体权限由开发者自行选择,此处ohos.permission.GET_BUNDLE_INFO_PRIVILEGED只作为示例 + let grantStatus = accessManger.verifyAccessTokenSync(callerTokenId, 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'); + if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) { + hilog.info(DOMAIN_NUMBER, TAG, 'PERMISSION_DENIED'); + callback(ERR_DENY, data); // 鉴权失败,返回错误 + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'verify access token success.'); + callback(ERR_OK, data + 1); // 鉴权通过,执行正常业务逻辑 + }; + + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { + // 开发者自行实现业务逻辑 + hilog.info(DOMAIN_NUMBER, TAG, `insertDataToMap, key: ${key} val: ${val}`); + callback(ERR_OK); + }; }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts index bed2370f6c82dd96cf096f34ca5c308d73d88c67..bd806115422e8421642bcf4967a02ac710c5494a 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_proxy.ts @@ -1,81 +1,81 @@ -/* - * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; -import type { InsertDataToMapCallback } from './i_idl_service_ext'; -import type IIdlServiceExt from './i_idl_service_ext'; -import rpc from '@ohos.rpc'; -import hilog from '@ohos.hilog'; - -const TAG: string = '[IdlServiceExtProxy]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class IdlServiceExtProxy implements IIdlServiceExt { - static readonly COMMAND_PROCESS_DATA = 1; - static readonly COMMAND_INSERT_DATA_TO_MAP = 2; - private proxy; - - constructor(proxy) { - this.proxy = proxy; - }; - - processData(data: number, callback: ProcessDataCallback): void { - let option = new rpc.MessageOption(); - let dataSequence = rpc.MessageSequence.create(); - let replySequence = rpc.MessageSequence.create(); - try { - dataSequence.writeInt(data); - this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_PROCESS_DATA, dataSequence, replySequence, option).then(function (result) { - if (result.errCode === 0) { - let errCodeVar = result.reply.readInt(); - if (errCodeVar !== 0) { - let returnValueVar = undefined; - callback(errCodeVar, returnValueVar); - return; - } - let returnValueVar = result.reply.readInt(); - callback(errCodeVar, returnValueVar); - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); - } - }); - } finally { - dataSequence.reclaim(); - replySequence.reclaim(); - }; - }; - - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { - let option = new rpc.MessageOption(); - let dataSequence = rpc.MessageSequence.create(); - let replySequence = rpc.MessageSequence.create(); - try { - dataSequence.writeString(key); - dataSequence.writeInt(val); - this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_INSERT_DATA_TO_MAP, dataSequence, replySequence, option).then(function (result) { - if (result.errCode === 0) { - let errCodeVar = result.reply.readInt(); - callback(errCodeVar); - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); - } - }); - } finally { - dataSequence.reclaim(); - replySequence.reclaim(); - }; - }; -}; - +/* + * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; +import type { InsertDataToMapCallback } from './i_idl_service_ext'; +import type IIdlServiceExt from './i_idl_service_ext'; +import rpc from '@ohos.rpc'; +import hilog from '@ohos.hilog'; + +const TAG: string = '[IdlServiceExtProxy]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class IdlServiceExtProxy implements IIdlServiceExt { + static readonly COMMAND_PROCESS_DATA = 1; + static readonly COMMAND_INSERT_DATA_TO_MAP = 2; + private proxy; + + constructor(proxy) { + this.proxy = proxy; + }; + + processData(data: number, callback: ProcessDataCallback): void { + let option = new rpc.MessageOption(); + let dataSequence = rpc.MessageSequence.create(); + let replySequence = rpc.MessageSequence.create(); + try { + dataSequence.writeInt(data); + this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_PROCESS_DATA, dataSequence, replySequence, option).then(function (result) { + if (result.errCode === 0) { + let errCodeVar = result.reply.readInt(); + if (errCodeVar !== 0) { + let returnValueVar = undefined; + callback(errCodeVar, returnValueVar); + return; + } + let returnValueVar = result.reply.readInt(); + callback(errCodeVar, returnValueVar); + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); + } + }); + } finally { + dataSequence.reclaim(); + replySequence.reclaim(); + }; + }; + + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { + let option = new rpc.MessageOption(); + let dataSequence = rpc.MessageSequence.create(); + let replySequence = rpc.MessageSequence.create(); + try { + dataSequence.writeString(key); + dataSequence.writeInt(val); + this.proxy.sendMessageRequest(IdlServiceExtProxy.COMMAND_INSERT_DATA_TO_MAP, dataSequence, replySequence, option).then(function (result) { + if (result.errCode === 0) { + let errCodeVar = result.reply.readInt(); + callback(errCodeVar); + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'sendMessageRequest failed, errCode: ' + result.errCode); + } + }); + } finally { + dataSequence.reclaim(); + replySequence.reclaim(); + }; + }; +}; + diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts index f94652f844fd7c97759d0c808b1f21cfc3b0c72f..9cb80f741507830ea4cc26666180ab85a06e6605 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/IdlServiceExt/idl_service_ext_stub.ts @@ -1,75 +1,75 @@ -/* - * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; -import type { InsertDataToMapCallback } from './i_idl_service_ext'; -import type IIdlServiceExt from './i_idl_service_ext'; -import rpc from '@ohos.rpc'; -import hilog from '@ohos.hilog'; - -const TAG: string = '[IdlServiceExtStub]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class IdlServiceExtStub extends rpc.RemoteObject implements IIdlServiceExt { - constructor(des: string) { - super(des); - }; - - async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise { - hilog.info(DOMAIN_NUMBER, TAG, 'onRemoteMessageRequest called, code = ' + code); - switch (code) { - case IdlServiceExtStub.COMMAND_PROCESS_DATA: { - let dataVar = data.readInt(); - let promise = new Promise((resolve, reject) => { - this.processData(dataVar, (errCode, returnValue) => { - reply.writeInt(errCode); - if (errCode === 0) { - reply.writeInt(returnValue); - } - resolve(); - }); - }); - await promise; - return true; - }; - case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: { - let keyVar = data.readString(); - let valVar = data.readInt(); - let promise = new Promise((resolve, reject) => { - this.insertDataToMap(keyVar, valVar, (errCode) => { - reply.writeInt(errCode); - resolve(); - }); - }); - await promise; - return true; - }; - default: { - hilog.info(DOMAIN_NUMBER, TAG, 'invalid request code' + code); - break; - } - } - return false; - } - - processData(data: number, callback: ProcessDataCallback): void { - }; - - insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { - }; - - static readonly COMMAND_PROCESS_DATA = 1; - static readonly COMMAND_INSERT_DATA_TO_MAP = 2; +/* + * Copyright (c) 2023 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 type { ProcessDataCallback } from './i_idl_service_ext'; +import type { InsertDataToMapCallback } from './i_idl_service_ext'; +import type IIdlServiceExt from './i_idl_service_ext'; +import rpc from '@ohos.rpc'; +import hilog from '@ohos.hilog'; + +const TAG: string = '[IdlServiceExtStub]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class IdlServiceExtStub extends rpc.RemoteObject implements IIdlServiceExt { + constructor(des: string) { + super(des); + }; + + async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise { + hilog.info(DOMAIN_NUMBER, TAG, 'onRemoteMessageRequest called, code = ' + code); + switch (code) { + case IdlServiceExtStub.COMMAND_PROCESS_DATA: { + let dataVar = data.readInt(); + let promise = new Promise((resolve, reject) => { + this.processData(dataVar, (errCode, returnValue) => { + reply.writeInt(errCode); + if (errCode === 0) { + reply.writeInt(returnValue); + } + resolve(); + }); + }); + await promise; + return true; + }; + case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: { + let keyVar = data.readString(); + let valVar = data.readInt(); + let promise = new Promise((resolve, reject) => { + this.insertDataToMap(keyVar, valVar, (errCode) => { + reply.writeInt(errCode); + resolve(); + }); + }); + await promise; + return true; + }; + default: { + hilog.info(DOMAIN_NUMBER, TAG, 'invalid request code' + code); + break; + } + } + return false; + } + + processData(data: number, callback: ProcessDataCallback): void { + }; + + insertDataToMap(key: string, val: number, callback: InsertDataToMapCallback): void { + }; + + static readonly COMMAND_PROCESS_DATA = 1; + static readonly COMMAND_INSERT_DATA_TO_MAP = 2; }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/calleeability/CalleeAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/calleeability/CalleeAbility.ts index 43226caade68c57355a83dc8cd9c15f56629b2b3..85dcb24126d318c442bb1f39cd6f2992c5131802 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/calleeability/CalleeAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/calleeability/CalleeAbility.ts @@ -1,134 +1,134 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import hilog from '@ohos.hilog'; -import type rpc from '@ohos.rpc'; -import type window from '@ohos.window'; -import type { Caller } from '@ohos.app.ability.UIAbility'; - -const TAG: string = '[CalleeAbility]'; -const MSG_SEND_METHOD: string = 'CallSendMsg'; -const DOMAIN_NUMBER: number = 0xFF00; - -class MyParcelable { - num: number = 0; - str: string = ''; - - constructor(num: number, string: string) { - this.num = num; - this.str = string; - }; - - mySequenceable(num, string): void { - this.num = num; - this.str = string; - }; - - marshalling(messageSequence: rpc.MessageSequence): boolean { - messageSequence.writeInt(this.num); - messageSequence.writeString(this.str); - return true; - }; - - unmarshalling(messageSequence: rpc.MessageSequence): boolean { - this.num = messageSequence.readInt(); - this.str = messageSequence.readString(); - return true; - }; -}; - -function sendMsgCallback(data: rpc.MessageSequence): rpc.Parcelable { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'CalleeSortFunc called'); - - // 获取Caller发送的序列化数据 - let receivedData: MyParcelable = new MyParcelable(0, ''); - data.readParcelable(receivedData); - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `receiveData[${receivedData.num}, ${receivedData.str}]`); - let num: number = receivedData.num; - - // 作相应处理 - // 返回序列化数据result给Caller - return new MyParcelable(num + 1, `send ${receivedData.str} succeed`) as rpc.Parcelable; -}; - -export default class CalleeAbility extends UIAbility { - caller: Caller | undefined; - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - try { - this.callee.on(MSG_SEND_METHOD, sendMsgCallback); - } catch (error) { - hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', `Failed to register. Error is ${error}`); - }; - }; - - async onButtonCall(): Promise { - try { - let msg: MyParcelable = new MyParcelable(1, 'origin_Msg'); - if (this.caller) { - await this.caller.call(MSG_SEND_METHOD, msg); - } - } catch (error) { - hilog.info(DOMAIN_NUMBER, TAG, `caller call failed with ${error}`); - }; - }; - - async onButtonCallWithResult(originMsg: string, backMsg: string): Promise { - try { - let msg: MyParcelable = new MyParcelable(1, originMsg); - if (this.caller) { - const data = await this.caller.callWithResult(MSG_SEND_METHOD, msg); - hilog.info(DOMAIN_NUMBER, TAG, 'caller callWithResult succeed'); - let result: MyParcelable = new MyParcelable(0, ''); - data.readParcelable(result); - backMsg = result.str; - hilog.info(DOMAIN_NUMBER, TAG, `caller result is [${result.num}, ${result.str}]`); - } - } catch (error) { - hilog.info(DOMAIN_NUMBER, TAG, `caller callWithResult failed with ${error}`); - }; - }; - - releaseCall(): void { - try { - if (this.caller) { - this.caller.release(); - this.caller = undefined; - } - hilog.info(DOMAIN_NUMBER, TAG, 'caller release succeed'); - } catch (error) { - hilog.info(DOMAIN_NUMBER, TAG, `caller release failed with ${error}`); - }; - }; - - onWindowStageCreate(windowStage: window.WindowStage): void { - // 设置UI加载 - windowStage.loadContent('pages/Page_CalleeAbility', (err, data) => { - }); - }; - - onDestroy(): void { - try { - this.callee.off(MSG_SEND_METHOD); - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Callee OnDestroy'); - this.releaseCall(); - } catch (error) { - hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', `Failed to register. Error is ${error}`); - }; - }; -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import hilog from '@ohos.hilog'; +import type rpc from '@ohos.rpc'; +import type window from '@ohos.window'; +import type { Caller } from '@ohos.app.ability.UIAbility'; + +const TAG: string = '[CalleeAbility]'; +const MSG_SEND_METHOD: string = 'CallSendMsg'; +const DOMAIN_NUMBER: number = 0xFF00; + +class MyParcelable { + num: number = 0; + str: string = ''; + + constructor(num: number, string: string) { + this.num = num; + this.str = string; + }; + + mySequenceable(num, string): void { + this.num = num; + this.str = string; + }; + + marshalling(messageSequence: rpc.MessageSequence): boolean { + messageSequence.writeInt(this.num); + messageSequence.writeString(this.str); + return true; + }; + + unmarshalling(messageSequence: rpc.MessageSequence): boolean { + this.num = messageSequence.readInt(); + this.str = messageSequence.readString(); + return true; + }; +}; + +function sendMsgCallback(data: rpc.MessageSequence): rpc.Parcelable { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'CalleeSortFunc called'); + + // 获取Caller发送的序列化数据 + let receivedData: MyParcelable = new MyParcelable(0, ''); + data.readParcelable(receivedData); + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', `receiveData[${receivedData.num}, ${receivedData.str}]`); + let num: number = receivedData.num; + + // 作相应处理 + // 返回序列化数据result给Caller + return new MyParcelable(num + 1, `send ${receivedData.str} succeed`) as rpc.Parcelable; +}; + +export default class CalleeAbility extends UIAbility { + caller: Caller | undefined; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.callee.on(MSG_SEND_METHOD, sendMsgCallback); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', `Failed to register. Error is ${error}`); + }; + }; + + async onButtonCall(): Promise { + try { + let msg: MyParcelable = new MyParcelable(1, 'origin_Msg'); + if (this.caller) { + await this.caller.call(MSG_SEND_METHOD, msg); + } + } catch (error) { + hilog.info(DOMAIN_NUMBER, TAG, `caller call failed with ${error}`); + }; + }; + + async onButtonCallWithResult(originMsg: string, backMsg: string): Promise { + try { + let msg: MyParcelable = new MyParcelable(1, originMsg); + if (this.caller) { + const data = await this.caller.callWithResult(MSG_SEND_METHOD, msg); + hilog.info(DOMAIN_NUMBER, TAG, 'caller callWithResult succeed'); + let result: MyParcelable = new MyParcelable(0, ''); + data.readParcelable(result); + backMsg = result.str; + hilog.info(DOMAIN_NUMBER, TAG, `caller result is [${result.num}, ${result.str}]`); + } + } catch (error) { + hilog.info(DOMAIN_NUMBER, TAG, `caller callWithResult failed with ${error}`); + }; + }; + + releaseCall(): void { + try { + if (this.caller) { + this.caller.release(); + this.caller = undefined; + } + hilog.info(DOMAIN_NUMBER, TAG, 'caller release succeed'); + } catch (error) { + hilog.info(DOMAIN_NUMBER, TAG, `caller release failed with ${error}`); + }; + }; + + onWindowStageCreate(windowStage: window.WindowStage): void { + // 设置UI加载 + windowStage.loadContent('pages/Page_CalleeAbility', (err, data) => { + }); + }; + + onDestroy(): void { + try { + this.callee.off(MSG_SEND_METHOD); + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Callee OnDestroy'); + this.releaseCall(); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', `Failed to register. Error is ${error}`); + }; + }; +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/collaborateability/CollaborateAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/collaborateability/CollaborateAbility.ts index 0075a932e47920cdde0c18e1e9aab31c3d50afc0..3a7cf3dc4f9bfa8c2c86e8a9da923839d7532d4a 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/collaborateability/CollaborateAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/collaborateability/CollaborateAbility.ts @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = '[CollaborateAbility]'; - -export default class CollaborateAbility extends UIAbility { - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Page_CollaborateAbility', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = '[CollaborateAbility]'; + +export default class CollaborateAbility extends UIAbility { + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Page_CollaborateAbility', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/entryability/EntryAbility.ts index 5137a3c83164b85c19acf9963d242ba786439bb0..e978e8c94a9b49f1a114e9e232b322d32e9cf4a4 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,78 +1,78 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import type Want from '@ohos.app.ability.Want'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -import type { Router, UIContext } from '@ohos.arkui.UIContext'; -import type { BusinessError } from '@ohos.base'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = '[EntryAbility]'; - -export default class EntryAbility extends UIAbility { - funcAbilityWant: Want | undefined = undefined; - uiContext: UIContext | undefined = undefined; - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - // 接收调用方UIAbility传过来的参数 - this.funcAbilityWant = want; - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - // Main window is created, set main page for this ability - let url = 'pages/Index'; - if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'funcA') { - url = 'pages/Page_ColdStartUp'; - } - - windowStage.loadContent(url, (err, data) => { - if (err.code) { - return; - } - - let windowClass: window.Window; - windowStage.getMainWindow((err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to obtain the main window. Code is ${err.code}, message is ${err.message}`); - return; - } - windowClass = data; - this.uiContext = windowClass.getUIContext(); - }); - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { - if (want?.parameters?.router && want.parameters.router === 'funcB') { - let funcAUrl = 'pages/Page_HotStartUp'; - if (this.uiContext) { - let router: Router = this.uiContext.getRouter(); - router.pushUrl({ - url: funcAUrl - }).catch((err: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to push url. Code is ${err.code}, message is ${err.message}`); - }); - } - } - }; -}; +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import type Want from '@ohos.app.ability.Want'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +import type { Router, UIContext } from '@ohos.arkui.UIContext'; +import type { BusinessError } from '@ohos.base'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = '[EntryAbility]'; + +export default class EntryAbility extends UIAbility { + funcAbilityWant: Want | undefined = undefined; + uiContext: UIContext | undefined = undefined; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 接收调用方UIAbility传过来的参数 + this.funcAbilityWant = want; + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + // Main window is created, set main page for this ability + let url = 'pages/Index'; + if (this.funcAbilityWant?.parameters?.router && this.funcAbilityWant.parameters.router === 'funcA') { + url = 'pages/Page_ColdStartUp'; + } + + windowStage.loadContent(url, (err, data) => { + if (err.code) { + return; + } + + let windowClass: window.Window; + windowStage.getMainWindow((err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to obtain the main window. Code is ${err.code}, message is ${err.message}`); + return; + } + windowClass = data; + this.uiContext = windowClass.getUIContext(); + }); + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { + if (want?.parameters?.router && want.parameters.router === 'funcB') { + let funcAUrl = 'pages/Page_HotStartUp'; + if (this.uiContext) { + let router: Router = this.uiContext.getRouter(); + router.pushUrl({ + url: funcAUrl + }).catch((err: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to push url. Code is ${err.code}, message is ${err.message}`); + }); + } + } + }; +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcability/FuncAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcability/FuncAbility.ts index 1e930b8926b4f929be7c17674fe556059a3c9662..652084d1df7760f4279091116e9bbc94b7ccfc05 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcability/FuncAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcability/FuncAbility.ts @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type window from '@ohos.window'; -import type { UIContext } from '@ohos.arkui.UIContext'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = '[FuncAbility]'; - -export default class FuncAbility extends UIAbility { - - funcAbilityWant: Want | undefined = undefined; - uiContext: UIContext | undefined = undefined; - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Page_FromStageModel', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } -}; +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type window from '@ohos.window'; +import type { UIContext } from '@ohos.arkui.UIContext'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = '[FuncAbility]'; + +export default class FuncAbility extends UIAbility { + + funcAbilityWant: Want | undefined = undefined; + uiContext: UIContext | undefined = undefined; + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Page_FromStageModel', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } +}; diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcbability/FuncBAbility.ts b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcbability/FuncBAbility.ts index b174e10333b8b69d6a91704542cd5900422c6720..a51fdddc382d108523803edf3cdba66f2124fcb7 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcbability/FuncBAbility.ts +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/funcbability/FuncBAbility.ts @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type window from '@ohos.window'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = '[FuncAbility]'; - -export default class FuncAbility extends UIAbility { - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Page_ColdStartUp', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type window from '@ohos.window'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = '[FuncAbility]'; + +export default class FuncAbility extends UIAbility { + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Page_ColdStartUp', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } +} diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CalleeAbility.ets b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CalleeAbility.ets index e1dc78961b89854bfdf1d837f734107947e4607e..9edc2977392cd87497c30c351b286311a16b37ca 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CalleeAbility.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CalleeAbility.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_CalleeAbility { - - build() { - Column() { - Row() { - Text($r('app.string.CalleePage')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224 }) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8, bottom: 317, right: 152, left: 152 }) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - .fontWeight(400) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_CalleeAbility { + + build() { + Column() { + Row() { + Text($r('app.string.CalleePage')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224 }) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8, bottom: 317, right: 152, left: 152 }) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + .fontWeight(400) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_ColdStartUp.ets b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_ColdStartUp.ets index 0a9a0b84d5229f37c038821c3592eb33ff2f764c..aa6cdd4d373060ac0a7ff6922e81607ba435f8d5 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_ColdStartUp.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_ColdStartUp.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; - -const TAG: string = '[Page_ColdStartUp]'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Page_ColdStartUp { - - build() { - Column() { - Row() { - Text($r('app.string.FunctionA')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Button($r('app.string.FuncAbilityD')) - .fontFamily('HarmonyHeiTi') - .height(48) - .width('624px') - .margin({ top: 550 }) - .type(ButtonType.Capsule) - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('app.color.button_color')) - .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - // 绑定点击事件 - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - // context为需要停止的UIAbility实例的AbilityContext - context.terminateSelf((err) => { - if (err.code) { - hilog.error(0x0000, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`); - return; - } - }); - }) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; + +const TAG: string = '[Page_ColdStartUp]'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Page_ColdStartUp { + + build() { + Column() { + Row() { + Text($r('app.string.FunctionA')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Button($r('app.string.FuncAbilityD')) + .fontFamily('HarmonyHeiTi') + .height(48) + .width('624px') + .margin({ top: 550 }) + .type(ButtonType.Capsule) + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('app.color.button_color')) + .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + // 绑定点击事件 + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + // context为需要停止的UIAbility实例的AbilityContext + context.terminateSelf((err) => { + if (err.code) { + hilog.error(0x0000, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`); + return; + } + }); + }) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CollaborateAbility.ets b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CollaborateAbility.ets index 965f0025b8daab1afe4d26eb34eb39be01867026..4267db1eae453aa926adcefa53302dfa4f94fd40 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CollaborateAbility.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_CollaborateAbility.ets @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; -import { BusinessError } from '@ohos.base'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = '[Page_CollaborateAbility]'; - -@Entry -@Component -struct Page_CollaborateAbility { - - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Text($r('app.string.Page_CollaborateAbility')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Button($r('app.string.ClosePage_CollaborateAbility')) - .fontFamily('HarmonyHeiTi') - .height(48) - .width('624px') - .margin({ top: 550 }) - .type(ButtonType.Capsule) - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('app.color.button_color')) - .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - .onClick(()=>{ - const RESULT_CODE: number = 1001; - // context为目标端UIAbility的AbilityContext - this.context.terminateSelfWithResult( - { - resultCode: RESULT_CODE, - want: { - bundleName: 'com.samples.stagemodelabilitydevelop', - abilityName: 'CollaborateAbility', - moduleName: 'entry', - parameters: { - info: '来自Page_CollaborateAbility页面' - } - } - }, - (err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, `terminateSelfWithResult err: ` + JSON.stringify(err)); - }); - }) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; +import { BusinessError } from '@ohos.base'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = '[Page_CollaborateAbility]'; + +@Entry +@Component +struct Page_CollaborateAbility { + + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Text($r('app.string.Page_CollaborateAbility')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Button($r('app.string.ClosePage_CollaborateAbility')) + .fontFamily('HarmonyHeiTi') + .height(48) + .width('624px') + .margin({ top: 550 }) + .type(ButtonType.Capsule) + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('app.color.button_color')) + .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .onClick(()=>{ + const RESULT_CODE: number = 1001; + // context为目标端UIAbility的AbilityContext + this.context.terminateSelfWithResult( + { + resultCode: RESULT_CODE, + want: { + bundleName: 'com.samples.stagemodelabilitydevelop', + abilityName: 'CollaborateAbility', + moduleName: 'entry', + parameters: { + info: '来自Page_CollaborateAbility页面' + } + } + }, + (err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, `terminateSelfWithResult err: ` + JSON.stringify(err)); + }); + }) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_FromStageModel.ets b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_FromStageModel.ets index d12d754a1023b19c67acefb72bba4b97fb95fe83..ef516cb938d60ef2e9828dbe34f44255163bf11a 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_FromStageModel.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_FromStageModel.ets @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import hilog from '@ohos.hilog'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = '[Page_FromStageModel]'; - -@Entry -@Component -struct Page_FromStageModel { - - build() { - Column() { - Row() { - Text($r('app.string.FuncAbilityA')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Button($r('app.string.FuncAbilityB')) - .fontFamily('HarmonyHeiTi') - .height(48) - .width('624px') - .margin({ top: 550 }) - .type(ButtonType.Capsule) - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('app.color.button_color')) - .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - .onClick(() => { - let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext - // context为需要停止的UIAbility实例的AbilityContext - context.terminateSelf((err) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`); - return; - } - }); - }) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import hilog from '@ohos.hilog'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = '[Page_FromStageModel]'; + +@Entry +@Component +struct Page_FromStageModel { + + build() { + Column() { + Row() { + Text($r('app.string.FuncAbilityA')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Button($r('app.string.FuncAbilityB')) + .fontFamily('HarmonyHeiTi') + .height(48) + .width('624px') + .margin({ top: 550 }) + .type(ButtonType.Capsule) + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('app.color.button_color')) + .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + .onClick(() => { + let context:common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext + // context为需要停止的UIAbility实例的AbilityContext + context.terminateSelf((err) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to terminate self. Code is ${err.code}, message is ${err.message}`); + return; + } + }); + }) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_HotStartUp.ets b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_HotStartUp.ets index 9a283aa5773686d90177a3ca826695ea66705621..88862e6cbd2f4d80a894b06bc388c5b442a09517 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_HotStartUp.ets +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/ets/pages/Page_HotStartUp.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Page_HotStartUp { - - build() { - Column() { - Row() { - Text($r('app.string.FunctionB')) - .fontSize(24) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - - Image($r('app.media.pic_empty')) - .width(120) - .height(120) - .margin({ top: 224 }) - - Text($r('app.string.NoContentAvailable')) - .fontSize(14) - .margin({ top: 8, bottom: 317, right: 152, left: 152 }) - .fontColor($r('app.color.text_color')) - .opacity(0.4) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Page_HotStartUp { + + build() { + Column() { + Row() { + Text($r('app.string.FunctionB')) + .fontSize(24) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + + Image($r('app.media.pic_empty')) + .width(120) + .height(120) + .margin({ top: 224 }) + + Text($r('app.string.NoContentAvailable')) + .fontSize(14) + .margin({ top: 8, bottom: 317, right: 152, left: 152 }) + .fontColor($r('app.color.text_color')) + .opacity(0.4) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/module.json5 index 040ce9cb635475c18ae912cf7c11b8882f63115e..c653608483fb0abc01c75c7b05cc6dd8f837c8c5 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/module.json5 @@ -1,143 +1,143 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "FuncAbility", - "srcEntry": "./ets/funcability/FuncAbility.ts", - "description": "$string:FuncAbility_desc", - "icon": "$media:icon", - "label": "$string:FuncAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.default" - ], - "actions": [ - "ohos.want.action.viewData" - ] - } - ] - }, - { - "name": "CollaborateAbility", - "srcEntry": "./ets/collaborateability/CollaborateAbility.ts", - "description": "$string:CollaborateAbility_desc", - "icon": "$media:icon", - "label": "$string:CollaborateAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true - }, - { - "name": "CalleeAbility", - "srcEntry": "./ets/calleeability/CalleeAbility.ts", - "description": "$string:CalleeAbility_desc", - "icon": "$media:icon", - "label": "$string:CalleeAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "launchType": "singleton", - "exported": true - }, - { - "name": "FuncBAbility", - "srcEntry": "./ets/funcbability/FuncBAbility.ts", - "description": "$string:FuncBAbility_desc", - "icon": "$media:icon", - "label": "$string:FuncBAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.default" - ], - "actions": [ - "ohos.want.action.editData" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - }, - { - "name": "ohos.permission.START_INVISIBLE_ABILITY", - }, - { - "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", - }, - { - "name": "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION", - } - ], - "extensionAbilities": [ - { - "name": "ServiceExtAbility", - "srcEntry": "./ets/serviceextability/ServiceExtAbility.ts", - "description": "$string:ServiceExtAbility_desc", - "label": "$string:ServiceExtAbility_label", - "type": "service", - "exported": true, - "metadata": [ - { - "name": "ohos.extension.service", - "resource": "$profile:serviceextability" - } - ] - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "FuncAbility", + "srcEntry": "./ets/funcability/FuncAbility.ts", + "description": "$string:FuncAbility_desc", + "icon": "$media:icon", + "label": "$string:FuncAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.default" + ], + "actions": [ + "ohos.want.action.viewData" + ] + } + ] + }, + { + "name": "CollaborateAbility", + "srcEntry": "./ets/collaborateability/CollaborateAbility.ts", + "description": "$string:CollaborateAbility_desc", + "icon": "$media:icon", + "label": "$string:CollaborateAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true + }, + { + "name": "CalleeAbility", + "srcEntry": "./ets/calleeability/CalleeAbility.ts", + "description": "$string:CalleeAbility_desc", + "icon": "$media:icon", + "label": "$string:CalleeAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "launchType": "singleton", + "exported": true + }, + { + "name": "FuncBAbility", + "srcEntry": "./ets/funcbability/FuncBAbility.ts", + "description": "$string:FuncBAbility_desc", + "icon": "$media:icon", + "label": "$string:FuncBAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.default" + ], + "actions": [ + "ohos.want.action.editData" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + }, + { + "name": "ohos.permission.START_INVISIBLE_ABILITY", + }, + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", + }, + { + "name": "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION", + } + ], + "extensionAbilities": [ + { + "name": "ServiceExtAbility", + "srcEntry": "./ets/serviceextability/ServiceExtAbility.ts", + "description": "$string:ServiceExtAbility_desc", + "label": "$string:ServiceExtAbility_label", + "type": "service", + "exported": true, + "metadata": [ + { + "name": "ohos.extension.service", + "resource": "$profile:serviceextability" + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/element/color.json index 940b8e80b740675551969422468b395b70c04c37..eb1a630dc398f79c67003a6f2dc14c55b0cf3119 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#f1f3f5" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - }, - { - "name": "button_color", - "value": "#027DFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#f1f3f5" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#182431" + }, + { + "name": "button_color", + "value": "#027DFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/profile/serviceextability.json b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/profile/serviceextability.json index ea557371205892b3f11f8175e10bf9d819bde46d..85c3d8af6f10a4bda8e6b90f21ab6b28a8acec5c 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/profile/serviceextability.json +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/entry/src/main/resources/base/profile/serviceextability.json @@ -1,8 +1,8 @@ -{ - "accessibilityCapabilities": [ - "retrieve", - "keyEventObserver", - "gesture", - "touchGuide" - ] +{ + "accessibilityCapabilities": [ + "retrieve", + "keyEventObserver", + "gesture", + "touchGuide" + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/hvigor/hvigor-config.json5 index 7fcecec159df6759049a45fd7a400d1fbaffeab4..dba571014f1a9610f06d593adbcdf6c0097948e6 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/oh-package.json5 b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/oh-package.json5 index f9e69b7bf082709cbf6cb3c5294720e2cf189d0b..4cc27b5a494b22f16df5e777ab2a39b69dfc23f4 100644 --- a/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/StageModelAbilityInteraction/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "stagemodelabilityinteraction", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "stagemodelabilityinteraction", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/app.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/app.json5 index f0eacd2abb349131f40440fc9c4b5fa33b291202..31c4b28f77454208695775fa2dae4a9a02b2dc7d 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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.stageprocessthread", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.stageprocessthread", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/resources/base/element/string.json index 7ec9f9eae046f2832a7c71245a3baac1499d131e..0bc5f904251a118e8d3ecc595d7d50e1ba9a133b 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/StageProcessThread/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "StageProcessThread" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "StageProcessThread" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/build-profile.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/build-profile.json5 index b3c7006645d2babeb5d114e3203429eedbe4e91e..2549e470214bc23b513044d186e5b7484a4adad3 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/entry/build-profile.json5 index 9cd0b63f73f2bf354918695319aa027129e893b4..b2e1b5ba3f99d0ab051d685c87b021392165d413 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/build-profile.json5 @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2023 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": { - "sourceOption": { - "workers": [ - "./src/main/ets/workers/Worker.ts" - ] - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/Worker.ts" + ] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/entry/oh-package.json5 index b31d93383c958c2a6f22317cae74bec37b36bc10..6876164b6ab4ebb24026d69c3302c8d120d87bd5 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/entryability/EntryAbility.ts index a4b5f95b55d6e4406831f1bb744056ed4660786e..d5f2afce2f40f5682043df692cac871019e47799 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,87 +1,87 @@ -/* - * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import type common from '@ohos.app.ability.common'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type { BusinessError } from '@ohos.base'; -import image from '@ohos.multimedia.image'; -import type resourceManager from '@ohos.resourceManager'; -import type window from '@ohos.window'; -import hilog from '@ohos.hilog'; -import commonEventManager from '@ohos.commonEventManager'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = 'EntryAbility'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - let context: common.UIAbilityContext = this.context; // UIAbilityContext - // 设置任务快照的名称 - context.setMissionLabel('test').then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in seting mission label.'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, `Failed to set mission label. Code is ${err.code}, message is ${err.message}`); - }); - - // 获取resourceManager资源管理 - const resourceMgr: resourceManager.ResourceManager = this.context.resourceManager; - resourceMgr.getRawFileContent('test.jpg').then((data) => { - hilog.info(DOMAIN_NUMBER, TAG, 'data.length = ' + data.byteLength); - // 获取图片的ArrayBuffer - const imageSource: image.ImageSource = image.createImageSource(data.buffer); - imageSource.createPixelMap().then((pixelMap) => { - // 设置任务快照的图标 - context.setMissionIcon(pixelMap, (err) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to set mission icon. Code is ${err.code}, message is ${err.message}`); - } else { - hilog.info(DOMAIN_NUMBER, TAG, 'Success to set mission icon.'); - } - }) - pixelMap.release(); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, 'setMissionIcon failed: ' + JSON.stringify(error)); - }); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, 'getRawFileContent failed: ' + JSON.stringify(error)); - }); - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onCreate'); - } - - // onDestroy():void { - // commonEventManager.removeStickyCommonEvent('usual.event.SCREEN_OFF', (err: Base.BusinessError) => { - // // sticky_event粘性公共事件名 - // if (err) { - // hilog.error(DOMAIN_NUMBER, TAG, `Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`); - // return; - // } - // hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in removeing sticky event.`); - // }); - // } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause:', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data:', JSON.stringify(data) ?? ''); - }); - } -} +/* + * Copyright (c) 2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import type common from '@ohos.app.ability.common'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type { BusinessError } from '@ohos.base'; +import image from '@ohos.multimedia.image'; +import type resourceManager from '@ohos.resourceManager'; +import type window from '@ohos.window'; +import hilog from '@ohos.hilog'; +import commonEventManager from '@ohos.commonEventManager'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = 'EntryAbility'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + let context: common.UIAbilityContext = this.context; // UIAbilityContext + // 设置任务快照的名称 + context.setMissionLabel('test').then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in seting mission label.'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, `Failed to set mission label. Code is ${err.code}, message is ${err.message}`); + }); + + // 获取resourceManager资源管理 + const resourceMgr: resourceManager.ResourceManager = this.context.resourceManager; + resourceMgr.getRawFileContent('test.jpg').then((data) => { + hilog.info(DOMAIN_NUMBER, TAG, 'data.length = ' + data.byteLength); + // 获取图片的ArrayBuffer + const imageSource: image.ImageSource = image.createImageSource(data.buffer); + imageSource.createPixelMap().then((pixelMap) => { + // 设置任务快照的图标 + context.setMissionIcon(pixelMap, (err) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to set mission icon. Code is ${err.code}, message is ${err.message}`); + } else { + hilog.info(DOMAIN_NUMBER, TAG, 'Success to set mission icon.'); + } + }) + pixelMap.release(); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'setMissionIcon failed: ' + JSON.stringify(error)); + }); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, 'getRawFileContent failed: ' + JSON.stringify(error)); + }); + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onCreate'); + } + + // onDestroy():void { + // commonEventManager.removeStickyCommonEvent('usual.event.SCREEN_OFF', (err: Base.BusinessError) => { + // // sticky_event粘性公共事件名 + // if (err) { + // hilog.error(DOMAIN_NUMBER, TAG, `Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`); + // return; + // } + // hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in removeing sticky event.`); + // }); + // } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause:', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data:', JSON.stringify(data) ?? ''); + }); + } +} diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageProcessModel.ets b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageProcessModel.ets index 35903cd7de98edb060d9003a60058ad6116d2cb2..513dc7ff17251abf236ec9fe09edb3e9d4a3c84c 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageProcessModel.ets +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageProcessModel.ets @@ -1,332 +1,332 @@ -/* - * Copyright (c) 2023 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 Base from '@ohos.base'; -import commonEventManager from '@ohos.commonEventManager'; -import promptAction from '@ohos.promptAction'; -import hilog from '@ohos.hilog'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = 'ProcessModel'; - -@Entry -@Component -struct PageProcessModel { - // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 - private subscriber: commonEventManager.CommonEventSubscriber | null = null; - // 订阅者信息 - private subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { - events: ['usual.event.SCREEN_OFF'], // 订阅灭屏公共事件 - }; - // 判断当前是否发送过粘性公共事件 - private ifSendStickyKey: boolean = false; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.process_button')) - .fontSize(24) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.subscribe_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - - } - .onClick(() => { - if (this.subscriber !== null) { - promptAction.showToast({ - message: $r('app.string.subscribe_failed_toast') - }); - return; - } - // 创建订阅者回调 - commonEventManager.createSubscriber(this.subscribeInfo, (err: Base.BusinessError, data: commonEventManager.CommonEventSubscriber) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in creating subscriber.'); - this.subscriber = data; - - // 订阅公共事件回调 - if (this.subscriber !== null) { - commonEventManager.subscribe(this.subscriber, (err: Base.BusinessError, data: commonEventManager.CommonEventData) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to subscribe common event. Code is ${err.code}, message is ${err.message}`); - return; - } - promptAction.showToast({ - message: JSON.stringify(data) - }); - hilog.info(DOMAIN_NUMBER, TAG, `Receive CommonEventData = ` + JSON.stringify(data)); - }) - if (this.ifSendStickyKey === false) { - promptAction.showToast({ - message: $r('app.string.subscribe_success_toast') - }); - } - } else { - hilog.error(DOMAIN_NUMBER, TAG, `Need create subscriber`); - } - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row(){ - Text($r('app.string.unsubscribe_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // subscriber为订阅事件时创建的订阅者对象 - if (this.subscriber !== null) { - commonEventManager.unsubscribe(this.subscriber, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `UnsubscribeCallBack err = ${JSON.stringify(err)}`); - } else { - promptAction.showToast({ - message: $r('app.string.unsubscribe_success_toast') - }); - hilog.info(DOMAIN_NUMBER, TAG, `Unsubscribe success`); - this.subscriber = null; - } - }) - } else { - promptAction.showToast({ - message: $r('app.string.unsubscribe_failed_toast') - }); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.publish_noinfo_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 发布公共事件 - commonEventManager.publish('usual.event.SCREEN_OFF', (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `PublishCallBack err = ${JSON.stringify(err)}`); - } else { - if (this.subscriber === null) { - promptAction.showToast({ - message: $r('app.string.publish_noinfo_success_toast') - }); - } - hilog.info(DOMAIN_NUMBER, TAG, `Publish success`); - } - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.publish_haveinfo_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 公共事件相关信息 - let options: commonEventManager.CommonEventPublishData = { - code: 1, // 公共事件的初始代码 - data: 'initial data', // 公共事件的初始数据 - }; - - // 发布公共事件 - commonEventManager.publish('usual.event.SCREEN_OFF', options, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, 'PublishCallBack err = ' + JSON.stringify(err)); - } else { - if (this.subscriber === null) { - promptAction.showToast({ - message: $r('app.string.publish_haveinfo_success_toast') - }); - } - hilog.info(DOMAIN_NUMBER, TAG, 'Publish success'); - } - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.publish_sticky_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 公共事件相关信息 - let options: commonEventManager.CommonEventPublishData = { - code: 1, // 公共事件的初始代码 - data: 'initial Sticky data', // 公共事件的初始数据 - isSticky: true - }; - - // 发布公共事件 - commonEventManager.publish('usual.event.SCREEN_OFF', options, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, 'PublishCallBack err=' + JSON.stringify(err)); - } else { - promptAction.showToast({ - message: $r('app.string.publish_sticky_success_toast') - }); - this.ifSendStickyKey = true; - hilog.info(DOMAIN_NUMBER, TAG, 'Publish success'); - } - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.remove_sticky_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - commonEventManager.removeStickyCommonEvent('usual.event.SCREEN_OFF', (err: Base.BusinessError) => { - // sticky_event粘性公共事件名 - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`); - return; - } - promptAction.showToast({ - message: $r('app.string.remove_sticky_success_toast') - }); - this.ifSendStickyKey = false; - hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in removeing sticky event.`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } - +/* + * Copyright (c) 2023 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 Base from '@ohos.base'; +import commonEventManager from '@ohos.commonEventManager'; +import promptAction from '@ohos.promptAction'; +import hilog from '@ohos.hilog'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = 'ProcessModel'; + +@Entry +@Component +struct PageProcessModel { + // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + private subscriber: commonEventManager.CommonEventSubscriber | null = null; + // 订阅者信息 + private subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { + events: ['usual.event.SCREEN_OFF'], // 订阅灭屏公共事件 + }; + // 判断当前是否发送过粘性公共事件 + private ifSendStickyKey: boolean = false; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.process_button')) + .fontSize(24) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.subscribe_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + + } + .onClick(() => { + if (this.subscriber !== null) { + promptAction.showToast({ + message: $r('app.string.subscribe_failed_toast') + }); + return; + } + // 创建订阅者回调 + commonEventManager.createSubscriber(this.subscribeInfo, (err: Base.BusinessError, data: commonEventManager.CommonEventSubscriber) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in creating subscriber.'); + this.subscriber = data; + + // 订阅公共事件回调 + if (this.subscriber !== null) { + commonEventManager.subscribe(this.subscriber, (err: Base.BusinessError, data: commonEventManager.CommonEventData) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to subscribe common event. Code is ${err.code}, message is ${err.message}`); + return; + } + promptAction.showToast({ + message: JSON.stringify(data) + }); + hilog.info(DOMAIN_NUMBER, TAG, `Receive CommonEventData = ` + JSON.stringify(data)); + }) + if (this.ifSendStickyKey === false) { + promptAction.showToast({ + message: $r('app.string.subscribe_success_toast') + }); + } + } else { + hilog.error(DOMAIN_NUMBER, TAG, `Need create subscriber`); + } + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row(){ + Text($r('app.string.unsubscribe_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // subscriber为订阅事件时创建的订阅者对象 + if (this.subscriber !== null) { + commonEventManager.unsubscribe(this.subscriber, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `UnsubscribeCallBack err = ${JSON.stringify(err)}`); + } else { + promptAction.showToast({ + message: $r('app.string.unsubscribe_success_toast') + }); + hilog.info(DOMAIN_NUMBER, TAG, `Unsubscribe success`); + this.subscriber = null; + } + }) + } else { + promptAction.showToast({ + message: $r('app.string.unsubscribe_failed_toast') + }); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.publish_noinfo_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 发布公共事件 + commonEventManager.publish('usual.event.SCREEN_OFF', (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `PublishCallBack err = ${JSON.stringify(err)}`); + } else { + if (this.subscriber === null) { + promptAction.showToast({ + message: $r('app.string.publish_noinfo_success_toast') + }); + } + hilog.info(DOMAIN_NUMBER, TAG, `Publish success`); + } + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.publish_haveinfo_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 公共事件相关信息 + let options: commonEventManager.CommonEventPublishData = { + code: 1, // 公共事件的初始代码 + data: 'initial data', // 公共事件的初始数据 + }; + + // 发布公共事件 + commonEventManager.publish('usual.event.SCREEN_OFF', options, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, 'PublishCallBack err = ' + JSON.stringify(err)); + } else { + if (this.subscriber === null) { + promptAction.showToast({ + message: $r('app.string.publish_haveinfo_success_toast') + }); + } + hilog.info(DOMAIN_NUMBER, TAG, 'Publish success'); + } + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.publish_sticky_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 公共事件相关信息 + let options: commonEventManager.CommonEventPublishData = { + code: 1, // 公共事件的初始代码 + data: 'initial Sticky data', // 公共事件的初始数据 + isSticky: true + }; + + // 发布公共事件 + commonEventManager.publish('usual.event.SCREEN_OFF', options, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, 'PublishCallBack err=' + JSON.stringify(err)); + } else { + promptAction.showToast({ + message: $r('app.string.publish_sticky_success_toast') + }); + this.ifSendStickyKey = true; + hilog.info(DOMAIN_NUMBER, TAG, 'Publish success'); + } + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.remove_sticky_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + commonEventManager.removeStickyCommonEvent('usual.event.SCREEN_OFF', (err: Base.BusinessError) => { + // sticky_event粘性公共事件名 + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to remove sticky common event. Code is ${err.code}, message is ${err.message}`); + return; + } + promptAction.showToast({ + message: $r('app.string.remove_sticky_success_toast') + }); + this.ifSendStickyKey = false; + hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in removeing sticky event.`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } + } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageTaskManager.ets b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageTaskManager.ets index 81e0357faa36c7a4307224bbe3dc52870336048d..22327b239a0ab120cc282bfc042180967150e7f1 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageTaskManager.ets +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageTaskManager.ets @@ -1,462 +1,462 @@ -/* - * Copyright (c) 2023 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 missionManager from '@ohos.app.ability.missionManager'; -import { BusinessError } from '@ohos.base'; -import image from '@ohos.multimedia.image'; -import promptAction from '@ohos.promptAction'; -import hilog from '@ohos.hilog'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = 'TaskManager'; - -@Entry -@Component -struct PageTaskManager { - private listenerId: number = 0; - private missionId: number = 0; - private listener: missionManager.MissionListener = { - // 任务创建 - onMissionCreated: (mission: number) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionCreated-------'); - }, - // 任务销毁 - onMissionDestroyed: (mission: number) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionDestroyed-------'); - }, - // 任务快照变化 - onMissionSnapshotChanged: (mission: number) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionSnapshotChanged-------'); - }, - // 任务被移动到前台 - onMissionMovedToFront: (mission: number) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionMovedToFront-------'); - }, - // 任务图标变化 - onMissionIconUpdated: (mission: number, icon: image.PixelMap) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionIconUpdated-------'); - }, - // 任务名称变化 - onMissionLabelUpdated: (mission: number) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionLabelUpdated-------'); - }, - // 任务实例被关闭 - onMissionClosed: (mission: number) => { - hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionClosed-------'); - } - }; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.taskmanager_button')) - .fontSize(24) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Start) - .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row(){ - Text($r('app.string.register_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - - } - .onClick(() => { - // 1.注册任务变化通知 - this.listenerId = missionManager.on('mission', this.listener); - promptAction.showToast({ - message: $r('app.string.register_success_toast') - }); - hilog.info(DOMAIN_NUMBER, TAG, `missionManager.on success, listenerId = ${this.listenerId}`); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row(){ - Text($r('app.string.obtain_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 2.获取系统最近20个任务 - missionManager.getMissionInfos('', 20, (error: BusinessError, missions: Array) => { - hilog.info(DOMAIN_NUMBER, TAG, 'getMissionInfos is called, error = ' + JSON.stringify(error)); - hilog.info(DOMAIN_NUMBER, TAG, 'size = ' + missions.length); - hilog.info(DOMAIN_NUMBER, TAG, 'missions = ' + JSON.stringify(missions)); - - // 判断系统最近任务中是否包含etsclock - for (let i = 0;i < missions.length; i++) { - if (missions[i].want.bundleName === 'ohos.samples.etsclock') { - promptAction.showToast({ - message: $r('app.string.obtain_success_toast') - }); - hilog.info(DOMAIN_NUMBER, TAG, `getMissionInfos.find etsclock, missionId = ${missions[i].missionId}`); - this.missionId = missions[i].missionId; - return; - } - } - promptAction.showToast({ - message: $r('app.string.obtain_failed_toast') - }); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.obtain_one_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 3.获取单个任务的详细信息() - missionManager.getMissionInfo('', this.missionId).then((data: missionManager.MissionInfo) => { - promptAction.showToast({ - message: JSON.stringify(data.want.bundleName) - }); - hilog.info(DOMAIN_NUMBER, TAG, `getMissionInfo successfully. Data: ${JSON.stringify(data)}`); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `getMissionInfo failed. Cause: ${error.message}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.obtain_snapshot_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - - } - .onClick(() => { - // 4.获取任务快照 - missionManager.getMissionSnapShot('', this.missionId, (error: BusinessError, snapshot: missionManager.MissionSnapshot) => { - if (error === null) { - promptAction.showToast({ - message: $r('app.string.obtain_snapshot_success_toast') - }); - } - hilog.info(DOMAIN_NUMBER, TAG, 'getMissionSnapShot is called, error = ' + JSON.stringify(error)); - hilog.info(DOMAIN_NUMBER, TAG, 'bundleName = ' + snapshot.ability.bundleName); - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row(){ - Text($r('app.string.obtain_low_snapshot_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 5.获取低分辨任务快照 - missionManager.getLowResolutionMissionSnapShot('', this.missionId, (error: BusinessError, snapshot: missionManager.MissionSnapshot) => { - if (error === null) { - promptAction.showToast({ - message: $r('app.string.obtain_low_snapshot_success_toast') - }); - } - hilog.info(DOMAIN_NUMBER, TAG, 'getLowResolutionMissionSnapShot is called, error = ' + JSON.stringify(error)); - hilog.info(DOMAIN_NUMBER, TAG, 'bundleName = ' + snapshot.ability.bundleName); - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.lock_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 6-1 加锁任务 - missionManager.lockMission(this.missionId).then(() => { - promptAction.showToast({ - message: $r('app.string.lock_success_toast') - }); - hilog.info(DOMAIN_NUMBER, TAG, 'lockMission is called '); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.unlock_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - - } - .onClick(() => { - // 6-2 解锁任务 - missionManager.unlockMission(this.missionId).then(() => { - promptAction.showToast({ - message: $r('app.string.unlock_success_toast') - }); - hilog.info(DOMAIN_NUMBER, TAG, 'unlockMission is called '); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row(){ - Text($r('app.string.front_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 7.把任务切到前台 - missionManager.moveMissionToFront(this.missionId).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'moveMissionToFront is called '); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.delete_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 8.删除单个任务 - missionManager.clearMission(this.missionId).then(() => { - promptAction.showToast({ - message: $r('app.string.delete_success_toast') - }); - hilog.info(DOMAIN_NUMBER, TAG, 'clearMission is called '); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.delete_all_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 9.删除全部任务 - missionManager.clearAllMissions().catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, `${err.code}`); - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row(){ - Text($r('app.string.unregister_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .width(232) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 10.解注册任务变化通知 - missionManager.off('mission', this.listenerId, (error: BusinessError) => { - if (error === null) { - promptAction.showToast({ - message: $r('app.string.unregister_success_toast') - }); - } - hilog.info(DOMAIN_NUMBER, TAG, 'unregisterMissionListener'); - }) - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('92%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 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 missionManager from '@ohos.app.ability.missionManager'; +import { BusinessError } from '@ohos.base'; +import image from '@ohos.multimedia.image'; +import promptAction from '@ohos.promptAction'; +import hilog from '@ohos.hilog'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = 'TaskManager'; + +@Entry +@Component +struct PageTaskManager { + private listenerId: number = 0; + private missionId: number = 0; + private listener: missionManager.MissionListener = { + // 任务创建 + onMissionCreated: (mission: number) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionCreated-------'); + }, + // 任务销毁 + onMissionDestroyed: (mission: number) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionDestroyed-------'); + }, + // 任务快照变化 + onMissionSnapshotChanged: (mission: number) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionSnapshotChanged-------'); + }, + // 任务被移动到前台 + onMissionMovedToFront: (mission: number) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionMovedToFront-------'); + }, + // 任务图标变化 + onMissionIconUpdated: (mission: number, icon: image.PixelMap) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionIconUpdated-------'); + }, + // 任务名称变化 + onMissionLabelUpdated: (mission: number) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionLabelUpdated-------'); + }, + // 任务实例被关闭 + onMissionClosed: (mission: number) => { + hilog.info(DOMAIN_NUMBER, TAG, '--------onMissionClosed-------'); + } + }; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.taskmanager_button')) + .fontSize(24) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ top: 12 , bottom: 11 , right: 24 , left: 24}) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row(){ + Text($r('app.string.register_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + + } + .onClick(() => { + // 1.注册任务变化通知 + this.listenerId = missionManager.on('mission', this.listener); + promptAction.showToast({ + message: $r('app.string.register_success_toast') + }); + hilog.info(DOMAIN_NUMBER, TAG, `missionManager.on success, listenerId = ${this.listenerId}`); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row(){ + Text($r('app.string.obtain_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 2.获取系统最近20个任务 + missionManager.getMissionInfos('', 20, (error: BusinessError, missions: Array) => { + hilog.info(DOMAIN_NUMBER, TAG, 'getMissionInfos is called, error = ' + JSON.stringify(error)); + hilog.info(DOMAIN_NUMBER, TAG, 'size = ' + missions.length); + hilog.info(DOMAIN_NUMBER, TAG, 'missions = ' + JSON.stringify(missions)); + + // 判断系统最近任务中是否包含etsclock + for (let i = 0;i < missions.length; i++) { + if (missions[i].want.bundleName === 'ohos.samples.etsclock') { + promptAction.showToast({ + message: $r('app.string.obtain_success_toast') + }); + hilog.info(DOMAIN_NUMBER, TAG, `getMissionInfos.find etsclock, missionId = ${missions[i].missionId}`); + this.missionId = missions[i].missionId; + return; + } + } + promptAction.showToast({ + message: $r('app.string.obtain_failed_toast') + }); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.obtain_one_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 3.获取单个任务的详细信息() + missionManager.getMissionInfo('', this.missionId).then((data: missionManager.MissionInfo) => { + promptAction.showToast({ + message: JSON.stringify(data.want.bundleName) + }); + hilog.info(DOMAIN_NUMBER, TAG, `getMissionInfo successfully. Data: ${JSON.stringify(data)}`); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `getMissionInfo failed. Cause: ${error.message}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.obtain_snapshot_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + + } + .onClick(() => { + // 4.获取任务快照 + missionManager.getMissionSnapShot('', this.missionId, (error: BusinessError, snapshot: missionManager.MissionSnapshot) => { + if (error === null) { + promptAction.showToast({ + message: $r('app.string.obtain_snapshot_success_toast') + }); + } + hilog.info(DOMAIN_NUMBER, TAG, 'getMissionSnapShot is called, error = ' + JSON.stringify(error)); + hilog.info(DOMAIN_NUMBER, TAG, 'bundleName = ' + snapshot.ability.bundleName); + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row(){ + Text($r('app.string.obtain_low_snapshot_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 5.获取低分辨任务快照 + missionManager.getLowResolutionMissionSnapShot('', this.missionId, (error: BusinessError, snapshot: missionManager.MissionSnapshot) => { + if (error === null) { + promptAction.showToast({ + message: $r('app.string.obtain_low_snapshot_success_toast') + }); + } + hilog.info(DOMAIN_NUMBER, TAG, 'getLowResolutionMissionSnapShot is called, error = ' + JSON.stringify(error)); + hilog.info(DOMAIN_NUMBER, TAG, 'bundleName = ' + snapshot.ability.bundleName); + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.lock_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 6-1 加锁任务 + missionManager.lockMission(this.missionId).then(() => { + promptAction.showToast({ + message: $r('app.string.lock_success_toast') + }); + hilog.info(DOMAIN_NUMBER, TAG, 'lockMission is called '); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.unlock_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + + } + .onClick(() => { + // 6-2 解锁任务 + missionManager.unlockMission(this.missionId).then(() => { + promptAction.showToast({ + message: $r('app.string.unlock_success_toast') + }); + hilog.info(DOMAIN_NUMBER, TAG, 'unlockMission is called '); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row(){ + Text($r('app.string.front_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 7.把任务切到前台 + missionManager.moveMissionToFront(this.missionId).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'moveMissionToFront is called '); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.delete_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 8.删除单个任务 + missionManager.clearMission(this.missionId).then(() => { + promptAction.showToast({ + message: $r('app.string.delete_success_toast') + }); + hilog.info(DOMAIN_NUMBER, TAG, 'clearMission is called '); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.delete_all_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 9.删除全部任务 + missionManager.clearAllMissions().catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, `${err.code}`); + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row(){ + Text($r('app.string.unregister_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .width(232) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 10.解注册任务变化通知 + missionManager.off('mission', this.listenerId, (error: BusinessError) => { + if (error === null) { + promptAction.showToast({ + message: $r('app.string.unregister_success_toast') + }); + } + hilog.info(DOMAIN_NUMBER, TAG, 'unregisterMissionListener'); + }) + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('92%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageThreadModel.ets b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageThreadModel.ets index 835fa534e61f97f51df4c5e935639730087ff16d..cd88089ee483da69972a94d009c14d3ea80a954c 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageThreadModel.ets +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/pages/PageThreadModel.ets @@ -1,175 +1,175 @@ -/* - * Copyright (c) 2023 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 emitter from '@ohos.events.emitter'; -import promptAction from '@ohos.promptAction'; -import worker from '@ohos.worker'; -import hilog from '@ohos.hilog'; - -const DOMAIN_NUMBER: number = 0xFF00; -const TAG: string = 'ThreadModel'; - -@Entry -@Component -struct PageThreadModel { - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.thread_button')) - .fontSize(24) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Start) - .margin({ top: 12, bottom: 11, right: 24, left: 24 }) - } - } - .width('100%') - .height(56) - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - - List({ initialIndex: 0 }) { - ListItem() { - Row() { - Row() { - Text($r('app.string.emitter_subscribe_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - - } - .onClick(() => { - // 定义一个eventId为1的事件 - let event: emitter.InnerEvent = { - eventId: 1 - }; - - // 收到eventId为1的事件后执行该回调 - let callback = (eventData: emitter.EventData): void => { - promptAction.showToast({ - message: JSON.stringify(eventData) - }); - hilog.info(DOMAIN_NUMBER, TAG, 'event callback:' + JSON.stringify(eventData)); - }; - - // 订阅eventId为1的事件 - emitter.on(event, callback); - promptAction.showToast({ - message: $r('app.string.emitter_subscribe_success_toast') - }); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 8, right: 12, left: 12 }) - - - ListItem() { - Row() { - Row() { - Text($r('app.string.emitter_sending_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - // 定义一个eventId为1的事件,事件优先级为Low - let event: emitter.InnerEvent = { - eventId: 1, - priority: emitter.EventPriority.LOW - }; - - let eventData: emitter.EventData = { - data: { - content: 'c', - id: 1, - isEmpty: false - } - }; - - // 发送eventId为1的事件,事件内容为eventData - emitter.emit(event, eventData); - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Row() { - Row() { - Text($r('app.string.worker_button')) - .textAlign(TextAlign.Start) - .fontWeight(FontWeight.Medium) - .margin({ top: 13, bottom: 13, left: 0, right: 8 }) - .fontSize(16) - .height(22) - .fontColor($r('app.color.text_color')) - } - .height(48) - .width('100%') - .borderRadius(24) - .margin({ top: 4, bottom: 4, left: 12, right: 84 }) - } - .onClick(() => { - let wk = new worker.ThreadWorker('entry/ets/workers/Worker.ts'); - // 发送消息到worker线程 - wk.postMessage('message from main thread.'); - - // 处理来自worker线程的消息 - wk.onmessage = (message): void => { - promptAction.showToast({ - message: JSON.stringify(message) - }); - hilog.info(DOMAIN_NUMBER, TAG, 'message from worker: ' + JSON.stringify(message)); - - // 根据业务按需停止worker线程 - wk.terminate(); - } - }) - } - .height(56) - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .margin({ top: 8 }) - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2023 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 emitter from '@ohos.events.emitter'; +import promptAction from '@ohos.promptAction'; +import worker from '@ohos.worker'; +import hilog from '@ohos.hilog'; + +const DOMAIN_NUMBER: number = 0xFF00; +const TAG: string = 'ThreadModel'; + +@Entry +@Component +struct PageThreadModel { + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.thread_button')) + .fontSize(24) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ top: 12, bottom: 11, right: 24, left: 24 }) + } + } + .width('100%') + .height(56) + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + + List({ initialIndex: 0 }) { + ListItem() { + Row() { + Row() { + Text($r('app.string.emitter_subscribe_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + + } + .onClick(() => { + // 定义一个eventId为1的事件 + let event: emitter.InnerEvent = { + eventId: 1 + }; + + // 收到eventId为1的事件后执行该回调 + let callback = (eventData: emitter.EventData): void => { + promptAction.showToast({ + message: JSON.stringify(eventData) + }); + hilog.info(DOMAIN_NUMBER, TAG, 'event callback:' + JSON.stringify(eventData)); + }; + + // 订阅eventId为1的事件 + emitter.on(event, callback); + promptAction.showToast({ + message: $r('app.string.emitter_subscribe_success_toast') + }); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 8, right: 12, left: 12 }) + + + ListItem() { + Row() { + Row() { + Text($r('app.string.emitter_sending_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + // 定义一个eventId为1的事件,事件优先级为Low + let event: emitter.InnerEvent = { + eventId: 1, + priority: emitter.EventPriority.LOW + }; + + let eventData: emitter.EventData = { + data: { + content: 'c', + id: 1, + isEmpty: false + } + }; + + // 发送eventId为1的事件,事件内容为eventData + emitter.emit(event, eventData); + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Row() { + Row() { + Text($r('app.string.worker_button')) + .textAlign(TextAlign.Start) + .fontWeight(FontWeight.Medium) + .margin({ top: 13, bottom: 13, left: 0, right: 8 }) + .fontSize(16) + .height(22) + .fontColor($r('app.color.text_color')) + } + .height(48) + .width('100%') + .borderRadius(24) + .margin({ top: 4, bottom: 4, left: 12, right: 84 }) + } + .onClick(() => { + let wk = new worker.ThreadWorker('entry/ets/workers/Worker.ts'); + // 发送消息到worker线程 + wk.postMessage('message from main thread.'); + + // 处理来自worker线程的消息 + wk.onmessage = (message): void => { + promptAction.showToast({ + message: JSON.stringify(message) + }); + hilog.info(DOMAIN_NUMBER, TAG, 'message from worker: ' + JSON.stringify(message)); + + // 根据业务按需停止worker线程 + wk.terminate(); + } + }) + } + .height(56) + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .margin({ top: 8 }) + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/workers/Worker.ts b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/workers/Worker.ts index 9506a11e7117f6c22e3f12873cd467ca680d1d5c..b3132c3eb617a9b6b0b27f8dbb899c0299581bab 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/workers/Worker.ts +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/ets/workers/Worker.ts @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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 worker from '@ohos.worker'; -import hilog from '@ohos.hilog'; - -let parent = worker.workerPort; -const DOMAIN_NUMBER: number = 0xFF00; - -// 处理来自主线程的消息 -parent.onmessage = (message): void => { - hilog.info(DOMAIN_NUMBER, 'Worker', 'onmessage: ' + JSON.stringify(message)); - // 发送消息到主线程 - parent.postMessage('message from worker thread.'); +/* + * Copyright (c) 2023 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 worker from '@ohos.worker'; +import hilog from '@ohos.hilog'; + +let parent = worker.workerPort; +const DOMAIN_NUMBER: number = 0xFF00; + +// 处理来自主线程的消息 +parent.onmessage = (message): void => { + hilog.info(DOMAIN_NUMBER, 'Worker', 'onmessage: ' + JSON.stringify(message)); + // 发送消息到主线程 + parent.postMessage('message from worker thread.'); }; \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/module.json5 index ea18183df804eb5ccab53cbb8d02cb7ce32b24ac..e4c60260259743c216f5b8ccda4889963a95b74e 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/module.json5 @@ -1,78 +1,78 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "StaticSubscriber", - "srcEntry": "./ets/staticsubscriber/StaticSubscriber.ts", - "description": "$string:StaticSubscriber_desc", - "icon": "$media:icon", - "label": "$string:StaticSubscriber_label", - "type": "staticSubscriber", - "metadata": [ - { - "name": "ohos.extension.staticSubscriber", - "resource": "$profile:staticsubscriber" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.COMMONEVENT_STICKY" - }, - { - "name": "ohos.permission.MANAGE_MISSIONS" - }, - { - "name": "ohos.permission.NOTIFICATION_CONTROLLER" - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "StaticSubscriber", + "srcEntry": "./ets/staticsubscriber/StaticSubscriber.ts", + "description": "$string:StaticSubscriber_desc", + "icon": "$media:icon", + "label": "$string:StaticSubscriber_label", + "type": "staticSubscriber", + "metadata": [ + { + "name": "ohos.extension.staticSubscriber", + "resource": "$profile:staticsubscriber" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.COMMONEVENT_STICKY" + }, + { + "name": "ohos.permission.MANAGE_MISSIONS" + }, + { + "name": "ohos.permission.NOTIFICATION_CONTROLLER" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/element/color.json index e1691a2f316e327d18f698691d314d79bf98cc9b..59da6fd48a8fb1776cf4a71be42a94aaa6129e4c 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/element/color.json @@ -1,20 +1,20 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#f1f3f5" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#f1f3f5" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/profile/staticsubscriber.json b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/profile/staticsubscriber.json index 56d7385453135ecb013d4b1ec867042f17eb5158..ed7f55886563c1259321b9b602d8fb9afa7e7994 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/profile/staticsubscriber.json +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/main/resources/base/profile/staticsubscriber.json @@ -1,11 +1,11 @@ -{ - "commonEvents": [ - { - "name": "StaticSubscriber", - "permission": "", - "events": [ - "usual.event.AIRPLANE_MODE" - ] - } - ] +{ + "commonEvents": [ + { + "name": "StaticSubscriber", + "permission": "", + "events": [ + "usual.event.AIRPLANE_MODE" + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/ohosTest/module.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/ohosTest/module.json5 index 931a761b1ee1895d7f20d004bbab636788422af1..520003bf20644b84e2971107d8f4ab991b739d6e 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/hvigor/hvigor-config.json5 index 7fcecec159df6759049a45fd7a400d1fbaffeab4..dba571014f1a9610f06d593adbcdf6c0097948e6 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageProcessThread/oh-package.json5 b/code/DocsSample/ApplicationModels/StageProcessThread/oh-package.json5 index afa4c1e4198fe2a34ed3763460ad30c445640b06..85da1030653aeaa9046428eb644b4610514e512e 100644 --- a/code/DocsSample/ApplicationModels/StageProcessThread/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/StageProcessThread/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "stageprocessthread", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "stageprocessthread", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/app.json5 b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/app.json5 index d5fac8aeb4943c32c130425f527425aabe391720..5fd2b0548729d939dce2d760bacc360df21ee982 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.stageservicewidgetcards", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.stageservicewidgetcards", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/resources/base/element/string.json index e2c37fdcf291dc681029c4c8f61508cd8241cdeb..db52f2f875890e5ded32109e09e1c539aa59e35d 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "StageServiceWidgetCards" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "StageServiceWidgetCards" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/README_zh.md b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/README_zh.md index 1a7a0475b3b5089a120c8f8dc6dc10eb664ffb4e..e100791e37a35cee7c350ee2b61bb2ef07a729a4 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/README_zh.md +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/README_zh.md @@ -1,248 +1,248 @@ -# 服务卡片开发指导(Stage模型) - -### 介绍 - -本示例展示了在一个Stage模型中,开发基于ArkTS UI及JS UI的卡片指导。 - -本示例参考[应用模型](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/application-models)。 - -### 效果预览 - -| 开发卡片事件 | 卡片数据交互 | -| ------------------------------------------ | ---------------------------------------------- | -| | | - -#### 使用说明 - -**开发基于ArkTS UI的卡片** - -1.开发卡片页面 - -1)长按应用图标并点击<服务卡片>; - -2)选择卡片属性动画示例并点击添加到桌面; - -3)点击“改变旋转角度”按钮,按钮产生旋转动画效果; - -4)回到主页,长按应用图标并点击<服务卡片>,选择卡片使用自定义绘制能力示例并点击添加到桌面; - -5)示例代码实现了通过CanvasRenderingContext2D对象在画布的中心绘制一个笑脸。 - -2.开发卡片事件 - -1)回到主页,长按应用图标并点击<服务卡片>,选择卡片使用router事件跳转到指定UIAbility示例并点击添加到桌面; - -2)点击“功能A”按钮,在UIAbility中接收router事件并获取参数,根据传递的params不同,选择拉起功能A页面; - -3)点击“功能B”按钮,在UIAbility中接收router事件并获取参数,根据传递的params不同,选择拉起功能B页面; - -4)回到主页,长按应用图标并点击<服务卡片>,选择通过message事件刷新卡片示例并点击添加到桌面; - -5)在卡片页面点击“Update”按钮,观察卡片页面,其中title信息更新为'Title Update.'文字信息更新为'Description update success.'; - -6)回到主页,长按应用图标并点击<服务卡片>,选择通过router事件刷新卡片内容示例并点击添加到桌面; - -7)点击“router事件跳转”按钮;点击Home键返回桌面,查看卡片内容从“init”更新为“RouterFromCard”:UIAbility;当按home键的方式回到卡片界面点击按钮时,内容则更新为“RouterFromCard”:onNewWant UIAbility.; - -8)回到主页,长按应用图标并点击<服务卡片>,选择通过call事件刷新卡片内容示例并点击添加到桌面; - -9)点击“callee拉至后台”按钮,查看卡片文字,内容从“init”更新为“CallFrom”; - -10)回到主页,长按应用图标并点击<服务卡片>,选择使用call事件拉起指定UIAbility到后台卡片示例并点击添加到桌面; - -11)先后点击“功能A”,“功能B”按钮,先后分别后台打印FunACall param及FunBCall param信息; - -3.卡片数据交互 - -1)回到主页,长按应用图标并点击<服务卡片>,选择卡片定时刷新示例并点击添加到桌面; - -2)等待1小时后观察卡片显示,标题从‘Title default’更新为'Title Update.'文字从‘定时刷新’更新为'Description update success.'; - -3)回到主页,长按应用图标并点击<服务卡片>,选择卡片定点刷新示例并点击添加到桌面; - -4)等待到指定时间10:30后观察卡片显示,标题从‘Title default’更新为'Title Update.'文字从‘定点刷新’更新为'Description update success.' - -5)回到主页,长按应用图标并点击<服务卡片>,选择固定时间后刷新示例并点击添加到桌面; - -6)点击“Update”按钮,等待5min后观察卡片显示; - -7)标题从‘Title default’更新为'Title Update.'文字从‘Description default’更新为'Description update success.'; - -8)回到主页,长按应用图标并点击<服务卡片>,选择刷新本地图片和网络图片示例并点击添加到桌面; - -9)此时卡片上图片显示默认图片,点击添加到桌面。此时显示为本地图片; - -10)点击“刷新”按钮 图片更新为网络下载图片; - -11)回到主页,长按应用图标并点击<服务卡片>,选择根据卡片状态刷新不同内容示例并点击添加到桌面; - -12)勾选“状态A”,等待30min后观察卡片显示,卡片中只更新状态A文字“待刷新”为“AAA”; - -13)勾选“状态B”,等待30min后观察卡片显示,卡片中只更新状态B文字“待刷新”为“BBB”; - -14)回到主页,安装<共享数据>应用并点击打开,页面显示有“更新过程数据”,“更新持久化数据”按钮; - -15)长按应用图标并点击<服务卡片>,选择<卡片代理刷新(过程数据)>示例;添加后观察卡片显示,卡片中央内容显示“加载中”; - -16)返回“代理刷新卡片”应用主页面,点击<更新过程数据>,弹出“更新过程数据成功”提示。点击Home键返回桌面,观察卡片显示。卡片中央内容刷新,从“加载中”更新为”Qing“,且卡片提供方应用没有被拉起; - -17)长按应用图标并点击<服务卡片>,选择<卡片代理刷新(持久化数据)>示例;添加后观察卡片显示,卡片中央内容显示“a”; - -18)返回“共享数据”应用主页面,点击<更新持久化数据>,弹出“更新持久化数据成功”提示。点击Home键返回桌面,观察卡片显示。卡片中央内容刷新,从“a”更新为”snow“,该过程卡片提供方应用没有被拉起; - -19)使用方刷新卡片内容:已确认无法在卡片内主动更新卡片,故该功能无法实现。 - -**开发基于JS UI的卡片** - -1)回到主页,长按应用图标并点击<服务卡片>,选择开发基于JS UI的卡片示例并点击添加到桌面; - -2)等待30min后观察卡片显示,title从“titleOnCreate”刷新为“titleOnUpdate”,文字内容从“detailOnCreat”刷新为“detailOnUpdate”; - -### 工程目录 -``` -entry/src/main/ets/ -├── attranimation -│   └── pages -│   └── AttrAnimationCard.ets //属性动画示例 -├── customcanvasdrawing -│   └── pages -│   └── CustomCanvasDrawingCard.ets //卡片使用自定义绘制能力示例 -├── entryability -│   └── EntryAbility.ts //router事件跳转到指定UIAbility逻辑 -├── entryformability -│   └── EntryFormAbility.ts //卡片业务逻辑模块,提供卡片创建、销毁、刷新等生命周期回调。 -├── funpages -│   ├── FunA.ets //router调起ability页面A -│   └── FunB.ets //router调起ability页面B -├── jscardentryability -│   └── JsCardEntryAbility.ts //JS卡片UIAbility实例 -├── jscardformability -│   └── JsCardFormAbility.ts //JS卡片业务逻辑模块 -├── nextrefreshtime -│   └── pages -│   └── NextRefreshTimeCard.ets //固定时间后刷新卡片页面 -├── pages -│   └── Index.ets //应用的默认页面 -├── persistentdataformability -│   └── PersistentDataFormAbility.ts //持久化数据下代理刷新卡片业务逻辑模块 -├── processdataentryability -│   └── ProcessDataFormAbility.ts //基于过程数据的卡片代理刷新订阅逻辑 -├── scheduledupdatetime -│   └── pages -│   └── ScheduledUpdateTimeCard.ets //定点刷新卡片页面 -├── updatebymessage -│   └── pages -│   └── UpdateByMessageCard.ets //message事件刷新卡片内容页面 -├── updatebystatusformability -│   └── UpdateByStatusFormAbility.ts //根据卡片状态刷新不同内容业务逻辑模块 -├── updatebytimeformability -│   └── UpdateByTimeFormAbility.ts //定时刷新卡片业务逻辑模块 -├── updateduration -│   └── pages -│   └── UpdateDurationCard.ets //定时刷新卡片页面 -├── wgtimgupdateentryformability -│   └── WgtImgUpdateEntryFormAbility.ts //本地图片和网络图片更新逻辑模块 -├── widgetcalleeentryability -│   └── WidgetCalleeEntryAbility.ts //通过call事件刷新卡片内容订阅逻辑 -├── widgetcalleeformability -│   └── WidgetCalleeFormAbility.ts //通过router或call事件刷新卡片内容页面更新逻辑 -├── widgeteventcall -│   └── pages -│   └── WidgetEventCallCard.ets //使用call事件拉起指定UIAbility到后台卡片页面 -├── widgeteventcallentryability -│   └── WidgetEventCallEntryAbility.ts //使用call事件拉起指定UIAbility到后台订阅逻辑 -├── widgetevententryability -│   └── WidgetEventRouterEntryAbility.ts //通过router事件刷新卡片内容逻辑入口 -├── widgeteventrouter -│   └── pages -│   └── WidgetEventRouterCard.ets //使用router事件跳转到指定UIAbility示例页面 -├── widgetimageupdate -│   └── pages -│   └── WidgetImageUpdateCard.ets //本地图片和网络图片更新示例页面 -├── widgetpersistentdata -│   └── pages -│   └── WidgetPersistentDataCard.ets //持久化数据下卡片代理刷新示例页面 -├── widgetprocessdata -│   └── pages -│   └── WidgetProcessDataCard.ets //基于过程数据的卡片代理刷新示例页面 -├── widgetupdatebystatus -│   └── pages -│   └── WidgetUpdateByStatusCard.ets //根据卡片状态刷新不同内容示例页面 -├── widgetupdatecall -│   └── pages -│   └── WidgetUpdateCallCard.ets //通过call事件刷新卡片内容示例页面 -└── widgetupdaterouter - └── pages - └── WidgetUpdateRouterCard.ets //通过router事件刷新卡片内容示例页面 -``` -### 具体实现 - -* 本示例分为基于ArkTS UI的卡片,基于JS UI的卡片两部分。其中ArkTS UI卡片下分为卡片页面,卡片事件,卡片数据交互三部分。 - * 开发卡片页面: - - * ArkTS卡片具备JS卡片的全量能力,并且新增了动效能力和自定义绘制的能力,支持声明式范式的部分组件、事件、动效、数据管理、状态管理能力。 - - * 示例分别展示了animation动效及自定义绘制的能力。 - - * 开发卡片事件: - - * 针对动态卡片,ArkTS卡片中提供了postCardAction()接口用于卡片内部和提供方应用间的交互,当前支持router、message和call三种类型的事件,仅在卡片中可以调用。 - * 接口定义:postCardAction(component: Object, action: Object): void - - * 卡片数据交互: - - * ArkTS卡片框架提供了updateForm()接口和requestForm()接口主动触发卡片的页面刷新,通过[LocalStorageProp](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/state-management/arkts-localstorage.md#localstorageprop)确认需要刷新的卡片数据。 - * 介绍了按时间刷新方式(通过form_config.json配置文件的updateDuration字段中进行设置),代理刷新,刷新网络数据等能力。 - - -### 相关权限 - -[ohos.permission.KEEP_BACKGROUND_RUNNING](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionkeep_background_running) - -[ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) - -[ohos.permission.GET_BUNDLE_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionget_bundle_info) - -[ohos.permission.START_ABILITIES_FROM_BACKGROUND](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionstart_abilities_from_background) - -### 依赖 - -1.本示例依赖共享数据的更新,由另一应用<共享数据>完成。测试代理刷新卡片功能时需要优先安装该应用。 - -- `app_signature`字段配置为应用的指纹信息,指纹信息的配置请参见[应用特权配置指南](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/device-dev/subsystems/subsys-app-privilege-config-guide.md#install_list_capabilityjson中配置)。 - - ``` - [ - ... - { - "signingConfigs": ["****"], // 指纹信息 - } - ] - ``` - - -### 约束与限制 - -1. 本示例支持标准系统上运行,支持设备:RK3568; - -2. 本示例支持API14版本SDK,版本号:5.0.2.57; - -3. 本示例已支持使DevEco Studio 5.0.1 Release (构建版本:5.0.5.306,构建 2024年12月12日)编译运行; - -4. 高等级APL特殊签名说明:无; - - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/DocsSample/ApplicationModels/StageServiceWidgetCards/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - - - +# 服务卡片开发指导(Stage模型) + +### 介绍 + +本示例展示了在一个Stage模型中,开发基于ArkTS UI及JS UI的卡片指导。 + +本示例参考[应用模型](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/application-models)。 + +### 效果预览 + +| 开发卡片事件 | 卡片数据交互 | +| ------------------------------------------ | ---------------------------------------------- | +| | | + +#### 使用说明 + +**开发基于ArkTS UI的卡片** + +1.开发卡片页面 + +1)长按应用图标并点击<服务卡片>; + +2)选择卡片属性动画示例并点击添加到桌面; + +3)点击“改变旋转角度”按钮,按钮产生旋转动画效果; + +4)回到主页,长按应用图标并点击<服务卡片>,选择卡片使用自定义绘制能力示例并点击添加到桌面; + +5)示例代码实现了通过CanvasRenderingContext2D对象在画布的中心绘制一个笑脸。 + +2.开发卡片事件 + +1)回到主页,长按应用图标并点击<服务卡片>,选择卡片使用router事件跳转到指定UIAbility示例并点击添加到桌面; + +2)点击“功能A”按钮,在UIAbility中接收router事件并获取参数,根据传递的params不同,选择拉起功能A页面; + +3)点击“功能B”按钮,在UIAbility中接收router事件并获取参数,根据传递的params不同,选择拉起功能B页面; + +4)回到主页,长按应用图标并点击<服务卡片>,选择通过message事件刷新卡片示例并点击添加到桌面; + +5)在卡片页面点击“Update”按钮,观察卡片页面,其中title信息更新为'Title Update.'文字信息更新为'Description update success.'; + +6)回到主页,长按应用图标并点击<服务卡片>,选择通过router事件刷新卡片内容示例并点击添加到桌面; + +7)点击“router事件跳转”按钮;点击Home键返回桌面,查看卡片内容从“init”更新为“RouterFromCard”:UIAbility;当按home键的方式回到卡片界面点击按钮时,内容则更新为“RouterFromCard”:onNewWant UIAbility.; + +8)回到主页,长按应用图标并点击<服务卡片>,选择通过call事件刷新卡片内容示例并点击添加到桌面; + +9)点击“callee拉至后台”按钮,查看卡片文字,内容从“init”更新为“CallFrom”; + +10)回到主页,长按应用图标并点击<服务卡片>,选择使用call事件拉起指定UIAbility到后台卡片示例并点击添加到桌面; + +11)先后点击“功能A”,“功能B”按钮,先后分别后台打印FunACall param及FunBCall param信息; + +3.卡片数据交互 + +1)回到主页,长按应用图标并点击<服务卡片>,选择卡片定时刷新示例并点击添加到桌面; + +2)等待1小时后观察卡片显示,标题从‘Title default’更新为'Title Update.'文字从‘定时刷新’更新为'Description update success.'; + +3)回到主页,长按应用图标并点击<服务卡片>,选择卡片定点刷新示例并点击添加到桌面; + +4)等待到指定时间10:30后观察卡片显示,标题从‘Title default’更新为'Title Update.'文字从‘定点刷新’更新为'Description update success.' + +5)回到主页,长按应用图标并点击<服务卡片>,选择固定时间后刷新示例并点击添加到桌面; + +6)点击“Update”按钮,等待5min后观察卡片显示; + +7)标题从‘Title default’更新为'Title Update.'文字从‘Description default’更新为'Description update success.'; + +8)回到主页,长按应用图标并点击<服务卡片>,选择刷新本地图片和网络图片示例并点击添加到桌面; + +9)此时卡片上图片显示默认图片,点击添加到桌面。此时显示为本地图片; + +10)点击“刷新”按钮 图片更新为网络下载图片; + +11)回到主页,长按应用图标并点击<服务卡片>,选择根据卡片状态刷新不同内容示例并点击添加到桌面; + +12)勾选“状态A”,等待30min后观察卡片显示,卡片中只更新状态A文字“待刷新”为“AAA”; + +13)勾选“状态B”,等待30min后观察卡片显示,卡片中只更新状态B文字“待刷新”为“BBB”; + +14)回到主页,安装<共享数据>应用并点击打开,页面显示有“更新过程数据”,“更新持久化数据”按钮; + +15)长按应用图标并点击<服务卡片>,选择<卡片代理刷新(过程数据)>示例;添加后观察卡片显示,卡片中央内容显示“加载中”; + +16)返回“代理刷新卡片”应用主页面,点击<更新过程数据>,弹出“更新过程数据成功”提示。点击Home键返回桌面,观察卡片显示。卡片中央内容刷新,从“加载中”更新为”Qing“,且卡片提供方应用没有被拉起; + +17)长按应用图标并点击<服务卡片>,选择<卡片代理刷新(持久化数据)>示例;添加后观察卡片显示,卡片中央内容显示“a”; + +18)返回“共享数据”应用主页面,点击<更新持久化数据>,弹出“更新持久化数据成功”提示。点击Home键返回桌面,观察卡片显示。卡片中央内容刷新,从“a”更新为”snow“,该过程卡片提供方应用没有被拉起; + +19)使用方刷新卡片内容:已确认无法在卡片内主动更新卡片,故该功能无法实现。 + +**开发基于JS UI的卡片** + +1)回到主页,长按应用图标并点击<服务卡片>,选择开发基于JS UI的卡片示例并点击添加到桌面; + +2)等待30min后观察卡片显示,title从“titleOnCreate”刷新为“titleOnUpdate”,文字内容从“detailOnCreat”刷新为“detailOnUpdate”; + +### 工程目录 +``` +entry/src/main/ets/ +├── attranimation +│   └── pages +│   └── AttrAnimationCard.ets //属性动画示例 +├── customcanvasdrawing +│   └── pages +│   └── CustomCanvasDrawingCard.ets //卡片使用自定义绘制能力示例 +├── entryability +│   └── EntryAbility.ts //router事件跳转到指定UIAbility逻辑 +├── entryformability +│   └── EntryFormAbility.ts //卡片业务逻辑模块,提供卡片创建、销毁、刷新等生命周期回调。 +├── funpages +│   ├── FunA.ets //router调起ability页面A +│   └── FunB.ets //router调起ability页面B +├── jscardentryability +│   └── JsCardEntryAbility.ts //JS卡片UIAbility实例 +├── jscardformability +│   └── JsCardFormAbility.ts //JS卡片业务逻辑模块 +├── nextrefreshtime +│   └── pages +│   └── NextRefreshTimeCard.ets //固定时间后刷新卡片页面 +├── pages +│   └── Index.ets //应用的默认页面 +├── persistentdataformability +│   └── PersistentDataFormAbility.ts //持久化数据下代理刷新卡片业务逻辑模块 +├── processdataentryability +│   └── ProcessDataFormAbility.ts //基于过程数据的卡片代理刷新订阅逻辑 +├── scheduledupdatetime +│   └── pages +│   └── ScheduledUpdateTimeCard.ets //定点刷新卡片页面 +├── updatebymessage +│   └── pages +│   └── UpdateByMessageCard.ets //message事件刷新卡片内容页面 +├── updatebystatusformability +│   └── UpdateByStatusFormAbility.ts //根据卡片状态刷新不同内容业务逻辑模块 +├── updatebytimeformability +│   └── UpdateByTimeFormAbility.ts //定时刷新卡片业务逻辑模块 +├── updateduration +│   └── pages +│   └── UpdateDurationCard.ets //定时刷新卡片页面 +├── wgtimgupdateentryformability +│   └── WgtImgUpdateEntryFormAbility.ts //本地图片和网络图片更新逻辑模块 +├── widgetcalleeentryability +│   └── WidgetCalleeEntryAbility.ts //通过call事件刷新卡片内容订阅逻辑 +├── widgetcalleeformability +│   └── WidgetCalleeFormAbility.ts //通过router或call事件刷新卡片内容页面更新逻辑 +├── widgeteventcall +│   └── pages +│   └── WidgetEventCallCard.ets //使用call事件拉起指定UIAbility到后台卡片页面 +├── widgeteventcallentryability +│   └── WidgetEventCallEntryAbility.ts //使用call事件拉起指定UIAbility到后台订阅逻辑 +├── widgetevententryability +│   └── WidgetEventRouterEntryAbility.ts //通过router事件刷新卡片内容逻辑入口 +├── widgeteventrouter +│   └── pages +│   └── WidgetEventRouterCard.ets //使用router事件跳转到指定UIAbility示例页面 +├── widgetimageupdate +│   └── pages +│   └── WidgetImageUpdateCard.ets //本地图片和网络图片更新示例页面 +├── widgetpersistentdata +│   └── pages +│   └── WidgetPersistentDataCard.ets //持久化数据下卡片代理刷新示例页面 +├── widgetprocessdata +│   └── pages +│   └── WidgetProcessDataCard.ets //基于过程数据的卡片代理刷新示例页面 +├── widgetupdatebystatus +│   └── pages +│   └── WidgetUpdateByStatusCard.ets //根据卡片状态刷新不同内容示例页面 +├── widgetupdatecall +│   └── pages +│   └── WidgetUpdateCallCard.ets //通过call事件刷新卡片内容示例页面 +└── widgetupdaterouter + └── pages + └── WidgetUpdateRouterCard.ets //通过router事件刷新卡片内容示例页面 +``` +### 具体实现 + +* 本示例分为基于ArkTS UI的卡片,基于JS UI的卡片两部分。其中ArkTS UI卡片下分为卡片页面,卡片事件,卡片数据交互三部分。 + * 开发卡片页面: + + * ArkTS卡片具备JS卡片的全量能力,并且新增了动效能力和自定义绘制的能力,支持声明式范式的部分组件、事件、动效、数据管理、状态管理能力。 + + * 示例分别展示了animation动效及自定义绘制的能力。 + + * 开发卡片事件: + + * 针对动态卡片,ArkTS卡片中提供了postCardAction()接口用于卡片内部和提供方应用间的交互,当前支持router、message和call三种类型的事件,仅在卡片中可以调用。 + * 接口定义:postCardAction(component: Object, action: Object): void + + * 卡片数据交互: + + * ArkTS卡片框架提供了updateForm()接口和requestForm()接口主动触发卡片的页面刷新,通过[LocalStorageProp](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/state-management/arkts-localstorage.md#localstorageprop)确认需要刷新的卡片数据。 + * 介绍了按时间刷新方式(通过form_config.json配置文件的updateDuration字段中进行设置),代理刷新,刷新网络数据等能力。 + + +### 相关权限 + +[ohos.permission.KEEP_BACKGROUND_RUNNING](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionkeep_background_running) + +[ohos.permission.INTERNET](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +[ohos.permission.GET_BUNDLE_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionget_bundle_info) + +[ohos.permission.START_ABILITIES_FROM_BACKGROUND](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionstart_abilities_from_background) + +### 依赖 + +1.本示例依赖共享数据的更新,由另一应用<共享数据>完成。测试代理刷新卡片功能时需要优先安装该应用。 + +- `app_signature`字段配置为应用的指纹信息,指纹信息的配置请参见[应用特权配置指南](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/device-dev/subsystems/subsys-app-privilege-config-guide.md#install_list_capabilityjson中配置)。 + + ``` + [ + ... + { + "signingConfigs": ["****"], // 指纹信息 + } + ] + ``` + + +### 约束与限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API14版本SDK,版本号:5.0.2.57; + +3. 本示例已支持使DevEco Studio 5.0.1 Release (构建版本:5.0.5.306,构建 2024年12月12日)编译运行; + +4. 高等级APL特殊签名说明:无; + + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ApplicationModels/StageServiceWidgetCards/ > .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/ApplicationModels/StageServiceWidgetCards/build-profile.json5 b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/build-profile.json5 index 4617f664e55e4b2b1a269cca64602f5370ff1134..346cfe6d818410579f21b2c92c8bc24cc0b4233c 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/build-profile.json5 @@ -1,46 +1,46 @@ -/* - * Copyright (c) 2022-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": 14, - "targetSdkVersion": 14, - "compatibleSdkVersion": 14, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [ - - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2022-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": 14, + "targetSdkVersion": 14, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/build-profile.json5 index 86224cda6f74439561b4e5f3b822bc27c7c69579..fde30086fc0aa158bf024fdc94b29be6a50442c6 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/build-profile.json5 @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2022-2023 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', - "showInServiceCenter": true, - "buildOption": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2022-2023 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', + "showInServiceCenter": true, + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/attranimation/pages/AttrAnimationCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/attranimation/pages/AttrAnimationCard.ets index 5f4f532e30146f4484b88798cc78515246b66c9d..f1c99554a3fa4b7298185c0dcaf5675ff3cc3d64 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/attranimation/pages/AttrAnimationCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/attranimation/pages/AttrAnimationCard.ets @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct AttrAnimationCard { - @State rotateAngle: number = 0; - - build() { - Column() { - Button() { - Text($r('app.string.change_rotate_angle')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - this.rotateAngle = (this.rotateAngle === 0 ? 90 : 0); - }) - .rotate({ angle: this.rotateAngle }) - .animation({ - curve: Curve.EaseOut, - playMode: PlayMode.Normal, - }) - }.height('100%').width('100%') - .justifyContent(FlexAlign.Center) - .backgroundImage($r('app.media.CardExampleBkg')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct AttrAnimationCard { + @State rotateAngle: number = 0; + + build() { + Column() { + Button() { + Text($r('app.string.change_rotate_angle')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + this.rotateAngle = (this.rotateAngle === 0 ? 90 : 0); + }) + .rotate({ angle: this.rotateAngle }) + .animation({ + curve: Curve.EaseOut, + playMode: PlayMode.Normal, + }) + }.height('100%').width('100%') + .justifyContent(FlexAlign.Center) + .backgroundImage($r('app.media.CardExampleBkg')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/customcanvasdrawing/pages/CustomCanvasDrawingCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/customcanvasdrawing/pages/CustomCanvasDrawingCard.ets index f14e23596ddc0585232ed4a2f1642bfa65919a32..9f75a48b6389fec4005192eb45883d3edc1e309b 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/customcanvasdrawing/pages/CustomCanvasDrawingCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/customcanvasdrawing/pages/CustomCanvasDrawingCard.ets @@ -1,92 +1,92 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct CustomCanvasDrawingCard { - private canvasWidth: number = 0; - private canvasHeight: number = 0; - // 初始化CanvasRenderingContext2D和RenderingContextSettings - private settings: RenderingContextSettings = new RenderingContextSettings(true); - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - - build() { - Column() { - Row() { - Canvas(this.context) - .width('100%') - .height('100%') - .onReady(() => { - // 在onReady回调中获取画布的实际宽和高 - this.canvasWidth = this.context.width; - this.canvasHeight = this.context.height; - // 绘制画布的背景 - this.context.fillStyle = '#EEF0FF'; - this.context.fillRect(0, 0, this.canvasWidth, this.canvasHeight); - // 在画布的中心绘制一个圆 - this.context.beginPath(); - let radius = this.context.width / 3; - let circleX = this.context.width / 2; - let circleY = this.context.height / 2; - this.context.moveTo(circleX - radius, circleY); - this.context.arc(circleX, circleY, radius, 2 * Math.PI, 0, true); - this.context.closePath(); - this.context.fillStyle = '#5A5FFF'; - this.context.fill(); - // 绘制笑脸的左眼 - let leftR = radius / 13; - let leftX = circleX - (radius / 2.3); - let leftY = circleY - (radius / 4.5); - this.context.beginPath(); - this.context.arc(leftX, leftY, leftR, 0, 2 * Math.PI, true); - this.context.strokeStyle = '#FFFFFF'; - this.context.lineWidth = 15; - this.context.stroke(); - // 绘制笑脸的右眼 - let rightR = radius / 13; - let rightX = circleX + (radius / 2.3); - let rightY = circleY - (radius / 4.5); - this.context.beginPath(); - this.context.arc(rightX, rightY, rightR, 0, 2 * Math.PI, true); - this.context.strokeStyle = '#FFFFFF'; - this.context.lineWidth = 15; - this.context.stroke(); - // 绘制笑脸的鼻子 - let startX = circleX; - let startY = circleY - 20; - this.context.beginPath(); - this.context.moveTo(startX, startY); - this.context.lineTo(startX - 8, startY + 40); - this.context.lineTo(startX + 8, startY + 40); - this.context.strokeStyle = '#FFFFFF'; - this.context.lineWidth = 15; - this.context.lineCap = 'round'; - this.context.lineJoin = 'round'; - this.context.stroke(); - // 绘制笑脸的嘴巴 - let mouthR = radius / 2; - let mouthX = circleX; - let mouthY = circleY + 10; - this.context.beginPath(); - this.context.arc(mouthX, mouthY, mouthR, Math.PI / 1.4, Math.PI / 3.4, true); - this.context.strokeStyle = '#FFFFFF'; - this.context.lineWidth = 15; - this.context.stroke(); - this.context.closePath(); - }) - } - }.height('100%').width('100%') - } +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct CustomCanvasDrawingCard { + private canvasWidth: number = 0; + private canvasHeight: number = 0; + // 初始化CanvasRenderingContext2D和RenderingContextSettings + private settings: RenderingContextSettings = new RenderingContextSettings(true); + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); + + build() { + Column() { + Row() { + Canvas(this.context) + .width('100%') + .height('100%') + .onReady(() => { + // 在onReady回调中获取画布的实际宽和高 + this.canvasWidth = this.context.width; + this.canvasHeight = this.context.height; + // 绘制画布的背景 + this.context.fillStyle = '#EEF0FF'; + this.context.fillRect(0, 0, this.canvasWidth, this.canvasHeight); + // 在画布的中心绘制一个圆 + this.context.beginPath(); + let radius = this.context.width / 3; + let circleX = this.context.width / 2; + let circleY = this.context.height / 2; + this.context.moveTo(circleX - radius, circleY); + this.context.arc(circleX, circleY, radius, 2 * Math.PI, 0, true); + this.context.closePath(); + this.context.fillStyle = '#5A5FFF'; + this.context.fill(); + // 绘制笑脸的左眼 + let leftR = radius / 13; + let leftX = circleX - (radius / 2.3); + let leftY = circleY - (radius / 4.5); + this.context.beginPath(); + this.context.arc(leftX, leftY, leftR, 0, 2 * Math.PI, true); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.stroke(); + // 绘制笑脸的右眼 + let rightR = radius / 13; + let rightX = circleX + (radius / 2.3); + let rightY = circleY - (radius / 4.5); + this.context.beginPath(); + this.context.arc(rightX, rightY, rightR, 0, 2 * Math.PI, true); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.stroke(); + // 绘制笑脸的鼻子 + let startX = circleX; + let startY = circleY - 20; + this.context.beginPath(); + this.context.moveTo(startX, startY); + this.context.lineTo(startX - 8, startY + 40); + this.context.lineTo(startX + 8, startY + 40); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.lineCap = 'round'; + this.context.lineJoin = 'round'; + this.context.stroke(); + // 绘制笑脸的嘴巴 + let mouthR = radius / 2; + let mouthX = circleX; + let mouthY = circleY + 10; + this.context.beginPath(); + this.context.arc(mouthX, mouthY, mouthR, Math.PI / 1.4, Math.PI / 3.4, true); + this.context.strokeStyle = '#FFFFFF'; + this.context.lineWidth = 15; + this.context.stroke(); + this.context.closePath(); + }) + } + }.height('100%').width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryability/EntryAbility.ts index ba5dcdafca81f67a20996b50c5c9382e7c40a040..8a99ccb46ffe9900b179d51f4a5b59c6c3616345 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,77 +1,77 @@ -/* - * Copyright (c) 2023-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 { window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'EntryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - private selectPage: string = 'funA'; - private currentWindowStage: window.WindowStage | null = null; - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - // 获取router事件中传递的targetPage参数 - hilog.info(DOMAIN_NUMBER, TAG, `Ability onCreate, ${JSON.stringify(want)}`); - if (want?.parameters?.params) { - // want.parameters.params 对应 postCardAction() 中 params 内容 - let params: Record = JSON.parse(want.parameters.params as string); - this.selectPage = params.targetPage as string; - hilog.info(DOMAIN_NUMBER, TAG, `onCreate selectPage: ${this.selectPage}`); - } - } - - // 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调 - onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, `onNewWant Want: ${JSON.stringify(want)}`); - if (want?.parameters?.params) { - // want.parameters.params 对应 postCardAction() 中 params 内容 - let params: Record = JSON.parse(want.parameters.params as string); - this.selectPage = params.targetPage as string; - hilog.info(DOMAIN_NUMBER, TAG, `onNewWant selectPage: ${this.selectPage}`); - } - if (this.currentWindowStage !== null) { - this.onWindowStageCreate(this.currentWindowStage); - } - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - let targetPage: string; - // 根据传递的targetPage不同,选择拉起不同的页面 - switch (this.selectPage) { - case 'funA': - targetPage = 'funpages/FunA'; - break; - case 'funB': - targetPage = 'funpages/FunB'; - break; - default: - targetPage = 'pages/Index'; - } - if (this.currentWindowStage === null) { - this.currentWindowStage = windowStage; - } - windowStage.loadContent(targetPage, (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } +/* + * Copyright (c) 2023-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 { window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'EntryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + private selectPage: string = 'funA'; + private currentWindowStage: window.WindowStage | null = null; + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 获取router事件中传递的targetPage参数 + hilog.info(DOMAIN_NUMBER, TAG, `Ability onCreate, ${JSON.stringify(want)}`); + if (want?.parameters?.params) { + // want.parameters.params 对应 postCardAction() 中 params 内容 + let params: Record = JSON.parse(want.parameters.params as string); + this.selectPage = params.targetPage as string; + hilog.info(DOMAIN_NUMBER, TAG, `onCreate selectPage: ${this.selectPage}`); + } + } + + // 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调 + onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, `onNewWant Want: ${JSON.stringify(want)}`); + if (want?.parameters?.params) { + // want.parameters.params 对应 postCardAction() 中 params 内容 + let params: Record = JSON.parse(want.parameters.params as string); + this.selectPage = params.targetPage as string; + hilog.info(DOMAIN_NUMBER, TAG, `onNewWant selectPage: ${this.selectPage}`); + } + if (this.currentWindowStage !== null) { + this.onWindowStageCreate(this.currentWindowStage); + } + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + let targetPage: string; + // 根据传递的targetPage不同,选择拉起不同的页面 + switch (this.selectPage) { + case 'funA': + targetPage = 'funpages/FunA'; + break; + case 'funB': + targetPage = 'funpages/FunB'; + break; + default: + targetPage = 'pages/Index'; + } + if (this.currentWindowStage === null) { + this.currentWindowStage = windowStage; + } + windowStage.loadContent(targetPage, (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryformability/EntryFormAbility.ts b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryformability/EntryFormAbility.ts index 3166a0106d4f95a87672520c750bc686dbe13e0d..78179e83dade7b7d5031a8c8089e0ce5770ed1ca 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryformability/EntryFormAbility.ts +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/entryformability/EntryFormAbility.ts @@ -1,91 +1,91 @@ -/* - * Copyright (c) 2023-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 { formBindingData, FormExtensionAbility, formInfo, formProvider } from '@kit.FormKit'; -import { Configuration, Want } from '@kit.AbilityKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'EntryFormAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryFormAbility extends FormExtensionAbility { - onAddForm(want: Want): formBindingData.FormBindingData { - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onAddForm'); - hilog.info(DOMAIN_NUMBER, TAG, want.parameters?.[formInfo.FormParam.NAME_KEY] as string); - // Called to return a FormBindingData object. - let formData = {}; - return formBindingData.createFormBindingData(formData); - } - - onCastToNormalForm(formId: string): void { - // 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理 - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onCastToNormalForm'); - } - - onUpdateForm(formId: string): void { - // 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新 - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onUpdateForm'); - let obj: Record = { - 'title': 'titleOnUpdateForm', - 'detail': 'detailOnUpdateForm' - }; - let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); - formProvider.updateForm(formId, formData).catch((error: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] updateForm, error:' + JSON.stringify(error)); - }); - } - - onChangeFormVisibility(newStatus: Record): void { - // 使用方发起可见或者不可见通知触发,提供方需要做相应的处理,仅系统应用生效 - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onChangeFormVisibility'); - } - - onFormEvent(formId: string, message: string): void { - // Called when a specified message event defined by the form provider is triggered. - hilog.info(DOMAIN_NUMBER, TAG, `FormAbility onFormEvent, formId = ${formId}, message: ${JSON.stringify(message)}`); - - class FormDataClass { - title: string = 'Title Update.'; // 和卡片布局中对应 - detail: string = 'Description update success.'; // 和卡片布局中对应 - } - - let formData = new FormDataClass(); - let formInfo: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData); - formProvider.updateForm(formId, formInfo).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'FormAbility updateForm success.'); - }).catch((error) => { - hilog.error(DOMAIN_NUMBER, TAG, `Operation updateForm failed. Cause: ${JSON.stringify(error)}`); - }); - } - - onRemoveForm(formId: string): void { - // 删除卡片实例数据 - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onRemoveForm'); - // 删除之前持久化的卡片实例数据 - // 此接口请根据实际情况实现,具体请参考:FormExtAbility Stage模型卡片实例 - } - - onConfigurationUpdate(config: Configuration) { - // 当前formExtensionAbility存活时更新系统配置信息时触发的回调。 - // 需注意:formExtensionAbility创建后10秒内无操作将会被清理。 - hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onConfigurationUpdate:' + JSON.stringify(config)); - } - - onAcquireFormState(want: Want): formInfo.FormState { - // Called to return a {@link FormState} object. - return formInfo.FormState.READY; - } +/* + * Copyright (c) 2023-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 { formBindingData, FormExtensionAbility, formInfo, formProvider } from '@kit.FormKit'; +import { Configuration, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'EntryFormAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryFormAbility extends FormExtensionAbility { + onAddForm(want: Want): formBindingData.FormBindingData { + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onAddForm'); + hilog.info(DOMAIN_NUMBER, TAG, want.parameters?.[formInfo.FormParam.NAME_KEY] as string); + // Called to return a FormBindingData object. + let formData = {}; + return formBindingData.createFormBindingData(formData); + } + + onCastToNormalForm(formId: string): void { + // 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理 + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onCastToNormalForm'); + } + + onUpdateForm(formId: string): void { + // 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新 + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onUpdateForm'); + let obj: Record = { + 'title': 'titleOnUpdateForm', + 'detail': 'detailOnUpdateForm' + }; + let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); + formProvider.updateForm(formId, formData).catch((error: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] updateForm, error:' + JSON.stringify(error)); + }); + } + + onChangeFormVisibility(newStatus: Record): void { + // 使用方发起可见或者不可见通知触发,提供方需要做相应的处理,仅系统应用生效 + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onChangeFormVisibility'); + } + + onFormEvent(formId: string, message: string): void { + // Called when a specified message event defined by the form provider is triggered. + hilog.info(DOMAIN_NUMBER, TAG, `FormAbility onFormEvent, formId = ${formId}, message: ${JSON.stringify(message)}`); + + class FormDataClass { + title: string = 'Title Update.'; // 和卡片布局中对应 + detail: string = 'Description update success.'; // 和卡片布局中对应 + } + + let formData = new FormDataClass(); + let formInfo: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData); + formProvider.updateForm(formId, formInfo).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'FormAbility updateForm success.'); + }).catch((error) => { + hilog.error(DOMAIN_NUMBER, TAG, `Operation updateForm failed. Cause: ${JSON.stringify(error)}`); + }); + } + + onRemoveForm(formId: string): void { + // 删除卡片实例数据 + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onRemoveForm'); + // 删除之前持久化的卡片实例数据 + // 此接口请根据实际情况实现,具体请参考:FormExtAbility Stage模型卡片实例 + } + + onConfigurationUpdate(config: Configuration) { + // 当前formExtensionAbility存活时更新系统配置信息时触发的回调。 + // 需注意:formExtensionAbility创建后10秒内无操作将会被清理。 + hilog.info(DOMAIN_NUMBER, TAG, '[EntryFormAbility] onConfigurationUpdate:' + JSON.stringify(config)); + } + + onAcquireFormState(want: Want): formInfo.FormState { + // Called to return a {@link FormState} object. + return formInfo.FormState.READY; + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/jscardentryability/JsCardEntryAbility.ts b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/jscardentryability/JsCardEntryAbility.ts index 2afbd3d94e27b198f8fdb2d3413901727b91a0dd..a0dc6d7c78282ac76c3d1b6789f1be5748576de0 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/jscardentryability/JsCardEntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/jscardentryability/JsCardEntryAbility.ts @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2022-2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type window from '@ohos.window'; - -const TAG: string = 'JsCardEntryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class JsCardEntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - if (want.parameters) { - let params: Record = JSON.parse(JSON.stringify(want.parameters.params)); - if (params.info === 'router info') { - hilog.info(DOMAIN_NUMBER, TAG, `router info: ${params.info}`); - } - if (params.message === 'router message') { - hilog.info(DOMAIN_NUMBER, TAG, `router message: ${params.message}`); - } - } - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } +/* + * Copyright (c) 2022-2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type window from '@ohos.window'; + +const TAG: string = 'JsCardEntryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class JsCardEntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + if (want.parameters) { + let params: Record = JSON.parse(JSON.stringify(want.parameters.params)); + if (params.info === 'router info') { + hilog.info(DOMAIN_NUMBER, TAG, `router info: ${params.info}`); + } + if (params.message === 'router message') { + hilog.info(DOMAIN_NUMBER, TAG, `router message: ${params.message}`); + } + } + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/nextrefreshtime/pages/NextRefreshTimeCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/nextrefreshtime/pages/NextRefreshTimeCard.ets index 25f1de4d678de0c0119fe51a64ed1dd985d95e3a..4b5af0b3c66090123ae92964ca50a283ef1929ce 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/nextrefreshtime/pages/NextRefreshTimeCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/nextrefreshtime/pages/NextRefreshTimeCard.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageNextRefreshTime = new LocalStorage(); - -@Entry(storageNextRefreshTime) -@Component -struct NextRefreshTimeCard { - @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); - @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.DescriptionDefault'); - - build() { - Column() { - Column() { - Text(this.title) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1) - .margin({ top: '8%', left: '10%' }) - Text(this.detail) - .fontColor('#FFFFFF') - .opacity(0.6) - .fontSize(12) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(2) - .margin({ top: '5%', left: '10%' }) - }.width('100%').height('50%') - .alignItems(HorizontalAlign.Start) - - Row() { - Button() { - Text($r('app.string.update')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '30%', bottom: '10%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'message', - params: { - msgTest: 'messageEvent' - } - }); - }) - }.width('100%').height('40%') - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageNextRefreshTime = new LocalStorage(); + +@Entry(storageNextRefreshTime) +@Component +struct NextRefreshTimeCard { + @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); + @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.DescriptionDefault'); + + build() { + Column() { + Column() { + Text(this.title) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(1) + .margin({ top: '8%', left: '10%' }) + Text(this.detail) + .fontColor('#FFFFFF') + .opacity(0.6) + .fontSize(12) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(2) + .margin({ top: '5%', left: '10%' }) + }.width('100%').height('50%') + .alignItems(HorizontalAlign.Start) + + Row() { + Button() { + Text($r('app.string.update')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '30%', bottom: '10%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'message', + params: { + msgTest: 'messageEvent' + } + }); + }) + }.width('100%').height('40%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/requestForm/pages/RequestFormCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/requestForm/pages/RequestFormCard.ets index 2ae05bd75171900ada72b2ec27a85f084e9fdfab..32df4f642f5ce9914ee01163ac21edded0e2c260 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/requestForm/pages/RequestFormCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/requestForm/pages/RequestFormCard.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageRequestFormCard = new LocalStorage(); - -@Entry(storageRequestFormCard) -@Component -struct RequestFormCard { - @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); - @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.widget_requestForm_desc'); - - build() { - Column() { - Column() { - Text(this.title) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1) - .margin({ top: '8%', left: '10%' }) - Text(this.detail) - .fontColor('#FFFFFF') - .opacity(0.6) - .fontSize(12) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(2) - .margin({ top: '5%', left: '10%' }) - }.width('100%') - .alignItems(HorizontalAlign.Start) - }.width('100%').height('100%') - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageRequestFormCard = new LocalStorage(); + +@Entry(storageRequestFormCard) +@Component +struct RequestFormCard { + @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); + @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.widget_requestForm_desc'); + + build() { + Column() { + Column() { + Text(this.title) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(1) + .margin({ top: '8%', left: '10%' }) + Text(this.detail) + .fontColor('#FFFFFF') + .opacity(0.6) + .fontSize(12) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(2) + .margin({ top: '5%', left: '10%' }) + }.width('100%') + .alignItems(HorizontalAlign.Start) + }.width('100%').height('100%') + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/scheduledupdatetime/pages/ScheduledUpdateTimeCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/scheduledupdatetime/pages/ScheduledUpdateTimeCard.ets index 86d91bccf2e86c85b62746518f1f81f64f1af262..eb0cb4076a8753f34a4458082ae403a290d014a5 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/scheduledupdatetime/pages/ScheduledUpdateTimeCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/scheduledupdatetime/pages/ScheduledUpdateTimeCard.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageScheUpdate = new LocalStorage(); - -@Entry(storageScheUpdate) -@Component -struct ScheduledUpdateTimeCard { - @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); - @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.widget_scheupdatetime_desc'); - - build() { - Column() { - Column() { - Text(this.title) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1) - .margin({ top: '8%', left: '10%' }) - Text(this.detail) - .fontColor('#FFFFFF') - .opacity(0.6) - .fontSize(12) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(2) - .margin({ top: '5%', left: '10%' }) - }.width('100%') - .alignItems(HorizontalAlign.Start) - }.width('100%').height('100%') - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageScheUpdate = new LocalStorage(); + +@Entry(storageScheUpdate) +@Component +struct ScheduledUpdateTimeCard { + @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); + @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.widget_scheupdatetime_desc'); + + build() { + Column() { + Column() { + Text(this.title) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(1) + .margin({ top: '8%', left: '10%' }) + Text(this.detail) + .fontColor('#FFFFFF') + .opacity(0.6) + .fontSize(12) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(2) + .margin({ top: '5%', left: '10%' }) + }.width('100%') + .alignItems(HorizontalAlign.Start) + }.width('100%').height('100%') + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updatebymessage/pages/UpdateByMessageCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updatebymessage/pages/UpdateByMessageCard.ets index d95fbfc2993e8b6ff8b8b1f8f9f3c9e219b4f3b1..3599d6b524703d705a850535e84dc4981e116113 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updatebymessage/pages/UpdateByMessageCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updatebymessage/pages/UpdateByMessageCard.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2023 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. - */ - -let storageUpdateByMsg = new LocalStorage(); - -@Entry(storageUpdateByMsg) -@Component -struct UpdateByMessageCard { - @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); - @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.DescriptionDefault'); - - build() { - Column() { - Column() { - Text(this.title) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%' }) - Text(this.detail) - .fontColor('#FFFFFF') - .opacity(0.6) - .fontSize(12) - .margin({ top: '5%', left: '10%' }) - }.width('100%').height('50%') - .alignItems(HorizontalAlign.Start) - - Row() { - Button() { - Text($r('app.string.update')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '30%', bottom: '10%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'message', - params: { msgTest: 'messageEvent' } - }); - }) - }.width('100%').height('40%') - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2023 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. + */ + +let storageUpdateByMsg = new LocalStorage(); + +@Entry(storageUpdateByMsg) +@Component +struct UpdateByMessageCard { + @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); + @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.DescriptionDefault'); + + build() { + Column() { + Column() { + Text(this.title) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%' }) + Text(this.detail) + .fontColor('#FFFFFF') + .opacity(0.6) + .fontSize(12) + .margin({ top: '5%', left: '10%' }) + }.width('100%').height('50%') + .alignItems(HorizontalAlign.Start) + + Row() { + Button() { + Text($r('app.string.update')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '30%', bottom: '10%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'message', + params: { msgTest: 'messageEvent' } + }); + }) + }.width('100%').height('40%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updateduration/pages/UpdateDurationCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updateduration/pages/UpdateDurationCard.ets index 15b84e8774e2f721d0e5bd7a112097bead79f6a8..b0e73bfd8545557c9cbb4c6b71d7360a6bf22e82 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updateduration/pages/UpdateDurationCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/updateduration/pages/UpdateDurationCard.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageUpdateDurationCard = new LocalStorage(); - -@Entry(storageUpdateDurationCard) -@Component -struct UpdateDurationCard { - @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); - @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.widget_updateduration_desc'); - - build() { - Column() { - Column() { - Text(this.title) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1) - .margin({ top: '8%', left: '10%' }) - Text(this.detail) - .fontColor('#FFFFFF') - .opacity(0.6) - .fontSize(12) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(2) - .margin({ top: '5%', left: '10%' }) - }.width('100%') - .alignItems(HorizontalAlign.Start) - }.width('100%').height('100%') - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageUpdateDurationCard = new LocalStorage(); + +@Entry(storageUpdateDurationCard) +@Component +struct UpdateDurationCard { + @LocalStorageProp('title') title: ResourceStr = $r('app.string.default_title'); + @LocalStorageProp('detail') detail: ResourceStr = $r('app.string.widget_updateduration_desc'); + + build() { + Column() { + Column() { + Text(this.title) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(1) + .margin({ top: '8%', left: '10%' }) + Text(this.detail) + .fontColor('#FFFFFF') + .opacity(0.6) + .fontSize(12) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(2) + .margin({ top: '5%', left: '10%' }) + }.width('100%') + .alignItems(HorizontalAlign.Start) + }.width('100%').height('100%') + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetcalleeentryability/WidgetCalleeEntryAbility.ts b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetcalleeentryability/WidgetCalleeEntryAbility.ts index 19752caebb755ff006e801ea04a22d1d794a8df9..03b6f519ca7d6884bc76a4e7453ea6034b36e227 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetcalleeentryability/WidgetCalleeEntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetcalleeentryability/WidgetCalleeEntryAbility.ts @@ -1,94 +1,94 @@ -/* - * Copyright (c) 2023-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 { window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { formBindingData, formProvider } from '@kit.FormKit'; -import { rpc } from '@kit.IPCKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'WidgetCalleeEntryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; -const MSG_SEND_METHOD: string = 'funA'; -const CONST_NUMBER_1: number = 1; - -class MyParcelable implements rpc.Parcelable { - num: number; - str: string; - - constructor(num: number, str: string) { - this.num = num; - this.str = str; - }; - - marshalling(messageSequence: rpc.MessageSequence): boolean { - messageSequence.writeInt(this.num); - messageSequence.writeString(this.str); - return true; - }; - - unmarshalling(messageSequence: rpc.MessageSequence): boolean { - this.num = messageSequence.readInt(); - this.str = messageSequence.readString(); - return true; - }; -} - -// 在收到call事件后会触发callee监听的方法 -let funACall = (data: rpc.MessageSequence): MyParcelable => { - // 获取call事件中传递的所有参数 - let params: Record = JSON.parse(data.readString()); - if (params.formId !== undefined) { - let curFormId: string = params.formId; - let message: string = params.calleeDetail; - hilog.info(DOMAIN_NUMBER, TAG, `UpdateForm formId: ${curFormId}, message: ${message}`); - let formData: Record = { - 'calleeDetail': message - }; - let formMsg: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData); - formProvider.updateForm(curFormId, formMsg).then((data) => { - hilog.info(DOMAIN_NUMBER, TAG, `updateForm success. ${JSON.stringify(data)}`); - }).catch((error: BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `updateForm failed: ${JSON.stringify(error)}`); - }); - } - return new MyParcelable(CONST_NUMBER_1, 'aaa'); -}; - -export default class WidgetCalleeEntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - try { - // 监听call事件所需的方法 - this.callee.on(MSG_SEND_METHOD, funACall); - } catch (error) { - hilog.error(DOMAIN_NUMBER, TAG, `${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`); - } - ; - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } +/* + * Copyright (c) 2023-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 { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { formBindingData, formProvider } from '@kit.FormKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'WidgetCalleeEntryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; +const MSG_SEND_METHOD: string = 'funA'; +const CONST_NUMBER_1: number = 1; + +class MyParcelable implements rpc.Parcelable { + num: number; + str: string; + + constructor(num: number, str: string) { + this.num = num; + this.str = str; + }; + + marshalling(messageSequence: rpc.MessageSequence): boolean { + messageSequence.writeInt(this.num); + messageSequence.writeString(this.str); + return true; + }; + + unmarshalling(messageSequence: rpc.MessageSequence): boolean { + this.num = messageSequence.readInt(); + this.str = messageSequence.readString(); + return true; + }; +} + +// 在收到call事件后会触发callee监听的方法 +let funACall = (data: rpc.MessageSequence): MyParcelable => { + // 获取call事件中传递的所有参数 + let params: Record = JSON.parse(data.readString()); + if (params.formId !== undefined) { + let curFormId: string = params.formId; + let message: string = params.calleeDetail; + hilog.info(DOMAIN_NUMBER, TAG, `UpdateForm formId: ${curFormId}, message: ${message}`); + let formData: Record = { + 'calleeDetail': message + }; + let formMsg: formBindingData.FormBindingData = formBindingData.createFormBindingData(formData); + formProvider.updateForm(curFormId, formMsg).then((data) => { + hilog.info(DOMAIN_NUMBER, TAG, `updateForm success. ${JSON.stringify(data)}`); + }).catch((error: BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `updateForm failed: ${JSON.stringify(error)}`); + }); + } + return new MyParcelable(CONST_NUMBER_1, 'aaa'); +}; + +export default class WidgetCalleeEntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + // 监听call事件所需的方法 + this.callee.on(MSG_SEND_METHOD, funACall); + } catch (error) { + hilog.error(DOMAIN_NUMBER, TAG, `${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`); + } + ; + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcall/pages/WidgetEventCallCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcall/pages/WidgetEventCallCard.ets index eda6d22d0cf92fb22a2aacdbb257a09d10ca131f..1830c200afb032b8a706eba828e1fccacdb5f1cd 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcall/pages/WidgetEventCallCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcall/pages/WidgetEventCallCard.ets @@ -1,84 +1,84 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageEventCall = new LocalStorage(); - -@Entry(storageEventCall) -@Component -struct WidgetEventCallCard { - @LocalStorageProp('formId') formId: string = '12400633174999288'; - - build() { - Column() { - Text($r('app.string.WidgetEventCallEntryAbility_desc')) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%' }) - Row() { - Column() { - Button() { - Text($r('app.string.ButtonA_label')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '20%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'call', - abilityName: 'WidgetEventCallEntryAbility', // 只能跳转到当前应用下的UIAbility - params: { - formId: this.formId, - method: 'funA' // 在EntryAbility中调用的方法名 - } - }); - }) - - Button() { - Text($r('app.string.ButtonB_label')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '8%', bottom: '15vp' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'call', - abilityName: 'WidgetEventCallEntryAbility', // 只能跳转到当前应用下的UIAbility - params: { - formId: this.formId, - method: 'funB', // 在EntryAbility中调用的方法名 - num: 1 // 需要传递的其他参数 - } - }); - }) - } - }.width('100%').height('80%') - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageEventCall = new LocalStorage(); + +@Entry(storageEventCall) +@Component +struct WidgetEventCallCard { + @LocalStorageProp('formId') formId: string = '12400633174999288'; + + build() { + Column() { + Text($r('app.string.WidgetEventCallEntryAbility_desc')) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%' }) + Row() { + Column() { + Button() { + Text($r('app.string.ButtonA_label')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '20%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'call', + abilityName: 'WidgetEventCallEntryAbility', // 只能跳转到当前应用下的UIAbility + params: { + formId: this.formId, + method: 'funA' // 在EntryAbility中调用的方法名 + } + }); + }) + + Button() { + Text($r('app.string.ButtonB_label')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '8%', bottom: '15vp' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'call', + abilityName: 'WidgetEventCallEntryAbility', // 只能跳转到当前应用下的UIAbility + params: { + formId: this.formId, + method: 'funB', // 在EntryAbility中调用的方法名 + num: 1 // 需要传递的其他参数 + } + }); + }) + } + }.width('100%').height('80%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcallentryability/WidgetEventCallEntryAbility.ts b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcallentryability/WidgetEventCallEntryAbility.ts index b49da20a6022785789b59bfba78e53f412063ea4..93915e3f8e4076467ed0d03a1c802cefbcc5f57a 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcallentryability/WidgetEventCallEntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventcallentryability/WidgetEventCallEntryAbility.ts @@ -1,84 +1,84 @@ -/* - * Copyright (c) 2022-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 { promptAction } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { rpc } from '@kit.IPCKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'WidgetEventCallEntryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; -const CONST_NUMBER_1: number = 1; -const CONST_NUMBER_2: number = 2; - -class MyParcelable implements rpc.Parcelable { - num: number; - str: string; - - constructor(num: number, str: string) { - this.num = num; - this.str = str; - } - - marshalling(messageSequence: rpc.MessageSequence): boolean { - messageSequence.writeInt(this.num); - messageSequence.writeString(this.str); - return true; - } - - unmarshalling(messageSequence: rpc.MessageSequence): boolean { - this.num = messageSequence.readInt(); - this.str = messageSequence.readString(); - return true; - } -} - -export default class WidgetEventCallEntryAbility extends UIAbility { - // 如果UIAbility第一次启动,在收到call事件后会触发onCreate生命周期回调 - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - try { - // 监听call事件所需的方法 - this.callee.on('funA', (data: rpc.MessageSequence) => { - // 获取call事件中传递的所有参数 - hilog.info(DOMAIN_NUMBER, TAG, `FunACall param: ${JSON.stringify(data.readString())}`); - promptAction.showToast({ - message: 'FunACall param:' + JSON.stringify(data.readString()) - }); - return new MyParcelable(CONST_NUMBER_1, 'aaa'); - }); - this.callee.on('funB', (data: rpc.MessageSequence) => { - // 获取call事件中传递的所有参数 - hilog.info(DOMAIN_NUMBER, TAG, `FunBCall param: ${JSON.stringify(data.readString())}`); - promptAction.showToast({ - message: 'FunBCall param:' + JSON.stringify(data.readString()) - }); - return new MyParcelable(CONST_NUMBER_2, 'bbb'); - }); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to register callee on. Cause: ${JSON.stringify(err as BusinessError)}`); - }; - } - - // 进程退出时,解除监听 - onDestroy(): void | Promise { - try { - this.callee.off('funA'); - this.callee.off('funB'); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to register callee off. Cause: ${JSON.stringify(err as BusinessError)}`); - }; - } +/* + * Copyright (c) 2022-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 { promptAction } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { rpc } from '@kit.IPCKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'WidgetEventCallEntryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; +const CONST_NUMBER_1: number = 1; +const CONST_NUMBER_2: number = 2; + +class MyParcelable implements rpc.Parcelable { + num: number; + str: string; + + constructor(num: number, str: string) { + this.num = num; + this.str = str; + } + + marshalling(messageSequence: rpc.MessageSequence): boolean { + messageSequence.writeInt(this.num); + messageSequence.writeString(this.str); + return true; + } + + unmarshalling(messageSequence: rpc.MessageSequence): boolean { + this.num = messageSequence.readInt(); + this.str = messageSequence.readString(); + return true; + } +} + +export default class WidgetEventCallEntryAbility extends UIAbility { + // 如果UIAbility第一次启动,在收到call事件后会触发onCreate生命周期回调 + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + // 监听call事件所需的方法 + this.callee.on('funA', (data: rpc.MessageSequence) => { + // 获取call事件中传递的所有参数 + hilog.info(DOMAIN_NUMBER, TAG, `FunACall param: ${JSON.stringify(data.readString())}`); + promptAction.showToast({ + message: 'FunACall param:' + JSON.stringify(data.readString()) + }); + return new MyParcelable(CONST_NUMBER_1, 'aaa'); + }); + this.callee.on('funB', (data: rpc.MessageSequence) => { + // 获取call事件中传递的所有参数 + hilog.info(DOMAIN_NUMBER, TAG, `FunBCall param: ${JSON.stringify(data.readString())}`); + promptAction.showToast({ + message: 'FunBCall param:' + JSON.stringify(data.readString()) + }); + return new MyParcelable(CONST_NUMBER_2, 'bbb'); + }); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to register callee on. Cause: ${JSON.stringify(err as BusinessError)}`); + }; + } + + // 进程退出时,解除监听 + onDestroy(): void | Promise { + try { + this.callee.off('funA'); + this.callee.off('funB'); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to register callee off. Cause: ${JSON.stringify(err as BusinessError)}`); + }; + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetevententryability/WidgetEventRouterEntryAbility.ts b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetevententryability/WidgetEventRouterEntryAbility.ts index dff614ade6143414754aaf7dba67c82a3cd5cb0b..919058d9398522472dd313466892cbfba867cfd4 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetevententryability/WidgetEventRouterEntryAbility.ts +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetevententryability/WidgetEventRouterEntryAbility.ts @@ -1,79 +1,79 @@ -/* - * Copyright (c) 2023-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 { window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { formBindingData, formInfo, formProvider } from '@kit.FormKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'WidgetEventRouterEntryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class WidgetEventRouterEntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.handleFormRouterEvent(want); - } - - handleFormRouterEvent(want: Want): void { - hilog.info(DOMAIN_NUMBER, TAG, 'handleFormRouterEvent, Want:', JSON.stringify(want)); - if (want.parameters && want.parameters[formInfo.FormParam.IDENTITY_KEY] !== undefined) { - let curFormId = JSON.stringify(want.parameters[formInfo.FormParam.IDENTITY_KEY]); - let message: string = JSON.stringify(want.parameters.routerDetail); - hilog.info(DOMAIN_NUMBER, TAG, `UpdateForm formId: ${curFormId}, message: ${message}`); - let formData: Record = { - routerDetail: message + 'UIAbility.', // 和卡片布局中对应 - }; - let formMsg = formBindingData.createFormBindingData(formData); - formProvider.updateForm(want.parameters[formInfo.FormParam.IDENTITY_KEY] + '', formMsg).then((data) => { - hilog.info(DOMAIN_NUMBER, TAG, 'updateForm success.', JSON.stringify(data)); - }).catch((error: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'updateForm failed.', JSON.stringify(error)); - }); - } - } - - // 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调 - onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, 'onNewWant Want:', JSON.stringify(want)); - if (want.parameters && want.parameters[formInfo.FormParam.IDENTITY_KEY] !== undefined) { - let curFormId = JSON.stringify(want.parameters[formInfo.FormParam.IDENTITY_KEY]); - let message: string = JSON.stringify(want.parameters.routerDetail); - hilog.info(DOMAIN_NUMBER, TAG, `UpdateForm formId: ${curFormId}, message: ${message}`); - let formData: Record = { - routerDetail: message + 'onNewWant UIAbility.', // 和卡片布局中对应 - }; - let formMsg = formBindingData.createFormBindingData(formData); - formProvider.updateForm(want.parameters[formInfo.FormParam.IDENTITY_KEY] + '', formMsg).then((data) => { - hilog.info(DOMAIN_NUMBER, TAG, 'updateForm success.', JSON.stringify(data)); - }).catch((error: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'updateForm failed.', JSON.stringify(error)); - }); - } - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } +/* + * Copyright (c) 2023-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 { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { formBindingData, formInfo, formProvider } from '@kit.FormKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'WidgetEventRouterEntryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class WidgetEventRouterEntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.handleFormRouterEvent(want); + } + + handleFormRouterEvent(want: Want): void { + hilog.info(DOMAIN_NUMBER, TAG, 'handleFormRouterEvent, Want:', JSON.stringify(want)); + if (want.parameters && want.parameters[formInfo.FormParam.IDENTITY_KEY] !== undefined) { + let curFormId = JSON.stringify(want.parameters[formInfo.FormParam.IDENTITY_KEY]); + let message: string = JSON.stringify(want.parameters.routerDetail); + hilog.info(DOMAIN_NUMBER, TAG, `UpdateForm formId: ${curFormId}, message: ${message}`); + let formData: Record = { + routerDetail: message + 'UIAbility.', // 和卡片布局中对应 + }; + let formMsg = formBindingData.createFormBindingData(formData); + formProvider.updateForm(want.parameters[formInfo.FormParam.IDENTITY_KEY] + '', formMsg).then((data) => { + hilog.info(DOMAIN_NUMBER, TAG, 'updateForm success.', JSON.stringify(data)); + }).catch((error: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'updateForm failed.', JSON.stringify(error)); + }); + } + } + + // 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调 + onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, 'onNewWant Want:', JSON.stringify(want)); + if (want.parameters && want.parameters[formInfo.FormParam.IDENTITY_KEY] !== undefined) { + let curFormId = JSON.stringify(want.parameters[formInfo.FormParam.IDENTITY_KEY]); + let message: string = JSON.stringify(want.parameters.routerDetail); + hilog.info(DOMAIN_NUMBER, TAG, `UpdateForm formId: ${curFormId}, message: ${message}`); + let formData: Record = { + routerDetail: message + 'onNewWant UIAbility.', // 和卡片布局中对应 + }; + let formMsg = formBindingData.createFormBindingData(formData); + formProvider.updateForm(want.parameters[formInfo.FormParam.IDENTITY_KEY] + '', formMsg).then((data) => { + hilog.info(DOMAIN_NUMBER, TAG, 'updateForm success.', JSON.stringify(data)); + }).catch((error: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'updateForm failed.', JSON.stringify(error)); + }); + } + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventrouter/pages/WidgetEventRouterCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventrouter/pages/WidgetEventRouterCard.ets index 443c3334bca65d9f51f5806fe3690ed9ecd107b9..da879698cf34bf7a6b645059e04815817109eaa7 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventrouter/pages/WidgetEventRouterCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgeteventrouter/pages/WidgetEventRouterCard.ets @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct WidgetEventRouterCard { - build() { - Column() { - Text($r('app.string.JumpLabel')) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%' }) - Row() { - Column() { - Button() { - Text($r('app.string.ButtonA_label')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '20%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'router', - abilityName: 'EntryAbility', - params: { targetPage: 'funA' } - }); - }) - - Button() { - Text($r('app.string.ButtonB_label')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '8%', bottom: '15vp' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'router', - abilityName: 'EntryAbility', - params: { targetPage: 'funB' } - }); - }) - } - }.width('100%').height('80%') - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct WidgetEventRouterCard { + build() { + Column() { + Text($r('app.string.JumpLabel')) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%' }) + Row() { + Column() { + Button() { + Text($r('app.string.ButtonA_label')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '20%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'router', + abilityName: 'EntryAbility', + params: { targetPage: 'funA' } + }); + }) + + Button() { + Text($r('app.string.ButtonB_label')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '8%', bottom: '15vp' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'router', + abilityName: 'EntryAbility', + params: { targetPage: 'funB' } + }); + }) + } + }.width('100%').height('80%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetimageupdate/pages/WidgetImageUpdateCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetimageupdate/pages/WidgetImageUpdateCard.ets index 988e5d19d4cbc6b932c6acbbbb4ab65418e645a3..c89885061c23bd77c145614dbf31c62ce5f31d36 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetimageupdate/pages/WidgetImageUpdateCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetimageupdate/pages/WidgetImageUpdateCard.ets @@ -1,103 +1,103 @@ -/* - * Copyright (c) 2022-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. - */ - -let storageWidgetImageUpdate = new LocalStorage(); - -@Entry(storageWidgetImageUpdate) -@Component -struct WidgetImageUpdateCard { - @LocalStorageProp('text') text: ResourceStr = $r('app.string.loading'); - @LocalStorageProp('loaded') loaded: boolean = false; - @LocalStorageProp('imgName') imgName: ResourceStr = $r('app.string.imgName'); - - build() { - if (this.loaded) { - Column() { - Column() { - Text(this.text) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(12) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1) - .margin({ top: '8%', left: '10%' }) - }.width('100%').height('50%') - .alignItems(HorizontalAlign.Start) - - Row() { - Button() { - Text($r('app.string.update')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '30%', bottom: '10%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'message', - params: { - info: 'refreshImage' - } - }); - }) - }.width('100%').height('40%') - .justifyContent(FlexAlign.Center) - } - .width('100%').height('100%') - .backgroundImage('memory://' + this.imgName) - .backgroundImageSize(ImageSize.Cover) - } else { - Column() { - Column() { - Text(this.text) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(12) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1) - .margin({ top: '8%', left: '10%' }) - }.width('100%').height('50%') - .alignItems(HorizontalAlign.Start) - - Row() { - Button() { - Text($r('app.string.update')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '30%', bottom: '10%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'message', - params: { - info: 'refreshImage' - } - }); - }) - }.width('100%').height('40%') - .justifyContent(FlexAlign.Center) - }.width('100%').height('100%') - .backgroundImage($r('app.media.ImageDisp')) - .backgroundImageSize(ImageSize.Cover) - } - } +/* + * Copyright (c) 2022-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. + */ + +let storageWidgetImageUpdate = new LocalStorage(); + +@Entry(storageWidgetImageUpdate) +@Component +struct WidgetImageUpdateCard { + @LocalStorageProp('text') text: ResourceStr = $r('app.string.loading'); + @LocalStorageProp('loaded') loaded: boolean = false; + @LocalStorageProp('imgName') imgName: ResourceStr = $r('app.string.imgName'); + + build() { + if (this.loaded) { + Column() { + Column() { + Text(this.text) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(12) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(1) + .margin({ top: '8%', left: '10%' }) + }.width('100%').height('50%') + .alignItems(HorizontalAlign.Start) + + Row() { + Button() { + Text($r('app.string.update')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '30%', bottom: '10%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'message', + params: { + info: 'refreshImage' + } + }); + }) + }.width('100%').height('40%') + .justifyContent(FlexAlign.Center) + } + .width('100%').height('100%') + .backgroundImage('memory://' + this.imgName) + .backgroundImageSize(ImageSize.Cover) + } else { + Column() { + Column() { + Text(this.text) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(12) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(1) + .margin({ top: '8%', left: '10%' }) + }.width('100%').height('50%') + .alignItems(HorizontalAlign.Start) + + Row() { + Button() { + Text($r('app.string.update')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '30%', bottom: '10%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'message', + params: { + info: 'refreshImage' + } + }); + }) + }.width('100%').height('40%') + .justifyContent(FlexAlign.Center) + }.width('100%').height('100%') + .backgroundImage($r('app.media.ImageDisp')) + .backgroundImageSize(ImageSize.Cover) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetpersistentdata/pages/WidgetPersistentDataCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetpersistentdata/pages/WidgetPersistentDataCard.ets index 492be67c22b9aedf9e156005dde8bb9cb2917298..2e81aa7864bd5ce535c970055ce7c2b8f5782221 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetpersistentdata/pages/WidgetPersistentDataCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetpersistentdata/pages/WidgetPersistentDataCard.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2023 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. - */ - -let storagePersis = new LocalStorage(); - -@Entry(storagePersis) -@Component -struct WidgetPersistentDataCard { - readonly FULL_WIDTH_PERCENT: string = '100%'; - readonly FULL_HEIGHT_PERCENT: string = '100%'; - @LocalStorageProp('list') list: Record[] = [{ 'type': 'a' }]; - - build() { - Column() { - Column() { - Text((this.list[0]['type'])) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%' }) - }.width('100%') - .alignItems(HorizontalAlign.Start) - }.width(this.FULL_WIDTH_PERCENT).height(this.FULL_HEIGHT_PERCENT) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2023 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. + */ + +let storagePersis = new LocalStorage(); + +@Entry(storagePersis) +@Component +struct WidgetPersistentDataCard { + readonly FULL_WIDTH_PERCENT: string = '100%'; + readonly FULL_HEIGHT_PERCENT: string = '100%'; + @LocalStorageProp('list') list: Record[] = [{ 'type': 'a' }]; + + build() { + Column() { + Column() { + Text((this.list[0]['type'])) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%' }) + }.width('100%') + .alignItems(HorizontalAlign.Start) + }.width(this.FULL_WIDTH_PERCENT).height(this.FULL_HEIGHT_PERCENT) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetprocessdata/pages/WidgetProcessDataCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetprocessdata/pages/WidgetProcessDataCard.ets index e73752b19033ba0306575261ca92d82de6e7936e..6819f0c4040e6186a9e0532f81d71c9278af5838 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetprocessdata/pages/WidgetProcessDataCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetprocessdata/pages/WidgetProcessDataCard.ets @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2023-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. - */ - -let storageProcess = new LocalStorage(); - -@Entry(storageProcess) -@Component -struct WidgetProcessDataCard { - @LocalStorageProp('datashareproxy://com.samples.widgetupdatebyproxy/weather') city: ResourceStr = - $r('app.string.loading'); - - build() { - Column() { - Column() { - Text(this.city) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%' }) - }.width('100%') - .alignItems(HorizontalAlign.Start) - }.width('100%').height('100%') - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2023-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. + */ + +let storageProcess = new LocalStorage(); + +@Entry(storageProcess) +@Component +struct WidgetProcessDataCard { + @LocalStorageProp('datashareproxy://com.samples.widgetupdatebyproxy/weather') city: ResourceStr = + $r('app.string.loading'); + + build() { + Column() { + Column() { + Text(this.city) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%' }) + }.width('100%') + .alignItems(HorizontalAlign.Start) + }.width('100%').height('100%') + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatebystatus/pages/WidgetUpdateByStatusCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatebystatus/pages/WidgetUpdateByStatusCard.ets index a8d757b219c5cc2d28b32674522a09f24609a164..7f5d495210ff7c10135d1392f0eec6c2a20166fc 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatebystatus/pages/WidgetUpdateByStatusCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatebystatus/pages/WidgetUpdateByStatusCard.ets @@ -1,112 +1,112 @@ -/* - * Copyright (c) 2023 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. - */ - -let storageUpdateByStatus = new LocalStorage(); - -@Entry(storageUpdateByStatus) -@Component -struct WidgetUpdateByStatusCard { - @LocalStorageProp('textA') textA: Resource = $r('app.string.to_be_refreshed'); - @LocalStorageProp('textB') textB: Resource = $r('app.string.to_be_refreshed'); - @State selectA: boolean = false; - @State selectB: boolean = false; - - build() { - Column() { - Column() { - Row() { - Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) - .padding(0) - .select(false) - .margin({ left: 26 }) - .onChange((value: boolean) => { - this.selectA = value; - postCardAction(this, { - action: 'message', - params: { - selectA: JSON.stringify(value) - } - }); - }) - Text($r('app.string.status_a')) - .fontColor('#000000') - .opacity(0.9) - .fontSize(14) - .margin({ left: 8 }) - } - .width('100%') - .padding(0) - .justifyContent(FlexAlign.Start) - - Row() { - Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) - .padding(0) - .select(false) - .margin({ left: 26 }) - .onChange((value: boolean) => { - this.selectB = value; - postCardAction(this, { - action: 'message', - params: { - selectB: JSON.stringify(value) - } - }); - }) - Text($r('app.string.status_b')) - .fontColor('#000000') - .opacity(0.9) - .fontSize(14) - .margin({ left: 8 }) - } - .width('100%') - .position({ y: 32 }) - .padding(0) - .justifyContent(FlexAlign.Start) - } - .position({ y: 12 }) - - Column() { - Row() { // 选中状态A才会进行刷新的内容 - Text($r('app.string.status_a')) - .fontColor('#000000') - .opacity(0.4) - .fontSize(12) - - Text(this.textA) - .fontColor('#000000') - .opacity(0.4) - .fontSize(12) - } - .margin({ top: '12px', left: 26, right: '26px' }) - - Row() { // 选中状态B才会进行刷新的内容 - Text($r('app.string.status_b')) - .fontColor('#000000') - .opacity(0.4) - .fontSize(12) - Text(this.textB) - .fontColor('#000000') - .opacity(0.4) - .fontSize(12) - }.margin({ top: '12px', bottom: '21px', left: 26, right: '26px' }) - } - .margin({ top: 80 }) - .width('100%') - .alignItems(HorizontalAlign.Start) - }.width('100%').height('100%') - .backgroundImage($r('app.media.CardUpdateByStatus')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2023 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. + */ + +let storageUpdateByStatus = new LocalStorage(); + +@Entry(storageUpdateByStatus) +@Component +struct WidgetUpdateByStatusCard { + @LocalStorageProp('textA') textA: Resource = $r('app.string.to_be_refreshed'); + @LocalStorageProp('textB') textB: Resource = $r('app.string.to_be_refreshed'); + @State selectA: boolean = false; + @State selectB: boolean = false; + + build() { + Column() { + Column() { + Row() { + Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) + .padding(0) + .select(false) + .margin({ left: 26 }) + .onChange((value: boolean) => { + this.selectA = value; + postCardAction(this, { + action: 'message', + params: { + selectA: JSON.stringify(value) + } + }); + }) + Text($r('app.string.status_a')) + .fontColor('#000000') + .opacity(0.9) + .fontSize(14) + .margin({ left: 8 }) + } + .width('100%') + .padding(0) + .justifyContent(FlexAlign.Start) + + Row() { + Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) + .padding(0) + .select(false) + .margin({ left: 26 }) + .onChange((value: boolean) => { + this.selectB = value; + postCardAction(this, { + action: 'message', + params: { + selectB: JSON.stringify(value) + } + }); + }) + Text($r('app.string.status_b')) + .fontColor('#000000') + .opacity(0.9) + .fontSize(14) + .margin({ left: 8 }) + } + .width('100%') + .position({ y: 32 }) + .padding(0) + .justifyContent(FlexAlign.Start) + } + .position({ y: 12 }) + + Column() { + Row() { // 选中状态A才会进行刷新的内容 + Text($r('app.string.status_a')) + .fontColor('#000000') + .opacity(0.4) + .fontSize(12) + + Text(this.textA) + .fontColor('#000000') + .opacity(0.4) + .fontSize(12) + } + .margin({ top: '12px', left: 26, right: '26px' }) + + Row() { // 选中状态B才会进行刷新的内容 + Text($r('app.string.status_b')) + .fontColor('#000000') + .opacity(0.4) + .fontSize(12) + Text(this.textB) + .fontColor('#000000') + .opacity(0.4) + .fontSize(12) + }.margin({ top: '12px', bottom: '21px', left: 26, right: '26px' }) + } + .margin({ top: 80 }) + .width('100%') + .alignItems(HorizontalAlign.Start) + }.width('100%').height('100%') + .backgroundImage($r('app.media.CardUpdateByStatus')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatecall/pages/WidgetUpdateCallCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatecall/pages/WidgetUpdateCallCard.ets index 95f756b494cd668780c18efd84a1894f8b11398e..d4cc453b2e8645dc7d7d2a1afb6f0886d2cbd1c6 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatecall/pages/WidgetUpdateCallCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdatecall/pages/WidgetUpdateCallCard.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageUpdtCall = new LocalStorage(); - -@Entry(storageUpdtCall) -@Component -struct WidgetUpdateCallCard { - @LocalStorageProp('formId') formId: string = '12400633174999288'; - @LocalStorageProp('calleeDetail') calleeDetail: ResourceStr = $r('app.string.init'); - - build() { - Column() { - Column() { - Text(this.calleeDetail) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%' }) - }.width('100%').height('50%') - .alignItems(HorizontalAlign.Start) - - Row() { - Button() { - Text($r('app.string.CalleeJumpLabel')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '30%', bottom: '10%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'call', - abilityName: 'WidgetCalleeEntryAbility', // 只能拉起当前应用下的UIAbility - params: { - method: 'funA', - formId: this.formId, - calleeDetail: 'CallFrom' - } - }); - }) - }.width('100%').height('40%') - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageUpdtCall = new LocalStorage(); + +@Entry(storageUpdtCall) +@Component +struct WidgetUpdateCallCard { + @LocalStorageProp('formId') formId: string = '12400633174999288'; + @LocalStorageProp('calleeDetail') calleeDetail: ResourceStr = $r('app.string.init'); + + build() { + Column() { + Column() { + Text(this.calleeDetail) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%' }) + }.width('100%').height('50%') + .alignItems(HorizontalAlign.Start) + + Row() { + Button() { + Text($r('app.string.CalleeJumpLabel')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '30%', bottom: '10%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'call', + abilityName: 'WidgetCalleeEntryAbility', // 只能拉起当前应用下的UIAbility + params: { + method: 'funA', + formId: this.formId, + calleeDetail: 'CallFrom' + } + }); + }) + }.width('100%').height('40%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdaterouter/pages/WidgetUpdateRouterCard.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdaterouter/pages/WidgetUpdateRouterCard.ets index f4eeba95cf93dd0e4915e4ab374079714df97e20..c3ddc319805774dc2831063f988702da2e44517f 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdaterouter/pages/WidgetUpdateRouterCard.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/ets/widgetupdaterouter/pages/WidgetUpdateRouterCard.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2022-2023 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. - */ - -let storageUpdtRouter = new LocalStorage(); - -@Entry(storageUpdtRouter) -@Component -struct WidgetUpdtRouterCard { - @LocalStorageProp('routerDetail') routerDetail: ResourceStr = $r('app.string.init'); - - build() { - Column() { - Column() { - Text(this.routerDetail) - .fontColor('#FFFFFF') - .opacity(0.9) - .fontSize(14) - .margin({ top: '8%', left: '10%', right: '10%' }) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(2) - }.width('100%').height('50%') - .alignItems(HorizontalAlign.Start) - - Row() { - Button() { - Text($r('app.string.JumpLabel')) - .fontColor('#45A6F4') - .fontSize(12) - } - .width(120) - .height(32) - .margin({ top: '30%', bottom: '10%' }) - .backgroundColor('#FFFFFF') - .borderRadius(16) - .onClick(() => { - postCardAction(this, { - action: 'router', - abilityName: 'WidgetEventRouterEntryAbility', // 只能跳转到当前应用下的UIAbility - params: { - routerDetail: 'RouterFromCard', - } - }); - }) - }.width('100%').height('40%') - .justifyContent(FlexAlign.Center) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Start) - .backgroundImage($r('app.media.CardEvent')) - .backgroundImageSize(ImageSize.Cover) - } +/* + * Copyright (c) 2022-2023 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. + */ + +let storageUpdtRouter = new LocalStorage(); + +@Entry(storageUpdtRouter) +@Component +struct WidgetUpdtRouterCard { + @LocalStorageProp('routerDetail') routerDetail: ResourceStr = $r('app.string.init'); + + build() { + Column() { + Column() { + Text(this.routerDetail) + .fontColor('#FFFFFF') + .opacity(0.9) + .fontSize(14) + .margin({ top: '8%', left: '10%', right: '10%' }) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .maxLines(2) + }.width('100%').height('50%') + .alignItems(HorizontalAlign.Start) + + Row() { + Button() { + Text($r('app.string.JumpLabel')) + .fontColor('#45A6F4') + .fontSize(12) + } + .width(120) + .height(32) + .margin({ top: '30%', bottom: '10%' }) + .backgroundColor('#FFFFFF') + .borderRadius(16) + .onClick(() => { + postCardAction(this, { + action: 'router', + abilityName: 'WidgetEventRouterEntryAbility', // 只能跳转到当前应用下的UIAbility + params: { + routerDetail: 'RouterFromCard', + } + }); + }) + }.width('100%').height('40%') + .justifyContent(FlexAlign.Center) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Start) + .backgroundImage($r('app.media.CardEvent')) + .backgroundImageSize(ImageSize.Cover) + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/js/WidgetJS/pages/index/index.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/js/WidgetJS/pages/index/index.json index 5cac48220e353047e1b14028e4affec7e01f6d5b..c7ea46e15d68890e531cbaa614633ba7e1929539 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/js/WidgetJS/pages/index/index.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/js/WidgetJS/pages/index/index.json @@ -1,22 +1,22 @@ -{ - "data": { - "title": "TitleDefault", - "detail": "TextDefault" - }, - "actions": { - "routerEvent": { - "action": "router", - "abilityName": "JSCardEntryAbility", - "params": { - "info": "router info", - "message": "router message" - } - }, - "messageEvent": { - "action": "message", - "params": { - "detail": "message detail" - } - } - } +{ + "data": { + "title": "TitleDefault", + "detail": "TextDefault" + }, + "actions": { + "routerEvent": { + "action": "router", + "abilityName": "JSCardEntryAbility", + "params": { + "info": "router info", + "message": "router message" + } + }, + "messageEvent": { + "action": "message", + "params": { + "detail": "message detail" + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/module.json5 index 11fea8127cc2b7929f08769ba29107595acd2357..fa089cd93622473c80295b93b2fc048dd88bde56 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/module.json5 @@ -1,214 +1,214 @@ -/* - * Copyright (c) 2022-2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "WidgetEventRouterEntryAbility", - "srcEntry": "./ets/widgetevententryability/WidgetEventRouterEntryAbility.ts", - "description": "$string:WidgetEventEntryAbility_desc", - "icon": "$media:icon", - "label": "$string:WidgetEventEntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "JsCardEntryAbility", - "srcEntry": "./ets/jscardentryability/JsCardEntryAbility.ts", - "description": "$string:JSCardEntryAbility_desc", - "icon": "$media:icon", - "label": "$string:JSCardEntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "WidgetCalleeEntryAbility", - "srcEntry": "./ets/widgetcalleeentryability/WidgetCalleeEntryAbility.ts", - "description": "$string:WidgetCalleeEntryAbility_desc", - "icon": "$media:icon", - "label": "$string:WidgetCalleeEntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - { - "name": "WidgetEventCallEntryAbility", - "srcEntry": "./ets/widgeteventcallentryability/WidgetEventCallEntryAbility.ts", - "description": "$string:WidgetEventCallEntryAbility_desc", - "icon": "$media:icon", - "label": "$string:WidgetEventCallEntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - } - ], - "extensionAbilities": [ - { - "name": "EntryFormAbility", - "srcEntry": "./ets/entryformability/EntryFormAbility.ts", - "label": "$string:EntryFormAbility_label", - "description": "$string:EntryFormAbility_desc", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_config" - } - ] - }, - { - "name": "WgtImgUpdateEntryFormAbility", - "srcEntry": "./ets/wgtimgupdateentryformability/WgtImgUpdateEntryFormAbility.ts", - "description": "$string:WgtImgUpdateEntryFormAbility_desc", - "label": "$string:WgtImgUpdateEntryFormAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_imgupdate_config" - } - ] - }, - { - "name": "UpdateByTimeFormAbility", - "srcEntry": "./ets/updatebytimeformability/UpdateByTimeFormAbility.ts", - "description": "$string:UpdateByTimeFormAbility_desc", - "label": "$string:UpdateByTimeFormAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_updatebytime_config" - } - ] - }, - { - "name": "UpdateByStatusFormAbility", - "srcEntry": "./ets/updatebystatusformability/UpdateByStatusFormAbility.ts", - "description": "$string:UpdateByStatusFormAbility_desc", - "label": "$string:UpdateByStatusFormAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_updatebystatus_config" - } - ] - }, - { - "name": "JsCardFormAbility", - "srcEntry": "./ets/jscardformability/JsCardFormAbility.ts", - "description": "$string:JSCardFormAbility_desc", - "label": "$string:JSCardFormAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_jscard_config" - } - ] - }, - { - "name": "ProcessDataFormAbility", - "srcEntry": "./ets/processdataentryability/ProcessDataFormAbility.ts", - "description": "$string:ProcessDataEntryAbility_desc", - "label": "$string:ProcessDataEntryAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_processdata_config" - } - ] - }, - { - "name": "WidgetCalleeFormAbility", - "srcEntry": "./ets/widgetcalleeformability/WidgetCalleeFormAbility.ts", - "description": "$string:WidgetCalleeFormAbility_desc", - "label": "$string:WidgetCalleeFormAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_widgetcallee_config" - } - ] - }, - { - "name": "PersistentDataFormAbility", - "srcEntry": "./ets/persistentdataformability/PersistentDataFormAbility.ts", - "description": "$string:PersistentDataFormAbility_desc", - "label": "$string:PersistentDataFormAbility_label", - "type": "form", - "metadata": [ - { - "name": "ohos.extension.form", - "resource": "$profile:form_persistentdata_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", - }, - { - "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO", - }, - { - "name": "ohos.permission.INTERNET", - "usedScene": { - "abilities": [ - "WgtImgUpdateEntryFormAbility" - ], - "when": "inuse", - } - } - ] - } +/* + * Copyright (c) 2022-2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "WidgetEventRouterEntryAbility", + "srcEntry": "./ets/widgetevententryability/WidgetEventRouterEntryAbility.ts", + "description": "$string:WidgetEventEntryAbility_desc", + "icon": "$media:icon", + "label": "$string:WidgetEventEntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "JsCardEntryAbility", + "srcEntry": "./ets/jscardentryability/JsCardEntryAbility.ts", + "description": "$string:JSCardEntryAbility_desc", + "icon": "$media:icon", + "label": "$string:JSCardEntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "WidgetCalleeEntryAbility", + "srcEntry": "./ets/widgetcalleeentryability/WidgetCalleeEntryAbility.ts", + "description": "$string:WidgetCalleeEntryAbility_desc", + "icon": "$media:icon", + "label": "$string:WidgetCalleeEntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + { + "name": "WidgetEventCallEntryAbility", + "srcEntry": "./ets/widgeteventcallentryability/WidgetEventCallEntryAbility.ts", + "description": "$string:WidgetEventCallEntryAbility_desc", + "icon": "$media:icon", + "label": "$string:WidgetEventCallEntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + } + ], + "extensionAbilities": [ + { + "name": "EntryFormAbility", + "srcEntry": "./ets/entryformability/EntryFormAbility.ts", + "label": "$string:EntryFormAbility_label", + "description": "$string:EntryFormAbility_desc", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_config" + } + ] + }, + { + "name": "WgtImgUpdateEntryFormAbility", + "srcEntry": "./ets/wgtimgupdateentryformability/WgtImgUpdateEntryFormAbility.ts", + "description": "$string:WgtImgUpdateEntryFormAbility_desc", + "label": "$string:WgtImgUpdateEntryFormAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_imgupdate_config" + } + ] + }, + { + "name": "UpdateByTimeFormAbility", + "srcEntry": "./ets/updatebytimeformability/UpdateByTimeFormAbility.ts", + "description": "$string:UpdateByTimeFormAbility_desc", + "label": "$string:UpdateByTimeFormAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_updatebytime_config" + } + ] + }, + { + "name": "UpdateByStatusFormAbility", + "srcEntry": "./ets/updatebystatusformability/UpdateByStatusFormAbility.ts", + "description": "$string:UpdateByStatusFormAbility_desc", + "label": "$string:UpdateByStatusFormAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_updatebystatus_config" + } + ] + }, + { + "name": "JsCardFormAbility", + "srcEntry": "./ets/jscardformability/JsCardFormAbility.ts", + "description": "$string:JSCardFormAbility_desc", + "label": "$string:JSCardFormAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_jscard_config" + } + ] + }, + { + "name": "ProcessDataFormAbility", + "srcEntry": "./ets/processdataentryability/ProcessDataFormAbility.ts", + "description": "$string:ProcessDataEntryAbility_desc", + "label": "$string:ProcessDataEntryAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_processdata_config" + } + ] + }, + { + "name": "WidgetCalleeFormAbility", + "srcEntry": "./ets/widgetcalleeformability/WidgetCalleeFormAbility.ts", + "description": "$string:WidgetCalleeFormAbility_desc", + "label": "$string:WidgetCalleeFormAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_widgetcallee_config" + } + ] + }, + { + "name": "PersistentDataFormAbility", + "srcEntry": "./ets/persistentdataformability/PersistentDataFormAbility.ts", + "description": "$string:PersistentDataFormAbility_desc", + "label": "$string:PersistentDataFormAbility_label", + "type": "form", + "metadata": [ + { + "name": "ohos.extension.form", + "resource": "$profile:form_persistentdata_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.KEEP_BACKGROUND_RUNNING", + }, + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO", + }, + { + "name": "ohos.permission.INTERNET", + "usedScene": { + "abilities": [ + "WgtImgUpdateEntryFormAbility" + ], + "when": "inuse", + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/color.json index 45df772f394dfcefbf2a1a317646964375a226d4..79695d2275265e18fa91fb2a1ee8eea2b72eb6ca 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "text_font_color", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#f1f3f5" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "text_font_color", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#f1f3f5" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/float.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/float.json index edb7816076bba14bb708f41ea9c255af12f22fdf..d50ddbfab2063f1a6236e1444b0f7d38c3389a98 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/float.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/element/float.json @@ -1,28 +1,28 @@ -{ - "float": [ - { - "name": "title_immersive_font_size", - "value": "19fp" - }, - { - "name": "detail_immersive_font_size", - "value": "16fp" - }, - { - "name": "detail_immersive_margin_top", - "value": "6vp" - }, - { - "name": "detail_immersive_opacity", - "value": "0.66" - }, - { - "name": "column_padding", - "value": "12vp" - }, - { - "name": "font_size", - "value": "16fp" - } - ] +{ + "float": [ + { + "name": "title_immersive_font_size", + "value": "19fp" + }, + { + "name": "detail_immersive_font_size", + "value": "16fp" + }, + { + "name": "detail_immersive_margin_top", + "value": "6vp" + }, + { + "name": "detail_immersive_opacity", + "value": "0.66" + }, + { + "name": "column_padding", + "value": "12vp" + }, + { + "name": "font_size", + "value": "16fp" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_config.json index e49d008bf2279327d934065de80b2888badfcdeb..42dd8d204174e124a47255e1ebb214f558df7fb7 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_config.json @@ -1,80 +1,80 @@ -{ - "forms": [ - { - "name": "AttrAnimation", - "description": "$string:widget_animation_desc", - "src": "./ets/attranimation/pages/AttrAnimationCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "CustomCanvasDrawing", - "description": "$string:widget_custom_desc", - "src": "./ets/customcanvasdrawing/pages/CustomCanvasDrawingCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "4*4", - "supportDimensions": [ - "4*4" - ] - }, - { - "name": "WidgetEventRouter", - "description": "$string:widget_eventrouter_desc", - "src": "./ets/widgeteventrouter/pages/WidgetEventRouterCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "UpdateByMessage", - "description": "$string:widget_updatebymsg_desc", - "src": "./ets/updatebymessage/pages/UpdateByMessageCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "AttrAnimation", + "description": "$string:widget_animation_desc", + "src": "./ets/attranimation/pages/AttrAnimationCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "CustomCanvasDrawing", + "description": "$string:widget_custom_desc", + "src": "./ets/customcanvasdrawing/pages/CustomCanvasDrawingCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "4*4", + "supportDimensions": [ + "4*4" + ] + }, + { + "name": "WidgetEventRouter", + "description": "$string:widget_eventrouter_desc", + "src": "./ets/widgeteventrouter/pages/WidgetEventRouterCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "UpdateByMessage", + "description": "$string:widget_updatebymsg_desc", + "src": "./ets/updatebymessage/pages/UpdateByMessageCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_imgupdate_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_imgupdate_config.json index 703dba1eba1258be701aa56ade7877d95c4ea573..c1ef6609cdcca8ef49cfe9d06455d6b1149ceab7 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_imgupdate_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_imgupdate_config.json @@ -1,23 +1,23 @@ -{ - "forms": [ - { - "name": "WidgetImageUpdate", - "description": "$string:WgtImgUpdateEntryFormAbility_desc", - "src": "./ets/widgetimageupdate/pages/WidgetImageUpdateCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": false, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "WidgetImageUpdate", + "description": "$string:WgtImgUpdateEntryFormAbility_desc", + "src": "./ets/widgetimageupdate/pages/WidgetImageUpdateCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_jscard_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_jscard_config.json index ab56d5a657d81321bdfa12869e1f3d24762d443b..3d2afc0a92f0a449de44b52ee33ca32e57b49a32 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_jscard_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_jscard_config.json @@ -1,22 +1,22 @@ -{ - "forms": [ - { - "name": "WidgetJS", - "description": "$string:JSCardEntryAbility_desc", - "src": "./js/WidgetJS/pages/index/index", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "WidgetJS", + "description": "$string:JSCardEntryAbility_desc", + "src": "./js/WidgetJS/pages/index/index", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_persistentdata_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_persistentdata_config.json index 0e037ca24cf6be3e7bebbbbdc957d62e525a581b..5eaba8e39de8a3d3cec1324f659e6d8a7b885506 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_persistentdata_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_persistentdata_config.json @@ -1,24 +1,24 @@ -{ - "forms": [ - { - "name": "WidgetPersistentData", - "description": "This is a service widget update by proxy using persistent data.", - "src": "./ets/widgetpersistentdata/pages/WidgetPersistentDataCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ], - "dataProxyEnabled": true - } - ] +{ + "forms": [ + { + "name": "WidgetPersistentData", + "description": "This is a service widget update by proxy using persistent data.", + "src": "./ets/widgetpersistentdata/pages/WidgetPersistentDataCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ], + "dataProxyEnabled": true + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_processdata_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_processdata_config.json index febbffd6a31ba3f1b9dc7fc6e1cf4e0ae704e361..fb01577423788df3934d28bf76e78861a15964e6 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_processdata_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_processdata_config.json @@ -1,23 +1,23 @@ -{ - "forms": [ - { - "name": "WidgetProcessData", - "description": "$string:ProcessDataEntryAbility_desc", - "src": "./ets/widgetprocessdata/pages/WidgetProcessDataCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ], - "dataProxyEnabled": true - } - ] +{ + "forms": [ + { + "name": "WidgetProcessData", + "description": "$string:ProcessDataEntryAbility_desc", + "src": "./ets/widgetprocessdata/pages/WidgetProcessDataCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ], + "dataProxyEnabled": true + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebystatus_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebystatus_config.json index 1447bd49a3e236fcb873f87d02d62861fc9e85d2..ecbeee54739e7ad2c5e54e1de5967b8c4363cebf 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebystatus_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebystatus_config.json @@ -1,23 +1,23 @@ -{ - "forms": [ - { - "name": "WidgetUpdateByStatus", - "description": "$string:UpdateByStatusFormAbility_desc", - "src": "./ets/widgetupdatebystatus/pages/WidgetUpdateByStatusCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "WidgetUpdateByStatus", + "description": "$string:UpdateByStatusFormAbility_desc", + "src": "./ets/widgetupdatebystatus/pages/WidgetUpdateByStatusCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebytime_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebytime_config.json index b84a54f2dbfeaf1e3c30a725fae9722aa5cd93bf..26ade10d74066f12757cd052d98e7c1c9cf5aca2 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebytime_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_updatebytime_config.json @@ -1,85 +1,85 @@ -{ - "forms": [ - { - "name": "UpdateDuration", - "description": "$string:widget_updateduration_desc", - "src": "./ets/updateduration/pages/UpdateDurationCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 2, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "ScheduledUpdateTime", - "description": "$string:widget_scheupdatetime_desc", - "src": "./ets/scheduledupdatetime/pages/ScheduledUpdateTimeCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 0, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "NextRefreshTime", - "description": "$string:widget_nextrefreshtime_desc", - "src": "./ets/nextrefreshtime/pages/NextRefreshTimeCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 0, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "RequestForm", - "description": "$string:widget_requestForm_desc", - "src": "./ets/requestForm/pages/RequestFormCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 2, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ], - "formConfigAbility": "ability://com.example.entry.EntryAbility", - "dataProxyEnabled": false, - "isDynamic": true, - "transparencyEnabled": false, - "metadata": [] - } - ] +{ + "forms": [ + { + "name": "UpdateDuration", + "description": "$string:widget_updateduration_desc", + "src": "./ets/updateduration/pages/UpdateDurationCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 2, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "ScheduledUpdateTime", + "description": "$string:widget_scheupdatetime_desc", + "src": "./ets/scheduledupdatetime/pages/ScheduledUpdateTimeCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 0, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "NextRefreshTime", + "description": "$string:widget_nextrefreshtime_desc", + "src": "./ets/nextrefreshtime/pages/NextRefreshTimeCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 0, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "RequestForm", + "description": "$string:widget_requestForm_desc", + "src": "./ets/requestForm/pages/RequestFormCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 2, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ], + "formConfigAbility": "ability://com.example.entry.EntryAbility", + "dataProxyEnabled": false, + "isDynamic": true, + "transparencyEnabled": false, + "metadata": [] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_widgetcallee_config.json b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_widgetcallee_config.json index 76684446af1f72650beaaf86ad0d39df4e903421..beef5ffda66d135d5060bcfe713557e153476bc2 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_widgetcallee_config.json +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/main/resources/base/profile/form_widgetcallee_config.json @@ -1,61 +1,61 @@ -{ - "forms": [ - { - "name": "WidgetUpdateRouter", - "description": "$string:WidgetEventEntryAbility_desc", - "src": "./ets/widgetupdaterouter/pages/WidgetUpdateRouterCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "WidgetEventCall", - "description": "$string:WidgetEventCallEntryAbility_desc", - "src": "./ets/widgeteventcall/pages/WidgetEventCallCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": false, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - }, - { - "name": "WidgetUpdateCall", - "description": "$string:WidgetCalleeEntryAbility_desc", - "src": "./ets/widgetupdatecall/pages/WidgetUpdateCallCard.ets", - "uiSyntax": "arkts", - "window": { - "designWidth": 720, - "autoDesignWidth": true - }, - "colorMode": "auto", - "isDefault": true, - "updateEnabled": true, - "scheduledUpdateTime": "10:30", - "updateDuration": 1, - "defaultDimension": "2*2", - "supportDimensions": [ - "2*2" - ] - } - ] +{ + "forms": [ + { + "name": "WidgetUpdateRouter", + "description": "$string:WidgetEventEntryAbility_desc", + "src": "./ets/widgetupdaterouter/pages/WidgetUpdateRouterCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "WidgetEventCall", + "description": "$string:WidgetEventCallEntryAbility_desc", + "src": "./ets/widgeteventcall/pages/WidgetEventCallCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": false, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + }, + { + "name": "WidgetUpdateCall", + "description": "$string:WidgetCalleeEntryAbility_desc", + "src": "./ets/widgetupdatecall/pages/WidgetUpdateCallCard.ets", + "uiSyntax": "arkts", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/ets/test/Form.test.ets b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/ets/test/Form.test.ets index e298772fd834bd6409c91416904e6d55b9ba72c1..8ccf92546d3f3a23f522e99e98eff5a7ba18f739 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/ets/test/Form.test.ets +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/ets/test/Form.test.ets @@ -1,1275 +1,1275 @@ -/* - * Copyright (c) 2022-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, Driver, MatchPattern, ON } from '@kit.TestKit'; -import { beforeAll, describe, expect, it } from '@ohos/hypium'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -const TAG = '[Sample_ServiceCard_Test]'; -const DOMAIN = 0xF811; -const BUNDLE = 'ServiceCard_'; -const DELAYTIME01 = 1000; -const DELAYTIME02 = 2000; -const DELAYTIME03 = 3000; -let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -let resourceManager = abilityDelegator.getAppContext().resourceManager; -let cardArkTsWidgetEventRouter = 'WidgetEventRouter'; -let cardWidgetUpdateRouter = 'WidgetUpdateRouter'; -let cardWidgetUpdateCallCard = 'WidgetUpdateCall'; -let cardWidgetEventCall = 'WidgetEventCall' -let cardUpdateByMessage = 'UpdateByMessage'; -let cardAttrAnimation = 'AttrAnimation'; -let cardCustomCanvasDrawing = 'CustomCanvasDrawing'; -let cardUpdateDuration = 'UpdateDuration'; -let cardScheduledUpdateTime = 'ScheduledUpdateTime'; -let cardNextRefreshTimeCard = 'NextRefreshTime'; -let cardWidgetImageUpdate = 'WidgetImageUpdate'; -let cardWidgetUpdateByStatus = 'WidgetUpdateByStatus'; -let cardWidgetProcessData = 'WidgetProcessData'; -let cardWidgetPersistentData = 'WidgetPersistentData'; -let cardWidgetJS = 'WidgetJS'; -let driver = Driver.create(); -// Sliding coordinate -const START_SLIDING_X = 700; -const FINISH_SLIDING_X = 50; -const SLIDING_COORDINATE_Y = 300; -// Add to desktop coordinate -const ADD_TO_DESKTOP_X = 300; -const ADD_TO_DESKTOP_Y = 1200; - -export default function formTest() { - describe('ActsFormTest', () => { - beforeAll(async () => { - // Exit the test interface to execute the test case - await driver.pressHome(); - await driver.delayMs(DELAYTIME01); - }) - - /* - * @tc.number: ServiceCard_ArkTS_001 - * @tc.name: Add WidgetEventRouter cards to desktop. - * @tc.desc: Add WidgetEventRouter cards to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 begin'); - await driver.delayMs(DELAYTIME01); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardArkTsWidgetEventRouter).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME02); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 2; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.add_to_desktop')), - MatchPattern.CONTAINS)); - let addCard = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.add_to_desktop')), - MatchPattern.CONTAINS)); - await addCard.click(); - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardArkTsWidgetEventRouter).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_002 - * @tc.name: Add cardWidgetUpdateRouter card to desktop. - * @tc.desc: Add cardWidgetUpdateRouter card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_002', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetUpdateRouter).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 12; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetUpdateRouter).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_003 - * @tc.name: Add UpdateByMessage card to desktop. - * @tc.desc: Add UpdateByMessage card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_003', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardUpdateByMessage).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 3; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardUpdateByMessage).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_004 - * @tc.name: Add CustomCanvasDrawing card to desktop. - * @tc.desc: Add CustomCanvasDrawing card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_004', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardCustomCanvasDrawing).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardCustomCanvasDrawing).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_005 - * @tc.name: Add Animation card to desktop. - * @tc.desc: Add Animation card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_005', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardAttrAnimation).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 addCardToDesktop'); - await driver.delayMs(2000); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardAttrAnimation).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_006 - * @tc.name: Add WidgetUpdateByStatus card to desktop. - * @tc.desc: Add WidgetUpdateByStatus card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_006', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetUpdateByStatus).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 7; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - /// Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetUpdateByStatus).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME01); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_007 - * @tc.name: Add WidgetProcessData card to desktop. - * @tc.desc: Add WidgetProcessData card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_007', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetProcessData).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 6; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetProcessData).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME01); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_008 - * @tc.name: Add UpdateDuration card to desktop. - * @tc.desc: Add UpdateDuration card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_008', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardUpdateDuration).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 8; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardUpdateDuration).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME01); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_009 - * @tc.name: Add ScheduledUpdateTime card to desktop. - * @tc.desc: Add ScheduledUpdateTime card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_009', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardScheduledUpdateTime).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 9; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardScheduledUpdateTime).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_010 - * @tc.name: Add NextRefreshTimeCard card to desktop. - * @tc.desc: Add NextRefreshTimeCard card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_010', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardNextRefreshTimeCard).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 10; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardNextRefreshTimeCard).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_011 - * @tc.name: Add WidgetImageUpdate card to desktop. - * @tc.desc: Add WidgetImageUpdate card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_011', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetImageUpdate).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 11; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetImageUpdate).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_012 - * @tc.name: Add WidgetEventCall card to desktop. - * @tc.desc: Add WidgetEventCall card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_012', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetEventCall).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 13; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetEventCall).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_013 - * @tc.name: Add WidgetUpdateCall card to desktop. - * @tc.desc: Add WidgetUpdateCall card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_013', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetUpdateCallCard).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - - for (let i = 0; i < 14; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetUpdateCallCard).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_ArkTS_014 - * @tc.name: Add WidgetPersistentData card to desktop. - * @tc.desc: Add WidgetPersistentData card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'ArkTS_014', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetPersistentData).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 5; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetPersistentData).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - - /* - * @tc.number: ServiceCard_JS_UI_001 - * @tc.name: Add WidgetJS card to desktop. - * @tc.desc: Add WidgetJS card to desktop. - * @tc.size: MediumTest - * @tc.type: Function - * @tc.level Level 1 - */ - it(BUNDLE + 'JS_UI_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 begin'); - await driver.delayMs(DELAYTIME03); - // Confirm the number of cards on the desktop - let cardArkTsCount = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 getFormData data: ${JSON.stringify(data)}`); - expect(result !== null).assertTrue(); - cardArkTsCount = result.split(cardWidgetJS).length - 1; - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 cardArkTsCount:' + cardArkTsCount); - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog err is: ' + JSON.stringify(err)); - }); - await driver.delayMs(DELAYTIME01); - - // Long click the application - await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - let app = - await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), - MatchPattern.CONTAINS)); - // Get the text control border - let rect = await app.getBounds(); - // Calculate the height of the text control - let height = rect.bottom - rect.top; - // Get the center point of the text control - let point = await app.getBoundsCenter(); - await driver.longClick(point.x, point.y - height); - hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 long click app, coordinate:(${point.x},` + `${point.y - height})`); - await driver.delayMs(DELAYTIME01); - - // Add an ArkTs card to launcher - await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); - let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); - await serviceCard.click(); - hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 Start to fling cards)`); - await driver.delayMs(DELAYTIME02); - for (let i = 0; i < 4; i++) { - await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); - await driver.delayMs(DELAYTIME01); - } - // Click to add to desktop - await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 addCardToDesktop'); - await driver.delayMs(DELAYTIME02); - - // Verify that only one card has been added - let cardArkTsCountSecond = 0; - await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") - .then((data) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog data success'); - let result = JSON.stringify(data); - hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 getFormData data: ${JSON.stringify(data)}`); - cardArkTsCountSecond = result.split(cardWidgetJS).length; - }) - .catch((err: BusinessError) => { - hilog.error(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog err is: ' + JSON.stringify(err)); - }); - - // Assert an ArkTs card has been added - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 assert an ArkTs card has been added, ' + - 'cardArkTsCountSecond:' + cardArkTsCountSecond); - expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); - hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); - await driver.delayMs(DELAYTIME02); - done(); - }) - }) +/* + * Copyright (c) 2022-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, Driver, MatchPattern, ON } from '@kit.TestKit'; +import { beforeAll, describe, expect, it } from '@ohos/hypium'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG = '[Sample_ServiceCard_Test]'; +const DOMAIN = 0xF811; +const BUNDLE = 'ServiceCard_'; +const DELAYTIME01 = 1000; +const DELAYTIME02 = 2000; +const DELAYTIME03 = 3000; +let abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +let resourceManager = abilityDelegator.getAppContext().resourceManager; +let cardArkTsWidgetEventRouter = 'WidgetEventRouter'; +let cardWidgetUpdateRouter = 'WidgetUpdateRouter'; +let cardWidgetUpdateCallCard = 'WidgetUpdateCall'; +let cardWidgetEventCall = 'WidgetEventCall' +let cardUpdateByMessage = 'UpdateByMessage'; +let cardAttrAnimation = 'AttrAnimation'; +let cardCustomCanvasDrawing = 'CustomCanvasDrawing'; +let cardUpdateDuration = 'UpdateDuration'; +let cardScheduledUpdateTime = 'ScheduledUpdateTime'; +let cardNextRefreshTimeCard = 'NextRefreshTime'; +let cardWidgetImageUpdate = 'WidgetImageUpdate'; +let cardWidgetUpdateByStatus = 'WidgetUpdateByStatus'; +let cardWidgetProcessData = 'WidgetProcessData'; +let cardWidgetPersistentData = 'WidgetPersistentData'; +let cardWidgetJS = 'WidgetJS'; +let driver = Driver.create(); +// Sliding coordinate +const START_SLIDING_X = 700; +const FINISH_SLIDING_X = 50; +const SLIDING_COORDINATE_Y = 300; +// Add to desktop coordinate +const ADD_TO_DESKTOP_X = 300; +const ADD_TO_DESKTOP_Y = 1200; + +export default function formTest() { + describe('ActsFormTest', () => { + beforeAll(async () => { + // Exit the test interface to execute the test case + await driver.pressHome(); + await driver.delayMs(DELAYTIME01); + }) + + /* + * @tc.number: ServiceCard_ArkTS_001 + * @tc.name: Add WidgetEventRouter cards to desktop. + * @tc.desc: Add WidgetEventRouter cards to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 begin'); + await driver.delayMs(DELAYTIME01); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardArkTsWidgetEventRouter).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME02); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 2; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.add_to_desktop')), + MatchPattern.CONTAINS)); + let addCard = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.add_to_desktop')), + MatchPattern.CONTAINS)); + await addCard.click(); + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_001 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardArkTsWidgetEventRouter).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_001 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_001 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_002 + * @tc.name: Add cardWidgetUpdateRouter card to desktop. + * @tc.desc: Add cardWidgetUpdateRouter card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_002', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetUpdateRouter).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 12; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_002 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetUpdateRouter).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_002 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_002 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_003 + * @tc.name: Add UpdateByMessage card to desktop. + * @tc.desc: Add UpdateByMessage card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_003', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardUpdateByMessage).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 3; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_003 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardUpdateByMessage).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_003 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_003 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_004 + * @tc.name: Add CustomCanvasDrawing card to desktop. + * @tc.desc: Add CustomCanvasDrawing card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_004', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardCustomCanvasDrawing).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_004 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardCustomCanvasDrawing).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_004 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_004 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_005 + * @tc.name: Add Animation card to desktop. + * @tc.desc: Add Animation card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_005', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardAttrAnimation).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 addCardToDesktop'); + await driver.delayMs(2000); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_005 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardAttrAnimation).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_005 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_005 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_006 + * @tc.name: Add WidgetUpdateByStatus card to desktop. + * @tc.desc: Add WidgetUpdateByStatus card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_006', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetUpdateByStatus).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 7; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + /// Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_006 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetUpdateByStatus).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_006 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_006 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME01); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_007 + * @tc.name: Add WidgetProcessData card to desktop. + * @tc.desc: Add WidgetProcessData card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_007', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetProcessData).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 6; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_007 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetProcessData).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_007 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_007 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME01); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_008 + * @tc.name: Add UpdateDuration card to desktop. + * @tc.desc: Add UpdateDuration card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_008', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardUpdateDuration).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 8; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_008 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardUpdateDuration).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_008 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_008 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME01); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_009 + * @tc.name: Add ScheduledUpdateTime card to desktop. + * @tc.desc: Add ScheduledUpdateTime card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_009', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardScheduledUpdateTime).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 9; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_009 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardScheduledUpdateTime).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_009 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_009 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_010 + * @tc.name: Add NextRefreshTimeCard card to desktop. + * @tc.desc: Add NextRefreshTimeCard card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_010', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardNextRefreshTimeCard).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 10; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_010 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardNextRefreshTimeCard).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_010 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_010 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_011 + * @tc.name: Add WidgetImageUpdate card to desktop. + * @tc.desc: Add WidgetImageUpdate card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_011', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetImageUpdate).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 11; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_011 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetImageUpdate).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_011 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_011 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_012 + * @tc.name: Add WidgetEventCall card to desktop. + * @tc.desc: Add WidgetEventCall card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_012', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetEventCall).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 13; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_012 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetEventCall).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_012 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_012 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_013 + * @tc.name: Add WidgetUpdateCall card to desktop. + * @tc.desc: Add WidgetUpdateCall card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_013', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetUpdateCallCard).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + + for (let i = 0; i < 14; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_013 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetUpdateCallCard).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_013 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_013 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_ArkTS_014 + * @tc.name: Add WidgetPersistentData card to desktop. + * @tc.desc: Add WidgetPersistentData card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'ArkTS_014', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetPersistentData).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 5; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `ArkTS_014 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetPersistentData).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'ArkTS_014 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'ArkTS_014 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + + /* + * @tc.number: ServiceCard_JS_UI_001 + * @tc.name: Add WidgetJS card to desktop. + * @tc.desc: Add WidgetJS card to desktop. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level Level 1 + */ + it(BUNDLE + 'JS_UI_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 begin'); + await driver.delayMs(DELAYTIME03); + // Confirm the number of cards on the desktop + let cardArkTsCount = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 getFormData data: ${JSON.stringify(data)}`); + expect(result !== null).assertTrue(); + cardArkTsCount = result.split(cardWidgetJS).length - 1; + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 cardArkTsCount:' + cardArkTsCount); + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog err is: ' + JSON.stringify(err)); + }); + await driver.delayMs(DELAYTIME01); + + // Long click the application + await driver.assertComponentExist(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + let app = + await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.EntryAbility_label')), + MatchPattern.CONTAINS)); + // Get the text control border + let rect = await app.getBounds(); + // Calculate the height of the text control + let height = rect.bottom - rect.top; + // Get the center point of the text control + let point = await app.getBoundsCenter(); + await driver.longClick(point.x, point.y - height); + hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 long click app, coordinate:(${point.x},` + `${point.y - height})`); + await driver.delayMs(DELAYTIME01); + + // Add an ArkTs card to launcher + await driver.assertComponentExist(ON.text('服务卡片', MatchPattern.CONTAINS)); + let serviceCard = await driver.findComponent(ON.text('服务卡片', MatchPattern.CONTAINS)); + await serviceCard.click(); + hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 Start to fling cards)`); + await driver.delayMs(DELAYTIME02); + for (let i = 0; i < 4; i++) { + await driver.swipe(START_SLIDING_X, SLIDING_COORDINATE_Y, FINISH_SLIDING_X, SLIDING_COORDINATE_Y, DELAYTIME03); + await driver.delayMs(DELAYTIME01); + } + // Click to add to desktop + await driver.click(ADD_TO_DESKTOP_X, ADD_TO_DESKTOP_Y); + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 addCardToDesktop'); + await driver.delayMs(DELAYTIME02); + + // Verify that only one card has been added + let cardArkTsCountSecond = 0; + await abilityDelegator.executeShellCommand("hidumper -s FormMgr -a '-n com.samples.stageservicewidgetcards'") + .then((data) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog data success'); + let result = JSON.stringify(data); + hilog.info(DOMAIN, TAG, BUNDLE + `JS_UI_001 getFormData data: ${JSON.stringify(data)}`); + cardArkTsCountSecond = result.split(cardWidgetJS).length; + }) + .catch((err: BusinessError) => { + hilog.error(DOMAIN, TAG, BUNDLE + 'JS_UI_001 hilog err is: ' + JSON.stringify(err)); + }); + + // Assert an ArkTs card has been added + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 assert an ArkTs card has been added, ' + + 'cardArkTsCountSecond:' + cardArkTsCountSecond); + expect(cardArkTsCount + 1).assertEqual(cardArkTsCountSecond); + hilog.info(DOMAIN, TAG, BUNDLE + 'JS_UI_001 ' + (cardArkTsCountSecond - cardArkTsCount) + ' card has been added'); + await driver.delayMs(DELAYTIME02); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/module.json5 b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/module.json5 index 2ef997b8574dd39472a480f0651741eb235834f8..7090c9c82dc10724ecfddb2de41576be7033bed9 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2022-2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2022-2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/hvigor/hvigor-config.json5 index 5046d5d3d2ca9af5c6e4b937bc58d432f47a4d66..ba6fd680958b77ed61f91defddecc741e5ce022a 100644 --- a/code/DocsSample/ApplicationModels/StageServiceWidgetCards/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/StageServiceWidgetCards/hvigor/hvigor-config.json5 @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2024-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": { - } +/* + * Copyright (c) 2024-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": { + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/app.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/app.json5 index 524fea75c60eb5e01ef46ae1d6d5d13fffe2c5ab..58e0e3fe0683820b38c425fdbfd4b975b779ff58 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/app.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2022-2023 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.widgetupdatebyproxy", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2022-2023 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.widgetupdatebyproxy", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/resources/base/element/string.json b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/resources/base/element/string.json index bdc95ce2a4822717e90c875e40f36f4c85ad6d5e..c01da4826f8ff83defeb7adc057ebd653bceded3 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "WidgetUpdateByProxy" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "WidgetUpdateByProxy" + } + ] +} diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/build-profile.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/build-profile.json5 index 4c924ac9356707b9f436dd7d2627c1044c02976b..ce622b89055839fc146bb4cc58d1ff2a1fde7d98 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/build-profile.json5 @@ -1,46 +1,46 @@ -/* - * Copyright (c) 2022-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": 14, - "targetSdkVersion": 14, - "compatibleSdkVersion": 14, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [ - - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2022-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": 14, + "targetSdkVersion": 14, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [ + + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/build-profile.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/build-profile.json5 index 86224cda6f74439561b4e5f3b822bc27c7c69579..fde30086fc0aa158bf024fdc94b29be6a50442c6 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/build-profile.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/build-profile.json5 @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2022-2023 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', - "showInServiceCenter": true, - "buildOption": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2022-2023 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', + "showInServiceCenter": true, + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/oh-package.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/oh-package.json5 index 220a000b93e49bc592373389f02b03bb17957353..08ac4501e6cd32341d549be8b4b778eb913467c0 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/oh-package.json5 @@ -1,25 +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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts index d7c9cb368adcb7afa058958b948d8b81fdd4206e..903e3e028c39af9d78fc38825c9305f43b5929ba 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts @@ -1,92 +1,92 @@ -/* - * Copyright (c) 2022-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 type dataSharePredicates from '@ohos.data.dataSharePredicates'; -import Extension from '@ohos.application.DataShareExtensionAbility'; -import hilog from '@ohos.hilog'; -import rdb from '@ohos.data.relationalStore'; -import type Want from '@ohos.app.ability.Want'; -import type { AsyncCallback } from '@ohos.base'; -import type { ValuesBucket } from '@ohos.data.ValuesBucket'; - -const DB_NAME = 'DB00.db'; -const TBL_NAME = 'TBL00'; -const DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS ' + TBL_NAME + - ' (cityId INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT)'; - -let rdbStore; -let result; -const TAG: string = 'DataShareExtAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class DataShareExtAbility extends Extension { - private rdbStore_; - - // 重写onCreate接口 - async onCreate(want: Want, callback: AsyncCallback): Promise { - result = this.context.cacheDir + '/datashare.txt'; - hilog.info(DOMAIN_NUMBER, TAG, `result : ${result}`); - // 业务实现使用RDB - rdb.getRdbStore(this.context, { - name: DB_NAME, - securityLevel: rdb.SecurityLevel.S1 - }, function (err, data) { - hilog.info(DOMAIN_NUMBER, TAG, `getRdbStore done, data : ${data}`); - rdbStore = data; - rdbStore.executeSql(DDL_TBL_CREATE, [], (err) => { - hilog.info(DOMAIN_NUMBER, TAG, `DataShareExtAbility onCreate, executeSql done err: ${JSON.stringify(err)}`); - }); - }); - } - - async insert(uri: string, valueBucket: ValuesBucket, callback: Function): Promise { - if (valueBucket === null) { - hilog.error(DOMAIN_NUMBER, TAG, 'invalid valueBuckets'); - return; - } else { - hilog.info(DOMAIN_NUMBER, TAG, `valueBucket, ${JSON.stringify(valueBucket)}`); - } - - rdbStore.insert(TBL_NAME, valueBucket, (err, ret) => { - hilog.info(DOMAIN_NUMBER, TAG, `callback ret: ${ret}`, JSON.stringify(err)); - if (callback !== undefined) { - callback(err, ret); - } - }); - } - - async update(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, - callback: Function): Promise { - hilog.info(DOMAIN_NUMBER, TAG, '[ttt] [DataShareTest] <> [update] enter'); - if (predicates === null || predicates === undefined) { - hilog.info(DOMAIN_NUMBER, TAG, '[ttt] [DataShareTest] <> [update] invalid predicates'); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, `[update] values = ${valueBucket}`); - hilog.info(DOMAIN_NUMBER, TAG, `[update] [update] predicates = ${predicates}`); - try { - await rdbStore.update(TBL_NAME, valueBucket, predicates, function (err, ret) { - hilog.info(DOMAIN_NUMBER, TAG, `[update] callback ret: ${ret}`); - hilog.info(DOMAIN_NUMBER, TAG, `[update] callback err: ${err}`); - if (callback !== undefined) { - callback(err, ret); - } - }); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, `[update] error: ${err}`); - }; - hilog.info(DOMAIN_NUMBER, TAG, '[update] leave'); - } +/* + * Copyright (c) 2022-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 type dataSharePredicates from '@ohos.data.dataSharePredicates'; +import Extension from '@ohos.application.DataShareExtensionAbility'; +import hilog from '@ohos.hilog'; +import rdb from '@ohos.data.relationalStore'; +import type Want from '@ohos.app.ability.Want'; +import type { AsyncCallback } from '@ohos.base'; +import type { ValuesBucket } from '@ohos.data.ValuesBucket'; + +const DB_NAME = 'DB00.db'; +const TBL_NAME = 'TBL00'; +const DDL_TBL_CREATE = 'CREATE TABLE IF NOT EXISTS ' + TBL_NAME + + ' (cityId INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT)'; + +let rdbStore; +let result; +const TAG: string = 'DataShareExtAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class DataShareExtAbility extends Extension { + private rdbStore_; + + // 重写onCreate接口 + async onCreate(want: Want, callback: AsyncCallback): Promise { + result = this.context.cacheDir + '/datashare.txt'; + hilog.info(DOMAIN_NUMBER, TAG, `result : ${result}`); + // 业务实现使用RDB + rdb.getRdbStore(this.context, { + name: DB_NAME, + securityLevel: rdb.SecurityLevel.S1 + }, function (err, data) { + hilog.info(DOMAIN_NUMBER, TAG, `getRdbStore done, data : ${data}`); + rdbStore = data; + rdbStore.executeSql(DDL_TBL_CREATE, [], (err) => { + hilog.info(DOMAIN_NUMBER, TAG, `DataShareExtAbility onCreate, executeSql done err: ${JSON.stringify(err)}`); + }); + }); + } + + async insert(uri: string, valueBucket: ValuesBucket, callback: Function): Promise { + if (valueBucket === null) { + hilog.error(DOMAIN_NUMBER, TAG, 'invalid valueBuckets'); + return; + } else { + hilog.info(DOMAIN_NUMBER, TAG, `valueBucket, ${JSON.stringify(valueBucket)}`); + } + + rdbStore.insert(TBL_NAME, valueBucket, (err, ret) => { + hilog.info(DOMAIN_NUMBER, TAG, `callback ret: ${ret}`, JSON.stringify(err)); + if (callback !== undefined) { + callback(err, ret); + } + }); + } + + async update(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, + callback: Function): Promise { + hilog.info(DOMAIN_NUMBER, TAG, '[ttt] [DataShareTest] <> [update] enter'); + if (predicates === null || predicates === undefined) { + hilog.info(DOMAIN_NUMBER, TAG, '[ttt] [DataShareTest] <> [update] invalid predicates'); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, `[update] values = ${valueBucket}`); + hilog.info(DOMAIN_NUMBER, TAG, `[update] [update] predicates = ${predicates}`); + try { + await rdbStore.update(TBL_NAME, valueBucket, predicates, function (err, ret) { + hilog.info(DOMAIN_NUMBER, TAG, `[update] callback ret: ${ret}`); + hilog.info(DOMAIN_NUMBER, TAG, `[update] callback err: ${err}`); + if (callback !== undefined) { + callback(err, ret); + } + }); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, `[update] error: ${err}`); + }; + hilog.info(DOMAIN_NUMBER, TAG, '[update] leave'); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/entryability/EntryAbility.ts index 49d5e0081866869f0a332154a46df117646e9666..588996f655b002c95ed9a995c1ad95748adab65c 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2022-2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import type Want from '@ohos.app.ability.Want'; -import type window from '@ohos.window'; - -const TAG: string = 'EntryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } +/* + * Copyright (c) 2022-2023 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 type AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import type Want from '@ohos.app.ability.Want'; +import type window from '@ohos.window'; + +const TAG: string = 'EntryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/module.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/module.json5 index ee02e886d2118b40b9b809e817f93b03dd857efa..676d3ccf415026dd1ddd57f771a1424ca899fd62 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/module.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/module.json5 @@ -1,112 +1,112 @@ -/* - * Copyright (c) 2022-2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "DataShareExtAbility", - "srcEntry": "./ets/DataShareExtAbility/DataShareExtAbility.ts", - "icon": "$media:icon", - "description": "$string:description_datashareextability", - "type": "dataShare", - "uri": "datashare://com.samples.widgetupdatebyproxy.DataShare", - "exported": true, - "metadata": [ - { - "name": "ohos.extension.dataShare", - "resource": "$profile:data_share_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO", - }, - { - "name": "ohos.permission.KEEP_BACKGROUND_RUNNING" - }, - { - "name": "ohos.permission.START_INVISIBLE_ABILITY" - }, - { - "name": "ohos.permission.INTERNET", - "usedScene": { - "abilities": [ - "WgtImgUpdateEntryFormAbility" - ], - "when": "inuse", - } - } - ], - "proxyData": [ - { - "uri": "datashareproxy://com.samples.widgetupdatebyproxy/test", - "requiredReadPermission": "ohos.permission.GET_BUNDLE_INFO", - "requiredWritePermission": "ohos.permission.KEEP_BACKGROUND_RUNNING", - "metadata": { - "name": "dataProperties", - "resource": "$profile:my_config" - } - }, - { - "uri": "datashareproxy://com.samples.widgetupdatebyproxy/weather", - "requiredReadPermission": "ohos.permission.GET_BUNDLE_INFO", - "requiredWritePermission": "ohos.permission.KEEP_BACKGROUND_RUNNING", - "metadata": { - "name": "dataProperties", - "resource": "$profile:my_config" - } - } - ] - } +/* + * Copyright (c) 2022-2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "DataShareExtAbility", + "srcEntry": "./ets/DataShareExtAbility/DataShareExtAbility.ts", + "icon": "$media:icon", + "description": "$string:description_datashareextability", + "type": "dataShare", + "uri": "datashare://com.samples.widgetupdatebyproxy.DataShare", + "exported": true, + "metadata": [ + { + "name": "ohos.extension.dataShare", + "resource": "$profile:data_share_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND", + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO", + }, + { + "name": "ohos.permission.KEEP_BACKGROUND_RUNNING" + }, + { + "name": "ohos.permission.START_INVISIBLE_ABILITY" + }, + { + "name": "ohos.permission.INTERNET", + "usedScene": { + "abilities": [ + "WgtImgUpdateEntryFormAbility" + ], + "when": "inuse", + } + } + ], + "proxyData": [ + { + "uri": "datashareproxy://com.samples.widgetupdatebyproxy/test", + "requiredReadPermission": "ohos.permission.GET_BUNDLE_INFO", + "requiredWritePermission": "ohos.permission.KEEP_BACKGROUND_RUNNING", + "metadata": { + "name": "dataProperties", + "resource": "$profile:my_config" + } + }, + { + "uri": "datashareproxy://com.samples.widgetupdatebyproxy/weather", + "requiredReadPermission": "ohos.permission.GET_BUNDLE_INFO", + "requiredWritePermission": "ohos.permission.KEEP_BACKGROUND_RUNNING", + "metadata": { + "name": "dataProperties", + "resource": "$profile:my_config" + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/color.json b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/color.json index afc173f8d5dcad83cc9d106e56fae9b79f74a29e..074928deab1befb3ee725e6cfb986c10fa3b67b4 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/color.json @@ -1,12 +1,12 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "text_font_color", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "text_font_color", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/float.json b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/float.json index edb7816076bba14bb708f41ea9c255af12f22fdf..d50ddbfab2063f1a6236e1444b0f7d38c3389a98 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/float.json +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/element/float.json @@ -1,28 +1,28 @@ -{ - "float": [ - { - "name": "title_immersive_font_size", - "value": "19fp" - }, - { - "name": "detail_immersive_font_size", - "value": "16fp" - }, - { - "name": "detail_immersive_margin_top", - "value": "6vp" - }, - { - "name": "detail_immersive_opacity", - "value": "0.66" - }, - { - "name": "column_padding", - "value": "12vp" - }, - { - "name": "font_size", - "value": "16fp" - } - ] +{ + "float": [ + { + "name": "title_immersive_font_size", + "value": "19fp" + }, + { + "name": "detail_immersive_font_size", + "value": "16fp" + }, + { + "name": "detail_immersive_margin_top", + "value": "6vp" + }, + { + "name": "detail_immersive_opacity", + "value": "0.66" + }, + { + "name": "column_padding", + "value": "12vp" + }, + { + "name": "font_size", + "value": "16fp" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/data_share_config.json b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/data_share_config.json index 6ed549c101e513e0749748ff932b87d2d0057c75..d014aa3fcd3ab58b84a456ab5a8c059176f61650 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/data_share_config.json +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/data_share_config.json @@ -1,16 +1,16 @@ -{ - "tableConfig": [ - { - "uri": "*", - "crossUserMode": 1 - }, - { - "uri": "datashareproxy://com.samples.widgetupdatebyproxy/entry/DB00", - "crossUserMode": 1 - }, - { - "uri": "datashareproxy://com.samples.widgetupdatebyproxy/entry/DB00/TBL00", - "crossUserMode": 2 - } - ] +{ + "tableConfig": [ + { + "uri": "*", + "crossUserMode": 1 + }, + { + "uri": "datashareproxy://com.samples.widgetupdatebyproxy/entry/DB00", + "crossUserMode": 1 + }, + { + "uri": "datashareproxy://com.samples.widgetupdatebyproxy/entry/DB00/TBL00", + "crossUserMode": 2 + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/my_config.json b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/my_config.json index ff029cea6555492b19e72ee07fbcfb8f259ef7a2..c48ee18052ba0d635e8129e8057371d5bd93c57f 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/my_config.json +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/main/resources/base/profile/my_config.json @@ -1,5 +1,5 @@ -{ - "path": "DB00/TBL00", - "type": "rdb", - "scope": "application" +{ + "path": "DB00/TBL00", + "type": "rdb", + "scope": "application" } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/ohosTest/module.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/ohosTest/module.json5 index c3051ee7a32ac8c040b8c035f14228a2e0fda303..075f09072e76717b6ab1ce434ed05a5d5254c8a0 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2022-2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2022-2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/hvigor/hvigor-config.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/hvigor/hvigor-config.json5 index 5046d5d3d2ca9af5c6e4b937bc58d432f47a4d66..ba6fd680958b77ed61f91defddecc741e5ce022a 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/hvigor/hvigor-config.json5 @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2024-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": { - } +/* + * Copyright (c) 2024-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": { + } } \ No newline at end of file diff --git a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/oh-package.json5 b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/oh-package.json5 index d88534a4121bb31db91aa697726ef7d48c57c581..63689954a1413817392bc86866e43199243a2c99 100644 --- a/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/oh-package.json5 +++ b/code/DocsSample/ApplicationModels/WidgetUpdateByProxy/oh-package.json5 @@ -1,13 +1,13 @@ -{ - "modelVersion": "5.0.0", - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "widgetupdatebyproxy", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} +{ + "modelVersion": "5.0.0", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "widgetupdatebyproxy", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..78ddc4311e7fc17f22fb7af93ab9ee8d2725fdb6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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.dynamicimport", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5b7aa338c6a82b01d37212e7d4c7cc9b1bc7de39 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DynamicImport" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/README.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c84429cdb583832a778327a75a0b9924b2414b0c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/README.md @@ -0,0 +1,111 @@ +# ArkTS动态加载 + +### 介绍 + +动态import支持条件延迟加载,支持部分反射功能,可以提升页面的加载速度;动态import支持加载HSP模块/HAR模块/OHPM包/Native库等,并且HAR模块间只有变量动态import时还可以进行模块解耦 + +本示例主要展示了动态加载的业务拓展场景介绍、动态加载常量表达式、动态加载变量表达式以及HAR模块间动态加载依赖解耦这些场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [动态加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-dynamic-import.md) + +### 效果预览 + +| 执行结果图 | +| ------------------------------------------------------------ | +| | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,分别点击ListItem组件可以执行对应文本内容的操作,然后在控制台中打印出对应日志。 +3. 运行测试用例DynamicImport.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 动态加载示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── DynamicImport.test.ets // 自动化测试代码 + │ │ └── List.test.ets + har1 // har1模块函数实现 + ├── src + │ ├── main + │ │ ├── ets + │ │ │ ├── utils + │ │ │ │ └── Calc.ets + │ │ │ └── components + │ │ │ │ └── MainPage.ets + har2 // har1模块函数实现 + ├── src + │ ├── main + │ │ ├── ets + │ │ │ ├── utils + │ │ │ │ └── Calc.ets + │ │ │ └── components + │ │ │ │ └── MainPage.ets + ├── index.ets + harlibrary // harlibrary模块函数实现 + ├── src + │ ├── main + │ │ ├── ets + │ │ │ ├── utils + │ │ │ │ └── Calc.ets + │ │ │ └── components + │ │ │ │ └── MainPage.ets + ├── index.ets + myHar // myHar模块函数实现 + ├── src + │ ├── main + │ │ ├── ets + │ │ │ └── components + │ │ │ │ └── MainPage.ets + ├── index.ets + myHsp // myHsp模块函数实现 + ├── src + │ ├── main + │ │ ├── ets + │ │ │ ├── pages + │ │ │ │ └── Index.ets + │ │ │ └── utils + │ │ │ │ └── Calc.ets + ├── index.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..feb4b2f6e8078edd981b74465d4cb40b9b4af36c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/build-profile.json5 @@ -0,0 +1,86 @@ +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "harlibrary", + "srcPath": "./harlibrary", + }, + { + "name": "myHar", + "srcPath": "./myHar", + }, + { + "name": "myHsp", + "srcPath": "./myHsp", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "har1", + "srcPath": "./har1", + }, + { + "name": "har2", + "srcPath": "./har2", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/code-linter.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6dae4488bdd09a58c021faf36a999eabae10c41c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 @@ -0,0 +1,81 @@ +/* + * 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": { + "arkOptions": { + "runtimeOnly": { + "packages": [ + "myhar", + // 仅用于使用变量动态import其他模块名场景,静态import或常量动态import无需配置。 + "myhsp", + // 仅用于使用变量动态import其他模块名场景,静态import或常量动态import无需配置。 + "@ohos/hypium", + "@ohos/crypto-js", + "libentry.so", + "har1", + "har2" + ], + // 配置本模块变量动态import其他模块名,要求与dependencies中配置的名字一致。 + "sources": [ + // 仅用于使用变量动态import模块自己单文件场景,静态import或常量动态import无需配置。 + "./src/main/ets/utils/Calc.ets", + "./src/main/ets/Calc.ets" + ] + // 配置本模块变量动态import自己的文件路径,路径相对于当前build-profile.json5文件。 + } + }, + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + }, + }, + "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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..76e9a20fd2a10f107faee8da40268086f038e4d0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/oh-package.json5 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "harlibrary": "file:../harlibrary", + "myhar": "file:../myHar", + //HAP常量动态import HAR模块名 HAP常量动态import HAR模块文件路径 + "myhsp": "file:../myHsp", + //HAP常量动态import HSP模块名 HAP常量动态import HSP模块名文件路径 + "@ohos/crypto-js": "2.0.3-rc.0", + //HAP常量动态import远程HAR模块名 + "@ohos/hypium": "1.0.19", + //HAP常量动态import ohpm包 + "libentry.so": "file:./src/main/cpp/types/libentry", + //HAP常量动态import自己的Native库 + "har1": "file:../har1", + "har2": "file:../har2" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9042897daf3d2e1d172d79cd9fbd41c19dc46f5e --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(DynamicImport) + +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) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b0593c2c04504a599cdf93d78cbeb66e10371e1 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/napi_init.cpp @@ -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. + */ + +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + double value0; + napi_get_value_double(env, args[0], &value0); + double value1; + napi_get_value_double(env, args[1], &value1); + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"add", nullptr, Add, 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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..914e7b4167fc19f23540e8e90e8b71100310fb00 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start hap_const_dynamic_import_native] +export const add: (a: number, b: number) => number; +// [End hap_const_dynamic_import_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2826cc7d6bd199c1008bb51d898dffa922201e6c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9a691411d51ae4a2d1333912efbb8d843b89ff8 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start hap_const_dynamic_import_add] +export function add(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); + return c; +} +// [End hap_const_dynamic_import_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Calc.ets new file mode 100644 index 0000000000000000000000000000000000000000..3cba60bf37e6546a4ebd30d9893163f8a53db7cd --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Calc.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. + */ + +export function add(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); + return c; +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/utils/Calc.ets new file mode 100644 index 0000000000000000000000000000000000000000..3cba60bf37e6546a4ebd30d9893163f8a53db7cd --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/utils/Calc.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. + */ + +export function add(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); + return c; +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/color.json similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/color.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/color.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/DynamicImport.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/DynamicImport.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/DynamicImport.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/DynamicImport.test.ets index bb30af241ad49fc2635c248e2eaac1600491524b..bc0df7fe9a942ad15f8eec24ea33a53cb6f29ef2 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/DynamicImport.test.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/DynamicImport.test.ets @@ -1,228 +1,228 @@ -/* - * 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'; - -export default function dynamicImportTest() { - describe('dynamicImportTest', () => { - - it('testDynamicImport001', 0, async () => { - console.info('uitest: testDynamicImport001 begin'); - let har: ESObject = await import('harlibrary'); - expect(har.Calc.staticAdd(8, 9)).assertEqual(17); - let calc: ESObject = new har.Calc(); - expect(calc.instanceAdd(10, 11)).assertEqual(21); - expect(har.addHarlibrary(6, 7)).assertEqual(13); - - let className = 'Calc'; - let methodName = 'instanceAdd'; - let staticMethod = 'staticAdd'; - let functionName = 'addHarlibrary'; - expect(har[className][staticMethod](12, 13)).assertEqual(25); - let calc1: ESObject = new har[className](); - expect(calc1[methodName](14, 15)).assertEqual(29); - expect(har[functionName](16, 17)).assertEqual(33); - console.info('uitest: testDynamicImport001 end'); - }) - - it('testDynamicImport002', 0, async () => { - console.info('uitest: testDynamicImport002 begin'); - let har: ESObject = await import('myhar'); - expect(har.add(2, 3)).assertEqual(5); - console.info('uitest: testDynamicImport002 end'); - }) - - it('testDynamicImport003', 0, async () => { - console.info('uitest: testDynamicImport003 begin'); - let har: ESObject = await import('myhar/Index'); - expect(har.add(2, 3)).assertEqual(5); - console.info('uitest: testDynamicImport003 end'); - }) - - it('testDynamicImport004', 0, async () => { - console.info('uitest: testDynamicImport004 begin'); - let hsp: ESObject = await import('myhsp'); - expect(hsp.add(2, 3)).assertEqual(5); - console.info('uitest: testDynamicImport004 end'); - }) - - it('testDynamicImport005', 0, async () => { - console.info('uitest: testDynamicImport005 begin'); - let hsp: ESObject = await import('myhsp/Index'); - expect(hsp.add(2, 3)).assertEqual(5); - console.info('uitest: testDynamicImport005 end'); - }) - - it('testDynamicImport006', 0, async () => { - console.info('uitest: testDynamicImport006 begin'); - let har: ESObject = await import('@ohos/crypto-js'); - expect(har.CryptoJS.src).assertUndefined(); - console.info('uitest: testDynamicImport006 end'); - }) - - it('testDynamicImport007', 0, async () => { - console.info('uitest: testDynamicImport007 begin'); - let ohpm: ESObject = await import('@ohos/hypium'); - expect(ohpm.TestType.FUNCTION).assertEqual(1); - console.info('uitest: testDynamicImport007 end'); - }) - - it('testDynamicImport008', 0, async () => { - console.info('uitest: testDynamicImport008 begin'); - let singleFile: ESObject = await import('../../../../src/main/ets/Calc'); - expect(singleFile.add(3, 5)).assertEqual(8); - console.info('uitest: testDynamicImport008 end'); - }) - - it('testDynamicImport009', 0, async () => { - console.info('uitest: testDynamicImport009 begin'); - let native: ESObject = await import('libentry.so'); - expect(native.default.add(2, 3)).assertEqual(5); - console.info('uitest: testDynamicImport009 end'); - }) - - it('testDynamicImport010', 0, async () => { - console.info('uitest: testDynamicImport010 begin'); - let systemApp: ESObject = await import('@system.app'); - expect(systemApp.default.getInfo()).assertNull(); - console.info('uitest: testDynamicImport010 end'); - }) - - it('testDynamicImport011', 0, async () => { - console.info('uitest: testDynamicImport011 begin'); - let curves: ESObject = await import('@ohos.curves'); - expect(curves.default.springMotion(0.555, 0.75, 0.001).interpolate(1)).assertEqual(0); - console.info('uitest: testDynamicImport011 end'); - }) - - it('testDynamicImport012', 0, async () => { - console.info('uitest: testDynamicImport012 begin'); - let matrix4: ESObject = await import('@ohos.matrix4'); - expect(matrix4.default.identity().transformPoint([1, 2])[0]).assertEqual(1); - console.info('uitest: testDynamicImport012 end'); - }) - - it('testDynamicImport013', 0, async () => { - console.info('uitest: testDynamicImport013 begin'); - let hilog: ESObject = await import('@ohos.hilog'); - expect(hilog.default.LogLevel.DEBUG).assertEqual(3); - console.info('uitest: testDynamicImport013 end'); - }) - - it('testDynamicImport014', 0, async () => { - console.info('uitest: testDynamicImport014 begin'); - let harName = 'myhar'; - let har: ESObject = await import(harName); - expect(har.add(3, 5)).assertEqual(8); - console.info('uitest: testDynamicImport014 end'); - }) - - it('testDynamicImport015', 0, async () => { - console.info('uitest: testDynamicImport015 begin'); - let filePath = '../../../main/ets/utils/Calc'; - let file: ESObject = await import(filePath); - expect(file.add(3, 5)).assertEqual(8); - console.info('uitest: testDynamicImport015 end'); - }) - - it('testDynamicImport016', 0, async () => { - console.info('uitest: testDynamicImport016 begin'); - let harPackageName = 'myhar'; - let har: ESObject = await import(harPackageName); - expect(har.add(3, 5)).assertEqual(8); - console.info('uitest: testDynamicImport016 end'); - }) - - it('testDynamicImport017', 0, async () => { - console.info('uitest: testDynamicImport017 begin'); - let hspPackageName = 'myhsp'; - let hsp: ESObject = await import(hspPackageName); - expect(hsp.add(3, 5)).assertEqual(8); - console.info('uitest: testDynamicImport017 end'); - }) - - it('testDynamicImport018', 0, async () => { - console.info('uitest: testDynamicImport018 begin'); - let remoteHarPackageName = '@ohos/crypto-js'; - let har: ESObject = await import(remoteHarPackageName); - expect(har.CryptoJS.src).assertUndefined(); - console.info('uitest: testDynamicImport018 end'); - }) - - it('testDynamicImport019', 0, async () => { - console.info('uitest: testDynamicImport019 begin'); - let ohpmPackageName = '@ohos/hypium'; - let ohpm: ESObject = await import(ohpmPackageName); - expect(ohpm.TestType.FUNCTION).assertEqual(1); - console.info('uitest: testDynamicImport019 end'); - }) - - it('testDynamicImport020', 0, async () => { - console.info('uitest: testDynamicImport020 begin'); - let calcFilePath = '../../../../src/main/ets/Calc'; - let singleFile: ESObject = await import(calcFilePath); - expect(singleFile.add(3, 5)).assertEqual(8); - console.info('uitest: testDynamicImport020 end'); - }) - - it('testDynamicImport021', 0, async () => { - console.info('uitest: testDynamicImport021 begin'); - let soName = 'libentry.so'; - let native: ESObject = await import(soName); - expect(native.default.add(2, 3)).assertEqual(5); - console.info('uitest: testDynamicImport021 end'); - }) - - it('testDynamicImport022', 0, async () => { - console.info('uitest: testDynamicImport022 begin'); - let packageName = '@system.app'; - let systemApp: ESObject = await import(packageName); - expect(systemApp.default.getInfo()).assertNull(); - console.info('uitest: testDynamicImport022 end'); - }) - - it('testDynamicImport023', 0, async () => { - console.info('uitest: testDynamicImport023 begin'); - let packageName = '@ohos.curves'; - let curves: ESObject = await import(packageName); - expect(curves.default.springMotion(0.555, 0.75, 0.001).interpolate(1)).assertEqual(0); - console.info('uitest: testDynamicImport023 end'); - }) - - it('testDynamicImport024', 0, async () => { - console.info('uitest: testDynamicImport024 begin'); - let packageName = '@ohos.matrix4'; - let matrix4: ESObject = await import(packageName); - expect(matrix4.default.identity().transformPoint([1, 2])[0]).assertEqual(1); - console.info('uitest: testDynamicImport024 end'); - }) - - it('testDynamicImport025', 0, async () => { - console.info('uitest: testDynamicImport025 begin'); - let packageName = '@ohos.hilog'; - let hilog: ESObject = await import(packageName); - expect(hilog.default.LogLevel.DEBUG).assertEqual(3); - console.info('uitest: testDynamicImport025 end'); - }) - - it('testDynamicImport026', 0, async () => { - console.info('uitest: testDynamicImport026 begin'); - let harName = 'har1'; - let har: ESObject = await import(harName); - expect(har.addHar1(4, 5)).assertEqual(9); - console.info('uitest: testDynamicImport026 end'); - }) - }) +/* + * 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'; + +export default function dynamicImportTest() { + describe('dynamicImportTest', () => { + + it('testDynamicImport001', 0, async () => { + console.info('uitest: testDynamicImport001 begin'); + let har: ESObject = await import('harlibrary'); + expect(har.Calc.staticAdd(8, 9)).assertEqual(17); + let calc: ESObject = new har.Calc(); + expect(calc.instanceAdd(10, 11)).assertEqual(21); + expect(har.addHarlibrary(6, 7)).assertEqual(13); + + let className = 'Calc'; + let methodName = 'instanceAdd'; + let staticMethod = 'staticAdd'; + let functionName = 'addHarlibrary'; + expect(har[className][staticMethod](12, 13)).assertEqual(25); + let calc1: ESObject = new har[className](); + expect(calc1[methodName](14, 15)).assertEqual(29); + expect(har[functionName](16, 17)).assertEqual(33); + console.info('uitest: testDynamicImport001 end'); + }) + + it('testDynamicImport002', 0, async () => { + console.info('uitest: testDynamicImport002 begin'); + let har: ESObject = await import('myhar'); + expect(har.add(2, 3)).assertEqual(5); + console.info('uitest: testDynamicImport002 end'); + }) + + it('testDynamicImport003', 0, async () => { + console.info('uitest: testDynamicImport003 begin'); + let har: ESObject = await import('myhar/Index'); + expect(har.add(2, 3)).assertEqual(5); + console.info('uitest: testDynamicImport003 end'); + }) + + it('testDynamicImport004', 0, async () => { + console.info('uitest: testDynamicImport004 begin'); + let hsp: ESObject = await import('myhsp'); + expect(hsp.add(2, 3)).assertEqual(5); + console.info('uitest: testDynamicImport004 end'); + }) + + it('testDynamicImport005', 0, async () => { + console.info('uitest: testDynamicImport005 begin'); + let hsp: ESObject = await import('myhsp/Index'); + expect(hsp.add(2, 3)).assertEqual(5); + console.info('uitest: testDynamicImport005 end'); + }) + + it('testDynamicImport006', 0, async () => { + console.info('uitest: testDynamicImport006 begin'); + let har: ESObject = await import('@ohos/crypto-js'); + expect(har.CryptoJS.src).assertUndefined(); + console.info('uitest: testDynamicImport006 end'); + }) + + it('testDynamicImport007', 0, async () => { + console.info('uitest: testDynamicImport007 begin'); + let ohpm: ESObject = await import('@ohos/hypium'); + expect(ohpm.TestType.FUNCTION).assertEqual(1); + console.info('uitest: testDynamicImport007 end'); + }) + + it('testDynamicImport008', 0, async () => { + console.info('uitest: testDynamicImport008 begin'); + let singleFile: ESObject = await import('../../../../src/main/ets/Calc'); + expect(singleFile.add(3, 5)).assertEqual(8); + console.info('uitest: testDynamicImport008 end'); + }) + + it('testDynamicImport009', 0, async () => { + console.info('uitest: testDynamicImport009 begin'); + let native: ESObject = await import('libentry.so'); + expect(native.default.add(2, 3)).assertEqual(5); + console.info('uitest: testDynamicImport009 end'); + }) + + it('testDynamicImport010', 0, async () => { + console.info('uitest: testDynamicImport010 begin'); + let systemApp: ESObject = await import('@system.app'); + expect(systemApp.default.getInfo()).assertNull(); + console.info('uitest: testDynamicImport010 end'); + }) + + it('testDynamicImport011', 0, async () => { + console.info('uitest: testDynamicImport011 begin'); + let curves: ESObject = await import('@ohos.curves'); + expect(curves.default.springMotion(0.555, 0.75, 0.001).interpolate(1)).assertEqual(0); + console.info('uitest: testDynamicImport011 end'); + }) + + it('testDynamicImport012', 0, async () => { + console.info('uitest: testDynamicImport012 begin'); + let matrix4: ESObject = await import('@ohos.matrix4'); + expect(matrix4.default.identity().transformPoint([1, 2])[0]).assertEqual(1); + console.info('uitest: testDynamicImport012 end'); + }) + + it('testDynamicImport013', 0, async () => { + console.info('uitest: testDynamicImport013 begin'); + let hilog: ESObject = await import('@ohos.hilog'); + expect(hilog.default.LogLevel.DEBUG).assertEqual(3); + console.info('uitest: testDynamicImport013 end'); + }) + + it('testDynamicImport014', 0, async () => { + console.info('uitest: testDynamicImport014 begin'); + let harName = 'myhar'; + let har: ESObject = await import(harName); + expect(har.add(3, 5)).assertEqual(8); + console.info('uitest: testDynamicImport014 end'); + }) + + it('testDynamicImport015', 0, async () => { + console.info('uitest: testDynamicImport015 begin'); + let filePath = '../../../main/ets/utils/Calc'; + let file: ESObject = await import(filePath); + expect(file.add(3, 5)).assertEqual(8); + console.info('uitest: testDynamicImport015 end'); + }) + + it('testDynamicImport016', 0, async () => { + console.info('uitest: testDynamicImport016 begin'); + let harPackageName = 'myhar'; + let har: ESObject = await import(harPackageName); + expect(har.add(3, 5)).assertEqual(8); + console.info('uitest: testDynamicImport016 end'); + }) + + it('testDynamicImport017', 0, async () => { + console.info('uitest: testDynamicImport017 begin'); + let hspPackageName = 'myhsp'; + let hsp: ESObject = await import(hspPackageName); + expect(hsp.add(3, 5)).assertEqual(8); + console.info('uitest: testDynamicImport017 end'); + }) + + it('testDynamicImport018', 0, async () => { + console.info('uitest: testDynamicImport018 begin'); + let remoteHarPackageName = '@ohos/crypto-js'; + let har: ESObject = await import(remoteHarPackageName); + expect(har.CryptoJS.src).assertUndefined(); + console.info('uitest: testDynamicImport018 end'); + }) + + it('testDynamicImport019', 0, async () => { + console.info('uitest: testDynamicImport019 begin'); + let ohpmPackageName = '@ohos/hypium'; + let ohpm: ESObject = await import(ohpmPackageName); + expect(ohpm.TestType.FUNCTION).assertEqual(1); + console.info('uitest: testDynamicImport019 end'); + }) + + it('testDynamicImport020', 0, async () => { + console.info('uitest: testDynamicImport020 begin'); + let calcFilePath = '../../../../src/main/ets/Calc'; + let singleFile: ESObject = await import(calcFilePath); + expect(singleFile.add(3, 5)).assertEqual(8); + console.info('uitest: testDynamicImport020 end'); + }) + + it('testDynamicImport021', 0, async () => { + console.info('uitest: testDynamicImport021 begin'); + let soName = 'libentry.so'; + let native: ESObject = await import(soName); + expect(native.default.add(2, 3)).assertEqual(5); + console.info('uitest: testDynamicImport021 end'); + }) + + it('testDynamicImport022', 0, async () => { + console.info('uitest: testDynamicImport022 begin'); + let packageName = '@system.app'; + let systemApp: ESObject = await import(packageName); + expect(systemApp.default.getInfo()).assertNull(); + console.info('uitest: testDynamicImport022 end'); + }) + + it('testDynamicImport023', 0, async () => { + console.info('uitest: testDynamicImport023 begin'); + let packageName = '@ohos.curves'; + let curves: ESObject = await import(packageName); + expect(curves.default.springMotion(0.555, 0.75, 0.001).interpolate(1)).assertEqual(0); + console.info('uitest: testDynamicImport023 end'); + }) + + it('testDynamicImport024', 0, async () => { + console.info('uitest: testDynamicImport024 begin'); + let packageName = '@ohos.matrix4'; + let matrix4: ESObject = await import(packageName); + expect(matrix4.default.identity().transformPoint([1, 2])[0]).assertEqual(1); + console.info('uitest: testDynamicImport024 end'); + }) + + it('testDynamicImport025', 0, async () => { + console.info('uitest: testDynamicImport025 begin'); + let packageName = '@ohos.hilog'; + let hilog: ESObject = await import(packageName); + expect(hilog.default.LogLevel.DEBUG).assertEqual(3); + console.info('uitest: testDynamicImport025 end'); + }) + + it('testDynamicImport026', 0, async () => { + console.info('uitest: testDynamicImport026 begin'); + let harName = 'har1'; + let har: ESObject = await import(harName); + expect(har.addHar1(4, 5)).assertEqual(9); + console.info('uitest: testDynamicImport026 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..99b93d0d0bc7b0b36bd58492e802a354189888a3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.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. + */ + +export { MainPage } from './src/main/ets/components/MainPage'; + +// [Start export_add_har1] +export { addHar1 } from './src/main/ets/utils/Calc'; +// [End export_add_har1] diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefa5f6959f0e65b9347a5182401ee9f4873007a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/build-profile.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..24a5f32b5a8d1a0747c833e6d8d8363200beca5b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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": "har1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad7bec2228055191728b1ac8c6bd9467c08a4d4b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.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. + */ + +// [Start function_add_har1] +export function addHar1(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am har1, %d + %d = %d', a, b, c); + + let harName = 'har2'; + import(harName).then((ns: ESObject) => { + console.info('DynamicImport addHar2 4 + 5 = ' + ns.addHar2(4, 5)); + }); + return c; +} +// [End function_add_har1] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f14a04c4479dcbdaeb9acf3755d881845cd4e9e1 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/module.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. + */ + +{ + "module": { + "name": "har1", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..acef8e5105641e7dee97640747d60fef35cb5d7a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/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": "har1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..63672b2a46dbb56553e093d392aab7ed4d9d6652 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.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. + */ + +export { MainPage } from './src/main/ets/components/MainPage'; + +// [Start export_add_har2] +export { addHar2 } from './src/main/ets/utils/Calc' +// [End export_add_har2] diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefa5f6959f0e65b9347a5182401ee9f4873007a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/build-profile.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d778bf2ab9bd7e94eb867bb5796bfacb377800f7 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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": "har2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets new file mode 100644 index 0000000000000000000000000000000000000000..72e3c50f492610fb9f9e03f87d2b7b0f3599c651 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start function_add_har2] +export function addHar2(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am har2, %d + %d = %d', a, b, c); + return c; +} +// [End function_add_har2] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cadd1c017107c2919c40339a5b4b0f3922db2a5d --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/module.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. + */ + +{ + "module": { + "name": "har2", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..280914cdf065451f11e81d4611ad57a1589ff426 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/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": "har2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9b782d958c2000424e0cd6a89fee65a6eae9ac03 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.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. + */ + +export { MainPage } from './src/main/ets/components/MainPage' + +// [Start module_members_export] +export { Calc, addHarlibrary } from './src/main/ets/utils/Calc' +// [End module_members_export] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefa5f6959f0e65b9347a5182401ee9f4873007a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/build-profile.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb0db5029552a7512339de1c2c4daddc14b5e805 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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": "harlibrary", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc34273737fde9632aebd8223f3e3f92dc0e6936 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start dynamic_call_add] +export class Calc { + public static staticAdd(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am harlibrary in staticAdd, %d + %d = %d', a, b, c); + return c; + } + + public instanceAdd(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am harlibrary in instanceAdd, %d + %d = %d', a, b, c); + return c; + } +} + +export function addHarlibrary(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am harlibrary in addHarlibrary, %d + %d = %d', a, b, c); + return c; +} +// [End dynamic_call_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6b2ff2e5614d9c8971dba0fbec723803d88efe30 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/module.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. + */ + +{ + "module": { + "name": "harlibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8d8baae08cb6c34c3af3f9eb7bd1984f0fd5a2e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/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": "harlibrary_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c7e6b0d1aa845146e5f429d6803f01e213338e2d --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets @@ -0,0 +1,24 @@ +/* + * 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 { MainPage } from './src/main/ets/components/MainPage' + +// [Start const_dynamic_import_har] +export function add(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am a HAR, %d + %d = %d', a, b, c); + return c; +} +// [End const_dynamic_import_har] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefa5f6959f0e65b9347a5182401ee9f4873007a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/build-profile.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3bb3dc439b03f6147960a3f405bc43d3011306c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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": "myhar", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a48a33b6c9ba916f38c321eb2fac9184c3c69670 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/module.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. + */ + +{ + "module": { + "name": "myHar", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ad42bd787b63dc3ea2e64f72f3e592c564622b21 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/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": "myHar_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5c710086a21abe2c0d919741917d0b481239d3b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start const_dynamic_import_hsp] +export function add(a: number, b: number): number { + let c = a + b; + console.info('DynamicImport I am a HSP, %d + %d = %d', a, b, c); + return c; +} +// [End const_dynamic_import_hsp] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4b63399df47f670baf9178f63e36c2c665de8958 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fafa5e8a4d6e987cbccc79fda84dc35dd8fbff54 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/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": "myhsp", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "packageType": "InterfaceHar", + "dependencies": { + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/utils/Calc.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/utils/Calc.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/ets/utils/Calc.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..36053121320bedc39a23cefcf5b618151c24f10a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "myHsp", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..98e1d8a84b3d8539ea33e79fe2ac593a05d23bb4 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..06e0923828c073ed20dfee08dcec9a48a006e4af --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/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": "myHsp_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/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/ArkTSRuntime/ArkTSModule/DynamicImport/ohosTest.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..e1a49c74cf2140669ae9c1f840d8265eee6314de --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/ohosTest.md @@ -0,0 +1,27 @@ +# 动态加载测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------- | ------------ | ---- | ---------------------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 动态加载harlibrary模块调用函数 | 成功拉起应用 | | 输出日志 | 是 | Pass | +| HAP常量动态import HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import HAR模块文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import HSP模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import HSP模块名文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import远程HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import ohpm包 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import自己的单文件 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import自己的Native库 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP常量动态import加载API | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import HAR模块文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import HSP模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import HSP模块名文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import远程HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import ohpm包 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import自己的单文件 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import自己的Native库 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| HAP变量动态import加载API | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | +| 动态加载耦合har包 | 成功拉起应用 | | 加载har1可以调用har2函数并打印日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/screenshots/DynamicImport.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/screenshots/DynamicImport.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/screenshots/DynamicImport.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/DynamicImport/screenshots/DynamicImport.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..575ac506f59479ee01b14a2230a1a3701b1d37d6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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.jsapisloadnativemodule", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ffe5bc881d78d728edddba05653be251bfd52308 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsApisLoadNativeModule" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/README.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ae2360ed7075b57392ca41769d538a2b04caf30a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/README.md @@ -0,0 +1,73 @@ +# ArkTS同步方式动态加载native模块 + +### 介绍 + +本工程主要展示了使用loadNativeModule接口能力进行同步方式加载native模块。该工程中展示的代码详细描述可查如下链接部分。 + +- [同步方式动态加载native模块](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/js-apis-load-native-module.md) + +### 效果预览 + +| 首页 | 点击HAP加载系统库模块按钮后 | 点击HAP加载Native库按钮后 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面中Text组件文本呈现LoadNativeModule效果并有两个按钮,分别点击之后第两个个按钮Text文本变化如上图并在工作台打印日志。 +3. 运行测试用例JsApisLoadNativeModule.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── index.d.ts + │ │ │ ├── CMakeList.txt + │ │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 同步方式动态加载native模块 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── JsApisLoadNativeModule.test.ets // 自动化测试代码 + │ │ └── List.test +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/code-linter.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..048216bab1dad5275ffb29881776debd3313a891 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 @@ -0,0 +1,70 @@ +/* + * 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", + // [Start hap_load_native_dependence_01] + "buildOption": { + "arkOptions": { + "runtimeOnly": { + "packages": [ + "libentry.so" + ] + } + }, + // [StartExclude hap_load_native_dependence_01] + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + }, + // [EndExclude hap_load_native_dependence_01] + }, + // [End hap_load_native_dependence_01] + "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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118460b3083cf236372a2651e5dcc3e542b95b2f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + // [Start hap_load_native_dependence] + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + }, + // [End hap_load_native_dependence] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c8b20f552ca24a21a9983318b49813b026cd2fa7 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(syncNative) + +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) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0fd6bae0c25c6ede739471ab179fb18536bede10 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "napi/native_api.h" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"add", nullptr, Add, 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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3604285cc292dcc5599b733afcfbf85b92dcb162 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start hap_load_native] +export const add: (a: number, b: number) => number; +// [End hap_load_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1033f7062a6d00b9fbfbaaf959c9bcd876fe0a6f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9f7f873fbc51484895e18fcfd60b2498521aecb0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/JsApisLoadNativeModule.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/JsApisLoadNativeModule.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/JsApisLoadNativeModule.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/JsApisLoadNativeModule.test.ets index b8706a4d4fd551af00a7da6135b54e0c43cc7745..9926c94a4323b65566cd3f11e6c2cca065298d0f --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/JsApisLoadNativeModule.test.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/JsApisLoadNativeModule.test.ets @@ -1,56 +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 { describe, it, expect } from '@ohos/hypium'; -// 导入测试依赖kit -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 JsApisLoadNativeModuleTest() { - describe('jsApisLoadNativeModuleTest', () => { - - it('testJsApisLoadNativeModule001', 0, async () => { - console.info('uitest: testJsApisLoadNativeModule001 begin'); - const want: Want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - } - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - await driver.delayMs(1000); - - const button1 = await driver.findComponent(ON.text('LoadSystemModule')); - const button2 = await driver.findComponent(ON.text('LoadNativeModule')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadNativeModule ohos.hilog success')); - - await driver.delayMs(1000); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadNativeModule libentry.so success result: 3')); - console.info('uitest: testJsApisLoadNativeModule001 end'); - }) - }) +/* + * 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'; +// 导入测试依赖kit +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 JsApisLoadNativeModuleTest() { + describe('jsApisLoadNativeModuleTest', () => { + + it('testJsApisLoadNativeModule001', 0, async () => { + console.info('uitest: testJsApisLoadNativeModule001 begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('LoadSystemModule')); + const button2 = await driver.findComponent(ON.text('LoadNativeModule')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadNativeModule ohos.hilog success')); + + await driver.delayMs(1000); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadNativeModule libentry.so success result: 3')); + console.info('uitest: testJsApisLoadNativeModule001 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f11cb9fd6c307decccf72c61922ccc5441e8e0d0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a2c44fdf8f9ac103168672568ff000ac395a2edc --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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.0", + "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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..37c22b202a9577e792485ef2f2f8f2d5702ed5f1 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/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/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/ohosTest.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..338b5a2815e7a1c0aa494c45f9fbc7a4cb3e5c1a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/ohosTest.md @@ -0,0 +1,9 @@ +# 同步方式动态加载Native模块测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------ | ------------ | ------------------------- | ------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| 主页按钮点击 | 位于主页 | 点击HAP加载系统库模块按钮 | 页面文本变化 | Pass | +| 主页按钮点击 | 位于主页 | 点击HAP加载Native库按钮 | 页面文本变化 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule1.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule1.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule1.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule2.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule2.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule2.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule3.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule3.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule3.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/screenshots/JsApisLoadNativeModule3.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7124fa63c7d479c1e919297822243895719e192a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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.lazyimport", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..36c2d06b26620a9becf3e0450676b9eab91daa88 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "LazyImport" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/README.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9755c18b8c075c01f46466ee4a2d11db75f5b156 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/README.md @@ -0,0 +1,75 @@ +# ArkTS延迟加载(lazy import) + +### 介绍 + +本工程主要对比了延迟加载与普通加载的区别,并展示延迟加载的错误使用方法。该工程中展示的代码详细描述可查如下链接部分。 + +- [延迟加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-lazy-import.md) + +### 效果预览 + +| 首页 | 依次点击按钮后结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面中Text组件呈现LazyImport效果,依次点击五个button,Text依次现实显示‘Call a success result: a = mod1 a executed’,‘‘Call b success result: b = mod1 b executed’, ‘‘Call c success result: c = mod2 c executed’, ‘Not advisable to use one error: ReferenceError: c is not initialized’, ‘Not advisable to use two error: ReferenceError: module environment is undefined’。 +3. 运行测试用例LazyImport.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── A.ets + │ │ ├── A_ns.ets + │ │ ├── B.ets + │ │ ├── C.ets + │ │ ├── fail_example.ets + │ │ ├── Index.ets // 延迟加载 + │ │ ├── middle.ets + │ │ ├── mod1.ets + │ │ ├── mod2.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── LazyImport.test.ets // 自动化测试代码 + │ │ └── List.test +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/code-linter.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..88b78d11f0276ab3b2e69dad150d0648fda2c0e7 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dbacc308e4f7758a11b72c6a2af812b2471a0e8a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd39a5616f8a7d2e416fd0135de8c25181ade29c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/main', (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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets index b26b2ae4786ceae9c5fad9e8e9a52fa97748b557..7b753cb569e108d743255435ca206e67e8f66993 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A.ets @@ -1,22 +1,22 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start export_variable_a] -import { c } from './B'; - -console.info(c); -// [End export_variable_a] - -export { c }; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_variable_a] +import { c } from './B'; + +console.info(c); +// [End export_variable_a] + +export { c }; diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets index 4928cba69da43798c536046b6110d12cd07419b1..dd739af27bcf8e0a1e2be1198388f92100441982 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/A_ns.ets @@ -1,22 +1,22 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start export_variable_a_ns] -import * as ns from './B'; - -console.info(ns.c); -// [End export_variable_a_ns] - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_variable_a_ns] +import * as ns from './B'; + +console.info(ns.c); +// [End export_variable_a_ns] + export { ns }; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets index 4a67139893e0bb4992088dce946d7c82d846e3e8..168cd240627e9ba9081e8057a03d21c76a2e0e5e --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/B.ets @@ -1,20 +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. - */ - -// [Start export_variable_b] -import lazy { c } from './C'; // 从'C'内获取c对象,标记为延迟加载 - -export { c }; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_variable_b] +import lazy { c } from './C'; // 从'C'内获取c对象,标记为延迟加载 + +export { c }; // [End export_variable_b] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets index 0e13c989d5b8f13b8082abfcbc0c24f06dd73491..7fff38a46b1790b5e05219de30334a28805bbcb1 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/C.ets @@ -1,20 +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. - */ - -// [Start export_variable_c] -let c = 'c'; - -export { c }; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_variable_c] +let c = 'c'; + +export { c }; // [End export_variable_c] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/fail_example.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/fail_example.ets old mode 100755 new mode 100644 similarity index 98% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/fail_example.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/fail_example.ets index f90b53a476da2737382007eec0196dc0af67d58e..02b43de9c6f6c759cf702efdde9e83251b4fe288 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/fail_example.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/fail_example.ets @@ -1,30 +1,30 @@ -/* - * 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 lazy var v; // 编译器提示报错:应用编译报错 -// export lazy default function f(){}; // 编译器提示报错:应用编译报错 -// export lazy default function(){}; // 编译器提示报错:应用编译报错 -// export lazy default 42; // 编译器提示报错:应用编译报错 -// export lazy { x }; // 编译器提示报错:应用编译报错 -// export lazy { x as v }; // 编译器提示报错:应用编译报错 -// export lazy { x } from 'mod'; // 编译器提示报错:应用编译报错 -// export lazy { x as v } from 'mod'; // 编译器提示报错:应用编译报错 -// export lazy * from 'mod'; // 编译器提示报错:应用编译报错 - -// import lazy v from 'mod'; // 编译器提示报错:应用编译报错 -// import lazy * as ns from 'mod'; // 编译器提示报错:应用编译报错 -// -// import lazy type { obj } from './mod'; // 不支持,编译器、应用编译报错 +/* + * 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 lazy var v; // 编译器提示报错:应用编译报错 +// export lazy default function f(){}; // 编译器提示报错:应用编译报错 +// export lazy default function(){}; // 编译器提示报错:应用编译报错 +// export lazy default 42; // 编译器提示报错:应用编译报错 +// export lazy { x }; // 编译器提示报错:应用编译报错 +// export lazy { x as v }; // 编译器提示报错:应用编译报错 +// export lazy { x } from 'mod'; // 编译器提示报错:应用编译报错 +// export lazy { x as v } from 'mod'; // 编译器提示报错:应用编译报错 +// export lazy * from 'mod'; // 编译器提示报错:应用编译报错 + +// import lazy v from 'mod'; // 编译器提示报错:应用编译报错 +// import lazy * as ns from 'mod'; // 编译器提示报错:应用编译报错 +// +// import lazy type { obj } from './mod'; // 不支持,编译器、应用编译报错 // import type lazy { obj } from './mod'; // 不支持,编译器、应用编译报错 \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/main.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/middle.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/middle.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/middle.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/middle.ets index fdff5d3d3fd8d5ba7b6618dd2936574fe8896569..14e7e73459001aae410c05b98ebeef59b4400cbf --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/middle.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/middle.ets @@ -1,20 +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 { c } from './A'; // 不推荐用法 -import { ns } from './A_ns'; // 不推荐用法 - - +/* + * 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 { c } from './A'; // 不推荐用法 +import { ns } from './A_ns'; // 不推荐用法 + + export { c, ns }; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets index 520baeafa3141c7677697bc0e0d82f5949e1f612..037aca4cb5c0efbfaebf8e1a8abb20ec292059d0 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod1.ets @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start export_module_variable_01] -export let a = 'mod1 a executed'; - -console.info(a); - -export let b = 'mod1 b executed'; - -console.info(b); +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_module_variable_01] +export let a = 'mod1 a executed'; + +console.info(a); + +export let b = 'mod1 b executed'; + +console.info(b); // [End export_module_variable_01] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets index bab31537ac4767071e97d06e2cf5cd487db70adf..b1a5022d65e8a1fcdae81f3caa81779329ed7a05 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/pages/mod2.ets @@ -1,20 +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. - */ - -// [Start export_module_variable_02] -export let c = 'mod2 c executed'; - -console.info(c); +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_module_variable_02] +export let c = 'mod2 c executed'; + +console.info(c); // [End export_module_variable_02] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9f7f873fbc51484895e18fcfd60b2498521aecb0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/LazyImport.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/LazyImport.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/LazyImport.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/LazyImport.test.ets index f1288468bfa55b76e65de412b18570f7551fa68b..84c6997036fcddef44a898730ab091c58561ec90 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/LazyImport.test.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/LazyImport.test.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -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 lazyImportTest() { - describe('lazyImportTest', () => { - - it('testLazyImport001', 0, async (done: Function) => { - console.info('uitest: testLazyImport001 begin'); - const want: Want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - } - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - await driver.delayMs(1000); - - await driver.assertComponentExist(ON.text('LazyImport')); - const button1 = await driver.findComponent(ON.text('Call a')); - const button2 = await driver.findComponent(ON.text('Call b')); - const button3 = await driver.findComponent(ON.text('Call c')); - const button4 = await driver.findComponent(ON.text('Not advisable to use one')); - const button5 = await driver.findComponent(ON.text('Not advisable to use two')); - - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call a success result: a = mod1 a executed')); - - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call b success result: b = mod1 b executed')); - - await button3.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call c success result: c = mod2 c executed')); - - await button4.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Not advisable to use one error: ReferenceError: c is not initialized')); - - await button5.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Not advisable to use two error: ReferenceError: module environment is undefined')); - console.info('uitest: testLazyImport001 end'); - done(); - }) - }) +/* + * 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 lazyImportTest() { + describe('lazyImportTest', () => { + + it('testLazyImport001', 0, async (done: Function) => { + console.info('uitest: testLazyImport001 begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + } + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(1000); + + await driver.assertComponentExist(ON.text('LazyImport')); + const button1 = await driver.findComponent(ON.text('Call a')); + const button2 = await driver.findComponent(ON.text('Call b')); + const button3 = await driver.findComponent(ON.text('Call c')); + const button4 = await driver.findComponent(ON.text('Not advisable to use one')); + const button5 = await driver.findComponent(ON.text('Not advisable to use two')); + + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call a success result: a = mod1 a executed')); + + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call b success result: b = mod1 b executed')); + + await button3.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call c success result: c = mod2 c executed')); + + await button4.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Not advisable to use one error: ReferenceError: c is not initialized')); + + await button5.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Not advisable to use two error: ReferenceError: module environment is undefined')); + console.info('uitest: testLazyImport001 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f11cb9fd6c307decccf72c61922ccc5441e8e0d0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3511c6358c656ebda11ff67ebc9dc6454caeaa69 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..14655ea1c07e1b7b8b8eb3d9f6813577b90f6a0f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/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/ArkTSRuntime/ArkTSModule/LazyImport/ohosTest.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..21e7812c01923e7a069ac5d78d7dd6794dc33ca2 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/ohosTest.md @@ -0,0 +1,12 @@ +# 延迟加载测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------ | ------------ | ------------------- | ------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| 主页按钮点击 | 位于主页 | 点击触发a按钮 | 页面文本变化 | Pass | +| 主页按钮点击 | 位于主页 | 点击触发b按钮 | 页面文本变化 | Pass | +| 主页按钮点击 | 位于主页 | 点击触发c按钮 | 页面文本变化 | Pass | +| 主页按钮点击 | 位于主页 | 点击不推荐用法1按钮 | 页面文本变化 | Pass | +| 主页按钮点击 | 位于主页 | 点击不推荐用法2按钮 | 页面文本变化 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport1.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport1.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport1.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport2.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport2.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/LazyImport/screenshots/LazyImport2.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2bb30c7089b9a26ce9e0f53b4b52455d2c1477b3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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.moduleloadingsideeffects", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d9d56cd3c1fc531811d9503e2ea331f459113c46 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ModuleLoadingSideEffects" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/README.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/README.md new file mode 100644 index 0000000000000000000000000000000000000000..89b5b5a0fe7ea3cd8a4b1c9d7e73ec41aea9427b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/README.md @@ -0,0 +1,74 @@ +# ArkTS模块加载副作用及优化 + +### 介绍 + +当使用ArkTS模块化时,模块的加载和执行可能会引发副作用。副作用是指在模块导入过程中,除了导出功能或对象之外,还产生了额外的行为或状态变化。这些行为可能影响程序别的部分,并导致非预期的顶层代码执行、全局状态变化、原型链修改、导入内容未定义等问题。 + +本项目展现了模块加载副作用及优化,包括模块执行顶层代码、修改全局对象、修改应用级ArkUI组件的状态变量信息、修改内置全局变量或原型链、循环依赖和延迟加载改变模块执行顺序等场景,对比产生副作用的场景和优化后场景。代码详细描述可查如下链接。 + +- [模块加载副作用及优化](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-module-side-effects.md) + +### 效果预览 + +| 首页 | +| ------------------------------------------------------------ | +| | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面中呈现五个按钮分别对应介绍中五个场景,分别点击按钮可以跳转到各个场景的页面,页面中有副作用以及优化后结果进行对比,并在工作台打印日志。 +3. 运行测试用例ModuleLoadingSideEffects.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── LazyImportChangeExecutionOrder // 延迟加载改变模块执行顺序 + │ │ ├── ModifyGlobalObject // 修改全局对象 + │ │ ├── ModifyingGlobalVariables // 修改内置全局变量或原型链 + │ │ ├── ModifyTheApplicationLevelArkUI // 修改应用级ArkUI组件的状态变量信息 + │ │ ├── TopCodeModification // 模块执行顶层代码 + │ │ └── Index.ets // 首页 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── ModuleLoadingSideEffects.test.ets // 自动化测试代码 + │ │ └── List.test +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/code-linter.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/.gitignore b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets new file mode 100644 index 0000000000000000000000000000000000000000..6be7578e26986f7c42af2bf97c4060b07b3fdfad --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.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. + */ + +// [Start import_global_module_data] +export let data = 'data from module'; + +globalThis.someGlobalVar = 100; +// [End import_global_module_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleOptimize.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleOptimize.ets new file mode 100644 index 0000000000000000000000000000000000000000..44c8c0b9b769c119c8447e1990880017c61ed34d --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleOptimize.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. + */ + +export let dataOptimize = 'data from module'; + +export function initialize() { + globalThis.someGlobalVar = 100; // 延迟到函数调用时执行 +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleUseGlobalVar.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/main.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets new file mode 100644 index 0000000000000000000000000000000000000000..138e8b5ed2b8f545f56ce71966eee53f5f9882fa --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.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. + */ + +// [Start export_change_global_data_100] +export let data1 = 'data from module'; + +globalThis.someGlobalVar = 100; // 改变了全局状态 +// [End export_change_global_data_100] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleOptimize.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleOptimize.ets new file mode 100644 index 0000000000000000000000000000000000000000..dbe96385783728ca62d4e9db2772b87487940c1f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleOptimize.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. + */ + +export let dataOptimize1 = 'data from module'; + +export function changeGlobalVar() { + globalThis.someGlobalVar = 100; +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets index 91c18c7516e5c64b92d3519fe94878b1a83d4189..4bb2bf0359222757d9f7b1acea162f4eca671333 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVar.ets @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start export_change_some_global_var] -import { data1 } from './module'; // 此时可能预期全局变量someGlobalVar的值为100 - -export function useGlobalVar() { - console.log(data1); - console.log(globalThis.someGlobalVar); // 此时由于main.ets中加载了sideEffectModule模块,someGlobalVar的值已经被改为200 -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_change_some_global_var] +import { data1 } from './module'; // 此时可能预期全局变量someGlobalVar的值为100 + +export function useGlobalVar() { + console.log(data1); + console.log(globalThis.someGlobalVar); // 此时由于main.ets中加载了sideEffectModule模块,someGlobalVar的值已经被改为200 +} // [End export_change_some_global_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVarOptimize.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVarOptimize.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVarOptimize.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVarOptimize.ets index a1d76f4f75e9c146352ee627cf21163037e0a78c..bb5ed7f6edc394d231d859120fe57d2873e3fbfb --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVarOptimize.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleUseGlobalVarOptimize.ets @@ -1,22 +1,22 @@ -/* - * 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 { dataOptimize1, changeGlobalVar } from './moduleOptimize'; - -export function useGlobalVarOptimize() { - console.log(dataOptimize1); - changeGlobalVar(); // 在需要的时候执行代码,而不是模块加载时执行。 - console.log(globalThis.someGlobalVar); +/* + * 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 { dataOptimize1, changeGlobalVar } from './moduleOptimize'; + +export function useGlobalVarOptimize() { + console.log(dataOptimize1); + changeGlobalVar(); // 在需要的时候执行代码,而不是模块加载时执行。 + console.log(globalThis.someGlobalVar); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets index 1f401a0dfdccf84e16662d7bd38a18daa3ae29f8..dc3c50caae5837aa28510552d1640f97dca554bc --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModule.ets @@ -1,20 +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. - */ - -// [Start export_change_global_data_200] -export let data2 = 'data from side effect module'; - -globalThis.someGlobalVar = 200; // 也变了全局状态 +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_change_global_data_200] +export let data2 = 'data from side effect module'; + +globalThis.someGlobalVar = 200; // 也变了全局状态 // [End export_change_global_data_200] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModuleOptimize.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModuleOptimize.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModuleOptimize.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModuleOptimize.ets index 18368b9a5315626e49c67327694354c05cd52ea7..8e7b8b4d08a36a36ab2735eab7e91482d3db6f69 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModuleOptimize.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/sideEffectModuleOptimize.ets @@ -1,20 +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. - */ - -export let dataOptimize2 = 'data from side effect module'; - -export function changeGlobalVar() { - globalThis.someGlobalVar = 200; +/* + * 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 let dataOptimize2 = 'data from side effect module'; + +export function changeGlobalVar() { + globalThis.someGlobalVar = 200; } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f22295fa7a24640506f9aa00dcbf97ec15584ed --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.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. + */ + +// [Start set_app_storage_var] +export let data = 'data from module'; + +AppStorage.setOrCreate('SomeAppStorageVar1', 200); // 修改应用全局的UI状态 +// [End set_app_storage_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/moduleOptimize.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/moduleOptimize.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f3eb44a109223ff2a6f99b41da4ab6994c926da --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/moduleOptimize.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. + */ + +export let dataOptimize = 'data from module'; + +export function initialize() { + AppStorage.setOrCreate('SomeAppStorageVar2', 200); +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets index 2d5fc12b0819cc5ea08d1b49435f701386dab24a..f6f29f149d80a6dd13f394da69a5b072efc4c11c --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/a.ets @@ -1,22 +1,22 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start module_cycle_dependence_a] -import { b } from './b'; - -console.log('Module A: ', b); - -export const a = 'A'; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start module_cycle_dependence_a] +import { b } from './b'; + +console.log('Module A: ', b); + +export const a = 'A'; // [End module_cycle_dependence_a] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets index 106641288af9a5e5fe0fb47e006d1f2f50124bc7..429b760ccd05995a34d547de36805c1988707632 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/b.ets @@ -1,22 +1,22 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start module_cycle_dependence_b] -import { a } from './a'; - -console.log('Module B: ', a); - -export const b = 'B'; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start module_cycle_dependence_b] +import { a } from './a'; + +console.log('Module B: ', a); + +export const b = 'B'; // [End module_cycle_dependence_b] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/main.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts index e67a9730726c1de2fc16c23abd5786c58bfb2943..fcd1cf7e7943a783bf81f52b7b8882cd65ab9c48 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyingGlobalVariables/modifyPrototype.ts @@ -1,22 +1,22 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start array_prototype_include] -export let data = 'data from modifyPrototype'; - -Array.prototype.includes = function (value) { - return this.indexOf(value) == -1; -}; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start array_prototype_include] +export let data = 'data from modifyPrototype'; + +Array.prototype.includes = function (value) { + return this.indexOf(value) == -1; +}; // [End array_prototype_include] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/main.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets new file mode 100644 index 0000000000000000000000000000000000000000..78a1749bdadd4c632fff4e602a03eff76c6ebf65 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start module_load_directly] +export function initialize() { + console.log('Module loaded!'); +} +// [End module_load_directly] + +// [Start module_load_optimize] +export const dataOptimizeTwo = 1; +// [End module_load_optimize] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModule.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModule.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModule.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModule.ets index 7c4d4ad681531c2a782f8411f6985da7c601c0ff..0881065f6e49ffb239da47cccf5ae651e0408514 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModule.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModule.ets @@ -1,18 +1,18 @@ -/* - * 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. - */ - -console.log('Module loaded!'); // 这段代码在导入时会立即执行,可能会导致副作用。 - +/* + * 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. + */ + +console.log('Module loaded!'); // 这段代码在导入时会立即执行,可能会导致副作用。 + export const data = 1; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModuleOptimize.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModuleOptimize.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModuleOptimize.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModuleOptimize.ets index d375625a0939a477210ecb9712a0437565a1646a..5a8ab7a8dc1d244adff002ccb2c6c2274f32b6ec --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModuleOptimize.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/topCodeModuleOptimize.ets @@ -1,16 +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. - */ - +/* + * 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 dataOptimizeOne = 1; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/CommonButton.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/CommonButton.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/resource.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0f1755b8cccfecc4200cf5b1ed991805e3e00b6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/resource.ets @@ -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. + */ + +export class P2PManager { + public resourceToString(resource: Resource):string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + +export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/ModuleLoadingSideEffects.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/ModuleLoadingSideEffects.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/ModuleLoadingSideEffects.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/ModuleLoadingSideEffects.test.ets index a0d89ffb531ed1615ed488615c6362688a6a613f..883d68ee9dc8b7399cda00170e1097633a988f05 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/ModuleLoadingSideEffects.test.ets +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/ets/test/ModuleLoadingSideEffects.test.ets @@ -1,156 +1,156 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -export default function moduleLoadingSideEffectsTest() { - describe('moduleLoadingSideEffectsTest', () => { - - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - it('testModuleLoadingSideEffects001', 0, async () => { - console.info('uitest: testModuleLoadingSideEffects001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('LazyImport')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('LazyImportSideEffect')); - const button3 = await driver.findComponent(ON.text('LazyImportOptimize')); - await driver.delayMs(1000); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SideEffect: undefined')); - await driver.delayMs(1000); - await button3.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Optimize: 100')); - console.info('uitest: testModuleLoadingSideEffects001 end'); - await driver.pressBack(); - }) - - it('testModuleLoadingSideEffects002', 0, async () => { - console.info('uitest: testModuleLoadingSideEffects002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ModifyGlobalObject')); - await driver.delayMs(1000); - await button1.click(); - - const button2 = await driver.findComponent(ON.text('SideEffect').type('Button')); - const button3 = await driver.findComponent(ON.text('Optimize').type('Button')); - await driver.delayMs(1000); - - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('sideEffect result: 200')); - await driver.delayMs(1000); - - await button3.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('optimize result: 100')); - console.info('uitest: testModuleLoadingSideEffects002 end'); - await driver.pressBack(); - }) - - it('testModuleLoadingSideEffects003', 0, async () => { - console.info('uitest: testModuleLoadingSideEffects003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('ModifyingGlobalVariables')); - await driver.delayMs(1000); - await button1.click(); - - const button2 = await driver.findComponent(ON.text(resourceToString($r('app.string.circular_dependency')))); - const button3 = await driver.findComponent(ON.text('Not Call modifyPrototype')); - const button4 = await driver.findComponent(ON.text('Call modifyPrototype')); - await driver.delayMs(1000); - - await button2.click(); - await button3.click(); - await driver.delayMs(1000); - - await driver.assertComponentExist(ON.text(resourceToString($r( - 'app.string.circular_dependency')) + 'error: ReferenceError: a is not initialized')); - await driver.assertComponentExist(ON.text('SideEffect: true')); - - await driver.delayMs(1000); - await button4.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Optimize: false')); - console.info('uitest: testModuleLoadingSideEffects003 end'); - await driver.pressBack(); - }) - - it('testModuleLoadingSideEffects004', 0, async () => { - console.info('uitest: testModuleLoadingSideEffects004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('ModifyTheApplicationLevelArkUI')); - await driver.delayMs(1000); - await button.click(); - - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('test100')); - await driver.assertComponentExist(ON.text('test200')); - console.info('uitest: testModuleLoadingSideEffects004 end'); - await driver.pressBack(); - }) - - it('testModuleLoadingSideEffects005', 0, async () => { - console.info('uitest: testModuleLoadingSideEffects005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('TopCodeModification')); - await driver.delayMs(1000); - await button1.click(); - - await driver.delayMs(1000); - - const button2 = await driver.findComponent(ON.text('Call top code')); - await driver.delayMs(1000); - - await button2.click(); - await driver.delayMs(1000); - - await driver.assertComponentExist(ON.text('sideEffect: Module loaded!1')); - await driver.assertComponentExist(ON.text('optimize one: 1')); - await driver.assertComponentExist(ON.text('optimize two: 1')); - console.info('uitest: testModuleLoadingSideEffects005 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +export default function moduleLoadingSideEffectsTest() { + describe('moduleLoadingSideEffectsTest', () => { + + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + it('testModuleLoadingSideEffects001', 0, async () => { + console.info('uitest: testModuleLoadingSideEffects001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('LazyImport')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('LazyImportSideEffect')); + const button3 = await driver.findComponent(ON.text('LazyImportOptimize')); + await driver.delayMs(1000); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SideEffect: undefined')); + await driver.delayMs(1000); + await button3.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Optimize: 100')); + console.info('uitest: testModuleLoadingSideEffects001 end'); + await driver.pressBack(); + }) + + it('testModuleLoadingSideEffects002', 0, async () => { + console.info('uitest: testModuleLoadingSideEffects002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ModifyGlobalObject')); + await driver.delayMs(1000); + await button1.click(); + + const button2 = await driver.findComponent(ON.text('SideEffect').type('Button')); + const button3 = await driver.findComponent(ON.text('Optimize').type('Button')); + await driver.delayMs(1000); + + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('sideEffect result: 200')); + await driver.delayMs(1000); + + await button3.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('optimize result: 100')); + console.info('uitest: testModuleLoadingSideEffects002 end'); + await driver.pressBack(); + }) + + it('testModuleLoadingSideEffects003', 0, async () => { + console.info('uitest: testModuleLoadingSideEffects003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('ModifyingGlobalVariables')); + await driver.delayMs(1000); + await button1.click(); + + const button2 = await driver.findComponent(ON.text(resourceToString($r('app.string.circular_dependency')))); + const button3 = await driver.findComponent(ON.text('Not Call modifyPrototype')); + const button4 = await driver.findComponent(ON.text('Call modifyPrototype')); + await driver.delayMs(1000); + + await button2.click(); + await button3.click(); + await driver.delayMs(1000); + + await driver.assertComponentExist(ON.text(resourceToString($r( + 'app.string.circular_dependency')) + 'error: ReferenceError: a is not initialized')); + await driver.assertComponentExist(ON.text('SideEffect: true')); + + await driver.delayMs(1000); + await button4.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Optimize: false')); + console.info('uitest: testModuleLoadingSideEffects003 end'); + await driver.pressBack(); + }) + + it('testModuleLoadingSideEffects004', 0, async () => { + console.info('uitest: testModuleLoadingSideEffects004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('ModifyTheApplicationLevelArkUI')); + await driver.delayMs(1000); + await button.click(); + + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('test100')); + await driver.assertComponentExist(ON.text('test200')); + console.info('uitest: testModuleLoadingSideEffects004 end'); + await driver.pressBack(); + }) + + it('testModuleLoadingSideEffects005', 0, async () => { + console.info('uitest: testModuleLoadingSideEffects005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('TopCodeModification')); + await driver.delayMs(1000); + await button1.click(); + + await driver.delayMs(1000); + + const button2 = await driver.findComponent(ON.text('Call top code')); + await driver.delayMs(1000); + + await button2.click(); + await driver.delayMs(1000); + + await driver.assertComponentExist(ON.text('sideEffect: Module loaded!1')); + await driver.assertComponentExist(ON.text('optimize one: 1')); + await driver.assertComponentExist(ON.text('optimize two: 1')); + console.info('uitest: testModuleLoadingSideEffects005 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/oh-package.json5 b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/ohosTest.md b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..7673093ea56fe2fbac0b6d4293365c9876490e79 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/ohosTest.md @@ -0,0 +1,12 @@ +# 模块加载副作用及优化测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动化 | 测试结果 | +| ------------------------------ | ---------------- | -------------------------------------- | ------------ | ---------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击LazyImport按钮 | 页面文本变化 | 是 | Pass | +| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击ModifyGlobalObject按钮 | 页面文本变化 | 是 | Pass | +| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击ModifyingGlobalVariables按钮 | 页面文本变化 | 是 | Pass | +| 主页按钮点击跳转按钮后文本显示 | 跳转按钮位于主页 | 点击ModifyTheApplicationLevelArkUI按钮 | 页面文本变化 | 是 | Pass | +| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击TopCodeModification按钮 | 页面文本变化 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/screenshots/ModuleLoadingSideEffects.png b/code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/screenshots/ModuleLoadingSideEffects.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/screenshots/ModuleLoadingSideEffects.png rename to code/DocsSample/ArkTS/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/screenshots/ModuleLoadingSideEffects.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/app.json5 old mode 100755 new mode 100644 index 935ada1e7802d58b7298d8143f06ceb737a51823..a52c889c4fd95e4197e1f2b159d52c3695d216a4 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/app.json5 @@ -1,25 +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.applicationmultithreading", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.applicationmultithreading", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index fa9c7dd41509b2e4240e8a14dab24d7b596747cd..2a444165a550f1d559edcae59743e326fe30a801 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ApplicationMultithreading" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ApplicationMultithreading" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/README.md old mode 100755 new mode 100644 index 8643222d9c0e7ccbcf21a9c9be546d9132048d16..359285278cebcdb589e8ee6c2c76265b7d3abb49 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/README.md @@ -1,95 +1,95 @@ -# ArkTS 应用多线程开发 - -### 介绍 - -ArkTS应用开发过程中,需要用到并发能力的业务场景很多,不同业务场景需要使用的并发能力不同,对应的主要任务类型也不同。 - -针对常见的业务场景,主要可以对应分为三种并发任务: - -[耗时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/time-consuming-task-overview.md):业务逻辑包含较大计算量或多次I/O读写等需要长时间执行的任务。 - -[长时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/long-time-task-overview.md):业务逻辑包含监听或定期采集数据等需要长时间保持运行的任务。 - -[常驻任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/resident-task-overview.md):业务逻辑跟随主线程生命周期或与主线程绑定的任务。 - -不同任务类型下可再细划分,比如典型的耗时任务有CPU密集型任务、I/O密集型任务以及同步任务,分别对应的典型业务场景也不相同。请开发者根据场景任务类型对应选择并发能力。 - -该工程中展示的代码详细描述可查如下链接: - -- [CPU密集型任务开发指导 (TaskPool和Worker)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/cpu-intensive-task-development.md) -- [I/O密集型任务开发指导 (TaskPool)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/io-intensive-task-development.md) -- [同步任务开发指导 (TaskPool和Worker)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sync-task-development.md) -- [长时任务开发指导(TaskPool)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/long-time-task-guide.md) -- [常驻任务开发指导(Worker)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/resident-task-guide.md) - -### 效果预览 - -| 首页 | 执行及结果即时反 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── CpuIntensiveTaskDevelopment.ets // CPU密集型任务开发指导 - │ │ ├── IoIntensiveTaskDevelopment.ets // I/O密集型任务开发指导 - │ │ ├── LongTimeTaskGuide.ets // 长时任务开发指导 - │ │ ├── ResidentTaskGuide.ets // 常驻任务开发指导 - │ │ ├── SyncTaskDevelopment.ets // 同步任务开发指导 - │ │ ├── write.ets // I/O密集型任务开发指导 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ │ ├── workers - │ │ ├── handle.ts // 同步任务开发指导 - │ │ ├── MyWorker1.ts // CPU密集型任务开发指导 - │ │ ├── MyWorker2.ts // 同步任务开发指导 - │ │ ├── Worker.ets // 常驻任务开发指导 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS 应用多线程开发 + +### 介绍 + +ArkTS应用开发过程中,需要用到并发能力的业务场景很多,不同业务场景需要使用的并发能力不同,对应的主要任务类型也不同。 + +针对常见的业务场景,主要可以对应分为三种并发任务: + +[耗时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/time-consuming-task-overview.md):业务逻辑包含较大计算量或多次I/O读写等需要长时间执行的任务。 + +[长时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/long-time-task-overview.md):业务逻辑包含监听或定期采集数据等需要长时间保持运行的任务。 + +[常驻任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/resident-task-overview.md):业务逻辑跟随主线程生命周期或与主线程绑定的任务。 + +不同任务类型下可再细划分,比如典型的耗时任务有CPU密集型任务、I/O密集型任务以及同步任务,分别对应的典型业务场景也不相同。请开发者根据场景任务类型对应选择并发能力。 + +该工程中展示的代码详细描述可查如下链接: + +- [CPU密集型任务开发指导 (TaskPool和Worker)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/cpu-intensive-task-development.md) +- [I/O密集型任务开发指导 (TaskPool)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/io-intensive-task-development.md) +- [同步任务开发指导 (TaskPool和Worker)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sync-task-development.md) +- [长时任务开发指导(TaskPool)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/long-time-task-guide.md) +- [常驻任务开发指导(Worker)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/resident-task-guide.md) + +### 效果预览 + +| 首页 | 执行及结果即时反 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── CpuIntensiveTaskDevelopment.ets // CPU密集型任务开发指导 + │ │ ├── IoIntensiveTaskDevelopment.ets // I/O密集型任务开发指导 + │ │ ├── LongTimeTaskGuide.ets // 长时任务开发指导 + │ │ ├── ResidentTaskGuide.ets // 常驻任务开发指导 + │ │ ├── SyncTaskDevelopment.ets // 同步任务开发指导 + │ │ ├── write.ets // I/O密集型任务开发指导 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ │ ├── workers + │ │ ├── handle.ts // 同步任务开发指导 + │ │ ├── MyWorker1.ts // CPU密集型任务开发指导 + │ │ ├── MyWorker2.ts // 同步任务开发指导 + │ │ ├── Worker.ets // 常驻任务开发指导 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/build-profile.json5 old mode 100755 new mode 100644 index a67b28bc7ed108abffba68fb2872c46dfac43c24..bc0de2c6ef7c7c47b81e63f81e69a43eaaed3fba --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/build-profile.json5 @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "sourceOption": { - "workers": [ - "./src/main/ets/workers/MyWorker1.ts", - "./src/main/ets/workers/MyWorker2.ts", - "./src/main/ets/workers/Worker.ets" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/MyWorker1.ts", + "./src/main/ets/workers/MyWorker2.ts", + "./src/main/ets/workers/Worker.ets" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/CpuIntensiveTaskDevelopment.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/CpuIntensiveTaskDevelopment.ets old mode 100755 new mode 100644 index 788f7e957dedb307ad1771465b49d8933c0d0fd7..4f734900b590babff045ae08a7936a8419167934 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/CpuIntensiveTaskDevelopment.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/CpuIntensiveTaskDevelopment.ets @@ -1,98 +1,98 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start process_image_histogram] -import { taskpool } from '@kit.ArkTS'; -// [StartExclude process_image_histogram] -// [Start call_worker_message] -import { worker } from '@kit.ArkTS'; - -const workerInstance: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker1.ts'); - -let done = false; - -// 接收Worker子线程的结果 -workerInstance.onmessage = (() => { - console.info('MyWorker.ts onmessage'); - if (!done) { - workerInstance.postMessage({ 'type': 1, 'value': 0 }); - done = true; - } -}) - -workerInstance.onerror = (() => { - // 接收Worker子线程的错误信息 -}) - -// 向Worker子线程发送训练消息 -workerInstance.postMessage({ 'type': 0 }); -// [End call_worker_message] - -// [Start after_destroy_callback] -// Worker线程销毁后,执行onexit回调方法 -workerInstance.onexit = (): void => { - console.info('main thread terminate'); -} -// [End after_destroy_callback] -// [EndExclude process_image_histogram] - -@Concurrent -function imageProcessing(dataSlice: ArrayBuffer): ArrayBuffer { - // 步骤1: 具体的图像处理操作及其他耗时操作 - return dataSlice; -} - -function histogramStatistic(pixelBuffer: ArrayBuffer): void { - // 步骤2: 分成三段并发调度 - let number: number = pixelBuffer.byteLength / 3; - let buffer1: ArrayBuffer = pixelBuffer.slice(0, number); - let buffer2: ArrayBuffer = pixelBuffer.slice(number, number * 2); - let buffer3: ArrayBuffer = pixelBuffer.slice(number * 2); - - let group: taskpool.TaskGroup = new taskpool.TaskGroup(); - group.addTask(imageProcessing, buffer1); - group.addTask(imageProcessing, buffer2); - group.addTask(imageProcessing, buffer3); - - taskpool.execute(group, taskpool.Priority.HIGH).then((ret: Object) => { - // 步骤3: 结果数组汇总处理 - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World' - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - let buffer: ArrayBuffer = new ArrayBuffer(24); - histogramStatistic(buffer); - this.message = 'success'; - // 销毁Worker线程 - workerInstance.terminate(); - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start process_image_histogram] +import { taskpool } from '@kit.ArkTS'; +// [StartExclude process_image_histogram] +// [Start call_worker_message] +import { worker } from '@kit.ArkTS'; + +const workerInstance: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker1.ts'); + +let done = false; + +// 接收Worker子线程的结果 +workerInstance.onmessage = (() => { + console.info('MyWorker.ts onmessage'); + if (!done) { + workerInstance.postMessage({ 'type': 1, 'value': 0 }); + done = true; + } +}) + +workerInstance.onerror = (() => { + // 接收Worker子线程的错误信息 +}) + +// 向Worker子线程发送训练消息 +workerInstance.postMessage({ 'type': 0 }); +// [End call_worker_message] + +// [Start after_destroy_callback] +// Worker线程销毁后,执行onexit回调方法 +workerInstance.onexit = (): void => { + console.info('main thread terminate'); +} +// [End after_destroy_callback] +// [EndExclude process_image_histogram] + +@Concurrent +function imageProcessing(dataSlice: ArrayBuffer): ArrayBuffer { + // 步骤1: 具体的图像处理操作及其他耗时操作 + return dataSlice; +} + +function histogramStatistic(pixelBuffer: ArrayBuffer): void { + // 步骤2: 分成三段并发调度 + let number: number = pixelBuffer.byteLength / 3; + let buffer1: ArrayBuffer = pixelBuffer.slice(0, number); + let buffer2: ArrayBuffer = pixelBuffer.slice(number, number * 2); + let buffer3: ArrayBuffer = pixelBuffer.slice(number * 2); + + let group: taskpool.TaskGroup = new taskpool.TaskGroup(); + group.addTask(imageProcessing, buffer1); + group.addTask(imageProcessing, buffer2); + group.addTask(imageProcessing, buffer3); + + taskpool.execute(group, taskpool.Priority.HIGH).then((ret: Object) => { + // 步骤3: 结果数组汇总处理 + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let buffer: ArrayBuffer = new ArrayBuffer(24); + histogramStatistic(buffer); + this.message = 'success'; + // 销毁Worker线程 + workerInstance.terminate(); + }) + } + .width('100%') + } + .height('100%') + } +} // [End process_image_histogram] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/IoIntensiveTaskDevelopment.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/IoIntensiveTaskDevelopment.ets old mode 100755 new mode 100644 index c3427c184dec9cc82660a1dd5c07dcdd29eac303..9284a713322900fe5999d052ed4592e93e98cbd5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/IoIntensiveTaskDevelopment.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/IoIntensiveTaskDevelopment.ets @@ -1,70 +1,70 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start define_concurrent_function] -import { write } from './write' -import { BusinessError } from '@kit.BasicServicesKit'; -import { taskpool } from '@kit.ArkTS'; -import { common } from '@kit.AbilityKit'; - -@Concurrent -async function concurrentTest(context: common.UIAbilityContext): Promise { - let filePath1: string = context.filesDir + '/path1.txt'; // 应用文件路径 - let filePath2: string = context.filesDir + '/path2.txt'; - // 循环写文件操作 - let fileList: string[] = []; - fileList.push(filePath1); - fileList.push(filePath2) - for (let i: number = 0; i < fileList.length; i++) { - write('Hello World!', fileList[i]).then(() => { - console.info(`Succeeded in writing the file. FileList: ${fileList[i]}`); - }).catch((err: BusinessError) => { - console.error(`Failed to write the file. Code is ${err.code}, message is ${err.message}`) - return false; - }) - } - return true; -} -// [End define_concurrent_function] - -// [Start taskpool_execute_concurrent_function] -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - let context = getContext() as common.UIAbilityContext; - // 使用TaskPool执行包含密集I/O的并发函数 - // 数组较大时,I/O密集型任务任务分发也会抢占UI主线程,需要使用多线程能力 - taskpool.execute(concurrentTest, context).then(() => { - // 调度结果处理 - console.info('taskpool: execute success') - }) - this.message = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_concurrent_function] +import { write } from './write' +import { BusinessError } from '@kit.BasicServicesKit'; +import { taskpool } from '@kit.ArkTS'; +import { common } from '@kit.AbilityKit'; + +@Concurrent +async function concurrentTest(context: common.UIAbilityContext): Promise { + let filePath1: string = context.filesDir + '/path1.txt'; // 应用文件路径 + let filePath2: string = context.filesDir + '/path2.txt'; + // 循环写文件操作 + let fileList: string[] = []; + fileList.push(filePath1); + fileList.push(filePath2) + for (let i: number = 0; i < fileList.length; i++) { + write('Hello World!', fileList[i]).then(() => { + console.info(`Succeeded in writing the file. FileList: ${fileList[i]}`); + }).catch((err: BusinessError) => { + console.error(`Failed to write the file. Code is ${err.code}, message is ${err.message}`) + return false; + }) + } + return true; +} +// [End define_concurrent_function] + +// [Start taskpool_execute_concurrent_function] +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let context = getContext() as common.UIAbilityContext; + // 使用TaskPool执行包含密集I/O的并发函数 + // 数组较大时,I/O密集型任务任务分发也会抢占UI主线程,需要使用多线程能力 + taskpool.execute(concurrentTest, context).then(() => { + // 调度结果处理 + console.info('taskpool: execute success') + }) + this.message = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} // [End taskpool_execute_concurrent_function] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/LongTimeTaskGuide.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/LongTimeTaskGuide.ets old mode 100755 new mode 100644 index fb99d63f4f920a6848f9f45762ec6103fb53c9c5..8258d4a0aa3f12270b44c9067a07c370405db224 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/LongTimeTaskGuide.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/LongTimeTaskGuide.ets @@ -1,78 +1,78 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start taskpool_listen_sensor_data] -import { sensor } from '@kit.SensorServiceKit'; -import { taskpool } from '@kit.ArkTS'; -import { BusinessError, emitter } from '@kit.BasicServicesKit'; - -@Concurrent -async function sensorListener(): Promise { - sensor.on(sensor.SensorId.ACCELEROMETER, (data) => { - emitter.emit({ eventId: 0 }, { data: data }); - }, { interval: 1000000000 }); - - emitter.on({ eventId: 1 }, () => { - sensor.off(sensor.SensorId.ACCELEROMETER) - emitter.off(1) - }) -} - -@Entry -@Component -struct Index { - sensorTask?: taskpool.LongTask - @State addListener: string = 'Add listener'; - @State deleteListener: string = 'Delete listener'; - - build() { - Column() { - Text(this.addListener) - .id('Add listener') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - this.sensorTask = new taskpool.LongTask(sensorListener); - emitter.on({ eventId: 0 }, (data) => { - // Do something here - console.info(`Receive ACCELEROMETER data: {${data.data?.x}, ${data.data?.y}, ${data.data?.z}`); - }); - taskpool.execute(this.sensorTask).then(() => { - console.info('Add listener of ACCELEROMETER success'); - }).catch((e: BusinessError) => { - // Process error - }) - this.addListener = 'success'; - }) - Text(this.deleteListener) - .id('Delete listener') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - emitter.emit({ eventId: 1 }); - emitter.off(0); - if (this.sensorTask != undefined) { - taskpool.terminateTask(this.sensorTask); - } else { - console.error('sensorTask is undefined.'); - } - this.deleteListener = 'success'; - }) - } - .height('100%') - .width('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start taskpool_listen_sensor_data] +import { sensor } from '@kit.SensorServiceKit'; +import { taskpool } from '@kit.ArkTS'; +import { BusinessError, emitter } from '@kit.BasicServicesKit'; + +@Concurrent +async function sensorListener(): Promise { + sensor.on(sensor.SensorId.ACCELEROMETER, (data) => { + emitter.emit({ eventId: 0 }, { data: data }); + }, { interval: 1000000000 }); + + emitter.on({ eventId: 1 }, () => { + sensor.off(sensor.SensorId.ACCELEROMETER) + emitter.off(1) + }) +} + +@Entry +@Component +struct Index { + sensorTask?: taskpool.LongTask + @State addListener: string = 'Add listener'; + @State deleteListener: string = 'Delete listener'; + + build() { + Column() { + Text(this.addListener) + .id('Add listener') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.sensorTask = new taskpool.LongTask(sensorListener); + emitter.on({ eventId: 0 }, (data) => { + // Do something here + console.info(`Receive ACCELEROMETER data: {${data.data?.x}, ${data.data?.y}, ${data.data?.z}`); + }); + taskpool.execute(this.sensorTask).then(() => { + console.info('Add listener of ACCELEROMETER success'); + }).catch((e: BusinessError) => { + // Process error + }) + this.addListener = 'success'; + }) + Text(this.deleteListener) + .id('Delete listener') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + emitter.emit({ eventId: 1 }); + emitter.off(0); + if (this.sensorTask != undefined) { + taskpool.terminateTask(this.sensorTask); + } else { + console.error('sensorTask is undefined.'); + } + this.deleteListener = 'success'; + }) + } + .height('100%') + .width('100%') + } +} // [End taskpool_listen_sensor_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/ResidentTaskGuide.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/ResidentTaskGuide.ets old mode 100755 new mode 100644 index 8acafb33ddc071b035b11428e90b9f2b205dc19e..beed792392ddcc7a3284720f73c92c108e6dbe07 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/ResidentTaskGuide.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/ResidentTaskGuide.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start worker_receive_child_thread_message] -import { worker } from '@kit.ArkTS'; -import resource from '../util/resource'; - -const workerInstance: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/Worker.ets'); - -@Entry -@Component -struct Index { - @State message: string = 'Listener task'; - - build() { - Column() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - workerInstance.postMessage({ type: 'End' }); - workerInstance.onmessage = (event) => { - console.info(resource.resourceToString($r('app.string.Information')), event.data); - } - // 10秒后停止worker - setTimeout(() => { - workerInstance.postMessage({ type: 'stop' }); - }, 10000); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start worker_receive_child_thread_message] +import { worker } from '@kit.ArkTS'; +import resource from '../util/resource'; + +const workerInstance: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/Worker.ets'); + +@Entry +@Component +struct Index { + @State message: string = 'Listener task'; + + build() { + Column() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + workerInstance.postMessage({ type: 'End' }); + workerInstance.onmessage = (event) => { + console.info(resource.resourceToString($r('app.string.Information')), event.data); + } + // 10秒后停止worker + setTimeout(() => { + workerInstance.postMessage({ type: 'stop' }); + }, 10000); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} // [End worker_receive_child_thread_message] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/SyncTaskDevelopment.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/SyncTaskDevelopment.ets old mode 100755 new mode 100644 index 7d8b8ebdf55218611683d6c0306376e0e8b99e1f..af8005c9a9a28cf583679a0df34301a00dfc86b9 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/SyncTaskDevelopment.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/SyncTaskDevelopment.ets @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start taskpool_handle_sync_task] -import { worker } from '@kit.ArkTS'; -import { taskpool } from '@kit.ArkTS'; - -// 步骤1: 定义并发函数,实现业务逻辑 -@Concurrent -async function taskpoolFunc(num: number): Promise { - // 根据业务逻辑实现相应的功能 - let tmpNum: number = num + 100; - return tmpNum; -} - -async function mainFunc(): Promise { - // 步骤2: 创建任务并执行 - let task1: taskpool.Task = new taskpool.Task(taskpoolFunc, 1); - let res1: number = await taskpool.execute(task1) as number; - let task2: taskpool.Task = new taskpool.Task(taskpoolFunc, res1); - let res2: number = await taskpool.execute(task2) as number; - // 步骤3: 对任务返回的结果进行操作 - console.info('taskpool: task res1 is: ' + res1); - console.info('taskpool: task res2 is: ' + res2); -} - -// [Start worker_handle_associated_sync_task] -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(async () => { - mainFunc(); - let w: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker2.ts'); - w.onmessage = (): void => { - // 接收Worker子线程的结果 - } - w.onerror = (): void => { - // 接收Worker子线程的错误信息 - } - // 向Worker子线程发送Set消息 - w.postMessage({ 'type': 0, 'data': 'data' }); - // 向Worker子线程发送Get消息 - w.postMessage({ 'type': 1 }); - // ... - // 根据实际业务,选择时机以销毁线程 - w.terminate(); - this.message = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} -// [End worker_handle_associated_sync_task] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start taskpool_handle_sync_task] +import { worker } from '@kit.ArkTS'; +import { taskpool } from '@kit.ArkTS'; + +// 步骤1: 定义并发函数,实现业务逻辑 +@Concurrent +async function taskpoolFunc(num: number): Promise { + // 根据业务逻辑实现相应的功能 + let tmpNum: number = num + 100; + return tmpNum; +} + +async function mainFunc(): Promise { + // 步骤2: 创建任务并执行 + let task1: taskpool.Task = new taskpool.Task(taskpoolFunc, 1); + let res1: number = await taskpool.execute(task1) as number; + let task2: taskpool.Task = new taskpool.Task(taskpoolFunc, res1); + let res2: number = await taskpool.execute(task2) as number; + // 步骤3: 对任务返回的结果进行操作 + console.info('taskpool: task res1 is: ' + res1); + console.info('taskpool: task res2 is: ' + res2); +} + +// [Start worker_handle_associated_sync_task] +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + mainFunc(); + let w: worker.ThreadWorker = new worker.ThreadWorker('entry/ets/workers/MyWorker2.ts'); + w.onmessage = (): void => { + // 接收Worker子线程的结果 + } + w.onerror = (): void => { + // 接收Worker子线程的错误信息 + } + // 向Worker子线程发送Set消息 + w.postMessage({ 'type': 0, 'data': 'data' }); + // 向Worker子线程发送Get消息 + w.postMessage({ 'type': 1 }); + // ... + // 根据实际业务,选择时机以销毁线程 + w.terminate(); + this.message = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End worker_handle_associated_sync_task] // [End taskpool_handle_sync_task] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/write.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/write.ets old mode 100755 new mode 100644 index 080687d4cd2d4812a3cb048476653fdf8b8da329..ddc321a216050f4aed52a6829213d9e1e4324091 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/write.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/managers/write.ets @@ -1,26 +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. - */ - -// [Start define_concurrent_function] -import { fileIo } from '@kit.CoreFileKit'; - -// 定义并发函数,内部密集调用I/O能力 -// 写入文件的实现 -export async function write(data: string, filePath: string): Promise { - let file: fileIo.File = await fileIo.open(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - await fileIo.write(file.fd, data); - fileIo.close(file); -} -// [End define_concurrent_function] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_concurrent_function] +import { fileIo } from '@kit.CoreFileKit'; + +// 定义并发函数,内部密集调用I/O能力 +// 写入文件的实现 +export async function write(data: string, filePath: string): Promise { + let file: fileIo.File = await fileIo.open(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + await fileIo.write(file.fd, data); + fileIo.close(file); +} +// [End define_concurrent_function] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index de30eb4b1b5ae7e15b8ea8141e26df19fb00d930..723a394265ee2e6bf6d895e9503c4b2d8e49207a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/util/resource.ets @@ -1,25 +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. - */ - -export class P2PManager { - public resourceToString(resource: Resource): string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - +/* + * 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 class P2PManager { + public resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/MyWorker1.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/MyWorker1.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/MyWorker2.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/MyWorker2.ts old mode 100755 new mode 100644 index 305484954b35ec4b9fe5086b44daf1320473086a..bcfa8e43c3e915902b187dfa4b788e2ddc2f55a3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/MyWorker2.ts +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/MyWorker2.ts @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start worker_handle_associated_sync_task] -import { worker, ThreadWorkerGlobalScope, MessageEvents } from '@kit.ArkTS'; -import Handle from './handle'; // 返回句柄 - -let workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -// 无法传输的句柄,所有操作依赖此句柄 -let handler: Handle = new Handle() - -// Worker线程的onmessage逻辑 -workerPort.onmessage = (e: MessageEvents): void => { - switch (e.data.type as number) { - case 0: - handler.syncSet(e.data.data); - workerPort.postMessage('success set'); - break; - case 1: - handler.syncGet(); - workerPort.postMessage('success get'); - break; - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start worker_handle_associated_sync_task] +import { worker, ThreadWorkerGlobalScope, MessageEvents } from '@kit.ArkTS'; +import Handle from './handle'; // 返回句柄 + +let workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +// 无法传输的句柄,所有操作依赖此句柄 +let handler: Handle = new Handle() + +// Worker线程的onmessage逻辑 +workerPort.onmessage = (e: MessageEvents): void => { + switch (e.data.type as number) { + case 0: + handler.syncSet(e.data.data); + workerPort.postMessage('success set'); + break; + case 1: + handler.syncGet(); + workerPort.postMessage('success get'); + break; + } +} // [End worker_handle_associated_sync_task] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/Worker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/Worker.ets old mode 100755 new mode 100644 index 5284d6d013bc07e0e8b84c7d0cc28b2e41d7b989..a6f690fd653d9e1ec03a9ad62126d1368f542981 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/Worker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/Worker.ets @@ -1,43 +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. - */ - -// [Start worker_correspond_main_thread] -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; -let isRunning = false; -workerPort.onmessage = (e: MessageEvents) => { - const type = e.data.type as string; - if (type === 'End') { - if (!isRunning) { - isRunning = true; - // 开始常驻任务 - performTask(); - } - } else if (type === 'stop') { - isRunning = false; - workerPort.close(); // 关闭Worker - } -} -// 模拟常驻任务 -function performTask() { - if (isRunning) { - // 模拟某个长期运行的任务 - workerPort.postMessage('Worker is performing a task'); - // 1秒后再次执行任务 - setTimeout(performTask, 1000); - } - workerPort.postMessage('Worker is stop performing a task'); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start worker_correspond_main_thread] +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; +let isRunning = false; +workerPort.onmessage = (e: MessageEvents) => { + const type = e.data.type as string; + if (type === 'End') { + if (!isRunning) { + isRunning = true; + // 开始常驻任务 + performTask(); + } + } else if (type === 'stop') { + isRunning = false; + workerPort.close(); // 关闭Worker + } +} +// 模拟常驻任务 +function performTask() { + if (isRunning) { + // 模拟某个长期运行的任务 + workerPort.postMessage('Worker is performing a task'); + // 1秒后再次执行任务 + setTimeout(performTask, 1000); + } + workerPort.postMessage('Worker is stop performing a task'); +} // [End worker_correspond_main_thread] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/handle.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/handle.ts old mode 100755 new mode 100644 index 2483125087277d2f7ae1c34b6dee302c94e67c26..0fa31c5bcbc8ae412379fbb77c6a76dccdebc409 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/handle.ts +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/ets/workers/handle.ts @@ -1,26 +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. - */ - -// [Start worker_handle_associated_sync_task] -export default class Handle { - syncGet() { - return; - } - - syncSet(num: number) { - return; - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start worker_handle_associated_sync_task] +export default class Handle { + syncGet() { + return; + } + + syncSet(num: number) { + return; + } +} // [End worker_handle_associated_sync_task] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/ohosTest.md old mode 100755 new mode 100644 index 980b4e8b35ab0ab22175ab9b5c7beefab4fd04b8..8d9208aab91887c11889a03ae4c3794bb9fd55cf --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/ohosTest.md @@ -1,12 +1,12 @@ -# ApplicationMultithreading 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------- | ----------------------------------- | ----------------------------------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| CPU密集型任务开发指导 | 位于CpuIntensiveTaskDevelopment.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| I/O密集型任务开发指导 | 位于IoIntensiveTaskDevelopment.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 同步任务开发指导 | 位于SyncTaskDevelopment.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 长时任务开发指导 | 位于LongTimeTaskGuide.ets | 点击Add listener,然后点击Delete listener | 1秒后页面显示“success” | Pass | Pass | +# ApplicationMultithreading 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ----------------------------------- | ----------------------------------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| CPU密集型任务开发指导 | 位于CpuIntensiveTaskDevelopment.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| I/O密集型任务开发指导 | 位于IoIntensiveTaskDevelopment.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 同步任务开发指导 | 位于SyncTaskDevelopment.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 长时任务开发指导 | 位于LongTimeTaskGuide.ets | 点击Add listener,然后点击Delete listener | 1秒后页面显示“success” | Pass | Pass | | 常驻任务开发指导 | 位于ResidentTaskGuide.ets | 点击Listener task | 1秒后页面显示“success” | Pass | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/screenshots/ApplicationMultithreading_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/screenshots/ApplicationMultithreading_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/screenshots/ApplicationMultithreading_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/ApplicationMultithreading/screenshots/ApplicationMultithreading_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d17398e5219b844609d08a69252aaff8e48e82ad --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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.nativeinterthreadshared", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a7b49bb83054967a50fa349f9711d2bc7867a496 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NativeInterthreadShared" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/README.md new file mode 100644 index 0000000000000000000000000000000000000000..10db80f66cd552eaca795640d4cebdb6be51e359 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/README.md @@ -0,0 +1,78 @@ +# ArkTS C++线程间数据共享场景 + +### 介绍 + +当应用在C++层进行多线程的并发计算时,因为ArkTS的API需要在ArkTS的环境执行,为了避免在非UI主线程每次回调等待UI主线程ArkTS环境中执行的API调用结果,需要在这些C++线程上创建ArkTS执行环境和直接调用API,并且可能需要在C++线程之间对Sendable对象进行共享和操作。 + +为了支持此类场景,需要实现在C++线程上创建调用ArkTS的能力,其次还需要对Sendable对象进行多线程共享和操作。 + +该工程中展示的代码详细描述可查如下链接: + +- [C++线程间数据共享场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/native-interthread-shared.md) + +### 效果预览 + +| 首页 | 执行结果 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击hello world,开始执行。 +2. 执行结果会即时反馈在屏幕中央。 + +### 工程目录 + +``` +entry/src + ├──main + │ ├── cpp + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp // Naitve实现加载ArkTS模块的能力示例代码 + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 暴露接口 + │ │ │ │ ├── oh-package.json5 + │ ├── ets + │ │ ├── entryability + │ │ │ ├── EntryAbility.ets + │ │ ├── entrybackupability + │ │ │ ├── EntryBackupAbility.ets + │ │ ├── pages + │ │ ├── Index.ets // UI主线程发起调用示例代码 + │ │ ├── SendableObjTest.ets // ArkTS文件定义示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖s + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..471250ade0685f26d9ed6c8fb7761e0f0882c8ec --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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", "armeabi-v7a"] + } + }, + "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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c0d30fecd1fcccb3c97501722b9a9fd4b089961a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(MyApplication) + +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) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e14476cf286b4d72905e8d03a3a01b4ae6abae3c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start native_deserialize_sendable] +// [Start native_load_arkts_module] +#include + +#include "napi/native_api.h" + +static void* g_serializationData = nullptr; +static void* CreateEnvAndSendSendable(void*) +{ + // 1. 创建基础运行环境 + napi_env env = nullptr; + napi_status ret = napi_create_ark_runtime(&env); + if (ret != napi_ok) { + std::abort(); + } + // 2. 加载自定义模块,假定SendableObjTest中提供创建sendable对象的方法newSendable + napi_value test = nullptr; + ret = napi_load_module_with_info( + env, "entry/src/main/ets/pages/SendableObjTest", "com.example.myapplication/entry", &test); + if (ret != napi_ok) { + std::abort(); + } + napi_value sendableObjTest = nullptr; + ret = napi_get_named_property(env, test, "SendableObjTest", &sendableObjTest); + if (ret != napi_ok) { + std::abort(); + } + // 3. 使用ArkTS中的newSendable,假设sendableObjTest中有一个函数newSendable能返回sendable对象 + napi_value newSendable = nullptr; + ret = napi_get_named_property(env, sendableObjTest, "newSendable", &newSendable); + if (ret != napi_ok) { + std::abort(); + } + // 4. 调用newSendable函数返回新创建的sendable对象,并保存在result中 + napi_value result = nullptr; + ret = napi_call_function(env, sendableObjTest, newSendable, 0, nullptr, &result); + if (ret != napi_ok) { + std::abort(); + } + // 5. 序列化sendable对象 + napi_value undefined; + napi_get_undefined(env, &undefined); + ret = napi_serialize(env, result, undefined, undefined, &g_serializationData); + if (ret != napi_ok) { + std::abort(); + } + return nullptr; +} +// [End native_load_arkts_module] + +static void* CreateEnvAndReceiveSendable(void*) +{ + // 1. 创建基础运行环境 + napi_env env = nullptr; + napi_status ret = napi_create_ark_runtime(&env); + if (ret != napi_ok) { + std::abort(); + } + // 2. 反序列化获取sendable共享对象,结果保存在result中,这个result就可以通过napi接口进行各种操作了 + napi_value result = nullptr; + ret = napi_deserialize(env, g_serializationData, &result); + if (ret != napi_ok) { + std::abort(); + } + // 3. 删除序列化数据 + ret = napi_delete_serialization_data(env, g_serializationData); + if (ret != napi_ok) { + std::abort(); + } + napi_valuetype valuetype0; + napi_typeof(env, result, &valuetype0); + if (valuetype0 != napi_number) { + std::abort(); + } + int value0; + napi_get_value_int32(env, result, &value0); + // 1024是判断ArkTS返回的结果是否正确 + if (value0 != 1024) { + std::abort(); + } + return nullptr; +} + +static napi_value TestSendSendable([[maybe_unused]] napi_env env, [[maybe_unused]] napi_callback_info info) +{ + std::thread t1(CreateEnvAndSendSendable, nullptr); + t1.join(); + std::thread t2(CreateEnvAndReceiveSendable, nullptr); + t2.join(); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { { "testSendSendable", nullptr, TestSendSendable, 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); +} +// [End native_deserialize_sendable] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f0e869789e35447127f450c8f0d5166ff5a8b010 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start native_deserialize_sendable] +export const testSendSendable: () => void; +// [End native_deserialize_sendable] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a650926654edf9cd7c69ef1f2386071d9bf83685 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start main_thread_init_call] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; +import { SendableObjTest } from './SendableObjTest' + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + SendableObjTest.newSendable() + hilog.info(0x0000, 'testTag', 'Test send Sendable begin'); + testNapi.testSendSendable(); + hilog.info(0x0000, 'testTag', 'Test send Sendable end'); + this.message = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End main_thread_init_call] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/SendableObjTest.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/SendableObjTest.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/SendableObjTest.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/SendableObjTest.ets index 81525e7578d43334d9a54ac502a7bb05a011872c..4980f9ffd021602856be29be6220415be85d337d --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/SendableObjTest.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/SendableObjTest.ets @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start arkts_define_obj] -@Sendable -export class SendableObjTest { - static newSendable() { - return 1024; - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start arkts_define_obj] +@Sendable +export class SendableObjTest { + static newSendable() { + return 1024; + } +} // [End arkts_define_obj] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..87004cca5e21188fd339fe1f71be39da07fbd800 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/ohosTest.md @@ -0,0 +1,8 @@ +# NativeInterthreadShared 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| C++线程间数据共享场景 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_1.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_1.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_2.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/screenshots/NativeInterthreadShared_2.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/app.json5 old mode 100755 new mode 100644 index ad1c26ecc32b1c99b714fa0a4fa85749c23e6e18..84ee501b79a89851d39dea77e031b35abf128f01 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/app.json5 @@ -1,25 +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.practicalcases", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.practicalcases", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 73a3c2a9cb2e2010b5e4990534a901b0208ed627..1f9360e43353b8d6c9c1f2d8911e88ae5767d203 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "PracticalCases" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "PracticalCases" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/README.md old mode 100755 new mode 100644 index 5c89060bdaeb1c3591b8d424d7ddac65a1f14ef1..28a3f6b9df71124393e115771e396d926e3c0df6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/README.md @@ -1,110 +1,110 @@ -# ArkTS 应用多线程开发实践案例 - -### 介绍 - -#### 使用TaskPool进行频繁数据库操作 - -对于需要频繁数据库操作的场景,由于读写数据库存在耗时,因此推荐在子线程中操作,避免阻塞UI线程。 - -通过ArkTS提供的TaskPool能力,可以将数据库操作任务移到子线程中。 - -#### 业务模块并发加载场景 - -在应用启动过程中,会有多个业务模块需要加载,例如应用的定位、打车、导航等不同的模块,如果全部在UI主线程初始化,则会严重影响冷启动耗时。此时需要在不同子线程并行化加载这些模块功能,降低启动耗时。 - -通过使用ArkTS提供的TaskPool能力,可以将不同业务初始化任务移到子线程中,业务模块通过下沉C++实现成[NativeBinding对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/transferabled-object.md)、或者在ArkTS层定义[Sendable对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md),就可以将初始化的模块返回UI主线程调用,实现如下。 - -#### 全局配置项功能场景 - -对于需要使用进程单例的场景,例如不同并发实例间需要数据保持一致的全局配置项业务,可以采用共享模块来实现。 - -#### ArkUI数据更新场景 - -当需要网络下载或者本地生成的数据需要发送到UI线程进行展示时,因为ArkUI的标注和[@Sendable装饰器](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md#sendable装饰器)不能同时修饰变量和对象,所以对于此类场景,需要使用[makeObserved](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/quick-start/arkts-new-makeObserved.md)在ArkUI中导入可观察的Sendable共享数据。 - -#### ArkUI瀑布流渲染场景 - -此处提供使用任务池[TaskPool](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-taskpool.md)提升[WaterFlow瀑布流](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-container-waterflow.md)渲染性能的开发指导。UI线程查询数据库数据,并将数据渲染到瀑布流组件,数据过大时会导致UI线程长时间等待,影响用户体验。因此,可以将数据查询操作放到子线程中,并通过TaskPool的接口返回数据给UI线程。 - -该工程中展示的代码详细描述可查如下链接: - -- [批量数据写数据库场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/batch-database-operations-guide.md) -- [业务模块并发加载场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/concurrent-loading-modules-guide.md) -- [全局配置项功能场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/global-configuration-guide.md) -- [ArkUI数据更新场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/makeobserved-sendable.md) -- [ArkUI瀑布流渲染场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/taskpool-waterflow.md) - -### 效果预览 - -| 首页 | 执行及结果 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── ConcurrentLoadingModulesGuide.ets // 业务模块并发加载场景示例代码 - │ │ ├── Config.ets // 全局配置项功能场景资源代码 - │ │ ├── GlobalConfigurationGuide.ets // 全局配置项功能场景示例代码 - │ │ ├── MakeobservedSendable.ets // ArkUI数据更新场景示例代码 - │ │ ├── Mock.ets // ArkUI瀑布流渲染场景资源代码 - │ │ ├── SendableData.ets // ArkUI数据更新场景资源代码 - │ │ ├── SharedValuesBucket.ets // 使用Sendable进行大容量数据库操作 - │ │ ├── UsingSendable.ets // 使用Sendable进行大容量数据库操作示例代码 - │ │ ├── UsingTaskPool.ets // 使用TaskPool进行频繁数据库操作示例代码 - │ │ ├── WaterfallRendering.ets // ArkUI瀑布流渲染场景示例代码资源代码 - │ │ ├── WaterFlowDataSource.ets // ArkUI瀑布流渲染场景资源代码 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── sdk - │ │ ├── Calculator.ets // 业务模块并发加载场景资源代码 - │ │ ├── TimerSdk.ets // 业务模块并发加载场景资源代码 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS 应用多线程开发实践案例 + +### 介绍 + +#### 使用TaskPool进行频繁数据库操作 + +对于需要频繁数据库操作的场景,由于读写数据库存在耗时,因此推荐在子线程中操作,避免阻塞UI线程。 + +通过ArkTS提供的TaskPool能力,可以将数据库操作任务移到子线程中。 + +#### 业务模块并发加载场景 + +在应用启动过程中,会有多个业务模块需要加载,例如应用的定位、打车、导航等不同的模块,如果全部在UI主线程初始化,则会严重影响冷启动耗时。此时需要在不同子线程并行化加载这些模块功能,降低启动耗时。 + +通过使用ArkTS提供的TaskPool能力,可以将不同业务初始化任务移到子线程中,业务模块通过下沉C++实现成[NativeBinding对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/transferabled-object.md)、或者在ArkTS层定义[Sendable对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md),就可以将初始化的模块返回UI主线程调用,实现如下。 + +#### 全局配置项功能场景 + +对于需要使用进程单例的场景,例如不同并发实例间需要数据保持一致的全局配置项业务,可以采用共享模块来实现。 + +#### ArkUI数据更新场景 + +当需要网络下载或者本地生成的数据需要发送到UI线程进行展示时,因为ArkUI的标注和[@Sendable装饰器](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md#sendable装饰器)不能同时修饰变量和对象,所以对于此类场景,需要使用[makeObserved](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/quick-start/arkts-new-makeObserved.md)在ArkUI中导入可观察的Sendable共享数据。 + +#### ArkUI瀑布流渲染场景 + +此处提供使用任务池[TaskPool](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-taskpool.md)提升[WaterFlow瀑布流](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-container-waterflow.md)渲染性能的开发指导。UI线程查询数据库数据,并将数据渲染到瀑布流组件,数据过大时会导致UI线程长时间等待,影响用户体验。因此,可以将数据查询操作放到子线程中,并通过TaskPool的接口返回数据给UI线程。 + +该工程中展示的代码详细描述可查如下链接: + +- [批量数据写数据库场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/batch-database-operations-guide.md) +- [业务模块并发加载场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/concurrent-loading-modules-guide.md) +- [全局配置项功能场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/global-configuration-guide.md) +- [ArkUI数据更新场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/makeobserved-sendable.md) +- [ArkUI瀑布流渲染场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/taskpool-waterflow.md) + +### 效果预览 + +| 首页 | 执行及结果 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── ConcurrentLoadingModulesGuide.ets // 业务模块并发加载场景示例代码 + │ │ ├── Config.ets // 全局配置项功能场景资源代码 + │ │ ├── GlobalConfigurationGuide.ets // 全局配置项功能场景示例代码 + │ │ ├── MakeobservedSendable.ets // ArkUI数据更新场景示例代码 + │ │ ├── Mock.ets // ArkUI瀑布流渲染场景资源代码 + │ │ ├── SendableData.ets // ArkUI数据更新场景资源代码 + │ │ ├── SharedValuesBucket.ets // 使用Sendable进行大容量数据库操作 + │ │ ├── UsingSendable.ets // 使用Sendable进行大容量数据库操作示例代码 + │ │ ├── UsingTaskPool.ets // 使用TaskPool进行频繁数据库操作示例代码 + │ │ ├── WaterfallRendering.ets // ArkUI瀑布流渲染场景示例代码资源代码 + │ │ ├── WaterFlowDataSource.ets // ArkUI瀑布流渲染场景资源代码 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── sdk + │ │ ├── Calculator.ets // 业务模块并发加载场景资源代码 + │ │ ├── TimerSdk.ets // 业务模块并发加载场景资源代码 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/ConcurrentLoadingModulesGuide.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/ConcurrentLoadingModulesGuide.ets old mode 100755 new mode 100644 index d28b227f7491cdeb56488d2d628a5f6473ee63a2..89275d0f5878bb4a9ff7447e322e0b06777539ec --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/ConcurrentLoadingModulesGuide.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/ConcurrentLoadingModulesGuide.ets @@ -1,97 +1,97 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start distribute_child_thread] -import { Calculator } from '../sdk/Calculator'; -import { TimerSdk } from '../sdk/TimerSdk'; -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -function initCalculator(): Calculator { - return Calculator.init(); -} - -@Concurrent -function initTimerSdk(): TimerSdk { - return TimerSdk.init(); -} - -@Entry -@Component -struct Index { - @State calculateAdd: string = 'calculate add'; - @State showHistory: string = 'show history'; - @State countdown: string = 'countdown'; - calc?: Calculator; - timer?: TimerSdk; - - aboutToAppear(): void { - taskpool.execute(initCalculator).then((ret) => { - this.calc = ret as Calculator; - }) - taskpool.execute(initTimerSdk).then((ret) => { - this.timer = ret as TimerSdk; - }) - } - - build() { - Row() { - Column() { - Text(this.calculateAdd) - .id('add') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - let result = this.calc?.add(1, 2) - console.info(`Result is ${result}`) - this.calculateAdd = 'success'; - }) - Text(this.showHistory) - .id('show') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - this.calc?.showHistory(); - this.showHistory = 'success'; - }) - Text(this.countdown) - .id('get') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - console.info(`Timer start`); - await this.timer?.Countdown(1000); - console.info(`Timer end`); - this.countdown = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start distribute_child_thread] +import { Calculator } from '../sdk/Calculator'; +import { TimerSdk } from '../sdk/TimerSdk'; +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +function initCalculator(): Calculator { + return Calculator.init(); +} + +@Concurrent +function initTimerSdk(): TimerSdk { + return TimerSdk.init(); +} + +@Entry +@Component +struct Index { + @State calculateAdd: string = 'calculate add'; + @State showHistory: string = 'show history'; + @State countdown: string = 'countdown'; + calc?: Calculator; + timer?: TimerSdk; + + aboutToAppear(): void { + taskpool.execute(initCalculator).then((ret) => { + this.calc = ret as Calculator; + }) + taskpool.execute(initTimerSdk).then((ret) => { + this.timer = ret as TimerSdk; + }) + } + + build() { + Row() { + Column() { + Text(this.calculateAdd) + .id('add') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + let result = this.calc?.add(1, 2) + console.info(`Result is ${result}`) + this.calculateAdd = 'success'; + }) + Text(this.showHistory) + .id('show') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + this.calc?.showHistory(); + this.showHistory = 'success'; + }) + Text(this.countdown) + .id('get') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + console.info(`Timer start`); + await this.timer?.Countdown(1000); + console.info(`Timer end`); + this.countdown = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} // [End distribute_child_thread] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Config.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Config.ets old mode 100755 new mode 100644 index d96061ebb11a1bf82b12b17f5ef2d429990dfc00..17b26eb4438df265ffec2cde12a65069690d5fbe --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Config.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Config.ets @@ -1,68 +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. - */ - -// [Start global_config] -import { ArkTSUtils } from '@kit.ArkTS'; - -'use shared' - -@Sendable -class Config { - public lock: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock; - public isLogin: boolean = false; - public loginUser?: string; - public wifiOn: boolean = false; - - async login(user: string) { - return this.lock.lockAsync(() => { - this.isLogin = true; - this.loginUser = user; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE) - } - - async logout(user?: string) { - return this.lock.lockAsync(() => { - this.isLogin = false; - this.loginUser = ''; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE) - } - - async getIsLogin(): Promise { - return this.lock.lockAsync(() => { - return this.isLogin; - }, ArkTSUtils.locks.AsyncLockMode.SHARED) - } - - async getUser(): Promise { - return this.lock.lockAsync(() => { - return this.loginUser!; - }, ArkTSUtils.locks.AsyncLockMode.SHARED) - } - - async setWifiState(state: boolean) { - return this.lock.lockAsync(() => { - this.wifiOn = state; - }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE) - } - - async isWifiOn() { - return this.lock.lockAsync(() => { - return this.wifiOn; - }, ArkTSUtils.locks.AsyncLockMode.SHARED) - } -} - -export let config = new Config(); +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start global_config] +import { ArkTSUtils } from '@kit.ArkTS'; + +'use shared' + +@Sendable +class Config { + public lock: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock; + public isLogin: boolean = false; + public loginUser?: string; + public wifiOn: boolean = false; + + async login(user: string) { + return this.lock.lockAsync(() => { + this.isLogin = true; + this.loginUser = user; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE) + } + + async logout(user?: string) { + return this.lock.lockAsync(() => { + this.isLogin = false; + this.loginUser = ''; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE) + } + + async getIsLogin(): Promise { + return this.lock.lockAsync(() => { + return this.isLogin; + }, ArkTSUtils.locks.AsyncLockMode.SHARED) + } + + async getUser(): Promise { + return this.lock.lockAsync(() => { + return this.loginUser!; + }, ArkTSUtils.locks.AsyncLockMode.SHARED) + } + + async setWifiState(state: boolean) { + return this.lock.lockAsync(() => { + this.wifiOn = state; + }, ArkTSUtils.locks.AsyncLockMode.EXCLUSIVE) + } + + async isWifiOn() { + return this.lock.lockAsync(() => { + return this.wifiOn; + }, ArkTSUtils.locks.AsyncLockMode.SHARED) + } +} + +export let config = new Config(); // [End global_config] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/GlobalConfigurationGuide.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/GlobalConfigurationGuide.ets old mode 100755 new mode 100644 index cc6e65b43ed0a58116e98155dcb92214a0f9148e..7dae8a9ab8069a63fddc4d64745f19aa01873385 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/GlobalConfigurationGuide.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/GlobalConfigurationGuide.ets @@ -1,127 +1,127 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start access_global_config] -import { config } from './Config'; -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -async function download() { - if (!await config.isWifiOn()) { - console.info('wifi is off'); - return false; - } - if (!await config.getIsLogin()) { - console.info('not login'); - return false; - } - console.info(`User[${await config.getUser()}] start download ...`); - return true; -} - -@Entry -@Component -struct Index { - @State message: string = 'not login'; - @State wifiState: string = 'wifi off'; - @State downloadResult: string = ''; - input: string = ''; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - TextInput({ placeholder: '请输入用户名' }) - .id('textInput') - .fontSize(20) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onChange((value) => { - this.input = value; - }) - Text('login') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - if (!await config.getIsLogin() && this.input) { - this.message = 'login: ' + this.input; - config.login(this.input); - } - }) - .backgroundColor(0xcccccc) - Text('logout') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - if (await config.getIsLogin()) { - this.message = 'not login'; - config.logout(); - } - }) - .backgroundColor(0xcccccc) - Text(this.wifiState) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - Toggle({ type: ToggleType.Switch }) - .onChange(async (isOn: boolean) => { - await config.setWifiState(isOn) - this.wifiState = isOn ? 'wifi on' : 'wifi off'; - }) - Text('download') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - let ret = await taskpool.execute(download); - this.downloadResult = ret ? 'download success' : 'download fail'; - }) - Text(this.downloadResult) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start access_global_config] +import { config } from './Config'; +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +async function download() { + if (!await config.isWifiOn()) { + console.info('wifi is off'); + return false; + } + if (!await config.getIsLogin()) { + console.info('not login'); + return false; + } + console.info(`User[${await config.getUser()}] start download ...`); + return true; +} + +@Entry +@Component +struct Index { + @State message: string = 'not login'; + @State wifiState: string = 'wifi off'; + @State downloadResult: string = ''; + input: string = ''; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + TextInput({ placeholder: '请输入用户名' }) + .id('textInput') + .fontSize(20) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onChange((value) => { + this.input = value; + }) + Text('login') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + if (!await config.getIsLogin() && this.input) { + this.message = 'login: ' + this.input; + config.login(this.input); + } + }) + .backgroundColor(0xcccccc) + Text('logout') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + if (await config.getIsLogin()) { + this.message = 'not login'; + config.logout(); + } + }) + .backgroundColor(0xcccccc) + Text(this.wifiState) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + Toggle({ type: ToggleType.Switch }) + .onChange(async (isOn: boolean) => { + await config.setWifiState(isOn) + this.wifiState = isOn ? 'wifi on' : 'wifi off'; + }) + Text('download') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + let ret = await taskpool.execute(download); + this.downloadResult = ret ? 'download success' : 'download fail'; + }) + Text(this.downloadResult) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + .width('100%') + } + .height('100%') + } +} // [End access_global_config] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/MakeobservedSendable.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/MakeobservedSendable.ets old mode 100755 new mode 100644 index d6343f2db608e99e829b2f8b7c26b99ea8593e02..f35e630a983f6ad4b9f26b743dd6ab0bde87c0fc --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/MakeobservedSendable.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/MakeobservedSendable.ets @@ -1,59 +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. - */ - -// [Start update_arkui_data] -import { taskpool } from '@kit.ArkTS'; -import { SendableData } from './SendableData'; -import { UIUtils } from '@kit.ArkUI'; - -@Concurrent -function threadGetData(param: string): SendableData { - // 在子线程处理数据 - let ret = new SendableData(); - console.info(`Concurrent threadGetData, param ${param}`); - ret.name = param + '-o'; - ret.age = Math.floor(Math.random() * 40); - ret.likes = Math.floor(Math.random() * 100); - return ret; -} - -@Entry -@ComponentV2 -struct Index { - // 通过makeObserved给普通对象或是Sendable对象添加可观察能力 - @Local send: SendableData = UIUtils.makeObserved(new SendableData()); - - build() { - Column() { - Text(this.send.name) - Button('change name').onClick(() => { - // 可以观察到属性的改变 - this.send.name += '0'; - }) - .id('change name') - Button('task').onClick(() => { - // 将待执行的函数放入taskpool内部任务队列等待,等待分发到工作线程执行。 - // 因为数据的构建和处理可以在子线程中完成,但有观察能力的数据不能传给子线程,只有在UI主线程里才可以操作可观察的数据。 - // 所以这里只是将`this.send`的属性`name`传给子线程操作。 - taskpool.execute(threadGetData, this.send.name).then(val => { - // 和@Local一起使用,可以观察this.send的变化 - this.send = UIUtils.makeObserved(val as SendableData); - }) - }) - .id('task') - } - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start update_arkui_data] +import { taskpool } from '@kit.ArkTS'; +import { SendableData } from './SendableData'; +import { UIUtils } from '@kit.ArkUI'; + +@Concurrent +function threadGetData(param: string): SendableData { + // 在子线程处理数据 + let ret = new SendableData(); + console.info(`Concurrent threadGetData, param ${param}`); + ret.name = param + '-o'; + ret.age = Math.floor(Math.random() * 40); + ret.likes = Math.floor(Math.random() * 100); + return ret; +} + +@Entry +@ComponentV2 +struct Index { + // 通过makeObserved给普通对象或是Sendable对象添加可观察能力 + @Local send: SendableData = UIUtils.makeObserved(new SendableData()); + + build() { + Column() { + Text(this.send.name) + Button('change name').onClick(() => { + // 可以观察到属性的改变 + this.send.name += '0'; + }) + .id('change name') + Button('task').onClick(() => { + // 将待执行的函数放入taskpool内部任务队列等待,等待分发到工作线程执行。 + // 因为数据的构建和处理可以在子线程中完成,但有观察能力的数据不能传给子线程,只有在UI主线程里才可以操作可观察的数据。 + // 所以这里只是将`this.send`的属性`name`传给子线程操作。 + taskpool.execute(threadGetData, this.send.name).then(val => { + // 和@Local一起使用,可以观察this.send的变化 + this.send = UIUtils.makeObserved(val as SendableData); + }) + }) + .id('task') + } + } +} // [End update_arkui_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Mock.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Mock.ets old mode 100755 new mode 100644 index 575da5e6cf792dda20c2a4c177ffbd2e1b7de38c..6a170811d42390b29d24c12f14ae3a3e160bd676 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Mock.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/Mock.ets @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start query_database_return_main_thread] -import { taskpool } from '@kit.ArkTS'; -import { fillImg } from './WaterfallRendering'; - -@Concurrent -function query() { - console.info('TaskPoolTest-this is query'); - let result = new Array(33); - for (let i = 0; i < 33; i++) { - result[i] = 'Image' + i; - } - taskpool.Task.sendData(result); -} - -export function getImgFromDB() { - //此处模拟查询数据库,并返回数据 - let task = new taskpool.Task(query); - task.onReceiveData(fillImg); - taskpool.execute(task); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start query_database_return_main_thread] +import { taskpool } from '@kit.ArkTS'; +import { fillImg } from './WaterfallRendering'; + +@Concurrent +function query() { + console.info('TaskPoolTest-this is query'); + let result = new Array(33); + for (let i = 0; i < 33; i++) { + result[i] = 'Image' + i; + } + taskpool.Task.sendData(result); +} + +export function getImgFromDB() { + //此处模拟查询数据库,并返回数据 + let task = new taskpool.Task(query); + task.onReceiveData(fillImg); + taskpool.execute(task); +} // [End query_database_return_main_thread] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SendableData.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SendableData.ets old mode 100755 new mode 100644 index 257afb98c3a77d2b3ffad25c29b706670b5c39a9..017a3125faa3548f3acf434187b964e25d1a0b7f --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SendableData.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SendableData.ets @@ -1,25 +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. - */ - -// [Start define_sendable_class] -@Sendable -export class SendableData { - public name: string = 'Tom'; - public age: number = 20; - public gender: number = 1; - public likes: number = 1; - public follow: boolean = false; -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_sendable_class] +@Sendable +export class SendableData { + public name: string = 'Tom'; + public age: number = 20; + public gender: number = 1; + public likes: number = 1; + public follow: boolean = false; +} // [End define_sendable_class] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SharedValuesBucket.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SharedValuesBucket.ets old mode 100755 new mode 100644 index e8b0c3eb414717d74ea55f86327b9ff2a05c5e44..aef09be5aa794a4416322ae6825e7809d89145b6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SharedValuesBucket.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/SharedValuesBucket.ets @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start define_data_format] -export interface IValueBucket { - id: number; - name: string; - age: number; - salary: number; -} - -@Sendable -export class SharedValuesBucket implements IValueBucket { - public id: number = 0; - public name: string = ''; - public age: number = 0; - public salary: number = 0; - - constructor(v: IValueBucket) { - this.id = v.id; - this.name = v.name; - this.age = v.age; - this.salary = v.salary; - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_data_format] +export interface IValueBucket { + id: number; + name: string; + age: number; + salary: number; +} + +@Sendable +export class SharedValuesBucket implements IValueBucket { + public id: number = 0; + public name: string = ''; + public age: number = 0; + public salary: number = 0; + + constructor(v: IValueBucket) { + this.id = v.id; + this.name = v.name; + this.age = v.age; + this.salary = v.salary; + } +} // [End define_data_format] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingSendable.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingSendable.ets old mode 100755 new mode 100644 index 128dfa970b65113e55f6f4b1bbd7c8a3a761767c..9afb2619264155dfb59dbb2528ab81b6faee57cb --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingSendable.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingSendable.ets @@ -1,145 +1,145 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start taskpool_frequently_operate_database] -import { relationalStore, ValuesBucket } from '@kit.ArkData'; -import { collections, taskpool } from '@kit.ArkTS'; -import { IValueBucket, SharedValuesBucket } from './SharedValuesBucket'; - -@Concurrent -async function create(context: Context) { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); - console.info(`Create Store.db successfully!`); - - // 创建表 - const CREATE_TABLE_SQL = 'CREATE TABLE IF NOT EXISTS test (' + - 'id INTEGER PRIMARY KEY AUTOINCREMENT, ' + - 'name TEXT NOT NULL, ' + - 'age INTEGER, ' + - 'salary REAL, ' + - 'blobType BLOB)'; - await store.executeSql(CREATE_TABLE_SQL); - console.info(`Create table test successfully!`); -} - -@Concurrent -async function insert(context: Context, valueBucketArray: Array) { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); - console.info(`Create Store.db successfully!`); - - // 数据插入 - await store.batchInsert('test', valueBucketArray as Object as Array); -} - -@Concurrent -async function query(context: Context): Promise> { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); - console.info(`Create Store.db successfully!`); - - // 获取结果集 - let predicates: relationalStore.RdbPredicates = new relationalStore.RdbPredicates('test'); - let resultSet = await store.query(predicates); // 查询所有数据 - console.info(`Query data successfully! row count:${resultSet.rowCount}`); - let index = 0; - let result = new Array(resultSet.rowCount); - resultSet.goToFirstRow(); - do { - result[index++] = resultSet.getRow(); - } while (resultSet.goToNextRow()); - resultSet.close(); - return result; -} - -@Concurrent -async function clear(context: Context) { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - await relationalStore.deleteRdbStore(context, CONFIG); - console.info(`Delete Store.db successfully!`); -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - let context = getContext(this); - - // 数据准备 - const count = 5 - let valueBucketArray = collections.Array.create(count, undefined); - for (let i = 0; i < count; i++) { - let v: IValueBucket = { - id: i, - name: 'zhangsan' + i, - age: 20, - salary: 5000 + 50 * i - }; - valueBucketArray[i] = new SharedValuesBucket(v); - } - await taskpool.execute(create, context); - await taskpool.execute(insert, context, valueBucketArray); - let index = 0; - let ret: collections.Array = - await taskpool.execute(query, context) as collections.Array; - for (let v of ret.values()) { - console.info(`Row[${index}].id = ${v.id}`) - console.info(`Row[${index}].name = ${v.name}`) - console.info(`Row[${index}].age = ${v.age}`) - console.info(`Row[${index}].salary = ${v.salary}`) - index++ - }; - await taskpool.execute(clear, context); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End taskpool_frequently_operate_database] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start taskpool_frequently_operate_database] +import { relationalStore, ValuesBucket } from '@kit.ArkData'; +import { collections, taskpool } from '@kit.ArkTS'; +import { IValueBucket, SharedValuesBucket } from './SharedValuesBucket'; + +@Concurrent +async function create(context: Context) { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); + console.info(`Create Store.db successfully!`); + + // 创建表 + const CREATE_TABLE_SQL = 'CREATE TABLE IF NOT EXISTS test (' + + 'id INTEGER PRIMARY KEY AUTOINCREMENT, ' + + 'name TEXT NOT NULL, ' + + 'age INTEGER, ' + + 'salary REAL, ' + + 'blobType BLOB)'; + await store.executeSql(CREATE_TABLE_SQL); + console.info(`Create table test successfully!`); +} + +@Concurrent +async function insert(context: Context, valueBucketArray: Array) { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); + console.info(`Create Store.db successfully!`); + + // 数据插入 + await store.batchInsert('test', valueBucketArray as Object as Array); +} + +@Concurrent +async function query(context: Context): Promise> { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); + console.info(`Create Store.db successfully!`); + + // 获取结果集 + let predicates: relationalStore.RdbPredicates = new relationalStore.RdbPredicates('test'); + let resultSet = await store.query(predicates); // 查询所有数据 + console.info(`Query data successfully! row count:${resultSet.rowCount}`); + let index = 0; + let result = new Array(resultSet.rowCount); + resultSet.goToFirstRow(); + do { + result[index++] = resultSet.getRow(); + } while (resultSet.goToNextRow()); + resultSet.close(); + return result; +} + +@Concurrent +async function clear(context: Context) { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + await relationalStore.deleteRdbStore(context, CONFIG); + console.info(`Delete Store.db successfully!`); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + let context = getContext(this); + + // 数据准备 + const count = 5 + let valueBucketArray = collections.Array.create(count, undefined); + for (let i = 0; i < count; i++) { + let v: IValueBucket = { + id: i, + name: 'zhangsan' + i, + age: 20, + salary: 5000 + 50 * i + }; + valueBucketArray[i] = new SharedValuesBucket(v); + } + await taskpool.execute(create, context); + await taskpool.execute(insert, context, valueBucketArray); + let index = 0; + let ret: collections.Array = + await taskpool.execute(query, context) as collections.Array; + for (let v of ret.values()) { + console.info(`Row[${index}].id = ${v.id}`) + console.info(`Row[${index}].name = ${v.name}`) + console.info(`Row[${index}].age = ${v.age}`) + console.info(`Row[${index}].salary = ${v.salary}`) + index++ + }; + await taskpool.execute(clear, context); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End taskpool_frequently_operate_database] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingTaskPool.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingTaskPool.ets old mode 100755 new mode 100644 index 903ef2869d15baa85128ad72d090b7bfb91da3af..f8c31644e52fc7393bddab516d76d81b97baa063 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingTaskPool.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/UsingTaskPool.ets @@ -1,143 +1,143 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start operate_child_thread_data] -import { relationalStore, ValuesBucket } from '@kit.ArkData'; -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -async function create(context: Context) { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); - console.info(`Create Store.db successfully!`); - - // 创建表 - const CREATE_TABLE_SQL = 'CREATE TABLE IF NOT EXISTS test (' + - 'id INTEGER PRIMARY KEY AUTOINCREMENT, ' + - 'name TEXT NOT NULL, ' + - 'age INTEGER, ' + - 'salary REAL, ' + - 'blobType BLOB)'; - await store.executeSql(CREATE_TABLE_SQL); - console.info(`Create table test successfully!`); -} - -@Concurrent -async function insert(context: Context, valueBucketArray: Array) { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); - console.info(`Create Store.db successfully!`); - - // 数据插入 - await store.batchInsert('test', valueBucketArray as Object as Array); -} - -@Concurrent -async function query(context: Context): Promise> { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); - console.info(`Create Store.db successfully!`); - - // 获取结果集 - let predicates: relationalStore.RdbPredicates = new relationalStore.RdbPredicates('test'); - let resultSet = await store.query(predicates); // 查询所有数据 - console.info(`Query data successfully! row count:${resultSet.rowCount}`); - let index = 0; - let result = new Array(resultSet.rowCount) - resultSet.goToFirstRow() - do { - result[index++] = resultSet.getRow(); - } while (resultSet.goToNextRow()); - resultSet.close(); - return result; -} - -@Concurrent -async function clear(context: Context) { - const CONFIG: relationalStore.StoreConfig = { - name: 'Store.db', - securityLevel: relationalStore.SecurityLevel.S1, - }; - - // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name - await relationalStore.deleteRdbStore(context, CONFIG); - console.info(`Delete Store.db successfully!`); -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - let context = getContext(this); - - // 数据准备 - const count = 5 - let valueBucketArray = new Array(count); - for (let i = 0; i < count; i++) { - let v: relationalStore.ValuesBucket = { - id: i, - name: 'zhangsan' + i, - age: 20, - salary: 5000 + 50 * i - }; - valueBucketArray[i] = v; - } - await taskpool.execute(create, context); - await taskpool.execute(insert, context, valueBucketArray); - let index = 0; - let ret = await taskpool.execute(query, context) as Array; - for (let v of ret) { - console.info(`Row[${index}].id = ${v.id}`) - console.info(`Row[${index}].name = ${v.name}`) - console.info(`Row[${index}].age = ${v.age}`) - console.info(`Row[${index}].salary = ${v.salary}`) - index++ - }; - await taskpool.execute(clear, context); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End operate_child_thread_data] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start operate_child_thread_data] +import { relationalStore, ValuesBucket } from '@kit.ArkData'; +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +async function create(context: Context) { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); + console.info(`Create Store.db successfully!`); + + // 创建表 + const CREATE_TABLE_SQL = 'CREATE TABLE IF NOT EXISTS test (' + + 'id INTEGER PRIMARY KEY AUTOINCREMENT, ' + + 'name TEXT NOT NULL, ' + + 'age INTEGER, ' + + 'salary REAL, ' + + 'blobType BLOB)'; + await store.executeSql(CREATE_TABLE_SQL); + console.info(`Create table test successfully!`); +} + +@Concurrent +async function insert(context: Context, valueBucketArray: Array) { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); + console.info(`Create Store.db successfully!`); + + // 数据插入 + await store.batchInsert('test', valueBucketArray as Object as Array); +} + +@Concurrent +async function query(context: Context): Promise> { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + let store: relationalStore.RdbStore = await relationalStore.getRdbStore(context, CONFIG); + console.info(`Create Store.db successfully!`); + + // 获取结果集 + let predicates: relationalStore.RdbPredicates = new relationalStore.RdbPredicates('test'); + let resultSet = await store.query(predicates); // 查询所有数据 + console.info(`Query data successfully! row count:${resultSet.rowCount}`); + let index = 0; + let result = new Array(resultSet.rowCount) + resultSet.goToFirstRow() + do { + result[index++] = resultSet.getRow(); + } while (resultSet.goToNextRow()); + resultSet.close(); + return result; +} + +@Concurrent +async function clear(context: Context) { + const CONFIG: relationalStore.StoreConfig = { + name: 'Store.db', + securityLevel: relationalStore.SecurityLevel.S1, + }; + + // 默认数据库文件路径为 context.databaseDir + rdb + StoreConfig.name + await relationalStore.deleteRdbStore(context, CONFIG); + console.info(`Delete Store.db successfully!`); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + let context = getContext(this); + + // 数据准备 + const count = 5 + let valueBucketArray = new Array(count); + for (let i = 0; i < count; i++) { + let v: relationalStore.ValuesBucket = { + id: i, + name: 'zhangsan' + i, + age: 20, + salary: 5000 + 50 * i + }; + valueBucketArray[i] = v; + } + await taskpool.execute(create, context); + await taskpool.execute(insert, context, valueBucketArray); + let index = 0; + let ret = await taskpool.execute(query, context) as Array; + for (let v of ret) { + console.info(`Row[${index}].id = ${v.id}`) + console.info(`Row[${index}].name = ${v.name}`) + console.info(`Row[${index}].age = ${v.age}`) + console.info(`Row[${index}].salary = ${v.salary}`) + index++ + }; + await taskpool.execute(clear, context); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End operate_child_thread_data] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterFlowDataSource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterFlowDataSource.ets old mode 100755 new mode 100644 index 95d9ebdbffba2bbdadc81d720e99e98bb75dbb32..ea630b8ba1019a8d0e1a165fb7f50f9b75e0af2c --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterFlowDataSource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterFlowDataSource.ets @@ -1,144 +1,144 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start encapsulate_waterfall_data_source] -// 实现IDataSource接口的对象,用于瀑布流组件加载数据 -export class WaterFlowDataSource implements IDataSource { - private dataArray: number[] = []; - private listeners: DataChangeListener[] = []; - - constructor() { - for (let i = 0; i < 100; i++) { - this.dataArray.push(i); - } - } - - // 获取索引对应的数据 - public getData(index: number): number { - return this.dataArray[index]; - } - - // 通知控制器数据重新加载 - notifyDataReload(): void { - this.listeners.forEach(listener => { - listener.onDataReloaded(); - }) - } - - // 通知控制器数据增加 - notifyDataAdd(index: number): void { - this.listeners.forEach(listener => { - listener.onDataAdd(index); - }) - } - - // 通知控制器数据变化 - notifyDataChange(index: number): void { - this.listeners.forEach(listener => { - listener.onDataChange(index); - }) - } - - // 通知控制器数据删除 - notifyDataDelete(index: number): void { - this.listeners.forEach(listener => { - listener.onDataDelete(index); - }) - } - - // 通知控制器数据位置变化 - notifyDataMove(from: number, to: number): void { - this.listeners.forEach(listener => { - listener.onDataMove(from, to); - }) - } - - //通知控制器数据批量修改 - notifyDatasetChange(operations: DataOperation[]): void { - this.listeners.forEach(listener => { - listener.onDatasetChange(operations); - }) - } - - // 获取数据总数 - public totalCount(): number { - return this.dataArray.length; - } - - // 注册改变数据的控制器 - registerDataChangeListener(listener: DataChangeListener): void { - if (this.listeners.indexOf(listener) < 0) { - this.listeners.push(listener); - } - } - - // 注销改变数据的控制器 - unregisterDataChangeListener(listener: DataChangeListener): void { - const pos = this.listeners.indexOf(listener); - if (pos >= 0) { - this.listeners.splice(pos, 1); - } - } - - // 增加数据 - public add1stItem(): void { - this.dataArray.splice(0, 0, this.dataArray.length); - this.notifyDataAdd(0); - } - - // 在数据尾部增加一个元素 - public addLastItem(): void { - this.dataArray.splice(this.dataArray.length, 0, this.dataArray.length); - this.notifyDataAdd(this.dataArray.length - 1); - } - - // 在指定索引位置增加一个元素 - public addItem(index: number): void { - this.dataArray.splice(index, 0, this.dataArray.length); - this.notifyDataAdd(index); - } - - // 删除第一个元素 - public delete1stItem(): void { - this.dataArray.splice(0, 1); - this.notifyDataDelete(0); - } - - // 删除第二个元素 - public delete2ndItem(): void { - this.dataArray.splice(1, 1); - this.notifyDataDelete(1); - } - - // 删除最后一个元素 - public deleteLastItem(): void { - this.dataArray.splice(-1, 1); - this.notifyDataDelete(this.dataArray.length); - } - - // 在指定索引位置删除一个元素 - public deleteItem(index: number): void { - this.dataArray.splice(index, 1); - this.notifyDataDelete(index); - } - - // 重新加载数据 - public reload(): void { - this.dataArray.splice(1, 1); - this.dataArray.splice(3, 2); - this.notifyDataReload(); - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start encapsulate_waterfall_data_source] +// 实现IDataSource接口的对象,用于瀑布流组件加载数据 +export class WaterFlowDataSource implements IDataSource { + private dataArray: number[] = []; + private listeners: DataChangeListener[] = []; + + constructor() { + for (let i = 0; i < 100; i++) { + this.dataArray.push(i); + } + } + + // 获取索引对应的数据 + public getData(index: number): number { + return this.dataArray[index]; + } + + // 通知控制器数据重新加载 + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded(); + }) + } + + // 通知控制器数据增加 + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index); + }) + } + + // 通知控制器数据变化 + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index); + }) + } + + // 通知控制器数据删除 + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index); + }) + } + + // 通知控制器数据位置变化 + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to); + }) + } + + //通知控制器数据批量修改 + notifyDatasetChange(operations: DataOperation[]): void { + this.listeners.forEach(listener => { + listener.onDatasetChange(operations); + }) + } + + // 获取数据总数 + public totalCount(): number { + return this.dataArray.length; + } + + // 注册改变数据的控制器 + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + this.listeners.push(listener); + } + } + + // 注销改变数据的控制器 + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + this.listeners.splice(pos, 1); + } + } + + // 增加数据 + public add1stItem(): void { + this.dataArray.splice(0, 0, this.dataArray.length); + this.notifyDataAdd(0); + } + + // 在数据尾部增加一个元素 + public addLastItem(): void { + this.dataArray.splice(this.dataArray.length, 0, this.dataArray.length); + this.notifyDataAdd(this.dataArray.length - 1); + } + + // 在指定索引位置增加一个元素 + public addItem(index: number): void { + this.dataArray.splice(index, 0, this.dataArray.length); + this.notifyDataAdd(index); + } + + // 删除第一个元素 + public delete1stItem(): void { + this.dataArray.splice(0, 1); + this.notifyDataDelete(0); + } + + // 删除第二个元素 + public delete2ndItem(): void { + this.dataArray.splice(1, 1); + this.notifyDataDelete(1); + } + + // 删除最后一个元素 + public deleteLastItem(): void { + this.dataArray.splice(-1, 1); + this.notifyDataDelete(this.dataArray.length); + } + + // 在指定索引位置删除一个元素 + public deleteItem(index: number): void { + this.dataArray.splice(index, 1); + this.notifyDataDelete(index); + } + + // 重新加载数据 + public reload(): void { + this.dataArray.splice(1, 1); + this.dataArray.splice(3, 2); + this.notifyDataReload(); + } +} // [End encapsulate_waterfall_data_source] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterfallRendering.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterfallRendering.ets old mode 100755 new mode 100644 index 2708bae45a5b6d79c67f1f9ee5a096af02110f21..55528d68623a9ca7d8a3e0945361b4154153b5ef --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterfallRendering.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/managers/WaterfallRendering.ets @@ -1,133 +1,133 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start receive_child_thread_data_render_waterfall_component] -import { WaterFlowDataSource } from './WaterFlowDataSource'; -import { getImgFromDB } from './Mock'; -import resource from '../util/resource'; - -// 模拟图片数组 -let img = new Array(33); - -export function fillImg(imgArr: Array) { - img = imgArr; -} - -@Entry -@Component -struct WaterFlowDemo { - @State minSize: number = 80; - @State maxSize: number = 180; - @State fontSize: number = 24; - @State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F]; - scroller: Scroller = new Scroller(); - dataSource: WaterFlowDataSource = new WaterFlowDataSource(); - private itemWidthArray: number[] = []; - private itemHeightArray: number[] = []; - - // 计算FlowItem宽/高 - getSize() { - let ret = Math.floor(Math.random() * this.maxSize); - return (ret > this.minSize ? ret : this.minSize); - } - - // 设置FlowItem的宽/高数组 - setItemSizeArray() { - for (let i = 0; i < 100; i++) { - this.itemWidthArray.push(this.getSize()); - this.itemHeightArray.push(this.getSize()); - } - } - - aboutToAppear() { - this.setItemSizeArray(); - } - - @Builder - itemFoot() { - Column() { - Text(`Footer`) - .fontSize(10) - .backgroundColor(Color.Red) - .width(50) - .height(50) - .align(Alignment.Center) - .margin({ top: 2 }); - } - } - - build() { - Column({ space: 2 }) { - Text('ArkUI WaterFlow Demo') - .onAppear(() => { - getImgFromDB(); - }) - WaterFlow() { - LazyForEach(this.dataSource, (item: number) => { - FlowItem() { - Column() { - Text('N' + item) - .fontSize(12) - .height('16') - .onClick(() => { - }); - // 为了模拟图片加载,使用Text组件显示,正常加载jpg文件时,可以直接使用Image组件 - // 参考 Image(this.img[item % 33]).objectFit(ImageFit.Contain).width('100%').layoutWeight(1) - if (img[item % 33] == null) { - Text(resource.resourceToString($r('app.string.Image_loading'))) - .width('100%') - .layoutWeight(1); - } - Text(img[item % 33]) - .width('100%') - .layoutWeight(1); - } - } - .onAppear(() => { - // 即将触底时提前增加数据 - if (item + 20 == this.dataSource.totalCount()) { - for (let i = 0; i < 100; i++) { - this.dataSource.addLastItem(); - } - } - }) - .width('100%') - .height(this.itemHeightArray[item % 100]) - .backgroundColor(this.colors[item % 5]) - }, (item: string) => item) - } - .columnsTemplate('1fr 1fr') - .columnsGap(10) - .rowsGap(5) - .backgroundColor(0xFAEEE0) - .width('100%') - .height('100%') - .onReachStart(() => { - console.info('TaskPoolTest-waterFlow reach start'); - }) - .onScrollStart(() => { - console.info('TaskPoolTest-waterFlow scroll start'); - }) - .onScrollStop(() => { - console.info('TaskPoolTest-waterFlow scroll stop'); - }) - .onScrollFrameBegin((offset: number, state: ScrollState) => { - console.info('TaskPoolTest-waterFlow scrollFrameBegin offset: ' + offset + ' state: ' + state.toString()); - return { offsetRemain: offset }; - }) - } - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start receive_child_thread_data_render_waterfall_component] +import { WaterFlowDataSource } from './WaterFlowDataSource'; +import { getImgFromDB } from './Mock'; +import resource from '../util/resource'; + +// 模拟图片数组 +let img = new Array(33); + +export function fillImg(imgArr: Array) { + img = imgArr; +} + +@Entry +@Component +struct WaterFlowDemo { + @State minSize: number = 80; + @State maxSize: number = 180; + @State fontSize: number = 24; + @State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F]; + scroller: Scroller = new Scroller(); + dataSource: WaterFlowDataSource = new WaterFlowDataSource(); + private itemWidthArray: number[] = []; + private itemHeightArray: number[] = []; + + // 计算FlowItem宽/高 + getSize() { + let ret = Math.floor(Math.random() * this.maxSize); + return (ret > this.minSize ? ret : this.minSize); + } + + // 设置FlowItem的宽/高数组 + setItemSizeArray() { + for (let i = 0; i < 100; i++) { + this.itemWidthArray.push(this.getSize()); + this.itemHeightArray.push(this.getSize()); + } + } + + aboutToAppear() { + this.setItemSizeArray(); + } + + @Builder + itemFoot() { + Column() { + Text(`Footer`) + .fontSize(10) + .backgroundColor(Color.Red) + .width(50) + .height(50) + .align(Alignment.Center) + .margin({ top: 2 }); + } + } + + build() { + Column({ space: 2 }) { + Text('ArkUI WaterFlow Demo') + .onAppear(() => { + getImgFromDB(); + }) + WaterFlow() { + LazyForEach(this.dataSource, (item: number) => { + FlowItem() { + Column() { + Text('N' + item) + .fontSize(12) + .height('16') + .onClick(() => { + }); + // 为了模拟图片加载,使用Text组件显示,正常加载jpg文件时,可以直接使用Image组件 + // 参考 Image(this.img[item % 33]).objectFit(ImageFit.Contain).width('100%').layoutWeight(1) + if (img[item % 33] == null) { + Text(resource.resourceToString($r('app.string.Image_loading'))) + .width('100%') + .layoutWeight(1); + } + Text(img[item % 33]) + .width('100%') + .layoutWeight(1); + } + } + .onAppear(() => { + // 即将触底时提前增加数据 + if (item + 20 == this.dataSource.totalCount()) { + for (let i = 0; i < 100; i++) { + this.dataSource.addLastItem(); + } + } + }) + .width('100%') + .height(this.itemHeightArray[item % 100]) + .backgroundColor(this.colors[item % 5]) + }, (item: string) => item) + } + .columnsTemplate('1fr 1fr') + .columnsGap(10) + .rowsGap(5) + .backgroundColor(0xFAEEE0) + .width('100%') + .height('100%') + .onReachStart(() => { + console.info('TaskPoolTest-waterFlow reach start'); + }) + .onScrollStart(() => { + console.info('TaskPoolTest-waterFlow scroll start'); + }) + .onScrollStop(() => { + console.info('TaskPoolTest-waterFlow scroll stop'); + }) + .onScrollFrameBegin((offset: number, state: ScrollState) => { + console.info('TaskPoolTest-waterFlow scrollFrameBegin offset: ' + offset + ' state: ' + state.toString()); + return { offsetRemain: offset }; + }) + } + } +} // [End receive_child_thread_data_render_waterfall_component] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/Calculator.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/Calculator.ets old mode 100755 new mode 100644 index 500bd8d995a57f4ddf0d105d16dcd6c4740710c8..cb5916ba305af3e65cc10d69041565bbf6317bc4 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/Calculator.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/Calculator.ets @@ -1,70 +1,70 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start define_calculator_module] -import { collections } from '@kit.ArkTS'; - -@Sendable -export class Calculator { - public history?: collections.Array>; - public totalCount: number = 0; - - static init(): Calculator { - let calc = new Calculator(); - calc.totalCount = 0; - calc.history = collections.Array.create(calc.totalCount, collections.Array.create(2, '')); - return calc; - } - - add(a: number, b: number) { - let result = a + b; - this.newCalc(`${a} + ${b}`, `${result}`); - return result; - } - - sub(a: number, b: number) { - let result = a - b; - this.newCalc(`${a} - ${b}`, `${result}`); - return result; - } - - mul(a: number, b: number) { - let result = a * b; - this.newCalc(`${a} * ${b}`, `${result}`); - return result; - } - - div(a: number, b: number) { - let result = a / b; - this.newCalc(`${a} / ${b}`, `${result}`); - return result; - } - - getHistory(): collections.Array> { - return this.history!; - } - - showHistory() { - for (let i = 0; i < this.totalCount; i++) { - console.info(`${i}: ${this.history![i][0]} = ${this.history![i][1]}`); - } - } - - private newCalc(opt: string, ret: string) { - let newRecord = new collections.Array(opt, ret); - this.totalCount = this.history!.unshift(newRecord); - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_calculator_module] +import { collections } from '@kit.ArkTS'; + +@Sendable +export class Calculator { + public history?: collections.Array>; + public totalCount: number = 0; + + static init(): Calculator { + let calc = new Calculator(); + calc.totalCount = 0; + calc.history = collections.Array.create(calc.totalCount, collections.Array.create(2, '')); + return calc; + } + + add(a: number, b: number) { + let result = a + b; + this.newCalc(`${a} + ${b}`, `${result}`); + return result; + } + + sub(a: number, b: number) { + let result = a - b; + this.newCalc(`${a} - ${b}`, `${result}`); + return result; + } + + mul(a: number, b: number) { + let result = a * b; + this.newCalc(`${a} * ${b}`, `${result}`); + return result; + } + + div(a: number, b: number) { + let result = a / b; + this.newCalc(`${a} / ${b}`, `${result}`); + return result; + } + + getHistory(): collections.Array> { + return this.history!; + } + + showHistory() { + for (let i = 0; i < this.totalCount; i++) { + console.info(`${i}: ${this.history![i][0]} = ${this.history![i][1]}`); + } + } + + private newCalc(opt: string, ret: string) { + let newRecord = new collections.Array(opt, ret); + this.totalCount = this.history!.unshift(newRecord); + } +} // [End define_calculator_module] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/TimerSdk.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/TimerSdk.ets old mode 100755 new mode 100644 index 4e6ffde12130e990b0df2beafe1f1f625a2125cf..dd41af4f3993c464c3a986a2e53f3e35e105c776 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/TimerSdk.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/sdk/TimerSdk.ets @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start define_timer_module] -@Sendable -export class TimerSdk { - static init(): TimerSdk { - let timer = new TimerSdk(); - return timer; - } - - async Countdown(time: number) { - return new Promise((resolve: (value: boolean) => void) => { - setTimeout(() => { - resolve(true); - }, time); - }); - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_timer_module] +@Sendable +export class TimerSdk { + static init(): TimerSdk { + let timer = new TimerSdk(); + return timer; + } + + async Countdown(time: number) { + return new Promise((resolve: (value: boolean) => void) => { + setTimeout(() => { + resolve(true); + }, time); + }); + } +} // [End define_timer_module] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index de30eb4b1b5ae7e15b8ea8141e26df19fb00d930..723a394265ee2e6bf6d895e9503c4b2d8e49207a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/ets/util/resource.ets @@ -1,25 +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. - */ - -export class P2PManager { - public resourceToString(resource: Resource): string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - +/* + * 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 class P2PManager { + public resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/ohosTest.md old mode 100755 new mode 100644 index 1f5d4346f509598a395848c9cf899ef953a0ffb9..9ce35f6fcef6a9ec8d681c73cf9e87a6dfb2c8a3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/ohosTest.md @@ -1,13 +1,13 @@ -# PracticalCases 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------------- | ------------------------------------- | ------------------------------------------------------------ | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 使用TaskPool进行频繁数据库操作 | 位于UsingTaskPool.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用Sendable进行大容量数据库操作 | 位于UsingSendable.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 业务模块并发加载场景 | 位于ConcurrentLoadingModulesGuide.ets | 点击calculate add,show history,countdown | 1秒后页面显示“success” | 是 | Pass | -| 全局配置项功能场景 | 位于GlobalConfigurationGuide.ets | 点击change name,task | 1秒后页面显示“success” | 是 | Pass | -| ArkUI数据更新场景 | 位于MakeobservedSendable.ets | 滑动屏幕 | 瀑布流形式加载信息 | 是 | Pass | +# PracticalCases 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------- | ------------------------------------- | ------------------------------------------------------------ | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 使用TaskPool进行频繁数据库操作 | 位于UsingTaskPool.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用Sendable进行大容量数据库操作 | 位于UsingSendable.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 业务模块并发加载场景 | 位于ConcurrentLoadingModulesGuide.ets | 点击calculate add,show history,countdown | 1秒后页面显示“success” | 是 | Pass | +| 全局配置项功能场景 | 位于GlobalConfigurationGuide.ets | 点击change name,task | 1秒后页面显示“success” | 是 | Pass | +| ArkUI数据更新场景 | 位于MakeobservedSendable.ets | 滑动屏幕 | 瀑布流形式加载信息 | 是 | Pass | | ArkUI瀑布流渲染场景 | 位于WaterfallRendering.ets | 点击wifi on,download,在输入框输入信息,点击login显示信息,点击not login清除信息 | 输入信息显示上方 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/screenshots/PracticalCases_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/screenshots/PracticalCases_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/screenshots/PracticalCases_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/PracticalCases/screenshots/PracticalCases_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab34d7c0dfe6a4e7e407173fbdaba68ba8dca67e --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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.asyncconcurrencyoverview", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..69253cafe848e5cf470bb24b2f74d918e10ea58c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AsyncConcurrencyOverview" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5d33a1047d584de076722a275007d8a5c17a2c45 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/README.md @@ -0,0 +1,66 @@ +# ArkTS 异步并发 (Promise和async/await) + +### 介绍 + +Promise和async/await提供异步并发能力,是标准的JS异步语法。异步代码会被挂起并在之后继续执行,同一时间只有一段代码执行,适用于单次I/O任务的场景开发,例如一次网络请求、一次文件读写等操作。无需另外启动线程执行。 + +异步语法是一种编程语言的特性,允许程序在执行某些操作时不必等待其完成,而是可以继续执行其他操作。该工程中展示的代码详细描述可查如下链接: + +- [异步并发 (Promise和async/await)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/async-concurrency-overview.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击hello world,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 异步并发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..69cbbedca4830c00322bf9fd274b2510d26509bc --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 14, + "compileSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31bf2f4c4df15f0403582b255ebdff1354312357 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e54d14e1b444a338b2c922f94a4fe4deed5be45 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..51bdf85846c3b83c16542085365521bdc35baf50 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cb5df2316a385286bf09b1aab230f0bf56d8b993 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f63462032245655b8df990c83c5d7312015c089 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0df4e83ad09f9c4378b3d49faeeaf118df8bc59c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..936cf43ead6c6ae132fc8169d8ffb96fcd8e6fa6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..d1a317c1aca88d11c85ff517305bc79bb854576d --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/ohosTest.md @@ -0,0 +1,8 @@ +# AsyncConcurrencyOverview 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------- | ------------ | --------------- |------------------| -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 异步并发 | 位于首页 | 点击Hello World | 3秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_1.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_1.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_2.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/AsyncConcurrencyOverview/screenshots/AsyncConcurrencyOverview_2.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f59e115f8c2d0f2683f6b5f091efdabe078bf4c1 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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.communicationobjects", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..481db996057e77d4e314fee5f5f129d509e49c5f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CommunicationObjects" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c623cdfa532af7caca4b60368e47096ee3c0d04f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/README.md @@ -0,0 +1,93 @@ +# ArkTS 线程间通信对象 + +### 介绍 + +#### 普通对象 + +普通对象跨线程时通过拷贝形式传递,两个线程的对象内容一致,但是指向各自线程的隔离内存区间,被分配在各自线程的虚拟机本地堆(LocalHeap)。例如Ecmascript262规范定义的Object、Array、Map等对象是通过这种方式实现跨并发实例通信的。 + +#### ArrayBuffer对象 + +ArrayBuffer内部包含一块Native内存,该ArrayBuffer的JS对象壳被分配在虚拟机本地堆(LocalHeap)。与普通对象一样,需要经过序列化与反序列化拷贝传递,但是Native内存有两种传输方式:拷贝和转移。 + +#### SharedArrayBuffer对象 + +SharedArrayBuffer内部包含一块Native内存,其JS对象壳被分配在虚拟机本地堆(LocalHeap)。支持跨并发实例间共享,但是访问及修改需要采用Atomics类,防止数据竞争。SharedArrayBuffer可以用于多个并发实例间的状态共享或者数据共享。 + +#### Transferable对象(NativeBinding对象) + +Transferable对象(也称为NativeBinding对象)指的是一个JS对象,绑定了一个C++对象,且主体功能由C++提供,其JS对象壳被分配在虚拟机本地堆(LocalHeap)。跨线程传输时可以直接复用同一个C++对象,相比于JS对象的拷贝模式,传输效率较高。因此,可共享或转移的NativeBinding对象也被称为Transferable对象。 + +该工程中展示的代码详细描述可查如下链接: + +- [普通对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/normal-object.md) +- [ArrayBuffer对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arraybuffer-object.md) +- [SharedArrayBuffer对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/shared-arraybuffer-object.md) +- [Transferable对象(NativeBinding对象)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/transferabled-object.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── ArrayBufferObject.ets // ArrayBuffer对象示例代码 + │ │ ├── NormalObject.ets // 普通对象示例代码 + │ │ ├── pixelMapTest.ets // Transferable对象示例代码 + │ │ ├── SharedArrayBufferObject.ets // SharedArrayBuffer对象示例代码 + │ │ ├── Test.ets // 普通对象示例代码 + │ │ ├── TransferabledObject.ets // Transferable对象示例代码 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/ArrayBufferObject.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/ArrayBufferObject.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/ArrayBufferObject.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/ArrayBufferObject.ets index efe2417d387d977d8e6946ea1b129688a1f37b5a..cf5c6e31588c6df17b4362c219574b7c8bb595b3 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/ArrayBufferObject.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/ArrayBufferObject.ets @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start copy_arraybuffer_transfer] -import { taskpool } from '@kit.ArkTS'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Concurrent -function adjustImageValue(arrayBuffer: ArrayBuffer): ArrayBuffer { - // 对arrayBuffer进行操作 - return arrayBuffer; // 返回值默认转移 -} - -function createImageTask(arrayBuffer: ArrayBuffer, isParamsByTransfer: boolean): taskpool.Task { - let task: taskpool.Task = new taskpool.Task(adjustImageValue, arrayBuffer); - if (!isParamsByTransfer) { // 是否使用转移方式 - // 传递空数组[],全部arrayBuffer参数传递均采用拷贝方式 - task.setTransferList([]); - } - return task; -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - let taskNum = 4; - let arrayBuffer = new ArrayBuffer(1024 * 1024); - let taskPoolGroup = new taskpool.TaskGroup(); - // 创建taskNum个Task - for (let i: number = 0; i < taskNum; i++) { - let arrayBufferSlice: ArrayBuffer = - arrayBuffer.slice(arrayBuffer.byteLength / taskNum * i, arrayBuffer.byteLength / taskNum * (i + 1)); - // 使用拷贝方式传入ArrayBuffer,所以isParamsByTransfer为false - taskPoolGroup.addTask(createImageTask(arrayBufferSlice, false)); - } - // 执行Task - taskpool.execute(taskPoolGroup).then((data) => { - // 返回结果,对数组拼接,获得最终结果 - }).catch((e: BusinessError) => { - console.error(e.message); - }) - // [StartExclude copy_arraybuffer_transfer] - this.message = 'success'; - // [EndExclude copy_arraybuffer_transfer] - }) - } - .height('100%') - .width('100%') - } -} -// [End copy_arraybuffer_transfer] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start copy_arraybuffer_transfer] +import { taskpool } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Concurrent +function adjustImageValue(arrayBuffer: ArrayBuffer): ArrayBuffer { + // 对arrayBuffer进行操作 + return arrayBuffer; // 返回值默认转移 +} + +function createImageTask(arrayBuffer: ArrayBuffer, isParamsByTransfer: boolean): taskpool.Task { + let task: taskpool.Task = new taskpool.Task(adjustImageValue, arrayBuffer); + if (!isParamsByTransfer) { // 是否使用转移方式 + // 传递空数组[],全部arrayBuffer参数传递均采用拷贝方式 + task.setTransferList([]); + } + return task; +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + let taskNum = 4; + let arrayBuffer = new ArrayBuffer(1024 * 1024); + let taskPoolGroup = new taskpool.TaskGroup(); + // 创建taskNum个Task + for (let i: number = 0; i < taskNum; i++) { + let arrayBufferSlice: ArrayBuffer = + arrayBuffer.slice(arrayBuffer.byteLength / taskNum * i, arrayBuffer.byteLength / taskNum * (i + 1)); + // 使用拷贝方式传入ArrayBuffer,所以isParamsByTransfer为false + taskPoolGroup.addTask(createImageTask(arrayBufferSlice, false)); + } + // 执行Task + taskpool.execute(taskPoolGroup).then((data) => { + // 返回结果,对数组拼接,获得最终结果 + }).catch((e: BusinessError) => { + console.error(e.message); + }) + // [StartExclude copy_arraybuffer_transfer] + this.message = 'success'; + // [EndExclude copy_arraybuffer_transfer] + }) + } + .height('100%') + .width('100%') + } +} +// [End copy_arraybuffer_transfer] diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/NormalObject.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/NormalObject.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/NormalObject.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/NormalObject.ets index c509943842a840359a3cd3a4281f5991a8f03a32..367ff95a2c2eb1a41e5e2dee6c8855b65ce92a28 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/NormalObject.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/NormalObject.ets @@ -1,59 +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. - */ - -// [Start example_normal_obj] -import { taskpool } from '@kit.ArkTS'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { TestA } from './Test'; - -@Concurrent -async function test1(arg: TestA) { - console.info('TestA name is: ' + arg.name); -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 1. 创建Test实例objA - let objA = new TestA('TestA'); - // 2. 创建任务task,将objA传递给该任务,objA非sendable对象,通过序列化传递给子线程 - let task = new taskpool.Task(test1, objA); - // 3. 执行任务 - taskpool.execute(task).then(() => { - console.info('taskpool: execute task success!'); - }).catch((e:BusinessError) => { - console.error(`taskpool: execute task: Code: ${e.code}, message: ${e.message}`); - }) - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End example_normal_obj] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_normal_obj] +import { taskpool } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { TestA } from './Test'; + +@Concurrent +async function test1(arg: TestA) { + console.info('TestA name is: ' + arg.name); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 1. 创建Test实例objA + let objA = new TestA('TestA'); + // 2. 创建任务task,将objA传递给该任务,objA非sendable对象,通过序列化传递给子线程 + let task = new taskpool.Task(test1, objA); + // 3. 执行任务 + taskpool.execute(task).then(() => { + console.info('taskpool: execute task success!'); + }).catch((e:BusinessError) => { + console.error(`taskpool: execute task: Code: ${e.code}, message: ${e.message}`); + }) + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End example_normal_obj] diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/SharedArrayBufferObject.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/SharedArrayBufferObject.ets old mode 100755 new mode 100644 similarity index 96% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/SharedArrayBufferObject.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/SharedArrayBufferObject.ets index d535b4450f593a59a5cff0601ec9b7c1b3a8f578..29141a392d743ec48436415f91b61cd6240ab530 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/SharedArrayBufferObject.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/SharedArrayBufferObject.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_pass_obj] -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -function transferAtomics(arg1: Int32Array) { - console.info('wait begin::'); - // 使用Atomics进行操作 - let res = Atomics.wait(arg1, 0, 0, 3000); - return res; -} - -@Entry -@Component -struct sharedArrayBuffer { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 定义可共享对象 - let sab: SharedArrayBuffer = new SharedArrayBuffer(20); - let int32 = new Int32Array(sab); - let task: taskpool.Task = new taskpool.Task(transferAtomics, int32); - taskpool.execute(task).then((res) => { - console.info('this res is: ' + res); - }); - setTimeout(() => { - Atomics.notify(int32, 0, 1); - }, 1000); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End example_pass_obj] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_pass_obj] +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +function transferAtomics(arg1: Int32Array) { + console.info('wait begin::'); + // 使用Atomics进行操作 + let res = Atomics.wait(arg1, 0, 0, 3000); + return res; +} + +@Entry +@Component +struct sharedArrayBuffer { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 定义可共享对象 + let sab: SharedArrayBuffer = new SharedArrayBuffer(20); + let int32 = new Int32Array(sab); + let task: taskpool.Task = new taskpool.Task(transferAtomics, int32); + taskpool.execute(task).then((res) => { + console.info('this res is: ' + res); + }); + setTimeout(() => { + Atomics.notify(int32, 0, 1); + }, 1000); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End example_pass_obj] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/Test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6520ec0a23ea74965db53791db280c917f62973f --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/Test.ets @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start define_test_class] +// 自定义class TestA +export class TestA { + constructor(name: string) { + this.name = name; + } + name: string = 'ClassA'; +} +// [End define_test_class] diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/TransferabledObject.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/TransferabledObject.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/TransferabledObject.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/TransferabledObject.ets index 3fb9c8d73bc51b2b981772741e31a0765ed645ca..afaea9ae5cd1325d118d467c8f09de32d055883a --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/TransferabledObject.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/TransferabledObject.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_pass_obj] -import { taskpool } from '@kit.ArkTS'; -import { loadPixelMap } from './pixelMapTest'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - @State pixelMap: PixelMap | undefined = undefined; - - private loadImageFromThread(): void { - const resourceMgr = getContext(this).resourceManager; - // 此处‘startIcon.png’为media下复制到rawfile文件夹中,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 - resourceMgr.getRawFd('startIcon.png').then(rawFileDescriptor => { - taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => { - if (pixelMap) { - this.pixelMap = pixelMap as PixelMap; - console.log('Succeeded in creating pixelMap.'); - // 主线程释放pixelMap。由于子线程返回pixelMap时已调用setTransferDetached,所以此处能够立即释放pixelMap。 - this.pixelMap.release(); - } else { - console.error('Failed to create pixelMap.'); - } - }).catch((e: BusinessError) => { - console.error('taskpool execute loadPixelMap failed. Code: ' + e.code + ', message: ' + e.message); - }); - }); - } - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - this.loadImageFromThread(); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End example_pass_obj] - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_pass_obj] +import { taskpool } from '@kit.ArkTS'; +import { loadPixelMap } from './pixelMapTest'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + @State pixelMap: PixelMap | undefined = undefined; + + private loadImageFromThread(): void { + const resourceMgr = getContext(this).resourceManager; + // 此处‘startIcon.png’为media下复制到rawfile文件夹中,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + resourceMgr.getRawFd('startIcon.png').then(rawFileDescriptor => { + taskpool.execute(loadPixelMap, rawFileDescriptor).then(pixelMap => { + if (pixelMap) { + this.pixelMap = pixelMap as PixelMap; + console.log('Succeeded in creating pixelMap.'); + // 主线程释放pixelMap。由于子线程返回pixelMap时已调用setTransferDetached,所以此处能够立即释放pixelMap。 + this.pixelMap.release(); + } else { + console.error('Failed to create pixelMap.'); + } + }).catch((e: BusinessError) => { + console.error('taskpool execute loadPixelMap failed. Code: ' + e.code + ', message: ' + e.message); + }); + }); + } + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.loadImageFromThread(); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End example_pass_obj] + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/pixelMapTest.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/pixelMapTest.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/pixelMapTest.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/pixelMapTest.ets index 333d036a1d35208abea20a06c1b6b8b4d01ff564..ebae20a4bdabf3fa4cdc4cb1f971255138c652a5 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/pixelMapTest.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/pixelMapTest.ets @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_pass_obj] -import { image } from '@kit.ImageKit'; - -@Concurrent -export async function loadPixelMap(rawFileDescriptor: number): Promise { - // 创建imageSource。 - const imageSource = image.createImageSource(rawFileDescriptor); - // 创建pixelMap。 - const pixelMap = imageSource.createPixelMapSync(); - // 释放imageSource。 - imageSource.release(); - // 使pixelMap在跨线程传输完成后,断开原线程的引用。 - pixelMap.setTransferDetached(true); - // 返回pixelMap给主线程。 - return pixelMap; -} -// [End example_pass_obj] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_pass_obj] +import { image } from '@kit.ImageKit'; + +@Concurrent +export async function loadPixelMap(rawFileDescriptor: number): Promise { + // 创建imageSource。 + const imageSource = image.createImageSource(rawFileDescriptor); + // 创建pixelMap。 + const pixelMap = imageSource.createPixelMapSync(); + // 释放imageSource。 + imageSource.release(); + // 使pixelMap在跨线程传输完成后,断开原线程的引用。 + pixelMap.setTransferDetached(true); + // 返回pixelMap给主线程。 + return pixelMap; +} +// [End example_pass_obj] diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/CommonButton.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/CommonButton.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/resource.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0f1755b8cccfecc4200cf5b1ed991805e3e00b6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/resource.ets @@ -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. + */ + +export class P2PManager { + public resourceToString(resource: Resource):string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + +export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..17230e4b4c0b7b7f78e8cd51164a88545540f6c2 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/ohosTest.md @@ -0,0 +1,11 @@ +# CommunicationObjects 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ------------------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 普通对象 | 位于NormalObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| ArrayBuffer对象 | 位于ArrayBufferObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| SharedArrayBuffer对象 | 位于SharedArrayBufferObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Transferable对象 | 位于TransferabledObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_1.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_1.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_2.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/screenshots/CommunicationObjects_2.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/app.json5 old mode 100755 new mode 100644 index 3983e609fa2e89e1cf02cd14aef2dae82962e94f..67e0031a603fbaa3b565efaf2c9c149fe016e1d5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/app.json5 @@ -1,25 +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.rulesandrestrictions", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.rulesandrestrictions", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index c5886e23bd3bfd13444b4118eea68c92e6d3a664..1c313db608d4275fc7c8778f1bc178749835da0f --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "RulesAndRestrictions" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "RulesAndRestrictions" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/README.md old mode 100755 new mode 100644 index 13b3282247804dda7e5bb6536bda12a68224a1f3..75d65c542bfb66a841a4c03e63f87ae684d206cf --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/README.md @@ -1,181 +1,181 @@ -# ArkTS Sendable使用规则与约束 - -该工程中展示的代码详细描述可查如下链接: - -- [Sendable使用规则与约束](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-constraints.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -achievenon/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // 非Sendable class只能实现非Sendable interface和Sendable装饰器修饰类型时仅支持修饰函数类型 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -arrowfunctions/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // 箭头函数不支持共享 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -cannotbeused/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // Sendable class和Sendable function不能使用除了@Sendable的其它装饰器 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -inheritedfromnon/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // 非Sendable class只能继承自非Sendable class - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -inheritonly/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // Sendable class只能继承自Sendable class - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -nocalculationsupport/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // Sendable class/interface的成员变量不支持使用计算属性名 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -notallowedInside/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // Sendable class的内部不允许使用当前模块内上下文环境中定义的变量 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -objectliterals/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // 不能使用对象字面量/数组字面量初始化Sendable类型 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -templatetype/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // 泛型类中的Sendable class,collections.Array/Map/Set的模板类型必须是Sendable类型 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -typecannot/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // 非Sendable类型不可以as成Sendable类型 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -variablenotsupported/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // Sendable class/interface的成员变量不支持使用!断言 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -variablesupport/src/ - ├── main - │ ├── ets - │ │ ├── pages - │ │ ├── Index.ets // Sendable class/interface成员变量必须是Sendable支持的数据类型 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS Sendable使用规则与约束 + +该工程中展示的代码详细描述可查如下链接: + +- [Sendable使用规则与约束](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-constraints.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +achievenon/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // 非Sendable class只能实现非Sendable interface和Sendable装饰器修饰类型时仅支持修饰函数类型 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +arrowfunctions/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // 箭头函数不支持共享 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +cannotbeused/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // Sendable class和Sendable function不能使用除了@Sendable的其它装饰器 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +inheritedfromnon/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // 非Sendable class只能继承自非Sendable class + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +inheritonly/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // Sendable class只能继承自Sendable class + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +nocalculationsupport/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // Sendable class/interface的成员变量不支持使用计算属性名 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +notallowedInside/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // Sendable class的内部不允许使用当前模块内上下文环境中定义的变量 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +objectliterals/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // 不能使用对象字面量/数组字面量初始化Sendable类型 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +templatetype/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // 泛型类中的Sendable class,collections.Array/Map/Set的模板类型必须是Sendable类型 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +typecannot/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // 非Sendable类型不可以as成Sendable类型 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +variablenotsupported/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // Sendable class/interface的成员变量不支持使用!断言 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +variablesupport/src/ + ├── main + │ ├── ets + │ │ ├── pages + │ │ ├── Index.ets // Sendable class/interface成员变量必须是Sendable支持的数据类型 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/oh-package.json5 old mode 100755 new mode 100644 index 53aaf83c430968562801bc58866165f296ac497c..3cb95eb922a2fdd179393258d2efaf767e482ea5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "achievenon", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "achievenon", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/ets/achievenonability/AchievenonAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/ets/achievenonability/AchievenonAbility.ets old mode 100755 new mode 100644 index 27da643e423cda9ae310a80e037feaede4451808..45dc888f879c0e5a6a68df0141e862bdb44a3f40 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/ets/achievenonability/AchievenonAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/ets/achievenonability/AchievenonAbility.ets @@ -1,56 +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 AchievenonAbility 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'); - } -} +/* + * 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 AchievenonAbility 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/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/module.json5 old mode 100755 new mode 100644 index 036b9b609354ff63a2ccce88b238454a57c8e6c6..c9efe2205069cdc6c533225dc3884fc964f466d2 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "achievenon", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "AchievenonAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "AchievenonAbility", - "srcEntry": "./ets/achievenonability/AchievenonAbility.ets", - "description": "$string:AchievenonAbility_desc", - "icon": "$media:layered_image", - "label": "$string:AchievenonAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "achievenon", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "AchievenonAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "AchievenonAbility", + "srcEntry": "./ets/achievenonability/AchievenonAbility.ets", + "description": "$string:AchievenonAbility_desc", + "icon": "$media:layered_image", + "label": "$string:AchievenonAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/module.json5 old mode 100755 new mode 100644 index aab900c1701e3a78eeb365baa809186690f3a708..63ed494102f704879b9389df017ae73f50ae7279 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/ohosTest/module.json5 @@ -1,27 +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": "achievenon_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "achievenon_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/achievenon/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/oh-package.json5 old mode 100755 new mode 100644 index 3bfbbecab27aed9d74a3e331f895007912bb78a2..84e7269a19d7818e7e80073edb0138bdc3b6f596 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "arrowfunctions", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "arrowfunctions", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/ets/arrowfunctionsability/ArrowfunctionsAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/ets/arrowfunctionsability/ArrowfunctionsAbility.ets old mode 100755 new mode 100644 index 278f4b7314da2c009de685626173fbea243e09dd..a5103414b79cbae8f415fcf58f4bf6a5de3cd55c --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/ets/arrowfunctionsability/ArrowfunctionsAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/ets/arrowfunctionsability/ArrowfunctionsAbility.ets @@ -1,56 +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 ArrowfunctionsAbility 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'); - } -} +/* + * 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 ArrowfunctionsAbility 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/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/module.json5 old mode 100755 new mode 100644 index 249019baddc03e204f1d5d4cb963c576c45873c7..10a492790713ba867f741ce51026411644e2d9b1 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "arrowfunctions", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ArrowfunctionsAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ArrowfunctionsAbility", - "srcEntry": "./ets/arrowfunctionsability/ArrowfunctionsAbility.ets", - "description": "$string:ArrowfunctionsAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ArrowfunctionsAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "arrowfunctions", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ArrowfunctionsAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ArrowfunctionsAbility", + "srcEntry": "./ets/arrowfunctionsability/ArrowfunctionsAbility.ets", + "description": "$string:ArrowfunctionsAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ArrowfunctionsAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9e14e199fb0c83a57728d2f3134f9fb49ab9e7fe..4fba8e77ac64b8dcfdf472f412beaeb762a00091 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/ohosTest/module.json5 @@ -1,27 +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": "arrowfunctions_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "arrowfunctions_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/arrowfunctions/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/build-profile.json5 old mode 100755 new mode 100644 index cf90707418606f7d7bc1cfd6abc850d0e1d91a94..63a72fc5f3f6887cebbddbfac6612381ed74c274 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/build-profile.json5 @@ -1,190 +1,190 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "inheritonly", - "srcPath": "./inheritonly", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "achievenon", - "srcPath": "./achievenon", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "arrowfunctions", - "srcPath": "./arrowfunctions", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "cannotbeused", - "srcPath": "./cannotbeused", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "inheritedfromnon", - "srcPath": "./inheritedfromnon", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "nocalculationsupport", - "srcPath": "./nocalculationsupport", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "notallowedInside", - "srcPath": "./notallowedInside", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "objectliterals", - "srcPath": "./objectliterals", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "templatetype", - "srcPath": "./templatetype", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "typecannot", - "srcPath": "./typecannot", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "variablenotsupported", - "srcPath": "./variablenotsupported", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "variablesupport", - "srcPath": "./variablesupport", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "inheritonly", + "srcPath": "./inheritonly", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "achievenon", + "srcPath": "./achievenon", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "arrowfunctions", + "srcPath": "./arrowfunctions", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "cannotbeused", + "srcPath": "./cannotbeused", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "inheritedfromnon", + "srcPath": "./inheritedfromnon", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "nocalculationsupport", + "srcPath": "./nocalculationsupport", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "notallowedInside", + "srcPath": "./notallowedInside", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "objectliterals", + "srcPath": "./objectliterals", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "templatetype", + "srcPath": "./templatetype", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "typecannot", + "srcPath": "./typecannot", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "variablenotsupported", + "srcPath": "./variablenotsupported", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "variablesupport", + "srcPath": "./variablesupport", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/oh-package.json5 old mode 100755 new mode 100644 index b8a1d53f8ce05e7d8667100118bed6bcc6d6ab5a..8b289874eca91d067320d099fdbf00ce9bdd0097 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "cannotbeused", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "cannotbeused", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/ets/cannotbeusedability/CannotbeusedAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/ets/cannotbeusedability/CannotbeusedAbility.ets old mode 100755 new mode 100644 index c4334fc2e04780591349e350f9b46c00c8a8ed85..903e0a0b16517ea0b1f1cec8cb4aabda0c8e157a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/ets/cannotbeusedability/CannotbeusedAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/ets/cannotbeusedability/CannotbeusedAbility.ets @@ -1,56 +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 CannotbeusedAbility 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'); - } -} +/* + * 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 CannotbeusedAbility 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/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/module.json5 old mode 100755 new mode 100644 index 23b37e40c6a5992549fceca6357521f0fa65bcc3..d7efe94a51170f90fe45c6fb941db744b8798466 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "cannotbeused", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CannotbeusedAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CannotbeusedAbility", - "srcEntry": "./ets/cannotbeusedability/CannotbeusedAbility.ets", - "description": "$string:CannotbeusedAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CannotbeusedAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "cannotbeused", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CannotbeusedAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CannotbeusedAbility", + "srcEntry": "./ets/cannotbeusedability/CannotbeusedAbility.ets", + "description": "$string:CannotbeusedAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CannotbeusedAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 1cd43069cdeec31bc5a9ca297a25d9ad557abb24..df5ccbe556f5e36097c762f3e865f6e2b2631a55 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/ohosTest/module.json5 @@ -1,27 +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": "cannotbeused_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "cannotbeused_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/cannotbeused/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/oh-package.json5 old mode 100755 new mode 100644 index 262be992a4d1ab8c7b5e635175321c4cbfc60260..5f2ff23668d4fb70b9c124650c21f3ad86041ef4 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "inheritedfromnon", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "inheritedfromnon", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/module.json5 old mode 100755 new mode 100644 index 5c75f9db0253068d322ae8ae6243439894d8f587..bd1c9d7e107653c2b3b14a028c2165f94c058c79 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "inheritedfromnon", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "InheritedfromnonAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "InheritedfromnonAbility", - "srcEntry": "./ets/inheritedfromnonability/InheritedfromnonAbility.ets", - "description": "$string:InheritedfromnonAbility_desc", - "icon": "$media:layered_image", - "label": "$string:InheritedfromnonAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "inheritedfromnon", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "InheritedfromnonAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "InheritedfromnonAbility", + "srcEntry": "./ets/inheritedfromnonability/InheritedfromnonAbility.ets", + "description": "$string:InheritedfromnonAbility_desc", + "icon": "$media:layered_image", + "label": "$string:InheritedfromnonAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 503c18e2748872deabcd78d64a9af1d9f97d84ed..a6c65cce0766f4d2ba993282606e736825073cc0 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/ohosTest/module.json5 @@ -1,27 +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": "inheritedfromnon_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "inheritedfromnon_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritedfromnon/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/oh-package.json5 old mode 100755 new mode 100644 index 68b429223571d72c6f02b543566840ff506c8bd6..1094343a30872fe67e23981cbed9b0f223c9e3b9 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * 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": "inheritonly", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} +/* + * 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": "inheritonly", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/module.json5 old mode 100755 new mode 100644 index 11cddab7765364f8924076e4c467fd9901aa711f..f88f96e831aa1ddfcf01881631ffbbf32f36969b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/module.json5 @@ -1,66 +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": "inheritonly", - "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" - } - ] - } - ] - } +/* + * 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": "inheritonly", + "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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/module.json5 old mode 100755 new mode 100644 index db2a11105497282e7b29a2bd703730de211867dd..e087c148e4a2f172203d0732f451e59d892b50a2 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/ohosTest/module.json5 @@ -1,27 +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": "inheritonly_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } +/* + * 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": "inheritonly_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/inheritonly/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/oh-package.json5 old mode 100755 new mode 100644 index 0262fd556fa0e82a60bfd0c1586b3d247fe2dc17..36774f109a8aad0ee139cafebabf0f61863e3651 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "nocalculationsupport", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "nocalculationsupport", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/module.json5 old mode 100755 new mode 100644 index 840daa891a5c910218687220a82d69d58de30ece..d34e7ac3445a2abf9c7250d752ad66515e65e8cd --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "nocalculationsupport", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "NocalculationsupportAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "NocalculationsupportAbility", - "srcEntry": "./ets/nocalculationsupportability/NocalculationsupportAbility.ets", - "description": "$string:NocalculationsupportAbility_desc", - "icon": "$media:layered_image", - "label": "$string:NocalculationsupportAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "nocalculationsupport", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "NocalculationsupportAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "NocalculationsupportAbility", + "srcEntry": "./ets/nocalculationsupportability/NocalculationsupportAbility.ets", + "description": "$string:NocalculationsupportAbility_desc", + "icon": "$media:layered_image", + "label": "$string:NocalculationsupportAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 46644b9a120e0199a00b0b0f6a278884f43bab0a..b4f93f658b5b6392910545c0588e15956950acec --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/ohosTest/module.json5 @@ -1,27 +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": "nocalculationsupport_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "nocalculationsupport_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/nocalculationsupport/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..be3bb1d96d5ed277a3c5806e3097b6b95e446286 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "notallowedinside", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..57ade9d6058da9161ac61ea35f77cfd60b8d7a30 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "notallowedInside", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "NotallowedInsideAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "NotallowedInsideAbility", + "srcEntry": "./ets/notallowedinsideability/NotallowedInsideAbility.ets", + "description": "$string:NotallowedInsideAbility_desc", + "icon": "$media:layered_image", + "label": "$string:NotallowedInsideAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3944d28a0523b7e47a7f67c636f70c4ec3a1c5bb --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/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": "notallowedInside_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b311b1744fac6ce8b06309d4a522a6cf3db24d9a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "objectliterals", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/objectliteralsability/ObjectliteralsAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/objectliteralsability/ObjectliteralsAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/objectliteralsability/ObjectliteralsAbility.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/objectliteralsability/ObjectliteralsAbility.ets index a047bbfadfb3a3e9e9bdfad81d396bfe3af466b7..2d61f034333e8da6b579ada872582bd4c23d4516 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/objectliteralsability/ObjectliteralsAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/objectliteralsability/ObjectliteralsAbility.ets @@ -1,56 +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 ObjectliteralsAbility 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'); - } -} +/* + * 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 ObjectliteralsAbility 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/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..46d71b3c4db6d28eba6c14eb3820be10b96817c7 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "objectliterals", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ObjectliteralsAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ObjectliteralsAbility", + "srcEntry": "./ets/objectliteralsability/ObjectliteralsAbility.ets", + "description": "$string:ObjectliteralsAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ObjectliteralsAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d1f7bfe9e897b9128aed4aaa359fd1acbe9742e4 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/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": "objectliterals_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/ohosTest.md old mode 100755 new mode 100644 index 6b863f0d7516afb5e09639875626a5562d68d5fe..145f148d7a6328e7ef9e11e303144c6dc015cd1a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/ohosTest.md @@ -1,20 +1,20 @@ -# RulesAndRestrictions 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------------------------------- | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| Sendable class只能继承自Sendable class | 位于InheritOnly模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 非Sendable class只能继承自非Sendable class | 位于InheritedFromNon模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 非Sendable class只能实现非Sendable interface | 位于AchieveNon模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Sendable class/interface成员变量必须是Sendable支持的数据类型 | 位于VariableSupport模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Sendable class/interface的成员变量不支持使用!断言 | 位于VariableNotSupported模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Sendable class/interface的成员变量不支持使用计算属性名 | 位于NoCalculationSupport模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 泛型类中的Sendable class,collections.Array,collections.Map,collections.Set的模板类型必须是Sendable类型 | 位于TemplateType模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Sendable class的内部不允许使用当前模块内上下文环境中定义的变量 | 位于NotAllowedInside模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Sendable class和Sendable function不能使用除了@Sendable的其它装饰器 | 位于CannotBeUsed模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 不能使用对象字面量/数组字面量初始化Sendable类型 | 位于ObjectLiterals模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 非Sendable类型不可以as成Sendable类型 | 位于TypeCannot模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 箭头函数不支持共享 | 位于ArrowFunctions模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +# RulesAndRestrictions 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------------------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Sendable class只能继承自Sendable class | 位于InheritOnly模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 非Sendable class只能继承自非Sendable class | 位于InheritedFromNon模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 非Sendable class只能实现非Sendable interface | 位于AchieveNon模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Sendable class/interface成员变量必须是Sendable支持的数据类型 | 位于VariableSupport模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Sendable class/interface的成员变量不支持使用!断言 | 位于VariableNotSupported模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Sendable class/interface的成员变量不支持使用计算属性名 | 位于NoCalculationSupport模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 泛型类中的Sendable class,collections.Array,collections.Map,collections.Set的模板类型必须是Sendable类型 | 位于TemplateType模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Sendable class的内部不允许使用当前模块内上下文环境中定义的变量 | 位于NotAllowedInside模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Sendable class和Sendable function不能使用除了@Sendable的其它装饰器 | 位于CannotBeUsed模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 不能使用对象字面量/数组字面量初始化Sendable类型 | 位于ObjectLiterals模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 非Sendable类型不可以as成Sendable类型 | 位于TypeCannot模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 箭头函数不支持共享 | 位于ArrowFunctions模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | | Sendable装饰器修饰类型时仅支持修饰函数类型 | 位于achievenon模块Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/screenshots/RulesAndRestrictions_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/screenshots/RulesAndRestrictions_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/screenshots/RulesAndRestrictions_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/screenshots/RulesAndRestrictions_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..64ef1bba31904ba29e9de3ef654356a547309445 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "templatetype", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/templatetypeability/TemplatetypeAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/templatetypeability/TemplatetypeAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/templatetypeability/TemplatetypeAbility.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/templatetypeability/TemplatetypeAbility.ets index ff03d624a5207cd5c0f0df6c2a671879c5799852..a4c871324447203389ec2175ecc9c0ffaceeff5c --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/templatetypeability/TemplatetypeAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/ets/templatetypeability/TemplatetypeAbility.ets @@ -1,56 +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 TemplatetypeAbility 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'); - } -} +/* + * 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 TemplatetypeAbility 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/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7ddbad453fe8cd9675ed764a39cf24f2b07d6d52 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "templatetype", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "TemplatetypeAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "TemplatetypeAbility", + "srcEntry": "./ets/templatetypeability/TemplatetypeAbility.ets", + "description": "$string:TemplatetypeAbility_desc", + "icon": "$media:layered_image", + "label": "$string:TemplatetypeAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e3217fd77717afb816dbe113af9a7ff5b425cce8 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/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": "templatetype_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..95280a463fabb58edb6e84e5881a93d3add3bbd6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "typecannot", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/typecannotability/TypecannotAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/typecannotability/TypecannotAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/typecannotability/TypecannotAbility.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/typecannotability/TypecannotAbility.ets index 6f994d2ad4af5d079e9abdb599d8856f7da03a2c..b63370a2df5b1c2593f9afbc378d65482dbfb0a8 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/typecannotability/TypecannotAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/ets/typecannotability/TypecannotAbility.ets @@ -1,56 +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 TypecannotAbility 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'); - } -} +/* + * 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 TypecannotAbility 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/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fd63f3981f89d4478fcbcb823f0dcf6a148e1548 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "typecannot", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "TypecannotAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "TypecannotAbility", + "srcEntry": "./ets/typecannotability/TypecannotAbility.ets", + "description": "$string:TypecannotAbility_desc", + "icon": "$media:layered_image", + "label": "$string:TypecannotAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5e0f529495ef9eb408c9a827bb2f36886b651e79 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/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": "typecannot_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9fee383a0fe54ed9fb0b1bd59ca1f50d6adbb97 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "variablenotsupported", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7f3312c028986d43263b23b613a6aaba8876a056 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "variablenotsupported", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "VariablenotsupportedAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "VariablenotsupportedAbility", + "srcEntry": "./ets/variablenotsupportedability/VariablenotsupportedAbility.ets", + "description": "$string:VariablenotsupportedAbility_desc", + "icon": "$media:layered_image", + "label": "$string:VariablenotsupportedAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d370f0279638af98534a5209c9894879961d552a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/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": "variablenotsupported_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2b90c7a5d175470a1be97236d77cae77c7dcf9ba --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "variablesupport", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..839e0588ab339ae37ec3636b3cb78a0f49abdd11 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "variablesupport", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "VariablesupportAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "VariablesupportAbility", + "srcEntry": "./ets/variablesupportability/VariablesupportAbility.ets", + "description": "$string:VariablesupportAbility_desc", + "icon": "$media:layered_image", + "label": "$string:VariablesupportAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..487ec34ffd8c2118d278304e163f9da5eda5d117 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/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": "variablesupport_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/app.json5 old mode 100755 new mode 100644 index 6475b5b34f4d63542330ad75ff2d81d482b3f95d..f70d9468b2d7b17c35933adec11526faafd10966 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/app.json5 @@ -1,25 +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.sendableobjectintroduction", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.sendableobjectintroduction", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 709001d41d18dcebcb6535d2e7821d3410f1841e..5ed25c150b8bf18bb493dcc68a2bd6bea1903086 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SendableObjectIntroduction" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SendableObjectIntroduction" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/README.md old mode 100755 new mode 100644 index 226690ade5ccc8391831e32b308ae91666928637..66f6f0edff728b79011056e87b5378f61b159204 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/README.md @@ -1,74 +1,74 @@ -# ArkTS Sendable对象简介 - -### 介绍 - -在传统JS引擎上,对象的并发通信开销的优化方式只有一种,就是把实现下沉到Native侧,通过[Transferable对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/transferabled-object.md)的转移或共享方式降低并发通信开销。而开发者仍然还有大量对象并发通信的诉求,这个问题在业界的JS引擎实现上并没有得到解决。 - -该工程中展示的代码详细描述可查如下链接: - -- [Sendable对象简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -class - ├── Index.ets // 装饰器修饰Class使用示例 -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── classusage.ets // 装饰器修饰Class使用示例 - │ │ ├── functionusage.ets // 装饰器修饰Function使用示例 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS Sendable对象简介 + +### 介绍 + +在传统JS引擎上,对象的并发通信开销的优化方式只有一种,就是把实现下沉到Native侧,通过[Transferable对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/transferabled-object.md)的转移或共享方式降低并发通信开销。而开发者仍然还有大量对象并发通信的诉求,这个问题在业界的JS引擎实现上并没有得到解决。 + +该工程中展示的代码详细描述可查如下链接: + +- [Sendable对象简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +class + ├── Index.ets // 装饰器修饰Class使用示例 +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── classusage.ets // 装饰器修饰Class使用示例 + │ │ ├── functionusage.ets // 装饰器修饰Function使用示例 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/build-profile.json5 old mode 100755 new mode 100644 index b56192b6cc935ae97ee38738ea22e2efb8e2c09f..199bbcdd0735cf3baa9719c46857dc523b849e6c --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/build-profile.json5 @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "class", - "srcPath": "./class", - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "class", + "srcPath": "./class", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/BuildProfile.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/BuildProfile.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/Index.ets old mode 100755 new mode 100644 index 9faaffcefcf96568f27d299ae68ec74e5fd63fb1..beab0dd0f90b9c2b4bbe5dcfc07b757669118c35 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/Index.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/Index.ets @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_modify_class] -export { MainPage } from './src/main/ets/components/MainPage'; - -@Sendable -class SendableTestClass { - desc: string = 'sendable: this is SendableTestClass '; - num: number = 5; - printName() { - console.info('sendable: SendableTestClass desc is: ' + this.desc); - } - get getNum(): number { - return this.num; - } -} - -let object = new SendableTestClass; -export { object } -// [End example_modify_class] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_modify_class] +export { MainPage } from './src/main/ets/components/MainPage'; + +@Sendable +class SendableTestClass { + desc: string = 'sendable: this is SendableTestClass '; + num: number = 5; + printName() { + console.info('sendable: SendableTestClass desc is: ' + this.desc); + } + get getNum(): number { + return this.num; + } +} + +let object = new SendableTestClass; +export { object } +// [End example_modify_class] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/build-profile.json5 old mode 100755 new mode 100644 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..aefa5f6959f0e65b9347a5182401ee9f4873007a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/build-profile.json5 @@ -1,46 +1,46 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/consumer-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/consumer-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/oh-package.json5 old mode 100755 new mode 100644 index f5b1cfe4d1110bfaaf52641a9ecacc6cdcbb28e6..281d417ae9d3a1483e0b63e5c7b57a8314722194 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * 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": "class", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} +/* + * 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": "class", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/ets/components/MainPage.ets old mode 100755 new mode 100644 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/ets/components/MainPage.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/ets/components/MainPage.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} +/* + * 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. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/module.json5 old mode 100755 new mode 100644 index cccbe501389f2316f27e2d8c732b99b27105fea1..e2be6bfb8bbdb97548ca232182bfade5bd49a47f --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/module.json5 @@ -1,25 +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. - */ - -{ - "module": { - "name": "class", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} +/* + * 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": "class", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 6bd546c8e847de189ef11f8434314104396076fc..66ecfa7e86d589ba2120da4bf9cfbe1b1fe88382 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/ohosTest/module.json5 @@ -1,27 +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": "class_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "class_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/class/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/oh-package.json5 old mode 100755 new mode 100644 index c38f46740d7ece3b2cc55d1f87a97eb9d6197c4c..047c5afc10f657c5cd36f3e0199790d507017d46 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/oh-package.json5 @@ -1,27 +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. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "class": "file:../class" - } -} - +/* + * 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": { + "class": "file:../class" + } +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/classusage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/classusage.ets old mode 100755 new mode 100644 index 0ec63eed40877aa6d3232d9a02f9cf2cd3cc40f0..2d4b84f75384d04b6295b865288bdc1a32ea8588 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/classusage.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/classusage.ets @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -@Entry -@Component -struct ClassUsage { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - import('class').then((ns: ESObject) => { - ns.object.printName(); - }) - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +@Entry +@Component +struct ClassUsage { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + import('class').then((ns: ESObject) => { + ns.object.printName(); + }) + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/functionusage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/functionusage.ets old mode 100755 new mode 100644 index ba9bdb75e0d0ee02bb4f6e79237457e3d29f205d..8f7dc518bea38802ec7ede667b24b8c91615b824 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/functionusage.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/managers/functionusage.ets @@ -1,81 +1,81 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_modify_function] -@Sendable -type SendableFuncType = () => void; - -@Sendable -class TopLevelSendableClass { - num: number = 1; - - PrintNum() { - console.info('Top level sendable class'); - } -} - -@Sendable -function topLevelSendableFunction() { - console.info('Top level sendable function'); -} - -@Sendable -function sendableTestFunction() { - const topClass = new TopLevelSendableClass(); // 顶层sendable class - topClass.PrintNum(); - topLevelSendableFunction(); // 顶层sendable function - console.info('Sendable test function'); -} - -@Sendable -class SendableTestClass { - constructor(func: SendableFuncType) { - this.callback = func; - } - - callback: SendableFuncType; // 顶层sendable function - - CallSendableFunc() { - sendableTestFunction(); // 顶层sendable function - } -} -// [End example_modify_function] - -@Entry -@Component -struct FunctionUsage { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - let sendableClass = new SendableTestClass(sendableTestFunction); - sendableClass.callback(); - sendableClass.CallSendableFunc(); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_modify_function] +@Sendable +type SendableFuncType = () => void; + +@Sendable +class TopLevelSendableClass { + num: number = 1; + + PrintNum() { + console.info('Top level sendable class'); + } +} + +@Sendable +function topLevelSendableFunction() { + console.info('Top level sendable function'); +} + +@Sendable +function sendableTestFunction() { + const topClass = new TopLevelSendableClass(); // 顶层sendable class + topClass.PrintNum(); + topLevelSendableFunction(); // 顶层sendable function + console.info('Sendable test function'); +} + +@Sendable +class SendableTestClass { + constructor(func: SendableFuncType) { + this.callback = func; + } + + callback: SendableFuncType; // 顶层sendable function + + CallSendableFunc() { + sendableTestFunction(); // 顶层sendable function + } +} +// [End example_modify_function] + +@Entry +@Component +struct FunctionUsage { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + let sendableClass = new SendableTestClass(sendableTestFunction); + sendableClass.callback(); + sendableClass.CallSendableFunc(); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index 79a04af93bcf6ee2b7d288a24558060fb6c69345..a0f1755b8cccfecc4200cf5b1ed991805e3e00b6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/ets/util/resource.ets @@ -1,25 +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. - */ - -export class P2PManager { - public resourceToString(resource: Resource):string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - +/* + * 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 class P2PManager { + public resourceToString(resource: Resource):string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/ohosTest.md old mode 100755 new mode 100644 index 146fe477fc901b78171b43bbf9ea1630241e76d8..262265b7a578d5e269013997e77b3845263cb57a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/ohosTest.md @@ -1,9 +1,9 @@ -# SendableObjectIntroduction 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------- | --------------------- | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 装饰器修饰Class使用示例 | 位于classusage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +# SendableObjectIntroduction 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------- | --------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 装饰器修饰Class使用示例 | 位于classusage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | | 装饰器修饰Function使用示例 | 位于functionusage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/screenshots/SendableObjectIntroduction_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/screenshots/SendableObjectIntroduction_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/screenshots/SendableObjectIntroduction_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectIntroduction/screenshots/SendableObjectIntroduction_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/app.json5 old mode 100755 new mode 100644 index 6c008d7cf32e8ae6b75cb7f8891a8c9b4ed9dbbd..9cde574c4a335947d9c469cfe7adc3443cfc4041 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/app.json5 @@ -1,25 +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.sendableobjectrelated", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.sendableobjectrelated", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 266194dd18998baf22352fa9778e24719daaba05..5851a8ec0435dee4db2131f3ddf468e6fa9069bc --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SendableObjectRelated" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SendableObjectRelated" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/README.md old mode 100755 new mode 100644 index c779b9c44fd1938265c8880b3b7be5a691814235..774f3873783e205d978b64b8388f39e069525fcf --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/README.md @@ -1,112 +1,112 @@ -# ArkTS Sendable对象相关 - -### 介绍 - -#### 异步锁 - -为了解决多线程并发任务间的数据竞争问题,ArkTS引入了异步锁能力。异步锁可能会被类对象持有,因此为了更方便地在并发实例间获取同一个异步锁对象,[AsyncLock对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-utils.md#asynclock)支持跨线程引用传递。 - -由于ArkTS语言支持异步操作,阻塞锁容易产生死锁问题,因此在ArkTS中仅支持异步锁(非阻塞式锁)。同时,异步锁还可以用于保证单线程内的异步任务时序一致性,防止异步任务时序不确定导致的同步问题。 - -#### ASON解析与生成 - -[ASON工具](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-utils.md#arktsutilsason)与JS提供的JSON工具类似,JSON用于进行JS对象的序列化(stringify)、反序列化(parse)。ASON则提供了[Sendable对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md)的序列化、反序列化能力。可以通过ASON.stringify方法将对象转换成字符串,也可以通过ASON.parse方法将字符串转成Sendable对象,以便此对象在并发任务间进行高性能引用传递。 - -#### 共享容器 - -ArkTS共享容器([@arkts.collections (ArkTS容器集)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md))是一种在并发任务间共享传输的容器类,可以用于并发场景下的高性能数据传递。功能与Ecmascript262规范定义的容器类似,但仍然有部分差异,具体可见[共享容器与原生API方法的行为差异对比](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-collections-introduction.md#共享容器与原生api方法的行为差异对比)。 - -ArkTS共享容器在多个并发任务间传递时,其默认行为是引用传递,支持多个并发任务可以操作同一个容器实例。另外,也支持拷贝传递,即每个并发任务持有一个ArkTS容器实例。 - -ArkTS共享容器并不是线程安全的,内部使用了fail-fast(快速失败)机制,即当检测多个并发实例同时对容器进行结构性改变时,会触发异常。因此,在容器内修改属性的场景下,开发者需要使用ArkTS提供的[异步锁](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-async-lock-introduction.md)机制保证ArkTS容器的安全访问。 - -ArkTS共享容器包含如下几种:[Array](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsarray)、[Map](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsmap)、[Set](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsset)、[TypedArray](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionstypedarray)(Int8Array、Uint8Array、Int16Array、Uint16Array、Int32Array、Uint32Array、Uint8ClampedArray、Float32Array)、[ArrayBuffer](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsarraybuffer)等,具体可见[@arkts.collections (ArkTS容器集)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md)。 - -#### 共享模块 - -共享模块是进程内只会加载一次的模块,使用"use shared"这一指令来标记一个模块是否为共享模块。 - -非共享模块在同一线程内只加载一次,在不同线程间会加载多次,在不同的线程内都会产生新的模块对象。因此可以使用共享模块来实现进程单例。 - -#### Sendable对象冻结 - -Sendable对象支持冻结操作,冻结后的对象变成只读对象,不能增删改属性,因此在多个并发实例间访问均不需要加锁,可以通过调用[Object.freeze](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)接口冻结对象。 - -该工程中展示的代码详细描述可查如下链接: - -- [异步锁](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-async-lock-introduction.md) -- [ASON解析与生成](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/ason-parsing-generation.md) -- [共享容器](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-collections-introduction.md) -- [共享模块](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable-module.md) -- [Sendable对象冻结](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-freeze.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── ArktsAsyncLockIntroduction.ets // 异步锁示例代码 - │ │ ├── ArktsCollectionsIntroduction.ets // 共享容器示例代码 - │ │ ├── ArktsSendableModule.ets // 共享模块示例代码 - │ │ ├── AsonParsingGeneration.ets // ASON解析与生成示例代码 - │ │ ├── helper.ts // Sendable对象冻结示例代码 - │ │ ├── SendableFreeze.ets // Sendable对象冻结示例代码 - │ │ ├── sharedModule.ets // 共享模块示例代码 - │ │ ├── test.ets // 共享模块示例代码 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ │ ├── workers - │ │ ├── Worker.ets // Sendable对象冻结示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS Sendable对象相关 + +### 介绍 + +#### 异步锁 + +为了解决多线程并发任务间的数据竞争问题,ArkTS引入了异步锁能力。异步锁可能会被类对象持有,因此为了更方便地在并发实例间获取同一个异步锁对象,[AsyncLock对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-utils.md#asynclock)支持跨线程引用传递。 + +由于ArkTS语言支持异步操作,阻塞锁容易产生死锁问题,因此在ArkTS中仅支持异步锁(非阻塞式锁)。同时,异步锁还可以用于保证单线程内的异步任务时序一致性,防止异步任务时序不确定导致的同步问题。 + +#### ASON解析与生成 + +[ASON工具](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-utils.md#arktsutilsason)与JS提供的JSON工具类似,JSON用于进行JS对象的序列化(stringify)、反序列化(parse)。ASON则提供了[Sendable对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable.md)的序列化、反序列化能力。可以通过ASON.stringify方法将对象转换成字符串,也可以通过ASON.parse方法将字符串转成Sendable对象,以便此对象在并发任务间进行高性能引用传递。 + +#### 共享容器 + +ArkTS共享容器([@arkts.collections (ArkTS容器集)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md))是一种在并发任务间共享传输的容器类,可以用于并发场景下的高性能数据传递。功能与Ecmascript262规范定义的容器类似,但仍然有部分差异,具体可见[共享容器与原生API方法的行为差异对比](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-collections-introduction.md#共享容器与原生api方法的行为差异对比)。 + +ArkTS共享容器在多个并发任务间传递时,其默认行为是引用传递,支持多个并发任务可以操作同一个容器实例。另外,也支持拷贝传递,即每个并发任务持有一个ArkTS容器实例。 + +ArkTS共享容器并不是线程安全的,内部使用了fail-fast(快速失败)机制,即当检测多个并发实例同时对容器进行结构性改变时,会触发异常。因此,在容器内修改属性的场景下,开发者需要使用ArkTS提供的[异步锁](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-async-lock-introduction.md)机制保证ArkTS容器的安全访问。 + +ArkTS共享容器包含如下几种:[Array](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsarray)、[Map](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsmap)、[Set](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsset)、[TypedArray](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionstypedarray)(Int8Array、Uint8Array、Int16Array、Uint16Array、Int32Array、Uint32Array、Uint8ClampedArray、Float32Array)、[ArrayBuffer](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md#collectionsarraybuffer)等,具体可见[@arkts.collections (ArkTS容器集)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-arkts-collections.md)。 + +#### 共享模块 + +共享模块是进程内只会加载一次的模块,使用"use shared"这一指令来标记一个模块是否为共享模块。 + +非共享模块在同一线程内只加载一次,在不同线程间会加载多次,在不同的线程内都会产生新的模块对象。因此可以使用共享模块来实现进程单例。 + +#### Sendable对象冻结 + +Sendable对象支持冻结操作,冻结后的对象变成只读对象,不能增删改属性,因此在多个并发实例间访问均不需要加锁,可以通过调用[Object.freeze](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)接口冻结对象。 + +该工程中展示的代码详细描述可查如下链接: + +- [异步锁](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-async-lock-introduction.md) +- [ASON解析与生成](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/ason-parsing-generation.md) +- [共享容器](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-collections-introduction.md) +- [共享模块](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-sendable-module.md) +- [Sendable对象冻结](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-freeze.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── ArktsAsyncLockIntroduction.ets // 异步锁示例代码 + │ │ ├── ArktsCollectionsIntroduction.ets // 共享容器示例代码 + │ │ ├── ArktsSendableModule.ets // 共享模块示例代码 + │ │ ├── AsonParsingGeneration.ets // ASON解析与生成示例代码 + │ │ ├── helper.ts // Sendable对象冻结示例代码 + │ │ ├── SendableFreeze.ets // Sendable对象冻结示例代码 + │ │ ├── sharedModule.ets // 共享模块示例代码 + │ │ ├── test.ets // 共享模块示例代码 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ │ ├── workers + │ │ ├── Worker.ets // Sendable对象冻结示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/build-profile.json5 old mode 100755 new mode 100644 index 59aacbbe9dfd99c6cbd33768d4ee63ad7178a1dd..9308c2de5fe3b0c4f971d581d1c1fe0755b1c385 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/build-profile.json5 @@ -1,48 +1,48 @@ - -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "apiType": "stageMode", - "buildOption": { - "sourceOption": { - "workers": [ - "./src/main/ets/workers/Worker.ets" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] + +/* + * 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": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/Worker.ets" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsAsyncLockIntroduction.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsAsyncLockIntroduction.ets old mode 100755 new mode 100644 index 4aa790451d85250f912bbdfb0a340fb7ae01d652..7fbe66b90db56960d8b8b217017aaeb5ba005488 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsAsyncLockIntroduction.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsAsyncLockIntroduction.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_protect] -import { ArkTSUtils, taskpool } from '@kit.ArkTS'; - -@Sendable -export class A { - private count_: number = 0; - public lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock(); - - public async getCount(): Promise { - // 对需要保护的数据加异步锁 - return this.lock_.lockAsync(() => { - return this.count_; - }) - } - - public async increaseCount() { - // 对需要保护的数据加异步锁 - await this.lock_.lockAsync(() => { - this.count_++; - }) - } -} - -@Concurrent -async function printCount(a: A) { - console.info('InputModule: count is:' + await a.getCount()); -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(async () => { - // 创建sendable对象a - let a: A = new A(); - // 将实例a传递给子线程 - await taskpool.execute(printCount, a); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End example_protect] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_protect] +import { ArkTSUtils, taskpool } from '@kit.ArkTS'; + +@Sendable +export class A { + private count_: number = 0; + public lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock(); + + public async getCount(): Promise { + // 对需要保护的数据加异步锁 + return this.lock_.lockAsync(() => { + return this.count_; + }) + } + + public async increaseCount() { + // 对需要保护的数据加异步锁 + await this.lock_.lockAsync(() => { + this.count_++; + }) + } +} + +@Concurrent +async function printCount(a: A) { + console.info('InputModule: count is:' + await a.getCount()); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(async () => { + // 创建sendable对象a + let a: A = new A(); + // 将实例a传递给子线程 + await taskpool.execute(printCount, a); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End example_protect] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsCollectionsIntroduction.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsCollectionsIntroduction.ets old mode 100755 new mode 100644 index 08bc354d33e7126dc6dc5ee4d081b1c934726d30..0e7507a4dbb0f31948516eda6a4f00753cfa92be --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsCollectionsIntroduction.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsCollectionsIntroduction.ets @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_use] -import { ArkTSUtils, collections, taskpool } from '@kit.ArkTS'; - -@Concurrent -async function add(arr: collections.Array, lock: ArkTSUtils.locks.AsyncLock) { - await lock.lockAsync(() => { // 如果不添加异步锁,任务会因为数据竞争冲突,导致抛异常失败 - arr[0]++; - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - let taskGroup = new taskpool.TaskGroup(); - let lock = new ArkTSUtils.locks.AsyncLock(); - let arr = collections.Array.create(1, 0); - let count = 1000; - while (count--) { - taskGroup.addTask(add, arr, lock); - } - taskpool.execute(taskGroup).then(() => { - console.info(`Return success: ${arr[0]} === ${count}`); - }).catch((e: Error) => { - console.error('Return error.'); - }) - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End example_use] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_use] +import { ArkTSUtils, collections, taskpool } from '@kit.ArkTS'; + +@Concurrent +async function add(arr: collections.Array, lock: ArkTSUtils.locks.AsyncLock) { + await lock.lockAsync(() => { // 如果不添加异步锁,任务会因为数据竞争冲突,导致抛异常失败 + arr[0]++; + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + let taskGroup = new taskpool.TaskGroup(); + let lock = new ArkTSUtils.locks.AsyncLock(); + let arr = collections.Array.create(1, 0); + let count = 1000; + while (count--) { + taskGroup.addTask(add, arr, lock); + } + taskpool.execute(taskGroup).then(() => { + console.info(`Return success: ${arr[0]} === ${count}`); + }).catch((e: Error) => { + console.error('Return error.'); + }) + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End example_use] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsSendableModule.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsSendableModule.ets old mode 100755 new mode 100644 index d1ec1cef13805c15268c3f595e20478528952403..a93bfd3d078eabf3f5b9d26dd98ba350aa25d452 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsSendableModule.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/ArktsSendableModule.ets @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start multi_thread_operate_exported_obj] -import { ArkTSUtils, taskpool } from '@kit.ArkTS'; -import { singletonA } from './sharedModule'; - -export { num, str } from './test'; // 正确示例,导出对象合集 - -@Sendable -export class A { - private count_: number = 0; - public lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock(); - - public async getCount(): Promise { - return this.lock_.lockAsync(() => { - return this.count_; - }) - } - - public async increaseCount() { - await this.lock_.lockAsync(() => { - this.count_++; - }) - } -} - -@Concurrent -async function increaseCount() { - await singletonA.increaseCount(); - console.info('SharedModule: count is:' + await singletonA.getCount()); -} - -@Concurrent -async function printCount() { - console.info('SharedModule: count is:' + await singletonA.getCount()); -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - @State mainThreadPrint: string = 'MainThread print count'; - @State taskpoolPrint: string = 'Taskpool print count'; - @State mainThreadIncrease: string = 'MainThread increase count'; - @State taskpoolIncrease: string = 'Taskpool increase count'; - - build() { - Row() { - Column() { - Button(this.mainThreadPrint) - .id('MainThread print count') - .onClick(async () => { - await printCount(); - this.mainThreadPrint = 'success'; - }) - Button(this.taskpoolPrint) - .id('Taskpool print count') - .onClick(async () => { - await taskpool.execute(printCount); - this.taskpoolPrint = 'success'; - }) - Button(this.mainThreadIncrease) - .id('MainThread increase count') - .onClick(async () => { - await increaseCount(); - this.mainThreadIncrease = 'success'; - }) - Button(this.taskpoolIncrease) - .id('Taskpool increase count') - .onClick(async () => { - await taskpool.execute(increaseCount); - this.taskpoolIncrease = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start multi_thread_operate_exported_obj] +import { ArkTSUtils, taskpool } from '@kit.ArkTS'; +import { singletonA } from './sharedModule'; + +export { num, str } from './test'; // 正确示例,导出对象合集 + +@Sendable +export class A { + private count_: number = 0; + public lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock(); + + public async getCount(): Promise { + return this.lock_.lockAsync(() => { + return this.count_; + }) + } + + public async increaseCount() { + await this.lock_.lockAsync(() => { + this.count_++; + }) + } +} + +@Concurrent +async function increaseCount() { + await singletonA.increaseCount(); + console.info('SharedModule: count is:' + await singletonA.getCount()); +} + +@Concurrent +async function printCount() { + console.info('SharedModule: count is:' + await singletonA.getCount()); +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + @State mainThreadPrint: string = 'MainThread print count'; + @State taskpoolPrint: string = 'Taskpool print count'; + @State mainThreadIncrease: string = 'MainThread increase count'; + @State taskpoolIncrease: string = 'Taskpool increase count'; + + build() { + Row() { + Column() { + Button(this.mainThreadPrint) + .id('MainThread print count') + .onClick(async () => { + await printCount(); + this.mainThreadPrint = 'success'; + }) + Button(this.taskpoolPrint) + .id('Taskpool print count') + .onClick(async () => { + await taskpool.execute(printCount); + this.taskpoolPrint = 'success'; + }) + Button(this.mainThreadIncrease) + .id('MainThread increase count') + .onClick(async () => { + await increaseCount(); + this.mainThreadIncrease = 'success'; + }) + Button(this.taskpoolIncrease) + .id('Taskpool increase count') + .onClick(async () => { + await taskpool.execute(increaseCount); + this.taskpoolIncrease = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} // [End multi_thread_operate_exported_obj] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/AsonParsingGeneration.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/AsonParsingGeneration.ets old mode 100755 new mode 100644 index 406d1c3bf0ba82174e0f7e0efb83fd987714d1b5..04d7088514d2a17254854ed067b8877aaf832a66 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/AsonParsingGeneration.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/AsonParsingGeneration.ets @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start example_serialize] -import { ArkTSUtils, collections } from '@kit.ArkTS'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - ArkTSUtils.ASON.parse('{}'); - ArkTSUtils.ASON.stringify(new collections.Array(1, 2, 3)); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End example_serialize] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start example_serialize] +import { ArkTSUtils, collections } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + ArkTSUtils.ASON.parse('{}'); + ArkTSUtils.ASON.stringify(new collections.Array(1, 2, 3)); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End example_serialize] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/SendableFreeze.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/SendableFreeze.ets old mode 100755 new mode 100644 index 08054f66745f2a7d52aa4b48867c2a90013e9bfc..88bce935a6037012138cc5508dbcefa337253552 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/SendableFreeze.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/SendableFreeze.ets @@ -1,56 +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. - */ - -// [Start freeze_obj_send_child_thread] -import { freezeObj } from './helper'; -import { worker } from '@kit.ArkTS'; - -@Sendable -export class GlobalConfig { - // 一些配置属性与方法 - init() { - // 初始化相关逻辑 - freezeObj(this); // 初始化完成后冻结当前对象 - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Sendable freezeObj Test'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - let gConifg = new GlobalConfig(); - gConifg.init(); - const workerInstance = new worker.ThreadWorker('entry/ets/workers/Worker.ets', { name: 'Worker1' }); - workerInstance.postMessage(gConifg); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End freeze_obj_send_child_thread] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start freeze_obj_send_child_thread] +import { freezeObj } from './helper'; +import { worker } from '@kit.ArkTS'; + +@Sendable +export class GlobalConfig { + // 一些配置属性与方法 + init() { + // 初始化相关逻辑 + freezeObj(this); // 初始化完成后冻结当前对象 + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Sendable freezeObj Test'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + let gConifg = new GlobalConfig(); + gConifg.init(); + const workerInstance = new worker.ThreadWorker('entry/ets/workers/Worker.ets', { name: 'Worker1' }); + workerInstance.postMessage(gConifg); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End freeze_obj_send_child_thread] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/helper.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/helper.ts old mode 100755 new mode 100644 index a79139165c2a907c31532655d04bb43b699b746d..1b512fdcfc87aa228d61f7dd39d60771c8e940d8 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/helper.ts +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/helper.ts @@ -1,20 +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. - */ - -// [Start provide_encapsulate_method] -export function freezeObj(obj: any) { - Object.freeze(obj); -} -// [End provide_encapsulate_method] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start provide_encapsulate_method] +export function freezeObj(obj: any) { + Object.freeze(obj); +} +// [End provide_encapsulate_method] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/sharedModule.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/sharedModule.ets old mode 100755 new mode 100644 index 400e8d095f937a4481b8cf0e21b5b5f351e53ce2..aced6a41d12c9346731f281cd72123c0c6d2c5b7 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/sharedModule.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/sharedModule.ets @@ -1,43 +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. - */ - -// [Start export_sendable_object] -// 共享模块 -import { ArkTSUtils } from '@kit.ArkTS'; - -// 声明当前模块为共享模块,只能导出可Sendable数据 -'use shared' - -// 共享模块,SingletonA全局唯一 -@Sendable -class SingletonA { - private count_: number = 0; - public lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock(); - - public async getCount(): Promise { - return this.lock_.lockAsync(() => { - return this.count_; - }) - } - - public async increaseCount() { - await this.lock_.lockAsync(() => { - this.count_++; - }) - } -} - -export let singletonA = new SingletonA(); -// [End export_sendable_object] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_sendable_object] +// 共享模块 +import { ArkTSUtils } from '@kit.ArkTS'; + +// 声明当前模块为共享模块,只能导出可Sendable数据 +'use shared' + +// 共享模块,SingletonA全局唯一 +@Sendable +class SingletonA { + private count_: number = 0; + public lock_: ArkTSUtils.locks.AsyncLock = new ArkTSUtils.locks.AsyncLock(); + + public async getCount(): Promise { + return this.lock_.lockAsync(() => { + return this.count_; + }) + } + + public async increaseCount() { + await this.lock_.lockAsync(() => { + this.count_++; + }) + } +} + +export let singletonA = new SingletonA(); +// [End export_sendable_object] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/test.ets old mode 100755 new mode 100644 index b8d2e46c3dc6c3f500e55052f694bc6bb159a533..2a511a29df76cec60e96a008a9258c96009a50d2 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/test.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/managers/test.ets @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// 不允许使用side-effects-import -// [Start constrained_test] -// import "./sharedModule" - -export let num = 1; -export let str = 'aaa'; - -// 共享模块 -'use shared' - -// export * from './test'; // 编译报错,不允许直接导出模块 -// export {num, str} from './test'; // 正确示例,导出对象合集 -// [End constrained_test] +/* + * 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. + */ + +// 不允许使用side-effects-import +// [Start constrained_test] +// import "./sharedModule" + +export let num = 1; +export let str = 'aaa'; + +// 共享模块 +'use shared' + +// export * from './test'; // 编译报错,不允许直接导出模块 +// export {num, str} from './test'; // 正确示例,导出对象合集 +// [End constrained_test] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index 79a04af93bcf6ee2b7d288a24558060fb6c69345..a0f1755b8cccfecc4200cf5b1ed991805e3e00b6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/util/resource.ets @@ -1,25 +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. - */ - -export class P2PManager { - public resourceToString(resource: Resource):string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - +/* + * 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 class P2PManager { + public resourceToString(resource: Resource):string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/workers/Worker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/ets/workers/Worker.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/ohosTest.md old mode 100755 new mode 100644 index 2b6334d9e476507eeff01e64b8bc8bc0c46b7717..52a5619b38b75b5c41348a3131e3ed8053166138 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/ohosTest.md @@ -1,12 +1,12 @@ -# SendableObjectRelated 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------- | ------------------------------------ | ------------------------------------------------------------ | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 异步锁 | 位于ArktsAsyncLockIntroduction.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| ASON解析与生成 | 位于AsonParsingGeneration.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 共享容器 | 位于ArktsCollectionsIntroduction.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 共享模块 | 位于ArktsSendableModule.ets | 点击MainThread print count;
点击Taskpool print count;
点击MainThread increase count
点击Taskpool increase count | 1秒后页面显示“success” | 是 | Pass | +# SendableObjectRelated 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------------------------ | ------------------------------------------------------------ | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 异步锁 | 位于ArktsAsyncLockIntroduction.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| ASON解析与生成 | 位于AsonParsingGeneration.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 共享容器 | 位于ArktsCollectionsIntroduction.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 共享模块 | 位于ArktsSendableModule.ets | 点击MainThread print count;
点击Taskpool print count;
点击MainThread increase count
点击Taskpool increase count | 1秒后页面显示“success” | 是 | Pass | | Sendable对象冻结 | 位于SendableFreeze.ets | 点击Sendable freezeObj Test | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/screenshots/SendableObjectRelated_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/screenshots/SendableObjectRelated_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/screenshots/SendableObjectRelated_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableObjectRelated/screenshots/SendableObjectRelated_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/app.json5 old mode 100755 new mode 100644 index d64880256ffcc2d52b74d603f6d85b9952bc44f2..7ad9c602c4e347c7415305f894002c5ad47feeba --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/app.json5 @@ -1,25 +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.sendablescenarios", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.sendablescenarios", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 22710ded99e49ba678f485474cde270b9ad32023..2d7136e3a901db0bf597cd0848dfaa01482a4ec1 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SendableScenarios" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SendableScenarios" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/README.md old mode 100755 new mode 100644 index e2db0e7115a0075f82e8ed4388a6809b7d2855c5..7fcabaa13447f919fe36aa714a8b027f076717a8 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/README.md @@ -1,85 +1,85 @@ -# ArkTS Sendable使用场景 - -### 介绍 - -Sendable对象可以在不同并发实例间通过引用传递。通过引用传递方式传输对象相比序列化方式更加高效,同时不会丢失class上携带的成员方法。因此,Sendable主要可以解决两个场景的问题: - -- 跨并发实例传输大数据(例如可能达到100KB以上的数据)。 -- 跨并发实例传递带方法的class实例对象。 - -该工程中展示的代码详细描述可查如下链接: - -- [Sendable使用场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-guide.md) - -### 效果预览 - -| bigdata模块 | crossconcurrency模块 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 运行bigdata模块,分别点击Listener task和Data processing task执行程序 -2. 执行结果会即时反馈在屏幕中,并在控制台打印log。 -3. 运行crossconcurrency模块,点击Hello World执行程序 -4. 执行结果会即时反馈在屏幕中,并在控制台打印log。 - -### 工程目录 - -``` -bigdata/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 跨并发实例传输大数据场景示例代码 - │ │ ├── sendable.ets // 跨并发实例传输大数据场景示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 - crossconcurrency/src/ - ├── main - │ ├── ets - │ │ ├── crossconcurrencyability - │ │ ├── pages - │ │ ├── Index.ets // 跨并发实例传递带方法的class实例对象示例代码 - │ │ ├── sendable.ets // 跨并发实例传递带方法的class实例对象示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS Sendable使用场景 + +### 介绍 + +Sendable对象可以在不同并发实例间通过引用传递。通过引用传递方式传输对象相比序列化方式更加高效,同时不会丢失class上携带的成员方法。因此,Sendable主要可以解决两个场景的问题: + +- 跨并发实例传输大数据(例如可能达到100KB以上的数据)。 +- 跨并发实例传递带方法的class实例对象。 + +该工程中展示的代码详细描述可查如下链接: + +- [Sendable使用场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-guide.md) + +### 效果预览 + +| bigdata模块 | crossconcurrency模块 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 运行bigdata模块,分别点击Listener task和Data processing task执行程序 +2. 执行结果会即时反馈在屏幕中,并在控制台打印log。 +3. 运行crossconcurrency模块,点击Hello World执行程序 +4. 执行结果会即时反馈在屏幕中,并在控制台打印log。 + +### 工程目录 + +``` +bigdata/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 跨并发实例传输大数据场景示例代码 + │ │ ├── sendable.ets // 跨并发实例传输大数据场景示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 + crossconcurrency/src/ + ├── main + │ ├── ets + │ │ ├── crossconcurrencyability + │ │ ├── pages + │ │ ├── Index.ets // 跨并发实例传递带方法的class实例对象示例代码 + │ │ ├── sendable.ets // 跨并发实例传递带方法的class实例对象示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/oh-package.json5 old mode 100755 new mode 100644 index 92738004f01ee8ef1b592e75649adff3ce5686e8..93ac2c522a65e6e46828abff69cb5b9b7b8d9000 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * 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": "bigdata", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} +/* + * 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": "bigdata", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/pages/sendable.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/pages/sendable.ets old mode 100755 new mode 100644 index cb2558af922d00d9411e4569ac83c05369d75bbb..ed1e51ff9971b9918e53caceae216c680a572771 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/pages/sendable.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/ets/pages/sendable.ets @@ -1,43 +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. - */ - -// [Start across_concurrent_instance_transfer_large_data] -// 将数据量较大的数据在Sendable class中组装 -@Sendable -export class TestTypeA { - public name: string = 'A'; - constructor(name: string) { - this.name = name; - } -} - -@Sendable -export class TestTypeB { - public name: string = 'B'; - constructor(name: string) { - this.name = name; - } -} - -@Sendable -export class Test { - public data1: TestTypeA; - public data2: TestTypeB; - constructor(arg1: TestTypeA, arg2: TestTypeB) { - this.data1 = arg1; - this.data2 = arg2; - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start across_concurrent_instance_transfer_large_data] +// 将数据量较大的数据在Sendable class中组装 +@Sendable +export class TestTypeA { + public name: string = 'A'; + constructor(name: string) { + this.name = name; + } +} + +@Sendable +export class TestTypeB { + public name: string = 'B'; + constructor(name: string) { + this.name = name; + } +} + +@Sendable +export class Test { + public data1: TestTypeA; + public data2: TestTypeB; + constructor(arg1: TestTypeA, arg2: TestTypeB) { + this.data1 = arg1; + this.data2 = arg2; + } +} // [End across_concurrent_instance_transfer_large_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/module.json5 old mode 100755 new mode 100644 index c10f0015f23e3c7e2b5669292b10194d3242a47f..8833eaf55322e96f8e9df55e2027ce16d3a865d6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/module.json5 @@ -1,66 +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": "bigdata", - "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" - } - ] - } - ] - } +/* + * 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": "bigdata", + "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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/module.json5 old mode 100755 new mode 100644 index de812daa8b7f436172f7d2a13a3376149d1ba3b0..32a2233605e1f92ea72fb8612401277c7ad0968e --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/ohosTest/module.json5 @@ -1,27 +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": "bigdata_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } +/* + * 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": "bigdata_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/bigdata/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/build-profile.json5 old mode 100755 new mode 100644 index becf2418c8c83485492b02a87e43ba96a4c55b85..9708d03bca464eae0186b76471efc828719942d5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/build-profile.json5 @@ -1,70 +1,70 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "bigdata", - "srcPath": "./bigdata", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "crossconcurrency", - "srcPath": "./crossconcurrency", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "bigdata", + "srcPath": "./bigdata", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "crossconcurrency", + "srcPath": "./crossconcurrency", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/oh-package.json5 old mode 100755 new mode 100644 index 7b0402b93852268bac5d57c67f46f325046a92f6..2153ed2bf1c59c166b32d25996d72b6bb86a4bf7 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "crossconcurrency", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "crossconcurrency", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/crossconcurrencyability/CrossconcurrencyAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/crossconcurrencyability/CrossconcurrencyAbility.ets deleted file mode 100755 index 500f3aa377f25e9ebe7c0062bdafa2d25a01643e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/crossconcurrencyability/CrossconcurrencyAbility.ets +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 CrossconcurrencyAbility 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/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/pages/sendable.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/pages/sendable.ets old mode 100755 new mode 100644 index b48d806bf6e5a6bd16bb32b05a9f71ed4183a5cd..37de2cd3c3de30d3188ea1610d70c8658c8ad286 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/pages/sendable.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/ets/pages/sendable.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start across_concurrent_instance_pass_class_method] -// 定义模拟类Test,模仿开发过程中需传递带方法的class -import { lang, collections } from '@kit.ArkTS' - -export type ISendable = lang.ISendable; - -@Sendable -export class SendableTestClass { - public name: string = 'John'; - public age: number = 20; - public sex: string = 'man'; - public arr: collections.Array = new collections.Array(1, 2, 3); - - constructor() { - } - - setAge(age: number): void { - this.age = age; - } - - printName(): string { - return this.name; - } - - printAge(): number { - return this.age; - } - - printSex(): string { - return this.sex; - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start across_concurrent_instance_pass_class_method] +// 定义模拟类Test,模仿开发过程中需传递带方法的class +import { lang, collections } from '@kit.ArkTS' + +export type ISendable = lang.ISendable; + +@Sendable +export class SendableTestClass { + public name: string = 'John'; + public age: number = 20; + public sex: string = 'man'; + public arr: collections.Array = new collections.Array(1, 2, 3); + + constructor() { + } + + setAge(age: number): void { + this.age = age; + } + + printName(): string { + return this.name; + } + + printAge(): number { + return this.age; + } + + printSex(): string { + return this.sex; + } +} // [End across_concurrent_instance_pass_class_method] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/module.json5 old mode 100755 new mode 100644 index b3eab50bcffeed7e0047707d831af59494e92fde..c643ef9a335689519d533a0e980b28d2d5b846f1 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "crossconcurrency", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CrossconcurrencyAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CrossconcurrencyAbility", - "srcEntry": "./ets/crossconcurrencyability/CrossconcurrencyAbility.ets", - "description": "$string:CrossconcurrencyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CrossconcurrencyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "crossconcurrency", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CrossconcurrencyAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CrossconcurrencyAbility", + "srcEntry": "./ets/crossconcurrencyability/CrossconcurrencyAbility.ets", + "description": "$string:CrossconcurrencyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CrossconcurrencyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 98e81963775d4194d458b46543d7630df2deaba8..c530a9ac5db7619d7c4bc352a9fc8157726c776d --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/ohosTest/module.json5 @@ -1,27 +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": "crossconcurrency_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "crossconcurrency_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/crossconcurrency/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/ohosTest.md old mode 100755 new mode 100644 index 3417c4410d53cf8a33b53c52947c1f4c1964c965..5dabaf7c7eafda2df07a7b00eb1d05d8d5efd06f --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/ohosTest.md @@ -1,9 +1,9 @@ -# SendableScenarios 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------- | ----------------------------------- | ----------------------------------------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 跨并发实例传输大数据场景 | 位于bigdata模块下Index.ets | 点击Listener task
点击Data processing task | 1秒后页面显示“success” | 是 | Pass | +# SendableScenarios 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------- | ----------------------------------- | ----------------------------------------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 跨并发实例传输大数据场景 | 位于bigdata模块下Index.ets | 点击Listener task
点击Data processing task | 1秒后页面显示“success” | 是 | Pass | | 跨并发实例传递带方法的class实例对象 | 位于crossconcurrency模块下Index.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/screenshots/SendableScenarios_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/screenshots/SendableScenarios_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/screenshots/SendableScenarios_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/SendableScenarios/screenshots/SendableScenarios_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/app.json5 old mode 100755 new mode 100644 index 09128953cd116a2c9cb47347ad5d15b72cefd121..f91bd56379c490cc5485033489e47bafa6d27add --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/app.json5 @@ -1,25 +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.interthreadcommunicationscenario", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.interthreadcommunicationscenario", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index d77691b8db262c69e4277f9a42378e075a035e49..6f3d5184db96e96ead58a268e2d8a233ef3c234e --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "InterThreadCommunicationScenario" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "InterThreadCommunicationScenario" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/README.md old mode 100755 new mode 100644 index ee0366719508365cd23758019807c24b78391980..bd8425b283068655228992794f9e99b4d4f9a01c --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/README.md @@ -1,104 +1,104 @@ -# ArkTS 线程间通信场景 - -### 介绍 - -#### 使用TaskPool执行独立的耗时任务 - -对于一个独立运行的耗时任务,只需要在任务执行完毕后将结果返回给宿主线程,没有上下文依赖 - -#### 使用TaskPool执行多个耗时任务 - -如果有多个任务同时执行,由于任务的复杂度不同,执行时间会不一样,返回数据的时间也是不可控的。如果宿主线程需要所有任务执行完毕的数据,那么可以通过下面这种方式实现。 - -除此以外,如果需要处理的数据量较大(比如一个列表中有10000条数据),把这些数据都放在一个Task中处理也是比较耗时的。那么就可以将原始数据拆分成多个列表,并将每个子列表分配给一个独立的Task进行执行,并且等待全部执行完毕后拼成完整的数据,这样可以节省处理时间,提升用户体验。 - -#### TaskPool任务与宿主线程通信 - -如果一个Task不仅需要返回的执行结果,还需要定时向宿主线状态或数据的变化,或者需要分段返回大量数据(例如从数据库中读取大量数据)。 - -#### Worker和宿主线程的即时消息通信 - -在ArkTS中,Worker相对于Taskpool存在一定的差异性,有数量限制但是可以长时间存在。一个[Worker](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-introduction.md)中可能会执行多个不同的任务,每个任务执行的时长或者返回的结果可能都不相同,宿主线程需要根据情况调用Worker中的不同方法,Worker则需要及时地将结果返回给宿主线程。 - -#### Worker同步调用宿主线程的接口 - -如果一个接口在主线程中已经实现了,Worker需要调用该接口。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用TaskPool执行独立的耗时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/independent-time-consuming-task.md) -- [使用TaskPool执行多个耗时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/multi-time-consuming-tasks.md) -- [TaskPool任务与宿主线程通信](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/taskpool-communicates-with-mainthread.md) -- [Worker和宿主线程的即时消息通信](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-communicates-with-mainthread.md) -- [Worker同步调用宿主线程的接口](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-invoke-mainthread-interface.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── IconItemSource.ets // 公共资源文件 - │ │ ├── IndependentTask.ets // 公共资源文件 - │ │ ├── IndependentTimeConsumingTask.ets // 使用TaskPool执行独立的耗时任务 - │ │ ├── MultiTask.ets // 公共资源文件 - │ │ ├── MultiTimeConsumingTasks.ets // 使用TaskPool执行多个耗时任务 - │ │ ├── TaskSendDataUsage.ets // TaskPool任务与宿主线程通信 - │ │ ├── WorkerCallGlobalUsage.ets // Worker同步调用宿主线程的接口 - │ │ ├── WorkerCommunicatesWithMainthread.ets // Worker和宿主线程的即时消息通信 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ │ ├── workers - │ │ ├── Worker.ets // 公共资源文件 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS 线程间通信场景 + +### 介绍 + +#### 使用TaskPool执行独立的耗时任务 + +对于一个独立运行的耗时任务,只需要在任务执行完毕后将结果返回给宿主线程,没有上下文依赖 + +#### 使用TaskPool执行多个耗时任务 + +如果有多个任务同时执行,由于任务的复杂度不同,执行时间会不一样,返回数据的时间也是不可控的。如果宿主线程需要所有任务执行完毕的数据,那么可以通过下面这种方式实现。 + +除此以外,如果需要处理的数据量较大(比如一个列表中有10000条数据),把这些数据都放在一个Task中处理也是比较耗时的。那么就可以将原始数据拆分成多个列表,并将每个子列表分配给一个独立的Task进行执行,并且等待全部执行完毕后拼成完整的数据,这样可以节省处理时间,提升用户体验。 + +#### TaskPool任务与宿主线程通信 + +如果一个Task不仅需要返回的执行结果,还需要定时向宿主线状态或数据的变化,或者需要分段返回大量数据(例如从数据库中读取大量数据)。 + +#### Worker和宿主线程的即时消息通信 + +在ArkTS中,Worker相对于Taskpool存在一定的差异性,有数量限制但是可以长时间存在。一个[Worker](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-introduction.md)中可能会执行多个不同的任务,每个任务执行的时长或者返回的结果可能都不相同,宿主线程需要根据情况调用Worker中的不同方法,Worker则需要及时地将结果返回给宿主线程。 + +#### Worker同步调用宿主线程的接口 + +如果一个接口在主线程中已经实现了,Worker需要调用该接口。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用TaskPool执行独立的耗时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/independent-time-consuming-task.md) +- [使用TaskPool执行多个耗时任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/multi-time-consuming-tasks.md) +- [TaskPool任务与宿主线程通信](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/taskpool-communicates-with-mainthread.md) +- [Worker和宿主线程的即时消息通信](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-communicates-with-mainthread.md) +- [Worker同步调用宿主线程的接口](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-invoke-mainthread-interface.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── IconItemSource.ets // 公共资源文件 + │ │ ├── IndependentTask.ets // 公共资源文件 + │ │ ├── IndependentTimeConsumingTask.ets // 使用TaskPool执行独立的耗时任务 + │ │ ├── MultiTask.ets // 公共资源文件 + │ │ ├── MultiTimeConsumingTasks.ets // 使用TaskPool执行多个耗时任务 + │ │ ├── TaskSendDataUsage.ets // TaskPool任务与宿主线程通信 + │ │ ├── WorkerCallGlobalUsage.ets // Worker同步调用宿主线程的接口 + │ │ ├── WorkerCommunicatesWithMainthread.ets // Worker和宿主线程的即时消息通信 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ │ ├── workers + │ │ ├── Worker.ets // 公共资源文件 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/build-profile.json5 old mode 100755 new mode 100644 index 51a699665aa94e70bd12ad030ec5c78177d26cfb..18d36695db66c543b72ea20e72d587e505625000 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/build-profile.json5 @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "sourceOption": { - "workers": [ - "./src/main/ets/workers/Worker.ets" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/Worker.ets" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IconItemSource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IconItemSource.ets old mode 100755 new mode 100644 index 6737d0bea5ade499fef326908f9f48f87b12cf09..8793b876b450c5f2d0014a90588ce689a3d4c93e --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IconItemSource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IconItemSource.ets @@ -1,26 +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. - */ - -// [Start implement_child_thread_task] -export class IconItemSource { - image: string | Resource = ''; - text: string | Resource = ''; - - constructor(image: string | Resource = '', text: string | Resource = '') { - this.image = image; - this.text = text; - } -} -// [End implement_child_thread_task] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start implement_child_thread_task] +export class IconItemSource { + image: string | Resource = ''; + text: string | Resource = ''; + + constructor(image: string | Resource = '', text: string | Resource = '') { + this.image = image; + this.text = text; + } +} +// [End implement_child_thread_task] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTask.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTask.ets old mode 100755 new mode 100644 index d673a99ffa21af2bac8cc6f3b274061a36518c94..4140b18fa3470cf6dc82d1abbc95b250cd61ac85 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTask.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTask.ets @@ -1,36 +1,36 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start implement_child_thread_task] -import { IconItemSource } from './IconItemSource'; - -// 在Task中执行的方法,需要添加@Concurrent注解,否则无法正常调用。 -@Concurrent -export function loadPicture(count: number): IconItemSource[] { - let iconItemSourceList: IconItemSource[] = []; - // 遍历添加6*count个IconItem的数据 - for (let index = 0; index < count; index++) { - const numStart: number = index * 6; - // 此处循环使用6张图片资源 - iconItemSourceList.push(new IconItemSource('$media:startIcon', `item${numStart + 1}`)); - iconItemSourceList.push(new IconItemSource('$media:background', `item${numStart + 2}`)); - iconItemSourceList.push(new IconItemSource('$media:foreground', `item${numStart + 3}`)); - iconItemSourceList.push(new IconItemSource('$media:startIcon', `item${numStart + 4}`)); - iconItemSourceList.push(new IconItemSource('$media:background', `item${numStart + 5}`)); - iconItemSourceList.push(new IconItemSource('$media:foreground', `item${numStart + 6}`)); - } - return iconItemSourceList; -} -// [End implement_child_thread_task] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start implement_child_thread_task] +import { IconItemSource } from './IconItemSource'; + +// 在Task中执行的方法,需要添加@Concurrent注解,否则无法正常调用。 +@Concurrent +export function loadPicture(count: number): IconItemSource[] { + let iconItemSourceList: IconItemSource[] = []; + // 遍历添加6*count个IconItem的数据 + for (let index = 0; index < count; index++) { + const numStart: number = index * 6; + // 此处循环使用6张图片资源 + iconItemSourceList.push(new IconItemSource('$media:startIcon', `item${numStart + 1}`)); + iconItemSourceList.push(new IconItemSource('$media:background', `item${numStart + 2}`)); + iconItemSourceList.push(new IconItemSource('$media:foreground', `item${numStart + 3}`)); + iconItemSourceList.push(new IconItemSource('$media:startIcon', `item${numStart + 4}`)); + iconItemSourceList.push(new IconItemSource('$media:background', `item${numStart + 5}`)); + iconItemSourceList.push(new IconItemSource('$media:foreground', `item${numStart + 6}`)); + } + return iconItemSourceList; +} +// [End implement_child_thread_task] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTimeConsumingTask.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTimeConsumingTask.ets old mode 100755 new mode 100644 index 9f5858f4a254dc6a40e213181d08b19dcd319f5e..86799a2f84db9324f97c34b2c152a1c17a42d8a5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTimeConsumingTask.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/IndependentTimeConsumingTask.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start execute_task] -import { taskpool } from '@kit.ArkTS'; -import { IconItemSource } from './IconItemSource'; -import { loadPicture } from './IndependentTask'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - let iconItemSourceList: IconItemSource[] = []; - // 创建Task - let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); - // 执行Task,并返回结果 - taskpool.execute(lodePictureTask).then((res: object) => { - // loadPicture方法的执行结果 - iconItemSourceList = res as IconItemSource[]; - }) - this.message = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} -// [End execute_task] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start execute_task] +import { taskpool } from '@kit.ArkTS'; +import { IconItemSource } from './IconItemSource'; +import { loadPicture } from './IndependentTask'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let iconItemSourceList: IconItemSource[] = []; + // 创建Task + let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); + // 执行Task,并返回结果 + taskpool.execute(lodePictureTask).then((res: object) => { + // loadPicture方法的执行结果 + iconItemSourceList = res as IconItemSource[]; + }) + this.message = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End execute_task] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTask.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTask.ets old mode 100755 new mode 100644 index 659fdce4a89fdaf24cd10c63c50eb089ce74e49f..96765cce24eaf69a4208a787f7965151d6f7c7b4 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTask.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTask.ets @@ -1,35 +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. - */ - -// [Start execute_task_group] -import { taskpool } from '@kit.ArkTS'; -import { IconItemSource } from './IconItemSource'; -import { loadPicture } from './IndependentTask'; - -let iconItemSourceList: IconItemSource[][]; - -let taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup(); -taskGroup.addTask(new taskpool.Task(loadPicture, 30)); -taskGroup.addTask(new taskpool.Task(loadPicture, 20)); -taskGroup.addTask(new taskpool.Task(loadPicture, 10)); -taskpool.execute(taskGroup).then((ret: object) => { - let tmpLength = (ret as IconItemSource[][]).length - for (let i = 0; i < tmpLength; i++) { - for (let j = 0; j < ret[i].length; j++) { - iconItemSourceList.push(ret[i][j]); - } - } -}) -// [End execute_task_group] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start execute_task_group] +import { taskpool } from '@kit.ArkTS'; +import { IconItemSource } from './IconItemSource'; +import { loadPicture } from './IndependentTask'; + +let iconItemSourceList: IconItemSource[][]; + +let taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup(); +taskGroup.addTask(new taskpool.Task(loadPicture, 30)); +taskGroup.addTask(new taskpool.Task(loadPicture, 20)); +taskGroup.addTask(new taskpool.Task(loadPicture, 10)); +taskpool.execute(taskGroup).then((ret: object) => { + let tmpLength = (ret as IconItemSource[][]).length + for (let i = 0; i < tmpLength; i++) { + for (let j = 0; j < ret[i].length; j++) { + iconItemSourceList.push(ret[i][j]); + } + } +}) +// [End execute_task_group] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTimeConsumingTasks.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTimeConsumingTasks.ets old mode 100755 new mode 100644 index 99d736c0417d6ebb4d108b3133b35e01b63a25be..1c9a4882789ccc97ddc53498e487b65c576990bb --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTimeConsumingTasks.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/MultiTimeConsumingTasks.ets @@ -1,47 +1,47 @@ -/* - * 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 { taskpool } from '@kit.ArkTS'; -import { IconItemSource } from './IconItemSource'; -import { loadPicture } from './IndependentTask'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - let iconItemSourceList: IconItemSource[] = []; - // 创建Task - let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); - // 执行Task,并返回结果 - taskpool.execute(lodePictureTask).then((res: object) => { - // loadPicture方法的执行结果 - iconItemSourceList = res as IconItemSource[]; - }) - this.message = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * 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 { taskpool } from '@kit.ArkTS'; +import { IconItemSource } from './IconItemSource'; +import { loadPicture } from './IndependentTask'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let iconItemSourceList: IconItemSource[] = []; + // 创建Task + let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); + // 执行Task,并返回结果 + taskpool.execute(lodePictureTask).then((res: object) => { + // loadPicture方法的执行结果 + iconItemSourceList = res as IconItemSource[]; + }) + this.message = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/TaskSendDataUsage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/TaskSendDataUsage.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/WorkerCallGlobalUsage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/WorkerCallGlobalUsage.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/WorkerCommunicatesWithMainthread.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/WorkerCommunicatesWithMainthread.ets old mode 100755 new mode 100644 index f961776160eb5a1c944621232448772a908aab7c..47cd27b9c87f5a3765ddc70739d623b2a478900b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/WorkerCommunicatesWithMainthread.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/managers/WorkerCommunicatesWithMainthread.ets @@ -1,77 +1,77 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start respond_worker_instant_message] -import { worker } from '@kit.ArkTS'; -import { BusinessError } from '@kit.BasicServicesKit'; - -function promiseCase() { - let p: Promise = new Promise((resolve: Function, reject: Function) => { - setTimeout(() => { - resolve(1); - }, 100) - }).then(undefined, (error: BusinessError) => { - }) - return p; -} - -async function postMessageTest() { - let ss = new worker.ThreadWorker('entry/ets/workers/Worker.ets'); - let res = undefined; - let flag = false; - let isTerminate = false; - ss.onexit = () => { - isTerminate = true; - } - // 接收Worker线程发送的消息 - ss.onmessage = (e) => { - res = e.data; - flag = true; - console.info('worker:: res is ' + res); - } - // 给Worker线程发送消息 - ss.postMessage('hello world'); - while (!flag) { - await promiseCase(); - } - - ss.terminate(); - while (!isTerminate) { - await promiseCase(); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - postMessageTest(); - this.message = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} -// [End respond_worker_instant_message] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start respond_worker_instant_message] +import { worker } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function promiseCase() { + let p: Promise = new Promise((resolve: Function, reject: Function) => { + setTimeout(() => { + resolve(1); + }, 100) + }).then(undefined, (error: BusinessError) => { + }) + return p; +} + +async function postMessageTest() { + let ss = new worker.ThreadWorker('entry/ets/workers/Worker.ets'); + let res = undefined; + let flag = false; + let isTerminate = false; + ss.onexit = () => { + isTerminate = true; + } + // 接收Worker线程发送的消息 + ss.onmessage = (e) => { + res = e.data; + flag = true; + console.info('worker:: res is ' + res); + } + // 给Worker线程发送消息 + ss.postMessage('hello world'); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + postMessageTest(); + this.message = 'success'; + }) + } + .width('100%') + } + .height('100%') + } +} +// [End respond_worker_instant_message] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index de30eb4b1b5ae7e15b8ea8141e26df19fb00d930..723a394265ee2e6bf6d895e9503c4b2d8e49207a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/util/resource.ets @@ -1,25 +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. - */ - -export class P2PManager { - public resourceToString(resource: Resource): string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - +/* + * 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 class P2PManager { + public resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/workers/Worker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/ets/workers/Worker.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/ohosTest.md old mode 100755 new mode 100644 index 0c2dd961ddcb9bf2aa3f9c1f0930a9288b6961a1..d1ad03d05b345b387ff14b0642ad524ffff86cec --- a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/ohosTest.md @@ -1,12 +1,12 @@ -# InterThreadCommunicationScenario 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------ | ---------------------------------------- | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 使用TaskPool执行独立的耗时任务 | 位于IndependentTimeConsumingTask.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用TaskPool执行多个耗时任务 | 位于MultiTimeConsumingTasks.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| TaskPool任务与宿主线程通信 | 位于TaskSendDataUsage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Worker同步调用宿主线程的接口 | 位于WorkerCallGlobalUsage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +# InterThreadCommunicationScenario 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------ | ---------------------------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 使用TaskPool执行独立的耗时任务 | 位于IndependentTimeConsumingTask.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用TaskPool执行多个耗时任务 | 位于MultiTimeConsumingTasks.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| TaskPool任务与宿主线程通信 | 位于TaskSendDataUsage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| Worker同步调用宿主线程的接口 | 位于WorkerCallGlobalUsage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | | Worker和宿主线程的即时消息通信 | 位于WorkerCommunicatesWithMainthread.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/screenshots/InterThreadCommunicationScenario_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/screenshots/InterThreadCommunicationScenario_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/screenshots/InterThreadCommunicationScenario_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationScenario/screenshots/InterThreadCommunicationScenario_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8e962e1c5889cd390dafe58bc3d077e0f407a7a1 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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.multithreadconcurrencyoverview", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4edacd4b6bb94f6dab42c23e1a53533f40c62640 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MultiThreadConcurrencyOverview" + } + ] +} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b645f7de86f693e817fad8866386283bb50ac705 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/README.md @@ -0,0 +1,72 @@ +# ArkTS 多线程并发概述 + +### 介绍 + +并发模型是用来实现不同应用场景中并发任务的编程模型,常见的并发模型分为基于内存共享的并发模型和基于消息通信的并发模型。 + +Actor并发模型作为基于消息通信并发模型的典型代表,不需要开发者去面对锁带来的一系列复杂偶发的问题,同时并发度也相对较高,因此得到了广泛的支持和使用。 + +当前ArkTS提供了TaskPool和Worker两种并发能力,TaskPool和Worker都基于Actor并发模型实现。 + +Actor并发模型和内存共享并发模型的具体对比请见[多线程并发模型](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/multi-thread-concurrency-overview.md#多线程并发模型)。 + +该工程中展示的代码详细描述可查如下链接: + +- [多线程并发概述](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/multi-thread-concurrency-overview.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击start,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 多线程并发概述示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6d9dd7fe7c4885558a2c87d0716b9497290c0fa4 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/code-linter.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/code-linter.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/.gitignore rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/.gitignore diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31bf2f4c4df15f0403582b255ebdff1354312357 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/obfuscation-rules.txt rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e54d14e1b444a338b2c922f94a4fe4deed5be45 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..51bdf85846c3b83c16542085365521bdc35baf50 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cb5df2316a385286bf09b1aab230f0bf56d8b993 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/mock/mock-config.json5 rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/mock/mock-config.json5 diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5f63462032245655b8df990c83c5d7312015c089 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0df4e83ad09f9c4378b3d49faeeaf118df8bc59c --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigorfile.ts rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..936cf43ead6c6ae132fc8169d8ffb96fcd8e6fa6 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..92c98cb4a77ebc0b4eba2570a1d78730858e0b82 --- /dev/null +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/ohosTest.md @@ -0,0 +1,9 @@ +# MultiThreadConcurrencyOverview 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------------------- | ------------ | --------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 使用基于Actor模型的TaskPool并发能力来解决生产者消费者问题 | 位于首页 | 点击start | 1秒后页面显示“success” | 是 | Pass | + diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_1.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_1.png diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_2.png rename to code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/screenshots/MultiThreadConcurrencyOverview_2.png diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/app.json5 old mode 100755 new mode 100644 index b7314386080ecd4f44fc341d87a57256ce5989a8..b298ce16efe768664cef96b4cefb1ac6f4e79356 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/app.json5 @@ -1,25 +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.taskpoolintroduction", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.taskpoolintroduction", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 32e39cdbf9d4dd35dae3fe2ad6b5f8121eb862bf..31939aac3aa0942c9e4d7ca18a68293d4c988cd1 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "TaskPoolIntroduction" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "TaskPoolIntroduction" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/README.md old mode 100755 new mode 100644 index aa74a6fc4bcd12edca2418922539f2d9d7d22b5a..6da606f8ad2b9b1c9e8d8579b83298fac125651c --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/README.md @@ -1,75 +1,75 @@ -# ArkTS TaskPool简介 - -### 介绍 - -任务池(TaskPool)作用是为应用程序提供一个多线程的运行环境,降低整体资源的消耗、提高系统的整体性能,且您无需关心线程实例的生命周期。具体接口信息及使用方法详情请见[TaskPool](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-taskpool.md)。 - -该工程中展示的代码详细描述可查如下链接: - -- [TaskPool简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/taskpool-introduction.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── asynchronousfunctions.ets // 并发异步函数中使用Promise - │ │ ├── customclasses.ets // 并发函数中使用自定义类或函数 - │ │ ├── generaluse.ets // 并发函数一般使用 - │ │ ├── returnpromise.ets // 并发函数返回Promise - │ │ ├── Test.ets // 并发函数中使用自定义类或函数 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS TaskPool简介 + +### 介绍 + +任务池(TaskPool)作用是为应用程序提供一个多线程的运行环境,降低整体资源的消耗、提高系统的整体性能,且您无需关心线程实例的生命周期。具体接口信息及使用方法详情请见[TaskPool](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-taskpool.md)。 + +该工程中展示的代码详细描述可查如下链接: + +- [TaskPool简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/taskpool-introduction.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── asynchronousfunctions.ets // 并发异步函数中使用Promise + │ │ ├── customclasses.ets // 并发函数中使用自定义类或函数 + │ │ ├── generaluse.ets // 并发函数一般使用 + │ │ ├── returnpromise.ets // 并发函数返回Promise + │ │ ├── Test.ets // 并发函数中使用自定义类或函数 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/Test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/Test.ets old mode 100755 new mode 100644 index 89d67c53a3d84e83febbb4117152130d0add3d7d..4146580945bd3c61602438bc08f34b55d5c46047 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/Test.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/Test.ets @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start concurrent_taskpool_test_resources] -export function testAdd(arg: number) { - return ++arg; -} - -@Sendable -export class MyTestA { - constructor(name: string) { - this.name = name; - } - name: string = 'MyTestA'; -} - -export class MyTestB { - static nameStr:string = 'MyTestB'; -} -// [End concurrent_taskpool_test_resources] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start concurrent_taskpool_test_resources] +export function testAdd(arg: number) { + return ++arg; +} + +@Sendable +export class MyTestA { + constructor(name: string) { + this.name = name; + } + name: string = 'MyTestA'; +} + +export class MyTestB { + static nameStr:string = 'MyTestB'; +} +// [End concurrent_taskpool_test_resources] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/asynchronousfunctions.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/asynchronousfunctions.ets old mode 100755 new mode 100644 index c98d1ccdec0d992fe8e93730aca46ef76febfc1c..d8c8842d898ca9c4adbaf1d2139af7d1a7f5d0f2 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/asynchronousfunctions.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/asynchronousfunctions.ets @@ -1,89 +1,89 @@ -/* - * 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. - */ - -// 并发异步函数中使用Promise -// 并发异步函数中如果使用Promise,建议搭配await使用捕获Promise中可能发生的异常。推荐使用示例如下。 -// [Start concurrent_taskpool_async_promise_usage] -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -async function testPromiseError() { - await new Promise((resolve, reject) => { - resolve(1); - }).then(()=>{ - throw new Error('testPromise Error'); - }) -} - -@Concurrent -async function testPromiseError1() { - await new Promise((resolve, reject) => { - reject('testPromiseError1 Error msg'); - }) -} - -@Concurrent -function testPromiseError2() { - return new Promise((resolve, reject) => { - reject('testPromiseError2 Error msg'); - }) -} - -async function testConcurrentFunc() { - let task1: taskpool.Task = new taskpool.Task(testPromiseError); - let task2: taskpool.Task = new taskpool.Task(testPromiseError1); - let task3: taskpool.Task = new taskpool.Task(testPromiseError2); - - taskpool.execute(task1).then((d:object)=>{ - console.info('task1 res is: ' + d); - }).catch((e:object)=>{ - console.info('task1 catch e: ' + e); - }) - taskpool.execute(task2).then((d:object)=>{ - console.info('task2 res is: ' + d); - }).catch((e:object)=>{ - console.info('task2 catch e: ' + e); - }) - taskpool.execute(task3).then((d:object)=>{ - console.info('task3 res is: ' + d); - }).catch((e:object)=>{ - console.info('task3 catch e: ' + e); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Button(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - testConcurrentFunc(); - // [StartExclude concurrent_taskpool_async_promise_usage] - this.message = 'success'; - // [EndExclude concurrent_taskpool_async_promise_usage] - }) - } - .width('100%') - } - .height('100%') - } -} +/* + * 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. + */ + +// 并发异步函数中使用Promise +// 并发异步函数中如果使用Promise,建议搭配await使用捕获Promise中可能发生的异常。推荐使用示例如下。 +// [Start concurrent_taskpool_async_promise_usage] +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +async function testPromiseError() { + await new Promise((resolve, reject) => { + resolve(1); + }).then(()=>{ + throw new Error('testPromise Error'); + }) +} + +@Concurrent +async function testPromiseError1() { + await new Promise((resolve, reject) => { + reject('testPromiseError1 Error msg'); + }) +} + +@Concurrent +function testPromiseError2() { + return new Promise((resolve, reject) => { + reject('testPromiseError2 Error msg'); + }) +} + +async function testConcurrentFunc() { + let task1: taskpool.Task = new taskpool.Task(testPromiseError); + let task2: taskpool.Task = new taskpool.Task(testPromiseError1); + let task3: taskpool.Task = new taskpool.Task(testPromiseError2); + + taskpool.execute(task1).then((d:object)=>{ + console.info('task1 res is: ' + d); + }).catch((e:object)=>{ + console.info('task1 catch e: ' + e); + }) + taskpool.execute(task2).then((d:object)=>{ + console.info('task2 res is: ' + d); + }).catch((e:object)=>{ + console.info('task2 catch e: ' + e); + }) + taskpool.execute(task3).then((d:object)=>{ + console.info('task3 res is: ' + d); + }).catch((e:object)=>{ + console.info('task3 catch e: ' + e); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + testConcurrentFunc(); + // [StartExclude concurrent_taskpool_async_promise_usage] + this.message = 'success'; + // [EndExclude concurrent_taskpool_async_promise_usage] + }) + } + .width('100%') + } + .height('100%') + } +} // [End concurrent_taskpool_async_promise_usage] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/customclasses.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/customclasses.ets old mode 100755 new mode 100644 index 6170a31b692005aaaf913254c2313013c33328f3..16c7dd8bce70e77364d1c36dd2537dd7b716e532 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/customclasses.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/customclasses.ets @@ -1,95 +1,95 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// 并发函数中使用自定义类或函数 -// 并发函数中使用自定义类或函数时需定义在不同文件,否则会被认为是闭包,如下例所示。 -// [Start concurrent_taskpool_custom_class_function] -import { taskpool } from '@kit.ArkTS'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { testAdd, MyTestA, MyTestB } from './Test'; - -function add(arg: number) { - return ++arg; -} - -class TestA { - constructor(name: string) { - this.name = name; - } - name: string = 'ClassA'; -} - -class TestB { - static nameStr: string = 'ClassB'; -} - -@Concurrent -function testFunc() { - // case1:在并发函数中直接调用同文件内定义的类或函数 - - // 直接调用同文件定义的函数add(),add飘红报错: - // Only imported variables and local variables can be used in @Concurrent decorated functions. - // add(1); - // 直接使用同文件定义的TestA构造,TestA飘红报错: - // Only imported variables and local variables can be used in @Concurrent decorated functions. - // let a = new TestA('aaa'); - // 直接访问同文件定义的TestB的成员nameStr,TestB飘红报错: - // Only imported variables and local variables can be used in @Concurrent decorated functions. - // console.info('TestB name is: ' + TestB.nameStr); - - // case2:在并发函数中调用定义在Test.ets文件并导入当前文件的类或函数 - - // 输出结果:res1 is: 2 - console.info('res1 is: ' + testAdd(1)); - let tmpStr = new MyTestA('TEST A'); - // 输出结果:res2 is: TEST A - console.info('res2 is: ' + tmpStr.name); - // 输出结果:res3 is: MyTestB - console.info('res3 is: ' + MyTestB.nameStr); -} - - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - let task = new taskpool.Task(testFunc); - taskpool.execute(task).then(() => { - console.info('taskpool: execute task success!'); - }).catch((e:BusinessError) => { - console.error(`taskpool: execute: Code: ${e.code}, message: ${e.message}`); - }) - // [StartExclude update_message_on_success] - this.message = 'success'; - // [EndExclude update_message_on_success] - }) - } - .height('100%') - .width('100%') - } -} -// [End concurrent_taskpool_custom_class_function] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// 并发函数中使用自定义类或函数 +// 并发函数中使用自定义类或函数时需定义在不同文件,否则会被认为是闭包,如下例所示。 +// [Start concurrent_taskpool_custom_class_function] +import { taskpool } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { testAdd, MyTestA, MyTestB } from './Test'; + +function add(arg: number) { + return ++arg; +} + +class TestA { + constructor(name: string) { + this.name = name; + } + name: string = 'ClassA'; +} + +class TestB { + static nameStr: string = 'ClassB'; +} + +@Concurrent +function testFunc() { + // case1:在并发函数中直接调用同文件内定义的类或函数 + + // 直接调用同文件定义的函数add(),add飘红报错: + // Only imported variables and local variables can be used in @Concurrent decorated functions. + // add(1); + // 直接使用同文件定义的TestA构造,TestA飘红报错: + // Only imported variables and local variables can be used in @Concurrent decorated functions. + // let a = new TestA('aaa'); + // 直接访问同文件定义的TestB的成员nameStr,TestB飘红报错: + // Only imported variables and local variables can be used in @Concurrent decorated functions. + // console.info('TestB name is: ' + TestB.nameStr); + + // case2:在并发函数中调用定义在Test.ets文件并导入当前文件的类或函数 + + // 输出结果:res1 is: 2 + console.info('res1 is: ' + testAdd(1)); + let tmpStr = new MyTestA('TEST A'); + // 输出结果:res2 is: TEST A + console.info('res2 is: ' + tmpStr.name); + // 输出结果:res3 is: MyTestB + console.info('res3 is: ' + MyTestB.nameStr); +} + + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + let task = new taskpool.Task(testFunc); + taskpool.execute(task).then(() => { + console.info('taskpool: execute task success!'); + }).catch((e:BusinessError) => { + console.error(`taskpool: execute: Code: ${e.code}, message: ${e.message}`); + }) + // [StartExclude update_message_on_success] + this.message = 'success'; + // [EndExclude update_message_on_success] + }) + } + .height('100%') + .width('100%') + } +} +// [End concurrent_taskpool_custom_class_function] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/generaluse.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/generaluse.ets old mode 100755 new mode 100644 index 8eaeb92949295a30ced9de4aba2cd83952bf8e5e..4d293c8748ca454fcfddfe6f930cf715615ad2f5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/generaluse.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/generaluse.ets @@ -1,58 +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. - */ - -// 并发函数一般使用 -// 并发函数为一个计算两数之和的普通函数,taskpool执行该函数并返回结果。 -// [Start concurrent_taskpool_common_usage] -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -function add(num1: number, num2: number): number { - return num1 + num2; -} - -async function concurrentFunc(): Promise { - try { - let task: taskpool.Task = new taskpool.Task(add, 1, 2); - console.info('taskpool res is: ' + await taskpool.execute(task)); - } catch (e) { - console.error('taskpool execute error is: ' + e); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - concurrentFunc(); - // [StartExclude update_message_on_success] - this.message = 'success'; - // [EndExclude update_message_on_success] - }) - } - .width('100%') - } - .height('100%') - } -} -// [End concurrent_taskpool_common_usage] +/* + * 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. + */ + +// 并发函数一般使用 +// 并发函数为一个计算两数之和的普通函数,taskpool执行该函数并返回结果。 +// [Start concurrent_taskpool_common_usage] +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +function add(num1: number, num2: number): number { + return num1 + num2; +} + +async function concurrentFunc(): Promise { + try { + let task: taskpool.Task = new taskpool.Task(add, 1, 2); + console.info('taskpool res is: ' + await taskpool.execute(task)); + } catch (e) { + console.error('taskpool execute error is: ' + e); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + concurrentFunc(); + // [StartExclude update_message_on_success] + this.message = 'success'; + // [EndExclude update_message_on_success] + }) + } + .width('100%') + } + .height('100%') + } +} +// [End concurrent_taskpool_common_usage] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/returnpromise.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/returnpromise.ets old mode 100755 new mode 100644 index df1443fc3305a8842a639d3cc5dc039ce59828ef..7ea74e162d45adc3255c29918ccaf3c577ab3423 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/returnpromise.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/managers/returnpromise.ets @@ -1,124 +1,124 @@ -/* - * 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. - */ - -// 并发函数返回Promise -// 并发函数中返回Promise的表现需关注,其中并发同步函数会处理返回该Promise并返回结果,如下例所示。 -// [Start concurrent_taskpool_promise_return] -import { taskpool } from '@kit.ArkTS'; - -@Concurrent -function testPromise(args1: number, args2: number): Promise { - return new Promise((testFuncA, testFuncB) => { - testFuncA(args1 + args2); - }); -} - -@Concurrent -async function testPromise1(args1: number, args2: number): Promise { - return new Promise((testFuncA, testFuncB) => { - testFuncA(args1 + args2); - }); -} - -@Concurrent -async function testPromise2(args1: number, args2: number): Promise { - return await new Promise((testFuncA, testFuncB) => { - testFuncA(args1 + args2); - }); -} - -@Concurrent -function testPromise3() { - return Promise.resolve(1); -} - -@Concurrent -async function testPromise4(): Promise { - return 1; -} - -@Concurrent -async function testPromise5(): Promise { - return await new Promise((resolve) => { - setTimeout(() => { - resolve('Promise setTimeout after resolve'); - }, 1000) - }); -} - -async function testConcurrentFunc() { - let task1: taskpool.Task = new taskpool.Task(testPromise, 1, 2); - let task2: taskpool.Task = new taskpool.Task(testPromise1, 1, 2); - let task3: taskpool.Task = new taskpool.Task(testPromise2, 1, 2); - let task4: taskpool.Task = new taskpool.Task(testPromise3); - let task5: taskpool.Task = new taskpool.Task(testPromise4); - let task6: taskpool.Task = new taskpool.Task(testPromise5); - - taskpool.execute(task1).then((d: object) => { - console.info('task1 res is: ' + d); - }).catch((e: object) => { - console.info('task1 catch e: ' + e); - }) - taskpool.execute(task2).then((d: object) => { - console.info('task2 res is: ' + d); - }).catch((e: object) => { - console.info('task2 catch e: ' + e); - }) - taskpool.execute(task3).then((d: object) => { - console.info('task3 res is: ' + d); - }).catch((e: object) => { - console.info('task3 catch e: ' + e); - }) - taskpool.execute(task4).then((d: object) => { - console.info('task4 res is: ' + d); - }).catch((e: object) => { - console.info('task4 catch e: ' + e); - }) - taskpool.execute(task5).then((d: object) => { - console.info('task5 res is: ' + d); - }).catch((e: object) => { - console.info('task5 catch e: ' + e); - }) - taskpool.execute(task6).then((d: object) => { - console.info('task6 res is: ' + d); - }).catch((e: object) => { - console.info('task6 catch e: ' + e); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Button(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - testConcurrentFunc(); - // [StartExclude update_message_on_success] - this.message = 'success'; - // [EndExclude update_message_on_success] - }) - } - .width('100%') - } - .height('100%') - } -} -// [End concurrent_taskpool_promise_return] +/* + * 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. + */ + +// 并发函数返回Promise +// 并发函数中返回Promise的表现需关注,其中并发同步函数会处理返回该Promise并返回结果,如下例所示。 +// [Start concurrent_taskpool_promise_return] +import { taskpool } from '@kit.ArkTS'; + +@Concurrent +function testPromise(args1: number, args2: number): Promise { + return new Promise((testFuncA, testFuncB) => { + testFuncA(args1 + args2); + }); +} + +@Concurrent +async function testPromise1(args1: number, args2: number): Promise { + return new Promise((testFuncA, testFuncB) => { + testFuncA(args1 + args2); + }); +} + +@Concurrent +async function testPromise2(args1: number, args2: number): Promise { + return await new Promise((testFuncA, testFuncB) => { + testFuncA(args1 + args2); + }); +} + +@Concurrent +function testPromise3() { + return Promise.resolve(1); +} + +@Concurrent +async function testPromise4(): Promise { + return 1; +} + +@Concurrent +async function testPromise5(): Promise { + return await new Promise((resolve) => { + setTimeout(() => { + resolve('Promise setTimeout after resolve'); + }, 1000) + }); +} + +async function testConcurrentFunc() { + let task1: taskpool.Task = new taskpool.Task(testPromise, 1, 2); + let task2: taskpool.Task = new taskpool.Task(testPromise1, 1, 2); + let task3: taskpool.Task = new taskpool.Task(testPromise2, 1, 2); + let task4: taskpool.Task = new taskpool.Task(testPromise3); + let task5: taskpool.Task = new taskpool.Task(testPromise4); + let task6: taskpool.Task = new taskpool.Task(testPromise5); + + taskpool.execute(task1).then((d: object) => { + console.info('task1 res is: ' + d); + }).catch((e: object) => { + console.info('task1 catch e: ' + e); + }) + taskpool.execute(task2).then((d: object) => { + console.info('task2 res is: ' + d); + }).catch((e: object) => { + console.info('task2 catch e: ' + e); + }) + taskpool.execute(task3).then((d: object) => { + console.info('task3 res is: ' + d); + }).catch((e: object) => { + console.info('task3 catch e: ' + e); + }) + taskpool.execute(task4).then((d: object) => { + console.info('task4 res is: ' + d); + }).catch((e: object) => { + console.info('task4 catch e: ' + e); + }) + taskpool.execute(task5).then((d: object) => { + console.info('task5 res is: ' + d); + }).catch((e: object) => { + console.info('task5 catch e: ' + e); + }) + taskpool.execute(task6).then((d: object) => { + console.info('task6 res is: ' + d); + }).catch((e: object) => { + console.info('task6 catch e: ' + e); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(() => { + testConcurrentFunc(); + // [StartExclude update_message_on_success] + this.message = 'success'; + // [EndExclude update_message_on_success] + }) + } + .width('100%') + } + .height('100%') + } +} +// [End concurrent_taskpool_promise_return] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index 6f34fb425d22c15f51339e6824dc9d50fe352064..40f1ea99bf38db7df02738bcbda5b77496a2544f --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/ets/util/resource.ets @@ -1,27 +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. - */ - -// [StartExclude p2p_manager_resource] -export class P2PManager { - public resourceToString(resource: Resource):string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - -export default p2pManager as P2PManager; -// [EndExclude p2p_manager_resource] +/* + * 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. + */ + +// [StartExclude p2p_manager_resource] +export class P2PManager { + public resourceToString(resource: Resource):string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + +export default p2pManager as P2PManager; +// [EndExclude p2p_manager_resource] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/ohosTest.md old mode 100755 new mode 100644 index 69c9a1c1b6c5eff9e791f6de70b855d859b36faa..006d184890948f84a14d0afb78a407758df00c01 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/ohosTest.md @@ -1,11 +1,11 @@ -# TaskPoolIntroduction 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------- | ----------------------------- | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 并发函数一般使用 | 位于generaluse.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 并发函数返回Promise | 位于returnpromise.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 并发函数中使用自定义类或函数 | 位于customclasses.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +# TaskPoolIntroduction 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------- | ----------------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 并发函数一般使用 | 位于generaluse.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 并发函数返回Promise | 位于returnpromise.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 并发函数中使用自定义类或函数 | 位于customclasses.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | | 并发异步函数中使用Promise | 位于asynchronousfunctions.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/screenshots/TaskPoolIntroduction_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/screenshots/TaskPoolIntroduction_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/screenshots/TaskPoolIntroduction_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/TaskPoolIntroduction/screenshots/TaskPoolIntroduction_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/app.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/app.json5 old mode 100755 new mode 100644 index e4e34e86f34eac85f39cce4de19d4bf1b7d4101c..889e27c848aef3c6c8e2bdbb6f8bf3392ee13ae5 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/app.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/app.json5 @@ -1,25 +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.workerIntroduction", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.workerIntroduction", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index b440180aef38b0e883f1e0ae059936547f70957b..c79ba2d1da86ad88202a183d6f99d832d94b54e9 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "WorkerIntroduction" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "WorkerIntroduction" + } + ] +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/README.md b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/README.md old mode 100755 new mode 100644 index 88a673e8cb79d476ee714879782e66a87397f2fd..96a3046faf5359f2430c99cefe995d9c09a58f47 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/README.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/README.md @@ -1,86 +1,86 @@ -# ArkTS Worker简介 - -### 介绍 - -Worker主要作用是为应用程序提供一个多线程的运行环境,可满足应用程序在执行过程中与宿主线程分离,在后台线程中运行一个脚本进行耗时操作,极大避免类似于计算密集型或高延迟的任务阻塞宿主线程的运行。具体接口信息及使用方法详情请见[Worker](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-worker.md)。 - -该工程中展示的代码详细描述可查如下链接: - -- [Worker简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-introduction.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── basicusage.ets // Worker基本用法示例 - │ │ ├── crosshar.ets // 跨har包加载Worker - │ │ ├── notrecommendedone.ets // 不推荐使用示例1 - │ │ ├── notrecommendedtwo.ets // 不推荐使用示例2 - │ │ ├── recommend.ets // 推荐使用示例 - │ │ ├── notrecommendedoneworker - │ │ ├── childworker.ets // 不推荐使用示例1 - │ │ ├── parentworker.ets // 不推荐使用示例1 - │ │ ├── notrecommendedtwoworker - │ │ ├── childworker.ets // 不推荐使用示例2 - │ │ ├── parentworker.ets // 不推荐使用示例2 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── recommendworkers - │ │ ├── childworker.ets // 推荐使用示例 - │ │ ├── parentworker.ets // 推荐使用示例 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ │ ├── workers - │ │ ├── worker.ets // Worker基本用法示例 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# ArkTS Worker简介 + +### 介绍 + +Worker主要作用是为应用程序提供一个多线程的运行环境,可满足应用程序在执行过程中与宿主线程分离,在后台线程中运行一个脚本进行耗时操作,极大避免类似于计算密集型或高延迟的任务阻塞宿主线程的运行。具体接口信息及使用方法详情请见[Worker](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-arkts/js-apis-worker.md)。 + +该工程中展示的代码详细描述可查如下链接: + +- [Worker简介](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/worker-introduction.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── managers + │ │ ├── basicusage.ets // Worker基本用法示例 + │ │ ├── crosshar.ets // 跨har包加载Worker + │ │ ├── notrecommendedone.ets // 不推荐使用示例1 + │ │ ├── notrecommendedtwo.ets // 不推荐使用示例2 + │ │ ├── recommend.ets // 推荐使用示例 + │ │ ├── notrecommendedoneworker + │ │ ├── childworker.ets // 不推荐使用示例1 + │ │ ├── parentworker.ets // 不推荐使用示例1 + │ │ ├── notrecommendedtwoworker + │ │ ├── childworker.ets // 不推荐使用示例2 + │ │ ├── parentworker.ets // 不推荐使用示例2 + │ │ ├── pages + │ │ ├── Index.ets // 首页 + │ │ ├── recommendworkers + │ │ ├── childworker.ets // 推荐使用示例 + │ │ ├── parentworker.ets // 推荐使用示例 + │ │ ├── util + │ │ ├── CommonButton.ets // 首页跳转UI + │ │ ├── resource.ets // 资源引用转换 + │ │ ├── workers + │ │ ├── worker.ets // Worker基本用法示例 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/build-profile.json5 old mode 100755 new mode 100644 index fcdcb832b7d1f71d9417f9f83c05606ed7ea2ed0..505aa8efb92cd942bc2423a4dba7f37b560823b8 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/build-profile.json5 @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "har", - "srcPath": "./har", - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "har", + "srcPath": "./har", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/code-linter.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/build-profile.json5 old mode 100755 new mode 100644 index 4d9432aa4f6123b7bb1550b2ec2da0b99b57cdd0..e5ef097c7eada5cd59e0b374370eb98b55d744fe --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/build-profile.json5 @@ -1,56 +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. - */ - -{ - "apiType": "stageMode", - // [Start manual_create_worker] - "buildOption": { - "sourceOption": { - "workers": [ - "./src/main/ets/recommendworkers/parentworker.ets", - "./src/main/ets/recommendworkers/childworker.ets", - "./src/main/ets/notrecommendedoneworker/parentworker.ets", - "./src/main/ets/notrecommendedoneworker/childworker.ets", - "./src/main/ets/notrecommendedtwoworker/parentworker.ets", - "./src/main/ets/notrecommendedtwoworker/childworker.ets", - './src/main/ets/workers/worker.ets' - ] - } - }, - // [End manual_create_worker] - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + // [Start manual_create_worker] + "buildOption": { + "sourceOption": { + "workers": [ + "./src/main/ets/recommendworkers/parentworker.ets", + "./src/main/ets/recommendworkers/childworker.ets", + "./src/main/ets/notrecommendedoneworker/parentworker.ets", + "./src/main/ets/notrecommendedoneworker/childworker.ets", + "./src/main/ets/notrecommendedtwoworker/parentworker.ets", + "./src/main/ets/notrecommendedtwoworker/childworker.ets", + './src/main/ets/workers/worker.ets' + ] + } + }, + // [End manual_create_worker] + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/oh-package.json5 old mode 100755 new mode 100644 index 9a2f7b5dfdfd296e2f1d91e5776cfcb600d767ac..c13df0e92671c84f031cbce3c6a346effdcdecb9 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/oh-package.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start config_har_dependency] -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "har": "file:../har" - } -} -// [End config_har_dependency] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start config_har_dependency] +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "har": "file:../har" + } +} +// [End config_har_dependency] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/basicusage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/basicusage.ets old mode 100755 new mode 100644 index 9d98b565c292472398851063025e8e2cb4a96998..cd589747664d22390591177c62aea9e3d87c335e --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/basicusage.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/basicusage.ets @@ -1,69 +1,69 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// {Start create_worker_object_register_callback_function] -import { ErrorEvent, MessageEvents, worker } from '@kit.ArkTS'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 创建Worker对象 - let workerInstance = new worker.ThreadWorker('entry/ets/workers/worker.ets'); - - // 注册onmessage回调,当宿主线程接收到来自其创建的Worker通过workerPort.postMessage接口发送的消息时被调用,在宿主线程执行 - workerInstance.onmessage = (e: MessageEvents) => { - let data: string = e.data; - console.info('workerInstance onmessage is: ', data); - } - - // 注册onerror回调,当Worker在执行过程中发生异常时被调用,在宿主线程执行 - workerInstance.onerror = (err: ErrorEvent) => { - console.info('workerInstance onerror message is: ' + err.message); - } - - // 注册onmessageerror回调,当Worker对象接收到一条无法被序列化的消息时被调用,在宿主线程执行 - workerInstance.onmessageerror = () => { - console.info('workerInstance onmessageerror'); - } - - // 注册onexit回调,当Worker销毁时被调用,在宿主线程执行 - workerInstance.onexit = (e: number) => { - // 当Worker正常退出时code为0,异常退出时code为1 - console.info('workerInstance onexit code is: ', e); - } - - // 向Worker线程发送消息 - workerInstance.postMessage('1'); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// {End create_worker_object_register_callback_function] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// {Start create_worker_object_register_callback_function] +import { ErrorEvent, MessageEvents, worker } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 创建Worker对象 + let workerInstance = new worker.ThreadWorker('entry/ets/workers/worker.ets'); + + // 注册onmessage回调,当宿主线程接收到来自其创建的Worker通过workerPort.postMessage接口发送的消息时被调用,在宿主线程执行 + workerInstance.onmessage = (e: MessageEvents) => { + let data: string = e.data; + console.info('workerInstance onmessage is: ', data); + } + + // 注册onerror回调,当Worker在执行过程中发生异常时被调用,在宿主线程执行 + workerInstance.onerror = (err: ErrorEvent) => { + console.info('workerInstance onerror message is: ' + err.message); + } + + // 注册onmessageerror回调,当Worker对象接收到一条无法被序列化的消息时被调用,在宿主线程执行 + workerInstance.onmessageerror = () => { + console.info('workerInstance onmessageerror'); + } + + // 注册onexit回调,当Worker销毁时被调用,在宿主线程执行 + workerInstance.onexit = (e: number) => { + // 当Worker正常退出时code为0,异常退出时code为1 + console.info('workerInstance onexit code is: ', e); + } + + // 向Worker线程发送消息 + workerInstance.postMessage('1'); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// {End create_worker_object_register_callback_function] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/crosshar.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/crosshar.ets old mode 100755 new mode 100644 index 0283114af25aa708e6156e814490404ad4031f4a..1756627224307f8c3b286f61a0f5f29693e36ca6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/crosshar.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/crosshar.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start load_har_worker] -import { worker } from '@kit.ArkTS'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 通过@标识路径加载形式,加载har中Worker线程文件 - let workerInstance = new worker.ThreadWorker('@har/ets/workers/worker.ets'); - workerInstance.onmessage = () => { - console.info('main thread onmessage'); - }; - workerInstance.postMessage('hello world'); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End load_har_worker] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start load_har_worker] +import { worker } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 通过@标识路径加载形式,加载har中Worker线程文件 + let workerInstance = new worker.ThreadWorker('@har/ets/workers/worker.ets'); + workerInstance.onmessage = () => { + console.info('main thread onmessage'); + }; + workerInstance.postMessage('hello world'); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End load_har_worker] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedone.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedone.ets old mode 100755 new mode 100644 index 2135ba6313ed7534928c4131d1ac72c9323531d2..3a52ca621603844e9ddcda07e2cab2c8d384f83a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedone.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedone.ets @@ -1,59 +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. - */ - -// [Start not_recommended_example] -import resource from '../util/resource'; -import { worker, MessageEvents, ErrorEvent } from '@kit.ArkTS'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 主线程中创建父worker对象 - const parentworker = new worker.ThreadWorker('entry/ets/notrecommendedoneworker/parentworker.ets'); - - parentworker.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_recommended1')) + e.data); - } - - parentworker.onexit = () => { - console.info(resource.resourceToString($r('app.string.Not_recommended2'))); - } - - parentworker.onerror = (err: ErrorEvent) => { - console.info(resource.resourceToString($r('app.string.Not_recommended3')) + err); - } - - parentworker.postMessage(resource.resourceToString($r('app.string.Not_recommended4'))); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End not_recommended_example] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start not_recommended_example] +import resource from '../util/resource'; +import { worker, MessageEvents, ErrorEvent } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 主线程中创建父worker对象 + const parentworker = new worker.ThreadWorker('entry/ets/notrecommendedoneworker/parentworker.ets'); + + parentworker.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_recommended1')) + e.data); + } + + parentworker.onexit = () => { + console.info(resource.resourceToString($r('app.string.Not_recommended2'))); + } + + parentworker.onerror = (err: ErrorEvent) => { + console.info(resource.resourceToString($r('app.string.Not_recommended3')) + err); + } + + parentworker.postMessage(resource.resourceToString($r('app.string.Not_recommended4'))); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End not_recommended_example] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedtwo.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedtwo.ets old mode 100755 new mode 100644 index 80c99d81e3fb0da8615c112357933353c07a7a34..06c3b06789dd15b58f89b1085d7450c29942f6fd --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedtwo.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/notrecommendedtwo.ets @@ -1,59 +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. - */ - -// [Start not_recommended_example] -import resource from '../util/resource'; -import { worker, MessageEvents, ErrorEvent } from '@kit.ArkTS'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 主线程中创建父worker对象 - const parentworker = new worker.ThreadWorker('entry/ets/notrecommendedtwoworker/parentworker.ets'); - - parentworker.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_recommended1')) + e.data); - } - - parentworker.onexit = () => { - console.info(resource.resourceToString($r('app.string.Not_recommended2'))); - } - - parentworker.onerror = (err: ErrorEvent) => { - console.info(resource.resourceToString($r('app.string.Not_recommended3')) + err); - } - - parentworker.postMessage(resource.resourceToString($r('app.string.Not_recommended4'))); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End not_recommended_example] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start not_recommended_example] +import resource from '../util/resource'; +import { worker, MessageEvents, ErrorEvent } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 主线程中创建父worker对象 + const parentworker = new worker.ThreadWorker('entry/ets/notrecommendedtwoworker/parentworker.ets'); + + parentworker.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_recommended1')) + e.data); + } + + parentworker.onexit = () => { + console.info(resource.resourceToString($r('app.string.Not_recommended2'))); + } + + parentworker.onerror = (err: ErrorEvent) => { + console.info(resource.resourceToString($r('app.string.Not_recommended3')) + err); + } + + parentworker.postMessage(resource.resourceToString($r('app.string.Not_recommended4'))); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End not_recommended_example] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/recommend.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/recommend.ets old mode 100755 new mode 100644 index 0266902ba5de718e9c9188ce0c69e570ec74cdaf..57ae48a862a3b8bc8608bdf517f1232483ab2c44 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/recommend.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/managers/recommend.ets @@ -1,59 +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. - */ - -// [Start recommended_example] -import resource from '../util/resource'; -import { worker, MessageEvents, ErrorEvent } from '@kit.ArkTS'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize(50) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - // 主线程中创建父worker对象 - const parentworker = new worker.ThreadWorker('entry/ets/recommendworkers/parentworker.ets'); - - parentworker.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.recommend1')) + e.data); - } - - parentworker.onexit = () => { - console.info(resource.resourceToString($r('app.string.recommend2'))); - } - - parentworker.onerror = (err: ErrorEvent) => { - console.info(resource.resourceToString($r('app.string.recommend3')) + err); - } - - parentworker.postMessage(resource.resourceToString($r('app.string.recommend4'))); - this.message = 'success'; - }) - } - .height('100%') - .width('100%') - } -} -// [End recommended_example] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start recommended_example] +import resource from '../util/resource'; +import { worker, MessageEvents, ErrorEvent } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + // 主线程中创建父worker对象 + const parentworker = new worker.ThreadWorker('entry/ets/recommendworkers/parentworker.ets'); + + parentworker.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.recommend1')) + e.data); + } + + parentworker.onexit = () => { + console.info(resource.resourceToString($r('app.string.recommend2'))); + } + + parentworker.onerror = (err: ErrorEvent) => { + console.info(resource.resourceToString($r('app.string.recommend3')) + err); + } + + parentworker.postMessage(resource.resourceToString($r('app.string.recommend4'))); + this.message = 'success'; + }) + } + .height('100%') + .width('100%') + } +} +// [End recommended_example] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/childworker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/childworker.ets old mode 100755 new mode 100644 index aaa52b70d5c9b4b75216d5c973ca1d0f98f70cc7..a79e8997908ad81b07c05bb9281f8e7f9894c6ba --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/childworker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/childworker.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start not_recommended_example] -import resource from '../util/resource'; -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; - -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -workerPort.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_one_childworker_worker1')) + e.data); - - // 父Worker销毁后,子Worker向父Worker发送信息,行为不可预期 - workerPort.postMessage(resource.resourceToString($r('app.string.Not_one_childworker_worker2'))); - setTimeout(() => { - workerPort.postMessage(resource.resourceToString($r('app.string.Not_one_childworker_worker2'))); - }, 1000); -} -// [End not_recommended_example] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start not_recommended_example] +import resource from '../util/resource'; +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; + +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_one_childworker_worker1')) + e.data); + + // 父Worker销毁后,子Worker向父Worker发送信息,行为不可预期 + workerPort.postMessage(resource.resourceToString($r('app.string.Not_one_childworker_worker2'))); + setTimeout(() => { + workerPort.postMessage(resource.resourceToString($r('app.string.Not_one_childworker_worker2'))); + }, 1000); +} +// [End not_recommended_example] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/parentworker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/parentworker.ets old mode 100755 new mode 100644 index 61bbf3fc3c86cffaca7a672e46ccf24bb5581aa4..5403dbc76df5eb09d48ce76cf2daeb5fe61c9b8f --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/parentworker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedoneworker/parentworker.ets @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start not_recommended_example] -import resource from '../util/resource'; -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; - -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -workerPort.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker1')) + e.data); - - let childworker = new worker.ThreadWorker('entry/ets/workers/childworker.ets'); - - childworker.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker2')) + e.data); - } - - childworker.onexit = () => { - console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker3'))); - workerPort.postMessage(resource.resourceToString($r('app.string.Not_one_parentworker_worker4'))); - } - - childworker.onerror = (err: ErrorEvent) => { - console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker5')) + err); - } - - childworker.postMessage(resource.resourceToString($r('app.string.Not_one_parentworker_worker6'))); - - // 创建子Worker后,销毁父Worker - workerPort.close(); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start not_recommended_example] +import resource from '../util/resource'; +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; + +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker1')) + e.data); + + let childworker = new worker.ThreadWorker('entry/ets/workers/childworker.ets'); + + childworker.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker2')) + e.data); + } + + childworker.onexit = () => { + console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker3'))); + workerPort.postMessage(resource.resourceToString($r('app.string.Not_one_parentworker_worker4'))); + } + + childworker.onerror = (err: ErrorEvent) => { + console.info(resource.resourceToString($r('app.string.Not_one_parentworker_worker5')) + err); + } + + childworker.postMessage(resource.resourceToString($r('app.string.Not_one_parentworker_worker6'))); + + // 创建子Worker后,销毁父Worker + workerPort.close(); +} // [End not_recommended_example] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/childworker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/childworker.ets old mode 100755 new mode 100644 index 991e2a67b02fbbf6594d9bb8ecd8023b80654eff..ebdea6679fd84df93a8a29cb9e4a0032e450904b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/childworker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/childworker.ets @@ -1,25 +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. - */ - -// [Start not_recommended_example] -import resource from '../util/resource'; -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; - -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -workerPort.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_two_childworker_worker')) + e.data); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start not_recommended_example] +import resource from '../util/resource'; +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; + +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_two_childworker_worker')) + e.data); +} // [End not_recommended_example] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/parentworker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/parentworker.ets old mode 100755 new mode 100644 index 24e94626b820df67db2d4c17c0317602cecb3491..25419ef11930d8aef689930b5df7e6e55f9bd3af --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/parentworker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/notrecommendedtwoworker/parentworker.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start not_recommended_example] -import resource from '../util/resource'; -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; - -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -workerPort.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker1')) + e.data); - - // 父Worker销毁后创建子Worker,行为不可预期 - workerPort.close(); - let childworker = new worker.ThreadWorker('entry/ets/notrecommendedtwoworker/childworker.ets'); - - // 子Worker线程未确认创建成功前销毁父Worker,行为不可预期 - // let childworker = new worker.ThreadWorker('entry/ets/workers/childworker.ets'); - // workerPort.close(); - - childworker.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker2')) + e.data); - } - - childworker.onexit = () => { - console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker3'))); - workerPort.postMessage(resource.resourceToString($r('app.string.Not_two_parentworker_worker4'))); - } - - childworker.onerror = (err: ErrorEvent) => { - console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker5')) + err); - } - - childworker.postMessage(resource.resourceToString($r('app.string.Not_two_parentworker_worker6'))); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start not_recommended_example] +import resource from '../util/resource'; +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; + +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker1')) + e.data); + + // 父Worker销毁后创建子Worker,行为不可预期 + workerPort.close(); + let childworker = new worker.ThreadWorker('entry/ets/notrecommendedtwoworker/childworker.ets'); + + // 子Worker线程未确认创建成功前销毁父Worker,行为不可预期 + // let childworker = new worker.ThreadWorker('entry/ets/workers/childworker.ets'); + // workerPort.close(); + + childworker.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker2')) + e.data); + } + + childworker.onexit = () => { + console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker3'))); + workerPort.postMessage(resource.resourceToString($r('app.string.Not_two_parentworker_worker4'))); + } + + childworker.onerror = (err: ErrorEvent) => { + console.info(resource.resourceToString($r('app.string.Not_two_parentworker_worker5')) + err); + } + + childworker.postMessage(resource.resourceToString($r('app.string.Not_two_parentworker_worker6'))); +} // [End not_recommended_example] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/childworker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/childworker.ets old mode 100755 new mode 100644 index fb2424b61d9c62af9db35572768789e0c509655e..8e14b97d6c18d224bd6791e29a3633a711c3637c --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/childworker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/childworker.ets @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start recommended_example] -import resource from '../util/resource'; -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; - -// 创建子Worker线程中与父Worker线程通信的对象 -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -workerPort.onmessage = (e: MessageEvents) => { - if (e.data == resource.resourceToString($r('app.string.Recommend_child_worker1'))) { - // 子Worker线程业务逻辑... - console.info(resource.resourceToString($r('app.string.Recommend_child_worker2'))); - workerPort.close(); - } -} -// [End recommended_example] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start recommended_example] +import resource from '../util/resource'; +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; + +// 创建子Worker线程中与父Worker线程通信的对象 +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = (e: MessageEvents) => { + if (e.data == resource.resourceToString($r('app.string.Recommend_child_worker1'))) { + // 子Worker线程业务逻辑... + console.info(resource.resourceToString($r('app.string.Recommend_child_worker2'))); + workerPort.close(); + } +} +// [End recommended_example] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/parentworker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/parentworker.ets old mode 100755 new mode 100644 index 90bebf6519cc81517e6fa599c9b720efa7a4ea56..f4b7f8a4800de64ec8bd85fd31f030fdc0587427 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/parentworker.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/recommendworkers/parentworker.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start recommended_example] -import resource from '../util/resource'; -import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; - -// 创建父Worker线程中与主线程通信的对象 -const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - -workerPort.onmessage = (e: MessageEvents) => { - if (e.data == resource.resourceToString($r('app.string.Recommend_parentworker_worker1'))) { - let childworker = new worker.ThreadWorker('entry/ets/recommendworkers/childworker.ets'); - - childworker.onmessage = (e: MessageEvents) => { - console.info(resource.resourceToString($r('app.string.Recommend_parentworker_worker2')) + e.data); - if (e.data == resource.resourceToString($r('app.string.Recommend_parentworker_worker3'))) { - workerPort.postMessage(resource.resourceToString($r('app.string.Recommend_parentworker_worker4'))); - } - } - - childworker.onexit = () => { - console.info(resource.resourceToString($r('app.string.Recommend_parentworker_worker5'))); - // 子Worker退出后再销毁父Worker - workerPort.close(); - } - - childworker.onerror = (err: ErrorEvent) => { - console.info(resource.resourceToString($r('app.string.Recommend_parentworker_worker6')) + err); - } - - childworker.postMessage(resource.resourceToString($r('app.string.Recommend_parentworker_worker7'))); - } -} -// [End recommended_example] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start recommended_example] +import resource from '../util/resource'; +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; + +// 创建父Worker线程中与主线程通信的对象 +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = (e: MessageEvents) => { + if (e.data == resource.resourceToString($r('app.string.Recommend_parentworker_worker1'))) { + let childworker = new worker.ThreadWorker('entry/ets/recommendworkers/childworker.ets'); + + childworker.onmessage = (e: MessageEvents) => { + console.info(resource.resourceToString($r('app.string.Recommend_parentworker_worker2')) + e.data); + if (e.data == resource.resourceToString($r('app.string.Recommend_parentworker_worker3'))) { + workerPort.postMessage(resource.resourceToString($r('app.string.Recommend_parentworker_worker4'))); + } + } + + childworker.onexit = () => { + console.info(resource.resourceToString($r('app.string.Recommend_parentworker_worker5'))); + // 子Worker退出后再销毁父Worker + workerPort.close(); + } + + childworker.onerror = (err: ErrorEvent) => { + console.info(resource.resourceToString($r('app.string.Recommend_parentworker_worker6')) + err); + } + + childworker.postMessage(resource.resourceToString($r('app.string.Recommend_parentworker_worker7'))); + } +} +// [End recommended_example] diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/util/CommonButton.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/util/CommonButton.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/util/resource.ets old mode 100755 new mode 100644 index 79a04af93bcf6ee2b7d288a24558060fb6c69345..a0f1755b8cccfecc4200cf5b1ed991805e3e00b6 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/util/resource.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/util/resource.ets @@ -1,25 +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. - */ - -export class P2PManager { - public resourceToString(resource: Resource):string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - +/* + * 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 class P2PManager { + public resourceToString(resource: Resource):string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/workers/worker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/ets/workers/worker.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/.gitignore b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/BuildProfile.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/BuildProfile.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/Index.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/Index.ets old mode 100755 new mode 100644 index 0c4e469d33c702b15e39f043e6062afdea868323..e5366a9d163962a9c1f933ab95195b5c909baf51 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/Index.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/Index.ets @@ -1,16 +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 { MainPage } from './src/main/ets/components/MainPage'; +/* + * 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 { MainPage } from './src/main/ets/components/MainPage'; diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/build-profile.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/build-profile.json5 old mode 100755 new mode 100644 index 9681515781f28335a31897789bbda8cbe2f4edb4..39a0c7e7c20931806481f920aa4f3ee6c07e9408 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/build-profile.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * 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": { - "sourceOption": { - "workers": [ - './src/main/ets/workers/worker.ets' - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] +/* + * 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": { + "sourceOption": { + "workers": [ + './src/main/ets/workers/worker.ets' + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/consumer-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/consumer-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/obfuscation-rules.txt b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/oh-package.json5 old mode 100755 new mode 100644 index 08c9c66275c8a5b15a1130a0fb3c1721181e6402..15ebac70263f6adf055a2dec2c9683bc52aa628a --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * 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": "har", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} +/* + * 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": "har", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/ets/components/MainPage.ets old mode 100755 new mode 100644 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/ets/components/MainPage.ets +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/ets/components/MainPage.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} +/* + * 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. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/ets/workers/worker.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/ets/workers/worker.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/module.json5 old mode 100755 new mode 100644 index 7e826fa36804430626f31f88fdd1d47ca88635b8..08e47d7196d116bb79a6930eb997e30bac3057bc --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/module.json5 @@ -1,25 +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. - */ - -{ - "module": { - "name": "har", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} +/* + * 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": "har", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 6469ce25bb80062ba0f3b8b2a11872f82dec4498..fdb1caba1f72318f568e39c5c3ec17aad4e5f531 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/ohosTest/module.json5 @@ -1,27 +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": "har_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "har_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/test/List.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/har/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/hvigorfile.ts b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/oh-package.json5 b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/oh-package.json5 +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/ohosTest.md b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/ohosTest.md old mode 100755 new mode 100644 index a5f3ba2d406ca32f27211db76fdd2c7ef1278e13..bca2a5aa47ef1f2d1a8e83deeae5ae69e79b6c31 --- a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/ohosTest.md +++ b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/ohosTest.md @@ -1,12 +1,12 @@ -# WorkerIntroduction 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------ | ------------------------- | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| Worker基本用法示例 | 位于basicusage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 跨har包加载Worker | 位于crosshar.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 推荐使用示例 | 位于recommend.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 不推荐使用示例1 | 位于notrecommendedone.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +# WorkerIntroduction 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------ | ------------------------- | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| Worker基本用法示例 | 位于basicusage.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 跨har包加载Worker | 位于crosshar.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 推荐使用示例 | 位于recommend.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 不推荐使用示例1 | 位于notrecommendedone.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | | 不推荐使用示例2 | 位于notrecommendedtwo.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/screenshots/WorkerIntroduction_1.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/screenshots/WorkerIntroduction_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/screenshots/WorkerIntroduction_2.png b/code/DocsSample/ArkTS/ArkTsConcurrent/MultithreadedConcurrency/WorkerIntroduction/screenshots/WorkerIntroduction_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..703f9ed9bab50236b5a0f0982d22ba17a60e41dd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/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.jsvmdebug", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f9ac3bc9d51b0f741aea48407a3c035fe191091f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmDebug" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/README.md new file mode 100644 index 0000000000000000000000000000000000000000..192afb17321f2899a09c93f26b5c07b92384f6c4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/README.md @@ -0,0 +1,138 @@ +# ArkTS JSVM-API典型使用场景指导 + +### 介绍 + +使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 + +- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 +- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 + +该工程中展示的代码详细描述可查如下链接: + +- [JSVM-API调试&定位](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/jsvm-debugger-cpuprofiler-heapsnapshot.md) +- [使用 code cache 加速编译](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-code-cache.md) +- [使用JSVM-API接口创建多个引擎执行JS代码并销毁](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-runtime-task.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-----------------------------------------------------------: | :-----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +aboutcodecache/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +openinspector/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +snapshot/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +runtimetask/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +### 依赖 + +不涉及。 + +### 约束与限制 + +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/JsvmDebug > .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/JsvmDebug/runtimetask/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/.gitignore diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/build-profile.json5 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/build-profile.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/build-profile.json5 diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a1d266f456e36c0534d03d1ba57ca7ff2d8d8254 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/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": "aboutcodecache", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libaboutcodecache.so": "file:./src/main/cpp/types/libaboutcodecache" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc20c12512451f6ec9698b5dde44430b319ca941 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmDebug) + +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) + +add_library(aboutcodecache SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(aboutcodecache PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6cb5634570dfd40b1997ee22a4178416f81c6ab3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/hello.cpp @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start jsvm_code_cache] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +// [StartExclude jsvm_code_cache] +#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) +// [EndExclude jsvm_code_cache] + +JSVM_Value UseCodeCache(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 编译参数准备 + JSVM_Value jsSrc; + JSVM_Script script; + JSVM_Value result; + size_t length = 0; + const uint8_t* dataPtr = nullptr; + bool cacheRejected = true; + static std::string src = R"JS( + a = 65536; + b = 32768; + c = a + b; + )JS"; + + // 生成 code cache + { + JSVM_HandleScope handleScope; + OH_JSVM_OpenHandleScope(env, &handleScope); + + // 源码字符串转换为 js 字符串 + OH_JSVM_CreateStringUtf8(env, src.c_str(), src.size(), &jsSrc); + + // 编译js代码 + OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script); + + // 执行js代码 + OH_JSVM_RunScript(env, script, &result); + int value = 0; + OH_JSVM_GetValueInt32(env, result, &value); + OH_LOG_INFO(LOG_APP, "first run result: %{public}d\n", value); + + if (dataPtr == nullptr) { + // 将js源码编译出的脚本保存到 cache, 可以避免重复编译, 带来性能提升 + OH_JSVM_CreateCodeCache(env, script, &dataPtr, &length); + } + + OH_JSVM_CloseHandleScope(env, handleScope); + } + + // 使用 code cache + { + JSVM_HandleScope handleScope; + OH_JSVM_OpenHandleScope(env, &handleScope); + + // 源码字符串转换为 js 字符串 + OH_JSVM_CreateStringUtf8(env, src.c_str(), src.size(), &jsSrc); + + // 使用 code cache 编译js代码 + OH_JSVM_CompileScript(env, jsSrc, dataPtr, length, true, &cacheRejected, &script); + + // 执行js代码 + OH_JSVM_RunScript(env, script, &result); + int value = 0; + OH_JSVM_GetValueInt32(env, result, &value); + OH_LOG_INFO(LOG_APP, "second run result: %{public}d\n", value); + + OH_JSVM_CloseHandleScope(env, handleScope); + } + OH_LOG_INFO(LOG_APP, "cache rejected: %{public}d\n", cacheRejected); + return result; +} + +// Register a callback. +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = UseCodeCache} +}; +static JSVM_CallbackStruct *method = param; +// Register the C++ callback as a JSVM globalThis.UseCodeCache property for the JS to call. +static JSVM_PropertyDescriptor descriptor[] = { + {"UseCodeCache", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// [End jsvm_code_cache] + +// 样例测试JS +const char *SRC_CALL_NATIVE = R"JS(UseCodeCache();)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 = "aboutcodecache", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/Index.d.ts similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/Index.d.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/Index.d.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..864f45f378824770265d666f8818af231d042b3a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/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": "libaboutcodecache.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/JsvmDebug/aboutcodecache/src/main/ets/aboutcodecacheability/AboutcodecacheAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/aboutcodecacheability/AboutcodecacheAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/aboutcodecacheability/AboutcodecacheAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/aboutcodecacheability/AboutcodecacheAbility.ets index 980a32158164cefc54dbc80b5fda066deb4f4a44..6cd7641edcacea42d4168ca13b8a879e0c1eb726 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/aboutcodecacheability/AboutcodecacheAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/aboutcodecacheability/AboutcodecacheAbility.ets @@ -1,56 +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 AboutcodecacheAbility 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'); - } -}; +/* + * 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 AboutcodecacheAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..51ba8ce9777190a2e5cd51e663c63433fb54358d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/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 'libaboutcodecache.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmDebug/aboutcodecache/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6e64e7c3a207a8f4a3311a1dc8508057991004e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "aboutcodecache", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "AboutcodecacheAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "AboutcodecacheAbility", + "srcEntry": "./ets/aboutcodecacheability/AboutcodecacheAbility.ets", + "description": "$string:AboutcodecacheAbility_desc", + "icon": "$media:layered_image", + "label": "$string:AboutcodecacheAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/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/JsvmDebug/aboutcodecache/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7466d16a61207d3ab7a78da766e5a9a445d4da81 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "AboutcodecacheAbility_desc", + "value": "description" + }, + { + "name": "AboutcodecacheAbility_label", + "value": "JsvmDebug" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..51e57c0df48c67804e7953f0f9a7b01f358b7d20 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/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('testcodecache', 0, async (done: Function) => { + console.log('uitest: Testcodecache begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'AboutcodecacheAbility' + } + 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('AboutcodecacheAbility'); + + 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: Testcodecache end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..435ff848b637e47f5ed3383ec626d549086713dd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/aboutcodecache/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": "aboutcodecache_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..565c3bc4d0c79c9a1e6f59fdc475218b283fa150 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/build-profile.json5 @@ -0,0 +1,94 @@ +/* + * 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": "openinspector", + "srcPath": "./openinspector", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "snapshot", + "srcPath": "./snapshot", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "aboutcodecache", + "srcPath": "./aboutcodecache", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "runtimetask", + "srcPath": "./runtimetask", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..47b1a9ebd0480497eeb005badc6c3027428074e4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/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*/ + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..acb5922f467d4bc97cb88937f26e971dd4805ecc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/hvigorfile.ts @@ -0,0 +1,22 @@ +/* + * 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/JsvmDebug/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/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/JsvmDebug/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..5a1b7ca5d27ef45e5f9fc2e632cef872292da15c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/ohosTest.md @@ -0,0 +1,11 @@ +# JsvmDebug 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 在指定的主机和端口上激活inspector,将用来调试JS代码 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取当前堆快照并将其输出到流 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用 code cache 加速编译 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| JSVM-API接口创建多个引擎执行JS代码并销毁 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutClass/newinstance/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d92ed452ae96fe6dfa75db591db4a7c70def7233 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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": "openinspector", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libopeninspector.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fafdfa0936b61c3089a717a66e1854df3efce13b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmDebug) + +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) + +add_library(openinspector SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(openinspector PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..665b23ced4cf269af5690413d9d5b7f54abfd615 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_open_inspector] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +#include +// [StartExclude oh_jsvm_open_inspector] +#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) +// [EndExclude oh_jsvm_open_inspector] + +// 待调试的JS源码 +static std::string g_srcDebugger = R"JS( +const concat = (...args) => args.reduce((a, b) => a + b); +var dialogue = concat('"What ', 'is ', 'your ', 'name ', '?"'); +dialogue = concat(dialogue, ' --', '"My ', 'name ', 'is ', 'Bob ', '."'); +)JS"; + +// 开启debugger +static const int INSPECTOR_PORT = 9225; +static void EnableInspector(JSVM_Env env) +{ + // 在指定的主机和端口上激活inspector,创建socket。 + OH_JSVM_OpenInspector(env, "localhost", INSPECTOR_PORT); + // 等待建立socket连接。 + OH_JSVM_WaitForDebugger(env, true); +} + +// 关闭debugger +static void CloseInspector(JSVM_Env env) +{ + // 关闭inspector,结束socket连接。 + OH_JSVM_CloseInspector(env); +} + +static void RunScript(JSVM_Env env) +{ + JSVM_HandleScope handleScope; + OH_JSVM_OpenHandleScope(env, &handleScope); + + JSVM_Value jsSrc; + OH_JSVM_CreateStringUtf8(env, g_srcDebugger.c_str(), g_srcDebugger.size(), &jsSrc); + + JSVM_Script script; + OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script); + + JSVM_Value result; + OH_JSVM_RunScript(env, script, &result); + + OH_JSVM_CloseHandleScope(env, handleScope); +} + +void TestJSVM() +{ + JSVM_InitOptions initOptions{}; + OH_JSVM_Init(&initOptions); + + JSVM_VM vm; + OH_JSVM_CreateVM(nullptr, &vm); + JSVM_VMScope vmScope; + OH_JSVM_OpenVMScope(vm, &vmScope); + + JSVM_Env env; + OH_JSVM_CreateEnv(vm, 0, nullptr, &env); + // 执行JS代码之前打开debugger。 + EnableInspector(env); + JSVM_EnvScope envScope; + OH_JSVM_OpenEnvScope(env, &envScope); + + // 执行JS代码。 + RunScript(env); + + OH_JSVM_CloseEnvScope(env, envScope); + // 执行JS代码之后关闭debugger。 + CloseInspector(env); + OH_JSVM_DestroyEnv(env); + OH_JSVM_CloseVMScope(vm, vmScope); + OH_JSVM_DestroyVM(vm); +} +// [End jsvm_open_inspector] + +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 = "openinspector", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/Index.d.ts similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/Index.d.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/Index.d.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8547e3a114fd2d5bf4f9d61252bab1f77cb59991 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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": "libopeninspector.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/JsvmDebug/openinspector/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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/JsvmDebug/openinspector/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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/JsvmDebug/openinspector/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3c889cdea0fa1e4d7c8778843a2cee40306b295 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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 'libopeninspector.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmDebug/openinspector/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71598eafd4f328515f880fcca1592cb66642b109 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/module.json5 @@ -0,0 +1,78 @@ +/* + * 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": "openinspector", + "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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET", + "reason": "$string:app_name", + "usedScene": { + "abilities": [ + "FromAbility" + ], + "when": "inuse" + } + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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/JsvmDebug/openinspector/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e093041b1b2803be636046cf61a547d2da895f77 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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": "JsvmDebug" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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/JsvmDebug/openinspector/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7cea7ff3d34ae36aacaa319ef90dff74c5b41b22 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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('testOpenInspector', 0, async (done: Function) => { + console.log('uitest: TestOpenInspector 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: TestOpenInspector end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d709d9cb6adc9753b540434ca6815a02478ba993 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/openinspector/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": "openinspector_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutClass/removewrap/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..52c578358ceef8673400a283f2dbf4714056cc45 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/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": "runtimetask", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libruntimetask.so": "file:./src/main/cpp/types/libruntimetask" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..196f881cee2734ff19b103339d9e26023a2be012 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmDebug) + +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) + +add_library(runtimetask SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(runtimetask PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4cb6a95e0d0d78c8ae130a5b0000faeea7b8aa2d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/hello.cpp @@ -0,0 +1,425 @@ +/* + * 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" + +// [Start runtime_task] +#include +#include +#include +using namespace std; +// 定义map管理每个独立vm环境 +static map g_vmMap; +static map g_envMap; +static map g_callBackStructMap; +static uint32_t g_envtagNumber = 0; +static std::mutex g_envMapLock; +// [StartExclude runtime_task] + +#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) +// [EndExclude runtime_task] + +#define CHECK_COND(cond) \ + do { \ + if (!(cond)) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = false", __FILE__, __LINE__); \ + return -1; \ + } \ + } while (0) + +class Task { +public: + virtual ~Task() = default; + virtual void Run() = 0; +}; +static map> g_taskQueueMap; + +// 自定义Consoleinfo方法 +static JSVM_Value Consoleinfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1]; + #define MAX_LOG_LENGTH 255 + char log[MAX_LOG_LENGTH + 1] = ""; + size_t logLength; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); + + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, args[0], log, MAX_LOG_LENGTH, &logLength)); + log[MAX_LOG_LENGTH] = 0; + OH_LOG_INFO(LOG_APP, "JSVM API TEST: %{public}s", log); + return nullptr; +} + +// 自定义创建Promise方法用以在JS代码中创建Promise +static JSVM_Value CreatePromise(JSVM_Env env, JSVM_CallbackInfo info) +{ + OH_LOG_INFO(LOG_APP, "JSVM API TEST: CreatePromise start"); + int envID = -1; + // 通过当前env获取envID + for (auto it = g_envMap.begin(); it != g_envMap.end(); ++it) { + if (*it->second == env) { + envID = it->first; + break; + } + } + if (envID == -1) { + OH_LOG_ERROR(LOG_APP, "JSVM API TEST: CreatePromise envID failed"); + return nullptr; + } + JSVM_Value promise; + JSVM_Deferred deferred; + JSVM_CALL(OH_JSVM_CreatePromise(env, &deferred, &promise)); + // 设计ReadTask类用以将promise对象的deferred加入执行队列 + class ReadTask : public Task { + public: + ReadTask(JSVM_Env env, JSVM_Deferred deferred, int envNum) : env_(env), envID_(envNum), deferred_(deferred) {} + void Run() override + { + // string str = "TEST RUN OH_JSVM_ResolveDeferred"; + int envID = 0; + for (auto it = g_envMap.begin(); it != g_envMap.end(); ++it) { + if (*it->second == env_) { + envID = it->first; + break; + } + } + OH_LOG_INFO(LOG_APP, "JSVM API TEST: CreatePromise %{public}d", envID); + JSVM_Value result; + if (OH_JSVM_CreateInt32(env_, envID, &result) != JSVM_OK) { + return; + } + if (OH_JSVM_ResolveDeferred(env_, deferred_, result) != JSVM_OK) { + return; + } + } + + private: + JSVM_Env env_; + int envID_; + JSVM_Deferred deferred_; + }; + g_taskQueueMap[envID].push_back(new ReadTask(env, deferred, envID)); + OH_LOG_INFO(LOG_APP, "JSVM API TEST: CreatePromise end"); + return promise; +} + +// 自定义Add方法 +static JSVM_Value Add(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 2; + JSVM_Value args[2]; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); + double num1; + double num2; + JSVM_CALL(OH_JSVM_GetValueDouble(env, args[0], &num1)); + JSVM_CALL(OH_JSVM_GetValueDouble(env, args[1], &num2)); + JSVM_Value sum = nullptr; + JSVM_CALL(OH_JSVM_CreateDouble(env, num1 + num2, &sum)); + return sum; +} + +// 自定义AssertEqual方法 +static JSVM_Value AssertEqual(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 2; + JSVM_Value args[2]; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); + + bool isStrictEquals = false; + JSVM_CALL(OH_JSVM_StrictEquals(env, args[0], args[1], &isStrictEquals)); + + if (isStrictEquals) { + OH_LOG_INFO(LOG_APP, "JSVM API TEST RESULT: PASS"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM API TEST RESULT: FAILED"); + } + return nullptr; +} + +static int fromOHStringValue(JSVM_Env &env, JSVM_Value &value, std::string &result) +{ + size_t size; + CHECK_RET(OH_JSVM_GetValueStringUtf8(env, value, nullptr, 0, &size)); + char resultStr[size + 1]; + CHECK_RET(OH_JSVM_GetValueStringUtf8(env, value, resultStr, size + 1, &size)); + result = resultStr; + return 0; +} + +// 提供创建JSVM运行环境的对外接口并返回对应唯一ID +static int CreateJsCore(uint32_t *result) +{ + OH_LOG_INFO(LOG_APP, "JSVM CreateJsCore START"); + g_taskQueueMap[g_envtagNumber] = deque {}; + + if (g_aa == 0) { + JSVM_InitOptions init_options; + memset(&init_options, 0, sizeof(init_options)); + CHECK(OH_JSVM_Init(&init_options)); + g_aa++; + } + std::lock_guard lock_guard(g_envMapLock); + + // 虚拟机实例 + g_vmMap[g_envtagNumber] = new JSVM_VM; + JSVM_CreateVMOptions options; + JSVM_VMScope vmScope; + memset(&options, 0, sizeof(options)); + CHECK(OH_JSVM_CreateVM(&options, g_vmMap[g_envtagNumber])); + CHECK(OH_JSVM_OpenVMScope(*g_vmMap[g_envtagNumber], &vmScope)); + + // 新环境 + g_envMap[g_envtagNumber] = new JSVM_Env; + g_callBackStructMap[g_envtagNumber] = new JSVM_CallbackStruct[4]; + + // 注册用户提供的本地函数的回调函数指针和数据,通过JSVM-API暴露给js + constexpr int kLoopCount = 4; + for (int i = 0; i < kLoopCount; i++) { + g_callBackStructMap[g_envtagNumber][i].data = nullptr; + } + g_callBackStructMap[g_envtagNumber][0].callback = Consoleinfo; + g_callBackStructMap[g_envtagNumber][1].callback = Add; + g_callBackStructMap[g_envtagNumber][2].callback = AssertEqual; + g_callBackStructMap[g_envtagNumber][3].callback = CreatePromise; + JSVM_PropertyDescriptor descriptors[] = { + { "consoleinfo", NULL, &g_callBackStructMap[g_envtagNumber][0], NULL, NULL, NULL, JSVM_DEFAULT }, + { "add", NULL, &g_callBackStructMap[g_envtagNumber][1], NULL, NULL, NULL, JSVM_DEFAULT }, + { "assertEqual", NULL, &g_callBackStructMap[g_envtagNumber][2], NULL, NULL, NULL, JSVM_DEFAULT }, + { "createPromise", NULL, &g_callBackStructMap[g_envtagNumber][3], NULL, NULL, NULL, JSVM_DEFAULT }, + }; + CHECK(OH_JSVM_CreateEnv( + *g_vmMap[g_envtagNumber], sizeof(descriptors) / sizeof(descriptors[0]), descriptors, g_envMap[g_envtagNumber])); + CHECK(OH_JSVM_CloseVMScope(*g_vmMap[g_envtagNumber], vmScope)); + + OH_LOG_INFO(LOG_APP, "JSVM CreateJsCore END"); + *result = g_envtagNumber; + g_envtagNumber++; + return 0; +} + +// 对外提供释放JSVM环境接口,通过envId释放对应环境 +static int ReleaseJsCore(uint32_t coreEnvId) +{ + OH_LOG_INFO(LOG_APP, "JSVM ReleaseJsCore START"); + CHECK_COND(g_envMap.count(coreEnvId) != 0 && g_envMap[coreEnvId] != nullptr); + + std::lock_guard lock_guard(g_envMapLock); + + CHECK(OH_JSVM_DestroyEnv(*g_envMap[coreEnvId])); + g_envMap[coreEnvId] = nullptr; + g_envMap.erase(coreEnvId); + CHECK(OH_JSVM_DestroyVM(*g_vmMap[coreEnvId])); + g_vmMap[coreEnvId] = nullptr; + g_vmMap.erase(coreEnvId); + delete[] g_callBackStructMap[coreEnvId]; + g_callBackStructMap[coreEnvId] = nullptr; + g_callBackStructMap.erase(coreEnvId); + g_taskQueueMap.erase(coreEnvId); + + OH_LOG_INFO(LOG_APP, "JSVM ReleaseJsCore END"); + return 0; +} + +static std::mutex g_mutexLock; +// 对外提供执行JS代码接口,通过coreID在对应的JSVN环境中执行JS代码 +static int EvaluateJS(uint32_t envId, const char *source, std::string &res) +{ + OH_LOG_INFO(LOG_APP, "JSVM EvaluateJS START"); + + CHECK_COND(g_envMap.count(envId) != 0 && g_envMap[envId] != nullptr); + + JSVM_Env env = *g_envMap[envId]; + JSVM_VM vm = *g_vmMap[envId]; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + + std::lock_guard lock_guard(g_mutexLock); + { + // 创建JSVM环境 + CHECK_RET(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(*g_envMap[envId], &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(*g_envMap[envId], &handleScope)); + + // 通过script调用测试函数 + JSVM_Script script; + JSVM_Value jsSrc; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, source, 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_ValueType type; + CHECK_RET(OH_JSVM_Typeof(env, result, &type)); + OH_LOG_INFO(LOG_APP, "JSVM API TEST type: %{public}d", type); + // Execute tasks in the current env event queue + while (!g_taskQueueMap[envId].empty()) { + auto task = g_taskQueueMap[envId].front(); + g_taskQueueMap[envId].pop_front(); + task->Run(); + delete task; + } + + if (type == JSVM_STRING) { + CHECK_COND(fromOHStringValue(env, result, res) != -1); + } else if (type == JSVM_BOOLEAN) { + bool ret = false; + CHECK_RET(OH_JSVM_GetValueBool(env, result, &ret)); + ret ? res = "true" : res = "false"; + } else if (type == JSVM_NUMBER) { + int32_t num; + CHECK_RET(OH_JSVM_GetValueInt32(env, result, &num)); + res = std::to_string(num); + } else if (type == JSVM_OBJECT) { + JSVM_Value objResult; + CHECK_RET(OH_JSVM_JsonStringify(env, result, &objResult)); + CHECK_COND(fromOHStringValue(env, objResult, res) != -1); + } + } + { + bool aal = false; + CHECK_RET(OH_JSVM_PumpMessageLoop(*g_vmMap[envId], &aal)); + CHECK_RET(OH_JSVM_PerformMicrotaskCheckpoint(*g_vmMap[envId])); + CHECK_RET(OH_JSVM_CloseHandleScope(*g_envMap[envId], handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(*g_envMap[envId], envScope)); + CHECK_RET(OH_JSVM_CloseVMScope(*g_vmMap[envId], vmScope)); + } + OH_LOG_INFO(LOG_APP, "JSVM EvaluateJS END"); + return 0; +} + +static int32_t TestJSVM() +{ + const char source1[] = "{\ + let a = \"hello World\";\ + consoleinfo(a);\ + const mPromise = createPromise();\ + mPromise.then((result) => {\ + assertEqual(result, 0);\ + });\ + a;\ + };"; + + const char source2[] = "{\ + let a = \"second hello\";\ + consoleinfo(a);\ + let b = add(99, 1);\ + assertEqual(100, b);\ + assertEqual(add(99, 1), 100);\ + createPromise().then((result) => {\ + assertEqual(result, 1);\ + });\ + a;\ + };"; + + // 创建首个运行环境,并绑定TS回调 + uint32_t coreId1; + CHECK_COND(CreateJsCore(&coreId1) == 0); + OH_LOG_INFO(LOG_APP, "TEST coreId: %{public}d", coreId1); + // 在首个运行环境中执行JS代码 + std::string result1; + CHECK_COND(EvaluateJS(coreId1, source1, result1) == 0); + OH_LOG_INFO(LOG_APP, "TEST evaluateJS: %{public}s", result1.c_str()); + + // 创建第二个运行环境,并绑定TS回调 + uint32_t coreId2; + CHECK_COND(CreateJsCore(&coreId2) == 0); + OH_LOG_INFO(LOG_APP, "TEST coreId: %{public}d", coreId2); + // 在第二个运行环境中执行JS代码 + std::string result2; + CHECK_COND(EvaluateJS(coreId2, source2, result2) == 0); + OH_LOG_INFO(LOG_APP, "TEST evaluateJS: %{public}s", result2.c_str()); + + // 释放首个运行环境 + CHECK_COND(ReleaseJsCore(coreId1) == 0); + // 释放第二个运行环境 + CHECK_COND(ReleaseJsCore(coreId2) == 0); + OH_LOG_INFO(LOG_APP, "Test NAPI end"); + + return 0; +} +// [End runtime_task] + +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 = "runtimetask", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/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/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/oh-package.json5 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/oh-package.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/types/libruntimetask/oh-package.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..18d41e69dc0d2e9d624b9d9e201e392449cf073f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/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 'libruntimetask.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/JsvmDebug/runtimetask/src/main/ets/runtimetaskability/RuntimetaskAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/runtimetaskability/RuntimetaskAbility.ets similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/runtimetaskability/RuntimetaskAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/runtimetaskability/RuntimetaskAbility.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0917b7889eaf9727c90b39516d8d425f603ab51 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/module.json5 @@ -0,0 +1,41 @@ +/* + * 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": "runtimetask", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "RuntimetaskAbility", + "deviceTypes": [ + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "RuntimetaskAbility", + "srcEntry": "./ets/runtimetaskability/RuntimetaskAbility.ets", + "description": "$string:RuntimetaskAbility_desc", + "icon": "$media:layered_image", + "label": "$string:RuntimetaskAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/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/JsvmDebug/runtimetask/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/float.json similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/float.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/float.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..99fd7b9e813430145bbc28198f3c11b97a310739 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "runtimetask_test", + "type": "feature", + "deviceTypes": [ + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/screenshots/JsvmDebug_2.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmDebug/snapshot/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..bbb00a28e0ca0201c021f8c2ba30e0e7445cb8e2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/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/JsvmUsageGuide/JsvmAboutClass/removewrap/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dee921dd018c4a38d4f1d78fa800d96e77bf4e18 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/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": "snapshot", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libsnapshot.so": "file:./src/main/cpp/types/libsnapshot" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6730c6ce01e017589553a4410584984626930b90 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmDebug) + +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) + +add_library(snapshot SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(snapshot PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..afa8fdaf11f2f65d0f05ae181db9092bd4cd923d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/hello.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start heap_snapshot] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +#include +// [StartExclude heap_snapshot] +#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) +// [EndExclude heap_snapshot] + +using namespace std; + +// 待调优的JS代码。 +static string g_srcProf = R"JS( +function sleep(delay) { + var start = (new Date()).getTime(); + while ((new Date()).getTime() - start < delay) { + continue; + } +} + +function work3() { + sleep(300); +} + +function work2() { + work3(); + sleep(200); +} + +function work1() { + work2(); + sleep(100); +} + +work1(); +)JS"; + +// 数据输出流回调,用户自定义,处理返回的调优数据,此处以写入文件为例。 +static bool OutputStream(const char *data, int size, void *streamData) +{ + auto &os = *reinterpret_cast(streamData); + if (data) { + os.write(data, size); + } else { + os.close(); + } + return true; +} + +static JSVM_CpuProfiler ProfilingBegin(JSVM_VM vm) +{ + // 文件输出流,保存调优数据,/data/storage/el2/base/files为沙箱路径。以包名为com.example.helloworld为例。 + // 实际文件会保存到/data/app/el2/100/base/com.example.helloworld/files/heap-snapshot-begin.heapsnapshot。 + ofstream heapSnapshot("/data/storage/el2/base/files/heap-snapshot-begin.heapsnapshot", + ios::out | ios::binary | ios::trunc); + // 执行JS前获取一次Heap Snapshot数据。 + OH_JSVM_TakeHeapSnapshot(vm, OutputStream, &heapSnapshot); + JSVM_CpuProfiler cpuProfiler; + // 开启CPU Profiler。 + OH_JSVM_StartCpuProfiler(vm, &cpuProfiler); + return cpuProfiler; +} + +// 关闭调优数据采集工具 +static void ProfilingEnd(JSVM_VM vm, JSVM_CpuProfiler cpuProfiler) +{ + // 文件输出流,保存调优数据,/data/storage/el2/base/files为沙箱路径。以包名为com.example.helloworld为例。 + // 实际文件会保存到/data/app/el2/100/base/com.example.helloworld/files/cpu-profile.cpuprofile。 + ofstream cpuProfile("/data/storage/el2/base/files/cpu-profile.cpuprofile", + ios::out | ios::binary | ios::trunc); + // 关闭CPU Profiler,获取数据。 + OH_JSVM_StopCpuProfiler(vm, cpuProfiler, OutputStream, &cpuProfile); + ofstream heapSnapshot("/data/storage/el2/base/files/heap-snapshot-end.heapsnapshot", + ios::out | ios::binary | ios::trunc); + // 执行JS后再获取一次Heap Snapshot数据,与执行前数据作对比,以分析内存问题或者进行内存调优。 + OH_JSVM_TakeHeapSnapshot(vm, OutputStream, &heapSnapshot); +} + +static JSVM_Value RunScriptWithStatistics(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_VM vm; + OH_JSVM_GetVM(env, &vm); + + // 开始调优。 + auto cpuProfiler = ProfilingBegin(vm); + + JSVM_HandleScope handleScope; + OH_JSVM_OpenHandleScope(env, &handleScope); + + JSVM_Value jsSrc; + OH_JSVM_CreateStringUtf8(env, g_srcProf.c_str(), g_srcProf.size(), &jsSrc); + + JSVM_Script script; + OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script); + + JSVM_Value result; + // 执行JS代码。 + OH_JSVM_RunScript(env, script, &result); + + OH_JSVM_CloseHandleScope(env, handleScope); + + // 结束调优。 + ProfilingEnd(vm, cpuProfiler); + return nullptr; +} +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = RunScriptWithStatistics}, +}; +static JSVM_CallbackStruct *method = param; +// runScriptWithStatistics方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"runScriptWithStatistics", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = R"JS(runScriptWithStatistics();)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; +} +// [End heap_snapshot] + +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 = "snapshot", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/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/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..16c3808c9505f120ac6dea911d49d7901885583e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/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": "libsnapshot.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/JsvmDebug/snapshot/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4b31cda95a2229bc66464359ae72adbb32c602b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/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 'libsnapshot.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmDebug/snapshot/src/main/ets/snapshotability/SnapshotAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/ets/snapshotability/SnapshotAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/ets/snapshotability/SnapshotAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/ets/snapshotability/SnapshotAbility.ets index e11c5aafc0ae1e5b16ff1be334728c758c076fd3..1c4217cc16e6a7acfbaa14e465984465bd04d2eb --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/ets/snapshotability/SnapshotAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/ets/snapshotability/SnapshotAbility.ets @@ -1,56 +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 SnapshotAbility 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'); - } -}; +/* + * 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 SnapshotAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0c4cda92ed87a720522d6fe7b4bcdb7c12d46c5f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "snapshot", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "SnapshotAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "SnapshotAbility", + "srcEntry": "./ets/snapshotability/SnapshotAbility.ets", + "description": "$string:SnapshotAbility_desc", + "icon": "$media:layered_image", + "label": "$string:SnapshotAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/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/JsvmDebug/snapshot/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ac0d6697eeedf1c2e45b72f06d9a105a97f9bffc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "SnapshotAbility_desc", + "value": "description" + }, + { + "name": "SnapshotAbility_label", + "value": "JsvmDebug" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f1801beec1f481656dc8ea304ca921b75ea9742 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/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('testSnapshot', 0, async (done: Function) => { + console.log('uitest: TestSnapshot begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'SnapshotAbility' + } + 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('SnapshotAbility'); + + 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: TestSnapshot end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c8526b3853fcb2175f87eeb0819c5c1d604cb12 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmDebug/snapshot/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": "snapshot_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c70654c811615148cd180442465e50beeca4af71 --- /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 100644 index 0000000000000000000000000000000000000000..6c4c265d8c2e7a6a25091f88d0c6425ca4853c0d --- /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 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8398ee3c910cff3acca6260dc6d4c45c7b0b7289 --- /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) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-------------------------------------------------------------: | :-------------------------------------------------------------: | +| | | + +### 使用说明 + +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 100644 index 0000000000000000000000000000000000000000..dfff3e654af72bbb647ca37e2884ac52a8a9e80d --- /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/JsvmUsageGuide/JsvmAboutPromise/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/code-linter.json5 diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/.gitignore 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 100644 index 0000000000000000000000000000000000000000..fea31f4580540c7c560b62bf531292c471c410f1 --- /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/JsvmUsageGuide/JsvmAboutPromise/ispromise/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/obfuscation-rules.txt 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 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /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 100644 index 0000000000000000000000000000000000000000..27bd6f5841bfad0b32f0bc7821c9ee0a68529ec2 --- /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 100644 index 0000000000000000000000000000000000000000..c0031cf18050a8e9f3727bb6d8bda9cfe39df741 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/cpp/hello.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_process] +#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); } +// [End oh_jsvm_process] 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 100644 index 0000000000000000000000000000000000000000..15f72a84a72e0916cbdeafcc0895f9c7a4745b74 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start export_native] +export const runTest: () => void; +// [End export_native] \ 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 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /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 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /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 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /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 100644 index 0000000000000000000000000000000000000000..280db53c570483c7d05c7da85363600719bfecef --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start call_native_cpp] +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%') + } +} +// [End call_native_cpp] 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 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /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 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /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 100644 index 0000000000000000000000000000000000000000..8002e233e660a51ebf737040605ed40ef96e1f4e --- /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 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/background.png 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 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json 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 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/startIcon.png 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 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/main_pages.json 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 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /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 100644 index 0000000000000000000000000000000000000000..8002e233e660a51ebf737040605ed40ef96e1f4e --- /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 100644 index 0000000000000000000000000000000000000000..52d5186346bf8a90831df8e553ac1b5da49aeaa1 --- /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 100644 index 0000000000000000000000000000000000000000..85648926249bfa905428b7cbf593b1cf7a5f6188 --- /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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/List.test.ets 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 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /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 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /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/JsvmUsageGuide/JsvmAboutClass/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /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 100644 index 0000000000000000000000000000000000000000..679da07e5c03390f9ddc4dc6f00bd6621ca80db1 --- /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 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmProcess/screenshots/JsvmProcess_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e4a86a1d711b241e1ed1492dce68ab80ee1bf474 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/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.jsvmaboutarray", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fc7ee24f918c7065f5dafe97a7d67fe3e3031e02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutArray" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0c4518398360a8addafcffa38f86ef5b38ac6b36 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/README.md @@ -0,0 +1,333 @@ +# ArkTS使用JSVM-API接口进行array相关开发 + +### 介绍 + +使用 JSVM-API 接口进行数组(array)相关开发时,调用相关接口可以在 JSVM 模块中直接操作和处理 JavaScript 中的数组。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行array相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-array.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------------: | :----------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createarray/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createarraywithlength/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createdataview/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createtypedarray/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +deleteelement/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getarraylength/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getdataviewinfo/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getelement/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +gettypedarrayinfo/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +haselement/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +isarray/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +isdataview/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +istypedarray/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +setelement/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutArray > .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/JsvmUsageGuide/JsvmAboutArray/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d76069bbe0c677acf8e8a33fdad0307e418d3fd8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/build-profile.json5 @@ -0,0 +1,214 @@ +/* + * 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": "createarray", + "srcPath": "./createarray", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createarraywithlength", + "srcPath": "./createarraywithlength", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createtypedarray", + "srcPath": "./createtypedarray", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createdataview", + "srcPath": "./createdataview", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getarraylength", + "srcPath": "./getarraylength", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getdataviewinfo", + "srcPath": "./getdataviewinfo", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "deleteelement", + "srcPath": "./deleteelement", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getelement", + "srcPath": "./getelement", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "gettypedarrayinfo", + "srcPath": "./gettypedarrayinfo", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "haselement", + "srcPath": "./haselement", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "isarray", + "srcPath": "./isarray", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "isdataview", + "srcPath": "./isdataview", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "istypedarray", + "srcPath": "./istypedarray", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "setelement", + "srcPath": "./setelement", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/code-linter.json5 diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ecbf3d7359bb228ab566ebf167568a964461ba2e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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": "createarray", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatearray.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..71ffbe12acf9abf5afa7b4004a238f05b3ea0a6d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createarray SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc034ea8e0a45856ae9c7c9481d8964c79033fa4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/hello.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_array] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_array] +#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) +// [EndExclude oh_jsvm_create_array] + +// CreateArray注册回调 +static int g_diffValueFive = 5; +// OH_JSVM_CreateArray的样例方法 +static JSVM_Value CreateArray(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 创建一个空数组 + JSVM_Value array = nullptr; + JSVM_Status status = OH_JSVM_CreateArray(env, &array); + // 对创建的数组进行赋值 + for (int i = 0; i < g_diffValueFive; i++) { + JSVM_Value element; + OH_JSVM_CreateInt32(env, i, &element); + OH_JSVM_SetElement(env, array, i, element); + } + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateArray fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateArray success"); + } + return array; +} +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateArray}, +}; +static JSVM_CallbackStruct *method = param; +// CreateArray方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createArray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + function testCreateArray() { + return createArray(); + } + testCreateArray(); +)JS"; +// [End oh_jsvm_create_array] + +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 = "createarray", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c1310bc793b05567be9c7fac3eb42b1f3f05531 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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": "libcreatearray.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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1ad949a7278f94c63ab7464ea4cb5238cd4aded2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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 'libcreatearray.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3596cb1a405d77456cf442ca186fdba00a6f806 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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": "createarray", + "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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cab53b2b24f83534fda539b662f4de609ee1b85b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..16d656e84635c24df0425c220efe1ef0fe8378d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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('testCreateArray', 0, async (done: Function) => { + console.log('uitest: TestCreateArray 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: TestCreateArray end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..011ac94ef81b0148a099cff950ec37a169c00137 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/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": "createarray_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/obfuscation-rules.txt old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10bc7b2060f860234cd6886d1eef14e1c7391e4e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/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": "createarraywithlength", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatearraywithlength.so": "file:./src/main/cpp/types/libcreatearraywithlength" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6511b92654ecd904ab690ff8fd2d0901ef7447c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createarraywithlength SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createarraywithlength PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f28007a2139ef8c82d7c20d87b37b6c6643ba2d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/hello.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_array_with_length] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_array_with_length] +#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) +// [EndExclude oh_jsvm_create_array_with_length] + +// OH_JSVM_CreateArrayWithLength的样例方法 +static JSVM_Value CreateArrayWithLength(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + JSVM_Value result = nullptr; + // 解析传递的参数OH_JSVM_GetCbInfo + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + // 获取传递的数组长度 + int32_t length; + OH_JSVM_GetValueInt32(env, argv[0], &length); + // 使用OH_JSVM_CreateArrayWithLength创建传递固定长度的数组 + JSVM_Status status = OH_JSVM_CreateArrayWithLength(env, length, &result); + if (status == JSVM_OK) { + // 给创建的数组设置值 + for (int32_t i = 0; i < length; i++) { + JSVM_Value value; + OH_JSVM_CreateInt32(env, i, &value); + OH_JSVM_SetElement(env, result, i, value); + } + OH_LOG_INFO(LOG_APP, "JSVM CreateArrayWithLength success"); + } else { + OH_LOG_ERROR(LOG_APP, "JSVM CreateArrayWithLength fail"); + } + return result; +} +// CreateArrayWithLength注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateArrayWithLength}, +}; +static JSVM_CallbackStruct *method = param; +// CreateArrayWithLength方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createArrayWithLength", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +let num = 7; +function testCreateArrayWithLength(num) { + return createArrayWithLength(num); +} +testCreateArrayWithLength(num); +)JS"; +// [End oh_jsvm_create_array_with_length] + +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 = "createarraywithlength", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e5fb57edaab34c9e0b819017f76db529cbee5ef0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/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": "libcreatearraywithlength.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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/createarraywithlengthability/CreatearraywithlengthAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/createarraywithlengthability/CreatearraywithlengthAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/createarraywithlengthability/CreatearraywithlengthAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/createarraywithlengthability/CreatearraywithlengthAbility.ets index 767c2d4d445406bc2b988d7757267dd5cd875d84..09df711e0fdab29e55de3779a00a9a643ace6c39 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/createarraywithlengthability/CreatearraywithlengthAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/createarraywithlengthability/CreatearraywithlengthAbility.ets @@ -1,56 +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 CreatearraywithlengthAbility 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'); - } -}; +/* + * 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 CreatearraywithlengthAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..40855f42806c694c5836a866512d7ffdc5986596 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/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 'libcreatearraywithlength.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(20) + .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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e5012073cc487d4422617cd63e5c506a4da663ec --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createarraywithlength", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatearraywithlengthAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatearraywithlengthAbility", + "srcEntry": "./ets/createarraywithlengthability/CreatearraywithlengthAbility.ets", + "description": "$string:CreatearraywithlengthAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatearraywithlengthAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c887db6610373b5150c613963f11fe10367fc6e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatearraywithlengthAbility_desc", + "value": "description" + }, + { + "name": "CreatearraywithlengthAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1aa404cb806ad447263f75acd7ca3b5536b0371 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/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('testCreateArrayWithLength', 0, async (done: Function) => { + console.log('uitest: TestCreateArrayWithLength begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatearraywithlengthAbility' + } + 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('CreatearraywithlengthAbility'); + + 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: TestCreateArrayWithLength end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/List.test.ets similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ead9aad5172eda12d872b3b802d4bb0f44efe05d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/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": "createarraywithlength_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/.gitignore similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/obfuscation-rules.txt similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/obfuscation-rules.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/obfuscation-rules.txt diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..50d711d2fb2ea6ea6bad9d23d9bb1c08965cad4a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/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": "createdataview", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatedataview.so": "file:./src/main/cpp/types/libcreatedataview" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2e3832115135f64116df63b8d1e44da6a7ad50aa --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createdataview SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createdataview PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..653b95f9cccc2abac28c1b1a056c6a045609c410 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/hello.cpp @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_dataview] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_dataview] +#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) + +static int g_diffValueFour = 4; +static int g_diffValueTwelve = 12; +// [EndExclude oh_jsvm_create_dataview] + +// OH_JSVM_CreateDataview的样例方法 +static JSVM_Value CreateDataView(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + JSVM_Value arrayBuffer = nullptr; + JSVM_Value result = nullptr; + // DataView的字节长度 + size_t byteLength = g_diffValueFour; + // 字节偏移量 + size_t byteOffset = g_diffValueTwelve; + // 获取回调函数的参数信息 + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 将参数转换为对象类型 + OH_JSVM_CoerceToObject(env, args[0], &arrayBuffer); + // 创建一个数据视图对象,并指定字节长度和字节偏移量 + JSVM_Status status = OH_JSVM_CreateDataview(env, byteLength, arrayBuffer, byteOffset, &result); + // 获取DataView的指针和长度信息 + uint8_t *data = nullptr; + size_t length = 0; + // 为DataView赋值 + for (size_t i = 0; i < length; i++) { + data[i] = static_cast(i + 1); + } + int32_t infoType; + OH_JSVM_GetValueInt32(env, args[1], &infoType); + size_t returnLength; + JSVM_Value returnArrayBuffer = nullptr; + size_t returnOffset; + enum InfoType { BYTE_LENGTHE, ARRAY_BUFFERE, BYTE_OFFSET }; + // 获取dataview信息 + OH_JSVM_GetDataviewInfo(env, result, &returnLength, (void **)&data, &returnArrayBuffer, &returnOffset); + JSVM_Value returnResult = nullptr; + switch (infoType) { + case BYTE_LENGTHE: + JSVM_Value len; + OH_JSVM_CreateInt32(env, returnLength, &len); + returnResult = len; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateDataView fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateDataView success, returnLength: %{public}d", returnLength); + } + break; + case ARRAY_BUFFERE: + bool isArraybuffer; + OH_JSVM_IsArraybuffer(env, returnArrayBuffer, &isArraybuffer); + JSVM_Value isArray; + OH_JSVM_GetBoolean(env, isArraybuffer, &isArray); + returnResult = isArray; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateDataView fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateDataView success, isArraybuffer: %{public}d", isArraybuffer); + } + break; + case BYTE_OFFSET: + JSVM_Value offset; + OH_JSVM_CreateInt32(env, returnOffset, &offset); + returnResult = offset; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateDataView fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateDataView success, returnOffset: %{public}d", returnOffset); + } + break; + default: + break; + } + return returnResult; +} +// CreateDataView注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateDataView}, +}; +static JSVM_CallbackStruct *method = param; +// CreateDataView方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createDataView", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let BYTE_LENGTH = 0; + createDataView(new ArrayBuffer(16), BYTE_LENGTH); + let IS_ARRAYBUFFER = 1; + createDataView(new ArrayBuffer(16), IS_ARRAYBUFFER); + let BYTE_OFFSET = 2; + createDataView(new ArrayBuffer(16), BYTE_OFFSET); +)JS"; +// [End oh_jsvm_create_dataview] + +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 = "createdataview", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6d5f067aff3a11838b5078968cff7fa9424c21b9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/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": "libcreatedataview.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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/createdataviewability/CreatedataviewAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/createdataviewability/CreatedataviewAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/createdataviewability/CreatedataviewAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/createdataviewability/CreatedataviewAbility.ets index 3097d59ba6bd4f43f97c0f5e95bebd3362e3c8fb..f3329ad686196f6eefa33f99635fd41378fbccfa --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/createdataviewability/CreatedataviewAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/createdataviewability/CreatedataviewAbility.ets @@ -1,56 +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 CreatedataviewAbility 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'); - } -}; +/* + * 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 CreatedataviewAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e0e8375993999da608bf840da74763013719a73 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/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 'libcreatedataview.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2edbae32ff9b376cf3eff9092eeab31a8388fb11 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createdataview", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatedataviewAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatedataviewAbility", + "srcEntry": "./ets/createdataviewability/CreatedataviewAbility.ets", + "description": "$string:CreatedataviewAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatedataviewAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9587b21cf68d76103d5fca5a552319f1ee282ab4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatedataviewAbility_desc", + "value": "description" + }, + { + "name": "CreatedataviewAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/layered_image.json similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/profile/main_pages.json similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d76e813752bb8f8d570e0b66a05a455a80ed36e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { 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('testCreateDataview', 0, async (done: Function) => { + console.log('uitest: TestCreateDataview begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatedataviewAbility' + } + 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('CreatedataviewAbility'); + + 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: TestCreateDataview end'); + done(); + }) + }) +} + + diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ad513a5815838dcc8288933e7c5a32ade1f55c1b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/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": "createdataview_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0d18bda7bb6268636d0d5af32e2ba58d049fa8b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/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": "createtypedarray", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatetypedarray.so": "file:./src/main/cpp/types/libcreatetypedarray" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..68979498b9ab5fae85ab745295ba835168bc960a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createtypedarray SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createtypedarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5cde47efc85e0bad18a39fe13f7ff1c0eab2b3bd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/hello.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_typedarray] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_typedarray] +#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) +// [EndExclude oh_jsvm_create_typedarray] + +// OH_JSVM_CreateTypedarray的样例方法 +static int g_diffValueThree = 3; +static JSVM_Value CreateTypedArray(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + int32_t typeNum; + OH_JSVM_GetValueInt32(env, args[0], &typeNum); + JSVM_TypedarrayType arrayType; + // 用于存储每个元素的大小 + size_t elementSize = 0; + // 转换为JSVM_TypedarrayType类型 + arrayType = static_cast(typeNum); + switch (typeNum) { + case JSVM_INT8_ARRAY: + case JSVM_UINT8_ARRAY: + case JSVM_UINT8_CLAMPED_ARRAY: + elementSize = sizeof(int8_t); + break; + case JSVM_INT16_ARRAY: + case JSVM_UINT16_ARRAY: + elementSize = sizeof(int16_t); + break; + case JSVM_INT32_ARRAY: + case JSVM_UINT32_ARRAY: + elementSize = sizeof(int32_t); + break; + case JSVM_FLOAT32_ARRAY: + elementSize = sizeof(float); + break; + case JSVM_FLOAT64_ARRAY: + elementSize = sizeof(double); + break; + case JSVM_BIGINT64_ARRAY: + case JSVM_BIGUINT64_ARRAY: + elementSize = sizeof(int64_t); + break; + default: + // 默认创建JSVM_INT8_ARRAY类型 + arrayType = JSVM_INT8_ARRAY; + elementSize = sizeof(int8_t); + break; + } + size_t length = g_diffValueThree; + JSVM_Value arrayBuffer = nullptr; + JSVM_Value typedArray = nullptr; + void *data; + // 创建一个ArrayBuffer + OH_JSVM_CreateArraybuffer(env, length * elementSize, (void **)&data, &arrayBuffer); + // 根据给定类型创建TypedArray + JSVM_Status status = OH_JSVM_CreateTypedarray(env, arrayType, length, arrayBuffer, 0, &typedArray); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateTypedArray fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateTypedArray success"); + } + return typedArray; +} +// CreateTypedArray注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateTypedArray}, +}; +static JSVM_CallbackStruct *method = param; +// CreateTypedArray方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createTypedArray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +const type = { + INT8_ARRAY: 0, + UINT8_ARRAY: 1, + UINT8_CLAMPED_ARRAY: 2, + INT16_ARRAY: 3, + UINT16_ARRAY: 4, + INT32_ARRAY: 5, + UINT32_ARRAY: 6, + FLOAT32_ARRAY: 7, + FLOAT64_ARRAY: 8, + BIGINT64_ARRAY: 9, + BIGUINT64_ARRAY: 10 +}; +createTypedArray(type.INT8_ARRAY); +createTypedArray(type.INT32_ARRAY); +)JS"; +// [End oh_jsvm_create_typedarray] + +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 = "createtypedarray", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fcf561ebde3f8cd6fd89f8804bea1c78ef66d794 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/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": "libcreatetypedarray.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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/createtypedarrayability/CreatetypedarrayAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/createtypedarrayability/CreatetypedarrayAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/createtypedarrayability/CreatetypedarrayAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/createtypedarrayability/CreatetypedarrayAbility.ets index f397f464aa9de6ca4274f90b0b7bf248981b07b3..fe363aaad25f33395ab7ddd1428563e1ef41783b --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/createtypedarrayability/CreatetypedarrayAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/createtypedarrayability/CreatetypedarrayAbility.ets @@ -1,56 +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 CreatetypedarrayAbility 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'); - } -}; +/* + * 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 CreatetypedarrayAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b46621430799c4971aa60d845e7c175168c2ac05 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/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 'libcreatetypedarray.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e02d76dcd39c30bab6136cdeb9647ae077ca043 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createtypedarray", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatetypedarrayAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatetypedarrayAbility", + "srcEntry": "./ets/createtypedarrayability/CreatetypedarrayAbility.ets", + "description": "$string:CreatetypedarrayAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatetypedarrayAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7082e7bcf9831a8456f795dbec1f0d0dccd5be3c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatetypedarrayAbility_desc", + "value": "description" + }, + { + "name": "CreatetypedarrayAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d7162797f56d0adc307fc889c8802d868e4c2928 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/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('testCreateTypedarray', 0, async (done: Function) => { + console.log('uitest: TestCreateTypedarray begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatetypedarrayAbility' + } + 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('CreatetypedarrayAbility'); + + 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: TestCreateTypedarray end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f1f3f7cf1d7400d748d671217257615cb0eeee64 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/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": "createtypedarray_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/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/JsvmUsageGuide/JsvmAboutArray/deleteelement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1af11c0643f8ce41edf9455c8e50d23b4142026b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/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": "deleteelement", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libdeleteelement.so": "file:./src/main/cpp/types/libdeleteelement" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c799add86de2ae052fe0d004be1e11d251da9325 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(deleteelement SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(deleteelement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f06c3ab788556337814d4fa15498b69aea964ba2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/hello.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_delete_element] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_delete_element] +#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) +// [EndExclude oh_jsvm_delete_element] + +// OH_JSVM_DeleteElement的样例方法 +static JSVM_Value DeleteElement(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取要删除的元素的索引 + uint32_t index; + OH_JSVM_GetValueUint32(env, args[1], &index); + // 尝试删除请求索引位置的元素 + bool deleted = true; + JSVM_Status status = OH_JSVM_DeleteElement(env, args[0], index, &deleted); + // 将boolean结果转换为JSVM_Value并返回 + JSVM_Value result = nullptr; + OH_JSVM_GetBoolean(env, deleted, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM DeleteElement fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM DeleteElement: %{public}d", deleted); + } + return result; +} +// DeleteElement注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = DeleteElement}, +}; +static JSVM_CallbackStruct *method = param; +// DeleteElement方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"deleteElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +let arr = [10, 'hello', null, true]; +deleteElement(arr, 0); +)JS"; +// [End oh_jsvm_delete_element] + +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 = "deleteelement", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/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/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e8875dabd02d5877d484a65aa864f1e8c64eafbf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/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": "libdeleteelement.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/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/deleteelementability/DeleteelementAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/deleteelementability/DeleteelementAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/deleteelementability/DeleteelementAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/deleteelementability/DeleteelementAbility.ets index 4e8791a9282d39c354bdf4dcc37f794c631d35e2..e313dd21ca2d4c9faa4c7916d68514edd23f910f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/deleteelementability/DeleteelementAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/deleteelementability/DeleteelementAbility.ets @@ -1,56 +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 DeleteelementAbility 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'); - } -}; +/* + * 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 DeleteelementAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c371ac6ee66b9c5062f9851b82d84555bb5107c3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/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 'libdeleteelement.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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%') + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..163d1935ef8463aec41f7914e2bf8635ea1c1544 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "deleteelement", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "DeleteelementAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "DeleteelementAbility", + "srcEntry": "./ets/deleteelementability/DeleteelementAbility.ets", + "description": "$string:DeleteelementAbility_desc", + "icon": "$media:layered_image", + "label": "$string:DeleteelementAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/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/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4c5c74c7ace4333c47508db5b5a8b29081a72a69 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "DeleteelementAbility_desc", + "value": "description" + }, + { + "name": "DeleteelementAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb6563dcb69fdf90b9c490b6da252fc725a9e15a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/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('testDeleteElement', 0, async (done: Function) => { + console.log('uitest: TestDeleteElement begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'DeleteelementAbility' + } + 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('DeleteelementAbility'); + + 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: TestDeleteElement end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cb29a6bf4e036ec4b0cd8e1751d85ec0593f27ea --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/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": "deleteelement_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIArray/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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/JsvmUsageGuide/JsvmAboutArray/getarraylength/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f2e5e8ee3ba4cc253a0b329dc57aabcb85ca0063 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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": "getarraylength", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetarraylength.so": "file:./src/main/cpp/types/libgetarraylength" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..78e4ce4f5d7f8f30c42ee535de424cc6c693eb91 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(getarraylength SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getarraylength PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c703610d0a6a03eb6531191e3b43928c91a38af --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/hello.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_array_length] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_array_length] +#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) +// [EndExclude oh_jsvm_get_array_length] + +// OH_JSVM_GetArrayLength的样例方法 +static JSVM_Value GetArrayLength(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + JSVM_Value result = nullptr; + uint32_t length; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 检查参数是否为数组 + bool isArray = false; + OH_JSVM_IsArray(env, args[0], &isArray); + if (!isArray) { + OH_LOG_INFO(LOG_APP, "JSVM Argument must be an array"); + return nullptr; + } + OH_JSVM_GetArrayLength(env, args[0], &length); + // 创建返回值 + OH_JSVM_CreateInt32(env, length, &result); + OH_LOG_INFO(LOG_APP, "JSVM length: %{public}d", length); + return result; +} +// GetArrayLength注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetArrayLength}, +}; +static JSVM_CallbackStruct *method = param; +// GetArrayLength方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getArrayLength", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +let data = [0, 1, 2, 3, 4, 5]; +getArrayLength(data); +)JS"; +// [End oh_jsvm_get_array_length] + +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 = "getarraylength", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..671224c598d18ed69736bf42c1e165f37e7d2f60 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/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": "libgetarraylength.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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/getarraylengthability/GetarraylengthAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/getarraylengthability/GetarraylengthAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/getarraylengthability/GetarraylengthAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/getarraylengthability/GetarraylengthAbility.ets index 9d7f472795ef0878ab9bf87e6cb06fef41b22763..bc99f07f17f9358f39a2c25e45fd54b59e7e883f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/getarraylengthability/GetarraylengthAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/getarraylengthability/GetarraylengthAbility.ets @@ -1,56 +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 GetarraylengthAbility 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'); - } -}; +/* + * 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 GetarraylengthAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a6819482982f430379714e5b0ecd2ce2a7d26b46 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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 'libgetarraylength.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f07b6deaa2dc5754cc072d49714ce2d241267552 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getarraylength", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetarraylengthAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetarraylengthAbility", + "srcEntry": "./ets/getarraylengthability/GetarraylengthAbility.ets", + "description": "$string:GetarraylengthAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetarraylengthAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..75b181bc89c28a638d006d3e6d2b5cd3aa8dad00 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetarraylengthAbility_desc", + "value": "description" + }, + { + "name": "GetarraylengthAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..510d3dc814f1964145dfb0ea34cc464bf5eda8d6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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('testGetArrayLength', 0, async (done: Function) => { + console.log('uitest: TestGetArrayLength begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetarraylengthAbility' + } + 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('GetarraylengthAbility'); + + 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: TestGetArrayLength end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..14ad84f0a98ce74ba773607e08faa67951b835d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/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": "getarraylength_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d23005f4923ec5bd7dd37247ef04346dddc3f50e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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": "getdataviewinfo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetdataviewinfo.so": "file:./src/main/cpp/types/libgetdataviewinfo" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ede5023178e3e3610ce81d849183c5e086a36ec6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getdataviewinfo SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getdataviewinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55257eb6547f94ad2537f2134927f9837f85fc55 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/hello.cpp @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_dataview_info] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_dataview_info] +#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) +// [EndExclude oh_jsvm_get_dataview_info] + +// OH_JSVM_GetDataviewInfo的样例方法 +static JSVM_Value GetDataViewInfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取并解析参数,第一个参数为需要获得的信息的DataView类型数据,第二个参数为需要获得的信息类型的枚举值 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 将第二个参数转为int32类型的数字 + int32_t infoType; + OH_JSVM_GetValueInt32(env, args[1], &infoType); + size_t byteLength; + void *data; + JSVM_Value arrayBuffer = nullptr; + size_t byteOffset; + // 定义枚举类型与ArkTS侧枚举类型infoType顺序含义一致 + enum InfoTypeEnum { BYTE_LENGTHE, ARRAY_BUFFERE, BYTE_OFFSET }; + // 获取dataview信息 + JSVM_Status status = OH_JSVM_GetDataviewInfo(env, args[0], &byteLength, &data, &arrayBuffer, &byteOffset); + JSVM_Value result = nullptr; + switch (infoType) { + case BYTE_LENGTHE: + // 返回查询DataView的长度 + JSVM_Value len; + OH_JSVM_CreateInt32(env, byteLength, &len); + result = len; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetDataViewInfo fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetDataViewInfo success, byteLength: %{public}d", byteLength); + } + break; + case ARRAY_BUFFERE: + // 判断DataView的Info里的arraybuffer是否为arraybuffer + bool isArrayBuffer; + OH_JSVM_IsArraybuffer(env, arrayBuffer, &isArrayBuffer); + JSVM_Value isArray; + OH_JSVM_GetBoolean(env, isArrayBuffer, &isArray); + result = isArray; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetDataViewInfo fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetDataViewInfo success, isArrayBuffer: %{public}d", isArrayBuffer); + } + break; + case BYTE_OFFSET: + // 返回查询DataView的偏移量 + JSVM_Value offset; + OH_JSVM_CreateInt32(env, byteOffset, &offset); + result = offset; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetDataViewInfo fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetDataViewInfo success, byteOffset: %{public}d", byteOffset); + } + break; + default: + break; + } + return result; +} +// GetDataViewInfo注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetDataViewInfo}, +}; +static JSVM_CallbackStruct *method = param; +// GetDataViewInfo方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getDataViewInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +// bytelength +getDataViewInfo(new DataView(new Int8Array([2, 5]).buffer), 0); +// is arraybuffer +let data = 'a'; +let isarraybuffer = 1; +getDataViewInfo(data, isarraybuffer); +// is arraybuffer +data = new DataView(new Int8Array([2, 5, 3]).buffer); +isarraybuffer = 1; +getDataViewInfo(data, isarraybuffer); +// byte_offset +data = new DataView(new Int8Array([2, 5, 3]).buffer); +isarraybuffer = 2; +getDataViewInfo(data, isarraybuffer); +)JS"; +// [End oh_jsvm_get_dataview_info] + +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 = "getdataviewinfo", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c878cd453d527f7c8e1f15791b756546d0172ef8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/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": "libgetdataviewinfo.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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/getdataviewinfoability/GetdataviewinfoAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/getdataviewinfoability/GetdataviewinfoAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/getdataviewinfoability/GetdataviewinfoAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/getdataviewinfoability/GetdataviewinfoAbility.ets index 3ac062e2cac503163bc784f3122c2b1c500ed528..58476b71f029fd7faa451a57f7f6d4f122520cd7 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/getdataviewinfoability/GetdataviewinfoAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/getdataviewinfoability/GetdataviewinfoAbility.ets @@ -1,56 +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 GetdataviewinfoAbility 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'); - } -}; +/* + * 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 GetdataviewinfoAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..86ffd8964ee22a6630f6349ceecea35242cf5a82 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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 'libgetdataviewinfo.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9b95016bac911cc89f2999c9cd864225a4b586d7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getdataviewinfo", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetdataviewinfoAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetdataviewinfoAbility", + "srcEntry": "./ets/getdataviewinfoability/GetdataviewinfoAbility.ets", + "description": "$string:GetdataviewinfoAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetdataviewinfoAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6439e36e102b3d13c771dbf5fa3f98155efa064a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetdataviewinfoAbility_desc", + "value": "description" + }, + { + "name": "GetdataviewinfoAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..adbf66523ca9120613a3c5bf5d0a24c86e605088 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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('testGetDataviewInfo', 0, async (done: Function) => { + console.log('uitest: TestGetDataviewInfo begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetdataviewinfoAbility' + } + 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('GetdataviewinfoAbility'); + + 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: TestGetDataviewInfo end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..714dbba2aee84bf9bc1b1c9413e21f128ea901ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/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": "getdataviewinfo_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/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/JsvmUsageGuide/JsvmAboutArray/getelement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..694ee70e9d045004a3e13e520e84aad2a22be518 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/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": "getelement", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetelement.so": "file:./src/main/cpp/types/libgetelement" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dea780a7ac4ffe7f2ba4814b4380ad680e773901 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getelement SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getelement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e75b7e408e08db72144b9ca993d0ae0fb1ac817 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/hello.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_element] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_element] +#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) +// [EndExclude oh_jsvm_get_element] + +// OH_JSVM_GetElement的样例方法 +static JSVM_Value GetElement(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取请求元素的索引值 + uint32_t index; + OH_JSVM_GetValueUint32(env, args[1], &index); + // 获取请求索引位置的元素值并存储在result中 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetElement(env, args[0], index, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetElement fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetElement success"); + } + return result; +} +// GetElement注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetElement}, +}; +static JSVM_CallbackStruct *method = param; +// GetElement方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +let arr = [10, 'hello', null, true]; +getElement(arr, 3); +)JS"; +// [End oh_jsvm_get_element] + +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 = "getelement", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c617e658fbe33255dc8123af921c07be80f19a46 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/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": "libgetelement.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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/getelementability/GetelementAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/getelementability/GetelementAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/getelementability/GetelementAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/getelementability/GetelementAbility.ets index 217add160364eacba9a51d7963d2656ff2da503d..01f96a258a9043681da8f3329690471b58002ca0 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/getelementability/GetelementAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/getelementability/GetelementAbility.ets @@ -1,56 +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 GetelementAbility 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'); - } -}; +/* + * 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 GetelementAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd716c1b4c3ffb950a6b5710a834767e766c3b20 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/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 'libgetelement.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8b4f09b2083801f8ad16fbc3ee050042a6a07a32 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "getelement", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetelementAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetelementAbility", + "srcEntry": "./ets/getelementability/GetelementAbility.ets", + "description": "$string:GetelementAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetelementAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5652fa10a13d7d0e1a7465511c9fa5769966950a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetelementAbility_desc", + "value": "description" + }, + { + "name": "GetelementAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5ce5cae884e0c8ef6a39128b7b3d8ee8d6cefbd4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/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('testGetElement', 0, async (done: Function) => { + console.log('uitest: TestGetElement begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetelementAbility' + } + 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('GetelementAbility'); + + 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: TestGetElement end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/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/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10c17dc86430c0ec714a39b4dbbcb37c2242f411 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "getelement_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a7ec9c7d0a0bb4d596ee2bcec1f0fe9377806d14 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/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": "gettypedarrayinfo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgettypedarrayinfo.so": "file:./src/main/cpp/types/libgettypedarrayinfo" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..30a71205c4276e1743f58c44ae582658eb12438b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(gettypedarrayinfo SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(gettypedarrayinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ffe81877197e2795c4fb02a736f77464ca58eacc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/hello.cpp @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_typedarray_info] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_typedarray_info] +#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) +// [EndExclude oh_jsvm_get_typedarray_info] + +// OH_JSVM_GetTypedarrayInfo的样例方法 +static JSVM_Value GetTypedArrayInfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取并解析参数,第一个参数为需要获得的信息的TypedArray类型数据,第二个参数为需要获得的信息类型的枚举值 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + + // 将第二个参数转为int32类型便于比较 + int32_t infoTypeParam; + OH_JSVM_GetValueInt32(env, args[1], &infoTypeParam); + // 定义枚举类型与ArkTS侧枚举类型infoType顺序含义一致 + enum InfoType { INFO_TYPE, INFO_LENGTH, INFO_ARRAY_BUFFER, INFO_BYTE_OFFSET }; + void *data; + JSVM_TypedarrayType type; + size_t byteOffset; + size_t length; + JSVM_Value arrayBuffer = nullptr; + // 调用接口OH_JSVM_GetTypedarrayInfo获得TypedArray类型数据的信息 + JSVM_Status status = OH_JSVM_GetTypedarrayInfo(env, args[0], &type, &length, &data, &arrayBuffer, &byteOffset); + JSVM_Value result = nullptr; + // 根据属性名,返回TypedArray对应的属性值 + switch (infoTypeParam) { + case INFO_TYPE: + // 如果传入的参数是int8类型的TypedArray数据,它的类型(type)为JSVM_INT8_ARRAY + JSVM_Value int8_type; + OH_JSVM_GetBoolean(env, type == JSVM_INT8_ARRAY, &int8_type); + result = int8_type; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); + } else { + OH_LOG_INFO( + LOG_APP, "JSVM GetTypedArrayInfo success, JSVM_INT8_ARRAY: %{public}d", type == JSVM_INT8_ARRAY); + } + break; + case INFO_LENGTH: + // TypedArray中的元素数 + JSVM_Value jsvmLength; + OH_JSVM_CreateInt32(env, length, &jsvmLength); + result = jsvmLength; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetTypedArrayInfo success, length: %{public}d", length); + } + break; + case INFO_BYTE_OFFSET: + // TypedArray数组的第一个元素所在的基础原生数组中的字节偏移量 + JSVM_Value jsvmOffset; + OH_JSVM_CreateInt32(env, byteOffset, &jsvmOffset); + result = jsvmOffset; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetTypedArrayInfo success, byteOffset: %{public}d", byteOffset); + } + break; + case INFO_ARRAY_BUFFER: + // TypedArray下的ArrayBuffer + bool isArrayBuffer; + OH_JSVM_IsArraybuffer(env, arrayBuffer, &isArrayBuffer); + JSVM_Value isArray; + OH_JSVM_GetBoolean(env, isArrayBuffer, &isArray); + result = isArray; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetTypedArrayInfo success, isArrayBuffer: %{public}d", isArrayBuffer); + } + break; + default: + break; + } + return result; +} +// GetTypedArrayInfo注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetTypedArrayInfo}, +}; +static JSVM_CallbackStruct *method = param; +// GetTypedArrayInfo方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getTypedArrayInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +// is JSVM_INT8_ARRAY +getTypedArrayInfo(new Int8Array(3), 0); +// length +getTypedArrayInfo(new Int8Array(5), 1); +// is_arraybuffer +getTypedArrayInfo(new Int8Array(5), 2); +// byteoffset +getTypedArrayInfo(new Int8Array(1), 3); +)JS"; +// [End oh_jsvm_get_typedarray_info] + +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 = "gettypedarrayinfo", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31378eaf067c060d81a1a28a7ad4f86901758b7e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/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": "libgettypedarrayinfo.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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets index a1f4288be64e9d58c71135e1363af56cedfb7025..f58741051a64bb68a3afff446010e9a5ade00de6 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets @@ -1,56 +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 GettypedarrayinfoAbility 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'); - } -}; +/* + * 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 GettypedarrayinfoAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..40315899072546e08670005700b3a7978544fadf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/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 'libgettypedarrayinfo.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0916244dcb0e828544f2753c04e1f49e39d2a7b3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "gettypedarrayinfo", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GettypedarrayinfoAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GettypedarrayinfoAbility", + "srcEntry": "./ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets", + "description": "$string:GettypedarrayinfoAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GettypedarrayinfoAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7a7172a8284bc4cfe9a419bc28ce86e0a151040d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GettypedarrayinfoAbility_desc", + "value": "description" + }, + { + "name": "GettypedarrayinfoAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d45009355932531a3797557bc34d84cb497707b4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/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('testGetTypedarrayInfo', 0, async (done: Function) => { + console.log('uitest: TestGetTypedarrayInfo begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GettypedarrayinfoAbility' + } + 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('GettypedarrayinfoAbility'); + + 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: TestGetTypedarrayInfo end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8c2115c22bbd9d6e18c58661612fe1c78802d82b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "gettypedarrayinfo_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/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/JsvmUsageGuide/JsvmAboutArray/haselement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..146d18ff7079fd58c5a86be7564543eb5356c861 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/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": "haselement", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libhaselement.so": "file:./src/main/cpp/types/libhaselement" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2090b5c9a0a3dac5c8630df57ab2b80b9abb5d35 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(haselement SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(haselement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb477ae473206386201605e95a3e48c44c978e92 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/hello.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_has_element] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_has_element] +#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) +// [EndExclude oh_jsvm_has_element] + +// OH_JSVM_HasElement的样例方法 +static JSVM_Value HasElement(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取要判断的元素的索引 + uint32_t index; + OH_JSVM_GetValueUint32(env, args[1], &index); + // 判断指定索引位置的元素是否存在 + bool hasElement = true; + JSVM_Status status = OH_JSVM_HasElement(env, args[0], index, &hasElement); + // 将boolean结果转换为JSVM_Value并返回 + JSVM_Value result = nullptr; + OH_JSVM_GetBoolean(env, hasElement, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM hasElement fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM hasElement: %{public}d", hasElement); + } + return result; +} +// HasElement注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = HasElement}, +}; +static JSVM_CallbackStruct *method = param; +// HasElement方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"hasElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *srcCallNative = R"JS( +let arr = [10, 'hello', null, true]; +hasElement(arr, 0); +hasElement(arr, 4); +)JS"; +// [End oh_jsvm_has_element] + +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, srcCallNative, 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 = "haselement", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f096725231cdb06d929c0bcc97a701ee6256a426 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/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": "libhaselement.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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/haselementability/HaselementAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/haselementability/HaselementAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/haselementability/HaselementAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/haselementability/HaselementAbility.ets index 07ad3bee1f10ab16d8be8eded337651fb5bde9ce..3a3d098ca79cc2b86cbf06e08de9c60f804838d3 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/haselementability/HaselementAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/haselementability/HaselementAbility.ets @@ -1,56 +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 HaselementAbility 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'); - } -}; +/* + * 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 HaselementAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0eddb902d3228fda65fc849e47e2b0658d87d67b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/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 'libhaselement.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c4df04c786d808b21afb3e62f8cd2f9f825916ef --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "haselement", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "HaselementAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "HaselementAbility", + "srcEntry": "./ets/haselementability/HaselementAbility.ets", + "description": "$string:HaselementAbility_desc", + "icon": "$media:layered_image", + "label": "$string:HaselementAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0f181f5fe6eeddadbc3b1723a8d8af09c02dbbb4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "HaselementAbility_desc", + "value": "description" + }, + { + "name": "HaselementAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9907a4623b0b88af42148e0423873eb48439a474 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/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('testHasElement', 0, async (done: Function) => { + console.log('uitest: TestHasElement begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'HaselementAbility' + } + 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('HaselementAbility'); + + 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: TestHasElement end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/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/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8c4f4995a88c645a73aa6d962052410fc41ff0b1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "haselement_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/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/JsvmUsageGuide/JsvmAboutPromise/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIClass/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/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/JsvmUsageGuide/JsvmAboutArray/isarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab38673af064673e8170babdf75fc4bc30d18add --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/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": "isarray", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libisarray.so": "file:./src/main/cpp/types/libisarray" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..deb9a0bd2494ea5a3e3695c5495c43f83fde6a52 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(isarray SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(isarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6572e09cf4de241e9bd0b808944fe31248fdbc6d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_is_array] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_is_array] +#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) +// [EndExclude oh_jsvm_is_array] + +// OH_JSVM_IsArray的样例方法 +static JSVM_Value IsArray(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + bool result = false; + JSVM_Status status = OH_JSVM_IsArray(env, args[0], &result); + JSVM_Value returnValue = nullptr; + OH_JSVM_GetBoolean(env, result, &returnValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM IsArray fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM IsArray success, IsArray: %{public}d", result); + } + return returnValue; +} +// IsArray注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsArray}, +}; +static JSVM_CallbackStruct *method = param; +// IsArray方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isArray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *srcCallNative = R"JS( +let data = [1, 2, 3, 4, 5]; +isArray(data); +)JS"; +// [End oh_jsvm_is_array] + +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, srcCallNative, 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 = "isarray", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5565a148eb7bcdc4ce91d120bf30667f35b1cb33 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/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": "libisarray.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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/isarrayability/IsarrayAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/isarrayability/IsarrayAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/isarrayability/IsarrayAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/isarrayability/IsarrayAbility.ets index 45c7e40a72449739578b862c764d1ce51b25ac9d..adb10e1e6632bc4677ea3463c8e83dfc2eef1119 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/isarrayability/IsarrayAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/isarrayability/IsarrayAbility.ets @@ -1,56 +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 IsarrayAbility 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'); - } -}; +/* + * 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 IsarrayAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5d5708e83b0cf87c48e21f23e025061cfeb4080 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/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 'libisarray.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..74147792b47299446b24f7afa84108500d8ceda1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "isarray", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IsarrayAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IsarrayAbility", + "srcEntry": "./ets/isarrayability/IsarrayAbility.ets", + "description": "$string:IsarrayAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IsarrayAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8eff575f5e411a2621640e678b1b8d7b9997c974 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IsarrayAbility_desc", + "value": "description" + }, + { + "name": "IsarrayAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d47f60af1d97f9499d9a23770bcbb5f5dfaf2866 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/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('testIsArray', 0, async (done: Function) => { + console.log('uitest: TestIsArray begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IsarrayAbility' + } + 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('IsarrayAbility'); + + 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: TestIsArray end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/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/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f91518e902aa843c67f0dcb6e14020107f95160f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "isarray_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/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/JsvmUsageGuide/JsvmAboutArray/isdataview/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8459e56f4a117495420eff5e70310922750c120f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/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": "isdataview", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libisdataview.so": "file:./src/main/cpp/types/libisdataview" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ffaa819a24146f6e47a3c48a4819d53fa6ec9e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(isdataview SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(isdataview PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aaeab782df7cd19fa41f6bb0ed464859ad038c2c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/hello.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_is_dataview] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_is_dataview] +#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) +// [EndExclude oh_jsvm_is_dataview] + +// OH_JSVM_IsDataview的样例方法 +static JSVM_Value IsDataView(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 调用OH_JSVM_IsDataview接口判断给定入参是否为DataView数据。 + bool result = false; + JSVM_Status status = OH_JSVM_IsDataview(env, args[0], &result); + JSVM_Value isDateView = nullptr; + OH_JSVM_GetBoolean(env, result, &isDateView); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM IsDataView fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM IsDataView: %{public}d", result); + } + return isDateView; +} +// IsDataView注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsDataView}, +}; +static JSVM_CallbackStruct *method = param; +// IsDataView方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isDataView", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *srcCallNative = R"JS( +let buffer = new ArrayBuffer(16); +let dataView = new DataView(buffer); +isDataView(dataView); +)JS"; +// [End oh_jsvm_is_dataview] + +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, srcCallNative, 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 = "isdataview", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..22941059791f75b5914ed7c6c81cb2e43a0b7703 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/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": "libisdataview.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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/isdataviewability/IsdataviewAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/isdataviewability/IsdataviewAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/isdataviewability/IsdataviewAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/isdataviewability/IsdataviewAbility.ets index cb0b5d78dc2421036ae0e87050ead25ddba215f3..460ad01950eb67637051cc9d942e4974b843434a --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/isdataviewability/IsdataviewAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/isdataviewability/IsdataviewAbility.ets @@ -1,56 +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 IsdataviewAbility 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'); - } -}; +/* + * 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 IsdataviewAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1f2d7cee549d730be6b3000f1e5c55f603a4f8e4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/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 'libisdataview.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bad4d685353ba412d38899c0653bb31abd2dc375 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "isdataview", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IsdataviewAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IsdataviewAbility", + "srcEntry": "./ets/isdataviewability/IsdataviewAbility.ets", + "description": "$string:IsdataviewAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IsdataviewAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..df24b674f0d4bc4bfff7105092f8cdb1d68e4e8f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IsdataviewAbility_desc", + "value": "description" + }, + { + "name": "IsdataviewAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ee817cc5d0f42c134b7183ab56cb3c62895fc02a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/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('testIsDataview', 0, async (done: Function) => { + console.log('uitest: TestIsDataview begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IsdataviewAbility' + } + 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('IsdataviewAbility'); + + 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: TestIsDataview end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4bbbdf0034cca4db08f5308f9226346a2c31d7e7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "isdataview_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIDate/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/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/JsvmUsageGuide/JsvmAboutArray/istypedarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..107934447f3455488c22307c2b344e4bacc154c5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/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": "istypedarray", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libistypedarray.so": "file:./src/main/cpp/types/libistypedarray" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f13755fac9b39122337f71f3b9e9ab108969db3f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(istypedarray SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(istypedarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54e342f3f676640638f17ea51c6648cb4d9ec2cd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/hello.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_is_typedarray] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_is_typedarray] +#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) +// [EndExclude oh_jsvm_is_typedarray] + +// OH_JSVM_IsTypedarray的样例方法 +static JSVM_Value IsTypedarray(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + bool result = false; + JSVM_Status status = OH_JSVM_IsTypedarray(env, args[0], &result); + JSVM_Value isTypedArray = nullptr; + OH_JSVM_GetBoolean(env, result, &isTypedArray); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM IsTypedarray fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM IsTypedarray: %{public}d", result); + } + return isTypedArray; +} +// IsTypedarray注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsTypedarray}, +}; +static JSVM_CallbackStruct *method = param; +// IsTypedarray方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isTypedarray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *srcCallNative = R"JS( +isTypedarray(new Uint16Array([1, 2, 3, 4])); +)JS"; +// [End oh_jsvm_is_typedarray] + +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, srcCallNative, 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 = "istypedarray", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..435fcd9766e8d6c992a137ae95aa623691a8ef70 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/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": "libistypedarray.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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/istypedarrayability/IstypedarrayAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/istypedarrayability/IstypedarrayAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/istypedarrayability/IstypedarrayAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/istypedarrayability/IstypedarrayAbility.ets index fd64cb185adcdd43f5924e419f5de709239cc605..586d03f9607ab22bb262f1886331771b1b2f76de --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/istypedarrayability/IstypedarrayAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/istypedarrayability/IstypedarrayAbility.ets @@ -1,56 +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 IstypedarrayAbility 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'); - } -}; +/* + * 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 IstypedarrayAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d3f74513ab35bf976041d9b979469e7c57ec8db --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/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 'libistypedarray.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..875e3d13a10e243635b8a8b2579295bcd25806f4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "istypedarray", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IstypedarrayAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IstypedarrayAbility", + "srcEntry": "./ets/istypedarrayability/IstypedarrayAbility.ets", + "description": "$string:IstypedarrayAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IstypedarrayAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..01682acd0d217ba94ef609c41e3cbfcd76cfcdb0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IstypedarrayAbility_desc", + "value": "description" + }, + { + "name": "IstypedarrayAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fee65d72c48461b14d9e0919587be329749940e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/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('testIsTypedarray', 0, async (done: Function) => { + console.log('uitest: TestIsTypedarray begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IstypedarrayAbility' + } + 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('IstypedarrayAbility'); + + 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: TestIsTypedarray end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eb1d73b6885f663a53ce8b8b8b46fd03ecdc4862 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "istypedarray_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/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/JsvmUsageGuide/JsvmAboutArray/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2d5caf585dd75ef6f81b5f92cad3a6ef074940cb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/ohosTest.md @@ -0,0 +1,21 @@ +# JsvmAboutArray 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 创建一个新的 JavaScript 数组对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建一个指定长度的 JavaScript 数组对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 在现有的 ArrayBuffer 上创建一个 JavaScript DataView 对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 在现有的 ArrayBuffer 上创建一个 JavaScript TypedArray 对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 尝试删除给定对象的指定索引处的元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 返回 Array 对象的长度 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取 Dataview 对象的信息 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定对象指定索引处的元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取 TypedArray(类型化数组)对象的信息 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 若给定对象的指定索引处拥有属性,获取该元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断一个 JavaScript 对象是否为 Array 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断一个 JavaScript 对象是否为 Dataview 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断一个 JavaScript 对象是否为 Typedarray 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 在给定对象的指定索引处设置元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/screenshots/JsvmAboutArray_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/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/JsvmUsageGuide/JsvmAboutArray/setelement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0cef4be6a39c859633e6e9fb86d65dedd0b15062 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/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": "setelement", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libsetelement.so": "file:./src/main/cpp/types/libsetelement" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..98f3e8a2dd8f4ed35db24c2f943a070b88746487 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(setelement SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(setelement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..018496ac65c2f4e9712bffc0b9be83c31faad7f6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/hello.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_set_element] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_set_element] +#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) +// [EndExclude oh_jsvm_set_element] + +// OH_JSVM_SetElement的样例方法 +static int g_diffValueThree = 3; +static JSVM_Value SetElement(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = g_diffValueThree; + JSVM_Value args[3] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + int32_t index = 0; + OH_JSVM_GetValueInt32(env, args[1], &index); + JSVM_Status status = OH_JSVM_SetElement(env, args[0], index, args[2]); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM SetElement fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM SetElement success"); + } + return args[0]; +} +// SetElement注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = SetElement}, +}; +static JSVM_CallbackStruct *method = param; +// SetElement方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"setElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +setElement(3); +)JS"; +// [End oh_jsvm_set_element] + +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 = "setelement", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2d7971a31d17f8fa9d80ec4b4e7271440b4e1d6c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/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": "libsetelement.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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..34ff1332d8688956ad3e94bb64eb039e10494d83 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/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 'libsetelement.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/setelementability/SetelementAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/setelementability/SetelementAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/setelementability/SetelementAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/setelementability/SetelementAbility.ets index a8a457f34d676b45256f33398cfc5197a08757bc..53e8ce06e1f98ee1bb9723ace968e68e0d108e2f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/setelementability/SetelementAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/setelementability/SetelementAbility.ets @@ -1,56 +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 SetelementAbility 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'); - } -}; +/* + * 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 SetelementAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a23090f1df7ff2e203287ed69684066a24e53378 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "setelement", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "SetelementAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "SetelementAbility", + "srcEntry": "./ets/setelementability/SetelementAbility.ets", + "description": "$string:SetelementAbility_desc", + "icon": "$media:layered_image", + "label": "$string:SetelementAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7a34b15ba771be4f8f1ebda67de443575ffbe559 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "SetelementAbility_desc", + "value": "description" + }, + { + "name": "SetelementAbility_label", + "value": "JsvmAboutArray" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..83482007cec3dfca312fcec41f3ceddd68328034 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/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('testSetElement', 0, async (done: Function) => { + console.log('uitest: TestSetElement begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'SetelementAbility' + } + 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('SetelementAbility'); + + 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: TestSetElement end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/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/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ff765a5fcb3b16b2d0946bf4e67098fe14a4cbbd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "setelement_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dd76d3797807a5142e608864f78170b3e8279a7f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/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.jsvmaboutarraybuffer", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..be2a53f0f30e1a958840aa56368e753625a225c4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutArraybuffer" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6b9d389b076c5be4c61b6724018fd12abfb31f9a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/README.md @@ -0,0 +1,133 @@ +# ArkTS使用JSVM-API接口进行ArrayBuffer相关开发 + +### 介绍 + +ArrayBuffer 是 JavaScript 中的一种数据类型,用于表示通用的、固定长度的原始二进制数据缓冲区。它提供了一种在 JavaScript 中有效地表示和操作原始二进制数据的方式。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行ArrayBuffer相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-arraybuffer.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createarraybuffer/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getarraybufferinfo/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +isarraybuffer/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +isdetachedarraybuffer/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutArraybuffer > .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/JsvmUsageGuide/JsvmAboutArraybuffer/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19692da56f711c566a0f02b65c3bc7bce6cc5738 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/build-profile.json5 @@ -0,0 +1,94 @@ +/* + * 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": "getarraybufferinfo", + "srcPath": "./getarraybufferinfo", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "isarraybuffer", + "srcPath": "./isarraybuffer", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "isdetachedarraybuffer", + "srcPath": "./isdetachedarraybuffer", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createarraybuffer", + "srcPath": "./createarraybuffer", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/code-linter.json5 diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIError/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c7ef987202fc8582b86bcd47a6364430ffd98965 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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": "createarraybuffer", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatearraybuffer.so": "file:./src/main/cpp/types/libcreatearraybuffer" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b6769decfe8713815d178a6812994c7fb2c27e4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsFive) + +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(createarraybuffer SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createarraybuffer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..12e9f4072b8e342cbc9041423e8fb157b7727975 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/hello.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_arraybuffer] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_create_arraybuffer] +#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) +// [EndExclude oh_jsvm_create_arraybuffer] + +// OH_JSVM_CreateArraybuffer的样例方法 +static JSVM_Value CreateArraybuffer(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + JSVM_Value result = nullptr; + // 解析传递的参数 + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + int32_t value; + size_t length; + OH_JSVM_GetValueInt32(env, argv[0], &value); + length = size_t(value); + void *data; + // 创建一个新的ArrayBuffer + JSVM_Status status = OH_JSVM_CreateArraybuffer(env, length, &data, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateArraybuffer: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateArraybuffer: success"); + OH_LOG_INFO(LOG_APP, "JSVM ArrayBuffer length: %{public}d", length); + } + // 返回创建好的ArrayBuffer + return result; +} +// CreateArraybuffer注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateArraybuffer}, +}; +static JSVM_CallbackStruct *method = param; +// CreateArraybuffer方法别名,供TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createArraybuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +createArraybuffer(8); +)JS"; +// [End oh_jsvm_create_arraybuffer] + +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 = "createarraybuffer", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ebcd307a4ab1d378da76653b36f60652d85056fd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/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": "libcreatearraybuffer.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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/createarraybufferability/CreatearraybufferAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/createarraybufferability/CreatearraybufferAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/createarraybufferability/CreatearraybufferAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/createarraybufferability/CreatearraybufferAbility.ets index 4fc9d4f58cdfa2e3dd90a05812f50a4841a1058b..e0536f2782f2f85dbd1792be08621674b04fae29 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/createarraybufferability/CreatearraybufferAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/createarraybufferability/CreatearraybufferAbility.ets @@ -1,56 +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 CreatearraybufferAbility 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'); - } -}; +/* + * 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 CreatearraybufferAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ddd7c89c0e72e03a1287b05f3d42a768f460e19 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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 'libcreatearraybuffer.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..15287f77110ad7b7f2ffd8433f70112f9070da3b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createarraybuffer", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatearraybufferAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatearraybufferAbility", + "srcEntry": "./ets/createarraybufferability/CreatearraybufferAbility.ets", + "description": "$string:CreatearraybufferAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatearraybufferAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6f0babdfaa8a16430d195e5356db65e23b390595 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatearraybufferAbility_desc", + "value": "description" + }, + { + "name": "CreatearraybufferAbility_label", + "value": "JsvmAboutArraybuffer" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3343ee782217f949aa569dfdda9d05c6b8416df --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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('testCreateArraybuffer', 0, async (done: Function) => { + console.log('uitest: TestCreateArraybuffer begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatearraybufferAbility' + } + 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('CreatearraybufferAbility'); + + 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: TestCreateArraybuffer end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..04231245952f78b5b6849ada6359e55f9385dbba --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/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": "createarraybuffer_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7525bbe93f9ecfe71129ddb2430ae1f66bc8c984 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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": "getarraybufferinfo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetarraybufferinfo.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d05b01552c3bceb4ef0d057bdaec9c8d48b8311b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsFive) + +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(getarraybufferinfo SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getarraybufferinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97834ceb65c12bb34defe62a376e17ae299d2e06 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/hello.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_arraybuffer_info] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_arraybuffer_info] +#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) +// [EndExclude oh_jsvm_get_arraybuffer_info] + +// OH_JSVM_GetArraybufferInfo的样例方法 +static JSVM_Value GetArraybufferInfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + // 解析传递的参数 + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 检查参数是否为ArrayBuffer + bool isArrayBuffer = false; + OH_JSVM_IsArraybuffer(env, args[0], &isArrayBuffer); + if (!isArrayBuffer) { + OH_LOG_ERROR(LOG_APP, "JSVM GetArraybufferInfo isArrayBuffer:false"); + } + void *data; + size_t byteLength; + // 获取ArrayBuffer的底层数据缓冲区和长度 + JSVM_Status status = OH_JSVM_GetArraybufferInfo(env, args[0], &data, &byteLength); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetArraybufferInfo: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetArraybufferInfo: success"); + } + return args[0]; +} +// GetArraybufferInfo注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetArraybufferInfo}, +}; +static JSVM_CallbackStruct *method = param; +// GetArraybufferInfo方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getArraybufferInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +getArraybufferInfo(new ArrayBuffer(10)); +)JS"; +// [End oh_jsvm_get_arraybuffer_info] + +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 = "getarraybufferinfo", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..36110c3808103016e9effaeb7439bca1a9243bce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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": "libgetarraybufferinfo.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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a654430123e7f95b50afc77f66bfcb5ab0b0265d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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 'libgetarraybufferinfo.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..15f1044e02ccef92222a02af7966d8ad5a93ba28 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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": "getarraybufferinfo", + "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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0878d320041f9ad39bbc03670d7c88cde4e68170 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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": "JsvmAboutArraybuffer" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..904159f6e6a6c448a338d13afdd5db2fc8a471e2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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('testGetArraybufferInfo', 0, async (done: Function) => { + console.log('uitest: TestGetArraybufferInfo 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: TestGetArraybufferInfo end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90eb73f5732e3725c2c869a2b3ace5ed956872cc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/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": "getarraybufferinfo_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..accae1ce0d3daf7972bb9aefc203bb5be14f9cdb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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": "isarraybuffer", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libisarraybuffer.so": "file:./src/main/cpp/types/libisarraybuffer" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..38a29ee6fcbd07ef289de040479fc95570057168 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsFive) + +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(isarraybuffer SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(isarraybuffer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..95abdfe935990df6d815edc4d43802914df937cc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_is_arraybuffer] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_is_arraybuffer] +#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) +// [EndExclude oh_jsvm_is_arraybuffer] + +// OH_JSVM_IsArraybuffer的样例方法 +static JSVM_Value IsArrayBuffer(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 调用OH_JSVM_IsArraybuffer接口判断给定入参是否为ArrayBuffer数据 + bool isArrayBuffer = false; + JSVM_Status status = OH_JSVM_IsArraybuffer(env, args[0], &isArrayBuffer); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM IsArrayBuffer: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM IsArrayBuffer: success"); + OH_LOG_INFO(LOG_APP, "JSVM IsArrayBuffer: %{public}d", isArrayBuffer); + } + JSVM_Value boolean = nullptr; + OH_JSVM_GetBoolean(env, isArrayBuffer, &boolean); + return boolean; +} +// IsArrayBuffer注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsArrayBuffer}, +}; +static JSVM_CallbackStruct *method = param; +// IsArrayBuffer方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isArrayBuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +isArrayBuffer(new ArrayBuffer(8)); +)JS"; +// [End oh_jsvm_is_arraybuffer] + +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 = "isarraybuffer", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0d0f89ea18ff6ee64f07aec91f938c033bec8fed --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/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": "libisarraybuffer.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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/isarraybufferability/IsarraybufferAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/isarraybufferability/IsarraybufferAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/isarraybufferability/IsarraybufferAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/isarraybufferability/IsarraybufferAbility.ets index db8d5c53f7d06b6ec02bbe9f481cbfcb1dd40d09..92e42cd7cdb59af4bb30a1962d61751c41d36698 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/isarraybufferability/IsarraybufferAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/isarraybufferability/IsarraybufferAbility.ets @@ -1,56 +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 IsarraybufferAbility 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'); - } -}; +/* + * 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 IsarraybufferAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..92986da4b555627e2f2ffa3db4ed06a05664d561 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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 'libisarraybuffer.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9f4a0a746ba8480722ec340c563e157d951e1e1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "isarraybuffer", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IsarraybufferAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IsarraybufferAbility", + "srcEntry": "./ets/isarraybufferability/IsarraybufferAbility.ets", + "description": "$string:IsarraybufferAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IsarraybufferAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..dd0e15f88bd7aa2cc9c13cae6ae0eb8bce8cc01c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IsarraybufferAbility_desc", + "value": "description" + }, + { + "name": "IsarraybufferAbility_label", + "value": "JsvmAboutArraybuffer" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a25784b7ea3e9e556b7584f91195e3c2ad075bc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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('testIsArraybuffer', 0, async (done: Function) => { + console.log('uitest: TestIsArraybuffer begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IsarraybufferAbility' + } + 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('IsarraybufferAbility'); + + 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: TestIsArraybuffer end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cfae646a7ddf4bc5387a3e78069eeb001dc06048 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/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": "isarraybuffer_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e08f1de466d01b1232f7a5b9afc0f4aad59ae74f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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": "isdetachedarraybuffer", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libisdetachedarraybuffer.so": "file:./src/main/cpp/types/libisdetachedarraybuffer" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d61b43a65ce7171c8cb448e8ce190161d9de8af0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsFive) + +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(isdetachedarraybuffer SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(isdetachedarraybuffer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9af5afe26df35921a2b056969dbe99b6b49f2321 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/hello.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_is_detached_arraybuffer] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_is_detached_arraybuffer] +#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) +// [EndExclude oh_jsvm_is_detached_arraybuffer] + +// OH_JSVM_DetachArraybuffer、OH_JSVM_IsDetachedArraybuffer的样例方法 +static JSVM_Value DetachArraybuffer(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value arraybuffer = args[0]; + JSVM_Status status = OH_JSVM_DetachArraybuffer(env, arraybuffer); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM DetachArraybuffer: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM DetachArraybuffer: success"); + } + return arraybuffer; +} +static JSVM_Value IsDetachedArraybuffer(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value arraybuffer = args[0]; + OH_JSVM_DetachArraybuffer(env, arraybuffer); + bool result = false; + JSVM_Status status = OH_JSVM_IsDetachedArraybuffer(env, arraybuffer, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM IsDetachedArraybuffer: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM IsDetachedArraybuffer: success"); + OH_LOG_INFO(LOG_APP, "JSVM IsArrayBuffer: %{public}d", result); + } + JSVM_Value isDetached = nullptr; + OH_JSVM_GetBoolean(env, result, &isDetached); + return isDetached; +} +// DetachArraybuffer、IsDetachedArraybuffer注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = DetachArraybuffer}, + {.data = nullptr, .callback = IsDetachedArraybuffer}, +}; +static JSVM_CallbackStruct *method = param; +// DetachArraybuffer、IsDetachedArraybuffer方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"detachArraybuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + {"isDetachedArraybuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( +let arrayBuffer = new ArrayBuffer(10); +detachArraybuffer(arrayBuffer); +isDetachedArraybuffer(arrayBuffer); +)JS"; +// [End oh_jsvm_is_detached_arraybuffer] + +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 = "isdetachedarraybuffer", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d43e7fc610f4238570c34ad582e3eb8f0b03c26 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/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": "libisdetachedarraybuffer.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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets index 636f1cadc06c6ff0bbc820f7595afbb3cbc1ad10..115ea549e99b92aeff3d07c08b2dce99e88feb94 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets @@ -1,56 +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 IsdetachedarraybufferAbility 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'); - } -}; +/* + * 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 IsdetachedarraybufferAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..d169c6584ae801bf5c6c236af6d73e4905cc76c8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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 'libisdetachedarraybuffer.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e8d00d61168ae6193c7bb285db1e6016c51cfd24 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "isdetachedarraybuffer", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IsdetachedarraybufferAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IsdetachedarraybufferAbility", + "srcEntry": "./ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets", + "description": "$string:IsdetachedarraybufferAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IsdetachedarraybufferAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..350c9cfa5c3ea940e624b4cbb171acbadd0e9978 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IsdetachedarraybufferAbility_desc", + "value": "description" + }, + { + "name": "IsdetachedarraybufferAbility_label", + "value": "JsvmAboutArraybuffer" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a80ca20263e3eb4764dba57b259142bd2c6448b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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('testIsDetachedArraybuffer', 0, async (done: Function) => { + console.log('uitest: TestIsDetachedArraybuffer begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IsdetachedarraybufferAbility' + } + 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('IsdetachedarraybufferAbility'); + + 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: TestIsDetachedArraybuffer end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7140dc89464009bc639587be2b12c38b7ff850d7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/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": "isdetachedarraybuffer_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/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/JsvmUsageGuide/JsvmAboutArraybuffer/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ff22838956b2b80c8bd4ac3fdbe11896a360b069 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/ohosTest.md @@ -0,0 +1,11 @@ +# JsvmAboutArraybuffer 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 创建一个指定大小的 ArrayBuffer 对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 检索 ArrayBuffer 的底层数据缓冲区及其长度 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断一个 JavaScript 对象是否为 ArrayBuffer 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 检查给定的 ArrayBuffer 是否已被分离(detached) | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/screenshots/JsvmAboutArraybuffer_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b2d9a927300e1b9654f0c831c3963d169f9b55f4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/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.jsvmaboutbigint", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e240af11babe1d1c2bd9bfec77bd42aa290249d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutBigint" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/README.md new file mode 100644 index 0000000000000000000000000000000000000000..76af84a747c278389f7b4e0025486bddf8f75b21 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/README.md @@ -0,0 +1,173 @@ +# ArkTS使用JSVM-API接口操作bigint类型值 + +### 介绍 + +BigInt是JavaScript中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过JSVM-API提供的接口,可以在JSVM模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口操作bigint类型值](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-bigint.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createbigintint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createbigintuint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createbigintwords/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluebigintint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluebigintuint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluebigintwords/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutBigint > .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/JsvmUsageGuide/JsvmAboutBigint/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2294a3e6114a624bf4e8405147634fbaee0c1f06 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/build-profile.json5 @@ -0,0 +1,118 @@ +/* + * 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": "getvaluebigintwords", + "srcPath": "./getvaluebigintwords", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createbigintwords", + "srcPath": "./createbigintwords", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createbigintuint64", + "srcPath": "./createbigintuint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvaluebigintuint64", + "srcPath": "./getvaluebigintuint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createbigintint64", + "srcPath": "./createbigintint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvaluebigintint64", + "srcPath": "./getvaluebigintint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/code-linter.json5 diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIObject/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..24310f1b2b1e768ea28d954eb7196ea9453db20b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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": "createbigintint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatebigintint64.so": "file:./src/main/cpp/types/libcreatebigintint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..66e21840c890e442f5ba2739a7f79d737ced670f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(createbigintint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createbigintint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..10a8ab8a937d6ee10b6fff4387245da9e3b9f5c7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/hello.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_bigint_int64] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_create_bigint_int64] +#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) +// [EndExclude oh_jsvm_create_bigint_int64] + +// 声明int64_t的变量value +static int64_t g_testValueDemo = -5555555555555555555; +// OH_JSVM_CreateBigintInt64的样例方法 +static JSVM_Value CreateBigintInt64(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value returnValue = nullptr; + JSVM_Status status = OH_JSVM_CreateBigintInt64(env, g_testValueDemo, &returnValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateBigintInt64 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateBigintInt64 success"); + } + return returnValue; +} +// CreateBigintInt64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateBigintInt64}, +}; +static JSVM_CallbackStruct *method = param; +// CreateBigintInt64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createBigintInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createBigintInt64())JS"; +// [End oh_jsvm_create_bigint_int64] + +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 = "createbigintint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1039157d9bc26f86d8435c75d5222b0fcf0b0259 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/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": "libcreatebigintint64.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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/createbigintint64ability/Createbigintint64Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/createbigintint64ability/Createbigintint64Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/createbigintint64ability/Createbigintint64Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/createbigintint64ability/Createbigintint64Ability.ets index 29246bb9bc43f16dda68f02fb7091bf9cd79fed0..54b0d127ef4a54661213636bac00954acdeffc36 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/createbigintint64ability/Createbigintint64Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/createbigintint64ability/Createbigintint64Ability.ets @@ -1,56 +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 Createbigintint64Ability 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'); - } -}; +/* + * 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 Createbigintint64Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6fbeb81a911c1039779a2040b44a815dc05bf485 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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 'libcreatebigintint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2e973d7deaa435b2887bd54f6a08f70238089de0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createbigintint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createbigintint64Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createbigintint64Ability", + "srcEntry": "./ets/createbigintint64ability/Createbigintint64Ability.ets", + "description": "$string:Createbigintint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createbigintint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3734dc3222ce6c96f24ae078f5862e6ad9d8f779 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createbigintint64Ability_desc", + "value": "description" + }, + { + "name": "Createbigintint64Ability_label", + "value": "JsvmAboutBigint" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a9a5af9fceb5a8d1a347a480e23848425f1b2da5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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('testCreateBigintInt64', 0, async (done: Function) => { + console.log('uitest: TestCreateBigintInt64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createbigintint64Ability' + } + 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('Createbigintint64Ability'); + + 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: TestCreateBigintInt64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d4b914b9dc2df6fd2d327786cc2958d2888d32e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/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": "createbigintint64_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..adc44991579386c3cb6b9ba5d63974e1c622d5b1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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": "createbigintuint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatebigintuint64.so": "file:./src/main/cpp/types/libcreatebigintuint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f920b2ca4548c04c8c3b3933e6293bb813199818 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsSix) + +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(createbigintuint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createbigintuint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7bb92d66bc337882f02ac088cb573576947b30c7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/hello.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_bigint_uint64] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_create_bigint_uint64] +#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) +// [EndExclude oh_jsvm_create_bigint_uint64] + +// 声明uint64_t的变量value +static uint64_t g_testValue = 5555555555555555555; +// OH_JSVM_CreateBigintUint64的样例方法 +static JSVM_Value CreateBigintUint64(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 将value转化为JSVM_Value类型返回 + JSVM_Value returnValue = nullptr; + JSVM_Status status = OH_JSVM_CreateBigintUint64(env, g_testValue, &returnValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateBigintUint64 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateBigintUint64 success"); + } + return returnValue; +} +// CreateBigintUint64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateBigintUint64}, +}; +static JSVM_CallbackStruct *method = param; +// CreateBigintUint64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createBigintUint64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(createBigintUint64())JS"; +// [End oh_jsvm_create_bigint_uint64] + +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 = "createbigintuint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..60767790c0819694f74ab3982847b01a7a644cf4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/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": "libcreatebigintuint64.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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/createbigintuint64ability/Createbigintuint64Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/createbigintuint64ability/Createbigintuint64Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/createbigintuint64ability/Createbigintuint64Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/createbigintuint64ability/Createbigintuint64Ability.ets index 97961561906f158d96002d07f2db15cc51d04cf5..2cd000ac840c04a5b9b1099fb2bab6e1e41faa9f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/createbigintuint64ability/Createbigintuint64Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/createbigintuint64ability/Createbigintuint64Ability.ets @@ -1,56 +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 Createbigintuint64Ability 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'); - } -}; +/* + * 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 Createbigintuint64Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..86c3436cf21be7ba9627b50755f212cbf87fe0f6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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 'libcreatebigintuint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5d90e5c19e5e9fb462ec2100a9efcac824513876 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createbigintuint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createbigintuint64Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createbigintuint64Ability", + "srcEntry": "./ets/createbigintuint64ability/Createbigintuint64Ability.ets", + "description": "$string:Createbigintuint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createbigintuint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..453a15bb9e1c0ac47a35e5b9cc9792b9fda7040f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createbigintuint64Ability_desc", + "value": "description" + }, + { + "name": "Createbigintuint64Ability_label", + "value": "JsvmAboutBigint" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..15db66924a5133dd09ceece4c0487f14a5c23aa4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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('testCreateBigintUint64', 0, async (done: Function) => { + console.log('uitest: TestCreateBigintUint64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createbigintuint64Ability' + } + 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('Createbigintuint64Ability'); + + 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: TestCreateBigintUint64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..22b19149cf0b50a73f58a5c3bee9d9a90524f9e1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/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": "createbigintuint64_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a2d75a437afb730ed06e4b121178be7adbbed147 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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": "createbigintwords", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatebigintwords.so": "file:./src/main/cpp/types/libcreatebigintwords" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cfcf91bc154ff9c87c63d56bd95c50c414f6d904 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsSix) + +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(createbigintwords SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createbigintwords PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4854cc07297c90d3ced5b0d285e962f36492b516 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_bigint_words] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_create_bigint_words] +#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) +// [EndExclude oh_jsvm_create_bigint_words] + +// OH_JSVM_CreateBigintWords的样例方法 +static int g_diffValueThree = 3; +static JSVM_Value CreateBigintWords(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 使用OH_JSVM_CreateBigintWords接口创建一个BigInt对象 + int signBit = 0; + size_t wordCount = g_diffValueThree; + uint64_t words[] = {12ULL, 34ULL, 56ULL}; + JSVM_Value returnValue = nullptr; + JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &returnValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateBigintWords fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateBigintWords success"); + } + return returnValue; +} +// CreateBigintWords注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateBigintWords}, +}; +static JSVM_CallbackStruct *method = param; +// CreateBigintWords方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createBigintWords", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createBigintWords())JS"; +// [EndExclude oh_jsvm_create_bigint_words] + +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 = "createbigintwords", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8139562209b9d493ce7760dd91ff70b132b79d2e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/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": "libcreatebigintwords.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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/createbigintwordsability/CreatebigintwordsAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/createbigintwordsability/CreatebigintwordsAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/createbigintwordsability/CreatebigintwordsAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/createbigintwordsability/CreatebigintwordsAbility.ets index 3e3a9544d9213bf9c23534ef458b2545b6a6b063..6882d87f8202345606860f555520945d969cad43 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/createbigintwordsability/CreatebigintwordsAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/createbigintwordsability/CreatebigintwordsAbility.ets @@ -1,56 +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 CreatebigintwordsAbility 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'); - } -}; +/* + * 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 CreatebigintwordsAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..eaa34dcf8d1ff63354a96ec0bfb600e4bcbee14e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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 'libcreatebigintwords.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70ae7e137f4991b1398d6bf583bfa0ea271726b7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createbigintwords", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatebigintwordsAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatebigintwordsAbility", + "srcEntry": "./ets/createbigintwordsability/CreatebigintwordsAbility.ets", + "description": "$string:CreatebigintwordsAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatebigintwordsAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..19ddee92e5a864360528dc3300b60855b3778482 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatebigintwordsAbility_desc", + "value": "description" + }, + { + "name": "CreatebigintwordsAbility_label", + "value": "JsvmAboutBigint" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6660d833f35a307b325f6e20d56fa639ccd2e961 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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('testCreateBigintWords', 0, async (done: Function) => { + console.log('uitest: TestCreateBigintWords begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatebigintwordsAbility' + } + 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('CreatebigintwordsAbility'); + + 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: TestCreateBigintWords end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ef673a26fea2be7143d4717d055f21edad06aefc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/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": "createbigintwords_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..61f2056b38af04d3f48cd813ee695f76c9efdc50 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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": "getvaluebigintint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluebigintint64.so": "file:./src/main/cpp/types/libgetvaluebigintint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b70a939a1f7b3df894ebdd2f2dd52eb089fd962 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getvaluebigintint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluebigintint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dba3632d4afcb3a937ac0890aad88f3ab874d5c3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_bigint_int64] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_value_bigint_int64] +#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) +// [EndExclude oh_jsvm_get_value_bigint_int64] + +// OH_JSVM_GetValueBigintInt64的样例方法 +static JSVM_Value GetBigintInt64(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 从传入的参数中提取64位整数的BigInt数据 + int64_t value; + bool lossLess; + OH_JSVM_GetValueBigintInt64(env, args[0], &value, &lossLess); + // 判断从JS侧获取bigint是否为无损转换,如果不是抛出异常 + if (!lossLess) { + OH_JSVM_ThrowError(env, nullptr, "BigInt values have no lossless converted"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetBigintInt64 success:%{public}d", lossLess); + } + JSVM_Value returnValue = nullptr; + OH_JSVM_CreateBigintInt64(env, value, &returnValue); + return returnValue; +} +// GetBigintInt64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetBigintInt64}, +}; +static JSVM_CallbackStruct *method = param; +// GetBigintInt64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getBigintInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getBigintInt64(BigInt(-5555555555555555)))JS"; +// [End oh_jsvm_get_value_bigint_int64] + +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 = "getvaluebigintint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..76d755dfeb0ccf12a2f54f4081650fd84f48ae59 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/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": "libgetvaluebigintint64.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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets index e8ea958a636e2c978ec514d91c51d0de57800253..b0db1a92dfd4c59075d48dad88c47822a90a33ac --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets @@ -1,56 +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 Getvaluebigintint64Ability 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'); - } -}; +/* + * 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 Getvaluebigintint64Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8cfef82a52050021990beb70acc21a4db51dc5f3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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 'libgetvaluebigintint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..16def6fbe4dc2203d4d185ad572f0000dcac7282 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvaluebigintint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Getvaluebigintint64Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvaluebigintint64Ability", + "srcEntry": "./ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets", + "description": "$string:Getvaluebigintint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvaluebigintint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b1099263f5385dcd226ca5c14b79b859eeb18f9d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvaluebigintint64Ability_desc", + "value": "description" + }, + { + "name": "Getvaluebigintint64Ability_label", + "value": "JsvmAboutBigint" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e520467a8011eef5f8f518b414dae83a4876d14 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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('testGetValueBigintInt64', 0, async (done: Function) => { + console.log('uitest: TestGetValueBigintInt64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvaluebigintint64Ability' + } + 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('Getvaluebigintint64Ability'); + + 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: TestGetValueBigintInt64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8fa9a60e6c948875a04fae9475f5752cdbc8049e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/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": "getvaluebigintint64_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e13b7234716a9d4bb027426386bf017d10ded607 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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": "getvaluebigintuint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluebigintuint64.so": "file:./src/main/cpp/types/libgetvaluebigintuint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1380e03dafa237bb4f214e27334f009dff5e9288 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getvaluebigintuint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluebigintuint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a264a73f72a24b005a0ae9dfb95ed9fba8e9d132 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_bigint_uint64] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_value_bigint_uint64] +#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) +// [EndExclude oh_jsvm_get_value_bigint_uint64] + +// OH_JSVM_GetValueBigintUint64的样例方法 +static JSVM_Value GetValueBigintUint64(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 从参数值中获取BigInt的数值 + uint64_t value = 0; + bool lossLess = false; + OH_JSVM_GetValueBigintUint64(env, args[0], &value, &lossLess); + // 判断从JS侧获取bigint是否为无损转换,如果不是抛出异常 + if (!lossLess) { + OH_JSVM_ThrowError(env, nullptr, "BigInt values have no lossless converted"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueBigintUint64 success:%{public}d", lossLess); + } + JSVM_Value returnValue = nullptr; + OH_JSVM_CreateBigintUint64(env, value, &returnValue); + return returnValue; +} +// GetValueBigintUint64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueBigintUint64}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueBigintUint64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueBigintUint64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getValueBigintUint64(BigInt(5555555555555555)))JS"; +// [End oh_jsvm_get_value_bigint_uint64] + +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 = "getvaluebigintuint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a4b69ee6d31ec3a1fad83dfd991c0bbdf7eb39b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/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": "libgetvaluebigintuint64.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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets index 935527790747cf9b368bc41c10bf7999f6434602..aa335815c85927f1ed5ff4d97abc9b7d50774c0a --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets @@ -1,56 +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 Getvaluebigintuint64Ability 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'); - } -}; +/* + * 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 Getvaluebigintuint64Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..990bc7b00cfc1d98d64bca13b373e8a3f5a0bba0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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 'libgetvaluebigintuint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e96cb223039ab1b07dcb2239751d1c789f90f663 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvaluebigintuint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Getvaluebigintuint64Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvaluebigintuint64Ability", + "srcEntry": "./ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets", + "description": "$string:Getvaluebigintuint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvaluebigintuint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fadfd15d2aa8cfad945f72d49f11a9312a5bbb1d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvaluebigintuint64Ability_desc", + "value": "description" + }, + { + "name": "Getvaluebigintuint64Ability_label", + "value": "JsvmAboutBigint" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a066752b3f60114454fedd9f7574b7763b331d5c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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('testGetValueBigintUint64', 0, async (done: Function) => { + console.log('uitest: TestGetValueBigintUint64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvaluebigintuint64Ability' + } + 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('Getvaluebigintuint64Ability'); + + 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: TestGetValueBigintUint64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e2f7820c6da73fbf5ac79923892c222066cc2935 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/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": "getvaluebigintuint64_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/NodeAPI/NodeApiUse/NodeApiString/entry/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..adcecf185db4c006b827b4a5c4c08e3ee9b89057 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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": "getvaluebigintwords", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluebigintwords.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f8d4d03e59d8e5654328b57acf2df3ee93d1fa9a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsSix) + +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(getvaluebigintwords SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluebigintwords PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..162e9835aff0be7a68d0a8256dd4458584f12de0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/hello.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_bigint_words] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +#include +// [StartExclude oh_jsvm_get_value_bigint_words] +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" +#define MAX_MALLOC_SIZE 0x800000 + +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) +// [EndExclude oh_jsvm_get_value_bigint_words] + +// OH_JSVM_GetValueBigintWords的样例方法 +static JSVM_Value GetValueBigintWords(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + int signBit = 0; + size_t wordCount = 0; + uint64_t* words{nullptr}; + // 调用OH_JSVM_GetValueBigintWords接口获取wordCount + JSVM_Status status = OH_JSVM_GetValueBigintWords(env, args[0], nullptr, &wordCount, nullptr); + OH_LOG_INFO(LOG_APP, "OH_JSVM_GetValueBigintWords wordCount:%{public}d.", wordCount); + if (wordCount == 0 || wordCount > SOME_REASONABLE_MAX) { + OH_LOG_ERROR(LOG_APP, "Invalid wordCount: %{public}zu", wordCount); + return nullptr; + } + words = (uint64_t*)malloc(wordCount*sizeof(uint64_t)); + if (words == nullptr) { + OH_LOG_ERROR(LOG_APP, "OH_JSVM_GetValueBigintWords malloc failed."); + return nullptr; + } + // 调用OH_JSVM_GetValueBigintWords接口获取传入bigInt相关信息,如:signBit传入bigInt正负信息 + status = OH_JSVM_GetValueBigintWords(env, args[0], &signBit, &wordCount, words); + free(words); + words = nullptr; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "OH_JSVM_GetValueBigintWords fail, status:%{public}d.", status); + } else { + OH_LOG_INFO(LOG_APP, "OH_JSVM_GetValueBigintWords signBit: %{public}d.", signBit); + } + // 将符号位转化为int类型传出去 + JSVM_Value returnValue = nullptr; + OH_JSVM_CreateInt32(env, signBit, &returnValue); + return returnValue; +} +// GetValueBigintWords注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueBigintWords}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueBigintWords方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueBigintWords", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getValueBigintWords(BigInt(5555555555555555)))JS"; +// [End oh_jsvm_get_value_bigint_words] + +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 = "getvaluebigintwords", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9049a01a9cb6083e5b5b7b845982931f9838ea83 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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": "libgetvaluebigintwords.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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..2a4f046ebf4965155fc7be527b181bec1ed2589d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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 'libgetvaluebigintwords.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8860dbc775e0fac14fda8b300e85caf57104d884 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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": "getvaluebigintwords", + "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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4954adb219c50aba12827b99827c9425f889cc36 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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": "JsvmAboutBigint" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6c136a7eeb25a3435da3db9e140eb1fa96f39d95 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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('testGetValueBigintWords', 0, async (done: Function) => { + console.log('uitest: TestGetValueBigintWords 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: TestGetValueBigintWords end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0cb4f1d1cd505b260cd10cf91037b5769dcaa034 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/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": "getvaluebigintwords_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/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/JsvmUsageGuide/JsvmAboutBigint/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..fc40b5f95e9033430d0a94b39c7048cff096b542 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/ohosTest.md @@ -0,0 +1,13 @@ +# JsvmAboutBigint 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 将C int64_t类型的值转换为JavaScript BigInt类型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 将C uint64_t类型的值转换为JavaScript BigInt类型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 将一组无符号64位字转换为单个BigInt值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 返回给定JavaScript BigInt的C int64_t基础类型等价值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 返回给定JavaScript BigInt的C uint64_t基础类型等价值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 将单个BigInt值转换为一个符号位、一个64位的小端数组和该数组的长度 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/screenshots/JsvmAboutBigint_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..40f0a262dabb04294260bc5faa395dc7d7801327 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/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.jsvmaboutclass", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ebd7615caef10da12ea2874af839b03f6c502cfd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutClass" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0a5473cf1e663cec4bd189ad704d4132af253a43 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/README.md @@ -0,0 +1,113 @@ +# ArkTS使用JSVM接口进行class相关开发 + +### 介绍 + +使用JSVM-API接口进行class相关开发,处理JavaScript中的类,例如定义类、构造实例等。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM进行class相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-class.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +|:------------------------------------------------------------------:|:------------------------------------------------------------------:| +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +defineclass/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +newinstance/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +removewrap/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutClass > .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/JsvmUsageGuide/JsvmAboutClass/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2b6d0c3ba4c2903ebccbe6dda4608169767d242b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/build-profile.json5 @@ -0,0 +1,82 @@ +/* + * 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": "newinstance", + "srcPath": "./newinstance", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "defineclass", + "srcPath": "./defineclass", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "removewrap", + "srcPath": "./removewrap", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/code-linter.json5 diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutClass/defineclass/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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/JsvmUsageGuide/JsvmAboutClass/defineclass/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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/JsvmUsageGuide/JsvmAboutClass/defineclass/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..64b19291d0d4531eae4520314c8a3f4a2194526e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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": "defineclass", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libdefineclass.so": "file:./src/main/cpp/types/libdefineclass" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..59145d6c51db7e0716905c6495a076b2085c3796 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutClass) + +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(defineclass SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(defineclass PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6bdc26d598360a481c3220a1ef2bd057459a9947 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/hello.cpp @@ -0,0 +1,207 @@ +/* + * 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" +// [Start oh_jsvm_defineclass] +#include +// [StartExclude oh_jsvm_defineclass] +#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) +// [EndExclude oh_jsvm_defineclass] + +JSVM_Value CreateInstance(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value newTarget; + // 获取构造函数的new.target值 + JSVM_CALL(OH_JSVM_GetNewTarget(env, info, &newTarget)); + OH_LOG_INFO(LOG_APP, "Create Instance"); + OH_LOG_INFO(LOG_APP, + "NAPI MyObject::New %{public}s", + newTarget != nullptr ? "newTarget != nullptr" : "newTarget == nullptr"); + JSVM_Value jsObject = nullptr; + JSVM_CALL(OH_JSVM_CreateObject(env, &jsObject)); + JSVM_Value jsName = nullptr; + JSVM_CALL(OH_JSVM_CreateStringUtf8(env, "name", JSVM_AUTO_LENGTH, &jsName)); + JSVM_Value jsValue = nullptr; + JSVM_CALL(OH_JSVM_CreateStringUtf8(env, "lilei", JSVM_AUTO_LENGTH, &jsValue)); + JSVM_CALL(OH_JSVM_SetProperty(env, jsObject, jsName, jsValue)); + return jsObject; +} + +std::string ToString(JSVM_Env env, JSVM_Value val) +{ + JSVM_Value jsonString; + JSVM_CALL(OH_JSVM_JsonStringify(env, val, &jsonString)); + size_t totalLen = 0; + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, nullptr, 0, &totalLen)); + size_t needLen = totalLen + 1; + char* buff = new char[needLen]; + std::memset(buff, 0, needLen); + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, buff, needLen, &totalLen)); + std::string str(buff); + delete[] buff; + return str; +} + +// 封装c++中的自定义数据结构 +JSVM_Value DefineClass(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_CallbackStruct param; + param.data = nullptr; + param.callback = CreateInstance; + JSVM_Value cons; + // 用于在JavaScript中定义一个类 + JSVM_CALL(OH_JSVM_DefineClass(env, "MyObject", JSVM_AUTO_LENGTH, ¶m, 0, nullptr, &cons)); + JSVM_Value instanceValue = nullptr; + // 作为class的构造函数调用 + JSVM_CALL(OH_JSVM_NewInstance(env, cons, 0, nullptr, &instanceValue)); + std::string str = ToString(env, instanceValue); + OH_LOG_INFO(LOG_APP, "NewInstance:%{public}s", str.c_str()); + + // 作为普通的函数调用 + JSVM_Value global; + JSVM_CALL(OH_JSVM_GetGlobal(env, &global)); + JSVM_Value key; + JSVM_CALL(OH_JSVM_CreateStringUtf8(env, "Constructor", JSVM_AUTO_LENGTH, &key)); + JSVM_CALL(OH_JSVM_SetProperty(env, global, key, cons)); + JSVM_Value result; + JSVM_CALL(OH_JSVM_CallFunction(env, global, cons, 0, nullptr, &result)); + std::string buf = ToString(env, result); + OH_LOG_INFO(LOG_APP, "NewInstance:%{public}s", buf.c_str()); + return nullptr; +} + +// 注册DefineClass的方法 +JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = DefineClass}, +}; + +static JSVM_CallbackStruct *method = param; + +// DefineClass方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"defineClass", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// [End oh_jsvm_defineclass] + +const char *SRC_CALL_NATIVE = R"JS( defineClass(); )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 = "defineclass", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d658bf92ef03e40b877c930ef079e72aa75ea19a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/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": "libdefineclass.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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/defineclassability/DefineclassAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/defineclassability/DefineclassAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/defineclassability/DefineclassAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/defineclassability/DefineclassAbility.ets index 8d53596cef3491d4f1c5c2f4be58fe146807777a..98602fa428d1bd9830b82c0f06c5942b43acc19b --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/defineclassability/DefineclassAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/defineclassability/DefineclassAbility.ets @@ -1,56 +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 DefineclassAbility 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'); - } -}; +/* + * 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 DefineclassAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f7a286b6ee5b59c4a86764aa1431b20c201bd620 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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 'libdefineclass.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98a4883aad4035e3812d8e10c2e15c0407936a4e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "defineclass", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "DefineclassAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "DefineclassAbility", + "srcEntry": "./ets/defineclassability/DefineclassAbility.ets", + "description": "$string:DefineclassAbility_desc", + "icon": "$media:layered_image", + "label": "$string:DefineclassAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2ca64655460a20cc39572d29383900c4aa5de568 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/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": "defineclass_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigorfile.ts diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutClass/newinstance/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8cdef9667a752ffebcd70dbcac5d4be537888f92 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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": "newinstance", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libnewinstance.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbd46b2a34e8ecb0f9e7663bae2497f0ec4aaca5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutClass) + +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(newinstance SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(newinstance PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f41d968610e2349d54cc063bf856657639c9420 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/hello.cpp @@ -0,0 +1,176 @@ +/* + * 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" +// [Start oh_jsvm_newinstance] +#include +// [StartExclude oh_jsvm_newinstance] +#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) +// [EndExclude oh_jsvm_newinstance] + +std::string ToString(JSVM_Env env, JSVM_Value val) +{ + JSVM_Value jsonString; + JSVM_CALL(OH_JSVM_JsonStringify(env, val, &jsonString)); + size_t totalLen = 0; + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, nullptr, 0, &totalLen)); + size_t needLen = totalLen + 1; + char* buff = new char[needLen]; + std::memset(buff, 0, needLen); + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, buff, needLen, &totalLen)); + std::string str(buff); + delete[] buff; + return str; +} + +// OH_JSVM_NewInstance的样例方法 +static JSVM_Value NewInstance(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); + JSVM_Value result = nullptr; + // 调用OH_JSVM_NewInstance接口,实例化一个对象,将这个对象返回 + JSVM_CALL(OH_JSVM_NewInstance(env, args[0], 1, &args[1], &result)); + std::string str = ToString(env, result); + OH_LOG_INFO(LOG_APP, "NewInstance:%{public}s", str.c_str()); + return nullptr; +} + +// 通过给定的构造函数,构建一个实例。 +// NewInstance注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = NewInstance}, +}; + +static JSVM_CallbackStruct *method = param; + +// NewInstance方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"newInstance", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// [End oh_jsvm_newinstance] + +const char *SRC_CALL_NATIVE = R"JS( function Fruit(name) { this.name = name; } newInstance(Fruit, "apple"); )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 = "newinstance", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..87c3109518b6cb2a890e93d937fbbe7efabfbb3d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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": "libnewinstance.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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..072eebfa6bba87ea372e1010d76a81828de797c3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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 'libnewinstance.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c62425b62debf462c73fc0f106028a9f08518429 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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": "newinstance", + "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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/layered_image.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/layered_image.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/main_pages.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/main_pages.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9ce5eb8c27891f052aaa5644c07b0fc613f80c21 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/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": "newinstance_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/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/JsvmUsageGuide/JsvmAboutClass/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..837470505b005591e1a46d1de3e94e427417736c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/ohosTest.md @@ -0,0 +1,10 @@ +# JsvmAboutClass 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|------------------------------------| ------------ |------------------------| ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 在JavaScript中定义一个类,并与对应的C类进行封装和交互 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 通过给定的构造函数,构建一个实例 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 解包先前封装在JavaScript对象中的原生实例并释放封装 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutClass/removewrap/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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/JsvmUsageGuide/JsvmAboutClass/removewrap/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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/JsvmUsageGuide/JsvmAboutClass/removewrap/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9c974bf11b567f6e91b07a613720549dbbae2e60 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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": "removewrap", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libremovewrap.so": "file:./src/main/cpp/types/libremovewrap" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a0d5309512c2f0e1f1792630f7bfca105a4aef00 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutClass) + +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(removewrap SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(removewrap PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f60452cc7804f827a67e6682c8886cb2d27638f3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/hello.cpp @@ -0,0 +1,209 @@ +/* + * 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" +// [Start oh_jsvm_removewrap] +#include +// [StartExclude oh_jsvm_removewrap] +#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) +// [EndExclude oh_jsvm_removewrap] + +// OH_JSVM_GetNewTarget、OH_JSVM_DefineClass、OH_JSVM_Wrap、OH_JSVM_Unwrap、OH_JSVM_RemoveWrap的样例方法 + +// 自定义类结构体Object +struct Object { + std::string name; + int32_t age; +}; + +// 定义一个回调函数 +static void DerefItem(JSVM_Env env, void *data, void *hint) +{ + OH_LOG_INFO(LOG_APP, "JSVM deref_item"); + (void)hint; +} + +static JSVM_Value WrapObject(JSVM_Env env, JSVM_CallbackInfo info) +{ + OH_LOG_INFO(LOG_APP, "JSVM wrap"); + Object obj; + // 设置Object属性 + obj.name = "lilei"; + const int adultAge = 18; + obj.age = adultAge; + Object *objPointer = &obj; + // 获取回调信息中的参数数量和将要被封装的值 + size_t argc = 1; + JSVM_Value toWrap = nullptr; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, &toWrap, nullptr, nullptr)); + // OH_JSVM_Wrap将自定义结构Object进行封装 + JSVM_CALL(OH_JSVM_Wrap(env, toWrap, reinterpret_cast(objPointer), DerefItem, NULL, NULL)); + Object *data; + // OH_JSVM_UnWrap解包先前封装在JavaScript对象中的原生实例 + JSVM_CALL(OH_JSVM_Unwrap(env, toWrap, reinterpret_cast(&data))); + OH_LOG_INFO(LOG_APP, "JSVM name: %{public}s", data->name.c_str()); + OH_LOG_INFO(LOG_APP, "JSVM age: %{public}d", data->age); + return nullptr; +} + +static JSVM_Value RemoveWrap(JSVM_Env env, JSVM_CallbackInfo info) +{ + OH_LOG_INFO(LOG_APP, "JSVM removeWrap"); + Object obj; + // 设置Object属性 + obj.name = "lilei"; + const int adultAge = 18; + obj.age = adultAge; + Object *objPointer = &obj; + // 获取回调信息中的参数数量和将要被封装的值 + size_t argc = 1; + JSVM_Value toWrap = nullptr; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, &toWrap, nullptr, nullptr)); + // 将自定义结构Object封装 + JSVM_CALL(OH_JSVM_Wrap(env, toWrap, reinterpret_cast(objPointer), DerefItem, NULL, NULL)); + Object *data; + // 解包先前封装的object,并移除封装 + JSVM_CALL(OH_JSVM_RemoveWrap(env, toWrap, reinterpret_cast(&objPointer))); + // 检查是否已被移除 + JSVM_Status status = OH_JSVM_Unwrap(env, toWrap, reinterpret_cast(&data)); + if (status != JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_RemoveWrap success"); + } + return nullptr; +} + +// WrapObject、RemoveWrap注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = WrapObject}, + {.data = nullptr, .callback = RemoveWrap}, +}; +static JSVM_CallbackStruct *method = param; +// WrapObject、RemoveWrap方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"wrapObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + {"removeWrap", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// [End oh_jsvm_removewrap] + +const char *SRC_CALL_NATIVE = R"JS( class Obj {}; wrapObject(new Obj()); removeWrap(new Obj()); )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 = "removewrap", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8d69688ce47d4ef098f0d47ca1bb8f6d1584e0d8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/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": "libremovewrap.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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..59959343b37fdb3aa2f1b5030668936a15084af8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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 'libremovewrap.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/removewrapability/RemovewrapAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/removewrapability/RemovewrapAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/removewrapability/RemovewrapAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/removewrapability/RemovewrapAbility.ets index e2615e64a58367a6f7ca7dbdf9ef55c88411a006..2baa653836d5fd3c52f98a4fdeb3f298199db803 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/removewrapability/RemovewrapAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/removewrapability/RemovewrapAbility.ets @@ -1,56 +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 RemovewrapAbility 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'); - } -}; +/* + * 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 RemovewrapAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dba5b8b160fc7b964f5890ae2f11524d78437ae1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "removewrap", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "RemovewrapAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "RemovewrapAbility", + "srcEntry": "./ets/removewrapability/RemovewrapAbility.ets", + "description": "$string:RemovewrapAbility_desc", + "icon": "$media:layered_image", + "label": "$string:RemovewrapAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..89b6b4602da68ca839178509bc7563aedba07b48 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/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": "removewrap_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/screenshots/JsvmAboutClass_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7dc0586640be430bbbb644dd4fc0557fd19f5154 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/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.jsvmaboutdate", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5afae2877f941aec936a287edf67c384033c2305 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutDate" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c738d7bf6adc7df49c63d9e58c19575ab15ac799 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/README.md @@ -0,0 +1,113 @@ +# ArkTS使用JSVM-API接口进行Date相关开发 + +### 介绍 + +JSVM-API中date相关接口用于处理JavaScript Date对象,并在JSVM模块和JavaScript代码之间进行日期数据的转换和处理。这对于在JSVM模块中处理时间和日期相关逻辑非常有用。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行Date相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-date.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :---------------------------------------------------------------: | :---------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createdate/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getdatevalue/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +isdate/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutDate > .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/JsvmUsageGuide/JsvmAboutDate/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6cbe1b8c78fdb479193a54e0384d86751692d178 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/build-profile.json5 @@ -0,0 +1,82 @@ +/* + * 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": "createdate", + "srcPath": "./createdate", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getdatevalue", + "srcPath": "./getdatevalue", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "isdate", + "srcPath": "./isdate", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/code-linter.json5 diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutDate/createdate/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..85cea6f4b8dec3ddc571321ca342aa074b65b9ea --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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": "createdate", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatedate.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..554f98f9c40d53adbbdf5818c4e871ae452dc02b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutDate) + +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(createdate SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createdate PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cea5b52e7cb2e883c422735b31357e528069d428 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/hello.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_date] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +#include +// [StartExclude oh_jsvm_create_date] +#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) +// [EndExclude oh_jsvm_create_date] + +// OH_JSVM_CreateDate的样例方法 +static JSVM_Value CreateDate(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 通过c接口获取Unix纪元以来经过的秒数,并转化为毫秒数为单位 + double value = static_cast(time(nullptr) * 1000); + // 调用OH_JSVM_CreateDate接口将double值转换成表示日期时间的JavaScript值返回出去 + JSVM_Value returnValue = nullptr; + + JSVM_CALL(OH_JSVM_CreateDate(env, value, &returnValue)); + + bool isDate; + JSVM_CALL(OH_JSVM_IsDate(env, returnValue, &isDate)); + if (isDate == false) { + OH_LOG_ERROR(LOG_APP, "JSVM IsDate fail"); + return returnValue; + } + + value = 0; + JSVM_CALL(OH_JSVM_GetDateValue(env, returnValue, &value)); + + uint64_t time = static_cast(value) / 1000; + char *date = ctime(reinterpret_cast(&time)); + OH_LOG_INFO(LOG_APP, "JSVM CreateDate success:%{public}s", date); + + return returnValue; +} + +// CreateDate注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateDate}, +}; +static JSVM_CallbackStruct *method = param; +// CreateDate方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createDate", nullptr, method, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(createDate())JS"; +// [End oh_jsvm_create_date] + +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 = "createdate", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..98100150ef16e9ab5a3ebb8644457b46a73a550c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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": "libcreatedate.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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..49fca32a24ba6b8a7f8887b6bd35f1a2bff2a38b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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 'libcreatedate.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..340f4e73eda4084c17e156de6beb8e1651038b4d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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": "createdate", + "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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..460a69fe459d08ab8e811cd7c83ba0a6cee66419 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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": "JsvmAboutDate" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..09099662a5ee92c957f944f4d0893af8388d88f2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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('testCreateDate', 0, async (done: Function) => { + console.log('uitest: TestCreateDate 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: TestCreateDate end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7e1ae01ec347c1fc6e665aa1d6e245243c2a5e7d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/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": "createdate_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d87886f1cc232ae34c7006bf710f65ac15cee8e6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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": "getdatevalue", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetdatevalue.so": "file:./src/main/cpp/types/libgetdatevalue" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..519bebf639f50b4928244fc5e381316f6d4795ac --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutDate) + +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(getdatevalue SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getdatevalue PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b45bc5a637191eecc2aaeb0503bf531361c49cce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * 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" +// [Stat oh_jsvm_get_date_value] +#include +// [StartExclude oh_jsvm_get_date_value] +#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) +// [EndExclude oh_jsvm_get_date_value] + +// OH_JSVM_GetDateValue的样例方法 +static JSVM_Value GetDateValue(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); + // 获取传入的Unix Time Stamp时间 + double value; + JSVM_CALL(OH_JSVM_GetDateValue(env, args[0], &value)); + + // 将获取到的Unix Time Stamp时间转化为日期字符串打印 + uint64_t time = static_cast(value) / 1000; + char *date = ctime(reinterpret_cast(&time)); + OH_LOG_INFO(LOG_APP, "JSVM GetDateValue success:%{public}s", date); + + JSVM_Value returnValue = nullptr; + JSVM_CALL(OH_JSVM_CreateDouble(env, value, &returnValue)); + return returnValue; +} + +// CreateDate注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetDateValue}, +}; +static JSVM_CallbackStruct *method = param; +// CreateDate方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getDateValue", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(getDateValue(new Date(Date.now())))JS"; +// [End oh_jsvm_get_date_value] + +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 = "getdatevalue", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a4f8967b575d5b2ef0409444fa0fadfd4a0444c2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/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": "libgetdatevalue.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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/getdatevalueability/GetdatevalueAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/getdatevalueability/GetdatevalueAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/getdatevalueability/GetdatevalueAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/getdatevalueability/GetdatevalueAbility.ets index 07614324813b24c0f271eb12b5389ac424b4943a..4197cee54fde2f30f42210657b6e3d4aa84d92b8 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/getdatevalueability/GetdatevalueAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/getdatevalueability/GetdatevalueAbility.ets @@ -1,56 +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 GetdatevalueAbility 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'); - } -}; +/* + * 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 GetdatevalueAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..fedabe9554430cfdbac232c6b678941e9ee9d24b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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 'libgetdatevalue.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..54da6858a03c35b9be6d604c46107ae0eb46e9d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getdatevalue", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetdatevalueAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetdatevalueAbility", + "srcEntry": "./ets/getdatevalueability/GetdatevalueAbility.ets", + "description": "$string:GetdatevalueAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetdatevalueAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..56aaf0feaaf364440bffd54c118b8453dabd5e87 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetdatevalueAbility_desc", + "value": "description" + }, + { + "name": "GetdatevalueAbility_label", + "value": "JsvmAboutDate" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8740d051bd5fa977a71ff9dcedaa316063a5c43e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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('testGetDateValue', 0, async (done: Function) => { + console.log('uitest: TestGetDateValue begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetdatevalueAbility' + } + 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('GetdatevalueAbility'); + + 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: TestGetDateValue end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7029c62d68d3c9feff602d95e6b8e0a93f1144ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/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": "getdatevalue_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/.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/JsvmUsageGuide/JsvmAboutDate/isdate/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutDate/isdate/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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/JsvmUsageGuide/JsvmAboutDate/isdate/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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/JsvmUsageGuide/JsvmAboutDate/isdate/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..66e0533be2a9441c901cfcff9471f98dc9743714 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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": "isdate", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libisdate.so": "file:./src/main/cpp/types/libisdate" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ecb3665d3335b9e0e2c51a4b441b424b754a7d6e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutDate) + +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(isdate SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(isdate PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb7e36d3aaaa156ebcfef866021aedde70fd8e60 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/hello.cpp @@ -0,0 +1,155 @@ +/* + * 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) + +// [Start oh_jsvm_is_date] +// OH_JSVM_IsDate的样例方法 +static JSVM_Value IsDate(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); + bool isData; + JSVM_CALL(OH_JSVM_IsDate(env, args[0], &isData)); + OH_LOG_INFO(LOG_APP, "JSVM IsDate success:%{public}d", isData); + + JSVM_Value result = nullptr; + JSVM_CALL(OH_JSVM_GetBoolean(env, isData, &result)); + return result; +} +// CreateDate注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsDate}, +}; +static JSVM_CallbackStruct *method = param; +// CreateDate方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isDate", nullptr, method, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(isDate(new Date(Date.now())))JS"; +// [End oh_jsvm_is_date] + +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 = "isdate", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f5bb4004b04c2d80c35770653def1fac87f339cc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/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; diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e49a449d5cd1c463e814a4335799c7511d484d6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/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": "libisdate.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/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/isdateability/IsdateAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/isdateability/IsdateAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/isdateability/IsdateAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/isdateability/IsdateAbility.ets index 823473d99a18ad8c06dfe6b0c23e5165a10dcf74..29f9cd7504b5c430ba395ef15b6df928f67f609b --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/isdateability/IsdateAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/isdateability/IsdateAbility.ets @@ -1,56 +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 IsdateAbility 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'); - } -}; +/* + * 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 IsdateAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9114e76f35838a979932c6098d5685baae8e6c25 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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 'libisdate.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7d8595bb96379d04c40c8994e0e6dff99eadc10c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "isdate", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IsdateAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IsdateAbility", + "srcEntry": "./ets/isdateability/IsdateAbility.ets", + "description": "$string:IsdateAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IsdateAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c52973df9869308559b2fbb6ce1fbaa91f6dfadf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IsdateAbility_desc", + "value": "description" + }, + { + "name": "IsdateAbility_label", + "value": "JsvmAboutDate" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc16b02e16cb8e385f501469303aeba48f788041 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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('testIsDate', 0, async (done: Function) => { + console.log('uitest: TestIsDate begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IsdateAbility' + } + 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('IsdateAbility'); + + 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: TestIsDate end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..70177e87b6e6e0de60a35df99ea6a7ca7b5e924d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/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": "isdate_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/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/JsvmUsageGuide/JsvmAboutDate/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..1e30ecb80ff41f354bbb12c1cf8e9938d4f915b8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/ohosTest.md @@ -0,0 +1,10 @@ +# JsvmAboutDate 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 创建了一个表示给定毫秒数的Date对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript Date的时间值的Double基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断一个JavaScript对象是否为Date类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/screenshots/JsvmAboutDate_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dda96436534c0e6fc0d01b56ade49a387d57ac75 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/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.jsvmaboutobject", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ef233ddf9974f4f9d48542091b9bd51d722cf129 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutObject" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/README.md new file mode 100644 index 0000000000000000000000000000000000000000..54b11900f72a8223708e5fae4f3539ebbfe79ba5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/README.md @@ -0,0 +1,273 @@ +# ArkTS使用JSVM-API接口进行object相关开发 + +### 介绍 + +使用JSVM-API接口进行object相关开发,处理JavaScript对象的基本操作的功能,例如创建对象、获取原型、冻结和密封对象,检查对象的类型等。这些操作是在处理JavaScript对象时非常常见的,提供了一种与JavaScript对象交互的方式。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行object相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-object.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +checkobjecttypetag/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createexternal/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createobject/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createsymbol/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getprototype/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvalueexternal/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +instanceof/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +objectfreeze/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +objectseal/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +symbolfor/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +typeof/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutObject > .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/JsvmUsageGuide/JsvmAboutObject/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71d1cf384f3db7d9d70f9e93e1a3ca823c37ff39 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/build-profile.json5 @@ -0,0 +1,178 @@ +/* + * 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": "getprototype", + "srcPath": "./getprototype", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createobject", + "srcPath": "./createobject", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "objectfreeze", + "srcPath": "./objectfreeze", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "objectseal", + "srcPath": "./objectseal", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "typeof", + "srcPath": "./typeof", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "instanceof", + "srcPath": "./instanceof", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "checkobjecttypetag", + "srcPath": "./checkobjecttypetag", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createexternal", + "srcPath": "./createexternal", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvalueexternal", + "srcPath": "./getvalueexternal", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createsymbol", + "srcPath": "./createsymbol", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "symbolfor", + "srcPath": "./symbolfor", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/.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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2ca9a7fcfe8e19836c6822f011ce2abe4941df27 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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": "checkobjecttypetag", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcheckobjecttypetag.so": "file:./src/main/cpp/types/libcheckobjecttypetag" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ededd4e1177c5d146ddc1b390aeb32cdc3717276 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(checkobjecttypetag SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(checkobjecttypetag PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c27886bdfcbb5c1414e5dc54a4baf1e75d01df60 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/hello.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_check_object_type_tag] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +#define NUMBERINT_FOUR +// [StartExclude oh_jsvm_check_object_type_tag] +#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) +// [EndExclude oh_jsvm_check_object_type_tag] + +// 定义一个静态常量JSVM_TypeTag数组存储类型标签 +static const JSVM_TypeTag TagsData[NUMBERINT_FOUR] = { + {0x9e4b2449547061b3, 0x33999f8a6516c499}, + {0x1d55a794c53a726d, 0x43633f509f9c944e}, + {0, 0}, // 用于表示无标签或默认标签 + {0x6a971439f5b2e5d7, 0x531dc28a7e5317c0}, +}; +// OH_JSVM_TypeTagObject的样例方法 +static JSVM_Value SetTypeTagToObject(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取两个JavaScript侧传入的参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取索引数字转换为JSVM_Value + int32_t index = 0; + OH_JSVM_GetValueInt32(env, args[1], &index); + // 给参数(对象)设置类型标签 + JSVM_Status status = OH_JSVM_TypeTagObject(env, args[0], &TagsData[index]); + // 将bool结果转换为JSVM_Value并返回 + JSVM_Value result = nullptr; + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM SetTypeTagToObject fail"); + OH_JSVM_GetBoolean(env, false, &result); + } else { + OH_LOG_INFO(LOG_APP, "JSVM SetTypeTagToObject success"); + OH_JSVM_GetBoolean(env, true, &result); + } + return result; +} +// OH_JSVM_CheckObjectTypeTag的样例方法 +static JSVM_Value CheckObjectTypeTag(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取两个JavaScript侧传入的参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取索引数字转换为JSVM_Value + int32_t index = 0; + OH_JSVM_GetValueInt32(env, args[1], &index); + // 检查对象的类型标签 + bool checkResult = false; + JSVM_Status status = OH_JSVM_CheckObjectTypeTag(env, args[0], &TagsData[index], &checkResult); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM SetTypeTagToObject fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM SetTypeTagToObject:%{public}d", checkResult); + } + // 将bool结果转换为JSVM_Value并返回 + JSVM_Value checked = nullptr; + OH_JSVM_GetBoolean(env, checkResult, &checked); + return checked; +} +// SetTypeTagToObject,CheckObjectTypeTag注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = SetTypeTagToObject}, + {.data = nullptr, .callback = CheckObjectTypeTag}, +}; +static JSVM_CallbackStruct *method = param; +// SetTypeTagToObject,CheckObjectTypeTag方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"setTypeTagToObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + {"checkObjectTypeTag", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS( + class Obj { + data; + message; + } + let obj= { data: 0, message: "hello world"}; + setTypeTagToObject(obj, 0); + checkObjectTypeTag(obj, 0);)JS"; +// [End oh_jsvm_check_object_type_tag] + +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 = "checkobjecttypetag", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0e9da982043323bf5f48260a795a2698ade097bc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/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": "libcheckobjecttypetag.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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets index 01897d10b74ea16235a335418bc1477b207c41ec..d4572bdd887d1746a97ee66d7dd07173420be38e --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets @@ -1,56 +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 CheckobjecttypetagAbility 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'); - } -}; +/* + * 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 CheckobjecttypetagAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..79ccd79a8e6363fc70738115a60f85e512991c26 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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 'libcheckobjecttypetag.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_CheckObjectTypeTag'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..146fe9ab4aff39e915904beb7d6723ed5de9588d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "checkobjecttypetag", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CheckobjecttypetagAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CheckobjecttypetagAbility", + "srcEntry": "./ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets", + "description": "$string:CheckobjecttypetagAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CheckobjecttypetagAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..31eca34aa45ad344fbd2e3fd25472f72b59f9b76 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CheckobjecttypetagAbility_desc", + "value": "description" + }, + { + "name": "CheckobjecttypetagAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e718a6bda7ff4c3583af283468a2163e4ac32a55 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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('testCheckObjectTypeTag', 0, async (done: Function) => { + console.log('uitest: TestCheckObjectTypeTag begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CheckobjecttypetagAbility' + } + 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('CheckobjecttypetagAbility'); + + 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: TestCheckObjectTypeTag end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..12d16b4f61e3ef5981c4806ed74c485934c6a907 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/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": "checkobjecttypetag_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/.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/JsvmUsageGuide/JsvmAboutObject/createexternal/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/createexternal/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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/JsvmUsageGuide/JsvmAboutObject/createexternal/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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/JsvmUsageGuide/JsvmAboutObject/createexternal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a08c5142234dc5775f1bc3c6dbbb20ef23a41815 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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": "createexternal", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateexternal.so": "file:./src/main/cpp/types/libcreateexternal" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..97202c0cfa30df9ed8f8a473c732fe4d7a0ab808 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(createexternal SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createexternal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6eb4034c4a658229ad5b18612be1dc4422b572c3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/hello.cpp @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_external] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +#include +#include +// [StartExclude oh_jsvm_create_external] +#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) +// [EndExclude oh_jsvm_create_external] + +// OH_JSVM_CreateExternal的样例方法 +static JSVM_Value CreateExternal(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t dataSize = 10; + void *data = malloc(dataSize); + if (data == nullptr) { + OH_LOG_ERROR(LOG_APP, "JSVM Failed to malloc."); + return nullptr; + } + memset(data, 0, dataSize); + const char* testStr = "test"; + JSVM_Value external = nullptr; + JSVM_Status status = OH_JSVM_CreateExternal( + env, data, [](JSVM_Env env, void *data, void *hint) {free(data);}, (void *)testStr, &external); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM Failed to create external data, status:%{public}d.", status); + free(data); + data = nullptr; + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateExternal success"); + } + return external; +} +// CreateExternal注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateExternal}, +}; +static JSVM_CallbackStruct *method = param; +// CreateExternal方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createExternal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createExternal())JS"; +// [End oh_jsvm_create_external] + +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 = "createexternal", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..be27396720a0fa328e6560a486516bb0e5e08102 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/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": "libcreateexternal.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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/createexternalability/CreateexternalAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/createexternalability/CreateexternalAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/createexternalability/CreateexternalAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/createexternalability/CreateexternalAbility.ets index 0b554dac92f59c1cf5e6906287a5cc273c90ca3b..a1d7aa147cc6488fdb8e4eb2be8afcd73f6cd7a2 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/createexternalability/CreateexternalAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/createexternalability/CreateexternalAbility.ets @@ -1,56 +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 CreateexternalAbility 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'); - } -}; +/* + * 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 CreateexternalAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..895125b49b1f39dfbd60b6c41ca5d199fd5208ed --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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 'libcreateexternal.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7cfef6f75e0e9370f4873f224ec55bb31059be1c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createexternal", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreateexternalAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreateexternalAbility", + "srcEntry": "./ets/createexternalability/CreateexternalAbility.ets", + "description": "$string:CreateexternalAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreateexternalAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..477cec44f86d60e163fcebb3602292105b4df3d7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreateexternalAbility_desc", + "value": "description" + }, + { + "name": "CreateexternalAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..67f1a8df729543962c968f1bba318c6dc5762dc4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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('testCreateExternal', 0, async (done: Function) => { + console.log('uitest: TestCreateExternal begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreateexternalAbility' + } + 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('CreateexternalAbility'); + + 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: TestCreateExternal end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3d00fb89ec9c037fe1ed589e104e28e2a866e293 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/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": "createexternal_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/.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/JsvmUsageGuide/JsvmAboutObject/createobject/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/createobject/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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/JsvmUsageGuide/JsvmAboutObject/createobject/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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/JsvmUsageGuide/JsvmAboutObject/createobject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..92e42ff1a8ab10ad5628b569fa7ea1cfc90d289b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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": "createobject", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateobject.so": "file:./src/main/cpp/types/libcreateobject" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf648023637b963c15082bd295e73ec70cb871df --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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(createobject SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createobject PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f0966b941944eae0cfeb751ee5baa6f3a07a67d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/hello.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_object] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_create_object] +#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) +// [EndExclude oh_jsvm_create_object] + +// OH_JSVM_CreateObject的样例方法 +static JSVM_Value CreateObject(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value object = nullptr; + // 创建一个空对象 + JSVM_Status status = OH_JSVM_CreateObject(env, &object); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateObject fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateObject success"); + } + // 设置对象的属性 + JSVM_Value name = nullptr; + // 设置属性名为 "name" + OH_JSVM_CreateStringUtf8(env, "name", JSVM_AUTO_LENGTH, &name); + JSVM_Value value = nullptr; + // 设置属性值为 "Hello from N-API!" + OH_JSVM_CreateStringUtf8(env, "Hello OH_JSVM_CreateObject!", JSVM_AUTO_LENGTH, &value); + // 将属性设置到对象上 + OH_JSVM_SetProperty(env, object, name, value); + return object; +} +// CreateObject注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateObject}, +}; +static JSVM_CallbackStruct *method = param; +// CreateObject方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createObject())JS"; +// [End oh_jsvm_create_object] + +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 = "createobject", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3b63257128ba9eed6e0ca3002f0e0deceb6998f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/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": "libcreateobject.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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/createobjectability/CreateobjectAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/createobjectability/CreateobjectAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/createobjectability/CreateobjectAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/createobjectability/CreateobjectAbility.ets index 28e01f58b9d96b4dba0e734bf701f6ed89c4e71c..7ba5ff339f5d6ba39efba44191ad0121b615e0c2 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/createobjectability/CreateobjectAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/createobjectability/CreateobjectAbility.ets @@ -1,56 +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 CreateobjectAbility 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'); - } -}; +/* + * 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 CreateobjectAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..81c6c22b047c45f4650af982b703c60983eb7d34 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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 'libcreateobject.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..80b23bf8c7f2034afbf22d88e6e2f83e9cfdb503 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createobject", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreateobjectAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreateobjectAbility", + "srcEntry": "./ets/createobjectability/CreateobjectAbility.ets", + "description": "$string:CreateobjectAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreateobjectAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..bb24ee9ff92361ab10e8cb7642b7e605fef2970e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreateobjectAbility_desc", + "value": "description" + }, + { + "name": "CreateobjectAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9eaa609e06d0c3b4212a60c50f5542d0e812b6ad --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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('testCreateObject', 0, async (done: Function) => { + console.log('uitest: TestCreateObject begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreateobjectAbility' + } + 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('CreateobjectAbility'); + + 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: TestCreateObject end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..34d9e19e41a5236faacaec98abd0726d3774f2df --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/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": "createobject_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/.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/JsvmUsageGuide/JsvmAboutObject/createsymbol/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/createsymbol/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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/JsvmUsageGuide/JsvmAboutObject/createsymbol/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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/JsvmUsageGuide/JsvmAboutObject/createsymbol/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b4e40ae1092e8e74579c437dcfa666373d0afddd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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": "createsymbol", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatesymbol.so": "file:./src/main/cpp/types/libcreatesymbol" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5aab5eaaa26effb2521a129ca3984aab60191f16 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(createsymbol SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createsymbol PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..82f0935c3e018c7df4481797fc5e2f8ad6bb08fb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_symbol] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +// [StartExclude oh_jsvm_create_symbol] +#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) +// [EndExclude oh_jsvm_create_symbol] + +// OH_JSVM_CreateSymbol的样例方法 +static JSVM_Value CreateSymbol(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value result = nullptr; + const char *des = "only"; + OH_JSVM_CreateStringUtf8(env, des, JSVM_AUTO_LENGTH, &result); + JSVM_Value returnSymbol = nullptr; + OH_JSVM_CreateSymbol(env, result, &returnSymbol); + JSVM_ValueType valuetypeSymbol; + OH_JSVM_Typeof(env, returnSymbol, &valuetypeSymbol); + if (valuetypeSymbol == JSVM_SYMBOL) { + OH_LOG_INFO(LOG_APP, "JSVM CreateSymbol Success"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateSymbol fail"); + } + return returnSymbol; +} +// CreateSymbol注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateSymbol}, +}; +static JSVM_CallbackStruct *method = param; +// CreateSymbol方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createSymbol", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createSymbol())JS"; +// [End oh_jsvm_create_symbol] + +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 = "createsymbol", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3a1844f0f4845f682f99a5136b4fe2270e40a917 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/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": "libcreatesymbol.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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/createsymbolability/CreatesymbolAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/createsymbolability/CreatesymbolAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/createsymbolability/CreatesymbolAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/createsymbolability/CreatesymbolAbility.ets index 6b997d74345ebfdb317b66479c1cdba31e14ed23..c1ec919eeb2cfcb9e6352ffa3a8fbd2db84794de --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/createsymbolability/CreatesymbolAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/createsymbolability/CreatesymbolAbility.ets @@ -1,56 +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 CreatesymbolAbility 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'); - } -}; +/* + * 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 CreatesymbolAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7aea0e047487468b40b9fef77aa8e2df82af3e40 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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 'libcreatesymbol.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5bd3807a9e3d5db9df293a876aa634115113ce28 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createsymbol", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatesymbolAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatesymbolAbility", + "srcEntry": "./ets/createsymbolability/CreatesymbolAbility.ets", + "description": "$string:CreatesymbolAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatesymbolAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..51f7a086694e28e108d2f844f9db50576f4cbf6f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatesymbolAbility_desc", + "value": "description" + }, + { + "name": "CreatesymbolAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ecf83c2a133bab57d2c69a143b430a4f8f46b7e7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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('testCreateSymbol', 0, async (done: Function) => { + console.log('uitest: TestCreateSymbol begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatesymbolAbility' + } + 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('CreatesymbolAbility'); + + 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: TestCreateSymbol end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fea12ddaa844024145de6f4c27c1cc9a4c5ed42d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/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": "createsymbol_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/.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/JsvmUsageGuide/JsvmAboutObject/getprototype/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/getprototype/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..74058a69fffe9b6ef5d5e12a17fae4020e9456b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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": "getprototype", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetprototype.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f95e3b6e48bfa59704b4cf419b9039a5bb7dfc36 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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(getprototype SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getprototype PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa7698ee35c5757180d9b4e3cb6773f7cfe563ad --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_prototype] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +// [StartExclude oh_jsvm_get_prototype] +#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) +// [EndExclude oh_jsvm_get_prototype] + +// GetPrototype注册回调 +// OH_JSVM_GetPrototype的样例方法 +static JSVM_Value GetPrototype(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + JSVM_Value result{nullptr}; + JSVM_Status status = OH_JSVM_GetPrototype(env, argv[0], &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetPrototype fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetPrototype success"); + } + return result; +} +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetPrototype}, +}; +static JSVM_CallbackStruct *method = param; +// GetPrototype方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getPrototype", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(const myObject = {}; + const proto = getPrototype(myObject); + console.log(proto === Object.prototype);)JS"; +// [End oh_jsvm_get_prototype] + +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 = "getprototype", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dc2fbe8986e82c4852d851c282b544be062ed225 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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": "libgetprototype.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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..52727f910acaf11bfe500425ce5c4520b88a9f9c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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 'libgetprototype.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8e78e77d7e3ad2e451e7367c3c1a05aeee65def7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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": "getprototype", + "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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3da670abdb7561ffc22ded5d1d87916d3a3e6755 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9064d60bce1d3cddb16af12dd7150196c7ce2198 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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('testGetPrototype', 0, async (done: Function) => { + console.log('uitest: TestGetPrototype 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: TestGetPrototype end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8d28f054f1448ba4b0dcde0151053187d316ef38 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/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": "getprototype_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/.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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e3853ee142d14f8a28e790a60d1a156a1ca58747 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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": "getvalueexternal", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvalueexternal.so": "file:./src/main/cpp/types/libgetvalueexternal" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c5b9dd4661d9205efff144cfbcbece42bd7ccdb0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(getvalueexternal SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvalueexternal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff0511a63221cd63698e2162a4e143de3078fd75 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/hello.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_external] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_value_external] +#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) +// [EndExclude oh_jsvm_get_value_external] + +// OH_JSVM_GetValueExternal的样例方法 +static JSVM_Value GetValueExternal(JSVM_Env env, JSVM_CallbackInfo info) +{ + static int data = 0x12345; + JSVM_Value externalValue = nullptr; + JSVM_Status status = OH_JSVM_CreateExternal(env, (void*)&data, nullptr, nullptr, &externalValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateExternal fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateExternal success"); + } + void *dataValue; + status = OH_JSVM_GetValueExternal(env, externalValue, &dataValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueExternal fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueExternal success"); + } + // 将符号位转化为int类型传出去 + JSVM_Value returnValue = nullptr; + int retData = *static_cast(dataValue); + OH_JSVM_CreateInt32(env, retData, &returnValue); + return returnValue; +} +// GetValueExternal注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueExternal}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueExternal方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueExternal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getValueExternal())JS"; +// [End oh_jsvm_get_value_external] + +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 = "getvalueexternal", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3a52b5b551641a46c7b8bc7050af3b5688bd58a8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/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": "libgetvalueexternal.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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/getvalueexternalability/GetvalueexternalAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/getvalueexternalability/GetvalueexternalAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/getvalueexternalability/GetvalueexternalAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/getvalueexternalability/GetvalueexternalAbility.ets index e7c7abb34e69afcb89f4b468bc1f37394f4dbe6d..854e76dae73727ff8f0e60d20cfbc024c2b0d15b --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/getvalueexternalability/GetvalueexternalAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/getvalueexternalability/GetvalueexternalAbility.ets @@ -1,56 +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 GetvalueexternalAbility 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'); - } -}; +/* + * 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 GetvalueexternalAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..75b4b1456e769929a8c96b8a49b91a5bee3d2f63 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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 'libgetvalueexternal.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..478a853dbc37215488366da603298d4bdd0e7f2e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvalueexternal", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetvalueexternalAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetvalueexternalAbility", + "srcEntry": "./ets/getvalueexternalability/GetvalueexternalAbility.ets", + "description": "$string:GetvalueexternalAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetvalueexternalAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..15cee882c62dab4c1560db476d6c9a5469315fbe --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetvalueexternalAbility_desc", + "value": "description" + }, + { + "name": "GetvalueexternalAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a0d1cd86ec22c97469d8a697aceca0c24789852 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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('testGetValueExternal', 0, async (done: Function) => { + console.log('uitest: TestGetValueExternal begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetvalueexternalAbility' + } + 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('GetvalueexternalAbility'); + + 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: TestGetValueExternal end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..73f83efdafaf24eac2152b2eb3b0a0876d9f4486 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/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": "getvalueexternal_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/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/NodeAPI/NodeApiUse/NodeAPIArray/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/.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/JsvmUsageGuide/JsvmAboutObject/instanceof/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/instanceof/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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/JsvmUsageGuide/JsvmAboutObject/instanceof/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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/JsvmUsageGuide/JsvmAboutObject/instanceof/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..84060f72213192f04fea7d90e20066906a9983ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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": "instanceof", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libinstanceof.so": "file:./src/main/cpp/types/libinstanceof" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d584dc0bec723d558936004a07e0d4fc9b8f9c36 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(instanceof SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(instanceof PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..673e900837d52e63f558e964b424198b81451567 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/hello.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_instanceof] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_instanceof] +#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) +// [EndExclude oh_jsvm_instanceof] + +// OH_JSVM_Instanceof的样例方法 +static JSVM_Value InstanceOf(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取两个JavaScript侧传入的参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + bool result = false; + JSVM_Status status = OH_JSVM_Instanceof(env, args[0], args[1], &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM InstanceOf fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM InstanceOf:%{public}d", result); + } + JSVM_Value returnValue = nullptr; + OH_JSVM_GetBoolean(env, result, &returnValue); + return returnValue; +} +// InstanceOf注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = InstanceOf}, +}; +static JSVM_CallbackStruct *method = param; +// InstanceOf方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"instanceOf", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(class Person { + name; + age; + constructor(name, age) { + this.name = name; + this.age = age; + } + } + instanceOf(new Person('Alice', 30), Person); + ;)JS"; +// [End oh_jsvm_instanceof] + +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 = "instanceof", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c5074f726033952faca790580c1224dae65af879 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/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": "libinstanceof.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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/instanceofability/InstanceofAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/instanceofability/InstanceofAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/instanceofability/InstanceofAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/instanceofability/InstanceofAbility.ets index c4e9fc4ba73d81c9ccedb3e779ea33ca67232b7e..9031c4e9ccc01e1ec017f02d232eddaa02bdf0bc --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/instanceofability/InstanceofAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/instanceofability/InstanceofAbility.ets @@ -1,56 +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 InstanceofAbility 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'); - } -}; +/* + * 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 InstanceofAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c1efd2b974d111c0b9e63d19bdcf4fef0eb280b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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 'libinstanceof.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4a40496aa13fbd77814c999721bdaa2450ea7c07 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "instanceof", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "InstanceofAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "InstanceofAbility", + "srcEntry": "./ets/instanceofability/InstanceofAbility.ets", + "description": "$string:InstanceofAbility_desc", + "icon": "$media:layered_image", + "label": "$string:InstanceofAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d9adfa2b71875596f0fe78675c560da7af62767f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "InstanceofAbility_desc", + "value": "description" + }, + { + "name": "InstanceofAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad4b59a5598f8cafc718213283c4fe7eab9d4f7d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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('testInstanceof', 0, async (done: Function) => { + console.log('uitest: TestInstanceof begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'InstanceofAbility' + } + 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('InstanceofAbility'); + + 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: TestInstanceof end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..579d34e1b8a7e2ce2d47bc1d3ffe0aa2e74c8a8e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "instanceof_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/.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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0961a75159bc8916e8806636d42fba5bff1fc9f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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": "objectfreeze", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libobjectfreeze.so": "file:./src/main/cpp/types/libobjectfreeze" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d091da41ab135d8621b860f79205cc843b0dbeb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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(objectfreeze SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(objectfreeze PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d56b978b5f3b9e629740b284967f5abd6570e6a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_object_freeze] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_object_freeze] +#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) +// [EndExclude oh_jsvm_object_freeze] + +// OH_JSVM_ObjectFreeze的样例方法 +const int FREEZE_TEST_VALUE = 111111; +static JSVM_Value ObjectFreeze(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接受一个JavaScript侧传入的object + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + // 调用接口OH_JSVM_ObjectFreeze将传入的object冻结 + JSVM_Status status = OH_JSVM_ObjectFreeze(env, argv[0]); + if (status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "Test JSVM OH_JSVM_ObjectFreeze success"); + } + // 测试冻结后的对象中属性能否修改 + JSVM_Value value = nullptr; + OH_JSVM_CreateInt32(env, FREEZE_TEST_VALUE, &value); + OH_JSVM_SetNamedProperty(env, argv[0], "data", value); + // 将冻结后修改过的属性返回JavaScript侧 + return argv[0]; +} +// ObjectFreeze注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = ObjectFreeze}, +}; +static JSVM_CallbackStruct *method = param; +// ObjectFreeze方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"objectFreeze", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(let obj = { data: 55, message: "hello world"}; + objectFreeze(obj))JS"; +// [End oh_jsvm_object_freeze] + +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 = "objectfreeze", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bb8749ef3a296e53aaa63a8c11faf48a0fabfea2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/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": "libobjectfreeze.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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/objectfreezeability/ObjectfreezeAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/objectfreezeability/ObjectfreezeAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/objectfreezeability/ObjectfreezeAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/objectfreezeability/ObjectfreezeAbility.ets index d154be7b090890e69dd06f4f61ee00db5908705f..4f071e4b9a40abb04e6a15a4840a8b0f8686e5c2 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/objectfreezeability/ObjectfreezeAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/objectfreezeability/ObjectfreezeAbility.ets @@ -1,56 +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 ObjectfreezeAbility 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'); - } -}; +/* + * 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 ObjectfreezeAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9855c7bcc81b77d1d37bd8b082a90b2aafcff3be --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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 'libobjectfreeze.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..20e2ca5492e4d9263a92773022dabafdc9ecc084 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "objectfreeze", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ObjectfreezeAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ObjectfreezeAbility", + "srcEntry": "./ets/objectfreezeability/ObjectfreezeAbility.ets", + "description": "$string:ObjectfreezeAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ObjectfreezeAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..127d4344fc0e1a83dcf659463886dfac50e38bc6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ObjectfreezeAbility_desc", + "value": "description" + }, + { + "name": "ObjectfreezeAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f02636e2b790afe65136ada305cd44b9ffa1ec5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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('testObjectFreeze', 0, async (done: Function) => { + console.log('uitest: TestObjectFreeze begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ObjectfreezeAbility' + } + 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('ObjectfreezeAbility'); + + 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: TestObjectFreeze end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb3e6f9ad1246fc6448b325f8548af3ace349e85 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "objectfreeze_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/.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/JsvmUsageGuide/JsvmAboutObject/objectseal/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/objectseal/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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/JsvmUsageGuide/JsvmAboutObject/objectseal/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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/JsvmUsageGuide/JsvmAboutObject/objectseal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7c69b69ab1c4b04fd5040a4e08654bca6e175b14 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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": "objectseal", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libobjectseal.so": "file:./src/main/cpp/types/libobjectseal" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..eba25f767d656cc0890581b90af3c52d04679355 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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(objectseal SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(objectseal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1bc0cf6af528be56ccfdb4d0014e1880571fb15b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/hello.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_object_seal] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_object_seal] +#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) +// [EndExclude oh_jsvm_object_seal] + +// OH_JSVM_ObjectSeal的样例方法 +const int TEST_VALUE = 111111; +static JSVM_Value ObjectSeal(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接受一个JavaScript侧传入的object + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + // 调用接口OH_JSVM_ObjectSeal将传入的object封闭,使其无法添加新的属性 + JSVM_Status status = OH_JSVM_ObjectSeal(env, argv[0]); + if (status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "Test JSVM OH_JSVM_ObjectSeal success"); + } + // 检查封闭后的对象中属性能否修改、删除、新增 + // 封闭后对象修改 + JSVM_Value changeValue = nullptr; + OH_JSVM_CreateInt32(env, TEST_VALUE, &changeValue); + OH_JSVM_SetNamedProperty(env, argv[0], "data", changeValue); + // 封闭后对象删除 + JSVM_Value deleteProperty = nullptr; + OH_JSVM_CreateStringUtf8(env, "message", JSVM_AUTO_LENGTH, &deleteProperty); + bool result = false; + OH_JSVM_DeleteProperty(env, argv[0], deleteProperty, &result); + if (result) { + OH_LOG_INFO(LOG_APP, "Test JSVM OH_JSVM_ObjectSeal failed"); + } + // 封闭后对象新增 + JSVM_Value addValue = nullptr; + OH_JSVM_CreateStringUtf8(env, "addValue", JSVM_AUTO_LENGTH, &addValue); + OH_JSVM_SetNamedProperty(env, argv[0], "newProperty", addValue); + // 将封闭后改动过的对象返回JavaScript侧 + return argv[0]; +} +// ObjectSeal注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = ObjectSeal}, +}; +static JSVM_CallbackStruct *method = param; +// ObjectSeal方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"objectSeal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS( let obj = { data: 55, message: "hello world"}; + objectSeal(obj))JS"; +// [End oh_jsvm_object_seal] + +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 = "objectseal", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..913f2ad794e418a55985361d363e831ca7ed1b65 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/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": "libobjectseal.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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/objectsealability/ObjectsealAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/objectsealability/ObjectsealAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/objectsealability/ObjectsealAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/objectsealability/ObjectsealAbility.ets index 5a7738b9e80812d2f763b1e2fcffb2d18b033a6b..6a4926e705e3af70c3103cc5e0b9fb3ed196574b --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/objectsealability/ObjectsealAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/objectsealability/ObjectsealAbility.ets @@ -1,56 +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 ObjectsealAbility 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'); - } -}; +/* + * 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 ObjectsealAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a0d8d097ebd38aa049b550dc517702dcb541f04 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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 'libobjectseal.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ba8e2d0bce2d6926be0839cc92421887e0500324 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "objectseal", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ObjectsealAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ObjectsealAbility", + "srcEntry": "./ets/objectsealability/ObjectsealAbility.ets", + "description": "$string:ObjectsealAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ObjectsealAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d3b4bf96f9d1dd55c2aba9f500eff17877867db3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ObjectsealAbility_desc", + "value": "description" + }, + { + "name": "ObjectsealAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c9c7dc2d940ae1ed60c543d616ae4a864a73e24 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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('testObjectSeal', 0, async (done: Function) => { + console.log('uitest: TestObjectSeal begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ObjectsealAbility' + } + 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('ObjectsealAbility'); + + 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: TestObjectSeal end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4f94ebe3421861066c14de55238abbcb2ec4acf4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "objectseal_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/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/JsvmUsageGuide/JsvmAboutObject/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..3e518f73a7edd68b80d3780ccf949b38e8978920 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/ohosTest.md @@ -0,0 +1,18 @@ +# JsvmAboutObject 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------------------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 检查给定的类型标签是否与对象上的类型标签匹配 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建一个包装了外部指针的JavaScript对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建一个默认的JavaScript Object对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据给定的描述符创建一个Symbol对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript对象的原型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取先前传递给Hello World的外部数据指针 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断一个对象是否是某个构造函数的实例 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 冻结给定的对象,防止向其添加新属性,删除现有属性,防止更改现有属性的可枚举性、可配置性或可写性,并防止更改现有属性的值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 密封给定的对象。这可以防止向其添加新属性,以及将所有现有属性标记为不可配置 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 在全局注册表中搜索具有给定描述的现有Symbol,如果该Symbol已经存在,它将被返回,否则将在注册表中创建一个新Symbol | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 返回JavaScript对象的类型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/screenshots/JsvmAboutObject_2.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/.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/JsvmUsageGuide/JsvmAboutObject/symbolfor/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/symbolfor/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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/JsvmUsageGuide/JsvmAboutObject/symbolfor/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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/JsvmUsageGuide/JsvmAboutObject/symbolfor/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6c503d8ba3249c911439c9dce6de0051328cfe16 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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": "symbolfor", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libsymbolfor.so": "file:./src/main/cpp/types/libsymbolfor" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7a64d446b3a6b2a460f41ffb54387273c98642cc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(symbolfor SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(symbolfor PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50cd55a55c9a821e374350097f1fa44f943a7e3d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/hello.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_symbol_for] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_symbol_for] +#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) +// [EndExclude oh_jsvm_symbol_for] + +static const size_t TESTMO_LENGTH = 9; +// 定义一个常量,用于存储最大字符串长度 +static const int MAX_BUFFER_SIZE = 128; +// OH_JSVM_SymbolFor的样例方法 +static JSVM_Value SymbolFor(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value description = nullptr; + OH_JSVM_CreateStringUtf8(env, "test_demo", TESTMO_LENGTH, &description); + char buffer[MAX_BUFFER_SIZE]; + size_t bufferSize = MAX_BUFFER_SIZE; + size_t copied = 0; + OH_JSVM_GetValueStringUtf8(env, description, buffer, bufferSize, &copied); + JSVM_Value symbol = nullptr; + OH_JSVM_CreateSymbol(env, description, &symbol); + JSVM_Value result_symbol = nullptr; + JSVM_Status status = OH_JSVM_SymbolFor(env, buffer, copied, &result_symbol); + JSVM_ValueType valuetypeSymbol; + OH_JSVM_Typeof(env, result_symbol, &valuetypeSymbol); + if (valuetypeSymbol == JSVM_SYMBOL && status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_SymbolFor success"); + } + // 返回结果 + return result_symbol; +} +// SymbolFor注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = SymbolFor}, +}; +static JSVM_CallbackStruct *method = param; +// SymbolFor方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"symbolFor", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(symbolFor())JS"; +// [End oh_jsvm_symbol_for] + +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 = "symbolfor", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f7836eab0c92a8999632ec003c52a202e13a6281 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/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": "libsymbolfor.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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e319a64c0e475e3c0f73197e4c3a8a5c3d1c72a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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 'libsymbolfor.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/symbolforability/SymbolforAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/symbolforability/SymbolforAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/symbolforability/SymbolforAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/symbolforability/SymbolforAbility.ets index 94d37772006c30f439800331f77c9c7407bc33fe..619d5e0e813c5399eaef08f3db36d370ecebbeb0 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/symbolforability/SymbolforAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/symbolforability/SymbolforAbility.ets @@ -1,56 +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 SymbolforAbility 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'); - } -}; +/* + * 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 SymbolforAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..990e56565d96d45f1fb944ff5389bca6df6207f8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/module.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "symbolfor", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "SymbolforAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "SymbolforAbility", + "srcEntry": "./ets/symbolforability/SymbolforAbility.ets", + "description": "$string:SymbolforAbility_desc", + "icon": "$media:layered_image", + "label": "$string:SymbolforAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a1845a148fe20bb6f8925d35eadac0c2c4181761 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "SymbolforAbility_desc", + "value": "description" + }, + { + "name": "SymbolforAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4c204adf70d2407f4fcf9ffcc517e735a63404f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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('testSymbolFor', 0, async (done: Function) => { + console.log('uitest: TestSymbolFor 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: TestSymbolFor end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..26ee7cdcb37c84d4b964df753679ca44c006cf9f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "symbolfor_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/.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/JsvmUsageGuide/JsvmAboutObject/typeof/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutObject/typeof/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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/JsvmUsageGuide/JsvmAboutObject/typeof/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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/JsvmUsageGuide/JsvmAboutObject/typeof/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9c59fc83064cd57b98524237b2334c0b1b576de --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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": "typeof", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libtypeof.so": "file:./src/main/cpp/types/libtypeof" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5281c648ba631c26b6c02f354ca38cf19da3fcfd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutObject) + +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) + +add_library(typeof SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(typeof PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..20882f1bb747af06edb0804be32034e9d12a58e7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/hello.cpp @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_typeof] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_typeof] +#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) +// [EndExclude oh_jsvm_typeof] + +// OH_JSVM_Typeof的样例方法 +static JSVM_Value GetTypeof(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_ValueType valueType; + OH_JSVM_Typeof(env, args[0], &valueType); + JSVM_Value type = nullptr; + switch (valueType) { + case JSVM_UNDEFINED: + OH_LOG_INFO(LOG_APP, "JSVM Input type is undefined"); + OH_JSVM_CreateStringUtf8(env, "Input type is undefined", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_NULL: + OH_LOG_INFO(LOG_APP, "JSVM Input type is null"); + OH_JSVM_CreateStringUtf8(env, "Input type is null", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_BOOLEAN: + OH_LOG_INFO(LOG_APP, "JSVM Input type is boolean"); + OH_JSVM_CreateStringUtf8(env, "Input type is boolean", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_NUMBER: + OH_LOG_INFO(LOG_APP, "JSVM Input type is number"); + OH_JSVM_CreateStringUtf8(env, "Input type is number", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_STRING: + OH_LOG_INFO(LOG_APP, "JSVM Input type is string"); + OH_JSVM_CreateStringUtf8(env, "Input type is string", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_SYMBOL: + OH_LOG_INFO(LOG_APP, "JSVM Input type is symbol"); + OH_JSVM_CreateStringUtf8(env, "Input type is symbol", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_OBJECT: + OH_LOG_INFO(LOG_APP, "JSVM Input type is object"); + OH_JSVM_CreateStringUtf8(env, "Input type is object", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_FUNCTION: + OH_LOG_INFO(LOG_APP, "JSVM Input type is function"); + OH_JSVM_CreateStringUtf8(env, "Input type is function", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_EXTERNAL: + OH_LOG_INFO(LOG_APP, "JSVM Input type is external"); + OH_JSVM_CreateStringUtf8(env, "Input type is external", JSVM_AUTO_LENGTH, &type); + break; + case JSVM_BIGINT: + OH_LOG_INFO(LOG_APP, "JSVM Input type is bigint"); + OH_JSVM_CreateStringUtf8(env, "Input type is bigint", JSVM_AUTO_LENGTH, &type); + break; + default: + OH_LOG_INFO(LOG_APP, "JSVM Input type does not match any"); + OH_JSVM_CreateStringUtf8(env, " ", JSVM_AUTO_LENGTH, &type); + break; + } + return type; +} +// GetTypeof注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetTypeof}, +}; +static JSVM_CallbackStruct *method = param; +// GetTypeof方法别名,TS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getTypeof", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getTypeof(true);)JS"; +// [End oh_jsvm_typeof] + +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 = "typeof", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cc8c0984833add392968b5c8260b9028462ef3d9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/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": "libtypeof.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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba0644d764ecbb7a94d7f73c0da0adb351b73931 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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 'libtypeof.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/typeofability/TypeofAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/typeofability/TypeofAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/typeofability/TypeofAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/typeofability/TypeofAbility.ets index 0a4dd741d42150ae023983f9f0099c56c153b944..5db4403ad0ae1b1b8ac346cf707b314d326ba978 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/typeofability/TypeofAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/typeofability/TypeofAbility.ets @@ -1,56 +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 TypeofAbility 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'); - } -}; +/* + * 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 TypeofAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dfeabf17a16abc4abbfee218e6fd01701e37883c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "typeof", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "TypeofAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "TypeofAbility", + "srcEntry": "./ets/typeofability/TypeofAbility.ets", + "description": "$string:TypeofAbility_desc", + "icon": "$media:layered_image", + "label": "$string:TypeofAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..99c1866e9cef517425d6ce2c9112d95479f81579 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "TypeofAbility_desc", + "value": "description" + }, + { + "name": "TypeofAbility_label", + "value": "JsvmAboutObject" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..99908a153bb83fa4930dc5caae83a2bb687b6300 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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('testTypeof', 0, async (done: Function) => { + console.log('uitest: TestTypeof begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'TypeofAbility' + } + 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('TypeofAbility'); + + 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: TestTypeof end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/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/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..589903faa07d63a7c80db06d80eb03704c5e6b4b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "typeof_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..951d28629e67cbb47321a23b258701d5221b3c2f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/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.jsvmaboutprimitive", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5fc6906c32e3ecaf31a876c953fa40dd525fd213 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutPrimitive" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/README.md new file mode 100644 index 0000000000000000000000000000000000000000..56fb04bde9535f1fa8399949cff770fb09bd18b0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/README.md @@ -0,0 +1,233 @@ +# ArkTs使用JSVM-API接口进行primitive类相关开发 + +### 介绍 + +在使用JSVM-API接口时,开发人员可以实现在JSVM模块中与JavaScript对象的交互,并进行数据转换和获取特定对象的操作,它们在不同的场景中发挥着重要的作用,使开发人员能够更灵活地处理JavaScript值和对象。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行primitive类相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-primitive.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :--------------------------------------------------------------------: | :--------------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +coercetobool/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +coercetonumber/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +coercetoobject/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +coercetostring/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getboolean/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getglobal/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getnull/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getundefined/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluebool/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutPrimitive > .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/JsvmUsageGuide/JsvmAboutPrimitive/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7bed37cdafb725d973f7b67fe178ec1c22131b3e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/build-profile.json5 @@ -0,0 +1,154 @@ +/* + * 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": "coercetobool", + "srcPath": "./coercetobool", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "coercetonumber", + "srcPath": "./coercetonumber", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "coercetoobject", + "srcPath": "./coercetoobject", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "coercetostring", + "srcPath": "./coercetostring", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getboolean", + "srcPath": "./getboolean", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvaluebool", + "srcPath": "./getvaluebool", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getglobal", + "srcPath": "./getglobal", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getnull", + "srcPath": "./getnull", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getundefined", + "srcPath": "./getundefined", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..520ffbdd0bb7ce9712176b7bb367030b34f58d3b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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": "coercetobool", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcoercetobool.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c196aec3ccd4b8fa2e222984d3e9525df0fb12f9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPrimitiveOne) + +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(coercetobool SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(coercetobool PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49bd5a10b1f126d91a02faa77f8539e436adf7fb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_coerce_to_bool] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_coerce_to_bool] +#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) +// [EndExclude oh_jsvm_coerce_to_bool] + +// OH_JSVM_CoerceToBool的样例方法 +static JSVM_Value CoerceToBool(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value boolean = nullptr; + JSVM_Status status = OH_JSVM_CoerceToBool(env, args[0], &boolean); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CoerceToBool failed"); + } else { + bool result = false; + OH_JSVM_GetValueBool(env, boolean, &result); + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToBool success:%{public}d", result); + } + return boolean; +} +// CoerceToBool注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CoerceToBool}, +}; +static JSVM_CallbackStruct *method = param; +// CoerceToBool方法别名,ArkTS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"coerceToBool", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(coerceToBool("123"))JS"; +// [End oh_jsvm_coerce_to_bool] + +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 = "coercetobool", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10a24b2643eb1a995abdf262abe3c2b01f35a36e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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": "libcoercetobool.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c2933b5639bfc93679662821c998d486096b7f5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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 'libcoercetobool.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..574c7b77d7a628e6adbe96764a1583e34745f760 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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": "coercetobool", + "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7c00d4195f1b057baef9855dc29e653b488275cf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..68479d14f59dfa8e284974a5cbe75e067d3de470 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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('testCoerceToBool', 0, async (done: Function) => { + console.log('uitest: TestCoerceToBool 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: TestCoerceToBool end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ae9cbd3f31fb6154e06f20dfa17db00537c72108 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/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": "coercetobool_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1c31ed541df2da8ac28babfdc69a307d9570f66f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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": "coercetonumber", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcoercetonumber.so": "file:./src/main/cpp/types/libcoercetonumber" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c17bb3eff70c83adc5a181c1ca1cfc85b32cfc32 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPrimitiveOne) + +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(coercetonumber SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(coercetonumber PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e0d5f5ac7c54c0b382a5afda78e057d43f031cc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_coerce_to_number] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +// [StartExclude oh_jsvm_coerce_to_number] +#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) +// [EndExclude oh_jsvm_coerce_to_number] + +// OH_JSVM_CoerceToNumber的样例方法 +static JSVM_Value CoerceToNumber(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value number = nullptr; + JSVM_Status status = OH_JSVM_CoerceToNumber(env, args[0], &number); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CoerceToNumber failed"); + } else { + int32_t result = 0; + OH_JSVM_GetValueInt32(env, number, &result); + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToNumber success:%{public}d", result); + } + return number; +} +// CoerceToNumber注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CoerceToNumber}, +}; +static JSVM_CallbackStruct *method = param; +// CoerceToNumber方法别名,ArkTS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"coerceToNumber", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(coerceToNumber(true))JS"; +// [End oh_jsvm_coerce_to_number] + +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 = "coercetonumber", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..417e718843a3f981e625acfa88922196ba4c2052 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/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": "libcoercetonumber.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/coercetonumberability/CoercetonumberAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/coercetonumberability/CoercetonumberAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/coercetonumberability/CoercetonumberAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/coercetonumberability/CoercetonumberAbility.ets index d6963dabfa682701e57129a998e489ed68bf0125..fc2c75d969311327861044a14bf51afcb8d85e60 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/coercetonumberability/CoercetonumberAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/coercetonumberability/CoercetonumberAbility.ets @@ -1,56 +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 CoercetonumberAbility 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'); - } -}; +/* + * 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 CoercetonumberAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..baccd05bd192b552ea1d2d9c61544e45788a3109 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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 'libcoercetonumber.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4c714c1d578bc45d4f2c46de2c843029ff14d91f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "coercetonumber", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CoercetonumberAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CoercetonumberAbility", + "srcEntry": "./ets/coercetonumberability/CoercetonumberAbility.ets", + "description": "$string:CoercetonumberAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CoercetonumberAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..50f8113573dd8e92840d65b0b65004281b61a7eb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CoercetonumberAbility_desc", + "value": "description" + }, + { + "name": "CoercetonumberAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..01f8e96410f91b292e88b73c2b73699e04119829 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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('testCoerceToNumber', 0, async (done: Function) => { + console.log('uitest: TestCoerceToNumber begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CoercetonumberAbility' + } + 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('CoercetonumberAbility'); + + 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: TestCoerceToNumber end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f1fb390b304c4030444ac6f0f4e6555cbeca33f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/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": "coercetonumber_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d0290aa78befac75ef1d38df39d6757d5c1f2fd4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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": "coercetoobject", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcoercetoobject.so": "file:./src/main/cpp/types/libcoercetoobject" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..39a94fca6df64390f3c13b79ba0b3a8f7d5f8e56 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPrimitiveOne) + +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(coercetoobject SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(coercetoobject PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b926aab8144d3b0032a5a2ec55f0639062716ca2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/hello.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_coerce_to_object] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_coerce_to_object] +#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) +// [EndExclude oh_jsvm_coerce_to_object] + +// OH_JSVM_CoerceToObject的样例方法 +static JSVM_Value CoerceToObject(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value obj = nullptr; + JSVM_Status status = OH_JSVM_CoerceToObject(env, args[0], &obj); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_CoerceToObject failed"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToObject success"); + } + return obj; +} +// CoerceToObjec注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CoerceToObject}, +}; +static JSVM_CallbackStruct *method = param; +// CoerceToObject方法别名,ArkTS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"coerceToObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(coerceToObject(123))JS"; +// [End oh_jsvm_coerce_to_object] + +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 = "coercetoobject", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c8f5a610569d426c407ea92011df136628eeec73 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/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": "libcoercetoobject.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/coercetoobjectability/CoercetoobjectAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/coercetoobjectability/CoercetoobjectAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/coercetoobjectability/CoercetoobjectAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/coercetoobjectability/CoercetoobjectAbility.ets index 5c5635055535fd91d8df5a1403b64152057189d1..e4f782d492c8b9ea9f7c84f142a592d41d290a6f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/coercetoobjectability/CoercetoobjectAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/coercetoobjectability/CoercetoobjectAbility.ets @@ -1,56 +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 CoercetoobjectAbility 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'); - } -}; +/* + * 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 CoercetoobjectAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d412b0978190268f40b6c1c2c5f51eeb06d571d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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 'libcoercetoobject.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90d5f155b28c362a2b58335b98394c88582b764e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "coercetoobject", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CoercetoobjectAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CoercetoobjectAbility", + "srcEntry": "./ets/coercetoobjectability/CoercetoobjectAbility.ets", + "description": "$string:CoercetoobjectAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CoercetoobjectAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..15bf2a904381a5de6d5d8871c916ebab6234dfaf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CoercetoobjectAbility_desc", + "value": "description" + }, + { + "name": "CoercetoobjectAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..88e013b83f5c1b6499c7316f0a14347cfd586f1f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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('testCoerceToObject', 0, async (done: Function) => { + console.log('uitest: TestCoerceToObject begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CoercetoobjectAbility' + } + 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('CoercetoobjectAbility'); + + 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: TestCoerceToObject end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6bd3133055637f3346afe7981435fe4fe09f3523 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/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": "coercetoobject_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0e658fa97fd84655cc251d36bf1e1e6fd93615ca --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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": "coercetostring", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcoercetostring.so": "file:./src/main/cpp/types/libcoercetostring" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..33b18fc51061679d1d392c08a8dfb511bdae7dbb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(coercetostring SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(coercetostring PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..78878510f4698adbb9ac36eb36e6d90b9d13d0e5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/hello.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_coerce_to_string] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_coerce_to_string] +#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) +// [EndExclude oh_jsvm_coerce_to_string] + +// OH_JSVM_CoerceToString的样例方法 +static JSVM_Value CoerceToString(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value str = nullptr; + JSVM_Status status = OH_JSVM_CoerceToString(env, args[0], &str); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_CoerceToString fail"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToString success"); + } + return str; +} +// CoerceToString注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CoerceToString}, +}; +static JSVM_CallbackStruct *method = param; +// CoerceToString方法别名,ArkTS侧调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"coerceToString", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(coerceToString(22222))JS"; +// [End oh_jsvm_coerce_to_string] + +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 = "coercetostring", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c239252cc90b3ac394d8cd278e4d90d01b6809a3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/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": "libcoercetostring.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/coercetostringability/CoercetostringAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/coercetostringability/CoercetostringAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/coercetostringability/CoercetostringAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/coercetostringability/CoercetostringAbility.ets index da349f67a8b31c6de34cf4b8bf53f2dd2a050fda..ffbafce1af57adff0d83a2e88f94a811e20aa721 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/coercetostringability/CoercetostringAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/coercetostringability/CoercetostringAbility.ets @@ -1,56 +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 CoercetostringAbility 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'); - } -}; +/* + * 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 CoercetostringAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..ce2d63125e8724a62557b48c5c4a14e9dc9e247e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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 'libcoercetostring.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10e89833e3e22a0b4bb1395c3590b42068bd922a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "coercetostring", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CoercetostringAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CoercetostringAbility", + "srcEntry": "./ets/coercetostringability/CoercetostringAbility.ets", + "description": "$string:CoercetostringAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CoercetostringAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..bd1a49726a5776c88fe29f462547c7ce7930c8d1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CoercetostringAbility_desc", + "value": "description" + }, + { + "name": "CoercetostringAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d19394ce5c8866b545c05579f62f518487e25e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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('testCoerceToString', 0, async (done: Function) => { + console.log('uitest: TestCoerceToString begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CoercetostringAbility' + } + 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('CoercetostringAbility'); + + 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: TestCoerceToString end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6b5ba124ce76d2f4797bc01aee2c350ed286b7e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/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": "coercetostring_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/.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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3654c8deca14f73efd7ff9432e99c34463b13a73 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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": "getboolean", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetboolean.so": "file:./src/main/cpp/types/libgetboolean" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5434154e397ff44ee2f80f089f5f277f5effbf96 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getboolean SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getboolean PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7dd32588530a73cdb67c2d29fdfd7b9d9276dc09 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/hello.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_boolean] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_boolean] +#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) +// [EndExclude oh_jsvm_get_boolean] + +// OH_JSVM_GetBoolean的样例方法 +static JSVM_Value GetBoolean(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 传入两个参数并解析 + size_t argc = 2; + JSVM_Value argv[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + int32_t paramData = 0; + OH_JSVM_GetValueInt32(env, argv[0], ¶mData); + int32_t paramValue = 0; + OH_JSVM_GetValueInt32(env, argv[1], ¶mValue); + JSVM_Value returnValue = nullptr; + bool type = false; + if (paramData == paramValue) { + OH_LOG_INFO(LOG_APP, "JSVM resultType equal"); + type = true; + } + JSVM_Status status = OH_JSVM_GetBoolean(env, type, &returnValue); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_CoerceToNumber fail"); + } else { + bool result = false; + OH_JSVM_GetValueBool(env, returnValue, &result); + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToNumber success:%{public}d", result); + } + // 返回结果 + return returnValue; +} +// GetBoolean注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetBoolean}, +}; +static JSVM_CallbackStruct *method = param; +// GetBoolean方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getBoolean", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(getBoolean(1, 2))JS"; +// const char *SRC_CALL_NATIVE = R"JS(getBoolean(1, 1))JS"; +// [End oh_jsvm_get_boolean] + +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 = "getboolean", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c62d32f5c35555e3f255703bf3d7e55d83461781 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/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": "libgetboolean.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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/getbooleanability/GetbooleanAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/getbooleanability/GetbooleanAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/getbooleanability/GetbooleanAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/getbooleanability/GetbooleanAbility.ets index c0d77c773313647f793724d9295fa9c3e41acb82..261b6b314dac068c8ab123f5636b9208b2dacb99 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/getbooleanability/GetbooleanAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/getbooleanability/GetbooleanAbility.ets @@ -1,56 +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 GetbooleanAbility 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'); - } -}; +/* + * 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 GetbooleanAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..43b51fe15c6cfde2f77f0f601d8d733119c11118 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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 'libgetboolean.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..65f18d7732e73c47bd030fb12c7bffee13c0f180 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getboolean", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetbooleanAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetbooleanAbility", + "srcEntry": "./ets/getbooleanability/GetbooleanAbility.ets", + "description": "$string:GetbooleanAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetbooleanAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b154bf6f562df9d22e74aaf87be79d04f1315aab --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetbooleanAbility_desc", + "value": "description" + }, + { + "name": "GetbooleanAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca2482aa3ce45421d46c0516c41cb24af097520e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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('testGetBoolean', 0, async (done: Function) => { + console.log('uitest: TestGetBoolean begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetbooleanAbility' + } + 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('GetbooleanAbility'); + + 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: TestGetBoolean end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fd95e84ec930648d8169974e4757d78d88cc126e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/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": "getboolean_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/.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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7b5841f36f7d2531e0e34d9ac994ab6fbf2e32b4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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": "getglobal", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetglobal.so": "file:./src/main/cpp/types/libgetglobal" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..17a118953061efd24fb0f890d0f12a38d311d889 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getglobal SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getglobal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..337416b4d75166f21795681730942ea9392f8087 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/hello.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_global] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_global] +#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) +// [EndExclude oh_jsvm_get_global] + +// OH_JSVM_GetGlobal的样例方法 +static JSVM_Value GetGlobal(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取全局对象 + JSVM_Value value = nullptr; + JSVM_Value global = nullptr; + OH_JSVM_CreateInt32(env, 1, &value); + JSVM_Status status = OH_JSVM_GetGlobal(env, &global); + OH_JSVM_SetNamedProperty(env, global, "Row", value); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetGlobal fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetGlobal success"); + } + return global; +} +// GetGlobal注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetGlobal}, +}; +static JSVM_CallbackStruct *method = param; +// GetGlobal方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getGlobal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(getGlobal())JS"; +// [End oh_jsvm_get_global] + +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 = "getglobal", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..88e8f331acbee420605e3be711a97ab75fb02d95 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/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": "libgetglobal.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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/getglobalability/GetglobalAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/getglobalability/GetglobalAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/getglobalability/GetglobalAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/getglobalability/GetglobalAbility.ets index 9b526c52aa248df6ce20c292ad5b158577cf0d89..c61f2cc27a334f5ef125952027f6e23288d74bcc --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/getglobalability/GetglobalAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/getglobalability/GetglobalAbility.ets @@ -1,56 +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 GetglobalAbility 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'); - } -}; +/* + * 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 GetglobalAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d0605383bdf64a3f723ca3b2b3070c8b928e516 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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 'libgetglobal.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b5e64105ccd8616bcc89119cb9a8c6e04e6d2604 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "getglobal", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetglobalAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetglobalAbility", + "srcEntry": "./ets/getglobalability/GetglobalAbility.ets", + "description": "$string:GetglobalAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetglobalAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cdd44b9aa06645fb7ec24a28a0f2301d9cbc7f6e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetglobalAbility_desc", + "value": "description" + }, + { + "name": "GetglobalAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1068e965314ccc054879dd8b693561fc147ca25f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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('testGetGlobal', 0, async (done: Function) => { + console.log('uitest: TestGetGlobal begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetglobalAbility' + } + 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('GetglobalAbility'); + + 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: TestGetGlobal end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6fe66615a4a021864db9ff8e4bbf0a157929e870 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "getglobal_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/.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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aa2c7261d98b11eb436890f45111da6e3f524354 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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": "getnull", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetnull.so": "file:./src/main/cpp/types/libgetnull" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b4921e4229aca3512db6d1513958f7822ea72f52 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getnull SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getnull PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3e8d5f1efddfa8bf775d0c12f9405f097a8b0a74 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/hello.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_null] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_null] +#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) +// [EndExclude oh_jsvm_get_null] + +// GetNull注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetNull}, +}; +static JSVM_CallbackStruct *method = param; +// GetNull方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getNull", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// OH_JSVM_GetNull的样例方法 +static JSVM_Value GetNull(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value nullValue = nullptr; + JSVM_Status status = OH_JSVM_GetNull(env, &nullValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetNull fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetNull success"); + } + return nullValue; +} +// [End oh_jsvm_get_null] +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(getNull())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 = "getnull", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5dfd54979da4cc954d4e4e753dc2e873753790c5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/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": "libgetnull.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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/getnullability/GetnullAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/getnullability/GetnullAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/getnullability/GetnullAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/getnullability/GetnullAbility.ets index d4cbef99bace35155ff2ac6e19c6c3e9c6ba593c..3b1db3c5dce0af822b6f88a3e79c10f68c7a2825 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/getnullability/GetnullAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/getnullability/GetnullAbility.ets @@ -1,56 +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 GetnullAbility 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'); - } -}; +/* + * 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 GetnullAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..09ba916ba710749f1fec139db3fd688baeff6fc3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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 'libgetnull.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..086197ee7b17c1dc84a54594724032932907856a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "getnull", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetnullAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetnullAbility", + "srcEntry": "./ets/getnullability/GetnullAbility.ets", + "description": "$string:GetnullAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetnullAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..335bb4cf1648882a53584ef0f70ee84e3d81f2ee --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetnullAbility_desc", + "value": "description" + }, + { + "name": "GetnullAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f203e4a5c87f4e48e9bfa9399dfcc249c8343737 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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('testGetNull', 0, async (done: Function) => { + console.log('uitest: TestGetNull begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetnullAbility' + } + 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('GetnullAbility'); + + 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: TestGetNull end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3ebc4f295442faf1e6b287f17d6d3e77770643ba --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "getnull_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/.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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2704b7a1c24bf0ab485c75cf0d5e12db0be0d8d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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": "getundefined", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetundefined.so": "file:./src/main/cpp/types/libgetundefined" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..62d2397b1276b549d08dad89fa475951b1932f60 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getundefined SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getundefined PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..886c13bf8ec51132fa1a69b92d5ddcd44c2f9732 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_undefined] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_undefined] +#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) +// [EndExclude oh_jsvm_get_undefined] + +// GetUndefined注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetUndefined}, +}; +static JSVM_CallbackStruct *method = param; +// GetUndefined方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getUndefined", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// OH_JSVM_GetUndefined的样例方法 +static JSVM_Value GetUndefined(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取并解析传进的参数 + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 创建一个undefined值 + JSVM_Value value = nullptr; + JSVM_Status status = OH_JSVM_GetUndefined(env, &value); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetUndefined failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetUndefined success"); + } + return value; +} +// [End oh_jsvm_get_undefined] +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(getUndefined())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 = "getundefined", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5390bebd13757f9fb09f62d3a741bd6ca086f145 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/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": "libgetundefined.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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/getundefinedability/GetundefinedAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/getundefinedability/GetundefinedAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/getundefinedability/GetundefinedAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/getundefinedability/GetundefinedAbility.ets index 514e61f539dbf7615ffe243dcd9444f7142438a8..1dcce0364278e82d31393c0dc4c75a1c39ae5705 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/getundefinedability/GetundefinedAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/getundefinedability/GetundefinedAbility.ets @@ -1,56 +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 GetundefinedAbility 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'); - } -}; +/* + * 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 GetundefinedAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b300a0a348c5d2748eef6f02ac55b4ab279bc6a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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 'libgetundefined.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..80aaf8561ea8cc8a10e63821ffc83256a84fec58 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "getundefined", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetundefinedAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetundefinedAbility", + "srcEntry": "./ets/getundefinedability/GetundefinedAbility.ets", + "description": "$string:GetundefinedAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetundefinedAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..fc76dbea40a94722adb0222bcb2490d5760a1c37 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetundefinedAbility_desc", + "value": "description" + }, + { + "name": "GetundefinedAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4c92820a1e256a7395ad3a94cdd25363ed42aba7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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('testGetUndefined', 0, async (done: Function) => { + console.log('uitest: TestGetUndefined begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetundefinedAbility' + } + 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('GetundefinedAbility'); + + 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: TestGetUndefined end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fca546749f1c8ea4b14016cb48e82387bd2a6391 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "getundefined_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/.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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cac566efdba566922fdad8e81e1ad2d5d367c0e6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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": "getvaluebool", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluebool.so": "file:./src/main/cpp/types/libgetvaluebool" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e30c606abfacecca6c83465bdce6a6a97800d13 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +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) + +add_library(getvaluebool SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluebool PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5a600134ce7fd79787cc53e889933776b45623a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_bool] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_value_bool] +#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) +// [EndExclude oh_jsvm_get_value_bool] + +// GetValueBool注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueBool}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueBool方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueBool", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// OH_JSVM_GetValueBool的样例方法 +static JSVM_Value GetValueBool(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + bool result = false; + JSVM_Status status = OH_JSVM_GetValueBool(env, args[0], &result); + if (status == JSVM_BOOLEAN_EXPECTED || status != JSVM_OK) { + // 如果OH_JSVM_GetValueBool成功会返回JSVM_OK,如果传入一个非布尔值则会返回JSVM_BOOLEAN_EXPECTED + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetValueBool fail:%{public}d", status); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetValueBool success:%{public}d", result); + } + JSVM_Value boolJv = nullptr; + OH_JSVM_GetBoolean(env, result, &boolJv); + return boolJv; +} +// [End oh_jsvm_get_value_bool] +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(getValueBool("abc"))JS"; +// const char *SRC_CALL_NATIVE = R"JS(getValueBool(true))JS"; +// const char *SRC_CALL_NATIVE = R"JS(getValueBool(false))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 = "getvaluebool", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d7135bafaa50e4a65dfa39a139e3d7c2dd91073 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/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": "libgetvaluebool.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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/getvalueboolability/GetvalueboolAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/getvalueboolability/GetvalueboolAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/getvalueboolability/GetvalueboolAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/getvalueboolability/GetvalueboolAbility.ets index 9b932f88617ffcef1fe70d7f106c4aee91bddd12..db1edcc600efcc237b437d0b7b4de03c4228f810 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/getvalueboolability/GetvalueboolAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/getvalueboolability/GetvalueboolAbility.ets @@ -1,56 +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 GetvalueboolAbility 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'); - } -}; +/* + * 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 GetvalueboolAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..839aea8595991df33f6a36e4b2ef472c43d451bd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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 'libgetvaluebool.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c53c24198f1a1a2bb21a535c1320536b71182cae --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "getvaluebool", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetvalueboolAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetvalueboolAbility", + "srcEntry": "./ets/getvalueboolability/GetvalueboolAbility.ets", + "description": "$string:GetvalueboolAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetvalueboolAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8b441c740250d3504d82d114f0169da0aeccb67b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetvalueboolAbility_desc", + "value": "description" + }, + { + "name": "GetvalueboolAbility_label", + "value": "JsvmAboutPrimitive" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e81c81c336eb43be0bf7072e3b7f54e235f08329 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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('testGetValueBool', 0, async (done: Function) => { + console.log('uitest: TestGetValueBool begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetvalueboolAbility' + } + 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('GetvalueboolAbility'); + + 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: TestGetValueBool end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6bbc2c38a34c09f37ed6a1d0e7b6df8bcfde7978 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "getvaluebool_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/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/JsvmUsageGuide/JsvmAboutPrimitive/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..55b42fcca911e345ee7141dce598971ce4fbfd06 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/ohosTest.md @@ -0,0 +1,16 @@ +# JsvmAboutPrimitive 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 将目标值转换为Boolean类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 将目标值转换为Number类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 将目标值转换为Object类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 将目标值转换为String类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取JavaScript单例对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取当前环境中的全局global对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取JavaScript null | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取JavaScript undefined | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript Boolean的C布尔基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/screenshots/JsvmAboutPrimitive_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71b860edb4a68bee69990406803a34e9e941af4a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/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.jsvmaboutpromise", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a5110316462c3cd08ca48bc5c489a70d4ba7cbfc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutPromise" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1bb1c761bf759ce4a7ea6a30093b0432d61517dc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/README.md @@ -0,0 +1,93 @@ +# ArkTS使用JSVM-API接口处理异步操作 + +### 介绍 + +使用JSVM-API接口处理异步操作。异步操作是指需要一定时间才能完成的操作,例如从网络下载数据或读取大型文件。与同步操作不同,异步操作不会阻塞主线程,而是会在后台执行。当异步操作完成后,事件循环将把它放入任务队列中,等待主线程空闲时执行。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口处理异步操作](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-promise.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +|:--------------------------------------------------------------------:|:--------------------------------------------------------------------:| +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +ispromise/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +resolvereject/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutPromise > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a0f429ebde3243f20488636ad52914f8fad8968b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/build-profile.json5 @@ -0,0 +1,70 @@ +/* + * 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": "ispromise", + "srcPath": "./ispromise", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "resolvereject", + "srcPath": "./resolvereject", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/.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/JsvmUsageGuide/JsvmAboutPromise/ispromise/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPromise/ispromise/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bcc8778338ccd731ac0e51f2bdf3e8c84d9d1485 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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": "ispromise", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libispromise.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e647ce8e15d09a54a3a12666f1311fe39aacefc1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPromise) + +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) + +add_library(ispromise SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(ispromise PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f945813dfa4f721a1550a92d85eb2b7119610825 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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. + */ + +// [Start oh_jsvm_ispromise] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [EndExclude oh_jsvm_ispromise] +#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) +// [EndExclude oh_jsvm_ispromise] + +// OH_JSVM_IsPromise的样例方法 +static JSVM_Value IsPromise(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + bool isPromise = false; + JSVM_Status status = OH_JSVM_IsPromise(env, args[0], &isPromise); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_IsPromise fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_IsPromise success:%{public}d", isPromise); + } + JSVM_Value result = nullptr; + OH_JSVM_GetBoolean(env, isPromise, &result); + return result; +} +// IsPromise注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = IsPromise}, +}; +static JSVM_CallbackStruct *method = param; +// IsPromise方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"isPromise", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(isPromise())JS"; +// [End oh_jsvm_ispromise] + +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 = "ispromise", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..707408e357296ba0f66dfe1cf27499b3b0202b2c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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": "libispromise.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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6b05ea2e7e2859cec0713ea7ad73f4b6ddfe6f15 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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 'libispromise.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71b05a2821f709b7c21afb01c7fc08c3bc779b4c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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": "ispromise", + "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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fff774cdd338fe5c8d6a4f6fa8755bebc09a45e0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/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": "ispromise_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/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/JsvmUsageGuide/JsvmAboutPromise/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..55a080857346281ad06a712a3e942064ad952205 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ohosTest.md @@ -0,0 +1,9 @@ +# JsvmAboutDate 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------- | ------------ | ------------------------ | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 查询Promise是否为Promise对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 通过与之关联的延迟对象来解析JavaScript promise | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/.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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b3562ec8fe355ea6be4469d92d4109d0214cd045 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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": "resolvereject", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libresolvereject.so": "file:./src/main/cpp/types/libresolvereject" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d08cc789ed1300d8f38176a7582dfce1cd36cb7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPromise) + +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) + +add_library(resolvereject SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(resolvereject PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e5bef1b3757e29cf3b51902b9f5e9c32f0e1005a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/hello.cpp @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_resolvedeferred_and_rejectdeferred] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_resolvedeferred_and_rejectdeferred] +#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) +// [EndExclude oh_jsvm_resolvedeferred_and_rejectdeferred] + +// OH_JSVM_CreatePromise、OH_JSVM_ResolveDeferred、OH_JSVM_RejectDeferred的样例方法 +static JSVM_Value CreatePromise(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Deferred defer = nullptr; + JSVM_Value promise = nullptr; + JSVM_Status status = OH_JSVM_CreatePromise(env, &defer, &promise); + bool isPromise = false; + JSVM_Value returnIsPromise = nullptr; + OH_JSVM_IsPromise(env, promise, &isPromise); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreatePromise fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreatePromise success:%{public}d", isPromise); + } + // 将布尔值转为可以返回的JSVM_Value + OH_JSVM_GetBoolean(env, isPromise, &returnIsPromise); + return returnIsPromise; +} + +static JSVM_Value ResolveRejectDeferred(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获得并解析参数 + size_t argc = 3; + JSVM_Value args[3] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 第一个参数为向resolve传入的信息,第二个参数为向reject传入的信息,第三个参数为Promise的状态 + bool status = false; + OH_JSVM_GetValueBool(env, args[2], &status); + // 创建Promise对象 + JSVM_Deferred deferred = nullptr; + JSVM_Value promise = nullptr; + JSVM_Status createStatus = OH_JSVM_CreatePromise(env, &deferred, &promise); + if (createStatus != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "Create promise failed"); + return nullptr; + } + // 根据第三个参数设置resolve或reject + if (status) { + OH_JSVM_ResolveDeferred(env, deferred, args[0]); + OH_LOG_INFO(LOG_APP, "OH_JSVM_ResolveDeferred resolve"); + } else { + OH_JSVM_RejectDeferred(env, deferred, args[1]); + OH_LOG_INFO(LOG_APP, "OH_JSVM_RejectDeferred reject"); + } + JSVM_Value result = nullptr; + OH_JSVM_GetBoolean(env, true, &result); + return result; +} +// CreatePromise,ResolveRejectDeferred注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreatePromise}, + {.data = nullptr, .callback = ResolveRejectDeferred}, +}; +static JSVM_CallbackStruct *method = param; +// CreatePromise,ResolveRejectDeferred方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createPromise", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + {"resolveRejectDeferred", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE_CREATE_PROMISE = R"JS(createPromise())JS"; +const char *SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED1 = R"JS(resolveRejectDeferred('success','fail', true))JS"; +const char *SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED2 = R"JS(resolveRejectDeferred('success','fail', false))JS"; +// [End oh_jsvm_resolvedeferred_and_rejectdeferred] + +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_CREATE_PROMISE, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CreateStringUtf8(env, SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED1, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CreateStringUtf8(env, SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED2, 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 = "resolvereject", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7d2e60a9d671fd0303863bfe5e43fe38d43e068e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/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": "libresolvereject.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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..88be5d10c014ec407c3e88106abe24ea32700f10 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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 'libresolvereject.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/resolverejectability/ResolverejectAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/resolverejectability/ResolverejectAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/resolverejectability/ResolverejectAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/resolverejectability/ResolverejectAbility.ets index d0c5f17885a91c17e7999f36445bbe3b684f8695..ab6c16a445d02d9e91baf61403628522ff2161fe --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/resolverejectability/ResolverejectAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/resolverejectability/ResolverejectAbility.ets @@ -1,56 +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 ResolverejectAbility 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'); - } -}; +/* + * 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 ResolverejectAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4ca7fde00d542389fdc9cdd7fe7f4f55eb475a31 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "resolvereject", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ResolverejectAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ResolverejectAbility", + "srcEntry": "./ets/resolverejectability/ResolverejectAbility.ets", + "description": "$string:ResolverejectAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ResolverejectAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..76eb1ad89d26e4a2dfeb456faed39cb817368fe0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/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": "resolvereject_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/screenshots/JsvmAboutPromise_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0c4891ad144e5c3d9a9c08cd66146fa9ece4aaf2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/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.jsvmaboutproperty", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..64d18ea938ce3945542ac6ce460d164571e9b212 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutProperty" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1fbf681171109ab4b8e748df4c7f9e0c6e4c32b7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/README.md @@ -0,0 +1,273 @@ +# ArkTs使用JSVM-API接口设置JavaScript对象的属性 + +### 介绍 + +使用JSVM-API接口获取和设置JavaScript对象的属性。通过合理使用这些函数,实现更复杂的功能和逻辑。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口设置JavaScript对象的属性](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-property.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-------------------------------------------------------------------: | :-------------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +defineproperties/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +deleteproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getallpropertynames/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getnamedproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getpropertynames/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +hasnamedproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +hasownproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +hasproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +setnamedproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +setproperty/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutProperty > .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/JsvmUsageGuide/JsvmAboutProperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c36837826c9e80a086c1b96c41145a4125f93f99 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/build-profile.json5 @@ -0,0 +1,178 @@ +/* + * 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": "getpropertynames", + "srcPath": "./getpropertynames", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getproperty", + "srcPath": "./getproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "deleteproperty", + "srcPath": "./deleteproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getnamedproperty", + "srcPath": "./getnamedproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "defineproperties", + "srcPath": "./defineproperties", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getallpropertynames", + "srcPath": "./getallpropertynames", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "setproperty", + "srcPath": "./setproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "hasproperty", + "srcPath": "./hasproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "hasownproperty", + "srcPath": "./hasownproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "setnamedproperty", + "srcPath": "./setnamedproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "hasnamedproperty", + "srcPath": "./hasnamedproperty", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/.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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..25cd3b53558e03890f999d6db503aaba13589b48 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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": "defineproperties", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libdefineproperties.so": "file:./src/main/cpp/types/libdefineproperties" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6dab316b05832d38a6d52fe12f6e9860d6c66599 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(defineproperties SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(defineproperties PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0816302d41e0f9b22ad1734aeae73151793a05a4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/hello.cpp @@ -0,0 +1,257 @@ +/* + * 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" +#include +#include + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" +#define MAX_MALLOC_SIZE 0x800000 + +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) + +// [Start oh_jsvm_define_properties] +// 属性描述符列表中defineMethodPropertiesExample属性的回调函数 +static JSVM_Value DefineMethodPropertiesExample(JSVM_Env env, JSVM_CallbackInfo info) +{ + int32_t propValue = 26; + JSVM_Value returnValue; + OH_JSVM_CreateInt32(env, propValue, &returnValue); + return returnValue; +} +// 属性描述符列表中getterCallback属性的回调函数 +static JSVM_Value GetterCallback(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value result; + const char *str = "Hello world!"; + size_t length = strlen(str); + // 创建属性的值 + OH_JSVM_CreateStringUtf8(env, str, length, &result); + return result; +} + +// 执行JavaScript字符串的函数 +static JSVM_Value RunScriptAndLogResult(JSVM_Env env, const std::string &srcCode) +{ + JSVM_Value sourceCodeValue; + OH_JSVM_CreateStringUtf8(env, srcCode.c_str(), srcCode.size(), &sourceCodeValue); + JSVM_Script script; + // 编译JavaScript代码字符串并返回编译后的脚本 + OH_JSVM_CompileScript(env, sourceCodeValue, nullptr, 0, true, nullptr, &script); + JSVM_Value jsVmResult; + // 执行JavaScript代码字符串 + OH_JSVM_RunScript(env, script, &jsVmResult); + return jsVmResult; +} + +// OH_JSVM_DefineProperties的样例方法 +static JSVM_Value DefineProperties(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接受一个JavaScript侧传入的空object + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + // 创建一个string类型的属性值 + JSVM_Value stringValue; + OH_JSVM_CreateStringUtf8(env, "Hello!", JSVM_AUTO_LENGTH, &stringValue); + // 创建属性描述符对应的回调函数列表 + JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = DefineMethodPropertiesExample}, + {.data = nullptr, .callback = GetterCallback}, + + }; + // 创建属性描述符列表,不同类型属性值添加位置参考JSVM_PropertyDescriptor定义 + JSVM_PropertyDescriptor descriptor[] = { + // 定义method类型的属性值 + {"defineMethodPropertiesExample", nullptr, ¶m[0], nullptr, nullptr, nullptr, JSVM_DEFAULT}, + // 定义string类型的属性值 + {"defineStringPropertiesExample", nullptr, nullptr, nullptr, nullptr, stringValue, JSVM_DEFAULT}, + // 定义getter类型的属性值 + {"getterCallback", nullptr, nullptr, ¶m[1], nullptr, nullptr, JSVM_DEFAULT}}; + // 根据属性描述符列表为obj对象创建属性 + JSVM_Status statusProperty = OH_JSVM_DefineProperties(env, + *argv, + sizeof(descriptor) / sizeof(descriptor[0]), + descriptor); + if (statusProperty != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM DefineProperties fail"); + return nullptr; + } + // 调用obj对象中添加的属性 + // 运行obj.defineMethodPropertiesExample()并将结果返回给JavaScript + std::string srcMethod = R"JS(obj.defineMethodPropertiesExample();)JS"; + JSVM_Value jsVmResult = RunScriptAndLogResult(env, srcMethod); + if (jsVmResult != nullptr) { + int32_t number; + OH_JSVM_GetValueInt32(env, jsVmResult, &number); + OH_LOG_INFO(LOG_APP, "JSVM DefineMethodPropertiesExample success:%{public}d", number); + } + // 运行obj.defineStringPropertiesExample()并将结果返回给JavaScript + static std::string srcString = R"JS(obj.defineStringPropertiesExample;)JS"; + JSVM_Value jsVmResult1 = RunScriptAndLogResult(env, srcString); + if (jsVmResult1 != nullptr) { + size_t length = 0; + OH_JSVM_GetValueStringUtf8(env, jsVmResult1, nullptr, 0, &length); + if (length == 0 || length > MAX_MALLOC_SIZE) { + OH_LOG_ERROR(LOG_APP, "Invalid string length: %{public}zu", length); + return jsVmResult; + } + char *buf = (char *)malloc(length + 1); + OH_JSVM_GetValueStringUtf8(env, jsVmResult1, buf, length + 1, &length); + OH_LOG_INFO(LOG_APP, "JSVM defineStringPropertiesExample success:%{public}s", buf); + free(buf); + } + // 调用obj的getterCallback()并将结果字符串返回给JavaScript + static std::string srcGetter = R"JS(obj.getterCallback;)JS"; + JSVM_Value jsVmResult2 = RunScriptAndLogResult(env, srcGetter); + if (jsVmResult2 != nullptr) { + size_t length = 0; + OH_JSVM_GetValueStringUtf8(env, jsVmResult2, nullptr, 0, &length); + OH_JSVM_GetValueStringUtf8(env, jsVmResult1, nullptr, 0, &length); + if (length == 0 || length > MAX_MALLOC_SIZE) { + OH_LOG_ERROR(LOG_APP, "Invalid string length: %{public}zu", length); + return jsVmResult; + } + char *buf = (char *)malloc(length + 1); + OH_JSVM_GetValueStringUtf8(env, jsVmResult2, buf, length + 1, &length); + OH_LOG_INFO(LOG_APP, "JSVM getterCallback success:%{public}s", buf); + free(buf); + } + return jsVmResult; +} + +// DefineProperties注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = DefineProperties}, +}; +static JSVM_CallbackStruct *method = param; +// DefineProperties方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"defineProperties", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = {}; + defineProperties(obj) +)JS"; +// [End oh_jsvm_define_properties] + +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 = "defineproperties", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..710ab15309650a8cea37526fcc4d27cd4620a9de --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/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": "libdefineproperties.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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/definepropertiesability/DefinepropertiesAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/definepropertiesability/DefinepropertiesAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/definepropertiesability/DefinepropertiesAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/definepropertiesability/DefinepropertiesAbility.ets index 009e78ebcd79ee6b9551f5c41dd2ec6d25510fa0..749d8a72ea436f34f645eee84c1e680f4815cf82 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/definepropertiesability/DefinepropertiesAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/definepropertiesability/DefinepropertiesAbility.ets @@ -1,56 +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 DefinepropertiesAbility 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'); - } -}; +/* + * 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 DefinepropertiesAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..852bf54d05b6db3f667570e75fd10ab4b72fb429 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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 'libdefineproperties.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a83b27d31234e7ff997725821a71ee680a414ba9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "defineproperties", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "DefinepropertiesAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "DefinepropertiesAbility", + "srcEntry": "./ets/definepropertiesability/DefinepropertiesAbility.ets", + "description": "$string:DefinepropertiesAbility_desc", + "icon": "$media:layered_image", + "label": "$string:DefinepropertiesAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f18a7b148c64f2507c5f8ae0be57389f2c993429 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "DefinepropertiesAbility_desc", + "value": "description" + }, + { + "name": "DefinepropertiesAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d008fe49316e44ac62ef1f907552150e5a58c7ef --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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('testDefineProperties', 0, async (done: Function) => { + console.log('uitest: TestDefineProperties begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'DefinepropertiesAbility' + } + 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('DefinepropertiesAbility'); + + 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: TestDefineProperties end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7f0304213fd029544b34175970ebeb1c443bf015 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/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": "defineproperties_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/.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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7fb26b79ca413ee4636b80f3524f30cd77e6504 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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": "deleteproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libdeleteproperty.so": "file:./src/main/cpp/types/libdeleteproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ae8663537b8bd8811d237d88bafb31d69e5bda6c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(deleteproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(deleteproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d375545847f355cca3092a76f1193c79be49aac --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/hello.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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) + +// [Start oh_jsvm_delete_property] +// OH_JSVM_DeleteProperty的样例方法 +static JSVM_Value DeleteProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_ValueType valueType; + OH_JSVM_Typeof(env, args[0], &valueType); + if (valueType != JSVM_OBJECT) { + OH_JSVM_ThrowError(env, nullptr, "Expects an object as argument."); + return nullptr; + } + // 从传入的Object对象中删除指定属性,返回是否删除成功的bool结果值 + bool result = false; + JSVM_Status status = OH_JSVM_DeleteProperty(env, args[0], args[1], &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_DeleteProperty failed"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_DeleteProperty success:%{public}d", result); + } + // 将bool结果转换为JSVM_value并返回 + JSVM_Value ret; + OH_JSVM_GetBoolean(env, result, &ret); + return ret; +} +// DeleteProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = DeleteProperty}, +}; +static JSVM_CallbackStruct *method = param; +// DeleteProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"deleteProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + deleteProperty(obj, "message") +)JS"; +// [End oh_jsvm_delete_property] + +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 = "deleteproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c7abd6bc79771f585ea06c8ab65284eecb2e9ee0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/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": "libdeleteproperty.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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/deletepropertyability/DeletepropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/deletepropertyability/DeletepropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/deletepropertyability/DeletepropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/deletepropertyability/DeletepropertyAbility.ets index 65df077589e72656a23b3bc7e98cb70379c731c1..d8c5eb971639b23199cc83b59eaef8ae6bfd32b3 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/deletepropertyability/DeletepropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/deletepropertyability/DeletepropertyAbility.ets @@ -1,56 +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 DeletepropertyAbility 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'); - } -}; +/* + * 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 DeletepropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b94ebea74230f957085188bb5679ed827b5ca538 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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 'libdeleteproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f7ba360423f48f1fe4577f2c637b6c5fc88d89b0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "deleteproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "DeletepropertyAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "DeletepropertyAbility", + "srcEntry": "./ets/deletepropertyability/DeletepropertyAbility.ets", + "description": "$string:DeletepropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:DeletepropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8465ed8521db075ec583c8076aa6a5d7241c6b61 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "DeletepropertyAbility_desc", + "value": "description" + }, + { + "name": "DeletepropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..54839fe37e9e2ae98482821ae33185fbffc4c7cb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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('testDeleteProperty', 0, async (done: Function) => { + console.log('uitest: TestDeleteProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'DeletepropertyAbility' + } + 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('DeletepropertyAbility'); + + 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: TestDeleteProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d2f9fb4e8d7a26713fc3958f1377ba7b5b7aca29 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/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": "deleteproperty_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/.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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..42c4974bcb397675bb910b4bbb5540ba651b91cc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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": "getallpropertynames", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetallpropertynames.so": "file:./src/main/cpp/types/libgetallpropertynames" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dddd5f5e2026c9307c176214d471781551e1c881 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(getallpropertynames SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getallpropertynames PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f3603c467037a163831643dd7abbd9b53e47508 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/hello.cpp @@ -0,0 +1,166 @@ +/* + * 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) + +// [Start oh_jsvm_get_all_property_names] +// OH_JSVM_GetAllPropertyNames的样例方法 +static JSVM_Value GetAllPropertyNames(JSVM_Env env, JSVM_CallbackInfo info) +{ + // // 获取js侧传入的一个参数 + size_t argc = 1; + JSVM_Value args[1]; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取给定对象的所有属性名称(自有属性) + JSVM_Value result; + JSVM_Status status = OH_JSVM_GetAllPropertyNames(env, args[0], + JSVM_KeyCollectionMode::JSVM_KEY_O_ONLY, + JSVM_KeyFilter::JSVM_KEY_WRITABLE, + JSVM_KeyConversion::JSVM_KEY_NUMBERS_TO_STRINGS, &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "Failed to get allpropertynames"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetAllPropertyNames success"); + } + return result; +} +// GetAllPropertyNames注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetAllPropertyNames}, +}; +static JSVM_CallbackStruct *method = param; +// GetAllPropertyNames方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getAllPropertyNames", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = '{ data: 0, message: "hello world", 50: 1}'; + let script = getAllPropertyNames(obj); +)JS"; +// [End oh_jsvm_get_all_property_names] + +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 = "getallpropertynames", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bf650222f63023c8d241ec0cc69d591e4ed12ddf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/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": "libgetallpropertynames.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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/getallpropertynamesability/GetallpropertynamesAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/getallpropertynamesability/GetallpropertynamesAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/getallpropertynamesability/GetallpropertynamesAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/getallpropertynamesability/GetallpropertynamesAbility.ets index 7721b55d683ae9dfbcbed117cc0c1fadb0fdbae2..12dcb64dcc33babd53c80a443a5f8f884391ae52 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/getallpropertynamesability/GetallpropertynamesAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/getallpropertynamesability/GetallpropertynamesAbility.ets @@ -1,56 +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 GetallpropertynamesAbility 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'); - } -}; +/* + * 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 GetallpropertynamesAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6f9b27ce3dc8c81160fd7166a034dbdd8f0b0ae5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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 'libgetallpropertynames.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_GetAllPropertyNames'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b93bf158ee7561d3e44d88ba2cdac14f5ddcff48 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getallpropertynames", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetallpropertynamesAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetallpropertynamesAbility", + "srcEntry": "./ets/getallpropertynamesability/GetallpropertynamesAbility.ets", + "description": "$string:GetallpropertynamesAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetallpropertynamesAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5312574924688346fb3acacc71d6b7afa06d7c8a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetallpropertynamesAbility_desc", + "value": "description" + }, + { + "name": "GetallpropertynamesAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..568b414f12aafad3484cd0bef381bc09a5181d70 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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('testGetAllPropertyNames', 0, async (done: Function) => { + console.log('uitest: TestGetAllPropertyNames begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetallpropertynamesAbility' + } + 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('GetallpropertynamesAbility'); + + 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: TestGetAllPropertyNames end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..74e9dc18bc10eb2532a228ea6ae10fd5514ffb4b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/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": "getallpropertynames_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/.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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d9a8c8ec95cdff1d3be0e46f7d830a8debc48ddd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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": "getnamedproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetnamedproperty.so": "file:./src/main/cpp/types/libgetnamedproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..56df704efeae570392c065e17094402ec2fca036 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(getnamedproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getnamedproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27e398df1f077fb186b41582eec1d4214f928fdc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/hello.cpp @@ -0,0 +1,168 @@ +/* + * 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 "ark_runtime/jsvm.h" +#include "hilog/log.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) + +// [Start oh_jsvm_get_named_property] +// OH_JSVM_GetNamedProperty的样例方法 +const size_t MAX_KEY_LENGTH = 32; +static JSVM_Value GetNamedProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + char strKey[MAX_KEY_LENGTH] = ""; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取要获取的属性名 + size_t keyLength; + OH_JSVM_GetValueStringUtf8(env, args[1], strKey, MAX_KEY_LENGTH, &keyLength); + // 获取指定属性的值并存储在result中 + JSVM_Value result; + JSVM_Status status = OH_JSVM_GetNamedProperty(env, args[0], strKey, &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_GetNamedProperty failed"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetNamedProperty success"); + } + return result; +} +// GetNamedProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetNamedProperty}, +}; +static JSVM_CallbackStruct *method = param; +// GetNamedProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getNamedProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + getNamedProperty(obj, "message") +)JS"; +// [End oh_jsvm_get_named_property] + +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 = "getnamedproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..86fbcae9a1416992e1ec6c34235000d8b05b9c13 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/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": "libgetnamedproperty.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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/getnamedpropertyability/GetnamedpropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/getnamedpropertyability/GetnamedpropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/getnamedpropertyability/GetnamedpropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/getnamedpropertyability/GetnamedpropertyAbility.ets index 8a5e585206df54cb36fbf708ea0b243cd22fb37d..da89e6399305b705021ed4ce153eebb371580179 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/getnamedpropertyability/GetnamedpropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/getnamedpropertyability/GetnamedpropertyAbility.ets @@ -1,56 +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 GetnamedpropertyAbility 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'); - } -}; +/* + * 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 GetnamedpropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e6d8624a9ecc33f58561ae808d2edcdc451f694 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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 'libgetnamedproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5ee6d3e7e38eb040d39a92f82b6f6a1c6011f64b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getnamedproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetnamedpropertyAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetnamedpropertyAbility", + "srcEntry": "./ets/getnamedpropertyability/GetnamedpropertyAbility.ets", + "description": "$string:GetnamedpropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetnamedpropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d26d5177167c0b2a2654664f9424d43e3d094573 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetnamedpropertyAbility_desc", + "value": "description" + }, + { + "name": "GetnamedpropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..653253a107d94ec9c1da43ba1f28c33565d0fabc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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('testGetNamedProperty', 0, async (done: Function) => { + console.log('uitest: TestGetNamedProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetnamedpropertyAbility' + } + 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('GetnamedpropertyAbility'); + + 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: TestGetNamedProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b3e3350a842df43bc8e4d5330facb7ba1a6281cd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/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": "getnamedproperty_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/.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/JsvmUsageGuide/JsvmAboutProperty/getproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/getproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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/JsvmUsageGuide/JsvmAboutProperty/getproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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/JsvmUsageGuide/JsvmAboutProperty/getproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e92939fc442913bab8ca2f39640fe1f1a6d54662 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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": "getproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetproperty.so": "file:./src/main/cpp/types/libgetproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc0ca19546bc0921776d867bf8b2296d37de0005 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPropertyOne) + +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) + +add_library(getproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c4a2052105293182acdf03694118d2ebfb5bd34 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * 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) + +// [Start oh_jsvm_get_property] +// OH_JSVM_GetProperty的样例方法 +static JSVM_Value GetProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接收两个js传来的参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 传入的第一个参数为要检测的object,第二个对象为要检测的属性,通过调用OH_JSVM_GetProperty接口获取对应的值 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetProperty(env, args[0], args[1], &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_GetProperty fail"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetProperty success"); + } + return result; +} +// GetProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetProperty}, +}; +static JSVM_CallbackStruct *method = param; +// GetProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + getProperty(obj, "message") +)JS"; +// [End oh_jsvm_get_property] + +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 = "getproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7d7e24664065e6522a70c1fd550efc0b22077a8f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/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": "libgetproperty.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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/getpropertyability/GetpropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/getpropertyability/GetpropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/getpropertyability/GetpropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/getpropertyability/GetpropertyAbility.ets index 555f5ba18a7eea060b27a4fbee5946d1621641d5..ee69dcb61d7fce0b1c4226b73b0a618e45849c10 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/getpropertyability/GetpropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/getpropertyability/GetpropertyAbility.ets @@ -1,56 +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 GetpropertyAbility 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'); - } -}; +/* + * 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 GetpropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b32ce360e2b6e5c0e1b3c360fb61dd24fdde1ca3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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 'libgetproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..06ee603a1bc3cfb080834a5133f04c45e3ecd745 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetpropertyAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetpropertyAbility", + "srcEntry": "./ets/getpropertyability/GetpropertyAbility.ets", + "description": "$string:GetpropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetpropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c402a0e57513ba5ab54ef60989d4e7aeb92c18e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetpropertyAbility_desc", + "value": "description" + }, + { + "name": "GetpropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c5af891cc641ba6515b56ad772baa578cd597854 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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('testGetProperty', 0, async (done: Function) => { + console.log('uitest: TestGetProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetpropertyAbility' + } + 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('GetpropertyAbility'); + + 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: TestGetProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2bc62a8afd027b6accd811d1a1d0e3ce9bc7b600 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/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": "getproperty_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/.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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d8ac2accaf5c81eb8794f2490b0c9b2da23d2353 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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": "getpropertynames", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetpropertynames.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4546d46454ba2375aa4c83606ebc602b1e47b314 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPropertyOne) + +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) + +add_library(getpropertynames SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getpropertynames PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbf79e1814442f39913543ad3a9dc86341b4f450 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * 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) + +// [Start oh_jsvm_get_property_names] +// OH_JSVM_GetPropertyNames的样例方法 +static JSVM_Value GetPropertyNames(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 将obj作为参数传入 + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 以字符串数组的形式获取对象的可枚举属性的名称,以result传出 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetPropertyNames(env, args[0], &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "Failed to get propertynames"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetPropertyNames success"); + } + return result; +} +// GetPropertyNames注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetPropertyNames}, +}; +static JSVM_CallbackStruct *method = param; +// GetPropertyNames方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getPropertyNames", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = '{ data: 0, message: "hello world"}'; + let script = getPropertyNames(obj); +)JS"; +// [End oh_jsvm_get_property_names] + +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 = "getpropertynames", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a55ca35c9e174941b7c70c4564d033202b63cf22 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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": "libgetpropertynames.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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b9f77ef80afe9b61cc5f8dc6ae2707a9828db563 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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 'libgetpropertynames.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..778f1d8bd1e948d0260215a4dcafac9383f647fb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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": "getpropertynames", + "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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1fb1f941578b22e364953323a32ac7b001b6d733 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..668e57697d7c1de1bf2ff11e40633f224ba67bba --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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('testGetPropertyNames', 0, async (done: Function) => { + console.log('uitest: TestGetPropertyNames 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: TestGetPropertyNames end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..08449f7be7094146d6a4c4812b518798bbe9eb5c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/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": "getpropertynames_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/.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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cf1fafa36b910633acec8d147e3839b0a17ac733 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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": "hasnamedproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libhasnamedproperty.so": "file:./src/main/cpp/types/libhasnamedproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..395b46e09c4a169c5dc2693635a3e7b0887d183f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(hasnamedproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(hasnamedproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d75ad1e0ba37aa0a817e2bc40513c38df9e4d767 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/hello.cpp @@ -0,0 +1,171 @@ +/* + * 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) + +// [Start oh_jsvm_has_named_property] +// OH_JSVM_HasNamedProperty的样例方法 +const size_t STR_KEY_LEN = 32; +static JSVM_Value HasNamedProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + char strKey[STR_KEY_LEN] = ""; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 获取要检查的属性名 + size_t keyLength; + OH_JSVM_GetValueStringUtf8(env, args[1], strKey, STR_KEY_LEN, &keyLength); + // 检查对象是否具有指定命名的属性,并将结果存储在hasProperty中 + bool hasProperty = false; + JSVM_Status status = OH_JSVM_HasNamedProperty(env, args[0], strKey, &hasProperty); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_HasNamedProperty failed"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_HasNamedProperty success:%{public}d", hasProperty); + } + // 将bool结果转换为JSVM_Value并返回 + JSVM_Value result; + OH_JSVM_GetBoolean(env, hasProperty, &result); + return result; +} +// HasNamedProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = HasNamedProperty}, +}; +static JSVM_CallbackStruct *method = param; +// HasNamedProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"hasNamedProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + hasNamedProperty(obj, "message") +)JS"; +// [End oh_jsvm_has_named_property] + +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 = "hasnamedproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cec57929cdb14006c0766a8365dc8167d704d5b8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/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": "libhasnamedproperty.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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/hasnamedpropertyability/HasnamedpropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/hasnamedpropertyability/HasnamedpropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/hasnamedpropertyability/HasnamedpropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/hasnamedpropertyability/HasnamedpropertyAbility.ets index 3818d1d9b53911271846011487264aa735c65f1a..f0a3a72706651fa3ec7a9375a57dd10c9302f108 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/hasnamedpropertyability/HasnamedpropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/hasnamedpropertyability/HasnamedpropertyAbility.ets @@ -1,56 +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 HasnamedpropertyAbility 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'); - } -}; +/* + * 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 HasnamedpropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f700231cbecdb0495c08d32210f9de9a3c754015 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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 'libhasnamedproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5ce858194fea57278ac9679f0bbf352df5317aa1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "hasnamedproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "HasnamedpropertyAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "HasnamedpropertyAbility", + "srcEntry": "./ets/hasnamedpropertyability/HasnamedpropertyAbility.ets", + "description": "$string:HasnamedpropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:HasnamedpropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a5607b54b5eb3d10df277f010ae0993eabee9812 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "HasnamedpropertyAbility_desc", + "value": "description" + }, + { + "name": "HasnamedpropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..584048aa60bdf42f6d7c556fedbccd814ad41b32 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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('testHasNamedProperty', 0, async (done: Function) => { + console.log('uitest: TestHasNamedProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'HasnamedpropertyAbility' + } + 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('HasnamedpropertyAbility'); + + 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: TestHasNamedProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce195d251d6f2b936b89f08c151a19724693bdf1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "hasnamedproperty_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/.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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a276285db6df023ad6ad880be2ef6b5311299757 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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": "hasownproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libhasownproperty.so": "file:./src/main/cpp/types/libhasownproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..945aa4eaab769ca88f45715343a9c8b7a0fe7e34 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(hasownproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(hasownproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45d47c53644228f5f32a415dc9b3105017650d76 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/hello.cpp @@ -0,0 +1,181 @@ +/* + * 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) + +// [Start oh_jsvm_has_own_property] +// OH_JSVM_HasOwnProperty的样例方法 +static JSVM_Value HasOwnProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的两个参数 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 检查第一个参数是否为对象 + JSVM_ValueType valueType1; + OH_JSVM_Typeof(env, args[0], &valueType1); + if (valueType1 != JSVM_OBJECT) { + OH_JSVM_ThrowError(env, nullptr, "First argument must be an object."); + return nullptr; + } + // 检查第二个参数是否为string + JSVM_ValueType valuetype2; + OH_JSVM_Typeof(env, args[1], &valuetype2); + if (valuetype2 != JSVM_STRING) { + OH_JSVM_ThrowError(env, nullptr, "Second argument must be a string."); + return nullptr; + } + // 检查对象是否具有指定属性,结果存储在hasProperty中 + bool hasProperty; + JSVM_Status status = OH_JSVM_HasOwnProperty(env, args[0], args[1], &hasProperty); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_HasOwnProperty failed"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_HasOwnProperty success:%{public}d", hasProperty); + } + // 将bool结果转换为JSVM_Value并返回 + JSVM_Value result; + OH_JSVM_GetBoolean(env, hasProperty, &result); + return result; +} +// HasOwnProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = HasOwnProperty}, +}; +static JSVM_CallbackStruct *method = param; +// HasOwnProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"hasOwnProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + hasOwnProperty(obj, "message") + hasOwnProperty(obj, "__defineGetter__") +)JS"; +// [End oh_jsvm_has_own_property] + +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 = "hasownproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b759b773e775174ae9abd261fd629d4d1f4dedf5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/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": "libhasownproperty.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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/hasownpropertyability/HasownpropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/hasownpropertyability/HasownpropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/hasownpropertyability/HasownpropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/hasownpropertyability/HasownpropertyAbility.ets index 6f5d549b4ef2c977dfcd61d3bab323cc49eabcc0..cd36fd79e31870b544ddadb0a8c417e9dc78a4dd --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/hasownpropertyability/HasownpropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/hasownpropertyability/HasownpropertyAbility.ets @@ -1,56 +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 HasownpropertyAbility 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'); - } -}; +/* + * 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 HasownpropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..199480e7dca7ed7c6e64e8c7824dc9caa477ca09 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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 'libhasownproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..39f936321adcf422c62fa5b226bcb87a3661363d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "hasownproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "HasownpropertyAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "HasownpropertyAbility", + "srcEntry": "./ets/hasownpropertyability/HasownpropertyAbility.ets", + "description": "$string:HasownpropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:HasownpropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b96f1cf66c1a79243695bb7e26bf6c8de95473d6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "HasownpropertyAbility_desc", + "value": "description" + }, + { + "name": "HasownpropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c219ee83170cde2558b51aaa5bdc5a86b6cf5245 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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('testHasOwnProperty', 0, async (done: Function) => { + console.log('uitest: TestHasOwnProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'HasownpropertyAbility' + } + 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('HasownpropertyAbility'); + + 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: TestHasOwnProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0112adaed88ae70e13326dd38d85091eab5f4f2b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "hasownproperty_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/.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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..516888132a73ffaedce5839c6a61c0dfb3760204 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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": "hasproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libhasproperty.so": "file:./src/main/cpp/types/libhasproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6f672a727efb1645fb2ef3cf29a2afa055b4065 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPropertyOne) + +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) + +add_library(hasproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(hasproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8106190d3a9ebf48005179da53a6f01a8c9b1ee --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/hello.cpp @@ -0,0 +1,167 @@ +/* + * 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) + +// [Start oh_jsvm_has_property] +// OH_JSVM_HasProperty的样例方法 +static JSVM_Value HasProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 从js侧传入两个参数:第一个参数为要检验的对象,第二个参数为要检测是否存在对象的属性 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 将参数传入OH_JSVM_HasProperty方法中,若接口调用成功则将结果转化为JSVM_Value类型抛出,否则抛出错误 + bool result; + JSVM_Status status = OH_JSVM_HasProperty(env, args[0], args[1], &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_HasProperty fail"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_HasProperty success:%{public}d", result); + } + // 若传入属性存在传入对象中,则输出true将结果转化为JSVM_Value类型抛出 + JSVM_Value returnReslut = nullptr; + OH_JSVM_GetBoolean(env, result, &returnReslut); + return returnReslut; +} +// HasProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = HasProperty}, +}; +static JSVM_CallbackStruct *method = param; +// HasProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"hasProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + hasProperty(obj, "data") + hasProperty(obj, 0) +)JS"; +// [End oh_jsvm_has_property] + +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 = "hasproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b0b7775d9c39f79c4f04c1f14ae7dff72ddea889 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/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": "libhasproperty.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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/haspropertyability/HaspropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/haspropertyability/HaspropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/haspropertyability/HaspropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/haspropertyability/HaspropertyAbility.ets index 038f1b97e4ae4038e13b8779dcb9d8d2a5cb54da..3702f7f57bb46d045c55c67b17142d6ff02711cc --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/haspropertyability/HaspropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/haspropertyability/HaspropertyAbility.ets @@ -1,56 +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 HaspropertyAbility 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'); - } -}; +/* + * 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 HaspropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e36318dd0e2c7a6a3b105533327694977ea072a4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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 'libhasproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9333bc5583c9f92899e789c535988b4b1074f9db --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "hasproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "HaspropertyAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "HaspropertyAbility", + "srcEntry": "./ets/haspropertyability/HaspropertyAbility.ets", + "description": "$string:HaspropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:HaspropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1703bf5a8cc7fb6be1e2c51a4ad447509b613e72 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "HaspropertyAbility_desc", + "value": "description" + }, + { + "name": "HaspropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..89128f7bb361b82c1e2cd28e2564eb426b8d7cbf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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('testHasProperty', 0, async (done: Function) => { + console.log('uitest: TestHasProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'HaspropertyAbility' + } + 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('HaspropertyAbility'); + + 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: TestHasProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f1c5ae200a64d5c3476454edca1dd5152413267 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "hasproperty_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/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/NodeAPI/NodeApiUse/NodeAPIBigint/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/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/JsvmUsageGuide/JsvmAboutProperty/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..9a9dbf391e5460b5dc511ce3840ff0c92d4da147 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/ohosTest.md @@ -0,0 +1,18 @@ +# JsvmAboutProperty 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 批量的向给定对象中定义属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 用给定的属性的名称,删除目标对象属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定对象的所有可用属性名称 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 用给定的属性的名称,检索目标对象的属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 用给定的属性的名称,检索目标对象的属性,此方法等效于调用Hello World | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定对象的所有可枚举属性名称 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 用给定的属性的名称,查询目标对象是否有此属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断给定Object中是否有名为key的own property | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 用给定的属性的名称,查询目标对象是否有此属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 为给定对象设置一个属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 用给定的属性的名称为目标对象设置属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/screenshots/JsvmAboutProperty_2.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/.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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4b22f0c7b5a85f022a38be857196ac51e75c48f3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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": "setnamedproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libsetnamedproperty.so": "file:./src/main/cpp/types/libsetnamedproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1aaa08d4eede213300cd4470c68e7e3ea5ce559 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutProperty) + +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) + +add_library(setnamedproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(setnamedproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5b9eef9575bf2632222008830ee194df07b40bbb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/hello.cpp @@ -0,0 +1,174 @@ +/* + * 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) + +// [Start oh_jsvm_set_named_property] +// OH_JSVM_SetNamedProperty的样例方法 +const size_t STR_KEY_LEN = 32; +static JSVM_Value SetNamedProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取js侧传入的一个参数 + size_t argc = 1; + JSVM_Value str; + char strKey[STR_KEY_LEN] = ""; + OH_JSVM_GetCbInfo(env, info, &argc, &str, nullptr, nullptr); + // 获取传入参数字符串并存储在strKey中 + size_t keyLength; + OH_JSVM_GetValueStringUtf8(env, str, strKey, STR_KEY_LEN, &keyLength); + // 创建一个新对象 + JSVM_Value newObj; + OH_JSVM_CreateObject(env, &newObj); + // 设置整数值1234为属性值 + int32_t value = 1234; + JSVM_Value numValue; + OH_JSVM_CreateInt32(env, value, &numValue); + // 将整数值与指定属性名关联 + JSVM_Status status = OH_JSVM_SetNamedProperty(env, newObj, strKey, numValue); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_SetNamedProperty failed"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_SetNamedProperty success"); + } + // 返回新创建并设置命名属性的对象 + return newObj; +} +// SetNamedProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = SetNamedProperty}, +}; +static JSVM_CallbackStruct *method = param; +// SetNamedProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"setNamedProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + setNamedProperty("message") +)JS"; +// [End oh_jsvm_set_named_property] + +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 = "setnamedproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4993f42700ac41b320d73ad2227f58da20519b00 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/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": "libsetnamedproperty.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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4f83d35959226804786d1e01f4c5445a4920df3d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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 'libsetnamedproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/setnamedpropertyability/SetnamedpropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/setnamedpropertyability/SetnamedpropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/setnamedpropertyability/SetnamedpropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/setnamedpropertyability/SetnamedpropertyAbility.ets index f7239079bb220954b132518b6d37d2839cd0b56e..f3a650e5614339cc2feb4ee3992633aa501e79d3 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/setnamedpropertyability/SetnamedpropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/setnamedpropertyability/SetnamedpropertyAbility.ets @@ -1,56 +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 SetnamedpropertyAbility 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'); - } -}; +/* + * 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 SetnamedpropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..be0003bbefc70a90679f1ba3a8f3c59b22e18630 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "setnamedproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "SetnamedpropertyAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "SetnamedpropertyAbility", + "srcEntry": "./ets/setnamedpropertyability/SetnamedpropertyAbility.ets", + "description": "$string:SetnamedpropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:SetnamedpropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..00edf98c8a41b1b0a9b400867f17f10c9024b735 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "SetnamedpropertyAbility_desc", + "value": "description" + }, + { + "name": "SetnamedpropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..01c28a2092ce8a071c5ffac0fc517405947027ba --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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('testSetNamedProperty', 0, async (done: Function) => { + console.log('uitest: TestSetNamedProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'SetnamedpropertyAbility' + } + 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('SetnamedpropertyAbility'); + + 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: TestSetNamedProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e494eccaee7de5f224651acda68ce49527372a6a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "setnamedproperty_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/.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/JsvmUsageGuide/JsvmAboutProperty/setproperty/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutProperty/setproperty/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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/JsvmUsageGuide/JsvmAboutProperty/setproperty/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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/JsvmUsageGuide/JsvmAboutProperty/setproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..84d963dd856ece2cce1752a294145b826402220b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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": "setproperty", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libsetproperty.so": "file:./src/main/cpp/types/libsetproperty" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4bf4840ac37514bfa696da9303aa44c2d682d4fc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutPropertyOne) + +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) + +add_library(setproperty SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(setproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0702ef3d274e9955c8a0a1e10dba46e77624606 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/hello.cpp @@ -0,0 +1,167 @@ +/* + * 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) + +// [Start oh_jsvm_set_property] +// OH_JSVM_SetProperty的样例方法 +static JSVM_Value SetProperty(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接收js侧传入的三个参数:第一个参数为想要设置的object,第二个参数为属性,第三个参数为属性对应的值 + size_t argc = 3; + JSVM_Value args[3] = {nullptr}; + JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_GetCbInfo fail"); + return nullptr; + } + // 通过调用OH_JSVM_SetProperty接口将属性与值设置入object如果失败,直接抛出错误 + status = OH_JSVM_SetProperty(env, args[0], args[1], args[2]); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_SetProperty fail"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_SetProperty success"); + } + // 将设置成功后的object返回出去 + return args[0]; +} +// SetProperty注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = SetProperty}, +}; +static JSVM_CallbackStruct *method = param; +// SetProperty方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"setProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let obj = { data: 0, message: "hello world", 50: 1}; + setProperty(obj, "code", "hi") +)JS"; +// [End oh_jsvm_set_property] + +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 = "setproperty", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..57e01ed73ad76ed4796ae378a07362a336ae56f4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/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": "libsetproperty.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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5547fa7cacb6af5f879a888c7d37d3ca5554867 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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 'libsetproperty.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/setpropertyability/SetpropertyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/setpropertyability/SetpropertyAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/setpropertyability/SetpropertyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/setpropertyability/SetpropertyAbility.ets index 615301b220803547909c40e138fb4335a0689437..210466c53c3c78fdb12508871b43d1f7dc39c39e --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/setpropertyability/SetpropertyAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/setpropertyability/SetpropertyAbility.ets @@ -1,56 +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 SetpropertyAbility 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'); - } -}; +/* + * 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 SetpropertyAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f3e301cdbecdc024b2085cf61540c8a290d28110 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "setproperty", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "SetpropertyAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "SetpropertyAbility", + "srcEntry": "./ets/setpropertyability/SetpropertyAbility.ets", + "description": "$string:SetpropertyAbility_desc", + "icon": "$media:layered_image", + "label": "$string:SetpropertyAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b44128d457e2683d0533e2c676ba18b099eb9dad --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "SetpropertyAbility_desc", + "value": "description" + }, + { + "name": "SetpropertyAbility_label", + "value": "JsvmAboutProperty" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fe705bf04e86c7652a22a45fbf765eebb08bb96d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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('testSetProperty', 0, async (done: Function) => { + console.log('uitest: TestSetProperty begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'SetpropertyAbility' + } + 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('SetpropertyAbility'); + + 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: TestSetProperty end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17ccc65377c137675412a5cf8d98f5874c90c31c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "setproperty_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01ae5288a135b74b3719798f21df73c3a3a62aa0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/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.jsvmaboutstring", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e583037fa45535edde72a032c9c0971761cfcfb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmAboutString" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/README.md new file mode 100644 index 0000000000000000000000000000000000000000..502e9ae1769141ac0f30ffb13b92d418025c951c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/README.md @@ -0,0 +1,173 @@ +# ArkTs使用JSVM-API接口创建和获取string值 + +### 介绍 + +使用JSVM-API接口获取和设置JavaScript对象的属性。通过合理使用这些函数,实现更复杂的功能和逻辑。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口创建和获取string值](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-string.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createstringlatin1/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createstringutf8/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createstringutf16/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluestringlatin1/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluestringutf8/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluestringutf16/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutString > .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/JsvmUsageGuide/JsvmAboutString/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..db53f869ad88b314e5e7d6b6aa251d307a97d241 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/build-profile.json5 @@ -0,0 +1,118 @@ +/* + * 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": "getvaluestringutf8", + "srcPath": "./getvaluestringutf8", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createstringutf8", + "srcPath": "./createstringutf8", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvaluestringutf16", + "srcPath": "./getvaluestringutf16", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createstringutf16", + "srcPath": "./createstringutf16", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvaluestringlatin1", + "srcPath": "./getvaluestringlatin1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createstringlatin1", + "srcPath": "./createstringlatin1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/.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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb21c08f458e988814e8625d3c861ea50ef8d994 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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": "createstringlatin1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatestringlatin1.so": "file:./src/main/cpp/types/libcreatestringlatin1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..981566719f45047d709b6c202414c81ad57d826f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutString) + +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) + +add_library(createstringlatin1 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createstringlatin1 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e32e98cebd9a079f5c97053ab5042aba6304d0e4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/hello.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_string_latin1] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +// [StartExclude oh_jsvm_create_string_latin1] +#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) +// [EndExclude oh_jsvm_create_string_latin1] + +// CreateStringLatin1注册回调 +// 定义字符串缓冲区的最大长度 +static const int MAX_BUFFER_SIZE = 128; +// OH_JSVM_CreateStringLatin1的样例方法 +static JSVM_Value CreateStringLatin1(JSVM_Env env, JSVM_CallbackInfo info) +{ + const char *str = "Hello, World! éçñ, successes to create Latin1 string!"; + size_t length = JSVM_AUTO_LENGTH; + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateStringLatin1(env, str, length, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateStringLatin1 fail"); + } else { + char buf[MAX_BUFFER_SIZE]; + size_t lengthInner; + OH_JSVM_GetValueStringLatin1(env, result, buf, MAX_BUFFER_SIZE, &lengthInner); + OH_LOG_INFO(LOG_APP, "JSVM CreateStringLatin1 success: %{public}s", buf); + } + return result; +} +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateStringLatin1}, +}; +static JSVM_CallbackStruct *method = param; +// CreateStringLatin1方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createStringLatin1", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let script = createStringLatin1(); +)JS"; +// [End oh_jsvm_create_string_latin1] + +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 = "createstringlatin1", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8ae5b27af50d2208c9c74a8b8a7976b7c4b7ad33 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/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": "libcreatestringlatin1.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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/createstringlatin1ability/Createstringlatin1Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/createstringlatin1ability/Createstringlatin1Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/createstringlatin1ability/Createstringlatin1Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/createstringlatin1ability/Createstringlatin1Ability.ets index b149539887b857f4034d1f8ca35ad2c313ee4170..7018945a85d72df08459bd82989d504cc43a9e01 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/createstringlatin1ability/Createstringlatin1Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/createstringlatin1ability/Createstringlatin1Ability.ets @@ -1,56 +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 Createstringlatin1Ability 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'); - } -}; +/* + * 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 Createstringlatin1Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5effaba83d83fdfb4cf569978a99fbc02691b876 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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 'libcreatestringlatin1.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..db113bbf9729cb65e8cbf422324202cffa262f66 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createstringlatin1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createstringlatin1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createstringlatin1Ability", + "srcEntry": "./ets/createstringlatin1ability/Createstringlatin1Ability.ets", + "description": "$string:Createstringlatin1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createstringlatin1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9e79474145c64f53f5c247cc03163c2b44cd46d5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createstringlatin1Ability_desc", + "value": "description" + }, + { + "name": "Createstringlatin1Ability_label", + "value": "JsvmAboutString" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0d89fd15b43061200a343ed9c64997e8322234a7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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('testCreateStringLatin1', 0, async (done: Function) => { + console.log('uitest: TestCreateStringLatin1 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createstringlatin1Ability' + } + 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('Createstringlatin1Ability'); + + 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: TestCreateStringLatin1 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c4bb7f225410839e35893937a2c1ececc74c4995 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/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": "createstringlatin1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/.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/JsvmUsageGuide/JsvmAboutString/createstringutf16/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutString/createstringutf16/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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/JsvmUsageGuide/JsvmAboutString/createstringutf16/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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/JsvmUsageGuide/JsvmAboutString/createstringutf16/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4db4fec0aab02675ecf35b8d654b67be87ba31b8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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": "createstringutf16", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatestringutf16.so": "file:./src/main/cpp/types/libcreatestringutf16" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c27fcc77efa77536aace2220be59aebf35954ca8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutString) + +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) + +add_library(createstringutf16 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createstringutf16 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..119ab953c9818ca89effa4880b7237964f7af8de --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/hello.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_string_utf16] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +#include +#include +// [StartExclude oh_jsvm_create_string_utf16] +#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) +// [EndExclude oh_jsvm_create_string_utf16] + +// OH_JSVM_CreateStringUtf16的样例方法 +static JSVM_Value CreateStringUtf16(JSVM_Env env, JSVM_CallbackInfo info) +{ + const char16_t *str = u"你好, World!, successes to create UTF-16 string!"; + std::u16string ustr(str); + size_t length = ustr.length(); + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateStringUtf16(env, str, length, &result); + std::u16string u16str = {str}; + // 将 std::u16string 转换为 std::string + std::wstring_convert, char16_t> converter; + std::string strResult = converter.to_bytes(u16str); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateStringUtf16 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateStringUtf16 success: %{public}s", strResult.c_str()); + } + return result; +} +// CreateStringUtf16注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateStringUtf16}, +}; +static JSVM_CallbackStruct *method = param; +// CreateStringUtf16方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createStringUtf16", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let script = createStringUtf16(); +)JS"; +// [End oh_jsvm_create_string_utf16] + +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 = "createstringutf16", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e78b723bbb6313156a33b24d7000f36d15fdb260 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/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": "libcreatestringutf16.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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/createstringutf16ability/Createstringutf16Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/createstringutf16ability/Createstringutf16Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/createstringutf16ability/Createstringutf16Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/createstringutf16ability/Createstringutf16Ability.ets index 1f7d012757176894103bcf119cb0a668b6d7d330..f55281a97387e1ee3a2bc7e1c56730293a26f2d3 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/createstringutf16ability/Createstringutf16Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/createstringutf16ability/Createstringutf16Ability.ets @@ -1,56 +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 Createstringutf16Ability 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'); - } -}; +/* + * 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 Createstringutf16Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5d7bf8bf264dd3bce69af2a1d6c740268853158 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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 'libcreatestringutf16.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..67d9698b622e7bc816251538753e5372bbe3b635 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createstringutf16", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createstringutf16Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createstringutf16Ability", + "srcEntry": "./ets/createstringutf16ability/Createstringutf16Ability.ets", + "description": "$string:Createstringutf16Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createstringutf16Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1890388e764eea5aa8c34ce3983f26b4b8cbbd2c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createstringutf16Ability_desc", + "value": "description" + }, + { + "name": "Createstringutf16Ability_label", + "value": "JsvmAboutString" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..92b42b3c86b5d6ef7f3386294f60e4ac88d0eed4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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('testCreateStringUtf16', 0, async (done: Function) => { + console.log('uitest: TestCreateStringUtf16 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createstringutf16Ability' + } + 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('Createstringutf16Ability'); + + 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: TestCreateStringUtf16 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c67774b7b32d66034e3417b4bdc95989c1157368 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/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": "createstringutf16_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/.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/JsvmUsageGuide/JsvmAboutString/createstringutf8/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutString/createstringutf8/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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/JsvmUsageGuide/JsvmAboutString/createstringutf8/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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/JsvmUsageGuide/JsvmAboutString/createstringutf8/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed9c77f4d3a3362220ce9ca0d95728e5df753bfa --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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": "createstringutf8", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatestringutf8.so": "file:./src/main/cpp/types/libcreatestringutf8" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2a5952976ca2d84232ecf1b8045fe89445d51d86 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutString) + +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) + +add_library(createstringutf8 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createstringutf8 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f3abfc46f946be3546b20451c35089ac4c70a33 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/hello.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_string_utf8] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +// [StartExclude oh_jsvm_create_string_utf8] +#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) +// [EndExclude oh_jsvm_create_string_utf8] + +// OH_JSVM_CreateStringUtf8的样例方法 +static JSVM_Value CreateStringUtf8(JSVM_Env env, JSVM_CallbackInfo info) +{ + const char *str = u8"你好, World!, successes to create UTF-8 string!"; + size_t length = strlen(str); + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateStringUtf8(env, str, length, &result); + if (status != JSVM_OK) { + OH_JSVM_ThrowError(env, nullptr, "Failed to create UTF-8 string"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM CreateStringUtf8 success: %{public}s", str); + } + return result; +} +// CreateStringUtf8注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateStringUtf8}, +}; +static JSVM_CallbackStruct *method = param; +// CreateStringUtf8方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createStringUtf8", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let script = createStringUtf8(); +)JS"; +// [End oh_jsvm_create_string_utf8] + +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 = "createstringutf8", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01e8bf5dfcc9610a96f2e40607502986bf75525e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/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": "libcreatestringutf8.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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/createstringutf8ability/Createstringutf8Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/createstringutf8ability/Createstringutf8Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/createstringutf8ability/Createstringutf8Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/createstringutf8ability/Createstringutf8Ability.ets index 5feed4e3d07643012bdac8a8b4fce1fdc165042a..33326532fe7b23263d54a426a146390791219893 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/createstringutf8ability/Createstringutf8Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/createstringutf8ability/Createstringutf8Ability.ets @@ -1,56 +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 Createstringutf8Ability 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'); - } -}; +/* + * 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 Createstringutf8Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ef1c87772d60ba3701c0b04cc8178001300aa73 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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 'libcreatestringutf8.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..beb50ecab63be08f424eb5bfc5dca9610487562a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createstringutf8", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createstringutf8Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createstringutf8Ability", + "srcEntry": "./ets/createstringutf8ability/Createstringutf8Ability.ets", + "description": "$string:Createstringutf8Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createstringutf8Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e36fc0a2bc016d63a6b88abb0503724afd7ca95c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createstringutf8Ability_desc", + "value": "description" + }, + { + "name": "Createstringutf8Ability_label", + "value": "JsvmAboutString" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bcf5447dcc2fe275550265fdae2592835feda6f0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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('testCreateStringUtf8', 0, async (done: Function) => { + console.log('uitest: TestCreateStringUtf8 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createstringutf8Ability' + } + 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('Createstringutf8Ability'); + + 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: TestCreateStringUtf8 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0413d85c14f339db0956a8ca6228740be5c2bd65 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/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": "createstringutf8_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/.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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..660b85226f4b6983e503e924cf5003bcfa705846 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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": "getvaluestringlatin1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluestringlatin1.so": "file:./src/main/cpp/types/libgetvaluestringlatin1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2cd6e19ea3de6fe398d6822a34e8b515954541d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutString) + +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) + +add_library(getvaluestringlatin1 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluestringlatin1 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60652f22ec7258722d2e6ad102cee5b8968c766b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/hello.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_string_latin1] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +// [StartExclude oh_jsvm_get_value_string_latin1] +#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) +// [EndExclude oh_jsvm_get_value_string_latin1] + +// OH_JSVM_GetValueStringLatin1的样例方法 +// 定义字符串缓冲区的最大长度 +static const int MAX_BUFFER_SIZE = 128; +static JSVM_Value GetValueStringLatin1(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + char buf[MAX_BUFFER_SIZE]; + size_t length; + JSVM_Value jsvmRes = nullptr; + JSVM_Status status = OH_JSVM_GetValueStringLatin1(env, args[0], buf, MAX_BUFFER_SIZE, &length); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueStringLatin1 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueStringLatin1 success: %{public}s", buf); + } + OH_JSVM_CreateStringLatin1(env, buf, length, &jsvmRes); + return jsvmRes; +} +// GetValueStringLatin1注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueStringLatin1}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueStringLatin1方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueStringLatin1", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let data = "中文"; + let script = getValueStringLatin1(data); +)JS"; +// [End oh_jsvm_get_value_string_latin1] + +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 = "getvaluestringlatin1", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..501d4bb9f1405c45889a74c63c3b736bd4a6d2df --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/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": "libgetvaluestringlatin1.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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets index 8fa795619c16bb15c2529e5da5b1811c948e12b5..3f4cf52e7f6898c3f733e59480dc3d9920b119aa --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets @@ -1,56 +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 Getvaluestringlatin1Ability 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'); - } -}; +/* + * 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 Getvaluestringlatin1Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..99242bf94b108429ed2ed351880f57fc77ede1ee --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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 'libgetvaluestringlatin1.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ef501871330ec46126b6ee1881643e79b3c5ed46 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvaluestringlatin1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Getvaluestringlatin1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvaluestringlatin1Ability", + "srcEntry": "./ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets", + "description": "$string:Getvaluestringlatin1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvaluestringlatin1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c6341d8d9ae01f759ae57a186e2b2d850856664f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvaluestringlatin1Ability_desc", + "value": "description" + }, + { + "name": "Getvaluestringlatin1Ability_label", + "value": "JsvmAboutString" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4a92abdc0caac216b7559042908c7b49431c337 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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('testGetValueStringLatin1', 0, async (done: Function) => { + console.log('uitest: TestGetValueStringLatin1 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvaluestringlatin1Ability' + } + 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('Getvaluestringlatin1Ability'); + + 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: TestGetValueStringLatin1 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f7c28910206f9f5ca17aa8be56137f1b1ed886ee --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/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": "getvaluestringlatin1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/.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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8c3af9b1484431bbdc64dce31787ea9ada4f9e8b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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": "getvaluestringutf16", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluestringutf16.so": "file:./src/main/cpp/types/libgetvaluestringutf16" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0617721e65d0cd0005d0f09e5f2fe706672a242c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutString) + +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) + +add_library(getvaluestringutf16 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluestringutf16 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..00f7732f0b88cb925105a1931a3fb7c75637eec9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/hello.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_string_utf16] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +#include +#include +// [StartExclude oh_jsvm_get_value_string_utf16] +#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) +// [EndExclude oh_jsvm_get_value_string_utf16] + +// OH_JSVM_GetValueStringUtf16的样例方法 +// 定义字符串缓冲区的最大长度 +static const int MAX_BUFFER_SIZE = 128; +static JSVM_Value GetValueStringUtf16(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + JSVM_Value result = nullptr; + size_t length = 0; + char16_t buffer[MAX_BUFFER_SIZE] = {0}; + // 字符串的缓冲区大小 + size_t bufferSize = MAX_BUFFER_SIZE; + JSVM_Status status = OH_JSVM_GetValueStringUtf16(env, args[0], buffer, bufferSize, &length); + // 将 char16_t 转换为 std::u16string + std::u16string u16str = {buffer}; + // 将 std::u16string 转换为 std::string + std::wstring_convert, char16_t> converter; + std::string str = converter.to_bytes(u16str); + // 获取字符串返回结果 + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueStringUtf16 fail"); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueStringUtf16 success: %{public}s", str.c_str()); + } + return result; +} +// GetValueStringUtf16注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueStringUtf16}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueStringUtf16方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueStringUtf16", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let data = "ahello。"; + let script = getValueStringUtf16(data); +)JS"; +// [End oh_jsvm_get_value_string_utf16] + +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 = "getvaluestringutf16", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31443c0527e0d2a072c3f20b946700673fec4974 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/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": "libgetvaluestringutf16.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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets index ce6acc4a782b24e5c656215967fec5fc72a9de26..441c2bd280e3dd72a1597d43cdeda93743499195 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets @@ -1,56 +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 Getvaluestringutf16Ability 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'); - } -}; +/* + * 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 Getvaluestringutf16Ability 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1fbf0916d6ae2cede656dc8013a0ec4da7bac2f3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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 'libgetvaluestringutf16.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..80dce385f33a045183300e74ee2b2de24d8a9d9d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvaluestringutf16", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Getvaluestringutf16Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvaluestringutf16Ability", + "srcEntry": "./ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets", + "description": "$string:Getvaluestringutf16Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvaluestringutf16Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a4979b2c4b9b52dfb07d610e4c63f16d18082d89 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvaluestringutf16Ability_desc", + "value": "description" + }, + { + "name": "Getvaluestringutf16Ability_label", + "value": "JsvmAboutString" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..133fc2bb86c8068d0b707b717e64c6b802dd1894 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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('testGetValueStringUtf16', 0, async (done: Function) => { + console.log('uitest: TestGetValueStringUtf16 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvaluestringutf16Ability' + } + 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('Getvaluestringutf16Ability'); + + 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: TestGetValueStringUtf16 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ef448862ddbd26d9711bb2cdee9a969526110340 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/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": "getvaluestringutf16_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/.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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f2c7b354dc2d05e3efb908c814f797f5b9be3151 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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": "getvaluestringutf8", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluestringutf8.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7250a3ad6acea238eff0281d47e43c5b134a0193 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmAboutString) + +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) + +add_library(getvaluestringutf8 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluestringutf8 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bb15b60d2c2d0418a6d85f91632998dd38081334 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/hello.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_string_utf8] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +#include +// [StartExclude oh_jsvm_get_value_string_utf8] +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" +#define MAX_MALLOC_SIZE 0x800000 + +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) +// [EndExclude oh_jsvm_get_value_string_utf8] + +// OH_JSVM_GetValueStringUtf8的样例方法 +static JSVM_Value GetValueStringUtf8(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + size_t length = 0; + JSVM_Status status = OH_JSVM_GetValueStringUtf8(env, args[0], nullptr, 0, &length); + if (length == 0 || length > MAX_MALLOC_SIZE) { + OH_LOG_ERROR(LOG_APP, "Invalid string length: %{public}zu", length); + return jsVmResult; + } + char *buf = (char *)malloc(length + 1); + status = OH_JSVM_GetValueStringUtf8(env, args[0], buf, length + 1, &length); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueStringUtf8 fail"); + free(buf); + return nullptr; + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueStringUtf8 success: %{public}s", buf); + } + JSVM_Value result = nullptr; + OH_JSVM_CreateStringUtf8(env, buf, length, &result); + free(buf); + return result; +} +// GetValueStringUtf8注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueStringUtf8}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueStringUtf8方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueStringUtf8", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS( + let data = "aaBC+-$%^你好123"; + let script = getValueStringUtf8(data); +)JS"; +// [End oh_jsvm_get_value_string_utf8] + +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 = "getvaluestringutf8", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a4238e7158575c4ad8e0e6148cd6f125b76edc79 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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": "libgetvaluestringutf8.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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..090a5c31a8a7e2a94aa0453ab82428e53c22b91d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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 'libgetvaluestringutf8.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a57554c5fa0d8519ce1db20a1583e6be7d88e672 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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": "getvaluestringutf8", + "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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3c9edea49abd4287a9bc26a3a1901d94d881ddce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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": "JsvmAboutString" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c627e81499d50cbe603bc171b07060ff2bacd183 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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('testGetValueStringUtf8', 0, async (done: Function) => { + console.log('uitest: TestGetValueStringUtf8 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: TestGetValueStringUtf8 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a0a873074ee86f43327e175ab32f59b783b7e7c3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/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": "getvaluestringutf8_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/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/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/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/JsvmUsageGuide/JsvmAboutString/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..079f6083c788e180c320162ce8b303a18d9019fe --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/ohosTest.md @@ -0,0 +1,13 @@ +# JsvmAboutString 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 获取给定JavaScript string对象的Utf8编码字符串 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据Utf8编码的字符串创建一个JavaScript string对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript string对象的Utf16编码字符串 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据Utf16编码的字符串数据创建JavaScript string对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript string对象的Latin1编码字符串 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据Latin-1编码的字符串创建一个JavaScript string对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutString/screenshots/JsvmAboutString_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fdbab31b67ea5eac241a399dec4c09424f4a581c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/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.jsvmbasicdatatypes", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0717d1aaf402b6f50787907b8bfc57100ba0bfb7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmBasicDataTypes" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2d839421deba0e45ba9b84dfdbba75f708aed7e1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/README.md @@ -0,0 +1,213 @@ +# ArkTS使用JSVM-API接口创建基本数据类型 + +### 介绍 + +在JavaScript中,整数类型是一种基本数据类型,用于表示没有小数部分的数值。double类型用于表示有小数的数值。JavaScript的数值存储方式会导致在某些情况下无法准确表示非常大或非常小的数值,在这种情况下,需要使用BigInt对应的JSVM-API接口来处理更大范围的整数。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口创建基本数据类型](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-basic-data-types.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :--------------------------------------------------------------------: | :--------------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World ,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createdouble/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createint32/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createuint32/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvaluedouble/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvalueint32/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvalueint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvalueuint32/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmBasicDataTypes > .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/JsvmUsageGuide/JsvmBasicDataTypes/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8fd6419e1a91f4ff2b1a724d2c851c512f59aab6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/build-profile.json5 @@ -0,0 +1,142 @@ +/* + * 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": "getvalueuint32", + "srcPath": "./getvalueuint32", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvalueint32", + "srcPath": "./getvalueint32", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvalueint64", + "srcPath": "./getvalueint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getvaluedouble", + "srcPath": "./getvaluedouble", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createint32", + "srcPath": "./createint32", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createuint32", + "srcPath": "./createuint32", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createint64", + "srcPath": "./createint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createdouble", + "srcPath": "./createdouble", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ed05653cca31b61d64cf6471529eaf50d4f70709 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * 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": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/.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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c6d0dac73b2a62826e12610d92b647b3af64b6a7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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": "createdouble", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatedouble.so": "file:./src/main/cpp/types/libcreatedouble" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..364ccbf29e58974306af53d82c93a518afca2554 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createdouble SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createdouble PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a822e9807e28495b22e142249168d025e75747d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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. + */ + +// [Start oh_jsvm_create_double] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_double] +#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) +// [EndExclude oh_jsvm_create_double] + +// OH_JSVM_CreateDouble的样例方法 +static JSVM_Value CreateDouble(JSVM_Env env, JSVM_CallbackInfo info) +{ + double value = 1.234; + // 创建JavaScript中的double数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateDouble(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateDouble fail"); + } else { + double number = 0; + OH_JSVM_GetValueDouble(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateDouble success: %{public}f", number); + } + return result; +} + +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateDouble}, +}; +static JSVM_CallbackStruct *method = param; +// CreateDouble方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createDouble", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createDouble())JS"; +// [End oh_jsvm_create_double] + +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 = "createdouble", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..07112ef05dd7115781e3bba7de9001cb53e52cfc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/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": "libcreatedouble.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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets index d67f550837a6b8c560ca5cce48e2af13a2e3aaf2..6a9c2cbcc4cc4abe34d4194ab38317c5f29b1de0 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class CreatedoubleAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class CreatedoubleAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a8e8874ef07d6371ebfd14497a3a52bf99ca8043 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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 'libcreatedouble.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9b58e4ac831192d483a8456ddb604f345c475d4f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createdouble", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatedoubleAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatedoubleAbility", + "srcEntry": "./ets/createdoubleability/CreatedoubleAbility.ets", + "description": "$string:CreatedoubleAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatedoubleAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/float.json similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/float.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/float.json diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e1275bfb9201a3f0ac8c48d4b8277cbe60ccdd75 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatedoubleAbility_desc", + "value": "description" + }, + { + "name": "CreatedoubleAbility_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..884353874ac6627a5298b9918c47f9d8368ecd2a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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('testCreateDouble', 0, async (done: Function) => { + console.log('uitest: TestCreateDouble begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatedoubleAbility' + } + 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('CreatedoubleAbility'); + + 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: TestCreateDouble end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7b241d74d31922efec9234c67c23673e675287ae --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/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": "createdouble_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/.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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4507a2ecd45fde3a0fb3ec8a910524f5f7853d1f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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": "createint32", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateint32.so": "file:./src/main/cpp/types/libcreateint32" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f9bdf9271d3d70ec7ade48c0fb1ac1992f026893 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createint32 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f671f5eadcd9165dad3fb6fa908267a12d04d81 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/hello.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_int32] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_int32] +#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) +// [EndExclude oh_jsvm_create_int32] + +// OH_JSVM_CreateInt32的样例方法 +static JSVM_Value CreateInt32(JSVM_Env env, JSVM_CallbackInfo info) +{ + int32_t value = -20; + // 创建JavaScript中的int32数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateInt32(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateInt32 fail"); + } else { + int32_t number = 0; + OH_JSVM_GetValueInt32(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateInt32 success: %{public}d", number); + } + return result; +} + +// CreateInt32注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateInt32}, +}; +static JSVM_CallbackStruct *method = param; +// CreateInt32方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createInt32())JS"; +// [End oh_jsvm_create_int32] + +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 = "createint32", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..37d87a3282436a82a46f2ab0f2d2bfe80f0d0715 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/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": "libcreateint32.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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/createint32ability/Createint32Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/createint32ability/Createint32Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/createint32ability/Createint32Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/createint32ability/Createint32Ability.ets index 19e4b37789b986925fa04b69dc9a50e166135f02..d76b52b1c97eb594fff49e5f27d83a9ede2f417b --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/createint32ability/Createint32Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/createint32ability/Createint32Ability.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Createint32Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class Createint32Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6bb339635e7766bd3c95c284c80369be898ac5a3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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 'libcreateint32.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a684705ce0a7a4e79f0590bec9f0d04149629a37 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createint32", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createint32Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createint32Ability", + "srcEntry": "./ets/createint32ability/Createint32Ability.ets", + "description": "$string:Createint32Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createint32Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..19b814ed2a2c9fce357062e488f034f1085ffe0c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createint32Ability_desc", + "value": "description" + }, + { + "name": "Createint32Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f4230efd09ffd5c4eaf34741d3f27cb380aceaaa --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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('testCreateInt32', 0, async (done: Function) => { + console.log('uitest: TestCreateInt32 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createint32Ability' + } + 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('Createint32Ability'); + + 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: TestCreateInt32 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..67190c9e5c7b327097bde18d61ec9de5a5e9ed74 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/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": "createint32_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/.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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0ca706152ac79490f7def1fe934fd25cc9d5ae58 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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": "createint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateint64.so": "file:./src/main/cpp/types/libcreateint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c59239f03840727822e3a236549d7babbccd127 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..241ad92c3e4ce81adc860b4baa589269e42147a4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/hello.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_int64] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_int64] +#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) +// [EndExclude oh_jsvm_create_int64] + +// OH_JSVM_CreateInt64的样例方法 +static JSVM_Value CreateInt64(JSVM_Env env, JSVM_CallbackInfo info) +{ + // int64是有符号的64位整数类型,可以表示范围从-2^63到2^63 - 1的整数,即 -9223372036854775808到9223372036854775807 + // 要表示的整数值 + int64_t value = 2147483648; + // 创建JavaScript中的int64数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateInt64(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateInt64 fail"); + } else { + int64_t number = 0; + OH_JSVM_GetValueInt64(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateInt64 success: %{public}ld", number); + } + return result; +} + +// CreateInt64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateInt64}, +}; +static JSVM_CallbackStruct *method = param; +// CreateInt64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createInt64())JS"; +// [End oh_jsvm_create_int64] + +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 = "createint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..82ec4846629896cb53c22b7ca7b9c435de78142c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/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": "libcreateint64.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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/createint64ability/Createint64Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/createint64ability/Createint64Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/createint64ability/Createint64Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/createint64ability/Createint64Ability.ets index 48e34d5cef246299e12c3f0bbfafbd4b090b0e34..f65ac599b5d30a72196155a8e80661e48e77e937 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/createint64ability/Createint64Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/createint64ability/Createint64Ability.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Createint64Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class Createint64Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..d84dc3c2e9c1cee52c9f15fa2d0f50b3ebaa2972 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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 'libcreateint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aff59ba55039252522fa86a68a3b3a7526a0b4bc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createint64Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createint64Ability", + "srcEntry": "./ets/createint64ability/Createint64Ability.ets", + "description": "$string:Createint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1e3a4cefa2ec46ad5037ca39adf96562562a7491 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createint64Ability_desc", + "value": "description" + }, + { + "name": "Createint64Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c266475a275e462bb464a28bcc87fa3e3ec884df --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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('testCreateInt64', 0, async (done: Function) => { + console.log('uitest: TestCreateInt64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createint64Ability' + } + 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('Createint64Ability'); + + 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: TestCreateInt64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..61457fd3f6d6399b81bba1fcda3508a6c52d8b8e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/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": "createint64_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/.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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..daa6d3f06a74c5cbc88c0109112807c53158214f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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": "createuint32", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateuint32.so": "file:./src/main/cpp/types/libcreateuint32" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..184deeb980903f436030be54d42ec21c2bdce0bb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(createuint32 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createuint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09e64074d6da80fdcb18925799008f1d10d20c44 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/hello.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_uint32] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_create_uint32] +#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) +// [EndExclude oh_jsvm_create_uint32] + +// OH_JSVM_CreateUint32的样例方法 +static JSVM_Value CreateUInt32(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 如果使用 + // uint32_t类型来定义-26,会发生溢出,溢出时会对结果进行模运算,将负数的二进制补码转换为相应的正数。-26输出4294967270 + // uint32_t是无符号的32位整数类型,只能表示非负整数。它的范围是从0到2 ^32 - 1,即0到4294967295 + // 要表示的整数值 + uint32_t value = 26; + // 创建JavaScript中的uint32数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateUint32(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateUInt32 fail"); + } else { + uint32_t number = 0; + OH_JSVM_GetValueUint32(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateUInt32 success: %{public}u", number); + } + return result; +} + +// CreateUInt32注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateUInt32}, +}; +static JSVM_CallbackStruct *method = param; +// CreateUInt32方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createUInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(createUInt32())JS"; +// [End oh_jsvm_create_uint32] + +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 = "createuint32", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6203cb2eab75e7764b965f4ea5f52a8c683efd7d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/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": "libcreateuint32.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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets index efcda6ddd2282ed9cdb8457e3a014a788219382e..32d30a9079fd3ef06bc98e6bdb2e2a0047da5627 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Createuint32Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class Createuint32Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..dbbbbfde9af6a78aadf4f3f10589137df69d236f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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 'libcreateuint32.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6136e1848e85e6d5d153fd24402be8ddfd4374c2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createuint32", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createuint32Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createuint32Ability", + "srcEntry": "./ets/createuint32ability/Createuint32Ability.ets", + "description": "$string:Createuint32Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createuint32Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..45dd30e382140fb937578b3fc1cad3547d41af3b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createuint32Ability_desc", + "value": "description" + }, + { + "name": "Createuint32Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb8fb3e4fec28977f35b09afa4139888656a426b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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('testCreateUint32', 0, async (done: Function) => { + console.log('uitest: TestCreateUint32 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createuint32Ability' + } + 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('Createuint32Ability'); + + 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: TestCreateUint32 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b1a963b6af744813767c2535e6c1a384bd15d212 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/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": "createuint32_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/.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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4adebc3b57c689f6643fc8ea1e0986480b11766b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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": "getvaluedouble", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvaluedouble.so": "file:./src/main/cpp/types/libgetvaluedouble" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e49d0fbcde3c2210c362bb6c02c23f3f60b8653 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(getvaluedouble SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvaluedouble PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9ac2f18ce4c07bd0b4ebc0d037bac7109865891 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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. + */ + +// [Start oh_jsvm_get_value_double] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_value_double] +#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) +// [EndExclude oh_jsvm_get_value_double] + +// OH_JSVM_GetValueDouble的样例方法 +static JSVM_Value GetDouble(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + double value; + JSVM_Status status = OH_JSVM_GetValueDouble(env, args[0], &value); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetDouble fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetDouble success: %{public}f", value); + } + return args[0]; +} + +// GetDouble注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetDouble}, +}; +static JSVM_CallbackStruct *method = param; +// GetDouble方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getDouble", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getDouble(-110.0456))JS"; +// [EndExclude oh_jsvm_get_value_double] + +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 = "getvaluedouble", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1cba47eb3223d20ca1c537fd9949af61014b7bbd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/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": "libgetvaluedouble.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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/getvaluedoubleability/GetvaluedoubleAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/getvaluedoubleability/GetvaluedoubleAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/getvaluedoubleability/GetvaluedoubleAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/getvaluedoubleability/GetvaluedoubleAbility.ets index dba739725383ef55fda31d1d7b7d6a764750cfd0..cfbdba57fe2fa0f9fc10f44d960ac879dcb87da8 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/getvaluedoubleability/GetvaluedoubleAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/getvaluedoubleability/GetvaluedoubleAbility.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class GetvaluedoubleAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class GetvaluedoubleAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ef860f004f2f85283fbb4f12bb68705198a490f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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 'libgetvaluedouble.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c62508cb0e63c61baa795c9fc6058a673e912904 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvaluedouble", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetvaluedoubleAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetvaluedoubleAbility", + "srcEntry": "./ets/getvaluedoubleability/GetvaluedoubleAbility.ets", + "description": "$string:GetvaluedoubleAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetvaluedoubleAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0ee636b385f3c97b03cda7171db946b523272328 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetvaluedoubleAbility_desc", + "value": "description" + }, + { + "name": "GetvaluedoubleAbility_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a59ff4a6e199d56b5dcf088c057329eb6afbea08 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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('testGetValueDouble', 0, async (done: Function) => { + console.log('uitest: TestGetValueDouble begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetvaluedoubleAbility' + } + 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('GetvaluedoubleAbility'); + + 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: TestGetValueDouble end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..081f77bc27e2b1ca05c2352603d034d2c60de620 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/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": "getvaluedouble_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..559beb0fe7cb1fa24f48b7f35899deb36206e246 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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": "getvalueint32", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvalueint32.so": "file:./src/main/cpp/types/libgetvalueint32" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6eebe42c373a57fd3aad8a7af7e565cb5ec4ecf4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(getvalueint32 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvalueint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9cf74aea089e32d9c58b1ea07d51e8412defcf1f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/hello.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_int32] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_value_int32] +#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) +// [EndExclude oh_jsvm_get_value_int32] + +// OH_JSVM_GetValueInt32的样例方法 +static JSVM_Value GetValueInt32(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + int32_t result32 = 0; + // 解析传递的参数 + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 将前端传过来的参数转为JSVM模块的int32类型 + JSVM_Status status = OH_JSVM_GetValueInt32(env, args[0], &result32); + if (status != JSVM_OK) { + return nullptr; + } + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueInt32 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueInt32 success: %{public}d", result32); + } + return args[0]; +} + +// GetValueInt32注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueInt32}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueInt32方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getValueInt32(-123))JS"; +// [EndExclude oh_jsvm_get_value_int32] + +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 = "getvalueint32", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b16c22eb9756fefb2b156b5e5f1e7b00cc05062a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/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": "libgetvalueint32.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/getvalueint32ability/Getvalueint32Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/getvalueint32ability/Getvalueint32Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/getvalueint32ability/Getvalueint32Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/getvalueint32ability/Getvalueint32Ability.ets index 7607c4681642de933d3ba94e9badda4c9ef42d59..95250ef0343610c196924a1336d69e68dee83c19 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/getvalueint32ability/Getvalueint32Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/getvalueint32ability/Getvalueint32Ability.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Getvalueint32Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class Getvalueint32Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7805ff25158d3b67d5e80f29e6032964e3e543cb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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 'libgetvalueint32.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..102c5ee189282b9bb05d7c4c317322698d36c82e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvalueint32", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Getvalueint32Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvalueint32Ability", + "srcEntry": "./ets/getvalueint32ability/Getvalueint32Ability.ets", + "description": "$string:Getvalueint32Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvalueint32Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..74660f7434fd9e7104a158f5bab0e81d18305402 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvalueint32Ability_desc", + "value": "description" + }, + { + "name": "Getvalueint32Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..51cfa9704003d9c776e75a607368880c2c5589a9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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('testGetValueInt32', 0, async (done: Function) => { + console.log('uitest: TestGetValueInt32 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvalueint32Ability' + } + 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('Getvalueint32Ability'); + + 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: TestGetValueInt32 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3cf8a9cf57aa9a0af8882e3233aee6d0af726ca4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/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": "getvalueint32_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3a300d3190d7d9d2b6fd5d4d8e546a1564ecae94 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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": "getvalueint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvalueint64.so": "file:./src/main/cpp/types/libgetvalueint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..de7a3ca78888729b7dea34d83e79fe585b51e57b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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(getvalueint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvalueint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b2f7c5d3d5c71da6de091970dae53019f15dd33 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/hello.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_int64] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_value_int64] +#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) +// [EndExclude oh_jsvm_get_value_int64] + +// OH_JSVM_GetValueInt64的样例方法 +static JSVM_Value GetValueInt64(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + int64_t result64 = 0; + // 解析传递的值 + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 将前端传过来的参数分别转为JSVM模块的int64类型 + JSVM_Status status = OH_JSVM_GetValueInt64(env, args[0], &result64); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueInt64 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueInt64 success: %{public}d", result64); + } + return args[0]; +} + +// GetValueInt64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueInt64}, +}; +static JSVM_CallbackStruct *method = param; +// GetValueInt64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getValueInt64(-123))JS"; +// [End oh_jsvm_get_value_int64] + +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 = "getvalueint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..675da76204fb0e03fc979d91ac3fe4fbb740bbf6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/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": "libgetvalueint64.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/getvalueint64ability/Getvalueint64Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/getvalueint64ability/Getvalueint64Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/getvalueint64ability/Getvalueint64Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/getvalueint64ability/Getvalueint64Ability.ets index bbfbf5bedb8c4614390fb3d408ac1b37c85bbe48..6f8befe4242603704a6b8be88a2dba3504e133a3 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/getvalueint64ability/Getvalueint64Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/getvalueint64ability/Getvalueint64Ability.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Getvalueint64Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class Getvalueint64Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb9f302146f51edc82e1d2f2832b08a58b970544 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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 'libgetvalueint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2ca98d368aacc292e265cdb2eaa83978ac59c19b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getvalueint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Getvalueint64Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvalueint64Ability", + "srcEntry": "./ets/getvalueint64ability/Getvalueint64Ability.ets", + "description": "$string:Getvalueint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvalueint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7c45a2953a835a86ed9b457ee207d8b08e286956 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvalueint64Ability_desc", + "value": "description" + }, + { + "name": "Getvalueint64Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0fca3488df0bab0630d436de603ac72bd36d2dae --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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('testGetValueInt64', 0, async (done: Function) => { + console.log('uitest: TestGetValueInt64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvalueint64Ability' + } + 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('Getvalueint64Ability'); + + 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: TestGetValueInt64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2aedd60cbf574fa077adb9917acb8e094bf6afe2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/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": "getvalueint64_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a988e9ec7e3e67a8c756f26f07b95be60470302b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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": "getvalueuint32", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvalueuint32.so": "file:./src/main/cpp/types/libgetvalueuint32" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..67c7b089564d9e99494bb614245fd5f2b7a4db2a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(GetValueUint32) + +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(getvalueuint32 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvalueuint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb130e8f4a4e9585dfa845314076d8b3855cc11f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/hello.cpp @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_value_uint32] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" + +// [StartExclude oh_jsvm_get_value_uint32] +#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) +// [EndExclude oh_jsvm_get_value_uint32] + +// OH_JSVM_GetValueUint32的样例方法 +static JSVM_Value GetValueUint32(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取传入的数字类型参数 + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + // 解析传入的参数 + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + uint32_t number = 0; + // 获取传入参数的值中的无符号32位整数 + JSVM_Status status = OH_JSVM_GetValueUint32(env, argv[0], &number); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM GetValueUint32 fail"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM GetValueUint32 success: %{public}u", number); + } + return argv[0]; +} + +// GetValueUint32注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetValueUint32}, +}; +static JSVM_CallbackStruct *method = param; + +// GetValueUint32方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getValueUint32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* SRC_CALL_NATIVE = R"JS(getValueUint32(123))JS"; +// [End oh_jsvm_get_value_uint32] + +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 = "getvalueuint32", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1892cf3f4c75381cc20ae814a589ef7958b4696b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/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": "libgetvalueuint32.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32ability/Getvalueuint32Ability.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32ability/Getvalueuint32Ability.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32ability/Getvalueuint32Ability.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32ability/Getvalueuint32Ability.ets index 672434b365faa2ab415b57e48ad3bbeb6a1e53f8..d7c77ef51df1e1eec37ab78f58dabf95aa7035bc --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32ability/Getvalueuint32Ability.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32ability/Getvalueuint32Ability.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Getvalueuint32Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class Getvalueuint32Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32backupability/Getvalueuint32BackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32backupability/Getvalueuint32BackupAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32backupability/Getvalueuint32BackupAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32backupability/Getvalueuint32BackupAbility.ets index b2f0e204ac79e2e8bd64e8adeba7c5842622df28..3e2a11e2beee9f0ab3dd3d7adfb8f34545d76736 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32backupability/Getvalueuint32BackupAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/getvalueuint32backupability/Getvalueuint32BackupAbility.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; - -const DOMAIN = 0x0000; - -export default class Getvalueuint32BackupAbility extends BackupExtensionAbility { - async onBackup() { - hilog.info(DOMAIN, 'testTag', 'onBackup ok'); - await Promise.resolve(); - } - - async onRestore(bundleVersion: BundleVersion) { - hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); - await Promise.resolve(); - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class Getvalueuint32BackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7407f72a435ed8fef4ab0a87fb71cc8e8a1d0201 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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 'libgetvalueuint32.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab01538bd622d8efe23a796b9cbdd9620cedc576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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": "getvalueuint32", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Getvalueuint32Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Getvalueuint32Ability", + "srcEntry": "./ets/getvalueuint32ability/Getvalueuint32Ability.ets", + "description": "$string:Getvalueuint32Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Getvalueuint32Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Getvalueuint32BackupAbility", + "srcEntry": "./ets/getvalueuint32backupability/Getvalueuint32BackupAbility.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..010d3b35e85ab47d8b917cd7d016facd7933de39 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Getvalueuint32Ability_desc", + "value": "description" + }, + { + "name": "Getvalueuint32Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..21603bee159ced57e6c1b9bfed71c56caa658c0f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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('testGetValueUint32', 0, async (done: Function) => { + console.log('uitest: TestGetValueUint32 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Getvalueuint32Ability' + } + 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('Getvalueuint32Ability'); + + 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: TestGetValueUint32 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..705f3fe838ebc48948bb79b9fbcbfa32e3431e8d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/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": "getvalueuint32_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0bbbb33b0bd997de3ffe32ac6228075c5a4b1f0e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.2", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b555a4269faeadc6caab93d696e194c30862899 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "modelVersion": "5.0.2", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2fd61feb9d41f297dd3f835af52ae281ce0e2885 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/ohosTest.md @@ -0,0 +1,15 @@ +# JsvmBasicDataTypes 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 根据Double类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据Int32_t类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据Int64_t类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 根据Uint32_t类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript number的Double基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript number的Int32基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript number的Int64基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取给定JavaScript number的Uint32基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/screenshots/JsvmBasicDataTypes_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..185fc255b029bdbcac6eb9940f8ebc070bb09a78 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/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.jsvmerror", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4fd0266eeb44c0a8c0439aa670081fd11dd7dc7e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmError" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5048cf4f47416cddb3e50030e17c76a6e31d58d2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/README.md @@ -0,0 +1,293 @@ +# ArkTs使用JSVM-API接口进行错误处理开发 + +### 介绍 + +使用JSVM-API接口进行错误处理开发,使得在JSVM-API模块中能够更好地管理和响应错误情况。通过合理使用这些函数,可以提高模块的稳定性和可靠性。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行错误处理开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-error.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :-----------------------------------------------------------: | :-----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createrangeerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createsyntaxerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createtypeerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getandclearlastexception/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getlasterrorinfo/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +iserror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +isexceptionpending/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +throwerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +throwrangeerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +throwsyntaxerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +throwtypeerror/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmError > .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/JsvmUsageGuide/JsvmError/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d347235e59e605bfd262e1a3e3ad756c7d0dd71b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/build-profile.json5 @@ -0,0 +1,190 @@ +/* + * 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": "createerror", + "srcPath": "./createerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "throwerror", + "srcPath": "./throwerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "throwtypeerror", + "srcPath": "./throwtypeerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "throwrangeerror", + "srcPath": "./throwrangeerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "throwsyntaxerror", + "srcPath": "./throwsyntaxerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "iserror", + "srcPath": "./iserror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createtypeerror", + "srcPath": "./createtypeerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createrangeerror", + "srcPath": "./createrangeerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createsyntaxerror", + "srcPath": "./createsyntaxerror", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getandclearlastexception", + "srcPath": "./getandclearlastexception", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "isexceptionpending", + "srcPath": "./isexceptionpending", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getlasterrorinfo", + "srcPath": "./getlasterrorinfo", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/.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/JsvmUsageGuide/JsvmError/createerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/createerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..45fc020f213fd0625ea76343dbbf4812a8038631 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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": "createerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateerror.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..646502a8b6d574b61ad16a550affc88da5f0f314 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(createerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4724bf8d7f83bc15f2cc245a366b74a9f8349df --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/hello.cpp @@ -0,0 +1,179 @@ +/* + * 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) + +// [Start oh_jsvm_create_error] +// 捕获清除并打印错误,该函数作为公共函数,在本文档后续样例中不再声明和定义 +static void GetLastErrorAndClean(JSVM_Env env) +{ + // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); + // 打印错误信息 + JSVM_Value message; + JSVM_Value errorCode; + OH_JSVM_GetNamedProperty((env), result, "message", &message); + OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); + const int maxMessageLength = 256; + const int maxCodeLength = 256; + char messagestr[maxMessageLength]; + char codeStr[maxCodeLength]; + OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); + OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); + OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); +} + +// OH_JSVM_CreateError的样例方法 +static JSVM_Value JsVmCreateThrowError(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 + JSVM_Value errorCode = nullptr; + OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); + // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 + JSVM_Value errorMessage = nullptr; + OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); + // 创建一个JavaScript对象error + JSVM_Value error = nullptr; + OH_JSVM_CreateError(env, errorCode, errorMessage, &error); + // 通过OH_JSVM_Throw接口将对象抛出 + OH_JSVM_Throw(env, error); + GetLastErrorAndClean(env); + return nullptr; +} + +// JsVmThrow注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmCreateThrowError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmThrow方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmCreateThrowError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmCreateThrowError();)JS"; +// [End oh_jsvm_create_error] + +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 = "createerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..08ccb34006f06bf86f549b1269179705b2e39605 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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": "libcreateerror.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/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0adc1a4d4033ffc1119c91a1e23ea4de3193005f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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 'libcreateerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/createerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1afc6e120aaad5a0fa714e89a2ef30d49f36f8e6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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": "createerror", + "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/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..05c747fe963a7c53e44928c6e79f4675ca367e39 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dd6267a0d6ba940a7b935e2cb31e08990009f45 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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('testCreateError', 0, async (done: Function) => { + console.log('uitest: TestCreateError 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: TestCreateError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4afacccb72cad7b1254e870172735868b3d165a0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/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": "createerror_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/.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/JsvmUsageGuide/JsvmError/createrangeerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/createrangeerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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/JsvmUsageGuide/JsvmError/createrangeerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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/JsvmUsageGuide/JsvmError/createrangeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..794eed302f6a87b7484b39681f04cd33962a6580 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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": "createrangeerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreaterangeerror.so": "file:./src/main/cpp/types/libcreaterangeerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d408997169682709598785b4675c3ce71557ce12 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(createrangeerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createrangeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b63e5932bbba81e06f802dfc706f834f4693e455 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * 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) + +// [Start oh_jsvm_create_range_error] +// OH_JSVM_CreateRangeError的样例方法 +static JSVM_Value JsVmCreateRangeError(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 + JSVM_Value errorCode = nullptr; + OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); + // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 + JSVM_Value errorMessage = nullptr; + OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateRangeError(env, errorCode, errorMessage, &result); + if (status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM API CreateRangeError SUCCESS"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM API CreateRangeError FAILED"); + } + return result; +} +// JsVmCreateRangeError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmCreateRangeError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmCreateRangeError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmCreateRangeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmCreateRangeError();)JS"; +// [End oh_jsvm_create_range_error] + +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 = "createrangeerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f4ae2861bcfce16c00897e27904c7640db616d03 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/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": "libcreaterangeerror.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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/createrangeerrorability/CreaterangeerrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/createrangeerrorability/CreaterangeerrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/createrangeerrorability/CreaterangeerrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/createrangeerrorability/CreaterangeerrorAbility.ets index 394253f1bc3a6da5522ed7f2832966f187c3ca34..c22cc9d9060adb37f78580ee6f893d2993b98ca0 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/createrangeerrorability/CreaterangeerrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/createrangeerrorability/CreaterangeerrorAbility.ets @@ -1,56 +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 CreaterangeerrorAbility 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'); - } -}; +/* + * 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 CreaterangeerrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..32026a9b1f3a6e69ed68b110ce052175cea6013a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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 'libcreaterangeerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0c27fd2f396854016993c03755046e7edffe4a28 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createrangeerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreaterangeerrorAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreaterangeerrorAbility", + "srcEntry": "./ets/createrangeerrorability/CreaterangeerrorAbility.ets", + "description": "$string:CreaterangeerrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreaterangeerrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cb358fc78c5766a9d136ae26da31bfcaf21c8323 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreaterangeerrorAbility_desc", + "value": "description" + }, + { + "name": "CreaterangeerrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a80e0145e4547c87dc6ed463dca617ddc975644 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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('testCreateRangeError', 0, async (done: Function) => { + console.log('uitest: TestCreateRangeError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreaterangeerrorAbility' + } + 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('CreaterangeerrorAbility'); + + 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: TestCreateRangeError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..efa99ca79b1097e8c16607b41949accd47bd3426 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/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": "createrangeerror_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/.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/JsvmUsageGuide/JsvmError/createsyntaxerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/createsyntaxerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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/JsvmUsageGuide/JsvmError/createsyntaxerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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/JsvmUsageGuide/JsvmError/createsyntaxerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cc5e28cfd281cfe543d65978630c9e317a415993 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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": "createsyntaxerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatesyntaxerror.so": "file:./src/main/cpp/types/libcreatesyntaxerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..69e1f39691657128493a26d4b0b9e7c098d445d4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(createsyntaxerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createsyntaxerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a42ca8818fa6fae99f53f670a194d6c44f0a0797 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * 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) + +// [Start oh_jsvm_create_syntax_error] +// OH_JSVM_CreateSyntaxError的样例方法 +static JSVM_Value JsVmCreateSyntaxError(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 + JSVM_Value errorCode = nullptr; + OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); + // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 + JSVM_Value errorMessage = nullptr; + OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateSyntaxError(env, errorCode, errorMessage, &result); + if (status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM API CreateSyntaxError SUCCESS"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM API CreateSyntaxError FAILED"); + } + return result; +} +// JsVmCreateSyntaxError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmCreateSyntaxError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmThrow方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmCreateSyntaxError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmCreateSyntaxError();)JS"; +// [End oh_jsvm_create_syntax_error] + +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 = "createsyntaxerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1bae7049ef4933b413e35f0c9e13e39c76e71ecd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/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": "libcreatesyntaxerror.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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets index 4d3b9b1116423c749b999a44419620165bdf592e..b9fa1783748a233a288ae6d0db0f8821c0b282cd --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets @@ -1,56 +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 CreatesyntaxerrorAbility 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'); - } -}; +/* + * 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 CreatesyntaxerrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8680f3871c4cca741105498d16559fb98a7ee7f1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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 'libcreatesyntaxerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..751d118ee6efc97785542b0af824450172afb369 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createsyntaxerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatesyntaxerrorAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatesyntaxerrorAbility", + "srcEntry": "./ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets", + "description": "$string:CreatesyntaxerrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatesyntaxerrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f1a5b4372d1768a34b7f8ca5999fac7ebaa6e56d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatesyntaxerrorAbility_desc", + "value": "description" + }, + { + "name": "CreatesyntaxerrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..724e339a2a7ec957716fa8f35cbaa0c54f03d307 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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('testCreateSyntaxError', 0, async (done: Function) => { + console.log('uitest: TestCreateSyntaxError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatesyntaxerrorAbility' + } + 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('CreatesyntaxerrorAbility'); + + 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: TestCreateSyntaxError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..17a8fd92c1e27ba0c770eb95e45856d6df01fff4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/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": "createsyntaxerror_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/.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/JsvmUsageGuide/JsvmError/createtypeerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/createtypeerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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/JsvmUsageGuide/JsvmError/createtypeerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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/JsvmUsageGuide/JsvmError/createtypeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3699fb5510cd3042e2d15787b9e46358706fbbb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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": "createtypeerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatetypeerror.so": "file:./src/main/cpp/types/libcreatetypeerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd081f46ea46ccee823487ad276cc8595ae45d04 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(createtypeerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createtypeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b914e402bbc50f57e563127de3d09f0a973401fb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * 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) + +// [Start oh_jsvm_create_type_error] +// OH_JSVM_CreateTypeError的样例方法 +static JSVM_Value JsVmCreateTypeError(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 + JSVM_Value errorCode = nullptr; + OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); + // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 + JSVM_Value errorMessage = nullptr; + OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateTypeError(env, errorCode, errorMessage, &result); + if (status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM API Create TypeError SUCCESS"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM API Create TypeError FAILED"); + } + return result; +} +// JsVmCreateTypeError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmCreateTypeError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmCreateTypeError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmCreateTypeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmCreateTypeError();)JS"; +// [End oh_jsvm_create_type_error] + +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 = "createtypeerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fddd88934e49acba7e4d0186cd3887c824758bd7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/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": "libcreatetypeerror.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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/createtypeerrorability/CreateTypeErrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/createtypeerrorability/CreateTypeErrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/createtypeerrorability/CreateTypeErrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/createtypeerrorability/CreateTypeErrorAbility.ets index ef0e54189bbe8017abd0fb303211c81c0272a9f2..60e7992c8f914757d3bbcb42eccae0af8c063c49 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/createtypeerrorability/CreateTypeErrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/createtypeerrorability/CreateTypeErrorAbility.ets @@ -1,56 +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 CreateTypeErrorAbility 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'); - } -}; +/* + * 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 CreateTypeErrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5561ff42c3ba1d1e2773b450af7b319d0c5c405d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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 'libcreatetypeerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0635f758165d9c65bb27b88c740fbecbbbee9c20 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "createtypeerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreateTypeErrorAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreateTypeErrorAbility", + "srcEntry": "./ets/createtypeerrorability/CreateTypeErrorAbility.ets", + "description": "$string:CreateTypeErrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreateTypeErrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1b0fb6f6669cf1e6a591a489d4e346ff18fa7bd9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreateTypeErrorAbility_desc", + "value": "description" + }, + { + "name": "CreateTypeErrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..23b7bc2384d6f8ddf1779b4ea8405451ec351ab4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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('testCreateTypeError', 0, async (done: Function) => { + console.log('uitest: TestCreateTypeError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreateTypeErrorAbility' + } + 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('CreateTypeErrorAbility'); + + 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: TestCreateTypeError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..47c64e9faf1dc8ab7c4fa414fb9e619f37ddba78 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/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": "createtypeerror_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/.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/JsvmUsageGuide/JsvmError/getandclearlastexception/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/getandclearlastexception/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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/JsvmUsageGuide/JsvmError/getandclearlastexception/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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/JsvmUsageGuide/JsvmError/getandclearlastexception/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce9fb1f628d737667d32b52f1f1964b5047bc45f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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": "getandclearlastexception", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetandclearlastexception.so": "file:./src/main/cpp/types/libgetandclearlastexception" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1f3a62ea9111f4d8d67bdf8728942e26ff9356f0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(getandclearlastexception SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getandclearlastexception PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a64b404d11f0935de8c1dcb70547190099719d9d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/hello.cpp @@ -0,0 +1,156 @@ +/* + * 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) + +// [Start oh_jsvm_get_and_clear_last_exception] +// OH_JSVM_GetAndClearLastException的样例方法 +static JSVM_Value JsVmGetAndClearLastException(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 抛出异常,创造异常情况 + OH_JSVM_ThrowError(env, "OH_JSVM_ThrowError errorCode", "OH_JSVM_ThrowError errorMessage"); + // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); + if (status != JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_GetAndClearLastException FAILED"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_GetAndClearLastException SUCCESS"); + } + return result; +} +// JsVmGetAndClearLastException注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmGetAndClearLastException}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmGetAndClearLastException方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmGetAndClearLastException", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmGetAndClearLastException();)JS"; +// [End oh_jsvm_get_and_clear_last_exception] + +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 = "getandclearlastexception", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4ff65b223c56c15626197f64f70c846369ade636 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/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": "libgetandclearlastexception.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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets index 8209ef96f0a8d61413ee0f34bba65ece19ea77ac..e23d25077c5408c2e1149af19212c74716b482fe --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets @@ -1,56 +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 GetandclearlastexceptionAbility 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'); - } -}; +/* + * 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 GetandclearlastexceptionAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..cd32c826799b8f8253e5f53fef97c74c7ba1822a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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 'libgetandclearlastexception.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4891dbbfdebeae1cfaa72d34fe5d2c5e319e3280 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getandclearlastexception", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetandclearlastexceptionAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetandclearlastexceptionAbility", + "srcEntry": "./ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets", + "description": "$string:GetandclearlastexceptionAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetandclearlastexceptionAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c7016b49b9da4821d09c14c694b69fbfd002dc7b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetandclearlastexceptionAbility_desc", + "value": "description" + }, + { + "name": "GetandclearlastexceptionAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ae265192b6a53bedf436bd13b93aba8b5b029251 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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('testGetAndClearLastException', 0, async (done: Function) => { + console.log('uitest: TestGetAndClearLastException begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetandclearlastexceptionAbility' + } + 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('GetandclearlastexceptionAbility'); + + 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: TestGetAndClearLastException end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e8a5853c79815a1a389736df48c2057aa2af0fd0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/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": "getandclearlastexception_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/.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/JsvmUsageGuide/JsvmError/getlasterrorinfo/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/getlasterrorinfo/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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/JsvmUsageGuide/JsvmError/getlasterrorinfo/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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/JsvmUsageGuide/JsvmError/getlasterrorinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..027afee4c3683a076fe3f60ecf4292cdee8e3abd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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": "getlasterrorinfo", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetlasterrorinfo.so": "file:./src/main/cpp/types/libgetlasterrorinfo" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..89a61c4de9837c4c4c365c4c28902596710a4feb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(getlasterrorinfo SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getlasterrorinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f7b3f1237c36b2099ae033e866258124dea5431 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/hello.cpp @@ -0,0 +1,166 @@ +/* + * 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) + +// [Start oh_jsvm_get_last_error_info] +// OH_JSVM_GetLastErrorInfo的样例方法 +static JSVM_Value JsVmGetLastErrorInfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取输入参数(这里以字符串message作为参数传入) + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 将传入的字符串参数以OH_JSVM_GetValueInt32取出,主动制造错误 + int32_t value = 0; + OH_JSVM_GetValueInt32(env, args[0], &value); + // 调用接口OH_JSVM_GetLastErrorInfo获取最后一次错误信息 + const JSVM_ExtendedErrorInfo *errorInfo; + OH_JSVM_GetLastErrorInfo(env, &errorInfo); + + // 取出错误消息作为返回值带出去打印 + JSVM_Value result = nullptr; + OH_LOG_INFO(LOG_APP, + "JSVM API OH_JSVM_GetLastErrorInfo: SUCCESS, error message is %{public}s, error code is %{public}d", + errorInfo->errorMessage, errorInfo->errorCode); + // 对异常进行处理,防止程序由于抛异常而退出 + JSVM_Value result1 = nullptr; + OH_JSVM_GetAndClearLastException(env, &result1); + OH_JSVM_CreateInt32(env, errorInfo->errorCode, &result); + return result; +} +// JsVmGetLastErrorInfo注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmGetLastErrorInfo}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmGetLastErrorInfo方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmGetLastErrorInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmGetLastErrorInfo();)JS"; +// [End oh_jsvm_get_last_error_info] + +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 = "getlasterrorinfo", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cd07d9e1ff30f0e79831dfed9f802bd08db50074 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/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": "libgetlasterrorinfo.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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets index c1df8a88e9379f0f2451a7c8a06831efd4b93bd0..70352007a6595c22c15e0f633d84b2afea30999f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets @@ -1,56 +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 GetlasterrorInfoAbility 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'); - } -}; +/* + * 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 GetlasterrorInfoAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e488f42860517829b932c22fbc0ddd9b1b716c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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 'libgetlasterrorinfo.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a4923980f38b52633ee73e7994bbb2f5ef44715c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getlasterrorinfo", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetlasterrorInfoAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetlasterrorInfoAbility", + "srcEntry": "./ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets", + "description": "$string:GetlasterrorInfoAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetlasterrorInfoAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..16097cf65589d1faa951244e44bb4435e14b04f4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetlasterrorInfoAbility_desc", + "value": "description" + }, + { + "name": "GetlasterrorInfoAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..79afcc5677db20ebf9d6b99dd9089e4b243ec010 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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('testGetLastErrorInfo', 0, async (done: Function) => { + console.log('uitest: TestGetLastErrorInfo begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetlasterrorInfoAbility' + } + 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('GetlasterrorInfoAbility'); + + 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: TestGetLastErrorInfo end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c8353f702747ee19204bd7aa4c7219cc8eb2df3a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/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": "getlasterrorinfo_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/.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/JsvmUsageGuide/JsvmError/iserror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/iserror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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/JsvmUsageGuide/JsvmError/iserror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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/JsvmUsageGuide/JsvmError/iserror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7e807ee8cdf0b9e5320439088b3012418f4f3d86 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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": "iserror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libiserror.so": "file:./src/main/cpp/types/libiserror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0688691815f5f2ed3de3c442c8b94ea8110da221 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(iserror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(iserror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf50296c12e2a6872a7ddf8384c5806a2ee20e2e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/hello.cpp @@ -0,0 +1,161 @@ +/* + * 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) + +// [Start oh_jsvm_is_error] +// OH_JSVM_IsError的样例方法 +static JSVM_Value JsVmIsError(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); + // 调用接口OH_JSVM_IsError判断入参是否为一个error对象 + bool result = false; + // 如果JSVM_Value为一个error对象,则设置result为true的布尔值,否则设置为false + JSVM_Status status = OH_JSVM_IsError(env, args[0], &result); + if (status == JSVM_OK) { + OH_LOG_INFO(LOG_APP, "JSVM API call OH_JSVM_IsError success, result is %{public}d", result); + } else { + OH_LOG_INFO(LOG_APP, "JSVM API call OH_JSVM_IsError failed"); + } + // 取出result通过OH_JSVM_GetBoolean接口将取出的bool值转换为JSVM_Value类型的值返回出去 + JSVM_Value returnValue = nullptr; + OH_JSVM_GetBoolean(env, result, &returnValue); + return returnValue; +} +// JsVmIsError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmIsError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmIsError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmIsError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmIsError(Error()))JS"; +// [End oh_jsvm_is_error] + +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 = "iserror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/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/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..926afa128701ef325532483e5a43e18c05f13b9e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/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": "libiserror.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/JsvmUsageGuide/JsvmError/iserror/src/main/ets/iserrorability/IserrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/iserrorability/IserrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/iserrorability/IserrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/iserrorability/IserrorAbility.ets index c7c66b070a1bf06e3f3c64ac1b05b905626abb5d..fef24b4d9e03f2d1a02f00a37dc2aed381922e44 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/iserrorability/IserrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/iserrorability/IserrorAbility.ets @@ -1,56 +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 IserrorAbility 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'); - } -}; +/* + * 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 IserrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..59cc37cf1168d61d5d1fc6d3f18899e12d592916 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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 'libiserror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/iserror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..54300ca15bdfc24bb15879470b555a3c530d0df1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "iserror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IserrorAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IserrorAbility", + "srcEntry": "./ets/iserrorability/IserrorAbility.ets", + "description": "$string:IserrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IserrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6b8f8fce3d4987ce83046755318c47379fc8291b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IserrorAbility_desc", + "value": "description" + }, + { + "name": "IserrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..09dd8628c07a7aac060caab554cf46447a2a1ce1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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('testIsError', 0, async (done: Function) => { + console.log('uitest: TestIsError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IserrorAbility' + } + 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('IserrorAbility'); + + 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: TestIsError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/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/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..378102b3e71973c25080c5264ed8744628c399b2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "iserror_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/.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/JsvmUsageGuide/JsvmError/isexceptionpending/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/isexceptionpending/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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/JsvmUsageGuide/JsvmError/isexceptionpending/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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/JsvmUsageGuide/JsvmError/isexceptionpending/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..52141205c9f0f549c425080b96b2e0ede72b8a71 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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": "isexceptionpending", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libisexceptionpending.so": "file:./src/main/cpp/types/libisexceptionpending" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c31f3153cc3664b52b87f2451de3121d6aa67750 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(isexceptionpending SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(isexceptionpending PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15530e8edf04d62031e6383142283241be595ef9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/hello.cpp @@ -0,0 +1,168 @@ +/* + * 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) + +// [Start oh_jsvm_is_exception_pending] +// OH_JSVM_GetAndClearLastException的样例方法 +static JSVM_Value JsVmIsExceptionPending(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Status status; + bool isExceptionPending = false; + // 在执行一些可能引发异常的操作后 + OH_JSVM_ThrowError(env, "OH_JSVM_ThrowError errorCode", "OH_JSVM_ThrowError errorMessage"); + // 检查当前环境中是否有异常挂起 + status = OH_JSVM_IsExceptionPending(env, &isExceptionPending); + if (status != JSVM_OK) { + return nullptr; + } + if (isExceptionPending) { + OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_IsExceptionPending: SUCCESS"); + // 处理异常挂起的情况 + JSVM_Value result = nullptr; + status = OH_JSVM_GetAndClearLastException(env, &result); + if (status != JSVM_OK) { + return nullptr; + } + // 将处理的异常返回出去 + return result; + } else { + OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_IsExceptionPending: FAILED"); + } + return nullptr; +} +// JsVmIsExceptionPending注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmIsExceptionPending}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmIsExceptionPending方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmIsExceptionPending", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmIsExceptionPending();)JS"; +// [End oh_jsvm_is_exception_pending] + +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 = "isexceptionpending", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..93b0b1126a1faf89ac68a6231d954c977c6ef16b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/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": "libisexceptionpending.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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/isexceptionpendingability/IsexceptionpendingAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/isexceptionpendingability/IsexceptionpendingAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/isexceptionpendingability/IsexceptionpendingAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/isexceptionpendingability/IsexceptionpendingAbility.ets index 509b469f697978a18f9bcc09013980eb20522f10..257fee01bddbc70a98d7935c78d90eae9b2d7ba1 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/isexceptionpendingability/IsexceptionpendingAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/isexceptionpendingability/IsexceptionpendingAbility.ets @@ -1,56 +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 IsexceptionpendingAbility 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'); - } -}; +/* + * 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 IsexceptionpendingAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8898b91ea2f14c47ee64cb24b87e179ddc7560eb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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 'libisexceptionpending.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a33aebf396e2f7a635e60f176ec27900e08565b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "isexceptionpending", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "IsexceptionpendingAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "IsexceptionpendingAbility", + "srcEntry": "./ets/isexceptionpendingability/IsexceptionpendingAbility.ets", + "description": "$string:IsexceptionpendingAbility_desc", + "icon": "$media:layered_image", + "label": "$string:IsexceptionpendingAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3399f5a2fa01d721498b0ebd3443df2fc00bec6a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "IsexceptionpendingAbility_desc", + "value": "description" + }, + { + "name": "IsexceptionpendingAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb34bd84017ca874f6f403c3bb1b170a7941fe35 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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('testIsExceptionPending', 0, async (done: Function) => { + console.log('uitest: TestIsExceptionPending begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'IsexceptionpendingAbility' + } + 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('IsexceptionpendingAbility'); + + 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: TestIsExceptionPending end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/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/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c86b2c326c2d5de59f68448561d2c18f202e2fcb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "isexceptionpending_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/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/JsvmUsageGuide/JsvmError/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..8e25fa8cc7a8710c82ccf19b0ee16751dc36175a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/ohosTest.md @@ -0,0 +1,20 @@ +# JsvmError 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------ | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript Error | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript RangeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript SyntaxError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript TypeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取并清除最近一次出现的异常 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 获取调用JSVM接口最后一次发生的错误信息 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断给定的JSVM_Value是否表示一个error对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断是否出现了异常 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 抛出一个带文本信息的JS Error | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript RangeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript SyntaxError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript SyntaxError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 创建并获取一个带文本信息的JavaScript TypeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/screenshots/JsvmError_2.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/.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/JsvmUsageGuide/JsvmError/throwerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/throwerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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/JsvmUsageGuide/JsvmError/throwerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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/JsvmUsageGuide/JsvmError/throwerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aba6265ae563ef6525c3ce27128b3ef9ecccb1f1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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": "throwerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libthrowerror.so": "file:./src/main/cpp/types/libthrowerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..561b1fafd25ffac96c4eaf22aef112dc5ce6d6a7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(throwerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(throwerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f1ae595fa19b8859d605fd41b45b94d7472c465a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/hello.cpp @@ -0,0 +1,183 @@ +/* + * 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) + +static void GetLastErrorAndClean(JSVM_Env env) +{ + // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); + // 打印错误信息 + JSVM_Value message; + JSVM_Value errorCode; + OH_JSVM_GetNamedProperty((env), result, "message", &message); + OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); + const int maxMessageLength = 256; + const int maxCodeLength = 256; + char messagestr[maxMessageLength]; + char codeStr[maxCodeLength]; + OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); + OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); + OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); +} + +// [Start oh_jsvm_throw_error] +// OH_JSVM_ThrowError的样例方法 +static JSVM_Value JsVmThrowError(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + if (argc == 0) { + // 如果没有传递参数,直接抛出错误 + OH_JSVM_ThrowError(env, "-1", "has Error"); + } else if (argc == 1) { + size_t length; + // 通过入参获取到javaScript侧传入的字符串长度。 + OH_JSVM_GetValueStringUtf8(env, argv[0], nullptr, 0, &length); + char *buffer = new char[length + 1]; + // 获取入参的字符串内容。 + OH_JSVM_GetValueStringUtf8(env, argv[0], buffer, length + 1, nullptr); + // 作为error信息填入到OH_JSVM_ThrowError接口中。 + OH_JSVM_ThrowError(env, "self defined error code", buffer); + delete[] buffer; + } + GetLastErrorAndClean(env); + return nullptr; +} +// JsVmThrowError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmThrowError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmThrowError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmThrowError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmThrowError();jsVmThrowError("self defined error message");)JS"; +// [End oh_jsvm_throw_error] + +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 = "throwerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/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/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e44e55f9001c789bd21cef11b0fe77c661bd2bfc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/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": "libthrowerror.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/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb4f2484d26bdb1a90cd24c40d515bcc3654259b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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 'libthrowerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/throwerrorability/ThrowerrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/throwerrorability/ThrowerrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/throwerrorability/ThrowerrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/throwerrorability/ThrowerrorAbility.ets index 897f255f8c773ce9c273008f6c4bbd7f9df516b5..ec0453fc4da29bc16ccf674ff3d07279d434a675 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/throwerrorability/ThrowerrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/throwerrorability/ThrowerrorAbility.ets @@ -1,56 +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 ThrowerrorAbility 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'); - } -}; +/* + * 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 ThrowerrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bb657a31b515a4b300027e097c24b7433e104301 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "throwerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ThrowerrorAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ThrowerrorAbility", + "srcEntry": "./ets/throwerrorability/ThrowerrorAbility.ets", + "description": "$string:ThrowerrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ThrowerrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d7fcd5ad6f3e963a9e590e6824bc8c7c4429969b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ThrowerrorAbility_desc", + "value": "description" + }, + { + "name": "ThrowerrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..56ee26520593f14ff573c7960387ec1df1ad1caf --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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('testThrowError', 0, async (done: Function) => { + console.log('uitest: TestThrowError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ThrowerrorAbility' + } + 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('ThrowerrorAbility'); + + 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: TestThrowError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/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/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8d6e408d5fcc995a6a1a70646670189d936c4c81 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "throwerror_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/.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/JsvmUsageGuide/JsvmError/throwrangeerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/throwrangeerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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/JsvmUsageGuide/JsvmError/throwrangeerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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/JsvmUsageGuide/JsvmError/throwrangeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6366a341fe91fdeb8b263b57a1b4188b22836a6f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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": "throwrangeerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libthrowrangeerror.so": "file:./src/main/cpp/types/libthrowrangeerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bb0d5f352bfbf3cc9b9c6d20b28a09dc1ca9f7a8 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(throwrangeerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(throwrangeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4269865e3ad7b5d6b28a133af621d0eaeaf73a6a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/hello.cpp @@ -0,0 +1,179 @@ +/* + * 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) + +// 捕获清除并打印错误,该函数作为公共函数,在本文档后续样例中不再声明和定义 +static void GetLastErrorAndClean(JSVM_Env env) +{ + // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); + // 打印错误信息 + JSVM_Value message; + JSVM_Value errorCode; + OH_JSVM_GetNamedProperty((env), result, "message", &message); + OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); + const int maxMessageLength = 256; + const int maxCodeLength = 256; + char messagestr[maxMessageLength]; + char codeStr[maxCodeLength]; + OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); + OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); + OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); +} + +// [Start oh_jsvm_throw_range_error] +// OH_JSVM_ThrowRangeError的样例方法 +static JSVM_Value JsVmThrowRangeError(JSVM_Env env, JSVM_CallbackInfo info) +{ + // js侧传入两个参数 + size_t argc = 2; + JSVM_Value argv[2] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + // 如果传入参数个数不为2 + if (argc != 2) { + // 这里抛出一个RangeError + OH_JSVM_ThrowRangeError(env, "OH_JSVM_ThrowRangeError", "Expected two numbers as arguments"); + GetLastErrorAndClean(env); + return nullptr; + } + JSVM_Value result = nullptr; + OH_JSVM_GetBoolean(env, true, &result); + return result; +} +// JsVmThrowRangeError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmThrowRangeError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmThrowRangeError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmThrowRangeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmThrowRangeError(1);)JS"; +// [End oh_jsvm_throw_range_error] + +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 = "throwrangeerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fc45dc27dc2057f4a3989531be3a1f9350b3b0b5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/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": "libthrowrangeerror.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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..51c64d091a4dee4a28c915e36a87313c4f73eea1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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 'libthrowrangeerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/throwrangeerrorability/ThrowrangeerrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/throwrangeerrorability/ThrowrangeerrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/throwrangeerrorability/ThrowrangeerrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/throwrangeerrorability/ThrowrangeerrorAbility.ets index 05e9c0d253d1acbd333ca4210a9fdc0ccb1b1ec9..3d02deea2786329ba329edd24dc145510172d51d --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/throwrangeerrorability/ThrowrangeerrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/throwrangeerrorability/ThrowrangeerrorAbility.ets @@ -1,56 +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 ThrowrangeerrorAbility 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'); - } -}; +/* + * 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 ThrowrangeerrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..19f876193ac297ccb7f1b2ac5f33368b0851d870 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "throwrangeerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ThrowrangeerrorAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ThrowrangeerrorAbility", + "srcEntry": "./ets/throwrangeerrorability/ThrowrangeerrorAbility.ets", + "description": "$string:ThrowrangeerrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ThrowrangeerrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..136d4395f271512d170448ccfdff250a70a0010f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ThrowrangeerrorAbility_desc", + "value": "description" + }, + { + "name": "ThrowrangeerrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..424cae4a7ffbd909b4554628d8310ce8a67e4ce5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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('testThrowRangeError', 0, async (done: Function) => { + console.log('uitest: TestThrowRangeError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ThrowrangeerrorAbility' + } + 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('ThrowrangeerrorAbility'); + + 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: TestThrowRangeError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/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/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..20b06c3ea787fab1b5ba98a84a56ed12cc26a8d4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "throwrangeerror_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/.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/JsvmUsageGuide/JsvmError/throwsyntaxerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/throwsyntaxerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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/JsvmUsageGuide/JsvmError/throwsyntaxerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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/JsvmUsageGuide/JsvmError/throwsyntaxerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..53f860259f381a8b67766fd5e64e638fd1b73003 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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": "throwsyntaxerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libthrowsyntaxerror.so": "file:./src/main/cpp/types/libthrowsyntaxerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..680ef809be974477c9186a5a68173bc2a3cd5804 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(throwsyntaxerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(throwsyntaxerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba54e1427004ef429513c4e7415e863efc0f3717 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/hello.cpp @@ -0,0 +1,184 @@ +/* + * 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) + +// 捕获清除并打印错误,该函数作为公共函数,在本文档后续样例中不再声明和定义 +static void GetLastErrorAndClean(JSVM_Env env) +{ + // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); + // 打印错误信息 + JSVM_Value message; + JSVM_Value errorCode; + OH_JSVM_GetNamedProperty((env), result, "message", &message); + OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); + const int maxMessageLength = 256; + const int maxCodeLength = 256; + char messagestr[maxMessageLength]; + char codeStr[maxCodeLength]; + OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); + OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); + OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); +} + +// [Start oh_jsvm_throw_syntax_error] +// OH_JSVM_ThrowSyntaxError的样例方法 +static JSVM_Value JsVmThrowSyntaxError(JSVM_Env env, JSVM_CallbackInfo info) +{ + // JS侧传入运行的JS代码 + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + JSVM_Script script = nullptr; + // 通过OH_JSVM_CompileScript接口编译JS代码 + OH_JSVM_CompileScript(env, argv[0], nullptr, 0, true, nullptr, &script); + JSVM_Value scriptResult = nullptr; + // 通过OH_JSVM_RunScript接口运行JS代码 + JSVM_Status status = OH_JSVM_RunScript(env, script, &scriptResult); + if (status != JSVM_OK) { + // 如果JSVM_RunScript接口返回状态不为JSVM_OK,则抛出一个SyntaxError + OH_JSVM_ThrowSyntaxError(env, "JsVmThrowSyntaxError", "throw syntax error"); + GetLastErrorAndClean(env); + return nullptr; + } + JSVM_Value result = nullptr; + OH_JSVM_GetBoolean(env, true, &result); + return result; +} +// JsVmThrowSyntaxError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmThrowSyntaxError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmThrowSyntaxError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmThrowSyntaxError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmThrowSyntaxError();)JS"; +// [End oh_jsvm_throw_syntax_error] + +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 = "throwsyntaxerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..da7cb3b77c82de216915498955d2aac2c954ecc6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/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": "libthrowsyntaxerror.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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b527e27d96c6a0b4bcce69add10aa3ab21aff30e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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 'libthrowsyntaxerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets index acb971da27effdf43dd8f4d499d444b5536afa9f..1e16c210f1678ad3d7c51cfca0fbfb0f1f488e4f --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets @@ -1,56 +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 ThrowsyntaxerrorAbility 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'); - } -}; +/* + * 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 ThrowsyntaxerrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a9c59db7c7abf605e529c269d9913c10f611b303 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "throwsyntaxerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ThrowsyntaxerrorAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ThrowsyntaxerrorAbility", + "srcEntry": "./ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets", + "description": "$string:ThrowsyntaxerrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ThrowsyntaxerrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1cb0b10b447f02acc3d69ad1263a38584d41dd38 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ThrowsyntaxerrorAbility_desc", + "value": "description" + }, + { + "name": "ThrowsyntaxerrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3bf8f3e6d0e45e518600f3e951d740c3217dbd2d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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('testThrowSyntaxError', 0, async (done: Function) => { + console.log('uitest: TestThrowSyntaxError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ThrowsyntaxerrorAbility' + } + 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('ThrowsyntaxerrorAbility'); + + 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: TestThrowSyntaxError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..88f620e8499fdbdb17459561f453d0847e9c4e6d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "throwsyntaxerror_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/.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/JsvmUsageGuide/JsvmError/throwtypeerror/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmError/throwtypeerror/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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/JsvmUsageGuide/JsvmError/throwtypeerror/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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/JsvmUsageGuide/JsvmError/throwtypeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0ee682a348217166df7cb7acef906fd1ef73fa5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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": "throwtypeerror", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libthrowtypeerror.so": "file:./src/main/cpp/types/libthrowtypeerror" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..48f97e21c2c5766353b414d2f4e4be3ca77b9012 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmError) + +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) + +add_library(throwtypeerror SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(throwtypeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49d8898f15ef6772086100f9b5fc8f91cc6cc112 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/hello.cpp @@ -0,0 +1,183 @@ +/* + * 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) + +static void GetLastErrorAndClean(JSVM_Env env) +{ + // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); + // 打印错误信息 + JSVM_Value message; + JSVM_Value errorCode; + OH_JSVM_GetNamedProperty((env), result, "message", &message); + OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); + const int maxMessageLength = 256; + const int maxCodeLength = 256; + char messagestr[maxMessageLength]; + char codeStr[maxCodeLength]; + OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); + OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); + OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); +} + +// [Start oh_jsvm_throw_type_error] +// OH_JSVM_ThrowTypeError的样例方法 +static JSVM_Value JsVmThrowTypeError(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); + if (argc == 0) { + // 如果没有传递参数,直接抛出错误 + OH_JSVM_ThrowTypeError(env, "-1", "throwing type error"); + } else if (argc == 1) { + size_t length; + // 通过入参获取到javaScript侧传入的字符串长度 + OH_JSVM_GetValueStringUtf8(env, argv[0], nullptr, 0, &length); + char *buffer = new char[length + 1]; + // 获取入参的字符串内容 + OH_JSVM_GetValueStringUtf8(env, argv[0], buffer, length + 1, nullptr); + // 作为error信息填入到OH_JSVM_ThrowError接口中 + OH_JSVM_ThrowTypeError(env, "self defined error code", buffer); + delete[] buffer; + } + GetLastErrorAndClean(env); + return nullptr; +} +// JsVmThrowTypeError注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsVmThrowTypeError}, +}; +static JSVM_CallbackStruct *method = param; +// JsVmThrowTypeError方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"jsVmThrowTypeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; +// 样例测试js +const char *SRC_CALL_NATIVE = R"JS(jsVmThrowTypeError();jsVmThrowTypeError("self defined error message");)JS"; +// [End oh_jsvm_throw_type_error] + +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 = "throwtypeerror", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f14a6db9ce479d9512417b24e0fe8f2094f33224 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/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": "libthrowtypeerror.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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a49adff02a87823a265b83cd4e8f6fa715dce6c2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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 'libthrowtypeerror.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/throwtypeerrorability/ThrowtypeerrorAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/throwtypeerrorability/ThrowtypeerrorAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/throwtypeerrorability/ThrowtypeerrorAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/throwtypeerrorability/ThrowtypeerrorAbility.ets index 2d14d456ad182f74769adf164940b6aec51b52c7..2c1dab4730d58a1c018eb0b128b469d0048f57e9 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/throwtypeerrorability/ThrowtypeerrorAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/throwtypeerrorability/ThrowtypeerrorAbility.ets @@ -1,56 +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 ThrowtypeerrorAbility 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'); - } -}; +/* + * 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 ThrowtypeerrorAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6a7f7e1f3c6c84781fa5f0009f0d5285f70642b2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/module.json5 @@ -0,0 +1,44 @@ +/* + * 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": "throwtypeerror", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ThrowtypeerrorAbility", + "deviceTypes": [ + "default", + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ThrowtypeerrorAbility", + "srcEntry": "./ets/throwtypeerrorability/ThrowtypeerrorAbility.ets", + "description": "$string:ThrowtypeerrorAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ThrowtypeerrorAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..908e0f170b85598f786a81d6d158f7dc5d65bf7f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ThrowtypeerrorAbility_desc", + "value": "description" + }, + { + "name": "ThrowtypeerrorAbility_label", + "value": "JsvmError" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b234d6ecd865af6898f6943551dcd96c32f294c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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('testThrowTypeError', 0, async (done: Function) => { + console.log('uitest: TestThrowTypeError begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ThrowtypeerrorAbility' + } + 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('ThrowtypeerrorAbility'); + + 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: TestThrowTypeError end'); + done(); + }) + }) +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/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/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d18ae367f49c69ca82cd9fb394d323dfa3bbada --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "throwtypeerror_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..03f0b7aac0d4ce9f3184cf0201d4cdb0b5d7f4bd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/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.jsvmlifecycle", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a81a963d2ca9ee54da5496e886e9a59e1f6112e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmLifeCycle" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/README.md new file mode 100644 index 0000000000000000000000000000000000000000..fb56535ae3b7906bf20a10c7b9a9239ede6d1858 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/README.md @@ -0,0 +1,141 @@ +# ArkTs使用JSVM-API接口进行生命周期相关开发 + +### 介绍 + +在JSVM-API中,JSVM_Value是一个表示JavaScript值的抽象类型,它可以表示任何JavaScript值,包括基本类型(如数字、字符串、布尔值)和对象类型(如数组、函数、对象等)。 JSVM_Value的生命周期与其在JavaScript中的对应值的生命周期紧密相关。当JavaScript值被垃圾回收时,与之关联的JSVM_Value也将不再有效。重要的是不要在JavaScript值不再存在时尝试使用JSVM_Value。 + +框架层的scope通常用于管理JSVM_Value的生命周期。在JSVM-API中,可以使用OH_JSVM_OpenHandleScope和OH_JSVM_CloseHandleScope函数来创建和销毁scope。通过在scope内创建JSVM_Value,可以确保在scope结束时自动释放JSVM_Value,避免内存泄漏。 + +JSVM_Ref是一个JSVM-API类型,用于管理JSVM_Value的生命周期。JSVM_Ref允许您在JSVM_Value的生命周期内保持对其的引用,即使它已经超出了其原始上下文的范围。这使得您可以在不同的上下文中共享JSVM_Value,并确保在不再需要时正确释放其内存。 + +合理使用OH_JSVM_OpenHandleScope和OH_JSVM_CloseHandleScope管理JSVM_Value的生命周期,做到生命周期最小化,避免发生内存泄漏问题。 + +每个JSVM_Value属于特定的HandleScope,HandleScope通过OH_JSVM_OpenHandleScope和OH_JSVM_CloseHandleScope来建立和关闭,HandleScope关闭后,所属的JSVM_Value就会自动释放。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行生命周期相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-life-cycle.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :---------------------------------------------------------------: | :---------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +addfinalizer/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +openescapablehandlescope/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +openhandlescope/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +referenceref/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmLifeCycle > .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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/.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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8f7a117b0c0ec70ae8a442979fecae40d15334b3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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": "addfinalizer", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libaddfinalizer.so": "file:./src/main/cpp/types/libaddfinalizer" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6b5f8e481338c0d3863d44d94c6d775c05dbc685 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmLifeCycle) + +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) + +add_library(addfinalizer SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(addfinalizer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f21dfdd8c559ac99d3b213293bb663f597c7fe47 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/hello.cpp @@ -0,0 +1,126 @@ +/* + * 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) + +// [Start oh_jsvm_add_finalizer] +static int AddFinalizer(JSVM_VM vm, JSVM_Env env) +{ + // 打开 handlescope + JSVM_HandleScope handleScope; + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + // 创建 object 并设置回调 + JSVM_Value obj; + CHECK_RET(OH_JSVM_CreateObject(env, &obj)); + CHECK_RET(OH_JSVM_AddFinalizer( + env, obj, nullptr, + [](JSVM_Env env, void *data, void *hint) -> void { + // Finalizer 方法,可在该方法中清理 Native 对象 + OH_LOG_INFO(LOG_APP, "JSVM: finalizer called."); + }, + nullptr, nullptr)); + OH_LOG_INFO(LOG_APP, "JSVM: finalizer added."); + // 关闭 handlescope,触发 GC,GC 时 Finalizer 会被调用 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + OH_LOG_INFO(LOG_APP, "JSVM: before call gc."); + CHECK_RET(OH_JSVM_MemoryPressureNotification(env, JSVM_MemoryPressureLevel::JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL)); + OH_LOG_INFO(LOG_APP, "JSVM: after call gc."); + + return 0; +} + +static void RunDemo(JSVM_VM vm, JSVM_Env env) +{ + if (AddFinalizer(vm, env) != 0) { + OH_LOG_INFO(LOG_APP, "Run PromiseRegisterHandler failed"); + } +} +// [End oh_jsvm_add_finalizer] + +static napi_value RunTest(napi_env env, napi_callback_info info) +{ + JSVM_VM vm; + JSVM_Env envs = nullptr; + RunDemo(vm, envs); + 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 = "addfinalizer", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2c7b363db44fe3c00a262ea3b7c7883ccba2de84 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/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": "libaddfinalizer.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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/addfinalizerability/AddfinalizerAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/addfinalizerability/AddfinalizerAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/addfinalizerability/AddfinalizerAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/addfinalizerability/AddfinalizerAbility.ets index 8e9507b136e0e4eba2f6ac7bc67a5d3ff2237a02..3f175ec34f970a29960520067d7753fde77f8a05 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/addfinalizerability/AddfinalizerAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/addfinalizerability/AddfinalizerAbility.ets @@ -1,56 +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 AddfinalizerAbility 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'); - } -}; +/* + * 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 AddfinalizerAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ecafb6e1aa76975408c5da11a28ed7f78f39021 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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 'libaddfinalizer.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d7637b4badac4ab8f1b8805eeeec455cdd679fe7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "addfinalizer", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "AddfinalizerAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "AddfinalizerAbility", + "srcEntry": "./ets/addfinalizerability/AddfinalizerAbility.ets", + "description": "$string:AddfinalizerAbility_desc", + "icon": "$media:layered_image", + "label": "$string:AddfinalizerAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..07298009eb7fbbd1a103648eb17ece950b529893 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "AddfinalizerAbility_desc", + "value": "description" + }, + { + "name": "AddfinalizerAbility_label", + "value": "JsvmLifeCycle" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..856c055bab897cb88883814cd19ae866070c1f7f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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('testAddFinalizer', 0, async (done: Function) => { + console.log('uitest: TestAddFinalizer begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'AddfinalizerAbility' + } + 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('AddfinalizerAbility'); + + 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: TestAddFinalizer end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cbed882e355404e47694ff17ee8364ffba2842e6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/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": "addfinalizer_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7cfbd6f62e60092f62f20c2390ac67c315044a0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/build-profile.json5 @@ -0,0 +1,94 @@ +/* + * 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": "openhandlescope", + "srcPath": "./openhandlescope", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "openescapablehandlescope", + "srcPath": "./openescapablehandlescope", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "referenceref", + "srcPath": "./referenceref", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "addfinalizer", + "srcPath": "./addfinalizer", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1e473e424320d4e68b16737b289f5c851bb19d36 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "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/NodeAPI/NodeApiUse/NodeAPIDate/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/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/JsvmUsageGuide/JsvmLifeCycle/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..d07a4aa352b945a84dcc5ee046f0828d35769147 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/ohosTest.md @@ -0,0 +1,11 @@ +# JsvmLifeCycle 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 为对象添加JSVM_Finalize回调,以便在JavaScript对象被垃圾回收时调用来释放原生对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 打开一个新的scope逃逸Handle scope,在关闭该scope之前创建的对象与父作用域有相同的生命周期 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 打开一个Handle scope,确保scope范围内的JSVM_Value不被GC回收 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 增加由Hello World创建的引用的引用计数,以确保对象在有引用时不会被提前释放 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/.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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f0cdca70796e03dcf71f2256a32affa04e2bf7bd --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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": "openescapablehandlescope", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libopenescapablehandlescope.so": "file:./src/main/cpp/types/libopenescapablehandlescope" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6009db002510ae53c0920c455c2604568d167b54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmLifeCycle) + +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) + +add_library(openescapablehandlescope SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(openescapablehandlescope PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbf119d706c1db74813cc572d9c63f1a613ca1af --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/hello.cpp @@ -0,0 +1,177 @@ +/* + * 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) + +// [Start oh_jsvm_open_escapable_handle_scope_close_escapable_handle_scope_escape_handle] +// OH_JSVM_OpenEscapableHandleScope、OH_JSVM_CloseEscapableHandleScope、OH_JSVM_EscapeHandle的样例方法 +static JSVM_Value EscapableHandleScopeTest(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 创建一个可逃逸的句柄作用域 + JSVM_EscapableHandleScope scope = nullptr; + JSVM_Status status = OH_JSVM_OpenEscapableHandleScope(env, &scope); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_OpenEscapableHandleScope: failed"); + return nullptr; + } + // 在可逃逸的句柄作用域内创建一个obj + JSVM_Value obj; + OH_JSVM_CreateObject(env, &obj); + // 在对象中添加属性 + JSVM_Value value = nullptr; + OH_JSVM_CreateStringUtf8(env, "Test jsvm_escapable_handle_scope", JSVM_AUTO_LENGTH, &value); + OH_JSVM_SetNamedProperty(env, obj, "name", value); + // 调用OH_JSVM_EscapeHandle将对象逃逸到作用域之外 + JSVM_Value escapedObj = nullptr; + OH_JSVM_EscapeHandle(env, scope, obj, &escapedObj); + // 关闭可逃逸的句柄作用域,清理资源 + status = OH_JSVM_CloseEscapableHandleScope(env, scope); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CloseEscapableHandleScope: failed"); + return nullptr; + } + // 此时的escapedObj已逃逸,可以在作用域外继续使用escapedObj + bool result = false; + OH_JSVM_CreateStringUtf8(env, "name", JSVM_AUTO_LENGTH, &value); + OH_JSVM_HasProperty(env, escapedObj, value, &result); + if (result) { + OH_LOG_INFO(LOG_APP, "JSVM EscapableHandleScopeTest: success"); + } + return escapedObj; +} + +// EscapableHandleScopeTest注册回调 +static JSVM_CallbackStruct param[] = { + {.callback = EscapableHandleScopeTest, .data = nullptr}, +}; +static JSVM_CallbackStruct *method = param; +// EscapableHandleScopeTest方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"escapableHandleScopeTest", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = "escapableHandleScopeTest()"; +// [End oh_jsvm_open_escapable_handle_scope_close_escapable_handle_scope_escape_handle] + +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 = "openescapablehandlescope", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fdf21229621254e83368b7fcfb6e3eb104b7167a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/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": "libopenescapablehandlescope.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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets index ca71248535f232a901b8554495decb139e2b48ae..6802668c1435816eab9873a79e2a22044680393c --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets @@ -1,56 +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 OpenescapablehandlescopeAbility 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'); - } -}; +/* + * 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 OpenescapablehandlescopeAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..25099de28d093494ad1d6e56be334073a01e81d9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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 'libopenescapablehandlescope.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ac31360dee87bac2aa7308e8cb5f78a7db424473 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "openescapablehandlescope", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "OpenescapablehandlescopeAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "OpenescapablehandlescopeAbility", + "srcEntry": "./ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets", + "description": "$string:OpenescapablehandlescopeAbility_desc", + "icon": "$media:layered_image", + "label": "$string:OpenescapablehandlescopeAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..603926c5ce7ecd45a9ad8dfe90cb803fe59db77d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "OpenescapablehandlescopeAbility_desc", + "value": "description" + }, + { + "name": "OpenescapablehandlescopeAbility_label", + "value": "JsvmLifeCycle" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4b372d04bbdb8425ab59ea3cab9e467abc9dfea --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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('testOpenEscapableHandleScope', 0, async (done: Function) => { + console.log('uitest: TestOpenEscapableHandleScope begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'OpenescapablehandlescopeAbility' + } + 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('OpenescapablehandlescopeAbility'); + + 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: TestOpenEscapableHandleScope end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..99aacbc46ab44bec0db93d6282458998a85bfe8f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/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": "openescapablehandlescope_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/.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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7afe9b6f3693a69073444e48278e0f26f2bf0f7b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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": "openhandlescope", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libopenhandlescope.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..14b69294913f02091b3387579edd5549224bcbeb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmLifeCycle) + +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) + +add_library(openhandlescope SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(openhandlescope PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e6cbf9a8b3b723940381423f133e066e973375f6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/hello.cpp @@ -0,0 +1,169 @@ +/* + * 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) + +// [Start oh_jsvm_open_handle_scope_and_oh_jsvm_close_handle_scope] +// OH_JSVM_OpenHandleScope、OH_JSVM_CloseHandleScope的三种样例方法 +static JSVM_Value HandleScopeFor(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 在for循环中频繁调用JSVM接口创建js对象时,要加handle_scope及时释放不再使用的资源。 + // 下面例子中,每次循环结束局部变量res的生命周期已结束,因此加scope及时释放其持有的js对象,防止内存泄漏 + constexpr uint32_t DIFF_VALUE_HUNDRED_THOUSAND = 10000; + JSVM_Value checked = nullptr; + for (int i = 0; i < DIFF_VALUE_HUNDRED_THOUSAND; i++) { + JSVM_HandleScope scope = nullptr; + JSVM_Status status = OH_JSVM_OpenHandleScope(env, &scope); + if (status != JSVM_OK || scope == nullptr) { + OH_JSVM_GetBoolean(env, false, &checked); + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_OpenHandleScope: failed"); + return checked; + } + JSVM_Value res = nullptr; + OH_JSVM_CreateObject(env, &res); + status = OH_JSVM_CloseHandleScope(env, scope); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CloseHandleScope: failed"); + } + } + OH_JSVM_GetBoolean(env, true, &checked); + OH_LOG_INFO(LOG_APP, "JSVM HandleScopeFor: success"); + return checked; +} + +// HandleScopeFor注册回调 +static JSVM_CallbackStruct param[] = { + {.callback = HandleScopeFor, .data = nullptr}, +}; + +static JSVM_CallbackStruct *method = param; +// HandleScopeFor方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"HandleScopeFor", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = "HandleScopeFor()"; +// [End oh_jsvm_open_handle_scope_and_oh_jsvm_close_handle_scope] + +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 = "openhandlescope", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7d6e6febff745ee031374cee7d9d1ef37c19aa75 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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": "libopenhandlescope.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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8a8cd1c9b4a87ce6fe54b1b89603d9c2fcc4b9cb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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 'libopenhandlescope.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1c9a28b2fa3543b486d1e1d0330e1a447ff9e431 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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": "openhandlescope", + "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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b6f5d69fa12fcc7a32bf475e7fe8942d3db231e0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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": "JsvmLifeCycle" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..da98ac03f9c082ea92839520fe88e2cea54a9243 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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('testOpenHandleScope', 0, async (done: Function) => { + console.log('uitest: TestOpenHandleScope 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: TestOpenHandleScope end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d34e9992399d1bd2dbf76975f16a43b207c7f656 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/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": "openhandlescope_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/.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/JsvmUsageGuide/JsvmLifeCycle/referenceref/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/JsvmLifeCycle/referenceref/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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/JsvmUsageGuide/JsvmLifeCycle/referenceref/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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/JsvmUsageGuide/JsvmLifeCycle/referenceref/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1b0a19f319251a416183feeca3e6f333ec27b2f1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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": "referenceref", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libreferenceref.so": "file:./src/main/cpp/types/libreferenceref" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cfff8a97cd98b407a408103fcea54b5d07331464 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(JsvmLifeCycle) + +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) + +add_library(referenceref SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(referenceref PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09fa88cbb068fa1946ae98a8a05f73fc5a27eeb5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/hello.cpp @@ -0,0 +1,195 @@ +/* + * 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) + +// [Start oh_jsvm_reference_ref_and_oh_jsvm_reference_unref] +static JSVM_Value UseReference(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 创建 JavaScript 对象 + JSVM_Value obj = nullptr; + OH_JSVM_CreateObject(env, &obj); + JSVM_Value value = nullptr; + OH_JSVM_CreateStringUtf8(env, "UseReference", JSVM_AUTO_LENGTH, &value); + OH_JSVM_SetNamedProperty(env, obj, "name", value); + + JSVM_Ref g_ref = nullptr; + // 创建对JavaScript对象的引用 + JSVM_Status status = OH_JSVM_CreateReference(env, obj, 1, &g_ref); + if (status != JSVM_OK) { + return nullptr; + } + + // 增加传入引用的引用计数并返回生成的引用计数 + uint32_t result; + OH_JSVM_ReferenceRef(env, g_ref, &result); + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_ReferenceRef, count = %{public}d.", result); + const int resultValue = 2; + if (result != resultValue) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_ReferenceRef: failed"); + return nullptr; + } + + // 减少传入引用的引用计数并返回生成的引用计数 + uint32_t num; + OH_JSVM_ReferenceUnref(env, g_ref, &num); + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_ReferenceUnref, count = %{public}d.", num); + if (num != 1) { + return nullptr; + } + + JSVM_Value object = nullptr; + // 通过调用OH_JSVM_GetReferenceValue获取引用的JavaScript对象 + status = OH_JSVM_GetReferenceValue(env, g_ref, &object); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetReferenceValue: failed"); + return nullptr; + } + + // 不再使用引用,通过调用OH_JSVM_DeleteReference删除对JavaScript对象的引用 + status = OH_JSVM_DeleteReference(env, g_ref); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_DeleteReference: failed"); + return nullptr; + } + + // 将获取到的对象返回 + OH_LOG_INFO(LOG_APP, "JSVM UseReference success"); + return object; +} + +// CreateReference、UseReference、DeleteReference注册回调 +static JSVM_CallbackStruct param[] = { + {.callback = UseReference, .data = nullptr}, +}; +static JSVM_CallbackStruct *method = param; +// CreateReference、UseReference、DeleteReference方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"useReference", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = "useReference()"; +// [End oh_jsvm_reference_ref_and_oh_jsvm_reference_unref] + +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 = "referenceref", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..00b60dcce9db302511492f32cedd7c9c3690a584 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/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": "libreferenceref.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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..19bc6dba180d233023fb9d9fe8c27ae3d5ced3aa --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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 'libreferenceref.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/referencerefability/ReferencerefAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/referencerefability/ReferencerefAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/referencerefability/ReferencerefAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/referencerefability/ReferencerefAbility.ets index 0b6a17a06825e77444f3ac891b40778b2da29b4a..5d3dd16ceeef8ca18d5a4cad066fc84990f272d3 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/referencerefability/ReferencerefAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/referencerefability/ReferencerefAbility.ets @@ -1,56 +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 ReferencerefAbility 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'); - } -}; +/* + * 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 ReferencerefAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ab9624e612fc693f3a1e0f9f3ae3ff341c99f44c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "referenceref", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "ReferencerefAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "ReferencerefAbility", + "srcEntry": "./ets/referencerefability/ReferencerefAbility.ets", + "description": "$string:ReferencerefAbility_desc", + "icon": "$media:layered_image", + "label": "$string:ReferencerefAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..de9920cf09653a3a17a58577c2610c932832e7e9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "ReferencerefAbility_desc", + "value": "description" + }, + { + "name": "ReferencerefAbility_label", + "value": "JsvmLifeCycle" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6cc3c556aaff9bcd248caf220e8ab47ffbadea7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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('testReferenceRef', 0, async (done: Function) => { + console.log('uitest: TestReferenceRef begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'ReferencerefAbility' + } + 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('ReferencerefAbility'); + + 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: TestReferenceRef end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..59eb234df77e795ae3994050a3e85697e24f1075 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/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": "referenceref_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/screenshots/JsvmLifeCycle_2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ad92f03cd682bb8e0f6ae555a5e0d3933009513d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/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.usageinstructionsone", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..16413e8d3183cd7bc0258cc04e1bf8e3318801ed --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UsageInstructionsOne" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/README.md new file mode 100644 index 0000000000000000000000000000000000000000..dffd83b7c76e5a788a5e545719a5931b547b414e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/README.md @@ -0,0 +1,160 @@ +# ArkTS JSVM-API使用指导 + +### 介绍 + +使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 + +- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 +- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口进行函数创建和调用](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-function-call.md) +- [使用JSVM-API接口进行虚拟机快照相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-create-snapshot.md) +- [使用JSVM-API接口进行JSON操作](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-JSON.md) +- [使用JSVM-API接口进行任务队列相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-execute_tasks.md) +- [使用JSVM-API接口进行WebAssembly模块相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-wasm.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击hello world,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +aboutjson/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createsnapshot/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +functioncall/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +pumpmessageloop/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 + webassembly/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/UsageInstructionsOne > .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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/.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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3eef1a4384628633d921b7851f4d61fd37f7cfa0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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": "aboutjson", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libaboutjson.so": "file:./src/main/cpp/types/libaboutjson" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e4c935ba66de48ceb9a96e74986e50f2adbfb56 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsOne) + +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(aboutjson SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(aboutjson PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..965823b684147f5e4dea2dc0230c7ab655d42e4b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/hello.cpp @@ -0,0 +1,185 @@ +/* + * 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 "ark_runtime/jsvm.h" +#include +#include + +#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) + +// [Start oh_jsvm_json_parse_and_json_stringify] +// 解析JSON数字 +static JSVM_Value JsonParseNumber(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 设置要解析的JSON数字 + std::string strNumber = "10.555"; + JSVM_Value jsonString; + JSVM_CALL(OH_JSVM_CreateStringUtf8(env, strNumber.c_str(), strNumber.size(), &jsonString)); + JSVM_Value jsonObject; + // 调用OH_JSVM_JsonParse函数解析JSON数字,并将结果存储在JSON对象中 + JSVM_CALL(OH_JSVM_JsonParse(env, jsonString, &jsonObject)); + double number; + JSVM_CALL(OH_JSVM_GetValueDouble(env, jsonObject, &number)); + OH_LOG_INFO(LOG_APP, "Test JSVM jsonParseNumber: %{public}f", number); + return nullptr; +} + +// 解析JSON字符串中的对象 +static JSVM_Value JsonParseObject(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 设置要解析的JSON对象字符串 + std::string strObject = "{\"first\": \"one\", \"second\": \"two\", \"third\": \"three\"}"; + JSVM_Value strJson; + JSVM_CALL(OH_JSVM_CreateStringUtf8(env, strObject.c_str(), strObject.size(), &strJson)); + JSVM_Value jsonObject; + // 调用OH_JSVM_JsonParse函数解析JSON对象字符串,并将结果存储在JSON对象中 + JSVM_CALL(OH_JSVM_JsonParse(env, strJson, &jsonObject)); + JSVM_Value jsonString; + // 调用OH_JSVM_JsonStringify函数将对象转换为字符串格式,并将结果存储在JSVM字符串对象中 + JSVM_CALL(OH_JSVM_JsonStringify(env, jsonObject, &jsonString)); + size_t totalLen = 0; + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, nullptr, 0, &totalLen)); + size_t needLen = totalLen + 1; + char* buff = new char[needLen]; + JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, buff, needLen, &totalLen)); + OH_LOG_INFO(LOG_APP, "Test JSVM jsonParseNumber: %{public}s", buff); + delete[] buff; + return nullptr; +} + +// JsonParse注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = JsonParseNumber}, + {.data = nullptr, .callback = JsonParseObject}, +}; + +static JSVM_CallbackStruct *method = param; + +JSVM_PropertyDescriptor descriptor[] = { + {"jsonParseNumber", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + {"jsonParseObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 待执行的js代码 +static const char *STR_TASK = R"JS(jsonParseNumber();jsonParseObject();)JS"; +// [End oh_jsvm_json_parse_and_json_stringify] + +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, STR_TASK, 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 = "aboutjson", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4186c9f0331a66e9b827a7826ee9888283c3fc33 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/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": "libaboutjson.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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/aboutjsonability/AboutjsonAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/aboutjsonability/AboutjsonAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/aboutjsonability/AboutjsonAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/aboutjsonability/AboutjsonAbility.ets index 62594c6b9421ae0b4a8b6f24f9c2a5aeafe5a4e1..ac9499d7d33261087c18eb0ec49b3ab6359bc8ac --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/aboutjsonability/AboutjsonAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/aboutjsonability/AboutjsonAbility.ets @@ -1,56 +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 AboutjsonAbility 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'); - } -}; +/* + * 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 AboutjsonAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ba46b0d01055709619100b87d58773fa2bd5e91 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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 'libaboutjson.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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6cb67f9f71483ff5943e031a22e51252b557b31c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "aboutjson", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "AboutjsonAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "AboutjsonAbility", + "srcEntry": "./ets/aboutjsonability/AboutjsonAbility.ets", + "description": "$string:AboutjsonAbility_desc", + "icon": "$media:layered_image", + "label": "$string:AboutjsonAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e2fa38f441547155e11fc4541ea6c9c4b10d33a6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "AboutjsonAbility_desc", + "value": "description" + }, + { + "name": "AboutjsonAbility_label", + "value": "UsageInstructionsOne" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e91a9e1ef884dd6f79d63d7506bde6fc47fadaa3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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('testAboutJSON', 0, async (done: Function) => { + console.log('uitest: TestAboutJSON begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'AboutjsonAbility' + } + 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('AboutjsonAbility'); + + 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: TestAboutJSON end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5b74fd35ad14fff07f470cab9e6a564615b31534 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "aboutjson_test", + "type": "feature", + "deviceTypes": [ + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..73c8c74ee0b13ce19a79296797d0be0c8d521504 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/build-profile.json5 @@ -0,0 +1,106 @@ +/* + * 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": "createsnapshot", + "srcPath": "./createsnapshot", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "functioncall", + "srcPath": "./functioncall", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "aboutjson", + "srcPath": "./aboutjson", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "pumpmessageloop", + "srcPath": "./pumpmessageloop", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "webassembly", + "srcPath": "./webassembly", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/.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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..23894ad544570fe9718dffd758b294301e11daec --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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": "createsnapshot", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatesnapshot.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d48847ce5945f278cdc95f7127d3ee0f45c6bf7a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsOne) + +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) + +add_library(createsnapshot SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createsnapshot PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca726795adff90efe7faa86fa3ccbb4919096dcb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/hello.cpp @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_create_snapshot_and_create_env_from_snapshot] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include +#include + +#define LOG_DEMAIN 0x0202 +#define LOG_TAG "TEST_TAG" + +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。 +// 如果不是,则调用GET_AND_THROW_LAST_ERROR处理错误并返回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) + +static const int MAX_BUFFER_SIZE = 128; +// CreateHelloString()函数需绑定到JSVM虚拟机, 用于OH_JSVM_CreateSnapshot虚拟机快照的正常创建 +static JSVM_Value CreateHelloString(JSVM_Env env, JSVM_CallbackInfo info) +{ + JSVM_Value outPut; + OH_JSVM_CreateStringUtf8(env, "Hello world!", JSVM_AUTO_LENGTH, &outPut); + return outPut; +} +// 提供外部引用的方式以便JavaScript环境可以调用绑定的函数 +static JSVM_CallbackStruct helloCb = {CreateHelloString, nullptr}; + +static intptr_t g_externals[] = { + (intptr_t)&helloCb, + 0, +}; + +static JSVM_Value RunVMScript(JSVM_Env env, std::string &src) +{ + // 打开handleScope作用域 + JSVM_HandleScope handleScope; + OH_JSVM_OpenHandleScope(env, &handleScope); + JSVM_Value jsStr = nullptr; + OH_JSVM_CreateStringUtf8(env, src.c_str(), src.size(), &jsStr); + // 编译JavaScript代码 + JSVM_Script script; + OH_JSVM_CompileScript(env, jsStr, nullptr, 0, true, nullptr, &script); + // 执行JavaScript代码 + JSVM_Value result = nullptr; + OH_JSVM_RunScript(env, script, &result); + // 关闭handleScope作用域 + OH_JSVM_CloseHandleScope(env, handleScope); + return result; +} +// OH_JSVM_CreateSnapshot的样例方法 +static void CreateVMSnapshot() +{ + // 创建JavaScript虚拟机实例,打开虚拟机作用域 + JSVM_VM vm; + JSVM_CreateVMOptions vmOptions; + memset(&vmOptions, 0, sizeof(vmOptions)); + // isForSnapshotting设置该虚拟机是否用于创建快照 + vmOptions.isForSnapshotting = true; + OH_JSVM_CreateVM(&vmOptions, &vm); + JSVM_VMScope vmScope; + OH_JSVM_OpenVMScope(vm, &vmScope); + // 创建JavaScript环境,打开环境作用域 + JSVM_Env env; + // 将native函数注册成JavaScript可调用的方法 + JSVM_PropertyDescriptor descriptor[] = { + {"createHelloString", nullptr, &helloCb, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + }; + OH_JSVM_CreateEnv(vm, 1, descriptor, &env); + JSVM_EnvScope envScope; + OH_JSVM_OpenEnvScope(env, &envScope); + // 使用OH_JSVM_CreateSnapshot创建虚拟机的启动快照 + const char *blobData = nullptr; + size_t blobSize = 0; + JSVM_Env envs[1] = {env}; + OH_JSVM_CreateSnapshot(vm, 1, envs, &blobData, &blobSize); + // 将snapshot保存到文件中 + // 保存快照数据,/data/storage/el2/base/files/test_blob.bin为沙箱路径 + // 以包名为com.example.jsvm为例,实际文件会保存到/data/app/el2/100/base/com.example.jsvm/files/test_blob.bin + std::ofstream file("/data/storage/el2/base/files/test_blob.bin", + std::ios::out | std::ios::binary | std::ios::trunc); + file.write(blobData, blobSize); + file.close(); + // 关闭并销毁环境和虚拟机 + OH_JSVM_CloseEnvScope(env, envScope); + OH_JSVM_DestroyEnv(env); + OH_JSVM_CloseVMScope(vm, vmScope); + OH_JSVM_DestroyVM(vm); +} + +static void RunVMSnapshot() +{ + // blobData的生命周期不能短于vm的生命周期 + // 从文件中读取snapshot + std::vector blobData; + std::ifstream file("/data/storage/el2/base/files/test_blob.bin", std::ios::in | std::ios::binary | std::ios::ate); + size_t blobSize = file.tellg(); + blobData.resize(blobSize); + file.seekg(0, std::ios::beg); + file.read(blobData.data(), blobSize); + file.close(); + OH_LOG_INFO(LOG_APP, "Test JSVM RunVMSnapshot read file blobSize = : %{public}ld", blobSize); + // 使用快照数据创建虚拟机实例 + JSVM_VM vm; + JSVM_CreateVMOptions vmOptions; + memset(&vmOptions, 0, sizeof(vmOptions)); + vmOptions.snapshotBlobData = blobData.data(); + vmOptions.snapshotBlobSize = blobSize; + OH_JSVM_CreateVM(&vmOptions, &vm); + JSVM_VMScope vmScope; + OH_JSVM_OpenVMScope(vm, &vmScope); + // 从快照中创建环境env + JSVM_Env env; + OH_JSVM_CreateEnvFromSnapshot(vm, 0, &env); + JSVM_EnvScope envScope; + OH_JSVM_OpenEnvScope(env, &envScope); + // 执行js脚本,快照记录的env中定义了createHelloString() + std::string src = "createHelloString()"; + JSVM_Value result = RunVMScript(env, src); + // 环境关闭前检查脚本运行结果 + char str[MAX_BUFFER_SIZE]; + OH_JSVM_GetValueStringUtf8(env, result, str, MAX_BUFFER_SIZE, nullptr); + if (strcmp(str, "Hello world!") != 0) { + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d", __FILE__, __LINE__); + } + // 关闭并销毁环境和虚拟机 + OH_JSVM_CloseEnvScope(env, envScope); + OH_JSVM_DestroyEnv(env); + OH_JSVM_CloseVMScope(vm, vmScope); + OH_JSVM_DestroyVM(vm); + return; +} + +static JSVM_Value AdjustExternalMemory(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 在创建虚拟机快照时,如果存在对外部的依赖,需要在OH_JSVM_Init时,将外部依赖注册到initOptions.externalReferences中 + // 创建虚拟机快照并将快照保存到文件中 + CreateVMSnapshot(); + // snapshot可以记录下特定的js执行环境,可以跨进程通过snapshot快速还原出js执行上下文环境 + RunVMSnapshot(); + JSVM_Value result = nullptr; + OH_JSVM_CreateInt32(env, 0, &result); + return result; +} + +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = AdjustExternalMemory}, +}; +static JSVM_CallbackStruct *method = param; +// AdjustExternalMemory方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"adjustExternalMemory", nullptr, method, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试JS +const char *SRC_CALL_NATIVE = R"JS(adjustExternalMemory();)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++; + initOptions.externalReferences = g_externals; + int argc = 0; + char **argv = nullptr; + initOptions.argc = &argc; + initOptions.argv = argv; + 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; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + OH_LOG_INFO(LOG_APP, "JSVM Init"); + 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 = "createsnapshot", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +// [End oh_jsvm_create_snapshot_and_create_env_from_snapshot] diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..dfb4b188c2ae8961b9e7d00be177aefa1f17649a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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": "libcreatesnapshot.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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e181902f311b2f7dc314db5885f7ac693189476 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/pages/Index.ets @@ -0,0 +1,45 @@ +/* + * 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 'libcreatesnapshot.so'; + +// [Start create_snapshot_call_native] +@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%') + } +} +// [End create_snapshot_call_native] diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..769e893b6b882f896b1ff7a7dc47f2ffa53c133a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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": "createsnapshot", + "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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b974782ef1cb4db4e7e515932f0def6cd89cf1d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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": "UsageInstructionsOne" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b108b49b4b3ef2e1759af90f7a963bd8cc0d5c3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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('testVirtualMachine', 0, async (done: Function) => { + console.log('uitest: TestVirtualMachine 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: TestVirtualMachine end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6350e0f5d33f3fee1ecba2213fe3a8bfeea726c9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/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": "createsnapshot_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/.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/JsvmUsageGuide/UsageInstructionsOne/functioncall/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsOne/functioncall/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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/JsvmUsageGuide/UsageInstructionsOne/functioncall/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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/JsvmUsageGuide/UsageInstructionsOne/functioncall/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d615c366197ba752d6b64ab0641242f50dab452d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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": "functioncall", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libfunctioncall.so": "file:./src/main/cpp/types/libfunctioncall" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a93514b1236fc59e6955dad5defc2435d8f02d42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsOne) + +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(functioncall SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(functioncall PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ecb51ba8931a82502b448463cbf7e9c17e938106 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/hello.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start jsvm_function_call] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" + +#define CHECK_RET(cond) \ + if ((cond)) { \ + 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; \ + } + +#define CHECK(cond) \ + if (!(cond)) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ + cond); \ + return -1; \ + } + +JSVM_Value NativeCreateFunctionTest(JSVM_Env env, JSVM_CallbackInfo info) +{ + void *data; + size_t argc = 1; + JSVM_Value argv[1] = {nullptr}; + JSVM_Value thisArg; + // 获取callback 参数信息 + JSVM_Status ret = OH_JSVM_GetCbInfo(env, info, &argc, &argv[0], &thisArg, &data); + if (ret != 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__, ret, info != nullptr ? info->errorMessage : ""); + return nullptr; + } + const int maxMessageLength = 256; + char message[256]; + OH_JSVM_GetValueStringLatin1(env, argv[0], message, maxMessageLength, nullptr); + if (data == nullptr) { + OH_LOG_ERROR(LOG_APP, "jsvm: %{public}s; callback data null", message); + } else { + OH_LOG_INFO(LOG_APP, "jsvm: %{public}s; %{public}s", message, (char *)data); + } + return nullptr; +} + +static int32_t TEST_FUNC() +{ + JSVM_InitOptions initOptions{}; + JSVM_VM vm; + JSVM_Env env = nullptr; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + static bool isVMInit = false; + if (!isVMInit) { + isVMInit = true; + // 单个进程只用初始化一次 + OH_JSVM_Init(&initOptions); + } + CHECK_RET(OH_JSVM_CreateVM(nullptr, &vm)); + CHECK_RET(OH_JSVM_CreateEnv(vm, 0, nullptr, &env)); + CHECK_RET(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + + // 创建并检查函数 + char hello[] = "Hello World!"; + JSVM_CallbackStruct cb = {NativeCreateFunctionTest, (void *)hello}; + JSVM_Value func; + CHECK_RET(OH_JSVM_CreateFunction(env, "", JSVM_AUTO_LENGTH, &cb, &func)); + bool isFunction = false; + CHECK_RET(OH_JSVM_IsFunction(env, func, &isFunction)); + CHECK(isFunction); + + // 将函数设置到全局对象中 + JSVM_Value global; + CHECK_RET(OH_JSVM_GetGlobal(env, &global)); + JSVM_Value key; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, "NativeFunc", JSVM_AUTO_LENGTH, &key)); + CHECK_RET(OH_JSVM_SetProperty(env, global, key, func)); + + // 通过call 接口调用函数 + JSVM_Value argv[1] = {nullptr}; + OH_JSVM_CreateStringUtf8(env, "jsvm api call function", JSVM_AUTO_LENGTH, &argv[0]); + CHECK_RET(OH_JSVM_CallFunction(env, global, func, 1, argv, &result)); + + // 通过script调用函数 + JSVM_Script script; + JSVM_Value jsSrc; + const char *srcCallNative = R"JS(NativeFunc('js source call function');)JS"; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, srcCallNative, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK_RET(OH_JSVM_CloseVMScope(vm, vmScope)); + CHECK_RET(OH_JSVM_DestroyEnv(env)); + CHECK_RET(OH_JSVM_DestroyVM(vm)); + return 0; +} +// [End jsvm_function_call] + +static napi_value RunTest(napi_env env, napi_callback_info info) +{ + TEST_FUNC(); + 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 = "functioncall", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..701827d530db7ecd032f023e1b68cfe29bc0058c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/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": "libfunctioncall.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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/functioncallability/FunctioncallAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/functioncallability/FunctioncallAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/functioncallability/FunctioncallAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/functioncallability/FunctioncallAbility.ets index 71439a2d3e1480c80382798753521e9b1899a699..308ebdac2150d848f334de5bad65ed57af18ea79 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/functioncallability/FunctioncallAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/functioncallability/FunctioncallAbility.ets @@ -1,56 +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 FunctioncallAbility 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'); - } -}; +/* + * 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 FunctioncallAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..13de3baa1d434ea842c033320f316901a6032847 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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 'libfunctioncall.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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..79be9255c54edaef0b5f5e164f54b4d0f60328e0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "functioncall", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "FunctioncallAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "FunctioncallAbility", + "srcEntry": "./ets/functioncallability/FunctioncallAbility.ets", + "description": "$string:FunctioncallAbility_desc", + "icon": "$media:layered_image", + "label": "$string:FunctioncallAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ed9da58e521d8e0936fd1942302f52aebd1f4502 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "FunctioncallAbility_desc", + "value": "description" + }, + { + "name": "FunctioncallAbility_label", + "value": "UsageInstructionsOne" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..43bdcbc5c778116e23eb12bd623f481476c3a0f4 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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('testFunctionCall', 0, async (done: Function) => { + console.log('uitest: TestFunctionCall begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'FunctioncallAbility' + } + 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('FunctioncallAbility'); + + 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: TestFunctionCall end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71d4c586d9a9338c4184cb5d969510f26b84cc1e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "functioncall_test", + "type": "feature", + "deviceTypes": [ + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/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/JsvmUsageGuide/UsageInstructionsOne/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..343302a3ad0e1e176fdf53a74eeb56b3174d0f24 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/ohosTest.md @@ -0,0 +1,12 @@ +# UsageInstructionsOne 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|---------------------------------|--------|---------------|------------------|------|------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 使用JSVM-API接口进行JSON操作 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用JSVM-API接口进行函数创建和调用 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用JSVM-API接口进行虚拟机快照相关开发 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用JSVM-API接口进行任务队列相关开发 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 使用JSVM-API接口进行WebAssembly模块相关开发 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/.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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..38bdcc9929e2c5bd7f51c4fc96a398ccebd0d6ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/build-profile.json5 @@ -0,0 +1,39 @@ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ca0dd64ef5cf5954330c5088bf0304069736d600 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "pumpmessageloop", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libpumpmessageloop.so": "file:./src/main/cpp/types/libpumpmessageloop" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a1aee019c4c4e174e42df75d8b46e9ea49eb82b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsOne) + +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) + +add_library(pumpmessageloop SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(pumpmessageloop PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c925e81524d52f4dc616cc73ef64f73595bbfe33 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/hello.cpp @@ -0,0 +1,197 @@ +/* + * 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" +// [Start oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] +#include +#include +// [StartExclude oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] +#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) +// [EndExclude oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] + +// 待执行的js代码 +static const char *STR_TASK = R"JS( + // wasm 字节码 (以add 模块为例) + // 以下 wasmBuffer 对应的 wasm 字节码文本格式如下所示,只包含了一个函数 add + // (module + // (func $add (param $lhs i32) (param $rhs i32) (result i32) + // local.get $lhs + // local.get $rhs + // i32.add + // ) + // (export "add" (func $add)) + // ) + var wasmBytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, + 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, + 0x07, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01, + 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b]); + + var p = WebAssembly.instantiate(wasmBytes, {}); + p.then((result) => { + consoleinfo("Called with instance " + result); + }); + p.finally(() => { + consoleinfo("Called Finally"); + }); +)JS"; + +// 保证js代码中的打印信息可以正常输出 +static JSVM_Value ConsoleInfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + size_t argc = 1; + JSVM_Value args[1]; + #define MAX_LOG_LENGTH 255 + char log[MAX_LOG_LENGTH + 1] = ""; + size_t logLength; + JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); + + OH_JSVM_GetValueStringUtf8(env, args[0], log, MAX_LOG_LENGTH, &logLength); + log[MAX_LOG_LENGTH] = 0; + OH_LOG_INFO(LOG_APP, "JSVM API TEST: %{public}s", log); + return nullptr; +} + +// 注册consoleinfo的方法 +JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = ConsoleInfo}, +}; +JSVM_PropertyDescriptor descriptor[] = { + {"consoleinfo", NULL, ¶m[0], NULL, NULL, NULL, JSVM_DEFAULT}, +}; + +static int32_t TestJSVM() +{ + JSVM_InitOptions init_options; + memset(&init_options, 0, sizeof(init_options)); + if (g_aa == 0) { + OH_JSVM_Init(&init_options); + g_aa++; + } + // 创建JavaScript虚拟机实例,打开虚拟机作用域 + JSVM_VM vm; + JSVM_CreateVMOptions options; + memset(&options, 0, sizeof(options)); + CHECK(OH_JSVM_CreateVM(&options, &vm)); + JSVM_VMScope vm_scope; + CHECK(OH_JSVM_OpenVMScope(vm, &vm_scope)); + + JSVM_Env env; + CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); + JSVM_EnvScope envScope; + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + JSVM_HandleScope handlescope; + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handlescope)); + JSVM_Value sourcecodevalue; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, STR_TASK, strlen(STR_TASK), &sourcecodevalue)); + JSVM_Script script; + CHECK_RET(OH_JSVM_CompileScript(env, sourcecodevalue, nullptr, 0, true, nullptr, &script)); + JSVM_Value result; + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + bool rst = false; + auto start = std::chrono::system_clock::now(); + while (true) { + // 如果任务队列中没有任务启动,则rst设置为false + CHECK_RET(OH_JSVM_PumpMessageLoop(vm, &rst)); + CHECK_RET(OH_JSVM_PerformMicrotaskCheckpoint(vm)); + // 定时退出 + auto now = std::chrono::system_clock::now(); + auto cost = std::chrono::duration_cast(now - start).count(); + const int timeoutMs = 100; + if (cost > timeoutMs) { + break; + } + } + + // 关闭并销毁环境和虚拟机 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handlescope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK(OH_JSVM_DestroyEnv(env)); + CHECK(OH_JSVM_CloseVMScope(vm, vm_scope)); + CHECK(OH_JSVM_DestroyVM(vm)); + return 0; +} +// [End oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] + +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 = "pumpmessageloop", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..24f6bafaba63baf43e0ec70a23b59a083ba34a01 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/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": "libpumpmessageloop.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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ac85077e7324220719957ba8187b5e204663774 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/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 'libpumpmessageloop.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_PumpMessageLoop'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pumpmessageloopability/PumpmessageloopAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pumpmessageloopability/PumpmessageloopAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pumpmessageloopability/PumpmessageloopAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pumpmessageloopability/PumpmessageloopAbility.ets index 1c50f39a728cbf50d78626f8cdfcb717c27675a1..ce70b476cba95bff5b33c4f821ef7d81e737bea7 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pumpmessageloopability/PumpmessageloopAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pumpmessageloopability/PumpmessageloopAbility.ets @@ -1,41 +1,41 @@ -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -export default class PumpmessageloopAbility 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'); - } -}; +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class PumpmessageloopAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..36fe86318c9193f8ee15a762c777e84bdf381032 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/module.json5 @@ -0,0 +1,27 @@ +{ + "module": { + "name": "pumpmessageloop", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "PumpmessageloopAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "PumpmessageloopAbility", + "srcEntry": "./ets/pumpmessageloopability/PumpmessageloopAbility.ets", + "description": "$string:PumpmessageloopAbility_desc", + "icon": "$media:layered_image", + "label": "$string:PumpmessageloopAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..16319397009db7e037bd2e563476472d2b510007 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "pumpmessageloop_test", + "type": "feature", + "deviceTypes": [ + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/screenshots/UsageInstructionsOne_2.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/.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/JsvmUsageGuide/UsageInstructionsOne/webassembly/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsOne/webassembly/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/hvigorfile.ts similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/oh-package.json5 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/oh-package.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/oh-package.json5 diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/CMakeLists.txt similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/CMakeLists.txt rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/CMakeLists.txt diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/hello.cpp similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/hello.cpp rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/hello.cpp diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/oh-package.json5 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/oh-package.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/cpp/types/libwebassembly/oh-package.json5 diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/pages/Index.ets similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/pages/Index.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/pages/Index.ets diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/webassemblyability/WebassemblyAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/webassemblyability/WebassemblyAbility.ets similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/webassemblyability/WebassemblyAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/ets/webassemblyability/WebassemblyAbility.ets diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/module.json5 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/module.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/module.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/float.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/string.json similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/background.png similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/foreground.png similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/startIcon.png similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/Ability.test.ets similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/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/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/module.json5 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/module.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/webassembly/src/ohosTest/module.json5 diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/.gitignore rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/.gitignore diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/app.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c845cc69ba13e1f0fc598d9f907d9380589f0d93 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/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.usageinstructionstwo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0ecae715a5d4c8d8ae829ee037727e3593d409b7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "UsageInstructionsTwo" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/README.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..690d9c4d6f0d01066755ecc8e623cc38a0559db5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/README.md @@ -0,0 +1,179 @@ +# ArkTS JSVM-API使用指导 + +### 介绍 + +使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 + +- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 +- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口获取JSVM API的版本号](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-version.md) +- [使用JSVM-API接口进行JavaScript代码调试调优](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-heapstatistics-debugger-cpuprofiler-heapsnapshot.md) +- [使用JSVM-API判断给定的两个JS value是否严格相等](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-strict-equals.md) +- [使用JSVM-API进行内存管理](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-memory-management.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击Hello World,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +adjustexternalmemory/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getheapstatistics/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getversion/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +getvm/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +memorypressurenotification/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +strictequals/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/UsageInstructionsTwo > .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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/.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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..60036cd797a6dbfd8219ccaf6da0c9afe0420dbc --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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": "adjustexternalmemory", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libadjustexternalmemory.so": "file:./src/main/cpp/types/libadjustexternalmemory" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fcb47014e0914c1d06007d56ba85d57b3b70415a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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) + +add_library(adjustexternalmemory SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(adjustexternalmemory PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34f3d637c6f317624be9d88b1b02a9d52b0930b2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/hello.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_adjust_external_memory] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_adjust_external_memory] +#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) +// [EndExclude oh_jsvm_adjust_external_memory] + +// OH_JSVM_AdjustExternalMemory的样例方法 +static JSVM_Value AdjustExternalMemory(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 分配1MB的内存 + int64_t change = 1024 * 1024; + int64_t adjustedValue = 0; + JSVM_Status status = OH_JSVM_AdjustExternalMemory(env, change, &adjustedValue); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_AdjustExternalMemory: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_AdjustExternalMemory: success"); + OH_LOG_INFO(LOG_APP, "JSVM Allocate memory size: %{public}d", adjustedValue); + } + JSVM_Value checked; + OH_JSVM_GetBoolean(env, true, &checked); + return checked; +} +// AdjustExternalMemory注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = AdjustExternalMemory}, +}; +static JSVM_CallbackStruct *method = param; +// AdjustExternalMemory方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"adjustExternalMemory", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = R"JS(adjustExternalMemory())JS"; +// [End oh_jsvm_adjust_external_memory] + +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 = "adjustexternalmemory", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1255828d1de9006032aa960058761eee2c8b0d83 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/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": "libadjustexternalmemory.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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets index d61ee4ac3258b648caf11a77b3773633d7753e87..56cc3a6fa60a64e4f53ac6800aed297333326290 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets @@ -1,56 +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 AdjustexternalmemoryAbility 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'); - } -}; +/* + * 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 AdjustexternalmemoryAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3eeda3302aba655e52057895426f5a794bff3f09 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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 'libadjustexternalmemory.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..15384a3f96285aa8f90e819cc4b794cc708202ba --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "adjustexternalmemory", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "AdjustexternalmemoryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "AdjustexternalmemoryAbility", + "srcEntry": "./ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets", + "description": "$string:AdjustexternalmemoryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:AdjustexternalmemoryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..625d290483d42a3ae063b70245278fa2be31605e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "AdjustexternalmemoryAbility_desc", + "value": "description" + }, + { + "name": "AdjustexternalmemoryAbility_label", + "value": "UsageInstructionsTwo" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6ba6ddb80a862b2d170af90e09cf0a829163c27 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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('testAdjustExternalMemory', 0, async (done: Function) => { + console.log('uitest: TestAdjustExternalMemory begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'AdjustexternalmemoryAbility' + } + 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('AdjustexternalmemoryAbility'); + + 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: TestAdjustExternalMemory end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7627e73168882bff0199e48e4616eb1e6e9cdcac --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/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": "adjustexternalmemory_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8d2d2e894f9c60beb3574e9993962d3d847d4f23 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/build-profile.json5 @@ -0,0 +1,118 @@ +/* + * 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": "getvm", + "srcPath": "./getvm", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getheapstatistics", + "srcPath": "./getheapstatistics", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "getversion", + "srcPath": "./getversion", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "adjustexternalmemory", + "srcPath": "./adjustexternalmemory", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "memorypressurenotification", + "srcPath": "./memorypressurenotification", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "strictequals", + "srcPath": "./strictequals", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/code-linter.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/code-linter.json5 rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/code-linter.json5 diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/.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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7b0d2fc8829dee61da4f034b491eca5a99268eb --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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": "getheapstatistics", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetheapstatistics.so": "file:./src/main/cpp/types/libgetheapstatistics" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9a635c19549916df26dfbba22fbda471a9f36f20 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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) + +add_library(getheapstatistics SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getheapstatistics PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..350ab85ce4cef2557145951fac4874404fb47900 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/hello.cpp @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_heap_statistics] +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" +// [StartExclude oh_jsvm_get_heap_statistics] +#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) +// [EndExclude oh_jsvm_get_heap_statistics] + +// OH_JSVM_GetHeapStatistics的样例方法 +void PrintHeapStatistics(JSVM_HeapStatistics result) +{ + OH_LOG_INFO(LOG_APP, "JSVM API heap totalHeapSize: %{public}zu", result.totalHeapSize); + OH_LOG_INFO(LOG_APP, "JSVM API heap totalHeapSizeExecutable: %{public}zu", result.totalHeapSizeExecutable); + OH_LOG_INFO(LOG_APP, "JSVM API heap totalPhysicalSize: %{public}zu", result.totalPhysicalSize); + OH_LOG_INFO(LOG_APP, "JSVM API heap totalAvailableSize: %{public}zu", result.totalAvailableSize); + OH_LOG_INFO(LOG_APP, "JSVM API heap usedHeapSize: %{public}zu", result.usedHeapSize); + OH_LOG_INFO(LOG_APP, "JSVM API heap heapSizeLimit: %{public}zu", result.heapSizeLimit); + OH_LOG_INFO(LOG_APP, "JSVM API heap mallocedMemory: %{public}zu", result.mallocedMemory); + OH_LOG_INFO(LOG_APP, "JSVM API heap externalMemory: %{public}zu", result.externalMemory); + OH_LOG_INFO(LOG_APP, "JSVM API heap peakMallocedMemory: %{public}zu", result.peakMallocedMemory); + OH_LOG_INFO(LOG_APP, "JSVM API heap numberOfNativeContexts: %{public}zu", result.numberOfNativeContexts); + OH_LOG_INFO(LOG_APP, "JSVM API heap numberOfDetachedContexts: %{public}zu", result.numberOfDetachedContexts); + OH_LOG_INFO(LOG_APP, "JSVM API heap totalGlobalHandlesSize: %{public}zu", result.totalGlobalHandlesSize); + OH_LOG_INFO(LOG_APP, "JSVM API heap usedGlobalHandlesSize: %{public}zu", result.usedGlobalHandlesSize); +} + +static JSVM_Value GetHeapStatistics(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取当前虚拟机对象 + JSVM_VM testVm; + OH_JSVM_GetVM(env, &testVm); + // 获取虚拟机的堆统计信息 + JSVM_HeapStatistics result; + OH_JSVM_GetHeapStatistics(testVm, &result); + // 打印虚拟机堆统计信息 + PrintHeapStatistics(result); + // 返回虚拟机堆统计信息中‘本机上下文数量’ + JSVM_Value nativeContextsCnt = nullptr; + OH_JSVM_CreateInt64(env, result.numberOfNativeContexts, &nativeContextsCnt); + return nativeContextsCnt; +} +// GetHeapStatistics注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetHeapStatistics}, +}; +static JSVM_CallbackStruct *method = param; +// GetHeapStatistics方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getHeapStatistics", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = R"JS(getHeapStatistics())JS"; +// [End oh_jsvm_get_heap_statistics] + +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 = "getheapstatistics", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6740937c4baf8840a3e857a6b3cfa3ff4fea22be --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/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": "libgetheapstatistics.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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/getheapstatisticsability/GetheapstatisticsAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/getheapstatisticsability/GetheapstatisticsAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/getheapstatisticsability/GetheapstatisticsAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/getheapstatisticsability/GetheapstatisticsAbility.ets index 498f8ee4406541123705fb90708ffb22246c9fac..eb8b50a8fb48cf93c2a0300b8652f9961080ad94 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/getheapstatisticsability/GetheapstatisticsAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/getheapstatisticsability/GetheapstatisticsAbility.ets @@ -1,56 +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 GetheapstatisticsAbility 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'); - } -}; +/* + * 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 GetheapstatisticsAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..318154626578e0c7ad4374b5e0b794584783ff37 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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 'libgetheapstatistics.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..81c388c0a419b0d0aaf081c53d3c2ce42417b6d2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getheapstatistics", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetheapstatisticsAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetheapstatisticsAbility", + "srcEntry": "./ets/getheapstatisticsability/GetheapstatisticsAbility.ets", + "description": "$string:GetheapstatisticsAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetheapstatisticsAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cff501cf69d624a84541b975aa7a32c3a33fa3e7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetheapstatisticsAbility_desc", + "value": "description" + }, + { + "name": "GetheapstatisticsAbility_label", + "value": "UsageInstructionsTwo" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..043966859f2eb5425e2e8174054d0278a3da6823 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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('testGetHeapStatistics', 0, async (done: Function) => { + console.log('uitest: TestGetHeapStatistics begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetheapstatisticsAbility' + } + 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('GetheapstatisticsAbility'); + + 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: TestGetHeapStatistics end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f9931db74f22d137797a88c98a0220f594a7f7b6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/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": "getheapstatistics_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/.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/JsvmUsageGuide/UsageInstructionsTwo/getversion/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsTwo/getversion/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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/JsvmUsageGuide/UsageInstructionsTwo/getversion/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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/JsvmUsageGuide/UsageInstructionsTwo/getversion/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d21aec907603f283c1d58309cbe4efc78f7ab81f --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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": "getversion", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetversion.so": "file:./src/main/cpp/types/libgetversion" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb90367e4b40964e31010d48f25c30f6db2ea2e2 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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) + +add_library(getversion SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getversion PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f2b4431dfa4822ddbfb256154f61a032b196df9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/hello.cpp @@ -0,0 +1,175 @@ +/* + * 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) + +// [Start oh_jsvm_get_version_and_vm_info] +// OH_JSVM_GetVersion的样例方法 +static JSVM_Value GetVersion(JSVM_Env env, JSVM_CallbackInfo info) +{ + uint32_t jsVersion = 0; + // 调用接口,获取当前JSVM运行时支持的最高JSVM API版本 + JSVM_CALL(OH_JSVM_GetVersion(env, &jsVersion)); + int value = static_cast(jsVersion); + OH_LOG_INFO(LOG_APP, "JSVM GetVersion success:%{public}d", value); + return nullptr; +} + +// OH_JSVM_GetVMInfo的样例方法 +// 打印JSVM(JavaScript虚拟机)的各项信息 +void PrintVmInfo(JSVM_VMInfo vmInfo) +{ + OH_LOG_INFO(LOG_APP, "JSVM API apiVersion: %{public}d", vmInfo.apiVersion); + OH_LOG_INFO(LOG_APP, "JSVM API engine: %{public}s", vmInfo.engine); + OH_LOG_INFO(LOG_APP, "JSVM API version: %{public}s", vmInfo.version); + OH_LOG_INFO(LOG_APP, "JSVM API cachedDataVersionTag: 0x%{public}x", vmInfo.cachedDataVersionTag); +} + +static JSVM_Value GetVMInfo(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 调用接口,获取虚拟机的信息 + JSVM_VMInfo result; + JSVM_CALL(OH_JSVM_GetVMInfo(&result)); + // 输出VM虚拟机信息 + PrintVmInfo(result); + return nullptr; +} + +// IsStrictEquals注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetVersion}, + {.data = nullptr, .callback = GetVMInfo}, +}; +static JSVM_CallbackStruct *method = param; +// IsStrictEquals方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getVersion", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, + {"getVMInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +static const char *STR_TASK = R"JS(getVersion();getVMInfo();)JS"; +// [End oh_jsvm_get_version_and_vm_info] + +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, STR_TASK, 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 = "getversion", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..045101c18b71f603031eb57c1f80b35a46a93cff --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/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": "libgetversion.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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/getversionability/GetversionAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/getversionability/GetversionAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/getversionability/GetversionAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/getversionability/GetversionAbility.ets index 6f019158d7713c6ce9e283d7bd1534168225a9cb..10f2c73bb6ab64acbb48a50aecbcf66791d5ae88 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/getversionability/GetversionAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/getversionability/GetversionAbility.ets @@ -1,56 +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 GetversionAbility 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'); - } -}; +/* + * 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 GetversionAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a403e9baf230f7482b1b787b415683cc1cedf588 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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 'libgetversion.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..72d31930686b2e7d3d75e69e8fed5e546364d9d0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "getversion", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "GetversionAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "GetversionAbility", + "srcEntry": "./ets/getversionability/GetversionAbility.ets", + "description": "$string:GetversionAbility_desc", + "icon": "$media:layered_image", + "label": "$string:GetversionAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..274263abc0e240b7dda247ba870160084df6e158 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "GetversionAbility_desc", + "value": "description" + }, + { + "name": "GetversionAbility_label", + "value": "UsageInstructionsTwo" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..89734ba4ead9254a8a753b160430e7c91236776d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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('testGetVersion', 0, async (done: Function) => { + console.log('uitest: TestGetVersion begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'GetversionAbility' + } + 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('GetversionAbility'); + + 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: TestGetVersion end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..84f25198a213b8a451a2fd55853614e60324008e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/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": "getversion_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/.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/JsvmUsageGuide/UsageInstructionsTwo/getvm/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsTwo/getvm/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..265dbe9f725f573310ebe5326f21638519e58dc0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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": "getvm", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libgetvm.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4f4d6b6d9ee679374e63263eb4d6d703a590f7ed --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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) + +add_library(getvm SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(getvm PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..acb683d7dc640035942328e13b7324d49a3ddb81 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/hello.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_get_vm] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_get_vm] +#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) +// [EndExclude oh_jsvm_get_vm] + +// OH_JSVM_GetVM的样例方法 +static JSVM_Value GetVM(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 获取当前虚拟机对象,后续可以进行与虚拟机相关的操作或分析 + JSVM_VM testVm; + JSVM_Status status = OH_JSVM_GetVM(env, &testVm); + JSVM_Value result = nullptr; + if (status != JSVM_OK || testVm == nullptr) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetVM: failed"); + OH_JSVM_GetBoolean(env, true, &result); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetVM: success"); + OH_JSVM_GetBoolean(env, false, &result); + } + return result; +} +// GetVM注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = GetVM}, +}; +static JSVM_CallbackStruct *method = param; +// GetVM方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"getVM", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = R"JS(getVM())JS"; +// [End oh_jsvm_get_vm] + +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 = "getvm", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..05c7308f965753c803bea9d02488406271dcdd3d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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": "libgetvm.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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3cf4799224e2cb0b4f5313ccdb932205f1c63118 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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 'libgetvm.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..73807e1bab2aba895a063882561612698c43c575 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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": "getvm", + "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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..da67aa185b21542466bae158fb292d7eb63b11ca --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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": "UsageInstructionsTwo" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e98c7d638662d8577061657128cd7835b124e6a6 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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('testGetVM', 0, async (done: Function) => { + console.log('uitest: TestGetVM 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: TestGetVM end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d01da0917d98c994993163fd3c8f02595127a2d9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/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": "getvm_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/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/NodeAPI/NodeApiUse/NodeAPIError/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/hvigorfile.ts rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/.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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..216aeb4f7b87134586aec0399ed08475bfbda5c0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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": "memorypressurenotification", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libmemorypressurenotification.so": "file:./src/main/cpp/types/libmemorypressurenotification" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2afdde30dc40630da0f5b7e43d51fd96a8cbe672 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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) + +add_library(memorypressurenotification SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(memorypressurenotification PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45d1e997e58ac1d82aa62eceb0695e3028c5e4f9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/hello.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_memory_pressure_notification] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_memory_pressure_notification] +#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) +// [EndExclude oh_jsvm_memory_pressure_notification] + +// OH_JSVM_MemoryPressureNotification的样例方法 +static JSVM_Value MemoryPressureNotification(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 设置当前JSVM的内存压力级别 + JSVM_Status status = OH_JSVM_MemoryPressureNotification(env, JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_MemoryPressureNotification: failed"); + } else { + OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_MemoryPressureNotification: success"); + OH_LOG_INFO(LOG_APP, "JSVM Current JSVM memory pressure level: %{public}d", + JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL); + } + return nullptr; +} +// MemoryPressureNotification注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = MemoryPressureNotification}, +}; +static JSVM_CallbackStruct *method = param; +// MemoryPressureNotification方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"memoryPressureNotification", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +const char *SRC_CALL_NATIVE = R"JS(memoryPressureNotification())JS"; +// [End oh_jsvm_memory_pressure_notification] + +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 = "memorypressurenotification", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..29adc05a8d7df821b50396c9d3b4833ed16c3531 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/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": "libmemorypressurenotification.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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets index 330268c766ec0b6b5c00c76e48d0f475802f76ea..1f29e75384d40bff8172d334ff86d2e8a45e203d --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets @@ -1,56 +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 MemorypressurenotificationAbility 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'); - } -}; +/* + * 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 MemorypressurenotificationAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c672c52f29267a06f48889cf8c1dc68e11cb081c --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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 'libmemorypressurenotification.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9537498798aa4e10317830287735f3780d7531ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "memorypressurenotification", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "MemorypressurenotificationAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "MemorypressurenotificationAbility", + "srcEntry": "./ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets", + "description": "$string:MemorypressurenotificationAbility_desc", + "icon": "$media:layered_image", + "label": "$string:MemorypressurenotificationAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..49248b372c03bc598f1ec1228c8f381c6790268d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "MemorypressurenotificationAbility_desc", + "value": "description" + }, + { + "name": "MemorypressurenotificationAbility_label", + "value": "UsageInstructionsTwo" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..dd181e4cf106f37a74d371d2e41bf961e2f4577d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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('testMemoryPressureNotification', 0, async (done: Function) => { + console.log('uitest: TestMemoryPressureNotification begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'MemorypressurenotificationAbility' + } + 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('MemorypressurenotificationAbility'); + + 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: TestMemoryPressureNotification end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3177bcc11ab23f125fd62da1c70bb8050948f097 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/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": "memorypressurenotification_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/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/JsvmUsageGuide/UsageInstructionsTwo/ohosTest.md b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..0634982710fcbe38d8ce5fb8a42a55717f86beb7 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/ohosTest.md @@ -0,0 +1,13 @@ +# UsageInstructionsTwo 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 使用JSVM-API接口获取JSVM API的版本号 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 设置JavaScript对象保持活动状态的外部分配内存的数量 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 通知虚拟机系统内存不足并有选择地触发垃圾回收 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 判断给定的两个JS value是否严格相等 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 检索给定环境的虚拟机实例 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | +| 返回一组虚拟机堆的统计数据 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_1.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_1.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_1.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_2.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_2.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/screenshots/UsageInstructionsTwo_2.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/.gitignore b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/.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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/build-profile.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..01bed8940ff6f2d5843f8d1d7e184725f59be699 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/hvigorfile.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/obfuscation-rules.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e1a669d623dab33720acec9678158116a39630e0 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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": "strictequals", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libstrictequals.so": "file:./src/main/cpp/types/libstrictequals" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9c4f5b36c35d4be09b078771bd0f8306af392954 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +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) + +add_library(strictequals SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(strictequals PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/hello.cpp b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/hello.cpp new file mode 100644 index 0000000000000000000000000000000000000000..422c3d54e807e7a6f3c2bfe0f964d610ceeeeb65 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/hello.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start oh_jsvm_strict_equals] +#include "napi/native_api.h" +#include "ark_runtime/jsvm.h" +#include "hilog/log.h" +// [StartExclude oh_jsvm_strict_equals] +#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) +// [EndExclude oh_jsvm_strict_equals] + +// OH_JSVM_StrictEquals的样例方法 +static JSVM_Value IsStrictEquals(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 接受两个入参 + size_t argc = 2; + JSVM_Value args[2] = {nullptr}; + 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; + 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(data = '123';value = '123';isStrictEquals(data,value);)JS"; +// [End oh_jsvm_strict_equals] + +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 = "strictequals", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/Index.d.ts b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..87c2a3033bf359f3f7b2e40f1280487aadaf4576 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/oh-package.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..58028a5e325aff200103cf3c248971a1870345b9 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/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": "libstrictequals.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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..caf23cac32db70cfe9fe5948a481d6241010562d --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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 'libstrictequals.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/strictequalsability/StrictequalsAbility.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/strictequalsability/StrictequalsAbility.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/strictequalsability/StrictequalsAbility.ets rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/strictequalsability/StrictequalsAbility.ets index 20282d42a9768d485d514b071ed631d0be9bf609..01c4665b17ffd0af07289fd89b8d924a9aae273d --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/strictequalsability/StrictequalsAbility.ets +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/strictequalsability/StrictequalsAbility.ets @@ -1,56 +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 StrictequalsAbility 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'); - } -}; +/* + * 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 StrictequalsAbility 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/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e01d7becac53bbf6f2fbd7c2c3ecbdab087bcc3e --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/module.json5 @@ -0,0 +1,42 @@ +/* + * 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": "strictequals", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "StrictequalsAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "StrictequalsAbility", + "srcEntry": "./ets/strictequalsability/StrictequalsAbility.ets", + "description": "$string:StrictequalsAbility_desc", + "icon": "$media:layered_image", + "label": "$string:StrictequalsAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..74779e5a2e8037d618e9c55005263eac4f8d73da --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "StrictequalsAbility_desc", + "value": "description" + }, + { + "name": "StrictequalsAbility_label", + "value": "UsageInstructionsTwo" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7ffdae3020d40c3ae82e259cfdc0eb338e731ad1 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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', () => { + /** + * 打开应用,点击OH_JSVM_StrictEquals执行 + */ + it('testStrictEquals', 0, async (done: Function) => { + console.log('uitest: TestStrictEquals begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'StrictequalsAbility' + } + 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('StrictequalsAbility'); + + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('OH_JSVM_StrictEquals')); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('success')); + console.log('uitest: TestStrictEquals end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..409f7a46b0cd8ce6325b4420f055b5a5c76b408b --- /dev/null +++ b/code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/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": "strictequals_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fc6fef3c84d2bf3e48c68a72392d172146123754 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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.nodeapiasynchronoustask", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7174a1f89ecc67be923be0d01a0a5887e86a0863 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIAsynchronousTask" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a4fbd95a3025f437381db5aa394e8eb34ac822b4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/README.md @@ -0,0 +1,74 @@ +# ArkTS使用Node-API接口进行异步任务开发 + +### 介绍 + +本工程展示了使用Node-API接口进行异步任务开发中的Promise方式和callback方式,详细描述可查如下链接。 + +- [使用Node-API接口进行异步任务开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-asynchronous-task.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现如上图效果,和两个按钮,依次点击按钮后可以调用Promise方式和callback方式的方法,并将结果呈现到text文本中,并在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIAsynchronousTask.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── libentry + │ │ └── libentry1 + │ │ ├── callback.cpp // callback方式实现 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp // Promise方式实现 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 异步任务 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIAsynchronousTask.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeAPIAsynchronousTask > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a26930aada5667e32aa820a560ebf36b42056cc6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/oh-package.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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry", + "libentry1.so": "file:./src/main/cpp/types/libentry1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cffbe7f5288faae9c19ff3c29f7fa07188d9d13f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,18 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIAsynchronousTask) + +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) + +add_library(entry1 SHARED callback.cpp) +target_link_libraries(entry1 PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp index a8f6b91fab1083322638a4df17c076a6451905e6..a749dbe7feebff350191c01e2123ac9066107686 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/callback.cpp @@ -1,105 +1,105 @@ -/* - * 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" - -// [Start napi_create_queue_async_work] -static constexpr int INT_ARGS_2 = 2; // 入参索引 - -struct CallbackData { - napi_async_work asyncWork = nullptr; - napi_ref callbackRef = nullptr; - double args[2] = {0}; - double result = 0; -}; - -// [StartExclude napi_create_queue_async_work] -// [Start napi_async_first_call_back_work] -static void ExecuteCB(napi_env env, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - callbackData->result = callbackData->args[0] + callbackData->args[1]; -} -// [End napi_async_first_call_back_work] - -// [Start napi_async_second_call_back_work] -static void CompleteCB(napi_env env, napi_status status, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - napi_value callbackArg[1] = {nullptr}; - napi_create_double(env, callbackData->result, &callbackArg[0]); - napi_value callback = nullptr; - napi_get_reference_value(env, callbackData->callbackRef, &callback); - // 执行回调函数 - napi_value result; - napi_value undefined; - napi_get_undefined(env, &undefined); - napi_call_function(env, undefined, callback, 1, callbackArg, &result); - // 删除napi_ref对象以及异步任务 - napi_delete_reference(env, callbackData->callbackRef); - napi_delete_async_work(env, callbackData->asyncWork); - delete callbackData; -} -// [End napi_async_second_call_back_work] -// [EndExclude napi_create_queue_async_work] - -napi_value AsyncWork(napi_env env, napi_callback_info info) -{ - size_t argc = 3; - napi_value args[3]; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - auto asyncContext = new CallbackData(); - // 将接收到的参数保存到callbackData - napi_get_value_double(env, args[0], &asyncContext->args[0]); - napi_get_value_double(env, args[1], &asyncContext->args[1]); - // 将传入的callback转换为napi_ref延长其生命周期,防止被GC掉 - napi_create_reference(env, args[INT_ARGS_2], 1, &asyncContext->callbackRef); - napi_value resourceName = nullptr; - napi_create_string_utf8(env, "asyncWorkCallback", NAPI_AUTO_LENGTH, &resourceName); - // 创建异步任务 - napi_create_async_work(env, nullptr, resourceName, ExecuteCB, CompleteCB, - asyncContext, &asyncContext->asyncWork); - // 将异步任务加入队列 - napi_queue_async_work(env, asyncContext->asyncWork); - return nullptr; -} -// [End napi_create_queue_async_work] - -// [Start napi_value_init] -// 模块初始化 -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "asyncWork", nullptr, AsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr } - }; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} -// [End napi_value_init] - -static napi_module demoModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "entry1", - .nm_priv = ((void*)0), - .reserved = { 0 }, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) -{ - napi_module_register(&demoModule); +/* + * 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" + +// [Start napi_create_queue_async_work] +static constexpr int INT_ARGS_2 = 2; // 入参索引 + +struct CallbackData { + napi_async_work asyncWork = nullptr; + napi_ref callbackRef = nullptr; + double args[2] = {0}; + double result = 0; +}; + +// [StartExclude napi_create_queue_async_work] +// [Start napi_async_first_call_back_work] +static void ExecuteCB(napi_env env, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + callbackData->result = callbackData->args[0] + callbackData->args[1]; +} +// [End napi_async_first_call_back_work] + +// [Start napi_async_second_call_back_work] +static void CompleteCB(napi_env env, napi_status status, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + napi_value callbackArg[1] = {nullptr}; + napi_create_double(env, callbackData->result, &callbackArg[0]); + napi_value callback = nullptr; + napi_get_reference_value(env, callbackData->callbackRef, &callback); + // 执行回调函数 + napi_value result; + napi_value undefined; + napi_get_undefined(env, &undefined); + napi_call_function(env, undefined, callback, 1, callbackArg, &result); + // 删除napi_ref对象以及异步任务 + napi_delete_reference(env, callbackData->callbackRef); + napi_delete_async_work(env, callbackData->asyncWork); + delete callbackData; +} +// [End napi_async_second_call_back_work] +// [EndExclude napi_create_queue_async_work] + +napi_value AsyncWork(napi_env env, napi_callback_info info) +{ + size_t argc = 3; + napi_value args[3]; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + auto asyncContext = new CallbackData(); + // 将接收到的参数保存到callbackData + napi_get_value_double(env, args[0], &asyncContext->args[0]); + napi_get_value_double(env, args[1], &asyncContext->args[1]); + // 将传入的callback转换为napi_ref延长其生命周期,防止被GC掉 + napi_create_reference(env, args[INT_ARGS_2], 1, &asyncContext->callbackRef); + napi_value resourceName = nullptr; + napi_create_string_utf8(env, "asyncWorkCallback", NAPI_AUTO_LENGTH, &resourceName); + // 创建异步任务 + napi_create_async_work(env, nullptr, resourceName, ExecuteCB, CompleteCB, + asyncContext, &asyncContext->asyncWork); + // 将异步任务加入队列 + napi_queue_async_work(env, asyncContext->asyncWork); + return nullptr; +} +// [End napi_create_queue_async_work] + +// [Start napi_value_init] +// 模块初始化 +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "asyncWork", nullptr, AsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +// [End napi_value_init] + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry1", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8527a2bca893b3b576341002649fbdf2838b9912 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,99 @@ +/* + * 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" + +// [Start napi_create_async_work] +struct CallbackData { + napi_async_work asyncWork = nullptr; + napi_deferred deferred = nullptr; + napi_ref callback = nullptr; + double args = 0; + double result = 0; +}; + +// [StartExclude napi_create_async_work] +// [Start napi_first_call_back_work] +static void ExecuteCB(napi_env env, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + callbackData->result = callbackData->args; +} +// [End napi_first_call_back_work] + +// [Start napi_second_call_back_main] +static void CompleteCB(napi_env env, napi_status status, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + napi_value result = nullptr; + napi_create_double(env, callbackData->result, &result); + if (callbackData->result > 0) { + napi_resolve_deferred(env, callbackData->deferred, result); + } else { + napi_reject_deferred(env, callbackData->deferred, result); + } + + napi_delete_async_work(env, callbackData->asyncWork); + delete callbackData; +} +// [End napi_second_call_back_main] +// [EndExclude napi_create_async_work] + +static napi_value AsyncWork(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1]; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_value promise = nullptr; + napi_deferred deferred = nullptr; + napi_create_promise(env, &deferred, &promise); + + auto callbackData = new CallbackData(); + callbackData->deferred = deferred; + napi_get_value_double(env, args[0], &callbackData->args); + + napi_value resourceName = nullptr; + napi_create_string_utf8(env, "AsyncCallback", NAPI_AUTO_LENGTH, &resourceName); + // 创建异步任务 + napi_create_async_work(env, nullptr, resourceName, ExecuteCB, CompleteCB, callbackData, &callbackData->asyncWork); + // 将异步任务加入队列 + napi_queue_async_work(env, callbackData->asyncWork); + + return promise; +} +// [End napi_create_async_work] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"asyncWork", nullptr, AsyncWork, 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8da6054c9da56dfb00546bd149b70709873510aa --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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 asyncWork: (data: number) => Promise; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d89e141e55f4f98ab72072db70e2882bf21d43f9 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/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 asyncWork: (arg1: number, arg2: number, callback: (result: number) => void) => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f6d9ff0107a24e75e2d5fa689276f8abcf838079 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/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": "libentry1.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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..13102ac26e8e307ce939b8e74f08ea8f954a303c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,53 @@ +/* + * 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 nativeModule from 'libentry1.so'; + +let num1: number = 123; +let num2: number = 456; + +@Entry +@Component +struct Index { + @State message: string = 'AsyncWork'; + + build() { + Column({space: 5}) { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + Button($r('app.string.AsyncWorkPromise')) + .margin(3) + .onClick(() => { + testNapi.asyncWork(1024).then((result) => { + hilog.info(0x0000, 'XXX', 'result is %{public}d', result); + this.message = 'result is ' + result.toString(); + }); + }) + Button($r('app.string.AsyncWorkCallback')) + .margin(3) + .onClick(() => { + nativeModule.asyncWork(num1, num2, (result) => { + hilog.info(0x0000, 'XXX', 'result is %{public}d', result); + this.message = 'result is ' + result.toString(); + }); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/NodeAPIAsynchronousTask.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/NodeAPIAsynchronousTask.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/NodeAPIAsynchronousTask.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/NodeAPIAsynchronousTask.test.ets index ec6dfa380fb91b242dbc36902f3fe7f3f307eb67..1e0ec01bdaed7011ede6208e501117b0ece32d8a --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/NodeAPIAsynchronousTask.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/ets/test/NodeAPIAsynchronousTask.test.ets @@ -1,74 +1,74 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIAsynchronousTaskTest() { - describe('nodeAPIAsynchronousTaskTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用nAsyncWorkPromise相关函数 - */ - it('testNodeAPIAsynchronousTask001', 0, async () => { - console.info('uitest: testNodeAPIAsynchronousTask001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call AsyncWorkPromise')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('result is 1024')); - console.info('uitest: testNodeAPIAsynchronousTask001 end'); - }) - - /** - * 点击按钮,调用AsyncWorkCallback相关函数 - */ - it('testNodeAPIAsynchronousTask002', 0, async () => { - console.info('uitest: testNodeAPIAsynchronousTask002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call AsyncWorkCallback')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('result is 579')); - console.info('uitest: testNodeAPIAsynchronousTask002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIAsynchronousTaskTest() { + describe('nodeAPIAsynchronousTaskTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用nAsyncWorkPromise相关函数 + */ + it('testNodeAPIAsynchronousTask001', 0, async () => { + console.info('uitest: testNodeAPIAsynchronousTask001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call AsyncWorkPromise')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('result is 1024')); + console.info('uitest: testNodeAPIAsynchronousTask001 end'); + }) + + /** + * 点击按钮,调用AsyncWorkCallback相关函数 + */ + it('testNodeAPIAsynchronousTask002', 0, async () => { + console.info('uitest: testNodeAPIAsynchronousTask002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call AsyncWorkCallback')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('result is 579')); + console.info('uitest: testNodeAPIAsynchronousTask002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2563e5f7d9fc59455068a133a7d5792cf8963583 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/ohosTest.md @@ -0,0 +1,9 @@ +# 使用Node-API接口进行异步任务开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| --------------------------------------- | ------------ | -------------------------------------- | ---------------------------------------------------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 asyncWork | 位于主页 | 点击Call AsyncWorkCallback的Button组件 | 成功调用函数输出日志,页面顶端文本变为result is 579 | Pass | +| ArkTS端成功调用native侧接口 asyncWork | 位于主页 | 点击Call AsyncWorkPromise的Button组件 | 成功调用函数输出日志,页面顶端文本变为result is 1024 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask1.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask2.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/screenshots/NodeAPIAsynchronousTask2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..32cec47a1c82878bd14d3fa23e6a1472d7884581 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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.nodeapiapplicationscenario", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8bbf5ef474d4adf5f35b4776dd5425f734e82d02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeApiApplicationScenario" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/README.md new file mode 100644 index 0000000000000000000000000000000000000000..19ccb5ce33ed117c58af11ba6f79f5ab9551d567 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/README.md @@ -0,0 +1,87 @@ +# ArkTSNode-API使用场景 + +### 介绍 + +开发者通过pthread_create创建新线程后,可以通过napi_create_ark_runtime来创建一个新的ArkTS基础运行时环境,并通过该运行时环境加载ArkTS模块。当使用结束后,开发者需要通过napi_destroy_ark_runtime来销毁所创建的ArkTS基础运行时环境。 + +napi_create_threadsafe_function是Node-API接口之一,用于创建一个线程安全的JavaScript函数。主要用于在多个线程之间共享和调用,而不会出现竞争条件或死锁。例如异步计算、数据共享、多线程编程场景。 + +Node-API中的napi_call_threadsafe_function_with_priority接口的功能是从异步线程向ArkTS线程投递任务,底层队列会根据任务的优先级和入队方式来处理任务。 + +在自己创建的ArkTS运行环境中调用异步的ArkTS接口时,可以通过使用Node-API中的扩展接口napi_run_event_loop和napi_stop_event_loop来运行和停止ArkTS实例中的事件循环,该工程中展示的代码详细描述可查如下链接。 + +- [使用Node-API接口创建ArkTS运行时环境](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-ark-runtime.md) +- [使用Node-API接口进行线程安全开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-thread-safety.md) +- [使用Node-API接口从异步线程向ArkTS线程投递指定优先级和入队方式的的任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-call-threadsafe-function-with-priority.md) +- [使用扩展的Node-API接口在异步线程中运行和停止事件循环](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-event-loop.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击button组件可以执行对应文本内容的Node-API接口并将文本NodeAPI改为执行成功结果。 +3. 运行测试用例NodeApiApplicationScenario.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── libentry + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── libentry1 + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ │ ├── thread_safety.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // Node-API使用场景 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeApiApplicationScenario.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4cc3a2d6c65f4b4d1bd6a128ac45a311c7cbe69a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/build-profile.json5 @@ -0,0 +1,70 @@ +/* + * 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", +// [Start napi_event_loop_build] +// [Start napi_ark_runtime_build] + "buildOption": { + "arkOptions" : { + "runtimeOnly" : { + "sources": [ + "./src/main/ets/pages/ObjectUtils.ets" + ] + } + }, +// [End napi_event_loop_build] +// [Start napi_ark_runtime_build] + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a26930aada5667e32aa820a560ebf36b42056cc6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/oh-package.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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry", + "libentry1.so": "file:./src/main/cpp/types/libentry1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..86fbdf5e67103bff089b6f03449cf696e798a5a6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,12 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(MyApplication) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +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) +add_library(entry1 SHARED thread_safety.cpp) +target_link_libraries(entry1 PUBLIC libace_napi.z.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3a06f1f62688b12d72e8d7f2c27af8ef17d899e7 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_call_threadsafe_function_with_priority_cpp] +// [Start napi_ark_runtime_cpp] +#include +#include "napi/native_api.h" +// [StartExclute napi_ark_runtime_cpp] +#include +#include +#include + +static constexpr int INT_ARG_2 = 2; // 入参索引 +static constexpr int INT_ARG_12 = 12; // 入参索引 +static constexpr int INT_ARG_15 = 15; // 入参索引 +// [EndExclute napi_ark_runtime_cpp] +// [StartExclute napi_call_threadsafe_function_with_priority_cpp] +static void *CreateArkRuntimeFunc(void *arg) +{ + // 1. 创建基础运行环境 + napi_env env; + napi_status ret = napi_create_ark_runtime(&env); + if (ret != napi_ok) { + return nullptr; + } + + // 2. 加载自定义模块 + napi_value objUtils; + ret = napi_load_module_with_info(env, "entry/src/main/ets/pages/ObjectUtils", "com.example.myapplication/entry", + &objUtils); + if (ret != napi_ok) { + return nullptr; + } + + // 3. 使用ArkTS中的logger + napi_value logger; + ret = napi_get_named_property(env, objUtils, "Logger", &logger); + if (ret != napi_ok) { + return nullptr; + } + ret = napi_call_function(env, objUtils, logger, 0, nullptr, nullptr); + + // 4. 销毁ArkTS环境 + ret = napi_destroy_ark_runtime(&env); + + return nullptr; +} + +static napi_value CreateArkRuntime(napi_env env, napi_callback_info info) +{ + pthread_t tid; + pthread_create(&tid, nullptr, CreateArkRuntimeFunc, nullptr); + pthread_join(tid, nullptr); + return nullptr; +} +// [StartExclute napi_ark_runtime_cpp] +// [Start napi_event_loop_cpp] +static napi_value ResolvedCallback(napi_env env, napi_callback_info info) +{ + napi_stop_event_loop(env); + return nullptr; +} + +static napi_value RejectedCallback(napi_env env, napi_callback_info info) +{ + napi_stop_event_loop(env); + return nullptr; +} + +static void *RunEventLoopFunc(void *arg) +{ + // 1. 创建ArkTS实例 + napi_env env; + napi_status ret = napi_create_ark_runtime(&env); + if (ret != napi_ok) { + return nullptr; + } + + // 2. 加载自定义的模块 + napi_value objectUtils; + // 'com.example.myapplication' 为当前应用的bundleName + ret = napi_load_module_with_info(env, "ets/pages/ObjectUtils", "com.example.myapplication/entry", &objectUtils); + if (ret != napi_ok) { + return nullptr; + } + + // 3. 调用异步SetTimeout接口 + napi_value setTimeout = nullptr; + napi_value promise = nullptr; + + napi_get_named_property(env, objectUtils, "SetTimeout", &setTimeout); + napi_call_function(env, objectUtils, setTimeout, 0, nullptr, &promise); + + napi_value theFunc = nullptr; + if (napi_get_named_property(env, promise, "then", &theFunc) != napi_ok) { + return nullptr; + } + + napi_value resolvedCallback = nullptr; + napi_value rejectedCallback = nullptr; + napi_create_function(env, "resolvedCallback", NAPI_AUTO_LENGTH, ResolvedCallback, nullptr, &resolvedCallback); + napi_create_function(env, "rejectedCallback", NAPI_AUTO_LENGTH, RejectedCallback, nullptr, &rejectedCallback); + napi_value argv[2] = {resolvedCallback, rejectedCallback}; + napi_call_function(env, promise, theFunc, INT_ARG_2, argv, nullptr); + + auto flag = reinterpret_cast(arg); + if (*flag == true) { + napi_run_event_loop(env, napi_event_mode_default); + } else { + // 非阻塞式的处理任务,有可能队列中还没有任务就已经返回了 + napi_run_event_loop(env, napi_event_mode_nowait); + } + return nullptr; +} + +static napi_value RunEventLoop(napi_env env, napi_callback_info info) +{ + pthread_t tid; + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + bool flag = false; + napi_get_value_bool(env, argv[0], &flag); + // 创建异步线程 + pthread_create(&tid, nullptr, RunEventLoopFunc, &flag); + pthread_join(tid, nullptr); + + return nullptr; +} +// [StartExclute napi_event_loop_cpp] +// [EndExclute napi_call_threadsafe_function_with_priority_cpp] +struct CallbackData { + napi_threadsafe_function tsfn; + napi_async_work work; +}; +// ArkTS线程的回调实现 +static void CallJs(napi_env env, napi_value jsCb, void *context, void *data) +{ + if (env == nullptr) { + return; + } + napi_value resultNumber = nullptr; + napi_value undefined = nullptr; + napi_get_undefined(env, &undefined); + napi_value number1 = nullptr; + napi_create_int32(env, INT_ARG_12, &number1); + napi_value number2 = nullptr; + napi_create_int32(env, INT_ARG_15, &number2); + napi_value argv[2] = {number1, number2}; + napi_call_function(env, undefined, jsCb, INT_ARG_2, argv, &resultNumber); + int32_t res = 0; + napi_get_value_int32(env, resultNumber, &res); +} + +// 异步线程中调用该接口向ArkTS线程投递指定优先级和入队方式的任务 +static void ExecuteWork(napi_env env, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + // 执行任务为napi_priority_idle优先级,入队方式为队列尾部入队 + napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_idle, true); + napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_low, true); + napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_high, true); + napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_immediate, true); + // 执行任务为napi_priority_high优先级,入队方式为队列头部入队 + napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_high, false); +} + +static void WorkComplete(napi_env env, napi_status status, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + napi_release_threadsafe_function(callbackData->tsfn, napi_tsfn_release); + napi_delete_async_work(env, callbackData->work); + callbackData->work = nullptr; + callbackData->tsfn = nullptr; +} + +static napi_value CallThreadSafeWithPriority(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value jsCb = nullptr; + CallbackData *callbackData = nullptr; + napi_get_cb_info(env, info, &argc, &jsCb, nullptr, reinterpret_cast(&callbackData)); + napi_value resourceName = nullptr; + napi_create_string_utf8(env, "Thread-safe Function Demo", NAPI_AUTO_LENGTH, &resourceName); + napi_create_threadsafe_function(env, jsCb, nullptr, resourceName, 0, 1, callbackData, nullptr, callbackData, CallJs, + &callbackData->tsfn); + napi_create_async_work(env, nullptr, resourceName, ExecuteWork, WorkComplete, callbackData, &callbackData->work); + napi_queue_async_work(env, callbackData->work); + return nullptr; +} +// [EndExclute napi_event_loop_cpp] +// [EndExclute napi_ark_runtime_cpp] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + CallbackData *callbackData = new CallbackData(); + napi_property_descriptor desc[] = { + {"createArkRuntime", nullptr, CreateArkRuntime, nullptr, nullptr, nullptr, napi_static, nullptr}, + {"runEventLoop", nullptr, RunEventLoop, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"callThreadSafeWithPriority", nullptr, CallThreadSafeWithPriority, nullptr, nullptr, nullptr, + napi_default, callbackData}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module nativeModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = nullptr, + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterQueueWorkModule() { napi_module_register(&nativeModule); } +// [End napi_call_threadsafe_function_with_priority_cpp] +// [End napi_event_loop_cpp] +// [End napi_ark_runtime_cpp] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/thread_safety.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/thread_safety.cpp old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/thread_safety.cpp rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/thread_safety.cpp index dc5e4f08e19fd7ef1ac68b6a6584a81230a0e3fc..e76b91ce31c0bb3c7a26e1bef608d39e494531b1 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/thread_safety.cpp +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/thread_safety.cpp @@ -1,146 +1,146 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_thread_safety_cpp] -#include "napi/native_api.h" -#include "hilog/log.h" -#include - -static constexpr int INT_ARG_2 = 2; // 入参索引 -static constexpr int INT_BUF_32 = 32; // 入参索引 - -struct CallbackData { - napi_threadsafe_function tsfn; - napi_async_work work; -}; - -static void ExecuteWork(napi_env env, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - std::promise promise; - auto future = promise.get_future(); - napi_call_threadsafe_function(callbackData->tsfn, &promise, napi_tsfn_nonblocking); - try { - auto result = future.get(); - OH_LOG_INFO(LOG_APP, "XXX, Result from JS %{public}s", result.c_str()); - } catch (const std::exception &e) { - OH_LOG_INFO(LOG_APP, "XXX, Result from JS %{public}s", e.what()); - } -} - -static napi_value ResolvedCallback(napi_env env, napi_callback_info info) -{ - void *data = nullptr; - size_t argc = 1; - napi_value argv[1]; - if (napi_get_cb_info(env, info, &argc, argv, nullptr, &data) != napi_ok) { - return nullptr; - } - size_t result = 0; - char buf[32] = {0}; - napi_get_value_string_utf8(env, argv[0], buf, INT_BUF_32, &result); - reinterpret_cast *>(data)->set_value(std::string(buf)); - return nullptr; -} - -static napi_value RejectedCallback(napi_env env, napi_callback_info info) -{ - void *data = nullptr; - if (napi_get_cb_info(env, info, nullptr, nullptr, nullptr, &data) != napi_ok) { - return nullptr; - } - reinterpret_cast *>(data)->set_exception( - std::make_exception_ptr(std::runtime_error("Error in jsCallback"))); - return nullptr; -} - -static void CallJs(napi_env env, napi_value jsCb, void *context, void *data) -{ - if (env == nullptr) { - return; - } - napi_value undefined = nullptr; - napi_value promise = nullptr; - napi_get_undefined(env, &undefined); - napi_call_function(env, undefined, jsCb, 0, nullptr, &promise); - napi_value thenFunc = nullptr; - if (napi_get_named_property(env, promise, "then", &thenFunc) != napi_ok) { - return; - } - napi_value resolvedCallback; - napi_value rejectedCallback; - napi_create_function(env, "resolvedCallback", NAPI_AUTO_LENGTH, ResolvedCallback, data, &resolvedCallback); - napi_create_function(env, "rejectedCallback", NAPI_AUTO_LENGTH, RejectedCallback, data, &rejectedCallback); - napi_value argv[2] = {resolvedCallback, rejectedCallback}; - napi_call_function(env, promise, thenFunc, INT_ARG_2, argv, nullptr); -} - -static void WorkComplete(napi_env env, napi_status status, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - napi_release_threadsafe_function(callbackData->tsfn, napi_tsfn_release); - napi_delete_async_work(env, callbackData->work); - callbackData->tsfn = nullptr; - callbackData->work = nullptr; -} - - -static napi_value StartThread(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value jsCb = nullptr; - CallbackData *callbackData = nullptr; - napi_get_cb_info(env, info, &argc, &jsCb, nullptr, reinterpret_cast(&callbackData)); - - // 创建一个线程安全函数 - napi_value resourceName = nullptr; - napi_create_string_utf8(env, "Thread-safe Function Demo", NAPI_AUTO_LENGTH, &resourceName); - napi_create_threadsafe_function(env, jsCb, nullptr, resourceName, 0, 1, callbackData, nullptr, callbackData, CallJs, - &callbackData->tsfn); - - // 创建一个异步任务 - // ExecuteWork会执行在一个由libuv创建的非JS线程上 - // 此处使用napi_create_async_work是为了模拟在非JS线程场景使用napi_call_threadsafe_function接口向JS线程提交任务 - napi_create_async_work(env, nullptr, resourceName, ExecuteWork, WorkComplete, callbackData, &callbackData->work); - - // 将异步任务加入到异步队列中 - napi_queue_async_work(env, callbackData->work); - return nullptr; -} - - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - CallbackData *callbackData = new CallbackData(); // 可在线程退出时释放 - napi_property_descriptor desc[] = { - {"startThread", nullptr, StartThread, nullptr, nullptr, nullptr, napi_default, callbackData}, - }; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} -EXTERN_C_END -// [End napi_thread_safety_cpp] - -static napi_module demoModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "entry1", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_thread_safety_cpp] +#include "napi/native_api.h" +#include "hilog/log.h" +#include + +static constexpr int INT_ARG_2 = 2; // 入参索引 +static constexpr int INT_BUF_32 = 32; // 入参索引 + +struct CallbackData { + napi_threadsafe_function tsfn; + napi_async_work work; +}; + +static void ExecuteWork(napi_env env, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + std::promise promise; + auto future = promise.get_future(); + napi_call_threadsafe_function(callbackData->tsfn, &promise, napi_tsfn_nonblocking); + try { + auto result = future.get(); + OH_LOG_INFO(LOG_APP, "XXX, Result from JS %{public}s", result.c_str()); + } catch (const std::exception &e) { + OH_LOG_INFO(LOG_APP, "XXX, Result from JS %{public}s", e.what()); + } +} + +static napi_value ResolvedCallback(napi_env env, napi_callback_info info) +{ + void *data = nullptr; + size_t argc = 1; + napi_value argv[1]; + if (napi_get_cb_info(env, info, &argc, argv, nullptr, &data) != napi_ok) { + return nullptr; + } + size_t result = 0; + char buf[32] = {0}; + napi_get_value_string_utf8(env, argv[0], buf, INT_BUF_32, &result); + reinterpret_cast *>(data)->set_value(std::string(buf)); + return nullptr; +} + +static napi_value RejectedCallback(napi_env env, napi_callback_info info) +{ + void *data = nullptr; + if (napi_get_cb_info(env, info, nullptr, nullptr, nullptr, &data) != napi_ok) { + return nullptr; + } + reinterpret_cast *>(data)->set_exception( + std::make_exception_ptr(std::runtime_error("Error in jsCallback"))); + return nullptr; +} + +static void CallJs(napi_env env, napi_value jsCb, void *context, void *data) +{ + if (env == nullptr) { + return; + } + napi_value undefined = nullptr; + napi_value promise = nullptr; + napi_get_undefined(env, &undefined); + napi_call_function(env, undefined, jsCb, 0, nullptr, &promise); + napi_value thenFunc = nullptr; + if (napi_get_named_property(env, promise, "then", &thenFunc) != napi_ok) { + return; + } + napi_value resolvedCallback; + napi_value rejectedCallback; + napi_create_function(env, "resolvedCallback", NAPI_AUTO_LENGTH, ResolvedCallback, data, &resolvedCallback); + napi_create_function(env, "rejectedCallback", NAPI_AUTO_LENGTH, RejectedCallback, data, &rejectedCallback); + napi_value argv[2] = {resolvedCallback, rejectedCallback}; + napi_call_function(env, promise, thenFunc, INT_ARG_2, argv, nullptr); +} + +static void WorkComplete(napi_env env, napi_status status, void *data) +{ + CallbackData *callbackData = reinterpret_cast(data); + napi_release_threadsafe_function(callbackData->tsfn, napi_tsfn_release); + napi_delete_async_work(env, callbackData->work); + callbackData->tsfn = nullptr; + callbackData->work = nullptr; +} + + +static napi_value StartThread(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value jsCb = nullptr; + CallbackData *callbackData = nullptr; + napi_get_cb_info(env, info, &argc, &jsCb, nullptr, reinterpret_cast(&callbackData)); + + // 创建一个线程安全函数 + napi_value resourceName = nullptr; + napi_create_string_utf8(env, "Thread-safe Function Demo", NAPI_AUTO_LENGTH, &resourceName); + napi_create_threadsafe_function(env, jsCb, nullptr, resourceName, 0, 1, callbackData, nullptr, callbackData, CallJs, + &callbackData->tsfn); + + // 创建一个异步任务 + // ExecuteWork会执行在一个由libuv创建的非JS线程上 + // 此处使用napi_create_async_work是为了模拟在非JS线程场景使用napi_call_threadsafe_function接口向JS线程提交任务 + napi_create_async_work(env, nullptr, resourceName, ExecuteWork, WorkComplete, callbackData, &callbackData->work); + + // 将异步任务加入到异步队列中 + napi_queue_async_work(env, callbackData->work); + return nullptr; +} + + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + CallbackData *callbackData = new CallbackData(); // 可在线程退出时释放 + napi_property_descriptor desc[] = { + {"startThread", nullptr, StartThread, nullptr, nullptr, nullptr, napi_default, callbackData}, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END +// [End napi_thread_safety_cpp] + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry1", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3f830fc2841db8ed2fa7e6d69b5ac6b04a8f465d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_ark_runtime_dts] +export const createArkRuntime: () => object; +// [End napi_ark_runtime_dts] +// [Start napi_event_loop_dts] +export const runEventLoop: (isDefault: boolean) => object; +// [End napi_event_loop_dts] +// [Start napi_call_threadsafe_function_with_priority_dts] +export const callThreadSafeWithPriority: (cb: (a: number, b: number) => number) => void; +// [End napi_call_threadsafe_function_with_priority_dts] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3708a31b140166dca2db73f900f89b1bbd069a5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/Index.d.ts @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_thread_safety_dts] +export const startThread: (a: () => Promise) => void; +// [End napi_thread_safety_dts] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f6d9ff0107a24e75e2d5fa689276f8abcf838079 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/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": "libentry1.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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..75f20730a7502c2debf881c52e415e691204c30a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_call_threadsafe_function_with_priority_ets] +// [Start napi_event_loop_ets] +// [Start napi_ark_runtime_ets] +import testNapi from 'libentry.so'; +// [StartExclute napi_call_threadsafe_function_with_priority_ets] +// [StartExclute napi_event_loop_ets] +// [StartExclute napi_ark_runtime_ets] +// [Start napi_thread_safety_ets] +import nativeModule from 'libentry1.so'; +// [StartExclute napi_thread_safety_ets] +@Entry +@Component +struct Index { + @State message: string = 'NodeAPI'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + Button($r('app.string.createArkRuntime')) + .width('70%') + .onClick(() => { + // [EndExclute napi_ark_runtime_ets] + testNapi.createArkRuntime(); + // [End napi_ark_runtime_ets] + this.message = 'ArkRuntime success'; + }) + Button($r('app.string.runEventLoop')) + .width('70%') + .onClick(() => { + // [EndExclute napi_event_loop_ets] + testNapi.runEventLoop(true); + // [End napi_event_loop_ets] + this.message = 'EventLoop success'; + }) + Button($r('app.string.CallThreadSafeWithPriority')) + .width('70%') + .onClick(() => { + // [EndExclute napi_call_threadsafe_function_with_priority_ets] + let callback = (a: number, b: number): number => { + console.info('result is ' + (a + b)) + return a + b; + } + testNapi.callThreadSafeWithPriority(callback); + // [End napi_call_threadsafe_function_with_priority_ets] + this.message = 'ThreadSafeWithPriority success'; + }) + Button($r('app.string.startThread')) + .width('70%') + .onClick(() => { + // [EndExclute napi_thread_safety_ets] + let callback = (): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + resolve('string from promise'); + }, 5000); + }); + } + nativeModule.startThread(callback); + // [End napi_thread_safety_ets] + this.message = 'StartThread success'; + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/ObjectUtils.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/ObjectUtils.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/ObjectUtils.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/ObjectUtils.ets index 7dc7cf1eea9caf2538cdd3e7516129333612bc03..893ce0d23b1ee6fe246d7fbbc64b5157d11e3d6c --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/ObjectUtils.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/ObjectUtils.ets @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_ark_runtime_utils] -export function Logger() { - console.log('print log'); -} -// [End napi_ark_runtime_utils] -// [Start napi_event_loop_utils] -export function SetTimeout(): Promise { - return new Promise((resolve) => { - setTimeout(() => { - console.info('set timer delay 1s'); - // attempt to stop the event loop at napi terminal - resolve(); - }, 1000) - }) -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_ark_runtime_utils] +export function Logger() { + console.log('print log'); +} +// [End napi_ark_runtime_utils] +// [Start napi_event_loop_utils] +export function SetTimeout(): Promise { + return new Promise((resolve) => { + setTimeout(() => { + console.info('set timer delay 1s'); + // attempt to stop the event loop at napi terminal + resolve(); + }, 1000) + }) +} // [End napi_event_loop_utils] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/NodeApiApplicationScenario.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/NodeApiApplicationScenario.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/NodeApiApplicationScenario.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/NodeApiApplicationScenario.test.ets index 25017f55819a8fa4a8fe4422c85d23b0aeae7a28..92fe3c03994fcb6065761dc9f2622aa474a7380c --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/NodeApiApplicationScenario.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/NodeApiApplicationScenario.test.ets @@ -1,108 +1,108 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeApiApplicationScenarioTest() { - describe('nodeApiApplicationScenarioTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用createArkRuntime相关函数 - */ - it('testNodeApiArkTSRuntime001', 0, async (done: Function) => { - console.info('uitest: testNodeApiArkTSRuntime001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call createArkRuntime')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ArkRuntime success')); - console.info('uitest: testNodeApiArkTSRuntime001 end'); - done(); - }) - - /** - * 点击按钮,调用runEventLoop相关函数 - */ - it('testNodeAPIEventLoop001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIEventLoop001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call runEventLoop')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('EventLoop success')); - console.info('uitest: testNodeAPIEventLoop001 end'); - done(); - }) - - /** - * 点击按钮,调用CallThreadSafeWithPriority相关函数 - */ - it('testNodeAPICallThreadsafeFunctionWithPriority001', 0, async (done: Function) => { - console.info('uitest: testNodeAPICallThreadsafeFunctionWithPriority001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call CallThreadSafeWithPriority')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ThreadSafeWithPriority success')); - console.info('uitest: testNodeAPIArray001 end'); - done(); - }) - - /** - * 点击按钮,调用startThread相关函数 - */ - it('testNodeAPIThreadSafety001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIThreadSafety001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call startThread')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('StartThread success')); - console.info('uitest: testNodeAPIThreadSafety001 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeApiApplicationScenarioTest() { + describe('nodeApiApplicationScenarioTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用createArkRuntime相关函数 + */ + it('testNodeApiArkTSRuntime001', 0, async (done: Function) => { + console.info('uitest: testNodeApiArkTSRuntime001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call createArkRuntime')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ArkRuntime success')); + console.info('uitest: testNodeApiArkTSRuntime001 end'); + done(); + }) + + /** + * 点击按钮,调用runEventLoop相关函数 + */ + it('testNodeAPIEventLoop001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIEventLoop001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call runEventLoop')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('EventLoop success')); + console.info('uitest: testNodeAPIEventLoop001 end'); + done(); + }) + + /** + * 点击按钮,调用CallThreadSafeWithPriority相关函数 + */ + it('testNodeAPICallThreadsafeFunctionWithPriority001', 0, async (done: Function) => { + console.info('uitest: testNodeAPICallThreadsafeFunctionWithPriority001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call CallThreadSafeWithPriority')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ThreadSafeWithPriority success')); + console.info('uitest: testNodeAPIArray001 end'); + done(); + }) + + /** + * 点击按钮,调用startThread相关函数 + */ + it('testNodeAPIThreadSafety001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIThreadSafety001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call startThread')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('StartThread success')); + console.info('uitest: testNodeAPIThreadSafety001 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeApiUse/NodeAPIFunction/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/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/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..f8877f53e556b44d0365c16f8adfe6f25782c52b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/ohosTest.md @@ -0,0 +1,11 @@ +# Node-API使用场景用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| -------------------------------------------------------- | ------------ | ----------------------------------------------- | --------------------------------------------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口createArkRuntime | 位于主页 | 点击Call createArkRuntime的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | +| ArkTS端成功调用native侧接口 callThreadSafeWithPriority | 位于主页 | 点击Call CallThreadSafeWithPriority的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | +| ArkTS端成功调用native侧接口runEventLoop | 位于主页 | 点击按钮为调用runEventLoop的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | +| ArkTS端成功调用native侧接口startThread | 位于主页 | 点击按钮为调用startThread的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario1.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario2.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiApplicationScenario/screenshots/NodeApiApplicationScenario2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..14d4a8aecf247cbbb116614d283cc7b86ff7c3dd --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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.nodeapiloadmodule", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f11975d7ca7ac9a1020af913a9fce5c3842f222e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeApiLoadModule" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/README.md new file mode 100644 index 0000000000000000000000000000000000000000..304c37ec9a7420d708dbb2d462f1da916bce0975 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API接口在主线程中进行模块加载 + +### 介绍 + +本工程展示了使用Node-API接口在主线程中进行系统模块加载与ArkTS单文件加载。详细描述可查如下链接中。 + +- [使用Node-API接口在主线程中进行模块加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-load-module.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现如上图效果和两个按钮,依次点击按钮后可以加载系统模块和单文件模块,并将成功结果呈现到text文本中。 +3. 运行测试用例NodeApiLoadModule.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── libentry + │ │ └── libentry1 + │ │ ├── file.cpp // ArkTS单文件加载 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp // 系统模块加载 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 加载模块 + │ │ ├── Test.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeApiLoadModule.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiLoadModule > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7aad2ac11a47640135f632c27e17743e626f8db4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + // [Start napi_load_module_napi_build] + "buildOption": { + "arkOptions" : { + "runtimeOnly" : { + "sources": [ + "./src/main/ets/Test.ets" + ] + } + }, + // [End napi_load_module_napi_build] + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a26930aada5667e32aa820a560ebf36b42056cc6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/oh-package.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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry", + "libentry1.so": "file:./src/main/cpp/types/libentry1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4848d2f549bbd45bf5e96159e668ff8d7ad5d400 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,18 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeApiLoadModule) + +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) + +add_library(entry1 SHARED file.cpp) +target_link_libraries(entry1 PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/file.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/file.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1b77c615f1f5a31226d9c7bdfcfd952d8b1d806 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/file.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "napi/native_api.h" +#include +// [Start napi_load_module_napi_file] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + napi_value result; + // 1. 使用napi_load_module加载Test文件中的模块 + napi_status status = napi_load_module(env, "ets/Test", &result); + + napi_value testFn; + // 2. 使用napi_get_named_property获取test函数 + napi_get_named_property(env, result, "test", &testFn); + // 3. 使用napi_call_function调用函数test + napi_call_function(env, result, testFn, 0, nullptr, nullptr); + + napi_value value; + napi_value key; + std::string keyStr = "value"; + napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); + // 4. 使用napi_get_property获取变量value + napi_get_property(env, result, key, &value); + return result; +} +// [End napi_load_module_napi_file] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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 = "entry1", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8049c17efaeecf97692d03ae160765168f576357 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/napi_init.cpp @@ -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. + */ + +#include "napi/native_api.h" +#include +// [Start napi_load_module_napi_init] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + // 1. 使用napi_load_module加载模块@ohos.hilog + napi_value result; + napi_status status = napi_load_module(env, "@ohos.hilog", &result); + + // 2. 使用napi_get_named_property获取info函数 + napi_value infoFn; + napi_get_named_property(env, result, "info", &infoFn); + + napi_value tag; + std::string formatStr = "test"; + napi_create_string_utf8(env, formatStr.c_str(), formatStr.size(), &tag); + + napi_value outputString; + std::string str = "Hello OpenHarmony"; + napi_create_string_utf8(env, str.c_str(), str.size(), &outputString); + + napi_value flag; + napi_create_int32(env, 0, &flag); + + napi_value args[3] = {flag, tag, outputString}; + // 3. 使用napi_call_function调用info函数 + napi_call_function(env, result, infoFn, 3, args, nullptr); + return result; +} +// [End napi_load_module_napi_init] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f6d9ff0107a24e75e2d5fa689276f8abcf838079 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/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": "libentry1.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/Test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..d212d171e4dddd769fb7385ffe56c0892e2c8754 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/Test.ets @@ -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. + */ +// [Start napi_load_module_napi_test] +let value = 123; +function test() { + console.log('Hello OpenHarmony'); +} +export {value, test}; +// [End napi_load_module_napi_test] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0b0bf4e26bfb2d0f2e8b9a0e79f514bf85590b9b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,46 @@ +/* + * 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 test from 'libentry1.so'; + +@Entry +@Component +struct Index { + @State message: string = 'LoudModule'; + + build() { + Column() { + Text(this.message) + .fontSize(30) + Button($r('app.string.loadModuleSystem')) + .margin(3) + .width('70%') + .onClick(() => { + testNapi.loadModule(); + this.message = 'loadModuleSystem success'; + }) + Button($r('app.string.loadModuleFile')) + .margin(3) + .width('70%') + .onClick(() => { + test.loadModule(); + this.message = 'loadModuleFile success'; + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/NodeApiLoadModule.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/NodeApiLoadModule.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/NodeApiLoadModule.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/NodeApiLoadModule.test.ets index faf4dd5f2b735c38047f68101d12246cf90e14f2..917767907b347f49f358ccf7b7a6ec599325edd8 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/NodeApiLoadModule.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/ets/test/NodeApiLoadModule.test.ets @@ -1,74 +1,74 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeApiLoadModuleTest() { - describe('nodeApiLoadModuleTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用loadModuleFile相关函数 - */ - it('testNodeApiLoadModuleTest001', 0, async () => { - console.info('uitest: testNodeApiLoadModuleTest001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleFile')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleFile success')); - console.info('uitest: testNodeApiLoadModuleTest001 end'); - }) - - /** - * 点击按钮,调用loadModuleSystem相关函数 - */ - it('testNodeApiLoadModuleTest002', 0, async () => { - console.info('uitest: testNodeApiLoadModuleTest002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleSystem')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleSystem success')); - console.info('uitest: testNodeApiLoadModuleTest002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeApiLoadModuleTest() { + describe('nodeApiLoadModuleTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用loadModuleFile相关函数 + */ + it('testNodeApiLoadModuleTest001', 0, async () => { + console.info('uitest: testNodeApiLoadModuleTest001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleFile')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleFile success')); + console.info('uitest: testNodeApiLoadModuleTest001 end'); + }) + + /** + * 点击按钮,调用loadModuleSystem相关函数 + */ + it('testNodeApiLoadModuleTest002', 0, async () => { + console.info('uitest: testNodeApiLoadModuleTest002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleSystem')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleSystem success')); + console.info('uitest: testNodeApiLoadModuleTest002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..8d1aaa6c111ed92dafe6acad58ab82bfdc2aead0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/ohosTest.md @@ -0,0 +1,9 @@ +# 使用Node-API接口在主线程中进行模块加载测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ---------------------------------------- | ------------ | ----------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleSystem的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleSystem success | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleFile的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleFile success | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule1.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule2.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/screenshots/NodeApiLoadModule2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e0db583f686c1965d52b20bb8c8acf64b7925f0f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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.nodeapiloadmodulewithinfo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e99e87423387c8938d635dd33c523dc7c4468b28 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeApiLoadModuleWithInfo" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..16bfb3e320f9ad3d508ac4a0cd90d9033b0c5b0e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/README.md @@ -0,0 +1,86 @@ +# ArkTS使用Node-API接口进行模块加载 + +### 介绍 + + Node-API中的napi_load_module_with_info接口的功能是进行模块的加载,当模块加载出来之后,可以使用函数napi_get_property获取模块导出的变量,也可以使用napi_get_named_property获取模块导出的函数,该函数可以在新创建的ArkTS基础运行时环境中使用。 + + 本工程展示了使用napi_load_module_with_info接口进行对不同内容的加载,代码详细描述可查如下链接。 + +- [使用Node-API接口进行模块加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-load-module-with-info.md) + +### 效果预览 + +| 首页图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现LoadModule效果和六个按钮,点击按钮后可以调用napi_load_module_with_info接口进行对不同内容进行加载,并修改Text文本内容。 +3. 运行测试用例NodeApiLoadModuleWithInfo.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── libentry + │ │ └── libentryone + │ │ └── libentrytwo + │ │ └── libentrythree + │ │ └── libentryfour + │ │ ├── api.cpp // 加载API模块 + │ │ ├── har_name.cpp // 加载HAR模块名 + │ │ ├── file.cpp // 加载模块内文件路径 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp // 加载Native库 + │ │ ├── remote_har.cpp // 加载远程HAR模块名 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 加载模块 + │ │ ├── Test.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeApiLoadModuleWithInfo.test.ets // 自动化测试代码 + │ │ └── List.test.ets + har1/ // HAR加载HAR模块名 + har2/ // HAR加载HAR模块名 + library/ // 加载HAR模块名 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiLoadModuleWithInfo > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..81e44eac1b9e1c64907767dad07b03e740e7903d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/build-profile.json5 @@ -0,0 +1,70 @@ +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "library", + "srcPath": "./library", + }, + { + "name": "har1", + "srcPath": "./har1", + }, + { + "name": "har2", + "srcPath": "./har2", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..865bd3b2e34c6196ab93c2608153b4a7b1b47ec6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/build-profile.json5 @@ -0,0 +1,94 @@ +/* + * 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", + // [Start napi_load_module_with_info_entry_build] + // [Start napi_load_module_with_info_entry_build2] + // [Start napi_load_module_with_info_entry_build3] + // [Start napi_load_module_with_info_entry_build4] + "buildOption": { + "arkOptions" : { + "runtimeOnly" : { + // [StartExclute napi_load_module_with_info_entry_build2] + // [StartExclute napi_load_module_with_info_entry_build3] + // [StartExclute napi_load_module_with_info_entry_build4] + "sources": [ + "./src/main/ets/Test.ets", + ], + // [EndExclute napi_load_module_with_info_entry_build2] + // [EndExclute napi_load_module_with_info_entry_build3] + // [EndExclute napi_load_module_with_info_entry_build4] + // [End napi_load_module_with_info_entry_build] + "packages": [ + // [StartExclute napi_load_module_with_info_entry_build3] + // [StartExclute napi_load_module_with_info_entry_build4] + "library", + // [End napi_load_module_with_info_entry_build2] + // [EndExclute napi_load_module_with_info_entry_build4] + "libentry.so", + // [End napi_load_module_with_info_entry_build4] + "libentryone.so", + "libentrytwo.so", + "libentrythree.so", + "libentryfour.so", + "har1", + // [EndExclute napi_load_module_with_info_entry_build3] + "@ohos/hypium" + // [End napi_load_module_with_info_entry_build3] + ] + } + }, + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..39c5cb8b47068d09b86ac03e5ed1f4dc6d348ac4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/oh-package.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + // [Start napi_load_module_with_info_entry_oh] + // [Start napi_load_module_with_info_entry_oh2] + // [Start napi_load_module_with_info_entry_oh3] + "dependencies": { + // [StartExclute napi_load_module_with_info_entry_oh] + // [StartExclute napi_load_module_with_info_entry_oh2] + "libentry.so": "file:./src/main/cpp/types/libentry", + // [Start napi_load_module_with_info_entry_oh3] + "libentryone.so": "file:./src/main/cpp/types/libentryone", + "libentrytwo.so": "file:./src/main/cpp/types/libentrytwo", + "libentrythree.so": "file:./src/main/cpp/types/libentrythree", + "libentryfour.so": "file:./src/main/cpp/types/libentryfour", + // [EndExclute napi_load_module_with_info_entry_oh] + "library": "file:../library", + // [End napi_load_module_with_info_entry_oh] + // [EndExclute napi_load_module_with_info_entry_oh2] + "@ohos/hypium": "1.0.16", + // [End napi_load_module_with_info_entry_oh2] + "har1": "file:../har1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b07592f9d00324552afd71baab1096bddee6c9e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,27 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeApiLoadModuleWithInfo) + +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) + +add_library(entryone SHARED har_name.cpp) +target_link_libraries(entryone PUBLIC libace_napi.z.so) + +add_library(entrytwo SHARED remote_har.cpp) +target_link_libraries(entrytwo PUBLIC libace_napi.z.so) + +add_library(entrythree SHARED api.cpp) +target_link_libraries(entrythree PUBLIC libace_napi.z.so) + +add_library(entryfour SHARED file.cpp) +target_link_libraries(entryfour PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/api.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/api.cpp old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/api.cpp rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/api.cpp index 25303449576fb8a6738a36652d74cde23cc5807d..756e39601eed35c4cc12ac0961842fa3ddc94d14 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/api.cpp +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/api.cpp @@ -1,66 +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. - */ - -#include -#include "napi/native_api.h" -// [Start napi_load_module_with_info_entry_api] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - // 1. 使用napi_load_module_with_info加载模块@ohos.hilog - napi_value result; - napi_status status = napi_load_module_with_info(env, "@ohos.hilog", nullptr, &result); - - // 2. 使用napi_get_named_property获取info函数 - napi_value infoFn; - napi_get_named_property(env, result, "info", &infoFn); - - napi_value tag; - std::string formatStr = "test"; - napi_create_string_utf8(env, formatStr.c_str(), formatStr.size(), &tag); - - napi_value outputString; - std::string str = "Hello OpenHarmony"; - napi_create_string_utf8(env, str.c_str(), str.size(), &outputString); - - napi_value flag; - napi_create_int32(env, 0, &flag); - - napi_value args[3] = {flag, tag, outputString}; - // 3. 使用napi_call_function调用info函数 - napi_call_function(env, result, infoFn, 3, args, nullptr); - return result; -} -// [End napi_load_module_with_info_entry_api] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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 = "entrythree", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +/* + * 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 +#include "napi/native_api.h" +// [Start napi_load_module_with_info_entry_api] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + // 1. 使用napi_load_module_with_info加载模块@ohos.hilog + napi_value result; + napi_status status = napi_load_module_with_info(env, "@ohos.hilog", nullptr, &result); + + // 2. 使用napi_get_named_property获取info函数 + napi_value infoFn; + napi_get_named_property(env, result, "info", &infoFn); + + napi_value tag; + std::string formatStr = "test"; + napi_create_string_utf8(env, formatStr.c_str(), formatStr.size(), &tag); + + napi_value outputString; + std::string str = "Hello OpenHarmony"; + napi_create_string_utf8(env, str.c_str(), str.size(), &outputString); + + napi_value flag; + napi_create_int32(env, 0, &flag); + + napi_value args[3] = {flag, tag, outputString}; + // 3. 使用napi_call_function调用info函数 + napi_call_function(env, result, infoFn, 3, args, nullptr); + return result; +} +// [End napi_load_module_with_info_entry_api] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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 = "entrythree", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/file.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/file.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5738fb4c5ff043a4616d31f33936e59925d3013f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/file.cpp @@ -0,0 +1,61 @@ +/* + * 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 +#include "napi/native_api.h" +// [Start napi_load_module_with_info_entry_file] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + napi_value result; + // 1. 使用napi_load_module_with_info加载Test文件中的模块 + napi_status status = + napi_load_module_with_info(env, "entry/src/main/ets/Test", "com.example.application/entry", &result); + + napi_value testFn; + // 2. 使用napi_get_named_property获取test函数 + napi_get_named_property(env, result, "test", &testFn); + // 3. 使用napi_call_function调用函数test + napi_call_function(env, result, testFn, 0, nullptr, nullptr); + + napi_value value; + napi_value key; + std::string keyStr = "value"; + napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); + // 4. 使用napi_get_property获取变量value + napi_get_property(env, result, key, &value); + return result; +} +// [End napi_load_module_with_info_entry_file] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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 = "entryfour", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/har_name.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/har_name.cpp old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/har_name.cpp rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/har_name.cpp index f89cf21d3e2da4fb7e5b20feae223d35dff3ad8d..422e4ccfe8823f97e53528573722a596e3ef27eb --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/har_name.cpp +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/har_name.cpp @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "napi/native_api.h" -// [Start napi_load_module_with_info_entry_har_name] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - napi_value result; - // 1. 使用napi_load_module_with_info加载library - napi_status status = napi_load_module_with_info(env, "library", "com.example.application/entry", &result); - - napi_value testFn; - // 2. 使用napi_get_named_property获取test函数 - napi_get_named_property(env, result, "test", &testFn); - // 3. 使用napi_call_function调用函数test - napi_call_function(env, result, testFn, 0, nullptr, nullptr); - - napi_value value; - napi_value key; - std::string keyStr = "value"; - napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); - // 4. 使用napi_get_property获取变量value - napi_get_property(env, result, key, &value); - return result; -} -// [End napi_load_module_with_info_entry_har_name] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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 = "entryone", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +/* + * 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 +#include "napi/native_api.h" +// [Start napi_load_module_with_info_entry_har_name] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + napi_value result; + // 1. 使用napi_load_module_with_info加载library + napi_status status = napi_load_module_with_info(env, "library", "com.example.application/entry", &result); + + napi_value testFn; + // 2. 使用napi_get_named_property获取test函数 + napi_get_named_property(env, result, "test", &testFn); + // 3. 使用napi_call_function调用函数test + napi_call_function(env, result, testFn, 0, nullptr, nullptr); + + napi_value value; + napi_value key; + std::string keyStr = "value"; + napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); + // 4. 使用napi_get_property获取变量value + napi_get_property(env, result, key, &value); + return result; +} +// [End napi_load_module_with_info_entry_har_name] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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 = "entryone", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b9981d7ae59b49a9e5cf33ff680ad183d438800 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "napi/native_api.h" +// [Start napi_load_module_with_info_entry_napi_init] +static constexpr int INT_ARG_2 = 2; // 入参索引 +static constexpr int INT_ARG_3 = 3; // 入参索引 + +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + napi_value result; + // 1. 使用napi_load_module_with_info加载libentry.so + napi_status status = napi_load_module_with_info(env, "libentry.so", "com.example.application/entry", &result); + + napi_value addFn; + // 2. 使用napi_get_named_property获取add函数 + napi_get_named_property(env, result, "add", &addFn); + + napi_value a; + napi_value b; + napi_create_int32(env, INT_ARG_2, &a); + napi_create_int32(env, INT_ARG_3, &b); + napi_value args[2] = {a, b}; + // 3. 使用napi_call_function调用函数add + napi_value returnValue; + napi_call_function(env, result, addFn, INT_ARG_2, args, &returnValue); + return result; +} +// [End napi_load_module_with_info_entry_napi_init] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/remote_har.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/remote_har.cpp old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/remote_har.cpp rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/remote_har.cpp index bd1fbfb30193248486ee2c20024f9b96eb250d66..80badfb2538d068ad239b7b545f11c84f2675eee --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/remote_har.cpp +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/remote_har.cpp @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "napi/native_api.h" -// [Start napi_load_module_with_info_entry_remote_har] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - napi_value result; - // 1. 使用napi_load_module_with_info加载@ohos/hypium - napi_status status = napi_load_module_with_info(env, "@ohos/hypium", "com.example.application/entry", &result); - - napi_value key; - std::string keyStr = "DEFAULT"; - napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); - // 2. 使用napi_get_property获取DEFAULT变量 - napi_value defaultValue; - napi_get_property(env, result, key, &defaultValue); - return result; -} -// [End napi_load_module_with_info_entry_remote_har] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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 = "entrytwo", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +/* + * 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 +#include "napi/native_api.h" +// [Start napi_load_module_with_info_entry_remote_har] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + napi_value result; + // 1. 使用napi_load_module_with_info加载@ohos/hypium + napi_status status = napi_load_module_with_info(env, "@ohos/hypium", "com.example.application/entry", &result); + + napi_value key; + std::string keyStr = "DEFAULT"; + napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); + // 2. 使用napi_get_property获取DEFAULT变量 + napi_value defaultValue; + napi_get_property(env, result, key, &defaultValue); + return result; +} +// [End napi_load_module_with_info_entry_remote_har] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"loadModule", nullptr, loadModule, 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 = "entrytwo", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4a1ffa1d0bfd258d1319753e279a03d66f358f31 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/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": "libentryfour.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..579c7f166e3135a2ba47e8e09014683714fb8ed4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/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": "libentryone.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..1a698bc1fbe0f52dfde79c8417a8651723a8f67b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/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": "libentrythree.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e289d9bde6bc129cd18f18ecfc30c280efa5fd6a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..414b54bb3222340829059c0a64879e9cb9e2fc8d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/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": "libentrytwo.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/Test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..546907f37cac2e5c0c3484733c0ce7cbf354b3d9 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/Test.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_load_module_with_info_entry_test] +let value = 123; + +function test() { + console.log('Hello OpenHarmony'); +} + +export { value, test }; +// [End napi_load_module_with_info_entry_test] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6ca2ad0cbcee6e875cf2c3970e52ffae70b6dac5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,73 @@ +/* + * 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 napiHar from 'libentryone.so'; +import napiRemoteHar from 'libentrytwo.so'; +import napiAPI from 'libentrythree.so'; +import napiFile from 'libentryfour.so' +import { tests } from 'har1'; + +@Entry +@Component +struct Index { + @State message: string = 'LoadModule'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bolder) + Button($r('app.string.loadModuleFile')) + .width('70%') + .onClick(() => { + napiFile.loadModule(); + this.message = 'loadModuleFile success'; + }) + Button($r('app.string.loadModuleHarName')) + .width('70%') + .onClick(() => { + napiHar.loadModule(); + this.message = 'loadModuleHarName success'; + }) + Button($r('app.string.loadModuleRemoteHar')) + .width('70%') + .onClick(() => { + napiRemoteHar.loadModule(); + this.message = 'loadModuleRemoteHar success'; + }) + Button($r('app.string.loadModuleAPI')) + .width('70%') + .onClick(() => { + napiAPI.loadModule(); + this.message = 'loadModuleAPI success'; + }) + Button($r('app.string.loadModuleNative')) + .width('70%') + .onClick(() => { + testNapi.loadModule(); + this.message = 'loadModuleNative success'; + }) + Button($r('app.string.loadModuleHarToHar')) + .width('70%') + .onClick(() => { + tests(); + this.message = 'loadModuleHarToHar success'; + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/NodeApiLoadModuleWithInfo.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/NodeApiLoadModuleWithInfo.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/NodeApiLoadModuleWithInfo.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/NodeApiLoadModuleWithInfo.test.ets index 5de842ae29e87ac7c00854224aa3911aa1783eb0..2b44cc7776d1464352f791e3a0f5c7807f93d4b3 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/NodeApiLoadModuleWithInfo.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/ets/test/NodeApiLoadModuleWithInfo.test.ets @@ -1,133 +1,133 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeApiLoadModuleWithInfoTest() { - describe('nodeApiLoadModuleWithInfoTest', () => { - - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,加载模块内文件路径 - */ - it('testNodeApiLoadModuleWithInfo001', 0, async () => { - console.info('uitest: testNodeApiLoadModuleWithInfo001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleFile')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleFile success')); - console.info('uitest: testNodeApiLoadModuleWithInfo001 end'); - }) - - /** - * 点击按钮,加载HAR模块名 - */ - it('testNodeApiLoadModuleWithInfo002', 0, async () => { - console.info('uitest: testNodeApiLoadModuleWithInfo002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleHarName')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleHarName success')); - console.info('uitest: testNodeApiLoadModuleWithInfo002 end'); - }) - - /** - * 点击按钮,加载远程HAR模块名 - */ - it('testNodeApiLoadModuleWithInfo003', 0, async () => { - console.info('uitest: testNodeApiLoadModuleWithInfo003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleRemoteHar')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleRemoteHar success')); - console.info('uitest: testNodeApiLoadModuleWithInfo003 end'); - }) - - /** - * 点击按钮,加载API模块 - */ - it('testNodeApiLoadModuleWithInfo004', 0, async () => { - console.info('uitest: testNodeApiLoadModuleWithInfo004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleAPI')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleAPI success')); - console.info('uitest: testNodeApiLoadModuleWithInfo004 end'); - }) - - /** - * 点击按钮,加载Native库 - */ - it('testNodeApiLoadModuleWithInfo005', 0, async () => { - console.info('uitest: testNodeApiLoadModuleWithInfo005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleNative')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleNative success')); - console.info('uitest: testNodeApiLoadModuleWithInfo005 end'); - }) - - /** - * 点击按钮,调用loadModuleHarToHar相关函数 - */ - it('testNodeApiLoadModuleWithInfo006', 0, async (done: Function) => { - console.info('uitest: testNodeApiLoadModuleWithInfo006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button = await driver.findComponent(ON.text('Call loadModuleHarToHar')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('loadModuleHarToHar success')); - console.info('uitest: testNodeApiLoadModuleWithInfo006 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeApiLoadModuleWithInfoTest() { + describe('nodeApiLoadModuleWithInfoTest', () => { + + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,加载模块内文件路径 + */ + it('testNodeApiLoadModuleWithInfo001', 0, async () => { + console.info('uitest: testNodeApiLoadModuleWithInfo001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleFile')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleFile success')); + console.info('uitest: testNodeApiLoadModuleWithInfo001 end'); + }) + + /** + * 点击按钮,加载HAR模块名 + */ + it('testNodeApiLoadModuleWithInfo002', 0, async () => { + console.info('uitest: testNodeApiLoadModuleWithInfo002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleHarName')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleHarName success')); + console.info('uitest: testNodeApiLoadModuleWithInfo002 end'); + }) + + /** + * 点击按钮,加载远程HAR模块名 + */ + it('testNodeApiLoadModuleWithInfo003', 0, async () => { + console.info('uitest: testNodeApiLoadModuleWithInfo003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleRemoteHar')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleRemoteHar success')); + console.info('uitest: testNodeApiLoadModuleWithInfo003 end'); + }) + + /** + * 点击按钮,加载API模块 + */ + it('testNodeApiLoadModuleWithInfo004', 0, async () => { + console.info('uitest: testNodeApiLoadModuleWithInfo004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleAPI')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleAPI success')); + console.info('uitest: testNodeApiLoadModuleWithInfo004 end'); + }) + + /** + * 点击按钮,加载Native库 + */ + it('testNodeApiLoadModuleWithInfo005', 0, async () => { + console.info('uitest: testNodeApiLoadModuleWithInfo005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleNative')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleNative success')); + console.info('uitest: testNodeApiLoadModuleWithInfo005 end'); + }) + + /** + * 点击按钮,调用loadModuleHarToHar相关函数 + */ + it('testNodeApiLoadModuleWithInfo006', 0, async (done: Function) => { + console.info('uitest: testNodeApiLoadModuleWithInfo006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button = await driver.findComponent(ON.text('Call loadModuleHarToHar')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('loadModuleHarToHar success')); + console.info('uitest: testNodeApiLoadModuleWithInfo006 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d546ed066c760397503aec02b7f11f07b650713 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/Index.ets @@ -0,0 +1,24 @@ +/* + * 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 'libhar1.so'; + +export { MainPage } from './src/main/ets/components/MainPage'; + +function tests() { + testNapi.loadModule(); +} + +export { tests }; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5eb0ae7fbd5768f0e40b3a253f97947551ef02d4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/build-profile.json5 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + // [Start napi_load_module_with_info_har1_build] + "buildOption": { + "arkOptions": { + "runtimeOnly": { + "packages": [ + "har2", + // [End napi_load_module_with_info_har1_build] + "libhar1.so" + ] + } + }, + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..71a986edbe8fa1e0e48f9a9a5f58ede225a02c6c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/oh-package.json5 @@ -0,0 +1,29 @@ +/* + * 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": "har1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + // [Start napi_load_module_with_info_har1_oh] + "dependencies": { + "har2": "file:../har2", + // [End napi_load_module_with_info_har1_oh] + "libhar1.so": "file:./src/main/cpp/types/libhar1" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6d0ae0000373f59e7da988c05f20cbfbc0b1b379 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/CMakeLists.txt @@ -0,0 +1,15 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeApiLoadModuleWithInfo) + +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(har1 SHARED napi_init.cpp) +target_link_libraries(har1 PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42b1317cde5c19d3711446a61a7d62c5a3e9f21b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/napi_init.cpp @@ -0,0 +1,85 @@ +/* + * 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 + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} +// [Start napi_load_module_with_info_har1_napi_init] +static napi_value loadModule(napi_env env, napi_callback_info info) +{ + napi_value result; + // 1. 使用napi_load_module_with_info加载har2,注意这里的moduleName为模块所在HAP包的moduleName + napi_status status = napi_load_module_with_info(env, "har2", "com.example.application/entry", &result); + + napi_value testFn; + // 2. 使用napi_get_named_property获取test函数 + napi_get_named_property(env, result, "test", &testFn); + // 3. 使用napi_call_function调用函数test + napi_call_function(env, result, testFn, 0, nullptr, nullptr); + + napi_value value; + napi_value key; + std::string keyStr = "value"; + napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); + // 4. 使用napi_get_property获取变量value + napi_get_property(env, result, key, &value); + return result; +} +// [End napi_load_module_with_info_har1_napi_init] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"loadModule", nullptr, loadModule, 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 = "har1", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterHar1Module(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6d71322a731b61bec50eb1002392c88297248e4e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_load_module_with_info_har1_dts] +export const add: (a: number, b: number) => number; +// [End napi_load_module_with_info_har1_dts] +export const loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a356d1c4b695457d77224e1bfc3d5f92b219a7f0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/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": "libhar1.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f14a04c4479dcbdaeb9acf3755d881845cd4e9e1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/module.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. + */ + +{ + "module": { + "name": "har1", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..acef8e5105641e7dee97640747d60fef35cb5d7a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/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": "har1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f732c3b8dbed8d09c0359565944a4f936106cc2 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/Index.ets @@ -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. + */ + +export { MainPage } from './src/main/ets/components/MainPage' +// [Start napi_load_module_with_info_har2_index] +let value = 123; + +function test() { + console.log('Hello OpenHarmony'); +} + +export { value, test }; +// [End napi_load_module_with_info_har2_index] diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefa5f6959f0e65b9347a5182401ee9f4873007a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/build-profile.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d778bf2ab9bd7e94eb867bb5796bfacb377800f7 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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": "har2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..cadd1c017107c2919c40339a5b4b0f3922db2a5d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/module.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. + */ + +{ + "module": { + "name": "har2", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..280914cdf065451f11e81d4611ad57a1589ff426 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/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": "har2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeApiUse/NodeAPIObject/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..35eea49ec65b1f1dc5e389af5d716a94aad5de35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/Index.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// [Start napi_load_module_with_info_library_index] +export { MainPage } from './src/main/ets/components/MainPage'; + +let value = 123; +function test() { + console.log('Hello OpenHarmony'); +} +export {value, test}; +// [End napi_load_module_with_info_library_index] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..aefa5f6959f0e65b9347a5182401ee9f4873007a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/build-profile.json5 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4a133b6457174dee797c57765bf21c5525232e9d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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": "library", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..7dc1a0d257a948cd6882b47f74253fdf1acaefcb --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/ets/components/MainPage.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3c26b263b06c3ad91afe531365411f41b4e3c56d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/module.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. + */ + +{ + "module": { + "name": "library", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..412ad2e266e2b80a018b05263a0e36a0a872d2fd --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/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": "library_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ca5e692c3d0a82dd52324b5275710d42213b6ed0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/ohosTest.md @@ -0,0 +1,13 @@ +# 使用Node-API接口进行模块加载测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ---------------------------------------- | ------------ | -------------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleFile的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleFile success | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleHarName的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleHarName success | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleRemoteHar的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleRemoteHar success | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleAPI的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleAPI success | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleNative的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleNative success | Pass | +| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleHarToHar的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleHarToHar success | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo1.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo2.png b/code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/screenshots/NodeApiLoadModuleWithInfo2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..468e2de0695b2446b87c2f119118231e9f1a0b95 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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.nodeapiarray", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..287d800ee71b6aaa5dfdf925aee740bba8780b17 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIArray" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/README.md new file mode 100644 index 0000000000000000000000000000000000000000..459d9f907012946a6a2ca9a7ffeee45b65a53780 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API接口进行array相关开发 + +### 介绍 + +使用Node-API接口进行array相关开发时,调用相关接口可以在Node-API模块中直接操作和处理ArkTS中的数组,使用Node-API接口进行数组(array)相关开发时,涉及的基本概念主要包括数组的创建、访问、修改、遍历以及与数组相关的操作。 + +该工程中展示了在Node-API模块中进行数组创建、获取数组长度、通过索引获得对应值等场景,其中代码详细描述可查如下链接。 + +- [使用Node-API接口进行array相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-array.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIArray.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API接口进行array相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIArray.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIArray/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3ff3d42ffad671f76bf15576067bcda8f47767e2 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPI_array) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e39963a3d05aa5a9fc8d708397b319ec818fc07 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,475 @@ +/* + * 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 +#include "napi/native_api.h" + +// [Start napi_create_array] +static constexpr int INT_NUMBER_5 = 5; // 入参索引 +static constexpr int INT_ARGS_2 = 2; // 入参索引 + +// 使用Node-API接口进行array相关开发 napi_create_array +static napi_value CreateArray(napi_env env, napi_callback_info info) +{ + // 创建一个空数组 + napi_value jsArray = nullptr; + napi_create_array(env, &jsArray); + // 将创建好的数组进行赋值 + for (int i = 0; i < INT_NUMBER_5; i++) { + napi_value element; + napi_create_int32(env, i, &element); + napi_set_element(env, jsArray, i, element); + } + // 返回已创建好的数组 + return jsArray; +} +// [End napi_create_array] + +// [Start napi_create_array_with_length] +// 使用Node-API接口进行array相关开发 napi_create_array_with_length +static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_value jsArray = nullptr; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 获取传递的数组长度 + int32_t length = 0; + napi_get_value_int32(env, argv[0], &length); + // 使用napi_create_array_with_length创建指定长度的数组 + napi_create_array_with_length(env, length, &jsArray); + // 返回数组 + return jsArray; +} +// [End napi_create_array_with_length] + +// [Start napi_get_array_length] +// 使用Node-API接口进行array相关开发 napi_get_array_length +static napi_value GetArrayLength(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_value result; + uint32_t length; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 检查参数是否为数组 + bool isArray; + napi_is_array(env, args[0], &isArray); + if (!isArray) { + napi_throw_type_error(env, nullptr, "Argument must be an array"); + return nullptr; + } + napi_get_array_length(env, args[0], &length); + // 创建返回值 + napi_create_uint32(env, length, &result); + return result; +} +// [End napi_get_array_length] + +// [Start napi_is_array] +// 使用Node-API接口进行array相关开发 napi_is_array +static napi_value IsArray(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 调用napi_is_array接口判断给定入参是否为array数组 + bool result; + napi_status status = napi_is_array(env, args[0], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_is_array fail"); + return nullptr; + } + // 将结果转成napi_value类型返回 + napi_value returnValue; + napi_get_boolean(env, result, &returnValue); + + return returnValue; +} +// [End napi_is_array] + +// [Start napi_set_element] +// 使用Node-API接口进行array相关开发 napi_set_element +static napi_value NapiSetElement(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 3; + napi_value args[3] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 检查第一个参数是否为数组 + bool isArr = false; + napi_is_array(env, args[0], &isArr); + if (!isArr) { + napi_throw_type_error(env, nullptr, "Argument should be an object of type array"); + return nullptr; + } + // 获取要设置的元素索引 + double index = 0; + napi_get_value_double(env, args[1], &index); + // 将传入的值设置到数组指定索引位置 + napi_set_element(env, args[0], static_cast(index), args[INT_ARGS_2]); + + return nullptr; +} +// [End napi_set_element] + +// [Start napi_get_element] +// 使用Node-API接口进行array相关开发 napi_get_element +static napi_value NapiGetElement(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取请求元素的索引值 + uint32_t index; + napi_get_value_uint32(env, args[1], &index); + // 获取请求索引位置的元素值并存储在result中 + napi_value result; + napi_get_element(env, args[0], index, &result); + + return result; +} +// [End napi_get_element] + +// [Start napi_has_element] +// 使用Node-API接口进行array相关开发 napi_has_element +static napi_value NapiHasElement(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取要判断的元素的索引 + uint32_t index; + napi_get_value_uint32(env, args[1], &index); + // 判断指定索引位置的元素是否存在 + bool hasElement = true; + napi_has_element(env, args[0], index, &hasElement); + // 将bool结果转换为napi_value并返回 + napi_value result; + napi_get_boolean(env, hasElement, &result); + return result; +} +// [End napi_has_element] + +// [Start napi_delete_element] +// 使用Node-API接口进行array相关开发 napi_delete_element +static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取要删除的元素的索引 + uint32_t index; + napi_get_value_uint32(env, args[1], &index); + // 尝试删除请求索引位置的元素 + bool deleted = true; + napi_delete_element(env, args[0], index, &deleted); + // 将bool结果转换为napi_value并返回 + napi_value result; + napi_get_boolean(env, deleted, &result); + return result; +} +// [End napi_delete_element] + +// [Start napi_create_typed_array] +// 使用Node-API接口进行array相关开发 napi_create_typedarray +static napi_value CreateTypedArray(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + int32_t typeNum = 0; + napi_get_value_int32(env, args[0], &typeNum); + napi_typedarray_type arrayType; + // 用于存储每个元素的大小 + size_t elementSize = 0; + // 根据传递的类型值选择创建对应的类型数组 + arrayType = static_cast(typeNum); + switch (typeNum) { + case napi_int8_array: + case napi_uint8_array: + case napi_uint8_clamped_array: + elementSize = sizeof(int8_t); + break; + case napi_int16_array: + case napi_uint16_array: + elementSize = sizeof(int16_t); + break; + case napi_int32_array: + case napi_uint32_array: + elementSize = sizeof(int32_t); + break; + case napi_float32_array: + elementSize = sizeof(float); + break; + case napi_float64_array: + elementSize = sizeof(double); + break; + case napi_bigint64_array: + case napi_biguint64_array: + elementSize = sizeof(int64_t); + break; + default: + // 默认创建napi_int8_array类型 + arrayType = napi_int8_array; + elementSize = sizeof(int8_t); + break; + } + size_t length = 3; + napi_value arrayBuffer = nullptr; + napi_value typedArray = nullptr; + void *data; + // 创建一个ArrayBuffer + napi_create_arraybuffer(env, length * elementSize, (void **)&data, &arrayBuffer); + // 根据给定类型创建TypedArray + napi_create_typedarray(env, arrayType, length, arrayBuffer, 0, &typedArray); + return typedArray; +} +// [End napi_create_typed_array] + +// [Start napi_is_typed_array] +// 使用Node-API接口进行array相关开发 napi_is_typedarray +static napi_value IsTypedarray(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 调用napi_is_typedarray接口判断给定入参类型是否为TypedArray。 + bool result = false; + napi_status status = napi_is_typedarray(env, args[0], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_is_typedarray fail"); + return nullptr; + } + // 将结果转成napi_value类型返回。 + napi_value returnValue = nullptr; + napi_get_boolean(env, result, &returnValue); + + return returnValue; +} +// [End napi_is_typed_array] + +// [Start napi_get_typed_array_info] +// 使用Node-API接口进行array相关开发 napi_get_typedarray_info +static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数,第一个参数为需要获得的信息的TypedArray类型数据,第二个参数为需要获得的信息类型的枚举值 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将第二个参数转为int32类型便于比较 + int32_t infoTypeParam; + napi_get_value_int32(env, args[1], &infoTypeParam); + // 定义枚举类型与ArkTS侧枚举类型InfoType顺序含义一致 + enum InfoType { INFO_TYPE = 1, INFO_LENGTH, INFO_ARRAY_BUFFER, INFO_BYTE_OFFSET }; + void *data; + napi_typedarray_type type; + size_t byteOffset; + size_t length; + napi_value arraybuffer; + // 调用接口napi_get_typedarray_info获得TypedArray类型数据的信息 + napi_get_typedarray_info(env, args[0], &type, &length, &data, &arraybuffer, &byteOffset); + napi_value result; + // 根据属性名,返回TypedArray对应的属性值 + switch (infoTypeParam) { + case INFO_TYPE: + // 如果传入的参数是int8类型的TypedArray数据,它的类型(type)为napi_int8_array + napi_value int8_type; + napi_get_boolean(env, type == napi_int8_array, &int8_type); + result = int8_type; + break; + case INFO_LENGTH: + // TypedArray中的元素数 + napi_value napiLength; + napi_create_int32(env, length, &napiLength); + result = napiLength; + break; + case INFO_BYTE_OFFSET: + // TypedArray数组的第一个元素所在的基础原生数组中的字节偏移量 + napi_value napiByteOffset; + napi_create_int32(env, byteOffset, &napiByteOffset); + result = napiByteOffset; + break; + case INFO_ARRAY_BUFFER: + // TypedArray下的ArrayBuffer + result = arraybuffer; + break; + default: + break; + } + return result; +} +// [End napi_get_typed_array_info] + +// [Start napi_create_data_view] +// 使用Node-API接口进行array相关开发 napi_create_dataview +static napi_value CreateDataView(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_value arraybuffer = nullptr; + napi_value result = nullptr; + // DataView的字节长度 + size_t byteLength = 12; + // 字节偏移量 + size_t byteOffset = 4; + // 获取回调函数的参数信息 + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将参数转换为对象类型 + napi_coerce_to_object(env, args[0], &arraybuffer); + // 创建一个数据视图对象,并指定字节长度和字节偏移量 + napi_status status = napi_create_dataview(env, byteLength, arraybuffer, byteOffset, &result); + if (status != napi_ok) { + // 抛出创建DataView内容失败的错误 + napi_throw_error(env, nullptr, "Failed to create DataView"); + return nullptr; + } + // 获取DataView的指针和长度信息 + uint8_t *data = nullptr; + size_t length = 0; + napi_get_dataview_info(env, result, &length, (void **)&data, nullptr, nullptr); + // 为DataView赋值 + for (size_t i = 0; i < length; i++) { + data[i] = static_cast(i + 1); + } + return result; +} +// [End napi_create_data_view] + +// [Start napi_is_data_view] +// 使用Node-API接口进行array相关开发 napi_is_dataview +static napi_value IsDataView(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 调用napi_is_dataview接口判断给定入参是否为DataView数据。 + bool result; + napi_status status = napi_is_dataview(env, args[0], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_is_dataview fail"); + return nullptr; + } + // 将结果转成napi_value类型返回。 + napi_value returnValue; + napi_get_boolean(env, result, &returnValue); + + return returnValue; +} +// [End napi_is_data_view] + +// [Start napi_get_data_view_info] +// 使用Node-API接口进行array相关开发 napi_get_dataview_info +static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传入的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将第二个参数转为int32类型的数字 + int32_t infoType; + napi_get_value_int32(env, args[1], &infoType); + size_t byteLength; + void *data; + napi_value arrayBuffer; + size_t byteOffset; + // 定义枚举类型与ArkTS侧枚举类型InfoType顺序含义一致 + enum InfoType { BYTE_LENGTH = 0, ARRAY_BUFFER, BYTE_OFFSET }; + // 获取dataview信息 + napi_get_dataview_info(env, args[0], &byteLength, &data, &arrayBuffer, &byteOffset); + napi_value result; + switch (infoType) { + case BYTE_LENGTH: + // 返回查询DataView的字节数 + napi_value napiByteLength; + napi_create_int32(env, byteLength, &napiByteLength); + result = napiByteLength; + break; + case ARRAY_BUFFER: + // 返回查询DataView的arraybuffer + result = arrayBuffer; + break; + case BYTE_OFFSET: + // 返回查询DataView的偏移字节量 + napi_value napiByteOffset; + napi_create_int32(env, byteOffset, &napiByteOffset); + result = napiByteOffset; + break; + default: + break; + } + return result; +} +// [End napi_get_data_view_info] + +// [Start change_use_napi_process] +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_value typedArrayTypes; + napi_create_object(env, &typedArrayTypes); + napi_value typeIndex; + std::string typeKeys[] = { + "INT8_ARRAY", "UINT8_ARRAY", "UINT8_CLAMPED_ARRAY", "INT16_ARRAY", "UINT16_ARRAY", "INT32_ARRAY", + "UINT32_ARRAY", "FLOAT32_ARRAY", "FLOAT64_ARRAY", "BIGINT64_ARRAY", "BIGUINT64_ARRAY", + }; + for (int32_t i = 0; i < sizeof(typeKeys) / sizeof(typeKeys[0]); i++) { + napi_create_int32(env, i, &typeIndex); + napi_set_named_property(env, typedArrayTypes, typeKeys[i].c_str(), typeIndex); + } + napi_property_descriptor desc[] = { + {"createArray", nullptr, CreateArray, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createArrayWithLength", nullptr, CreateArrayWithLength, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getArrayLength", nullptr, GetArrayLength, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"isArray", nullptr, IsArray, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiSetElement", nullptr, NapiSetElement, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiGetElement", nullptr, NapiGetElement, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiHasElement", nullptr, NapiHasElement, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiDeleteElement", nullptr, NapiDeleteElement, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createTypedArray", nullptr, CreateTypedArray, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"TypedArrayTypes", nullptr, nullptr, nullptr, nullptr, typedArrayTypes, napi_default, nullptr}, + {"isTypedarray", nullptr, IsTypedarray, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getTypedarrayInfo", nullptr, GetTypedarrayInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createDataView", nullptr, CreateDataView, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"isDataView", nullptr, IsDataView, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getDataViewInfo", nullptr, GetDataViewInfo, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END +// [End change_use_napi_process] + +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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..68e3ae88c293d8134e311460824d582d5195b2cc --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_create_array_api] +export const createArray: () => number[]; // 使用Node-API接口进行array相关开发 napi_create_array +// [End napi_create_array_api] + +// [Start napi_create_array_with_length_api] +export const createArrayWithLength: (length: number) => void[]; // 使用Node-API接口进行array相关开发 napi_create_array_with_length +// [End napi_create_array_with_length_api] + +// [Start napi_get_array_length_api] +export const getArrayLength: (arr: Array) => number | void; // 使用Node-API接口进行array相关开发 napi_get_array_length +// [End napi_get_array_length_api] + +// [Start napi_is_array_api] +export const isArray: (data: Array | T) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_array +// [End napi_is_array_api] + +// [Start napi_set_element_api] +export const napiSetElement: (arr: Array, index: number, + value: T) => void; // 使用Node-API接口进行array相关开发 napi_set_element +// [End napi_set_element_api] + +// [Start napi_get_element_api] +export const napiGetElement: (arr: Array, + index: number) => number | string | Object | boolean | undefined; // 使用Node-API接口进行array相关开发 napi_get_element +// [End napi_get_element_api] + +// [Start napi_has_element_api] +export const napiHasElement: (arr: Array, index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_has_element +// [End napi_has_element_api] + +// [Start napi_delete_element_api] +export const napiDeleteElement: (arr: Array, + index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_delete_element +// [End napi_delete_element_api] + +// [Start napi_create_typed_array_api] +export const enum TypedArrayTypes { + INT8_ARRAY = 0, + UINT8_ARRAY, + UINT8_CLAMPED_ARRAY, + INT16_ARRAY, + UINT16_ARRAY, + INT32_ARRAY, + UINT32_ARRAY, + FLOAT32_ARRAY, + FLOAT64_ARRAY, + BIGINT64_ARRAY, + BIGuINT64_ARRAY, +} + +export const createTypedArray: (type: TypedArrayTypes) => T; // 使用Node-API接口进行array相关开发 napi_create_typedarray +// [End napi_create_typed_array_api] + +// [Start napi_is_typed_array_api] +export const isTypedarray: (data: Object) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_typedarray +// [End napi_is_typed_array_api] + +// [Start napi_get_typed_array_info_api] +export const getTypedarrayInfo: (typeArray: T, + infoType: number) => ArrayBuffer | number | boolean; // 使用Node-API接口进行array相关开发 napi_get_typedarray_info +// [End napi_get_typed_array_info_api] + +// [Start napi_create_data_view_api] +export const createDataView: (arraybuffer: ArrayBuffer) => DataView | void; // 使用Node-API接口进行array相关开发 napi_create_dataview +// [End napi_create_data_view_api] + +// [Start napi_is_data_view_api] +export const isDataView: (date: DataView | string) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_dataview +// [End napi_is_data_view_api] + +// [Start napi_get_data_view_info_api] +export const getDataViewInfo: (dataView: DataView, + infoType: number) => ArrayBuffer | number; // 使用Node-API接口进行array相关开发 napi_get_dataview_info +// [End napi_get_data_view_info_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..36cf2e6c68429a72355ae135c9b2f42ce3c02ddd --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,310 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiCreateArray', + '2.napiCreateArrayWithLength', + '3.napiGetArrayLength', + '4.napiIsArray', + '5.napiSetElement', + '6.napiGetElement', + '7.napiHasElement', + '8.napiDeleteElement', + '9.napiCreateTypedArray', + '10.napiIsTypedArray', + '11.napiGetTypedArrayInfo', + '12.napiCreateDataView', + '13.napiIsDataView', + '14.napiGetDataViewInfo' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(23) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 4 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiCreateArray') { + // [Start ark_napi_create_array] + //使用Node-API接口进行array相关开发 napi_create_array + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array:%{public}s', + JSON.stringify(testNapi.createArray())); + // [End ark_napi_create_array] + this.result = 'napiCreateArraySuccess'; + } else if (item === '2.napiCreateArrayWithLength') { + // [Start ark_napi_create_array_with_length] + // 使用Node-API接口进行array相关开发 napi_create_array_with_length + let array = testNapi.createArrayWithLength(6); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array_with_length:%{public}d', array.length); + // [End ark_napi_create_array_with_length] + this.result = 'napiCreateArrayWithLengthSuccess'; + } else if (item === '3.napiGetArrayLength') { + // [Start ark_napi_get_array_length] + // 使用Node-API接口进行array相关开发 napi_get_array_length + const arr = [0, 1, 2, 3, 4, 5]; + hilog.info(0x0000, 'testTag', 'Test Node-API get_array_length:%{public}d', + testNapi.getArrayLength(arr)); + // [End ark_napi_get_array_length] + this.result = 'napiGetArrayLengthSuccess'; + } else if (item === '4.napiIsArray') { + // [Start ark_napi_is_array] + // 使用Node-API接口进行array相关开发 napi_is_array + try { + let value = new Array(1); + let data = "123"; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_array: %{public}s', + testNapi.isArray(value)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_array: %{public}s', + testNapi.isArray(data)); + // [StartExclude ark_napi_is_array] + this.result = 'napiIsArraySuccess'; + // [EndExclude ark_napi_is_array] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_array error: %{public}s', error.message); + // [StartExclude ark_napi_is_array] + this.result = 'napiIsArrayFail'; + // [EndExclude ark_napi_is_array] + } + // [End ark_napi_is_array] + } else if (item === '5.napiSetElement') { + // [Start ark_napi_set_element] + // 使用Node-API接口进行array相关开发 napi_set_element + let arr = [10, 20, 30]; + testNapi.napiSetElement(arr, 1, 'newElement'); + testNapi.napiSetElement(arr, 2, 50); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr: %{public}s', arr.toString()); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[3]: %{public}s', arr[3]); + + interface MyObject { + first: number; + second: number; + } + + let obj: MyObject = { + first: 1, + second: 2 + }; + testNapi.napiSetElement(arr, 4, obj); + let objAsString = JSON.stringify(arr[4]); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[4]: %{public}s', objAsString); + // [End ark_napi_set_element] + this.result = 'napiSetElementSuccess'; + } else if (item === '6.napiGetElement') { + // [Start ark_napi_get_element] + // 使用Node-API接口进行array相关开发 napi_get_element + interface MyObject { + first: number; + second: number; + } + + let obj: MyObject = { + first: 1, + second: 2 + }; + let arr = [10, 'hello', null, obj]; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', + testNapi.napiGetElement(arr, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[1]: %{public}s', + testNapi.napiGetElement(arr, 1)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[2]: %{public}s', + testNapi.napiGetElement(arr, 2)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[3]: %{public}s', + testNapi.napiGetElement(arr, 3)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[4]: %{public}s', + JSON.stringify(testNapi.napiGetElement(arr, 4))); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[null]: %{public}s', + testNapi.napiGetElement(arr, 5)); + // [End ark_napi_get_element] + this.result = 'napiGetElementSuccess'; + } else if (item === '7.napiHasElement') { + // [Start ark_napi_has_element] + // 使用Node-API接口进行array相关开发 napi_has_element + let arr = [10, 'hello', null, 'world']; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', + testNapi.napiHasElement(arr, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[7]: %{public}s', + testNapi.napiHasElement(arr, 7)); + // [End ark_napi_has_element] + this.result = 'napiHasElementSuccess'; + } else if (item === '8.napiDeleteElement') { + // [Start ark_napi_delete_element] + // 使用Node-API接口进行array相关开发 napi_delete_element + let arr = [10, 'hello', null, 'world']; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', + testNapi.napiHasElement(arr, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_element arr[0]: %{public}s', + testNapi.napiDeleteElement(arr, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element deleted arr[0]: %{public}s', + testNapi.napiHasElement(arr, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', + testNapi.napiGetElement(arr, 0)); + // [End ark_napi_delete_element] + this.result = 'napiDeleteElementSuccess'; + } else if (item === '9.napiCreateTypedArray') { + // [Start ark_napi_create_typed_array] + // 使用Node-API接口进行array相关开发 napi_create_typedarray + let typedArray = testNapi.createTypedArray(testNapi.TypedArrayTypes["INT8_ARRAY"]); + if (typedArray instanceof Int8Array) { + hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Int8Array'); + // [StartExclude ark_napi_create_typed_array] + this.result = 'napiCreateInt8ArraySuccess'; + // [EndExclude ark_napi_create_typed_array] + } + let uint8Array = testNapi.createTypedArray(testNapi.TypedArrayTypes["UINT8_ARRAY"]); + if (uint8Array instanceof Uint8Array) { + hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Uint8Array'); + // [StartExclude ark_napi_create_typed_array] + this.result = 'napiCreateUint8ArraySuccess'; + // [EndExclude ark_napi_create_typed_array] + } + // [End ark_napi_create_typed_array] + } else if (item === '10.napiIsTypedArray') { + // [Start ark_napi_is_typed_array] + // 使用Node-API接口进行array相关开发 napi_is_typedarray + try { + let value = new Uint8Array([1, 2, 3, 4]); + let data = "123"; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_typedarray: %{public}s', + testNapi.isTypedarray(value)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_typedarray: %{public}s', + testNapi.isTypedarray(data)); + // [StartExclude ark_napi_is_typed_array] + this.result = 'napiIsTypedArraySuccess'; + // [EndExclude ark_napi_is_typed_array] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_typedarray error: %{public}s', error.message); + // [StartExclude ark_napi_is_typed_array] + this.result = 'napiIsTypedArrayFail'; + // [EndExclude ark_napi_is_typed_array] + } + // [End ark_napi_is_typed_array] + } else if (item === '11.napiGetTypedArrayInfo') { + // [Start ark_napi_get_typed_array_info] + // 使用Node-API接口进行array相关开发 napi_get_typedarray_info + // 传入TypedArray类型数据。TypedArray是一种用来描述二进制数据的类数组数据视图,没有直接构造器,可以用其子类构造类数组 + // TypedArray的子类有: Int8Array Uint8Array Uint8ClampedArray Int16Array Int32Array等 + let int8Array = new Int8Array([15, 7]); + // 定义枚举类型 这些都是TypedArray的属性 + enum InfoType { + TYPE = 1, // 传入的TypedArray的类型 + LENGTH = 2, // 传入的TypedArray的长度 + ARRAY_BUFFER = 3, // TypedArray下的ArrayBuffer + BYTE_OFFSET = 4 // 数组的第一个元素所在的基础原生数组中的字节偏移量 + }; + let arrbuff = testNapi.getTypedarrayInfo(int8Array, InfoType.ARRAY_BUFFER) as ArrayBuffer; + // 将arraybuffer转为数组 + let arr = new Array(new Int8Array(arrbuff)); + hilog.info(0x0000, 'Node-API', 'get_typedarray_info_arraybuffer: %{public}s', arr.toString()); + hilog.info(0x0000, 'Node-API', 'get_typedarray_info_isIn8Array: %{public}s', + testNapi.getTypedarrayInfo(int8Array, InfoType.TYPE).toString()); + hilog.info(0x0000, 'Node-API', 'get_typedarray_info_length: %{public}d', + testNapi.getTypedarrayInfo(int8Array, InfoType.LENGTH)); + hilog.info(0x0000, 'Node-API', 'get_typedarray_info_byte_offset: %{public}d', + testNapi.getTypedarrayInfo(int8Array, InfoType.BYTE_OFFSET)); + // [End ark_napi_get_typed_array_info] + this.result = 'napiGetTypedArrayInfoSuccess'; + } else if (item === '12.napiCreateDataView') { + // [Start ark_napi_create_data_view] + // 使用Node-API接口进行array相关开发 napi_create_dataview + const arrayBuffer = new ArrayBuffer(16); + const dataView = testNapi.createDataView(arrayBuffer) as DataView; + hilog.info(0x0000, 'testTag', 'Test Node-API dataView:%{public}d', dataView.byteLength); + hilog.info(0x0000, 'testTag', 'Test Node-API dataView第一个数据:%{public}d', dataView.getInt8(0)); + // [End ark_napi_create_data_view] + this.result = 'napiCreateDataViewSuccess'; + } else if (item === '13.napiIsDataView') { + // [Start ark_napi_is_data_view] + // 使用Node-API接口进行array相关开发 napi_is_dataview + try { + let buffer = new ArrayBuffer(16); + let dataView = new DataView(buffer); + let data = "123"; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_dataview: %{public}s', + testNapi.isDataView(dataView)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_dataview: %{public}s', + testNapi.isDataView(data)); + // [StartExclude ark_napi_is_data_view] + this.result = 'napiIsDataViewSuccess'; + // [EndExclude ark_napi_is_data_view] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_dataview error: %{public}s', error.message); + // [StartExclude ark_napi_is_data_view] + this.result = 'napiIsDataViewFail'; + // [EndExclude ark_napi_is_data_view] + } + // [End ark_napi_is_data_view] + } else if (item === '14.napiGetDataViewInfo') { + // [Start ark_napi_get_data_view_info] + // 使用Node-API接口进行array相关开发 napi_get_dataview_info + // 创建一个ArrayBuffer + let arrayBuffer = new Int8Array([2, 5]).buffer; + // 使用arrayBuffer创建一个dataView + let dataView = new DataView(arrayBuffer); + // 定义一个枚举类型 + enum InfoType { + BYTE_LENGTH = 0, + ARRAY_BUFFER = 1, + BYTE_OFFSET = 2, + }; + // 传入DataView类型参数查询DataView的字节数 + hilog.info(0x0000, 'Node-API', 'get_dataview_info_bytelength %{public}d', + testNapi.getDataViewInfo(dataView, InfoType.BYTE_LENGTH)); + // 传入DataView类型参数查询DataView的ArrayBuffer + let arrbuff = testNapi.getDataViewInfo(dataView, InfoType.ARRAY_BUFFER) as ArrayBuffer; + // 将arraybuffer转为数组 + let arr = Array.from(new Int8Array(arrbuff)); + hilog.info(0x0000, 'Node-API', 'get_dataview_info_arraybuffer %{public}s', arr.toString()); + // 传入DataView类型参数查询DataView开始投影的数据缓冲区中的字节偏移量 + hilog.info(0x0000, 'Node-API', 'get_dataview_info_byteoffset %{public}d', + testNapi.getDataViewInfo(dataView, InfoType.BYTE_OFFSET)); + // [End ark_napi_get_data_view_info] + this.result = 'napiGetDataViewInfoSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + .id('List') + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} + diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/NodeAPIArray.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/NodeAPIArray.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/NodeAPIArray.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/NodeAPIArray.test.ets index dd42061a0827cbc82123d705d1b6ba393925f6e8..86db0eafed5612cae04012e69fd164a53ae73cc3 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/NodeAPIArray.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/ets/test/NodeAPIArray.test.ets @@ -1,270 +1,270 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIArrayTest() { - describe('nodeAPIArrayTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiCreateArray相关函数 - */ - it('testNodeAPIArray001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiCreateArray')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateArraySuccess')); - console.info('uitest: testNodeAPIArray001 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateArrayWithLength相关函数 - */ - it('testNodeAPIArray002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCreateArrayWithLength')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateArrayWithLengthSuccess')); - console.info('uitest: testNodeAPIArray002 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetArrayLength相关函数 - */ - it('testNodeAPIArray003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiGetArrayLength')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetArrayLengthSuccess')); - console.info('uitest: testNodeAPIArray003 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsArray相关函数 - */ - it('testNodeAPIArray004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiIsArray')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsArraySuccess')); - console.info('uitest: testNodeAPIArray004 end'); - done(); - }) - - /** - * 点击按钮,调用napiSetElement相关函数 - */ - it('testNodeAPIArray005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiSetElement')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiSetElementSuccess')); - console.info('uitest: testNodeAPIArray005 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetElement相关函数 - */ - it('testNodeAPIArray006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiGetElement')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetElementSuccess')); - console.info('uitest: testNodeAPIArray006 end'); - done(); - }) - - /** - * 点击按钮,调用napiHasElement相关函数 - */ - it('testNodeAPIArray007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiHasElement')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiHasElementSuccess')); - console.info('uitest: testNodeAPIArray007 end'); - done(); - }) - - /** - * 点击按钮,调用napiDeleteElement相关函数 - */ - it('testNodeAPIArray008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiDeleteElement')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiDeleteElementSuccess')); - console.info('uitest: testNodeAPIArray008 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateTypedArray相关函数 - */ - it('testNodeAPIArray009', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray009 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('9.napiCreateTypedArray')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateUint8ArraySuccess')); - console.info('uitest: testNodeAPIArray009 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsTypedArray相关函数 - */ - it('testNodeAPIArray010', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray010 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const list = await driver.findComponent(ON.id('List')) - await list.scrollToBottom(); - const text = await driver.findComponent(ON.text('10.napiIsTypedArray')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsTypedArraySuccess')); - console.info('uitest: testNodeAPIArray010 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetTypedArrayInfo相关函数 - */ - it('testNodeAPIArray011', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray011 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('11.napiGetTypedArrayInfo')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetTypedArrayInfoSuccess')); - console.info('uitest: testNodeAPIArray011 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateDataView相关函数 - */ - it('testNodeAPIArray012', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray012 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('12.napiCreateDataView')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateDataViewSuccess')); - console.info('uitest: testNodeAPIArray012 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsDataView相关函数 - */ - it('testNodeAPIArray013', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray013 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('13.napiIsDataView')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsDataViewSuccess')); - console.info('uitest: testNodeAPIArray013 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetDataViewInfo相关函数 - */ - it('testNodeAPIArray014', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray014 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('14.napiGetDataViewInfo')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetDataViewInfoSuccess')); - console.info('uitest: testNodeAPIArray014 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIArrayTest() { + describe('nodeAPIArrayTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiCreateArray相关函数 + */ + it('testNodeAPIArray001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiCreateArray')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateArraySuccess')); + console.info('uitest: testNodeAPIArray001 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateArrayWithLength相关函数 + */ + it('testNodeAPIArray002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCreateArrayWithLength')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateArrayWithLengthSuccess')); + console.info('uitest: testNodeAPIArray002 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetArrayLength相关函数 + */ + it('testNodeAPIArray003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiGetArrayLength')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetArrayLengthSuccess')); + console.info('uitest: testNodeAPIArray003 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsArray相关函数 + */ + it('testNodeAPIArray004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiIsArray')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsArraySuccess')); + console.info('uitest: testNodeAPIArray004 end'); + done(); + }) + + /** + * 点击按钮,调用napiSetElement相关函数 + */ + it('testNodeAPIArray005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiSetElement')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiSetElementSuccess')); + console.info('uitest: testNodeAPIArray005 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetElement相关函数 + */ + it('testNodeAPIArray006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiGetElement')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetElementSuccess')); + console.info('uitest: testNodeAPIArray006 end'); + done(); + }) + + /** + * 点击按钮,调用napiHasElement相关函数 + */ + it('testNodeAPIArray007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiHasElement')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiHasElementSuccess')); + console.info('uitest: testNodeAPIArray007 end'); + done(); + }) + + /** + * 点击按钮,调用napiDeleteElement相关函数 + */ + it('testNodeAPIArray008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiDeleteElement')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiDeleteElementSuccess')); + console.info('uitest: testNodeAPIArray008 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateTypedArray相关函数 + */ + it('testNodeAPIArray009', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray009 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('9.napiCreateTypedArray')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateUint8ArraySuccess')); + console.info('uitest: testNodeAPIArray009 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsTypedArray相关函数 + */ + it('testNodeAPIArray010', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray010 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const list = await driver.findComponent(ON.id('List')) + await list.scrollToBottom(); + const text = await driver.findComponent(ON.text('10.napiIsTypedArray')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsTypedArraySuccess')); + console.info('uitest: testNodeAPIArray010 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetTypedArrayInfo相关函数 + */ + it('testNodeAPIArray011', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray011 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('11.napiGetTypedArrayInfo')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetTypedArrayInfoSuccess')); + console.info('uitest: testNodeAPIArray011 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateDataView相关函数 + */ + it('testNodeAPIArray012', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray012 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('12.napiCreateDataView')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateDataViewSuccess')); + console.info('uitest: testNodeAPIArray012 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsDataView相关函数 + */ + it('testNodeAPIArray013', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray013 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('13.napiIsDataView')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsDataViewSuccess')); + console.info('uitest: testNodeAPIArray013 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetDataViewInfo相关函数 + */ + it('testNodeAPIArray014', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray014 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('14.napiGetDataViewInfo')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetDataViewInfoSuccess')); + console.info('uitest: testNodeAPIArray014 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/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/NodeAPI/NodeApiUse/NodeAPIArray/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..427fd83742dcfc21df8c7ac8df2a7e221a042646 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/ohosTest.md @@ -0,0 +1,21 @@ +# 使用Node-API进行array相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------ | ------------ | ----------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 createArray | 位于主页 | 点击文本为1.napiCreateArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateArraySuccess | Pass | +| ArkTS端成功调用native侧接口createArrayWithLength | 位于主页 | 点击文本为2.napiCreateArrayWithLength的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateArrayWithLengthSuccess | Pass | +| ArkTS端成功调用native侧接口getArrayLength | 位于主页 | 点击文本为3.napiGetArrayLength的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetArrayLengthSuccess | Pass | +| ArkTS端成功调用native侧接口isArray | 位于主页 | 点击文本为4.napiIsArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsArraySuccess | Pass | +| ArkTS端成功调用native侧接口napiSetElement | 位于主页 | 点击文本为5.napiSetElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetElementSuccess | Pass | +| ArkTS端成功调用native侧接口napiGetElement | 位于主页 | 点击文本为6.napiGetElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetElementSuccess | Pass | +| ArkTS端成功调用native侧接口napiHasElement | 位于主页 | 点击文本为7.napiHasElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasElementSuccess | Pass | +| ArkTS端成功调用native侧接口napiDeleteElement | 位于主页 | 点击文本为8.napiDeleteElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDeleteElementSuccess | Pass | +| ArkTS端成功调用native侧接口createTypedArray | 位于主页 | 点击文本为9.napiCreateTypedArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateUint8ArraySuccess | Pass | +| ArkTS端成功调用native侧接口isTypedarray | 位于主页 | 点击文本为10.napiIsTypedArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsTypedArraySuccess | Pass | +| ArkTS端成功调用native侧接口getTypedarrayInfo | 位于主页 | 点击文本为11.napiGetTypedArrayInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetTypedArrayInfoSuccess | Pass | +| ArkTS端成功调用native侧接口createDataView | 位于主页 | 点击文本为12.napiCreateDataView的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateDataViewSuccess | Pass | +| ArkTS端成功调用native侧接口isDataView | 位于主页 | 点击文本为13.napiIsDataView的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsDataViewSuccess | Pass | +| ArkTS端成功调用native侧接口getDataViewInfo | 位于主页 | 点击文本为14.napiGetDataViewInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetDataViewInfoSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArray/screenshots/NodeAPIArray2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3c06c351a9453c431eb482faaccc7f97979e8cdf --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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.nodeapiarraybuffer", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ecb3d6a55ff4b283049e8879de9222ef112dec39 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIArraybuffer" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8194990926032c388f5f502909138bd6b2531a8b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API接口进行ArrayBuffer相关开发 + +### 介绍 + +ArrayBuffer是ArkTS中的一种数据类型,用于表示通用的、固定长度的原始二进制数据缓冲区。它提供了一种在ArkTS中有效地表示和操作原始二进制数据的方式 + +该工程主要展示了使用Node-API接口进行检查值是否为ArrayBuffer、获取给定的ArrayBuffer对象信息、分离ArrayBuffer信息、判定是否分离ArrayBuffer以及创建指定长度的ArrayBuffer对象,其中展示的代码详细描述可查如下链接。 + +- [使用Node-API接口进行ArrayBuffer相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-arraybuffer.md) + +### 效果预览 + +| 首页 | 执行效果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIArraybuffer.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API接口进行Arraybuffer相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIArraybuffer.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6286d6e380e4dd0023bbb062ba912ebbf351ee68 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPI_arraybuffer) + +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_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ce1932066fee8e4aff0a6c13c75e9e209fa94a0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,157 @@ +/* + * 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" + +// [Start napi_is_arraybuffer] +// napi_is_arraybuffer +static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) +{ + // 接受一个入参 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 调用napi_is_arraybuffer接口判断给定入参是否为ArrayBuffer数据 + bool result = false; + napi_status status = napi_is_arraybuffer(env, args[0], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_is_arraybuffer fail"); + return nullptr; + } + // 将结果转成napi_value类型返回 + napi_value returnValue = nullptr; + napi_get_boolean(env, result, &returnValue); + return returnValue; +} +// [End napi_is_arraybuffer] + +// [Start napi_get_arraybuffer_info] +// napi_get_arraybuffer_info +static napi_value GetArraybufferInfo(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 检查参数是否为ArrayBuffer + bool isArraybuffer = false; + napi_is_arraybuffer(env, args[0], &isArraybuffer); + if (!isArraybuffer) { + napi_throw_type_error(env, nullptr, "Argument must be an ArrayBuffer"); + return nullptr; + } + + void *data = nullptr; + size_t byteLength = 0; + // 获取ArrayBuffer的底层数据缓冲区和长度 + napi_status status = napi_get_arraybuffer_info(env, args[0], &data, &byteLength); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Failed to get ArrayBuffer info"); + return nullptr; + } + // 创建结果对象 + napi_value result = nullptr; + napi_create_object(env, &result); + // 创建数据缓冲区的字节长度属性 + napi_value byteLengthValue = nullptr; + napi_create_uint32(env, byteLength, &byteLengthValue); + napi_set_named_property(env, result, "byteLength", byteLengthValue); + napi_value bufferData; + napi_create_arraybuffer(env, byteLength, &data, &bufferData); + napi_set_named_property(env, result, "buffer", bufferData); + return result; +} +// [End napi_get_arraybuffer_info] + +// [Start napi_detach_arraybuffer] +// napi_detach_arraybuffer +static napi_value DetachedArraybuffer(napi_env env, napi_callback_info info) +{ + // 调用napi_detach_arraybuffer接口分离给定ArrayBuffer的底层数据 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value arrayBuffer = args[0]; + napi_detach_arraybuffer(env, arrayBuffer); + // 将分离后的arraybuffer传出去 + return arrayBuffer; +} + +// napi_is_detach_arraybuffer +static napi_value IsDetachedArraybuffer(napi_env env, napi_callback_info info) +{ + // 调用napi_is_detached_arraybuffer判断给定的arraybuffer是否已被分离 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value arrayBuffer = args[0]; + bool result = false; + napi_is_detached_arraybuffer(env, arrayBuffer, &result); + // 将返回值通过napi_get_boolean接口转成napi_value传出去做打印 + napi_value returnValue; + napi_get_boolean(env, result, &returnValue); + return returnValue; +} +// [End napi_detach_arraybuffer] + +// [Start napi_create_arraybuffer] +// napi_create_arraybuffer +static napi_value CreateArraybuffer(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_value result = nullptr; + // 解析传递的参数 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + int32_t value; + size_t length; + // 将ArkTS侧传递的参数转换为size_t类型,作为napi_create_arraybuffer的参数 + napi_get_value_int32(env, argv[0], &value); + length = size_t(value); + void *data; + // 创建一个新的ArrayBuffer + napi_create_arraybuffer(env, length, &data, &result); + if (data != nullptr) { + // 确保安全后才能使用data进行操作 + } + // 返回ArrayBuffer + return result; +} +// [End napi_create_arraybuffer] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"isArrayBuffer", nullptr, IsArrayBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getArraybufferInfo", nullptr, GetArraybufferInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"detachedArraybuffer", nullptr, DetachedArraybuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"isDetachedArraybuffer", nullptr, IsDetachedArraybuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createArraybuffer", nullptr, CreateArraybuffer, 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..876dc914041123f1a0573cce73f5e5690a828642 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts @@ -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. + */ + +// [Start napi_is_arraybuffer_api] +export const isArrayBuffer: (arrayBuffer: T) => boolean | void; // napi_is_arraybuffer +// [End napi_is_arraybuffer_api] + +// [Start napi_get_arraybuffer_info_api] +export class ArrayBufferInfo { + byteLength: number; + buffer: Object; +} + +export const getArraybufferInfo: (data: ArrayBuffer) => ArrayBufferInfo | void; // napi_get_arraybuffer_info +// [End napi_get_arraybuffer_info_api] + +// [Start napi_detach_arraybuffer_api] +export const detachedArraybuffer: (buffer: ArrayBuffer) => ArrayBuffer; // napi_detach_arraybuffer + +export const isDetachedArraybuffer: (arrarBeffer: ArrayBuffer) => boolean; //napi_is_detached_arraybuffer +// [End napi_detach_arraybuffer_api] + +// [Start napi_create_arraybuffer_api] +export const createArraybuffer: (size: number) => ArrayBuffer; // napi_create_arraybuffer +// [End napi_create_arraybuffer_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..46aaf9a9985a4165b947bb512eb798b5f3b52259 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,118 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiIsArraybuffer', + '2.napiGetArraybufferInfo', + '3.napiDetachArraybuffer', + '4.napiCreateArraybuffer' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(25) + .fontWeight(FontWeight.Bold) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiIsArraybuffer') { + // [Start ark_napi_is_arraybuffer] + // napi_is_arraybuffer + try { + let value = new ArrayBuffer(1); + let data = "123"; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer: %{public}s', + testNapi.isArrayBuffer(value)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer: %{public}s', + testNapi.isArrayBuffer(data)); + // [StartExclude ark_napi_is_arraybuffer] + this.result = 'napiIsArraybufferSuccess'; + // [EndExclude ark_napi_is_arraybuffer] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer error: %{public}s', + error.message); + // [StartExclude ark_napi_is_arraybuffer] + this.result = 'napiIsArraybufferFail'; + // [EndExclude ark_napi_is_arraybuffer] + } + // [End ark_napi_is_arraybuffer] + } else if (item === '2.napiGetArraybufferInfo') { + // [Start ark_napi_get_arraybuffer_info + // napi_get_arraybuffer_info + const buffer = new ArrayBuffer(10); + hilog.info(0x0000, 'testTag', 'Test Node-API get_arraybuffer_info:%{public}s ', + JSON.stringify(testNapi.getArraybufferInfo(buffer))); + // [End ark_napi_get_arraybuffer_info] + this.result = 'napiGetArraybufferInfoSuccess'; + } else if (item === '3.napiDetachArraybuffer') { + // [Start ark_napi_detach_arraybuffer] + // napi_detach_arraybuffer and napi_is_detached_arraybuffer + try { + const bufferArray = new ArrayBuffer(8); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer one: %{public}s', + testNapi.isDetachedArraybuffer(bufferArray)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer two: %{public}s ', + testNapi.isDetachedArraybuffer(testNapi.detachedArraybuffer(bufferArray))); + // [StartExclude ark_napi_detach_arraybuffer] + this.result = 'napiDetachArraybufferSuccess'; + // [EndExclude ark_napi_detach_arraybuffer] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer error: %{public}s', + error.message); + // [StartExclude ark_napi_detach_arraybuffer] + this.result = 'napiDetachArraybufferFail'; + // [EndExclude ark_napi_detach_arraybuffer] + } + // [End ark_napi_detach_arraybuffer] + } else if (item === '4.napiCreateArraybuffer') { + // [Start ark_napi_create_arraybuffer] + // napi_create_arraybuffer + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_arraybuffer:%{public}s', + testNapi.createArraybuffer(10).toString()); + // [End ark_napi_create_arraybuffer] + this.result = 'napiCreateArraybufferSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/NodeAPIArraybuffer.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/NodeAPIArraybuffer.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/NodeAPIArraybuffer.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/NodeAPIArraybuffer.test.ets index b60c400c9a7407f0e6d25e6e2d852640845750f1..690d990b499deda672edeabc4b2bfa10dd3b50d1 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/NodeAPIArraybuffer.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/ets/test/NodeAPIArraybuffer.test.ets @@ -1,103 +1,103 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIArraybufferTest() { - describe('nodeAPIArraybufferTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiIsArraybuffer相关函数 - */ - it('testNodeAPIArraybuffer001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArraybuffer001 begin'); - const driver = Driver.create(); - const text = await driver.findComponent(ON.text('1.napiIsArraybuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsArraybufferSuccess')); - console.info('uitest: testNodeAPIArraybuffer001 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetArraybufferInfo相关函数 - */ - it('testNodeAPIArraybuffer002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArraybuffer002 begin'); - const driver = Driver.create(); - const text = await driver.findComponent(ON.text('2.napiGetArraybufferInfo')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetArraybufferInfoSuccess')); - console.info('uitest: testNodeAPIArraybuffer002 end'); - done(); - }) - - /** - * 点击按钮,调用napiDetachArraybuffer相关函数 - */ - it('testNodeAPIArraybuffer003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArraybuffer003 begin'); - const driver = Driver.create(); - const text = await driver.findComponent(ON.text('3.napiDetachArraybuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiDetachArraybufferSuccess')); - console.info('uitest: testNodeAPIArraybuffer003 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateArraybuffer相关函数 - */ - it('testNodeAPIArraybuffer004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArraybuffer004 begin'); - const driver = Driver.create(); - const text = await driver.findComponent(ON.text('4.napiCreateArraybuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateArraybufferSuccess')); - console.info('uitest: testNodeAPIArraybuffer004 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIArraybufferTest() { + describe('nodeAPIArraybufferTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiIsArraybuffer相关函数 + */ + it('testNodeAPIArraybuffer001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArraybuffer001 begin'); + const driver = Driver.create(); + const text = await driver.findComponent(ON.text('1.napiIsArraybuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsArraybufferSuccess')); + console.info('uitest: testNodeAPIArraybuffer001 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetArraybufferInfo相关函数 + */ + it('testNodeAPIArraybuffer002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArraybuffer002 begin'); + const driver = Driver.create(); + const text = await driver.findComponent(ON.text('2.napiGetArraybufferInfo')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetArraybufferInfoSuccess')); + console.info('uitest: testNodeAPIArraybuffer002 end'); + done(); + }) + + /** + * 点击按钮,调用napiDetachArraybuffer相关函数 + */ + it('testNodeAPIArraybuffer003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArraybuffer003 begin'); + const driver = Driver.create(); + const text = await driver.findComponent(ON.text('3.napiDetachArraybuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiDetachArraybufferSuccess')); + console.info('uitest: testNodeAPIArraybuffer003 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateArraybuffer相关函数 + */ + it('testNodeAPIArraybuffer004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArraybuffer004 begin'); + const driver = Driver.create(); + const text = await driver.findComponent(ON.text('4.napiCreateArraybuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateArraybufferSuccess')); + console.info('uitest: testNodeAPIArraybuffer004 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIPromise/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..acc3a882531b40df6e3930d8febbb3bbaa94b309 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/ohosTest.md @@ -0,0 +1,11 @@ +# 使用Node-API进行arraybuffer相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------ | ------------ | -------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口isArrayBuffer | 位于主页 | 点击文本为1.napiIsArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsArraybufferSuccess | Pass | +| ArkTS端成功调用native侧接口getArraybufferInfo | 位于主页 | 点击文本为2.napiGetArraybufferInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetArraybufferInfoSuccess | Pass | +| ArkTS端成功调用native侧接口isDetachedArraybuffer | 位于主页 | 点击文本为3.napiDetachArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDetachArraybufferSuccess | Pass | +| ArkTS端成功调用native侧接口createArraybuffer | 位于主页 | 点击文本为4.napiCreateArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateArraybufferSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIArraybuffer/screenshots/NodeAPIArraybuffer2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb7248cc0fc879872b5aff3b1e7a378396f44a33 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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.nodeapibasicdatatypes", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..35e276d0d7f9cb5aca8bdc569221eade8311a122 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIBasicDataTypes" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0e53ee9d1bf352458636edcc88f31a44e40da9ee --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API进行basic_data_types相关开发 + +### 介绍 + +ArkTS的Number类型是一个双精度64位二进制格式IEEE 754值。只有在-2^53+1到2^53-1范围内(闭区间)的整数才能在不丢失精度的情况下被表示,在超过该取值范围的情况下,需要使用BigInt对应的NPI接口来处理更大范围的整数。 + +该工程主要展示了使用Node-API接口将number类型转换为uint32、int32、int64、double以及前述四种类型转换回number类型,其中展示的代码详细描述可查如下链接。 + +- [使用Node-API进行basic_data_types相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-basic-data-types.md) + +### 效果预览 + +| 首页 | 执行效果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIBasicDataTypes.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API接口进行basic_data_types相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIBasicDataTypes.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..05a6c8b00b71513a20e645f2f9b31749cb8d9c9d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIBasicDataTypes) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe51be316ca80a051160b90ad0e0012087630a9f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,204 @@ +/* + * 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" + +// [Start napi_get_value_uint32] +// napi_get_value_uint32 +static napi_value GetValueUint32(napi_env env, napi_callback_info info) +{ + // 获取传入的数字类型参数 + size_t argc = 1; + napi_value argv[1] = {nullptr}; + // 解析传入的参数 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + uint32_t number = 0; + // 获取传入参数的值中的无符号32位整数 + napi_status status = napi_get_value_uint32(env, argv[0], &number); + // 如果传递的参数不是数字,将会返回napi_number_expected,设置函数返回nullptr + if (status == napi_number_expected) { + return nullptr; + } + napi_value result = nullptr; + // 创建传入参数无符号32位整数,并传出 + napi_create_uint32(env, number, &result); + return result; +} +// [End napi_get_value_uint32] + +// [Start napi_get_value_int32] +// napi_get_value_int32 +static napi_value GetValueInt32(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + int32_t result32 = 0; + // 解析传递的参数 + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将前端传过来的参数转为Node-API模块的int32类型 + napi_status status = napi_get_value_int32(env, args[0], &result32); + // 如果传递的参数不是数字napi_get_value_int32接口将会返回napi_number_expected,设置函数返回nullptr + if (status == napi_number_expected) { + return nullptr; + } + // 调用napi_create_int32接口将int32类型的数据转为napi_value返回 + napi_value napiResult32 = nullptr; + napi_create_int32(env, result32, &napiResult32); + return napiResult32; +} +// [End napi_get_value_int32] + +// [Start napi_get_value_int64] +// napi_get_value_int64 +static napi_value GetValueInt64(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + int64_t result64 = 0; + // 解析传递的值 + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将前端传过来的参数转为Node-API模块的int64类型 + napi_status status = napi_get_value_int64(env, args[0], &result64); + // 如果传递的参数不是数字, 返回napi_number_expected. + if (status == napi_number_expected) { + return nullptr; + } + // 调用napi_create_int64接口将int64类型的数据转为napi_value返回前端 + napi_value napiResult64 = nullptr; + napi_create_int64(env, result64, &napiResult64); + return napiResult64; +} +// [End napi_get_value_int64] + +// [Start napi_get_value_double] +// napi_get_value_double +static napi_value GetDouble(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + double value = 0; + napi_status status = napi_get_value_double(env, args[0], &value); + // 传入非数字接口返回napi_number_expected + if (status == napi_number_expected) { + return nullptr; + } + napi_value result = nullptr; + napi_create_double(env, value, &result); + return result; +} +// [End napi_get_value_double] + +// [Start napi_create_int32] +// napi_create_int32 +static napi_value CreateInt32(napi_env env, napi_callback_info info) +{ + // int32_t是有符号的32位整数类型,表示带有符号的整数,它的范围是从-2^31到2^31 - 1,也就是-2147483648到2147483647 + // 要表示的整数值 + int32_t value = -26; + // 创建ArkTS中的int32数字 + napi_value result = nullptr; + napi_status status = napi_create_int32(env, value, &result); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Failed to create int32 value"); + } + return result; +} +// [End napi_create_int32] + +// [Start napi_create_uint32] +// napi_create_uint32 +static napi_value CreateUInt32(napi_env env, napi_callback_info info) +{ + // 如果使用 + // uint32_t类型来定义-26,会发生溢出,溢出时会对结果进行模运算,将负数的二进制补码转换为相应的正数。-26输出4294967270 + // uint32_t是无符号的32位整数类型,只能表示非负整数。它的范围是从0到2 ^32 - 1,即0到4294967295 + // 要表示的整数值 + uint32_t value = 26; + // 创建ArkTS中的uint32数字 + napi_value result = nullptr; + napi_status status = napi_create_uint32(env, value, &result); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Failed to create uint32 value"); + } + return result; +} +// [End napi_create_uint32] + +// [Start napi_create_int64] +// napi_create_int64 +static napi_value CreateInt64(napi_env env, napi_callback_info info) +{ + // int64是有符号的64位整数类型,可以表示范围从-2^63到2^63 - 1的整数,即 -9223372036854775808到9223372036854775807 + // 要表示的整数值 + int64_t value = 2147483648; + // 创建ArkTS中的int64数字 + napi_value result = nullptr; + napi_status status = napi_create_int64(env, value, &result); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Failed to create int64 value"); + } + return result; +} +// [End napi_create_int64] + +// [Start napi_create_double] +// napi_create_double +static napi_value CreateDouble(napi_env env, napi_callback_info info) +{ + double value = 1.234; + // 创建ArkTS中的double数字 + napi_value result = nullptr; + napi_status status = napi_create_double(env, value, &result); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Failed to create double value"); + } + return result; +} +// [End napi_create_double] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getValueUint32", nullptr, GetValueUint32, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueInt32", nullptr, GetValueInt32, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueInt64", nullptr, GetValueInt64, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getDouble", nullptr, GetDouble, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createInt32", nullptr, CreateInt32, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createUInt32", nullptr, CreateUInt32, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createInt64", nullptr, CreateInt64, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createDouble", nullptr, CreateDouble, 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a2d502bc37599108de34c1e2c4b5b2d3c9d435e0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_get_value_uint32_api] +export const getValueUint32: (data: T) => number | void; // napi_get_value_uint32 +// [End napi_get_value_uint32_api] + +// [Start napi_get_value_int32_api] +export const getValueInt32: (value: number | string) => number | void; // napi_get_value_int32 +// [End napi_get_value_int32_api] + +// [Start napi_get_value_int64_api] +export const getValueInt64: (value: number | string) => number | void; // napi_get_value_int64 +// [End napi_get_value_int64_api] + +// [Start napi_get_value_double_api] +export const getDouble: (value: number | string) => number | void; // napi_get_value_double +// [End napi_get_value_double_api] + +// [Start napi_create_int32_api] +export const createInt32: () => number; // napi_create_int32 +// [End napi_create_int32_api] + +// [Start napi_create_uint32_api] +export const createUInt32: () => number; // napi_create_uint32 +// [End napi_create_uint32_api] + +// [Start napi_create_int64_api] +export const createInt64: () => number; // napi_create_int64 +// [End napi_create_int64_api] + +// [Start napi_create_double_api] +export const createDouble: () => number; // napi_create_double +// [End napi_create_double_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3e91ea528417cfa9ef9c16e76ad6889ea5c2059 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,152 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiGetValueUint32', + '2.napiGetValueInt32', + '3.napiGetValueInt64', + '4.napiGetValueDouble', + '5.napiCreateInt32', + '6.napiCreateUint32', + '7.napiCreateInt64', + '8.napiCreateDouble' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(25) + .fontWeight(FontWeight.Bold) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiGetValueUint32') { + // [Start ark_napi_get_value_uint32] + // napi_get_value_uint32 + let value = testNapi.getValueUint32(111111111111); + let data = testNapi.getValueUint32("sssss"); + hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', value); + // 传入非数字"sssss"时函数返回undefined + hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}s', data); + // 传入uint32范围内的数字100时函数返回原数字 + hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', + testNapi.getValueUint32(100)); + // [End ark_napi_get_value_uint32] + this.result = 'napiGetValueUint32Success'; + } else if (item === '2.napiGetValueInt32') { + // [Start ark_napi_get_value_int32] + // napi_get_value_int32 + // 传入非数字“ss”时函数返回undefined + hilog.info(0x0000, 'Node-API', 'get_value_int32_not_number %{public}s', testNapi.getValueInt32('ss')); + // 传入int32范围内的数字100时函数返回原数字 + hilog.info(0x0000, 'Node-API', 'get_value_int32_number %{public}d', testNapi.getValueInt32(100)); + // 传入68719476735,此数字的二进制为111111111111111111111111111111111111,在int32类型中此二进制代表数字-1 + hilog.info(0x0000, 'Node-API', 'get_value_int32_oversize %{public}d', + testNapi.getValueInt32(68719476735)); + // 大于2的31次-1的数字且不是二进制为111111111111111111111111111111111111这样的在int32中有特殊含义的数字也会溢出,导致数值发生改变,返回值按后32位二进制编码解码 + hilog.info(0x0000, 'Node-API', 'get_value_int32_oversize %{public}d', + testNapi.getValueInt32(687194767355)); + // 传入NAN(not a number)、+Infinity(正无穷)或-Infinity(负无穷),会返回数字0 + hilog.info(0x0000, 'Node-API', 'get_value_int32_number_NAN %{public}d', testNapi.getValueInt32(NaN)); + hilog.info(0x0000, 'Node-API', 'get_value_int32_number_+Infinity %{public}d', + testNapi.getValueInt32(+Infinity)); + hilog.info(0x0000, 'Node-API', 'get_value_int32_number_-Infinity %{public}d', + testNapi.getValueInt32(-Infinity)); + // [End ark_napi_get_value_int32] + this.result = 'napiGetValueInt32Success'; + } else if (item === '3.napiGetValueInt64') { + // [Start ark_napi_get_value_int64] + // napi_get_value_int64 + // 输入不超过int64表示范围的数字,会返回该数字 + hilog.info(0x0000, 'Node-API', 'get_value_int64_number %{public}d', testNapi.getValueInt64(80)); + // 传入非数字“ss”,获得函数返回的值应为undefined + hilog.info(0x0000, 'Node-API', 'get_value_int64_not_number %{public}s', + testNapi.getValueInt64('sAs')); + // 输入超过int64表示范围的数字会溢出,失去精度,导致输入数字与返回数字不相等 + hilog.info(0x0000, 'Node-API', 'get_value_int64_number_oversize %{public}d', + testNapi.getValueInt64(9223372036854775809)); + // 传入NAN(not a number)、+Infinity(正无穷)或-Infinity(负无穷)接口返回数字0 + hilog.info(0x0000, 'Node-API', 'get_value_int64_number_NAN %{public}d', testNapi.getValueInt64(NaN)); + hilog.info(0x0000, 'Node-API', 'get_value_int64_number_+Infinity %{public}d', + testNapi.getValueInt64(+Infinity)); + hilog.info(0x0000, 'Node-API', 'get_value_int64_number_-Infinity %{public}d', + testNapi.getValueInt64(-Infinity)); + // [End ark_napi_get_value_int64] + this.result = 'napiGetValueInt64Success'; + } else if (item === '4.napiGetValueDouble') { + // [Start ark_napi_get_value_double] + // napi_get_value_double + // 输入数字,返回该数字 + hilog.info(0x0000, 'Node-API', 'get_value_double_number %{public}d', testNapi.getDouble(80.885)); + // 传入非数字,获得函数返回的值应为undefined + hilog.info(0x0000, 'Node-API', 'get_value_double_not_number %{public}s', testNapi.getDouble('sAs')); + // [End ark_napi_get_value_double] + this.result = 'napiGetValueDoubleSuccess'; + } else if (item === '5.napiCreateInt32') { + // [Start ark_napi_create_int32] + // napi_create_int32 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int32:' + testNapi.createInt32()); + // [End ark_napi_create_int32] + this.result = 'napiCreateInt32Success'; + } else if (item === '6.napiCreateUint32') { + // [Start ark_napi_create_uint32] + // napi_create_uint32 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_uint32: ' + testNapi.createUInt32()); + // [End ark_napi_create_uint32] + this.result = 'napiCreateUint32Success'; + } else if (item === '7.napiCreateInt64') { + // [Start ark_napi_create_int64] + // napi_create_int64 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int64: ' + testNapi.createInt64()); + // [End ark_napi_create_int64] + this.result = 'napiCreateInt64Success'; + } else if (item === '8.napiCreateDouble') { + // [Start ark_napi_create_double] + // napi_create_double + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_double: ' + testNapi.createDouble()); + // [End ark_napi_create_double] + this.result = 'napiCreateDoubleSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/NodeAPIBasicDataTypes.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/NodeAPIBasicDataTypes.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/NodeAPIBasicDataTypes.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/NodeAPIBasicDataTypes.test.ets index d975c99e5376a9786b89483ca93dc9381965d642..ba4c97320d84ad948da60dd3307777a9c93e0490 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/NodeAPIBasicDataTypes.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/ets/test/NodeAPIBasicDataTypes.test.ets @@ -1,172 +1,172 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIBasicDataTypesTest() { - describe('nodeAPIBasicDataTypesTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiGetValueUint32相关函数 - */ - it('testNodeAPIBasicDataTypes001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiGetValueUint32')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueUint32Success')); - console.info('uitest: testNodeAPIBasicDataTypes001 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueInt32相关函数 - */ - it('testNodeAPIBasicDataTypes002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiGetValueInt32')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueInt32Success')); - console.info('uitest: testNodeAPIBasicDataTypes002 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueInt64相关函数 - */ - it('testNodeAPIBasicDataTypes003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiGetValueInt64')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueInt64Success')); - console.info('uitest: testNodeAPIBasicDataTypes003 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueDouble相关函数 - */ - it('testNodeAPIBasicDataTypes004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiGetValueDouble')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueDoubleSuccess')); - console.info('uitest: testNodeAPIBasicDataTypes004 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateInt32相关函数 - */ - it('testNodeAPIBasicDataTypes005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiCreateInt32')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateInt32Success')); - console.info('uitest: testNodeAPIBasicDataTypes005 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateUint32相关函数 - */ - it('testNodeAPIBasicDataTypes006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiCreateUint32')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateUint32Success')); - console.info('uitest: testNodeAPIBasicDataTypes006 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateInt64相关函数 - */ - it('testNodeAPIBasicDataTypes007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiCreateInt64')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateInt64Success')); - console.info('uitest: testNodeAPIBasicDataTypes007 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateDouble相关函数 - */ - it('testNodeAPIBasicDataTypes008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBasicDataTypes008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiCreateDouble')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateDoubleSuccess')); - console.info('uitest: testNodeAPIBasicDataTypes008 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIBasicDataTypesTest() { + describe('nodeAPIBasicDataTypesTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiGetValueUint32相关函数 + */ + it('testNodeAPIBasicDataTypes001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiGetValueUint32')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueUint32Success')); + console.info('uitest: testNodeAPIBasicDataTypes001 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueInt32相关函数 + */ + it('testNodeAPIBasicDataTypes002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiGetValueInt32')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueInt32Success')); + console.info('uitest: testNodeAPIBasicDataTypes002 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueInt64相关函数 + */ + it('testNodeAPIBasicDataTypes003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiGetValueInt64')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueInt64Success')); + console.info('uitest: testNodeAPIBasicDataTypes003 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueDouble相关函数 + */ + it('testNodeAPIBasicDataTypes004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiGetValueDouble')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueDoubleSuccess')); + console.info('uitest: testNodeAPIBasicDataTypes004 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateInt32相关函数 + */ + it('testNodeAPIBasicDataTypes005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiCreateInt32')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateInt32Success')); + console.info('uitest: testNodeAPIBasicDataTypes005 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateUint32相关函数 + */ + it('testNodeAPIBasicDataTypes006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiCreateUint32')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateUint32Success')); + console.info('uitest: testNodeAPIBasicDataTypes006 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateInt64相关函数 + */ + it('testNodeAPIBasicDataTypes007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiCreateInt64')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateInt64Success')); + console.info('uitest: testNodeAPIBasicDataTypes007 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateDouble相关函数 + */ + it('testNodeAPIBasicDataTypes008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBasicDataTypes008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiCreateDouble')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateDoubleSuccess')); + console.info('uitest: testNodeAPIBasicDataTypes008 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIProperty/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..8f2b1c917efde7d7b84a04bf09980ee3708d81ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/ohosTest.md @@ -0,0 +1,15 @@ +# 使用Node-API进行basic_data_types相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ----------------------------------------- | ------------ | ---------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口getValueUint32 | 位于主页 | 点击文本为1.napiGetValueUint32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueUint32Success | Pass | +| ArkTS端成功调用native侧接口getValueInt32 | 位于主页 | 点击文本为2.napiGetValueInt32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueInt32Success | Pass | +| ArkTS端成功调用native侧接口getValueInt64 | 位于主页 | 点击文本为3.napiGetValueInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueInt64Success | Pass | +| ArkTS端成功调用native侧接口getDouble | 位于主页 | 点击文本为4.napiGetValueDouble的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueDoubleSuccess | Pass | +| ArkTS端成功调用native侧接口createInt32 | 位于主页 | 点击文本为5.napiCreateInt32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateInt32Success | Pass | +| ArkTS端成功调用native侧接口createUInt32 | 位于主页 | 点击文本为6.napiCreateUint32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateUint32Success | Pass | +| ArkTS端成功调用native侧接口createInt64 | 位于主页 | 点击文本为7.napiCreateInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateInt64Success | Pass | +| ArkTS端成功调用native侧接口createDouble | 位于主页 | 点击文本为8.napiCreateDouble的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateDoubleSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/screenshots/NodeAPIBasicDataTypes2.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/.gitignore rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/.gitignore diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7ed0906f6a6be33a5de971f50e9b0512bd3d61d6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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.nodeapibigint", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..deea14308270e1cfbdc5f7eb0b0b3e22edf122f7 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIBigint" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e1c04cfd4497b7702cbc155828670cebd318f5da --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API进行bigint相关开发 + +### 介绍 + +BigInt是ArkTS中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过Node-API提供的接口,可以在Node-API模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。 + +该工程主要展示使用Node-API创建中展示使用int64、uint64类型和给定字节数的uint64创建BigInt对象等场景。其中代码详细描述可查如下链接。 + +- [使用Node-API进行bigint相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-bigint.md) + +### 效果预览 + +| 执行结果图 | | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIBigint.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行bigint相关开发 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIBigint.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea844a34168cc6341d754515caebfc99c88b88b4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIBigint) + +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_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d06064f2e2eb94232062bec8dbd7bb461760b571 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,162 @@ +/* + * 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" + +// [Start napi_create_bigint_int64] +// napi_create_bigint_int64 +static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) +{ + // 声明int64_t的变量value + int64_t value = -5555555555555555555; + // 将value转化为napi_value类型返回 + napi_value returnValue = nullptr; + napi_create_bigint_int64(env, value, &returnValue); + return returnValue; +} +// [End napi_create_bigint_int64] + +// [Start napi_create_bigint_uint64] +// napi_create_bigint_uint64 +static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) +{ + // 声明uint64_t的变量value + uint64_t value = 5555555555555555555; + // 将value转化为napi_value类型返回 + napi_value returnValue = nullptr; + napi_create_bigint_uint64(env, value, &returnValue); + return returnValue; +} +// [End napi_create_bigint_uint64] + +// [Start napi_create_bigint_words] +// napi_create_bigint_words +static napi_value CreateBigintWords(napi_env env, napi_callback_info info) +{ + // 使用napi_create_bigint_words接口创建一个BigInt对象 + int signBit = 0; + size_t wordCount = 3; + uint64_t words[] = {12ULL, 34ULL, 56ULL}; + napi_value returnValue = nullptr; + napi_status status = napi_create_bigint_words(env, signBit, wordCount, words, &returnValue); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_create_bigint_words fail"); + return nullptr; + } + return returnValue; +} +// [End napi_create_bigint_words] + +// [Start napi_get_value_bigint_int64] +// napi_get_value_bigint_int64 +static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 从传入的参数中提取64位整数的BigInt数据 + int64_t value = 0; + bool lossLess = false; + napi_status status = napi_get_value_bigint_int64(env, args[0], &value, &lossLess); + // 判断从ArkTS侧获取bigint是否为无损转换,如果不是抛出异常 + if (!lossLess) { + napi_throw_error(env, nullptr, "BigInt values have not been lossless converted"); + return nullptr; + } + // 如果接口调用成功正常调用则返回true给ArkTS侧 + napi_value returnValue = nullptr; + napi_get_boolean(env, status == napi_ok, &returnValue); + return returnValue; +} +// [End napi_get_value_bigint_int64] + +// [Start napi_get_value_bigint_uint64] +// napi_get_value_bigint_uint64 +static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 从参数值中获取BigInt的数值 + uint64_t value = 0; + bool lossLess = false; + napi_status status = napi_get_value_bigint_uint64(env, args[0], &value, &lossLess); + // 判断从ArkTS侧获取bigint是否为无损转换,如果不是抛出异常 + if (!lossLess) { + napi_throw_error(env, nullptr, "BigInt values have no lossless converted"); + return nullptr; + } + // 如果接口调用成功正常调用则返回true给ArkTS侧 + napi_value returnValue = nullptr; + napi_get_boolean(env, status == napi_ok, &returnValue); + return returnValue; +} +// [End napi_get_value_bigint_uint64] + +// [Start napi_get_value_bigint_words] +// napi_get_value_bigint_words +static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + int signBit = 0; + size_t wordCount = 0; + uint64_t words = 0; + // 调用napi_get_value_bigint_words接口获取wordCount + napi_status status = napi_get_value_bigint_words(env, args[0], nullptr, &wordCount, nullptr); + OH_LOG_INFO(LOG_APP, "Node-API , wordCount:%{public}d.", wordCount); + // 调用napi_get_value_bigint_words接口获取传入bigInt相关信息,如:signBit传入bigInt正负信息 + status = napi_get_value_bigint_words(env, args[0], &signBit, &wordCount, &words); + OH_LOG_INFO(LOG_APP, "Node-API , signBit: %{public}d.", signBit); + if (status != napi_ok) { + OH_LOG_ERROR(LOG_APP, "Node-API , reason:%{public}d.", status); + napi_throw_error(env, nullptr, "napi_get_date_value fail"); + return nullptr; + } + // 将符号位转化为int类型传出去 + napi_value returnValue = nullptr; + napi_create_int32(env, signBit, &returnValue); + return returnValue; +} +// [End napi_get_value_bigint_words] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"createBigintInt64t", nullptr, CreateBigintInt64t, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createBigintUint64t", nullptr, CreateBigintUint64t, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createBigintWords", nullptr, CreateBigintWords, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueBigintInt64t", nullptr, GetValueBigintInt64t, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueBigintUint64t", nullptr, GetValueBigintUint64t, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueBigintWords", nullptr, GetValueBigintWords, 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..744aef778a05f057319e3135f7f55c88ed145f9b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_create_bigint_int64_api] +export const createBigintInt64t: () => bigint; // napi_create_bigint_int64 +// [End napi_create_bigint_int64_api] + +// [Start napi_create_bigint_uint64_api] +export const createBigintUint64t: () => bigint; // napi_create_bigint_uint64 +// [End napi_create_bigint_uint64_api] + +// [Start napi_create_bigint_words_api] +export const createBigintWords: () => bigint | void; // napi_create_bigint_words +// [End napi_create_bigint_words_api] + +// [Start napi_get_value_bigint_int64_api] +export const getValueBigintInt64t: (bigInt64: bigint) => boolean | void; // napi_get_value_bigint_int64 +// [End napi_get_value_bigint_int64_api] + +// [Start napi_get_value_bigint_uint64_api] +export const getValueBigintUint64t: (bigUint64: bigint) => boolean | void; // napi_get_value_bigint_uint64 +// [End napi_get_value_bigint_uint64_api] + +// [Start napi_get_value_bigint_words_api] +export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; // napi_get_value_bigint_words +// [End napi_get_value_bigint_words_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3427679cc07ef656ea38c795e14f5ce06b2dfbfa --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,149 @@ +/* + * 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'; + + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiCreateBigintInt64', + '2.napiCreateBigintUint64', + '3.napiCreateBigintWords', + '4.napiGetValueBigintInt64', + '5.napiGetValueBigintUint64', + '6.napiGetValueBigintWords' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(22) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiCreateBigintInt64') { + // [Start ark_napi_create_bigint_int64] + // napi_create_bigint_int64 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_int64: %{public}d', + testNapi.createBigintInt64t()); + // [End ark_napi_create_bigint_int64] + this.result = 'napiCreateBigintInt64Success'; + } else if (item === '2.napiCreateBigintUint64') { + // [Start ark_napi_create_bigint_uint64] + // napi_create_bigint_uint64 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_uint64: %{public}d', + testNapi.createBigintUint64t()); + // [End ark_napi_create_bigint_uint64] + this.result = 'napiCreateBigintUint64Success'; + } else if (item === '3.napiCreateBigintWords') { + // [Start ark_napi_create_bigint_words] + // napi_create_bigint_words + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_words: %{public}d', + testNapi.createBigintWords()); + // [StartExclude ark_napi_create_bigint_words] + this.result = 'napiCreateBigintWordsSuccess'; + // [EndExclude ark_napi_create_bigint_words] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_create_bigint_words] + this.result = 'napiCreateBigintWordsFail'; + // [EndExclude ark_napi_create_bigint_words] + } + // [End ark_napi_create_bigint_words] + } else if (item === '4.napiGetValueBigintInt64') { + // [Start ark_napi_get_value_bigint_int64] + // napi_get_value_bigint_int64 + let bigInt = BigInt(-5555555555555555); + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_int64: %{public}s', + JSON.stringify(testNapi.getValueBigintInt64t(bigInt))); + // [StartExclude ark_napi_get_value_bigint_int64] + this.result = 'napiGetValueBigintInt64Success'; + // [EndExclude ark_napi_get_value_bigint_int64] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_int64] + this.result = 'napiGetValueBigintInt64Fail'; + // [EndExclude ark_napi_get_value_bigint_int64] + } + // [End ark_napi_get_value_bigint_int64] + } else if (item === '5.napiGetValueBigintUint64') { + // [Start ark_napi_get_value_bigint_uint64] + // napi_get_value_bigint_uint64 + let bigUint = BigInt(5555555555555555); + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_uint64: %{public}s', + JSON.stringify(testNapi.getValueBigintUint64t(bigUint))); + // [StartExclude ark_napi_get_value_bigint_uint64] + this.result = 'napiGetValueBigintUint64Success'; + // [EndExclude ark_napi_get_value_bigint_uint64] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_uint64] + this.result = 'napiGetValueBigintUint64Fail'; + // [EndExclude ark_napi_get_value_bigint_uint64] + } + // [End ark_napi_get_value_bigint_uint64] + } else if (item === '6.napiGetValueBigintWords') { + // [Start ark_napi_get_value_bigint_words] + // napi_get_value_bigint_words + let bigInt = BigInt(-5555555555555555); + let bigUint = BigInt(5555555555555555); + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', + testNapi.getValueBigintWords(bigInt)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', + testNapi.getValueBigintWords(bigUint)); + // [StartExclude ark_napi_get_value_bigint_words] + this.result = 'napiGetValueBigintWordsSuccess'; + // [EndExclude ark_napi_get_value_bigint_words] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); + // [StartExclude ark_napi_get_value_bigint_words] + this.result = 'napiGetValueBigintWordsFail'; + // [EndExclude ark_napi_get_value_bigint_words] + } + // [End ark_napi_get_value_bigint_words] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/NodeAPIBigint.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/NodeAPIBigint.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/NodeAPIBigint.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/NodeAPIBigint.test.ets index f7ce867cb9e0729f174e7685325aa06e1c0dfb86..2caac72b079029d4a32bbb253ca2ac5884456889 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/NodeAPIBigint.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/ets/test/NodeAPIBigint.test.ets @@ -1,140 +1,140 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIBigintTest() { - describe('nodeAPIBigintTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiCreateBigintInt64相关函数 - */ - it('testNodeAPIBigint001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBigint001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiCreateBigintInt64')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateBigintInt64Success')); - console.info('uitest: testNodeAPIBigint001 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateBigintUint64相关函数 - */ - it('testNodeAPIBigint002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBigint002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCreateBigintUint64')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateBigintUint64Success')); - console.info('uitest: testNodeAPIBigint002 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateBigintWords相关函数 - */ - it('testNodeAPIBigint003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBigint003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiCreateBigintWords')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateBigintWordsSuccess')); - console.info('uitest: testNodeAPIBigint003 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueBigintInt64相关函数 - */ - it('testNodeAPIBigint004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBigint004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiGetValueBigintInt64')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueBigintInt64Success')); - console.info('uitest: testNodeAPIBigint004 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueBigintUint64相关函数 - */ - it('testNodeAPIBigint005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBigint005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiGetValueBigintUint64')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueBigintUint64Success')); - console.info('uitest: testNodeAPIBigint005 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueBigintWords相关函数 - */ - it('testNodeAPIBigint006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBigint006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiGetValueBigintWords')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueBigintWordsSuccess')); - console.info('uitest: testNodeAPIBigint006 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIBigintTest() { + describe('nodeAPIBigintTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiCreateBigintInt64相关函数 + */ + it('testNodeAPIBigint001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBigint001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiCreateBigintInt64')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateBigintInt64Success')); + console.info('uitest: testNodeAPIBigint001 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateBigintUint64相关函数 + */ + it('testNodeAPIBigint002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBigint002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCreateBigintUint64')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateBigintUint64Success')); + console.info('uitest: testNodeAPIBigint002 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateBigintWords相关函数 + */ + it('testNodeAPIBigint003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBigint003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiCreateBigintWords')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateBigintWordsSuccess')); + console.info('uitest: testNodeAPIBigint003 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueBigintInt64相关函数 + */ + it('testNodeAPIBigint004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBigint004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiGetValueBigintInt64')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueBigintInt64Success')); + console.info('uitest: testNodeAPIBigint004 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueBigintUint64相关函数 + */ + it('testNodeAPIBigint005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBigint005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiGetValueBigintUint64')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueBigintUint64Success')); + console.info('uitest: testNodeAPIBigint005 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueBigintWords相关函数 + */ + it('testNodeAPIBigint006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBigint006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiGetValueBigintWords')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueBigintWordsSuccess')); + console.info('uitest: testNodeAPIBigint006 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/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/NodeAPI/NodeApiUse/NodeAPIBigint/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c6b0c615b9f9a1bb7b4569f246766f8b3d81163f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/ohosTest.md @@ -0,0 +1,13 @@ +# 使用Node-API进行bigInt相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------ | ------------ | ---------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口createBigintInt64t | 位于主页 | 点击文本为1.napiCreateBigintInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBigintInt64Success | Pass | +| ArkTS端成功调用native侧接口createBigintUint64t | 位于主页 | 点击文本为2.napiCreateBigintUint64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBigintUint64Success | Pass | +| ArkTS端成功调用native侧接口createBigintWords | 位于主页 | 点击文本为3.napiCreateBigintWords的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBigintWordsSuccess | Pass | +| ArkTS端成功调用native侧接口getValueBigintInt64t | 位于主页 | 点击文本为4.napiGetValueBigintInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBigintInt64Success | Pass | +| ArkTS端成功调用native侧接口getValueBigintUint64t | 位于主页 | 点击文本为5.napiGetValueBigintUint64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBigintUint64Success | Pass | +| ArkTS端成功调用native侧接口getValueBigintWords | 位于主页 | 点击文本为6.napiGetValueBigintWords的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBigintWordsSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBigint/screenshots/NodeAPIBigint2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/.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/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0f22d3635c6d937cf66f10f0df4e9dfa1d0a08ef --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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.nodeapibuffer", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b65e358d5abef814467d124fddb22a70d5f9290e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIBuffer" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b7924bf84520a9ca5d63137bab3b541c28733ff5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API进行buffer相关开发 + +### 介绍 + +在ArkTS中,Buffer是一种用于处理二进制数据的数据类型,使用Node-API接口进行buffer相关开发时,使用Buffer对象与ArkTS代码之间进行二进制数据的有效交互,以便在Node-API模块创建、操纵和传递Buffer对象到ArkTS,从而处理和传递二进制数据,比如文件I/O、网络传输等。 + +该工程主要展示了使用Node-API进行创建指定大小ArkTS Buffer、创建并获取指定大小ArkTS Buffer、判断给定value是否为Buffer对象等功能场景,其中代码详细描述可查如下链接。 + +- [使用Node-API进行buffer相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-buffer.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIBuffer.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API接口进行array相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIBuffer.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/code-linter.json5 old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/code-linter.json5 rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/code-linter.json5 diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..84934e6047a91862f2e85b17805e5884d2f278ed --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIBuffer) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..67edc5118d32d1ff49365da07ca16a8e27cb5213 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,181 @@ +/* + * 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 +#include "hilog/log.h" +#include "napi/native_api.h" + +static constexpr int INT_ARG_5 = 5; // 入参索引 + +// napi_create_buffer +static napi_value CreateBuffer(napi_env env, napi_callback_info info) +{ + std::string str("CreateBuffer"); + void *bufferPtr = nullptr; + size_t bufferSize = str.size(); + napi_value buffer = nullptr; + // 调用napi_create_buffer接口创建并获取一个指定大小的ArkTS Buffer + napi_create_buffer(env, bufferSize, &bufferPtr, &buffer); + // 将字符串str的值复制到buffer的内存中 + strcpy((char *)bufferPtr, str.data()); + return buffer; +} + +// napi_create_buffer_copy +static napi_value CreateBufferCopy(napi_env env, napi_callback_info info) +{ + // 要copy的内容 + std::string str("CreateBufferCopy"); + napi_value buffer = nullptr; + // 调用napi_create_buffer_copy接口创建buffer并将str的内容copy到buffer + void *resultData = nullptr; + napi_create_buffer_copy(env, str.size(), str.data(), &resultData, &buffer); + OH_LOG_INFO(LOG_APP, "Node-API resultData is : %{public}s.", resultData); + return buffer; +} + +// 回调函数,用于释放内存 +void FinalizeCallback(napi_env env, void *data, void *hint) +{ + if (data == nullptr) { + return; + } + free(data); + data = nullptr; +} + +// napi_create_external_buffer +static napi_value CreateExternalBuffer(napi_env env, napi_callback_info info) +{ + // 创建一个字符串 + std::string str("CreateExternalBuffer"); + // 在堆上分配内存,大小为字符串的长度 + void *data = malloc(str.size()); + // 将字符串复制到分配的内存中 + strcpy(static_cast(data), str.data()); + // 使用napi_create_external_buffer接口创建并获取一个指定大小buffer + napi_value buffer = nullptr; + napi_create_external_buffer(env, str.size(), data, FinalizeCallback, nullptr, &buffer); + return buffer; +} + +// napi_get_buffer_info +static napi_value GetBufferInfo(napi_env env, napi_callback_info info) +{ + // 创建一个字符串 + std::string str("GetBufferInfo"); + napi_value buffer = nullptr; + void *bufferPtr = nullptr; + size_t bufferSize = str.size(); + napi_create_buffer(env, bufferSize, &bufferPtr, &buffer); + strcpy((char *)bufferPtr, str.data()); + + // 获取Buffer的信息 + void *tmpBufferPtr = nullptr; + size_t bufferLength = 0; + napi_get_buffer_info(env, buffer, &tmpBufferPtr, &bufferLength); + + // 创建一个新的ArkTS字符串来保存Buffer的内容并返出去 + napi_value returnValue = nullptr; + napi_create_string_utf8(env, (char *)tmpBufferPtr, bufferLength, &returnValue); + return returnValue; +} + +// napi_is_buffer +static napi_value IsBuffer(napi_env env, napi_callback_info info) +{ + // 创建一个Buffer对象 + std::string str = "buffer"; + napi_value buffer = nullptr; + napi_create_buffer(env, strlen(str.data()), (void **)(str.data()), &buffer); + + // 调用napi_is_buffer接口判断创建的对象是否为buffer + bool result = false; + napi_is_buffer(env, buffer, &result); + // 将结果返回出去 + napi_value returnValue = nullptr; + napi_get_boolean(env, result, &returnValue); + return returnValue; +} + +typedef struct { + uint8_t *data; + size_t length; +} BufferData; + +void FinalizeCallback1(napi_env env, void *finalizeData, void *finalizeHint) +{ + // 获取终结时的数据 + BufferData *bufferData = static_cast(finalizeData); + + // 执行清理操作,比如释放资源 + delete[] bufferData->data; + delete bufferData; +} + +// napi_create_external_arraybuffer +napi_value CreateExternalArraybuffer(napi_env env, napi_callback_info info) +{ + // 创建一个有五个元素的C++数组 + uint8_t *dataArray = new uint8_t[5]{1, 2, 3, 4, 5}; + napi_value externalBuffer = nullptr; + BufferData *bufferData = new BufferData{dataArray, 5}; + + // 使用napi_create_external_arraybuffer创建一个外部Array Buffer对象,并指定终结回调函数 + napi_status status = + napi_create_external_arraybuffer(env, dataArray, 5, FinalizeCallback1, bufferData, &externalBuffer); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Node-API napi_create_external_arraybuffer fail"); + return nullptr; + } + napi_value outputArray; + // 使用napi_create_typedarray创建一个Array对象,并将externalBuffer对象作为参数传入 + status = napi_create_typedarray(env, napi_int8_array, INT_ARG_5, externalBuffer, 0, &outputArray); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Node-API napi_create_typedarray fail"); + return nullptr; + } + return outputArray; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"createBuffer", nullptr, CreateBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createBufferCopy", nullptr, CreateBufferCopy, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createExternalBuffer", nullptr, CreateExternalBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getBufferInfo", nullptr, GetBufferInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"isBuffer", nullptr, IsBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createExternalArraybuffer", nullptr, CreateExternalArraybuffer, 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..cdb09fd249e3b0b422550d1cc39d22d5e0249aa1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/Index.d.ts @@ -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. + */ + +export const createBuffer: () => string; // napi_create_buffer + +export const createBufferCopy: () => string; // napi_create_buffer_copy + +export const createExternalBuffer: () => string; // napi_create_external_buffer + +export const getBufferInfo: () => string; // napi_get_buffer_info + +export const isBuffer: () => boolean; // napi_is_buffer + +export const createExternalArraybuffer: () => ArrayBuffer | void; // napi_create_external_arraybuffer \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4383e4a33d4f91528389feb33d49fa3ea17b34d8 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiCreateBuffer', + '2.napiCreateBufferCopy', + '3.napiCreateExternalBuffer', + '4.napiGetBufferInfo', + '5.napiIsBuffer', + '6.napiCreateExternalArraybuffer' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiCreateBuffer') { + // napi_create_buffer + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_buffer: %{public}s', + testNapi.createBuffer().toString()); + this.result = 'napiCreateBufferSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_buffer error'); + this.result = 'napiCreateBufferFail'; + } + } else if (item === '2.napiCreateBufferCopy') { + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_buffer_copy: %{public}s', + testNapi.createBufferCopy().toString()); + this.result = 'napiCreateBufferCopySuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_buffer_copy error'); + this.result = 'napiCreateBufferCopyFail'; + } + } else if (item === '3.napiCreateExternalBuffer') { + // napi_create_external_buffer + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_external_buffer: %{public}s', + testNapi.createExternalBuffer() + .toString()); + this.result = 'napiCreateExternalBufferSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_external_buffer error'); + this.result = 'napiCreateExternalBufferFail'; + } + } else if (item === '4.napiGetBufferInfo') { + // napi_get_buffer_info + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_buffer_info: %{public}s', + testNapi.getBufferInfo().toString()); + this.result = 'napiGetBufferInfoSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_buffer_info error'); + this.result = 'napiGetBufferInfoFail'; + } + } else if (item === '5.napiIsBuffer') { + // napi_is_buffer + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_buffer: %{public}s', + JSON.stringify(testNapi.isBuffer())); + this.result = 'napiIsBufferSuccess'; + } catch (error) { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_buffer error'); + this.result = 'napiIsBufferFail'; + } + } else if (item === '6.napiCreateExternalArraybuffer') { + // napi_create_external_arraybuffer + hilog.info(0x0000, 'testTag', 'Node-API createExternalArraybuffer: %{public}s', + JSON.stringify(testNapi.createExternalArraybuffer())); + this.result = 'napiCreateExternalArraybufferSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/NodeAPIBuffer.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/NodeAPIBuffer.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/NodeAPIBuffer.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/NodeAPIBuffer.test.ets index e25baf1c960bd495730daf6f12893e54858f9777..c608ca72edcf03fde12279f9db752de5894a3c79 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/NodeAPIBuffer.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/ets/test/NodeAPIBuffer.test.ets @@ -1,140 +1,140 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIBufferTest() { - describe('nodeAPIBufferTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiCreateBuffer相关函数 - */ - it('testNodeAPIBuffer001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBuffer001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiCreateBuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateBufferSuccess')); - console.info('uitest: testNodeAPIBuffer001 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateBufferCopy相关函数 - */ - it('testNodeAPIBuffer002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBuffer002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCreateBufferCopy')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateBufferCopySuccess')); - console.info('uitest: testNodeAPIBuffer002 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateExternalBuffer相关函数 - */ - it('testNodeAPIBuffer003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBuffer003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiCreateExternalBuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateExternalBufferSuccess')); - console.info('uitest: testNodeAPIBuffer003 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetBufferInfo相关函数 - */ - it('testNodeAPIBuffer004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBuffer004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiGetBufferInfo')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetBufferInfoSuccess')); - console.info('uitest: testNodeAPIBuffer004 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsBuffer相关函数 - */ - it('testNodeAPIBuffer005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBuffer005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiIsBuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsBufferSuccess')); - console.info('uitest: testNodeAPIBuffer005 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateExternalArraybuffer相关函数 - */ - it('testNodeAPIBuffer006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIBuffer006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiCreateExternalArraybuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateExternalArraybufferSuccess')); - console.info('uitest: testNodeAPIBuffer006 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIBufferTest() { + describe('nodeAPIBufferTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiCreateBuffer相关函数 + */ + it('testNodeAPIBuffer001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBuffer001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiCreateBuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateBufferSuccess')); + console.info('uitest: testNodeAPIBuffer001 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateBufferCopy相关函数 + */ + it('testNodeAPIBuffer002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBuffer002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCreateBufferCopy')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateBufferCopySuccess')); + console.info('uitest: testNodeAPIBuffer002 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateExternalBuffer相关函数 + */ + it('testNodeAPIBuffer003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBuffer003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiCreateExternalBuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateExternalBufferSuccess')); + console.info('uitest: testNodeAPIBuffer003 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetBufferInfo相关函数 + */ + it('testNodeAPIBuffer004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBuffer004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiGetBufferInfo')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetBufferInfoSuccess')); + console.info('uitest: testNodeAPIBuffer004 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsBuffer相关函数 + */ + it('testNodeAPIBuffer005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBuffer005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiIsBuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsBufferSuccess')); + console.info('uitest: testNodeAPIBuffer005 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateExternalArraybuffer相关函数 + */ + it('testNodeAPIBuffer006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIBuffer006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiCreateExternalArraybuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateExternalArraybufferSuccess')); + console.info('uitest: testNodeAPIBuffer006 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeApiString/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigorfile.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/hvigorfile.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigorfile.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/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/NodeAPI/NodeApiUse/NodeAPIBuffer/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c07c6db136c67a301d748f49f904f6a121b74cb8 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/ohosTest.md @@ -0,0 +1,12 @@ +# 使用Node-API进行buffer相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ---------------------------------------------------- | ------------ | --------------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口createBuffer | 位于主页 | 点击文本为1.napiCreateBuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBufferSuccess | Pass | +| ArkTS端成功调用native侧接口createExternalBuffer | 位于主页 | 点击文本为2.napiCreateExternalBuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateExternalBufferSuccess | Pass | +| ArkTS端成功调用native侧接口getBufferInfo | 位于主页 | 点击文本为3.napiGetBufferInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetBufferInfoSuccess | Pass | +| ArkTS端成功调用native侧接口isBuffer | 位于主页 | 点击文本为4.napiIsBuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsBufferSuccess | Pass | +| ArkTS端成功调用native侧接口createExternalArraybuffer | 位于主页 | 点击文本为5.napiCreateExternalArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateExternalArraybufferSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIBuffer/screenshots/NodeAPIBuffer2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/.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/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..85431f44a1fc5e6e07c79ba9a7f25b0039de74b3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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.nodeapiclass", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..bb35b0f80cdbf2e7e15a3060bf4186ae669bcaa6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIClass" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/README.md new file mode 100644 index 0000000000000000000000000000000000000000..75df20dd5ec65634045b72aed7e3825718bf570c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行class相关开发 + +### 介绍 + +该工程主要展示了使用Node-API接口进行class相关开发,处理ArkTS中的类,例如定义类、构造实例等,其中代码详细描述可查如下链接。 + +- [使用Node-API进行class相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-class.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIClass.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行class相关开发 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIClass.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIClass/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e2ef75281e3f604cd53ac14a485e3e33690a870a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIClass) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..646bf143671ce9b2906d81d037352a3643ec32b7 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "napi/native_api.h" + +static constexpr int INT_ARG_18 = 18; // 入参索引 + +// [Start napi_new_instance] +// napi_new_instance +static napi_value NewInstance(napi_env env, napi_callback_info info) +{ + // 传入并解析参数,第一个参数为传入的构造函数,第二个参数为需要传入构造函数的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 调用napi_new_instance接口,实例化一个对象,将这个对象返回 + napi_value result = nullptr; + napi_new_instance(env, args[0], 1, &args[1], &result); + return result; +} +// [End napi_new_instance] + +// [Start napi_wrap_unwrap_remove_wrap] +struct Object { + std::string name; + int32_t age; +}; + +static void DerefItem(napi_env env, void *data, void *hint) +{ + // 可选的原生回调,用于在ArkTS对象被垃圾回收时释放原生实例 + OH_LOG_INFO(LOG_APP, "Node-API DerefItem"); + (void)hint; +} + +// napi_wrap +static napi_value Wrap(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "Node-API wrap"); + // 初始化Node-API模块的object + struct Object *obj = new struct Object(); + obj->name = "lilei"; + obj->age = INT_ARG_18; + size_t argc = 1; + napi_value toWrap; + // 调用napi_wrap将Node-API模块的object绑定到ArkTS object上 + napi_get_cb_info(env, info, &argc, &toWrap, NULL, NULL); + napi_wrap(env, toWrap, reinterpret_cast(obj), DerefItem, NULL, NULL); + + return toWrap; +} + +// napi_remove_wrap +static napi_value RemoveWrap(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "Node-API removeWrap"); + size_t argc = 1; + napi_value wrapped = nullptr; + void *data = nullptr; + // 调用napi_remove_wrap从一个被包装的对象中解除包装 + napi_get_cb_info(env, info, &argc, &wrapped, nullptr, nullptr); + napi_remove_wrap(env, wrapped, &data); + + return nullptr; +} + +// napi_unwrap +static napi_value UnWrap(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "Node-API unWrap"); + size_t argc = 1; + napi_value wrapped = nullptr; + napi_get_cb_info(env, info, &argc, &wrapped, nullptr, nullptr); + // 调用napi_unwrap取出绑定在ArkTS object中的数据并打印 + struct Object *data; + napi_unwrap(env, wrapped, reinterpret_cast(&data)); + OH_LOG_INFO(LOG_APP, "Node-API name: %{public}s", data->name.c_str()); + OH_LOG_INFO(LOG_APP, "Node-API age: %{public}d", data->age); + return nullptr; +} +// [End napi_wrap_unwrap_remove_wrap] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"newInstance", nullptr, NewInstance, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"wrap", nullptr, Wrap, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"removeWrap", nullptr, RemoveWrap, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"unWrap", nullptr, UnWrap, 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..afe70ce8263004f35fffdb5062ef491ca0b74c31 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts @@ -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. + */ + +// [Start napi_new_instance_api] +export const newInstance: (obj: Object, param: string) => Object // napi_new_instance +// [End napi_new_instance_api] + +// [Start napi_wrap_unwrap_remove_wrap_api] +export const wrap: (obj: Object) => Object; // napi_wrap + +export const unWrap: (obj: Object) => void; // napi_unwrap + +export const removeWrap: (obj: Object) => void; // napi_remove_wrap +// [End napi_wrap_unwrap_remove_wrap_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4af3327267d743c64cd12b910ebaede1af310c5e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,99 @@ +/* + * 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'; + +// [Start ark_napi_new_instance] +class Fruit { + name: string; + + constructor(name: string) { + this.name = name; + } +} + +// [StartExclude ark_napi_new_instance] +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiNewInstance', + '2.napiRemoveWrap' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(25) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiNewInstance') { + // [EndExclude ark_napi_new_instance] + // napi_new_instance + // 调用函数,用变量obj接收函数返回的实例化对象 + let obj = testNapi.newInstance(Fruit, 'test'); + // 打印实例化对象obj的信息 + hilog.info(0x0000, 'Node-API', 'napi_new_instance %{public}s', JSON.stringify(obj)); + // [End ark_napi_new_instance] + this.result = 'napiNewInstanceSuccess'; + } else if (item === '2.napiRemoveWrap') { + // [Start ark_napi_wrap_unwrap_remove_wrap] + try { + class Obj { + } + + let obj: Obj = {}; + testNapi.wrap(obj) // napi_wrap + testNapi.unWrap(obj) // napi_unwrap + testNapi.removeWrap(obj) // napi_remove_wrap + // [StartExclude ark_napi_wrap_unwrap_remove_wrap] + this.result = 'napiRemoveWrapSuccess'; + // [EndExclude ark_napi_wrap_unwrap_remove_wrap] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API error: %{public}s', error.message); + // [StartExclude ark_napi_wrap_unwrap_remove_wrap] + this.result = 'napiRemoveWrapFail'; + // [EndExclude ark_napi_wrap_unwrap_remove_wrap] + } + // [End ark_napi_wrap_unwrap_remove_wrap] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/NodeAPIClass.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/NodeAPIClass.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/NodeAPIClass.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/NodeAPIClass.test.ets index 196d2e9397631ae4519c4016ba4419e28d2c14e0..a49158997376f4bc4f3cc56a62875bec0ef4440a --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/NodeAPIClass.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/ets/test/NodeAPIClass.test.ets @@ -1,76 +1,76 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIClassTest() { - describe('nodeAPIClassTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiNewInstance相关函数 - */ - it('testNodeAPIClass001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIClass001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiNewInstance')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiNewInstanceSuccess')); - console.info('uitest: testNodeAPIClass001 end'); - done(); - }) - - /** - * 点击按钮,调用napiRemoveWrap相关函数 - */ - it('testNodeAPIClass002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIClass002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiRemoveWrap')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiRemoveWrapSuccess')); - console.info('uitest: testNodeAPIClass002 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIClassTest() { + describe('nodeAPIClassTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiNewInstance相关函数 + */ + it('testNodeAPIClass001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIClass001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiNewInstance')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiNewInstanceSuccess')); + console.info('uitest: testNodeAPIClass001 end'); + done(); + }) + + /** + * 点击按钮,调用napiRemoveWrap相关函数 + */ + it('testNodeAPIClass002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIClass002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiRemoveWrap')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiRemoveWrapSuccess')); + console.info('uitest: testNodeAPIClass002 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/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/NodeAPI/NodeApiUse/NodeAPIClass/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..dcc1bfe10bccb914e2d0bdcff7e6583454422c86 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/ohosTest.md @@ -0,0 +1,9 @@ +# 使用Node-API进行class相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------- | ------------ | ------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口newInstance | 位于主页 | 点击文本为1.napiNewInstance的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiNewInstanceSuccess | Pass | +| ArkTS端成功调用native侧接口wrap,unWrap,removeWrap | 位于主页 | 点击文本为2.napiRemoveWrap的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveWrapSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIClass/screenshots/NodeAPIClass2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/.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/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b633624a3b888709d30c16424f1f40a64ce266bb --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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.nodeapicleanuphook", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c29b6d22df62f38ea4476aea401be08f182a15d1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPICleanuphook" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bcd6d07107e57da41dc6eec60a83c38ed981807a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API进行cleanuphook相关开发 + +### 介绍 + +使用Node-API接口在进程退出时处理未释放资源,在Node-API模块注册清理钩子,一旦当前环境退出,这些钩子就会运行,使所有资源都被正确释放。 + +本工程主要展示了使用Node-API注册钩子函数、取消钩子函数等场景,其中代码详细描述可查如下链接。 + +- [使用Node-API进行cleanuphook相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-cleanuphook.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPICleanuphook.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行cleanuphook相关开发 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPICleanuphook.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f2183d9fd75e928522f580e921ea9ccc4903a780 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/build-profile.json5 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + }, + "sourceOption": { + "workers": [ + "./src/main/ets/workers/worker.ts" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..65ee02bda50fd000682086c26fcf3a412ab717f8 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPICleanuphook) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libuv.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65368b76173f7f77f68ed20ab3c75621c56c1e68 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_remove_add_env_cleanup_hook] +#include +#include +#include +#include "napi/native_api.h" +#include "uv.h" + +// 定义内存结构,包含指向数据的指针和数据的大小 +typedef struct { + char *data; + size_t size; +} Memory; + +// 外部缓冲区清理回调函数,用于释放分配的内存 +void ExternalFinalize(napi_env env, void *finalizeData, void *finalizeHint) +{ + Memory *wrapper = (Memory *)finalizeHint; + // [StartExclude napi_remove_add_env_cleanup_hook] + if (wrapper == nullptr) { + //处理内存分配失败的情况 + return; + } + // [EndExclude napi_remove_add_env_cleanup_hook] + free(wrapper->data); + free(wrapper); + OH_LOG_INFO(LOG_APP, "Node-API napi_add_env_cleanup_hook ExternalFinalize"); +} + +// 在环境关闭时执行一些清理操作,如清理全局变量或其他需要在环境关闭时处理的资源 +static void Cleanup(void *arg) +{ + // 执行清理操作 + OH_LOG_INFO(LOG_APP, "Node-API napi_add_env_cleanup_hook cleanuped: %{public}d", *(int *)(arg)); +} + +// 创建外部缓冲区并注册环境清理钩子函数 +static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) +{ + // 分配内存并复制字符串数据到内存中 + std::string str("Hello from Node-API!"); + Memory *wrapper = (Memory *)malloc(sizeof(Memory)); + // [StartExclude napi_remove_add_env_cleanup_hook] + if (wrapper == nullptr) { + //处理内存分配失败的情况 + return nullptr; + } + // [End napi_remove_add_env_cleanup_hook] + wrapper->data = static_cast(malloc(str.size())); + strcpy(wrapper->data, str.c_str()); + wrapper->size = str.size(); + // 创建外部缓冲区对象,并指定清理回调函数 + napi_value buffer = nullptr; + napi_create_external_buffer(env, wrapper->size, (void *)wrapper->data, ExternalFinalize, wrapper, &buffer); + // 静态变量作为钩子函数参数 + static int hookArg = 42; + static int hookParameter = 1; + // 注册环境清理钩子函数 + napi_status status = napi_add_env_cleanup_hook(env, Cleanup, &hookArg); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Test Node-API napi_add_env_cleanup_hook failed."); + return nullptr; + } + // 注册环境清理钩子函数,此处不移除环境清理钩子,为了在Java环境被销毁时,这个钩子函数被调用,用来模拟执行一些清理操作,例如释放资源、关闭文件等。 + status = napi_add_env_cleanup_hook(env, Cleanup, &hookParameter); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Test Node-API napi_add_env_cleanup_hook failed."); + return nullptr; + } + // 立即移除环境清理钩子函数,确保不会在后续环境清理时被调用 + // 通常,当为其添加此钩子的资源无论如何都被拆除时调用这个接口 + napi_remove_env_cleanup_hook(env, Cleanup, &hookArg); + // 返回创建的外部缓冲区对象 + return buffer; +} +// [End napi_remove_add_env_cleanup_hook] + +// [Start napi_add_remove_async_cleanup_hook] +typedef struct { + napi_env env; + void *testData; + uv_async_s asyncUv; + napi_async_cleanup_hook_handle cleanupHandle; +} AsyncContent; + +// 删除异步工作对象并注销钩子函数 +static void FinalizeWork(uv_handle_s *handle) +{ + AsyncContent *asyncData = reinterpret_cast(handle->data); + // 不再需要异步清理钩子函数的情况下,尝试将其从环境中移除 + napi_status result = napi_remove_async_cleanup_hook(asyncData->cleanupHandle); + if (result != napi_ok) { + napi_throw_error(asyncData->env, nullptr, "Test Node-API napi_remove_async_cleanup_hook failed"); + } + // 释放AsyncContent + free(asyncData); +} + +// 异步执行环境清理工作 +static void AsyncWork(uv_async_s *async) +{ + // 执行一些清理工作,比如释放动态分配的内存 + AsyncContent *asyncData = reinterpret_cast(async->data); + if (asyncData->testData != nullptr) { + free(asyncData->testData); + asyncData->testData = nullptr; + } + // 关闭libuv句柄,并触发FinalizeWork回调清理 + uv_close((uv_handle_s *)async, FinalizeWork); +} + +// 异步清理钩子函数,创建异步工作对象并执行 +static void AsyncCleanup(napi_async_cleanup_hook_handle handle, void *info) +{ + AsyncContent *data = reinterpret_cast(info); + // 获取libUv循环实例并初始化一个异步句柄,以便后续执行异步工作 + uv_loop_s *uvLoop; + napi_get_uv_event_loop(data->env, &uvLoop); + uv_async_init(uvLoop, &data->asyncUv, AsyncWork); + + data->asyncUv.data = data; + data->cleanupHandle = handle; + // 发送异步信号触发AsyncWork函数执行清理工作 + uv_async_send(&data->asyncUv); +} + +static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) +{ + // 分配AsyncContent内存 + AsyncContent *data = reinterpret_cast(malloc(sizeof(AsyncContent))); + // StartExclude napi_add_remove_async_cleanup_hook] + if (data == nullptr) { + //处理内存分配失败的情况 + return nullptr; + } + // [EndExclude napi_add_remove_async_cleanup_hook] + data->env = env; + data->cleanupHandle = nullptr; + // 分配内存并复制字符串数据 + const char *testDataStr = "TestNapiAsyncCleanUpHook"; + data->testData = strdup(testDataStr); + if (data->testData == nullptr) { + napi_throw_error(env, nullptr, "Test Node-API data->testData is nullptr"); + } + // 添加异步清理钩子函数 + napi_status status = napi_add_async_cleanup_hook(env, AsyncCleanup, data, &data->cleanupHandle); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Test Node-API napi_add_async_cleanup_hook failed"); + } + napi_value result = nullptr; + napi_get_boolean(env, true, &result); + return result; +} +// [End napi_add_remove_async_cleanup_hook] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"napiEnvCleanUpHook", nullptr, NapiEnvCleanUpHook, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiAsyncCleanUpHook", nullptr, NapiAsyncCleanUpHook, 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3eb2054062f7f535639b798a09b80ab9cf2e2d9a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_remove_add_env_cleanup_hook_api] +export const napiEnvCleanUpHook: () => Object | void; +// [End napi_remove_add_env_cleanup_hook_api] + +// [Start napi_add_remove_async_cleanup_hook_api] +export const napiAsyncCleanUpHook: () => boolean | void; +// [End napi_add_remove_async_cleanup_hook_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..28e1689452486c68ce0b379850c18c45b1313d2c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import worker from '@ohos.worker'; +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State result: string = ''; + private items: string[] = [ + 'Reset Result Message', + '1.napiRemoveEnvCleanupHook', + '2.napiRemoveAsyncCleanupHook' + ]; + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiRemoveEnvCleanupHook') { + // [Start connect_with_worker] + let wk = new worker.ThreadWorker('entry/ets/workers/worker.ts'); + // 发送消息到worker线程 + wk.postMessage('test NapiEnvCleanUpHook'); + // 处理来自worker线程的消息 + wk.onmessage = (message) => { + hilog.info(0x0000, 'testTag', 'Test Node-API message from worker: %{public}s', + JSON.stringify(message)); + wk.terminate(); + }; + // [End connect_with_worker] + this.result = 'napiRemoveEnvCleanupHookSuccess'; + } else if (item === '2.napiRemoveAsyncCleanupHook') { + // [Start ark_napi_remove_add_env_cleanup_hook] + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook: %{public}s', + testNapi.napiAsyncCleanUpHook()); + // [StartExclude ark_napi_remove_add_env_cleanup_hook] + this.result = 'napiRemoveAsyncCleanupHookSuccess'; + // [EndExclude ark_napi_remove_add_env_cleanup_hook] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_add_async_cleanup_hook error.message: %{public}s', + error.message); + // [StartExclude ark_napi_remove_add_env_cleanup_hook] + this.result = 'napiRemoveAsyncCleanupHookFail'; + // [EndExclude ark_napi_remove_add_env_cleanup_hook] + } + // [End ark_napi_remove_add_env_cleanup_hook] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/workers/worker.ts diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/NodeAPICleanuphook.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/NodeAPICleanuphook.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/NodeAPICleanuphook.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/NodeAPICleanuphook.test.ets index d37ce1a0b300c4ff88ba390527bccf328d58bdbe..52eb13f571aeb81f9b37691849a2caf4c6f3baa9 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/NodeAPICleanuphook.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/ets/test/NodeAPICleanuphook.test.ets @@ -1,76 +1,76 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPICleanUpHookTest() { - describe('nodeAPICleanUpHookTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiRemoveEnvCleanupHook相关函数 - */ - it('testNodeAPICleanUpHook001', 0, async (done: Function) => { - console.info('uitest: testNodeAPICleanUpHook001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiRemoveEnvCleanupHook')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiRemoveEnvCleanupHookSuccess')); - console.info('uitest: testNodeAPICleanUpHook001 end'); - done(); - }) - - /** - * 点击按钮,调用napiRemoveAsyncCleanupHook相关函数 - */ - it('testNodeAPICleanUpHook002', 0, async (done: Function) => { - console.info('uitest: testNodeAPICleanUpHook002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiRemoveAsyncCleanupHook')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiRemoveAsyncCleanupHookSuccess')); - console.info('uitest: testNodeAPICleanUpHook002 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPICleanUpHookTest() { + describe('nodeAPICleanUpHookTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiRemoveEnvCleanupHook相关函数 + */ + it('testNodeAPICleanUpHook001', 0, async (done: Function) => { + console.info('uitest: testNodeAPICleanUpHook001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiRemoveEnvCleanupHook')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiRemoveEnvCleanupHookSuccess')); + console.info('uitest: testNodeAPICleanUpHook001 end'); + done(); + }) + + /** + * 点击按钮,调用napiRemoveAsyncCleanupHook相关函数 + */ + it('testNodeAPICleanUpHook002', 0, async (done: Function) => { + console.info('uitest: testNodeAPICleanUpHook002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiRemoveAsyncCleanupHook')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiRemoveAsyncCleanupHookSuccess')); + console.info('uitest: testNodeAPICleanUpHook002 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/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/NodeAPI/NodeApiUse/NodeAPICleanuphook/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..ad29bd34c0c4af8e174c7b1d4cd81a5c9639776a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/ohosTest.md @@ -0,0 +1,9 @@ +# 使用Node-API进行cleanuphook相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ----------------------------------------------- | ------------ | ------------------------------------------------ | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口napiEnvCleanUpHook | 位于主页 | 点击文本为1.napiRemoveEnvCleanupHook的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveEnvCleanupHookSuccess | Pass | +| ArkTS端成功调用native侧接口napiAsyncCleanUpHook | 位于主页 | 点击文本为2.napiRemoveAsyncCleanupHook的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveAsyncCleanupHookSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPICleanuphook/screenshots/NodeAPICleanuphook2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/.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/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fa13ae7af0de08d35169bb9696ba811f33549083 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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.nodeapidate", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6494c478d05fdf40ac19263be4e5888c720bddd6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIDate" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9309937e1b31eb8b58b078b419683cb9546804ad --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行Date相关开发 + +### 介绍 + +Node-API中date相关接口用于处理ArkTS Date对象,并在Node-API模块和ArkTS代码之间进行日期数据的转换和处理。这对于在Node-API模块中处理时间和日期相关逻辑非常有用,工程中展示的代码详细描述可查如下链接。 + +- [使用Node-API进行Date相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-date.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIDate.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行Date相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIDate.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIDate/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2730fd3d239aab7d27310420f9c63c947b00abc2 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIDate) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..929ee77210c88d35d2a902fec057ec91ef06a5ba --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_create_date] +#include +#include "napi/native_api.h" + +// napi_create_date +static napi_value CreateDate(napi_env env, napi_callback_info info) +{ + // 获取传入的Unix Time Stamp时间 + double value = 1501924876711; + // 调用napi_create_date接口将double值转换成表示日期时间,并创建成一个ArkTS对象放入returnValue中 + napi_value returnValue = nullptr; + napi_create_date(env, value, &returnValue); + return returnValue; +} +// [End napi_create_date] + +// [Start napi_get_date_value] +// napi_get_date_value +static napi_value GetDateValue(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取传入的Unix Time Stamp时间 + double value = 0; + napi_status status = napi_get_date_value(env, args[0], &value); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_get_date_value fail"); + return nullptr; + } + + // 将获取到的Unix Time Stamp时间打印 + OH_LOG_INFO(LOG_APP, "Node-API gets unix time stamp is:%{public}lf.", value); + + // 把转换后的Unix Time Stamp时间创建成ArkTS double数值,并放入returnValue中 + napi_value returnValue = nullptr; + napi_create_double(env, value, &returnValue); + return returnValue; +} +// [End napi_get_date_value] + +// [Start napi_is_date] +// napi_is_date +static napi_value IsDate(napi_env env, napi_callback_info info) +{ + // 接受一个入参 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 调用napi_is_date接口判断给定入参是否为Date数据 + bool result = false; + napi_status status = napi_is_date(env, args[0], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_is_date fail"); + return nullptr; + } + // 将结果转成napi_value类型返回 + napi_value returnValue = nullptr; + napi_get_boolean(env, result, &returnValue); + + return returnValue; +} +// [End napi_is_date] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"createDate", nullptr, CreateDate, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getDateValue", nullptr, GetDateValue, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"isDate", nullptr, IsDate, 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..487a558af13526058c0d2e4e6ee2b401bf5c7142 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts @@ -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. + */ + +// [Start napi_create_date_api] +export const createDate: () => Date; // napi_create_date +// [End napi_create_date_api] + +// [Start napi_get_date_value_api] +export const getDateValue: (date: Date) => number | void; // napi_get_date_value +// [End napi_get_date_value_api] + +// [Start napi_is_date_api] +export const isDate: (date: T) => boolean | void; // napi_is_date +// [End napi_is_date_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1b434882378743dbf1e989b537bbc0d0609389ab --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,105 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiCreateDate', + '2.napiGetDateValue', + '3.napiIsDate' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(25) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiCreateDate') { + // [Start ark_napi_create_date] + // napi_create_date + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_date: %{public}s', + testNapi.createDate().toString()); + // [End ark_napi_create_date] + this.result = 'napiCreateDateSuccess'; + } else if (item === '2.napiGetDateValue') { + // [Start ark_napi_get_date_value] + // napi_get_date_value + try { + const date = new Date(); + hilog.info(0x0000, 'testTag', 'Node-API: output the Unix Time Stamp: %{public}d', date.getTime()); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_date_value: %{public}d', + testNapi.getDateValue(date)); + // [StartExclude ark_napi_get_date_value] + this.result = 'napiGetDateValueSuccess'; + // [EndExclude ark_napi_get_date_value] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_date_value error: %{public}s', + error.message); + // [StartExclude ark_napi_get_date_value] + this.result = 'napiGetDateValueFail'; + // [EndExclude ark_napi_get_date_value] + } + // [End ark_napi_get_date_value] + } else if (item === '3.napiIsDate') { + // [Start ark_napi_is_date] + // napi_is_date + try { + let now: Date = new Date(); + let date = "123"; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(now)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(date)); + // [StartExclude ark_napi_is_date] + this.result = 'napiIsDateSuccess'; + // [EndExclude ark_napi_is_date] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_date error: %{public}s', error.message); + // [StartExclude ark_napi_is_date] + this.result = 'napiIsDateFail'; + // [EndExclude ark_napi_is_date] + } + // [End ark_napi_is_date] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/NodeAPIDate.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/NodeAPIDate.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/NodeAPIDate.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/NodeAPIDate.test.ets index 876fec5e8d08a53c414e1bb21c6347365b2cb731..be15ef45481ff447df8314033097e7da0f08a6e3 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/NodeAPIDate.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/ets/test/NodeAPIDate.test.ets @@ -1,92 +1,92 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIDateTest() { - describe('nodeAPIDateTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiCreateDate相关函数 - */ - it('testNodeAPIDate001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIDate001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiCreateDate')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateDateSuccess')); - console.info('uitest: testNodeAPIDate001 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetDateValue相关函数 - */ - it('testNodeAPIDate002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIDate002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiGetDateValue')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetDateValueSuccess')); - console.info('uitest: testNodeAPIDate002 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsDate相关函数 - */ - it('testNodeAPIDate003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIDate003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiIsDate')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsDateSuccess')); - console.info('uitest: testNodeAPIDate003 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIDateTest() { + describe('nodeAPIDateTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiCreateDate相关函数 + */ + it('testNodeAPIDate001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIDate001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiCreateDate')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateDateSuccess')); + console.info('uitest: testNodeAPIDate001 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetDateValue相关函数 + */ + it('testNodeAPIDate002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIDate002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiGetDateValue')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetDateValueSuccess')); + console.info('uitest: testNodeAPIDate002 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsDate相关函数 + */ + it('testNodeAPIDate003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIDate003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiIsDate')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsDateSuccess')); + console.info('uitest: testNodeAPIDate003 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/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/NodeAPI/NodeApiUse/NodeAPIDate/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..65f673412429e16fd63378eb8a61b4637c2e560d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/ohosTest.md @@ -0,0 +1,10 @@ +# 使用Node-API进行date相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| --------------------------------------- | ------------ | -------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口createDate | 位于主页 | 点击文本为1.napiCreateDate的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateDateSuccess | Pass | +| ArkTS端成功调用native侧接口getDateValue | 位于主页 | 点击文本为2.napiGetDateValue的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetDateValueSuccess | Pass | +| ArkTS端成功调用native侧接口isDate | 位于主页 | 点击文本为3.napiIsDate的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsDateSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIDate/screenshots/NodeAPIDate2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/.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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a932871591370123c0453a57642ba17998e0d066 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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.nodeapienvironmentallifecycle", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..284c1c7cb89d9d81b020cdd60e7ec355016dc4a4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIEnvironmentalLifeCycle" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/README.md new file mode 100644 index 0000000000000000000000000000000000000000..da3acf2b58411e84bec327f5b97bf0ac2198425c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行environmental-life-cycle相关开发 + +### 介绍 + +在Node-API模块中,可以使用Node-API接口将特定数据与当前的环境相关联,并在需要时检索该数据,本工程主要展示绑定和检索与当前运行环境相关联的数据项,其中代码详细描述可查如下链接。 + +- [使用Node-API进行environmental-life-cycle相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-environmental-life-cycle.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| :----------------------------------------------------------- | :----------------------------------------------------------- | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIEnvironmentalLifeCycle.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行environmental-life-cycle相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIEnvironmentalLifeCycle.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..59ead807ce33211de6fc982e7bd61261b4138158 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIEnviornmentalLifeCycle) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1fd25dbe91fce7d065490ed414ba56c4a408237b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_set_instance_data] +#include +#include "napi/native_api.h" + +// 定义一个结构来存储实例数据 +struct InstanceData { + int32_t value; +}; + +// 对象被释放时的回调函数,用于清理实例数据 +void FinalizeCallback(napi_env env, void *finalizeData, void *finalizeHint) +{ + if (finalizeData) { + InstanceData *data = reinterpret_cast(finalizeData); + // 释放内存,清除指针指向地址 + delete (data); + *(InstanceData **)finalizeData = nullptr; + } +} + +// napi_set_instance_data +static napi_value SetInstanceData(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + int32_t instanceDataValue; + napi_get_value_int32(env, argv[0], &instanceDataValue); + InstanceData *instanceData = new InstanceData; + instanceData->value = instanceDataValue; + // 调用napi_set_instance_data将实例数据关联到Node-API环境,并指定FinalizeCallback函数 + napi_status status = napi_set_instance_data(env, instanceData, FinalizeCallback, nullptr); + bool success = true; + napi_value result; + if (status == napi_ok) { + napi_get_boolean(env, success, &result); + } + return result; +} +// [End napi_set_instance_data] + +// [Start napi_get_instance_data] +// napi_get_instance_data +static napi_value GetInstanceData(napi_env env, napi_callback_info info) +{ + InstanceData *resData = nullptr; + // napi_get_instance_data获取之前想关联的数据项 + napi_get_instance_data(env, (void **)&resData); + napi_value result; + napi_create_int32(env, resData->value, &result); + return result; +} +// [End napi_get_instance_data] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"setInstanceData", nullptr, SetInstanceData, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getInstanceData", nullptr, GetInstanceData, 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..11b146eb4a61230afd9c61ab61302a3aabad3a80 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_set_instance_data_api] +export const setInstanceData: (data: number) => boolean; // napi_set_instance_data +// [End napi_set_instance_data_api] + +// [Start napi_get_instance_data_api] +export const getInstanceData: () => number; // napi_get_instance_data +// [End napi_get_instance_data_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..83c5f014121234d77f4e0ae68ec89a126aef1970 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,77 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiSetInstanceData', + '2.napiGetInstanceData' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(22) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiSetInstanceData') { + // [Start ark_napi_set_instance_data] + // napi_set_instance_data + let data = 5; + let value = testNapi.setInstanceData(data); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}s', value); + // [End ark_napi_set_instance_data] + this.result = 'napiSetInstanceDataSuccess'; + } else if (item === '2.napiGetInstanceData') { + // [Start ark_napi_get_instance_data] + // napi_get_instance_data + let data = 5; + testNapi.setInstanceData(data); + let value = testNapi.getInstanceData(); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}d', value); + // [End ark_napi_get_instance_data] + this.result = 'napiGetInstanceDataSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/NodeAPIEnvironmentalLifeCycle.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/NodeAPIEnvironmentalLifeCycle.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/NodeAPIEnvironmentalLifeCycle.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/NodeAPIEnvironmentalLifeCycle.test.ets index e26b8bde87769ab24d44fdabe745a7932d8b1b9d..52e7cf03ffa1b9fc09bb5b913f3ae3539605032b --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/NodeAPIEnvironmentalLifeCycle.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/ets/test/NodeAPIEnvironmentalLifeCycle.test.ets @@ -1,76 +1,76 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIEnvironmentalLifeCycleTest() { - describe('nodeAPIEnvironmentalLifeCycleTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiSetInstanceData相关函数 - */ - it('testNodeAPIEnvironmentalLifeCycle001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIEnvironmentalLifeCycle001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiSetInstanceData')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiSetInstanceDataSuccess')); - console.info('uitest: testNodeAPIEnvironmentalLifeCycle001 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetInstanceData相关函数 - */ - it('testNodeAPIEnvironmentalLifeCycle002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIEnvironmentalLifeCycle002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiGetInstanceData')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetInstanceDataSuccess')); - console.info('uitest: testNodeAPIEnvironmentalLifeCycle002 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIEnvironmentalLifeCycleTest() { + describe('nodeAPIEnvironmentalLifeCycleTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiSetInstanceData相关函数 + */ + it('testNodeAPIEnvironmentalLifeCycle001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIEnvironmentalLifeCycle001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiSetInstanceData')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiSetInstanceDataSuccess')); + console.info('uitest: testNodeAPIEnvironmentalLifeCycle001 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetInstanceData相关函数 + */ + it('testNodeAPIEnvironmentalLifeCycle002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIEnvironmentalLifeCycle002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiGetInstanceData')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetInstanceDataSuccess')); + console.info('uitest: testNodeAPIEnvironmentalLifeCycle002 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..0d3d2bb4a4a68e34037dbfec6a10d01c3b88e3fe --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/ohosTest.md @@ -0,0 +1,9 @@ +# 使用Node-API进行environmental-life-cycle相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| --------------------------------------------- | ------------ | ----------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 setInstanceData | 位于主页 | 点击文本为1.napiSetInstanceData的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetInstanceDataSuccess | Pass | +| ArkTS端成功调用native侧接口getInstanceData | 位于主页 | 点击文本为2.napiGetInstanceData的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetInstanceDataSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/screenshots/NodeAPIEnvironmentalLifeCycle2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/.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/NodeAPI/NodeApiUse/NodeAPIError/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5e4fc240f9ca92b571d9ed42fd959d4067d49f36 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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.nodeapierror", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7863ec920dcfbc4284eb209e1a8a4e6d27c5cdfb --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIError" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e6f0304bc6527c7bc0551704a0590da04abb0a9d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行错误处理开发 + +### 介绍 + +使用Node-API接口进行错误处理开发,使得在Node-API模块中能够更好地管理和响应错误情况。通过合理使用这些函数,可以提高模块的稳定性和可靠性,本工程主要展示使用Node-API进行创建错误对象并抛出、获取错误对象、检查napi_value是否代表错误对象和抛出致命异常终止进程等场景,其中代码详细描述可查如下链接。 + +- [使用Node-API进行错误处理开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-error.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIError.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行错误处理开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIError.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIError/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..42d85db3cb485ea74bdc8e2df3dd55dc39f77e27 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIError) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea24d692ae5bee3cb885b2bd36ac1e975c3a2ed4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,324 @@ +/* + * 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 "hilog/log.h" +#include "napi/native_api.h" + +// [Start napi_get_last_error_info] +// napi_get_last_error_info +static napi_value GetLastErrorInfo(napi_env env, napi_callback_info info) +{ + // 获取输入参数(这里以字符串message作为参数传入) + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将传入的字符串参数以napi_get_value_int32取出,主动制造错误 + int32_t value = 0; + napi_status status = napi_get_value_int32(env, args[0], &value); + // 接口使用错误,故返回值不为napi_ok + if (status != napi_ok) { + OH_LOG_INFO(LOG_APP, "napi_get_value_int32 return status, status is not equal to napi_ok."); + } + // 调用接口napi_get_last_error_info获取最后一次错误信息 + const napi_extended_error_info *errorInfo; + napi_get_last_error_info(env, &errorInfo); + // 取出错误码与接口调用错误后其返回值作比较 + if (errorInfo->error_code == status) { + OH_LOG_INFO(LOG_APP, "napi_get_last_error_info return errorInfo, error_code equal to status."); + } + // 取出错误消息作为返回值带出去打印 + napi_value result = nullptr; + napi_create_string_utf8(env, errorInfo->error_message, NAPI_AUTO_LENGTH, &result); + return result; +} +// [End napi_get_last_error_info] + +// [Start napi_create_type_error] +// napi_create_type_error +static napi_value CreatTypeError(napi_env env, napi_callback_info info) +{ + // 构造errorCode和errorMessage + napi_value errorCode = nullptr; + napi_create_string_utf8(env, "napi_create_error errorCode", NAPI_AUTO_LENGTH, &errorCode); + napi_value errorMessage = nullptr; + napi_create_string_utf8(env, "napi_create_error errorMessage", NAPI_AUTO_LENGTH, &errorMessage); + // 调用napi_create_type_error创建一个typeError错误对象 + napi_value error = nullptr; + napi_create_type_error(env, errorCode, errorMessage, &error); + return error; +} +// [End napi_create_type_error] + +// [Start napi_create_range_error] +// napi_create_range_error +static napi_value CreatRangeError(napi_env env, napi_callback_info info) +{ + // 构造errorCode和errorMessage + napi_value errorCode = nullptr; + napi_create_string_utf8(env, "napi_create_error errorCode", NAPI_AUTO_LENGTH, &errorCode); + napi_value errorMessage = nullptr; + napi_create_string_utf8(env, "napi_create_error errorMessage", NAPI_AUTO_LENGTH, &errorMessage); + // 调用napi_create_range_error创建一个typeError错误对象 + napi_value error = nullptr; + napi_create_range_error(env, errorCode, errorMessage, &error); + return error; +} +// [End napi_create_range_error] + +// [Start napi_create_error] +// napi_create_error and napi_throw +static napi_value NapiThrow(napi_env env, napi_callback_info info) +{ + // 代码中发生某些错误后,可执行以下操作抛出异常 + // 在Node-API环境中创建一个字符串,并将其存储在errorCode变量中 + napi_value errorCode = nullptr; + napi_create_string_utf8(env, "throw errorCode", NAPI_AUTO_LENGTH, &errorCode); + // 在Node-API环境中创建一个字符串,并将其存储在errorMessage变量中 + napi_value errorMessage = nullptr; + napi_create_string_utf8(env, "throw errorMessage", NAPI_AUTO_LENGTH, &errorMessage); + // 创建一个ArkTS对象error + napi_value error = nullptr; + napi_create_error(env, errorCode, errorMessage, &error); + // 通过napi_throw接口将对象抛出 + napi_throw(env, error); + return nullptr; +} +// [End napi_create_error] + +// [Start napi_throw_error] +// napi_throw_error +// 这里直接抛出一个带有errorMessage的错误 +static napi_value NapiThrowErrorMessage(napi_env env, napi_callback_info info) +{ + napi_throw_error(env, nullptr, "napi_throw_error throwing an error"); + return nullptr; +} + +// 传入两个参数,在第二个参数,也就是除数为0的时候抛出一个错误 +static napi_value NapiThrowError(napi_env env, napi_callback_info info) +{ + // ArkTS侧传入两个参数 + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 将其转换为double类型的值作为被除数和除数 + double dividend; + double divisor; + napi_get_value_double(env, argv[0], ÷nd); + napi_get_value_double(env, argv[1], &divisor); + // 在这里判断除数如果为0则直接抛出一个错误,errorCode为:DIVIDE_BY_ZERO,errorMessage为:Cannot divide by zero + if (divisor == 0) { + napi_throw_error(env, "DIVIDE_BY_ZERO", "Cannot divide by zero"); + } + return nullptr; +} +// [End napi_throw_error] + +// [Start napi_throw_type_error] +// napi_throw_type_error +// 这里直接抛出一个带有errorMessage的TypeError +static napi_value ThrowTypeErrorMessage(napi_env env, napi_callback_info info) +{ + napi_throw_type_error(env, nullptr, "napi_throw_type_error throwing an error"); + return nullptr; +} + +// 传入一个类型不匹配的参数,判断类型不匹配之后抛出typeError +static napi_value ThrowTypeError(napi_env env, napi_callback_info info) +{ + // ArkTS侧传入一个参数 + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 将传入参数转换为napi_valuetype类型的值 + napi_valuetype valueType; + napi_typeof(env, argv[0], &valueType); + // 如果传入参数不为napi_number类型的值则抛出TypeError + if (valueType != napi_number) { + // 这里抛出一个既带有errorCode也带有errorMessage的TypeError + napi_throw_type_error(env, "napi_throw_type_error", "Argument must be a number"); + } + return nullptr; +} +// [End napi_throw_type_error] + +// [Start napi_throw_range_error] +// napi_throw_range_error +// 这里直接抛出一个带有errorMessage的RangeError +static napi_value ThrowRangeErrorMessage(napi_env env, napi_callback_info info) +{ + napi_throw_range_error(env, nullptr, "napi_throw_range_error one"); + return nullptr; +} + +// 传入不匹配的参数个数,判断不匹配之后抛出rangeError +static napi_value ThrowRangeError(napi_env env, napi_callback_info info) +{ + // ArkTS侧传入两个参数 + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 如果传入参数个数不为2 + if (argc != 2) { + // 这里抛出一个RangeError + napi_throw_range_error(env, "napi_throw_range_error", "Expected two numbers as arguments"); + return nullptr; + } + // 下面将传入的两值相加并传出去 + double numOne = 0; + double numTwo = 0; + napi_get_value_double(env, argv[0], &numOne); + napi_get_value_double(env, argv[1], &numTwo); + double result = numOne + numTwo; + napi_value resultValue; + napi_create_double(env, result, &resultValue); + return resultValue; +} +// [End napi_throw_range_error] + +// [Start napi_is_error] +// napi_is_error +static napi_value NapiIsError(napi_env env, napi_callback_info info) +{ + // 接收一个入参 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 调用接口napi_is_error判断入参是否为一个error对象 + bool result = false; + // 如果napi_value为一个error对象,则设置result为true的布尔值,否则设置为false + napi_is_error(env, args[0], &result); + // 取出result通过napi_get_boolean接口将取出的bool值转换为napi_value类型的值返回出去 + napi_value returnValue = nullptr; + napi_get_boolean(env, result, &returnValue); + return returnValue; +} +// [End napi_is_error] + +// [Start napi_get_and_clear_last_exception] +// napi_get_and_clear_last_exception +static napi_value GetAndClearLastException(napi_env env, napi_callback_info info) +{ + // 抛出异常,创造异常情况 + napi_throw_error(env, "napi_create_error errorCode", "napi_create_error errorMessage"); + // 调用napi_get_and_clear_last_exception接口获取并清除最后一个未处理的异常。即使存在挂起的ArkTS异常,也可以调用此API + napi_value result = nullptr; + napi_status status = napi_get_and_clear_last_exception(env, &result); + if (status != napi_ok) { + return nullptr; + } + return result; +} +// [End napi_get_and_clear_last_exception] + +// [Start napi_is_exception_pending] +// napi_is_exception_pending +static napi_value IsExceptionPending(napi_env env, napi_callback_info info) +{ + napi_status status; + bool isExceptionPending = false; + // 在执行一些可能引发异常的操作后 + napi_throw_error(env, "napi_create_error errorCode", "napi_create_error errorMessage"); + // 检查当前环境中是否有异常挂起 + status = napi_is_exception_pending(env, &isExceptionPending); + if (status != napi_ok) { + return nullptr; + } + if (isExceptionPending) { + // 处理异常挂起的情况 + napi_value result = nullptr; + status = napi_get_and_clear_last_exception(env, &result); + if (status != napi_ok) { + return nullptr; + } + // 将处理的异常返回出去 + return result; + } + return nullptr; +} +// [End napi_is_exception_pending] + +// [Start napi_fatal_error] +// napi_fatal_error +static napi_value FatalError(napi_env env, napi_callback_info info) +{ + // 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 + // 模拟一个致命错误条件 + bool errorCondition = true; + if (errorCondition) { + // 创建一个致命错误信息 + napi_fatal_error("napi_fatal_error test", NAPI_AUTO_LENGTH, "napi_create_error errorMessage", NAPI_AUTO_LENGTH); + } + return nullptr; +} +// [End napi_fatal_error] + +// [Start napi_fatal_exception] +// napi_fatal_exception +static napi_value FatalException(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (status != napi_ok) { + return nullptr; + } + // 请注意,使用napi_fatal_exception函数会导致应用进程直接终止,因此应该谨慎使用,仅在主线程遇到无法恢复的严重错误时才应该调用该函数 + // 模拟一个致命错误条件 + status = napi_fatal_exception(env, args[0]); + if (status != napi_ok) { + return nullptr; + } + return nullptr; +} +// [End napi_fatal_exception] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getLastErrorInfo", nullptr, GetLastErrorInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"creatTypeError", nullptr, CreatTypeError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"creatRangeError", nullptr, CreatRangeError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiThrow", nullptr, NapiThrow, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiThrowErrorMessage", nullptr, NapiThrowErrorMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiThrowError", nullptr, NapiThrowError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"throwTypeErrorMessage", nullptr, ThrowTypeErrorMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"throwTypeError", nullptr, ThrowTypeError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"throwRangeErrorMessage", nullptr, ThrowRangeErrorMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"throwRangeError", nullptr, ThrowRangeError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiIsError", nullptr, NapiIsError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAndClearLastException", nullptr, GetAndClearLastException, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"isExceptionPending", nullptr, IsExceptionPending, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"fatalError", nullptr, FatalError, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"fatalException", nullptr, FatalException, 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa36b9c53181275e92a291c874e0be87d9a792ed --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_get_last_error_info_api] +export const getLastErrorInfo: (str: string) => string; // napi_get_last_error_info +// [End napi_get_last_error_info_api] + +// [Start napi_create_type_error_api] +export const creatTypeError: () => Error; // napi_create_type_error +// [End napi_create_type_error_api] + +// [Start napi_create_range_error_api] +export const creatRangeError: () => Error; // napi_create_range_error +// [End napi_create_range_error_api] + +// [Start napi_create_error_api] +export const napiThrow: () => void; // napi_create_error and napi_throw +// [End napi_create_error_api] + +// [Start napi_throw_error_api] +export const napiThrowErrorMessage: () => void; // napi_throw_error + +export const napiThrowError: (dividend: number, divisor: number) => void; // napi_throw_error +// [End napi_throw_error_api] + +// [Start napi_throw_type_error_api] +export const throwTypeErrorMessage: () => void; // napi_throw_type_error + +export const throwTypeError: (message: string) => void; // napi_throw_type_error +// [End napi_throw_type_error_api] + +// [Start napi_throw_range_error_api] +export const throwRangeErrorMessage: () => void; // napi_throw_range_error + +export const throwRangeError: (num: number) => number | void; // napi_throw_range_error +// [End napi_throw_range_error_api] + +// [Start napi_is_error_api] +export const napiIsError: (obj: T) => boolean; // napi_is_error +// [End napi_is_error_api] + +// [Start napi_get_and_clear_last_exception_api] +export const getAndClearLastException: () => Error | void; // napi_get_and_clear_last_exception +// [End napi_get_and_clear_last_exception_api] + +// [Start ark_napi_is_exception_pending_interface] +export interface MyObject { + code: string; + message: string; +} +// [End ark_napi_is_exception_pending_interface] + +// [Start napi_is_exception_pending_api] +export const isExceptionPending: () => Object | void; // napi_is_exception_pending +// [End napi_is_exception_pending_api] + +// [Start napi_fatal_error_api] +export const fatalError: () => void; // napi_fatal_error +// [End napi_fatal_error_api] + +// [Start napi_fatal_exception_api] +export const fatalException: (err: Error) => void; // napi_fatal_exception +// [End napi_fatal_exception_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5aee78b8562aa6f5961e9388f763308d9ba910b3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,308 @@ +/* + * 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, { MyObject } from 'libentry.so'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiGetLastErrorInfo', + '2.napiCreateTypeError', + '3.napiCreateRangeError', + '4.napiCreateErrorAndNapiThrow', + '5.napiThrowError', + '6.napiThrowTypeError', + '7.napiThrowRangeError', + '8.napiIsError', + '9.napiGetAndClearLastException', + '10.napiIsExceptionPending', + '11.napiFatalError', + '12.napiFatalException' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiGetLastErrorInfo') { + // [Start ark_napi_get_last_error_info] + // napi_get_last_error_info + try { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info: %{public}s', + testNapi.getLastErrorInfo('message')); + // [StartExclude ark_napi_get_last_error_info] + this.result = 'napiGetLastErrorInfoSuccess'; + // [EndExclude ark_napi_get_last_error_info] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info error: %{public}s', error); + // [StartExclude ark_napi_get_last_error_info] + this.result = 'napiGetLastErrorInfoFail'; + // [EndExclude ark_napi_get_last_error_info] + } + // [End ark_napi_get_last_error_info] + } else if (item === '2.napiCreateTypeError') { + // [Start ark_napi_create_type_error] + try { + // [StartExclude ark_napi_create_type_error] + this.result = 'napiCreateTypeErrorSuccess'; + // [EndExclude ark_napi_create_type_error] + throw testNapi.creatTypeError(); + } catch (error) { // napi_create_type_error + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_create_type_error errorCode: %{public}s, errorMessage %{public}s', error.code, + error.message); + // [StartExclude ark_napi_create_type_error] + this.result = 'napiCreateTypeErrorFail'; + // [EndExclude ark_napi_create_type_error] + } + // [End ark_napi_create_type_error] + } else if (item === '3.napiCreateRangeError') { + // [Start ark_napi_create_range_error] + // napi_create_range_error + try { + // [StartExclude ark_napi_create_range_error] + this.result = 'napiCreateRangeErrorSuccess'; + // [EndExclude ark_napi_create_range_error] + throw testNapi.creatRangeError(); + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_create_range_error errorCode: %{public}s, errorMessage: %{public}s', + error.code, + error.message); + // [StartExclude ark_napi_create_range_error] + this.result = 'napiCreateRangeErrorFail'; + // [EndExclude ark_napi_create_range_error] + } + // [End ark_napi_create_range_error] + } else if (item === '4.napiCreateErrorAndNapiThrow') { + // [Start ark_napi_create_error] + // napi_create_error and napi_throw + try { + testNapi.napiThrow(); + // [StartExclude ark_napi_create_error] + this.result = 'napiCreateErrorAndNapiThrowSuccess'; + // [EndExclude ark_napi_create_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw errorCode: %{public}s, errorMessage: %{public}s', + error.code, error.message); + // [StartExclude ark_napi_create_error] + this.result = 'napiCreateErrorAndNapiThrowFail'; + // [EndExclude ark_napi_create_error] + } + // [End ark_napi_create_error] + } else if (item === '5.napiThrowError') { + // [Start ark_napi_throw_error] + // napi_throw_error + try { + testNapi.napiThrowErrorMessage(); + // [StartExclude ark_napi_throw_error] + this.result = 'napiThrowErrorMessageSuccess'; + // [EndExclude ark_napi_throw_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw_error error code: %{public}s , message: %{public}s', error.code, + error.message); + // [StartExclude ark_napi_throw_error] + this.result = 'napiThrowErrorMessageFail'; + // [EndExclude ark_napi_throw_error] + } + try { + testNapi.napiThrowError(5, 0); + // [StartExclude ark_napi_throw_error] + this.result = 'napiThrowErrorSuccess'; + // [EndExclude ark_napi_throw_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw_error errorCode: %{public}s , errorManager: %{public}s', error.code, + error.message); + // [StartExclude ark_napi_throw_error] + this.result = 'napiThrowErrorFail'; + // [EndExclude ark_napi_throw_error] + } + // [End ark_napi_throw_error] + } else if (item === '6.napiThrowTypeError') { + // [Start ark_napi_throw_type_error] + // napi_throw_type_error + try { + testNapi.throwTypeErrorMessage(); + // [StartExclude ark_napi_throw_type_error] + this.result = 'throwTypeErrorMessageSuccess'; + // [EndExclude ark_napi_throw_type_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', + error.code, + error.message); + // [StartExclude ark_napi_throw_type_error] + this.result = 'throwTypeErrorMessageFail'; + // [EndExclude ark_napi_throw_type_error] + } + try { + testNapi.throwTypeError('str'); + // [StartExclude ark_napi_throw_type_error] + this.result = 'throwTypeErrorSuccess'; + // [EndExclude ark_napi_throw_type_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', + error.code, + error.message); + // [StartExclude ark_napi_throw_type_error] + this.result = 'throwTypeErrorFail'; + // [EndExclude ark_napi_throw_type_error] + } + // [End ark_napi_throw_type_error] + } else if (item === '7.napiThrowRangeError') { + // [Start ark_napi_throw_range_error] + // napi_throw_range_error + try { + testNapi.throwRangeErrorMessage(); + // [StartExclude ark_napi_throw_range_error] + this.result = 'throwRangeErrorMessageSuccess'; + // [EndExclude ark_napi_throw_range_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', + error.code, + error.message); + // [StartExclude ark_napi_throw_range_error] + this.result = 'throwRangeErrorMessageFail'; + // [EndExclude ark_napi_throw_range_error] + } + + try { + testNapi.throwRangeError(1); + // [StartExclude ark_napi_throw_range_error] + this.result = 'throwRangeErrorSuccess'; + // [EndExclude ark_napi_throw_range_error] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', + error.code, + error.message); + // [StartExclude ark_napi_throw_range_error] + this.result = 'throwRangeErrorFail'; + // [EndExclude ark_napi_throw_range_error] + } + // [End ark_napi_throw_range_error] + } else if (item === '8.napiIsError') { + // [Start ark_napi_is_error] + // napi_is_error + try { + // [StartExclude ark_napi_is_error] + this.result = 'napiIsErrorSuccess'; + // [EndExclude ark_napi_is_error] + throw new Error("throwing an error"); + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', + testNapi.napiIsError(error) + .toString()); + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', + testNapi.napiIsError(1) + .toString()); + // [StartExclude ark_napi_is_error] + this.result = 'napiIsErrorFail'; + // [EndExclude ark_napi_is_error] + } + // [End ark_napi_is_error] + } else if (item === '9.napiGetAndClearLastException') { + // [Start ark_napi_get_and_clear_last_exception] + // napi_get_and_clear_last_exception + // 这里获取到最后一个未处理的异常 + hilog.info(0x0000, 'testTag', + 'Test Node-API napi_get_and_clear_last_exception, error.message: %{public}s', + testNapi.getAndClearLastException()); + // [End ark_napi_get_and_clear_last_exception] + this.result = 'napiGetAndClearLastExceptionSuccess'; + } else if (item === '10.napiIsExceptionPending') { + // [Start ark_napi_is_exception_pending] + // napi_is_exception_pending + try { + let result = testNapi.isExceptionPending() as MyObject; + hilog.info(0x0000, 'testTag', + 'Test Node-API napi_is_exception_pending, error.Code: %{public}s, error.message: %{public}s', + result.code, result.message); + // [StartExclude ark_napi_is_exception_pending] + this.result = 'napiIsExceptionPendingSuccess'; + // [EndExclude ark_napi_is_exception_pending] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_exception_pending error'); + // [StartExclude ark_napi_is_exception_pending] + this.result = 'napiIsExceptionPendingFail'; + // [EndExclude ark_napi_is_exception_pending] + } + // [End ark_napi_is_exception_pending] + } else if (item === '11.napiFatalError') { + // [Start ark_napi_fatal_error] + // napi_fatal_error 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 + // 模拟一个致命错误条件 + try { + testNapi.fatalError(); + // [StartExclude ark_napi_fatal_error] + this.result = 'napiFatalErrorSuccess'; + // [EndExclude ark_napi_fatal_error] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_error error'); + // [StartExclude ark_napi_fatal_error] + this.result = 'napiFatalErrorFail'; + // [EndExclude ark_napi_fatal_error] + } + // [End ark_napi_fatal_error] + } else if (item === '12.napiFatalException') { + // napi_fatal_exception 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 + // 模拟一个致命错误条件 + try { + // [Start ark_napi_fatal_exception] + const err = new Error("a fatal exception occurred"); + testNapi.fatalException(err); + // [End ark_napi_fatal_exception] + this.result = 'napiFatalExceptionSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_exception error'); + this.result = 'napiFatalExceptionFail'; + } + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/NodeAPIError.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/NodeAPIError.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/NodeAPIError.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/NodeAPIError.test.ets index 8e66b792f5529c8771537e2602232b2cfceebbb0..843a51cf0d490046fc10541f996b4a6766610182 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/NodeAPIError.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/ets/test/NodeAPIError.test.ets @@ -1,204 +1,204 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIErrorTest() { - describe('nodeAPIErrorTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiGetLastErrorInfo相关函数 - */ - it('testNodeAPIError001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiGetLastErrorInfo')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetLastErrorInfoSuccess')); - console.info('uitest: testNodeAPIError001 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateTypeError相关函数 - */ - it('testNodeAPIError002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCreateTypeError')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateTypeErrorFail')); - console.info('uitest: testNodeAPIError002 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateRangeError相关函数 - */ - it('testNodeAPIError003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiCreateRangeError')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateRangeErrorFail')); - console.info('uitest: testNodeAPIError003 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateErrorAndNapiThrow相关函数 - */ - it('testNodeAPIError004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiCreateErrorAndNapiThrow')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateErrorAndNapiThrowFail')); - console.info('uitest: testNodeAPIError004 end'); - done(); - }) - - /** - * 点击按钮,调用napiThrowError相关函数 - */ - it('testNodeAPIError005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiThrowError')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiThrowErrorFail')); - console.info('uitest: testNodeAPIError005 end'); - done(); - }) - - /** - * 点击按钮,调用napiThrowTypeError相关函数 - */ - it('testNodeAPIError006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiThrowTypeError')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: throwTypeErrorFail')); - console.info('uitest: testNodeAPIError006 end'); - done(); - }) - - /** - * 点击按钮,调用napiThrowRangeError相关函数 - */ - it('testNodeAPIError007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiThrowRangeError')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: throwRangeErrorFail')); - console.info('uitest: testNodeAPIError007 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsError相关函数 - */ - it('testNodeAPIError008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiIsError')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsErrorFail')); - console.info('uitest: testNodeAPIError008 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetAndClearLastException相关函数 - */ - it('testNodeAPIError009', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError009 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('9.napiGetAndClearLastException')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetAndClearLastExceptionSuccess')); - console.info('uitest: testNodeAPIError009 end'); - done(); - }) - - /** - * 点击按钮,调用napiIsExceptionPending相关函数 - */ - it('testNodeAPIError010', 0, async (done: Function) => { - console.info('uitest: testNodeAPIError010 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('10.napiIsExceptionPending')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsExceptionPendingSuccess')); - console.info('uitest: testNodeAPIError010 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIErrorTest() { + describe('nodeAPIErrorTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiGetLastErrorInfo相关函数 + */ + it('testNodeAPIError001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiGetLastErrorInfo')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetLastErrorInfoSuccess')); + console.info('uitest: testNodeAPIError001 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateTypeError相关函数 + */ + it('testNodeAPIError002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCreateTypeError')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateTypeErrorFail')); + console.info('uitest: testNodeAPIError002 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateRangeError相关函数 + */ + it('testNodeAPIError003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiCreateRangeError')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateRangeErrorFail')); + console.info('uitest: testNodeAPIError003 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateErrorAndNapiThrow相关函数 + */ + it('testNodeAPIError004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiCreateErrorAndNapiThrow')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateErrorAndNapiThrowFail')); + console.info('uitest: testNodeAPIError004 end'); + done(); + }) + + /** + * 点击按钮,调用napiThrowError相关函数 + */ + it('testNodeAPIError005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiThrowError')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiThrowErrorFail')); + console.info('uitest: testNodeAPIError005 end'); + done(); + }) + + /** + * 点击按钮,调用napiThrowTypeError相关函数 + */ + it('testNodeAPIError006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiThrowTypeError')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: throwTypeErrorFail')); + console.info('uitest: testNodeAPIError006 end'); + done(); + }) + + /** + * 点击按钮,调用napiThrowRangeError相关函数 + */ + it('testNodeAPIError007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiThrowRangeError')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: throwRangeErrorFail')); + console.info('uitest: testNodeAPIError007 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsError相关函数 + */ + it('testNodeAPIError008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiIsError')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsErrorFail')); + console.info('uitest: testNodeAPIError008 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetAndClearLastException相关函数 + */ + it('testNodeAPIError009', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError009 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('9.napiGetAndClearLastException')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetAndClearLastExceptionSuccess')); + console.info('uitest: testNodeAPIError009 end'); + done(); + }) + + /** + * 点击按钮,调用napiIsExceptionPending相关函数 + */ + it('testNodeAPIError010', 0, async (done: Function) => { + console.info('uitest: testNodeAPIError010 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('10.napiIsExceptionPending')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsExceptionPendingSuccess')); + console.info('uitest: testNodeAPIError010 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/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/NodeAPI/NodeApiUse/NodeAPIError/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..00c324b80d74feb5f6104b88b6ef8ec82ce6f024 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/ohosTest.md @@ -0,0 +1,17 @@ +# 使用Node-API进行错误处理开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| --------------------------------------------------- | ------------ | -------------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 getLastErrorInfo | 位于主页 | 点击文本为1.napiGetLastErrorInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetLastErrorInfoSuccess | Pass | +| ArkTS端成功调用native侧接口creatTypeError | 位于主页 | 点击文本为2.napiCreateTypeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateTypeErrorSuccess | Pass | +| ArkTS端成功调用native侧接口creatRangeError | 位于主页 | 点击文本为3.napiCreateRangeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateRangeErrorSuccess | Pass | +| ArkTS端成功调用native侧接口napiThrow | 位于主页 | 点击文本为4.napiCreateErrorAndNapiThrow的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateErrorAndNapiThrowSuccess | Pass | +| ArkTS端成功调用native侧接口napiThrowError | 位于主页 | 点击文本为5.napiThrowError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiThrowErrorSuccess | Pass | +| ArkTS端成功调用native侧接口throwTypeError | 位于主页 | 点击文本为6.napiThrowTypeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: throwTypeErrorSuccess | Pass | +| ArkTS端成功调用native侧接口throwRangeError | 位于主页 | 点击文本为7.napiThrowRangeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: throwRangeErrorSuccess | Pass | +| ArkTS端成功调用native侧接口napiIsError | 位于主页 | 点击文本为8.napiIsError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsErrorSuccess | Pass | +| ArkTS端成功调用native侧接口getAndClearLastException | 位于主页 | 点击文本为9.napiGetAndClearLastException的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetAndClearLastExceptionSuccess | Pass | +| ArkTS端成功调用native侧接口isExceptionPending | 位于主页 | 点击文本为10.napiIsExceptionPending的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsExceptionPendingSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIError/screenshots/NodeAPIError2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/.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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d82f431489ee2e2357a3a51eacb479d252ec8912 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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.nodeapiextendcapabilities", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0c07424d46ace6d3d28a29b9f8aab25f4c266ee4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIExtendCapabilities" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/README.md new file mode 100644 index 0000000000000000000000000000000000000000..977d66194b8d7d1d642e23afa12d309ecd1b9264 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行扩展能力功能开发 + +### 介绍 + +扩展能力接口进一步扩展了Node-API的功能,提供了一些额外的接口,用于在Node-API模块中与ArkTS进行更灵活的交互和定制,这些接口可以用于创建自定义ArkTS对象等场景,本工程主要展示了使用Node-API对模块加载、ArkTS Object相关、运行指定abc文件、异步工作对象加入队列并指定优先级、给ArkTS对象绑定回调和回调所需的参数等场景,其中展示的代码详细描述可查如下链接。 + +- [使用Node-API进行扩展能力功能开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-extension.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIExtendCapabilities.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行扩展能力功能开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIExtendCapabilities.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..577025fb9d438d0d80bd11a2d1eef29f3259d44a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,18 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(using_NodeAPI_extend_capabilities) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc093e6fc1f55b935367a0524c05b982862aa54c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,578 @@ +/* + * 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 +#include +#include +#include +#include "hilog/log.h" + +static constexpr int INT_ARG_100 = 100; // 入参索引 + +// [Start node_api_module_add] +// 模块加载 +static napi_value Add(napi_env env, napi_callback_info info) +{ + // 接受传入两个参数 + size_t requireArgc = 2; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 将传入的napi_value类型的参数转化为double类型 + double valueLeft; + double valueRight; + napi_get_value_double(env, args[0], &valueLeft); + napi_get_value_double(env, args[1], &valueRight); + + // 将转化后的double值相加并转成napi_value返回给ArkTS代码使用 + napi_value sum; + napi_create_double(env, valueLeft + valueRight, &sum); + + return sum; +} + +// [StartExclude node_api_module_add] +// [Start node_api_module_create_object_properties] +// ArkTS Object相关 napi_create_object_with_properties +static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1] = {nullptr}; + // 获取解析传递的参数 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 声明了一个napi_property_descriptor数组desc,其中包含了一个名为"name"的属性,其值为传入的第一个参数argv[0]。 + napi_property_descriptor desc[] = { + {"name", nullptr, nullptr, nullptr, nullptr, argv[0], napi_default_jsproperty, nullptr}}; + napi_value object = nullptr; + // 调用napi_create_object_with_properties来创建一个新的ArkTS对象,并将属性值添加到该对象中。 + napi_create_object_with_properties(env, &object, sizeof(desc) / sizeof(desc[0]), desc); + napi_valuetype valueType; + napi_typeof(env, object, &valueType); + if (valueType == napi_object) { + return object; + } +} +// [End node_api_module_create_object_properties] +// [Start node_api_module_create_object_name_properties] +// ArkTS Object相关 napi_create_object_with_named_properties +static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1] = {nullptr}; + // 获取解析传递的参数 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + napi_value obj = nullptr; + const char *key[] = { + "name", + }; + const napi_value values[] = { + argv[0], + }; + napi_property_descriptor desc[] = {{"name", nullptr, nullptr, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_status status = napi_create_object_with_named_properties( + env, &obj, sizeof(desc) / sizeof(desc[0]), key, values); + if (status != napi_ok) { + return argv[0]; + } + return obj; +} +// [End node_api_module_create_object_name_properties] +// [Start node_api_module_run_script_path] +// 运行指定abc文件 napi_run_script_path +static napi_value RunScriptPath(napi_env env, napi_callback_info info) +{ + napi_value value = nullptr; + // 注意:记得在应用rawfile目录下放置.abc文件 + const char *scriptPath = "/entry/src/main/resources/rawfile/test.abc"; + // 使用napi_run_script_path函数执行指定路径中的文件 + napi_status status = napi_run_script_path(env, scriptPath, &value); + // 检查是否执行成功,如果失败,返回false + napi_value returnValue = nullptr; + if (value == nullptr || status != napi_ok) { + napi_get_boolean(env, false, &returnValue); + } else { + napi_get_boolean(env, true, &returnValue); + } + return returnValue; +} +// [End node_api_module_run_script_path] +// 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object +// [Start napi_coerce_to_native_binding_object] +class Object { +public: + Object() = default; + ~Object() = default; + + static Object *GetInstance() + { + Object *instance = new Object(); + return instance; + } + + static napi_value GetAddress(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + if (thisVar == nullptr) { + return nullptr; + } + void *object = nullptr; + napi_unwrap(env, thisVar, &object); + if (object == nullptr) { + return nullptr; + } + uint64_t addressVal = reinterpret_cast(object); + napi_value address = nullptr; + napi_create_bigint_uint64(env, addressVal, &address); + return address; + } + + // 获取数组大小 + static napi_value GetSetSize(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + if (thisVar == nullptr) { + return nullptr; + } + void *object = nullptr; + napi_unwrap(env, thisVar, &object); + if (object == nullptr) { + return nullptr; + } + std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); + uint32_t setSize = reinterpret_cast(object)->numberSet_.size(); + napi_value napiSize = nullptr; + napi_create_uint32(env, setSize, &napiSize); + return napiSize; + } + + // 往数组里插入元素 + static napi_value Store(napi_env env, napi_callback_info info) + { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr); + if (argc != 1) { + napi_throw_error(env, nullptr, "Store args number must be one."); + return nullptr; + } + napi_valuetype type = napi_undefined; + napi_typeof(env, args[0], &type); + if (type != napi_number) { + napi_throw_error(env, nullptr, "Store args is not number."); + return nullptr; + } + if (thisVar == nullptr) { + return nullptr; + } + uint32_t value = 0; + napi_get_value_uint32(env, args[0], &value); + void *object = nullptr; + napi_unwrap(env, thisVar, &object); + if (object == nullptr) { + return nullptr; + } + std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); + reinterpret_cast(object)->numberSet_.insert(value); + return nullptr; + } + + // 删除数组元素 + static napi_value Erase(napi_env env, napi_callback_info info) + { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr); + if (argc != 1) { + napi_throw_error(env, nullptr, "Erase args number must be one."); + return nullptr; + } + napi_valuetype type = napi_undefined; + napi_typeof(env, args[0], &type); + if (type != napi_number) { + napi_throw_error(env, nullptr, "Erase args is not number."); + return nullptr; + } + if (thisVar == nullptr) { + return nullptr; + } + uint32_t value = 0; + napi_get_value_uint32(env, args[0], &value); + void *object = nullptr; + napi_unwrap(env, thisVar, &object); + if (object == nullptr) { + return nullptr; + } + std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); + reinterpret_cast(object)->numberSet_.erase(value); + return nullptr; + } + + // 清空数组 + static napi_value Clear(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + if (thisVar == nullptr) { + return nullptr; + } + void *object = nullptr; + napi_unwrap(env, thisVar, &object); + if (object == nullptr) { + return nullptr; + } + std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); + reinterpret_cast(object)->numberSet_.clear(); + return nullptr; + } + +private: + Object(const Object &) = delete; + Object &operator=(const Object &) = delete; + + std::unordered_set numberSet_{}; + std::mutex numberSetMutex_{}; +}; + +void FinializeCallback(napi_env env, void *data, void *hint) { return; } + +// 解绑回调,在序列化时调用,可在对象解绑时执行一些清理操作 +void *DetachCallback(napi_env env, void *value, void *hint) { return value; } + +// 绑定回调,在反序列化时调用 +napi_value AttachCallback(napi_env env, void *value, void *hint) +{ + napi_value object = nullptr; + napi_create_object(env, &object); + napi_property_descriptor desc[] = { + {"getAddress", nullptr, Object::GetAddress, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSetSize", nullptr, Object::GetSetSize, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"store", nullptr, Object::Store, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"erase", nullptr, Object::Erase, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"clear", nullptr, Object::Clear, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, object, sizeof(desc) / sizeof(desc[0]), desc); + // 将JS对象object和native对象value生命周期进行绑定 + napi_wrap(env, object, value, FinializeCallback, nullptr, nullptr); + // JS对象携带native信息 + napi_coerce_to_native_binding_object(env, object, DetachCallback, AttachCallback, value, hint); + return object; +} +// [StartExclude napi_coerce_to_native_binding_object] +// [Start napi_serialize_deserialize_delete_serialization_data] +// 序列化和反序列化 +static napi_value AboutSerialize(napi_env env, napi_callback_info info) +{ + // 获取传入的ts的一个对象作为参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value undefined = nullptr; + // 构造napi_serialize方法所需参数 + napi_get_undefined(env, &undefined); + void *data = nullptr; + // 调用napi_serialize方法将ts对象转化为native数据 + napi_status status = napi_serialize(env, args[0], undefined, undefined, &data); + if (status != napi_ok || data == nullptr) { + napi_throw_error(env, nullptr, "Node-API napi_serialize fail"); + return nullptr; + } + // 构造napi_value类型的数据,用于接收将native数据转化为ts对象后的数据 + napi_value result = nullptr; + napi_deserialize(env, data, &result); + napi_value number = nullptr; + // 获取native数据转化为ts对象后的数据中的numKey属性的值 + napi_get_named_property(env, result, "numKey", &number); + // 判断获取到的属性值是否为number类型 + napi_valuetype valuetype; + napi_typeof(env, number, &valuetype); + if (valuetype != napi_number) { + napi_throw_error(env, nullptr, "Node-API Wrong type of argment. Expects a number."); + return nullptr; + } + // 调用napi_delete_serialization_data方法删除序列化数据 + napi_delete_serialization_data(env, data); + // 返回获取到的属性值 + return number; +} +// [End napi_serialize_deserialize_delete_serialization_data] +// [Start napi_is_sendable] +// Sendable相关 napi_is_sendable +static napi_value IsSendable(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + bool isSendable = false; + napi_is_sendable(env, args[0], &isSendable); + napi_value result; + napi_get_boolean(env, isSendable, &result); + return result; +} +// [End napi_is_sendable] + +// [Start napi_define_sendable_class] +static napi_value func(napi_env env, napi_callback_info info) +{ + napi_value val; + napi_create_string_utf8(env, "func result", NAPI_AUTO_LENGTH, &val); + return val; +} + +static napi_value DefineSendableClass(napi_env env) +{ + napi_value str; + napi_create_string_utf8(env, "str", NAPI_AUTO_LENGTH, &str); + + napi_property_descriptor props[] = { + {"staticStr", nullptr, nullptr, nullptr, nullptr, str, + static_cast(napi_static | napi_writable), nullptr}, + {"staticFunc", nullptr, func, nullptr, nullptr, nullptr, napi_static, nullptr}, + {"str", nullptr, nullptr, nullptr, nullptr, str, static_cast(1 << 9 | napi_writable), + nullptr}, + {"func", nullptr, nullptr, nullptr, nullptr, nullptr, + static_cast(1 << 11 | napi_writable), nullptr}, + }; + + napi_value sendableClass = nullptr; + napi_define_sendable_class( + env, "SendableClass", NAPI_AUTO_LENGTH, + [](napi_env env, napi_callback_info info) -> napi_value { + napi_value thisVar = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); + napi_value str; + napi_create_string_utf8(env, "instance str", NAPI_AUTO_LENGTH, &str); + napi_property_descriptor props[] = { + {"str", nullptr, nullptr, nullptr, nullptr, str, napi_default, nullptr}, + {"func", nullptr, func, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, thisVar, sizeof(props) / sizeof(props[0]), props); + return thisVar; + }, + nullptr, sizeof(props) / sizeof(props[0]), props, nullptr, &sendableClass); + + return sendableClass; +} +// [End napi_define_sendable_class] +// [Start napi_create_sendable_object_with_properties] +// Sendable相关 napi_create_sendable_object_with_properties +static napi_value GetSendableObject(napi_env env, napi_callback_info info) +{ + napi_value val_true; + napi_get_boolean(env, true, &val_true); + napi_property_descriptor desc1[] = { + {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, + }; + napi_value obj; + napi_create_sendable_object_with_properties(env, 1, desc1, &obj); + return obj; +} +// [End napi_create_sendable_object_with_properties +// [Start napi_create_sendable_array] +// Sendable相关 napi_create_sendable_array +static napi_value GetSendableArray(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_create_sendable_array(env, &result); + return result; +} +// [End napi_create_sendable_array] +// [Start napi_create_sendable_array_with_length] +// Sendable相关 napi_create_sendable_array_with_length +static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_create_sendable_array_with_length(env, 1, &result); + return result; +} +// End napi_create_sendable_array_with_length] +// [Start napi_create_sendable_arraybuffer] +// Sendable相关 napi_create_sendable_arraybuffer +static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) +{ + static size_t length = 1024; + void *data; + napi_value result = nullptr; + napi_create_sendable_arraybuffer(env, length, &data, &result); + bool isArrayBuffer = false; + napi_is_arraybuffer(env, result, &isArrayBuffer); + OH_LOG_INFO(LOG_APP, "isArrayBuffer: %{public}d", isArrayBuffer); + return result; +} +// [End napi_create_sendable_arraybuffer] +// [Start napi_create_sendable_typed_array] +// Sendable相关 napi_create_sendable_typedarray +static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) +{ + static size_t length = 1024; + static size_t offset = 0; + void *data; + napi_value arraybuffer = nullptr; + napi_create_sendable_arraybuffer(env, length, &data, &arraybuffer); + + napi_value result = nullptr; + napi_create_sendable_typedarray(env, napi_uint8_array, length, arraybuffer, offset, &result); + bool isTypedArray = false; + napi_is_typedarray(env, result, &isTypedArray); + OH_LOG_INFO(LOG_APP, "isTypedArray: %{public}d", isTypedArray); + return result; +} +// [End napi_create_sendable_typed_array] +// [Start napi_wrap_sendable] +// Sendable相关 napi_wrap_sendable +static napi_value WrapSendable(napi_env env, napi_callback_info info) +{ + napi_value val_true; + napi_get_boolean(env, true, &val_true); + napi_property_descriptor desc1[] = { + {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, + }; + napi_value obj; + napi_create_sendable_object_with_properties(env, 1, desc1, &obj); + + const char *testStr = "test"; + napi_wrap_sendable( + env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr); + + return nullptr; +} +// [End napi_wrap_sendable] +// [Start napi_wrap_sendable_with_size] +// Sendable相关 napi_wrap_sendable_with_size +static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) +{ + napi_value val_true; + napi_get_boolean(env, true, &val_true); + napi_property_descriptor desc1[] = { + {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, + }; + napi_value obj; + napi_create_sendable_object_with_properties(env, 1, desc1, &obj); + + const char *testStr = "test"; + napi_wrap_sendable_with_size( + env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr, INT_ARG_100); + + return nullptr; +} +// [End napi_wrap_sendable_with_size] +// [Start napi_unwrap_sendable] +// Sendable相关 napi_unwrap_sendable +static napi_value UnwrapSendable(napi_env env, napi_callback_info info) +{ + napi_value val_true; + napi_get_boolean(env, true, &val_true); + napi_property_descriptor desc1[] = { + {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, + }; + napi_value obj; + napi_create_sendable_object_with_properties(env, 1, desc1, &obj); + + const char *testStr = "test"; + napi_wrap_sendable( + env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr); + + char *tmpTestStr = nullptr; + napi_unwrap_sendable(env, obj, (void **)&tmpTestStr); + OH_LOG_INFO(LOG_APP, "native value is %{public}s", tmpTestStr); + + return nullptr; +} +// [End napi_unwrap_sendable] +// [Start napi_remove_wrap_sendable] +// Sendable相关 napi_remove_wrap_sendable +static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) +{ + napi_value val_true; + napi_get_boolean(env, true, &val_true); + napi_property_descriptor desc1[] = { + {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, + }; + napi_value obj; + napi_create_sendable_object_with_properties(env, 1, desc1, &obj); + + const char *testStr = "test"; + napi_wrap_sendable( + env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr); + + char *tmpTestStr = nullptr; + napi_remove_wrap_sendable(env, obj, (void **)&tmpTestStr); + OH_LOG_INFO(LOG_APP, "native value is %{public}s", tmpTestStr); + + return nullptr; +} +// [End napi_remove_wrap_sendable] +// [EndExclude napi_coerce_to_native_binding_object] +// [EndExclude node_api_module_add] + +// C++函数Init用于初始化插件,用于将ArkTS层的函数或属性与C++层的函数进行关联 +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + // 通过napi_property_descriptor结构体,可以定义需要导出的属性,并在Node-API模块中使用。napi_define_properties将属性与实际的C++函数进行关联,使其可以被ArkTS层访问和调用 + napi_property_descriptor desc[] = { + {"add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createObjectWithProperties", nullptr, CreateObjectWithProperties, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"createObjectWithNameProperties", nullptr, CreateObjectWithNameProperties, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"runScriptPath", nullptr, RunScriptPath, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getAddress", nullptr, Object::GetAddress, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSetSize", nullptr, Object::GetSetSize, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"store", nullptr, Object::Store, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"erase", nullptr, Object::Erase, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"clear", nullptr, Object::Clear, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"aboutSerialize", nullptr, AboutSerialize, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"isSendable", nullptr, IsSendable, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSendableObject", nullptr, GetSendableObject, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSendableArray", nullptr, GetSendableArray, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSendableArrayWithLength", nullptr, GetSendableArrayWithLength, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"getSendableArrayBuffer", nullptr, GetSendableArrayBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getSendableTypedArray", nullptr, GetSendableTypedArray, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"wrapSendable", nullptr, WrapSendable, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"wrapSendableWithSize", nullptr, WrapSendableWithSize, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"unwrapSendable", nullptr, UnwrapSendable, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"removeWrapSendable", nullptr, RemoveWrapSendable, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + auto object = Object::GetInstance(); + napi_wrap(env, exports, reinterpret_cast(object), FinializeCallback, nullptr, nullptr); + napi_coerce_to_native_binding_object(env, exports, DetachCallback, AttachCallback, reinterpret_cast(object), + nullptr); + napi_value cons = DefineSendableClass(env); + napi_set_named_property(env, exports, "SendableClass", cons); + return exports; +} +EXTERN_C_END + +// 插件的初始化被定义在一个名为demoModule的结构体中,其中包含了模块的基本信息,比如模块的版本号、注册函数等 +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}, +}; + +// 在RegisterEntryModule函数中,使用napi_module_register函数注册并导出了这个插件 +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } +// [End napi_coerce_to_native_binding_object] +// [End node_api_module_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..92396c6fc77f3c1a295c7ec5317dec74034cd915 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start node_api_module_add_api] +export const add: (a: number, b: number) => number; // 模块加载 +// [End node_api_module_add_api] + +// [Start node_api_module_create_object_properties_api] +export const createObjectWithProperties: (data: string) => Object; // ArkTS Object相关 napi_create_object_with_properties +// [End node_api_module_create_object_properties_api] + +// [Start node_api_module_create_object_name_properties_api] +export const createObjectWithNameProperties: (data: string) => string | { name: string }; // ArkTS Object相关 napi_create_object_with_named_properties +// [End node_api_module_create_object_name_properties_api] + +// [Start node_api_module_run_script_path_api] +export const runScriptPath: () => boolean; // 运行指定abc文件 napi_run_script_path +// [End node_api_module_run_script_path_api] +// [Start napi_coerce_to_native_binding_object_api] +// 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object +export const getAddress: () => number; + +export const getSetSize: () => number; + +export const store: (a: number) => void; + +export const erase: (a: number) => void; + +export const clear: () => void; +// [End napi_coerce_to_native_binding_object_api] + +// [Start napi_serialize_deserialize_delete_serialization_data_api] +export const aboutSerialize: (obj: Object) => number; // 序列化和反序列化 +// [End napi_serialize_deserialize_delete_serialization_data_api] + +// [Start napi_is_sendable_api] +export const isSendable: (a: T) => boolean; // Sendable相关 napi_is_sendable +// [End napi_is_sendable_api] + +// [Start napi_define_sendable_class_api] +@Sendable +export class SendableClass { + static staticStr: string; + static staticFunc(): string; + str: string; + func(): string; +} // Sendable相关 napi_define_sendable_class +// [End napi_define_sendable_class_api] + +// [Start napi_create_sendable_object_with_properties_api] +export const getSendableObject: () => { x: true }; // Sendable相关 napi_create_sendable_object_with_properties +// [End napi_create_sendable_object_with_properties_api] + +// [Start napi_create_sendable_array_api] +export const getSendableArray: () => []; // Sendable相关 napi_create_sendable_array +// [End napi_create_sendable_array_api] + +// [Start napi_create_sendable_array_with_length_api] +export const getSendableArrayWithLength: () => []; // Sendable相关 napi_create_sendable_array_with_length +// [End napi_create_sendable_array_with_length_api] + +// [Start napi_create_sendable_arraybuffer_api] +export const getSendableArrayBuffer: () => void; // Sendable相关 napi_create_sendable_arraybuffer +// [End napi_create_sendable_arraybuffer_api] + +// [Start napi_create_sendable_typed_array_api] +export const getSendableTypedArray: () => void; // Sendable相关 napi_create_sendable_typedarray +// [End napi_create_sendable_typed_array_api] + +// [Start napi_wrap_sendable_api] +export const wrapSendable: () => void; // Sendable相关 napi_wrap_sendable +// [End napi_wrap_sendable_api] + +// [Start napi_wrap_sendable_with_size_api] +export const wrapSendableWithSize: () => void; // Sendable相关 napi_wrap_sendable_with_size +// [End napi_wrap_sendable_with_size_api] + +// [Start napi_unwrap_sendable_api] +export const unwrapSendable: () => void; // Sendable相关 napi_unwrap_sendable +// [End napi_unwrap_sendable_api] + +// [Start napi_remove_wrap_sendable_api] +export const removeWrapSendable: () => void; // Sendable相关 napi_remove_wrap_sendable +// [End napi_remove_wrap_sendable_api] diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a673344ac395a03647b5d6c54aa50492adcc4698 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,267 @@ +/* + * 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 taskpool from '@ohos.taskpool'; + +// [Start ark_napi_coerce_to_native_binding_object] +@Concurrent +function getAddress() { + let address: number = testNapi.getAddress(); + console.info('taskpool:: address is' + address); +} + +@Concurrent +function store(a: number, b: number, c: number) { + let size: number = testNapi.getSetSize(); + console.info('set size is' + size + 'before store'); + testNapi.store(a); + testNapi.store(b); + testNapi.store(c); + size = testNapi.getSetSize(); + console.info('set size is' + size + 'after store'); +} + +@Concurrent +function erase(a: number) { + let size: number = testNapi.getSetSize(); + console.info('set size is' + size + 'before erase'); + testNapi.erase(a); + size = testNapi.getSetSize(); + console.info('set size is' + size + 'after erase'); +} + +@Concurrent +function clear() { + let size: number = testNapi.getSetSize(); + console.info('set size is' + size + 'before clear'); + testNapi.clear(); + size = testNapi.getSetSize(); + console.info('set size is' + size + 'after clear'); +} + +async function test01(): Promise { + let address: number = testNapi.getAddress(); + console.info('host thread address is' + address); + + let task1 = new taskpool.Task(getAddress); + await taskpool.execute(task1); + + let task2 = new taskpool.Task(store, 1, 2, 3); + await taskpool.execute(task2); + + let task3 = new taskpool.Task(store, 4, 5, 6); + await taskpool.execute(task3); + + let task4 = new taskpool.Task(erase, 3); + await taskpool.execute(task4); + + let task5 = new taskpool.Task(erase, 5); + await taskpool.execute(task5); + + let task6 = new taskpool.Task(clear); + await taskpool.execute(task6); +} +// [End ark_napi_coerce_to_native_binding_object] + +// [Start ark_napi_serialize_deserialize_delete_serialization_data] +class Obj { + numKey: number = 0; +} +// [StartExclude ark_napi_serialize_deserialize_delete_serialization_data] + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiLoadModule', + '2.napiCreateObjectWithProperties', + '3.napiCreateObjectWithNamedProperties', + '4.napiRunScriptPath', + '5.napiCoerceToNativeBindingObject', + '6.napiAboutSerialize', + '7.napiIsSendable', + '8.napiDefineSendableClass', + '9.napiCreateSendableObjectWithProperties', + '10.napiCreateSendableArray', + '11.napiCreateSendableArrayWithLength', + '12.napiCreateSendableArraybuffer', + '13.napiCreateSendableTypedArray', + '14.napiWrapSendable', + '15.napiWrapSendableWithSize', + '16.napiUnwrapSendable', + '17.napiRemoveWrapSendable' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(17) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiLoadModule') { + // [Start ark_node_api_module_add] + hilog.info(0x0000, 'testTag', 'Test Node-API 2 + 3 = %{public}d', testNapi.add(2, 3)); + // [End ark_node_api_module_add] + this.result = 'napiLoadModuleSuccess'; + } else if (item === '2.napiCreateObjectWithProperties') { + // [Start ark_node_api_module_create_object_properties] + // ArkTS Object相关 napi_create_object_with_properties + let value1 = testNapi.createObjectWithProperties('createObject'); + hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_properties:%{public}s', + JSON.stringify(value1)); + // [End ark_node_api_module_create_object_properties] + this.result = 'napiCreateObjectWithPropertiesSuccess'; + } else if (item === '3.napiCreateObjectWithNamedProperties') { + // [Start ark_node_api_module_create_object_name_properties] + // ArkTS Object相关 napi_create_object_with_named_properties + let value2 = testNapi.createObjectWithNameProperties('ls'); + hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_named_properties:%{public}s', + JSON.stringify(value2)); + // [End ark_node_api_module_create_object_name_properties] + this.result = 'napiCreateObjectWithNamedPropertiesSuccess'; + } else if (item === '4.napiRunScriptPath') { + // [Start ark_node_api_module_run_script_path] + // 运行指定abc文件 napi_run_script_path + try { // 在此处执行错误返回false,成功就返回true + hilog.info(0x0000, 'testTag', 'Test Node-API napi_run_script_path: %{public}s', + testNapi.runScriptPath()); + // [StartExclude ark_node_api_module_run_script_path] + this.result = 'napiRunScriptPathSuccess'; + // [EndExclude ark_node_api_module_run_script_path] + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_run_script_path errorMessage: %{public}s', + error.message); + // [StartExclude ark_node_api_module_run_script_path] + this.result = 'napiRunScriptPathFail'; + // [EndExclude ark_node_api_module_run_script_path] + } + // [End ark_node_api_module_run_script_path] + } else if (item === '5.napiCoerceToNativeBindingObject') { + // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object + test01(); + this.result = 'napiCoerceToNativeBindingObjectSuccess'; + } else if (item === '6.napiAboutSerialize') { + // [EndExclude ark_napi_serialize_deserialize_delete_serialization_data] + // 序列化和反序列化 + let obj: Obj = { numKey: 500 }; + hilog.info(0x0000, 'testTag', ' Node-API aboutSerialize: %{public}d', testNapi.aboutSerialize(obj)); + // [End ark_napi_serialize_deserialize_delete_serialization_data] + this.result = 'napiAboutSerializeSuccess'; + } else if (item === '7.napiIsSendable') { + // [Start ark_napi_is_sendable] + // Sendable相关 napi_is_sendable + let value = testNapi.isSendable('createObject'); + hilog.info(0x0000, 'testTag', 'Node-API napi_is_sendable: %{public}s', JSON.stringify(value)); + // [End ark_napi_is_sendable] + this.result = 'napiIsSendableSuccess'; + } else if (item === '8.napiDefineSendableClass') { + // [Start ark_napi_define_sendable_class] + // Sendable相关 napi_define_sendable_class + let value = new testNapi.SendableClass(); + hilog.info(0x0000, 'testTag', 'Node-API napi_define_sendable_class: %{public}s', value.str); + // [End ark_napi_define_sendable_class] + this.result = 'napiDefineSendableClassSuccess'; + } else if (item === '9.napiCreateSendableObjectWithProperties') { + // [Start ark_napi_create_sendable_object_with_properties] + // Sendable相关 napi_create_sendable_object_with_properties + let value = testNapi.getSendableObject(); + hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_object_with_properties: %{public}s', + JSON.stringify(value)); + // [End ark_napi_create_sendable_object_with_properties] + this.result = 'napiCreateSendableObjectWithPropertiesSuccess'; + } else if (item === '10.napiCreateSendableArray') { + // [Start ark_napi_create_sendable_array] + // Sendable相关 napi_create_sendable_array + let value = testNapi.getSendableArray(); + hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array: %{public}s', + JSON.stringify(value)); + // [End ark_napi_create_sendable_array] + this.result = 'napiCreateSendableArraySuccess'; + } else if (item === '11.napiCreateSendableArrayWithLength') { + // [Start ark_napi_create_sendable_array_with_length] + // Sendable相关 napi_create_sendable_array_with_length + let value = testNapi.getSendableArrayWithLength(); + hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array_with_length: %{public}s', + JSON.stringify(value.length)); + // [End ark_napi_create_sendable_array_with_length] + this.result = 'napiCreateSendableArrayWithLengthSuccess'; + } else if (item === '12.napiCreateSendableArraybuffer') { + // [Start ark_napi_create_sendable_arraybuffer] + // Sendable相关 napi_create_sendable_arraybuffer + testNapi.getSendableArrayBuffer(); + // [End ark_napi_create_sendable_arraybuffer] + this.result = 'napiCreateSendableArraybufferSuccess'; + } else if (item === '13.napiCreateSendableTypedArray') { + // [Start ark_napi_create_sendable_typed_array] + // Sendable相关 napi_create_sendable_typedarray + testNapi.getSendableTypedArray(); + // [End ark_napi_create_sendable_typed_array] + this.result = 'napiCreateSendableTypedArraySuccess'; + } else if (item === '14.napiWrapSendable') { + // [Start ark_napi_wrap_sendable] + // Sendable相关 napi_wrap_sendable + testNapi.wrapSendable(); + // [End ark_napi_wrap_sendable] + this.result = 'napiWrapSendableSuccess'; + } else if (item === '15.napiWrapSendableWithSize') { + // [Start ark_napi_wrap_sendable_with_size] + // Sendable相关 napi_wrap_sendable_with_size + testNapi.wrapSendableWithSize(); + // [End ark_napi_wrap_sendable_with_size] + this.result = 'napiWrapSendableWithSizeSuccess'; + } else if (item === '16.napiUnwrapSendable') { + // [Start ark_napi_unwrap_sendable] + // Sendable相关 napi_unwrap_sendable + testNapi.unwrapSendable(); + // [End ark_napi_unwrap_sendable] + this.result = 'napiUnwrapSendableSuccess'; + } else if (item === '17.napiRemoveWrapSendable') { + // [Start ark_napi_remove_wrap_sendable] + // Sendable相关 napi_remove_wrap_sendable + testNapi.removeWrapSendable(); + // [End ark_napi_remove_wrap_sendable] + this.result = 'napiRemoveWrapSendableSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + .id('List') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/rawfile/test.abc b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/rawfile/test.abc old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/rawfile/test.abc rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/rawfile/test.abc diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/NodeAPIExtendCapabilities.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/NodeAPIExtendCapabilities.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/NodeAPIExtendCapabilities.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/NodeAPIExtendCapabilities.test.ets index 77950eed60e49232e683083245fcd38e3014c82f..9d921ccf59360e62b6df68df49de04dd0ad573d8 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/NodeAPIExtendCapabilities.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/ets/test/NodeAPIExtendCapabilities.test.ets @@ -1,318 +1,318 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIExtendCapabilitiesTest() { - describe('nodeAPIExtendCapabilitiesTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击,调用napiLoadModule相关函数 - */ - it('testNodeAPIExtendCapabilities001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiLoadModule')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiLoadModuleSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities001 end'); - done(); - }) - - /** - * 点击,调用napiCreateObjectWithProperties相关函数 - */ - it('testNodeAPIExtendCapabilities002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCreateObjectWithProperties')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateObjectWithPropertiesSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities002 end'); - done(); - }) - - /** - * 点击,调用napiCreateObjectWithNamedProperties相关函数 - */ - it('testNodeAPIExtendCapabilities003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiCreateObjectWithNamedProperties')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateObjectWithNamedPropertiesSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities003 end'); - done(); - }) - - /** - * 点击,调用napiRunScriptPath相关函数 - */ - it('testNodeAPIExtendCapabilities004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiRunScriptPath')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiRunScriptPathSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities004 end'); - done(); - }) - - /** - * 点击,调用napiCoerceToNativeBindingObject相关函数 - */ - it('testNodeAPIExtendCapabilities005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiCoerceToNativeBindingObject')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCoerceToNativeBindingObjectSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities005 end'); - done(); - }) - - /** - * 点击,调用napiAboutSerialize相关函数 - */ - it('testNodeAPIExtendCapabilities006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiAboutSerialize')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiAboutSerializeSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities006 end'); - done(); - }) - - /** - * 点击,调用napiIsSendable相关函数 - */ - it('testNodeAPIExtendCapabilities007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiIsSendable')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsSendableSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities007 end'); - done(); - }) - - /** - * 点击,调用napiDefineSendableClass相关函数 - */ - it('testNodeAPIExtendCapabilities008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiDefineSendableClass')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiDefineSendableClassSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities008 end'); - done(); - }) - - /** - * 点击,调用napiCreateSendableObjectWithProperties相关函数 - */ - it('testNodeAPIExtendCapabilities009', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities009 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('9.napiCreateSendableObjectWithProperties')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateSendableObjectWithPropertiesSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities009 end'); - done(); - }) - - /** - * 点击,调用napiCreateSendableArray相关函数 - */ - it('testNodeAPIExtendCapabilities010', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities010 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('10.napiCreateSendableArray')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateSendableArraySuccess')); - console.info('uitest: testNodeAPIExtendCapabilities010 end'); - done(); - }) - - /** - * 点击,调用napiCreateSendableArrayWithLength相关函数 - */ - it('testNodeAPIExtendCapabilities011', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities011 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const list = await driver.findComponent(ON.id('List')) - await list.scrollToBottom(); - const text = await driver.findComponent(ON.text('11.napiCreateSendableArrayWithLength')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateSendableArrayWithLengthSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities011 end'); - done(); - }) - - /** - * 点击,调用napiCreateSendableArraybuffer相关函数 - */ - it('testNodeAPIExtendCapabilities012', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities012 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('12.napiCreateSendableArraybuffer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateSendableArraybufferSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities012 end'); - done(); - }) - - /** - * 点击,调用napiCreateSendableTypedArray相关函数 - */ - it('testNodeAPIExtendCapabilities013', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray013 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('13.napiCreateSendableTypedArray')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateSendableTypedArraySuccess')); - console.info('uitest: testNodeAPIArray013 end'); - done(); - }) - - /** - * 点击,调用napiWrapSendable相关函数 - */ - it('testNodeAPIExtendCapabilities014', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities014 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('14.napiWrapSendable')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiWrapSendableSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities014 end'); - done(); - }) - - /** - * 点击,调用napiWrapSendableWithSize相关函数 - */ - it('testNodeAPIExtendCapabilities015', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities015 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('15.napiWrapSendableWithSize')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiWrapSendableWithSizeSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities015 end'); - done(); - }) - - /** - * 点击,调用napiUnwrapSendable相关函数 - */ - it('testNodeAPIExtendCapabilities016', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities016 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('16.napiUnwrapSendable')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiUnwrapSendableSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities016 end'); - done(); - }) - - /** - * 点击,调用napiRemoveWrapSendable相关函数 - */ - it('testNodeAPIExtendCapabilities017', 0, async (done: Function) => { - console.info('uitest: testNodeAPIExtendCapabilities017 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('17.napiRemoveWrapSendable')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiRemoveWrapSendableSuccess')); - console.info('uitest: testNodeAPIExtendCapabilities017 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIExtendCapabilitiesTest() { + describe('nodeAPIExtendCapabilitiesTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击,调用napiLoadModule相关函数 + */ + it('testNodeAPIExtendCapabilities001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiLoadModule')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiLoadModuleSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities001 end'); + done(); + }) + + /** + * 点击,调用napiCreateObjectWithProperties相关函数 + */ + it('testNodeAPIExtendCapabilities002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCreateObjectWithProperties')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateObjectWithPropertiesSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities002 end'); + done(); + }) + + /** + * 点击,调用napiCreateObjectWithNamedProperties相关函数 + */ + it('testNodeAPIExtendCapabilities003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiCreateObjectWithNamedProperties')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateObjectWithNamedPropertiesSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities003 end'); + done(); + }) + + /** + * 点击,调用napiRunScriptPath相关函数 + */ + it('testNodeAPIExtendCapabilities004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiRunScriptPath')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiRunScriptPathSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities004 end'); + done(); + }) + + /** + * 点击,调用napiCoerceToNativeBindingObject相关函数 + */ + it('testNodeAPIExtendCapabilities005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiCoerceToNativeBindingObject')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCoerceToNativeBindingObjectSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities005 end'); + done(); + }) + + /** + * 点击,调用napiAboutSerialize相关函数 + */ + it('testNodeAPIExtendCapabilities006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiAboutSerialize')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiAboutSerializeSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities006 end'); + done(); + }) + + /** + * 点击,调用napiIsSendable相关函数 + */ + it('testNodeAPIExtendCapabilities007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiIsSendable')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsSendableSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities007 end'); + done(); + }) + + /** + * 点击,调用napiDefineSendableClass相关函数 + */ + it('testNodeAPIExtendCapabilities008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiDefineSendableClass')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiDefineSendableClassSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities008 end'); + done(); + }) + + /** + * 点击,调用napiCreateSendableObjectWithProperties相关函数 + */ + it('testNodeAPIExtendCapabilities009', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities009 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('9.napiCreateSendableObjectWithProperties')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateSendableObjectWithPropertiesSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities009 end'); + done(); + }) + + /** + * 点击,调用napiCreateSendableArray相关函数 + */ + it('testNodeAPIExtendCapabilities010', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities010 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('10.napiCreateSendableArray')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateSendableArraySuccess')); + console.info('uitest: testNodeAPIExtendCapabilities010 end'); + done(); + }) + + /** + * 点击,调用napiCreateSendableArrayWithLength相关函数 + */ + it('testNodeAPIExtendCapabilities011', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities011 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const list = await driver.findComponent(ON.id('List')) + await list.scrollToBottom(); + const text = await driver.findComponent(ON.text('11.napiCreateSendableArrayWithLength')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateSendableArrayWithLengthSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities011 end'); + done(); + }) + + /** + * 点击,调用napiCreateSendableArraybuffer相关函数 + */ + it('testNodeAPIExtendCapabilities012', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities012 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('12.napiCreateSendableArraybuffer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateSendableArraybufferSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities012 end'); + done(); + }) + + /** + * 点击,调用napiCreateSendableTypedArray相关函数 + */ + it('testNodeAPIExtendCapabilities013', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray013 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('13.napiCreateSendableTypedArray')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateSendableTypedArraySuccess')); + console.info('uitest: testNodeAPIArray013 end'); + done(); + }) + + /** + * 点击,调用napiWrapSendable相关函数 + */ + it('testNodeAPIExtendCapabilities014', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities014 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('14.napiWrapSendable')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiWrapSendableSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities014 end'); + done(); + }) + + /** + * 点击,调用napiWrapSendableWithSize相关函数 + */ + it('testNodeAPIExtendCapabilities015', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities015 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('15.napiWrapSendableWithSize')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiWrapSendableWithSizeSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities015 end'); + done(); + }) + + /** + * 点击,调用napiUnwrapSendable相关函数 + */ + it('testNodeAPIExtendCapabilities016', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities016 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('16.napiUnwrapSendable')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiUnwrapSendableSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities016 end'); + done(); + }) + + /** + * 点击,调用napiRemoveWrapSendable相关函数 + */ + it('testNodeAPIExtendCapabilities017', 0, async (done: Function) => { + console.info('uitest: testNodeAPIExtendCapabilities017 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('17.napiRemoveWrapSendable')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiRemoveWrapSendableSuccess')); + console.info('uitest: testNodeAPIExtendCapabilities017 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..607ec76e71fa62109565c5eb49cb391a6c2e569d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/ohosTest.md @@ -0,0 +1,23 @@ +# 使用Node-API进行扩展能力功能开发测试用例归档 + +## 用例表 + +| 测试功能 | 预 置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------------------ | ------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 createObjectWithProperties | 位于主页 | 点击文本为1.napiCreateObjectWithProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateObjectWithPropertiesSuccess | Pass | +| ArkTS端成功调用native侧接口createObjectWithNameProperties | 位于主页 | 点击文本为2.napiCreateObjectWithNamedProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateObjectWithNamedPropertiesSuccess | Pass | +| ArkTS端成功调用native侧接口runScriptPath | 位于主页 | 点击文本为3.napiRunScriptPath的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRunScriptPathSuccess | Pass | +| ArkTS端成功调用native侧接口getAddress,getSetSize,store,erase,clear | 位于主页 | 点击文本为4.napiCoerceToNativeBindingObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToNativeBindingObjectSuccess | Pass | +| ArkTS端成功调用native侧接口aboutSerialize | 位于主页 | 点击文本为5.napiAboutSerialize的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiAboutSerializeSuccess | Pass | +| ArkTS端成功调用native侧接口isSendable | 位于主页 | 点击文本为6.napiIsSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsSendableSuccess | Pass | +| ArkTS端成功调用native侧接口SendableClass | 位于主页 | 点击文本为7.napiDefineSendableClass的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDefineSendableClassSuccess | Pass | +| ArkTS端成功调用native侧接口getSendableObject | 位于主页 | 点击文本为8.napiCreateSendableObjectWithProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableObjectWithPropertiesSuccess | Pass | +| ArkTS端成功调用native侧接口getSendableArray | 位于主页 | 点击文本为9.napiCreateSendableArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableArraySuccess | Pass | +| ArkTS端成功调用native侧接口getSendableArrayWithLength | 位于主页 | 点击文本为10.napiCreateSendableArrayWithLength的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableArrayWithLengthSuccess | Pass | +| ArkTS端成功调用native侧接口getSendableArrayBuffer | 位于主页 | 点击文本为11.napiCreateSendableArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableArraybufferSuccess | Pass | +| ArkTS端成功调用native侧接口getSendableTypedArray | 位于主页 | 点击文本为12.napiCreateSendableTypedArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableTypedArraySuccess | Pass | +| ArkTS端成功调用native侧接口wrapSendable | 位于主页 | 点击文本为13.napiWrapSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiWrapSendableSuccess | Pass | +| ArkTS端成功调用native侧接口wrapSendableWithSize | 位于主页 | 点击文本为14.napiWrapSendableWithSize的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiWrapSendableWithSizeSuccess | Pass | +| ArkTS端成功调用native侧接口unwrapSendable | 位于主页 | 点击文本为15.napiUnwrapSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiUnwrapSendableSuccess | Pass | +| ArkTS端成功调用native侧接口removeWrapSendable | 位于主页 | 点击文本为16.napiRemoveWrapSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveWrapSendableSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/screenshots/NodeAPIExtendCapabilities2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/.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/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..387aa7412d1aba98da6e635bfe9b68f25fd8cb73 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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.nodeapifunction", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1ed347339c44314b3863956d34f536c0f3379ad1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIFunction" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/README.md new file mode 100644 index 0000000000000000000000000000000000000000..153bb70af463818a007e5b856999401a51d3999e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行function相关开发 + +### 介绍 + +函数调用允许开发者从Node-API模块中调用ArkTS函数,并传递参数进行调用,或者直接在Node-API模块中创建一个ArkTS方法,本工程中展示的代码详细描述可查如下链接。 + +- [使用Node-API进行function相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-function.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIFunction.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行function相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIFunction.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e73eccd5e9220359542d5fb58fc94cede9c119b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIFunctio) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ad39888a62fb8defd0c10d2ce1d6b7905bb1207 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_get_cb_info] +#include "napi/native_api.h" + +// napi_get_cb_info +// 获取ArkTS侧入参的的参数信息 +static napi_value GetCbArgs(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + return args[0]; +} + +// 获取ArkTS侧入参的参数个数 +static napi_value GetCbArgQuantity(napi_env env, napi_callback_info info) +{ + size_t argc = 0; + napi_value result = nullptr; + napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr); + napi_create_int32(env, argc, &result); + return result; +} + +// 获取ArkTS侧this参数 +static napi_value GetCbContext(napi_env env, napi_callback_info info) +{ + napi_value thisArg = nullptr; + napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, nullptr); + return thisArg; +} +// [End napi_get_cb_info] + +// [Start napi_call_function] +// napi_call_function +static napi_value CallFunction(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value argv[1] = {nullptr}; + // 获取ArkTS侧入参 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 获取全局对象,这里用global是因为napi_call_function的第二个参数是JS函数的this入参。 + napi_value global = nullptr; + napi_get_global(env, &global); + // 调用ArkTS方法 + napi_value result = nullptr; + // 调用napi_call_function时传入的argv的长度必须大于等于argc声明的数量,且被初始化成nullptr + napi_call_function(env, global, argv[0], argc, argv, &result); + return result; +} + +static napi_value ObjCallFunction(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传递的两个参数 + size_t argc = 2; + napi_value argv[2] = {nullptr}; + // 获取ArkTS侧入参 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 调用ArkTS方法 + napi_value result = nullptr; + // 调用napi_call_function时传入的argv的长度必须大于等于argc声明的数量,且被初始化成nullptr + napi_call_function(env, argv[0], argv[1], argc, argv, &result); + return result; +} +// [End napi_call_function] + +// [Start napi_create_function] +// napi_create_function +static napi_value CalculateArea(napi_env env, napi_callback_info info) +{ + // 获取ArkTS侧传递的两个参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + double width = 0; + napi_get_value_double(env, args[0], &width); + double height = 0; + napi_get_value_double(env, args[1], &height); + napi_value area = nullptr; + napi_create_double(env, width * height, &area); + return area; +} +// [End napi_create_function] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getCbArgs", nullptr, GetCbArgs, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getCbArgQuantity", nullptr, GetCbArgQuantity, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getCbContext", nullptr, GetCbContext, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"callFunction", nullptr, CallFunction, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"objCallFunction", nullptr, ObjCallFunction, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_value fn = nullptr; + napi_create_function(env, nullptr, 0, CalculateArea, nullptr, &fn); + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + napi_set_named_property(env, exports, "calculateArea", fn); + 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2c93ee618e16d12f2514c7d36a996f07d6d42896 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_get_cb_info_api] +export const getCbArgs: (arg: T) => T; // napi_get_cb_info + +// getCbArgQuantity的入参由用户自定义,在此用例中,我们用两个入参,一个是string,一个是number +export const getCbArgQuantity: (str: string, num: number) => number; + +export const getCbContext: () => Object; +// [End napi_get_cb_info_api] + +// [Start napi_call_function_api] +export const callFunction: (func: Function) => number; // napi_call_function + +export const objCallFunction: (obj: Object, func: Function) => number; +// [End napi_call_function_api] + +// [Start napi_create_function_api] +export const calculateArea: (width: number, height: number) => number; // napi_create_function +// [End napi_create_function_api] diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..17e4121c9f607dc41501c986e276ae8ab32cfe95 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.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. + */ + +// [Start ark_napi_get_cb_info] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; + +function summation(arr: Array) { + let sum: number = 0; + for (let i = 0; i < arr.length; i++) { + sum += arr[i]; + } + return sum; +} + +const str = 'message'; +const arr = [0, 1, 2, 3, 4, 5]; +const num = 526; + +class Student { + name: string; + age: number; + score: number; + + constructor(name: string, age: number, score: number) { + this.name = name; + this.age = age; + this.score = score; + } +} + +// [StartExclude ark_napi_get_cb_info] +// [Start ark_napi_call_function] +function returnNumber() { + return 10; +} + +class Person { + age(): number { + return 11; + } +} + +// [StartExclude ark_napi_call_function] +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiGetCbInfo', + '2.napiCallFunction', + '3.napiCreateFunction' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(25) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiGetCbInfo') { + // [EndExclude ark_napi_get_cb_info] + // napi_get_cb_info + let student = new Student('Alice', 18, 100); + // 获取参数 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get string arg:%{public}s', + testNapi.getCbArgs(str)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get array arg:%{public}s ', + testNapi.getCbArgs(arr).toString()); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get num arg:%{public}d ', + testNapi.getCbArgs(num)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get undefined arg:%{public}s ', + testNapi.getCbArgs(undefined)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get object arg:%{public}s ', + JSON.stringify(testNapi.getCbArgs(student))); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get function arg:%{public}d ', + testNapi.getCbArgs(summation(arr))); + // 获取参数个数 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get arg quantity:%{public}d ', + testNapi.getCbArgQuantity(str, num)); + // 获取上下文 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get thisArg:%{public}s ', + testNapi.getCbContext().toString()); + // [End ark_napi_get_cb_info] + this.result = 'napiGetCbInfoSuccess'; + } else if (item === '2.napiCallFunction') { + // [EndExclude ark_napi_call_function] + // napi_call_function + const person = new Person(); + hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', + testNapi.callFunction(returnNumber)); + hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', + testNapi.objCallFunction(person, person.age)); + // [End ark_napi_call_function] + this.result = 'napiCallFunctionSuccess'; + } else if (item === '3.napiCreateFunction') { + // [Start ark_napi_create_function] + // napi_create_function + hilog.info(0x0000, 'testTag', 'Test Node-API create_function:%{public}d ', + testNapi.calculateArea(1.2, 4)); + // [End ark_napi_create_function] + this.result = 'napiCreateFunctionSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/NodeAPIFunction.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/NodeAPIFunction.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/NodeAPIFunction.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/NodeAPIFunction.test.ets index e96bf7cf14b9c949fcac205bfb78d4202e931a6e..a6c99e15542b203e85845d55b812d2d9b23175ee --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/NodeAPIFunction.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/ets/test/NodeAPIFunction.test.ets @@ -1,92 +1,92 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIFunctionTest() { - describe('nodeAPIFunctionTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击,调用napiGetCbInfo相关函数 - */ - it('testNodeAPIFunction001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiGetCbInfo')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetCbInfoSuccess')); - console.info('uitest: testNodeAPIArray001 end'); - done(); - }) - - /** - * 点击,调用napiCallFunction相关函数 - */ - it('testNodeAPIFunction002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIFunction002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCallFunction')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCallFunctionSuccess')); - console.info('uitest: testNodeAPIFunction002 end'); - done(); - }) - - /** - * 点击,调用napiCreateFunction相关函数 - */ - it('testNodeAPIFunction003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIFunction003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiCreateFunction')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateFunctionSuccess')); - console.info('uitest: testNodeAPIFunction003 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIFunctionTest() { + describe('nodeAPIFunctionTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击,调用napiGetCbInfo相关函数 + */ + it('testNodeAPIFunction001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiGetCbInfo')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetCbInfoSuccess')); + console.info('uitest: testNodeAPIArray001 end'); + done(); + }) + + /** + * 点击,调用napiCallFunction相关函数 + */ + it('testNodeAPIFunction002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIFunction002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCallFunction')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCallFunctionSuccess')); + console.info('uitest: testNodeAPIFunction002 end'); + done(); + }) + + /** + * 点击,调用napiCreateFunction相关函数 + */ + it('testNodeAPIFunction003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIFunction003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiCreateFunction')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateFunctionSuccess')); + console.info('uitest: testNodeAPIFunction003 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/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/NodeAPI/NodeApiUse/NodeAPIFunction/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..2185351bc19c54e84388d45f2672a9489ac97738 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/ohosTest.md @@ -0,0 +1,10 @@ +# 使用Node-API进行function相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 getCbArgs,getCbArgQuantity,getCbContext | 位于主页 | 点击文本为1.napiGetCbInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetCbInfoSuccess | Pass | +| ArkTS端成功调用native侧接口callFunction,objCallFunction | 位于主页 | 点击文本为2.napiCallFunction的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCallFunctionSuccess | Pass | +| ArkTS端成功调用native侧接口calculateArea | 位于主页 | 点击文本为3.napiCreateFunction的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateFunctionSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIFunction/screenshots/NodeAPIFunction2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/.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/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3c4059b649808acd398ee92d1a9b4398499d73d5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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.nodeapilifecycle", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..614dd49c770f84229143d282ce234acc2dd1e43d --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPILifeCycle" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9b33a559337c74fcc841817bb937a4c65b85e04c --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行life-cycle相关开发 + +### 介绍 + +在Node-API中,napi_value是一个表示ArkTS值的抽象类型,它可以表示任何ArkTS值,包括基本类型(如数字、字符串、布尔值)和复杂对象类型(如数组、函数、对象等),napi_value的生命周期与其在ArkTS中的对应值的生命周期紧密相关。当ArkTS值被垃圾回收时,与之关联的napi_value也将不再有效。重要的是不要在ArkTS值不再存在时尝试使用napi_value,框架层的scope通常用于管理napi_value的生命周期。在Node-API中,可以使用napi_open_handle_scope和napi_close_handle_scope函数来创建和销毁scope。通过在scope内创建napi_value,可以确保在scope结束时自动释放napi_value,避免内存泄漏,napi_ref是一个Node-API类型,用于管理napi_value的生命周期。napi_ref允许您在napi_value的生命周期内保持对其的引用,即使它已经超出了其原始上下文的范围。这使得您可以在不同的上下文中共享napi_value,并确保在不再需要时正确释放其内存,本工程中展示的代码详细描述可查如下链接。 + +- [使用Node-API进行life-cycle相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-life-cycle.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPILifeCycle.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行life-cycle相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPILifeCycle.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..14f9035365352af3f51715e5b066fd52b5b58163 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPILifeCycle) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11d42cc90b40029227cf1950ce2a8509eddac00a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,196 @@ +/* + * 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 "hilog/log.h" +#include "napi/native_api.h" + +// [Start napi_open_close_handle_scope] +// napi_open_handle_scope、napi_close_handle_scope +static napi_value HandleScopeTest(napi_env env, napi_callback_info info) +{ + // 通过调用napi_open_handle_scope来创建一个句柄作用域 + napi_handle_scope scope; + napi_open_handle_scope(env, &scope); + // 在句柄作用域内创建一个obj + napi_value obj = nullptr; + napi_create_object(env, &obj); + // 在对象中添加属性 + napi_value value = nullptr; + napi_create_string_utf8(env, "handleScope", NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, obj, "key", value); + // 在作用域内获取obj的属性并返回 + napi_value result = nullptr; + napi_get_named_property(env, obj, "key", &result); + // 关闭句柄作用域,自动释放在该作用域内创建的对象句柄 + napi_close_handle_scope(env, scope); + // 此处的result能够得到值“handleScope” + return result; +} + +static napi_value HandleScope(napi_env env, napi_callback_info info) +{ + // 通过调用napi_open_handle_scope来创建一个句柄作用域 + napi_handle_scope scope; + napi_open_handle_scope(env, &scope); + // 在句柄作用域内创建一个obj + napi_value obj = nullptr; + napi_create_object(env, &obj); + // 在对象中添加属性 + napi_value value = nullptr; + napi_create_string_utf8(env, "handleScope", NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, obj, "key", value); + // 关闭句柄作用域,自动释放在该作用域内创建的对象句柄 + napi_close_handle_scope(env, scope); + // 在作用域外获取obj的属性并返回,此处只能得到“undefined” + napi_value result = nullptr; + napi_get_named_property(env, obj, "key", &result); + return result; +} +// [End napi_open_close_handle_scope] + +// [Start napi_open_close_escapable_handle_scope] +// napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle +static napi_value EscapableHandleScopeTest(napi_env env, napi_callback_info info) +{ + // 创建一个可逃逸的句柄作用域 + napi_escapable_handle_scope scope; + napi_open_escapable_handle_scope(env, &scope); + // 在可逃逸的句柄作用域内创建一个obj + napi_value obj = nullptr; + napi_create_object(env, &obj); + // 在对象中添加属性 + napi_value value = nullptr; + napi_create_string_utf8(env, "Test napi_escapable_handle_scope", NAPI_AUTO_LENGTH, &value); + napi_set_named_property(env, obj, "key", value); + // 调用napi_escape_handle将对象逃逸到作用域之外 + napi_value escapedObj = nullptr; + napi_escape_handle(env, scope, obj, &escapedObj); + // 关闭可逃逸的句柄作用域,清理资源 + napi_close_escapable_handle_scope(env, scope); + // 在获取逃逸后的obj:escapedObj的属性并返回,此处也能够得到“napi_escapable_handle_scope” + napi_value result = nullptr; + // 为了验证逃逸的实现,可以在此处获取obj的属性,此处会得到“undefined” + napi_get_named_property(env, escapedObj, "key", &result); + return result; +} +// [End napi_open_close_escapable_handle_scope] + +// [Start napi_create_delete_reference] +// 创建一个指向napi_ref类型的指针,用于存储创建的引用。在调用napi_create_reference函数之前,你需要分配一个napi_ref类型的变量,并将其地址传递给result位置的参数 +napi_ref g_ref; + +void Finalizer(napi_env env, void *data, void *hint) +{ + // 执行资源清理操作 + OH_LOG_INFO(LOG_APP, "Node-API: Use terminators to release resources."); +} + +static napi_value CreateReference(napi_env env, napi_callback_info info) +{ + napi_value obj = nullptr; + napi_create_object(env, &obj); + napi_value value = nullptr; + napi_create_string_utf8(env, "CreateReference", NAPI_AUTO_LENGTH, &value); + // 将键值对添加到对象中 + napi_set_named_property(env, obj, "key", value); + // [StartExclude napi_create_delete_reference] + // 创建对ArkTS对象的引用 + napi_status status = napi_create_reference(env, obj, 1, &g_ref); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_create_reference fail"); + return nullptr; + } + // [EndExclude napi_create_delete_reference] + // 添加终结器 + void *data = {}; + napi_add_finalizer(env, obj, data, Finalizer, nullptr, &g_ref); + // 增加传入引用的引用计数并返回生成的引用计数 + uint32_t result = 0; + napi_reference_ref(env, g_ref, &result); + OH_LOG_INFO(LOG_APP, "napi_reference_ref, count = %{public}d.", result); + uint32_t numCount = 2; + if (result != numCount) { + // 若传入引用的引用计数未增加,则抛出错误 + napi_throw_error(env, nullptr, "napi_reference_ref fail"); + return nullptr; + } + return obj; +} + +static napi_value UseReference(napi_env env, napi_callback_info info) +{ + napi_value obj = nullptr; + // 通过调用napi_get_reference_value获取引用的ArkTS对象 + napi_status status = napi_get_reference_value(env, g_ref, &obj); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_get_reference_value fail"); + return nullptr; + } + // 将获取到的对象返回 + return obj; +} + +static napi_value DeleteReference(napi_env env, napi_callback_info info) +{ + // 减少传入引用的引用计数并返回生成的引用计数 + uint32_t result = 0; + napi_value count = nullptr; + napi_reference_unref(env, g_ref, &result); + OH_LOG_INFO(LOG_APP, "napi_reference_ref, count = %{public}d.", result); + uint32_t numCount = 1; + if (result != numCount) { + // 若传入引用的引用计数未减少,则抛出错误 + napi_throw_error(env, nullptr, "napi_reference_unref fail"); + return nullptr; + } + // 通过调用napi_delete_reference删除对ArkTS对象的引用 + napi_status status = napi_delete_reference(env, g_ref); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_delete_reference fail"); + return nullptr; + } + napi_value returnResult = nullptr; + napi_create_string_utf8(env, "napi_delete_reference success", NAPI_AUTO_LENGTH, &returnResult); + return returnResult; +} +// [End napi_create_delete_reference] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"handleScopeTest", nullptr, HandleScopeTest, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"handleScope", nullptr, HandleScope, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"escapableHandleScopeTest", nullptr, EscapableHandleScopeTest, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"createReference", nullptr, CreateReference, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"useReference", nullptr, UseReference, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"deleteReference", nullptr, DeleteReference, 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..83a3655c86b7e0ba6dc02b2f7b68af7fa4edf7f4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_open_close_handle_scope_api] +export const handleScopeTest: () => string; // napi_open_handle_scope、napi_close_handle_scope + +export const handleScope: () => string; +// [End napi_open_close_handle_scope_api] + +// [Start napi_open_close_escapable_handle_scope_api] +export const escapableHandleScopeTest: () => string; // napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle +// [End napi_open_close_escapable_handle_scope_api] + +// [Start napi_create_delete_reference_api] +export const createReference: () => Object | void; // napi_add_finalizer + +export const useReference: () => Object | void; + +export const deleteReference: () => string | void; +// [End napi_create_delete_reference_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfca35ef5272ec16fe00a031d150080c9c124c0b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,121 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiOpenHandleScope', + '2.napiOpenEscapableHandleScope', + '3.napiAddFinalizer' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiOpenHandleScope') { + // [Start ark_napi_open_close_handle_scope] + // napi_open_handle_scope napi_close_handle_scope + try { + hilog.info(0x0000, 'testTag', 'Test Node-API handleScopeTest: %{public}s', + testNapi.handleScopeTest()); + hilog.info(0x0000, 'testTag', 'Test Node-API handleScope: %{public}s', testNapi.handleScope()); + // [StartExclude ark_napi_open_close_handle_scope] + this.result = 'napiOpenHandleScopeSuccess'; + // [EndExclude ark_napi_open_close_handle_scope] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API handleScopeTest errorCode: %{public}s, errorMessage: %{public}s', error.code, + error.message); + // [StartExclude ark_napi_open_close_handle_scope] + this.result = 'napiOpenHandleScopeFail'; + // [EndExclude ark_napi_open_close_handle_scope] + } + // [End ark_napi_open_close_handle_scope] + } else if (item === '2.napiOpenEscapableHandleScope') { + // [Start ark_napi_open_close_escapable_handle_scope] + // napi_open_escapable_handle_scope napi_close_escapable_handle_scope、napi_escape_handle + try { + hilog.info(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest: %{public}s', + testNapi.escapableHandleScopeTest()); + // [StartExclude ark_napi_open_close_escapable_handle_scope] + this.result = 'napiOpenEscapableHandleScopeSuccess'; + // [EndExclude ark_napi_open_close_escapable_handle_scope] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API EscapableHandleScopeTest errorCode: %{public}s, errorMessage: %{public}s', + error.code, + error.message); + // [StartExclude ark_napi_open_close_escapable_handle_scope] + this.result = 'napiOpenEscapableHandleScopeFail'; + // [EndExclude ark_napi_open_close_escapable_handle_scope] + } + // [End ark_napi_open_close_escapable_handle_scope] + } else if (item === '3.napiAddFinalizer') { + // [Start ark_napi_create_delete_reference] + // napi_add_finalizer + try { + hilog.info(0x0000, 'testTag', 'Test Node-API createReference: %{public}s', + JSON.stringify(testNapi.createReference())); + hilog.info(0x0000, 'testTag', 'Test Node-API useReference: %{public}s', + JSON.stringify(testNapi.useReference())); + hilog.info(0x0000, 'testTag', 'Test Node-API deleteReference: %{public}s', + testNapi.deleteReference()); + // [StartExclude ark_napi_create_delete_reference] + this.result = 'napiAddFinalizerSuccess'; + // [EndExclude ark_napi_create_delete_reference] + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API ReferenceTest errorCode: %{public}s, errorMessage: %{public}s', error.code, + error.message); + // [StartExclude ark_napi_create_delete_reference] + this.result = 'napiAddFinalizerFail'; + // [EndExclude ark_napi_create_delete_reference] + } + // [End ark_napi_create_delete_reference] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/NodeAPILifeCycle.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/NodeAPILifeCycle.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/NodeAPILifeCycle.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/NodeAPILifeCycle.test.ets index f87901c5c86d2453532d376e247a3eb33e472c8f..09225b5744ee01c1bea3b1df5da894676a03f63d --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/NodeAPILifeCycle.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/ets/test/NodeAPILifeCycle.test.ets @@ -1,92 +1,92 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPILifeCycleTest() { - describe('nodeAPILifeCycleTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiOpenHandleScope相关函数 - */ - it('testNodeAPILifeCycle001', 0, async (done: Function) => { - console.info('uitest: testNodeAPILifeCycle001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiOpenHandleScope')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiOpenHandleScopeSuccess')); - console.info('uitest: testNodeAPILifeCycle001 end'); - done(); - }) - - /** - * 点击按钮,调用napiOpenEscapableHandleScope相关函数 - */ - it('testNodeAPILifeCycle002', 0, async (done: Function) => { - console.info('uitest: testNodeAPILifeCycle002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiOpenEscapableHandleScope')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiOpenEscapableHandleScopeSuccess')); - console.info('uitest: testNodeAPILifeCycle002 end'); - done(); - }) - - /** - * 点击按钮,调用napiAddFinalizer相关函数 - */ - it('testNodeAPILifeCycle003', 0, async (done: Function) => { - console.info('uitest: testNodeAPILifeCycle003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiAddFinalizer')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiAddFinalizerSuccess')); - console.info('uitest: testNodeAPILifeCycle003 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPILifeCycleTest() { + describe('nodeAPILifeCycleTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiOpenHandleScope相关函数 + */ + it('testNodeAPILifeCycle001', 0, async (done: Function) => { + console.info('uitest: testNodeAPILifeCycle001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiOpenHandleScope')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiOpenHandleScopeSuccess')); + console.info('uitest: testNodeAPILifeCycle001 end'); + done(); + }) + + /** + * 点击按钮,调用napiOpenEscapableHandleScope相关函数 + */ + it('testNodeAPILifeCycle002', 0, async (done: Function) => { + console.info('uitest: testNodeAPILifeCycle002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiOpenEscapableHandleScope')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiOpenEscapableHandleScopeSuccess')); + console.info('uitest: testNodeAPILifeCycle002 end'); + done(); + }) + + /** + * 点击按钮,调用napiAddFinalizer相关函数 + */ + it('testNodeAPILifeCycle003', 0, async (done: Function) => { + console.info('uitest: testNodeAPILifeCycle003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiAddFinalizer')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiAddFinalizerSuccess')); + console.info('uitest: testNodeAPILifeCycle003 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/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/NodeAPI/NodeApiUse/NodeAPILifeCycle/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..a9e8fe658dd15f101cba6e6e46573cc42ace1a03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/ohosTest.md @@ -0,0 +1,10 @@ +# 使用Node-API进行life-cycle相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 handleScopeTest,handleScope | 位于主页 | 点击文本为1.napiOpenHandleScope的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiOpenHandleScopeSuccess | Pass | +| ArkTS端成功调用native侧接口createArrayWithLength | 位于主页 | 点击文本为2.escapableHandleScopeTest的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiOpenEscapableHandleScopeSuccess | Pass | +| ArkTS端成功调用native侧接口createReference,useReference,deleteReference | 位于主页 | 点击文本为3.napiAddFinalizer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiAddFinalizerSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPILifeCycle/screenshots/NodeAPILifeCycle2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/.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/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..0decfcbcf49f844403d1d21fde29c32e38332f7f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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.nodeapiobject", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7e559b881b5e1e421c9b3098cfc09841c006799b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIObject" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5e8579cd0a0d80dd2c4fb3d6d8c47492fdf3c894 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行object相关开发 + +### 介绍 + +使用Node-API接口进行object相关开发,处理ArkTS对象的基本操作的功能,例如创建对象、获取原型、冻结和密封对象,检查对象的类型等。这些操作是在处理ArkTS对象时非常常见的,提供了一种与ArkTS对象交互的方式,本工程中展示的代码详细描述可查如下链接。 + +- [使用Node-API进行object相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-object.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIObject.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行object相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIObject.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIObject/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..20682a016d99c9e93e88b6032230a6dc7c4d6e17 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIObject) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..719f648475bb682f40b376e6fbde2ceeeeeaa0f1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,303 @@ +/* + * 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 +#include +#include "hilog/log.h" +#include "napi/native_api.h" + +// napi_get_prototype +static napi_value GetPrototype(napi_env env, napi_callback_info info) +{ + // 获取并解析传参 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value result = nullptr; + // 获取此对象的原型对象,将结果返回到napi_value类型的变量result中 + napi_get_prototype(env, args[0], &result); + return result; +} +// napi_create_object +napi_value NewObject(napi_env env, napi_callback_info info) +{ + napi_value object = nullptr; + // 创建一个空对象 + napi_create_object(env, &object); + // 设置对象的属性 + napi_value name = nullptr; + // 设置属性名为"name" + napi_create_string_utf8(env, "name", NAPI_AUTO_LENGTH, &name); + napi_value value = nullptr; + // 设置属性值为"Hello from Node-API!" + napi_create_string_utf8(env, "Hello from Node-API!", NAPI_AUTO_LENGTH, &value); + // 将属性设置到对象上 + napi_set_property(env, object, name, value); + return object; +} +// napi_object_freeze +static napi_value ObjectFreeze(napi_env env, napi_callback_info info) +{ + // 接受一个ArkTS侧传入的object + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + + // 调用接口napi_object_freeze将传入的object冻结 + napi_value objFreeze = argv[0]; + napi_status status = napi_object_freeze(env, objFreeze); + if (status == napi_ok) { + OH_LOG_INFO(LOG_APP, "Node-API napi_object_freeze success"); + } + // 将冻结后的object传回ArkTS侧 + return objFreeze; +} +// napi_object_seal +static napi_value ObjectSeal(napi_env env, napi_callback_info info) +{ + // 接受一个ArkTS侧传入的object + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 调用接口napi_object_seal将传入的object封闭,使其无法添加新的属性 + napi_value objSeal = argv[0]; + napi_status status = napi_object_seal(env, objSeal); + if (status == napi_ok) { + OH_LOG_INFO(LOG_APP, "Node-API napi_object_seal success"); + } + // 将封闭后的object传回ArkTS侧 + return objSeal; +} +// napi_typeof +static napi_value NapiTypeof(napi_env env, napi_callback_info info) +{ + // 接受一个入参 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 调用napi_typeof判断传入ArkTS参数类型 + napi_valuetype valueType; + napi_status status = napi_typeof(env, args[0], &valueType); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_typeof fail"); + return nullptr; + } + // 将结果转成napi_value类型返回。 + napi_value returnValue = nullptr; + switch (valueType) { + case napi_undefined: + napi_create_string_utf8(env, "Input type is napi_undefined", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_null: + napi_create_string_utf8(env, "Input type is napi_null", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_boolean: + napi_create_string_utf8(env, "Input type is napi_boolean", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_number: + napi_create_string_utf8(env, "Input type is napi_number", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_string: + napi_create_string_utf8(env, "Input type is napi_string", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_object: + napi_create_string_utf8(env, "Input type is napi_object", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_function: + napi_create_string_utf8(env, "Input type is napi_function", NAPI_AUTO_LENGTH, &returnValue); + break; + case napi_bigint: + napi_create_string_utf8(env, "Input type is napi_bigint", NAPI_AUTO_LENGTH, &returnValue); + break; + default: + napi_create_string_utf8(env, "unknown", NAPI_AUTO_LENGTH, &returnValue); + } + return returnValue; +} +// napi_instanceof +static napi_value NapiInstanceof(napi_env env, napi_callback_info info) +{ + // 接受两个入参 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 调用napi_instanceof接口判断给定object是否为给定constructor的实例 + bool result = true; + napi_status status = napi_instanceof(env, args[0], args[1], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_instanceof fail"); + return nullptr; + } + // 将结果转成napi_value类型返回 + napi_value returnValue = nullptr; + napi_get_boolean(env, result, &returnValue); + + return returnValue; +} + +#define NUMBERINT_FOUR 4 +// 定义一个静态常量napi_type_tag数组存储类型标签 +static const napi_type_tag TagsData[NUMBERINT_FOUR] = { + {0x9e4b2449547061b3, 0x33999f8a6516c499}, + {0x1d55a794c53a726d, 0x43633f509f9c944e}, + // 用于表示无标签或默认标签 + {0, 0}, + {0x6a971439f5b2e5d7, 0x531dc28a7e5317c0}, +}; +// napi_type_tag_object +static napi_value SetTypeTagToObject(napi_env env, napi_callback_info info) +{ + // 获取函数调用信息和参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取索引数字转换为napi_value + int32_t index = 0; + napi_get_value_int32(env, args[1], &index); + // 给参数(对象)设置类型标签 + napi_status status = napi_type_tag_object(env, args[0], &TagsData[index]); + if (status != napi_ok) { + napi_throw_error(env, "Reconnect error", "napi_type_tag_object failed"); + return nullptr; + } + // 将bool结果转换为napi_value并返回 + napi_value result = nullptr; + napi_get_boolean(env, true, &result); + return result; +} +// napi_check_object_type_tag +static napi_value CheckObjectTypeTag(napi_env env, napi_callback_info info) +{ + // 获取函数调用信息和参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取索引数字转换为napi_value + int32_t index = 0; + napi_get_value_int32(env, args[1], &index); + // 检查对象的类型标签 + bool checkResult = true; + napi_check_object_type_tag(env, args[0], &TagsData[index], &checkResult); + // 将bool结果转换为napi_value并返回 + napi_value checked = nullptr; + napi_get_boolean(env, checkResult, &checked); + + return checked; +} + +// 用于释放外部数据的回调函数 +void finalizeCallback(napi_env env, void *data, void *hint) +{ + // 释放外部数据 + free(data); +} +// napi_create_external +static napi_value GetExternalType(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取参数的数据类型 + napi_valuetype valueType; + napi_typeof(env, args[0], &valueType); + napi_value returnValue = nullptr; + if (valueType == napi_external) { + // 如果数据类型是napi_external,则返回true + napi_get_boolean(env, true, &returnValue); + } else { + napi_get_boolean(env, false, &returnValue); + } + return returnValue; +} + +static napi_value CreateExternal(napi_env env, napi_callback_info info) +{ + // 设置外部数据大小为10 + const size_t dataSize = 10; + // 分配外部数据 + void *data = malloc(dataSize); + // 初始化外部数据 + memset(data, 0, dataSize); + napi_value result = nullptr; + // 返回带有外部数据的对象 + napi_status status = napi_create_external(env, data, finalizeCallback, nullptr, &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, " Node-API Failed to create external data"); + return nullptr; + } + return result; +} +// napi_get_value_external +static int g_external = 5; +static napi_value GetValueExternal(napi_env env, napi_callback_info info) +{ + // 创建外部数据 + int *data = &g_external; + napi_value setExternal = nullptr; + napi_create_external(env, data, nullptr, nullptr, &setExternal); + // 获得外部数据的值 + void *getExternal; + napi_get_value_external(env, setExternal, &getExternal); + // 返回获得到的外部数据 + napi_value result = nullptr; + napi_create_int32(env, *(int *)getExternal, &result); + return result; +} +// napi_create_symbol +static napi_value CreateSymbol(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + const char *des = "only"; + // 使用napi_create_string_utf8创建描述字符串 + napi_create_string_utf8(env, des, NAPI_AUTO_LENGTH, &result); + napi_value returnSymbol = nullptr; + // 创建一个symbol类型,并返回 + napi_create_symbol(env, result, &returnSymbol); + return returnSymbol; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getPrototype", nullptr, GetPrototype, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createObject", nullptr, NewObject, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"objectFreeze", nullptr, ObjectFreeze, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"objectSeal", nullptr, ObjectSeal, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiTypeof", nullptr, NapiTypeof, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiInstanceof", nullptr, NapiInstanceof, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setTypeTagToObject", nullptr, SetTypeTagToObject, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"checkObjectTypeTag", nullptr, CheckObjectTypeTag, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createExternal", nullptr, GetExternalType, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getExternalType", nullptr, CreateExternal, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueExternal", nullptr, GetValueExternal, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createSymbol", nullptr, CreateSymbol, 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e7e947155818906dd51f76fd9b888f6b304081b1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const getPrototype: (object: Object) => Object; // napi_get_prototype + +export const createObject: () => { name: string }; // napi_create_object + +export interface Obj { + data: number + message: string +} + +export const objectFreeze: (objFreeze: Object) => Obj; // napi_object_freeze + +export interface Obj1 { + data: number + message: string + id: number +} + +export const objectSeal: (objSeal: Object) => Obj1; // napi_object_seal + +export const napiTypeof: (value: T) => string | void; // napi_typeof + +export const napiInstanceof: (date: Object, construct: Object) => boolean | void; // napi_instanceof + +export const setTypeTagToObject: (obj: Object, index: number) => boolean | void; // napi_type_tag_object + +export const checkObjectTypeTag: (obj: Object, index: number) => boolean; // napi_check_object_type_tag + +export const createExternal: () => Object; // napi_create_external + +export const getExternalType: (externalData: Object) => boolean; // napi_create_external + +export const getValueExternal: () => number; // napi_get_value_external + +export const createSymbol: () => symbol; // napi_create_symbol \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e09c966fc6c0f06a37be377ab154e31abaa007d5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,234 @@ +/* + * 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 { napiGetPrototype } from './napiGetPrototype'; + +// 定义一个类 +class Person { + // 属性 + name: string; + age: number; + + // 构造函数 + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } +} + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiGetPrototype', + '2.napiCreateObject', + '3.napiObjectFreeze', + '4.napiObjectSeal', + '5.napiTypeof', + '6.napiInstanceof', + '7.napiTypeTagObject', + '8.napiCreateExternal', + '9.napiGetValueExternal', + '10.napiCreateSymbol' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(22) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiGetPrototype') { + napiGetPrototype(); + this.result = 'napiGetPrototypeSuccess'; + } else if (item === '2.napiCreateObject') { + // napi_create_object + try { + const myObject = testNapi.createObject(); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_object: %{public}s', myObject.name); + this.result = 'napiCreateObjectSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', + 'Test Node-API napi_create_object errorCode: %{public}s, errorMessage: %{public}s', error.code, + error.message); + this.result = 'napiCreateObjectFail'; + } + } else if (item === '3.napiObjectFreeze') { + // napi_object_freeze + try { + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + let objFreeze = testNapi.objectFreeze(obj); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_freeze: %{public}s', (objFreeze.data = 1)); + this.result = 'napiObjectFreezeSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_object_freeze error: %{public}s', error.message); + this.result = 'napiObjectFreezeFail'; + } + } else if (item === '4.napiObjectSeal') { + // napi_object_seal + try { + class Obj { + public data: number = 0 + public message: string = '' + // 可选属性 + public address?: number = 0 + } + + let obj: Obj = { data: 0, message: 'hello world' }; + let objSeal = testNapi.objectSeal(obj); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_seal: %{public}s', objSeal.message); + objSeal.data = 1; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_seal: %{public}d', objSeal.data); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_seal: %{public}d', (objSeal.id = 1)); + this.result = 'napiObjectSealSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_object_seal error: %{public}s', error.message); + this.result = 'napiObjectSealFail'; + } + } else if (item === '5.napiTypeof') { + // napi_typeof + try { + let varUndefined: undefined; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', + testNapi.napiTypeof(varUndefined)); + let varNull: null = null; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', + testNapi.napiTypeof(varNull)); + let varTrue = true; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', + testNapi.napiTypeof(varTrue)); + let varNum = 1; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', testNapi.napiTypeof(varNum)); + let varString = 'str'; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', + testNapi.napiTypeof(varString)); + + class Obj { + public id: number = 0 + public name: string = '' + } + + let varObject: Obj = { id: 1, name: 'LiLei' }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', + testNapi.napiTypeof(varObject)); + const addNum = (a: number, b: number): number => a * b; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', testNapi.napiTypeof(addNum)); + let varBigint = BigInt('1234567890123456789012345678901234567890'); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', + testNapi.napiTypeof(varBigint)); + this.result = 'napiTypeofSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_typeof error: %{public}s', error.message); + this.result = 'napiTypeofFail'; + } + } else if (item === '6.napiInstanceof') { + // napi_instanceof + try { + class Person { + public name: string; + public age: number; + + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } + } + + const person = new Person('Alice', 30); + + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_instanceof: %{public}s', + testNapi.napiInstanceof(person, Person)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_instanceof: %{public}s', + testNapi.napiInstanceof(obj, Person)); + this.result = 'napiInstanceofSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_instanceof error: %{public}s', error.message); + this.result = 'napiInstanceofFail'; + } + } else if (item === '7.napiTypeTagObject') { + + // napi_type_tag_object and napi_check_object_type_tag + class Obj { + public data: number = 0 + public message: string = '' + } + + let objA: Obj = { data: 0, message: 'hello world' }; + let objB: Obj = { data: 10, message: 'typetag' }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_type_tag_object objA -> 0: %{public}s', + testNapi.setTypeTagToObject(objA, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_type_tag_object objB -> 0: %{public}s', + testNapi.setTypeTagToObject(objB, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_check_object_type_tag objA -> 0: %{public}s', + testNapi.checkObjectTypeTag(objA, 0)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_check_object_type_tag objB -> 1: %{public}s', + testNapi.checkObjectTypeTag(objB, 1)); + this.result = 'napiTypeTagObjectSuccess'; + } else if (item === '8.napiCreateExternal') { + // napi_create_external + const externalData = testNapi.createExternal(); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_external:%{public}s', + testNapi.getExternalType(externalData)); + this.result = 'napiCreateExternalSuccess'; + } else if (item === '9.napiGetValueExternal') { + // napi_get_value_external + hilog.info(0x0000, 'Node-API', 'get_value_external:%{public}d', testNapi.getValueExternal()); + this.result = 'napiGetValueExternalSuccess'; + } else if (item === '10.napiCreateSymbol') { + // napi_create_symbol + let varSymbol = testNapi.createSymbol(); + hilog.info(0x0000, 'Node-API', 'createSymbol:%{public}s', typeof varSymbol); + this.result = 'napiCreateSymbolSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/napiGetPrototype.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/napiGetPrototype.ts old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/napiGetPrototype.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/napiGetPrototype.ts index 64a5b11f3b8897ebc23191440d8c21f75ea98086..27a5176ac28468c7516fb6750469b7f68917f462 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/napiGetPrototype.ts +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/napiGetPrototype.ts @@ -1,43 +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 testNapi from 'libentry.so'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -export function napiGetPrototype() { - class Person { - // 属性 - name: string; - age: number; - - // 构造函数 - constructor(name: string, age: number) { - this.name = name; - this.age = age; - } - } - - //创建类的实例 - const person = new Person('Alice', 30); - // 传入实例对象,获取该对象的原型 - let applePrototype = testNapi.getPrototype(person); - // 判断通过testNapi.getPrototype()函数获取到的原型是不是apple的原型 - // 在DevEco Studio 4.1及以后的版本中,由于ArkTS没有原型的概念,因此尝试进行原型赋值或相关操作时,将会触发错误提示'Prototype assignment is not supported (arkts-no-prototype-assignment)',以下代码需在ts文件中执行 - if (applePrototype === Person.prototype) { - hilog.info(0x0000, 'Node-API', 'get_prototype_success'); - } else { - hilog.info(0x0000, 'Node-API', 'get_prototype_fail'); - } +/* + * 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 { hilog } from '@kit.PerformanceAnalysisKit'; + +export function napiGetPrototype() { + class Person { + // 属性 + name: string; + age: number; + + // 构造函数 + constructor(name: string, age: number) { + this.name = name; + this.age = age; + } + } + + //创建类的实例 + const person = new Person('Alice', 30); + // 传入实例对象,获取该对象的原型 + let applePrototype = testNapi.getPrototype(person); + // 判断通过testNapi.getPrototype()函数获取到的原型是不是apple的原型 + // 在DevEco Studio 4.1及以后的版本中,由于ArkTS没有原型的概念,因此尝试进行原型赋值或相关操作时,将会触发错误提示'Prototype assignment is not supported (arkts-no-prototype-assignment)',以下代码需在ts文件中执行 + if (applePrototype === Person.prototype) { + hilog.info(0x0000, 'Node-API', 'get_prototype_success'); + } else { + hilog.info(0x0000, 'Node-API', 'get_prototype_fail'); + } }; \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/NodeAPIObject.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/NodeAPIObject.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/NodeAPIObject.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/NodeAPIObject.test.ets index 21bcb3d083c7b88aea39083d25223ba8853fe781..b0da8a29b4688f332d0b04c1b5b9569baf63d9f0 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/NodeAPIObject.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/ets/test/NodeAPIObject.test.ets @@ -1,204 +1,204 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIObjectTest() { - describe('nodeAPIObjectTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiGetPrototype相关函数 - */ - it('testNodeAPIObject001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiGetPrototype')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetPrototypeSuccess')); - console.info('uitest: testNodeAPIObject001 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateObject相关函数 - */ - it('testNodeAPIObject002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCreateObject')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateObjectSuccess')); - console.info('uitest: testNodeAPIObject002 end'); - done(); - }) - - /** - * 点击按钮,调用napiObjectFreeze相关函数 - */ - it('testNodeAPIObject003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiObjectFreeze')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiObjectFreezeFail')); - console.info('uitest: testNodeAPIObject003 end'); - done(); - }) - - /** - * 点击按钮,调用napiObjectSeal相关函数 - */ - it('testNodeAPIObject004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiObjectSeal')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiObjectSealFail')); - console.info('uitest: testNodeAPIObject004 end'); - done(); - }) - - /** - * 点击按钮,调用napiTypeof相关函数 - */ - it('testNodeAPIObject005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiTypeof')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiTypeofSuccess')); - console.info('uitest: testNodeAPIObject005 end'); - done(); - }) - - /** - * 点击按钮,调用napiInstanceof相关函数 - */ - it('testNodeAPIObject006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiInstanceof')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiInstanceofSuccess')); - console.info('uitest: testNodeAPIObject006 end'); - done(); - }) - - /** - * 点击按钮,调用napiTypeTagObject相关函数 - */ - it('testNodeAPIObject007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiTypeTagObject')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiTypeTagObjectSuccess')); - console.info('uitest: testNodeAPIObject007 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateExternal相关函数 - */ - it('testNodeAPIObject008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiCreateExternal')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateExternalSuccess')); - console.info('uitest: testNodeAPIObject008 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueExternal相关函数 - */ - it('testNodeAPIObject009', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject009 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('9.napiGetValueExternal')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueExternalSuccess')); - console.info('uitest: testNodeAPIObject009 end'); - done(); - }) - - /** - * 点击按钮,调用napiCreateSymbol相关函数 - */ - it('testNodeAPIObject010', 0, async (done: Function) => { - console.info('uitest: testNodeAPIObject010 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('10.napiCreateSymbol')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCreateSymbolSuccess')); - console.info('uitest: testNodeAPIObject010 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIObjectTest() { + describe('nodeAPIObjectTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiGetPrototype相关函数 + */ + it('testNodeAPIObject001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiGetPrototype')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetPrototypeSuccess')); + console.info('uitest: testNodeAPIObject001 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateObject相关函数 + */ + it('testNodeAPIObject002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCreateObject')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateObjectSuccess')); + console.info('uitest: testNodeAPIObject002 end'); + done(); + }) + + /** + * 点击按钮,调用napiObjectFreeze相关函数 + */ + it('testNodeAPIObject003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiObjectFreeze')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiObjectFreezeFail')); + console.info('uitest: testNodeAPIObject003 end'); + done(); + }) + + /** + * 点击按钮,调用napiObjectSeal相关函数 + */ + it('testNodeAPIObject004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiObjectSeal')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiObjectSealFail')); + console.info('uitest: testNodeAPIObject004 end'); + done(); + }) + + /** + * 点击按钮,调用napiTypeof相关函数 + */ + it('testNodeAPIObject005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiTypeof')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiTypeofSuccess')); + console.info('uitest: testNodeAPIObject005 end'); + done(); + }) + + /** + * 点击按钮,调用napiInstanceof相关函数 + */ + it('testNodeAPIObject006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiInstanceof')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiInstanceofSuccess')); + console.info('uitest: testNodeAPIObject006 end'); + done(); + }) + + /** + * 点击按钮,调用napiTypeTagObject相关函数 + */ + it('testNodeAPIObject007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiTypeTagObject')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiTypeTagObjectSuccess')); + console.info('uitest: testNodeAPIObject007 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateExternal相关函数 + */ + it('testNodeAPIObject008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiCreateExternal')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateExternalSuccess')); + console.info('uitest: testNodeAPIObject008 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueExternal相关函数 + */ + it('testNodeAPIObject009', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject009 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('9.napiGetValueExternal')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueExternalSuccess')); + console.info('uitest: testNodeAPIObject009 end'); + done(); + }) + + /** + * 点击按钮,调用napiCreateSymbol相关函数 + */ + it('testNodeAPIObject010', 0, async (done: Function) => { + console.info('uitest: testNodeAPIObject010 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('10.napiCreateSymbol')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCreateSymbolSuccess')); + console.info('uitest: testNodeAPIObject010 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/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/NodeAPI/NodeApiUse/NodeAPIObject/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..3a03dabf0e6be61925897562c63e67b6c2224f40 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/ohosTest.md @@ -0,0 +1,17 @@ +# 使用Node-API进行object相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ------------------------------------------ | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 napiGetPrototype | 位于主页 | 点击文本为1.napiGetPrototype的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetPrototypeSuccess | Pass | +| ArkTS端成功调用native侧接口createObject | 位于主页 | 点击文本为2.napiCreateObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateObjectSuccess | Pass | +| ArkTS端成功调用native侧接口objectFreeze | 位于主页 | 点击文本为3.napiObjectFreeze的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiObjectFreezeSuccess | Pass | +| ArkTS端成功调用native侧接口objectSeal | 位于主页 | 点击文本为4.napiObjectSeal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiObjectSealSuccess | Pass | +| ArkTS端成功调用native侧接口napiTypeOf | 位于主页 | 点击文本为5.napiTypeof的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiTypeofSuccess | Pass | +| ArkTS端成功调用native侧接口napiInstanceof | 位于主页 | 点击文本为6.napiInstanceof的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiInstanceofSuccess | Pass | +| ArkTS端成功调用native侧接口setTypeTagToObject,checkObjectTypeTag | 位于主页 | 点击文本为7.napiTypeTagObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiTypeTagObjectSuccess | Pass | +| ArkTS端成功调用native侧接口createExternal,getExternalType | 位于主页 | 点击文本为8.napiCreateExternal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateExternalSuccess | Pass | +| ArkTS端成功调用native侧接口getValueExternal | 位于主页 | 点击文本为9.napiGetValueExternal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueExternalSuccess | Pass | +| ArkTS端成功调用native侧接口createSymbol | 位于主页 | 点击文本为10.napiCreateSymbol的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSymbolSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIObject/screenshots/NodeAPIObject2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/.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/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..73fa2769f1b2577d1acc3e9aa07efd6f10b0a4d4 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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.nodeapiprimitive", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3c78d5cd71985c16434471fa9127afa9b4beb353 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIPrimitive" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4e3b689642b5f8518c3d54932f49476cbd04a624 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API接口进行primitiv类相关开发 + +### 介绍 + +在使用Node-API接口时,开发人员可以实现在Node-API模块中与ArkTS对象的交互,并进行数据转换和获取特定对象的操作,它们在不同的场景中发挥着重要的作用,使开发人员能够更灵活地处理ArkTS值和对象,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [使用Node-API接口进行primitiv类相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-primitive.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIPrimitive.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API接口进行primitiv类相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIPrimitive.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..073d9270fb39f0ba7fa9a9f539823701a983c203 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIPrimitive) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f637edcfb9b26bd2c7a3b1fa372ec7cd903561a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,192 @@ +/* + * 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" + +// [Start napi_coerce_to_bool] +// napi_coerce_to_bool +static napi_value CoerceToBool(napi_env env, napi_callback_info info) +{ + // 获取并解析传进的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将传入的值转换为布尔值 + napi_value result = nullptr; + napi_coerce_to_bool(env, args[0], &result); + // 返回强转之后的ArkTS boolean值 + return result; +} +// [End napi_coerce_to_bool] + +// [Start napi_coerce_to_number] +// napi_coerce_to_number +static napi_value CoerceToNumber(napi_env env, napi_callback_info info) +{ + // 获取并解析传进的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将传入的值转换为number值 + napi_value result = nullptr; + napi_coerce_to_number(env, args[0], &result); + return result; +} +// [End napi_coerce_to_number] + +// [Start napi_coerce_to_object] +// napi_coerce_to_object +static napi_value CoerceToObject(napi_env env, napi_callback_info info) +{ + // 获取并解析传进的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_value obj = nullptr; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将传入的值转换为Object值 + napi_coerce_to_object(env, args[0], &obj); + return obj; +} +// [End napi_coerce_to_object] + +// [Start napi_coerce_to_string] +// napi_coerce_to_string +static napi_value CoerceToString(napi_env env, napi_callback_info info) +{ + // 获取并解析传进的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 将传入的值转换为string + napi_value str = nullptr; + napi_coerce_to_string(env, args[0], &str); + return str; +} +// [End napi_coerce_to_string] + +// [Start napi_get_boolean] +// napi_get_boolean +static napi_value GetBoolean(napi_env env, napi_callback_info info) +{ + // 传入两个参数并解析 + size_t argc = 2; + napi_value argv[2]; + napi_valuetype data; + napi_valuetype value; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + // 判断两个参数类型值 + napi_typeof(env, argv[0], &data); + napi_typeof(env, argv[1], &value); + + napi_value returnValue = nullptr; + // 判断两个类型值是否相等,获取结果的布尔值 + napi_get_boolean(env, data == value, &returnValue); + // 返回结果 + return returnValue; +} +// [End napi_get_boolean] + +// [Start napi_get_value_bool] +// napi_get_value_bool +static napi_value GetValueBool(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + bool boolC = false; + napi_status status = napi_get_value_bool(env, args[0], &boolC); + if (status == napi_boolean_expected) { + // 如果napi_get_value_bool成功会返回napi_ok,如果传入一个非布尔值则会返回napi_boolean_expected + return nullptr; + } + napi_value boolNapi = nullptr; + napi_get_boolean(env, boolC, &boolNapi); + return boolNapi; +} +// [End napi_get_value_bool] + +// [Start napi_get_global] +// napi_get_global +static napi_value GetGlobal(napi_env env, napi_callback_info info) +{ + napi_value global = nullptr; + // 获取global对象 + napi_get_global(env, &global); + return global; +} +// [End napi_get_global] + +// [Start napi_get_null] +// napi_get_null +static napi_value GetNull(napi_env env, napi_callback_info info) +{ + napi_value nullValue = nullptr; + napi_get_null(env, &nullValue); + return nullValue; +} +// [End napi_get_null] + +// [Start napi_get_undefined] +// napi_get_undefined +static napi_value GetUndefined(napi_env env, napi_callback_info info) +{ + // 获取并解析传进的参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_value value = nullptr; + napi_get_undefined(env, &value); + // 判断传入参数的类型与undefined值的类型是否一致 + bool isEqual = false; + napi_strict_equals(env, args[0], value, &isEqual); + // 参数与undefined值相等 + napi_value result = nullptr; + // 返回判断类型之后的结果,相等返回为true,不等则为false + napi_get_boolean(env, isEqual, &result); + return result; +} +// [End napi_get_undefined] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"coerceToBool", nullptr, CoerceToBool, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"coerceToNumber", nullptr, CoerceToNumber, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"coerceToObject", nullptr, CoerceToObject, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"coerceToString", nullptr, CoerceToString, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getBoolean", nullptr, GetBoolean, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueBool", nullptr, GetValueBool, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getGlobal", nullptr, GetGlobal, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getNull", nullptr, GetNull, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getUndefined", nullptr, GetUndefined, 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..82d04677a8075e579e3d802af33ce3d819584075 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_coerce_to_bool_api] +export const coerceToBool: (data: T) => boolean; // napi_coerce_to_bool +// [End napi_coerce_to_bool_api] + +// [Start napi_coerce_to_number_api] +export const coerceToNumber: (data: T) => number; // napi_coerce_to_number +// [End napi_coerce_to_number_api] + +// [Start napi_coerce_to_object_api] +export const coerceToObject: (data: T) => Object; // napi_coerce_to_object +// [End napi_coerce_to_object_api] + +// [Start napi_coerce_to_string_api] +export const coerceToString: (data: T) => string; // napi_coerce_to_string +// [End napi_coerce_to_string_api] + +// [Start napi_get_boolean_api] +export const getBoolean: (data: T, value: String) => boolean; // napi_get_boolean +// [End napi_get_boolean_api] + +// [Start napi_get_value_bool_api] +export const getValueBool: (value: boolean | string) => boolean | void; // napi_get_value_bool +// [End napi_get_value_bool_api] + +// [Start napi_get_global_api] +export const getGlobal: () => Object; // napi_get_global +// [End napi_get_global_api] + +// [Start napi_get_null_api] +export const getNull: () => null; // napi_get_null +// [End napi_get_null_api] + +// [Start napi_get_undefined_api] +export const getUndefined: (value: undefined) => boolean; // napi_get_undefined +// [End napi_get_undefined_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..0e03007cd582a3cd5432ce0641c747b91e1fad49 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,166 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiCoerceToBool', + '2.napiCoerceToNumber', + '3.napiCoerceToObject', + '4.napiCoerceToString', + '5.napiGetBoolean', + '6.napiGetValueBool', + '7.napiGetGlobal', + '8.napiGetNull', + '9.napiGetUndefined' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(22) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiCoerceToBool') { + // [Start ark_napi_coerce_to_bool] + // napi_coerce_to_bool + let value = testNapi.coerceToBool(0); + let str = testNapi.coerceToBool('111111111'); + let obj = new Object(); + let res = testNapi.coerceToBool(obj); + let result = testNapi.coerceToBool(null); + // false + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', value); + // true + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', str); + // true + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', res); + // false + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', result); + // [End ark_napi_coerce_to_bool] + this.result = 'napiCoerceToBoolSuccess'; + } else if (item === '2.napiCoerceToNumber') { + // [Start ark_napi_coerce_to_number] + // napi_coerce_to_number + let value = testNapi.coerceToNumber('2556'); + let str = testNapi.coerceToNumber('sssss'); + let bool = testNapi.coerceToNumber(true); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', value); + // 返回的为NAN + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', str); + // 返回的是1 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', bool); + // [End ark_napi_coerce_to_number] + this.result = 'napiCoerceToNumberSuccess'; + } else if (item === '3.napiCoerceToObject') { + // [Start ark_napi_coerce_to_object] + // napi_coerce_to_object + let value = testNapi.coerceToObject('222222'); + let result = testNapi.coerceToObject(111); + hilog.info(0x0000, 'testTag', 'Node-API coerceToObject:%{public}s.', typeof result); + if (typeof value === 'object') { + hilog.info(0x0000, 'testTag', 'Node-API The value is an object.'); + } else { + hilog.info(0x0000, 'testTag', 'Node-API The value is not an object.'); + } + // [End ark_napi_coerce_to_object] + this.result = 'napiCoerceToObjectSuccess'; + } else if (item === '4.napiCoerceToString') { + // [Start ark_napi_coerce_to_string] + // napi_coerce_to_string + let value = testNapi.coerceToString(212); + let obj = new Object(); + let res = testNapi.coerceToString(obj); + let bool = testNapi.coerceToString(false); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', value); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', typeof res); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', bool); + // [End ark_napi_coerce_to_string] + this.result = 'napiCoerceToStringSuccess'; + } else if (item === '5.napiGetBoolean') { + // [Start ark_napi_get_boolean] + // napi_get_boolean + let value = testNapi.getBoolean(1, '1'); + let data = testNapi.getBoolean('sss', '1'); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', value); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', data); + // [End ark_napi_get_boolean] + this.result = 'napiGetBooleanSuccess'; + } else if (item === '6.napiGetValueBool') { + // [Start ark_napi_get_value_bool] + // napi_get_value_bool + // // 分别传入布尔值和非布尔值检测接口,传入布尔值将返回原布尔值,传入其他类型返回undefined + hilog.info(0x0000, 'Node-API', 'get_value_bool_not_bool %{public}s', + testNapi.getValueBool('你好123')); + hilog.info(0x0000, 'Node-API', 'get_value_bool_true %{public}s', testNapi.getValueBool(true)); + hilog.info(0x0000, 'Node-API', 'get_value_bool_false %{public}s', testNapi.getValueBool(false)); + // [End ark_napi_get_value_bool] + this.result = 'napiGetValueBoolSuccess'; + } else if (item === '7.napiGetGlobal') { + // [Start ark_napi_get_global] + // napi_get_global + let globalObj = testNapi.getGlobal(); + // 判断获取的global是否具有global的自身属性 + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_global:%{public}s', + globalObj.hasOwnProperty!("undefined")); + // [End ark_napi_get_global] + this.result = 'napiGetGlobalSuccess'; + } else if (item === '8.napiGetNull') { + // [Start ark_napi_get_null] + // napi_get_null + let value = testNapi.getNull(); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_null:%{public}s', value); + // [End ark_napi_get_null] + this.result = 'napiGetNullSuccess'; + } else if (item === '9.napiGetUndefined') { + // [Start ark_napi_get_undefined] + // napi_get_undefined + let data: undefined = undefined; + let value = testNapi.getUndefined(data); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_undefined:%{public}s', value); + // [End ark_napi_get_undefined] + this.result = 'napiGetUndefinedSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/NodeAPIPrimitive.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/NodeAPIPrimitive.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/NodeAPIPrimitive.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/NodeAPIPrimitive.test.ets index cc579bc71f3d6056b86e469f52e1e299385fdec9..0c7a70e6ef28bb2ea25972a9ac03cdf3f5169809 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/NodeAPIPrimitive.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/ets/test/NodeAPIPrimitive.test.ets @@ -1,188 +1,188 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIPrimitiveTest() { - describe('nodeAPIPrimitiveTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiCoerceToBool相关函数 - */ - it('testNodeAPIPrimitive001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiCoerceToBool')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCoerceToBoolSuccess')); - console.info('uitest: testNodeAPIPrimitive001 end'); - done(); - }) - - /** - * 点击按钮,调用napiCoerceToNumber相关函数 - */ - it('testNodeAPIPrimitive002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiCoerceToNumber')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCoerceToNumberSuccess')); - console.info('uitest: testNodeAPIPrimitive002 end'); - done(); - }) - - /** - * 点击按钮,调用napiCoerceToObject相关函数 - */ - it('testNodeAPIPrimitive003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiCoerceToObject')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCoerceToObjectSuccess')); - console.info('uitest: testNodeAPIPrimitive003 end'); - done(); - }) - - /** - * 点击按钮,调用napiCoerceToString相关函数 - */ - it('testNodeAPIPrimitive004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiCoerceToString')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiCoerceToStringSuccess')); - console.info('uitest: testNodeAPIPrimitive004 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetBoolean相关函数 - */ - it('testNodeAPIPrimitive005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiGetBoolean')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetBooleanSuccess')); - console.info('uitest: testNodeAPIPrimitive005 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetValueBool相关函数 - */ - it('testNodeAPIPrimitive006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiGetValueBool')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetValueBoolSuccess')); - console.info('uitest: testNodeAPIPrimitive006 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetGlobal相关函数 - */ - it('testNodeAPIPrimitive007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiGetGlobal')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetGlobalSuccess')); - console.info('uitest: testNodeAPIPrimitive007 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetNull相关函数 - */ - it('testNodeAPIPrimitive008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiGetNull')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetNullSuccess')); - console.info('uitest: testNodeAPIPrimitive008 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetUndefined相关函数 - */ - it('testNodeAPIPrimitive009', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPrimitive009 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('9.napiGetUndefined')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetUndefinedSuccess')); - console.info('uitest: testNodeAPIPrimitive009 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIPrimitiveTest() { + describe('nodeAPIPrimitiveTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiCoerceToBool相关函数 + */ + it('testNodeAPIPrimitive001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiCoerceToBool')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCoerceToBoolSuccess')); + console.info('uitest: testNodeAPIPrimitive001 end'); + done(); + }) + + /** + * 点击按钮,调用napiCoerceToNumber相关函数 + */ + it('testNodeAPIPrimitive002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiCoerceToNumber')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCoerceToNumberSuccess')); + console.info('uitest: testNodeAPIPrimitive002 end'); + done(); + }) + + /** + * 点击按钮,调用napiCoerceToObject相关函数 + */ + it('testNodeAPIPrimitive003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiCoerceToObject')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCoerceToObjectSuccess')); + console.info('uitest: testNodeAPIPrimitive003 end'); + done(); + }) + + /** + * 点击按钮,调用napiCoerceToString相关函数 + */ + it('testNodeAPIPrimitive004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiCoerceToString')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiCoerceToStringSuccess')); + console.info('uitest: testNodeAPIPrimitive004 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetBoolean相关函数 + */ + it('testNodeAPIPrimitive005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiGetBoolean')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetBooleanSuccess')); + console.info('uitest: testNodeAPIPrimitive005 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetValueBool相关函数 + */ + it('testNodeAPIPrimitive006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiGetValueBool')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetValueBoolSuccess')); + console.info('uitest: testNodeAPIPrimitive006 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetGlobal相关函数 + */ + it('testNodeAPIPrimitive007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiGetGlobal')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetGlobalSuccess')); + console.info('uitest: testNodeAPIPrimitive007 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetNull相关函数 + */ + it('testNodeAPIPrimitive008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiGetNull')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetNullSuccess')); + console.info('uitest: testNodeAPIPrimitive008 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetUndefined相关函数 + */ + it('testNodeAPIPrimitive009', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPrimitive009 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('9.napiGetUndefined')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetUndefinedSuccess')); + console.info('uitest: testNodeAPIPrimitive009 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/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/NodeAPI/NodeApiUse/NodeAPIPrimitive/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..08943f1064de198c399ef51370d05088b3f025c9 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/ohosTest.md @@ -0,0 +1,16 @@ +# 使用Node-API进行primitive相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------ | ------------ | ---------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 coerceToBool | 位于主页 | 点击文本为1.napiCoerceToBool的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToBoolSuccess | Pass | +| ArkTS端成功调用native侧接口coerceToNumber | 位于主页 | 点击文本为2.napiCoerceToNumber的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToNumberSuccess | Pass | +| ArkTS端成功调用native侧接口coerceToObject | 位于主页 | 点击文本为3.napiCoerceToObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToObjectSuccess | Pass | +| ArkTS端成功调用native侧接口coerceToString | 位于主页 | 点击文本为4.napiCoerceToString的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToStringSuccess | Pass | +| ArkTS端成功调用native侧接口getBoolean | 位于主页 | 点击文本为5.napiGetBoolean的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetBooleanSuccess | Pass | +| ArkTS端成功调用native侧接口getValueBool | 位于主页 | 点击文本为6.napiGetValueBool的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBoolSuccess | Pass | +| ArkTS端成功调用native侧接口getGlobal | 位于主页 | 点击文本为7.napiGetGlobal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetGlobalSuccess | Pass | +| ArkTS端成功调用native侧接口getNull | 位于主页 | 点击文本为8.napiGetNull的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetNullSuccess | Pass | +| ArkTS端成功调用native侧接口getUndefined | 位于主页 | 点击文本为9.napiGetUndefined的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetUndefinedSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPrimitive/screenshots/NodeAPIPrimitive2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/.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/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ca8d0359b98729aca9f85ded7d1515b655e151e0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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.nodeapipromise", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..06dbe37097cfdf422f01406cb4ccde79f49e45a2 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIPromise" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9f8919605ca4eb95c83f47ea8d057c08080fbea7 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行promise相关开发 + +### 介绍 + +使用Node-API接口处理异步操作。异步操作是指需要一定时间才能完成的操作,例如从网络下载数据或读取大型文件。与同步操作不同,异步操作不会阻塞主线程,而是会在后台执行。当异步操作完成后,事件循环将把它放入任务队列中,等待主线程空闲时执行,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [使用Node-API进行promise相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-promise.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIPromise.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行promise相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIPromise.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6054d4258741e3cf7a6e88615544cc0323f34904 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIPromise) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d8c07991152195c540023f38c435285b00582436 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,115 @@ +/* + * 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" + +static constexpr int INT_ARGS_2 = 2; // 入参索引 + +// [Start napi_is_promise] +// napi_is_promise +static napi_value IsPromise(napi_env env, napi_callback_info info) +{ + napi_value argv[1] = {nullptr}; + size_t argc = 1; + napi_status status; + // 获取传入的参数 + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + bool isPromise = false; + // 检查给定的入参是否为Promise对象,将结果保存在isPromise变量中 + status = napi_is_promise(env, argv[0], &isPromise); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_is_promise failed"); + return nullptr; + } + napi_value result = nullptr; + // 将isPromise的值转换为napi_value中的类型返回 + napi_get_boolean(env, isPromise, &result); + return result; +} +// [End napi_is_promise] + +// [Start napi_resolve_reject_deferred] +// napi_resolve_deferred & napi_reject_deferred +static napi_value CreatePromise(napi_env env, napi_callback_info info) +{ + // deferred是一个延迟对象,作用是将函数延迟一定时间再执行 + napi_deferred deferred = nullptr; + napi_value promise = nullptr; + // 调用接口创建Promise对象 + napi_status status = napi_create_promise(env, &deferred, &promise); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Create promise failed"); + return nullptr; + } + // 调用napi_is_promise判断napi_create_promise接口创建的是不是Promise对象 + bool isPromise = false; + napi_value returnIsPromise = nullptr; + napi_is_promise(env, promise, &isPromise); + // 将布尔值转为可以返回的napi_value + napi_get_boolean(env, isPromise, &returnIsPromise); + return returnIsPromise; +} + +static napi_value ResolveRejectDeferred(napi_env env, napi_callback_info info) +{ + // 获得并解析参数 + size_t argc = 3; + napi_value args[3] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 第一个参数为向resolve传入的信息,第二个参数为向reject传入的信息,第三个参数为Promise的状态 + bool status; + napi_get_value_bool(env, args[INT_ARGS_2], &status); + // 创建Promise对象 + napi_deferred deferred = nullptr; + napi_value promise = nullptr; + napi_status createStatus = napi_create_promise(env, &deferred, &promise); + if (createStatus != napi_ok) { + napi_throw_error(env, nullptr, "Create promise failed"); + return nullptr; + } + // 根据第三个参数设置resolve或reject + if (status) { + napi_resolve_deferred(env, deferred, args[0]); + } else { + napi_reject_deferred(env, deferred, args[1]); + } + // 返回设置了resolve或reject的Promise对象 + return promise; +} +// [End napi_resolve_reject_deferred] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"isPromise", nullptr, IsPromise, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createPromise", nullptr, CreatePromise, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"resolveRejectDeferred", nullptr, ResolveRejectDeferred, 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fe905bc14b18316bb5b79541ef2b559f15e50bdb --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_is_promise_api] +export const isPromise: (value: T) => boolean; // napi_is_promise +// [End napi_is_promise_api] + +// [Start napi_resolve_reject_deferred_api] +export const createPromise: () => boolean | void; // napi_resolve_deferred & napi_reject_deferred + +export const resolveRejectDeferred: (resolve: string, reject: string, status: boolean) => Promise | void; +// [End napi_resolve_reject_deferred_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..25c2d5b949a2f6aa62e5c8c9df11c949a2b4ae70 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,104 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiIsPromise', + '2.napiDeferred' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(22) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiIsPromise') { + // [Start ark_napi_is_promise] + // napi_is_promise + let value = Promise.resolve(); + // 传入的对象为Promise时,返回true,否则返回false + hilog.info(0x0000, 'Node-API', 'napi_is_promise %{public}s', testNapi.isPromise(value)); + hilog.info(0x0000, 'Node-API', 'napi_is_promise string %{public}s', testNapi.isPromise('')); + // [End ark_napi_is_promise] + this.result = 'napiIsPromiseSuccess'; + } else if (item === '2.napiDeferred') { + // [Start ark_napi_resolve_reject_deferred] + // napi_resolve_deferred & napi_reject_deferred + // 创建promise如果创建成功返回true,创建失败返回false + hilog.info(0x0000, 'Node-API', 'napi_create_promise %{public}s', testNapi.createPromise()); + // 调用resolveRejectDeferred函数设置resolve和reject的返回结果以及Promise状态 + // Promise状态为true时设置resolve,返回结果在then函数中获得 + let promiseSuccess: Promise = + testNapi.resolveRejectDeferred('success', 'fail', true) as Promise; + promiseSuccess.then((res) => { + hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) + // [StartExclude ark_napi_resolve_reject_deferred] + this.result = 'napiDeferredSuccess'; + // [EndExclude ark_napi_resolve_reject_deferred] + }).catch((err: Error) => { + hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) + // [StartExclude ark_napi_resolve_reject_deferred] + this.result = 'napiDeferredFail'; + // [EndExclude ark_napi_resolve_reject_deferred] + }) + // Promise状态为false时设置reject,返回结果在catch函数中获得 + let promiseFail: Promise = + testNapi.resolveRejectDeferred('success', 'fail', false) as Promise; + promiseFail.then((res) => { + hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) + // [StartExclude ark_napi_resolve_reject_deferred] + this.result = 'napiDeferredSuccess'; + // [EndExclude ark_napi_resolve_reject_deferred] + }).catch((err: Error) => { + hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) + // [StartExclude ark_napi_resolve_reject_deferred] + this.result = 'napiDeferredFail'; + // [EndExclude ark_napi_resolve_reject_deferred] + }) + // [End ark_napi_resolve_reject_deferred] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/NodeAPIPromise.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/NodeAPIPromise.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/NodeAPIPromise.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/NodeAPIPromise.test.ets index c2eb468f14f213436f90e5eaee9bfc2483137193..aabae590ad2375e4f20a9e615cb5ac6c17f10063 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/NodeAPIPromise.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/ets/test/NodeAPIPromise.test.ets @@ -1,76 +1,76 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIPromiseTest() { - describe('nodeAPIPromiseTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiIsPromise相关函数 - */ - it('testNodeAPIPromise001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPromise001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiIsPromise')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiIsPromiseSuccess')); - console.info('uitest: testNodeAPIPromise001 end'); - done(); - }) - - /** - * 点击按钮,调用napiDeferred相关函数 - */ - it('testNodeAPIPromise002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIPromise002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiDeferred')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiDeferredFail')); - console.info('uitest: testNodeAPIPromise002 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIPromiseTest() { + describe('nodeAPIPromiseTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiIsPromise相关函数 + */ + it('testNodeAPIPromise001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPromise001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiIsPromise')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiIsPromiseSuccess')); + console.info('uitest: testNodeAPIPromise001 end'); + done(); + }) + + /** + * 点击按钮,调用napiDeferred相关函数 + */ + it('testNodeAPIPromise002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIPromise002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiDeferred')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiDeferredFail')); + console.info('uitest: testNodeAPIPromise002 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/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/NodeAPI/NodeApiUse/NodeAPIPromise/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c7529c64a5039a0218e2c36fe02867c22e703ef6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/ohosTest.md @@ -0,0 +1,9 @@ +# 使用Node-API进行promise相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ----------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口isPromise | 位于主页 | 点击文本为1.napiIsPromise的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsPromiseSuccess | Pass | +| ArkTS端成功调用native侧接口createPromise,resolveRejectDeferred | 位于主页 | 点击文本为2.napiDeferred的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDeferredSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIPromise/screenshots/NodeAPIPromise2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/.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/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..11f7f25a804afe0848959c66a2e1a4fa3bb37fc8 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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.nodeapiproperty", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..17605199d53f591689bf739adc48b7d08c1e3cde --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeAPIProperty" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1f5ee2d295c3c9898d4149b1bf12b301d0acf644 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行property相关开发 + +### 介绍 + +使用Node-API接口获取和设置ArkTS对象的属性。通过合理使用这些函数,实现更复杂的功能和逻辑,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [使用Node-API进行property相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-property.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeAPIProperty.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行property相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeAPIProperty.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8fa817241b65762aa0ce666ea273298ce9662597 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NodeAPIProperty) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..97ecb669a7892d4574d36011712c3b4e32c9674f --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,391 @@ +/* + * 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 +#include "napi/native_api.h" + +static constexpr int INT_ARG_2 = 2; // 入参索引 + +// [Start napi_get_property_names] +// napi_get_property_names +static napi_value GetPropertyNames(napi_env env, napi_callback_info info) +{ + // 解析ArkTS的传参 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 以字符串数组的形式获取对象的可枚举属性的名称,以result传出 + napi_value result; + napi_status status = napi_get_property_names(env, args[0], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_get_property_names fail"); + return nullptr; + } + return result; +} +// [End napi_get_property_names] + +// [Start napi_set_property] +// napi_set_property +static napi_value SetProperty(napi_env env, napi_callback_info info) +{ + // 接收ArkTS侧传入的三个参数:第一个参数为想要设置的object,第二个参数为属性,第三个参数为属性对应的值 + size_t argc = 3; + napi_value args[3] = {nullptr}; + napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_get_cb_info fail"); + } + // 通过调用napi_set_property接口将属性与值设置入object,如果失败,直接抛出错误 + status = napi_set_property(env, args[0], args[1], args[INT_ARG_2]); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_set_property fail"); + return nullptr; + } + // 返回设置成功的object对象 + return args[0]; +} +// [End napi_set_property] + +// [Start napi_get_property] +// napi_get_property +static napi_value GetProperty(napi_env env, napi_callback_info info) +{ + // 接收两个ArkTS传来的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 传入的第一个参数为要检测的object,第二个对象为要检测的属性,通过调用napi_get_property接口获取对应的值 + napi_value result; + napi_status status = napi_get_property(env, args[0], args[1], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_get_property fail"); + return nullptr; + } + return result; +} +// [End napi_get_property] + +// [Start napi_has_property] +// napi_has_property +static napi_value HasProperty(napi_env env, napi_callback_info info) +{ + // 从ArkTS侧传入两个参数:第一个参数为要检验的对象,第二个参数为要检测是否存在对象的属性 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 将参数传入napi_has_property方法中,若接口调用成功则将结果转化为napi_value类型抛出,否则抛出错误 + bool result; + napi_status status = napi_has_property(env, args[0], args[1], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_has_property fail"); + return nullptr; + } + + // 若传入属性存在传入对象中,则输出true将结果转化为napi_value类型抛出 + napi_value returnResult; + napi_get_boolean(env, result, &returnResult); + return returnResult; +} +// [End napi_has_property] + +// [Start napi_delete_property] +// napi_delete_property +// 从传入的Object对象中删除指定属性,返回是否删除成功的bool结果值 +static napi_value DeleteProperty(napi_env env, napi_callback_info info) +{ + // 接收两个ArkTS传来的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valueType; + napi_typeof(env, args[0], &valueType); + if (valueType != napi_object) { + napi_throw_error(env, nullptr, "Expects an object as argument."); + return nullptr; + } + // 删除指定属性,结果存储在result中 + bool result = false; + napi_status status = napi_delete_property(env, args[0], args[1], &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_delete_property failed"); + return nullptr; + } + // 将bool结果转换为napi_value并返回 + napi_value ret; + napi_get_boolean(env, result, &ret); + return ret; +} +// [End napi_delete_property] + +// [Start napi_has_own_property] +// napi_has_own_property +static napi_value NapiHasOwnProperty(napi_env env, napi_callback_info info) +{ + // 接收两个ArkTS传来的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 检查第一个参数是否为对象 + napi_valuetype valueTypeObj; + napi_typeof(env, args[0], &valueTypeObj); + if (valueTypeObj != napi_object) { + napi_throw_error(env, nullptr, "First argument must be an object."); + return nullptr; + } + // 检查第二个参数是否为string + napi_valuetype valuetypeStr; + napi_typeof(env, args[1], &valuetypeStr); + if (valuetypeStr != napi_string) { + napi_throw_error(env, nullptr, "Second argument must be a string."); + return nullptr; + } + // 检查对象是否具有指定属性,结果存储在hasProperty中 + bool hasProperty; + napi_status status = napi_has_own_property(env, args[0], args[1], &hasProperty); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_has_own_property failed"); + return nullptr; + } + // 将bool结果转换为napi_value并返回 + napi_value result; + napi_get_boolean(env, hasProperty, &result); + return result; +} +// [End napi_has_own_property] + +// [Start napi_set_named_property] +// napi_set_named_property +static napi_value NapiSetNamedProperty(napi_env env, napi_callback_info info) +{ + // 接收一个ArkTS传来的参数 + size_t argc = 1; + napi_value str; + const int32_t strLength = 32; + char strKey[strLength] = ""; + napi_get_cb_info(env, info, &argc, &str, nullptr, nullptr); + // 获取传入参数字符串并存储在strKey中 + size_t keyLength; + napi_get_value_string_utf8(env, str, strKey, strLength, &keyLength); + // 创建一个新对象 + napi_value newObj; + napi_create_object(env, &newObj); + // 设置整数值1234为属性值 + int32_t value = 1234; + napi_value numValue; + napi_create_int32(env, value, &numValue); + // 将整数值与指定属性名关联 + napi_status status = napi_set_named_property(env, newObj, strKey, numValue); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_set_named_property failed"); + return nullptr; + } + // 返回设置了命名属性的对象newObj + return newObj; +} +// [End napi_set_named_property] + +// [Start napi_get_named_property] +// napi_get_named_property +static napi_value NapiGetNamedProperty(napi_env env, napi_callback_info info) +{ + // 接收两个ArkTS传来的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + const int32_t strLength = 32; + char strKey[strLength] = ""; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取要获取的属性名 + size_t keyLength; + napi_get_value_string_utf8(env, args[1], strKey, strLength, &keyLength); + // 获取指定属性的值并存储在result中 + napi_value result; + napi_status status = napi_get_named_property(env, args[0], strKey, &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_get_named_property failed"); + return nullptr; + } + // 返回result + return result; +} +// [End napi_get_named_property] + +// [Start napi_has_named_property] +// napi_has_named_property +static napi_value NapiHasNamedProperty(napi_env env, napi_callback_info info) +{ + // 接收两个ArkTS传来的参数 + size_t argc = 2; + napi_value args[2] = {nullptr}; + const int32_t strLength = 32; + char strKey[strLength] = ""; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取要检查的属性名 + size_t keyLength; + napi_get_value_string_utf8(env, args[1], strKey, strLength, &keyLength); + // 检查对象是否具有指定命名的属性,并将结果存储在hasProperty中 + bool hasProperty = false; + napi_status status = napi_has_named_property(env, args[0], strKey, &hasProperty); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_has_named_property failed"); + return nullptr; + } + // 将bool结果转换为napi_value并返回 + napi_value result; + napi_get_boolean(env, hasProperty, &result); + return result; +} +// [End napi_has_named_property] + +// [Start napi_define_properties] +// napi_define_properties +static napi_value DefineMethodPropertiesExample(napi_env env, napi_callback_info info) +{ + // 创建一个int32类型的属性值 + int32_t propValue = 26; + napi_value returnValue = nullptr; + napi_create_int32(env, propValue, &returnValue); + return returnValue; +} + +// Getter回调函数 +static napi_value GetterCallback(napi_env env, napi_callback_info info) +{ + napi_value result; + const char *str = u8"World!"; + size_t length = strlen(str); + // 创建属性的值 + napi_create_string_utf8(env, str, length, &result); + return result; +} + +// Setter回调函数 +static napi_value SetterCallback(napi_env env, napi_callback_info info) +{ + // 获取传递给setter的参数 + size_t argc = 1; + napi_value argv[1] = {nullptr}; + napi_value result; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + std::string buf; + size_t length; + napi_get_value_string_utf8(env, argv[0], (char *)buf.c_str(), NAPI_AUTO_LENGTH, &length); + napi_create_string_utf8(env, buf.c_str(), length, &result); + return result; +} + +static napi_value DefineMethodProperties(napi_env env, napi_callback_info info) +{ + napi_value obj; + napi_create_object(env, &obj); + // 在obj对象上定义了一个函数defineMethodPropertiesExample,在函数defineMethodPropertiesExample中定义了一个变量并返回,在调用obj的这个对象时可以调用这个函数 + napi_property_descriptor descriptor[] = {{"defineMethodPropertiesExample", nullptr, DefineMethodPropertiesExample, + nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, obj, sizeof(descriptor) / sizeof(descriptor[0]), descriptor); + return obj; +} + +static napi_value DefineStringProperties(napi_env env, napi_callback_info info) +{ + napi_value obj; + napi_create_object(env, &obj); + // 创建一个string类型的属性值 + napi_value string_value; + napi_create_string_utf8(env, "Hello!", NAPI_AUTO_LENGTH, &string_value); + napi_property_descriptor descriptor[] = { + {"defineStringPropertiesExample", nullptr, nullptr, nullptr, nullptr, string_value, napi_default, nullptr}}; + napi_define_properties(env, obj, sizeof(descriptor) / sizeof(descriptor[0]), descriptor); + return obj; +} + +static napi_value CreateStringWithGetterSetter(napi_env env, napi_callback_info info) +{ + napi_value obj; + napi_create_object(env, &obj); + // 定义getter函数 + napi_value getterFn; + napi_create_function(env, nullptr, 0, GetterCallback, nullptr, &getterFn); + napi_set_named_property(env, obj, "getterCallback", getterFn); + // 定义setter函数 + napi_value setterFn; + napi_create_function(env, nullptr, 0, SetterCallback, nullptr, &setterFn); + napi_set_named_property(env, obj, "setterCallback", setterFn); + // 定义带有getter和setter的属性 + napi_property_descriptor desc = {"defineGetterSetter", nullptr, GetterCallback, SetterCallback, nullptr, obj, + napi_enumerable, nullptr}; + napi_define_properties(env, obj, 1, &desc); + return obj; +} +// [End napi_define_properties] + +// [Start napi_get_all_property_names] +// napi_get_all_property_names +static napi_value GetAllPropertyNames(napi_env env, napi_callback_info info) +{ + // 传入一个参数 + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取给定对象的所有属性名称 + napi_value result; + napi_status status = napi_get_all_property_names(env, args[0], napi_key_own_only, napi_key_writable, + napi_key_numbers_to_strings, &result); + // 如果获取属性名失败,抛出一个错误 + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Node-API napi_get_all_property_names fail"); + return nullptr; + } + + return result; +} +// [End napi_get_all_property_names] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getPropertyNames", nullptr, GetPropertyNames, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setProperty", nullptr, SetProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getProperty", nullptr, GetProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"hasProperty", nullptr, HasProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"deleteProperty", nullptr, DeleteProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiHasOwnProperty", nullptr, NapiHasOwnProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiSetNamedProperty", nullptr, NapiSetNamedProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiGetNamedProperty", nullptr, NapiGetNamedProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"napiHasNamedProperty", nullptr, NapiHasNamedProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"defineMethodProperties", nullptr, DefineMethodProperties, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"defineStringProperties", nullptr, DefineStringProperties, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createStringWithGetterSetter", nullptr, CreateStringWithGetterSetter, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"getAllPropertyNames", nullptr, GetAllPropertyNames, 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa257f4b31780ba0fad4750f7eb5ca50a0ebc64b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_get_property_names_api] +export const getPropertyNames: (obj: Object) => Array | void; // napi_get_property_names +// [End napi_get_property_names_api] + +// [Start napi_set_property_api] +export const setProperty: (obj: Object, key: String, value: string) => Object | void; // napi_set_property +// [End napi_set_property_api] + +// [Start napi_get_property_api] +export const getProperty: (obj: Object, key: string) => string | void; // napi_get_property +// [End napi_get_property_api] + +// [Start napi_has_property_api] +export const hasProperty: (obj: Object, key: number | string) => boolean | void; // napi_has_property +// [End napi_has_property_api] + +// [Start napi_delete_property_api] +export const deleteProperty: (obj: Object, key: string) => boolean; // napi_delete_property +// [End napi_delete_property_api] + +// [Start napi_has_own_property_api] +export const napiHasOwnProperty: (obj: Object, key: string) => boolean | void; // napi_has_own_property +// [End napi_has_own_property_api] + +// [Start napi_set_named_property_api] +export const napiSetNamedProperty: (key: string) => Object | void; // napi_set_named_property +// [End napi_set_named_property_api] + +// [Start napi_get_named_property_api] +export const napiGetNamedProperty: (obj: Object, + key: string) => boolean | number | string | Object | void; // napi_get_named_property +// [End napi_get_named_property_api] + +// [Start napi_has_named_property_api] +export const napiHasNamedProperty: (obj: Object, key: string) => boolean | void; // napi_has_named_property +// [End napi_has_named_property_api] + +// [Start napi_define_properties_api] +export class DefineMethodObj { + defineMethodPropertiesExample: Function; +} + +export class DefineStringObj { + defineStringPropertiesExample: string; +} + +export class DefineGetterSetterObj { + getterCallback: Function; + setterCallback: Function; +} + +export const defineMethodProperties: () => DefineMethodObj; // napi_define_properties + +export const defineStringProperties: () => DefineStringObj; + +export const createStringWithGetterSetter: () => DefineGetterSetterObj; +// [End napi_define_properties_api] + +// [Start napi_get_all_property_names_api] +export const getAllPropertyNames: (obj: Object) => Array | void; // napi_get_all_property_names +// [End napi_get_all_property_names_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa572de2fda7ff101d228a24cbd963a3645890cf --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,294 @@ +/* + * 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 { napiDeleteProperty } from './napiDeleteProperty'; +import { napiHasOwnProperty } from './napiHasOwnProperty'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiGetPropertyNames', + '2.napiSetProperty', + '3.napiGetProperty', + '4.napiHasProperty', + '5.napiDeleteProperty', + '6.napiHasOwnProperty', + '7.napiSetNamedProperty', + '8.napiGetNamedProperty', + '9.napiHasNamedProperty', + '10.napiDefineProperties', + '11.napiGetAllPropertyNames' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 4 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiGetPropertyNames') { + // [Start ark_napi_get_property_names] + // napi_get_property_names + try { + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + let propertyNames = testNapi.getPropertyNames(obj); + if (Array.isArray(propertyNames) && propertyNames.length > 0) { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property_names: %{public}s', + propertyNames[0]); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property_names: %{public}s', + propertyNames[1]); + // [StartExclude ark_napi_get_property_names] + this.result = 'napiGetPropertyNamesSuccess'; + // [EndExclude ark_napi_get_property_names] + } + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_property_names error: %{public}s', + error.message); + // [StartExclude ark_napi_get_property_names] + this.result = 'napiGetPropertyNamesFail'; + // [EndExclude ark_napi_get_property_names] + } + // [End ark_napi_get_property_names] + } else if (item === '2.napiSetProperty') { + // [Start ark_napi_set_property] + // napi_set_property + try { + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + let result = testNapi.setProperty(obj, 'code', 'hi'); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property: %{public}s', + JSON.stringify(result)); + // [StartExclude ark_napi_set_property] + this.result = 'napiSetPropertySuccess'; + // [EndExclude ark_napi_set_property] + } catch (error) { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property error: %{public}s', error.message); + // [StartExclude ark_napi_set_property] + this.result = 'napiSetPropertyFail'; + // [EndExclude ark_napi_set_property] + } + // [End ark_napi_set_property] + } else if (item === '3.napiGetProperty') { + // [Start ark_napi_get_property] + // napi_get_property + try { + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property: %{public}s', + testNapi.getProperty(obj, 'message')); + // [StartExclude ark_napi_get_property] + this.result = 'napiGetPropertySuccess'; + // [EndExclude ark_napi_get_property] + } catch (error) { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property error: %{public}s', error.message); + // [StartExclude ark_napi_get_property] + this.result = 'napiGetPropertyFail'; + // [EndExclude ark_napi_get_property] + } + // [End ark_napi_get_property] + } else if (item === '4.napiHasProperty') { + // [Start ark_napi_has_property] + // napi_has_property + try { + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + let resultFalse = testNapi.hasProperty(obj, 0); + let resultTrue = testNapi.hasProperty(obj, 'data'); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property: %{public}s', + JSON.stringify(resultFalse)); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property: %{public}s', + JSON.stringify(resultTrue)); + // [StartExclude ark_napi_has_property] + this.result = 'napiHasPropertySuccess'; + // [EndExclude ark_napi_has_property] + } catch (error) { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property error: %{public}s', error.message); + // [StartExclude ark_napi_has_property] + this.result = 'napiHasPropertyFail'; + // [EndExclude ark_napi_has_property] + } + // [End ark_napi_has_property] + } else if (item === '5.napiDeleteProperty') { + // napi_delete_property + napiDeleteProperty(); + this.result = 'napiDeletePropertySuccess'; + } else if (item === '6.napiHasOwnProperty') { + // napi_has_own_property + napiHasOwnProperty(); + this.result = 'napiHasOwnPropertySuccess'; + } else if (item === '7.napiSetNamedProperty') { + // [Start ark_napi_set_named_property] + // napi_set_named_property + let obj = testNapi.napiSetNamedProperty('myProperty'); + let objAsString = JSON.stringify(obj); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_named_property: %{public}s', objAsString); + // [End ark_napi_set_named_property] + this.result = 'napiSetNamedPropertySuccess'; + } else if (item === '8.napiGetNamedProperty') { + // [Start ark_napi_get_named_property] + // napi_get_named_property + interface NestedObj { + nestedStr: string; + nestedNum: number; + } + + class Obj { + public str: string = ''; + public num: number = 0; + public bol: boolean = false; + public nestedObj: NestedObj = { nestedStr: '', nestedNum: 0 }; + } + + let obj: Obj = { + str: 'bar', + num: 42, + bol: true, + nestedObj: { nestedStr: 'nestedValue', nestedNum: 123 } + }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', + testNapi.napiGetNamedProperty(obj, 'str')); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}d', + testNapi.napiGetNamedProperty(obj, 'num')); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', + testNapi.napiGetNamedProperty(obj, 'bol')); + let nestedObj = testNapi.napiGetNamedProperty(obj, 'nestedObj'); + let objAsString = JSON.stringify(nestedObj); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', objAsString); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', + testNapi.napiGetNamedProperty(obj, 'null')); + // [End ark_napi_get_named_property] + this.result = 'napiGetNamedPropertySuccess'; + } else if (item === '9.napiHasNamedProperty') { + // [Start ark_napi_has_named_property] + // napi_has_named_property + interface NestedObj { + nestedStr: string; + nestedNum: number; + } + + class Obj { + public str: string = ''; + public num: number = 0; + public bol: boolean = false; + public nestedObj: NestedObj = { nestedStr: '', nestedNum: 0 }; + } + + let obj: Obj = { + str: 'bar', + num: 42, + bol: true, + nestedObj: { nestedStr: 'nestedValue', nestedNum: 123 } + }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', + testNapi.napiHasNamedProperty(obj, 'str')); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', + testNapi.napiHasNamedProperty(obj, 'nestedStr')); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', + testNapi.napiHasNamedProperty(obj, 'bol')); + // [End ark_napi_has_named_property] + this.result = 'napiHasNamedPropertySuccess'; + } else if (item === '10.napiDefineProperties') { + // [Start ark_napi_define_properties] + // napi_define_properties + // 定义method类型的属性 + hilog.info(0x0000, 'testTag', 'Test Node-API define_method_properties:%{public}d', + testNapi.defineMethodProperties() + .defineMethodPropertiesExample()); + // 定义string类型的属性 + hilog.info(0x0000, 'testTag', 'Test Node-API define_string_properties::%{public}s ', + testNapi.defineStringProperties() + .defineStringPropertiesExample); + // getter和setter + hilog.info(0x0000, 'testTag', 'Test Node-API get::%{public}s ', + testNapi.createStringWithGetterSetter() + .getterCallback()); + hilog.info(0x0000, 'testTag', 'Test Node-API setter::%{public}s ', + testNapi.createStringWithGetterSetter() + .setterCallback('set data')); + // [End ark_napi_define_properties] + this.result = 'napiDefinePropertiesSuccess'; + } else if (item === '11.napiGetAllPropertyNames') { + // [Start ark_napi_get_all_property_names] + // napi_get_all_property_names + try { + class Obj { + public data: number = 0 + public message: string = '' + } + + let obj: Obj = { data: 0, message: 'hello world' }; + let propertyNames = testNapi.getAllPropertyNames(obj); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names: %{public}s', + JSON.stringify(propertyNames)); + // [StartExclude ark_napi_get_all_property_names] + this.result = 'napiGetAllPropertyNamesSuccess'; + // [EndExclude ark_napi_get_all_property_names] + } catch (error) { + hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names error: %{public}s', + error.message); + // [StartExclude ark_napi_get_all_property_names] + this.result = 'napiGetAllPropertyNamesFail'; + // [EndExclude ark_napi_get_all_property_names] + } + // [End ark_napi_get_all_property_names] + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + .id('List') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts index 9c3a8b3383117625d4b182f8fe8f8895c6309f6b..7524a5a37ec7a7d0c56a7b70e889373883aaae05 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiDeleteProperty.ts @@ -1,37 +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. - */ - -// [Start ark_napi_delete_property] -import testNapi from 'libentry.so'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -export function napiDeleteProperty() { - class Obj { - first: number = 0; - } - - let obj: Obj = { first: 1 }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_property first: %{public}s', - testNapi.deleteProperty(obj, 'first')); - //设置新的属性为不可配置 - //这里的Object.defineProperty方法在DevEco Studio 4.1.0.400及其以上版本不支持,需在ts使用 - Object.defineProperty(obj, 'config', { - configurable: false, - value: 'value' - }) - hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_property config: %{public}s', - testNapi.deleteProperty(obj, 'config')); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ark_napi_delete_property] +import testNapi from 'libentry.so'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export function napiDeleteProperty() { + class Obj { + first: number = 0; + } + + let obj: Obj = { first: 1 }; + hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_property first: %{public}s', + testNapi.deleteProperty(obj, 'first')); + //设置新的属性为不可配置 + //这里的Object.defineProperty方法在DevEco Studio 4.1.0.400及其以上版本不支持,需在ts使用 + Object.defineProperty(obj, 'config', { + configurable: false, + value: 'value' + }) + hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_property config: %{public}s', + testNapi.deleteProperty(obj, 'config')); +} // [End ark_napi_delete_property] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts index ada41ab3209c4e78b75f9ff8473af5c9380463bc..33a517269d8c1abcbcaf9e3e723afb9b0ef79694 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/napiHasOwnProperty.ts @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start ark_napi_has_own_property] -import { hilog } from '@kit.PerformanceAnalysisKit'; -import testNapi from 'libentry.so'; - -export function napiHasOwnProperty() { - let myObj = { 'myProperty': 1 }; - let inheritedObj = { 'inheritedProperty': 2 }; - // 这里的Object.setPrototypeOf方法在DevEco Studio 4.1.0.400及其以上版本不支持,需在ts使用 - Object.setPrototypeOf(myObj, inheritedObj); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_own_property my: %{public}s', - testNapi.napiHasOwnProperty(myObj, 'myProperty')); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_own_property inherited: %{public}s', - testNapi.napiHasOwnProperty(myObj, 'inheritedProperty')); -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ark_napi_has_own_property] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; + +export function napiHasOwnProperty() { + let myObj = { 'myProperty': 1 }; + let inheritedObj = { 'inheritedProperty': 2 }; + // 这里的Object.setPrototypeOf方法在DevEco Studio 4.1.0.400及其以上版本不支持,需在ts使用 + Object.setPrototypeOf(myObj, inheritedObj); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_own_property my: %{public}s', + testNapi.napiHasOwnProperty(myObj, 'myProperty')); + hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_own_property inherited: %{public}s', + testNapi.napiHasOwnProperty(myObj, 'inheritedProperty')); +} // [End ark_napi_has_own_property] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/NodeAPIProperty.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/NodeAPIProperty.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/NodeAPIProperty.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/NodeAPIProperty.test.ets index 9db2e798cd3b33fdce95c428fa6153bea0ea5eb1..839c0c16aa2d416ebf3c4a63298c3b3fbab716e8 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/NodeAPIProperty.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/ets/test/NodeAPIProperty.test.ets @@ -1,223 +1,223 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIPropertyTest() { - describe('nodeAPIPropertyTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用napiGetPropertyNames相关函数 - */ - it('testNodeAPIProperty001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiGetPropertyNames')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetPropertyNamesSuccess')); - console.info('uitest: testNodeAPIArray001 end'); - done(); - }) - - /** - * 点击按钮,调用napiSetProperty相关函数 - */ - it('testNodeAPIProperty002', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('2.napiSetProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiSetPropertySuccess')); - console.info('uitest: testNodeAPIArray002 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetProperty相关函数 - */ - it('testNodeAPIProperty003', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('3.napiGetProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetPropertySuccess')); - console.info('uitest: testNodeAPIArray003 end'); - done(); - }) - - /** - * 点击按钮,调用napiHasProperty相关函数 - */ - it('testNodeAPIProperty004', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('4.napiHasProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiHasPropertySuccess')); - console.info('uitest: testNodeAPIArray004 end'); - done(); - }) - - /** - * 点击按钮,调用napiDeleteProperty相关函数 - */ - it('testNodeAPIProperty005', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('5.napiDeleteProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiDeletePropertySuccess')); - console.info('uitest: testNodeAPIArray005 end'); - done(); - }) - - /** - * 点击按钮,调用napiHasOwnProperty相关函数 - */ - it('testNodeAPIProperty006', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('6.napiHasOwnProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiHasOwnPropertySuccess')); - console.info('uitest: testNodeAPIArray006 end'); - done(); - }) - - /** - * 点击按钮,调用napiSetNamedProperty相关函数 - */ - it('testNodeAPIProperty007', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('7.napiSetNamedProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiSetNamedPropertySuccess')); - console.info('uitest: testNodeAPIArray007 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetNamedProperty相关函数 - */ - it('testNodeAPIProperty008', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray008 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('8.napiGetNamedProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetNamedPropertySuccess')); - console.info('uitest: testNodeAPIArray008 end'); - done(); - }) - - /** - * 点击按钮,调用napiHasNamedProperty相关函数 - */ - it('testNodeAPIProperty009', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray009 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('9.napiHasNamedProperty')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiHasNamedPropertySuccess')); - console.info('uitest: testNodeAPIArray009 end'); - done(); - }) - - /** - * 点击按钮,调用napiDefineProperties相关函数 - */ - it('testNodeAPIProperty010', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray010 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('10.napiDefineProperties')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiDefinePropertiesSuccess')); - console.info('uitest: testNodeAPIArray010 end'); - done(); - }) - - /** - * 点击按钮,调用napiGetAllPropertyNames相关函数 - */ - it('testNodeAPIProperty011', 0, async (done: Function) => { - console.info('uitest: testNodeAPIArray011 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const list = await driver.findComponent(ON.id('List')) - await list.scrollToBottom(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('11.napiGetAllPropertyNames')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiGetAllPropertyNamesSuccess')); - console.info('uitest: testNodeAPIArray011 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIPropertyTest() { + describe('nodeAPIPropertyTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用napiGetPropertyNames相关函数 + */ + it('testNodeAPIProperty001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiGetPropertyNames')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetPropertyNamesSuccess')); + console.info('uitest: testNodeAPIArray001 end'); + done(); + }) + + /** + * 点击按钮,调用napiSetProperty相关函数 + */ + it('testNodeAPIProperty002', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('2.napiSetProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiSetPropertySuccess')); + console.info('uitest: testNodeAPIArray002 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetProperty相关函数 + */ + it('testNodeAPIProperty003', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('3.napiGetProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetPropertySuccess')); + console.info('uitest: testNodeAPIArray003 end'); + done(); + }) + + /** + * 点击按钮,调用napiHasProperty相关函数 + */ + it('testNodeAPIProperty004', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('4.napiHasProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiHasPropertySuccess')); + console.info('uitest: testNodeAPIArray004 end'); + done(); + }) + + /** + * 点击按钮,调用napiDeleteProperty相关函数 + */ + it('testNodeAPIProperty005', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('5.napiDeleteProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiDeletePropertySuccess')); + console.info('uitest: testNodeAPIArray005 end'); + done(); + }) + + /** + * 点击按钮,调用napiHasOwnProperty相关函数 + */ + it('testNodeAPIProperty006', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('6.napiHasOwnProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiHasOwnPropertySuccess')); + console.info('uitest: testNodeAPIArray006 end'); + done(); + }) + + /** + * 点击按钮,调用napiSetNamedProperty相关函数 + */ + it('testNodeAPIProperty007', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('7.napiSetNamedProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiSetNamedPropertySuccess')); + console.info('uitest: testNodeAPIArray007 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetNamedProperty相关函数 + */ + it('testNodeAPIProperty008', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray008 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('8.napiGetNamedProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetNamedPropertySuccess')); + console.info('uitest: testNodeAPIArray008 end'); + done(); + }) + + /** + * 点击按钮,调用napiHasNamedProperty相关函数 + */ + it('testNodeAPIProperty009', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray009 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('9.napiHasNamedProperty')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiHasNamedPropertySuccess')); + console.info('uitest: testNodeAPIArray009 end'); + done(); + }) + + /** + * 点击按钮,调用napiDefineProperties相关函数 + */ + it('testNodeAPIProperty010', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray010 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('10.napiDefineProperties')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiDefinePropertiesSuccess')); + console.info('uitest: testNodeAPIArray010 end'); + done(); + }) + + /** + * 点击按钮,调用napiGetAllPropertyNames相关函数 + */ + it('testNodeAPIProperty011', 0, async (done: Function) => { + console.info('uitest: testNodeAPIArray011 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const list = await driver.findComponent(ON.id('List')) + await list.scrollToBottom(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('11.napiGetAllPropertyNames')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiGetAllPropertyNamesSuccess')); + console.info('uitest: testNodeAPIArray011 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/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/NodeAPI/NodeApiUse/NodeAPIProperty/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..39ca296385bbd8f80560884685005083c477d7f1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/ohosTest.md @@ -0,0 +1,18 @@ +# 使用Node-API进行property相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------- | ------------ | ---------------------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 getPropertyNames | 位于主页 | 点击文本为1.napiGetPropertyNames的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetPropertyNamesSuccess | Pass | +| ArkTS端成功调用native侧接口setProperty | 位于主页 | 点击文本为2.napiSetProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetPropertySuccess | Pass | +| ArkTS端成功调用native侧接口getProperty | 位于主页 | 点击文本为3.napiGetProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetPropertySuccess | Pass | +| ArkTS端成功调用native侧接口hasProperty | 位于主页 | 点击文本为4.napiHasProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasPropertySuccess | Pass | +| ArkTS端成功调用native侧接口napiDeleteProperty | 位于主页 | 点击文本为5.napiDeleteProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDeletePropertySuccess | Pass | +| ArkTS端成功调用native侧接口napiHasOwnProperty | 位于主页 | 点击文本为6.napiHasOwnProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasOwnPropertySuccess | Pass | +| ArkTS端成功调用native侧接口napiSetNamedProperty | 位于主页 | 点击文本为7.napiSetNamedProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetNamedPropertySuccess | Pass | +| ArkTS端成功调用native侧接口napiGetNamedProperty | 位于主页 | 点击文本为8.napiGetNamedProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetNamedPropertySuccess | Pass | +| ArkTS端成功调用native侧接口napiHasNamedProperty | 位于主页 | 点击文本为9.napiHasNamedProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasNamedPropertySuccess | Pass | +| ArkTS端成功调用native侧接口defineStringProperties | 位于主页 | 点击文本为10.napiDefineProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDefinePropertiesSuccess | Pass | +| ArkTS端成功调用native侧接口getAllPropertyNames | 位于主页 | 点击文本为11.napiGetAllPropertyNames的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetAllPropertyNamesSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeAPIProperty/screenshots/NodeAPIProperty2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/.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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..eafb1afea558c1c45fc5a4c19afc165e7ea3704e --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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.nodeapicustomasynchronousoperations", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e56ec1a57c784b54808661c63c8a97014213271a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeApiCustomAsynchronousOperations" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/README.md new file mode 100644 index 0000000000000000000000000000000000000000..472269d2e0197d1b1aaf4d38aa2bfcc2e8ace1b7 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/README.md @@ -0,0 +1,75 @@ +# ArkTS使用Node-API进行自定义异步操作相关开发 + +### 介绍 + +使用Node-API的自定义异步操作功能,可以使ArkTS的使用更加灵活和高效,可以处理那些可能阻塞事件循环的长时间运行任务,同时保持ArkTS应用的响应性和性能。 + +本工程主要展示了使用Node-API进行创建和销毁异步资源上下文环境、在异步资源上下文环境中执行ArkTS回调函数和创建关闭回调作用域实现场景,其中代码详细描述可查如下链接。 + +- [使用Node-API进行自定义异步操作相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-custom-asynchronous-operations.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeApiCustomAsynchronousOperations.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行自定义异步操作相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeApiCustomAsynchronousOperations.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c921de18a8c261d05fb0ebdfb8b91f375e187e13 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,19 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(use_napi_about_custom_asynchronous_operations) + +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) + +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libhilog_ndk.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fec57c3c1d82c66dcde159f92acff6cce1bcc239 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_async_open_close_callback_scope] +#include "napi/native_api.h" + +static constexpr int INT_ARG_3 = 3; // 入参索引 + +static napi_value AsynchronousWork(napi_env env, napi_callback_info info) +{ + // 接受四个参数 + size_t argc = 4; + napi_value args[4] = {nullptr}; + // 从回调信息中获取参数 + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 提取参数中的资源、接收器对象和函数 + napi_value resource = args[0]; + napi_value recv = args[1]; + napi_value func = args[2]; + napi_value argv[1] = {nullptr}; + argv[0] = args[INT_ARG_3]; + // 获取函数的类型 + napi_valuetype funcType; + napi_typeof(env, func, &funcType); + // 创建一个资源名称为"test"的字符串 + napi_value resourceName = nullptr; + napi_create_string_utf8(env, "test", NAPI_AUTO_LENGTH, &resourceName); + // 初始化异步上下文 + napi_async_context context; + napi_status status = napi_async_init(env, resource, resourceName, &context); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_async_init fail"); + return nullptr; + } + // 打开回调作用域 + napi_callback_scope scope = nullptr; + napi_open_callback_scope(env, resource, context, &scope); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_open_callback_scope fail"); + return nullptr; + } + // 调用回调函数 + napi_value result = nullptr; + if (funcType == napi_function) { + napi_make_callback(env, context, recv, func, 1, argv, &result); + } else { + napi_throw_error(env, nullptr, "Unexpected argument type"); + return nullptr; + } + // 关闭回调作用域 + napi_close_callback_scope(env, scope); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "napi_close_callback_scope fail"); + return nullptr; + } + // 销毁异步上下文 + napi_async_destroy(env, context); + return result; +} +// [End napi_async_open_close_callback_scope] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"asynchronousWork", nullptr, AsynchronousWork, 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..7cba3716d788dda2a73d791a2a8eff0df814c1f9 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_async_open_close_callback_scope_api] +export const asynchronousWork: (object: Object, obj: Object, fun: Function, num: number) => number | void; +// [End napi_async_open_close_callback_scope_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4764c2b12c5985b56effc6ad5250423c8900ea47 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start ark_napi_async_open_close_callback_scope] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import testNapi from 'libentry.so'; +import process from '@ohos.process'; + +// [StartExclude ark_napi_async_open_close_callback_scope] +@Entry +@Component +struct Index { + @State result: string = ''; + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(25) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 3 }) + List({ space: '10vp' }) { + ListItem() { + Text('1.customAsync') + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + // [EndExclude ark_napi_async_open_close_callback_scope] + try { + hilog.info(0x0000, 'testTag', 'Test Node-API asynchronousWork: %{public}d', + testNapi.asynchronousWork({}, process.ProcessManager, (num: number) => { + return num; + }, 123)); + this.result = 'customAsyncSuccess'; + } catch (error) { + hilog.error(0x0000, 'testTag', 'Test Node-API asynchronousWork error: %{public}s', error.message); + this.result = 'customAsyncFail'; + } + // [End ark_napi_async_open_close_callback_scope] + }) + } + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/NodeApiCustomAsynchronousOperations.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/NodeApiCustomAsynchronousOperations.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/NodeApiCustomAsynchronousOperations.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/NodeApiCustomAsynchronousOperations.test.ets index d74879a7e41f3c2f2bdd76ec3c13a87d9aad79e1..5a937534d2e256be9a5ec5358dcc165e4dbf3ad5 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/NodeApiCustomAsynchronousOperations.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/ets/test/NodeApiCustomAsynchronousOperations.test.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeApiCustomAsynchronousOperationsTest() { - describe('nodeApiCustomAsynchronousOperationsTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用customAsync相关函数 - */ - it('testNodeApiCustomAsynchronousOperations001', 0, async (done: Function) => { - console.info('uitest: testNodeApiCustomAsynchronousOperations001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.customAsync')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: customAsyncSuccess')); - console.info('uitest: testNodeApiCustomAsynchronousOperations001 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeApiCustomAsynchronousOperationsTest() { + describe('nodeApiCustomAsynchronousOperationsTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用customAsync相关函数 + */ + it('testNodeApiCustomAsynchronousOperations001', 0, async (done: Function) => { + console.info('uitest: testNodeApiCustomAsynchronousOperations001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.customAsync')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: customAsyncSuccess')); + console.info('uitest: testNodeApiCustomAsynchronousOperations001 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..7bb5b0bb697d44750e17c39531467f400e3b295a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/ohosTest.md @@ -0,0 +1,8 @@ +# 使用Node-API进行自定义异步操作相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------- | ------------ | --------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口asynchronousWork | 位于主页 | 点击文本为1.customAsync的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: customAsyncSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/screenshots/NodeApiCustomAsynchronousOperations2.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/.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/NodeAPI/NodeApiUse/NodeApiString/AppScope/app.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..468b1ae0de8e7646cb9895af286d36eed9763cf6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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.nodeapistring", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..14cc24af14edecbbb0155ee27ee2a2da83d81c08 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NodeApiString" + } + ] +} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/media/app_icon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/media/app_icon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/README.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/README.md new file mode 100644 index 0000000000000000000000000000000000000000..45a7b9643be9e135648c4d3470c651fb25413087 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/README.md @@ -0,0 +1,73 @@ +# ArkTS使用Node-API进行string相关开发 + +### 介绍 + +使用Node-API关于string的六个接口,可以让Node-API模块和ArkTS字符串进行交互,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [使用Node-API进行string相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-string.md) + +### 效果预览 + +| 首页 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 +3. 运行测试用例NodeApiString.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── Index.d.ts + │ │ ├── oh-package.json5 + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用Node-API进行string相关开发示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── NodeApiString.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/code-linter.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/.gitignore b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/build-profile.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..31862257476bc8403e59fa42b4c924974d7dbe03 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64", + "armeabi-v7a" + ] + } + }, + "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/NodeAPI/NodeApiUse/NodeApiString/entry/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d1147dffa085092ee7ab528ad83a6207a3a8c91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,17 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(use_napi_about_string) + +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) +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..218e221670f28a3782ca538d963aaa019accf8e6 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,162 @@ +/* + * 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 +#include + +static const int MAX_BUFFER_SIZE = 128; + +// [Start napi_get_value_string_utf8] +static napi_value GetValueStringUtf8(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取字符串的长度 + size_t length = 0; + napi_status status = napi_get_value_string_utf8(env, args[0], nullptr, 0, &length); + // 传入一个非字符串 napi_get_value_string_utf8接口会返回napi_string_expected + if (status != napi_ok) { + return nullptr; + } + char *buf = new char[length + 1]; + std::memset(buf, 0, length + 1); + napi_get_value_string_utf8(env, args[0], buf, length + 1, &length); + napi_value result = nullptr; + status = napi_create_string_utf8(env, buf, length, &result); + delete buf; + if (status != napi_ok) { + return nullptr; + }; + return result; +} +// [End napi_get_value_string_utf8] + +// [Start napi_create_string_utf8] +static napi_value CreateStringUtf8(napi_env env, napi_callback_info info) +{ + const char *str = u8"你好, World!, successes to create UTF-8 string! 111"; + size_t length = strlen(str); + napi_value result = nullptr; + napi_status status = napi_create_string_utf8(env, str, length, &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Failed to create UTF-8 string"); + return nullptr; + } + return result; +} +// [End napi_create_string_utf8] + +// [Start napi_get_value_string_utf16] +static napi_value GetValueStringUtf16(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1]; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value result = nullptr; + // 字符串的缓冲区 + char16_t buffer[MAX_BUFFER_SIZE]; + // 字符串的缓冲区大小 + size_t bufferSize = MAX_BUFFER_SIZE; + // 字符串的长度 + size_t stringLen; + // 获取字符串的数据和长度 + napi_get_value_string_utf16(env, args[0], buffer, bufferSize, &stringLen); + // 获取字符串返回结果 + napi_create_string_utf16(env, buffer, stringLen, &result); + // 返回结果 + return result; +} +// [End napi_get_value_string_utf16] + +// [Start napi_create_string_utf16] +static napi_value CreateStringUtf16(napi_env env, napi_callback_info info) +{ + const char16_t *str = u"你好, World!, successes to create UTF-16 string! 111"; + size_t length = NAPI_AUTO_LENGTH; + napi_value result = nullptr; + napi_status status = napi_create_string_utf16(env, str, length, &result); + if (status != napi_ok) { + napi_throw_error(env, nullptr, "Failed to create UTF-16 string"); + return nullptr; + } + return result; +} +// [End napi_create_string_utf16] + +// [Start napi_get_value_string_latin1] +static napi_value GetValueStringLatin1(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + char buf[MAX_BUFFER_SIZE]; + size_t length = 0; + napi_value napi_Res = nullptr; + napi_status status = napi_get_value_string_latin1(env, args[0], buf, MAX_BUFFER_SIZE, &length); + // 当输入的值不是字符串时,接口会返回napi_string_expected + if (status == napi_string_expected) { + return nullptr; + } + napi_create_string_latin1(env, buf, length, &napi_Res); + return napi_Res; +} +// [End napi_get_value_string_latin1] + +// [Start napi_create_string_latin1] +static napi_value CreateStringLatin1(napi_env env, napi_callback_info info) +{ + const char *str = "Hello, World! éçñ, successes to create Latin1 string! 111"; + size_t length = NAPI_AUTO_LENGTH; + napi_value result = nullptr; + napi_status status = napi_create_string_latin1(env, str, length, &result); + if (status != napi_ok) { + // 处理错误 + napi_throw_error(env, nullptr, "Failed to create Latin1 string"); + return nullptr; + } + return result; +} +// [End napi_create_string_latin1] + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"getValueStringUtf8", nullptr, GetValueStringUtf8, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createStringUtf8", nullptr, CreateStringUtf8, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueStringUtf16", nullptr, GetValueStringUtf16, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createStringUtf16", nullptr, CreateStringUtf16, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"getValueStringLatin1", nullptr, GetValueStringLatin1, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createStringLatin1", nullptr, CreateStringLatin1, 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c26ca99cec495c2b09a02db8e3e89701d14fad1 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// [Start napi_get_value_string_utf8_api] +export const getValueStringUtf8: (param: string | number) => string | void; +// [End napi_get_value_string_utf8_api] + +// [Start napi_create_string_utf8_api] +export const createStringUtf8: () => string | void; +// [End napi_create_string_utf8_api] + +// [Start napi_get_value_string_utf16_api] +export const getValueStringUtf16: (data: string) => string; +// [End napi_get_value_string_utf16_api] + +// [Start napi_create_string_utf16_api] +export const createStringUtf16: () => string | void; +// [End napi_create_string_utf16_api] + +// [Start napi_get_value_string_latin1_api] +export const getValueStringLatin1: (param: number | string) => string | void; +// [End napi_get_value_string_latin1_api] + +// [Start napi_create_string_latin1_api] +export const createStringLatin1: () => string | void; +// [End napi_create_string_latin1_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..23a4e3141bc213d73ddccf02806b879fa444f7ae --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,95 @@ +/* + * 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'; + +@Entry +@Component +struct Index { + @State result: string = '' + private items: string[] = [ + 'Reset Result Message', + '1.napiString' + ] + + build() { + Column() { + Text('Result: ' + this.result) + .fontSize(22) + .fontWeight(FontWeight.Bold) + .margin({ bottom: 4 }) + List({ space: '10vp' }) { + ForEach(this.items, (item: string) => { + ListItem() { + Text(item) + .fontSize(16) + .width('100%') + .height(60) + .textAlign(TextAlign.Center) + .fontWeight(FontWeight.Bold) + .borderRadius(30) + .backgroundColor(Color.White) + .onClick(() => { + if (item === 'Reset Result Message') { + this.result = ''; + } else if (item === '1.napiString') { + // [Start ark_napi_get_value_string_utf8] + // 分别传入字符和非字符检测接口,传入字符串类型的数据将返回原字符串,传入其他类型返回undefined + hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_string %{public}s', + testNapi.getValueStringUtf8('aaBC+-$%^你好123')); + hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_not_string %{public}s', + testNapi.getValueStringUtf8(50)); + // [End ark_napi_get_value_string_utf8] + // [Start ark_napi_create_string_utf8] + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf8:%{public}s', + testNapi.createStringUtf8()); + // [End ark_napi_create_string_utf8] + // [Start ark_napi_get_value_string_utf16] + let result = testNapi.getValueStringUtf16('hello,'); + hilog.info(0x0000, 'testTag', 'Node-API napi_get_value_string_utf16:%{public}s', result); + // [End ark_napi_get_value_string_utf16] + // [Start ark_napi_create_string_utf16] + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf16:%{public}s ', + testNapi.createStringUtf16()); + // [End ark_napi_create_string_utf16] + // [Start ark_napi_get_value_string_latin1] + // 传入非字符型数据,函数返回undefined + hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_not_string %{public}s', + testNapi.getValueStringLatin1(10)); + // ISO-8859-1编码不支持中文,传入中文字符会乱码 + hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_string_chinese %{public}s', + testNapi.getValueStringLatin1('中文')); + // 传入其他字符,不会乱码 + hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_string %{public}s', + testNapi.getValueStringLatin1('abo ABP=-&*/')); + // [End ark_napi_get_value_string_latin1] + // [Start ark_napi_create_string_latin1] + hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_latin1:%{public}s', + testNapi.createStringLatin1()); + // End ark_napi_create_string_latin1] + this.result = 'napiStringSuccess'; + } + }) + } + }) + }.scrollBar(BarState.Off) + .width('90%') + }.width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/background.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/background.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/foreground.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/foreground.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/startIcon.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/media/startIcon.png diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/en_US/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/en_US/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/zh_CN/element/string.json rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/zh_CN/element/string.json diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/Ability.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/Ability.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/NodeApiString.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/NodeApiString.test.ets old mode 100755 new mode 100644 similarity index 97% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/NodeApiString.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/NodeApiString.test.ets index 7e36a6a7178042a737d5e2fbbf0c26384b170ea1..989f22c481e8961562e868a2abbf6b0808adb1ba --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/NodeApiString.test.ets +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/ets/test/NodeApiString.test.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nodeAPIStringTest() { - describe('nodeAPIStringTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,调用Node-API关于string的方法 - */ - it('testNodeAPIString001', 0, async (done: Function) => { - console.info('uitest: testNodeAPIString001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('1.napiString')); - await driver.delayMs(1000); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Result: napiStringSuccess')); - console.info('uitest: testNodeAPIString001 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nodeAPIStringTest() { + describe('nodeAPIStringTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,调用Node-API关于string的方法 + */ + it('testNodeAPIString001', 0, async (done: Function) => { + console.info('uitest: testNodeAPIString001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('1.napiString')); + await driver.delayMs(1000); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Result: napiStringSuccess')); + console.info('uitest: testNodeAPIString001 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/List.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/List.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/List.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/List.test.ets diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/LocalUnit.test.ets rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/entry/src/test/LocalUnit.test.ets diff --git a/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/hvigorfile.ts b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/oh-package.json5 b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/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/NodeAPI/NodeApiUse/NodeApiString/ohosTest.md b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..0b01563969d6cec903ee32578b208732e6075ddf --- /dev/null +++ b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/ohosTest.md @@ -0,0 +1,8 @@ +# 使用Node-API进行string相关开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| ------------------------------------------------------------ | ------------ | -------------------------------- | ------------------------------------------------------------ | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | +| ArkTS端成功调用native侧接口 getValueStringUtf8,createStringUtf8,getValueStringUtf16, createStringUtf16, getValueStringLatin1,createStringLatin1 | 位于主页 | 点击文本为1.napiString的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiStringSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString1.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString1.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString1.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString1.png diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString2.png b/code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString2.png old mode 100755 new mode 100644 similarity index 100% rename from code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString2.png rename to code/DocsSample/ArkTS/NodeAPI/NodeApiUse/NodeApiString/screenshots/NodeApiString2.png diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/app.json5 deleted file mode 100755 index a5a836facd00af5d14fd57a9c60e9358c138c8bc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.dynamicimport", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/element/string.json deleted file mode 100755 index c33ab7f15330cb13dc7d89f552cb7170311fe99a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DynamicImport" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/README.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/README.md deleted file mode 100755 index c5e10694158daa2aae8351b33e44693c4a141dad..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# ArkTS动态加载 - -### 介绍 - -动态import支持条件延迟加载,支持部分反射功能,可以提升页面的加载速度;动态import支持加载HSP模块/HAR模块/OHPM包/Native库等,并且HAR模块间只有变量动态import时还可以进行模块解耦 - -本示例主要展示了动态加载的业务拓展场景介绍、动态加载常量表达式、动态加载变量表达式以及HAR模块间动态加载依赖解耦这些场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [动态加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-dynamic-import.md) - -### 效果预览 - -| 执行结果图 | -| ------------------------------------------------------------ | -| | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,分别点击ListItem组件可以执行对应文本内容的操作,然后在控制台中打印出对应日志。 -3. 运行测试用例DynamicImport.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 动态加载示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── DynamicImport.test.ets // 自动化测试代码 - │ │ └── List.test.ets - har1 // har1模块函数实现 - ├── src - │ ├── main - │ │ ├── ets - │ │ │ ├── utils - │ │ │ │ └── Calc.ets - │ │ │ └── components - │ │ │ │ └── MainPage.ets - har2 // har1模块函数实现 - ├── src - │ ├── main - │ │ ├── ets - │ │ │ ├── utils - │ │ │ │ └── Calc.ets - │ │ │ └── components - │ │ │ │ └── MainPage.ets - ├── index.ets - harlibrary // harlibrary模块函数实现 - ├── src - │ ├── main - │ │ ├── ets - │ │ │ ├── utils - │ │ │ │ └── Calc.ets - │ │ │ └── components - │ │ │ │ └── MainPage.ets - ├── index.ets - myHar // myHar模块函数实现 - ├── src - │ ├── main - │ │ ├── ets - │ │ │ └── components - │ │ │ │ └── MainPage.ets - ├── index.ets - myHsp // myHsp模块函数实现 - ├── src - │ ├── main - │ │ ├── ets - │ │ │ ├── pages - │ │ │ │ └── Index.ets - │ │ │ └── utils - │ │ │ │ └── Calc.ets - ├── index.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/build-profile.json5 deleted file mode 100755 index a8c3e30b26de45cd34e18bd4d08b63b9f2052517..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/build-profile.json5 +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "harlibrary", - "srcPath": "./harlibrary", - }, - { - "name": "myHar", - "srcPath": "./myHar", - }, - { - "name": "myHsp", - "srcPath": "./myHsp", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "har1", - "srcPath": "./har1", - }, - { - "name": "har2", - "srcPath": "./har2", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 deleted file mode 100755 index 9deb3b133d0769bdfb7f2274042723a33ad3a307..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/build-profile.json5 +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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": { - "arkOptions": { - "runtimeOnly": { - "packages": [ - "myhar", - // 仅用于使用变量动态import其他模块名场景,静态import或常量动态import无需配置。 - "myhsp", - // 仅用于使用变量动态import其他模块名场景,静态import或常量动态import无需配置。 - "@ohos/hypium", - "@ohos/crypto-js", - "libentry.so", - "har1", - "har2" - ], - // 配置本模块变量动态import其他模块名,要求与dependencies中配置的名字一致。 - "sources": [ - // 仅用于使用变量动态import模块自己单文件场景,静态import或常量动态import无需配置。 - "./src/main/ets/utils/Calc.ets", - "./src/main/ets/Calc.ets" - ] - // 配置本模块变量动态import自己的文件路径,路径相对于当前build-profile.json5文件。 - } - }, - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - }, - }, - "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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/oh-package.json5 deleted file mode 100755 index e3ec659f19f6c1d9f1d4d9a01c2e8710669616e6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/oh-package.json5 +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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": { - "harlibrary": "file:../harlibrary", - "myhar": "file:../myHar", - //HAP常量动态import HAR模块名 HAP常量动态import HAR模块文件路径 - "myhsp": "file:../myHsp", - //HAP常量动态import HSP模块名 HAP常量动态import HSP模块名文件路径 - "@ohos/crypto-js": "2.0.3-rc.0", - //HAP常量动态import远程HAR模块名 - "@ohos/hypium": "1.0.19", - //HAP常量动态import ohpm包 - "libentry.so": "file:./src/main/cpp/types/libentry", - //HAP常量动态import自己的Native库 - "har1": "file:../har1", - "har2": "file:../har2" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 47d73d8977698218e8204035ab583e554c6ee0a5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(DynamicImport) - -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) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index fd3f2e882cdeff7e13d955f8bfc6b99b2d89024f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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" - -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - double value0; - napi_get_value_double(env, args[0], &value0); - double value1; - napi_get_value_double(env, args[1], &value1); - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - return sum; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"add", nullptr, Add, 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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts deleted file mode 100755 index 27eb9617d25b96bff253c65e175409784697cd34..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start hap_const_dynamic_import_native] -export const add: (a: number, b: number) => number; -// [End hap_const_dynamic_import_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index e8f69f3d7619ec71489946af3b6f83522b32de76..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets deleted file mode 100755 index 606453a50db5c26c26696742b3d97d43ade54552..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/Calc.ets +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start hap_const_dynamic_import_add] -export function add(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); - return c; -} -// [End hap_const_dynamic_import_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Calc.ets deleted file mode 100755 index 591ad6994e8a1151843d46a2dc078a1fdde9b44a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/pages/Calc.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 function add(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); - return c; -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/utils/Calc.ets deleted file mode 100755 index 591ad6994e8a1151843d46a2dc078a1fdde9b44a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/ets/utils/Calc.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 function add(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am a HAP, %d + %d = %d', a, b, c); - return c; -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets deleted file mode 100755 index e0345cb61d753496fc4de59a5e8d08c67e695009..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/Index.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 { MainPage } from './src/main/ets/components/MainPage'; - -// [Start export_add_har1] -export { addHar1 } from './src/main/ets/utils/Calc'; -// [End export_add_har1] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/build-profile.json5 deleted file mode 100755 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/build-profile.json5 +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/oh-package.json5 deleted file mode 100755 index 076809555513a7342665525e864ac96d045eea53..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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": "har1", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets deleted file mode 100755 index 7cc5071259ad983e4117ffe8cfbc4be961d60b17..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/ets/utils/Calc.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start function_add_har1] -export function addHar1(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am har1, %d + %d = %d', a, b, c); - - let harName = 'har2'; - import(harName).then((ns: ESObject) => { - console.info('DynamicImport addHar2 4 + 5 = ' + ns.addHar2(4, 5)); - }); - return c; -} -// [End function_add_har1] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/module.json5 deleted file mode 100755 index bdac60be9af186785fdad034997a0ad0e8d0425e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "har1", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/module.json5 deleted file mode 100755 index 49d7bcb9feed30b64a003c95d738594b9280377f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har1/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "har1_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets deleted file mode 100755 index 248cad021d26d33980fb855f19ae7cba8ea59f2b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/Index.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 { MainPage } from './src/main/ets/components/MainPage'; - -// [Start export_add_har2] -export { addHar2 } from './src/main/ets/utils/Calc' -// [End export_add_har2] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/build-profile.json5 deleted file mode 100755 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/build-profile.json5 +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/oh-package.json5 deleted file mode 100755 index 39e87d1423686fe45e0bb54fe5e4d3aee89b302c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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": "har2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets deleted file mode 100755 index 13cc0fe20a97836f97a2dca506a6d7705a088812..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/ets/utils/Calc.ets +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start function_add_har2] -export function addHar2(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am har2, %d + %d = %d', a, b, c); - return c; -} -// [End function_add_har2] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/module.json5 deleted file mode 100755 index 26b32e3ff585426e0eb7e21fcdb475612c1b99de..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "har2", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/module.json5 deleted file mode 100755 index 68ada365ca86668f844fe10c4326151ffa0a03a5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/har2/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "har2_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets deleted file mode 100755 index ce8819144b46a1b13a52e65fac1975f790871cd7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/Index.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 { MainPage } from './src/main/ets/components/MainPage' - -// [Start module_members_export] -export { Calc, addHarlibrary } from './src/main/ets/utils/Calc' -// [End module_members_export] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/build-profile.json5 deleted file mode 100755 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/build-profile.json5 +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/oh-package.json5 deleted file mode 100755 index fd559b8421aaab156bb9bbb1c73c4d55d47f3204..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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": "harlibrary", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets deleted file mode 100755 index 022d3ccd82446561cd408adad7c1764bf76dd418..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/ets/utils/Calc.ets +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start dynamic_call_add] -export class Calc { - public static staticAdd(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am harlibrary in staticAdd, %d + %d = %d', a, b, c); - return c; - } - - public instanceAdd(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am harlibrary in instanceAdd, %d + %d = %d', a, b, c); - return c; - } -} - -export function addHarlibrary(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am harlibrary in addHarlibrary, %d + %d = %d', a, b, c); - return c; -} -// [End dynamic_call_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/module.json5 deleted file mode 100755 index 1bb4d3be02fa8547a1b16c0fd3c9673a640e223b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "harlibrary", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/module.json5 deleted file mode 100755 index 5e30fc13073902f0256b2b94cdeba8e3584dd0bf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/harlibrary/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "harlibrary_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets deleted file mode 100755 index 04b0c498128340aa4d66aca8ab42b5fc575c14f0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/Index.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 { MainPage } from './src/main/ets/components/MainPage' - -// [Start const_dynamic_import_har] -export function add(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am a HAR, %d + %d = %d', a, b, c); - return c; -} -// [End const_dynamic_import_har] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/build-profile.json5 deleted file mode 100755 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/build-profile.json5 +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/oh-package.json5 deleted file mode 100755 index f920fe0def5d3c19611547a828d46a87b0a20be1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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": "myhar", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/module.json5 deleted file mode 100755 index 99a54418fd18343b8500dcc18b3e50999fc17b79..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "myHar", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/module.json5 deleted file mode 100755 index fdacb0b45940f8aa38074ddb38590ec282333af6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHar/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "myHar_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets deleted file mode 100755 index 5166a860b1b3511064990194a968074e21ef5244..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/Index.ets +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start const_dynamic_import_hsp] -export function add(a: number, b: number): number { - let c = a + b; - console.info('DynamicImport I am a HSP, %d + %d = %d', a, b, c); - return c; -} -// [End const_dynamic_import_hsp] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/build-profile.json5 deleted file mode 100755 index fc9f620cc74d462e3cb6b192f43d6747e081ca05..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/oh-package.json5 deleted file mode 100755 index 74befca1b5b8e08d24963953a209f36df172ebe8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "myhsp", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "packageType": "InterfaceHar", - "dependencies": { - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/module.json5 deleted file mode 100755 index 3dd3c21994742636201d1f9cfc8964a3b12ed94b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "myHsp", - "type": "shared", - "description": "$string:shared_desc", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "pages": "$profile:main_pages" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/element/string.json deleted file mode 100755 index 95ba6cbabb98622d7723dcd5f616d3326345eb95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/main/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "shared_desc", - "value": "description" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/module.json5 deleted file mode 100755 index 3c711dbadde667b81190afb7a09fbc353a2cee3b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/myHsp/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "myHsp_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/DynamicImport/ohosTest.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/ohosTest.md deleted file mode 100755 index e75996f67741c75316165d7cdfe5032602221b48..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/DynamicImport/ohosTest.md +++ /dev/null @@ -1,27 +0,0 @@ -# 动态加载测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------- | ------------ | ---- | ---------------------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 动态加载harlibrary模块调用函数 | 成功拉起应用 | | 输出日志 | 是 | Pass | -| HAP常量动态import HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import HAR模块文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import HSP模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import HSP模块名文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import远程HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import ohpm包 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import自己的单文件 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import自己的Native库 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP常量动态import加载API | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import HAR模块文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import HSP模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import HSP模块名文件路径 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import远程HAR模块名 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import ohpm包 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import自己的单文件 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import自己的Native库 | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| HAP变量动态import加载API | 成功拉起应用 | | 成功调用模块函数输出日志 | 是 | Pass | -| 动态加载耦合har包 | 成功拉起应用 | | 加载har1可以调用har2函数并打印日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/app.json5 deleted file mode 100755 index fb8e60ca1c8ab0f5611381a45aaf7fc7b19332b9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsapisloadnativemodule", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/element/string.json deleted file mode 100755 index 0965d737f86e06ffd825c0b48429d1c90403ff56..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsApisLoadNativeModule" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/README.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/README.md deleted file mode 100755 index e3ee2fcaaaa3a3adccb38a2f08685696904d357a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS同步方式动态加载native模块 - -### 介绍 - -本工程主要展示了使用loadNativeModule接口能力进行同步方式加载native模块。该工程中展示的代码详细描述可查如下链接部分。 - -- [同步方式动态加载native模块](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/js-apis-load-native-module.md) - -### 效果预览 - -| 首页 | 点击HAP加载系统库模块按钮后 | 点击HAP加载Native库按钮后 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面中Text组件文本呈现LoadNativeModule效果并有两个按钮,分别点击之后第两个个按钮Text文本变化如上图并在工作台打印日志。 -3. 运行测试用例JsApisLoadNativeModule.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── index.d.ts - │ │ │ ├── CMakeList.txt - │ │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 同步方式动态加载native模块 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── JsApisLoadNativeModule.test.ets // 自动化测试代码 - │ │ └── List.test -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 deleted file mode 100755 index 472a9260420cea77f8d432f967a475169d6cea87..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/build-profile.json5 +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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", - // [Start hap_load_native_dependence_01] - "buildOption": { - "arkOptions": { - "runtimeOnly": { - "packages": [ - "libentry.so" - ] - } - }, - // [StartExclude hap_load_native_dependence_01] - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - }, - // [EndExclude hap_load_native_dependence_01] - }, - // [End hap_load_native_dependence_01] - "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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 deleted file mode 100755 index d11c699914c5da1f6f69880a2bbcc07a1f26de71..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/oh-package.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "", - // [Start hap_load_native_dependence] - "dependencies": { - "libentry.so": "file:./src/main/cpp/types/libentry" - }, - // [End hap_load_native_dependence] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index bcfe2e711da26da03f69e0864ce4c50e77bd969e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(syncNative) - -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) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 797f8cde7843a68ed5e952f83b285d50ffb148c0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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" - -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - - double value0; - napi_get_value_double(env, args[0], &value0); - - double value1; - napi_get_value_double(env, args[1], &value1); - - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - - return sum; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"add", nullptr, Add, 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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts deleted file mode 100755 index 0069b64ba2422995f2a96e701ec78bd063c26d64..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start hap_load_native] -export const add: (a: number, b: number) => number; -// [End hap_load_native] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 908bff690bb2ec0de4cc4db15639812107e0c017..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/module.json5 deleted file mode 100755 index d777a889f6080098370e6d5bc086c3a0b2e59097..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/module.json5 deleted file mode 100755 index cb58bf6e31485a15c2247d4f1e6318310977634b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigor/hvigor-config.json5 deleted file mode 100755 index b839e9394547af5fced4e6e694d628c9a12b5b35..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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": { - }, - "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/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/oh-package.json5 deleted file mode 100755 index 95bf2b62b5bab47507f62693edb088f7f4cf9a12..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/ohosTest.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/ohosTest.md deleted file mode 100755 index 7918401ea1c6ce6f8870db6a161027b256740846..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/JsApisLoadNativeModule/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 同步方式动态加载Native模块测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------ | ------------ | ------------------------- | ------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| 主页按钮点击 | 位于主页 | 点击HAP加载系统库模块按钮 | 页面文本变化 | Pass | -| 主页按钮点击 | 位于主页 | 点击HAP加载Native库按钮 | 页面文本变化 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/app.json5 deleted file mode 100755 index 836ca100041e3c29e6cbce2638b988d82f5154f6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.lazyimport", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/element/string.json deleted file mode 100755 index 3f16263846ad3d3986ace7b1dc8d125cd974f792..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "LazyImport" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/README.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/README.md deleted file mode 100755 index 4f92135947e6df7266389745c8efc84e40a8c4e8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS延迟加载(lazy import) - -### 介绍 - -本工程主要对比了延迟加载与普通加载的区别,并展示延迟加载的错误使用方法。该工程中展示的代码详细描述可查如下链接部分。 - -- [延迟加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-lazy-import.md) - -### 效果预览 - -| 首页 | 依次点击按钮后结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面中Text组件呈现LazyImport效果,依次点击五个button,Text依次现实显示‘Call a success result: a = mod1 a executed’,‘‘Call b success result: b = mod1 b executed’, ‘‘Call c success result: c = mod2 c executed’, ‘Not advisable to use one error: ReferenceError: c is not initialized’, ‘Not advisable to use two error: ReferenceError: module environment is undefined’。 -3. 运行测试用例LazyImport.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── A.ets - │ │ ├── A_ns.ets - │ │ ├── B.ets - │ │ ├── C.ets - │ │ ├── fail_example.ets - │ │ ├── Index.ets // 延迟加载 - │ │ ├── middle.ets - │ │ ├── mod1.ets - │ │ ├── mod2.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── LazyImport.test.ets // 自动化测试代码 - │ │ └── List.test -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/build-profile.json5 deleted file mode 100755 index f618d798839273eee6e9563ee7dbdb39d008ee4c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/oh-package.json5 deleted file mode 100755 index d6e4d8eaef5dd4396cecb0cdf283f333d4980725..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index 16a6312a0f9d30c4598fe4e970d3597d6a4ef095..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/main', (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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/module.json5 deleted file mode 100755 index d777a889f6080098370e6d5bc086c3a0b2e59097..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/module.json5 deleted file mode 100755 index cb58bf6e31485a15c2247d4f1e6318310977634b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/LazyImport/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/hvigor/hvigor-config.json5 deleted file mode 100755 index f8c80644cad05d55ccae44a856e78d6e81630488..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/LazyImport/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/oh-package.json5 deleted file mode 100755 index 7b54e25c410e3435ec6ec128c734470f679294ad..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/LazyImport/ohosTest.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/ohosTest.md deleted file mode 100755 index 8cd3385f9ddc5f12e5976a0516a6b1e019b1f14a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/LazyImport/ohosTest.md +++ /dev/null @@ -1,12 +0,0 @@ -# 延迟加载测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------ | ------------ | ------------------- | ------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| 主页按钮点击 | 位于主页 | 点击触发a按钮 | 页面文本变化 | Pass | -| 主页按钮点击 | 位于主页 | 点击触发b按钮 | 页面文本变化 | Pass | -| 主页按钮点击 | 位于主页 | 点击触发c按钮 | 页面文本变化 | Pass | -| 主页按钮点击 | 位于主页 | 点击不推荐用法1按钮 | 页面文本变化 | Pass | -| 主页按钮点击 | 位于主页 | 点击不推荐用法2按钮 | 页面文本变化 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/app.json5 deleted file mode 100755 index 8337e040e49274509597fad036d8161c3535676c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.moduleloadingsideeffects", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/element/string.json deleted file mode 100755 index c453d4b6b76caebf7ffbf96d48a1accb6e9458c1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ModuleLoadingSideEffects" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/README.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/README.md deleted file mode 100755 index a62807bdc703087590799d4c2a22bc1d394de774..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# ArkTS模块加载副作用及优化 - -### 介绍 - -当使用ArkTS模块化时,模块的加载和执行可能会引发副作用。副作用是指在模块导入过程中,除了导出功能或对象之外,还产生了额外的行为或状态变化。这些行为可能影响程序别的部分,并导致非预期的顶层代码执行、全局状态变化、原型链修改、导入内容未定义等问题。 - -本项目展现了模块加载副作用及优化,包括模块执行顶层代码、修改全局对象、修改应用级ArkUI组件的状态变量信息、修改内置全局变量或原型链、循环依赖和延迟加载改变模块执行顺序等场景,对比产生副作用的场景和优化后场景。代码详细描述可查如下链接。 - -- [模块加载副作用及优化](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arkts-module-side-effects.md) - -### 效果预览 - -| 首页 | -| ------------------------------------------------------------ | -| | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面中呈现五个按钮分别对应介绍中五个场景,分别点击按钮可以跳转到各个场景的页面,页面中有副作用以及优化后结果进行对比,并在工作台打印日志。 -3. 运行测试用例ModuleLoadingSideEffects.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── LazyImportChangeExecutionOrder // 延迟加载改变模块执行顺序 - │ │ ├── ModifyGlobalObject // 修改全局对象 - │ │ ├── ModifyingGlobalVariables // 修改内置全局变量或原型链 - │ │ ├── ModifyTheApplicationLevelArkUI // 修改应用级ArkUI组件的状态变量信息 - │ │ ├── TopCodeModification // 模块执行顶层代码 - │ │ └── Index.ets // 首页 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── ModuleLoadingSideEffects.test.ets // 自动化测试代码 - │ │ └── List.test -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/oh-package.json5 deleted file mode 100755 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets deleted file mode 100755 index 77afe81b29fc135ba68bdf81d4e3e23a62f8b176..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/module.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start import_global_module_data] -export let data = 'data from module'; - -globalThis.someGlobalVar = 100; -// [End import_global_module_data] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleOptimize.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleOptimize.ets deleted file mode 100755 index 1a5e5366d90ef61d8ee1a84255122a7f17be4381..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/LazyImportChangeExecutionOrder/moduleOptimize.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 let dataOptimize = 'data from module'; - -export function initialize() { - globalThis.someGlobalVar = 100; // 延迟到函数调用时执行 -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets deleted file mode 100755 index 78c9caab64651ec67f1edfaa3218bbf684010c83..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/module.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start export_change_global_data_100] -export let data1 = 'data from module'; - -globalThis.someGlobalVar = 100; // 改变了全局状态 -// [End export_change_global_data_100] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleOptimize.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleOptimize.ets deleted file mode 100755 index 72ac72eafc903f83ed44adee2e35a5e09ba5b404..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyGlobalObject/moduleOptimize.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 let dataOptimize1 = 'data from module'; - -export function changeGlobalVar() { - globalThis.someGlobalVar = 100; -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets deleted file mode 100755 index 8d84ffea4937a5161a0840123a26f27b6459e53f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/module.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start set_app_storage_var] -export let data = 'data from module'; - -AppStorage.setOrCreate('SomeAppStorageVar1', 200); // 修改应用全局的UI状态 -// [End set_app_storage_var] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/moduleOptimize.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/moduleOptimize.ets deleted file mode 100755 index eb397654b22cff1825eec29b3268cab6de125105..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/ModifyTheApplicationLevelArkUI/moduleOptimize.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 let dataOptimize = 'data from module'; - -export function initialize() { - AppStorage.setOrCreate('SomeAppStorageVar2', 200); -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets deleted file mode 100755 index d83291a9749632fe4fed48fec4b3e90ca3097958..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/pages/TopCodeModification/module.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start module_load_directly] -export function initialize() { - console.log('Module loaded!'); -} -// [End module_load_directly] - -// [Start module_load_optimize] -export const dataOptimizeTwo = 1; -// [End module_load_optimize] diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/resource.ets deleted file mode 100755 index 79a04af93bcf6ee2b7d288a24558060fb6c69345..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/ets/util/resource.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 class P2PManager { - public resourceToString(resource: Resource):string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - -export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/oh-package.json5 b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/ohosTest.md b/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/ohosTest.md deleted file mode 100755 index 35810afe64f04f05c98485cbdeefbd518b46adcf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTSRuntime/ArkTSModule/ModuleLoadingSideEffects/ohosTest.md +++ /dev/null @@ -1,12 +0,0 @@ -# 模块加载副作用及优化测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动化 | 测试结果 | -| ------------------------------ | ---------------- | -------------------------------------- | ------------ | ---------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击LazyImport按钮 | 页面文本变化 | 是 | Pass | -| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击ModifyGlobalObject按钮 | 页面文本变化 | 是 | Pass | -| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击ModifyingGlobalVariables按钮 | 页面文本变化 | 是 | Pass | -| 主页按钮点击跳转按钮后文本显示 | 跳转按钮位于主页 | 点击ModifyTheApplicationLevelArkUI按钮 | 页面文本变化 | 是 | Pass | -| 主页按钮点击跳转按钮后按钮点击 | 跳转按钮位于主页 | 点击TopCodeModification按钮 | 页面文本变化 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/app.json5 deleted file mode 100755 index f31613490084ae7f4392f05586b514c949cccb22..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nativeinterthreadshared", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/element/string.json deleted file mode 100755 index f600c1a2242d6cfec1c177a2a68cd0e9e0b8735a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NativeInterthreadShared" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/README.md b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/README.md deleted file mode 100755 index 67f2e86e27a110793329ecbd146a4ce8b231337c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/README.md +++ /dev/null @@ -1,78 +0,0 @@ -# ArkTS C++线程间数据共享场景 - -### 介绍 - -当应用在C++层进行多线程的并发计算时,因为ArkTS的API需要在ArkTS的环境执行,为了避免在非UI主线程每次回调等待UI主线程ArkTS环境中执行的API调用结果,需要在这些C++线程上创建ArkTS执行环境和直接调用API,并且可能需要在C++线程之间对Sendable对象进行共享和操作。 - -为了支持此类场景,需要实现在C++线程上创建调用ArkTS的能力,其次还需要对Sendable对象进行多线程共享和操作。 - -该工程中展示的代码详细描述可查如下链接: - -- [C++线程间数据共享场景](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/native-interthread-shared.md) - -### 效果预览 - -| 首页 | 执行结果 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击hello world,开始执行。 -2. 执行结果会即时反馈在屏幕中央。 - -### 工程目录 - -``` -entry/src - ├──main - │ ├── cpp - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp // Naitve实现加载ArkTS模块的能力示例代码 - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 暴露接口 - │ │ │ │ ├── oh-package.json5 - │ ├── ets - │ │ ├── entryability - │ │ │ ├── EntryAbility.ets - │ │ ├── entrybackupability - │ │ │ ├── EntryBackupAbility.ets - │ │ ├── pages - │ │ ├── Index.ets // UI主线程发起调用示例代码 - │ │ ├── SendableObjTest.ets // ArkTS文件定义示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖s - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTS/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/build-profile.json5 deleted file mode 100755 index 21cff554210e7ead0baebebb58a5da1a84dd5fd8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/build-profile.json5 +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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", "armeabi-v7a"] - } - }, - "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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index cf003100b179d6b736c1f42f5e87cc57ab237287..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(MyApplication) - -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) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 6c257d1c7f1fa2212d10666403a59e7c98f025d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start native_deserialize_sendable] -// [Start native_load_arkts_module] -#include - -#include "napi/native_api.h" - -static void* g_serializationData = nullptr; -static void* CreateEnvAndSendSendable(void*) -{ - // 1. 创建基础运行环境 - napi_env env = nullptr; - napi_status ret = napi_create_ark_runtime(&env); - if (ret != napi_ok) { - std::abort(); - } - // 2. 加载自定义模块,假定SendableObjTest中提供创建sendable对象的方法newSendable - napi_value test = nullptr; - ret = napi_load_module_with_info( - env, "entry/src/main/ets/pages/SendableObjTest", "com.example.myapplication/entry", &test); - if (ret != napi_ok) { - std::abort(); - } - napi_value sendableObjTest = nullptr; - ret = napi_get_named_property(env, test, "SendableObjTest", &sendableObjTest); - if (ret != napi_ok) { - std::abort(); - } - // 3. 使用ArkTS中的newSendable,假设sendableObjTest中有一个函数newSendable能返回sendable对象 - napi_value newSendable = nullptr; - ret = napi_get_named_property(env, sendableObjTest, "newSendable", &newSendable); - if (ret != napi_ok) { - std::abort(); - } - // 4. 调用newSendable函数返回新创建的sendable对象,并保存在result中 - napi_value result = nullptr; - ret = napi_call_function(env, sendableObjTest, newSendable, 0, nullptr, &result); - if (ret != napi_ok) { - std::abort(); - } - // 5. 序列化sendable对象 - napi_value undefined; - napi_get_undefined(env, &undefined); - ret = napi_serialize(env, result, undefined, undefined, &g_serializationData); - if (ret != napi_ok) { - std::abort(); - } - return nullptr; -} -// [End native_load_arkts_module] - -static void* CreateEnvAndReceiveSendable(void*) -{ - // 1. 创建基础运行环境 - napi_env env = nullptr; - napi_status ret = napi_create_ark_runtime(&env); - if (ret != napi_ok) { - std::abort(); - } - // 2. 反序列化获取sendable共享对象,结果保存在result中,这个result就可以通过napi接口进行各种操作了 - napi_value result = nullptr; - ret = napi_deserialize(env, g_serializationData, &result); - if (ret != napi_ok) { - std::abort(); - } - // 3. 删除序列化数据 - ret = napi_delete_serialization_data(env, g_serializationData); - if (ret != napi_ok) { - std::abort(); - } - napi_valuetype valuetype0; - napi_typeof(env, result, &valuetype0); - if (valuetype0 != napi_number) { - std::abort(); - } - int value0; - napi_get_value_int32(env, result, &value0); - // 1024是判断ArkTS返回的结果是否正确 - if (value0 != 1024) { - std::abort(); - } - return nullptr; -} - -static napi_value TestSendSendable([[maybe_unused]] napi_env env, [[maybe_unused]] napi_callback_info info) -{ - std::thread t1(CreateEnvAndSendSendable, nullptr); - t1.join(); - std::thread t2(CreateEnvAndReceiveSendable, nullptr); - t2.join(); - return nullptr; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { { "testSendSendable", nullptr, TestSendSendable, 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); -} -// [End native_deserialize_sendable] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index d0d1a44b655ca1700e67008dad059ca1ab437c70..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start native_deserialize_sendable] -export const testSendSendable: () => void; -// [End native_deserialize_sendable] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index cc485abc9a4abcdf0d6dad9750ed7ceb71cb1e0b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start main_thread_init_call] -import { hilog } from '@kit.PerformanceAnalysisKit'; -import testNapi from 'libentry.so'; -import { SendableObjTest } from './SendableObjTest' - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - .onClick(() => { - SendableObjTest.newSendable() - hilog.info(0x0000, 'testTag', 'Test send Sendable begin'); - testNapi.testSendSendable(); - hilog.info(0x0000, 'testTag', 'Test send Sendable end'); - this.message = 'success'; - }) - } - .width('100%') - } - .height('100%') - } -} -// [End main_thread_init_call] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/ohosTest.md b/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/ohosTest.md deleted file mode 100755 index cf0c529a0f5b0a473373a4f327ea428a45ca6dfa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ApplicationMultithreadingDevelopment/NativeInterthreadShared/ohosTest.md +++ /dev/null @@ -1,8 +0,0 @@ -# NativeInterthreadShared 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| C++线程间数据共享场景 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/app.json5 deleted file mode 100755 index eb5e9df1209bf7b55d0c263d00ce828aeb4cd9b4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024 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.asyncconcurrencyoverview", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/element/string.json deleted file mode 100755 index efeed98b51026b1a2bb71c49f11fe2038394eb8a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AsyncConcurrencyOverview" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/README.md b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/README.md deleted file mode 100755 index 8e17cab11e26b306b384d81c2c2950802625b09e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/README.md +++ /dev/null @@ -1,66 +0,0 @@ -# ArkTS 异步并发 (Promise和async/await) - -### 介绍 - -Promise和async/await提供异步并发能力,是标准的JS异步语法。异步代码会被挂起并在之后继续执行,同一时间只有一段代码执行,适用于单次I/O任务的场景开发,例如一次网络请求、一次文件读写等操作。无需另外启动线程执行。 - -异步语法是一种编程语言的特性,允许程序在执行某些操作时不必等待其完成,而是可以继续执行其他操作。该工程中展示的代码详细描述可查如下链接: - -- [异步并发 (Promise和async/await)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/async-concurrency-overview.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击hello world,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 异步并发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/build-profile.json5 deleted file mode 100755 index 66e9c201526f26074790e52f116e13040c6ec690..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 14, - "compileSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/build-profile.json5 deleted file mode 100755 index 90b14923bfc8eb7450488a9312783c21aa1966db..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/oh-package.json5 deleted file mode 100755 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index 0cccf0646583878db78d837a301a66ac8091071a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1755a4686cf9f79996fdcd75b26f06b555c3ad3f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/module.json5 deleted file mode 100755 index b541792385cb5a1a925f93ae8c9242b9596ec27e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/module.json5 deleted file mode 100755 index 1f646ea03f584d15f4a5406ea548af0214a093d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/hvigor/hvigor-config.json5 deleted file mode 100755 index 794f9e19bae07bcc213a33859789cdcd746fb4ed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/oh-package.json5 deleted file mode 100755 index c60577dcc2abd816fbd7199b386894b565974a26..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/AsyncConcurrencyOverview/ohosTest.md b/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/ohosTest.md deleted file mode 100755 index e8643e78fe410ffd22156394709544c7ace232b6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/AsyncConcurrencyOverview/ohosTest.md +++ /dev/null @@ -1,8 +0,0 @@ -# AsyncConcurrencyOverview 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------- | ------------ | --------------- |------------------| -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 异步并发 | 位于首页 | 点击Hello World | 3秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/app.json5 deleted file mode 100755 index acc133aae3b183b44e6d74c8770efd122e16a8f7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.communicationobjects", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/element/string.json deleted file mode 100755 index 8b6ecf1b4157403c8873cb87e7eca97200da7145..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "CommunicationObjects" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/README.md b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/README.md deleted file mode 100755 index d01e95dbbeb804f4a969036abbd6de53dce4771f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/README.md +++ /dev/null @@ -1,93 +0,0 @@ -# ArkTS 线程间通信对象 - -### 介绍 - -#### 普通对象 - -普通对象跨线程时通过拷贝形式传递,两个线程的对象内容一致,但是指向各自线程的隔离内存区间,被分配在各自线程的虚拟机本地堆(LocalHeap)。例如Ecmascript262规范定义的Object、Array、Map等对象是通过这种方式实现跨并发实例通信的。 - -#### ArrayBuffer对象 - -ArrayBuffer内部包含一块Native内存,该ArrayBuffer的JS对象壳被分配在虚拟机本地堆(LocalHeap)。与普通对象一样,需要经过序列化与反序列化拷贝传递,但是Native内存有两种传输方式:拷贝和转移。 - -#### SharedArrayBuffer对象 - -SharedArrayBuffer内部包含一块Native内存,其JS对象壳被分配在虚拟机本地堆(LocalHeap)。支持跨并发实例间共享,但是访问及修改需要采用Atomics类,防止数据竞争。SharedArrayBuffer可以用于多个并发实例间的状态共享或者数据共享。 - -#### Transferable对象(NativeBinding对象) - -Transferable对象(也称为NativeBinding对象)指的是一个JS对象,绑定了一个C++对象,且主体功能由C++提供,其JS对象壳被分配在虚拟机本地堆(LocalHeap)。跨线程传输时可以直接复用同一个C++对象,相比于JS对象的拷贝模式,传输效率较高。因此,可共享或转移的NativeBinding对象也被称为Transferable对象。 - -该工程中展示的代码详细描述可查如下链接: - -- [普通对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/normal-object.md) -- [ArrayBuffer对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/arraybuffer-object.md) -- [SharedArrayBuffer对象](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/shared-arraybuffer-object.md) -- [Transferable对象(NativeBinding对象)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/transferabled-object.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,点击任意按钮进行跳转,点击Hello World执行程序 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── managers - │ │ ├── ArrayBufferObject.ets // ArrayBuffer对象示例代码 - │ │ ├── NormalObject.ets // 普通对象示例代码 - │ │ ├── pixelMapTest.ets // Transferable对象示例代码 - │ │ ├── SharedArrayBufferObject.ets // SharedArrayBuffer对象示例代码 - │ │ ├── Test.ets // 普通对象示例代码 - │ │ ├── TransferabledObject.ets // Transferable对象示例代码 - │ │ ├── pages - │ │ ├── Index.ets // 首页 - │ │ ├── util - │ │ ├── CommonButton.ets // 首页跳转UI - │ │ ├── resource.ets // 资源引用转换 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/oh-package.json5 deleted file mode 100755 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/Test.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/Test.ets deleted file mode 100755 index 2e652f5499777a2448e0f11ff776630b58e83c39..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/managers/Test.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start define_test_class] -// 自定义class TestA -export class TestA { - constructor(name: string) { - this.name = name; - } - name: string = 'ClassA'; -} -// [End define_test_class] diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/resource.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/resource.ets deleted file mode 100755 index 79a04af93bcf6ee2b7d288a24558060fb6c69345..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/ets/util/resource.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 class P2PManager { - public resourceToString(resource: Resource):string { - return getContext(this).resourceManager.getStringSync(resource); - } -} - -// 默认导出let -let p2pManager = new P2PManager(); - -export default p2pManager as P2PManager; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/ohosTest.md b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/ohosTest.md deleted file mode 100755 index e914f669f2238275975e9a354182bd7cb4809646..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/CommunicationObjects/ohosTest.md +++ /dev/null @@ -1,11 +0,0 @@ -# CommunicationObjects 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------- | ------------------------------- | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 普通对象 | 位于NormalObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| ArrayBuffer对象 | 位于ArrayBufferObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| SharedArrayBuffer对象 | 位于SharedArrayBufferObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| Transferable对象 | 位于TransferabledObject.ets | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/oh-package.json5 deleted file mode 100755 index 0f6e4f8db54490daa7ecbbb6bc4d77983eddb327..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "notallowedinside", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/module.json5 deleted file mode 100755 index a27e9f18c9852323faf2e581f95705b40896ebcc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "notallowedInside", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "NotallowedInsideAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "NotallowedInsideAbility", - "srcEntry": "./ets/notallowedinsideability/NotallowedInsideAbility.ets", - "description": "$string:NotallowedInsideAbility_desc", - "icon": "$media:layered_image", - "label": "$string:NotallowedInsideAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/module.json5 deleted file mode 100755 index 98cf2c71b05797ac36c3c05339d0b3566a295ab6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/notallowedInside/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "notallowedInside_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/oh-package.json5 deleted file mode 100755 index c04ca7fbd7655d78bd74f107c999d6009844847e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "objectliterals", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/module.json5 deleted file mode 100755 index 9461e70f734ab0733313b38a33a38e782ac78dd1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "objectliterals", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ObjectliteralsAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ObjectliteralsAbility", - "srcEntry": "./ets/objectliteralsability/ObjectliteralsAbility.ets", - "description": "$string:ObjectliteralsAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ObjectliteralsAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/module.json5 deleted file mode 100755 index 400184ab715d28d7c0ec3143b50887fb4b1a0b6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/objectliterals/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "objectliterals_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/oh-package.json5 deleted file mode 100755 index dbb5d033190e461545c03ce46cb81e336cf8b49b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "templatetype", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/module.json5 deleted file mode 100755 index f8d35fed0bb7a0bb5fdde3ccdf640b7909e9a686..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "templatetype", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "TemplatetypeAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "TemplatetypeAbility", - "srcEntry": "./ets/templatetypeability/TemplatetypeAbility.ets", - "description": "$string:TemplatetypeAbility_desc", - "icon": "$media:layered_image", - "label": "$string:TemplatetypeAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/module.json5 deleted file mode 100755 index 7ead18e3f65d4a88713ad08176415aff0128fa5d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/templatetype/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "templatetype_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/oh-package.json5 deleted file mode 100755 index c40faf81af388e0ceef9da9c599b301de5a0d4bc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "typecannot", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/module.json5 deleted file mode 100755 index 31ad2bd9ab72e3e7ea132eb90f6aa4680f2fb256..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "typecannot", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "TypecannotAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "TypecannotAbility", - "srcEntry": "./ets/typecannotability/TypecannotAbility.ets", - "description": "$string:TypecannotAbility_desc", - "icon": "$media:layered_image", - "label": "$string:TypecannotAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/module.json5 deleted file mode 100755 index d1c5eb7265052344bb69416f0a1f2a7f097cdbc6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/typecannot/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "typecannot_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/oh-package.json5 deleted file mode 100755 index c5eb5718c9601c439c01525a1a363ac7290aeb94..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "variablenotsupported", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/module.json5 deleted file mode 100755 index ad5c0a436a4fdc1d109abd866357effc61fb09c5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "variablenotsupported", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "VariablenotsupportedAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "VariablenotsupportedAbility", - "srcEntry": "./ets/variablenotsupportedability/VariablenotsupportedAbility.ets", - "description": "$string:VariablenotsupportedAbility_desc", - "icon": "$media:layered_image", - "label": "$string:VariablenotsupportedAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/module.json5 deleted file mode 100755 index ceaac6ea8f4f69300654bbcf08ed6565f487cf26..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablenotsupported/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "variablenotsupported_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/build-profile.json5 deleted file mode 100755 index b4d65d490ef6cbe22d933b9231555210f1555786..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/oh-package.json5 deleted file mode 100755 index f44dd71404e28896e9f5e6f1db416e5d56ee8132..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "variablesupport", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/module.json5 deleted file mode 100755 index ba603c0fa7f6b1f21cf4d381ac577ecd0fe30f3a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "variablesupport", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "VariablesupportAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "VariablesupportAbility", - "srcEntry": "./ets/variablesupportability/VariablesupportAbility.ets", - "description": "$string:VariablesupportAbility_desc", - "icon": "$media:layered_image", - "label": "$string:VariablesupportAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/module.json5 deleted file mode 100755 index 53359bf4e293e72471c18fa84b90321fcd8f1be3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions/variablesupport/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "variablesupport_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/app.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/app.json5 deleted file mode 100755 index 57ca40f75ff0f8e8db9bf9e909d784baeb54f3f6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024 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.multithreadconcurrencyoverview", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/element/string.json deleted file mode 100755 index d8673170449aacf6c72dca5fd02fe5fea01b01df..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MultiThreadConcurrencyOverview" - } - ] -} diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/README.md b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/README.md deleted file mode 100755 index 16920a8501e45c5c9e8d0c0b1b01bc94900ac96f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# ArkTS 多线程并发概述 - -### 介绍 - -并发模型是用来实现不同应用场景中并发任务的编程模型,常见的并发模型分为基于内存共享的并发模型和基于消息通信的并发模型。 - -Actor并发模型作为基于消息通信并发模型的典型代表,不需要开发者去面对锁带来的一系列复杂偶发的问题,同时并发度也相对较高,因此得到了广泛的支持和使用。 - -当前ArkTS提供了TaskPool和Worker两种并发能力,TaskPool和Worker都基于Actor并发模型实现。 - -Actor并发模型和内存共享并发模型的具体对比请见[多线程并发模型](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/multi-thread-concurrency-overview.md#多线程并发模型)。 - -该工程中展示的代码详细描述可查如下链接: - -- [多线程并发概述](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/multi-thread-concurrency-overview.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------: | :----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击start,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 多线程并发概述示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/build-profile.json5 deleted file mode 100755 index dc186a2884483501f458f38bdb6d22288743326c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2024 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/build-profile.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/build-profile.json5 deleted file mode 100755 index 90b14923bfc8eb7450488a9312783c21aa1966db..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/oh-package.json5 deleted file mode 100755 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index 0cccf0646583878db78d837a301a66ac8091071a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1755a4686cf9f79996fdcd75b26f06b555c3ad3f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/module.json5 deleted file mode 100755 index b541792385cb5a1a925f93ae8c9242b9596ec27e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/module.json5 deleted file mode 100755 index 1f646ea03f584d15f4a5406ea548af0214a093d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigor/hvigor-config.json5 deleted file mode 100755 index 794f9e19bae07bcc213a33859789cdcd746fb4ed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/oh-package.json5 b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/oh-package.json5 deleted file mode 100755 index c60577dcc2abd816fbd7199b386894b565974a26..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2024 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/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/ohosTest.md b/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/ohosTest.md deleted file mode 100755 index 40ef2575031f54440b80a195ef730dbec810d6af..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/ArkTsConcurrent/MultithreadedConcurrency/MultiThreadConcurrencyOverview/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# MultiThreadConcurrencyOverview 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------------------------------- | ------------ | --------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 使用基于Actor模型的TaskPool并发能力来解决生产者消费者问题 | 位于首页 | 点击start | 1秒后页面显示“success” | 是 | Pass | - diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmDebug/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/app.json5 deleted file mode 100755 index 66e2875f1a25b25a27478b037d49ed22c6954cdb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmdebug", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/resources/base/element/string.json deleted file mode 100755 index 9f1ea061be7c5da5ec57aa7209de10840bbff4aa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmDebug" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/README.md deleted file mode 100755 index ed914e07b0a5fdfd09a23f3b02856653dffdcef2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/README.md +++ /dev/null @@ -1,138 +0,0 @@ -# ArkTS JSVM-API典型使用场景指导 - -### 介绍 - -使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 - -- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 -- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 - -该工程中展示的代码详细描述可查如下链接: - -- [JSVM-API调试&定位](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/jsvm-debugger-cpuprofiler-heapsnapshot.md) -- [使用 code cache 加速编译](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-code-cache.md) -- [使用JSVM-API接口创建多个引擎执行JS代码并销毁](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-runtime-task.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-----------------------------------------------------------: | :-----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -aboutcodecache/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -openinspector/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -snapshot/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -runtimetask/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -``` - -### 相关权限 - -[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) - -### 依赖 - -不涉及。 - -### 约束与限制 - -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/JsvmDebug > .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/JsvmDebug/aboutcodecache/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmDebug/aboutcodecache/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmDebug/aboutcodecache/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmDebug/aboutcodecache/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/oh-package.json5 deleted file mode 100755 index 5e36a9bb95c4ccfb6f512403c93470e028d82a9d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "aboutcodecache", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libaboutcodecache.so": "file:./src/main/cpp/types/libaboutcodecache" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/CMakeLists.txt deleted file mode 100755 index cf0fc258d8a7266c3801927b5cc91e1c4bed18e6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmDebug) - -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) - -add_library(aboutcodecache SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(aboutcodecache PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/hello.cpp deleted file mode 100755 index 3ebce1b1a9e07cd18d16ee715fbbdb842a1e2bdf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/hello.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start jsvm_code_cache] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -// [StartExclude jsvm_code_cache] -#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) -// [EndExclude jsvm_code_cache] - -JSVM_Value UseCodeCache(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 编译参数准备 - JSVM_Value jsSrc; - JSVM_Script script; - JSVM_Value result; - size_t length = 0; - const uint8_t* dataPtr = nullptr; - bool cacheRejected = true; - static std::string src = R"JS( - a = 65536; - b = 32768; - c = a + b; - )JS"; - - // 生成 code cache - { - JSVM_HandleScope handleScope; - OH_JSVM_OpenHandleScope(env, &handleScope); - - // 源码字符串转换为 js 字符串 - OH_JSVM_CreateStringUtf8(env, src.c_str(), src.size(), &jsSrc); - - // 编译js代码 - OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script); - - // 执行js代码 - OH_JSVM_RunScript(env, script, &result); - int value = 0; - OH_JSVM_GetValueInt32(env, result, &value); - OH_LOG_INFO(LOG_APP, "first run result: %{public}d\n", value); - - if (dataPtr == nullptr) { - // 将js源码编译出的脚本保存到 cache, 可以避免重复编译, 带来性能提升 - OH_JSVM_CreateCodeCache(env, script, &dataPtr, &length); - } - - OH_JSVM_CloseHandleScope(env, handleScope); - } - - // 使用 code cache - { - JSVM_HandleScope handleScope; - OH_JSVM_OpenHandleScope(env, &handleScope); - - // 源码字符串转换为 js 字符串 - OH_JSVM_CreateStringUtf8(env, src.c_str(), src.size(), &jsSrc); - - // 使用 code cache 编译js代码 - OH_JSVM_CompileScript(env, jsSrc, dataPtr, length, true, &cacheRejected, &script); - - // 执行js代码 - OH_JSVM_RunScript(env, script, &result); - int value = 0; - OH_JSVM_GetValueInt32(env, result, &value); - OH_LOG_INFO(LOG_APP, "second run result: %{public}d\n", value); - - OH_JSVM_CloseHandleScope(env, handleScope); - } - OH_LOG_INFO(LOG_APP, "cache rejected: %{public}d\n", cacheRejected); - return result; -} - -// Register a callback. -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = UseCodeCache} -}; -static JSVM_CallbackStruct *method = param; -// Register the C++ callback as a JSVM globalThis.UseCodeCache property for the JS to call. -static JSVM_PropertyDescriptor descriptor[] = { - {"UseCodeCache", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// [End jsvm_code_cache] - -// 样例测试JS -const char *SRC_CALL_NATIVE = R"JS(UseCodeCache();)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 = "aboutcodecache", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/oh-package.json5 deleted file mode 100755 index 066c7380febdeb336ef018a9c11b465b14a110d1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/cpp/types/libaboutcodecache/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libaboutcodecache.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/JsvmDebug/aboutcodecache/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/pages/Index.ets deleted file mode 100755 index c28a78dc14cf3732c4fd4a3e12a8fb406d4dff23..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libaboutcodecache.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmDebug/aboutcodecache/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/module.json5 deleted file mode 100755 index 3025d78a5483e9640b5d653d8e833854cc9c83f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "aboutcodecache", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "AboutcodecacheAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "AboutcodecacheAbility", - "srcEntry": "./ets/aboutcodecacheability/AboutcodecacheAbility.ets", - "description": "$string:AboutcodecacheAbility_desc", - "icon": "$media:layered_image", - "label": "$string:AboutcodecacheAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/string.json deleted file mode 100755 index d473a265a98eb9b844a32d682cf8f9528b7f089d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "AboutcodecacheAbility_desc", - "value": "description" - }, - { - "name": "AboutcodecacheAbility_label", - "value": "JsvmDebug" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 184840bf0c267c97d0577291c7f5e88dd52bfbde..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testcodecache', 0, async (done: Function) => { - console.log('uitest: Testcodecache begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'AboutcodecacheAbility' - } - 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('AboutcodecacheAbility'); - - 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: Testcodecache end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmDebug/aboutcodecache/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/module.json5 deleted file mode 100755 index a6f6070ce42fe88721bb2979412e01a4f7fdc72f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/aboutcodecache/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "aboutcodecache_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/build-profile.json5 deleted file mode 100755 index 92fc4e620d45307ff4ee2a47e284f1ce6499087b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/build-profile.json5 +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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": "openinspector", - "srcPath": "./openinspector", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "snapshot", - "srcPath": "./snapshot", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "aboutcodecache", - "srcPath": "./aboutcodecache", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "runtimetask", - "srcPath": "./runtimetask", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmDebug/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/hvigor/hvigor-config.json5 deleted file mode 100755 index 9507fa00ff7ef49999fea76cdbfa6db8e74688bc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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*/ - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/hvigorfile.ts deleted file mode 100755 index e8e1ecbc43669db67b7be28c55610c16b5192b31..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/hvigorfile.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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/JsvmDebug/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmDebug/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/ohosTest.md deleted file mode 100755 index 352aa27ee1ab0f1160acc8cfa5f9c6ca7a11c225..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/ohosTest.md +++ /dev/null @@ -1,11 +0,0 @@ -# JsvmDebug 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 在指定的主机和端口上激活inspector,将用来调试JS代码 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取当前堆快照并将其输出到流 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用 code cache 加速编译 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| JSVM-API接口创建多个引擎执行JS代码并销毁 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmDebug/openinspector/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmDebug/openinspector/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmDebug/openinspector/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/oh-package.json5 deleted file mode 100755 index fa4a03ee8692162ca3e5ccf3e982b4156369b1b9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "openinspector", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libopeninspector.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 4777357731eac9e3a99c05bbcac6ca97769b220a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmDebug) - -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) - -add_library(openinspector SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(openinspector PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/hello.cpp deleted file mode 100755 index 2d39c18999170b7c3867f8581fcb80729a4cccf1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_open_inspector] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -#include -// [StartExclude oh_jsvm_open_inspector] -#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) -// [EndExclude oh_jsvm_open_inspector] - -// 待调试的JS源码 -static std::string g_srcDebugger = R"JS( -const concat = (...args) => args.reduce((a, b) => a + b); -var dialogue = concat('"What ', 'is ', 'your ', 'name ', '?"'); -dialogue = concat(dialogue, ' --', '"My ', 'name ', 'is ', 'Bob ', '."'); -)JS"; - -// 开启debugger -static const int INSPECTOR_PORT = 9225; -static void EnableInspector(JSVM_Env env) -{ - // 在指定的主机和端口上激活inspector,创建socket。 - OH_JSVM_OpenInspector(env, "localhost", INSPECTOR_PORT); - // 等待建立socket连接。 - OH_JSVM_WaitForDebugger(env, true); -} - -// 关闭debugger -static void CloseInspector(JSVM_Env env) -{ - // 关闭inspector,结束socket连接。 - OH_JSVM_CloseInspector(env); -} - -static void RunScript(JSVM_Env env) -{ - JSVM_HandleScope handleScope; - OH_JSVM_OpenHandleScope(env, &handleScope); - - JSVM_Value jsSrc; - OH_JSVM_CreateStringUtf8(env, g_srcDebugger.c_str(), g_srcDebugger.size(), &jsSrc); - - JSVM_Script script; - OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script); - - JSVM_Value result; - OH_JSVM_RunScript(env, script, &result); - - OH_JSVM_CloseHandleScope(env, handleScope); -} - -void TestJSVM() -{ - JSVM_InitOptions initOptions{}; - OH_JSVM_Init(&initOptions); - - JSVM_VM vm; - OH_JSVM_CreateVM(nullptr, &vm); - JSVM_VMScope vmScope; - OH_JSVM_OpenVMScope(vm, &vmScope); - - JSVM_Env env; - OH_JSVM_CreateEnv(vm, 0, nullptr, &env); - // 执行JS代码之前打开debugger。 - EnableInspector(env); - JSVM_EnvScope envScope; - OH_JSVM_OpenEnvScope(env, &envScope); - - // 执行JS代码。 - RunScript(env); - - OH_JSVM_CloseEnvScope(env, envScope); - // 执行JS代码之后关闭debugger。 - CloseInspector(env); - OH_JSVM_DestroyEnv(env); - OH_JSVM_CloseVMScope(vm, vmScope); - OH_JSVM_DestroyVM(vm); -} -// [End jsvm_open_inspector] - -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 = "openinspector", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmDebug/openinspector/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index b9c45d876cf71fc784ff5f0ee926e7c72301a78e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libopeninspector.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/JsvmDebug/openinspector/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmDebug/openinspector/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmDebug/openinspector/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/ets/pages/Index.ets deleted file mode 100755 index 32fadce71f8e8b8311f3057fa4e2cd8c6bc62530..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libopeninspector.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmDebug/openinspector/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/module.json5 deleted file mode 100755 index a6b879bea1520bfcf37e4e4fe24f164b700795ea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/module.json5 +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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": "openinspector", - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET", - "reason": "$string:app_name", - "usedScene": { - "abilities": [ - "FromAbility" - ], - "when": "inuse" - } - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/string.json deleted file mode 100755 index 6382470c42ee902ba35017108253ad745d6b9ecb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmDebug" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 4b4a8880b44143af8d79d5845427a867745821bc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testOpenInspector', 0, async (done: Function) => { - console.log('uitest: TestOpenInspector 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: TestOpenInspector end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmDebug/openinspector/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/module.json5 deleted file mode 100755 index 61bb03e80ec1a2dded463049fa6cca9ed41b4f2a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/openinspector/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "openinspector_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmDebug/runtimetask/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmDebug/runtimetask/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/oh-package.json5 deleted file mode 100755 index 2b6a6afd09ae5002c96c8ad5698da9f43addbd2f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "runtimetask", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libruntimetask.so": "file:./src/main/cpp/types/libruntimetask" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/CMakeLists.txt deleted file mode 100755 index fb9c66c70be1e569e094c9f979256ba5f3306f85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmDebug) - -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) - -add_library(runtimetask SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(runtimetask PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/hello.cpp deleted file mode 100755 index 94174827aae4c33bd34fe99fb0086edc2e5ccd64..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/cpp/hello.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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" - -// [Start runtime_task] -#include -#include -#include -using namespace std; -// 定义map管理每个独立vm环境 -static map g_vmMap; -static map g_envMap; -static map g_callBackStructMap; -static uint32_t g_envtagNumber = 0; -static std::mutex g_envMapLock; -// [StartExclude runtime_task] - -#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) -// [EndExclude runtime_task] - -#define CHECK_COND(cond) \ - do { \ - if (!(cond)) { \ - OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = false", __FILE__, __LINE__); \ - return -1; \ - } \ - } while (0) - -class Task { -public: - virtual ~Task() = default; - virtual void Run() = 0; -}; -static map> g_taskQueueMap; - -// 自定义Consoleinfo方法 -static JSVM_Value Consoleinfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1]; - #define MAX_LOG_LENGTH 255 - char log[MAX_LOG_LENGTH + 1] = ""; - size_t logLength; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); - - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, args[0], log, MAX_LOG_LENGTH, &logLength)); - log[MAX_LOG_LENGTH] = 0; - OH_LOG_INFO(LOG_APP, "JSVM API TEST: %{public}s", log); - return nullptr; -} - -// 自定义创建Promise方法用以在JS代码中创建Promise -static JSVM_Value CreatePromise(JSVM_Env env, JSVM_CallbackInfo info) -{ - OH_LOG_INFO(LOG_APP, "JSVM API TEST: CreatePromise start"); - int envID = -1; - // 通过当前env获取envID - for (auto it = g_envMap.begin(); it != g_envMap.end(); ++it) { - if (*it->second == env) { - envID = it->first; - break; - } - } - if (envID == -1) { - OH_LOG_ERROR(LOG_APP, "JSVM API TEST: CreatePromise envID failed"); - return nullptr; - } - JSVM_Value promise; - JSVM_Deferred deferred; - JSVM_CALL(OH_JSVM_CreatePromise(env, &deferred, &promise)); - // 设计ReadTask类用以将promise对象的deferred加入执行队列 - class ReadTask : public Task { - public: - ReadTask(JSVM_Env env, JSVM_Deferred deferred, int envNum) : env_(env), envID_(envNum), deferred_(deferred) {} - void Run() override - { - // string str = "TEST RUN OH_JSVM_ResolveDeferred"; - int envID = 0; - for (auto it = g_envMap.begin(); it != g_envMap.end(); ++it) { - if (*it->second == env_) { - envID = it->first; - break; - } - } - OH_LOG_INFO(LOG_APP, "JSVM API TEST: CreatePromise %{public}d", envID); - JSVM_Value result; - if (OH_JSVM_CreateInt32(env_, envID, &result) != JSVM_OK) { - return; - } - if (OH_JSVM_ResolveDeferred(env_, deferred_, result) != JSVM_OK) { - return; - } - } - - private: - JSVM_Env env_; - int envID_; - JSVM_Deferred deferred_; - }; - g_taskQueueMap[envID].push_back(new ReadTask(env, deferred, envID)); - OH_LOG_INFO(LOG_APP, "JSVM API TEST: CreatePromise end"); - return promise; -} - -// 自定义Add方法 -static JSVM_Value Add(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 2; - JSVM_Value args[2]; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); - double num1; - double num2; - JSVM_CALL(OH_JSVM_GetValueDouble(env, args[0], &num1)); - JSVM_CALL(OH_JSVM_GetValueDouble(env, args[1], &num2)); - JSVM_Value sum = nullptr; - JSVM_CALL(OH_JSVM_CreateDouble(env, num1 + num2, &sum)); - return sum; -} - -// 自定义AssertEqual方法 -static JSVM_Value AssertEqual(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 2; - JSVM_Value args[2]; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); - - bool isStrictEquals = false; - JSVM_CALL(OH_JSVM_StrictEquals(env, args[0], args[1], &isStrictEquals)); - - if (isStrictEquals) { - OH_LOG_INFO(LOG_APP, "JSVM API TEST RESULT: PASS"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM API TEST RESULT: FAILED"); - } - return nullptr; -} - -static int fromOHStringValue(JSVM_Env &env, JSVM_Value &value, std::string &result) -{ - size_t size; - CHECK_RET(OH_JSVM_GetValueStringUtf8(env, value, nullptr, 0, &size)); - char resultStr[size + 1]; - CHECK_RET(OH_JSVM_GetValueStringUtf8(env, value, resultStr, size + 1, &size)); - result = resultStr; - return 0; -} - -// 提供创建JSVM运行环境的对外接口并返回对应唯一ID -static int CreateJsCore(uint32_t *result) -{ - OH_LOG_INFO(LOG_APP, "JSVM CreateJsCore START"); - g_taskQueueMap[g_envtagNumber] = deque {}; - - if (g_aa == 0) { - JSVM_InitOptions init_options; - memset(&init_options, 0, sizeof(init_options)); - CHECK(OH_JSVM_Init(&init_options)); - g_aa++; - } - std::lock_guard lock_guard(g_envMapLock); - - // 虚拟机实例 - g_vmMap[g_envtagNumber] = new JSVM_VM; - JSVM_CreateVMOptions options; - JSVM_VMScope vmScope; - memset(&options, 0, sizeof(options)); - CHECK(OH_JSVM_CreateVM(&options, g_vmMap[g_envtagNumber])); - CHECK(OH_JSVM_OpenVMScope(*g_vmMap[g_envtagNumber], &vmScope)); - - // 新环境 - g_envMap[g_envtagNumber] = new JSVM_Env; - g_callBackStructMap[g_envtagNumber] = new JSVM_CallbackStruct[4]; - - // 注册用户提供的本地函数的回调函数指针和数据,通过JSVM-API暴露给js - constexpr int kLoopCount = 4; - for (int i = 0; i < kLoopCount; i++) { - g_callBackStructMap[g_envtagNumber][i].data = nullptr; - } - g_callBackStructMap[g_envtagNumber][0].callback = Consoleinfo; - g_callBackStructMap[g_envtagNumber][1].callback = Add; - g_callBackStructMap[g_envtagNumber][2].callback = AssertEqual; - g_callBackStructMap[g_envtagNumber][3].callback = CreatePromise; - JSVM_PropertyDescriptor descriptors[] = { - { "consoleinfo", NULL, &g_callBackStructMap[g_envtagNumber][0], NULL, NULL, NULL, JSVM_DEFAULT }, - { "add", NULL, &g_callBackStructMap[g_envtagNumber][1], NULL, NULL, NULL, JSVM_DEFAULT }, - { "assertEqual", NULL, &g_callBackStructMap[g_envtagNumber][2], NULL, NULL, NULL, JSVM_DEFAULT }, - { "createPromise", NULL, &g_callBackStructMap[g_envtagNumber][3], NULL, NULL, NULL, JSVM_DEFAULT }, - }; - CHECK(OH_JSVM_CreateEnv( - *g_vmMap[g_envtagNumber], sizeof(descriptors) / sizeof(descriptors[0]), descriptors, g_envMap[g_envtagNumber])); - CHECK(OH_JSVM_CloseVMScope(*g_vmMap[g_envtagNumber], vmScope)); - - OH_LOG_INFO(LOG_APP, "JSVM CreateJsCore END"); - *result = g_envtagNumber; - g_envtagNumber++; - return 0; -} - -// 对外提供释放JSVM环境接口,通过envId释放对应环境 -static int ReleaseJsCore(uint32_t coreEnvId) -{ - OH_LOG_INFO(LOG_APP, "JSVM ReleaseJsCore START"); - CHECK_COND(g_envMap.count(coreEnvId) != 0 && g_envMap[coreEnvId] != nullptr); - - std::lock_guard lock_guard(g_envMapLock); - - CHECK(OH_JSVM_DestroyEnv(*g_envMap[coreEnvId])); - g_envMap[coreEnvId] = nullptr; - g_envMap.erase(coreEnvId); - CHECK(OH_JSVM_DestroyVM(*g_vmMap[coreEnvId])); - g_vmMap[coreEnvId] = nullptr; - g_vmMap.erase(coreEnvId); - delete[] g_callBackStructMap[coreEnvId]; - g_callBackStructMap[coreEnvId] = nullptr; - g_callBackStructMap.erase(coreEnvId); - g_taskQueueMap.erase(coreEnvId); - - OH_LOG_INFO(LOG_APP, "JSVM ReleaseJsCore END"); - return 0; -} - -static std::mutex g_mutexLock; -// 对外提供执行JS代码接口,通过coreID在对应的JSVN环境中执行JS代码 -static int EvaluateJS(uint32_t envId, const char *source, std::string &res) -{ - OH_LOG_INFO(LOG_APP, "JSVM EvaluateJS START"); - - CHECK_COND(g_envMap.count(envId) != 0 && g_envMap[envId] != nullptr); - - JSVM_Env env = *g_envMap[envId]; - JSVM_VM vm = *g_vmMap[envId]; - JSVM_VMScope vmScope; - JSVM_EnvScope envScope; - JSVM_HandleScope handleScope; - JSVM_Value result; - - std::lock_guard lock_guard(g_mutexLock); - { - // 创建JSVM环境 - CHECK_RET(OH_JSVM_OpenVMScope(vm, &vmScope)); - CHECK_RET(OH_JSVM_OpenEnvScope(*g_envMap[envId], &envScope)); - CHECK_RET(OH_JSVM_OpenHandleScope(*g_envMap[envId], &handleScope)); - - // 通过script调用测试函数 - JSVM_Script script; - JSVM_Value jsSrc; - CHECK_RET(OH_JSVM_CreateStringUtf8(env, source, 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_ValueType type; - CHECK_RET(OH_JSVM_Typeof(env, result, &type)); - OH_LOG_INFO(LOG_APP, "JSVM API TEST type: %{public}d", type); - // Execute tasks in the current env event queue - while (!g_taskQueueMap[envId].empty()) { - auto task = g_taskQueueMap[envId].front(); - g_taskQueueMap[envId].pop_front(); - task->Run(); - delete task; - } - - if (type == JSVM_STRING) { - CHECK_COND(fromOHStringValue(env, result, res) != -1); - } else if (type == JSVM_BOOLEAN) { - bool ret = false; - CHECK_RET(OH_JSVM_GetValueBool(env, result, &ret)); - ret ? res = "true" : res = "false"; - } else if (type == JSVM_NUMBER) { - int32_t num; - CHECK_RET(OH_JSVM_GetValueInt32(env, result, &num)); - res = std::to_string(num); - } else if (type == JSVM_OBJECT) { - JSVM_Value objResult; - CHECK_RET(OH_JSVM_JsonStringify(env, result, &objResult)); - CHECK_COND(fromOHStringValue(env, objResult, res) != -1); - } - } - { - bool aal = false; - CHECK_RET(OH_JSVM_PumpMessageLoop(*g_vmMap[envId], &aal)); - CHECK_RET(OH_JSVM_PerformMicrotaskCheckpoint(*g_vmMap[envId])); - CHECK_RET(OH_JSVM_CloseHandleScope(*g_envMap[envId], handleScope)); - CHECK_RET(OH_JSVM_CloseEnvScope(*g_envMap[envId], envScope)); - CHECK_RET(OH_JSVM_CloseVMScope(*g_vmMap[envId], vmScope)); - } - OH_LOG_INFO(LOG_APP, "JSVM EvaluateJS END"); - return 0; -} - -static int32_t TestJSVM() -{ - const char source1[] = "{\ - let a = \"hello World\";\ - consoleinfo(a);\ - const mPromise = createPromise();\ - mPromise.then((result) => {\ - assertEqual(result, 0);\ - });\ - a;\ - };"; - - const char source2[] = "{\ - let a = \"second hello\";\ - consoleinfo(a);\ - let b = add(99, 1);\ - assertEqual(100, b);\ - assertEqual(add(99, 1), 100);\ - createPromise().then((result) => {\ - assertEqual(result, 1);\ - });\ - a;\ - };"; - - // 创建首个运行环境,并绑定TS回调 - uint32_t coreId1; - CHECK_COND(CreateJsCore(&coreId1) == 0); - OH_LOG_INFO(LOG_APP, "TEST coreId: %{public}d", coreId1); - // 在首个运行环境中执行JS代码 - std::string result1; - CHECK_COND(EvaluateJS(coreId1, source1, result1) == 0); - OH_LOG_INFO(LOG_APP, "TEST evaluateJS: %{public}s", result1.c_str()); - - // 创建第二个运行环境,并绑定TS回调 - uint32_t coreId2; - CHECK_COND(CreateJsCore(&coreId2) == 0); - OH_LOG_INFO(LOG_APP, "TEST coreId: %{public}d", coreId2); - // 在第二个运行环境中执行JS代码 - std::string result2; - CHECK_COND(EvaluateJS(coreId2, source2, result2) == 0); - OH_LOG_INFO(LOG_APP, "TEST evaluateJS: %{public}s", result2.c_str()); - - // 释放首个运行环境 - CHECK_COND(ReleaseJsCore(coreId1) == 0); - // 释放第二个运行环境 - CHECK_COND(ReleaseJsCore(coreId2) == 0); - OH_LOG_INFO(LOG_APP, "Test NAPI end"); - - return 0; -} -// [End runtime_task] - -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 = "runtimetask", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/pages/Index.ets deleted file mode 100755 index bf5a1eb34d17257d9b85626e416fc0ccaf013755..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libruntimetask.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/JsvmDebug/runtimetask/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/module.json5 deleted file mode 100755 index 1c36e137158a8da3a583e20711164b97beecb6e7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/module.json5 +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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": "runtimetask", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "RuntimetaskAbility", - "deviceTypes": [ - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "RuntimetaskAbility", - "srcEntry": "./ets/runtimetaskability/RuntimetaskAbility.ets", - "description": "$string:RuntimetaskAbility_desc", - "icon": "$media:layered_image", - "label": "$string:RuntimetaskAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/module.json5 deleted file mode 100755 index 245968a2c3ec5b7f1f34f8b9dd747528fe6ea237..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/runtimetask/src/ohosTest/module.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "runtimetask_test", - "type": "feature", - "deviceTypes": [ - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmDebug/snapshot/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/hvigorfile.ts deleted file mode 100755 index 080a923d0ff229bd57ef4afb24b2c2faeb029819..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmDebug/snapshot/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmDebug/snapshot/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/oh-package.json5 deleted file mode 100755 index b6f16febec32423a5dc783a0edd81a0f41aa096e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "snapshot", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libsnapshot.so": "file:./src/main/cpp/types/libsnapshot" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b0e6007926ad8a36e23160ff63832a636db9bf48..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmDebug) - -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) - -add_library(snapshot SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(snapshot PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/hello.cpp deleted file mode 100755 index 10bd63dab27a03f82cc7afbf4d120b7c98a7062f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/hello.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start heap_snapshot] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -#include -// [StartExclude heap_snapshot] -#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) -// [EndExclude heap_snapshot] - -using namespace std; - -// 待调优的JS代码。 -static string g_srcProf = R"JS( -function sleep(delay) { - var start = (new Date()).getTime(); - while ((new Date()).getTime() - start < delay) { - continue; - } -} - -function work3() { - sleep(300); -} - -function work2() { - work3(); - sleep(200); -} - -function work1() { - work2(); - sleep(100); -} - -work1(); -)JS"; - -// 数据输出流回调,用户自定义,处理返回的调优数据,此处以写入文件为例。 -static bool OutputStream(const char *data, int size, void *streamData) -{ - auto &os = *reinterpret_cast(streamData); - if (data) { - os.write(data, size); - } else { - os.close(); - } - return true; -} - -static JSVM_CpuProfiler ProfilingBegin(JSVM_VM vm) -{ - // 文件输出流,保存调优数据,/data/storage/el2/base/files为沙箱路径。以包名为com.example.helloworld为例。 - // 实际文件会保存到/data/app/el2/100/base/com.example.helloworld/files/heap-snapshot-begin.heapsnapshot。 - ofstream heapSnapshot("/data/storage/el2/base/files/heap-snapshot-begin.heapsnapshot", - ios::out | ios::binary | ios::trunc); - // 执行JS前获取一次Heap Snapshot数据。 - OH_JSVM_TakeHeapSnapshot(vm, OutputStream, &heapSnapshot); - JSVM_CpuProfiler cpuProfiler; - // 开启CPU Profiler。 - OH_JSVM_StartCpuProfiler(vm, &cpuProfiler); - return cpuProfiler; -} - -// 关闭调优数据采集工具 -static void ProfilingEnd(JSVM_VM vm, JSVM_CpuProfiler cpuProfiler) -{ - // 文件输出流,保存调优数据,/data/storage/el2/base/files为沙箱路径。以包名为com.example.helloworld为例。 - // 实际文件会保存到/data/app/el2/100/base/com.example.helloworld/files/cpu-profile.cpuprofile。 - ofstream cpuProfile("/data/storage/el2/base/files/cpu-profile.cpuprofile", - ios::out | ios::binary | ios::trunc); - // 关闭CPU Profiler,获取数据。 - OH_JSVM_StopCpuProfiler(vm, cpuProfiler, OutputStream, &cpuProfile); - ofstream heapSnapshot("/data/storage/el2/base/files/heap-snapshot-end.heapsnapshot", - ios::out | ios::binary | ios::trunc); - // 执行JS后再获取一次Heap Snapshot数据,与执行前数据作对比,以分析内存问题或者进行内存调优。 - OH_JSVM_TakeHeapSnapshot(vm, OutputStream, &heapSnapshot); -} - -static JSVM_Value RunScriptWithStatistics(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_VM vm; - OH_JSVM_GetVM(env, &vm); - - // 开始调优。 - auto cpuProfiler = ProfilingBegin(vm); - - JSVM_HandleScope handleScope; - OH_JSVM_OpenHandleScope(env, &handleScope); - - JSVM_Value jsSrc; - OH_JSVM_CreateStringUtf8(env, g_srcProf.c_str(), g_srcProf.size(), &jsSrc); - - JSVM_Script script; - OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script); - - JSVM_Value result; - // 执行JS代码。 - OH_JSVM_RunScript(env, script, &result); - - OH_JSVM_CloseHandleScope(env, handleScope); - - // 结束调优。 - ProfilingEnd(vm, cpuProfiler); - return nullptr; -} -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = RunScriptWithStatistics}, -}; -static JSVM_CallbackStruct *method = param; -// runScriptWithStatistics方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"runScriptWithStatistics", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = R"JS(runScriptWithStatistics();)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; -} -// [End heap_snapshot] - -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 = "snapshot", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/oh-package.json5 deleted file mode 100755 index bfedb5325ad8f948cd894fd1b73d88830a33b21b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/cpp/types/libsnapshot/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libsnapshot.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/JsvmDebug/snapshot/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/ets/pages/Index.ets deleted file mode 100755 index 2f98bef4cb9d61fbf7b9e49c56052873deebd521..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libsnapshot.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmDebug/snapshot/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/module.json5 deleted file mode 100755 index 5c1459e55a7c4316db7e0231803bdaccdb57faf9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "snapshot", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "SnapshotAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "SnapshotAbility", - "srcEntry": "./ets/snapshotability/SnapshotAbility.ets", - "description": "$string:SnapshotAbility_desc", - "icon": "$media:layered_image", - "label": "$string:SnapshotAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/string.json deleted file mode 100755 index 64866d03ccea8940df2907e5e6bbbeec817e2832..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "SnapshotAbility_desc", - "value": "description" - }, - { - "name": "SnapshotAbility_label", - "value": "JsvmDebug" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 95bb1ec3a69ee13790837e61419a9a1eed1508ec..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testSnapshot', 0, async (done: Function) => { - console.log('uitest: TestSnapshot begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'SnapshotAbility' - } - 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('SnapshotAbility'); - - 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: TestSnapshot end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmDebug/snapshot/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/module.json5 deleted file mode 100755 index 31599f4aa8e7c22381aab5a0501d62b1a21d3082..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmDebug/snapshot/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "snapshot_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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 deleted file mode 100755 index 4c34bddd1e355d98f66f53c9c2f1f047af99260b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 deleted file mode 100755 index 7b8d90ea32181dd4ead1ab4701d69de977e8cfc8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmProcess" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/README.md deleted file mode 100755 index 3b5babcca6f31ae62883b2cc11c18512a20e7643..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# 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) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-------------------------------------------------------------: | :-------------------------------------------------------------: | -| | | - -### 使用说明 - -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 deleted file mode 100755 index a21d5afe8864439233629ea7ea6ae9958d18ee60..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/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 deleted file mode 100755 index d27072efd782a98fdc3b4456f19249ba19c31bbb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/build-profile.json5 +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 deleted file mode 100755 index a481b73ee5b5ebe0a1bf336940d8c7efc697ae54..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100755 index 8abb3222db5808546c56d68083d4892f90e54244..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/hello.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_process] -#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); } -// [End oh_jsvm_process] 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 deleted file mode 100755 index 0368d3ca4666d9c8a3243c12d5cec2d801537e4e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start export_native] -export const runTest: () => void; -// [End export_native] \ 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 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 deleted file mode 100755 index 2404bc1f465b985fb4bf9c0bb9a2df93f0326bbe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start call_native_cpp] -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%') - } -} -// [End call_native_cpp] diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "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 deleted file mode 100755 index 7ea79fc923027d7102b96eca844f27ca2ce38471..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "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/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "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/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "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 deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "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 deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "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 deleted file mode 100755 index 7ea79fc923027d7102b96eca844f27ca2ce38471..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "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 deleted file mode 100755 index 16fcf0c75f86f523fbebae253952ed225edaacb7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/main/resources/zh_CN/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "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 deleted file mode 100755 index b0690e03efc28c20291353de66f77eb8c599b838..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 deleted file mode 100755 index a5e25bbf8717ad8578daa9c5f290e636c210301f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmProcess/ohosTest.md +++ /dev/null @@ -1,8 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutArray/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/app.json5 deleted file mode 100755 index dbc4b79b126e02b5ff273906780e88006b686748..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutarray", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/element/string.json deleted file mode 100755 index d832880742710e86023ca2b1469cb75b8d21eabe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutArray" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/README.md deleted file mode 100755 index 5a5a98bfc284f5cfc015e74e2d7500454c975321..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/README.md +++ /dev/null @@ -1,333 +0,0 @@ -# ArkTS使用JSVM-API接口进行array相关开发 - -### 介绍 - -使用 JSVM-API 接口进行数组(array)相关开发时,调用相关接口可以在 JSVM 模块中直接操作和处理 JavaScript 中的数组。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行array相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-array.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------------: | :----------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createarray/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createarraywithlength/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createdataview/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createtypedarray/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -deleteelement/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getarraylength/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getdataviewinfo/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getelement/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -gettypedarrayinfo/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -haselement/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -isarray/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -isdataview/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -istypedarray/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -setelement/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutArray > .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/JsvmUsageGuide/JsvmAboutArray/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/build-profile.json5 deleted file mode 100755 index 37ccc6996072997865e300d2432a11314b82bb24..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/build-profile.json5 +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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": "createarray", - "srcPath": "./createarray", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createarraywithlength", - "srcPath": "./createarraywithlength", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createtypedarray", - "srcPath": "./createtypedarray", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createdataview", - "srcPath": "./createdataview", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getarraylength", - "srcPath": "./getarraylength", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getdataviewinfo", - "srcPath": "./getdataviewinfo", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "deleteelement", - "srcPath": "./deleteelement", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getelement", - "srcPath": "./getelement", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "gettypedarrayinfo", - "srcPath": "./gettypedarrayinfo", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "haselement", - "srcPath": "./haselement", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "isarray", - "srcPath": "./isarray", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "isdataview", - "srcPath": "./isdataview", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "istypedarray", - "srcPath": "./istypedarray", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "setelement", - "srcPath": "./setelement", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarray/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/createarray/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarray/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/createarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/oh-package.json5 deleted file mode 100755 index 63c8d0c03a3a76c173fca18401e033301b3e3799..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createarray", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatearray.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 0d5cbba172b61d3cbeece3645462f856f0d3e2cc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createarray SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/hello.cpp deleted file mode 100755 index 41151a4fc1727538fb34f9c0098e6479e440202e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/hello.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_array] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_array] -#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) -// [EndExclude oh_jsvm_create_array] - -// CreateArray注册回调 -static int g_diffValueFive = 5; -// OH_JSVM_CreateArray的样例方法 -static JSVM_Value CreateArray(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 创建一个空数组 - JSVM_Value array = nullptr; - JSVM_Status status = OH_JSVM_CreateArray(env, &array); - // 对创建的数组进行赋值 - for (int i = 0; i < g_diffValueFive; i++) { - JSVM_Value element; - OH_JSVM_CreateInt32(env, i, &element); - OH_JSVM_SetElement(env, array, i, element); - } - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateArray fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateArray success"); - } - return array; -} -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateArray}, -}; -static JSVM_CallbackStruct *method = param; -// CreateArray方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createArray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - function testCreateArray() { - return createArray(); - } - testCreateArray(); -)JS"; -// [End oh_jsvm_create_array] - -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 = "createarray", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index d7e437a094293e33a5651b2312b145e451c2540f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatearray.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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/pages/Index.ets deleted file mode 100755 index 9c5aecdf2b3a1acbd7848835615cc8149bdd5aee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatearray.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/module.json5 deleted file mode 100755 index 346442d2174c6f1b5e5f6d6b55d8a281c2f7a9ac..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "createarray", - "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/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/string.json deleted file mode 100755 index 3d8bf574364ab41dac497568775ba44692fb216f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index d3c1e1ff83f34f3c5380d52640402c16a390a8d7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateArray', 0, async (done: Function) => { - console.log('uitest: TestCreateArray 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: TestCreateArray end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/module.json5 deleted file mode 100755 index d488a0eabcc08f7130607472faf7188425d69764..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarray/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createarray_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/oh-package.json5 deleted file mode 100755 index cc11ce7222e53e6c1094250bddad924f35c68f80..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createarraywithlength", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatearraywithlength.so": "file:./src/main/cpp/types/libcreatearraywithlength" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 47e014b43e16f06dd9ce1d0683efe02ba0aa5165..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createarraywithlength SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createarraywithlength PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/hello.cpp deleted file mode 100755 index 9dcc8c5817482258403f80b4c355e34ae90e1ae3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/hello.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_array_with_length] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_array_with_length] -#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) -// [EndExclude oh_jsvm_create_array_with_length] - -// OH_JSVM_CreateArrayWithLength的样例方法 -static JSVM_Value CreateArrayWithLength(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - JSVM_Value result = nullptr; - // 解析传递的参数OH_JSVM_GetCbInfo - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - // 获取传递的数组长度 - int32_t length; - OH_JSVM_GetValueInt32(env, argv[0], &length); - // 使用OH_JSVM_CreateArrayWithLength创建传递固定长度的数组 - JSVM_Status status = OH_JSVM_CreateArrayWithLength(env, length, &result); - if (status == JSVM_OK) { - // 给创建的数组设置值 - for (int32_t i = 0; i < length; i++) { - JSVM_Value value; - OH_JSVM_CreateInt32(env, i, &value); - OH_JSVM_SetElement(env, result, i, value); - } - OH_LOG_INFO(LOG_APP, "JSVM CreateArrayWithLength success"); - } else { - OH_LOG_ERROR(LOG_APP, "JSVM CreateArrayWithLength fail"); - } - return result; -} -// CreateArrayWithLength注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateArrayWithLength}, -}; -static JSVM_CallbackStruct *method = param; -// CreateArrayWithLength方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createArrayWithLength", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -let num = 7; -function testCreateArrayWithLength(num) { - return createArrayWithLength(num); -} -testCreateArrayWithLength(num); -)JS"; -// [End oh_jsvm_create_array_with_length] - -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 = "createarraywithlength", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/oh-package.json5 deleted file mode 100755 index c1f86fcff02c561516e5e9049b3902a2b9ce64b1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/cpp/types/libcreatearraywithlength/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatearraywithlength.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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/pages/Index.ets deleted file mode 100755 index c676a7579d053cef6951c6c9b8380fff2e672fdf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatearraywithlength.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(20) - .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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/module.json5 deleted file mode 100755 index cefadbebfd78a3620a5aa15d9f6bac0da3e5c7d6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createarraywithlength", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatearraywithlengthAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatearraywithlengthAbility", - "srcEntry": "./ets/createarraywithlengthability/CreatearraywithlengthAbility.ets", - "description": "$string:CreatearraywithlengthAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatearraywithlengthAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/string.json deleted file mode 100755 index 9e620f662592451b24eb7396b46cffe9066b3100..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatearraywithlengthAbility_desc", - "value": "description" - }, - { - "name": "CreatearraywithlengthAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index a049f3c66a848585fb0dbbe23cc5e0408e6be05a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateArrayWithLength', 0, async (done: Function) => { - console.log('uitest: TestCreateArrayWithLength begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatearraywithlengthAbility' - } - 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('CreatearraywithlengthAbility'); - - 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: TestCreateArrayWithLength end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/module.json5 deleted file mode 100755 index 04a223f6f4a47858e289e5acb196a60d59493df0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createarraywithlength/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createarraywithlength_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/createdataview/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createdataview/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/createdataview/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/oh-package.json5 deleted file mode 100755 index 7f4bd7b0930d51e8525093369dbc3eb339fe5e8f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createdataview", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatedataview.so": "file:./src/main/cpp/types/libcreatedataview" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 75bce4b0ca191ebba035a5a7506d2f2715a03541..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createdataview SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createdataview PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/hello.cpp deleted file mode 100755 index a09b5c67b6134477e971b157d04e9c826ea09446..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/hello.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_dataview] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_dataview] -#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) - -static int g_diffValueFour = 4; -static int g_diffValueTwelve = 12; -// [EndExclude oh_jsvm_create_dataview] - -// OH_JSVM_CreateDataview的样例方法 -static JSVM_Value CreateDataView(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - JSVM_Value arrayBuffer = nullptr; - JSVM_Value result = nullptr; - // DataView的字节长度 - size_t byteLength = g_diffValueFour; - // 字节偏移量 - size_t byteOffset = g_diffValueTwelve; - // 获取回调函数的参数信息 - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 将参数转换为对象类型 - OH_JSVM_CoerceToObject(env, args[0], &arrayBuffer); - // 创建一个数据视图对象,并指定字节长度和字节偏移量 - JSVM_Status status = OH_JSVM_CreateDataview(env, byteLength, arrayBuffer, byteOffset, &result); - // 获取DataView的指针和长度信息 - uint8_t *data = nullptr; - size_t length = 0; - // 为DataView赋值 - for (size_t i = 0; i < length; i++) { - data[i] = static_cast(i + 1); - } - int32_t infoType; - OH_JSVM_GetValueInt32(env, args[1], &infoType); - size_t returnLength; - JSVM_Value returnArrayBuffer = nullptr; - size_t returnOffset; - enum InfoType { BYTE_LENGTHE, ARRAY_BUFFERE, BYTE_OFFSET }; - // 获取dataview信息 - OH_JSVM_GetDataviewInfo(env, result, &returnLength, (void **)&data, &returnArrayBuffer, &returnOffset); - JSVM_Value returnResult = nullptr; - switch (infoType) { - case BYTE_LENGTHE: - JSVM_Value len; - OH_JSVM_CreateInt32(env, returnLength, &len); - returnResult = len; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateDataView fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateDataView success, returnLength: %{public}d", returnLength); - } - break; - case ARRAY_BUFFERE: - bool isArraybuffer; - OH_JSVM_IsArraybuffer(env, returnArrayBuffer, &isArraybuffer); - JSVM_Value isArray; - OH_JSVM_GetBoolean(env, isArraybuffer, &isArray); - returnResult = isArray; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateDataView fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateDataView success, isArraybuffer: %{public}d", isArraybuffer); - } - break; - case BYTE_OFFSET: - JSVM_Value offset; - OH_JSVM_CreateInt32(env, returnOffset, &offset); - returnResult = offset; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateDataView fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateDataView success, returnOffset: %{public}d", returnOffset); - } - break; - default: - break; - } - return returnResult; -} -// CreateDataView注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateDataView}, -}; -static JSVM_CallbackStruct *method = param; -// CreateDataView方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createDataView", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let BYTE_LENGTH = 0; - createDataView(new ArrayBuffer(16), BYTE_LENGTH); - let IS_ARRAYBUFFER = 1; - createDataView(new ArrayBuffer(16), IS_ARRAYBUFFER); - let BYTE_OFFSET = 2; - createDataView(new ArrayBuffer(16), BYTE_OFFSET); -)JS"; -// [End oh_jsvm_create_dataview] - -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 = "createdataview", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/oh-package.json5 deleted file mode 100755 index 9653374a74d9e0120477443519e557e0f44bef00..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/cpp/types/libcreatedataview/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatedataview.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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/pages/Index.ets deleted file mode 100755 index f5ffe06ef0d38bc84b39bef7af1ce0aeef566974..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatedataview.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/module.json5 deleted file mode 100755 index cba8ebfc170c0b3b0b930afe49fef8c4102dff1a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createdataview", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatedataviewAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatedataviewAbility", - "srcEntry": "./ets/createdataviewability/CreatedataviewAbility.ets", - "description": "$string:CreatedataviewAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatedataviewAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/string.json deleted file mode 100755 index 1428955362c2132011395f7d0504f93e3a5874ed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatedataviewAbility_desc", - "value": "description" - }, - { - "name": "CreatedataviewAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 3e65b7fc1310bd80f34a8e0fb0a645dfe62f828d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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('testCreateDataview', 0, async (done: Function) => { - console.log('uitest: TestCreateDataview begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatedataviewAbility' - } - 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('CreatedataviewAbility'); - - 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: TestCreateDataview end'); - done(); - }) - }) -} - - diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/module.json5 deleted file mode 100755 index 981100fb5ad30479139d3dc59aca7a9cac8a3caa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createdataview/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createdataview_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/oh-package.json5 deleted file mode 100755 index cedcd93b5539b622308f020cc1eef2fe4f60e808..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createtypedarray", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatetypedarray.so": "file:./src/main/cpp/types/libcreatetypedarray" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 8dc6f9cca71538001e8b22cfeaf6c95c5a92d9c4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createtypedarray SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createtypedarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/hello.cpp deleted file mode 100755 index 0600c70a8b2d65608f65964c6ce6194343c9119a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/hello.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_typedarray] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_typedarray] -#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) -// [EndExclude oh_jsvm_create_typedarray] - -// OH_JSVM_CreateTypedarray的样例方法 -static int g_diffValueThree = 3; -static JSVM_Value CreateTypedArray(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - int32_t typeNum; - OH_JSVM_GetValueInt32(env, args[0], &typeNum); - JSVM_TypedarrayType arrayType; - // 用于存储每个元素的大小 - size_t elementSize = 0; - // 转换为JSVM_TypedarrayType类型 - arrayType = static_cast(typeNum); - switch (typeNum) { - case JSVM_INT8_ARRAY: - case JSVM_UINT8_ARRAY: - case JSVM_UINT8_CLAMPED_ARRAY: - elementSize = sizeof(int8_t); - break; - case JSVM_INT16_ARRAY: - case JSVM_UINT16_ARRAY: - elementSize = sizeof(int16_t); - break; - case JSVM_INT32_ARRAY: - case JSVM_UINT32_ARRAY: - elementSize = sizeof(int32_t); - break; - case JSVM_FLOAT32_ARRAY: - elementSize = sizeof(float); - break; - case JSVM_FLOAT64_ARRAY: - elementSize = sizeof(double); - break; - case JSVM_BIGINT64_ARRAY: - case JSVM_BIGUINT64_ARRAY: - elementSize = sizeof(int64_t); - break; - default: - // 默认创建JSVM_INT8_ARRAY类型 - arrayType = JSVM_INT8_ARRAY; - elementSize = sizeof(int8_t); - break; - } - size_t length = g_diffValueThree; - JSVM_Value arrayBuffer = nullptr; - JSVM_Value typedArray = nullptr; - void *data; - // 创建一个ArrayBuffer - OH_JSVM_CreateArraybuffer(env, length * elementSize, (void **)&data, &arrayBuffer); - // 根据给定类型创建TypedArray - JSVM_Status status = OH_JSVM_CreateTypedarray(env, arrayType, length, arrayBuffer, 0, &typedArray); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateTypedArray fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateTypedArray success"); - } - return typedArray; -} -// CreateTypedArray注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateTypedArray}, -}; -static JSVM_CallbackStruct *method = param; -// CreateTypedArray方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createTypedArray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -const type = { - INT8_ARRAY: 0, - UINT8_ARRAY: 1, - UINT8_CLAMPED_ARRAY: 2, - INT16_ARRAY: 3, - UINT16_ARRAY: 4, - INT32_ARRAY: 5, - UINT32_ARRAY: 6, - FLOAT32_ARRAY: 7, - FLOAT64_ARRAY: 8, - BIGINT64_ARRAY: 9, - BIGUINT64_ARRAY: 10 -}; -createTypedArray(type.INT8_ARRAY); -createTypedArray(type.INT32_ARRAY); -)JS"; -// [End oh_jsvm_create_typedarray] - -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 = "createtypedarray", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/oh-package.json5 deleted file mode 100755 index 5f27f7ae47d7a588d954e0911c1f08ac789786f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/cpp/types/libcreatetypedarray/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatetypedarray.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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/pages/Index.ets deleted file mode 100755 index 79511e92a60c5c256aa4f9933bc7a6bd8b4a4e47..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatetypedarray.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/module.json5 deleted file mode 100755 index 85350c9d349dbe431b24ba765b2f18b85f0bca6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createtypedarray", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatetypedarrayAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatetypedarrayAbility", - "srcEntry": "./ets/createtypedarrayability/CreatetypedarrayAbility.ets", - "description": "$string:CreatetypedarrayAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatetypedarrayAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/string.json deleted file mode 100755 index 9789b9bc249ceb9c592c857f7d315cc926625fd6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatetypedarrayAbility_desc", - "value": "description" - }, - { - "name": "CreatetypedarrayAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 590ae770a2df6a343ce911dadfd44fbe91ba9fc0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateTypedarray', 0, async (done: Function) => { - console.log('uitest: TestCreateTypedarray begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatetypedarrayAbility' - } - 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('CreatetypedarrayAbility'); - - 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: TestCreateTypedarray end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/module.json5 deleted file mode 100755 index 2d81b3fa67b4f6dfbb905d0e6f24c4e301113817..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/createtypedarray/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createtypedarray_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/deleteelement/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/deleteelement/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/deleteelement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/oh-package.json5 deleted file mode 100755 index fbde5617062a2a8608ced22f6ed461463f4fd00b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "deleteelement", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libdeleteelement.so": "file:./src/main/cpp/types/libdeleteelement" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 5b12e77768b18a9af77d5b640b8eb509e32f5b1d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(deleteelement SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(deleteelement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/hello.cpp deleted file mode 100755 index 2e9f870a41cea44ee7b5a983d2ddfd08e68daf3e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/hello.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_delete_element] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_delete_element] -#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) -// [EndExclude oh_jsvm_delete_element] - -// OH_JSVM_DeleteElement的样例方法 -static JSVM_Value DeleteElement(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取要删除的元素的索引 - uint32_t index; - OH_JSVM_GetValueUint32(env, args[1], &index); - // 尝试删除请求索引位置的元素 - bool deleted = true; - JSVM_Status status = OH_JSVM_DeleteElement(env, args[0], index, &deleted); - // 将boolean结果转换为JSVM_Value并返回 - JSVM_Value result = nullptr; - OH_JSVM_GetBoolean(env, deleted, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM DeleteElement fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM DeleteElement: %{public}d", deleted); - } - return result; -} -// DeleteElement注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = DeleteElement}, -}; -static JSVM_CallbackStruct *method = param; -// DeleteElement方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"deleteElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -let arr = [10, 'hello', null, true]; -deleteElement(arr, 0); -)JS"; -// [End oh_jsvm_delete_element] - -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 = "deleteelement", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/oh-package.json5 deleted file mode 100755 index 0350dbeaf77df0b6c5690b4e50aeacbc73fe1202..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/cpp/types/libdeleteelement/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libdeleteelement.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/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/pages/Index.ets deleted file mode 100755 index 4247687554ab2c0380e67f98e188f13373b38998..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libdeleteelement.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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%') - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/module.json5 deleted file mode 100755 index e5267108248bb637e92634dfa27c94fe9f2fc2d7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "deleteelement", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "DeleteelementAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "DeleteelementAbility", - "srcEntry": "./ets/deleteelementability/DeleteelementAbility.ets", - "description": "$string:DeleteelementAbility_desc", - "icon": "$media:layered_image", - "label": "$string:DeleteelementAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/string.json deleted file mode 100755 index 8e16870578ec6a4dbbd7860ba8460832d83ced1e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "DeleteelementAbility_desc", - "value": "description" - }, - { - "name": "DeleteelementAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 25f031b236cc1a69c3563f1e1a964b7d982789f1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testDeleteElement', 0, async (done: Function) => { - console.log('uitest: TestDeleteElement begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'DeleteelementAbility' - } - 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('DeleteelementAbility'); - - 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: TestDeleteElement end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/module.json5 deleted file mode 100755 index 38e446602146c4406d1210529693a1aba85d4a05..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/deleteelement/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "deleteelement_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/getarraylength/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getarraylength/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/getarraylength/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/oh-package.json5 deleted file mode 100755 index afb639893990349b51e48cb6045c2246d4c2c4a8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getarraylength", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetarraylength.so": "file:./src/main/cpp/types/libgetarraylength" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 4c38cc2bfb64f2cf299251b7094dfdae1bfd88ee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(getarraylength SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getarraylength PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/hello.cpp deleted file mode 100755 index 812652590cd8e73cfa0a57a4a7a5f4f7f5aa2b5d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/hello.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_array_length] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_array_length] -#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) -// [EndExclude oh_jsvm_get_array_length] - -// OH_JSVM_GetArrayLength的样例方法 -static JSVM_Value GetArrayLength(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - JSVM_Value result = nullptr; - uint32_t length; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 检查参数是否为数组 - bool isArray = false; - OH_JSVM_IsArray(env, args[0], &isArray); - if (!isArray) { - OH_LOG_INFO(LOG_APP, "JSVM Argument must be an array"); - return nullptr; - } - OH_JSVM_GetArrayLength(env, args[0], &length); - // 创建返回值 - OH_JSVM_CreateInt32(env, length, &result); - OH_LOG_INFO(LOG_APP, "JSVM length: %{public}d", length); - return result; -} -// GetArrayLength注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetArrayLength}, -}; -static JSVM_CallbackStruct *method = param; -// GetArrayLength方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getArrayLength", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -let data = [0, 1, 2, 3, 4, 5]; -getArrayLength(data); -)JS"; -// [End oh_jsvm_get_array_length] - -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 = "getarraylength", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/oh-package.json5 deleted file mode 100755 index 9d5b523f8969dde7d886bdf68b75f893b6e901a6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/cpp/types/libgetarraylength/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetarraylength.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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/pages/Index.ets deleted file mode 100755 index d8feb8fc993bfc632f77b429edb0c2bd38f8358a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetarraylength.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/module.json5 deleted file mode 100755 index 4b52aff2465fbc5581e8638b8fde294b70ebcc25..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getarraylength", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetarraylengthAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetarraylengthAbility", - "srcEntry": "./ets/getarraylengthability/GetarraylengthAbility.ets", - "description": "$string:GetarraylengthAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetarraylengthAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/string.json deleted file mode 100755 index 88de37e1f0141f5005f5419c25737af465984a51..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetarraylengthAbility_desc", - "value": "description" - }, - { - "name": "GetarraylengthAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 957bffe8a8ee09009880fd6ad5c64e45f41ecd2b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetArrayLength', 0, async (done: Function) => { - console.log('uitest: TestGetArrayLength begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetarraylengthAbility' - } - 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('GetarraylengthAbility'); - - 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: TestGetArrayLength end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/module.json5 deleted file mode 100755 index 093ea392734b3693182069e56fa858499715620f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getarraylength/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getarraylength_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/oh-package.json5 deleted file mode 100755 index 240fac3600e8d65a9cbd6abb0e503b336d845b19..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getdataviewinfo", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetdataviewinfo.so": "file:./src/main/cpp/types/libgetdataviewinfo" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 7c755c188730fefe78eabac8f75a03f9310c86dd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getdataviewinfo SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getdataviewinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/hello.cpp deleted file mode 100755 index f33e8c4b21c3a57c981d9fe0567ae756635ff85a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/hello.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_dataview_info] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_dataview_info] -#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) -// [EndExclude oh_jsvm_get_dataview_info] - -// OH_JSVM_GetDataviewInfo的样例方法 -static JSVM_Value GetDataViewInfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取并解析参数,第一个参数为需要获得的信息的DataView类型数据,第二个参数为需要获得的信息类型的枚举值 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 将第二个参数转为int32类型的数字 - int32_t infoType; - OH_JSVM_GetValueInt32(env, args[1], &infoType); - size_t byteLength; - void *data; - JSVM_Value arrayBuffer = nullptr; - size_t byteOffset; - // 定义枚举类型与ArkTS侧枚举类型infoType顺序含义一致 - enum InfoTypeEnum { BYTE_LENGTHE, ARRAY_BUFFERE, BYTE_OFFSET }; - // 获取dataview信息 - JSVM_Status status = OH_JSVM_GetDataviewInfo(env, args[0], &byteLength, &data, &arrayBuffer, &byteOffset); - JSVM_Value result = nullptr; - switch (infoType) { - case BYTE_LENGTHE: - // 返回查询DataView的长度 - JSVM_Value len; - OH_JSVM_CreateInt32(env, byteLength, &len); - result = len; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetDataViewInfo fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetDataViewInfo success, byteLength: %{public}d", byteLength); - } - break; - case ARRAY_BUFFERE: - // 判断DataView的Info里的arraybuffer是否为arraybuffer - bool isArrayBuffer; - OH_JSVM_IsArraybuffer(env, arrayBuffer, &isArrayBuffer); - JSVM_Value isArray; - OH_JSVM_GetBoolean(env, isArrayBuffer, &isArray); - result = isArray; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetDataViewInfo fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetDataViewInfo success, isArrayBuffer: %{public}d", isArrayBuffer); - } - break; - case BYTE_OFFSET: - // 返回查询DataView的偏移量 - JSVM_Value offset; - OH_JSVM_CreateInt32(env, byteOffset, &offset); - result = offset; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetDataViewInfo fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetDataViewInfo success, byteOffset: %{public}d", byteOffset); - } - break; - default: - break; - } - return result; -} -// GetDataViewInfo注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetDataViewInfo}, -}; -static JSVM_CallbackStruct *method = param; -// GetDataViewInfo方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getDataViewInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -// bytelength -getDataViewInfo(new DataView(new Int8Array([2, 5]).buffer), 0); -// is arraybuffer -let data = 'a'; -let isarraybuffer = 1; -getDataViewInfo(data, isarraybuffer); -// is arraybuffer -data = new DataView(new Int8Array([2, 5, 3]).buffer); -isarraybuffer = 1; -getDataViewInfo(data, isarraybuffer); -// byte_offset -data = new DataView(new Int8Array([2, 5, 3]).buffer); -isarraybuffer = 2; -getDataViewInfo(data, isarraybuffer); -)JS"; -// [End oh_jsvm_get_dataview_info] - -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 = "getdataviewinfo", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/oh-package.json5 deleted file mode 100755 index 9a0cc23ab2695ca9790434ccf2613045d7de2e64..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/cpp/types/libgetdataviewinfo/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetdataviewinfo.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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/pages/Index.ets deleted file mode 100755 index 32d6f917d40376e5642198f538b946e1bce7efc5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetdataviewinfo.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/module.json5 deleted file mode 100755 index 001ee524e9667ef426e4ae8ce5d813f5f4eb3708..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getdataviewinfo", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetdataviewinfoAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetdataviewinfoAbility", - "srcEntry": "./ets/getdataviewinfoability/GetdataviewinfoAbility.ets", - "description": "$string:GetdataviewinfoAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetdataviewinfoAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/string.json deleted file mode 100755 index b619521694077ce29afdead29d58ffe1df63878a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetdataviewinfoAbility_desc", - "value": "description" - }, - { - "name": "GetdataviewinfoAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 1be7cecf360fae8c8d2415c3ed57c2b16bfd351d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetDataviewInfo', 0, async (done: Function) => { - console.log('uitest: TestGetDataviewInfo begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetdataviewinfoAbility' - } - 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('GetdataviewinfoAbility'); - - 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: TestGetDataviewInfo end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/module.json5 deleted file mode 100755 index c595eab4d425da594bf52dff487807541bed37ee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getdataviewinfo/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getdataviewinfo_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/getelement/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getelement/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/getelement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/oh-package.json5 deleted file mode 100755 index c1f8854b4ae2aad24300e2694eca896d2f04b70d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getelement", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetelement.so": "file:./src/main/cpp/types/libgetelement" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e464c31a379278896b4bebe5bc7e6485503b1276..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getelement SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getelement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/hello.cpp deleted file mode 100755 index 366f032f3493b11d5e22acd8f800440457f8b408..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/hello.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_element] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_element] -#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) -// [EndExclude oh_jsvm_get_element] - -// OH_JSVM_GetElement的样例方法 -static JSVM_Value GetElement(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取请求元素的索引值 - uint32_t index; - OH_JSVM_GetValueUint32(env, args[1], &index); - // 获取请求索引位置的元素值并存储在result中 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetElement(env, args[0], index, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetElement fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetElement success"); - } - return result; -} -// GetElement注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetElement}, -}; -static JSVM_CallbackStruct *method = param; -// GetElement方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -let arr = [10, 'hello', null, true]; -getElement(arr, 3); -)JS"; -// [End oh_jsvm_get_element] - -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 = "getelement", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/oh-package.json5 deleted file mode 100755 index 0e846c8c7b909da20eb414964174f3a3f1bc6059..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/cpp/types/libgetelement/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetelement.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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/pages/Index.ets deleted file mode 100755 index 187a0cf28e942dcd33f03935b1010008cfb7cc1d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetelement.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/module.json5 deleted file mode 100755 index 657a5d71ff043eafdbc24758b3bdfa93d4c5b67a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "getelement", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetelementAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetelementAbility", - "srcEntry": "./ets/getelementability/GetelementAbility.ets", - "description": "$string:GetelementAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetelementAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/string.json deleted file mode 100755 index b3ad9820da49caeded515c047435dab35168bd9d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetelementAbility_desc", - "value": "description" - }, - { - "name": "GetelementAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 4619cbc4aa77847af88bef09bf00bf3ccdcc722d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetElement', 0, async (done: Function) => { - console.log('uitest: TestGetElement begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetelementAbility' - } - 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('GetelementAbility'); - - 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: TestGetElement end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/module.json5 deleted file mode 100755 index ab78ec4839f774c638bea2dcf6a5aa2d1bcafc8c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/getelement/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "getelement_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/oh-package.json5 deleted file mode 100755 index 09fce729c0ee830aadf955c7726fcc35ae0c9cee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "gettypedarrayinfo", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgettypedarrayinfo.so": "file:./src/main/cpp/types/libgettypedarrayinfo" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b393844fb4902f87d0f57736e8a7ca710b7658b3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(gettypedarrayinfo SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(gettypedarrayinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/hello.cpp deleted file mode 100755 index f1cf8ff32d12c1322a300a10519cbbef6a8046bb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/hello.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_typedarray_info] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_typedarray_info] -#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) -// [EndExclude oh_jsvm_get_typedarray_info] - -// OH_JSVM_GetTypedarrayInfo的样例方法 -static JSVM_Value GetTypedArrayInfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取并解析参数,第一个参数为需要获得的信息的TypedArray类型数据,第二个参数为需要获得的信息类型的枚举值 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - - // 将第二个参数转为int32类型便于比较 - int32_t infoTypeParam; - OH_JSVM_GetValueInt32(env, args[1], &infoTypeParam); - // 定义枚举类型与ArkTS侧枚举类型infoType顺序含义一致 - enum InfoType { INFO_TYPE, INFO_LENGTH, INFO_ARRAY_BUFFER, INFO_BYTE_OFFSET }; - void *data; - JSVM_TypedarrayType type; - size_t byteOffset; - size_t length; - JSVM_Value arrayBuffer = nullptr; - // 调用接口OH_JSVM_GetTypedarrayInfo获得TypedArray类型数据的信息 - JSVM_Status status = OH_JSVM_GetTypedarrayInfo(env, args[0], &type, &length, &data, &arrayBuffer, &byteOffset); - JSVM_Value result = nullptr; - // 根据属性名,返回TypedArray对应的属性值 - switch (infoTypeParam) { - case INFO_TYPE: - // 如果传入的参数是int8类型的TypedArray数据,它的类型(type)为JSVM_INT8_ARRAY - JSVM_Value int8_type; - OH_JSVM_GetBoolean(env, type == JSVM_INT8_ARRAY, &int8_type); - result = int8_type; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); - } else { - OH_LOG_INFO( - LOG_APP, "JSVM GetTypedArrayInfo success, JSVM_INT8_ARRAY: %{public}d", type == JSVM_INT8_ARRAY); - } - break; - case INFO_LENGTH: - // TypedArray中的元素数 - JSVM_Value jsvmLength; - OH_JSVM_CreateInt32(env, length, &jsvmLength); - result = jsvmLength; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetTypedArrayInfo success, length: %{public}d", length); - } - break; - case INFO_BYTE_OFFSET: - // TypedArray数组的第一个元素所在的基础原生数组中的字节偏移量 - JSVM_Value jsvmOffset; - OH_JSVM_CreateInt32(env, byteOffset, &jsvmOffset); - result = jsvmOffset; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetTypedArrayInfo success, byteOffset: %{public}d", byteOffset); - } - break; - case INFO_ARRAY_BUFFER: - // TypedArray下的ArrayBuffer - bool isArrayBuffer; - OH_JSVM_IsArraybuffer(env, arrayBuffer, &isArrayBuffer); - JSVM_Value isArray; - OH_JSVM_GetBoolean(env, isArrayBuffer, &isArray); - result = isArray; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetTypedArrayInfo fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetTypedArrayInfo success, isArrayBuffer: %{public}d", isArrayBuffer); - } - break; - default: - break; - } - return result; -} -// GetTypedArrayInfo注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetTypedArrayInfo}, -}; -static JSVM_CallbackStruct *method = param; -// GetTypedArrayInfo方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getTypedArrayInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -// is JSVM_INT8_ARRAY -getTypedArrayInfo(new Int8Array(3), 0); -// length -getTypedArrayInfo(new Int8Array(5), 1); -// is_arraybuffer -getTypedArrayInfo(new Int8Array(5), 2); -// byteoffset -getTypedArrayInfo(new Int8Array(1), 3); -)JS"; -// [End oh_jsvm_get_typedarray_info] - -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 = "gettypedarrayinfo", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/oh-package.json5 deleted file mode 100755 index a2a823c548f89e28471a6c655cb7958a1aee06f3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/cpp/types/libgettypedarrayinfo/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgettypedarrayinfo.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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/pages/Index.ets deleted file mode 100755 index ee70840b9e6d7a6ce655cf40af6a66da10b02b47..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgettypedarrayinfo.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/module.json5 deleted file mode 100755 index 954fdd839038f848693da1e68780b6ab9d7c6002..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "gettypedarrayinfo", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GettypedarrayinfoAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GettypedarrayinfoAbility", - "srcEntry": "./ets/gettypedarrayinfoability/GettypedarrayinfoAbility.ets", - "description": "$string:GettypedarrayinfoAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GettypedarrayinfoAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/string.json deleted file mode 100755 index b839e5008f839e6c41c82114eb005bfb14749d82..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GettypedarrayinfoAbility_desc", - "value": "description" - }, - { - "name": "GettypedarrayinfoAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 1a47c5d0c6554b762d0c75907a4772e6dd3bcd20..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetTypedarrayInfo', 0, async (done: Function) => { - console.log('uitest: TestGetTypedarrayInfo begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GettypedarrayinfoAbility' - } - 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('GettypedarrayinfoAbility'); - - 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: TestGetTypedarrayInfo end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/module.json5 deleted file mode 100755 index 7e4bee2e6953d09003ccfdf4a5a7fefc7a430829..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/gettypedarrayinfo/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "gettypedarrayinfo_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/haselement/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/haselement/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/haselement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/oh-package.json5 deleted file mode 100755 index 91f1cc6de8f7db32a271be64bfe9d762729acc13..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "haselement", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libhaselement.so": "file:./src/main/cpp/types/libhaselement" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e1d5fe2b8d0f2ce740ff2de0f0943b9e07a0a8e4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(haselement SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(haselement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/hello.cpp deleted file mode 100755 index 4370926d0cf47706a10539fa33ba9eb89f25a41c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/hello.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_has_element] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_has_element] -#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) -// [EndExclude oh_jsvm_has_element] - -// OH_JSVM_HasElement的样例方法 -static JSVM_Value HasElement(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取要判断的元素的索引 - uint32_t index; - OH_JSVM_GetValueUint32(env, args[1], &index); - // 判断指定索引位置的元素是否存在 - bool hasElement = true; - JSVM_Status status = OH_JSVM_HasElement(env, args[0], index, &hasElement); - // 将boolean结果转换为JSVM_Value并返回 - JSVM_Value result = nullptr; - OH_JSVM_GetBoolean(env, hasElement, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM hasElement fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM hasElement: %{public}d", hasElement); - } - return result; -} -// HasElement注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = HasElement}, -}; -static JSVM_CallbackStruct *method = param; -// HasElement方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"hasElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *srcCallNative = R"JS( -let arr = [10, 'hello', null, true]; -hasElement(arr, 0); -hasElement(arr, 4); -)JS"; -// [End oh_jsvm_has_element] - -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, srcCallNative, 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 = "haselement", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/oh-package.json5 deleted file mode 100755 index bd4584f9ef44a707fde239b18e53fb938a5c5ee0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/cpp/types/libhaselement/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libhaselement.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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/pages/Index.ets deleted file mode 100755 index 071a12fc4f8d4f7a2d4b452e528356926f2b834c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libhaselement.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/module.json5 deleted file mode 100755 index e2c9317fe1f484f33fcf7d6eac1e9ac7fc4845e2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "haselement", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "HaselementAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "HaselementAbility", - "srcEntry": "./ets/haselementability/HaselementAbility.ets", - "description": "$string:HaselementAbility_desc", - "icon": "$media:layered_image", - "label": "$string:HaselementAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/string.json deleted file mode 100755 index 246a5cc3b975e995bff51a35138f4b1450dc600d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "HaselementAbility_desc", - "value": "description" - }, - { - "name": "HaselementAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 6912c5387c57b325d7139cf7d335c9fe5a410c51..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testHasElement', 0, async (done: Function) => { - console.log('uitest: TestHasElement begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'HaselementAbility' - } - 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('HaselementAbility'); - - 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: TestHasElement end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/module.json5 deleted file mode 100755 index b9f3e45cb5548553dd1a01bd933d7cc15006ebb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/haselement/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "haselement_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isarray/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/isarray/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isarray/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/isarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/oh-package.json5 deleted file mode 100755 index c92fdff9540bf41187b816001aaecbccd7d03473..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "isarray", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libisarray.so": "file:./src/main/cpp/types/libisarray" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 36f0d152c2e7678bd9320dabcebdb58fa1c616fa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(isarray SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(isarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/hello.cpp deleted file mode 100755 index 7eed0f9d066d00985f712dbd82a90aee2ae1734a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_is_array] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_is_array] -#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) -// [EndExclude oh_jsvm_is_array] - -// OH_JSVM_IsArray的样例方法 -static JSVM_Value IsArray(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - bool result = false; - JSVM_Status status = OH_JSVM_IsArray(env, args[0], &result); - JSVM_Value returnValue = nullptr; - OH_JSVM_GetBoolean(env, result, &returnValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM IsArray fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM IsArray success, IsArray: %{public}d", result); - } - return returnValue; -} -// IsArray注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = IsArray}, -}; -static JSVM_CallbackStruct *method = param; -// IsArray方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"isArray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *srcCallNative = R"JS( -let data = [1, 2, 3, 4, 5]; -isArray(data); -)JS"; -// [End oh_jsvm_is_array] - -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, srcCallNative, 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 = "isarray", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/oh-package.json5 deleted file mode 100755 index f11e22fde61bef032155f615543febe7f5bb073e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/cpp/types/libisarray/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libisarray.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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/pages/Index.ets deleted file mode 100755 index 95d272e3df4292f4634fd7814014c820e6b40f5b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libisarray.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/module.json5 deleted file mode 100755 index d3492384bfa90526fd41a7983bc2e39da352368a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "isarray", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IsarrayAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IsarrayAbility", - "srcEntry": "./ets/isarrayability/IsarrayAbility.ets", - "description": "$string:IsarrayAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IsarrayAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/string.json deleted file mode 100755 index 0bb38989cc0bed53a4c30f4169443eff679e70fd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IsarrayAbility_desc", - "value": "description" - }, - { - "name": "IsarrayAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 5bcfe8950d1748beacd6f107b9a8fc3544d53c08..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsArray', 0, async (done: Function) => { - console.log('uitest: TestIsArray begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IsarrayAbility' - } - 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('IsarrayAbility'); - - 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: TestIsArray end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/module.json5 deleted file mode 100755 index 356ab988c0d9f5c6f7474ffbc34fc70bfc71bb39..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isarray/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "isarray_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/isdataview/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isdataview/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/isdataview/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/oh-package.json5 deleted file mode 100755 index 476e6736cc2e105995dd8c1310f9e0fb783eed0b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "isdataview", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libisdataview.so": "file:./src/main/cpp/types/libisdataview" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 564b50cfe325b47f5b41bc67f91c2fced3e88945..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(isdataview SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(isdataview PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/hello.cpp deleted file mode 100755 index 762ea1f572867a91611c9bc8066555e7f68349c7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/hello.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_is_dataview] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_is_dataview] -#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) -// [EndExclude oh_jsvm_is_dataview] - -// OH_JSVM_IsDataview的样例方法 -static JSVM_Value IsDataView(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 调用OH_JSVM_IsDataview接口判断给定入参是否为DataView数据。 - bool result = false; - JSVM_Status status = OH_JSVM_IsDataview(env, args[0], &result); - JSVM_Value isDateView = nullptr; - OH_JSVM_GetBoolean(env, result, &isDateView); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM IsDataView fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM IsDataView: %{public}d", result); - } - return isDateView; -} -// IsDataView注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = IsDataView}, -}; -static JSVM_CallbackStruct *method = param; -// IsDataView方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"isDataView", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *srcCallNative = R"JS( -let buffer = new ArrayBuffer(16); -let dataView = new DataView(buffer); -isDataView(dataView); -)JS"; -// [End oh_jsvm_is_dataview] - -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, srcCallNative, 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 = "isdataview", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/oh-package.json5 deleted file mode 100755 index b6302ca5ecacfedf00dbd32632d9febfd9380fe3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/cpp/types/libisdataview/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libisdataview.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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/pages/Index.ets deleted file mode 100755 index f7f14d9729cbbe152c78781514f0975fd3bc2c80..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libisdataview.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/module.json5 deleted file mode 100755 index 5c8abef952e2622157583307af95caff89dfb1ce..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "isdataview", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IsdataviewAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IsdataviewAbility", - "srcEntry": "./ets/isdataviewability/IsdataviewAbility.ets", - "description": "$string:IsdataviewAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IsdataviewAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/string.json deleted file mode 100755 index 8603514ee5792c491a2254fb86c1959077e9e6a8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IsdataviewAbility_desc", - "value": "description" - }, - { - "name": "IsdataviewAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index a3dec8ed2b9e78fc9a9fd555c685f4f1134c1ff6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsDataview', 0, async (done: Function) => { - console.log('uitest: TestIsDataview begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IsdataviewAbility' - } - 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('IsdataviewAbility'); - - 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: TestIsDataview end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/module.json5 deleted file mode 100755 index 758fddc1c91feb0f00f5504034f08bab1e73ba20..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/isdataview/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "isdataview_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/istypedarray/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/istypedarray/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/istypedarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/oh-package.json5 deleted file mode 100755 index 38ca37b6db4e88185c70bbc38086a80015ca088d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "istypedarray", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libistypedarray.so": "file:./src/main/cpp/types/libistypedarray" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 7af3080ae7338459bf56af610a60523403a40864..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(istypedarray SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(istypedarray PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/hello.cpp deleted file mode 100755 index ecf31b201eecf2f237b11e7979a5b761c948fa80..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/hello.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_is_typedarray] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_is_typedarray] -#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) -// [EndExclude oh_jsvm_is_typedarray] - -// OH_JSVM_IsTypedarray的样例方法 -static JSVM_Value IsTypedarray(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - bool result = false; - JSVM_Status status = OH_JSVM_IsTypedarray(env, args[0], &result); - JSVM_Value isTypedArray = nullptr; - OH_JSVM_GetBoolean(env, result, &isTypedArray); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM IsTypedarray fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM IsTypedarray: %{public}d", result); - } - return isTypedArray; -} -// IsTypedarray注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = IsTypedarray}, -}; -static JSVM_CallbackStruct *method = param; -// IsTypedarray方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"isTypedarray", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *srcCallNative = R"JS( -isTypedarray(new Uint16Array([1, 2, 3, 4])); -)JS"; -// [End oh_jsvm_is_typedarray] - -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, srcCallNative, 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 = "istypedarray", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/oh-package.json5 deleted file mode 100755 index db3279c30a3f69b14a4fa9f4e171587b186fa0c2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/cpp/types/libistypedarray/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libistypedarray.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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/pages/Index.ets deleted file mode 100755 index e93f657328a27dce93eb61623723a692a4c38134..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libistypedarray.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/module.json5 deleted file mode 100755 index 8a0d306d786266ff4914c5203f35857f923e2756..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "istypedarray", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IstypedarrayAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IstypedarrayAbility", - "srcEntry": "./ets/istypedarrayability/IstypedarrayAbility.ets", - "description": "$string:IstypedarrayAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IstypedarrayAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/string.json deleted file mode 100755 index 305ffc3c425e09f39fda44d2c48b271b2384e555..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IstypedarrayAbility_desc", - "value": "description" - }, - { - "name": "IstypedarrayAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 16f2c7c380c4dd31481cfaa1a85898e3d9f9bdeb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsTypedarray', 0, async (done: Function) => { - console.log('uitest: TestIsTypedarray begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IstypedarrayAbility' - } - 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('IstypedarrayAbility'); - - 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: TestIsTypedarray end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/module.json5 deleted file mode 100755 index ea687953756a76f46f7d1f1b701245f91aa88248..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/istypedarray/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "istypedarray_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/ohosTest.md deleted file mode 100755 index e12b05ad3d59e5c4e61942ec3f9f76068473794e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/ohosTest.md +++ /dev/null @@ -1,21 +0,0 @@ -# JsvmAboutArray 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 创建一个新的 JavaScript 数组对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建一个指定长度的 JavaScript 数组对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 在现有的 ArrayBuffer 上创建一个 JavaScript DataView 对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 在现有的 ArrayBuffer 上创建一个 JavaScript TypedArray 对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 尝试删除给定对象的指定索引处的元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 返回 Array 对象的长度 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取 Dataview 对象的信息 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定对象指定索引处的元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取 TypedArray(类型化数组)对象的信息 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 若给定对象的指定索引处拥有属性,获取该元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断一个 JavaScript 对象是否为 Array 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断一个 JavaScript 对象是否为 Dataview 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断一个 JavaScript 对象是否为 Typedarray 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 在给定对象的指定索引处设置元素 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArray/setelement/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/setelement/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArray/setelement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/oh-package.json5 deleted file mode 100755 index 0c59a43f391026378085465b9e38edae273f6613..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "setelement", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libsetelement.so": "file:./src/main/cpp/types/libsetelement" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 19fe43ea27cf84cb3b14cecd2087aa483d4ecb38..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(setelement SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(setelement PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/hello.cpp deleted file mode 100755 index c81c3737da83a9a541a8e39e7f4033d18212fc05..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/hello.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_set_element] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_set_element] -#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) -// [EndExclude oh_jsvm_set_element] - -// OH_JSVM_SetElement的样例方法 -static int g_diffValueThree = 3; -static JSVM_Value SetElement(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = g_diffValueThree; - JSVM_Value args[3] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - int32_t index = 0; - OH_JSVM_GetValueInt32(env, args[1], &index); - JSVM_Status status = OH_JSVM_SetElement(env, args[0], index, args[2]); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM SetElement fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM SetElement success"); - } - return args[0]; -} -// SetElement注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = SetElement}, -}; -static JSVM_CallbackStruct *method = param; -// SetElement方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"setElement", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -setElement(3); -)JS"; -// [End oh_jsvm_set_element] - -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 = "setelement", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/oh-package.json5 deleted file mode 100755 index 029e1bf80d1f74c48ce628733113cf1275dba064..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/cpp/types/libsetelement/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libsetelement.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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/pages/Index.ets deleted file mode 100755 index 559532bd1526b2fdbb309fcf51c04a690051e12c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libsetelement.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/module.json5 deleted file mode 100755 index e5b86c801b88f7223820d6f13ab061a02b1388a2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "setelement", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "SetelementAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "SetelementAbility", - "srcEntry": "./ets/setelementability/SetelementAbility.ets", - "description": "$string:SetelementAbility_desc", - "icon": "$media:layered_image", - "label": "$string:SetelementAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/string.json deleted file mode 100755 index cbd9e537b8dc170716f3c967786f0a94db981f93..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "SetelementAbility_desc", - "value": "description" - }, - { - "name": "SetelementAbility_label", - "value": "JsvmAboutArray" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 062ebfc4fdd46da510cd9e8531b3bd2d44fa7647..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testSetElement', 0, async (done: Function) => { - console.log('uitest: TestSetElement begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'SetelementAbility' - } - 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('SetelementAbility'); - - 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: TestSetElement end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/module.json5 deleted file mode 100755 index 46b5e93ffff8192f97ded84197f0a289364b2c96..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArray/setelement/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "setelement_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/app.json5 deleted file mode 100755 index eb29f6aefa58b13dad4c6f3e1033c119efdae85c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutarraybuffer", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/element/string.json deleted file mode 100755 index 613535572c1e6e8475b3eca0795d315334006867..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutArraybuffer" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/README.md deleted file mode 100755 index 15dd8d20443600c5173aa1172f7ac44d7670c1b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/README.md +++ /dev/null @@ -1,133 +0,0 @@ -# ArkTS使用JSVM-API接口进行ArrayBuffer相关开发 - -### 介绍 - -ArrayBuffer 是 JavaScript 中的一种数据类型,用于表示通用的、固定长度的原始二进制数据缓冲区。它提供了一种在 JavaScript 中有效地表示和操作原始二进制数据的方式。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行ArrayBuffer相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-arraybuffer.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createarraybuffer/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getarraybufferinfo/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -isarraybuffer/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -isdetachedarraybuffer/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutArraybuffer > .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/JsvmUsageGuide/JsvmAboutArraybuffer/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/build-profile.json5 deleted file mode 100755 index fb1425aa3a942e155a36c0882194e164936775ef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/build-profile.json5 +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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": "getarraybufferinfo", - "srcPath": "./getarraybufferinfo", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "isarraybuffer", - "srcPath": "./isarraybuffer", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "isdetachedarraybuffer", - "srcPath": "./isdetachedarraybuffer", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createarraybuffer", - "srcPath": "./createarraybuffer", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/oh-package.json5 deleted file mode 100755 index b60ae4861ec8ff34dd31b7074d0f7a79213cde8f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createarraybuffer", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatearraybuffer.so": "file:./src/main/cpp/types/libcreatearraybuffer" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e5d69ce760bfc5e51e9e4533de0a456742da2060..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsFive) - -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(createarraybuffer SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createarraybuffer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/hello.cpp deleted file mode 100755 index 449f21385f3dd18c334b1eae97df053ea275625b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/hello.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_arraybuffer] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_create_arraybuffer] -#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) -// [EndExclude oh_jsvm_create_arraybuffer] - -// OH_JSVM_CreateArraybuffer的样例方法 -static JSVM_Value CreateArraybuffer(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - JSVM_Value result = nullptr; - // 解析传递的参数 - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - int32_t value; - size_t length; - OH_JSVM_GetValueInt32(env, argv[0], &value); - length = size_t(value); - void *data; - // 创建一个新的ArrayBuffer - JSVM_Status status = OH_JSVM_CreateArraybuffer(env, length, &data, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateArraybuffer: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateArraybuffer: success"); - OH_LOG_INFO(LOG_APP, "JSVM ArrayBuffer length: %{public}d", length); - } - // 返回创建好的ArrayBuffer - return result; -} -// CreateArraybuffer注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateArraybuffer}, -}; -static JSVM_CallbackStruct *method = param; -// CreateArraybuffer方法别名,供TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createArraybuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -createArraybuffer(8); -)JS"; -// [End oh_jsvm_create_arraybuffer] - -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 = "createarraybuffer", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/oh-package.json5 deleted file mode 100755 index a103e5b56078202802804a9b2480e2e2d5d394ac..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/cpp/types/libcreatearraybuffer/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatearraybuffer.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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/pages/Index.ets deleted file mode 100755 index caada64d53fbf53e3c0fbe1bdc8cbcbb8ba3e1d3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatearraybuffer.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/module.json5 deleted file mode 100755 index e7e9dbbb9e4b1946625b2cf7fd6bdf41dedd20b1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createarraybuffer", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatearraybufferAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatearraybufferAbility", - "srcEntry": "./ets/createarraybufferability/CreatearraybufferAbility.ets", - "description": "$string:CreatearraybufferAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatearraybufferAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/string.json deleted file mode 100755 index 238c217e3e90d012dec2b70b6d9caee60dd745a0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatearraybufferAbility_desc", - "value": "description" - }, - { - "name": "CreatearraybufferAbility_label", - "value": "JsvmAboutArraybuffer" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index efccdafb50ce6d8b91941a6ad8d961168b9a5c94..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateArraybuffer', 0, async (done: Function) => { - console.log('uitest: TestCreateArraybuffer begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatearraybufferAbility' - } - 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('CreatearraybufferAbility'); - - 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: TestCreateArraybuffer end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/module.json5 deleted file mode 100755 index a7ac6ba8642ed88aaae9982d2a9c54eb1f533dee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/createarraybuffer/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createarraybuffer_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/oh-package.json5 deleted file mode 100755 index cf14f3f986a763737682f004955d7e157e8207f7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getarraybufferinfo", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetarraybufferinfo.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/CMakeLists.txt deleted file mode 100755 index af0cebc3fb033264f0e3c2e384cab4627bdc1e67..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsFive) - -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(getarraybufferinfo SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getarraybufferinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/hello.cpp deleted file mode 100755 index e8af36eeb5ce6acd04147d0e24a64d7be93cade9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/hello.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_arraybuffer_info] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_arraybuffer_info] -#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) -// [EndExclude oh_jsvm_get_arraybuffer_info] - -// OH_JSVM_GetArraybufferInfo的样例方法 -static JSVM_Value GetArraybufferInfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - // 解析传递的参数 - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 检查参数是否为ArrayBuffer - bool isArrayBuffer = false; - OH_JSVM_IsArraybuffer(env, args[0], &isArrayBuffer); - if (!isArrayBuffer) { - OH_LOG_ERROR(LOG_APP, "JSVM GetArraybufferInfo isArrayBuffer:false"); - } - void *data; - size_t byteLength; - // 获取ArrayBuffer的底层数据缓冲区和长度 - JSVM_Status status = OH_JSVM_GetArraybufferInfo(env, args[0], &data, &byteLength); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetArraybufferInfo: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetArraybufferInfo: success"); - } - return args[0]; -} -// GetArraybufferInfo注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetArraybufferInfo}, -}; -static JSVM_CallbackStruct *method = param; -// GetArraybufferInfo方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getArraybufferInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -getArraybufferInfo(new ArrayBuffer(10)); -)JS"; -// [End oh_jsvm_get_arraybuffer_info] - -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 = "getarraybufferinfo", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index b5305705eac7dbfde47d9ae0672f77d3225e51f8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetarraybufferinfo.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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/pages/Index.ets deleted file mode 100755 index 7c4cb291d78d12530efa440fd7cbe667eab2d2ed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetarraybufferinfo.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/module.json5 deleted file mode 100755 index cfe4a3f064ba2da5ef182c4a5ae3b268ff75bcec..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getarraybufferinfo", - "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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/string.json deleted file mode 100755 index 1e692e6c955b246dba6e5297a40be6d61ce05877..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutArraybuffer" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 968c88ee64e67dedfb10a928739ae8f9e59301b8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetArraybufferInfo', 0, async (done: Function) => { - console.log('uitest: TestGetArraybufferInfo 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: TestGetArraybufferInfo end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/module.json5 deleted file mode 100755 index 4a8d6b5d441e56a1fbb6ea30b9fd3d7327f816e7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/getarraybufferinfo/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getarraybufferinfo_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/oh-package.json5 deleted file mode 100755 index 6ee87b9f96349a2745231b71bdc642c51d7a754b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "isarraybuffer", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libisarraybuffer.so": "file:./src/main/cpp/types/libisarraybuffer" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 466812669b62760968026b722ddee659108e4ebf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsFive) - -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(isarraybuffer SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(isarraybuffer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/hello.cpp deleted file mode 100755 index f80157fc4757fa15b21c1255d5edbfd37d94e937..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_is_arraybuffer] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_is_arraybuffer] -#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) -// [EndExclude oh_jsvm_is_arraybuffer] - -// OH_JSVM_IsArraybuffer的样例方法 -static JSVM_Value IsArrayBuffer(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 调用OH_JSVM_IsArraybuffer接口判断给定入参是否为ArrayBuffer数据 - bool isArrayBuffer = false; - JSVM_Status status = OH_JSVM_IsArraybuffer(env, args[0], &isArrayBuffer); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM IsArrayBuffer: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM IsArrayBuffer: success"); - OH_LOG_INFO(LOG_APP, "JSVM IsArrayBuffer: %{public}d", isArrayBuffer); - } - JSVM_Value boolean = nullptr; - OH_JSVM_GetBoolean(env, isArrayBuffer, &boolean); - return boolean; -} -// IsArrayBuffer注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = IsArrayBuffer}, -}; -static JSVM_CallbackStruct *method = param; -// IsArrayBuffer方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"isArrayBuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -isArrayBuffer(new ArrayBuffer(8)); -)JS"; -// [End oh_jsvm_is_arraybuffer] - -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 = "isarraybuffer", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/oh-package.json5 deleted file mode 100755 index 9a2ed9e1fa1f7cb80353c6070544c277b4af7cbc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/cpp/types/libisarraybuffer/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libisarraybuffer.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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/pages/Index.ets deleted file mode 100755 index aa30c7724ef1c4929263887a46b7857a52b7023b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libisarraybuffer.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/module.json5 deleted file mode 100755 index 36ef91299a45a57646a7df66c5244aed972000b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "isarraybuffer", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IsarraybufferAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IsarraybufferAbility", - "srcEntry": "./ets/isarraybufferability/IsarraybufferAbility.ets", - "description": "$string:IsarraybufferAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IsarraybufferAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/string.json deleted file mode 100755 index b915f12904d926a828393d1e6ce9359dbafda5ad..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IsarraybufferAbility_desc", - "value": "description" - }, - { - "name": "IsarraybufferAbility_label", - "value": "JsvmAboutArraybuffer" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 5a93f6e73027b1fa1967a9b1f34ea4d8550446c8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsArraybuffer', 0, async (done: Function) => { - console.log('uitest: TestIsArraybuffer begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IsarraybufferAbility' - } - 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('IsarraybufferAbility'); - - 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: TestIsArraybuffer end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/module.json5 deleted file mode 100755 index 882df228c32b47bc7bf265cafac113af46f6b530..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isarraybuffer/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "isarraybuffer_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/oh-package.json5 deleted file mode 100755 index 092dfbf9c6023abef75521d750f34c897ddc4a9a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "isdetachedarraybuffer", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libisdetachedarraybuffer.so": "file:./src/main/cpp/types/libisdetachedarraybuffer" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9e883e92c132006c11b131046df955457c843ba4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsFive) - -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(isdetachedarraybuffer SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(isdetachedarraybuffer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/hello.cpp deleted file mode 100755 index bbb0ebfec9f0a3fe2441ba9d3dd3fc7b803cac99..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/hello.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_is_detached_arraybuffer] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_is_detached_arraybuffer] -#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) -// [EndExclude oh_jsvm_is_detached_arraybuffer] - -// OH_JSVM_DetachArraybuffer、OH_JSVM_IsDetachedArraybuffer的样例方法 -static JSVM_Value DetachArraybuffer(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value arraybuffer = args[0]; - JSVM_Status status = OH_JSVM_DetachArraybuffer(env, arraybuffer); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM DetachArraybuffer: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM DetachArraybuffer: success"); - } - return arraybuffer; -} -static JSVM_Value IsDetachedArraybuffer(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value arraybuffer = args[0]; - OH_JSVM_DetachArraybuffer(env, arraybuffer); - bool result = false; - JSVM_Status status = OH_JSVM_IsDetachedArraybuffer(env, arraybuffer, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM IsDetachedArraybuffer: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM IsDetachedArraybuffer: success"); - OH_LOG_INFO(LOG_APP, "JSVM IsArrayBuffer: %{public}d", result); - } - JSVM_Value isDetached = nullptr; - OH_JSVM_GetBoolean(env, result, &isDetached); - return isDetached; -} -// DetachArraybuffer、IsDetachedArraybuffer注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = DetachArraybuffer}, - {.data = nullptr, .callback = IsDetachedArraybuffer}, -}; -static JSVM_CallbackStruct *method = param; -// DetachArraybuffer、IsDetachedArraybuffer方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"detachArraybuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - {"isDetachedArraybuffer", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( -let arrayBuffer = new ArrayBuffer(10); -detachArraybuffer(arrayBuffer); -isDetachedArraybuffer(arrayBuffer); -)JS"; -// [End oh_jsvm_is_detached_arraybuffer] - -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 = "isdetachedarraybuffer", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/oh-package.json5 deleted file mode 100755 index 31a656a2e752a523e64aba714aa4d3337aa60b2e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/cpp/types/libisdetachedarraybuffer/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libisdetachedarraybuffer.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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/pages/Index.ets deleted file mode 100755 index 4e614955a2cbbbf341adf3bb2df59665e91b9317..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libisdetachedarraybuffer.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/module.json5 deleted file mode 100755 index aef2750cb55b95045661929f0044e39b4a1a5e9a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "isdetachedarraybuffer", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IsdetachedarraybufferAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IsdetachedarraybufferAbility", - "srcEntry": "./ets/isdetachedarraybufferability/IsdetachedarraybufferAbility.ets", - "description": "$string:IsdetachedarraybufferAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IsdetachedarraybufferAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/string.json deleted file mode 100755 index 90d9dedcdac164e4a51719c55679f7931e5acfed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IsdetachedarraybufferAbility_desc", - "value": "description" - }, - { - "name": "IsdetachedarraybufferAbility_label", - "value": "JsvmAboutArraybuffer" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 0ba626d6a69ad48825ad6271e0753944c064c603..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsDetachedArraybuffer', 0, async (done: Function) => { - console.log('uitest: TestIsDetachedArraybuffer begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IsdetachedarraybufferAbility' - } - 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('IsdetachedarraybufferAbility'); - - 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: TestIsDetachedArraybuffer end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/module.json5 deleted file mode 100755 index c2f3415f602d95cfad086b581760973fd5a75d96..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/isdetachedarraybuffer/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "isdetachedarraybuffer_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutArraybuffer/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/ohosTest.md deleted file mode 100755 index 4694515986d2c1b239a969f03bb7e3d7f9f47697..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutArraybuffer/ohosTest.md +++ /dev/null @@ -1,11 +0,0 @@ -# JsvmAboutArraybuffer 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 创建一个指定大小的 ArrayBuffer 对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 检索 ArrayBuffer 的底层数据缓冲区及其长度 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断一个 JavaScript 对象是否为 ArrayBuffer 类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 检查给定的 ArrayBuffer 是否已被分离(detached) | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutBigint/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/app.json5 deleted file mode 100755 index 6f47fb9017563a9dd07b3074043418c726a77d3b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutbigint", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/element/string.json deleted file mode 100755 index 2b02ed225991044257a3cc77a3ffc721ffa1e6c2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutBigint" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/README.md deleted file mode 100755 index 63b4751b257c8e9e00634fd01ab4095b56fd50a3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/README.md +++ /dev/null @@ -1,173 +0,0 @@ -# ArkTS使用JSVM-API接口操作bigint类型值 - -### 介绍 - -BigInt是JavaScript中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过JSVM-API提供的接口,可以在JSVM模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口操作bigint类型值](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-bigint.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createbigintint64/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createbigintuint64/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createbigintwords/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluebigintint64/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluebigintuint64/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluebigintwords/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutBigint > .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/JsvmUsageGuide/JsvmAboutBigint/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/build-profile.json5 deleted file mode 100755 index 1e50db2443edc61aec0548c175cf1bdd9b7764c9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/build-profile.json5 +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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": "getvaluebigintwords", - "srcPath": "./getvaluebigintwords", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createbigintwords", - "srcPath": "./createbigintwords", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createbigintuint64", - "srcPath": "./createbigintuint64", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvaluebigintuint64", - "srcPath": "./getvaluebigintuint64", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createbigintint64", - "srcPath": "./createbigintint64", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvaluebigintint64", - "srcPath": "./getvaluebigintint64", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/oh-package.json5 deleted file mode 100755 index 92a4bca939424f4aef31c88b4b5e338e03591c01..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createbigintint64", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatebigintint64.so": "file:./src/main/cpp/types/libcreatebigintint64" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/CMakeLists.txt deleted file mode 100755 index d22b827470c8698d19631d32409d4e7a55dddf03..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(createbigintint64 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createbigintint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/hello.cpp deleted file mode 100755 index 113a5ae2587fe52339127f11e9fceedbaae4a78f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/hello.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_bigint_int64] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_create_bigint_int64] -#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) -// [EndExclude oh_jsvm_create_bigint_int64] - -// 声明int64_t的变量value -static int64_t g_testValueDemo = -5555555555555555555; -// OH_JSVM_CreateBigintInt64的样例方法 -static JSVM_Value CreateBigintInt64(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value returnValue = nullptr; - JSVM_Status status = OH_JSVM_CreateBigintInt64(env, g_testValueDemo, &returnValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateBigintInt64 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateBigintInt64 success"); - } - return returnValue; -} -// CreateBigintInt64注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateBigintInt64}, -}; -static JSVM_CallbackStruct *method = param; -// CreateBigintInt64方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createBigintInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createBigintInt64())JS"; -// [End oh_jsvm_create_bigint_int64] - -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 = "createbigintint64", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/oh-package.json5 deleted file mode 100755 index fdb5a8211db68b94262caba771c6529daacd95b5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/cpp/types/libcreatebigintint64/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatebigintint64.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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/pages/Index.ets deleted file mode 100755 index 8992c784222289f73b753c789d50a50f1a7b31e3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatebigintint64.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/module.json5 deleted file mode 100755 index af0e3d8c4a1d84e0ed37c17862616f3a6c5e4883..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createbigintint64", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createbigintint64Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createbigintint64Ability", - "srcEntry": "./ets/createbigintint64ability/Createbigintint64Ability.ets", - "description": "$string:Createbigintint64Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createbigintint64Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/string.json deleted file mode 100755 index 6f8e92b4168a3c8bbfb380e9aba65ba098c2647c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createbigintint64Ability_desc", - "value": "description" - }, - { - "name": "Createbigintint64Ability_label", - "value": "JsvmAboutBigint" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index b939d7ce062c37a4927c0c78e9a41db7240fdede..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateBigintInt64', 0, async (done: Function) => { - console.log('uitest: TestCreateBigintInt64 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createbigintint64Ability' - } - 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('Createbigintint64Ability'); - - 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: TestCreateBigintInt64 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/module.json5 deleted file mode 100755 index b2d5ceed6324cf5c1128ab2577438b2df3e22bd4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintint64/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createbigintint64_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/oh-package.json5 deleted file mode 100755 index 87d61adb9d48a3a50302cc9ef6a81824aca75b87..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createbigintuint64", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatebigintuint64.so": "file:./src/main/cpp/types/libcreatebigintuint64" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 38af960d6192fb147b14fe3df3173b52c4f0d068..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsSix) - -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(createbigintuint64 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createbigintuint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/hello.cpp deleted file mode 100755 index 26640be6252ccc20c4fc9bb3870efc1dabae8006..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/hello.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_bigint_uint64] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_create_bigint_uint64] -#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) -// [EndExclude oh_jsvm_create_bigint_uint64] - -// 声明uint64_t的变量value -static uint64_t g_testValue = 5555555555555555555; -// OH_JSVM_CreateBigintUint64的样例方法 -static JSVM_Value CreateBigintUint64(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 将value转化为JSVM_Value类型返回 - JSVM_Value returnValue = nullptr; - JSVM_Status status = OH_JSVM_CreateBigintUint64(env, g_testValue, &returnValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateBigintUint64 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateBigintUint64 success"); - } - return returnValue; -} -// CreateBigintUint64注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateBigintUint64}, -}; -static JSVM_CallbackStruct *method = param; -// CreateBigintUint64方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createBigintUint64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(createBigintUint64())JS"; -// [End oh_jsvm_create_bigint_uint64] - -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 = "createbigintuint64", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/oh-package.json5 deleted file mode 100755 index 088b2dfe013f7afd313003b40f0b25eb9f422027..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/cpp/types/libcreatebigintuint64/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatebigintuint64.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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/pages/Index.ets deleted file mode 100755 index 78544b5aa9c452fed66156e066ef5f43cb236060..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatebigintuint64.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/module.json5 deleted file mode 100755 index 28da694d72e66164e8ee1dd42fd7bdd9bf3c9e89..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createbigintuint64", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createbigintuint64Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createbigintuint64Ability", - "srcEntry": "./ets/createbigintuint64ability/Createbigintuint64Ability.ets", - "description": "$string:Createbigintuint64Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createbigintuint64Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/string.json deleted file mode 100755 index e057632eb6d0e5bce95a56cd23b998eb4c48b802..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createbigintuint64Ability_desc", - "value": "description" - }, - { - "name": "Createbigintuint64Ability_label", - "value": "JsvmAboutBigint" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 4c80c819765a1f0116b6266ebe76affec0cef355..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateBigintUint64', 0, async (done: Function) => { - console.log('uitest: TestCreateBigintUint64 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createbigintuint64Ability' - } - 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('Createbigintuint64Ability'); - - 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: TestCreateBigintUint64 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/module.json5 deleted file mode 100755 index 465522865fe9e1efd3b1a522eae303f119ca4a2b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintuint64/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createbigintuint64_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/oh-package.json5 deleted file mode 100755 index 18dc047ed6bf05d212de75a6032c7865cab50417..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createbigintwords", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatebigintwords.so": "file:./src/main/cpp/types/libcreatebigintwords" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/CMakeLists.txt deleted file mode 100755 index af39e3ec988a54623848dfb6a19989ba2f7d89e7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsSix) - -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(createbigintwords SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createbigintwords PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/hello.cpp deleted file mode 100755 index b66ede418b78ba67a85b2508eb4d6cf21bc6f854..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_bigint_words] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_create_bigint_words] -#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) -// [EndExclude oh_jsvm_create_bigint_words] - -// OH_JSVM_CreateBigintWords的样例方法 -static int g_diffValueThree = 3; -static JSVM_Value CreateBigintWords(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 使用OH_JSVM_CreateBigintWords接口创建一个BigInt对象 - int signBit = 0; - size_t wordCount = g_diffValueThree; - uint64_t words[] = {12ULL, 34ULL, 56ULL}; - JSVM_Value returnValue = nullptr; - JSVM_Status status = OH_JSVM_CreateBigintWords(env, signBit, wordCount, words, &returnValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateBigintWords fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateBigintWords success"); - } - return returnValue; -} -// CreateBigintWords注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateBigintWords}, -}; -static JSVM_CallbackStruct *method = param; -// CreateBigintWords方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createBigintWords", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createBigintWords())JS"; -// [EndExclude oh_jsvm_create_bigint_words] - -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 = "createbigintwords", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/oh-package.json5 deleted file mode 100755 index 6076c74a8fdb4fd248df9864765be9b20eab518f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/cpp/types/libcreatebigintwords/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatebigintwords.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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/pages/Index.ets deleted file mode 100755 index b41ea33b63868514bde727567d5145951f83aacd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatebigintwords.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/module.json5 deleted file mode 100755 index 873f21cc0e777c7e7a8584088868e2a11b8df455..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createbigintwords", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatebigintwordsAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatebigintwordsAbility", - "srcEntry": "./ets/createbigintwordsability/CreatebigintwordsAbility.ets", - "description": "$string:CreatebigintwordsAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatebigintwordsAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/string.json deleted file mode 100755 index bfc445306bf6c6c209f90943d29b3a65b84c091b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatebigintwordsAbility_desc", - "value": "description" - }, - { - "name": "CreatebigintwordsAbility_label", - "value": "JsvmAboutBigint" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index ed20536c53b0e747326a7d745e14c5559bc4270f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateBigintWords', 0, async (done: Function) => { - console.log('uitest: TestCreateBigintWords begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatebigintwordsAbility' - } - 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('CreatebigintwordsAbility'); - - 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: TestCreateBigintWords end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/module.json5 deleted file mode 100755 index a1b15147e64a31e918cb5cf6af76d6f42de0c22c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/createbigintwords/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createbigintwords_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/oh-package.json5 deleted file mode 100755 index 3caa8c90f895906faa5c983c2d6bd944ae7560cb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluebigintint64", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluebigintint64.so": "file:./src/main/cpp/types/libgetvaluebigintint64" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 29b45613e46f0473dfecfd4bb00e6a167a5b33b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getvaluebigintint64 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluebigintint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/hello.cpp deleted file mode 100755 index da556acb02dbee12e55c72c7704b385d26036a47..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_bigint_int64] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_value_bigint_int64] -#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) -// [EndExclude oh_jsvm_get_value_bigint_int64] - -// OH_JSVM_GetValueBigintInt64的样例方法 -static JSVM_Value GetBigintInt64(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 从传入的参数中提取64位整数的BigInt数据 - int64_t value; - bool lossLess; - OH_JSVM_GetValueBigintInt64(env, args[0], &value, &lossLess); - // 判断从JS侧获取bigint是否为无损转换,如果不是抛出异常 - if (!lossLess) { - OH_JSVM_ThrowError(env, nullptr, "BigInt values have no lossless converted"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetBigintInt64 success:%{public}d", lossLess); - } - JSVM_Value returnValue = nullptr; - OH_JSVM_CreateBigintInt64(env, value, &returnValue); - return returnValue; -} -// GetBigintInt64注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetBigintInt64}, -}; -static JSVM_CallbackStruct *method = param; -// GetBigintInt64方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getBigintInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getBigintInt64(BigInt(-5555555555555555)))JS"; -// [End oh_jsvm_get_value_bigint_int64] - -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 = "getvaluebigintint64", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/oh-package.json5 deleted file mode 100755 index ddd0695d32d2c66889bab9aa2a5ab3fd89448008..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/cpp/types/libgetvaluebigintint64/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluebigintint64.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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/pages/Index.ets deleted file mode 100755 index 6d63a3a7f9667a3b864ed293cd99d9f1011d7a24..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluebigintint64.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/module.json5 deleted file mode 100755 index 7b4e39aaf696cd8346b3ae86c59555824fb52fe7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvaluebigintint64", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Getvaluebigintint64Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvaluebigintint64Ability", - "srcEntry": "./ets/getvaluebigintint64ability/Getvaluebigintint64Ability.ets", - "description": "$string:Getvaluebigintint64Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvaluebigintint64Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/string.json deleted file mode 100755 index 69b8e9e8e6b4e6e8e49d02932ff7e7be70f6fd7a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvaluebigintint64Ability_desc", - "value": "description" - }, - { - "name": "Getvaluebigintint64Ability_label", - "value": "JsvmAboutBigint" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 33f4b1bcd30d62a333061bad9236c6d216ea4843..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueBigintInt64', 0, async (done: Function) => { - console.log('uitest: TestGetValueBigintInt64 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvaluebigintint64Ability' - } - 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('Getvaluebigintint64Ability'); - - 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: TestGetValueBigintInt64 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/module.json5 deleted file mode 100755 index fa0d11ffb3f532891a7e6c9ff747f51fb471afbe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintint64/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluebigintint64_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/oh-package.json5 deleted file mode 100755 index c0b9bf1800fd517b4f5f95070da59df701d3f326..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluebigintuint64", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluebigintuint64.so": "file:./src/main/cpp/types/libgetvaluebigintuint64" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/CMakeLists.txt deleted file mode 100755 index c3e6c71d980ce9459f2fed08a270b9b963722358..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getvaluebigintuint64 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluebigintuint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/hello.cpp deleted file mode 100755 index 8ffb85d0586a1b8f3bf91f2cb1d4f6b7d4c6b15a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_bigint_uint64] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_value_bigint_uint64] -#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) -// [EndExclude oh_jsvm_get_value_bigint_uint64] - -// OH_JSVM_GetValueBigintUint64的样例方法 -static JSVM_Value GetValueBigintUint64(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 从参数值中获取BigInt的数值 - uint64_t value = 0; - bool lossLess = false; - OH_JSVM_GetValueBigintUint64(env, args[0], &value, &lossLess); - // 判断从JS侧获取bigint是否为无损转换,如果不是抛出异常 - if (!lossLess) { - OH_JSVM_ThrowError(env, nullptr, "BigInt values have no lossless converted"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueBigintUint64 success:%{public}d", lossLess); - } - JSVM_Value returnValue = nullptr; - OH_JSVM_CreateBigintUint64(env, value, &returnValue); - return returnValue; -} -// GetValueBigintUint64注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueBigintUint64}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueBigintUint64方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueBigintUint64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getValueBigintUint64(BigInt(5555555555555555)))JS"; -// [End oh_jsvm_get_value_bigint_uint64] - -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 = "getvaluebigintuint64", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/oh-package.json5 deleted file mode 100755 index cde166077019067e218b00d596928c59c9252fab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/cpp/types/libgetvaluebigintuint64/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluebigintuint64.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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/pages/Index.ets deleted file mode 100755 index 25cabb17b28f647d771e365ef7dbaf22e5bbae40..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluebigintuint64.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/module.json5 deleted file mode 100755 index 0fc31b23eeb570d04dabbfe7ba206b3e2197146e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvaluebigintuint64", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Getvaluebigintuint64Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvaluebigintuint64Ability", - "srcEntry": "./ets/getvaluebigintuint64ability/Getvaluebigintuint64Ability.ets", - "description": "$string:Getvaluebigintuint64Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvaluebigintuint64Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/string.json deleted file mode 100755 index abf5fdc5e9ecb41e7ec5707e4efa370eb9df5049..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvaluebigintuint64Ability_desc", - "value": "description" - }, - { - "name": "Getvaluebigintuint64Ability_label", - "value": "JsvmAboutBigint" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 51b5a5b06cb12a5c62c660a005544b3f8428ae47..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueBigintUint64', 0, async (done: Function) => { - console.log('uitest: TestGetValueBigintUint64 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvaluebigintuint64Ability' - } - 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('Getvaluebigintuint64Ability'); - - 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: TestGetValueBigintUint64 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/module.json5 deleted file mode 100755 index 36a09b2ba6539182d50d8e40fb1b094f013246c8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintuint64/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluebigintuint64_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/oh-package.json5 deleted file mode 100755 index c5d26d5634e73d6fda2ed261a5d957ed286017e1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluebigintwords", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluebigintwords.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9fa94ef3a7e143cb8b5f7cfa4e6d20d90abe42b0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsSix) - -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(getvaluebigintwords SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluebigintwords PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/hello.cpp deleted file mode 100755 index 91c1992fbb8ccfbe28bb3c32939eec22a922d415..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/hello.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_bigint_words] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -#include -// [StartExclude oh_jsvm_get_value_bigint_words] -#define LOG_DOMAIN 0x3200 -#define LOG_TAG "APP" -#define MAX_MALLOC_SIZE 0x800000 - -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) -// [EndExclude oh_jsvm_get_value_bigint_words] - -// OH_JSVM_GetValueBigintWords的样例方法 -static JSVM_Value GetValueBigintWords(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - int signBit = 0; - size_t wordCount = 0; - uint64_t* words{nullptr}; - // 调用OH_JSVM_GetValueBigintWords接口获取wordCount - JSVM_Status status = OH_JSVM_GetValueBigintWords(env, args[0], nullptr, &wordCount, nullptr); - OH_LOG_INFO(LOG_APP, "OH_JSVM_GetValueBigintWords wordCount:%{public}d.", wordCount); - if (wordCount == 0 || wordCount > SOME_REASONABLE_MAX) { - OH_LOG_ERROR(LOG_APP, "Invalid wordCount: %{public}zu", wordCount); - return nullptr; - } - words = (uint64_t*)malloc(wordCount*sizeof(uint64_t)); - if (words == nullptr) { - OH_LOG_ERROR(LOG_APP, "OH_JSVM_GetValueBigintWords malloc failed."); - return nullptr; - } - // 调用OH_JSVM_GetValueBigintWords接口获取传入bigInt相关信息,如:signBit传入bigInt正负信息 - status = OH_JSVM_GetValueBigintWords(env, args[0], &signBit, &wordCount, words); - free(words); - words = nullptr; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "OH_JSVM_GetValueBigintWords fail, status:%{public}d.", status); - } else { - OH_LOG_INFO(LOG_APP, "OH_JSVM_GetValueBigintWords signBit: %{public}d.", signBit); - } - // 将符号位转化为int类型传出去 - JSVM_Value returnValue = nullptr; - OH_JSVM_CreateInt32(env, signBit, &returnValue); - return returnValue; -} -// GetValueBigintWords注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueBigintWords}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueBigintWords方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueBigintWords", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getValueBigintWords(BigInt(5555555555555555)))JS"; -// [End oh_jsvm_get_value_bigint_words] - -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 = "getvaluebigintwords", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index c982cc057cad050be25d94d9b3cba0a446a5e09a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluebigintwords.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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/pages/Index.ets deleted file mode 100755 index 7aae1b4697e858eb14a00bf04370936d6637689c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluebigintwords.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/module.json5 deleted file mode 100755 index 2ed4f636674bf0e41a6316249c3c956523c6d8ef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getvaluebigintwords", - "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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/string.json deleted file mode 100755 index 6c464703738dba8d0af90e9aa9b29d573bc93afd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutBigint" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 7548b34b75287f19afd08911ef69b4a8cb6c0a4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueBigintWords', 0, async (done: Function) => { - console.log('uitest: TestGetValueBigintWords 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: TestGetValueBigintWords end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/module.json5 deleted file mode 100755 index 01612183359ed34c77d177dadb979d3ac22032c7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/getvaluebigintwords/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluebigintwords_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutBigint/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/ohosTest.md deleted file mode 100755 index cde850b057742219ffa5f18b91f1135e64c11a02..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutBigint/ohosTest.md +++ /dev/null @@ -1,13 +0,0 @@ -# JsvmAboutBigint 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 将C int64_t类型的值转换为JavaScript BigInt类型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 将C uint64_t类型的值转换为JavaScript BigInt类型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 将一组无符号64位字转换为单个BigInt值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 返回给定JavaScript BigInt的C int64_t基础类型等价值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 返回给定JavaScript BigInt的C uint64_t基础类型等价值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 将单个BigInt值转换为一个符号位、一个64位的小端数组和该数组的长度 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/app.json5 deleted file mode 100755 index 0351d86ed7c514d1efa758aef3438d5b65f71b4e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutclass", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/element/string.json deleted file mode 100755 index c702a3d2a53daae9287547effcedd3a669e3a625..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutClass" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/README.md deleted file mode 100755 index 39235c3b642dc1494c6d2f10816a7752dcf7f23b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/README.md +++ /dev/null @@ -1,113 +0,0 @@ -# ArkTS使用JSVM接口进行class相关开发 - -### 介绍 - -使用JSVM-API接口进行class相关开发,处理JavaScript中的类,例如定义类、构造实例等。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM进行class相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-class.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -|:------------------------------------------------------------------:|:------------------------------------------------------------------:| -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -defineclass/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -newinstance/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -removewrap/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutClass > .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/JsvmUsageGuide/JsvmAboutClass/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/build-profile.json5 deleted file mode 100755 index 31b64e85fc254a9eba5e8c5601de3969a6c8b88d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/build-profile.json5 +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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": "newinstance", - "srcPath": "./newinstance", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "defineclass", - "srcPath": "./defineclass", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "removewrap", - "srcPath": "./removewrap", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutClass/defineclass/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/oh-package.json5 deleted file mode 100755 index 81dff615f819d1aeebec06e1b13c761afef5c775..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "defineclass", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libdefineclass.so": "file:./src/main/cpp/types/libdefineclass" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/CMakeLists.txt deleted file mode 100755 index d4e489efa7d736766026802f0b1bac115495bc77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutClass) - -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(defineclass SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(defineclass PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/hello.cpp deleted file mode 100755 index d12f29d6111357c2de827b6851b94143b05a2e40..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/hello.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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" -// [Start oh_jsvm_defineclass] -#include -// [StartExclude oh_jsvm_defineclass] -#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) -// [EndExclude oh_jsvm_defineclass] - -JSVM_Value CreateInstance(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value newTarget; - // 获取构造函数的new.target值 - JSVM_CALL(OH_JSVM_GetNewTarget(env, info, &newTarget)); - OH_LOG_INFO(LOG_APP, "Create Instance"); - OH_LOG_INFO(LOG_APP, - "NAPI MyObject::New %{public}s", - newTarget != nullptr ? "newTarget != nullptr" : "newTarget == nullptr"); - JSVM_Value jsObject = nullptr; - JSVM_CALL(OH_JSVM_CreateObject(env, &jsObject)); - JSVM_Value jsName = nullptr; - JSVM_CALL(OH_JSVM_CreateStringUtf8(env, "name", JSVM_AUTO_LENGTH, &jsName)); - JSVM_Value jsValue = nullptr; - JSVM_CALL(OH_JSVM_CreateStringUtf8(env, "lilei", JSVM_AUTO_LENGTH, &jsValue)); - JSVM_CALL(OH_JSVM_SetProperty(env, jsObject, jsName, jsValue)); - return jsObject; -} - -std::string ToString(JSVM_Env env, JSVM_Value val) -{ - JSVM_Value jsonString; - JSVM_CALL(OH_JSVM_JsonStringify(env, val, &jsonString)); - size_t totalLen = 0; - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, nullptr, 0, &totalLen)); - size_t needLen = totalLen + 1; - char* buff = new char[needLen]; - std::memset(buff, 0, needLen); - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, buff, needLen, &totalLen)); - std::string str(buff); - delete[] buff; - return str; -} - -// 封装c++中的自定义数据结构 -JSVM_Value DefineClass(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_CallbackStruct param; - param.data = nullptr; - param.callback = CreateInstance; - JSVM_Value cons; - // 用于在JavaScript中定义一个类 - JSVM_CALL(OH_JSVM_DefineClass(env, "MyObject", JSVM_AUTO_LENGTH, ¶m, 0, nullptr, &cons)); - JSVM_Value instanceValue = nullptr; - // 作为class的构造函数调用 - JSVM_CALL(OH_JSVM_NewInstance(env, cons, 0, nullptr, &instanceValue)); - std::string str = ToString(env, instanceValue); - OH_LOG_INFO(LOG_APP, "NewInstance:%{public}s", str.c_str()); - - // 作为普通的函数调用 - JSVM_Value global; - JSVM_CALL(OH_JSVM_GetGlobal(env, &global)); - JSVM_Value key; - JSVM_CALL(OH_JSVM_CreateStringUtf8(env, "Constructor", JSVM_AUTO_LENGTH, &key)); - JSVM_CALL(OH_JSVM_SetProperty(env, global, key, cons)); - JSVM_Value result; - JSVM_CALL(OH_JSVM_CallFunction(env, global, cons, 0, nullptr, &result)); - std::string buf = ToString(env, result); - OH_LOG_INFO(LOG_APP, "NewInstance:%{public}s", buf.c_str()); - return nullptr; -} - -// 注册DefineClass的方法 -JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = DefineClass}, -}; - -static JSVM_CallbackStruct *method = param; - -// DefineClass方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"defineClass", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// [End oh_jsvm_defineclass] - -const char *SRC_CALL_NATIVE = R"JS( defineClass(); )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 = "defineclass", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/oh-package.json5 deleted file mode 100755 index d6f41bb5341b986f8776557f1857b49f49a6215b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/cpp/types/libdefineclass/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libdefineclass.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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/pages/Index.ets deleted file mode 100755 index 9038232de90a1b2c14dee815439fda59d8f57cd4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libdefineclass.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/module.json5 deleted file mode 100755 index ec48d787bca4f8cbb63b5bd61aa0b42f7214d841..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "defineclass", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "DefineclassAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "DefineclassAbility", - "srcEntry": "./ets/defineclassability/DefineclassAbility.ets", - "description": "$string:DefineclassAbility_desc", - "icon": "$media:layered_image", - "label": "$string:DefineclassAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/module.json5 deleted file mode 100755 index d4e8cded069d4730c5cac8a110cd1c8363b397ec..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/defineclass/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "defineclass_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/newinstance/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutClass/newinstance/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/oh-package.json5 deleted file mode 100755 index aa232b128555d24d59eff133730077367e58c32b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "newinstance", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libnewinstance.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 30433259d42bfb20e4141ee383a7ab3ecb79e3c1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutClass) - -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(newinstance SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(newinstance PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/hello.cpp deleted file mode 100755 index 6cf85832d08e09fc7401800dc12bc637dc5b4b71..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/hello.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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" -// [Start oh_jsvm_newinstance] -#include -// [StartExclude oh_jsvm_newinstance] -#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) -// [EndExclude oh_jsvm_newinstance] - -std::string ToString(JSVM_Env env, JSVM_Value val) -{ - JSVM_Value jsonString; - JSVM_CALL(OH_JSVM_JsonStringify(env, val, &jsonString)); - size_t totalLen = 0; - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, nullptr, 0, &totalLen)); - size_t needLen = totalLen + 1; - char* buff = new char[needLen]; - std::memset(buff, 0, needLen); - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, buff, needLen, &totalLen)); - std::string str(buff); - delete[] buff; - return str; -} - -// OH_JSVM_NewInstance的样例方法 -static JSVM_Value NewInstance(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); - JSVM_Value result = nullptr; - // 调用OH_JSVM_NewInstance接口,实例化一个对象,将这个对象返回 - JSVM_CALL(OH_JSVM_NewInstance(env, args[0], 1, &args[1], &result)); - std::string str = ToString(env, result); - OH_LOG_INFO(LOG_APP, "NewInstance:%{public}s", str.c_str()); - return nullptr; -} - -// 通过给定的构造函数,构建一个实例。 -// NewInstance注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = NewInstance}, -}; - -static JSVM_CallbackStruct *method = param; - -// NewInstance方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"newInstance", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// [End oh_jsvm_newinstance] - -const char *SRC_CALL_NATIVE = R"JS( function Fruit(name) { this.name = name; } newInstance(Fruit, "apple"); )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 = "newinstance", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index d5493ca971eabb4091d4e1489cba19510097ba94..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libnewinstance.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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/pages/Index.ets deleted file mode 100755 index b14cc2db21b4a9189edff03a122d794d3ea422b8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libnewinstance.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/module.json5 deleted file mode 100755 index 031e8f89eb93b5e7854468efbb3b21a3c7090b15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "newinstance", - "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/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/module.json5 deleted file mode 100755 index 0871f6c08f3ac6fd9174f5127841e8ab374b1149..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/newinstance/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "newinstance_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/ohosTest.md deleted file mode 100755 index 0eea433059a6e97cfe83d712951654c273a580ea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/ohosTest.md +++ /dev/null @@ -1,10 +0,0 @@ -# JsvmAboutClass 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -|------------------------------------| ------------ |------------------------| ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 在JavaScript中定义一个类,并与对应的C类进行封装和交互 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 通过给定的构造函数,构建一个实例 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 解包先前封装在JavaScript对象中的原生实例并释放封装 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutClass/removewrap/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/oh-package.json5 deleted file mode 100755 index 9db3e411decea65bb22d7f283248f938d3130d25..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "removewrap", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libremovewrap.so": "file:./src/main/cpp/types/libremovewrap" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/CMakeLists.txt deleted file mode 100755 index ecd841228b066d9c539618b2b90a0bf6950ec8f1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutClass) - -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(removewrap SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(removewrap PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/hello.cpp deleted file mode 100755 index b5875b48b128392bfcc5d9392a0cada3e2376889..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/hello.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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" -// [Start oh_jsvm_removewrap] -#include -// [StartExclude oh_jsvm_removewrap] -#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) -// [EndExclude oh_jsvm_removewrap] - -// OH_JSVM_GetNewTarget、OH_JSVM_DefineClass、OH_JSVM_Wrap、OH_JSVM_Unwrap、OH_JSVM_RemoveWrap的样例方法 - -// 自定义类结构体Object -struct Object { - std::string name; - int32_t age; -}; - -// 定义一个回调函数 -static void DerefItem(JSVM_Env env, void *data, void *hint) -{ - OH_LOG_INFO(LOG_APP, "JSVM deref_item"); - (void)hint; -} - -static JSVM_Value WrapObject(JSVM_Env env, JSVM_CallbackInfo info) -{ - OH_LOG_INFO(LOG_APP, "JSVM wrap"); - Object obj; - // 设置Object属性 - obj.name = "lilei"; - const int adultAge = 18; - obj.age = adultAge; - Object *objPointer = &obj; - // 获取回调信息中的参数数量和将要被封装的值 - size_t argc = 1; - JSVM_Value toWrap = nullptr; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, &toWrap, nullptr, nullptr)); - // OH_JSVM_Wrap将自定义结构Object进行封装 - JSVM_CALL(OH_JSVM_Wrap(env, toWrap, reinterpret_cast(objPointer), DerefItem, NULL, NULL)); - Object *data; - // OH_JSVM_UnWrap解包先前封装在JavaScript对象中的原生实例 - JSVM_CALL(OH_JSVM_Unwrap(env, toWrap, reinterpret_cast(&data))); - OH_LOG_INFO(LOG_APP, "JSVM name: %{public}s", data->name.c_str()); - OH_LOG_INFO(LOG_APP, "JSVM age: %{public}d", data->age); - return nullptr; -} - -static JSVM_Value RemoveWrap(JSVM_Env env, JSVM_CallbackInfo info) -{ - OH_LOG_INFO(LOG_APP, "JSVM removeWrap"); - Object obj; - // 设置Object属性 - obj.name = "lilei"; - const int adultAge = 18; - obj.age = adultAge; - Object *objPointer = &obj; - // 获取回调信息中的参数数量和将要被封装的值 - size_t argc = 1; - JSVM_Value toWrap = nullptr; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, &toWrap, nullptr, nullptr)); - // 将自定义结构Object封装 - JSVM_CALL(OH_JSVM_Wrap(env, toWrap, reinterpret_cast(objPointer), DerefItem, NULL, NULL)); - Object *data; - // 解包先前封装的object,并移除封装 - JSVM_CALL(OH_JSVM_RemoveWrap(env, toWrap, reinterpret_cast(&objPointer))); - // 检查是否已被移除 - JSVM_Status status = OH_JSVM_Unwrap(env, toWrap, reinterpret_cast(&data)); - if (status != JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_RemoveWrap success"); - } - return nullptr; -} - -// WrapObject、RemoveWrap注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = WrapObject}, - {.data = nullptr, .callback = RemoveWrap}, -}; -static JSVM_CallbackStruct *method = param; -// WrapObject、RemoveWrap方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"wrapObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - {"removeWrap", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// [End oh_jsvm_removewrap] - -const char *SRC_CALL_NATIVE = R"JS( class Obj {}; wrapObject(new Obj()); removeWrap(new Obj()); )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 = "removewrap", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/oh-package.json5 deleted file mode 100755 index 3907e7f0b121140fa8986c15c2d8e6002280f763..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/cpp/types/libremovewrap/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libremovewrap.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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/pages/Index.ets deleted file mode 100755 index 923196f81b18e8d2f6c932004eb0bc503bc58e5d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libremovewrap.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/module.json5 deleted file mode 100755 index 3df97ea0c1bacbda237401224684a916516b854b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "removewrap", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "RemovewrapAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "RemovewrapAbility", - "srcEntry": "./ets/removewrapability/RemovewrapAbility.ets", - "description": "$string:RemovewrapAbility_desc", - "icon": "$media:layered_image", - "label": "$string:RemovewrapAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/module.json5 deleted file mode 100755 index 21f6f9895d4c0ce47de08fb9fef465d2b9615750..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutClass/removewrap/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "removewrap_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutDate/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/app.json5 deleted file mode 100755 index 946196578487ff1d9a968a7b2ad5e70311298c4d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutdate", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/element/string.json deleted file mode 100755 index 4c140066d6597c9254e0b7dc9b7d4349bdf9e4db..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutDate" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/README.md deleted file mode 100755 index 052e3de06dbc59ce215a2946519150cddf4f6dec..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/README.md +++ /dev/null @@ -1,113 +0,0 @@ -# ArkTS使用JSVM-API接口进行Date相关开发 - -### 介绍 - -JSVM-API中date相关接口用于处理JavaScript Date对象,并在JSVM模块和JavaScript代码之间进行日期数据的转换和处理。这对于在JSVM模块中处理时间和日期相关逻辑非常有用。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行Date相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-date.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :---------------------------------------------------------------: | :---------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createdate/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getdatevalue/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -isdate/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutDate > .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/JsvmUsageGuide/JsvmAboutDate/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/build-profile.json5 deleted file mode 100755 index f21d0c342cb31410ee3d1de43802e224e3bd2a25..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/build-profile.json5 +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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": "createdate", - "srcPath": "./createdate", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getdatevalue", - "srcPath": "./getdatevalue", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "isdate", - "srcPath": "./isdate", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/createdate/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutDate/createdate/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/createdate/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutDate/createdate/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/oh-package.json5 deleted file mode 100755 index ba430b17251df16a137ecc8aec1e2047b47931db..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createdate", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatedate.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b767168144786236d1b9e010b5b2c3a591018bab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutDate) - -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(createdate SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createdate PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/hello.cpp deleted file mode 100755 index 9f3162b40b8f42fd789069750900c4d05b41ea6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/hello.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_date] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -#include -// [StartExclude oh_jsvm_create_date] -#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) -// [EndExclude oh_jsvm_create_date] - -// OH_JSVM_CreateDate的样例方法 -static JSVM_Value CreateDate(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 通过c接口获取Unix纪元以来经过的秒数,并转化为毫秒数为单位 - double value = static_cast(time(nullptr) * 1000); - // 调用OH_JSVM_CreateDate接口将double值转换成表示日期时间的JavaScript值返回出去 - JSVM_Value returnValue = nullptr; - - JSVM_CALL(OH_JSVM_CreateDate(env, value, &returnValue)); - - bool isDate; - JSVM_CALL(OH_JSVM_IsDate(env, returnValue, &isDate)); - if (isDate == false) { - OH_LOG_ERROR(LOG_APP, "JSVM IsDate fail"); - return returnValue; - } - - value = 0; - JSVM_CALL(OH_JSVM_GetDateValue(env, returnValue, &value)); - - uint64_t time = static_cast(value) / 1000; - char *date = ctime(reinterpret_cast(&time)); - OH_LOG_INFO(LOG_APP, "JSVM CreateDate success:%{public}s", date); - - return returnValue; -} - -// CreateDate注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateDate}, -}; -static JSVM_CallbackStruct *method = param; -// CreateDate方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createDate", nullptr, method, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(createDate())JS"; -// [End oh_jsvm_create_date] - -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 = "createdate", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index ecdf0a0890f8ebbdb8a1fcad2ac1440a9d78f78a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatedate.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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/pages/Index.ets deleted file mode 100755 index 49705bc91e42757175a1ea8f3954ce1657fbc109..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatedate.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/module.json5 deleted file mode 100755 index 4fe8e8a71b1ab31cdbad0a8e9f005de06511aa83..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "createdate", - "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/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/string.json deleted file mode 100755 index 7c277b0d7142101b43d3a2e99eb8d2ae77463160..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutDate" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 33f66ded20be0e1bcb6282d35d24120512556e5e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateDate', 0, async (done: Function) => { - console.log('uitest: TestCreateDate 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: TestCreateDate end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/module.json5 deleted file mode 100755 index 479fba6ab54b5e439c66aba8c92e364c0c1ac2ef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/createdate/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createdate_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/oh-package.json5 deleted file mode 100755 index 131758b38988c9dca53ee813289048e77b09cc4d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getdatevalue", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetdatevalue.so": "file:./src/main/cpp/types/libgetdatevalue" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 25203265ca8062d35ceb2dbf34a7b8d037b9b9d1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutDate) - -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(getdatevalue SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getdatevalue PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/hello.cpp deleted file mode 100755 index ea80d807e3c3fb0e3cdf19c63e7a6e10975684fe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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" -// [Stat oh_jsvm_get_date_value] -#include -// [StartExclude oh_jsvm_get_date_value] -#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) -// [EndExclude oh_jsvm_get_date_value] - -// OH_JSVM_GetDateValue的样例方法 -static JSVM_Value GetDateValue(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); - // 获取传入的Unix Time Stamp时间 - double value; - JSVM_CALL(OH_JSVM_GetDateValue(env, args[0], &value)); - - // 将获取到的Unix Time Stamp时间转化为日期字符串打印 - uint64_t time = static_cast(value) / 1000; - char *date = ctime(reinterpret_cast(&time)); - OH_LOG_INFO(LOG_APP, "JSVM GetDateValue success:%{public}s", date); - - JSVM_Value returnValue = nullptr; - JSVM_CALL(OH_JSVM_CreateDouble(env, value, &returnValue)); - return returnValue; -} - -// CreateDate注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetDateValue}, -}; -static JSVM_CallbackStruct *method = param; -// CreateDate方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getDateValue", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(getDateValue(new Date(Date.now())))JS"; -// [End oh_jsvm_get_date_value] - -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 = "getdatevalue", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/oh-package.json5 deleted file mode 100755 index 60b9e733b79cb4d34ae79824d01964d226e6cec9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/cpp/types/libgetdatevalue/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetdatevalue.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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/pages/Index.ets deleted file mode 100755 index e640483145d5a192efc1f561daac7d9507a806ac..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetdatevalue.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/module.json5 deleted file mode 100755 index 57141d1fcd9a2307e400b8587b94a978764f8cf2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getdatevalue", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetdatevalueAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetdatevalueAbility", - "srcEntry": "./ets/getdatevalueability/GetdatevalueAbility.ets", - "description": "$string:GetdatevalueAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetdatevalueAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/string.json deleted file mode 100755 index 9bc8a91530d64aa18752a1bb2e1a6ffb2011ea2e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetdatevalueAbility_desc", - "value": "description" - }, - { - "name": "GetdatevalueAbility_label", - "value": "JsvmAboutDate" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 5c01d454c99c12b7b5532d4ef3a0a006c5cabbe4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetDateValue', 0, async (done: Function) => { - console.log('uitest: TestGetDateValue begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetdatevalueAbility' - } - 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('GetdatevalueAbility'); - - 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: TestGetDateValue end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/module.json5 deleted file mode 100755 index a6d1eaeb4f585cd848b79caf7b78bf160e24916a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/getdatevalue/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getdatevalue_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/isdate/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutDate/isdate/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/isdate/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutDate/isdate/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/oh-package.json5 deleted file mode 100755 index 044f1e59f00979c60fed6001b96a9f559a0291ba..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "isdate", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libisdate.so": "file:./src/main/cpp/types/libisdate" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 0759422fb29e4227a7dd6ee1b80932ebbabe6122..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutDate) - -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(isdate SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(isdate PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/hello.cpp deleted file mode 100755 index 97281822a22a4a70c98e961baa454920ed03ff1f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/hello.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_is_date] -// OH_JSVM_IsDate的样例方法 -static JSVM_Value IsDate(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr)); - bool isData; - JSVM_CALL(OH_JSVM_IsDate(env, args[0], &isData)); - OH_LOG_INFO(LOG_APP, "JSVM IsDate success:%{public}d", isData); - - JSVM_Value result = nullptr; - JSVM_CALL(OH_JSVM_GetBoolean(env, isData, &result)); - return result; -} -// CreateDate注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = IsDate}, -}; -static JSVM_CallbackStruct *method = param; -// CreateDate方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"isDate", nullptr, method, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(isDate(new Date(Date.now())))JS"; -// [End oh_jsvm_is_date] - -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 = "isdate", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/Index.d.ts deleted file mode 100755 index 10585337c7aa6add269644b526afd3266d50d61e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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; diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/oh-package.json5 deleted file mode 100755 index 18f3703cd62c1c12b95e8ddf2b91f1d257178299..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/cpp/types/libisdate/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libisdate.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/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/pages/Index.ets deleted file mode 100755 index c922180449255bd228b343a9de50afe9d1124a66..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libisdate.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/module.json5 deleted file mode 100755 index 2765162faf751c84d975265faeb4cf25a0cddc7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "isdate", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IsdateAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IsdateAbility", - "srcEntry": "./ets/isdateability/IsdateAbility.ets", - "description": "$string:IsdateAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IsdateAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/string.json deleted file mode 100755 index 46f7b89b295885dce0bb2e3c0a87e8790ab68023..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IsdateAbility_desc", - "value": "description" - }, - { - "name": "IsdateAbility_label", - "value": "JsvmAboutDate" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index de324b42f7ad41d62b29b5b0739a9126e30385d2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsDate', 0, async (done: Function) => { - console.log('uitest: TestIsDate begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IsdateAbility' - } - 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('IsdateAbility'); - - 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: TestIsDate end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/module.json5 deleted file mode 100755 index 1e0e3716363ae7db929645afde7395108da5c229..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/isdate/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "isdate_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutDate/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/ohosTest.md deleted file mode 100755 index 6c803df2537c9e145ad019996b3c2712aa1cd5b9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutDate/ohosTest.md +++ /dev/null @@ -1,10 +0,0 @@ -# JsvmAboutDate 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 创建了一个表示给定毫秒数的Date对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript Date的时间值的Double基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断一个JavaScript对象是否为Date类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutObject/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/app.json5 deleted file mode 100755 index 2cd6d6c49964ad01ec7192538f5d38ad91b7a6bf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutobject", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/element/string.json deleted file mode 100755 index 5459d567d96e0e654cd30582ad10e192b459e846..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutObject" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/README.md deleted file mode 100755 index 035f3ab236d58fa0d0d34b038e4ce02bb2723921..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/README.md +++ /dev/null @@ -1,273 +0,0 @@ -# ArkTS使用JSVM-API接口进行object相关开发 - -### 介绍 - -使用JSVM-API接口进行object相关开发,处理JavaScript对象的基本操作的功能,例如创建对象、获取原型、冻结和密封对象,检查对象的类型等。这些操作是在处理JavaScript对象时非常常见的,提供了一种与JavaScript对象交互的方式。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行object相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-object.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -checkobjecttypetag/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createexternal/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createobject/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createsymbol/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getprototype/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvalueexternal/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -instanceof/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -objectfreeze/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -objectseal/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -symbolfor/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -typeof/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutObject > .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/JsvmUsageGuide/JsvmAboutObject/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/build-profile.json5 deleted file mode 100755 index 18fd83aa12f9a4106306dc669fe2685c4a9b67e8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/build-profile.json5 +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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": "getprototype", - "srcPath": "./getprototype", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createobject", - "srcPath": "./createobject", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "objectfreeze", - "srcPath": "./objectfreeze", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "objectseal", - "srcPath": "./objectseal", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "typeof", - "srcPath": "./typeof", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "instanceof", - "srcPath": "./instanceof", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "checkobjecttypetag", - "srcPath": "./checkobjecttypetag", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createexternal", - "srcPath": "./createexternal", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvalueexternal", - "srcPath": "./getvalueexternal", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createsymbol", - "srcPath": "./createsymbol", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "symbolfor", - "srcPath": "./symbolfor", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/oh-package.json5 deleted file mode 100755 index ff47b6be87dba8bd186a831dc6edf77c72cf071e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "checkobjecttypetag", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcheckobjecttypetag.so": "file:./src/main/cpp/types/libcheckobjecttypetag" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/CMakeLists.txt deleted file mode 100755 index ac9bca7d701054a719579e088b792579289ea0cb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(checkobjecttypetag SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(checkobjecttypetag PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/hello.cpp deleted file mode 100755 index 05beaffab68ff07d87407db79649a98bb2da0609..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/hello.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_check_object_type_tag] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -#define NUMBERINT_FOUR -// [StartExclude oh_jsvm_check_object_type_tag] -#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) -// [EndExclude oh_jsvm_check_object_type_tag] - -// 定义一个静态常量JSVM_TypeTag数组存储类型标签 -static const JSVM_TypeTag TagsData[NUMBERINT_FOUR] = { - {0x9e4b2449547061b3, 0x33999f8a6516c499}, - {0x1d55a794c53a726d, 0x43633f509f9c944e}, - {0, 0}, // 用于表示无标签或默认标签 - {0x6a971439f5b2e5d7, 0x531dc28a7e5317c0}, -}; -// OH_JSVM_TypeTagObject的样例方法 -static JSVM_Value SetTypeTagToObject(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取两个JavaScript侧传入的参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取索引数字转换为JSVM_Value - int32_t index = 0; - OH_JSVM_GetValueInt32(env, args[1], &index); - // 给参数(对象)设置类型标签 - JSVM_Status status = OH_JSVM_TypeTagObject(env, args[0], &TagsData[index]); - // 将bool结果转换为JSVM_Value并返回 - JSVM_Value result = nullptr; - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM SetTypeTagToObject fail"); - OH_JSVM_GetBoolean(env, false, &result); - } else { - OH_LOG_INFO(LOG_APP, "JSVM SetTypeTagToObject success"); - OH_JSVM_GetBoolean(env, true, &result); - } - return result; -} -// OH_JSVM_CheckObjectTypeTag的样例方法 -static JSVM_Value CheckObjectTypeTag(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取两个JavaScript侧传入的参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取索引数字转换为JSVM_Value - int32_t index = 0; - OH_JSVM_GetValueInt32(env, args[1], &index); - // 检查对象的类型标签 - bool checkResult = false; - JSVM_Status status = OH_JSVM_CheckObjectTypeTag(env, args[0], &TagsData[index], &checkResult); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM SetTypeTagToObject fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM SetTypeTagToObject:%{public}d", checkResult); - } - // 将bool结果转换为JSVM_Value并返回 - JSVM_Value checked = nullptr; - OH_JSVM_GetBoolean(env, checkResult, &checked); - return checked; -} -// SetTypeTagToObject,CheckObjectTypeTag注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = SetTypeTagToObject}, - {.data = nullptr, .callback = CheckObjectTypeTag}, -}; -static JSVM_CallbackStruct *method = param; -// SetTypeTagToObject,CheckObjectTypeTag方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"setTypeTagToObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - {"checkObjectTypeTag", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS( - class Obj { - data; - message; - } - let obj= { data: 0, message: "hello world"}; - setTypeTagToObject(obj, 0); - checkObjectTypeTag(obj, 0);)JS"; -// [End oh_jsvm_check_object_type_tag] - -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 = "checkobjecttypetag", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/oh-package.json5 deleted file mode 100755 index b0f6513e2a7c01d7dc10776b06644272802be113..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/cpp/types/libcheckobjecttypetag/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcheckobjecttypetag.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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/pages/Index.ets deleted file mode 100755 index 08042f2a2f9c44c4c015665827faa679aa0b4974..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcheckobjecttypetag.so'; - -@Entry -@Component -struct Index { - @State message: string = 'OH_JSVM_CheckObjectTypeTag'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/module.json5 deleted file mode 100755 index 7cc3ba1ab69369ad22fb5151dda63998d7f621b1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "checkobjecttypetag", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CheckobjecttypetagAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CheckobjecttypetagAbility", - "srcEntry": "./ets/checkobjecttypetagability/CheckobjecttypetagAbility.ets", - "description": "$string:CheckobjecttypetagAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CheckobjecttypetagAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/string.json deleted file mode 100755 index 0da352112ba23cf4a5c47abdb259db9420cb883c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CheckobjecttypetagAbility_desc", - "value": "description" - }, - { - "name": "CheckobjecttypetagAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 8f274542bbe0412f72969f731e96a86dd80f6eb2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCheckObjectTypeTag', 0, async (done: Function) => { - console.log('uitest: TestCheckObjectTypeTag begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CheckobjecttypetagAbility' - } - 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('CheckobjecttypetagAbility'); - - 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: TestCheckObjectTypeTag end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/module.json5 deleted file mode 100755 index 209bcba3d6ebc377dcf369d947e330e59f02e032..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/checkobjecttypetag/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "checkobjecttypetag_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createexternal/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/createexternal/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createexternal/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/createexternal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/oh-package.json5 deleted file mode 100755 index 924171b7144c364ffaf80e176b865d5a295131cc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createexternal", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreateexternal.so": "file:./src/main/cpp/types/libcreateexternal" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 3d50aec22dbe58848813d264cb96dc927a566c35..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(createexternal SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createexternal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/hello.cpp deleted file mode 100755 index 05da3a82439b26e47de08779035af367fe478316..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/hello.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_external] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -#include -#include -// [StartExclude oh_jsvm_create_external] -#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) -// [EndExclude oh_jsvm_create_external] - -// OH_JSVM_CreateExternal的样例方法 -static JSVM_Value CreateExternal(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t dataSize = 10; - void *data = malloc(dataSize); - if (data == nullptr) { - OH_LOG_ERROR(LOG_APP, "JSVM Failed to malloc."); - return nullptr; - } - memset(data, 0, dataSize); - const char* testStr = "test"; - JSVM_Value external = nullptr; - JSVM_Status status = OH_JSVM_CreateExternal( - env, data, [](JSVM_Env env, void *data, void *hint) {free(data);}, (void *)testStr, &external); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM Failed to create external data, status:%{public}d.", status); - free(data); - data = nullptr; - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateExternal success"); - } - return external; -} -// CreateExternal注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateExternal}, -}; -static JSVM_CallbackStruct *method = param; -// CreateExternal方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createExternal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createExternal())JS"; -// [End oh_jsvm_create_external] - -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 = "createexternal", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/oh-package.json5 deleted file mode 100755 index 936b81b38a1bfc37e7ac39ec0f7c9b480ff4a30d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/cpp/types/libcreateexternal/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreateexternal.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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/pages/Index.ets deleted file mode 100755 index ceb34830ccddee9ddfe5c6efe764466d75034ef9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreateexternal.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/module.json5 deleted file mode 100755 index fc04e247934101629500885b5e2f7855587ce120..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createexternal", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreateexternalAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreateexternalAbility", - "srcEntry": "./ets/createexternalability/CreateexternalAbility.ets", - "description": "$string:CreateexternalAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreateexternalAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/string.json deleted file mode 100755 index ff9902b3b94972f9354052c4c688fa8d77c8d3ff..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreateexternalAbility_desc", - "value": "description" - }, - { - "name": "CreateexternalAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index b81e1ce2d612e17bfc77b3b1ab9317b4a30cf198..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateExternal', 0, async (done: Function) => { - console.log('uitest: TestCreateExternal begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreateexternalAbility' - } - 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('CreateexternalAbility'); - - 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: TestCreateExternal end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/module.json5 deleted file mode 100755 index fa0252cf174992e06ab099a8b4f1de9db9ec517d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createexternal/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createexternal_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/createobject/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createobject/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/createobject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/oh-package.json5 deleted file mode 100755 index 2b2930c1346312b3a309b0d746430da6c67db041..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createobject", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreateobject.so": "file:./src/main/cpp/types/libcreateobject" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 76f5f2056516361e1e48270914ab9a624f013fe3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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(createobject SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createobject PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/hello.cpp deleted file mode 100755 index 50bcb17a2a2466812c4fee37225a5173bbb5a9da..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/hello.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_object] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_create_object] -#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) -// [EndExclude oh_jsvm_create_object] - -// OH_JSVM_CreateObject的样例方法 -static JSVM_Value CreateObject(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value object = nullptr; - // 创建一个空对象 - JSVM_Status status = OH_JSVM_CreateObject(env, &object); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateObject fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateObject success"); - } - // 设置对象的属性 - JSVM_Value name = nullptr; - // 设置属性名为 "name" - OH_JSVM_CreateStringUtf8(env, "name", JSVM_AUTO_LENGTH, &name); - JSVM_Value value = nullptr; - // 设置属性值为 "Hello from N-API!" - OH_JSVM_CreateStringUtf8(env, "Hello OH_JSVM_CreateObject!", JSVM_AUTO_LENGTH, &value); - // 将属性设置到对象上 - OH_JSVM_SetProperty(env, object, name, value); - return object; -} -// CreateObject注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateObject}, -}; -static JSVM_CallbackStruct *method = param; -// CreateObject方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createObject())JS"; -// [End oh_jsvm_create_object] - -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 = "createobject", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/oh-package.json5 deleted file mode 100755 index 28d2121b361abf4b0315b82cdd68226e2e522116..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/cpp/types/libcreateobject/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreateobject.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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/pages/Index.ets deleted file mode 100755 index 4b46c6078ec4b003132e997283d740f4270f3fe7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreateobject.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/module.json5 deleted file mode 100755 index 95badc6f52d5c048de1689db4ae675f3b955d9b7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createobject", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreateobjectAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreateobjectAbility", - "srcEntry": "./ets/createobjectability/CreateobjectAbility.ets", - "description": "$string:CreateobjectAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreateobjectAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/string.json deleted file mode 100755 index 41bc46c4098e02accaa892c09b1a0bd17bdcd731..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreateobjectAbility_desc", - "value": "description" - }, - { - "name": "CreateobjectAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index ff12b3182c9ff42739b8d31d11c12bb5077223a9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateObject', 0, async (done: Function) => { - console.log('uitest: TestCreateObject begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreateobjectAbility' - } - 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('CreateobjectAbility'); - - 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: TestCreateObject end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/module.json5 deleted file mode 100755 index c43374ad962205c18d0a376751c9d2153a8e5b23..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createobject/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createobject_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/createsymbol/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createsymbol/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/createsymbol/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/oh-package.json5 deleted file mode 100755 index f9241794e7768f0bededc2955d8004925274ea74..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createsymbol", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatesymbol.so": "file:./src/main/cpp/types/libcreatesymbol" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 5fdefb94c9cf18209e20adcb0b64ddedc485a4f8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(createsymbol SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createsymbol PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/hello.cpp deleted file mode 100755 index 5cb03169be60991b50eb99ea8ccd3f612b0ff94e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_symbol] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -// [StartExclude oh_jsvm_create_symbol] -#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) -// [EndExclude oh_jsvm_create_symbol] - -// OH_JSVM_CreateSymbol的样例方法 -static JSVM_Value CreateSymbol(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value result = nullptr; - const char *des = "only"; - OH_JSVM_CreateStringUtf8(env, des, JSVM_AUTO_LENGTH, &result); - JSVM_Value returnSymbol = nullptr; - OH_JSVM_CreateSymbol(env, result, &returnSymbol); - JSVM_ValueType valuetypeSymbol; - OH_JSVM_Typeof(env, returnSymbol, &valuetypeSymbol); - if (valuetypeSymbol == JSVM_SYMBOL) { - OH_LOG_INFO(LOG_APP, "JSVM CreateSymbol Success"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateSymbol fail"); - } - return returnSymbol; -} -// CreateSymbol注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateSymbol}, -}; -static JSVM_CallbackStruct *method = param; -// CreateSymbol方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createSymbol", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createSymbol())JS"; -// [End oh_jsvm_create_symbol] - -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 = "createsymbol", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/oh-package.json5 deleted file mode 100755 index 33b3466c203f0bd14c4c0d675c9add35e35008b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/cpp/types/libcreatesymbol/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatesymbol.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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/pages/Index.ets deleted file mode 100755 index 09a6c90b63106cc2cd0141aee2508c55e8ac5f1b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatesymbol.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/module.json5 deleted file mode 100755 index 597c39a146ae702e0573d15d36bbba0cb5b27c6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createsymbol", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatesymbolAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatesymbolAbility", - "srcEntry": "./ets/createsymbolability/CreatesymbolAbility.ets", - "description": "$string:CreatesymbolAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatesymbolAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/string.json deleted file mode 100755 index 1c3a873a7c3c021a4b5986f858627a3bef253ffd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatesymbolAbility_desc", - "value": "description" - }, - { - "name": "CreatesymbolAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index cbc209eb1a081b000c85f51b624c25fb3c663426..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateSymbol', 0, async (done: Function) => { - console.log('uitest: TestCreateSymbol begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatesymbolAbility' - } - 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('CreatesymbolAbility'); - - 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: TestCreateSymbol end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/module.json5 deleted file mode 100755 index 5eed50482497d1b72c9f2ea8d5fa2ad698199cb2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/createsymbol/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createsymbol_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/getprototype/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getprototype/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/getprototype/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/oh-package.json5 deleted file mode 100755 index 05877d47466a65461e3938a23cfa7bed2d5f590c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getprototype", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetprototype.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 367da72ea09350129e4ee1c45c53732997d9f99a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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(getprototype SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getprototype PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/hello.cpp deleted file mode 100755 index d3aea8acd04f1ea5c72da3fc34f2ffd0546505d9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_prototype] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -// [StartExclude oh_jsvm_get_prototype] -#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) -// [EndExclude oh_jsvm_get_prototype] - -// GetPrototype注册回调 -// OH_JSVM_GetPrototype的样例方法 -static JSVM_Value GetPrototype(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - JSVM_Value result{nullptr}; - JSVM_Status status = OH_JSVM_GetPrototype(env, argv[0], &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetPrototype fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetPrototype success"); - } - return result; -} -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetPrototype}, -}; -static JSVM_CallbackStruct *method = param; -// GetPrototype方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getPrototype", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(const myObject = {}; - const proto = getPrototype(myObject); - console.log(proto === Object.prototype);)JS"; -// [End oh_jsvm_get_prototype] - -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 = "getprototype", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 277a4d031c624efc9975e6e71fee0b035de1bd9a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetprototype.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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/pages/Index.ets deleted file mode 100755 index a39b49aab56236c7404d1c14fcc6c7b01456bbe8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetprototype.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/module.json5 deleted file mode 100755 index 26760a7cf91a179f8c27df14e334b33730c3f30a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getprototype", - "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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/string.json deleted file mode 100755 index b9929ce09cb8fc121aa108b294bf206922e77948..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 0e0f8708783cb4e346ec6fae36f4cadd7c69d3a5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetPrototype', 0, async (done: Function) => { - console.log('uitest: TestGetPrototype 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: TestGetPrototype end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/module.json5 deleted file mode 100755 index d4eaf9addd4026c9a292577907dd53c4156f1caf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getprototype/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getprototype_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/oh-package.json5 deleted file mode 100755 index 78ec1d9aa1bb1bac8f5edc3cfd49215ff6eb7142..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvalueexternal", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvalueexternal.so": "file:./src/main/cpp/types/libgetvalueexternal" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 190651fdb59318321adb643759fbce192792b5be..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(getvalueexternal SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvalueexternal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/hello.cpp deleted file mode 100755 index 3416d4d9fad75af1c7450f8e3472870bc61eb3cb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/hello.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_external] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_value_external] -#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) -// [EndExclude oh_jsvm_get_value_external] - -// OH_JSVM_GetValueExternal的样例方法 -static JSVM_Value GetValueExternal(JSVM_Env env, JSVM_CallbackInfo info) -{ - static int data = 0x12345; - JSVM_Value externalValue = nullptr; - JSVM_Status status = OH_JSVM_CreateExternal(env, (void*)&data, nullptr, nullptr, &externalValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CreateExternal fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CreateExternal success"); - } - void *dataValue; - status = OH_JSVM_GetValueExternal(env, externalValue, &dataValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueExternal fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueExternal success"); - } - // 将符号位转化为int类型传出去 - JSVM_Value returnValue = nullptr; - int retData = *static_cast(dataValue); - OH_JSVM_CreateInt32(env, retData, &returnValue); - return returnValue; -} -// GetValueExternal注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueExternal}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueExternal方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueExternal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getValueExternal())JS"; -// [End oh_jsvm_get_value_external] - -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 = "getvalueexternal", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/oh-package.json5 deleted file mode 100755 index 8bc81701072ee3ad7bc89ed69a9a24cd1005d9fe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/cpp/types/libgetvalueexternal/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvalueexternal.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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/pages/Index.ets deleted file mode 100755 index 3d23b7a8b09baf513c33b94fa1da92b22770afde..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvalueexternal.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/module.json5 deleted file mode 100755 index 04d2006a87ee963a98647503cf6411b5c4e7fb30..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvalueexternal", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetvalueexternalAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetvalueexternalAbility", - "srcEntry": "./ets/getvalueexternalability/GetvalueexternalAbility.ets", - "description": "$string:GetvalueexternalAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetvalueexternalAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/string.json deleted file mode 100755 index 418b7f6b879824bc6a1f7db0b3533ac328851bfe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetvalueexternalAbility_desc", - "value": "description" - }, - { - "name": "GetvalueexternalAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 7386629c99318f58c8aee5d4087ce8d3110e5ab5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueExternal', 0, async (done: Function) => { - console.log('uitest: TestGetValueExternal begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetvalueexternalAbility' - } - 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('GetvalueexternalAbility'); - - 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: TestGetValueExternal end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/module.json5 deleted file mode 100755 index 73e07eb435fa330289da44119e6cbf764672f1b4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/getvalueexternal/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvalueexternal_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/instanceof/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/instanceof/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/instanceof/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/instanceof/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/oh-package.json5 deleted file mode 100755 index 99ced34fac25b9c032780f00c925a2511da8c465..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "instanceof", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libinstanceof.so": "file:./src/main/cpp/types/libinstanceof" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/CMakeLists.txt deleted file mode 100755 index dac25731fd61de85ce0e500dc68b0f6742b9f0f2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(instanceof SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(instanceof PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/hello.cpp deleted file mode 100755 index 55c02be3ad03ce570c85effb46929681064c08f2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/hello.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_instanceof] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_instanceof] -#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) -// [EndExclude oh_jsvm_instanceof] - -// OH_JSVM_Instanceof的样例方法 -static JSVM_Value InstanceOf(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取两个JavaScript侧传入的参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - bool result = false; - JSVM_Status status = OH_JSVM_Instanceof(env, args[0], args[1], &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM InstanceOf fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM InstanceOf:%{public}d", result); - } - JSVM_Value returnValue = nullptr; - OH_JSVM_GetBoolean(env, result, &returnValue); - return returnValue; -} -// InstanceOf注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = InstanceOf}, -}; -static JSVM_CallbackStruct *method = param; -// InstanceOf方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"instanceOf", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(class Person { - name; - age; - constructor(name, age) { - this.name = name; - this.age = age; - } - } - instanceOf(new Person('Alice', 30), Person); - ;)JS"; -// [End oh_jsvm_instanceof] - -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 = "instanceof", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/oh-package.json5 deleted file mode 100755 index 47bff799db312f9b70ca982e0ef4d76cd7064960..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/cpp/types/libinstanceof/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libinstanceof.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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/pages/Index.ets deleted file mode 100755 index 1bff49246c679eb73cdc7ee4df0f2ada6bd47194..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libinstanceof.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/module.json5 deleted file mode 100755 index 0432702469bb854f852f96c94267e9ab7db7759b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "instanceof", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "InstanceofAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "InstanceofAbility", - "srcEntry": "./ets/instanceofability/InstanceofAbility.ets", - "description": "$string:InstanceofAbility_desc", - "icon": "$media:layered_image", - "label": "$string:InstanceofAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/string.json deleted file mode 100755 index 1b566a233e96d6f515d103f78af00e2e914a8835..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "InstanceofAbility_desc", - "value": "description" - }, - { - "name": "InstanceofAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 44cf3969e32c2fdf50a1a31c7fc724468245b8ee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testInstanceof', 0, async (done: Function) => { - console.log('uitest: TestInstanceof begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'InstanceofAbility' - } - 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('InstanceofAbility'); - - 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: TestInstanceof end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/module.json5 deleted file mode 100755 index e0864982564f73af1ddad88f83de8e7b51de007e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/instanceof/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "instanceof_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/oh-package.json5 deleted file mode 100755 index 6c5d6d8055d6e04f96b18739b6f4e1f08cb0294f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "objectfreeze", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libobjectfreeze.so": "file:./src/main/cpp/types/libobjectfreeze" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 8a241f55fe6fab0de55293f988a6a7a5187b81f8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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(objectfreeze SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(objectfreeze PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/hello.cpp deleted file mode 100755 index 88611d7f8d5c476c73fab0beebae90a62017d63f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_object_freeze] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_object_freeze] -#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) -// [EndExclude oh_jsvm_object_freeze] - -// OH_JSVM_ObjectFreeze的样例方法 -const int FREEZE_TEST_VALUE = 111111; -static JSVM_Value ObjectFreeze(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 接受一个JavaScript侧传入的object - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - // 调用接口OH_JSVM_ObjectFreeze将传入的object冻结 - JSVM_Status status = OH_JSVM_ObjectFreeze(env, argv[0]); - if (status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "Test JSVM OH_JSVM_ObjectFreeze success"); - } - // 测试冻结后的对象中属性能否修改 - JSVM_Value value = nullptr; - OH_JSVM_CreateInt32(env, FREEZE_TEST_VALUE, &value); - OH_JSVM_SetNamedProperty(env, argv[0], "data", value); - // 将冻结后修改过的属性返回JavaScript侧 - return argv[0]; -} -// ObjectFreeze注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = ObjectFreeze}, -}; -static JSVM_CallbackStruct *method = param; -// ObjectFreeze方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"objectFreeze", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(let obj = { data: 55, message: "hello world"}; - objectFreeze(obj))JS"; -// [End oh_jsvm_object_freeze] - -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 = "objectfreeze", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/oh-package.json5 deleted file mode 100755 index aa691d9a9bc9516d782bfeab9be6050815c3c9d2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/cpp/types/libobjectfreeze/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libobjectfreeze.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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/pages/Index.ets deleted file mode 100755 index 1ac7898a595a0382295b42946e1399762c0e7f73..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libobjectfreeze.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/module.json5 deleted file mode 100755 index 49aaac4234a97d5dc36e34ea63910db3e8699804..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "objectfreeze", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ObjectfreezeAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ObjectfreezeAbility", - "srcEntry": "./ets/objectfreezeability/ObjectfreezeAbility.ets", - "description": "$string:ObjectfreezeAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ObjectfreezeAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/string.json deleted file mode 100755 index 0682ce8e28a7e1a1ded7f3583dce5548652829cc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ObjectfreezeAbility_desc", - "value": "description" - }, - { - "name": "ObjectfreezeAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index c06f07000ba8c2c5188cfef6925c407ba194e6f4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testObjectFreeze', 0, async (done: Function) => { - console.log('uitest: TestObjectFreeze begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ObjectfreezeAbility' - } - 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('ObjectfreezeAbility'); - - 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: TestObjectFreeze end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/module.json5 deleted file mode 100755 index 356c9ada0595c9a2902b1a626a5e9a161fc53b83..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectfreeze/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "objectfreeze_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/objectseal/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/objectseal/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/objectseal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/oh-package.json5 deleted file mode 100755 index e2c814ce9b3af6a676222731e29b698543e61435..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "objectseal", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libobjectseal.so": "file:./src/main/cpp/types/libobjectseal" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 2915cd52c1590757ea4f546d8189439a0b502d87..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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(objectseal SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(objectseal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/hello.cpp deleted file mode 100755 index 7a4fbd541b4d11a0f12fca6dd784a73c26b82f76..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/hello.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_object_seal] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_object_seal] -#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) -// [EndExclude oh_jsvm_object_seal] - -// OH_JSVM_ObjectSeal的样例方法 -const int TEST_VALUE = 111111; -static JSVM_Value ObjectSeal(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 接受一个JavaScript侧传入的object - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - // 调用接口OH_JSVM_ObjectSeal将传入的object封闭,使其无法添加新的属性 - JSVM_Status status = OH_JSVM_ObjectSeal(env, argv[0]); - if (status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "Test JSVM OH_JSVM_ObjectSeal success"); - } - // 检查封闭后的对象中属性能否修改、删除、新增 - // 封闭后对象修改 - JSVM_Value changeValue = nullptr; - OH_JSVM_CreateInt32(env, TEST_VALUE, &changeValue); - OH_JSVM_SetNamedProperty(env, argv[0], "data", changeValue); - // 封闭后对象删除 - JSVM_Value deleteProperty = nullptr; - OH_JSVM_CreateStringUtf8(env, "message", JSVM_AUTO_LENGTH, &deleteProperty); - bool result = false; - OH_JSVM_DeleteProperty(env, argv[0], deleteProperty, &result); - if (result) { - OH_LOG_INFO(LOG_APP, "Test JSVM OH_JSVM_ObjectSeal failed"); - } - // 封闭后对象新增 - JSVM_Value addValue = nullptr; - OH_JSVM_CreateStringUtf8(env, "addValue", JSVM_AUTO_LENGTH, &addValue); - OH_JSVM_SetNamedProperty(env, argv[0], "newProperty", addValue); - // 将封闭后改动过的对象返回JavaScript侧 - return argv[0]; -} -// ObjectSeal注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = ObjectSeal}, -}; -static JSVM_CallbackStruct *method = param; -// ObjectSeal方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"objectSeal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS( let obj = { data: 55, message: "hello world"}; - objectSeal(obj))JS"; -// [End oh_jsvm_object_seal] - -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 = "objectseal", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/oh-package.json5 deleted file mode 100755 index ef92118a40cbb8e2912c01cb619f2f4479a01fa0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/cpp/types/libobjectseal/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libobjectseal.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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/pages/Index.ets deleted file mode 100755 index 7d21d553ce739e5cb8d792d11f0244f1209869cd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libobjectseal.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/module.json5 deleted file mode 100755 index 8fbf4fecf084ee1bc96bf5fdb94c0481ed5521a4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "objectseal", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ObjectsealAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ObjectsealAbility", - "srcEntry": "./ets/objectsealability/ObjectsealAbility.ets", - "description": "$string:ObjectsealAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ObjectsealAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/string.json deleted file mode 100755 index 833d0f016e919c1d30d5d882726f0e1f437ff59b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ObjectsealAbility_desc", - "value": "description" - }, - { - "name": "ObjectsealAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 1cc6ea6bcbfc156fe7be021478ab6ec1aa1275b7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testObjectSeal', 0, async (done: Function) => { - console.log('uitest: TestObjectSeal begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ObjectsealAbility' - } - 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('ObjectsealAbility'); - - 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: TestObjectSeal end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/module.json5 deleted file mode 100755 index 6793d50f0f4a2b2da57ffe7334c8f5cd17c94b26..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/objectseal/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "objectseal_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/ohosTest.md deleted file mode 100755 index abd3d09965dc4c0560a29fa1a1e3ed7ad1d845cd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/ohosTest.md +++ /dev/null @@ -1,18 +0,0 @@ -# JsvmAboutObject 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------------------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 检查给定的类型标签是否与对象上的类型标签匹配 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建一个包装了外部指针的JavaScript对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建一个默认的JavaScript Object对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据给定的描述符创建一个Symbol对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript对象的原型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取先前传递给Hello World的外部数据指针 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断一个对象是否是某个构造函数的实例 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 冻结给定的对象,防止向其添加新属性,删除现有属性,防止更改现有属性的可枚举性、可配置性或可写性,并防止更改现有属性的值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 密封给定的对象。这可以防止向其添加新属性,以及将所有现有属性标记为不可配置 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 在全局注册表中搜索具有给定描述的现有Symbol,如果该Symbol已经存在,它将被返回,否则将在注册表中创建一个新Symbol | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 返回JavaScript对象的类型 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/symbolfor/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/symbolfor/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/symbolfor/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/oh-package.json5 deleted file mode 100755 index cbaa0d2b4e8f3a774b2128bb5ec66e8a275dfed9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "symbolfor", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libsymbolfor.so": "file:./src/main/cpp/types/libsymbolfor" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 51189c15834bf80ea2321778f16875f46a34d42a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(symbolfor SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(symbolfor PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/hello.cpp deleted file mode 100755 index 574da85338488c7fbff5bdfe6154bb6c532053d1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/hello.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_symbol_for] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_symbol_for] -#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) -// [EndExclude oh_jsvm_symbol_for] - -static const size_t TESTMO_LENGTH = 9; -// 定义一个常量,用于存储最大字符串长度 -static const int MAX_BUFFER_SIZE = 128; -// OH_JSVM_SymbolFor的样例方法 -static JSVM_Value SymbolFor(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value description = nullptr; - OH_JSVM_CreateStringUtf8(env, "test_demo", TESTMO_LENGTH, &description); - char buffer[MAX_BUFFER_SIZE]; - size_t bufferSize = MAX_BUFFER_SIZE; - size_t copied = 0; - OH_JSVM_GetValueStringUtf8(env, description, buffer, bufferSize, &copied); - JSVM_Value symbol = nullptr; - OH_JSVM_CreateSymbol(env, description, &symbol); - JSVM_Value result_symbol = nullptr; - JSVM_Status status = OH_JSVM_SymbolFor(env, buffer, copied, &result_symbol); - JSVM_ValueType valuetypeSymbol; - OH_JSVM_Typeof(env, result_symbol, &valuetypeSymbol); - if (valuetypeSymbol == JSVM_SYMBOL && status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_SymbolFor success"); - } - // 返回结果 - return result_symbol; -} -// SymbolFor注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = SymbolFor}, -}; -static JSVM_CallbackStruct *method = param; -// SymbolFor方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"symbolFor", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(symbolFor())JS"; -// [End oh_jsvm_symbol_for] - -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 = "symbolfor", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/oh-package.json5 deleted file mode 100755 index bfb52e45110843cb912b8f5e78b095b089671a61..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/cpp/types/libsymbolfor/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libsymbolfor.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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/pages/Index.ets deleted file mode 100755 index 4b25b6e8faf34cfbdaff988d2760970fb5cb74c8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libsymbolfor.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/module.json5 deleted file mode 100755 index efbfdcd4ba1dc16733ceb7c2f82b875eb4e48e68..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/module.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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": "symbolfor", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "SymbolforAbility", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "SymbolforAbility", - "srcEntry": "./ets/symbolforability/SymbolforAbility.ets", - "description": "$string:SymbolforAbility_desc", - "icon": "$media:layered_image", - "label": "$string:SymbolforAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/string.json deleted file mode 100755 index d061f37b3c8f6d7603745cd742b93699f5b76006..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "SymbolforAbility_desc", - "value": "description" - }, - { - "name": "SymbolforAbility_label", - "value": "label" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 235203dd233fe6d11e5afeed7ac3b9a49528e7bb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testSymbolFor', 0, async (done: Function) => { - console.log('uitest: TestSymbolFor 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: TestSymbolFor end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/module.json5 deleted file mode 100755 index d0bd3c1c9255b49adaedf73e4023d36b52f0e97f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/symbolfor/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "symbolfor_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutObject/typeof/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/typeof/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutObject/typeof/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/oh-package.json5 deleted file mode 100755 index 5962d1ecbc4a5ed30cbf9f1c748433fe59d0a17d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "typeof", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libtypeof.so": "file:./src/main/cpp/types/libtypeof" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9f521523a9058ce32bd513dd2a98ea9c08e555f0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutObject) - -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) - -add_library(typeof SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(typeof PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/hello.cpp deleted file mode 100755 index 0d5caecd78fc8228e92f4e075cde67ffc8933052..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/hello.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_typeof] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_typeof] -#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) -// [EndExclude oh_jsvm_typeof] - -// OH_JSVM_Typeof的样例方法 -static JSVM_Value GetTypeof(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_ValueType valueType; - OH_JSVM_Typeof(env, args[0], &valueType); - JSVM_Value type = nullptr; - switch (valueType) { - case JSVM_UNDEFINED: - OH_LOG_INFO(LOG_APP, "JSVM Input type is undefined"); - OH_JSVM_CreateStringUtf8(env, "Input type is undefined", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_NULL: - OH_LOG_INFO(LOG_APP, "JSVM Input type is null"); - OH_JSVM_CreateStringUtf8(env, "Input type is null", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_BOOLEAN: - OH_LOG_INFO(LOG_APP, "JSVM Input type is boolean"); - OH_JSVM_CreateStringUtf8(env, "Input type is boolean", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_NUMBER: - OH_LOG_INFO(LOG_APP, "JSVM Input type is number"); - OH_JSVM_CreateStringUtf8(env, "Input type is number", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_STRING: - OH_LOG_INFO(LOG_APP, "JSVM Input type is string"); - OH_JSVM_CreateStringUtf8(env, "Input type is string", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_SYMBOL: - OH_LOG_INFO(LOG_APP, "JSVM Input type is symbol"); - OH_JSVM_CreateStringUtf8(env, "Input type is symbol", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_OBJECT: - OH_LOG_INFO(LOG_APP, "JSVM Input type is object"); - OH_JSVM_CreateStringUtf8(env, "Input type is object", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_FUNCTION: - OH_LOG_INFO(LOG_APP, "JSVM Input type is function"); - OH_JSVM_CreateStringUtf8(env, "Input type is function", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_EXTERNAL: - OH_LOG_INFO(LOG_APP, "JSVM Input type is external"); - OH_JSVM_CreateStringUtf8(env, "Input type is external", JSVM_AUTO_LENGTH, &type); - break; - case JSVM_BIGINT: - OH_LOG_INFO(LOG_APP, "JSVM Input type is bigint"); - OH_JSVM_CreateStringUtf8(env, "Input type is bigint", JSVM_AUTO_LENGTH, &type); - break; - default: - OH_LOG_INFO(LOG_APP, "JSVM Input type does not match any"); - OH_JSVM_CreateStringUtf8(env, " ", JSVM_AUTO_LENGTH, &type); - break; - } - return type; -} -// GetTypeof注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetTypeof}, -}; -static JSVM_CallbackStruct *method = param; -// GetTypeof方法别名,TS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getTypeof", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getTypeof(true);)JS"; -// [End oh_jsvm_typeof] - -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 = "typeof", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/oh-package.json5 deleted file mode 100755 index b85857051386be0ccb4004ff50213c9ece0c994a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/cpp/types/libtypeof/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libtypeof.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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/pages/Index.ets deleted file mode 100755 index f9748bff77dd8c9cc97daf980b3f7a62d0fcf74b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libtypeof.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/module.json5 deleted file mode 100755 index cf7ef571afbc89f34a10f67663e32d19a5771b3d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "typeof", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "TypeofAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "TypeofAbility", - "srcEntry": "./ets/typeofability/TypeofAbility.ets", - "description": "$string:TypeofAbility_desc", - "icon": "$media:layered_image", - "label": "$string:TypeofAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/string.json deleted file mode 100755 index e747d9a12e402f73852c87a973281fd4d3c23294..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "TypeofAbility_desc", - "value": "description" - }, - { - "name": "TypeofAbility_label", - "value": "JsvmAboutObject" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index c832338632c9af9a3edd927f88ae5eee9b6c67b0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testTypeof', 0, async (done: Function) => { - console.log('uitest: TestTypeof begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'TypeofAbility' - } - 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('TypeofAbility'); - - 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: TestTypeof end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/module.json5 deleted file mode 100755 index 7b20cf40646758feacbfdbf51cf5440fbc1573d0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutObject/typeof/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "typeof_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/app.json5 deleted file mode 100755 index 48a4ad99be75078021bda015fed9e71e4c898416..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutprimitive", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/element/string.json deleted file mode 100755 index 9ef52441287357f773846dd11468b2ff6a0dfc86..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutPrimitive" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/README.md deleted file mode 100755 index c8449f4f90b7243487a01864eecd06f03e07b95d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/README.md +++ /dev/null @@ -1,233 +0,0 @@ -# ArkTs使用JSVM-API接口进行primitive类相关开发 - -### 介绍 - -在使用JSVM-API接口时,开发人员可以实现在JSVM模块中与JavaScript对象的交互,并进行数据转换和获取特定对象的操作,它们在不同的场景中发挥着重要的作用,使开发人员能够更灵活地处理JavaScript值和对象。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行primitive类相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-primitive.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :--------------------------------------------------------------------: | :--------------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -coercetobool/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -coercetonumber/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -coercetoobject/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -coercetostring/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getboolean/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getglobal/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getnull/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getundefined/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluebool/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutPrimitive > .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/JsvmUsageGuide/JsvmAboutPrimitive/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/build-profile.json5 deleted file mode 100755 index b7afbd979aacf083f79081ba57f94260e41d7122..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/build-profile.json5 +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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": "coercetobool", - "srcPath": "./coercetobool", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "coercetonumber", - "srcPath": "./coercetonumber", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "coercetoobject", - "srcPath": "./coercetoobject", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "coercetostring", - "srcPath": "./coercetostring", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getboolean", - "srcPath": "./getboolean", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvaluebool", - "srcPath": "./getvaluebool", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getglobal", - "srcPath": "./getglobal", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getnull", - "srcPath": "./getnull", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getundefined", - "srcPath": "./getundefined", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/oh-package.json5 deleted file mode 100755 index 6facad79bad450720bfb396401e39e0cc51542f8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "coercetobool", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcoercetobool.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/CMakeLists.txt deleted file mode 100755 index a88e8587fe9589c7e612c031d40c7d6375eff2be..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPrimitiveOne) - -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(coercetobool SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(coercetobool PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/hello.cpp deleted file mode 100755 index 78bf452b3256a726099517ee940c4f38674ac898..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_coerce_to_bool] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_coerce_to_bool] -#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) -// [EndExclude oh_jsvm_coerce_to_bool] - -// OH_JSVM_CoerceToBool的样例方法 -static JSVM_Value CoerceToBool(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value boolean = nullptr; - JSVM_Status status = OH_JSVM_CoerceToBool(env, args[0], &boolean); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CoerceToBool failed"); - } else { - bool result = false; - OH_JSVM_GetValueBool(env, boolean, &result); - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToBool success:%{public}d", result); - } - return boolean; -} -// CoerceToBool注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CoerceToBool}, -}; -static JSVM_CallbackStruct *method = param; -// CoerceToBool方法别名,ArkTS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"coerceToBool", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(coerceToBool("123"))JS"; -// [End oh_jsvm_coerce_to_bool] - -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 = "coercetobool", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index ac686c07169fa495209ef65b94d32cd72ebd7cef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcoercetobool.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/pages/Index.ets deleted file mode 100755 index fd69f54ee1e8ea5150d897f28d0742df2e31e486..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcoercetobool.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/module.json5 deleted file mode 100755 index 3f76496cdef585d8eab2b530a3de40c0b970f044..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "coercetobool", - "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/string.json deleted file mode 100755 index 6381fdf94160707776dcadacf90433b982401fc4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 9e896ce911722e073acfa3903f6a610c0ba4591b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCoerceToBool', 0, async (done: Function) => { - console.log('uitest: TestCoerceToBool 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: TestCoerceToBool end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/module.json5 deleted file mode 100755 index fef439084c6d128d7d6dc6a71eb3aa0f47234021..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetobool/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "coercetobool_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/oh-package.json5 deleted file mode 100755 index 6cf407cac7e8d35092f314ddbb541197ef0246e2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "coercetonumber", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcoercetonumber.so": "file:./src/main/cpp/types/libcoercetonumber" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/CMakeLists.txt deleted file mode 100755 index facc2363fc38d0537553d8c8c2c032b9e15bdd9b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPrimitiveOne) - -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(coercetonumber SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(coercetonumber PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/hello.cpp deleted file mode 100755 index 6eb547cd89815fb91f7273e477c8729b2c64f71e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_coerce_to_number] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -// [StartExclude oh_jsvm_coerce_to_number] -#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) -// [EndExclude oh_jsvm_coerce_to_number] - -// OH_JSVM_CoerceToNumber的样例方法 -static JSVM_Value CoerceToNumber(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value number = nullptr; - JSVM_Status status = OH_JSVM_CoerceToNumber(env, args[0], &number); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CoerceToNumber failed"); - } else { - int32_t result = 0; - OH_JSVM_GetValueInt32(env, number, &result); - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToNumber success:%{public}d", result); - } - return number; -} -// CoerceToNumber注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CoerceToNumber}, -}; -static JSVM_CallbackStruct *method = param; -// CoerceToNumber方法别名,ArkTS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"coerceToNumber", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(coerceToNumber(true))JS"; -// [End oh_jsvm_coerce_to_number] - -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 = "coercetonumber", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/oh-package.json5 deleted file mode 100755 index 53f344cc274b39ad4e5ac0385874e16d20406eea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/cpp/types/libcoercetonumber/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcoercetonumber.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/pages/Index.ets deleted file mode 100755 index f1f413a5f2c8fa43ef8f0fb5f530247f97fd90f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcoercetonumber.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/module.json5 deleted file mode 100755 index d34c66cc714dfbe9abf7f3c6c9d65ad173448ff9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "coercetonumber", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CoercetonumberAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CoercetonumberAbility", - "srcEntry": "./ets/coercetonumberability/CoercetonumberAbility.ets", - "description": "$string:CoercetonumberAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CoercetonumberAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/string.json deleted file mode 100755 index 688b3a1f501a926238d1ab91a13fa0b65eb7a02b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CoercetonumberAbility_desc", - "value": "description" - }, - { - "name": "CoercetonumberAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index d07af729629af7acc6cecf8ced1429981b4b0597..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCoerceToNumber', 0, async (done: Function) => { - console.log('uitest: TestCoerceToNumber begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CoercetonumberAbility' - } - 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('CoercetonumberAbility'); - - 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: TestCoerceToNumber end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/module.json5 deleted file mode 100755 index 8694a7613eb330801c0e56f3febdee8e1a95d1b1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetonumber/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "coercetonumber_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/oh-package.json5 deleted file mode 100755 index 0568f31272f510adab60380dea4c5616a003c7f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "coercetoobject", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcoercetoobject.so": "file:./src/main/cpp/types/libcoercetoobject" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 4ddb88de0d5c20a660a3a6826af9b884273a6a82..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPrimitiveOne) - -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(coercetoobject SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(coercetoobject PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/hello.cpp deleted file mode 100755 index efaba9b7241491b37e2c96ee1e25f2141b2072c8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/hello.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_coerce_to_object] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_coerce_to_object] -#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) -// [EndExclude oh_jsvm_coerce_to_object] - -// OH_JSVM_CoerceToObject的样例方法 -static JSVM_Value CoerceToObject(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value obj = nullptr; - JSVM_Status status = OH_JSVM_CoerceToObject(env, args[0], &obj); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_CoerceToObject failed"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToObject success"); - } - return obj; -} -// CoerceToObjec注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CoerceToObject}, -}; -static JSVM_CallbackStruct *method = param; -// CoerceToObject方法别名,ArkTS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"coerceToObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(coerceToObject(123))JS"; -// [End oh_jsvm_coerce_to_object] - -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 = "coercetoobject", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/oh-package.json5 deleted file mode 100755 index 4ce39594ad33322362c22e0e4f3e0a1dca870771..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/cpp/types/libcoercetoobject/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcoercetoobject.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/pages/Index.ets deleted file mode 100755 index 43505b6e1bcf31704477850712a2455893a036c4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcoercetoobject.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/module.json5 deleted file mode 100755 index e1a0d870b3f47e7b929eeec8b72ecb3831073a2a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "coercetoobject", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CoercetoobjectAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CoercetoobjectAbility", - "srcEntry": "./ets/coercetoobjectability/CoercetoobjectAbility.ets", - "description": "$string:CoercetoobjectAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CoercetoobjectAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/string.json deleted file mode 100755 index 34e1bf59a17a0d98d1450b3a9bb2bcb3774a6c8b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CoercetoobjectAbility_desc", - "value": "description" - }, - { - "name": "CoercetoobjectAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index cd7d27a848f53bb9a0e4eb37c84590bffbdc89d7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCoerceToObject', 0, async (done: Function) => { - console.log('uitest: TestCoerceToObject begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CoercetoobjectAbility' - } - 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('CoercetoobjectAbility'); - - 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: TestCoerceToObject end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/module.json5 deleted file mode 100755 index 2c976ff7d559a596882f957dc62bf5eef3252f57..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetoobject/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "coercetoobject_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/oh-package.json5 deleted file mode 100755 index 7f67da56f1e45ad6e8c592dfa06fa840c7088310..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "coercetostring", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcoercetostring.so": "file:./src/main/cpp/types/libcoercetostring" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 4bc265a8012747ba413a94bb30426c942af7bff7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(coercetostring SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(coercetostring PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/hello.cpp deleted file mode 100755 index 123b091580817070a816764b5562c72c7f602a6a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/hello.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_coerce_to_string] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_coerce_to_string] -#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) -// [EndExclude oh_jsvm_coerce_to_string] - -// OH_JSVM_CoerceToString的样例方法 -static JSVM_Value CoerceToString(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value str = nullptr; - JSVM_Status status = OH_JSVM_CoerceToString(env, args[0], &str); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_CoerceToString fail"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToString success"); - } - return str; -} -// CoerceToString注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CoerceToString}, -}; -static JSVM_CallbackStruct *method = param; -// CoerceToString方法别名,ArkTS侧调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"coerceToString", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(coerceToString(22222))JS"; -// [End oh_jsvm_coerce_to_string] - -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 = "coercetostring", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/oh-package.json5 deleted file mode 100755 index 24c7c053ec58cab28e76b1bfbf68ca4606f9329f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/cpp/types/libcoercetostring/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcoercetostring.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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/pages/Index.ets deleted file mode 100755 index 99339f82b2c9808e0d93ad672fa4d31159d12119..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcoercetostring.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/module.json5 deleted file mode 100755 index 1eee56a7af5c02a7492cb1fe62e0b7b4564d473f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "coercetostring", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CoercetostringAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CoercetostringAbility", - "srcEntry": "./ets/coercetostringability/CoercetostringAbility.ets", - "description": "$string:CoercetostringAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CoercetostringAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/string.json deleted file mode 100755 index 3d93e0aecaf8d75f596c97e4fd9a4113fd34f0a9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CoercetostringAbility_desc", - "value": "description" - }, - { - "name": "CoercetostringAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 54f405fa6ae44197d626090c407bdf1e6f5ef5b7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCoerceToString', 0, async (done: Function) => { - console.log('uitest: TestCoerceToString begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CoercetostringAbility' - } - 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('CoercetostringAbility'); - - 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: TestCoerceToString end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/module.json5 deleted file mode 100755 index b1d2aa50f7c303e12aad745b8d28f945577b53e9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/coercetostring/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "coercetostring_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/oh-package.json5 deleted file mode 100755 index 08c0881e28700f4b66cd5bb632a1b97dc69391e8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getboolean", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetboolean.so": "file:./src/main/cpp/types/libgetboolean" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 46e6a30dc7d1ca0bb362c8019e5cb7dff8bc4b88..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getboolean SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getboolean PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/hello.cpp deleted file mode 100755 index ebd0e23ed129bafe28e5dda23753aa592aa36b28..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/hello.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_boolean] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_boolean] -#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) -// [EndExclude oh_jsvm_get_boolean] - -// OH_JSVM_GetBoolean的样例方法 -static JSVM_Value GetBoolean(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 传入两个参数并解析 - size_t argc = 2; - JSVM_Value argv[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - int32_t paramData = 0; - OH_JSVM_GetValueInt32(env, argv[0], ¶mData); - int32_t paramValue = 0; - OH_JSVM_GetValueInt32(env, argv[1], ¶mValue); - JSVM_Value returnValue = nullptr; - bool type = false; - if (paramData == paramValue) { - OH_LOG_INFO(LOG_APP, "JSVM resultType equal"); - type = true; - } - JSVM_Status status = OH_JSVM_GetBoolean(env, type, &returnValue); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_CoerceToNumber fail"); - } else { - bool result = false; - OH_JSVM_GetValueBool(env, returnValue, &result); - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_CoerceToNumber success:%{public}d", result); - } - // 返回结果 - return returnValue; -} -// GetBoolean注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetBoolean}, -}; -static JSVM_CallbackStruct *method = param; -// GetBoolean方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getBoolean", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(getBoolean(1, 2))JS"; -// const char *SRC_CALL_NATIVE = R"JS(getBoolean(1, 1))JS"; -// [End oh_jsvm_get_boolean] - -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 = "getboolean", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/oh-package.json5 deleted file mode 100755 index 44148b8150525a6bea6a2710432e7880ea411623..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/cpp/types/libgetboolean/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetboolean.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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/pages/Index.ets deleted file mode 100755 index dcf7f830350661fde3de797fc1beb8403fc298fb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetboolean.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/module.json5 deleted file mode 100755 index af59a2b0b51f58353f26d8b8edc32912d95214fa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getboolean", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetbooleanAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetbooleanAbility", - "srcEntry": "./ets/getbooleanability/GetbooleanAbility.ets", - "description": "$string:GetbooleanAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetbooleanAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/string.json deleted file mode 100755 index fe1ec26c0cdf55b89af6a39e623bdd06cc6665e7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetbooleanAbility_desc", - "value": "description" - }, - { - "name": "GetbooleanAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 8e6181a7757faaa1aecaca4a77ab4c5b0c17a872..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetBoolean', 0, async (done: Function) => { - console.log('uitest: TestGetBoolean begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetbooleanAbility' - } - 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('GetbooleanAbility'); - - 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: TestGetBoolean end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/module.json5 deleted file mode 100755 index d84e576d823097d1776bce1c98d8e748b396297a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getboolean/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getboolean_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/oh-package.json5 deleted file mode 100755 index 6b41753d0fa26129323079ff0f5682132eaf8554..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getglobal", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetglobal.so": "file:./src/main/cpp/types/libgetglobal" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/CMakeLists.txt deleted file mode 100755 index d25ded8811591c17b35c8c9e341be1f00c2895eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getglobal SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getglobal PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/hello.cpp deleted file mode 100755 index 4321e184d2525b42bb832cccdcd9556826d91ca9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/hello.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_global] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_global] -#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) -// [EndExclude oh_jsvm_get_global] - -// OH_JSVM_GetGlobal的样例方法 -static JSVM_Value GetGlobal(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取全局对象 - JSVM_Value value = nullptr; - JSVM_Value global = nullptr; - OH_JSVM_CreateInt32(env, 1, &value); - JSVM_Status status = OH_JSVM_GetGlobal(env, &global); - OH_JSVM_SetNamedProperty(env, global, "Row", value); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetGlobal fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetGlobal success"); - } - return global; -} -// GetGlobal注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetGlobal}, -}; -static JSVM_CallbackStruct *method = param; -// GetGlobal方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getGlobal", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(getGlobal())JS"; -// [End oh_jsvm_get_global] - -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 = "getglobal", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/oh-package.json5 deleted file mode 100755 index ebe943799ed9639ad8c35da041ff5eca15042fea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/cpp/types/libgetglobal/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetglobal.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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/pages/Index.ets deleted file mode 100755 index 79eb37d286e70ca96f090b418d8e1f46bdc2dab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetglobal.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/module.json5 deleted file mode 100755 index bada9b3cffc5650ff577c1c6f7d3b8ce4ae3752a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "getglobal", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetglobalAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetglobalAbility", - "srcEntry": "./ets/getglobalability/GetglobalAbility.ets", - "description": "$string:GetglobalAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetglobalAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/string.json deleted file mode 100755 index 4fc66efff6ae5778d869c0a328d26945445469c9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetglobalAbility_desc", - "value": "description" - }, - { - "name": "GetglobalAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index c455dbaa2be006eeb2cca97275c2fb12b7166c9f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetGlobal', 0, async (done: Function) => { - console.log('uitest: TestGetGlobal begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetglobalAbility' - } - 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('GetglobalAbility'); - - 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: TestGetGlobal end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/module.json5 deleted file mode 100755 index 954dc926373dbc3c423de85d60fac64bde400174..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getglobal/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "getglobal_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/oh-package.json5 deleted file mode 100755 index c86d82f1873d53d3438c37b3eec6d4d6c29d931e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getnull", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetnull.so": "file:./src/main/cpp/types/libgetnull" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 34d492cbc8d1f461055be726b6511396f919e65a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getnull SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getnull PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/hello.cpp deleted file mode 100755 index 148def4d1362db21735f509ea7785fd67f01393e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/hello.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_null] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_null] -#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) -// [EndExclude oh_jsvm_get_null] - -// GetNull注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetNull}, -}; -static JSVM_CallbackStruct *method = param; -// GetNull方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getNull", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// OH_JSVM_GetNull的样例方法 -static JSVM_Value GetNull(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value nullValue = nullptr; - JSVM_Status status = OH_JSVM_GetNull(env, &nullValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetNull fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetNull success"); - } - return nullValue; -} -// [End oh_jsvm_get_null] -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(getNull())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 = "getnull", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/oh-package.json5 deleted file mode 100755 index 69f351200acb15f2315a5f879b4475e846b93ce7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/cpp/types/libgetnull/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetnull.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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/pages/Index.ets deleted file mode 100755 index a05088e543d7e98dbc2501564d1503292a6ccdb1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetnull.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/module.json5 deleted file mode 100755 index cb2da8c0cfaee4e79b3b878abfefca6ac7ab531d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "getnull", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetnullAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetnullAbility", - "srcEntry": "./ets/getnullability/GetnullAbility.ets", - "description": "$string:GetnullAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetnullAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/string.json deleted file mode 100755 index 24f0b34420fbf410d0425b4f1cde51dada4658dc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetnullAbility_desc", - "value": "description" - }, - { - "name": "GetnullAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index b17863e4fe8bce2661b734fa94e407c927d0bd1a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetNull', 0, async (done: Function) => { - console.log('uitest: TestGetNull begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetnullAbility' - } - 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('GetnullAbility'); - - 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: TestGetNull end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/module.json5 deleted file mode 100755 index dd901e63c17a386f9bfa091aef1011bb447764ff..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getnull/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "getnull_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/oh-package.json5 deleted file mode 100755 index a101e3e313571f95155366b0e62588d41c30159c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getundefined", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetundefined.so": "file:./src/main/cpp/types/libgetundefined" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/CMakeLists.txt deleted file mode 100755 index fbe5c5458506e8b0b417b06436320a216f5079c6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getundefined SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getundefined PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/hello.cpp deleted file mode 100755 index 7f587272a1371bc24cdb57d1df50a8b57bc74ad6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_undefined] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_undefined] -#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) -// [EndExclude oh_jsvm_get_undefined] - -// GetUndefined注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetUndefined}, -}; -static JSVM_CallbackStruct *method = param; -// GetUndefined方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getUndefined", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// OH_JSVM_GetUndefined的样例方法 -static JSVM_Value GetUndefined(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取并解析传进的参数 - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 创建一个undefined值 - JSVM_Value value = nullptr; - JSVM_Status status = OH_JSVM_GetUndefined(env, &value); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetUndefined failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetUndefined success"); - } - return value; -} -// [End oh_jsvm_get_undefined] -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(getUndefined())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 = "getundefined", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/oh-package.json5 deleted file mode 100755 index ed444d28c60f692266260de3094a670750d04a92..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/cpp/types/libgetundefined/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetundefined.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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/pages/Index.ets deleted file mode 100755 index 0c69a908015a7d05a615c87be4ca23115570c575..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetundefined.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/module.json5 deleted file mode 100755 index 5883732608c1500d6ffae618371aaca38a8eac50..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "getundefined", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetundefinedAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetundefinedAbility", - "srcEntry": "./ets/getundefinedability/GetundefinedAbility.ets", - "description": "$string:GetundefinedAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetundefinedAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/string.json deleted file mode 100755 index 033a2730bc2b2f164dbaa73f17ba06eb1277390e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetundefinedAbility_desc", - "value": "description" - }, - { - "name": "GetundefinedAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index f811865865327e0b86774675387bb92b9a7d8755..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetUndefined', 0, async (done: Function) => { - console.log('uitest: TestGetUndefined begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetundefinedAbility' - } - 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('GetundefinedAbility'); - - 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: TestGetUndefined end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/module.json5 deleted file mode 100755 index eb9a4b8237c88c59387b148198b88de82e36c37e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getundefined/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "getundefined_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/oh-package.json5 deleted file mode 100755 index f94f43e35c4928e50f4b92ff548e2c49b27d9a98..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluebool", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluebool.so": "file:./src/main/cpp/types/libgetvaluebool" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e712be0dec753ef7bf4689abacef03b886ae2c99..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -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) - -add_library(getvaluebool SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluebool PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/hello.cpp deleted file mode 100755 index ec3f580e1d3bc57b87d2e0970c065fb93ad09000..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_bool] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_value_bool] -#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) -// [EndExclude oh_jsvm_get_value_bool] - -// GetValueBool注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueBool}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueBool方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueBool", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// OH_JSVM_GetValueBool的样例方法 -static JSVM_Value GetValueBool(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - bool result = false; - JSVM_Status status = OH_JSVM_GetValueBool(env, args[0], &result); - if (status == JSVM_BOOLEAN_EXPECTED || status != JSVM_OK) { - // 如果OH_JSVM_GetValueBool成功会返回JSVM_OK,如果传入一个非布尔值则会返回JSVM_BOOLEAN_EXPECTED - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetValueBool fail:%{public}d", status); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetValueBool success:%{public}d", result); - } - JSVM_Value boolJv = nullptr; - OH_JSVM_GetBoolean(env, result, &boolJv); - return boolJv; -} -// [End oh_jsvm_get_value_bool] -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(getValueBool("abc"))JS"; -// const char *SRC_CALL_NATIVE = R"JS(getValueBool(true))JS"; -// const char *SRC_CALL_NATIVE = R"JS(getValueBool(false))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 = "getvaluebool", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/oh-package.json5 deleted file mode 100755 index 9d32f5488b75b56c9e3a33e488531a171eac0331..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/cpp/types/libgetvaluebool/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluebool.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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/pages/Index.ets deleted file mode 100755 index 2003b2dc6cb95f2fa50ed5e97b8096a592f593f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluebool.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/module.json5 deleted file mode 100755 index 9b276e0e2992dcb448fffde6e2f731030b54cb7b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "getvaluebool", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetvalueboolAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetvalueboolAbility", - "srcEntry": "./ets/getvalueboolability/GetvalueboolAbility.ets", - "description": "$string:GetvalueboolAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetvalueboolAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/string.json deleted file mode 100755 index a059c632a6f8b1d11fe80346527c081d8f781f0b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetvalueboolAbility_desc", - "value": "description" - }, - { - "name": "GetvalueboolAbility_label", - "value": "JsvmAboutPrimitive" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 0e12eb83348cf941619b80448279f43634ffd847..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueBool', 0, async (done: Function) => { - console.log('uitest: TestGetValueBool begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetvalueboolAbility' - } - 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('GetvalueboolAbility'); - - 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: TestGetValueBool end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/module.json5 deleted file mode 100755 index ec4548e4df8f3b4da86b3caaa279c09f59eec400..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/getvaluebool/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "getvaluebool_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPrimitive/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/ohosTest.md deleted file mode 100755 index 6c0b7e9b2cabda4b55b107583313eae2c3d94853..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive/ohosTest.md +++ /dev/null @@ -1,16 +0,0 @@ -# JsvmAboutPrimitive 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 将目标值转换为Boolean类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 将目标值转换为Number类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 将目标值转换为Object类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 将目标值转换为String类型对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取JavaScript单例对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取当前环境中的全局global对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取JavaScript null | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取JavaScript undefined | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript Boolean的C布尔基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/app.json5 deleted file mode 100755 index 160d1bf71015305acf3994cc4e5cde15f73a647d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutpromise", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/element/string.json deleted file mode 100755 index 69f3fda0449d90af8a24d66be8d31426112ed80c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutPromise" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/README.md deleted file mode 100755 index 11d00148849e29d37a562092de23b8b46b9dbd05..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/README.md +++ /dev/null @@ -1,93 +0,0 @@ -# ArkTS使用JSVM-API接口处理异步操作 - -### 介绍 - -使用JSVM-API接口处理异步操作。异步操作是指需要一定时间才能完成的操作,例如从网络下载数据或读取大型文件。与同步操作不同,异步操作不会阻塞主线程,而是会在后台执行。当异步操作完成后,事件循环将把它放入任务队列中,等待主线程空闲时执行。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口处理异步操作](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-promise.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -|:--------------------------------------------------------------------:|:--------------------------------------------------------------------:| -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -ispromise/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -resolvereject/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutPromise > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/build-profile.json5 deleted file mode 100755 index 9c52a08979c4468f1f8d201f605d621c52703ce6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/build-profile.json5 +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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": "ispromise", - "srcPath": "./ispromise", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "resolvereject", - "srcPath": "./resolvereject", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPromise/ispromise/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPromise/ispromise/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/oh-package.json5 deleted file mode 100755 index 6609f1019975da7d3f637f65f289984d006b9921..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "ispromise", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libispromise.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 12439788dd11b87ac75e68ce5c7f4a0374daf8d3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPromise) - -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) - -add_library(ispromise SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(ispromise PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/hello.cpp deleted file mode 100755 index 627c4d6bca6ea4d73388bb257fdf85dd89b1ffed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/hello.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_ispromise] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [EndExclude oh_jsvm_ispromise] -#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) -// [EndExclude oh_jsvm_ispromise] - -// OH_JSVM_IsPromise的样例方法 -static JSVM_Value IsPromise(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - bool isPromise = false; - JSVM_Status status = OH_JSVM_IsPromise(env, args[0], &isPromise); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_IsPromise fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_IsPromise success:%{public}d", isPromise); - } - JSVM_Value result = nullptr; - OH_JSVM_GetBoolean(env, isPromise, &result); - return result; -} -// IsPromise注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = IsPromise}, -}; -static JSVM_CallbackStruct *method = param; -// IsPromise方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"isPromise", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(isPromise())JS"; -// [End oh_jsvm_ispromise] - -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 = "ispromise", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 5a0ea78a445600662fec266bc39b8df0ac63e31e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libispromise.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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/pages/Index.ets deleted file mode 100755 index 5639888902d43d81e9849d8401b45f5c60b861c4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libispromise.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/module.json5 deleted file mode 100755 index e72f7a6391692e3366a6f7b73ffc17cac34042c8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "ispromise", - "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/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/module.json5 deleted file mode 100755 index 37191bb53c066ef21b94d3789430b7a44c8916a1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ispromise/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "ispromise_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPromise/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ohosTest.md deleted file mode 100755 index d91f25b154115d7e88d0f7cd3b1f3cbe5b659d07..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# JsvmAboutDate 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------- | ------------ | ------------------------ | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 查询Promise是否为Promise对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 通过与之关联的延迟对象来解析JavaScript promise | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/oh-package.json5 deleted file mode 100755 index 193f8161ce3bd1da5d2b93654a92ed7916e38f73..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "resolvereject", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libresolvereject.so": "file:./src/main/cpp/types/libresolvereject" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 541b71f1abc84c87d5a460202f9d678b1585a7f6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPromise) - -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) - -add_library(resolvereject SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(resolvereject PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/hello.cpp deleted file mode 100755 index c75293bfcc2d9722c95d3ecde763aace877eb5c9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/hello.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_resolvedeferred_and_rejectdeferred] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_resolvedeferred_and_rejectdeferred] -#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) -// [EndExclude oh_jsvm_resolvedeferred_and_rejectdeferred] - -// OH_JSVM_CreatePromise、OH_JSVM_ResolveDeferred、OH_JSVM_RejectDeferred的样例方法 -static JSVM_Value CreatePromise(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Deferred defer = nullptr; - JSVM_Value promise = nullptr; - JSVM_Status status = OH_JSVM_CreatePromise(env, &defer, &promise); - bool isPromise = false; - JSVM_Value returnIsPromise = nullptr; - OH_JSVM_IsPromise(env, promise, &isPromise); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreatePromise fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreatePromise success:%{public}d", isPromise); - } - // 将布尔值转为可以返回的JSVM_Value - OH_JSVM_GetBoolean(env, isPromise, &returnIsPromise); - return returnIsPromise; -} - -static JSVM_Value ResolveRejectDeferred(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获得并解析参数 - size_t argc = 3; - JSVM_Value args[3] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 第一个参数为向resolve传入的信息,第二个参数为向reject传入的信息,第三个参数为Promise的状态 - bool status = false; - OH_JSVM_GetValueBool(env, args[2], &status); - // 创建Promise对象 - JSVM_Deferred deferred = nullptr; - JSVM_Value promise = nullptr; - JSVM_Status createStatus = OH_JSVM_CreatePromise(env, &deferred, &promise); - if (createStatus != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "Create promise failed"); - return nullptr; - } - // 根据第三个参数设置resolve或reject - if (status) { - OH_JSVM_ResolveDeferred(env, deferred, args[0]); - OH_LOG_INFO(LOG_APP, "OH_JSVM_ResolveDeferred resolve"); - } else { - OH_JSVM_RejectDeferred(env, deferred, args[1]); - OH_LOG_INFO(LOG_APP, "OH_JSVM_RejectDeferred reject"); - } - JSVM_Value result = nullptr; - OH_JSVM_GetBoolean(env, true, &result); - return result; -} -// CreatePromise,ResolveRejectDeferred注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreatePromise}, - {.data = nullptr, .callback = ResolveRejectDeferred}, -}; -static JSVM_CallbackStruct *method = param; -// CreatePromise,ResolveRejectDeferred方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createPromise", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - {"resolveRejectDeferred", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE_CREATE_PROMISE = R"JS(createPromise())JS"; -const char *SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED1 = R"JS(resolveRejectDeferred('success','fail', true))JS"; -const char *SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED2 = R"JS(resolveRejectDeferred('success','fail', false))JS"; -// [End oh_jsvm_resolvedeferred_and_rejectdeferred] - -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_CREATE_PROMISE, JSVM_AUTO_LENGTH, &jsSrc)); - CHECK_RET(OH_JSVM_CreateStringUtf8(env, SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED1, JSVM_AUTO_LENGTH, &jsSrc)); - CHECK_RET(OH_JSVM_CreateStringUtf8(env, SRC_CALL_NATIVE_RESOLVE_REJECT_DEFERRED2, 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 = "resolvereject", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/oh-package.json5 deleted file mode 100755 index f18cdc7cefc973dd7f9f96aa42bccac828b8a99e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/cpp/types/libresolvereject/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libresolvereject.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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/pages/Index.ets deleted file mode 100755 index 1ebf019d9a48e78356c801cafea6b32f6e59190c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libresolvereject.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/module.json5 deleted file mode 100755 index 611397a0c45890bef58c9a3da51254f925a64e90..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "resolvereject", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ResolverejectAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ResolverejectAbility", - "srcEntry": "./ets/resolverejectability/ResolverejectAbility.ets", - "description": "$string:ResolverejectAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ResolverejectAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/module.json5 deleted file mode 100755 index 8a7f45711bf07412c11298d0656d26d689d488a6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutPromise/resolvereject/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "resolvereject_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutProperty/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/app.json5 deleted file mode 100755 index fa77fa691e7ccfb3a1c222bbbdcb0cfc02452fe8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutproperty", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/element/string.json deleted file mode 100755 index 462be837c6e7286420cb0637beb91ca7579e4361..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutProperty" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/README.md deleted file mode 100755 index 0fbdef4b0907b0924e809f070c3719a0f3702421..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/README.md +++ /dev/null @@ -1,273 +0,0 @@ -# ArkTs使用JSVM-API接口设置JavaScript对象的属性 - -### 介绍 - -使用JSVM-API接口获取和设置JavaScript对象的属性。通过合理使用这些函数,实现更复杂的功能和逻辑。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口设置JavaScript对象的属性](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-property.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-------------------------------------------------------------------: | :-------------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -defineproperties/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -deleteproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getallpropertynames/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getnamedproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getpropertynames/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -hasnamedproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -hasownproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -hasproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -setnamedproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -setproperty/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutProperty > .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/JsvmUsageGuide/JsvmAboutProperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/build-profile.json5 deleted file mode 100755 index 045c2423e4f0ffb9b60db95ffef85f005098f90b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/build-profile.json5 +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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": "getpropertynames", - "srcPath": "./getpropertynames", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getproperty", - "srcPath": "./getproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "deleteproperty", - "srcPath": "./deleteproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getnamedproperty", - "srcPath": "./getnamedproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "defineproperties", - "srcPath": "./defineproperties", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getallpropertynames", - "srcPath": "./getallpropertynames", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "setproperty", - "srcPath": "./setproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "hasproperty", - "srcPath": "./hasproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "hasownproperty", - "srcPath": "./hasownproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "setnamedproperty", - "srcPath": "./setnamedproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "hasnamedproperty", - "srcPath": "./hasnamedproperty", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/oh-package.json5 deleted file mode 100755 index c59b85f09d161374f24323bc4a19915a5a10735b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "defineproperties", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libdefineproperties.so": "file:./src/main/cpp/types/libdefineproperties" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 409794f0bc8b5372f028cb4494fc6af32c66edca..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(defineproperties SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(defineproperties PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/hello.cpp deleted file mode 100755 index 30231f3645d4c27e47adc4cab12133347d31025e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/hello.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * 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" -#include -#include - -#define LOG_DOMAIN 0x3200 -#define LOG_TAG "APP" -#define MAX_MALLOC_SIZE 0x800000 - -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) - -// [Start oh_jsvm_define_properties] -// 属性描述符列表中defineMethodPropertiesExample属性的回调函数 -static JSVM_Value DefineMethodPropertiesExample(JSVM_Env env, JSVM_CallbackInfo info) -{ - int32_t propValue = 26; - JSVM_Value returnValue; - OH_JSVM_CreateInt32(env, propValue, &returnValue); - return returnValue; -} -// 属性描述符列表中getterCallback属性的回调函数 -static JSVM_Value GetterCallback(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value result; - const char *str = "Hello world!"; - size_t length = strlen(str); - // 创建属性的值 - OH_JSVM_CreateStringUtf8(env, str, length, &result); - return result; -} - -// 执行JavaScript字符串的函数 -static JSVM_Value RunScriptAndLogResult(JSVM_Env env, const std::string &srcCode) -{ - JSVM_Value sourceCodeValue; - OH_JSVM_CreateStringUtf8(env, srcCode.c_str(), srcCode.size(), &sourceCodeValue); - JSVM_Script script; - // 编译JavaScript代码字符串并返回编译后的脚本 - OH_JSVM_CompileScript(env, sourceCodeValue, nullptr, 0, true, nullptr, &script); - JSVM_Value jsVmResult; - // 执行JavaScript代码字符串 - OH_JSVM_RunScript(env, script, &jsVmResult); - return jsVmResult; -} - -// OH_JSVM_DefineProperties的样例方法 -static JSVM_Value DefineProperties(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 接受一个JavaScript侧传入的空object - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - // 创建一个string类型的属性值 - JSVM_Value stringValue; - OH_JSVM_CreateStringUtf8(env, "Hello!", JSVM_AUTO_LENGTH, &stringValue); - // 创建属性描述符对应的回调函数列表 - JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = DefineMethodPropertiesExample}, - {.data = nullptr, .callback = GetterCallback}, - - }; - // 创建属性描述符列表,不同类型属性值添加位置参考JSVM_PropertyDescriptor定义 - JSVM_PropertyDescriptor descriptor[] = { - // 定义method类型的属性值 - {"defineMethodPropertiesExample", nullptr, ¶m[0], nullptr, nullptr, nullptr, JSVM_DEFAULT}, - // 定义string类型的属性值 - {"defineStringPropertiesExample", nullptr, nullptr, nullptr, nullptr, stringValue, JSVM_DEFAULT}, - // 定义getter类型的属性值 - {"getterCallback", nullptr, nullptr, ¶m[1], nullptr, nullptr, JSVM_DEFAULT}}; - // 根据属性描述符列表为obj对象创建属性 - JSVM_Status statusProperty = OH_JSVM_DefineProperties(env, - *argv, - sizeof(descriptor) / sizeof(descriptor[0]), - descriptor); - if (statusProperty != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM DefineProperties fail"); - return nullptr; - } - // 调用obj对象中添加的属性 - // 运行obj.defineMethodPropertiesExample()并将结果返回给JavaScript - std::string srcMethod = R"JS(obj.defineMethodPropertiesExample();)JS"; - JSVM_Value jsVmResult = RunScriptAndLogResult(env, srcMethod); - if (jsVmResult != nullptr) { - int32_t number; - OH_JSVM_GetValueInt32(env, jsVmResult, &number); - OH_LOG_INFO(LOG_APP, "JSVM DefineMethodPropertiesExample success:%{public}d", number); - } - // 运行obj.defineStringPropertiesExample()并将结果返回给JavaScript - static std::string srcString = R"JS(obj.defineStringPropertiesExample;)JS"; - JSVM_Value jsVmResult1 = RunScriptAndLogResult(env, srcString); - if (jsVmResult1 != nullptr) { - size_t length = 0; - OH_JSVM_GetValueStringUtf8(env, jsVmResult1, nullptr, 0, &length); - if (length == 0 || length > MAX_MALLOC_SIZE) { - OH_LOG_ERROR(LOG_APP, "Invalid string length: %{public}zu", length); - return jsVmResult; - } - char *buf = (char *)malloc(length + 1); - OH_JSVM_GetValueStringUtf8(env, jsVmResult1, buf, length + 1, &length); - OH_LOG_INFO(LOG_APP, "JSVM defineStringPropertiesExample success:%{public}s", buf); - free(buf); - } - // 调用obj的getterCallback()并将结果字符串返回给JavaScript - static std::string srcGetter = R"JS(obj.getterCallback;)JS"; - JSVM_Value jsVmResult2 = RunScriptAndLogResult(env, srcGetter); - if (jsVmResult2 != nullptr) { - size_t length = 0; - OH_JSVM_GetValueStringUtf8(env, jsVmResult2, nullptr, 0, &length); - OH_JSVM_GetValueStringUtf8(env, jsVmResult1, nullptr, 0, &length); - if (length == 0 || length > MAX_MALLOC_SIZE) { - OH_LOG_ERROR(LOG_APP, "Invalid string length: %{public}zu", length); - return jsVmResult; - } - char *buf = (char *)malloc(length + 1); - OH_JSVM_GetValueStringUtf8(env, jsVmResult2, buf, length + 1, &length); - OH_LOG_INFO(LOG_APP, "JSVM getterCallback success:%{public}s", buf); - free(buf); - } - return jsVmResult; -} - -// DefineProperties注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = DefineProperties}, -}; -static JSVM_CallbackStruct *method = param; -// DefineProperties方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"defineProperties", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = {}; - defineProperties(obj) -)JS"; -// [End oh_jsvm_define_properties] - -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 = "defineproperties", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/oh-package.json5 deleted file mode 100755 index cda01b57ad853cbbaf3ac18bbaf449ecb0de7f32..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/cpp/types/libdefineproperties/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libdefineproperties.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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/pages/Index.ets deleted file mode 100755 index a6227e5f82d7db71760d912aa62135de251c7282..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libdefineproperties.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/module.json5 deleted file mode 100755 index 7add5f24c345c4ff22045a0ec255131ae9164f61..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "defineproperties", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "DefinepropertiesAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "DefinepropertiesAbility", - "srcEntry": "./ets/definepropertiesability/DefinepropertiesAbility.ets", - "description": "$string:DefinepropertiesAbility_desc", - "icon": "$media:layered_image", - "label": "$string:DefinepropertiesAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/string.json deleted file mode 100755 index 3a13ad00d6abc17b554b17746e527a53f55b0cc2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "DefinepropertiesAbility_desc", - "value": "description" - }, - { - "name": "DefinepropertiesAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index a4270bba3e95d5a67ab87544afa94c5ae48fd945..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testDefineProperties', 0, async (done: Function) => { - console.log('uitest: TestDefineProperties begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'DefinepropertiesAbility' - } - 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('DefinepropertiesAbility'); - - 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: TestDefineProperties end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/module.json5 deleted file mode 100755 index c6810afd6f9f2e5244d9affeb5ceb0e1575868a2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/defineproperties/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "defineproperties_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/oh-package.json5 deleted file mode 100755 index fbd0dbf5b2e5429dc00df3a72ba9c63e0c26a8f2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "deleteproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libdeleteproperty.so": "file:./src/main/cpp/types/libdeleteproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 3c68e1323d444939cd1cadb9f9562df42e40ff45..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(deleteproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(deleteproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/hello.cpp deleted file mode 100755 index 4ed3a2dd097ba1b77d35b1c2391f4464e61b9012..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_delete_property] -// OH_JSVM_DeleteProperty的样例方法 -static JSVM_Value DeleteProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_ValueType valueType; - OH_JSVM_Typeof(env, args[0], &valueType); - if (valueType != JSVM_OBJECT) { - OH_JSVM_ThrowError(env, nullptr, "Expects an object as argument."); - return nullptr; - } - // 从传入的Object对象中删除指定属性,返回是否删除成功的bool结果值 - bool result = false; - JSVM_Status status = OH_JSVM_DeleteProperty(env, args[0], args[1], &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_DeleteProperty failed"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_DeleteProperty success:%{public}d", result); - } - // 将bool结果转换为JSVM_value并返回 - JSVM_Value ret; - OH_JSVM_GetBoolean(env, result, &ret); - return ret; -} -// DeleteProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = DeleteProperty}, -}; -static JSVM_CallbackStruct *method = param; -// DeleteProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"deleteProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - deleteProperty(obj, "message") -)JS"; -// [End oh_jsvm_delete_property] - -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 = "deleteproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/oh-package.json5 deleted file mode 100755 index d6413588d7d1a93ded249391d14cad7c861dc6b4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/cpp/types/libdeleteproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libdeleteproperty.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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 037ebc569d7a1527808d57191bb5d8acdeb18a4f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libdeleteproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/module.json5 deleted file mode 100755 index 836665b3e4f4446c13c6bbbf13b44e0f09f89a85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "deleteproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "DeletepropertyAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "DeletepropertyAbility", - "srcEntry": "./ets/deletepropertyability/DeletepropertyAbility.ets", - "description": "$string:DeletepropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:DeletepropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/string.json deleted file mode 100755 index 1aef48f84a8c43116e444bda64cede5e32f3d360..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "DeletepropertyAbility_desc", - "value": "description" - }, - { - "name": "DeletepropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 9e350045eaf8d867fb17ed7b526c7251f9f6b373..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testDeleteProperty', 0, async (done: Function) => { - console.log('uitest: TestDeleteProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'DeletepropertyAbility' - } - 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('DeletepropertyAbility'); - - 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: TestDeleteProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/module.json5 deleted file mode 100755 index 171021952ad39731dc9dfebfc37c94f32970b5da..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/deleteproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "deleteproperty_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/oh-package.json5 deleted file mode 100755 index 45bb916f6014f53262418e3f5fdba82c33e00190..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getallpropertynames", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetallpropertynames.so": "file:./src/main/cpp/types/libgetallpropertynames" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 448b8735b574f3e545705d543f2c5a0d6450fe3e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(getallpropertynames SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getallpropertynames PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/hello.cpp deleted file mode 100755 index 66b8d9957db20ceb190f236b6cd938845b72c9e4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/hello.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_get_all_property_names] -// OH_JSVM_GetAllPropertyNames的样例方法 -static JSVM_Value GetAllPropertyNames(JSVM_Env env, JSVM_CallbackInfo info) -{ - // // 获取js侧传入的一个参数 - size_t argc = 1; - JSVM_Value args[1]; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取给定对象的所有属性名称(自有属性) - JSVM_Value result; - JSVM_Status status = OH_JSVM_GetAllPropertyNames(env, args[0], - JSVM_KeyCollectionMode::JSVM_KEY_O_ONLY, - JSVM_KeyFilter::JSVM_KEY_WRITABLE, - JSVM_KeyConversion::JSVM_KEY_NUMBERS_TO_STRINGS, &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "Failed to get allpropertynames"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetAllPropertyNames success"); - } - return result; -} -// GetAllPropertyNames注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetAllPropertyNames}, -}; -static JSVM_CallbackStruct *method = param; -// GetAllPropertyNames方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getAllPropertyNames", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = '{ data: 0, message: "hello world", 50: 1}'; - let script = getAllPropertyNames(obj); -)JS"; -// [End oh_jsvm_get_all_property_names] - -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 = "getallpropertynames", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/oh-package.json5 deleted file mode 100755 index 60b97e056a9dd6ea38c0b378de1a343815379fd9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/cpp/types/libgetallpropertynames/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetallpropertynames.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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/pages/Index.ets deleted file mode 100755 index 63637d06a6008563416d916d37364204686fb897..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetallpropertynames.so'; - -@Entry -@Component -struct Index { - @State message: string = 'OH_JSVM_GetAllPropertyNames'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/module.json5 deleted file mode 100755 index 24abb823d227ee2ca6792098580ce3bf56b63cb5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getallpropertynames", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetallpropertynamesAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetallpropertynamesAbility", - "srcEntry": "./ets/getallpropertynamesability/GetallpropertynamesAbility.ets", - "description": "$string:GetallpropertynamesAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetallpropertynamesAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/string.json deleted file mode 100755 index f940655f4c22d1e0029e87daa46dbd611c3c43e8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetallpropertynamesAbility_desc", - "value": "description" - }, - { - "name": "GetallpropertynamesAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index ea05ca35f0f6a608ef4fc67f6b38bc65d2e92b3f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetAllPropertyNames', 0, async (done: Function) => { - console.log('uitest: TestGetAllPropertyNames begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetallpropertynamesAbility' - } - 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('GetallpropertynamesAbility'); - - 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: TestGetAllPropertyNames end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/module.json5 deleted file mode 100755 index 393e966fbdf2027dfc4fe2c0d97fa65cb0b88df2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getallpropertynames/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getallpropertynames_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/oh-package.json5 deleted file mode 100755 index e8e5dc4f640405f44d9d800af8b946615e88bd8f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getnamedproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetnamedproperty.so": "file:./src/main/cpp/types/libgetnamedproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index de0f007857ff8ffb2cf2df28bc3f09afe7b86455..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(getnamedproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getnamedproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/hello.cpp deleted file mode 100755 index 1a89a3e838dc51648f78c49cb8fba2eafaf978d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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 "ark_runtime/jsvm.h" -#include "hilog/log.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) - -// [Start oh_jsvm_get_named_property] -// OH_JSVM_GetNamedProperty的样例方法 -const size_t MAX_KEY_LENGTH = 32; -static JSVM_Value GetNamedProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - char strKey[MAX_KEY_LENGTH] = ""; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取要获取的属性名 - size_t keyLength; - OH_JSVM_GetValueStringUtf8(env, args[1], strKey, MAX_KEY_LENGTH, &keyLength); - // 获取指定属性的值并存储在result中 - JSVM_Value result; - JSVM_Status status = OH_JSVM_GetNamedProperty(env, args[0], strKey, &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_GetNamedProperty failed"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetNamedProperty success"); - } - return result; -} -// GetNamedProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetNamedProperty}, -}; -static JSVM_CallbackStruct *method = param; -// GetNamedProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getNamedProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - getNamedProperty(obj, "message") -)JS"; -// [End oh_jsvm_get_named_property] - -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 = "getnamedproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/oh-package.json5 deleted file mode 100755 index 3bf0f63687894e81a39c6cf0296cae38d3e9b16d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/cpp/types/libgetnamedproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetnamedproperty.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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 0cce1296bf82b8dde066ebddf5ce2fbc028aef16..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetnamedproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/module.json5 deleted file mode 100755 index b7b08e66dd25acca95bf9b3c572a8848268e5913..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getnamedproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetnamedpropertyAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetnamedpropertyAbility", - "srcEntry": "./ets/getnamedpropertyability/GetnamedpropertyAbility.ets", - "description": "$string:GetnamedpropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetnamedpropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/string.json deleted file mode 100755 index 28dc2bcede777599de6456fec37ca32df502e7b3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetnamedpropertyAbility_desc", - "value": "description" - }, - { - "name": "GetnamedpropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 1e520633c0e42bd3dd883d0ddc4742cd6e7ae46e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetNamedProperty', 0, async (done: Function) => { - console.log('uitest: TestGetNamedProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetnamedpropertyAbility' - } - 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('GetnamedpropertyAbility'); - - 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: TestGetNamedProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/module.json5 deleted file mode 100755 index ed90c4453f23a34891d885fb1fe7449256d71038..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getnamedproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getnamedproperty_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/getproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/getproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/oh-package.json5 deleted file mode 100755 index d62f4faafb916be0693caa40f6b29377dc5c0fcf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetproperty.so": "file:./src/main/cpp/types/libgetproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b2e21e59a210ace03e61c1ac21fed762afec27fb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPropertyOne) - -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) - -add_library(getproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/hello.cpp deleted file mode 100755 index d785e7aba472034fdfbf5963075fae605c4506b9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_get_property] -// OH_JSVM_GetProperty的样例方法 -static JSVM_Value GetProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 接收两个js传来的参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 传入的第一个参数为要检测的object,第二个对象为要检测的属性,通过调用OH_JSVM_GetProperty接口获取对应的值 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetProperty(env, args[0], args[1], &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_GetProperty fail"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetProperty success"); - } - return result; -} -// GetProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetProperty}, -}; -static JSVM_CallbackStruct *method = param; -// GetProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - getProperty(obj, "message") -)JS"; -// [End oh_jsvm_get_property] - -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 = "getproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/oh-package.json5 deleted file mode 100755 index c1cc0732f9dff2067f1308764b49049727fea09b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/cpp/types/libgetproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetproperty.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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index bb407c515607f21f2c288cf60005d8f6be9e4f50..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/module.json5 deleted file mode 100755 index d7faca32c15693fdb83496584136f07d0bbbc2ae..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetpropertyAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetpropertyAbility", - "srcEntry": "./ets/getpropertyability/GetpropertyAbility.ets", - "description": "$string:GetpropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetpropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/string.json deleted file mode 100755 index 991a2e032c0eb923a3eb1e27d393c9fabb2e2f67..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetpropertyAbility_desc", - "value": "description" - }, - { - "name": "GetpropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 925a0a45b0c2db1b03a159c8c2ecf8454641f89f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetProperty', 0, async (done: Function) => { - console.log('uitest: TestGetProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetpropertyAbility' - } - 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('GetpropertyAbility'); - - 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: TestGetProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/module.json5 deleted file mode 100755 index 8f068374c5a568a97570548400247837088d1855..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getproperty_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/oh-package.json5 deleted file mode 100755 index 5eb4ffe7a2a31807710a5e49279dd33bbaf110fe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getpropertynames", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetpropertynames.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 40d7eb68acd4b9b3ecab8bb450feb3df536a6816..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPropertyOne) - -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) - -add_library(getpropertynames SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getpropertynames PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/hello.cpp deleted file mode 100755 index e55e090e577da1a3b2161dd8b7fb2b3b3af364c9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_get_property_names] -// OH_JSVM_GetPropertyNames的样例方法 -static JSVM_Value GetPropertyNames(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 将obj作为参数传入 - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 以字符串数组的形式获取对象的可枚举属性的名称,以result传出 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetPropertyNames(env, args[0], &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "Failed to get propertynames"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetPropertyNames success"); - } - return result; -} -// GetPropertyNames注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetPropertyNames}, -}; -static JSVM_CallbackStruct *method = param; -// GetPropertyNames方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getPropertyNames", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = '{ data: 0, message: "hello world"}'; - let script = getPropertyNames(obj); -)JS"; -// [End oh_jsvm_get_property_names] - -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 = "getpropertynames", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index e7873e47f5cf3b3938ae7822120f395af7446a88..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetpropertynames.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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/pages/Index.ets deleted file mode 100755 index 2d31a4f3d5edc939f5ac8f60ae99c97bf2d609ff..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetpropertynames.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/module.json5 deleted file mode 100755 index 5e8d998cf93e8dac2ac98392ccc6eb2442bb3e1f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getpropertynames", - "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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/string.json deleted file mode 100755 index 1e3b82db3d2a0ee464b4d7e23dfa39e1bb65996e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 102509217384a4b61dcf0ca0516313e228909270..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetPropertyNames', 0, async (done: Function) => { - console.log('uitest: TestGetPropertyNames 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: TestGetPropertyNames end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/module.json5 deleted file mode 100755 index 393cda5ff4334d3b7120fb6e4b49907e2c0ddfc0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/getpropertynames/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getpropertynames_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/oh-package.json5 deleted file mode 100755 index b147d9a1945a05ab3ec91232137b82caedf5255d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "hasnamedproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libhasnamedproperty.so": "file:./src/main/cpp/types/libhasnamedproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index acaeb0b41a5fa1b86e0d66fae0850a14e17a0b18..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(hasnamedproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(hasnamedproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/hello.cpp deleted file mode 100755 index a350001301ee80ec20b39ead2bbd24ed276a1f6f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_has_named_property] -// OH_JSVM_HasNamedProperty的样例方法 -const size_t STR_KEY_LEN = 32; -static JSVM_Value HasNamedProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - char strKey[STR_KEY_LEN] = ""; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 获取要检查的属性名 - size_t keyLength; - OH_JSVM_GetValueStringUtf8(env, args[1], strKey, STR_KEY_LEN, &keyLength); - // 检查对象是否具有指定命名的属性,并将结果存储在hasProperty中 - bool hasProperty = false; - JSVM_Status status = OH_JSVM_HasNamedProperty(env, args[0], strKey, &hasProperty); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_HasNamedProperty failed"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_HasNamedProperty success:%{public}d", hasProperty); - } - // 将bool结果转换为JSVM_Value并返回 - JSVM_Value result; - OH_JSVM_GetBoolean(env, hasProperty, &result); - return result; -} -// HasNamedProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = HasNamedProperty}, -}; -static JSVM_CallbackStruct *method = param; -// HasNamedProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"hasNamedProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - hasNamedProperty(obj, "message") -)JS"; -// [End oh_jsvm_has_named_property] - -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 = "hasnamedproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/oh-package.json5 deleted file mode 100755 index cb23934b926e9c59c67cfb2f595ea33f4f10e505..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/cpp/types/libhasnamedproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libhasnamedproperty.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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 98ca9e16cc8a26fcb91f4ce61411fa7888f21a4e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libhasnamedproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/module.json5 deleted file mode 100755 index a5342e7d1073285df44c34fcb349b7d0dc82ed9f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "hasnamedproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "HasnamedpropertyAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "HasnamedpropertyAbility", - "srcEntry": "./ets/hasnamedpropertyability/HasnamedpropertyAbility.ets", - "description": "$string:HasnamedpropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:HasnamedpropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/string.json deleted file mode 100755 index 854f880b512a754f856d92016eb159063ee6a6c5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "HasnamedpropertyAbility_desc", - "value": "description" - }, - { - "name": "HasnamedpropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 4a3fa1b8d4adafad0188bb532d9004ef17c4e75f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testHasNamedProperty', 0, async (done: Function) => { - console.log('uitest: TestHasNamedProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'HasnamedpropertyAbility' - } - 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('HasnamedpropertyAbility'); - - 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: TestHasNamedProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/module.json5 deleted file mode 100755 index 61889a60303c7c1fed65f64cfd46f0af16f67f4f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasnamedproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "hasnamedproperty_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/oh-package.json5 deleted file mode 100755 index 68bf6e7bded2a66dbeed3dcc17b3a42ad8d5052a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "hasownproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libhasownproperty.so": "file:./src/main/cpp/types/libhasownproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 8840d15b890ab455d3d4e7e6cc88e4c1008e58c4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(hasownproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(hasownproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/hello.cpp deleted file mode 100755 index 325270cfe3c21636e405a94731e9db04106cb59e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_has_own_property] -// OH_JSVM_HasOwnProperty的样例方法 -static JSVM_Value HasOwnProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的两个参数 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 检查第一个参数是否为对象 - JSVM_ValueType valueType1; - OH_JSVM_Typeof(env, args[0], &valueType1); - if (valueType1 != JSVM_OBJECT) { - OH_JSVM_ThrowError(env, nullptr, "First argument must be an object."); - return nullptr; - } - // 检查第二个参数是否为string - JSVM_ValueType valuetype2; - OH_JSVM_Typeof(env, args[1], &valuetype2); - if (valuetype2 != JSVM_STRING) { - OH_JSVM_ThrowError(env, nullptr, "Second argument must be a string."); - return nullptr; - } - // 检查对象是否具有指定属性,结果存储在hasProperty中 - bool hasProperty; - JSVM_Status status = OH_JSVM_HasOwnProperty(env, args[0], args[1], &hasProperty); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_HasOwnProperty failed"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_HasOwnProperty success:%{public}d", hasProperty); - } - // 将bool结果转换为JSVM_Value并返回 - JSVM_Value result; - OH_JSVM_GetBoolean(env, hasProperty, &result); - return result; -} -// HasOwnProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = HasOwnProperty}, -}; -static JSVM_CallbackStruct *method = param; -// HasOwnProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"hasOwnProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - hasOwnProperty(obj, "message") - hasOwnProperty(obj, "__defineGetter__") -)JS"; -// [End oh_jsvm_has_own_property] - -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 = "hasownproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/oh-package.json5 deleted file mode 100755 index 328049443fee5142610d3921a6601233e64562fa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/cpp/types/libhasownproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libhasownproperty.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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 2f7168def623e15afaf9744e0ca7b161ed2c227b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libhasownproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/module.json5 deleted file mode 100755 index 153fbb77eae95b406ea97cc573a4403b8b0e7d6a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "hasownproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "HasownpropertyAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "HasownpropertyAbility", - "srcEntry": "./ets/hasownpropertyability/HasownpropertyAbility.ets", - "description": "$string:HasownpropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:HasownpropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/string.json deleted file mode 100755 index acc7ad4e1cb4ec6307d4346f8406c34c9eb007a9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "HasownpropertyAbility_desc", - "value": "description" - }, - { - "name": "HasownpropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 2f25df1f3b996543db86dcc04d20cdc89ee1c4f0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testHasOwnProperty', 0, async (done: Function) => { - console.log('uitest: TestHasOwnProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'HasownpropertyAbility' - } - 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('HasownpropertyAbility'); - - 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: TestHasOwnProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/module.json5 deleted file mode 100755 index dda4c6cac68df7c0ef9c5b989a1b6702039e53fd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasownproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "hasownproperty_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/oh-package.json5 deleted file mode 100755 index ad61c4038d2a883ca3dae360c4488fabf6365462..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "hasproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libhasproperty.so": "file:./src/main/cpp/types/libhasproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 468ac51837e1be3709440908694158147a310bf2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPropertyOne) - -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) - -add_library(hasproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(hasproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/hello.cpp deleted file mode 100755 index 413028d04b90dbb200a966b758cdc2555918f9e3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_has_property] -// OH_JSVM_HasProperty的样例方法 -static JSVM_Value HasProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 从js侧传入两个参数:第一个参数为要检验的对象,第二个参数为要检测是否存在对象的属性 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 将参数传入OH_JSVM_HasProperty方法中,若接口调用成功则将结果转化为JSVM_Value类型抛出,否则抛出错误 - bool result; - JSVM_Status status = OH_JSVM_HasProperty(env, args[0], args[1], &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_HasProperty fail"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_HasProperty success:%{public}d", result); - } - // 若传入属性存在传入对象中,则输出true将结果转化为JSVM_Value类型抛出 - JSVM_Value returnReslut = nullptr; - OH_JSVM_GetBoolean(env, result, &returnReslut); - return returnReslut; -} -// HasProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = HasProperty}, -}; -static JSVM_CallbackStruct *method = param; -// HasProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"hasProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - hasProperty(obj, "data") - hasProperty(obj, 0) -)JS"; -// [End oh_jsvm_has_property] - -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 = "hasproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/oh-package.json5 deleted file mode 100755 index 745046399b7e95f30369a2d2390c33ac118c7e6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/cpp/types/libhasproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libhasproperty.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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 54a365db068f018bf318a5cf20be8ba47a2830ec..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libhasproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/module.json5 deleted file mode 100755 index f2d743b9278ac4dcb555f9275f18d254cf92d9e2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "hasproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "HaspropertyAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "HaspropertyAbility", - "srcEntry": "./ets/haspropertyability/HaspropertyAbility.ets", - "description": "$string:HaspropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:HaspropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/string.json deleted file mode 100755 index d4283ee7ba15cdb278a57c13c8dd96147f9dfab4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "HaspropertyAbility_desc", - "value": "description" - }, - { - "name": "HaspropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 34a080c52db3ad95cc6670b5459a08f76e8b9378..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testHasProperty', 0, async (done: Function) => { - console.log('uitest: TestHasProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'HaspropertyAbility' - } - 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('HaspropertyAbility'); - - 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: TestHasProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/module.json5 deleted file mode 100755 index 52307b1f3cdb7d5a395a9be36f46457687741a58..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hasproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "hasproperty_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/ohosTest.md deleted file mode 100755 index c3f113be4437ce9d13656ee0accab8ce84fa6c23..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/ohosTest.md +++ /dev/null @@ -1,18 +0,0 @@ -# JsvmAboutProperty 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 批量的向给定对象中定义属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 用给定的属性的名称,删除目标对象属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定对象的所有可用属性名称 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 用给定的属性的名称,检索目标对象的属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 用给定的属性的名称,检索目标对象的属性,此方法等效于调用Hello World | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定对象的所有可枚举属性名称 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 用给定的属性的名称,查询目标对象是否有此属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断给定Object中是否有名为key的own property | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 用给定的属性的名称,查询目标对象是否有此属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 为给定对象设置一个属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 用给定的属性的名称为目标对象设置属性 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/oh-package.json5 deleted file mode 100755 index 7db23ca0ac8cc099a91919c31568f0b9e3ed230d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "setnamedproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libsetnamedproperty.so": "file:./src/main/cpp/types/libsetnamedproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index f55e7428410ee648200520114c83fb1e996d5f7f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutProperty) - -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) - -add_library(setnamedproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(setnamedproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/hello.cpp deleted file mode 100755 index e105db29e0b6fe7fc8a526d5783e46b6e4b7d955..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_set_named_property] -// OH_JSVM_SetNamedProperty的样例方法 -const size_t STR_KEY_LEN = 32; -static JSVM_Value SetNamedProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取js侧传入的一个参数 - size_t argc = 1; - JSVM_Value str; - char strKey[STR_KEY_LEN] = ""; - OH_JSVM_GetCbInfo(env, info, &argc, &str, nullptr, nullptr); - // 获取传入参数字符串并存储在strKey中 - size_t keyLength; - OH_JSVM_GetValueStringUtf8(env, str, strKey, STR_KEY_LEN, &keyLength); - // 创建一个新对象 - JSVM_Value newObj; - OH_JSVM_CreateObject(env, &newObj); - // 设置整数值1234为属性值 - int32_t value = 1234; - JSVM_Value numValue; - OH_JSVM_CreateInt32(env, value, &numValue); - // 将整数值与指定属性名关联 - JSVM_Status status = OH_JSVM_SetNamedProperty(env, newObj, strKey, numValue); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_SetNamedProperty failed"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_SetNamedProperty success"); - } - // 返回新创建并设置命名属性的对象 - return newObj; -} -// SetNamedProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = SetNamedProperty}, -}; -static JSVM_CallbackStruct *method = param; -// SetNamedProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"setNamedProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - setNamedProperty("message") -)JS"; -// [End oh_jsvm_set_named_property] - -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 = "setnamedproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/oh-package.json5 deleted file mode 100755 index 52424be521d53f4761fec21742ec839b76541d3e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/cpp/types/libsetnamedproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libsetnamedproperty.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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 89c81be87caafb618d4b447ff59f95d1ec30ea80..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libsetnamedproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/module.json5 deleted file mode 100755 index fa829143548c58c0f14c0d5c0c1d8c4beec69615..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "setnamedproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "SetnamedpropertyAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "SetnamedpropertyAbility", - "srcEntry": "./ets/setnamedpropertyability/SetnamedpropertyAbility.ets", - "description": "$string:SetnamedpropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:SetnamedpropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/string.json deleted file mode 100755 index 2787b15d5d88ac9adb38e21735e5bd84286334fe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "SetnamedpropertyAbility_desc", - "value": "description" - }, - { - "name": "SetnamedpropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 46909e12c028df33caab7c3512fb590c2f619f03..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testSetNamedProperty', 0, async (done: Function) => { - console.log('uitest: TestSetNamedProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'SetnamedpropertyAbility' - } - 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('SetnamedpropertyAbility'); - - 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: TestSetNamedProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/module.json5 deleted file mode 100755 index fafc3e927ac5a5499c9175d463d8aebcbb5e4ff5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setnamedproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "setnamedproperty_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutProperty/setproperty/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/setproperty/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutProperty/setproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/oh-package.json5 deleted file mode 100755 index 5a748a07abf44589198d4868a8cb756fd14865f7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "setproperty", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libsetproperty.so": "file:./src/main/cpp/types/libsetproperty" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 865164b58b0617bc407106c5d1fa6d106aebb2bc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutPropertyOne) - -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) - -add_library(setproperty SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(setproperty PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/hello.cpp deleted file mode 100755 index 663f72a97f07201c365881bc34640a9a87c90086..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/hello.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_set_property] -// OH_JSVM_SetProperty的样例方法 -static JSVM_Value SetProperty(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 接收js侧传入的三个参数:第一个参数为想要设置的object,第二个参数为属性,第三个参数为属性对应的值 - size_t argc = 3; - JSVM_Value args[3] = {nullptr}; - JSVM_Status status = OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_GetCbInfo fail"); - return nullptr; - } - // 通过调用OH_JSVM_SetProperty接口将属性与值设置入object如果失败,直接抛出错误 - status = OH_JSVM_SetProperty(env, args[0], args[1], args[2]); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "JSVM OH_JSVM_SetProperty fail"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_SetProperty success"); - } - // 将设置成功后的object返回出去 - return args[0]; -} -// SetProperty注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = SetProperty}, -}; -static JSVM_CallbackStruct *method = param; -// SetProperty方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"setProperty", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let obj = { data: 0, message: "hello world", 50: 1}; - setProperty(obj, "code", "hi") -)JS"; -// [End oh_jsvm_set_property] - -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 = "setproperty", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/oh-package.json5 deleted file mode 100755 index 5a92aab963ccd2eafa6497c70d687a462f68f7ed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/cpp/types/libsetproperty/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libsetproperty.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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/pages/Index.ets deleted file mode 100755 index 84761ef7438de356728ebff14969cd9d13cb9171..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libsetproperty.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/module.json5 deleted file mode 100755 index fb1103814736e724d867b235310ec8e5969967cd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "setproperty", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "SetpropertyAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "SetpropertyAbility", - "srcEntry": "./ets/setpropertyability/SetpropertyAbility.ets", - "description": "$string:SetpropertyAbility_desc", - "icon": "$media:layered_image", - "label": "$string:SetpropertyAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/string.json deleted file mode 100755 index 6aa980d30a6f32d23f5195d5d4e5434547de8399..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "SetpropertyAbility_desc", - "value": "description" - }, - { - "name": "SetpropertyAbility_label", - "value": "JsvmAboutProperty" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index c061efc63a40e7702a30ea9f598be12f8060c262..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testSetProperty', 0, async (done: Function) => { - console.log('uitest: TestSetProperty begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'SetpropertyAbility' - } - 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('SetpropertyAbility'); - - 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: TestSetProperty end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/module.json5 deleted file mode 100755 index ea13358c3e0db1c37ce8f7a1f485c068032bdc72..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutProperty/setproperty/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "setproperty_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmAboutString/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/app.json5 deleted file mode 100755 index 48d4bd983d05f648206cddcf8e1fbdda64df05c7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmaboutstring", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/element/string.json deleted file mode 100755 index a42a2fba6acdb9903f1b6cca9c827e875011b11c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmAboutString" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/README.md deleted file mode 100755 index 6d5f7f5f95a373f159568cfbe4dd5b44cdd729b5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/README.md +++ /dev/null @@ -1,173 +0,0 @@ -# ArkTs使用JSVM-API接口创建和获取string值 - -### 介绍 - -使用JSVM-API接口获取和设置JavaScript对象的属性。通过合理使用这些函数,实现更复杂的功能和逻辑。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口创建和获取string值](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-string.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createstringlatin1/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createstringutf8/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createstringutf16/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluestringlatin1/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluestringutf8/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluestringutf16/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmAboutString > .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/JsvmUsageGuide/JsvmAboutString/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/build-profile.json5 deleted file mode 100755 index d8f9f6ecb591e1e2823bdeee78c1006debab05c5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/build-profile.json5 +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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": "getvaluestringutf8", - "srcPath": "./getvaluestringutf8", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createstringutf8", - "srcPath": "./createstringutf8", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvaluestringutf16", - "srcPath": "./getvaluestringutf16", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createstringutf16", - "srcPath": "./createstringutf16", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvaluestringlatin1", - "srcPath": "./getvaluestringlatin1", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createstringlatin1", - "srcPath": "./createstringlatin1", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/oh-package.json5 deleted file mode 100755 index d9a696fcd8be85dce23c3c0295935250a8625b9e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createstringlatin1", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatestringlatin1.so": "file:./src/main/cpp/types/libcreatestringlatin1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/CMakeLists.txt deleted file mode 100755 index d52859a2bfd4b6801f4185d0cacfcd8d52f2234a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutString) - -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) - -add_library(createstringlatin1 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createstringlatin1 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/hello.cpp deleted file mode 100755 index 1a292bed1d3ce828011516009946c355c921abc0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/hello.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_string_latin1] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -// [StartExclude oh_jsvm_create_string_latin1] -#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) -// [EndExclude oh_jsvm_create_string_latin1] - -// CreateStringLatin1注册回调 -// 定义字符串缓冲区的最大长度 -static const int MAX_BUFFER_SIZE = 128; -// OH_JSVM_CreateStringLatin1的样例方法 -static JSVM_Value CreateStringLatin1(JSVM_Env env, JSVM_CallbackInfo info) -{ - const char *str = "Hello, World! éçñ, successes to create Latin1 string!"; - size_t length = JSVM_AUTO_LENGTH; - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateStringLatin1(env, str, length, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateStringLatin1 fail"); - } else { - char buf[MAX_BUFFER_SIZE]; - size_t lengthInner; - OH_JSVM_GetValueStringLatin1(env, result, buf, MAX_BUFFER_SIZE, &lengthInner); - OH_LOG_INFO(LOG_APP, "JSVM CreateStringLatin1 success: %{public}s", buf); - } - return result; -} -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateStringLatin1}, -}; -static JSVM_CallbackStruct *method = param; -// CreateStringLatin1方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createStringLatin1", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let script = createStringLatin1(); -)JS"; -// [End oh_jsvm_create_string_latin1] - -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 = "createstringlatin1", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/oh-package.json5 deleted file mode 100755 index 2fcc5928d51de38f011bd7ced8e6e31cc837baa5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/cpp/types/libcreatestringlatin1/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatestringlatin1.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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/pages/Index.ets deleted file mode 100755 index f75a6592ead5372f188659a7eece963de4994140..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatestringlatin1.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/module.json5 deleted file mode 100755 index 8a7e0c8372812e49f61c81c2cbdf579269e1566a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createstringlatin1", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createstringlatin1Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createstringlatin1Ability", - "srcEntry": "./ets/createstringlatin1ability/Createstringlatin1Ability.ets", - "description": "$string:Createstringlatin1Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createstringlatin1Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/string.json deleted file mode 100755 index c65d6b2c396cf46e27b83e4d9229a9f342d248b8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createstringlatin1Ability_desc", - "value": "description" - }, - { - "name": "Createstringlatin1Ability_label", - "value": "JsvmAboutString" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 5766f9d48dde41b973f1c518346f87c94f339ad4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateStringLatin1', 0, async (done: Function) => { - console.log('uitest: TestCreateStringLatin1 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createstringlatin1Ability' - } - 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('Createstringlatin1Ability'); - - 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: TestCreateStringLatin1 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/module.json5 deleted file mode 100755 index b17ba9220674e49b816fa89351274d0f07ea324d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringlatin1/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createstringlatin1_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutString/createstringutf16/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringutf16/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutString/createstringutf16/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/oh-package.json5 deleted file mode 100755 index dd734e09315892727dbbb923229cfcb6f3690d9e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createstringutf16", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatestringutf16.so": "file:./src/main/cpp/types/libcreatestringutf16" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 04d44dd7851d21228ebaf621fb2138392198d0bf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutString) - -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) - -add_library(createstringutf16 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createstringutf16 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/hello.cpp deleted file mode 100755 index 5c45e7a12a90372051b66f932f5fe250ba9c0117..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/hello.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_string_utf16] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -#include -#include -// [StartExclude oh_jsvm_create_string_utf16] -#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) -// [EndExclude oh_jsvm_create_string_utf16] - -// OH_JSVM_CreateStringUtf16的样例方法 -static JSVM_Value CreateStringUtf16(JSVM_Env env, JSVM_CallbackInfo info) -{ - const char16_t *str = u"你好, World!, successes to create UTF-16 string!"; - std::u16string ustr(str); - size_t length = ustr.length(); - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateStringUtf16(env, str, length, &result); - std::u16string u16str = {str}; - // 将 std::u16string 转换为 std::string - std::wstring_convert, char16_t> converter; - std::string strResult = converter.to_bytes(u16str); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateStringUtf16 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateStringUtf16 success: %{public}s", strResult.c_str()); - } - return result; -} -// CreateStringUtf16注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateStringUtf16}, -}; -static JSVM_CallbackStruct *method = param; -// CreateStringUtf16方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createStringUtf16", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let script = createStringUtf16(); -)JS"; -// [End oh_jsvm_create_string_utf16] - -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 = "createstringutf16", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/oh-package.json5 deleted file mode 100755 index 261f04720c4a5c58858c4d9a974ac51e399d0009..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/cpp/types/libcreatestringutf16/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatestringutf16.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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/pages/Index.ets deleted file mode 100755 index cb96f822f1e885c9a4065f386e6c78e673e27593..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatestringutf16.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/module.json5 deleted file mode 100755 index 3035bf63310933883600249e44de650af890d622..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createstringutf16", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createstringutf16Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createstringutf16Ability", - "srcEntry": "./ets/createstringutf16ability/Createstringutf16Ability.ets", - "description": "$string:Createstringutf16Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createstringutf16Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/string.json deleted file mode 100755 index b782589bd53f8228872bae90c4f2379876945861..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createstringutf16Ability_desc", - "value": "description" - }, - { - "name": "Createstringutf16Ability_label", - "value": "JsvmAboutString" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 9bd8b87611c41c423d89e12939eb6bebf987b62a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateStringUtf16', 0, async (done: Function) => { - console.log('uitest: TestCreateStringUtf16 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createstringutf16Ability' - } - 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('Createstringutf16Ability'); - - 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: TestCreateStringUtf16 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/module.json5 deleted file mode 100755 index 0228657d5d9ff48e1a5321bba5ee5e6caaba8aa6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf16/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createstringutf16_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutString/createstringutf8/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringutf8/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutString/createstringutf8/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/oh-package.json5 deleted file mode 100755 index 4ee14447f0b4ea72573c9da7e2bbdbef40f8ffc8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createstringutf8", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatestringutf8.so": "file:./src/main/cpp/types/libcreatestringutf8" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 3028ef0c410a121c79fec2338e616fceea65278a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutString) - -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) - -add_library(createstringutf8 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createstringutf8 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/hello.cpp deleted file mode 100755 index ae1b9e4656cecb224a883d6061f3b6bbf6de5627..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/hello.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_string_utf8] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -// [StartExclude oh_jsvm_create_string_utf8] -#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) -// [EndExclude oh_jsvm_create_string_utf8] - -// OH_JSVM_CreateStringUtf8的样例方法 -static JSVM_Value CreateStringUtf8(JSVM_Env env, JSVM_CallbackInfo info) -{ - const char *str = u8"你好, World!, successes to create UTF-8 string!"; - size_t length = strlen(str); - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateStringUtf8(env, str, length, &result); - if (status != JSVM_OK) { - OH_JSVM_ThrowError(env, nullptr, "Failed to create UTF-8 string"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM CreateStringUtf8 success: %{public}s", str); - } - return result; -} -// CreateStringUtf8注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateStringUtf8}, -}; -static JSVM_CallbackStruct *method = param; -// CreateStringUtf8方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createStringUtf8", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let script = createStringUtf8(); -)JS"; -// [End oh_jsvm_create_string_utf8] - -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 = "createstringutf8", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/oh-package.json5 deleted file mode 100755 index dcc507b436589bbced8b8a7e637badcc815b0c8b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/cpp/types/libcreatestringutf8/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatestringutf8.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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/pages/Index.ets deleted file mode 100755 index b1844cdeaf59de57a6fc4f46a63cd493d08d3ed4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatestringutf8.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/module.json5 deleted file mode 100755 index f2d88c25dd45be961974f3e55030a2a3c7f84663..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createstringutf8", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createstringutf8Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createstringutf8Ability", - "srcEntry": "./ets/createstringutf8ability/Createstringutf8Ability.ets", - "description": "$string:Createstringutf8Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createstringutf8Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/string.json deleted file mode 100755 index 963d2bd8aca15f236dfb415ef735d01dd0a71ac9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createstringutf8Ability_desc", - "value": "description" - }, - { - "name": "Createstringutf8Ability_label", - "value": "JsvmAboutString" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index f5e56b4c89cd5cda4cde26bc409d6b32ab52518f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateStringUtf8', 0, async (done: Function) => { - console.log('uitest: TestCreateStringUtf8 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createstringutf8Ability' - } - 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('Createstringutf8Ability'); - - 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: TestCreateStringUtf8 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/module.json5 deleted file mode 100755 index f273d80b981849ba5243e8b551cf7c16265740fe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/createstringutf8/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createstringutf8_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/oh-package.json5 deleted file mode 100755 index 2fe9c61070aab63b04d2f0d42ed6341323b5be12..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluestringlatin1", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluestringlatin1.so": "file:./src/main/cpp/types/libgetvaluestringlatin1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 2e51e58bd654768f3738765ee00063d4b5dc2e90..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutString) - -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) - -add_library(getvaluestringlatin1 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluestringlatin1 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/hello.cpp deleted file mode 100755 index 22ae0ae91452f6c869e2e5a59d05071f1f227c7f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/hello.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_string_latin1] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -// [StartExclude oh_jsvm_get_value_string_latin1] -#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) -// [EndExclude oh_jsvm_get_value_string_latin1] - -// OH_JSVM_GetValueStringLatin1的样例方法 -// 定义字符串缓冲区的最大长度 -static const int MAX_BUFFER_SIZE = 128; -static JSVM_Value GetValueStringLatin1(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - char buf[MAX_BUFFER_SIZE]; - size_t length; - JSVM_Value jsvmRes = nullptr; - JSVM_Status status = OH_JSVM_GetValueStringLatin1(env, args[0], buf, MAX_BUFFER_SIZE, &length); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueStringLatin1 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueStringLatin1 success: %{public}s", buf); - } - OH_JSVM_CreateStringLatin1(env, buf, length, &jsvmRes); - return jsvmRes; -} -// GetValueStringLatin1注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueStringLatin1}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueStringLatin1方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueStringLatin1", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let data = "中文"; - let script = getValueStringLatin1(data); -)JS"; -// [End oh_jsvm_get_value_string_latin1] - -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 = "getvaluestringlatin1", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/oh-package.json5 deleted file mode 100755 index b638ae2d9dcf3ece4cf846e75d8449c349af114c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/cpp/types/libgetvaluestringlatin1/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluestringlatin1.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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/pages/Index.ets deleted file mode 100755 index 8595933ac7c5172e9b2b512382699b8150e8e446..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluestringlatin1.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/module.json5 deleted file mode 100755 index 0f215e43198acdae570c2fe90b0e741327cf1041..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvaluestringlatin1", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Getvaluestringlatin1Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvaluestringlatin1Ability", - "srcEntry": "./ets/getvaluestringlatin1ability/Getvaluestringlatin1Ability.ets", - "description": "$string:Getvaluestringlatin1Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvaluestringlatin1Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/string.json deleted file mode 100755 index 2f6c38297fde7c9427330dac8c3e4277f9afad6a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvaluestringlatin1Ability_desc", - "value": "description" - }, - { - "name": "Getvaluestringlatin1Ability_label", - "value": "JsvmAboutString" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 999d3ab43c2ded5f05322f3ef0f12e18e3cc0e11..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueStringLatin1', 0, async (done: Function) => { - console.log('uitest: TestGetValueStringLatin1 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvaluestringlatin1Ability' - } - 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('Getvaluestringlatin1Ability'); - - 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: TestGetValueStringLatin1 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/module.json5 deleted file mode 100755 index b031af5499950f23960c637b285be09410838468..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringlatin1/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluestringlatin1_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/oh-package.json5 deleted file mode 100755 index 41bff22cfc99d66bc28925fc217b5659ac0f70b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluestringutf16", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluestringutf16.so": "file:./src/main/cpp/types/libgetvaluestringutf16" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 0a3dadf924c6de5c9b0808a15c5f6253a3e23c87..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutString) - -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) - -add_library(getvaluestringutf16 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluestringutf16 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/hello.cpp deleted file mode 100755 index 3775a2734ad933b5da720870b6845bcef38dd732..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/hello.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_string_utf16] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -#include -#include -// [StartExclude oh_jsvm_get_value_string_utf16] -#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) -// [EndExclude oh_jsvm_get_value_string_utf16] - -// OH_JSVM_GetValueStringUtf16的样例方法 -// 定义字符串缓冲区的最大长度 -static const int MAX_BUFFER_SIZE = 128; -static JSVM_Value GetValueStringUtf16(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - JSVM_Value result = nullptr; - size_t length = 0; - char16_t buffer[MAX_BUFFER_SIZE] = {0}; - // 字符串的缓冲区大小 - size_t bufferSize = MAX_BUFFER_SIZE; - JSVM_Status status = OH_JSVM_GetValueStringUtf16(env, args[0], buffer, bufferSize, &length); - // 将 char16_t 转换为 std::u16string - std::u16string u16str = {buffer}; - // 将 std::u16string 转换为 std::string - std::wstring_convert, char16_t> converter; - std::string str = converter.to_bytes(u16str); - // 获取字符串返回结果 - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueStringUtf16 fail"); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueStringUtf16 success: %{public}s", str.c_str()); - } - return result; -} -// GetValueStringUtf16注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueStringUtf16}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueStringUtf16方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueStringUtf16", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let data = "ahello。"; - let script = getValueStringUtf16(data); -)JS"; -// [End oh_jsvm_get_value_string_utf16] - -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 = "getvaluestringutf16", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/oh-package.json5 deleted file mode 100755 index 2cb3cff955bafbf56d93f3d7fa5e3e23969d3c4d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/cpp/types/libgetvaluestringutf16/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluestringutf16.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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/pages/Index.ets deleted file mode 100755 index 64ce337e1c1d2151dbebda07461c17a156aa5435..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluestringutf16.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/module.json5 deleted file mode 100755 index 56a8ad2fc75fc2e05b155212ebb2eb03d06feead..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvaluestringutf16", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Getvaluestringutf16Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvaluestringutf16Ability", - "srcEntry": "./ets/getvaluestringutf16ability/Getvaluestringutf16Ability.ets", - "description": "$string:Getvaluestringutf16Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvaluestringutf16Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/string.json deleted file mode 100755 index 4a8e3f92aa1f354cd2ee04bfeffd5797b69c0488..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvaluestringutf16Ability_desc", - "value": "description" - }, - { - "name": "Getvaluestringutf16Ability_label", - "value": "JsvmAboutString" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 7233ac3afc36ab84d93494ea3d66e37926d29191..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueStringUtf16', 0, async (done: Function) => { - console.log('uitest: TestGetValueStringUtf16 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvaluestringutf16Ability' - } - 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('Getvaluestringutf16Ability'); - - 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: TestGetValueStringUtf16 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/module.json5 deleted file mode 100755 index 792288067af8d2ed0ebc1327960faf5f887f8c03..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf16/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluestringutf16_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/oh-package.json5 deleted file mode 100755 index fbff5ac8d701b67e8bdd6eb3fd3bae05ab3dc47c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluestringutf8", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluestringutf8.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 2f3e9c8fee518f2a5440a82c13c7079beaa58090..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmAboutString) - -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) - -add_library(getvaluestringutf8 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluestringutf8 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/hello.cpp deleted file mode 100755 index 6ff3ff67a119c76e0320f9bcd3b692be1af25bb0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/hello.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_string_utf8] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -#include -// [StartExclude oh_jsvm_get_value_string_utf8] -#define LOG_DOMAIN 0x3200 -#define LOG_TAG "APP" -#define MAX_MALLOC_SIZE 0x800000 - -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) -// [EndExclude oh_jsvm_get_value_string_utf8] - -// OH_JSVM_GetValueStringUtf8的样例方法 -static JSVM_Value GetValueStringUtf8(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - size_t length = 0; - JSVM_Status status = OH_JSVM_GetValueStringUtf8(env, args[0], nullptr, 0, &length); - if (length == 0 || length > MAX_MALLOC_SIZE) { - OH_LOG_ERROR(LOG_APP, "Invalid string length: %{public}zu", length); - return jsVmResult; - } - char *buf = (char *)malloc(length + 1); - status = OH_JSVM_GetValueStringUtf8(env, args[0], buf, length + 1, &length); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueStringUtf8 fail"); - free(buf); - return nullptr; - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueStringUtf8 success: %{public}s", buf); - } - JSVM_Value result = nullptr; - OH_JSVM_CreateStringUtf8(env, buf, length, &result); - free(buf); - return result; -} -// GetValueStringUtf8注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueStringUtf8}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueStringUtf8方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueStringUtf8", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS( - let data = "aaBC+-$%^你好123"; - let script = getValueStringUtf8(data); -)JS"; -// [End oh_jsvm_get_value_string_utf8] - -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 = "getvaluestringutf8", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index cb5b309524cee7f5d561505630ee6064fe0992b1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluestringutf8.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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/pages/Index.ets deleted file mode 100755 index 8c286a1d51c3915751d6f249b0fbecb74ee5acd2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluestringutf8.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/module.json5 deleted file mode 100755 index 2b73a31dd5a44dfe61696239d88b54beaa84ffdf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getvaluestringutf8", - "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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/string.json deleted file mode 100755 index db834031ce122e63a63e707c6b9718e2b5383824..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmAboutString" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index badaf0048cf8d77e7f5102a9136098e5a3f8b500..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueStringUtf8', 0, async (done: Function) => { - console.log('uitest: TestGetValueStringUtf8 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: TestGetValueStringUtf8 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/module.json5 deleted file mode 100755 index 67e5e8f7204c5c7698c8f0166f1a21d88d6b550d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/getvaluestringutf8/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluestringutf8_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmAboutString/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/ohosTest.md deleted file mode 100755 index 9688268b6efcfb6dc8f8b49aa8edc87b99600d24..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmAboutString/ohosTest.md +++ /dev/null @@ -1,13 +0,0 @@ -# JsvmAboutString 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 获取给定JavaScript string对象的Utf8编码字符串 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据Utf8编码的字符串创建一个JavaScript string对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript string对象的Utf16编码字符串 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据Utf16编码的字符串数据创建JavaScript string对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript string对象的Latin1编码字符串 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据Latin-1编码的字符串创建一个JavaScript string对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/app.json5 deleted file mode 100755 index 0b2352e53d264cae5c4feccdd7f2785d2415ea67..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmbasicdatatypes", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/element/string.json deleted file mode 100755 index 07b44328064a591d0308043aa22ee1bedc9ae3a5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmBasicDataTypes" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/README.md deleted file mode 100755 index ae3feb8425332d7a055bfe257157feae94ffb31b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/README.md +++ /dev/null @@ -1,213 +0,0 @@ -# ArkTS使用JSVM-API接口创建基本数据类型 - -### 介绍 - -在JavaScript中,整数类型是一种基本数据类型,用于表示没有小数部分的数值。double类型用于表示有小数的数值。JavaScript的数值存储方式会导致在某些情况下无法准确表示非常大或非常小的数值,在这种情况下,需要使用BigInt对应的JSVM-API接口来处理更大范围的整数。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口创建基本数据类型](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-basic-data-types.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :--------------------------------------------------------------------: | :--------------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World ,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createdouble/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createint32/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createint64/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createuint32/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvaluedouble/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvalueint32/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvalueint64/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvalueuint32/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmBasicDataTypes > .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/JsvmUsageGuide/JsvmBasicDataTypes/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/build-profile.json5 deleted file mode 100755 index 7592cbeea8097139db112bbcc5001446e76b6dc8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/build-profile.json5 +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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": "getvalueuint32", - "srcPath": "./getvalueuint32", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvalueint32", - "srcPath": "./getvalueint32", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvalueint64", - "srcPath": "./getvalueint64", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getvaluedouble", - "srcPath": "./getvaluedouble", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createint32", - "srcPath": "./createint32", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createuint32", - "srcPath": "./createuint32", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createint64", - "srcPath": "./createint64", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createdouble", - "srcPath": "./createdouble", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/code-linter.json5 deleted file mode 100755 index 6908a38b9f860e27d82a721930afa7f8a745c9be..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/code-linter.json5 +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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": { - "@security/no-unsafe-aes": "error", - "@security/no-unsafe-hash": "error", - "@security/no-unsafe-mac": "warn", - "@security/no-unsafe-dh": "error", - "@security/no-unsafe-dsa": "error", - "@security/no-unsafe-ecdsa": "error", - "@security/no-unsafe-rsa-encrypt": "error", - "@security/no-unsafe-rsa-sign": "error", - "@security/no-unsafe-rsa-key": "error", - "@security/no-unsafe-dsa-key": "error", - "@security/no-unsafe-dh-key": "error", - "@security/no-unsafe-3des": "error" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/oh-package.json5 deleted file mode 100755 index 2ffad1e6aba3494f0bbfcb121b8396d545896871..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createdouble", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatedouble.so": "file:./src/main/cpp/types/libcreatedouble" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 8defe1820f7c3e3625b480d83057fd806e6f4ea7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createdouble SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createdouble PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/hello.cpp deleted file mode 100755 index a43da1bb0adf7908e8c8e4f21c7becb5166d30eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/hello.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_double] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_double] -#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) -// [EndExclude oh_jsvm_create_double] - -// OH_JSVM_CreateDouble的样例方法 -static JSVM_Value CreateDouble(JSVM_Env env, JSVM_CallbackInfo info) -{ - double value = 1.234; - // 创建JavaScript中的double数字 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateDouble(env, value, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateDouble fail"); - } else { - double number = 0; - OH_JSVM_GetValueDouble(env, result, &number); - OH_LOG_INFO(LOG_APP, "JSVM CreateDouble success: %{public}f", number); - } - return result; -} - -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateDouble}, -}; -static JSVM_CallbackStruct *method = param; -// CreateDouble方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createDouble", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createDouble())JS"; -// [End oh_jsvm_create_double] - -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 = "createdouble", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 deleted file mode 100755 index 3fb55a4452ec27a4a15ed27fa8ceb137c0183811..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatedouble.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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/pages/Index.ets deleted file mode 100755 index 2d32bc429f1c96eda724508ac96a10e18ea01983..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatedouble.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/module.json5 deleted file mode 100755 index e67fe2313c050d4d861dc16cebe9f9cbf5815846..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createdouble", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatedoubleAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatedoubleAbility", - "srcEntry": "./ets/createdoubleability/CreatedoubleAbility.ets", - "description": "$string:CreatedoubleAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatedoubleAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/string.json deleted file mode 100755 index 443e20337b8d363563dceb38b8c8e57a1475f348..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatedoubleAbility_desc", - "value": "description" - }, - { - "name": "CreatedoubleAbility_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index da0bb7758fe09d9749d61b50446adbc27c33416b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateDouble', 0, async (done: Function) => { - console.log('uitest: TestCreateDouble begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatedoubleAbility' - } - 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('CreatedoubleAbility'); - - 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: TestCreateDouble end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/module.json5 deleted file mode 100755 index 55ac2b0448a36fcf3eec3a1b229e80f49e68e962..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createdouble/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createdouble_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/oh-package.json5 deleted file mode 100755 index 3ddb6a7f84c19862ab4aba77d3244740a298cb02..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createint32", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreateint32.so": "file:./src/main/cpp/types/libcreateint32" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b4b5138d8ceb4c2dbd8c3d8fac3e8217ef0ebaea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createint32 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/hello.cpp deleted file mode 100755 index 669c52c34772a91ba9fd5f8830975c4350808013..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/hello.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_int32] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_int32] -#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) -// [EndExclude oh_jsvm_create_int32] - -// OH_JSVM_CreateInt32的样例方法 -static JSVM_Value CreateInt32(JSVM_Env env, JSVM_CallbackInfo info) -{ - int32_t value = -20; - // 创建JavaScript中的int32数字 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateInt32(env, value, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateInt32 fail"); - } else { - int32_t number = 0; - OH_JSVM_GetValueInt32(env, result, &number); - OH_LOG_INFO(LOG_APP, "JSVM CreateInt32 success: %{public}d", number); - } - return result; -} - -// CreateInt32注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateInt32}, -}; -static JSVM_CallbackStruct *method = param; -// CreateInt32方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createInt32())JS"; -// [End oh_jsvm_create_int32] - -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 = "createint32", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 deleted file mode 100755 index 7e936c3553ddcf771fc36f4b4fc559e43e2653e4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreateint32.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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/pages/Index.ets deleted file mode 100755 index 32f5bc185cd1ae2ca949e9449bca69d0d79fd3fa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreateint32.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/module.json5 deleted file mode 100755 index dfcde23da26e90b3c647153a4751b7f365a3958d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createint32", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createint32Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createint32Ability", - "srcEntry": "./ets/createint32ability/Createint32Ability.ets", - "description": "$string:Createint32Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createint32Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/string.json deleted file mode 100755 index 4952ec019e6b11d90d5209761d4dabc0d0e6e8f4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createint32Ability_desc", - "value": "description" - }, - { - "name": "Createint32Ability_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index b69e5b41434e6b0e3b6ca227f7f61215d01f54c9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateInt32', 0, async (done: Function) => { - console.log('uitest: TestCreateInt32 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createint32Ability' - } - 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('Createint32Ability'); - - 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: TestCreateInt32 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/module.json5 deleted file mode 100755 index 991d61fd96732dbe8a557ad0012a3dba22aec788..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint32/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createint32_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/oh-package.json5 deleted file mode 100755 index a10a43543c72e7da9089ab37df5ecfa08c2819df..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createint64", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreateint64.so": "file:./src/main/cpp/types/libcreateint64" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 6a981df243288ab52d9eb8fb2b7ca96ebb909655..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createint64 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/hello.cpp deleted file mode 100755 index 4f62e14e2802c602ae6129a06a214c9b92789d73..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/hello.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_int64] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_int64] -#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) -// [EndExclude oh_jsvm_create_int64] - -// OH_JSVM_CreateInt64的样例方法 -static JSVM_Value CreateInt64(JSVM_Env env, JSVM_CallbackInfo info) -{ - // int64是有符号的64位整数类型,可以表示范围从-2^63到2^63 - 1的整数,即 -9223372036854775808到9223372036854775807 - // 要表示的整数值 - int64_t value = 2147483648; - // 创建JavaScript中的int64数字 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateInt64(env, value, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateInt64 fail"); - } else { - int64_t number = 0; - OH_JSVM_GetValueInt64(env, result, &number); - OH_LOG_INFO(LOG_APP, "JSVM CreateInt64 success: %{public}ld", number); - } - return result; -} - -// CreateInt64注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateInt64}, -}; -static JSVM_CallbackStruct *method = param; -// CreateInt64方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createInt64())JS"; -// [End oh_jsvm_create_int64] - -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 = "createint64", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 deleted file mode 100755 index 08e7a45a0bc8e2db6ed1a6d1a511e31d347ab248..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreateint64.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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/pages/Index.ets deleted file mode 100755 index 31b8309e2f2b2ef1e1798c3743bd7e479466d10b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreateint64.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/module.json5 deleted file mode 100755 index dcf7e628b52ae232b10642760a31be44e6e759fd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createint64", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createint64Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createint64Ability", - "srcEntry": "./ets/createint64ability/Createint64Ability.ets", - "description": "$string:Createint64Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createint64Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/string.json deleted file mode 100755 index 21b1b8281faf0c659b24bc863ab23cab5cc556a0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createint64Ability_desc", - "value": "description" - }, - { - "name": "Createint64Ability_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 52794e0cf6e356c915e693a8620c3289eb002e08..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateInt64', 0, async (done: Function) => { - console.log('uitest: TestCreateInt64 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createint64Ability' - } - 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('Createint64Ability'); - - 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: TestCreateInt64 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/module.json5 deleted file mode 100755 index edf050545354972a0fb498a5709e27c9595cce6b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createint64/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createint64_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/oh-package.json5 deleted file mode 100755 index 2205c7d23f7f39c1d4cef62bdf757a8fbbff1445..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createuint32", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreateuint32.so": "file:./src/main/cpp/types/libcreateuint32" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9463604e10f153870d056655affe444ce1b90ce2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(createuint32 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createuint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/hello.cpp deleted file mode 100755 index 98de1a91a678735c199fe60fb1dbee38076399f8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/hello.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_uint32] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_create_uint32] -#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) -// [EndExclude oh_jsvm_create_uint32] - -// OH_JSVM_CreateUint32的样例方法 -static JSVM_Value CreateUInt32(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 如果使用 - // uint32_t类型来定义-26,会发生溢出,溢出时会对结果进行模运算,将负数的二进制补码转换为相应的正数。-26输出4294967270 - // uint32_t是无符号的32位整数类型,只能表示非负整数。它的范围是从0到2 ^32 - 1,即0到4294967295 - // 要表示的整数值 - uint32_t value = 26; - // 创建JavaScript中的uint32数字 - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateUint32(env, value, &result); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM CreateUInt32 fail"); - } else { - uint32_t number = 0; - OH_JSVM_GetValueUint32(env, result, &number); - OH_LOG_INFO(LOG_APP, "JSVM CreateUInt32 success: %{public}u", number); - } - return result; -} - -// CreateUInt32注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = CreateUInt32}, -}; -static JSVM_CallbackStruct *method = param; -// CreateUInt32方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"createUInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(createUInt32())JS"; -// [End oh_jsvm_create_uint32] - -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 = "createuint32", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 deleted file mode 100755 index 7bfb2c66cf5c1000638ac3dc6463b440c96108ea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreateuint32.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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/pages/Index.ets deleted file mode 100755 index 3072091e6c1073d2bee6011d853aff38a11e1544..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreateuint32.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/module.json5 deleted file mode 100755 index cc25dc7fe18a00c375c36502c9f443b95bdaef41..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createuint32", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Createuint32Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Createuint32Ability", - "srcEntry": "./ets/createuint32ability/Createuint32Ability.ets", - "description": "$string:Createuint32Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Createuint32Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/string.json deleted file mode 100755 index a4c07ca4de33c832a5ff17c83f93f66ec04de0b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Createuint32Ability_desc", - "value": "description" - }, - { - "name": "Createuint32Ability_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 7cd741c7c48b6ab5b27d7194132bc0e06eecdbb8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateUint32', 0, async (done: Function) => { - console.log('uitest: TestCreateUint32 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Createuint32Ability' - } - 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('Createuint32Ability'); - - 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: TestCreateUint32 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/module.json5 deleted file mode 100755 index 9257b69e82cce8445d462e6eb3bb556fe60e6d22..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/createuint32/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createuint32_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/oh-package.json5 deleted file mode 100755 index a4b612239b21b42517d05ba5e9033c76be6a9758..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvaluedouble", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvaluedouble.so": "file:./src/main/cpp/types/libgetvaluedouble" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 8bd85de0c75b0a74fcd74fb8a5d1d30a24a0bd53..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(getvaluedouble SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvaluedouble PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/hello.cpp deleted file mode 100755 index 03d8f1f8d943b4569056bdfea8eb01464ab7b43e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/hello.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_double] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_value_double] -#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) -// [EndExclude oh_jsvm_get_value_double] - -// OH_JSVM_GetValueDouble的样例方法 -static JSVM_Value GetDouble(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - double value; - JSVM_Status status = OH_JSVM_GetValueDouble(env, args[0], &value); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetDouble fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetDouble success: %{public}f", value); - } - return args[0]; -} - -// GetDouble注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetDouble}, -}; -static JSVM_CallbackStruct *method = param; -// GetDouble方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getDouble", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getDouble(-110.0456))JS"; -// [EndExclude oh_jsvm_get_value_double] - -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 = "getvaluedouble", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/oh-package.json5 deleted file mode 100755 index e82145546b63812510fdab79db34232ed0832dca..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/cpp/types/libgetvaluedouble/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvaluedouble.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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/pages/Index.ets deleted file mode 100755 index cf01d3f3fa4e5c2cbe299a4f9aed5502593da29f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvaluedouble.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/module.json5 deleted file mode 100755 index ef5f2188e2fc88e23fc846906c01d0aacfe039eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvaluedouble", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetvaluedoubleAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetvaluedoubleAbility", - "srcEntry": "./ets/getvaluedoubleability/GetvaluedoubleAbility.ets", - "description": "$string:GetvaluedoubleAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetvaluedoubleAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/string.json deleted file mode 100755 index 4f731d212fbc69b9e88ba52efd0b8de8dd5d2790..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetvaluedoubleAbility_desc", - "value": "description" - }, - { - "name": "GetvaluedoubleAbility_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 8156b7a3ff2db05aa31cf5a640502bea1b044d9d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueDouble', 0, async (done: Function) => { - console.log('uitest: TestGetValueDouble begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetvaluedoubleAbility' - } - 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('GetvaluedoubleAbility'); - - 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: TestGetValueDouble end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/module.json5 deleted file mode 100755 index 2b02944b229b6e8f1c76841971e51ee7606d3c99..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvaluedouble/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvaluedouble_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/oh-package.json5 deleted file mode 100755 index c2656b7e45b0da7b01c1c3808c20c9bed4ef0d97..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvalueint32", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvalueint32.so": "file:./src/main/cpp/types/libgetvalueint32" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 64e952af9fcc0c4b3429a384d64a79e3d8b09fba..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(getvalueint32 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvalueint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/hello.cpp deleted file mode 100755 index 91284f3db599b0c4cb5996cfb19a2f619f40612b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/hello.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_int32] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_value_int32] -#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) -// [EndExclude oh_jsvm_get_value_int32] - -// OH_JSVM_GetValueInt32的样例方法 -static JSVM_Value GetValueInt32(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - int32_t result32 = 0; - // 解析传递的参数 - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 将前端传过来的参数转为JSVM模块的int32类型 - JSVM_Status status = OH_JSVM_GetValueInt32(env, args[0], &result32); - if (status != JSVM_OK) { - return nullptr; - } - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueInt32 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueInt32 success: %{public}d", result32); - } - return args[0]; -} - -// GetValueInt32注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueInt32}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueInt32方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getValueInt32(-123))JS"; -// [EndExclude oh_jsvm_get_value_int32] - -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 = "getvalueint32", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/oh-package.json5 deleted file mode 100755 index b66b71212ef443729b0d9d65fc6af08c117f1ea6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/cpp/types/libgetvalueint32/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvalueint32.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/pages/Index.ets deleted file mode 100755 index d30d9aef64b6f5d3d8c6f13936de27becd54cd45..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvalueint32.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/module.json5 deleted file mode 100755 index 9fa14e29de7e25a31496a9f9c22566667540f362..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvalueint32", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Getvalueint32Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvalueint32Ability", - "srcEntry": "./ets/getvalueint32ability/Getvalueint32Ability.ets", - "description": "$string:Getvalueint32Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvalueint32Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/string.json deleted file mode 100755 index cd92a017c6b28927d6b84fb419d172433c317ece..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvalueint32Ability_desc", - "value": "description" - }, - { - "name": "Getvalueint32Ability_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index ae013930bdb389667c23fa4403de1e19f54d547c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueInt32', 0, async (done: Function) => { - console.log('uitest: TestGetValueInt32 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvalueint32Ability' - } - 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('Getvalueint32Ability'); - - 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: TestGetValueInt32 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/module.json5 deleted file mode 100755 index 686641c799f83555c71873a20f98f76d92be4317..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint32/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvalueint32_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/oh-package.json5 deleted file mode 100755 index 96d2a56367a1a9466e5ee5e7ca6dc9dec2233659..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvalueint64", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvalueint64.so": "file:./src/main/cpp/types/libgetvalueint64" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 21bbc9754c69f37da62a1a5a7eb923eaf598cdaa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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(getvalueint64 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvalueint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/hello.cpp deleted file mode 100755 index f8f2451be871a08ae520d3640680250993b4c644..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/hello.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_int64] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_value_int64] -#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) -// [EndExclude oh_jsvm_get_value_int64] - -// OH_JSVM_GetValueInt64的样例方法 -static JSVM_Value GetValueInt64(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - int64_t result64 = 0; - // 解析传递的值 - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 将前端传过来的参数分别转为JSVM模块的int64类型 - JSVM_Status status = OH_JSVM_GetValueInt64(env, args[0], &result64); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueInt64 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueInt64 success: %{public}d", result64); - } - return args[0]; -} - -// GetValueInt64注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueInt64}, -}; -static JSVM_CallbackStruct *method = param; -// GetValueInt64方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getValueInt64(-123))JS"; -// [End oh_jsvm_get_value_int64] - -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 = "getvalueint64", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/oh-package.json5 deleted file mode 100755 index 97fea61b98cbe6767a6d56fcbc43d18af6b31181..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/cpp/types/libgetvalueint64/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvalueint64.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/pages/Index.ets deleted file mode 100755 index e8293f9c5b51c03db460043654d04be83dfc4598..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvalueint64.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/module.json5 deleted file mode 100755 index 35160b266acb4cf262baeb08034fa95c31faf0bc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getvalueint64", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Getvalueint64Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvalueint64Ability", - "srcEntry": "./ets/getvalueint64ability/Getvalueint64Ability.ets", - "description": "$string:Getvalueint64Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvalueint64Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/string.json deleted file mode 100755 index f583d497b804bb82f3d83c1c36b7a4e9632a784c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvalueint64Ability_desc", - "value": "description" - }, - { - "name": "Getvalueint64Ability_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 447073c3fdfcbfb745bdc854566afae025763623..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueInt64', 0, async (done: Function) => { - console.log('uitest: TestGetValueInt64 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvalueint64Ability' - } - 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('Getvalueint64Ability'); - - 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: TestGetValueInt64 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/module.json5 deleted file mode 100755 index 586f5136271457cee1d20f05455627c00098dc9a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueint64/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvalueint64_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/oh-package.json5 deleted file mode 100755 index 4fd3e2eba4ab289a33f52e36283560e08323cae2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvalueuint32", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvalueuint32.so": "file:./src/main/cpp/types/libgetvalueuint32" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/CMakeLists.txt deleted file mode 100755 index df0efbaf6091a313d439f46b1758992b6ea65454..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(GetValueUint32) - -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(getvalueuint32 SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvalueuint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/hello.cpp deleted file mode 100755 index 3165b0388b8cc0db8238d1c8f257d93ba9f99e51..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/hello.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_value_uint32] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" - -// [StartExclude oh_jsvm_get_value_uint32] -#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) -// [EndExclude oh_jsvm_get_value_uint32] - -// OH_JSVM_GetValueUint32的样例方法 -static JSVM_Value GetValueUint32(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取传入的数字类型参数 - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - // 解析传入的参数 - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - uint32_t number = 0; - // 获取传入参数的值中的无符号32位整数 - JSVM_Status status = OH_JSVM_GetValueUint32(env, argv[0], &number); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM GetValueUint32 fail"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM GetValueUint32 success: %{public}u", number); - } - return argv[0]; -} - -// GetValueUint32注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetValueUint32}, -}; -static JSVM_CallbackStruct *method = param; - -// GetValueUint32方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getValueUint32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -const char* SRC_CALL_NATIVE = R"JS(getValueUint32(123))JS"; -// [End oh_jsvm_get_value_uint32] - -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 = "getvalueuint32", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/oh-package.json5 deleted file mode 100755 index b06823b75ce32f757d74a8d35954fc17554d0419..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/cpp/types/libgetvalueuint32/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvalueuint32.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/pages/Index.ets deleted file mode 100755 index 35fb46201e15c11e3bc27e5b809e22fcbf4d8e54..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvalueuint32.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/module.json5 deleted file mode 100755 index 100e9decb2e6f8b62cd1ec982d49a71bf9aabc6a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getvalueuint32", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "Getvalueuint32Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Getvalueuint32Ability", - "srcEntry": "./ets/getvalueuint32ability/Getvalueuint32Ability.ets", - "description": "$string:Getvalueuint32Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Getvalueuint32Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "Getvalueuint32BackupAbility", - "srcEntry": "./ets/getvalueuint32backupability/Getvalueuint32BackupAbility.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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/float.json deleted file mode 100755 index a8a5d404dcd8b0466194afc3aa25d90a8a327470..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/float.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/string.json deleted file mode 100755 index 96a70e17d9cc48c33ea172c1d9520d4d84d20d21..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "Getvalueuint32Ability_desc", - "value": "description" - }, - { - "name": "Getvalueuint32Ability_label", - "value": "JsvmBasicDataTypes" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 0c060b29824d6b6418eabd3f713bbbf27a8bf220..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetValueUint32', 0, async (done: Function) => { - console.log('uitest: TestGetValueUint32 begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'Getvalueuint32Ability' - } - 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('Getvalueuint32Ability'); - - 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: TestGetValueUint32 end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/module.json5 deleted file mode 100755 index a40e14a8fa4553aa1bc48bad6f9b3c760c2b1c6c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/getvalueuint32/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvalueuint32_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigor/hvigor-config.json5 deleted file mode 100755 index 8d4c6165b5641a4b568559d24ebba0d7105ee19c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "modelVersion": "5.0.2", - "dependencies": { - }, - "execution": { - // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ - // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ - // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ - // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ - }, - "nodeOptions": { - // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ - // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmBasicDataTypes/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/oh-package.json5 deleted file mode 100755 index 635416b1c57681f2f8e7fad6afd753a3f0753daf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "modelVersion": "5.0.2", - "description": "Please describe the basic information.", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.21", - "@ohos/hamock": "1.0.0" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/ohosTest.md deleted file mode 100755 index 9202aff6bd0b8b2fb3e4435fd054fb0c257e7aad..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmBasicDataTypes/ohosTest.md +++ /dev/null @@ -1,15 +0,0 @@ -# JsvmBasicDataTypes 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 根据Double类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据Int32_t类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据Int64_t类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 根据Uint32_t类型对象创建JavaScript number对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript number的Double基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript number的Int32基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript number的Int64基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取给定JavaScript number的Uint32基础类型值 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmError/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/app.json5 deleted file mode 100755 index 04fde9d869dd83eb111d95723a75b6a8657d2af7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmerror", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/element/string.json deleted file mode 100755 index 9818687db5252bff3e5df4d00f5bd237aeca5c7f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmError" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/README.md deleted file mode 100755 index 9140d22f42046eb43bdcfea6a4bb3c3551822f04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/README.md +++ /dev/null @@ -1,293 +0,0 @@ -# ArkTs使用JSVM-API接口进行错误处理开发 - -### 介绍 - -使用JSVM-API接口进行错误处理开发,使得在JSVM-API模块中能够更好地管理和响应错误情况。通过合理使用这些函数,可以提高模块的稳定性和可靠性。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行错误处理开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-error.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :-----------------------------------------------------------: | :-----------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -createerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createrangeerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createsyntaxerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createtypeerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getandclearlastexception/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getlasterrorinfo/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -iserror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -isexceptionpending/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -throwerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -throwrangeerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -throwsyntaxerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -throwtypeerror/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmError > .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/JsvmUsageGuide/JsvmError/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/build-profile.json5 deleted file mode 100755 index 3a9eaaf8f924a240fa80ae1d0fb27bd6a8b8afb5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/build-profile.json5 +++ /dev/null @@ -1,190 +0,0 @@ -/* - * 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": "createerror", - "srcPath": "./createerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "throwerror", - "srcPath": "./throwerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "throwtypeerror", - "srcPath": "./throwtypeerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "throwrangeerror", - "srcPath": "./throwrangeerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "throwsyntaxerror", - "srcPath": "./throwsyntaxerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "iserror", - "srcPath": "./iserror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createtypeerror", - "srcPath": "./createtypeerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createrangeerror", - "srcPath": "./createrangeerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "createsyntaxerror", - "srcPath": "./createsyntaxerror", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getandclearlastexception", - "srcPath": "./getandclearlastexception", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "isexceptionpending", - "srcPath": "./isexceptionpending", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getlasterrorinfo", - "srcPath": "./getlasterrorinfo", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/createerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/createerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/oh-package.json5 deleted file mode 100755 index a5fc50bf757397871a2fc5931ad98d7b5f553f71..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreateerror.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index c5484099daf79eebb7caa7900fd96e401f3b3126..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(createerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/hello.cpp deleted file mode 100755 index a409805922c17ef8ceb0aab4ea7bf869a8dbc686..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_create_error] -// 捕获清除并打印错误,该函数作为公共函数,在本文档后续样例中不再声明和定义 -static void GetLastErrorAndClean(JSVM_Env env) -{ - // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); - // 打印错误信息 - JSVM_Value message; - JSVM_Value errorCode; - OH_JSVM_GetNamedProperty((env), result, "message", &message); - OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); - const int maxMessageLength = 256; - const int maxCodeLength = 256; - char messagestr[maxMessageLength]; - char codeStr[maxCodeLength]; - OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); - OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); - OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); -} - -// OH_JSVM_CreateError的样例方法 -static JSVM_Value JsVmCreateThrowError(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 - JSVM_Value errorCode = nullptr; - OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); - // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 - JSVM_Value errorMessage = nullptr; - OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); - // 创建一个JavaScript对象error - JSVM_Value error = nullptr; - OH_JSVM_CreateError(env, errorCode, errorMessage, &error); - // 通过OH_JSVM_Throw接口将对象抛出 - OH_JSVM_Throw(env, error); - GetLastErrorAndClean(env); - return nullptr; -} - -// JsVmThrow注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmCreateThrowError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmThrow方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmCreateThrowError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmCreateThrowError();)JS"; -// [End oh_jsvm_create_error] - -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 = "createerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 829ad5fd7e4c31b24b32d9c1abcc40568c6f0d12..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreateerror.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/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/pages/Index.ets deleted file mode 100755 index 1eefbc5ae3dfa9b9dd08f92be296f0e14e136772..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreateerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/createerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/module.json5 deleted file mode 100755 index ee7a5d5ed383cac935289b803fc0a589c5b162a2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "createerror", - "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/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/string.json deleted file mode 100755 index fc7be80287bab7ddddf497790c60c8c2131618fd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 2f0bf8899653e15e5b6ee6d0605522bd4741b9ef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateError', 0, async (done: Function) => { - console.log('uitest: TestCreateError 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: TestCreateError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/module.json5 deleted file mode 100755 index 4a3fd27594d82847d3de6c464054b2edae4844f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createerror_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/createrangeerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createrangeerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/createrangeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/oh-package.json5 deleted file mode 100755 index a25803931e4d2b993890fa8a71bc50c978ffe744..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createrangeerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreaterangeerror.so": "file:./src/main/cpp/types/libcreaterangeerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 01313dd04889f2264d267819206eecfc49dea6ff..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(createrangeerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createrangeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/hello.cpp deleted file mode 100755 index e43240c661ff6776e7961cbaa2c36cd6a14c61ea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_create_range_error] -// OH_JSVM_CreateRangeError的样例方法 -static JSVM_Value JsVmCreateRangeError(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 - JSVM_Value errorCode = nullptr; - OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); - // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 - JSVM_Value errorMessage = nullptr; - OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateRangeError(env, errorCode, errorMessage, &result); - if (status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM API CreateRangeError SUCCESS"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM API CreateRangeError FAILED"); - } - return result; -} -// JsVmCreateRangeError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmCreateRangeError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmCreateRangeError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmCreateRangeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmCreateRangeError();)JS"; -// [End oh_jsvm_create_range_error] - -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 = "createrangeerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/oh-package.json5 deleted file mode 100755 index 87811c5d754e90e1b1e89864664ae36c8eed041b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/cpp/types/libcreaterangeerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreaterangeerror.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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/pages/Index.ets deleted file mode 100755 index e1fb293c740f6b01eb9a85d34136b42cffffc0ab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreaterangeerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/createrangeerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/module.json5 deleted file mode 100755 index aa3306221f463d39d288ce49443d25eda4ce72df..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createrangeerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreaterangeerrorAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreaterangeerrorAbility", - "srcEntry": "./ets/createrangeerrorability/CreaterangeerrorAbility.ets", - "description": "$string:CreaterangeerrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreaterangeerrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/string.json deleted file mode 100755 index ec0182512aa58a3c34ff5e93cd7069326c85340c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreaterangeerrorAbility_desc", - "value": "description" - }, - { - "name": "CreaterangeerrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 64be00249e53dccb2c8ebf4bb3e558664873eb24..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateRangeError', 0, async (done: Function) => { - console.log('uitest: TestCreateRangeError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreaterangeerrorAbility' - } - 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('CreaterangeerrorAbility'); - - 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: TestCreateRangeError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/module.json5 deleted file mode 100755 index 03dea5d0a28d64fad0fb9dc0ca2b843204411f91..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createrangeerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createrangeerror_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/createsyntaxerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createsyntaxerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/createsyntaxerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/oh-package.json5 deleted file mode 100755 index f0e76e351ea0af0ebc5e716878879a567e545a47..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createsyntaxerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatesyntaxerror.so": "file:./src/main/cpp/types/libcreatesyntaxerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index a34c88e1e015acb17e14c0c416974dadb76b0c35..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(createsyntaxerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createsyntaxerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/hello.cpp deleted file mode 100755 index 6d420a47b6adb1f6c66a3ea84103b35ac16beaab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_create_syntax_error] -// OH_JSVM_CreateSyntaxError的样例方法 -static JSVM_Value JsVmCreateSyntaxError(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 - JSVM_Value errorCode = nullptr; - OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); - // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 - JSVM_Value errorMessage = nullptr; - OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateSyntaxError(env, errorCode, errorMessage, &result); - if (status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM API CreateSyntaxError SUCCESS"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM API CreateSyntaxError FAILED"); - } - return result; -} -// JsVmCreateSyntaxError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmCreateSyntaxError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmThrow方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmCreateSyntaxError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmCreateSyntaxError();)JS"; -// [End oh_jsvm_create_syntax_error] - -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 = "createsyntaxerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/oh-package.json5 deleted file mode 100755 index 6f1311c9f9bd29861c347da03b3b586ca793805b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/cpp/types/libcreatesyntaxerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatesyntaxerror.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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/pages/Index.ets deleted file mode 100755 index d44750a57f1e097541324aca467e4dd6319b1027..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatesyntaxerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/module.json5 deleted file mode 100755 index 449335b6b98ab219fe3ad4168ab65c41ef31b6b6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createsyntaxerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreatesyntaxerrorAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreatesyntaxerrorAbility", - "srcEntry": "./ets/createsyntaxerrorability/CreatesyntaxerrorAbility.ets", - "description": "$string:CreatesyntaxerrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreatesyntaxerrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/string.json deleted file mode 100755 index e316f2170350397cad9a98fb8d15586c35e8e75f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreatesyntaxerrorAbility_desc", - "value": "description" - }, - { - "name": "CreatesyntaxerrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index a4f5d1732b9f1350884744e6c012d4879667e62e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateSyntaxError', 0, async (done: Function) => { - console.log('uitest: TestCreateSyntaxError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreatesyntaxerrorAbility' - } - 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('CreatesyntaxerrorAbility'); - - 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: TestCreateSyntaxError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/module.json5 deleted file mode 100755 index 91f2313d80a81756d4a624dc0daec44ce64b5c7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createsyntaxerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createsyntaxerror_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/createtypeerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createtypeerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/createtypeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/oh-package.json5 deleted file mode 100755 index 04869db2d594d08d941d348929c04cdd8efc714d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createtypeerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatetypeerror.so": "file:./src/main/cpp/types/libcreatetypeerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 3eb1cbdf19d24b22b1ba99f63021ef6fb61299cf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(createtypeerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createtypeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/hello.cpp deleted file mode 100755 index 7eac12fcf3ff2322edfefbe6a4423df72f72e5e3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_create_type_error] -// OH_JSVM_CreateTypeError的样例方法 -static JSVM_Value JsVmCreateTypeError(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 在JSVM环境中创建一个字符串,并将其存储在errorCode变量中 - JSVM_Value errorCode = nullptr; - OH_JSVM_CreateStringUtf8(env, "-1", JSVM_AUTO_LENGTH, &errorCode); - // 在JSVM环境中创建一个字符串,并将其存储在errorMessage变量中 - JSVM_Value errorMessage = nullptr; - OH_JSVM_CreateStringUtf8(env, "HasError", JSVM_AUTO_LENGTH, &errorMessage); - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_CreateTypeError(env, errorCode, errorMessage, &result); - if (status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM API Create TypeError SUCCESS"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM API Create TypeError FAILED"); - } - return result; -} -// JsVmCreateTypeError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmCreateTypeError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmCreateTypeError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmCreateTypeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmCreateTypeError();)JS"; -// [End oh_jsvm_create_type_error] - -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 = "createtypeerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/oh-package.json5 deleted file mode 100755 index e0c257dce2d5af342f3753e07a23dfad52c2aadf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/cpp/types/libcreatetypeerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatetypeerror.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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/pages/Index.ets deleted file mode 100755 index fc4d6af506019e75fd16ac22e4db4044d7951a1d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libcreatetypeerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/createtypeerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/module.json5 deleted file mode 100755 index 3a6433a1ad16475348c70cf59d6204b17d118cd8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "createtypeerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "CreateTypeErrorAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "CreateTypeErrorAbility", - "srcEntry": "./ets/createtypeerrorability/CreateTypeErrorAbility.ets", - "description": "$string:CreateTypeErrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:CreateTypeErrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/string.json deleted file mode 100755 index f84c143f98ba523105d49dc5cc97e84518da8ae9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "CreateTypeErrorAbility_desc", - "value": "description" - }, - { - "name": "CreateTypeErrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 6d1c03f7782e19de1d3fbcd96622955dfcfed2f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testCreateTypeError', 0, async (done: Function) => { - console.log('uitest: TestCreateTypeError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'CreateTypeErrorAbility' - } - 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('CreateTypeErrorAbility'); - - 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: TestCreateTypeError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/module.json5 deleted file mode 100755 index 8238646db73125cc296d08fb276e333e1c382abe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/createtypeerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createtypeerror_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/getandclearlastexception/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/getandclearlastexception/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/getandclearlastexception/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/oh-package.json5 deleted file mode 100755 index d607a6ee8ca95eeeb7d63a5e2d109dba2e1c26fd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getandclearlastexception", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetandclearlastexception.so": "file:./src/main/cpp/types/libgetandclearlastexception" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 7b34e025a6ea98569aa2eb823ee9c20e8ce7c3f7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(getandclearlastexception SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getandclearlastexception PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/hello.cpp deleted file mode 100755 index 9112e0c35e4acc18084343ea1fd78a631d00d197..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/hello.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_get_and_clear_last_exception] -// OH_JSVM_GetAndClearLastException的样例方法 -static JSVM_Value JsVmGetAndClearLastException(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 抛出异常,创造异常情况 - OH_JSVM_ThrowError(env, "OH_JSVM_ThrowError errorCode", "OH_JSVM_ThrowError errorMessage"); - // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); - if (status != JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_GetAndClearLastException FAILED"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_GetAndClearLastException SUCCESS"); - } - return result; -} -// JsVmGetAndClearLastException注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmGetAndClearLastException}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmGetAndClearLastException方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmGetAndClearLastException", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmGetAndClearLastException();)JS"; -// [End oh_jsvm_get_and_clear_last_exception] - -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 = "getandclearlastexception", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/oh-package.json5 deleted file mode 100755 index 3d496a26da8b939eb1d6e2ff90efd266c04f7e62..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/cpp/types/libgetandclearlastexception/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetandclearlastexception.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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/pages/Index.ets deleted file mode 100755 index 0f157cf9a9327196fd6122fd69bafa5e601637a3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetandclearlastexception.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/module.json5 deleted file mode 100755 index 91ad41dbddd9470fbfe2d765f58acfd659ade5c6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getandclearlastexception", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetandclearlastexceptionAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetandclearlastexceptionAbility", - "srcEntry": "./ets/getandclearlastexceptionability/GetandclearlastexceptionAbility.ets", - "description": "$string:GetandclearlastexceptionAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetandclearlastexceptionAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/string.json deleted file mode 100755 index bd3602a9eef5648f3348317ace34dba84e0074a8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetandclearlastexceptionAbility_desc", - "value": "description" - }, - { - "name": "GetandclearlastexceptionAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 564cdcea37032266802f9a5179372645481ce7c0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetAndClearLastException', 0, async (done: Function) => { - console.log('uitest: TestGetAndClearLastException begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetandclearlastexceptionAbility' - } - 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('GetandclearlastexceptionAbility'); - - 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: TestGetAndClearLastException end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/module.json5 deleted file mode 100755 index ef66a432e76b06bf40cf46277d8e39d4fedf298b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getandclearlastexception/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getandclearlastexception_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/getlasterrorinfo/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/getlasterrorinfo/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/getlasterrorinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/oh-package.json5 deleted file mode 100755 index 2b1e7e8384726b1fe7dfcfd17a6c1438e8908e16..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getlasterrorinfo", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetlasterrorinfo.so": "file:./src/main/cpp/types/libgetlasterrorinfo" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 3c5ddc6e74a932f6a4f69ff307ede204084a75de..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(getlasterrorinfo SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getlasterrorinfo PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/hello.cpp deleted file mode 100755 index 601edb67e943b9ac9f8f29b752d2463ef9915cbf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/hello.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_get_last_error_info] -// OH_JSVM_GetLastErrorInfo的样例方法 -static JSVM_Value JsVmGetLastErrorInfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取输入参数(这里以字符串message作为参数传入) - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 将传入的字符串参数以OH_JSVM_GetValueInt32取出,主动制造错误 - int32_t value = 0; - OH_JSVM_GetValueInt32(env, args[0], &value); - // 调用接口OH_JSVM_GetLastErrorInfo获取最后一次错误信息 - const JSVM_ExtendedErrorInfo *errorInfo; - OH_JSVM_GetLastErrorInfo(env, &errorInfo); - - // 取出错误消息作为返回值带出去打印 - JSVM_Value result = nullptr; - OH_LOG_INFO(LOG_APP, - "JSVM API OH_JSVM_GetLastErrorInfo: SUCCESS, error message is %{public}s, error code is %{public}d", - errorInfo->errorMessage, errorInfo->errorCode); - // 对异常进行处理,防止程序由于抛异常而退出 - JSVM_Value result1 = nullptr; - OH_JSVM_GetAndClearLastException(env, &result1); - OH_JSVM_CreateInt32(env, errorInfo->errorCode, &result); - return result; -} -// JsVmGetLastErrorInfo注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmGetLastErrorInfo}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmGetLastErrorInfo方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmGetLastErrorInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmGetLastErrorInfo();)JS"; -// [End oh_jsvm_get_last_error_info] - -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 = "getlasterrorinfo", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/oh-package.json5 deleted file mode 100755 index fc0beb5f027e67f732aa977280dffa018e9aafdc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/cpp/types/libgetlasterrorinfo/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetlasterrorinfo.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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/pages/Index.ets deleted file mode 100755 index e223955b81abd16eda04ae3bc703f844ba2660da..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetlasterrorinfo.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/module.json5 deleted file mode 100755 index 5ceb174fa47e2d2276dea80ea44b1937a398c254..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getlasterrorinfo", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetlasterrorInfoAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetlasterrorInfoAbility", - "srcEntry": "./ets/getlasterrorinfoability/GetlasterrorInfoAbility.ets", - "description": "$string:GetlasterrorInfoAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetlasterrorInfoAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/string.json deleted file mode 100755 index dea87b73159b3a9be4bee0bf83a1f777b2190bbf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetlasterrorInfoAbility_desc", - "value": "description" - }, - { - "name": "GetlasterrorInfoAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index f024ad3a204f14a854d3776183eb6b1fababdd70..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetLastErrorInfo', 0, async (done: Function) => { - console.log('uitest: TestGetLastErrorInfo begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetlasterrorInfoAbility' - } - 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('GetlasterrorInfoAbility'); - - 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: TestGetLastErrorInfo end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/module.json5 deleted file mode 100755 index bc31ddf4870984d78d496c8069eb4706070854c0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/getlasterrorinfo/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getlasterrorinfo_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/iserror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/iserror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/iserror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/iserror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/oh-package.json5 deleted file mode 100755 index a813e52c3c0060610176a75f541c9941836351a9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "iserror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libiserror.so": "file:./src/main/cpp/types/libiserror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 58f3b6251605ac2f253eae494c03ec252e0b46f7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(iserror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(iserror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/hello.cpp deleted file mode 100755 index 795a0fe3d0bd0f7cb78ca7054768fbe1d5d7ce45..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_is_error] -// OH_JSVM_IsError的样例方法 -static JSVM_Value JsVmIsError(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, args, nullptr, nullptr); - // 调用接口OH_JSVM_IsError判断入参是否为一个error对象 - bool result = false; - // 如果JSVM_Value为一个error对象,则设置result为true的布尔值,否则设置为false - JSVM_Status status = OH_JSVM_IsError(env, args[0], &result); - if (status == JSVM_OK) { - OH_LOG_INFO(LOG_APP, "JSVM API call OH_JSVM_IsError success, result is %{public}d", result); - } else { - OH_LOG_INFO(LOG_APP, "JSVM API call OH_JSVM_IsError failed"); - } - // 取出result通过OH_JSVM_GetBoolean接口将取出的bool值转换为JSVM_Value类型的值返回出去 - JSVM_Value returnValue = nullptr; - OH_JSVM_GetBoolean(env, result, &returnValue); - return returnValue; -} -// JsVmIsError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmIsError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmIsError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmIsError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmIsError(Error()))JS"; -// [End oh_jsvm_is_error] - -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 = "iserror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/oh-package.json5 deleted file mode 100755 index 046e20b416e422cde508316391c3a67bd9cec7da..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/cpp/types/libiserror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libiserror.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/JsvmUsageGuide/JsvmError/iserror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/pages/Index.ets deleted file mode 100755 index f15581fd6b2c0616380d9f7e953d228cca816285..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libiserror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/iserror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/module.json5 deleted file mode 100755 index 28767b5a1a4bee1e53cebe973c98e8ffcd45fc75..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "iserror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IserrorAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IserrorAbility", - "srcEntry": "./ets/iserrorability/IserrorAbility.ets", - "description": "$string:IserrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IserrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/string.json deleted file mode 100755 index 6c63c0e72952388d0a9ddc870690b377dea8a25d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IserrorAbility_desc", - "value": "description" - }, - { - "name": "IserrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 9047ef5aa7240290bd8e202ecb6c584da66d11a3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsError', 0, async (done: Function) => { - console.log('uitest: TestIsError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IserrorAbility' - } - 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('IserrorAbility'); - - 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: TestIsError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/module.json5 deleted file mode 100755 index d07eef90c7e899a614b76242632bc032b176f6d6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/iserror/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "iserror_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/isexceptionpending/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/isexceptionpending/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/isexceptionpending/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/oh-package.json5 deleted file mode 100755 index 08b7f30e9a3e650ed371d9b70888c248f312c480..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "isexceptionpending", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libisexceptionpending.so": "file:./src/main/cpp/types/libisexceptionpending" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/CMakeLists.txt deleted file mode 100755 index d58d0090bbcc6107d606026e41cc34c76563a674..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(isexceptionpending SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(isexceptionpending PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/hello.cpp deleted file mode 100755 index f64686c6842ec56d60a5316bdf41445ec84d9f58..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/hello.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_is_exception_pending] -// OH_JSVM_GetAndClearLastException的样例方法 -static JSVM_Value JsVmIsExceptionPending(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Status status; - bool isExceptionPending = false; - // 在执行一些可能引发异常的操作后 - OH_JSVM_ThrowError(env, "OH_JSVM_ThrowError errorCode", "OH_JSVM_ThrowError errorMessage"); - // 检查当前环境中是否有异常挂起 - status = OH_JSVM_IsExceptionPending(env, &isExceptionPending); - if (status != JSVM_OK) { - return nullptr; - } - if (isExceptionPending) { - OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_IsExceptionPending: SUCCESS"); - // 处理异常挂起的情况 - JSVM_Value result = nullptr; - status = OH_JSVM_GetAndClearLastException(env, &result); - if (status != JSVM_OK) { - return nullptr; - } - // 将处理的异常返回出去 - return result; - } else { - OH_LOG_INFO(LOG_APP, "JSVM API OH_JSVM_IsExceptionPending: FAILED"); - } - return nullptr; -} -// JsVmIsExceptionPending注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmIsExceptionPending}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmIsExceptionPending方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmIsExceptionPending", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmIsExceptionPending();)JS"; -// [End oh_jsvm_is_exception_pending] - -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 = "isexceptionpending", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/oh-package.json5 deleted file mode 100755 index 771487a2941f659a9ec955a6a308b4d55a378223..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/cpp/types/libisexceptionpending/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libisexceptionpending.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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/pages/Index.ets deleted file mode 100755 index fcb29310dc5c6e8926335bb5b458d2f94acc315b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libisexceptionpending.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/module.json5 deleted file mode 100755 index ed3f1b33dc5fdeb43f156283547cfa3646915a71..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "isexceptionpending", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "IsexceptionpendingAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "IsexceptionpendingAbility", - "srcEntry": "./ets/isexceptionpendingability/IsexceptionpendingAbility.ets", - "description": "$string:IsexceptionpendingAbility_desc", - "icon": "$media:layered_image", - "label": "$string:IsexceptionpendingAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/string.json deleted file mode 100755 index d9cd2cbfe85784fd9266a851035bc28c943601a8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "IsexceptionpendingAbility_desc", - "value": "description" - }, - { - "name": "IsexceptionpendingAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 1c35824fea85eefe012effaed6fa0e5973115dcd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testIsExceptionPending', 0, async (done: Function) => { - console.log('uitest: TestIsExceptionPending begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'IsexceptionpendingAbility' - } - 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('IsexceptionpendingAbility'); - - 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: TestIsExceptionPending end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/module.json5 deleted file mode 100755 index e4269bd675a686da59c16d4d1b8a1d3e89280ea0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/isexceptionpending/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "isexceptionpending_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/ohosTest.md deleted file mode 100755 index e309de19fb9adeeea737a9d092c08d8fbd4deffd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/ohosTest.md +++ /dev/null @@ -1,20 +0,0 @@ -# JsvmError 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------ | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript Error | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript RangeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript SyntaxError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript TypeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取并清除最近一次出现的异常 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 获取调用JSVM接口最后一次发生的错误信息 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断给定的JSVM_Value是否表示一个error对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断是否出现了异常 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 抛出一个带文本信息的JS Error | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript RangeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript SyntaxError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript SyntaxError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 创建并获取一个带文本信息的JavaScript TypeError | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/throwerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/throwerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/oh-package.json5 deleted file mode 100755 index b1b76a15bc1a40acdd50bd035ea1b3a052a20867..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "throwerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libthrowerror.so": "file:./src/main/cpp/types/libthrowerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 6bc7a47baeb559a80802f18aab30388417c3186a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(throwerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(throwerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/hello.cpp deleted file mode 100755 index 2bfcb246951d96925893437cf49b374a550ff4e7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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) - -static void GetLastErrorAndClean(JSVM_Env env) -{ - // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); - // 打印错误信息 - JSVM_Value message; - JSVM_Value errorCode; - OH_JSVM_GetNamedProperty((env), result, "message", &message); - OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); - const int maxMessageLength = 256; - const int maxCodeLength = 256; - char messagestr[maxMessageLength]; - char codeStr[maxCodeLength]; - OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); - OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); - OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); -} - -// [Start oh_jsvm_throw_error] -// OH_JSVM_ThrowError的样例方法 -static JSVM_Value JsVmThrowError(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - if (argc == 0) { - // 如果没有传递参数,直接抛出错误 - OH_JSVM_ThrowError(env, "-1", "has Error"); - } else if (argc == 1) { - size_t length; - // 通过入参获取到javaScript侧传入的字符串长度。 - OH_JSVM_GetValueStringUtf8(env, argv[0], nullptr, 0, &length); - char *buffer = new char[length + 1]; - // 获取入参的字符串内容。 - OH_JSVM_GetValueStringUtf8(env, argv[0], buffer, length + 1, nullptr); - // 作为error信息填入到OH_JSVM_ThrowError接口中。 - OH_JSVM_ThrowError(env, "self defined error code", buffer); - delete[] buffer; - } - GetLastErrorAndClean(env); - return nullptr; -} -// JsVmThrowError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmThrowError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmThrowError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmThrowError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmThrowError();jsVmThrowError("self defined error message");)JS"; -// [End oh_jsvm_throw_error] - -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 = "throwerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/oh-package.json5 deleted file mode 100755 index 02a85d7783342de671df12f95f2ca5089eeb42af..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/cpp/types/libthrowerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libthrowerror.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/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/pages/Index.ets deleted file mode 100755 index 998e449696ca4ada0b2a1099d549da9851dca404..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libthrowerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/throwerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/module.json5 deleted file mode 100755 index 3ab4c922be6c7047f5021d47e976251329071f71..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "throwerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ThrowerrorAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ThrowerrorAbility", - "srcEntry": "./ets/throwerrorability/ThrowerrorAbility.ets", - "description": "$string:ThrowerrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ThrowerrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/string.json deleted file mode 100755 index b80b6e3a544dd6e7cfb58b7d5e8941cdcb745572..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ThrowerrorAbility_desc", - "value": "description" - }, - { - "name": "ThrowerrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index e6abaa916eaf28abd29b01ee7bd5529f4fedeb3d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testThrowError', 0, async (done: Function) => { - console.log('uitest: TestThrowError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ThrowerrorAbility' - } - 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('ThrowerrorAbility'); - - 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: TestThrowError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/module.json5 deleted file mode 100755 index 69284f3e05155c68e8e3a592eaec8bd9565f4fde..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "throwerror_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/throwrangeerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwrangeerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/throwrangeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/oh-package.json5 deleted file mode 100755 index a41bd18c9a1d584e5726b7ad401f1713eea7402d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "throwrangeerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libthrowrangeerror.so": "file:./src/main/cpp/types/libthrowrangeerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 247bc126d6c15abb1d3631e8e6fa33190412c8e8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(throwrangeerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(throwrangeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/hello.cpp deleted file mode 100755 index 821c850896d4fe1099a16bd8bca5a7acdb363ff7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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) - -// 捕获清除并打印错误,该函数作为公共函数,在本文档后续样例中不再声明和定义 -static void GetLastErrorAndClean(JSVM_Env env) -{ - // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); - // 打印错误信息 - JSVM_Value message; - JSVM_Value errorCode; - OH_JSVM_GetNamedProperty((env), result, "message", &message); - OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); - const int maxMessageLength = 256; - const int maxCodeLength = 256; - char messagestr[maxMessageLength]; - char codeStr[maxCodeLength]; - OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); - OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); - OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); -} - -// [Start oh_jsvm_throw_range_error] -// OH_JSVM_ThrowRangeError的样例方法 -static JSVM_Value JsVmThrowRangeError(JSVM_Env env, JSVM_CallbackInfo info) -{ - // js侧传入两个参数 - size_t argc = 2; - JSVM_Value argv[2] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - // 如果传入参数个数不为2 - if (argc != 2) { - // 这里抛出一个RangeError - OH_JSVM_ThrowRangeError(env, "OH_JSVM_ThrowRangeError", "Expected two numbers as arguments"); - GetLastErrorAndClean(env); - return nullptr; - } - JSVM_Value result = nullptr; - OH_JSVM_GetBoolean(env, true, &result); - return result; -} -// JsVmThrowRangeError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmThrowRangeError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmThrowRangeError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmThrowRangeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmThrowRangeError(1);)JS"; -// [End oh_jsvm_throw_range_error] - -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 = "throwrangeerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/oh-package.json5 deleted file mode 100755 index 5de32810b88eb63fa9dd7a880879d4f237053cd9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/cpp/types/libthrowrangeerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libthrowrangeerror.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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/pages/Index.ets deleted file mode 100755 index 774c6496784d3929486af6344c35c716210c3090..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libthrowrangeerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/module.json5 deleted file mode 100755 index 478f372a4be4cef4c2a783118c74125067a9585c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "throwrangeerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ThrowrangeerrorAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ThrowrangeerrorAbility", - "srcEntry": "./ets/throwrangeerrorability/ThrowrangeerrorAbility.ets", - "description": "$string:ThrowrangeerrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ThrowrangeerrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/string.json deleted file mode 100755 index d8f6f6fd07442196f024f44b497cffd20270b2ee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ThrowrangeerrorAbility_desc", - "value": "description" - }, - { - "name": "ThrowrangeerrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index aa3a111076712d070f51fcec6011e8c8c26af463..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testThrowRangeError', 0, async (done: Function) => { - console.log('uitest: TestThrowRangeError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ThrowrangeerrorAbility' - } - 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('ThrowrangeerrorAbility'); - - 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: TestThrowRangeError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/module.json5 deleted file mode 100755 index 4fb52715dd137fc69a6fba8b4c2b87ef9ace79e3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwrangeerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "throwrangeerror_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/throwsyntaxerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwsyntaxerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/throwsyntaxerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/oh-package.json5 deleted file mode 100755 index 1400000e350ac2340a82154b5a7fa1b26b1aa11f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "throwsyntaxerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libthrowsyntaxerror.so": "file:./src/main/cpp/types/libthrowsyntaxerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 0e833e029323a25d702c47e237f62b2638840b77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(throwsyntaxerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(throwsyntaxerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/hello.cpp deleted file mode 100755 index 527403c712f5bcbcc0a724e30cfa6f04cfc0eef9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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) - -// 捕获清除并打印错误,该函数作为公共函数,在本文档后续样例中不再声明和定义 -static void GetLastErrorAndClean(JSVM_Env env) -{ - // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); - // 打印错误信息 - JSVM_Value message; - JSVM_Value errorCode; - OH_JSVM_GetNamedProperty((env), result, "message", &message); - OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); - const int maxMessageLength = 256; - const int maxCodeLength = 256; - char messagestr[maxMessageLength]; - char codeStr[maxCodeLength]; - OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); - OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); - OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); -} - -// [Start oh_jsvm_throw_syntax_error] -// OH_JSVM_ThrowSyntaxError的样例方法 -static JSVM_Value JsVmThrowSyntaxError(JSVM_Env env, JSVM_CallbackInfo info) -{ - // JS侧传入运行的JS代码 - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - JSVM_Script script = nullptr; - // 通过OH_JSVM_CompileScript接口编译JS代码 - OH_JSVM_CompileScript(env, argv[0], nullptr, 0, true, nullptr, &script); - JSVM_Value scriptResult = nullptr; - // 通过OH_JSVM_RunScript接口运行JS代码 - JSVM_Status status = OH_JSVM_RunScript(env, script, &scriptResult); - if (status != JSVM_OK) { - // 如果JSVM_RunScript接口返回状态不为JSVM_OK,则抛出一个SyntaxError - OH_JSVM_ThrowSyntaxError(env, "JsVmThrowSyntaxError", "throw syntax error"); - GetLastErrorAndClean(env); - return nullptr; - } - JSVM_Value result = nullptr; - OH_JSVM_GetBoolean(env, true, &result); - return result; -} -// JsVmThrowSyntaxError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmThrowSyntaxError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmThrowSyntaxError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmThrowSyntaxError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmThrowSyntaxError();)JS"; -// [End oh_jsvm_throw_syntax_error] - -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 = "throwsyntaxerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/oh-package.json5 deleted file mode 100755 index 24af3733f986e75148050d2dc8505240b6326208..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/cpp/types/libthrowsyntaxerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libthrowsyntaxerror.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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/pages/Index.ets deleted file mode 100755 index eec38a73ffd62150a51f350ffb9a95cc0cc3d197..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libthrowsyntaxerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/module.json5 deleted file mode 100755 index d9dfe63ec000beb3cd37434450937a06c336d3fc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "throwsyntaxerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ThrowsyntaxerrorAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ThrowsyntaxerrorAbility", - "srcEntry": "./ets/throwsyntaxerrorability/ThrowsyntaxerrorAbility.ets", - "description": "$string:ThrowsyntaxerrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ThrowsyntaxerrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/string.json deleted file mode 100755 index b18870a0c9c07d724d52ada8ede384b8501c78d8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ThrowsyntaxerrorAbility_desc", - "value": "description" - }, - { - "name": "ThrowsyntaxerrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index fe76fcf13451955e2ffd8d10d2b9ce77a773c395..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testThrowSyntaxError', 0, async (done: Function) => { - console.log('uitest: TestThrowSyntaxError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ThrowsyntaxerrorAbility' - } - 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('ThrowsyntaxerrorAbility'); - - 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: TestThrowSyntaxError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/module.json5 deleted file mode 100755 index d69b8b5c42329dacbe526b03cb4cad63b4feb39d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwsyntaxerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "throwsyntaxerror_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmError/throwtypeerror/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwtypeerror/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmError/throwtypeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/oh-package.json5 deleted file mode 100755 index a94708ad5b549bff7dc35bee7222be16244a379e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "throwtypeerror", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libthrowtypeerror.so": "file:./src/main/cpp/types/libthrowtypeerror" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/CMakeLists.txt deleted file mode 100755 index a65ba8e54d29765caa65c6bf3eba3d4c96e91a66..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmError) - -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) - -add_library(throwtypeerror SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(throwtypeerror PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/hello.cpp deleted file mode 100755 index e8013f05ad8a476fe9f11459fbd0775442e9f5d6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/hello.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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) - -static void GetLastErrorAndClean(JSVM_Env env) -{ - // 调用OH_JSVM_GetAndClearLastException接口获取并清除最后一个未处理的异常。即使存在挂起的JavaScript异常,也可以调用此API - JSVM_Value result = nullptr; - JSVM_Status status = OH_JSVM_GetAndClearLastException(env, &result); - // 打印错误信息 - JSVM_Value message; - JSVM_Value errorCode; - OH_JSVM_GetNamedProperty((env), result, "message", &message); - OH_JSVM_GetNamedProperty((env), result, "code", &errorCode); - const int maxMessageLength = 256; - const int maxCodeLength = 256; - char messagestr[maxMessageLength]; - char codeStr[maxCodeLength]; - OH_JSVM_GetValueStringUtf8(env, message, messagestr, maxMessageLength, nullptr); - OH_JSVM_GetValueStringUtf8(env, errorCode, codeStr, maxCodeLength, nullptr); - OH_LOG_INFO(LOG_APP, "JSVM error message: %{public}s, error code: %{public}s", messagestr, codeStr); -} - -// [Start oh_jsvm_throw_type_error] -// OH_JSVM_ThrowTypeError的样例方法 -static JSVM_Value JsVmThrowTypeError(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_GetCbInfo(env, info, &argc, argv, nullptr, nullptr); - if (argc == 0) { - // 如果没有传递参数,直接抛出错误 - OH_JSVM_ThrowTypeError(env, "-1", "throwing type error"); - } else if (argc == 1) { - size_t length; - // 通过入参获取到javaScript侧传入的字符串长度 - OH_JSVM_GetValueStringUtf8(env, argv[0], nullptr, 0, &length); - char *buffer = new char[length + 1]; - // 获取入参的字符串内容 - OH_JSVM_GetValueStringUtf8(env, argv[0], buffer, length + 1, nullptr); - // 作为error信息填入到OH_JSVM_ThrowError接口中 - OH_JSVM_ThrowTypeError(env, "self defined error code", buffer); - delete[] buffer; - } - GetLastErrorAndClean(env); - return nullptr; -} -// JsVmThrowTypeError注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsVmThrowTypeError}, -}; -static JSVM_CallbackStruct *method = param; -// JsVmThrowTypeError方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"jsVmThrowTypeError", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; -// 样例测试js -const char *SRC_CALL_NATIVE = R"JS(jsVmThrowTypeError();jsVmThrowTypeError("self defined error message");)JS"; -// [End oh_jsvm_throw_type_error] - -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 = "throwtypeerror", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/oh-package.json5 deleted file mode 100755 index 2b169e97866863d68cd41682e8932aa24798de48..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/cpp/types/libthrowtypeerror/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libthrowtypeerror.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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/pages/Index.ets deleted file mode 100755 index 5ba8ffaa00f141b95e2c181a9cebbf36142d342f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libthrowtypeerror.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/module.json5 deleted file mode 100755 index 4841afab766e3f461e79e1be8c213dd158347fce..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/module.json5 +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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": "throwtypeerror", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ThrowtypeerrorAbility", - "deviceTypes": [ - "default", - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ThrowtypeerrorAbility", - "srcEntry": "./ets/throwtypeerrorability/ThrowtypeerrorAbility.ets", - "description": "$string:ThrowtypeerrorAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ThrowtypeerrorAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/string.json deleted file mode 100755 index 3f12e6245566db3a59e4451fea939384cd5e89c7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ThrowtypeerrorAbility_desc", - "value": "description" - }, - { - "name": "ThrowtypeerrorAbility_label", - "value": "JsvmError" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 9ce627cb98e1198da879c4ed49f06b56a2efd503..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testThrowTypeError', 0, async (done: Function) => { - console.log('uitest: TestThrowTypeError begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ThrowtypeerrorAbility' - } - 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('ThrowtypeerrorAbility'); - - 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: TestThrowTypeError end'); - done(); - }) - }) -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/module.json5 deleted file mode 100755 index 0c06653f75e58dd6e5ab3dba76745aac87ebc45e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmError/throwtypeerror/src/ohosTest/module.json5 +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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": "throwtypeerror_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet", - "2in1" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/JsvmLifeCycle/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/app.json5 deleted file mode 100755 index cab34896e198658db6a1a1b97a78adac0bb841bb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.jsvmlifecycle", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/element/string.json deleted file mode 100755 index 9c06c4c0ae631d2a2ad58edef096a47cc5c78c5e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "JsvmLifeCycle" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/README.md deleted file mode 100755 index 3b3d2d5bcc35ce7f569765da4ace8909d41b405f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/README.md +++ /dev/null @@ -1,141 +0,0 @@ -# ArkTs使用JSVM-API接口进行生命周期相关开发 - -### 介绍 - -在JSVM-API中,JSVM_Value是一个表示JavaScript值的抽象类型,它可以表示任何JavaScript值,包括基本类型(如数字、字符串、布尔值)和对象类型(如数组、函数、对象等)。 JSVM_Value的生命周期与其在JavaScript中的对应值的生命周期紧密相关。当JavaScript值被垃圾回收时,与之关联的JSVM_Value也将不再有效。重要的是不要在JavaScript值不再存在时尝试使用JSVM_Value。 - -框架层的scope通常用于管理JSVM_Value的生命周期。在JSVM-API中,可以使用OH_JSVM_OpenHandleScope和OH_JSVM_CloseHandleScope函数来创建和销毁scope。通过在scope内创建JSVM_Value,可以确保在scope结束时自动释放JSVM_Value,避免内存泄漏。 - -JSVM_Ref是一个JSVM-API类型,用于管理JSVM_Value的生命周期。JSVM_Ref允许您在JSVM_Value的生命周期内保持对其的引用,即使它已经超出了其原始上下文的范围。这使得您可以在不同的上下文中共享JSVM_Value,并确保在不再需要时正确释放其内存。 - -合理使用OH_JSVM_OpenHandleScope和OH_JSVM_CloseHandleScope管理JSVM_Value的生命周期,做到生命周期最小化,避免发生内存泄漏问题。 - -每个JSVM_Value属于特定的HandleScope,HandleScope通过OH_JSVM_OpenHandleScope和OH_JSVM_CloseHandleScope来建立和关闭,HandleScope关闭后,所属的JSVM_Value就会自动释放。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行生命周期相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-life-cycle.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :---------------------------------------------------------------: | :---------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -addfinalizer/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -openescapablehandlescope/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -openhandlescope/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -referenceref/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/JsvmLifeCycle > .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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/oh-package.json5 deleted file mode 100755 index a232e1752ad048a0221c350df13dde782e1fdb78..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "addfinalizer", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libaddfinalizer.so": "file:./src/main/cpp/types/libaddfinalizer" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/CMakeLists.txt deleted file mode 100755 index a40ac21fbdc1b92c2b62857fb28c29a0d8d31d0b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmLifeCycle) - -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) - -add_library(addfinalizer SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(addfinalizer PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/hello.cpp deleted file mode 100755 index 44e52a83f4b2b432de46e9d31612d907dd17fb89..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/hello.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_add_finalizer] -static int AddFinalizer(JSVM_VM vm, JSVM_Env env) -{ - // 打开 handlescope - JSVM_HandleScope handleScope; - CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); - // 创建 object 并设置回调 - JSVM_Value obj; - CHECK_RET(OH_JSVM_CreateObject(env, &obj)); - CHECK_RET(OH_JSVM_AddFinalizer( - env, obj, nullptr, - [](JSVM_Env env, void *data, void *hint) -> void { - // Finalizer 方法,可在该方法中清理 Native 对象 - OH_LOG_INFO(LOG_APP, "JSVM: finalizer called."); - }, - nullptr, nullptr)); - OH_LOG_INFO(LOG_APP, "JSVM: finalizer added."); - // 关闭 handlescope,触发 GC,GC 时 Finalizer 会被调用 - CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); - OH_LOG_INFO(LOG_APP, "JSVM: before call gc."); - CHECK_RET(OH_JSVM_MemoryPressureNotification(env, JSVM_MemoryPressureLevel::JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL)); - OH_LOG_INFO(LOG_APP, "JSVM: after call gc."); - - return 0; -} - -static void RunDemo(JSVM_VM vm, JSVM_Env env) -{ - if (AddFinalizer(vm, env) != 0) { - OH_LOG_INFO(LOG_APP, "Run PromiseRegisterHandler failed"); - } -} -// [End oh_jsvm_add_finalizer] - -static napi_value RunTest(napi_env env, napi_callback_info info) -{ - JSVM_VM vm; - JSVM_Env envs = nullptr; - RunDemo(vm, envs); - 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 = "addfinalizer", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/oh-package.json5 deleted file mode 100755 index dfb41ef937a96fedffca8094af982c245f2a47a5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/cpp/types/libaddfinalizer/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libaddfinalizer.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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/pages/Index.ets deleted file mode 100755 index ddb30835b9163476f8d8f6084b0b4f3acd6b3274..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libaddfinalizer.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/module.json5 deleted file mode 100755 index 70b6d5b4452f3a7ac61986f1213347f3be347f9e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "addfinalizer", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "AddfinalizerAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "AddfinalizerAbility", - "srcEntry": "./ets/addfinalizerability/AddfinalizerAbility.ets", - "description": "$string:AddfinalizerAbility_desc", - "icon": "$media:layered_image", - "label": "$string:AddfinalizerAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/string.json deleted file mode 100755 index 3194937a92542dbe1cdd97892595023c6e774e50..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "AddfinalizerAbility_desc", - "value": "description" - }, - { - "name": "AddfinalizerAbility_label", - "value": "JsvmLifeCycle" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index c99fa3cf73188694208c437c39f57d7011a3ef6a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testAddFinalizer', 0, async (done: Function) => { - console.log('uitest: TestAddFinalizer begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'AddfinalizerAbility' - } - 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('AddfinalizerAbility'); - - 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: TestAddFinalizer end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/module.json5 deleted file mode 100755 index aa271837b8da297d9e0b26cc7e4f146a537688cf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/addfinalizer/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "addfinalizer_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/build-profile.json5 deleted file mode 100755 index 3e71ddabaf056db051a1f2eeb8d3e402777fe03b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/build-profile.json5 +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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": "openhandlescope", - "srcPath": "./openhandlescope", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "openescapablehandlescope", - "srcPath": "./openescapablehandlescope", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "referenceref", - "srcPath": "./referenceref", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "addfinalizer", - "srcPath": "./addfinalizer", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigor/hvigor-config.json5 deleted file mode 100755 index a653156fd914ed32a77644b64b6a0da0cc63c153..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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/JsvmUsageGuide/JsvmLifeCycle/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/ohosTest.md deleted file mode 100755 index bcb491022c77a00b274219a0e59bb9ff86e5f4d3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/ohosTest.md +++ /dev/null @@ -1,11 +0,0 @@ -# JsvmLifeCycle 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 为对象添加JSVM_Finalize回调,以便在JavaScript对象被垃圾回收时调用来释放原生对象 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 打开一个新的scope逃逸Handle scope,在关闭该scope之前创建的对象与父作用域有相同的生命周期 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 打开一个Handle scope,确保scope范围内的JSVM_Value不被GC回收 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 增加由Hello World创建的引用的引用计数,以确保对象在有引用时不会被提前释放 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/oh-package.json5 deleted file mode 100755 index 114b1205303bd928bcade65eea6d2fcedcbacd14..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "openescapablehandlescope", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libopenescapablehandlescope.so": "file:./src/main/cpp/types/libopenescapablehandlescope" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9f8118b41b5164a133a47d06195ab0d33236db8c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmLifeCycle) - -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) - -add_library(openescapablehandlescope SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(openescapablehandlescope PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/hello.cpp deleted file mode 100755 index 8cdbe605c83b9e6ea3f2e280865bbafd80bea6d7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/hello.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_open_escapable_handle_scope_close_escapable_handle_scope_escape_handle] -// OH_JSVM_OpenEscapableHandleScope、OH_JSVM_CloseEscapableHandleScope、OH_JSVM_EscapeHandle的样例方法 -static JSVM_Value EscapableHandleScopeTest(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 创建一个可逃逸的句柄作用域 - JSVM_EscapableHandleScope scope = nullptr; - JSVM_Status status = OH_JSVM_OpenEscapableHandleScope(env, &scope); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_OpenEscapableHandleScope: failed"); - return nullptr; - } - // 在可逃逸的句柄作用域内创建一个obj - JSVM_Value obj; - OH_JSVM_CreateObject(env, &obj); - // 在对象中添加属性 - JSVM_Value value = nullptr; - OH_JSVM_CreateStringUtf8(env, "Test jsvm_escapable_handle_scope", JSVM_AUTO_LENGTH, &value); - OH_JSVM_SetNamedProperty(env, obj, "name", value); - // 调用OH_JSVM_EscapeHandle将对象逃逸到作用域之外 - JSVM_Value escapedObj = nullptr; - OH_JSVM_EscapeHandle(env, scope, obj, &escapedObj); - // 关闭可逃逸的句柄作用域,清理资源 - status = OH_JSVM_CloseEscapableHandleScope(env, scope); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CloseEscapableHandleScope: failed"); - return nullptr; - } - // 此时的escapedObj已逃逸,可以在作用域外继续使用escapedObj - bool result = false; - OH_JSVM_CreateStringUtf8(env, "name", JSVM_AUTO_LENGTH, &value); - OH_JSVM_HasProperty(env, escapedObj, value, &result); - if (result) { - OH_LOG_INFO(LOG_APP, "JSVM EscapableHandleScopeTest: success"); - } - return escapedObj; -} - -// EscapableHandleScopeTest注册回调 -static JSVM_CallbackStruct param[] = { - {.callback = EscapableHandleScopeTest, .data = nullptr}, -}; -static JSVM_CallbackStruct *method = param; -// EscapableHandleScopeTest方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"escapableHandleScopeTest", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = "escapableHandleScopeTest()"; -// [End oh_jsvm_open_escapable_handle_scope_close_escapable_handle_scope_escape_handle] - -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 = "openescapablehandlescope", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/oh-package.json5 deleted file mode 100755 index a85e422d31b2bc1e47da2bb1f43ca0cd840a4d64..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/cpp/types/libopenescapablehandlescope/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libopenescapablehandlescope.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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/pages/Index.ets deleted file mode 100755 index 792847dda27430694567436728e45e34fee379ea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libopenescapablehandlescope.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/module.json5 deleted file mode 100755 index 305798d21f750e5450355678b38f17367620f735..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "openescapablehandlescope", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "OpenescapablehandlescopeAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "OpenescapablehandlescopeAbility", - "srcEntry": "./ets/openescapablehandlescopeability/OpenescapablehandlescopeAbility.ets", - "description": "$string:OpenescapablehandlescopeAbility_desc", - "icon": "$media:layered_image", - "label": "$string:OpenescapablehandlescopeAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/string.json deleted file mode 100755 index ca6933087517031f2a951b29bd2882114c090012..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "OpenescapablehandlescopeAbility_desc", - "value": "description" - }, - { - "name": "OpenescapablehandlescopeAbility_label", - "value": "JsvmLifeCycle" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 0b39b5ed670d9cb7d66ae91a9116c2487b7f15f9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testOpenEscapableHandleScope', 0, async (done: Function) => { - console.log('uitest: TestOpenEscapableHandleScope begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'OpenescapablehandlescopeAbility' - } - 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('OpenescapablehandlescopeAbility'); - - 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: TestOpenEscapableHandleScope end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/module.json5 deleted file mode 100755 index 6cabbf718b8247b81c67d147c00812038f795945..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openescapablehandlescope/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "openescapablehandlescope_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/oh-package.json5 deleted file mode 100755 index 423e154e35ef26d22ea7ad43b71d05d81f167f2e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "openhandlescope", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libopenhandlescope.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 2d159bb181941eb16279767301e8974b86c00743..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmLifeCycle) - -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) - -add_library(openhandlescope SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(openhandlescope PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/hello.cpp deleted file mode 100755 index ca40f5dec3561498bb7213c3d3f5d425ec21fc18..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/hello.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_open_handle_scope_and_oh_jsvm_close_handle_scope] -// OH_JSVM_OpenHandleScope、OH_JSVM_CloseHandleScope的三种样例方法 -static JSVM_Value HandleScopeFor(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 在for循环中频繁调用JSVM接口创建js对象时,要加handle_scope及时释放不再使用的资源。 - // 下面例子中,每次循环结束局部变量res的生命周期已结束,因此加scope及时释放其持有的js对象,防止内存泄漏 - constexpr uint32_t DIFF_VALUE_HUNDRED_THOUSAND = 10000; - JSVM_Value checked = nullptr; - for (int i = 0; i < DIFF_VALUE_HUNDRED_THOUSAND; i++) { - JSVM_HandleScope scope = nullptr; - JSVM_Status status = OH_JSVM_OpenHandleScope(env, &scope); - if (status != JSVM_OK || scope == nullptr) { - OH_JSVM_GetBoolean(env, false, &checked); - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_OpenHandleScope: failed"); - return checked; - } - JSVM_Value res = nullptr; - OH_JSVM_CreateObject(env, &res); - status = OH_JSVM_CloseHandleScope(env, scope); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_CloseHandleScope: failed"); - } - } - OH_JSVM_GetBoolean(env, true, &checked); - OH_LOG_INFO(LOG_APP, "JSVM HandleScopeFor: success"); - return checked; -} - -// HandleScopeFor注册回调 -static JSVM_CallbackStruct param[] = { - {.callback = HandleScopeFor, .data = nullptr}, -}; - -static JSVM_CallbackStruct *method = param; -// HandleScopeFor方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"HandleScopeFor", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = "HandleScopeFor()"; -// [End oh_jsvm_open_handle_scope_and_oh_jsvm_close_handle_scope] - -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 = "openhandlescope", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 89c71eb71c98c21bbec466c7791aec60019fbb94..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libopenhandlescope.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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/pages/Index.ets deleted file mode 100755 index 03c5e0b49156d13c0816d9de1cc38194a3a4f709..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libopenhandlescope.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/module.json5 deleted file mode 100755 index ba711d6075868bd0b2975730b5db7fd8b359cc15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "openhandlescope", - "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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/string.json deleted file mode 100755 index edd4b66d25b24044f41d63550af7b6aac2a49096..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "JsvmLifeCycle" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 9d04fd8fd422dd597c29149a2162bdb86758ad12..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testOpenHandleScope', 0, async (done: Function) => { - console.log('uitest: TestOpenHandleScope 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: TestOpenHandleScope end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/module.json5 deleted file mode 100755 index 396fcfaa88212ea49c76526c3beb4bc1e0841801..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/openhandlescope/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "openhandlescope_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/JsvmLifeCycle/referenceref/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/referenceref/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/JsvmLifeCycle/referenceref/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/oh-package.json5 deleted file mode 100755 index 5bd37280af4961a17d0cfd0bf26442039f597a59..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "referenceref", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libreferenceref.so": "file:./src/main/cpp/types/libreferenceref" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e6ebbba849a54d4d629643e98d0480f61ed724be..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(JsvmLifeCycle) - -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) - -add_library(referenceref SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(referenceref PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/hello.cpp deleted file mode 100755 index 387d2a6f143511f9bf9daa896fcb8b6d1624da32..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/hello.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_reference_ref_and_oh_jsvm_reference_unref] -static JSVM_Value UseReference(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 创建 JavaScript 对象 - JSVM_Value obj = nullptr; - OH_JSVM_CreateObject(env, &obj); - JSVM_Value value = nullptr; - OH_JSVM_CreateStringUtf8(env, "UseReference", JSVM_AUTO_LENGTH, &value); - OH_JSVM_SetNamedProperty(env, obj, "name", value); - - JSVM_Ref g_ref = nullptr; - // 创建对JavaScript对象的引用 - JSVM_Status status = OH_JSVM_CreateReference(env, obj, 1, &g_ref); - if (status != JSVM_OK) { - return nullptr; - } - - // 增加传入引用的引用计数并返回生成的引用计数 - uint32_t result; - OH_JSVM_ReferenceRef(env, g_ref, &result); - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_ReferenceRef, count = %{public}d.", result); - const int resultValue = 2; - if (result != resultValue) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_ReferenceRef: failed"); - return nullptr; - } - - // 减少传入引用的引用计数并返回生成的引用计数 - uint32_t num; - OH_JSVM_ReferenceUnref(env, g_ref, &num); - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_ReferenceUnref, count = %{public}d.", num); - if (num != 1) { - return nullptr; - } - - JSVM_Value object = nullptr; - // 通过调用OH_JSVM_GetReferenceValue获取引用的JavaScript对象 - status = OH_JSVM_GetReferenceValue(env, g_ref, &object); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetReferenceValue: failed"); - return nullptr; - } - - // 不再使用引用,通过调用OH_JSVM_DeleteReference删除对JavaScript对象的引用 - status = OH_JSVM_DeleteReference(env, g_ref); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_DeleteReference: failed"); - return nullptr; - } - - // 将获取到的对象返回 - OH_LOG_INFO(LOG_APP, "JSVM UseReference success"); - return object; -} - -// CreateReference、UseReference、DeleteReference注册回调 -static JSVM_CallbackStruct param[] = { - {.callback = UseReference, .data = nullptr}, -}; -static JSVM_CallbackStruct *method = param; -// CreateReference、UseReference、DeleteReference方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"useReference", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = "useReference()"; -// [End oh_jsvm_reference_ref_and_oh_jsvm_reference_unref] - -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 = "referenceref", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/oh-package.json5 deleted file mode 100755 index ce625a1fcdc489bbe1fee306c010491d9e90083e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/cpp/types/libreferenceref/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libreferenceref.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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/pages/Index.ets deleted file mode 100755 index 691cf5d69cda1cd26f49e78862d709a96f454776..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libreferenceref.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/module.json5 deleted file mode 100755 index 0ad3206d6fce4e12ed3810631e14047b286cf13b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "referenceref", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "ReferencerefAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "ReferencerefAbility", - "srcEntry": "./ets/referencerefability/ReferencerefAbility.ets", - "description": "$string:ReferencerefAbility_desc", - "icon": "$media:layered_image", - "label": "$string:ReferencerefAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/string.json deleted file mode 100755 index 973fe803e36f76e564dad091e558bcd1d736b755..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "ReferencerefAbility_desc", - "value": "description" - }, - { - "name": "ReferencerefAbility_label", - "value": "JsvmLifeCycle" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 3aa1dbc83bf90f124bd0b2d5a51f71ea77a94937..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testReferenceRef', 0, async (done: Function) => { - console.log('uitest: TestReferenceRef begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'ReferencerefAbility' - } - 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('ReferencerefAbility'); - - 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: TestReferenceRef end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/module.json5 deleted file mode 100755 index 45b4f0c1a6c3267406d1217d3ffc803117cdd3c6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/JsvmLifeCycle/referenceref/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "referenceref_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/UsageInstructionsOne/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/app.json5 deleted file mode 100755 index de155cec19b6e2ca3788be2342ec0061e3851f8b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.usageinstructionsone", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/element/string.json deleted file mode 100755 index 23a0c5df08c1e3213d918c4b4e262e600ef766ff..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UsageInstructionsOne" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/README.md deleted file mode 100755 index 5d13c47d5e15dae5cb4109f0a19822a419f38949..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/README.md +++ /dev/null @@ -1,160 +0,0 @@ -# ArkTS JSVM-API使用指导 - -### 介绍 - -使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 - -- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 -- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口进行函数创建和调用](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-function-call.md) -- [使用JSVM-API接口进行虚拟机快照相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-create-snapshot.md) -- [使用JSVM-API接口进行JSON操作](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-JSON.md) -- [使用JSVM-API接口进行任务队列相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-execute_tasks.md) -- [使用JSVM-API接口进行WebAssembly模块相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-wasm.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击hello world,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -aboutjson/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -createsnapshot/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -functioncall/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -pumpmessageloop/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 - webassembly/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/UsageInstructionsOne > .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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/oh-package.json5 deleted file mode 100755 index dba47d4ea78db1cd6953e6a59e4dcc5529ccdb68..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "aboutjson", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libaboutjson.so": "file:./src/main/cpp/types/libaboutjson" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 083fe70ccb65f6490ad693850b297e95f346c731..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsOne) - -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(aboutjson SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(aboutjson PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/hello.cpp deleted file mode 100755 index eed89dc8d6f8bffedd8b9c587ed012c51520c33e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/hello.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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 "ark_runtime/jsvm.h" -#include -#include - -#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) - -// [Start oh_jsvm_json_parse_and_json_stringify] -// 解析JSON数字 -static JSVM_Value JsonParseNumber(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 设置要解析的JSON数字 - std::string strNumber = "10.555"; - JSVM_Value jsonString; - JSVM_CALL(OH_JSVM_CreateStringUtf8(env, strNumber.c_str(), strNumber.size(), &jsonString)); - JSVM_Value jsonObject; - // 调用OH_JSVM_JsonParse函数解析JSON数字,并将结果存储在JSON对象中 - JSVM_CALL(OH_JSVM_JsonParse(env, jsonString, &jsonObject)); - double number; - JSVM_CALL(OH_JSVM_GetValueDouble(env, jsonObject, &number)); - OH_LOG_INFO(LOG_APP, "Test JSVM jsonParseNumber: %{public}f", number); - return nullptr; -} - -// 解析JSON字符串中的对象 -static JSVM_Value JsonParseObject(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 设置要解析的JSON对象字符串 - std::string strObject = "{\"first\": \"one\", \"second\": \"two\", \"third\": \"three\"}"; - JSVM_Value strJson; - JSVM_CALL(OH_JSVM_CreateStringUtf8(env, strObject.c_str(), strObject.size(), &strJson)); - JSVM_Value jsonObject; - // 调用OH_JSVM_JsonParse函数解析JSON对象字符串,并将结果存储在JSON对象中 - JSVM_CALL(OH_JSVM_JsonParse(env, strJson, &jsonObject)); - JSVM_Value jsonString; - // 调用OH_JSVM_JsonStringify函数将对象转换为字符串格式,并将结果存储在JSVM字符串对象中 - JSVM_CALL(OH_JSVM_JsonStringify(env, jsonObject, &jsonString)); - size_t totalLen = 0; - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, nullptr, 0, &totalLen)); - size_t needLen = totalLen + 1; - char* buff = new char[needLen]; - JSVM_CALL(OH_JSVM_GetValueStringUtf8(env, jsonString, buff, needLen, &totalLen)); - OH_LOG_INFO(LOG_APP, "Test JSVM jsonParseNumber: %{public}s", buff); - delete[] buff; - return nullptr; -} - -// JsonParse注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = JsonParseNumber}, - {.data = nullptr, .callback = JsonParseObject}, -}; - -static JSVM_CallbackStruct *method = param; - -JSVM_PropertyDescriptor descriptor[] = { - {"jsonParseNumber", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - {"jsonParseObject", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 待执行的js代码 -static const char *STR_TASK = R"JS(jsonParseNumber();jsonParseObject();)JS"; -// [End oh_jsvm_json_parse_and_json_stringify] - -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, STR_TASK, 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 = "aboutjson", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/oh-package.json5 deleted file mode 100755 index 45d6184b429324f01869f0141c449d2e46b3bc8d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/cpp/types/libaboutjson/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libaboutjson.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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/pages/Index.ets deleted file mode 100755 index 14a9ad316715e041ba0ff1d38d3f4f885499a8b0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libaboutjson.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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/module.json5 deleted file mode 100755 index cd1fb3993f508563d6bc9aacb583122fba7ab82b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "aboutjson", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "AboutjsonAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "AboutjsonAbility", - "srcEntry": "./ets/aboutjsonability/AboutjsonAbility.ets", - "description": "$string:AboutjsonAbility_desc", - "icon": "$media:layered_image", - "label": "$string:AboutjsonAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/string.json deleted file mode 100755 index 7af45ffc6f9a36a0138a391dc385758dc2a782e9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "AboutjsonAbility_desc", - "value": "description" - }, - { - "name": "AboutjsonAbility_label", - "value": "UsageInstructionsOne" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 59ddebeef19fbbdc93fdfdea03be50bb7e360448..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testAboutJSON', 0, async (done: Function) => { - console.log('uitest: TestAboutJSON begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'AboutjsonAbility' - } - 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('AboutjsonAbility'); - - 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: TestAboutJSON end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/module.json5 deleted file mode 100755 index af813d86386787f73eb1666805b2ceda57e307c6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/aboutjson/src/ohosTest/module.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "aboutjson_test", - "type": "feature", - "deviceTypes": [ - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/build-profile.json5 deleted file mode 100755 index 589d45ae023ea47d753f0993a8b0899ac4a6de65..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/build-profile.json5 +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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": "createsnapshot", - "srcPath": "./createsnapshot", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "functioncall", - "srcPath": "./functioncall", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "aboutjson", - "srcPath": "./aboutjson", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "pumpmessageloop", - "srcPath": "./pumpmessageloop", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "webassembly", - "srcPath": "./webassembly", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/oh-package.json5 deleted file mode 100755 index f7c7c87cc7242015e1451ffebfde166986c8d528..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "createsnapshot", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libcreatesnapshot.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/CMakeLists.txt deleted file mode 100755 index bc1b341b4e0325417d477e599499eb1d0b565da9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsOne) - -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) - -add_library(createsnapshot SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(createsnapshot PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/hello.cpp deleted file mode 100755 index c6fa3cb59ae7c15418374f62e962d82725358a27..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/hello.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_create_snapshot_and_create_env_from_snapshot] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include -#include - -#define LOG_DEMAIN 0x0202 -#define LOG_TAG "TEST_TAG" - -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。 -// 如果不是,则调用GET_AND_THROW_LAST_ERROR处理错误并返回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) - -static const int MAX_BUFFER_SIZE = 128; -// CreateHelloString()函数需绑定到JSVM虚拟机, 用于OH_JSVM_CreateSnapshot虚拟机快照的正常创建 -static JSVM_Value CreateHelloString(JSVM_Env env, JSVM_CallbackInfo info) -{ - JSVM_Value outPut; - OH_JSVM_CreateStringUtf8(env, "Hello world!", JSVM_AUTO_LENGTH, &outPut); - return outPut; -} -// 提供外部引用的方式以便JavaScript环境可以调用绑定的函数 -static JSVM_CallbackStruct helloCb = {CreateHelloString, nullptr}; - -static intptr_t g_externals[] = { - (intptr_t)&helloCb, - 0, -}; - -static JSVM_Value RunVMScript(JSVM_Env env, std::string &src) -{ - // 打开handleScope作用域 - JSVM_HandleScope handleScope; - OH_JSVM_OpenHandleScope(env, &handleScope); - JSVM_Value jsStr = nullptr; - OH_JSVM_CreateStringUtf8(env, src.c_str(), src.size(), &jsStr); - // 编译JavaScript代码 - JSVM_Script script; - OH_JSVM_CompileScript(env, jsStr, nullptr, 0, true, nullptr, &script); - // 执行JavaScript代码 - JSVM_Value result = nullptr; - OH_JSVM_RunScript(env, script, &result); - // 关闭handleScope作用域 - OH_JSVM_CloseHandleScope(env, handleScope); - return result; -} -// OH_JSVM_CreateSnapshot的样例方法 -static void CreateVMSnapshot() -{ - // 创建JavaScript虚拟机实例,打开虚拟机作用域 - JSVM_VM vm; - JSVM_CreateVMOptions vmOptions; - memset(&vmOptions, 0, sizeof(vmOptions)); - // isForSnapshotting设置该虚拟机是否用于创建快照 - vmOptions.isForSnapshotting = true; - OH_JSVM_CreateVM(&vmOptions, &vm); - JSVM_VMScope vmScope; - OH_JSVM_OpenVMScope(vm, &vmScope); - // 创建JavaScript环境,打开环境作用域 - JSVM_Env env; - // 将native函数注册成JavaScript可调用的方法 - JSVM_PropertyDescriptor descriptor[] = { - {"createHelloString", nullptr, &helloCb, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - }; - OH_JSVM_CreateEnv(vm, 1, descriptor, &env); - JSVM_EnvScope envScope; - OH_JSVM_OpenEnvScope(env, &envScope); - // 使用OH_JSVM_CreateSnapshot创建虚拟机的启动快照 - const char *blobData = nullptr; - size_t blobSize = 0; - JSVM_Env envs[1] = {env}; - OH_JSVM_CreateSnapshot(vm, 1, envs, &blobData, &blobSize); - // 将snapshot保存到文件中 - // 保存快照数据,/data/storage/el2/base/files/test_blob.bin为沙箱路径 - // 以包名为com.example.jsvm为例,实际文件会保存到/data/app/el2/100/base/com.example.jsvm/files/test_blob.bin - std::ofstream file("/data/storage/el2/base/files/test_blob.bin", - std::ios::out | std::ios::binary | std::ios::trunc); - file.write(blobData, blobSize); - file.close(); - // 关闭并销毁环境和虚拟机 - OH_JSVM_CloseEnvScope(env, envScope); - OH_JSVM_DestroyEnv(env); - OH_JSVM_CloseVMScope(vm, vmScope); - OH_JSVM_DestroyVM(vm); -} - -static void RunVMSnapshot() -{ - // blobData的生命周期不能短于vm的生命周期 - // 从文件中读取snapshot - std::vector blobData; - std::ifstream file("/data/storage/el2/base/files/test_blob.bin", std::ios::in | std::ios::binary | std::ios::ate); - size_t blobSize = file.tellg(); - blobData.resize(blobSize); - file.seekg(0, std::ios::beg); - file.read(blobData.data(), blobSize); - file.close(); - OH_LOG_INFO(LOG_APP, "Test JSVM RunVMSnapshot read file blobSize = : %{public}ld", blobSize); - // 使用快照数据创建虚拟机实例 - JSVM_VM vm; - JSVM_CreateVMOptions vmOptions; - memset(&vmOptions, 0, sizeof(vmOptions)); - vmOptions.snapshotBlobData = blobData.data(); - vmOptions.snapshotBlobSize = blobSize; - OH_JSVM_CreateVM(&vmOptions, &vm); - JSVM_VMScope vmScope; - OH_JSVM_OpenVMScope(vm, &vmScope); - // 从快照中创建环境env - JSVM_Env env; - OH_JSVM_CreateEnvFromSnapshot(vm, 0, &env); - JSVM_EnvScope envScope; - OH_JSVM_OpenEnvScope(env, &envScope); - // 执行js脚本,快照记录的env中定义了createHelloString() - std::string src = "createHelloString()"; - JSVM_Value result = RunVMScript(env, src); - // 环境关闭前检查脚本运行结果 - char str[MAX_BUFFER_SIZE]; - OH_JSVM_GetValueStringUtf8(env, result, str, MAX_BUFFER_SIZE, nullptr); - if (strcmp(str, "Hello world!") != 0) { - OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d", __FILE__, __LINE__); - } - // 关闭并销毁环境和虚拟机 - OH_JSVM_CloseEnvScope(env, envScope); - OH_JSVM_DestroyEnv(env); - OH_JSVM_CloseVMScope(vm, vmScope); - OH_JSVM_DestroyVM(vm); - return; -} - -static JSVM_Value AdjustExternalMemory(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 在创建虚拟机快照时,如果存在对外部的依赖,需要在OH_JSVM_Init时,将外部依赖注册到initOptions.externalReferences中 - // 创建虚拟机快照并将快照保存到文件中 - CreateVMSnapshot(); - // snapshot可以记录下特定的js执行环境,可以跨进程通过snapshot快速还原出js执行上下文环境 - RunVMSnapshot(); - JSVM_Value result = nullptr; - OH_JSVM_CreateInt32(env, 0, &result); - return result; -} - -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = AdjustExternalMemory}, -}; -static JSVM_CallbackStruct *method = param; -// AdjustExternalMemory方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"adjustExternalMemory", nullptr, method, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试JS -const char *SRC_CALL_NATIVE = R"JS(adjustExternalMemory();)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++; - initOptions.externalReferences = g_externals; - int argc = 0; - char **argv = nullptr; - initOptions.argc = &argc; - initOptions.argv = argv; - 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; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - OH_LOG_INFO(LOG_APP, "JSVM Init"); - 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 = "createsnapshot", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } -// [End oh_jsvm_create_snapshot_and_create_env_from_snapshot] diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 2a68d78e4623a2d040f69ebd9923af514506c99a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libcreatesnapshot.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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/pages/Index.ets deleted file mode 100755 index 8490bd77e6d24ee9e5891615373e5b07275d0b85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 'libcreatesnapshot.so'; - -// [Start create_snapshot_call_native] -@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%') - } -} -// [End create_snapshot_call_native] diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/module.json5 deleted file mode 100755 index 4fd68d7d5d1f1e5d90c2387a6d934addadb0443e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "createsnapshot", - "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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/string.json deleted file mode 100755 index 57b4ddbcfb716a61edfea58b903680c8352e2198..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "UsageInstructionsOne" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index fd2208064c4e85698b3d67a6edc8145388afbc19..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testVirtualMachine', 0, async (done: Function) => { - console.log('uitest: TestVirtualMachine 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: TestVirtualMachine end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/module.json5 deleted file mode 100755 index 1ddcba8011f028756f248a45e5f6e4f72f393ad6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/createsnapshot/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "createsnapshot_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsOne/functioncall/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/functioncall/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsOne/functioncall/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/oh-package.json5 deleted file mode 100755 index 5311039a72b6abebd73639407b9617d671b6a435..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "functioncall", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libfunctioncall.so": "file:./src/main/cpp/types/libfunctioncall" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 653ad2d17ca51a939083fd1543cd18c9d34be376..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsOne) - -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(functioncall SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(functioncall PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/hello.cpp deleted file mode 100755 index a85a5900d75988eeada8ca4715dbb6079ca08590..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/hello.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start jsvm_function_call] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" - -#define LOG_DOMAIN 0x3200 -#define LOG_TAG "APP" - -#define CHECK_RET(cond) \ - if ((cond)) { \ - 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; \ - } - -#define CHECK(cond) \ - if (!(cond)) { \ - OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ - cond); \ - return -1; \ - } - -JSVM_Value NativeCreateFunctionTest(JSVM_Env env, JSVM_CallbackInfo info) -{ - void *data; - size_t argc = 1; - JSVM_Value argv[1] = {nullptr}; - JSVM_Value thisArg; - // 获取callback 参数信息 - JSVM_Status ret = OH_JSVM_GetCbInfo(env, info, &argc, &argv[0], &thisArg, &data); - if (ret != 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__, ret, info != nullptr ? info->errorMessage : ""); - return nullptr; - } - const int maxMessageLength = 256; - char message[256]; - OH_JSVM_GetValueStringLatin1(env, argv[0], message, maxMessageLength, nullptr); - if (data == nullptr) { - OH_LOG_ERROR(LOG_APP, "jsvm: %{public}s; callback data null", message); - } else { - OH_LOG_INFO(LOG_APP, "jsvm: %{public}s; %{public}s", message, (char *)data); - } - return nullptr; -} - -static int32_t TEST_FUNC() -{ - JSVM_InitOptions initOptions{}; - JSVM_VM vm; - JSVM_Env env = nullptr; - JSVM_VMScope vmScope; - JSVM_EnvScope envScope; - JSVM_HandleScope handleScope; - JSVM_Value result; - static bool isVMInit = false; - if (!isVMInit) { - isVMInit = true; - // 单个进程只用初始化一次 - OH_JSVM_Init(&initOptions); - } - CHECK_RET(OH_JSVM_CreateVM(nullptr, &vm)); - CHECK_RET(OH_JSVM_CreateEnv(vm, 0, nullptr, &env)); - CHECK_RET(OH_JSVM_OpenVMScope(vm, &vmScope)); - CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); - CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); - - // 创建并检查函数 - char hello[] = "Hello World!"; - JSVM_CallbackStruct cb = {NativeCreateFunctionTest, (void *)hello}; - JSVM_Value func; - CHECK_RET(OH_JSVM_CreateFunction(env, "", JSVM_AUTO_LENGTH, &cb, &func)); - bool isFunction = false; - CHECK_RET(OH_JSVM_IsFunction(env, func, &isFunction)); - CHECK(isFunction); - - // 将函数设置到全局对象中 - JSVM_Value global; - CHECK_RET(OH_JSVM_GetGlobal(env, &global)); - JSVM_Value key; - CHECK_RET(OH_JSVM_CreateStringUtf8(env, "NativeFunc", JSVM_AUTO_LENGTH, &key)); - CHECK_RET(OH_JSVM_SetProperty(env, global, key, func)); - - // 通过call 接口调用函数 - JSVM_Value argv[1] = {nullptr}; - OH_JSVM_CreateStringUtf8(env, "jsvm api call function", JSVM_AUTO_LENGTH, &argv[0]); - CHECK_RET(OH_JSVM_CallFunction(env, global, func, 1, argv, &result)); - - // 通过script调用函数 - JSVM_Script script; - JSVM_Value jsSrc; - const char *srcCallNative = R"JS(NativeFunc('js source call function');)JS"; - CHECK_RET(OH_JSVM_CreateStringUtf8(env, srcCallNative, JSVM_AUTO_LENGTH, &jsSrc)); - CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); - CHECK_RET(OH_JSVM_RunScript(env, script, &result)); - - CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); - CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); - CHECK_RET(OH_JSVM_CloseVMScope(vm, vmScope)); - CHECK_RET(OH_JSVM_DestroyEnv(env)); - CHECK_RET(OH_JSVM_DestroyVM(vm)); - return 0; -} -// [End jsvm_function_call] - -static napi_value RunTest(napi_env env, napi_callback_info info) -{ - TEST_FUNC(); - 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 = "functioncall", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/oh-package.json5 deleted file mode 100755 index 35220b62828b457b3c2c313367394a908c5f143c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/cpp/types/libfunctioncall/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libfunctioncall.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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/pages/Index.ets deleted file mode 100755 index 077afe33876e7343ea52f7e3e5d4f43f598bee59..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libfunctioncall.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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/module.json5 deleted file mode 100755 index fb49b29a59da51919835f651a70569305dd8403d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "functioncall", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "FunctioncallAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "FunctioncallAbility", - "srcEntry": "./ets/functioncallability/FunctioncallAbility.ets", - "description": "$string:FunctioncallAbility_desc", - "icon": "$media:layered_image", - "label": "$string:FunctioncallAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/string.json deleted file mode 100755 index 44eeb07d7f4939e056048850c522148ba2ee2c49..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "FunctioncallAbility_desc", - "value": "description" - }, - { - "name": "FunctioncallAbility_label", - "value": "UsageInstructionsOne" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 54cb707f94e6bd4535d504848c0bbc0bd22872cb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testFunctionCall', 0, async (done: Function) => { - console.log('uitest: TestFunctionCall begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'FunctioncallAbility' - } - 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('FunctioncallAbility'); - - 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: TestFunctionCall end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/module.json5 deleted file mode 100755 index 6be052cc060a09b97b7783c27e2aed2cd1ea8652..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/functioncall/src/ohosTest/module.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "functioncall_test", - "type": "feature", - "deviceTypes": [ - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/ohosTest.md deleted file mode 100755 index 7514b8b85d76ac3f6cf782013bdc281e0d6d433c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/ohosTest.md +++ /dev/null @@ -1,12 +0,0 @@ -# UsageInstructionsOne 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -|---------------------------------|--------|---------------|------------------|------|------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 使用JSVM-API接口进行JSON操作 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用JSVM-API接口进行函数创建和调用 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用JSVM-API接口进行虚拟机快照相关开发 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用JSVM-API接口进行任务队列相关开发 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 使用JSVM-API接口进行WebAssembly模块相关开发 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/build-profile.json5 deleted file mode 100755 index 14bbd03b5cd8ccf4c6bec74c0b9550228d792cb5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/build-profile.json5 +++ /dev/null @@ -1,39 +0,0 @@ -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/oh-package.json5 deleted file mode 100755 index 65d6248edd37a08bd791bdf1ec208c1bc02eb4e2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/oh-package.json5 +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "pumpmessageloop", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libpumpmessageloop.so": "file:./src/main/cpp/types/libpumpmessageloop" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b379448254376fc29da97c8fd00b145712b7dfd3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsOne) - -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) - -add_library(pumpmessageloop SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(pumpmessageloop PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/hello.cpp deleted file mode 100755 index ca0f8add77962d2b872101afa5eb0f60c1165093..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/hello.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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" -// [Start oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] -#include -#include -// [StartExclude oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] -#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) -// [EndExclude oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] - -// 待执行的js代码 -static const char *STR_TASK = R"JS( - // wasm 字节码 (以add 模块为例) - // 以下 wasmBuffer 对应的 wasm 字节码文本格式如下所示,只包含了一个函数 add - // (module - // (func $add (param $lhs i32) (param $rhs i32) (result i32) - // local.get $lhs - // local.get $rhs - // i32.add - // ) - // (export "add" (func $add)) - // ) - var wasmBytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, - 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, - 0x07, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01, - 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b]); - - var p = WebAssembly.instantiate(wasmBytes, {}); - p.then((result) => { - consoleinfo("Called with instance " + result); - }); - p.finally(() => { - consoleinfo("Called Finally"); - }); -)JS"; - -// 保证js代码中的打印信息可以正常输出 -static JSVM_Value ConsoleInfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - size_t argc = 1; - JSVM_Value args[1]; - #define MAX_LOG_LENGTH 255 - char log[MAX_LOG_LENGTH + 1] = ""; - size_t logLength; - JSVM_CALL(OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL)); - - OH_JSVM_GetValueStringUtf8(env, args[0], log, MAX_LOG_LENGTH, &logLength); - log[MAX_LOG_LENGTH] = 0; - OH_LOG_INFO(LOG_APP, "JSVM API TEST: %{public}s", log); - return nullptr; -} - -// 注册consoleinfo的方法 -JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = ConsoleInfo}, -}; -JSVM_PropertyDescriptor descriptor[] = { - {"consoleinfo", NULL, ¶m[0], NULL, NULL, NULL, JSVM_DEFAULT}, -}; - -static int32_t TestJSVM() -{ - JSVM_InitOptions init_options; - memset(&init_options, 0, sizeof(init_options)); - if (g_aa == 0) { - OH_JSVM_Init(&init_options); - g_aa++; - } - // 创建JavaScript虚拟机实例,打开虚拟机作用域 - JSVM_VM vm; - JSVM_CreateVMOptions options; - memset(&options, 0, sizeof(options)); - CHECK(OH_JSVM_CreateVM(&options, &vm)); - JSVM_VMScope vm_scope; - CHECK(OH_JSVM_OpenVMScope(vm, &vm_scope)); - - JSVM_Env env; - CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); - JSVM_EnvScope envScope; - CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); - JSVM_HandleScope handlescope; - CHECK_RET(OH_JSVM_OpenHandleScope(env, &handlescope)); - JSVM_Value sourcecodevalue; - CHECK_RET(OH_JSVM_CreateStringUtf8(env, STR_TASK, strlen(STR_TASK), &sourcecodevalue)); - JSVM_Script script; - CHECK_RET(OH_JSVM_CompileScript(env, sourcecodevalue, nullptr, 0, true, nullptr, &script)); - JSVM_Value result; - CHECK_RET(OH_JSVM_RunScript(env, script, &result)); - bool rst = false; - auto start = std::chrono::system_clock::now(); - while (true) { - // 如果任务队列中没有任务启动,则rst设置为false - CHECK_RET(OH_JSVM_PumpMessageLoop(vm, &rst)); - CHECK_RET(OH_JSVM_PerformMicrotaskCheckpoint(vm)); - // 定时退出 - auto now = std::chrono::system_clock::now(); - auto cost = std::chrono::duration_cast(now - start).count(); - const int timeoutMs = 100; - if (cost > timeoutMs) { - break; - } - } - - // 关闭并销毁环境和虚拟机 - CHECK_RET(OH_JSVM_CloseHandleScope(env, handlescope)); - CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); - CHECK(OH_JSVM_DestroyEnv(env)); - CHECK(OH_JSVM_CloseVMScope(vm, vm_scope)); - CHECK(OH_JSVM_DestroyVM(vm)); - return 0; -} -// [End oh_jsvm_pump_message_loop_and_perform_microtask_checkpoint] - -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 = "pumpmessageloop", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/oh-package.json5 deleted file mode 100755 index 5ee71f8cd56754ca0902e7dfb703f57a575c1a8c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/cpp/types/libpumpmessageloop/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libpumpmessageloop.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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pages/Index.ets deleted file mode 100755 index 421e35222fc379414f0fd7e0ec2c7d91e4f0f078..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libpumpmessageloop.so'; - -@Entry -@Component -struct Index { - @State message: string = 'OH_JSVM_PumpMessageLoop'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/module.json5 deleted file mode 100755 index 1a185959e6feede3010d68b7329984b8827acd2e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -{ - "module": { - "name": "pumpmessageloop", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "PumpmessageloopAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "PumpmessageloopAbility", - "srcEntry": "./ets/pumpmessageloopability/PumpmessageloopAbility.ets", - "description": "$string:PumpmessageloopAbility_desc", - "icon": "$media:layered_image", - "label": "$string:PumpmessageloopAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/module.json5 deleted file mode 100755 index 22f91b0ebc2705ce734a1bcfd25afbba8c9bae7b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsOne/pumpmessageloop/src/ohosTest/module.json5 +++ /dev/null @@ -1,11 +0,0 @@ -{ - "module": { - "name": "pumpmessageloop_test", - "type": "feature", - "deviceTypes": [ - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/.gitignore deleted file mode 100755 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/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/JsvmUsageGuide/UsageInstructionsTwo/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/app.json5 deleted file mode 100755 index 1ae38a4aafa6e70a8f13b0da62d5990f6e23a77b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.usageinstructionstwo", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/element/string.json deleted file mode 100755 index eb95d62248b1beb93319446baa2e19bf8088b256..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UsageInstructionsTwo" - } - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/README.md deleted file mode 100755 index c803ac6f1898df3967fa817b29b94bcd1757b855..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/README.md +++ /dev/null @@ -1,179 +0,0 @@ -# ArkTS JSVM-API使用指导 - -### 介绍 - -使用JSVM-API实现跨语言交互,首先需要按照JSVM-API的机制实现模块的注册和加载等相关动作。 - -- ArkTS/JS侧:实现C++方法的调用。代码比较简单,import一个对应的so库后,即可调用C++方法。 -- Native侧:.cpp文件,实现模块的注册。需要提供注册lib库的名称,并在注册回调方法中定义接口的映射关系,即Native方法及对应的JS/ArkTS接口名称等。 - -该工程中展示的代码详细描述可查如下链接: - -- [使用JSVM-API接口获取JSVM API的版本号](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-version.md) -- [使用JSVM-API接口进行JavaScript代码调试调优](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-heapstatistics-debugger-cpuprofiler-heapsnapshot.md) -- [使用JSVM-API判断给定的两个JS value是否严格相等](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-strict-equals.md) -- [使用JSVM-API进行内存管理](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-memory-management.md) - -### 效果预览 - -| 首页 | 执行及结果即时反馈 | -| :----------------------------------------------------------------------: | :----------------------------------------------------------------------: | -| | | - -### 使用说明 - -1. 在主界面,可以点击Hello World,开始执行。 -2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 - -### 工程目录 - -``` -adjustexternalmemory/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getheapstatistics/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接口 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getversion/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -getvm/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -memorypressurenotification/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ ├── test - │ │ ├── Ability.test.ets // 自动化测试代码 -strictequals/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ │ ├── libentry - │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 - │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 - │ │ ├── CMakeLists.txt // 配置CMake打包参数 - │ │ ├── hello.cpp // 实现Native侧的runTest接 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // ArkTS侧调用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/JsvmUsageGuide/UsageInstructionsTwo > .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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/oh-package.json5 deleted file mode 100755 index c9cc6951fd3402c5d67c5b72f8788bda75cad31d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "adjustexternalmemory", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libadjustexternalmemory.so": "file:./src/main/cpp/types/libadjustexternalmemory" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/CMakeLists.txt deleted file mode 100755 index bb05dea29e7c0acaf53d115eac1d9fb6a2f13461..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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) - -add_library(adjustexternalmemory SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(adjustexternalmemory PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/hello.cpp deleted file mode 100755 index c7810d9f44ceafff35bc2f88d64118c754b56f7f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/hello.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_adjust_external_memory] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_adjust_external_memory] -#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) -// [EndExclude oh_jsvm_adjust_external_memory] - -// OH_JSVM_AdjustExternalMemory的样例方法 -static JSVM_Value AdjustExternalMemory(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 分配1MB的内存 - int64_t change = 1024 * 1024; - int64_t adjustedValue = 0; - JSVM_Status status = OH_JSVM_AdjustExternalMemory(env, change, &adjustedValue); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_AdjustExternalMemory: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_AdjustExternalMemory: success"); - OH_LOG_INFO(LOG_APP, "JSVM Allocate memory size: %{public}d", adjustedValue); - } - JSVM_Value checked; - OH_JSVM_GetBoolean(env, true, &checked); - return checked; -} -// AdjustExternalMemory注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = AdjustExternalMemory}, -}; -static JSVM_CallbackStruct *method = param; -// AdjustExternalMemory方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"adjustExternalMemory", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = R"JS(adjustExternalMemory())JS"; -// [End oh_jsvm_adjust_external_memory] - -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 = "adjustexternalmemory", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/oh-package.json5 deleted file mode 100755 index 772e11bab6a560a40a93ee7917d47a56ecd80ab5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/cpp/types/libadjustexternalmemory/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libadjustexternalmemory.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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/pages/Index.ets deleted file mode 100755 index 6a1ce75aed4f2ec57ca7744488168dfad05685b4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libadjustexternalmemory.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/module.json5 deleted file mode 100755 index 5d0fc1b02647804d1fb9fd393e5bc565c9f33505..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "adjustexternalmemory", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "AdjustexternalmemoryAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "AdjustexternalmemoryAbility", - "srcEntry": "./ets/adjustexternalmemoryability/AdjustexternalmemoryAbility.ets", - "description": "$string:AdjustexternalmemoryAbility_desc", - "icon": "$media:layered_image", - "label": "$string:AdjustexternalmemoryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/string.json deleted file mode 100755 index c339dd7cd928592918f49fdaedd416412a440afd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "AdjustexternalmemoryAbility_desc", - "value": "description" - }, - { - "name": "AdjustexternalmemoryAbility_label", - "value": "UsageInstructionsTwo" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index fc125513d9431b2985a89fc302d74d0ce03f4465..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testAdjustExternalMemory', 0, async (done: Function) => { - console.log('uitest: TestAdjustExternalMemory begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'AdjustexternalmemoryAbility' - } - 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('AdjustexternalmemoryAbility'); - - 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: TestAdjustExternalMemory end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/module.json5 deleted file mode 100755 index 170918af62bbb4bb22cd3e605517727aaf5612fe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/adjustexternalmemory/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "adjustexternalmemory_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/build-profile.json5 deleted file mode 100755 index 38065e7524caaafaa3743939b13bcee624712901..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/build-profile.json5 +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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": "getvm", - "srcPath": "./getvm", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getheapstatistics", - "srcPath": "./getheapstatistics", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "getversion", - "srcPath": "./getversion", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "adjustexternalmemory", - "srcPath": "./adjustexternalmemory", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "memorypressurenotification", - "srcPath": "./memorypressurenotification", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "strictequals", - "srcPath": "./strictequals", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/code-linter.json5 deleted file mode 100755 index 9deb9807637aa27ebde62e61e2362a417aacdc04..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/code-linter.json5 +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/oh-package.json5 deleted file mode 100755 index 4aa4f00e13dbd9f8c661524a5ef15d7e7830b68b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getheapstatistics", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetheapstatistics.so": "file:./src/main/cpp/types/libgetheapstatistics" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/CMakeLists.txt deleted file mode 100755 index b16e9bf4b506ebcbd8d2cfb9068a70101c45af78..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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) - -add_library(getheapstatistics SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getheapstatistics PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/hello.cpp deleted file mode 100755 index feb8547a1121079b1f7b68267b7296963b1d0bd7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/hello.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_heap_statistics] -#include "napi/native_api.h" -#include "hilog/log.h" -#include "ark_runtime/jsvm.h" -// [StartExclude oh_jsvm_get_heap_statistics] -#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) -// [EndExclude oh_jsvm_get_heap_statistics] - -// OH_JSVM_GetHeapStatistics的样例方法 -void PrintHeapStatistics(JSVM_HeapStatistics result) -{ - OH_LOG_INFO(LOG_APP, "JSVM API heap totalHeapSize: %{public}zu", result.totalHeapSize); - OH_LOG_INFO(LOG_APP, "JSVM API heap totalHeapSizeExecutable: %{public}zu", result.totalHeapSizeExecutable); - OH_LOG_INFO(LOG_APP, "JSVM API heap totalPhysicalSize: %{public}zu", result.totalPhysicalSize); - OH_LOG_INFO(LOG_APP, "JSVM API heap totalAvailableSize: %{public}zu", result.totalAvailableSize); - OH_LOG_INFO(LOG_APP, "JSVM API heap usedHeapSize: %{public}zu", result.usedHeapSize); - OH_LOG_INFO(LOG_APP, "JSVM API heap heapSizeLimit: %{public}zu", result.heapSizeLimit); - OH_LOG_INFO(LOG_APP, "JSVM API heap mallocedMemory: %{public}zu", result.mallocedMemory); - OH_LOG_INFO(LOG_APP, "JSVM API heap externalMemory: %{public}zu", result.externalMemory); - OH_LOG_INFO(LOG_APP, "JSVM API heap peakMallocedMemory: %{public}zu", result.peakMallocedMemory); - OH_LOG_INFO(LOG_APP, "JSVM API heap numberOfNativeContexts: %{public}zu", result.numberOfNativeContexts); - OH_LOG_INFO(LOG_APP, "JSVM API heap numberOfDetachedContexts: %{public}zu", result.numberOfDetachedContexts); - OH_LOG_INFO(LOG_APP, "JSVM API heap totalGlobalHandlesSize: %{public}zu", result.totalGlobalHandlesSize); - OH_LOG_INFO(LOG_APP, "JSVM API heap usedGlobalHandlesSize: %{public}zu", result.usedGlobalHandlesSize); -} - -static JSVM_Value GetHeapStatistics(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取当前虚拟机对象 - JSVM_VM testVm; - OH_JSVM_GetVM(env, &testVm); - // 获取虚拟机的堆统计信息 - JSVM_HeapStatistics result; - OH_JSVM_GetHeapStatistics(testVm, &result); - // 打印虚拟机堆统计信息 - PrintHeapStatistics(result); - // 返回虚拟机堆统计信息中‘本机上下文数量’ - JSVM_Value nativeContextsCnt = nullptr; - OH_JSVM_CreateInt64(env, result.numberOfNativeContexts, &nativeContextsCnt); - return nativeContextsCnt; -} -// GetHeapStatistics注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetHeapStatistics}, -}; -static JSVM_CallbackStruct *method = param; -// GetHeapStatistics方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getHeapStatistics", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = R"JS(getHeapStatistics())JS"; -// [End oh_jsvm_get_heap_statistics] - -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 = "getheapstatistics", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/oh-package.json5 deleted file mode 100755 index a30397b5871cd340983a771a010e07af4c213c1b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/cpp/types/libgetheapstatistics/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetheapstatistics.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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/pages/Index.ets deleted file mode 100755 index e5863e3dc6778ff4a27fb4f84fa2f80e0b5e4f22..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetheapstatistics.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/module.json5 deleted file mode 100755 index c0d3f31894c575f7dd20f9a63d1707b33a29fd7a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getheapstatistics", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetheapstatisticsAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetheapstatisticsAbility", - "srcEntry": "./ets/getheapstatisticsability/GetheapstatisticsAbility.ets", - "description": "$string:GetheapstatisticsAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetheapstatisticsAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/string.json deleted file mode 100755 index b662a8916ed6f8bdfe630b32deca90bbc7a7edbc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetheapstatisticsAbility_desc", - "value": "description" - }, - { - "name": "GetheapstatisticsAbility_label", - "value": "UsageInstructionsTwo" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index d33f4e0aed1d28485566a8e8b184360301306921..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetHeapStatistics', 0, async (done: Function) => { - console.log('uitest: TestGetHeapStatistics begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetheapstatisticsAbility' - } - 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('GetheapstatisticsAbility'); - - 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: TestGetHeapStatistics end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/module.json5 deleted file mode 100755 index af2c813f339f975e19d6cedc4c8f46dc42d97d7d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getheapstatistics/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getheapstatistics_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsTwo/getversion/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getversion/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsTwo/getversion/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/oh-package.json5 deleted file mode 100755 index 36d47adea9effb61206112e613f80588114b312f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getversion", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetversion.so": "file:./src/main/cpp/types/libgetversion" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 2773ea2fc15cda9d2c2c10e7c2158eb79d7746e4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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) - -add_library(getversion SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getversion PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/hello.cpp deleted file mode 100755 index ea3b28350ea99f2f066f27bedb2d871afec43669..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/hello.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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) - -// [Start oh_jsvm_get_version_and_vm_info] -// OH_JSVM_GetVersion的样例方法 -static JSVM_Value GetVersion(JSVM_Env env, JSVM_CallbackInfo info) -{ - uint32_t jsVersion = 0; - // 调用接口,获取当前JSVM运行时支持的最高JSVM API版本 - JSVM_CALL(OH_JSVM_GetVersion(env, &jsVersion)); - int value = static_cast(jsVersion); - OH_LOG_INFO(LOG_APP, "JSVM GetVersion success:%{public}d", value); - return nullptr; -} - -// OH_JSVM_GetVMInfo的样例方法 -// 打印JSVM(JavaScript虚拟机)的各项信息 -void PrintVmInfo(JSVM_VMInfo vmInfo) -{ - OH_LOG_INFO(LOG_APP, "JSVM API apiVersion: %{public}d", vmInfo.apiVersion); - OH_LOG_INFO(LOG_APP, "JSVM API engine: %{public}s", vmInfo.engine); - OH_LOG_INFO(LOG_APP, "JSVM API version: %{public}s", vmInfo.version); - OH_LOG_INFO(LOG_APP, "JSVM API cachedDataVersionTag: 0x%{public}x", vmInfo.cachedDataVersionTag); -} - -static JSVM_Value GetVMInfo(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 调用接口,获取虚拟机的信息 - JSVM_VMInfo result; - JSVM_CALL(OH_JSVM_GetVMInfo(&result)); - // 输出VM虚拟机信息 - PrintVmInfo(result); - return nullptr; -} - -// IsStrictEquals注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetVersion}, - {.data = nullptr, .callback = GetVMInfo}, -}; -static JSVM_CallbackStruct *method = param; -// IsStrictEquals方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getVersion", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, - {"getVMInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -// 样例测试js -static const char *STR_TASK = R"JS(getVersion();getVMInfo();)JS"; -// [End oh_jsvm_get_version_and_vm_info] - -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, STR_TASK, 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 = "getversion", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/oh-package.json5 deleted file mode 100755 index e04a84f1e49457b3011851c89fbb30752b7f3617..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/cpp/types/libgetversion/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetversion.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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/pages/Index.ets deleted file mode 100755 index 967a378e9dde836015fa7d234568b9d9464d3ade..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetversion.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/module.json5 deleted file mode 100755 index 5b80bc7a0fd4415794c9fb8147e95d11eb6671cb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "getversion", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "GetversionAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "GetversionAbility", - "srcEntry": "./ets/getversionability/GetversionAbility.ets", - "description": "$string:GetversionAbility_desc", - "icon": "$media:layered_image", - "label": "$string:GetversionAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/string.json deleted file mode 100755 index a774b640605fd1f986e4e8d2814210d6f1e6137b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "GetversionAbility_desc", - "value": "description" - }, - { - "name": "GetversionAbility_label", - "value": "UsageInstructionsTwo" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 3e561fa06de7a04118af8c130199c0a9bc09bd25..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetVersion', 0, async (done: Function) => { - console.log('uitest: TestGetVersion begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'GetversionAbility' - } - 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('GetversionAbility'); - - 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: TestGetVersion end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/module.json5 deleted file mode 100755 index 29bb82d5761c7be75a75eccb7187d7525e30764b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getversion/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getversion_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsTwo/getvm/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getvm/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsTwo/getvm/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/oh-package.json5 deleted file mode 100755 index b30f517d4614fd37e8cf671c54448a57b135090d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "getvm", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libgetvm.so": "file:./src/main/cpp/types/libentry" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/CMakeLists.txt deleted file mode 100755 index f43b6a3639e7472c5aef77390cd493a2e687e3ed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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) - -add_library(getvm SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(getvm PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/hello.cpp deleted file mode 100755 index d2502f321fad27208472384358e29411ade57f1a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/hello.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_get_vm] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_get_vm] -#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) -// [EndExclude oh_jsvm_get_vm] - -// OH_JSVM_GetVM的样例方法 -static JSVM_Value GetVM(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 获取当前虚拟机对象,后续可以进行与虚拟机相关的操作或分析 - JSVM_VM testVm; - JSVM_Status status = OH_JSVM_GetVM(env, &testVm); - JSVM_Value result = nullptr; - if (status != JSVM_OK || testVm == nullptr) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_GetVM: failed"); - OH_JSVM_GetBoolean(env, true, &result); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_GetVM: success"); - OH_JSVM_GetBoolean(env, false, &result); - } - return result; -} -// GetVM注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = GetVM}, -}; -static JSVM_CallbackStruct *method = param; -// GetVM方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"getVM", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = R"JS(getVM())JS"; -// [End oh_jsvm_get_vm] - -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 = "getvm", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index ff274def6048caf7eba01bd6be418a2014a3cd37..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libgetvm.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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/pages/Index.ets deleted file mode 100755 index 837d7a4b47fd6f84c435a5ee8739a40f41ed9706..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libgetvm.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/module.json5 deleted file mode 100755 index ff651598baaf7777a44c76a74c01db50338c82cc..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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": "getvm", - "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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/string.json deleted file mode 100755 index 895c9a6def198a85f4bb95bac711e75bb3be59eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "UsageInstructionsTwo" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 643e8a00234b9cc60a65bc87906918a315109d72..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testGetVM', 0, async (done: Function) => { - console.log('uitest: TestGetVM 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: TestGetVM end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/module.json5 deleted file mode 100755 index 26a069d024130d382a299ff825a5da72a6674191..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/getvm/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "getvm_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigorfile.ts deleted file mode 100755 index 2db60fa91881f6961e5def61af680301d22a1341..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/oh-package.json5 deleted file mode 100755 index f5ea14034e99d308ebce25182da7c56c343c1af1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "memorypressurenotification", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libmemorypressurenotification.so": "file:./src/main/cpp/types/libmemorypressurenotification" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e669cc2e2b28d023ba9e11c6d5f31e937bd27230..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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) - -add_library(memorypressurenotification SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(memorypressurenotification PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/hello.cpp deleted file mode 100755 index 02dc84601ce33f078a91df379c81806b2486d872..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/hello.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_memory_pressure_notification] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_memory_pressure_notification] -#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) -// [EndExclude oh_jsvm_memory_pressure_notification] - -// OH_JSVM_MemoryPressureNotification的样例方法 -static JSVM_Value MemoryPressureNotification(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 设置当前JSVM的内存压力级别 - JSVM_Status status = OH_JSVM_MemoryPressureNotification(env, JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL); - if (status != JSVM_OK) { - OH_LOG_ERROR(LOG_APP, "JSVM OH_JSVM_MemoryPressureNotification: failed"); - } else { - OH_LOG_INFO(LOG_APP, "JSVM OH_JSVM_MemoryPressureNotification: success"); - OH_LOG_INFO(LOG_APP, "JSVM Current JSVM memory pressure level: %{public}d", - JSVM_MEMORY_PRESSURE_LEVEL_CRITICAL); - } - return nullptr; -} -// MemoryPressureNotification注册回调 -static JSVM_CallbackStruct param[] = { - {.data = nullptr, .callback = MemoryPressureNotification}, -}; -static JSVM_CallbackStruct *method = param; -// MemoryPressureNotification方法别名,供JS调用 -static JSVM_PropertyDescriptor descriptor[] = { - {"memoryPressureNotification", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, -}; - -const char *SRC_CALL_NATIVE = R"JS(memoryPressureNotification())JS"; -// [End oh_jsvm_memory_pressure_notification] - -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 = "memorypressurenotification", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/oh-package.json5 deleted file mode 100755 index 06314ae4947284af732b385aa85f1f60bd0a6e88..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/cpp/types/libmemorypressurenotification/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libmemorypressurenotification.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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/pages/Index.ets deleted file mode 100755 index 3f8477f1e8c288cab4c8c36d541798a42b0b99e5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libmemorypressurenotification.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/module.json5 deleted file mode 100755 index 6418d7f372bd6cbb3f97bfb7ca21441dbe5e1018..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "memorypressurenotification", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "MemorypressurenotificationAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "MemorypressurenotificationAbility", - "srcEntry": "./ets/memorypressurenotificationability/MemorypressurenotificationAbility.ets", - "description": "$string:MemorypressurenotificationAbility_desc", - "icon": "$media:layered_image", - "label": "$string:MemorypressurenotificationAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/string.json deleted file mode 100755 index c1156c47a82b0bbc071cec37ada3b78d7799dab5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "MemorypressurenotificationAbility_desc", - "value": "description" - }, - { - "name": "MemorypressurenotificationAbility_label", - "value": "UsageInstructionsTwo" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 93a785013b4a36893a096c60daf353ba290b436d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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('testMemoryPressureNotification', 0, async (done: Function) => { - console.log('uitest: TestMemoryPressureNotification begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'MemorypressurenotificationAbility' - } - 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('MemorypressurenotificationAbility'); - - 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: TestMemoryPressureNotification end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/module.json5 deleted file mode 100755 index 265d5559116f55e8cb93e41eabe5d6e60a7522ac..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/memorypressurenotification/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "memorypressurenotification_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/ohosTest.md deleted file mode 100755 index afd31196ea26fe87ee44384c949b0071c561762b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/ohosTest.md +++ /dev/null @@ -1,13 +0,0 @@ -# UsageInstructionsTwo 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------------------------------- | ------------ | --------------- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 使用JSVM-API接口获取JSVM API的版本号 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 设置JavaScript对象保持活动状态的外部分配内存的数量 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 通知虚拟机系统内存不足并有选择地触发垃圾回收 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 判断给定的两个JS value是否严格相等 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 检索给定环境的虚拟机实例 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | -| 返回一组虚拟机堆的统计数据 | 位于首页 | 点击Hello World | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/.gitignore deleted file mode 100755 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx -/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/build-profile.json5 deleted file mode 100755 index 2c0104dcb596135013aa98865f37de336700177a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/build-profile.json5 +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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": "", - } - }, - "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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/hvigorfile.ts deleted file mode 100755 index 46872af92274609fb7926a0eb6451cebbb18afef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/hvigorfile.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/obfuscation-rules.txt deleted file mode 100755 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/obfuscation-rules.txt +++ /dev/null @@ -1,23 +0,0 @@ -# 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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/oh-package.json5 deleted file mode 100755 index f9981a8fa3e3f12b73263dc35cfa534038d94c5b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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": "strictequals", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libstrictequals.so": "file:./src/main/cpp/types/libstrictequals" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/CMakeLists.txt deleted file mode 100755 index a757f93fdd8f1faa488d00d5ae353fc1225fd820..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) -project(UsageInstructionsTwo) - -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) - -add_library(strictequals SHARED hello.cpp) -# 构建此可执行文件需要链接的库 -target_link_libraries(strictequals PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/hello.cpp deleted file mode 100755 index 7b81aaded91345e69457c9b8e6cb78fe1325c8b5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/hello.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start oh_jsvm_strict_equals] -#include "napi/native_api.h" -#include "ark_runtime/jsvm.h" -#include "hilog/log.h" -// [StartExclude oh_jsvm_strict_equals] -#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) -// [EndExclude oh_jsvm_strict_equals] - -// OH_JSVM_StrictEquals的样例方法 -static JSVM_Value IsStrictEquals(JSVM_Env env, JSVM_CallbackInfo info) -{ - // 接受两个入参 - size_t argc = 2; - JSVM_Value args[2] = {nullptr}; - 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; - 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(data = '123';value = '123';isStrictEquals(data,value);)JS"; -// [End oh_jsvm_strict_equals] - -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 = "strictequals", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/Index.d.ts deleted file mode 100755 index 8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/oh-package.json5 deleted file mode 100755 index 315b75619ac97d0bb54911ddc01c7b3a2b5a193e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/cpp/types/libstrictequals/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libstrictequals.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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/pages/Index.ets deleted file mode 100755 index 8ef108a51929beebbab860592669976541ec867b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 'libstrictequals.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(30) - .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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/module.json5 deleted file mode 100755 index 2c7147c8cdbbe46c06cb3f2f3e9adb43e9e48a98..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/module.json5 +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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": "strictequals", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "StrictequalsAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "StrictequalsAbility", - "srcEntry": "./ets/strictequalsability/StrictequalsAbility.ets", - "description": "$string:StrictequalsAbility_desc", - "icon": "$media:layered_image", - "label": "$string:StrictequalsAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/string.json deleted file mode 100755 index 7f004aac0f3849bb78c09f1b5b10cf3c333ee2be..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "StrictequalsAbility_desc", - "value": "description" - }, - { - "name": "StrictequalsAbility_label", - "value": "UsageInstructionsTwo" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/layered_image.json deleted file mode 100755 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/media/layered_image.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/profile/main_pages.json deleted file mode 100755 index 14bbd62cb9de385b1f5551945d749bb5e0e5fc2c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/main/resources/base/profile/main_pages.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "src": [ - "pages/Index" - ] -} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100755 index 485d59283b01ad0e39816668dc6f35cfc8b7ae62..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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', () => { - /** - * 打开应用,点击OH_JSVM_StrictEquals执行 - */ - it('testStrictEquals', 0, async (done: Function) => { - console.log('uitest: TestStrictEquals begin'); - - const want: Want = { - bundleName: bundleName, - abilityName: 'StrictequalsAbility' - } - 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('StrictequalsAbility'); - - await driver.delayMs(1000); - const text = await driver.findComponent(ON.text('OH_JSVM_StrictEquals')); - await text.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('success')); - console.log('uitest: TestStrictEquals end'); - done(); - }) - }) -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/List.test.ets deleted file mode 100755 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/module.json5 deleted file mode 100755 index 096e46e7510e100e501050fc891fe2cb51359124..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/JSVMAPI/JsvmUsageGuide/UsageInstructionsTwo/strictequals/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "strictequals_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/app.json5 deleted file mode 100755 index ede19046e1d4d5d8e31267aabe04bb10f678ae3f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiasynchronoustask", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/element/string.json deleted file mode 100755 index 2d04976352ccfdafe41f7582d9db3c730ecc86a1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIAsynchronousTask" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/README.md deleted file mode 100755 index ad578f30fe7b84924884f0572b2cf26b50935e5b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# ArkTS使用Node-API接口进行异步任务开发 - -### 介绍 - -本工程展示了使用Node-API接口进行异步任务开发中的Promise方式和callback方式,详细描述可查如下链接。 - -- [使用Node-API接口进行异步任务开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-asynchronous-task.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现如上图效果,和两个按钮,依次点击按钮后可以调用Promise方式和callback方式的方法,并将结果呈现到text文本中,并在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIAsynchronousTask.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── libentry - │ │ └── libentry1 - │ │ ├── callback.cpp // callback方式实现 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp // Promise方式实现 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 异步任务 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIAsynchronousTask.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeAPIAsynchronousTask > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/oh-package.json5 deleted file mode 100755 index 54a3b5a4446ba8baefec58d45e13bc351372dde4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/oh-package.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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", - "libentry1.so": "file:./src/main/cpp/types/libentry1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index ec971d6e4f0508b0048b11e5a73615e30928b990..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIAsynchronousTask) - -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) - -add_library(entry1 SHARED callback.cpp) -target_link_libraries(entry1 PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 9ec67bd35e443d9eb0032d95bfa957d5fab7442b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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" - -// [Start napi_create_async_work] -struct CallbackData { - napi_async_work asyncWork = nullptr; - napi_deferred deferred = nullptr; - napi_ref callback = nullptr; - double args = 0; - double result = 0; -}; - -// [StartExclude napi_create_async_work] -// [Start napi_first_call_back_work] -static void ExecuteCB(napi_env env, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - callbackData->result = callbackData->args; -} -// [End napi_first_call_back_work] - -// [Start napi_second_call_back_main] -static void CompleteCB(napi_env env, napi_status status, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - napi_value result = nullptr; - napi_create_double(env, callbackData->result, &result); - if (callbackData->result > 0) { - napi_resolve_deferred(env, callbackData->deferred, result); - } else { - napi_reject_deferred(env, callbackData->deferred, result); - } - - napi_delete_async_work(env, callbackData->asyncWork); - delete callbackData; -} -// [End napi_second_call_back_main] -// [EndExclude napi_create_async_work] - -static napi_value AsyncWork(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1]; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_value promise = nullptr; - napi_deferred deferred = nullptr; - napi_create_promise(env, &deferred, &promise); - - auto callbackData = new CallbackData(); - callbackData->deferred = deferred; - napi_get_value_double(env, args[0], &callbackData->args); - - napi_value resourceName = nullptr; - napi_create_string_utf8(env, "AsyncCallback", NAPI_AUTO_LENGTH, &resourceName); - // 创建异步任务 - napi_create_async_work(env, nullptr, resourceName, ExecuteCB, CompleteCB, callbackData, &callbackData->asyncWork); - // 将异步任务加入队列 - napi_queue_async_work(env, callbackData->asyncWork); - - return promise; -} -// [End napi_create_async_work] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"asyncWork", nullptr, AsyncWork, 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 35ceb64941d81f715f74b99a03645341649d9e36..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 asyncWork: (data: number) => Promise; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/Index.d.ts deleted file mode 100755 index 63a99bdb8085819692d732182ede6f9eba051040..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 asyncWork: (arg1: number, arg2: number, callback: (result: number) => void) => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/oh-package.json5 deleted file mode 100755 index 36e064ade2d3bc1ea4cfa7328074c55700ad0d91..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/cpp/types/libentry1/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentry1.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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index e350d5eb1faa8f67e264bad2f8afe3e98c2686ac..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 nativeModule from 'libentry1.so'; - -let num1: number = 123; -let num2: number = 456; - -@Entry -@Component -struct Index { - @State message: string = 'AsyncWork'; - - build() { - Column({space: 5}) { - Text(this.message) - .fontSize(30) - .fontWeight(FontWeight.Bold) - Button($r('app.string.AsyncWorkPromise')) - .margin(3) - .onClick(() => { - testNapi.asyncWork(1024).then((result) => { - hilog.info(0x0000, 'XXX', 'result is %{public}d', result); - this.message = 'result is ' + result.toString(); - }); - }) - Button($r('app.string.AsyncWorkCallback')) - .margin(3) - .onClick(() => { - nativeModule.asyncWork(num1, num2, (result) => { - hilog.info(0x0000, 'XXX', 'result is %{public}d', result); - this.message = 'result is ' + result.toString(); - }); - }) - } - .width('100%') - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/ohosTest.md deleted file mode 100755 index 1f25dfb7004407cb089f662ba674cf6ffeaeced0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeAPIAsynchronousTask/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 使用Node-API接口进行异步任务开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| --------------------------------------- | ------------ | -------------------------------------- | ---------------------------------------------------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 asyncWork | 位于主页 | 点击Call AsyncWorkCallback的Button组件 | 成功调用函数输出日志,页面顶端文本变为result is 579 | Pass | -| ArkTS端成功调用native侧接口 asyncWork | 位于主页 | 点击Call AsyncWorkPromise的Button组件 | 成功调用函数输出日志,页面顶端文本变为result is 1024 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/app.json5 deleted file mode 100755 index 649ca038445ef55415cebf2f3c4f97cbb9eaa53b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiloadmodule", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/element/string.json deleted file mode 100755 index 675cb765b62945079b5655adf8c381e4a7fd2d45..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeApiLoadModule" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/README.md deleted file mode 100755 index 55e0727daf77684511e51272ed38cb437b3693f2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API接口在主线程中进行模块加载 - -### 介绍 - -本工程展示了使用Node-API接口在主线程中进行系统模块加载与ArkTS单文件加载。详细描述可查如下链接中。 - -- [使用Node-API接口在主线程中进行模块加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-load-module.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现如上图效果和两个按钮,依次点击按钮后可以加载系统模块和单文件模块,并将成功结果呈现到text文本中。 -3. 运行测试用例NodeApiLoadModule.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── libentry - │ │ └── libentry1 - │ │ ├── file.cpp // ArkTS单文件加载 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp // 系统模块加载 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 加载模块 - │ │ ├── Test.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeApiLoadModule.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiLoadModule > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/build-profile.json5 deleted file mode 100755 index a00dddb50c688a3ee72bf4570dcebeb3b2934b54..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/build-profile.json5 +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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", - // [Start napi_load_module_napi_build] - "buildOption": { - "arkOptions" : { - "runtimeOnly" : { - "sources": [ - "./src/main/ets/Test.ets" - ] - } - }, - // [End napi_load_module_napi_build] - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/oh-package.json5 deleted file mode 100755 index 54a3b5a4446ba8baefec58d45e13bc351372dde4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/oh-package.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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", - "libentry1.so": "file:./src/main/cpp/types/libentry1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 5b0b4adc213ffaa3b4ccb2ce069b0902c3999cd3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeApiLoadModule) - -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) - -add_library(entry1 SHARED file.cpp) -target_link_libraries(entry1 PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/file.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/file.cpp deleted file mode 100755 index 5aef2ae53fc9b3a0271243d62f4b5090c2fe8e12..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/file.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 -// [Start napi_load_module_napi_file] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - napi_value result; - // 1. 使用napi_load_module加载Test文件中的模块 - napi_status status = napi_load_module(env, "ets/Test", &result); - - napi_value testFn; - // 2. 使用napi_get_named_property获取test函数 - napi_get_named_property(env, result, "test", &testFn); - // 3. 使用napi_call_function调用函数test - napi_call_function(env, result, testFn, 0, nullptr, nullptr); - - napi_value value; - napi_value key; - std::string keyStr = "value"; - napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); - // 4. 使用napi_get_property获取变量value - napi_get_property(env, result, key, &value); - return result; -} -// [End napi_load_module_napi_file] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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 = "entry1", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index c6ca2381ca2acb53442f26461edb975c5f1dbfc6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 -// [Start napi_load_module_napi_init] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - // 1. 使用napi_load_module加载模块@ohos.hilog - napi_value result; - napi_status status = napi_load_module(env, "@ohos.hilog", &result); - - // 2. 使用napi_get_named_property获取info函数 - napi_value infoFn; - napi_get_named_property(env, result, "info", &infoFn); - - napi_value tag; - std::string formatStr = "test"; - napi_create_string_utf8(env, formatStr.c_str(), formatStr.size(), &tag); - - napi_value outputString; - std::string str = "Hello OpenHarmony"; - napi_create_string_utf8(env, str.c_str(), str.size(), &outputString); - - napi_value flag; - napi_create_int32(env, 0, &flag); - - napi_value args[3] = {flag, tag, outputString}; - // 3. 使用napi_call_function调用info函数 - napi_call_function(env, result, infoFn, 3, args, nullptr); - return result; -} -// [End napi_load_module_napi_init] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/oh-package.json5 deleted file mode 100755 index 36e064ade2d3bc1ea4cfa7328074c55700ad0d91..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/cpp/types/libentry1/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentry1.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/Test.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/Test.ets deleted file mode 100755 index e9b1d7e82c1e88ced04cd8625c5ab6e369558a4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/Test.ets +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_load_module_napi_test] -let value = 123; -function test() { - console.log('Hello OpenHarmony'); -} -export {value, test}; -// [End napi_load_module_napi_test] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index d4341fc545f352ab5080b58213087eb565495714..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 test from 'libentry1.so'; - -@Entry -@Component -struct Index { - @State message: string = 'LoudModule'; - - build() { - Column() { - Text(this.message) - .fontSize(30) - Button($r('app.string.loadModuleSystem')) - .margin(3) - .width('70%') - .onClick(() => { - testNapi.loadModule(); - this.message = 'loadModuleSystem success'; - }) - Button($r('app.string.loadModuleFile')) - .margin(3) - .width('70%') - .onClick(() => { - test.loadModule(); - this.message = 'loadModuleFile success'; - }) - } - .width('100%') - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/ohosTest.md deleted file mode 100755 index 0ad3be6c53d6a5b1ce05485d36136418fd523cfe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModule/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 使用Node-API接口在主线程中进行模块加载测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ---------------------------------------- | ------------ | ----------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleSystem的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleSystem success | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleFile的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleFile success | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/app.json5 deleted file mode 100755 index 4097e707312a9c2b781061adbc916d15f112eaee..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiloadmodulewithinfo", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/element/string.json deleted file mode 100755 index fd19d4fd5b793d2c45bd3aaea753b5a7a4b999d2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeApiLoadModuleWithInfo" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/README.md deleted file mode 100755 index 89c98d8f9cbdd90bfdb9f49ff36f464086b4cd7f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/README.md +++ /dev/null @@ -1,86 +0,0 @@ -# ArkTS使用Node-API接口进行模块加载 - -### 介绍 - - Node-API中的napi_load_module_with_info接口的功能是进行模块的加载,当模块加载出来之后,可以使用函数napi_get_property获取模块导出的变量,也可以使用napi_get_named_property获取模块导出的函数,该函数可以在新创建的ArkTS基础运行时环境中使用。 - - 本工程展示了使用napi_load_module_with_info接口进行对不同内容的加载,代码详细描述可查如下链接。 - -- [使用Node-API接口进行模块加载](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-load-module-with-info.md) - -### 效果预览 - -| 首页图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现LoadModule效果和六个按钮,点击按钮后可以调用napi_load_module_with_info接口进行对不同内容进行加载,并修改Text文本内容。 -3. 运行测试用例NodeApiLoadModuleWithInfo.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── libentry - │ │ └── libentryone - │ │ └── libentrytwo - │ │ └── libentrythree - │ │ └── libentryfour - │ │ ├── api.cpp // 加载API模块 - │ │ ├── har_name.cpp // 加载HAR模块名 - │ │ ├── file.cpp // 加载模块内文件路径 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp // 加载Native库 - │ │ ├── remote_har.cpp // 加载远程HAR模块名 - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 加载模块 - │ │ ├── Test.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeApiLoadModuleWithInfo.test.ets // 自动化测试代码 - │ │ └── List.test.ets - har1/ // HAR加载HAR模块名 - har2/ // HAR加载HAR模块名 - library/ // 加载HAR模块名 -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiLoadModuleWithInfo > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/build-profile.json5 deleted file mode 100755 index b0505bb0e6c79e11a0f5ad813212199460e98ff6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/build-profile.json5 +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "library", - "srcPath": "./library", - }, - { - "name": "har1", - "srcPath": "./har1", - }, - { - "name": "har2", - "srcPath": "./har2", - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/build-profile.json5 deleted file mode 100755 index 03ac87827c9c7bb161ceedaa87b79a4d5fbec075..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/build-profile.json5 +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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", - // [Start napi_load_module_with_info_entry_build] - // [Start napi_load_module_with_info_entry_build2] - // [Start napi_load_module_with_info_entry_build3] - // [Start napi_load_module_with_info_entry_build4] - "buildOption": { - "arkOptions" : { - "runtimeOnly" : { - // [StartExclute napi_load_module_with_info_entry_build2] - // [StartExclute napi_load_module_with_info_entry_build3] - // [StartExclute napi_load_module_with_info_entry_build4] - "sources": [ - "./src/main/ets/Test.ets", - ], - // [EndExclute napi_load_module_with_info_entry_build2] - // [EndExclute napi_load_module_with_info_entry_build3] - // [EndExclute napi_load_module_with_info_entry_build4] - // [End napi_load_module_with_info_entry_build] - "packages": [ - // [StartExclute napi_load_module_with_info_entry_build3] - // [StartExclute napi_load_module_with_info_entry_build4] - "library", - // [End napi_load_module_with_info_entry_build2] - // [EndExclute napi_load_module_with_info_entry_build4] - "libentry.so", - // [End napi_load_module_with_info_entry_build4] - "libentryone.so", - "libentrytwo.so", - "libentrythree.so", - "libentryfour.so", - "har1", - // [EndExclute napi_load_module_with_info_entry_build3] - "@ohos/hypium" - // [End napi_load_module_with_info_entry_build3] - ] - } - }, - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/oh-package.json5 deleted file mode 100755 index 20e134cad1669ed077f1470c349f806f0724ec56..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/oh-package.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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": "", - // [Start napi_load_module_with_info_entry_oh] - // [Start napi_load_module_with_info_entry_oh2] - // [Start napi_load_module_with_info_entry_oh3] - "dependencies": { - // [StartExclute napi_load_module_with_info_entry_oh] - // [StartExclute napi_load_module_with_info_entry_oh2] - "libentry.so": "file:./src/main/cpp/types/libentry", - // [Start napi_load_module_with_info_entry_oh3] - "libentryone.so": "file:./src/main/cpp/types/libentryone", - "libentrytwo.so": "file:./src/main/cpp/types/libentrytwo", - "libentrythree.so": "file:./src/main/cpp/types/libentrythree", - "libentryfour.so": "file:./src/main/cpp/types/libentryfour", - // [EndExclute napi_load_module_with_info_entry_oh] - "library": "file:../library", - // [End napi_load_module_with_info_entry_oh] - // [EndExclute napi_load_module_with_info_entry_oh2] - "@ohos/hypium": "1.0.16", - // [End napi_load_module_with_info_entry_oh2] - "har1": "file:../har1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index f510980786015e47c4cb18d959d936dbae0b9fd8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeApiLoadModuleWithInfo) - -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) - -add_library(entryone SHARED har_name.cpp) -target_link_libraries(entryone PUBLIC libace_napi.z.so) - -add_library(entrytwo SHARED remote_har.cpp) -target_link_libraries(entrytwo PUBLIC libace_napi.z.so) - -add_library(entrythree SHARED api.cpp) -target_link_libraries(entrythree PUBLIC libace_napi.z.so) - -add_library(entryfour SHARED file.cpp) -target_link_libraries(entryfour PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/file.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/file.cpp deleted file mode 100755 index df5669b217c28eda4433161bc3ff7df75af8ae13..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/file.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 -#include "napi/native_api.h" -// [Start napi_load_module_with_info_entry_file] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - napi_value result; - // 1. 使用napi_load_module_with_info加载Test文件中的模块 - napi_status status = - napi_load_module_with_info(env, "entry/src/main/ets/Test", "com.example.application/entry", &result); - - napi_value testFn; - // 2. 使用napi_get_named_property获取test函数 - napi_get_named_property(env, result, "test", &testFn); - // 3. 使用napi_call_function调用函数test - napi_call_function(env, result, testFn, 0, nullptr, nullptr); - - napi_value value; - napi_value key; - std::string keyStr = "value"; - napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); - // 4. 使用napi_get_property获取变量value - napi_get_property(env, result, key, &value); - return result; -} -// [End napi_load_module_with_info_entry_file] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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 = "entryfour", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 4baacf9868eea04cb641a5c307d5a8131ede95ab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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" -// [Start napi_load_module_with_info_entry_napi_init] -static constexpr int INT_ARG_2 = 2; // 入参索引 -static constexpr int INT_ARG_3 = 3; // 入参索引 - -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - napi_value result; - // 1. 使用napi_load_module_with_info加载libentry.so - napi_status status = napi_load_module_with_info(env, "libentry.so", "com.example.application/entry", &result); - - napi_value addFn; - // 2. 使用napi_get_named_property获取add函数 - napi_get_named_property(env, result, "add", &addFn); - - napi_value a; - napi_value b; - napi_create_int32(env, INT_ARG_2, &a); - napi_create_int32(env, INT_ARG_3, &b); - napi_value args[2] = {a, b}; - // 3. 使用napi_call_function调用函数add - napi_value returnValue; - napi_call_function(env, result, addFn, INT_ARG_2, args, &returnValue); - return result; -} -// [End napi_load_module_with_info_entry_napi_init] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"loadModule", nullptr, loadModule, 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/oh-package.json5 deleted file mode 100755 index 1d11de68ff5ac505cde952e88ab0876f9a1d54b9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryfour/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentryfour.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/oh-package.json5 deleted file mode 100755 index 79fbadf636e53d87ee92b076521afde7547c7a96..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentryone/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentryone.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/oh-package.json5 deleted file mode 100755 index 1a5827542195a0b6e01901ac470d4806d122d906..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrythree/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentrythree.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/Index.d.ts deleted file mode 100755 index 3ea0fb8778e0944a151f2d7bb80fb7b707067f15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/Index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/oh-package.json5 deleted file mode 100755 index 3de70b84bbbfca145321d768066663ddcd937b31..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/cpp/types/libentrytwo/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentrytwo.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/Test.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/Test.ets deleted file mode 100755 index cc4cc49b665d5cbc600d0d3a35e61f2665a186ea..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/Test.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_load_module_with_info_entry_test] -let value = 123; - -function test() { - console.log('Hello OpenHarmony'); -} - -export { value, test }; -// [End napi_load_module_with_info_entry_test] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index a7f3c13067fede4ed1636bc88afdc4eb532d281c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 napiHar from 'libentryone.so'; -import napiRemoteHar from 'libentrytwo.so'; -import napiAPI from 'libentrythree.so'; -import napiFile from 'libentryfour.so' -import { tests } from 'har1'; - -@Entry -@Component -struct Index { - @State message: string = 'LoadModule'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bolder) - Button($r('app.string.loadModuleFile')) - .width('70%') - .onClick(() => { - napiFile.loadModule(); - this.message = 'loadModuleFile success'; - }) - Button($r('app.string.loadModuleHarName')) - .width('70%') - .onClick(() => { - napiHar.loadModule(); - this.message = 'loadModuleHarName success'; - }) - Button($r('app.string.loadModuleRemoteHar')) - .width('70%') - .onClick(() => { - napiRemoteHar.loadModule(); - this.message = 'loadModuleRemoteHar success'; - }) - Button($r('app.string.loadModuleAPI')) - .width('70%') - .onClick(() => { - napiAPI.loadModule(); - this.message = 'loadModuleAPI success'; - }) - Button($r('app.string.loadModuleNative')) - .width('70%') - .onClick(() => { - testNapi.loadModule(); - this.message = 'loadModuleNative success'; - }) - Button($r('app.string.loadModuleHarToHar')) - .width('70%') - .onClick(() => { - tests(); - this.message = 'loadModuleHarToHar success'; - }) - } - .width('100%') - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/Index.ets deleted file mode 100755 index 4c3322f217f4ecefd49477d90365ca2bdd057d30..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/Index.ets +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 'libhar1.so'; - -export { MainPage } from './src/main/ets/components/MainPage'; - -function tests() { - testNapi.loadModule(); -} - -export { tests }; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/build-profile.json5 deleted file mode 100755 index cd34a51c3351f98decdd49de9ef1218a30f36f1f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/build-profile.json5 +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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", - // [Start napi_load_module_with_info_har1_build] - "buildOption": { - "arkOptions": { - "runtimeOnly": { - "packages": [ - "har2", - // [End napi_load_module_with_info_har1_build] - "libhar1.so" - ] - } - }, - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/oh-package.json5 deleted file mode 100755 index 05b7ff9d29e1007e435eabf2ae9e2b2a48d6d0e9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/oh-package.json5 +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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": "har1", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - // [Start napi_load_module_with_info_har1_oh] - "dependencies": { - "har2": "file:../har2", - // [End napi_load_module_with_info_har1_oh] - "libhar1.so": "file:./src/main/cpp/types/libhar1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/CMakeLists.txt deleted file mode 100755 index d6cd09509747f250b4e04c7b6b463892524a73c7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeApiLoadModuleWithInfo) - -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(har1 SHARED napi_init.cpp) -target_link_libraries(har1 PUBLIC libace_napi.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/napi_init.cpp deleted file mode 100755 index ee70ca579e71850c21e220e490f3918a12399c84..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 - -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - - double value0; - napi_get_value_double(env, args[0], &value0); - - double value1; - napi_get_value_double(env, args[1], &value1); - - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - - return sum; -} -// [Start napi_load_module_with_info_har1_napi_init] -static napi_value loadModule(napi_env env, napi_callback_info info) -{ - napi_value result; - // 1. 使用napi_load_module_with_info加载har2,注意这里的moduleName为模块所在HAP包的moduleName - napi_status status = napi_load_module_with_info(env, "har2", "com.example.application/entry", &result); - - napi_value testFn; - // 2. 使用napi_get_named_property获取test函数 - napi_get_named_property(env, result, "test", &testFn); - // 3. 使用napi_call_function调用函数test - napi_call_function(env, result, testFn, 0, nullptr, nullptr); - - napi_value value; - napi_value key; - std::string keyStr = "value"; - napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key); - // 4. 使用napi_get_property获取变量value - napi_get_property(env, result, key, &value); - return result; -} -// [End napi_load_module_with_info_har1_napi_init] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"loadModule", nullptr, loadModule, 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 = "har1", - .nm_priv = ((void *)0), - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterHar1Module(void) { napi_module_register(&demoModule); } diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/index.d.ts deleted file mode 100755 index 5fc9f8f93b81cd75485a390a2302ef5c447af4d5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_load_module_with_info_har1_dts] -export const add: (a: number, b: number) => number; -// [End napi_load_module_with_info_har1_dts] -export const loadModule: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/oh-package.json5 deleted file mode 100755 index 6b3f73a609e6d026d2b26e8a924dbf44d66fe6c8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/cpp/types/libhar1/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libhar1.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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/module.json5 deleted file mode 100755 index bdac60be9af186785fdad034997a0ad0e8d0425e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "har1", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/module.json5 deleted file mode 100755 index 49d7bcb9feed30b64a003c95d738594b9280377f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har1/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "har1_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/Index.ets deleted file mode 100755 index 43a3d53c32592a69a07c9f75e3e0cfeed8866732..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/Index.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 { MainPage } from './src/main/ets/components/MainPage' -// [Start napi_load_module_with_info_har2_index] -let value = 123; - -function test() { - console.log('Hello OpenHarmony'); -} - -export { value, test }; -// [End napi_load_module_with_info_har2_index] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/build-profile.json5 deleted file mode 100755 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/build-profile.json5 +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/oh-package.json5 deleted file mode 100755 index 39e87d1423686fe45e0bb54fe5e4d3aee89b302c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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": "har2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/module.json5 deleted file mode 100755 index 26b32e3ff585426e0eb7e21fcdb475612c1b99de..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "har2", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/module.json5 deleted file mode 100755 index 68ada365ca86668f844fe10c4326151ffa0a03a5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/har2/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "har2_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/Index.ets deleted file mode 100755 index 64f8aae764d4fec19958945c51cfb46c06f9a255..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/Index.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_load_module_with_info_library_index] -export { MainPage } from './src/main/ets/components/MainPage'; - -let value = 123; -function test() { - console.log('Hello OpenHarmony'); -} -export {value, test}; -// [End napi_load_module_with_info_library_index] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/build-profile.json5 deleted file mode 100755 index 5552c941deb9b582d7a6fe3c10b68db248d60eb9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/build-profile.json5 +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - }, - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/oh-package.json5 deleted file mode 100755 index fae4159fcbe40c497182f2727c88badb04ce407b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/oh-package.json5 +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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": "library", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "Index.ets", - "author": "", - "license": "Apache-2.0", - "dependencies": {} -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/ets/components/MainPage.ets b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/ets/components/MainPage.ets deleted file mode 100755 index 1243a59406e1b63ff9546ee0bbcf9c2bde468a77..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/ets/components/MainPage.ets +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -@Component -export struct MainPage { - @State message: string = 'Hello World'; - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - } - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/module.json5 deleted file mode 100755 index 3f3b753ed0fd6b6a3fd011ac15c76fffe337cad6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/main/module.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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": "library", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/module.json5 deleted file mode 100755 index 472a25c73da304a66c5c53887f677517c5700640..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/library/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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": "library_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/ohosTest.md deleted file mode 100755 index 66f599baf454e0cf1cefa4d5dc442fce49516a7c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeAPIClassicUseCases/NodeApiLoadModuleWithInfo/ohosTest.md +++ /dev/null @@ -1,13 +0,0 @@ -# 使用Node-API接口进行模块加载测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ---------------------------------------- | ------------ | -------------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleFile的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleFile success | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleHarName的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleHarName success | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleRemoteHar的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleRemoteHar success | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleAPI的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleAPI success | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleNative的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleNative success | Pass | -| ArkTS端成功调用native侧接口 loadModule | 位于主页 | 点击按钮为调用Call loadModuleHarToHar的Button组件 | 成功调用函数输出日志,页面顶端文本变为loadModuleHarToHar success | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/app.json5 deleted file mode 100755 index b87b01bcc5b713156fc2aad7e7356d712e85e723..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiapplicationscenario", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/element/string.json deleted file mode 100755 index b853cf75b1c426baf4bab34a98b9780f6770199e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeApiApplicationScenario" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/README.md deleted file mode 100755 index 68729a5cbb6dec596bbd77b6412bc66a7851137c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/README.md +++ /dev/null @@ -1,87 +0,0 @@ -# ArkTSNode-API使用场景 - -### 介绍 - -开发者通过pthread_create创建新线程后,可以通过napi_create_ark_runtime来创建一个新的ArkTS基础运行时环境,并通过该运行时环境加载ArkTS模块。当使用结束后,开发者需要通过napi_destroy_ark_runtime来销毁所创建的ArkTS基础运行时环境。 - -napi_create_threadsafe_function是Node-API接口之一,用于创建一个线程安全的JavaScript函数。主要用于在多个线程之间共享和调用,而不会出现竞争条件或死锁。例如异步计算、数据共享、多线程编程场景。 - -Node-API中的napi_call_threadsafe_function_with_priority接口的功能是从异步线程向ArkTS线程投递任务,底层队列会根据任务的优先级和入队方式来处理任务。 - -在自己创建的ArkTS运行环境中调用异步的ArkTS接口时,可以通过使用Node-API中的扩展接口napi_run_event_loop和napi_stop_event_loop来运行和停止ArkTS实例中的事件循环,该工程中展示的代码详细描述可查如下链接。 - -- [使用Node-API接口创建ArkTS运行时环境](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-ark-runtime.md) -- [使用Node-API接口进行线程安全开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-thread-safety.md) -- [使用Node-API接口从异步线程向ArkTS线程投递指定优先级和入队方式的的任务](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-call-threadsafe-function-with-priority.md) -- [使用扩展的Node-API接口在异步线程中运行和停止事件循环](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-event-loop.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击button组件可以执行对应文本内容的Node-API接口并将文本NodeAPI改为执行成功结果。 -3. 运行测试用例NodeApiApplicationScenario.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── libentry - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── libentry1 - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ │ ├── thread_safety.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // Node-API使用场景 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeApiApplicationScenario.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/build-profile.json5 deleted file mode 100755 index 69c4785e3c936e5eee8a952c36fae67a8f40e683..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/build-profile.json5 +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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", -// [Start napi_event_loop_build] -// [Start napi_ark_runtime_build] - "buildOption": { - "arkOptions" : { - "runtimeOnly" : { - "sources": [ - "./src/main/ets/pages/ObjectUtils.ets" - ] - } - }, -// [End napi_event_loop_build] -// [Start napi_ark_runtime_build] - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/oh-package.json5 deleted file mode 100755 index 54a3b5a4446ba8baefec58d45e13bc351372dde4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/oh-package.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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", - "libentry1.so": "file:./src/main/cpp/types/libentry1" - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 59fb92fd61bd722b45780f2e2905d4bbd818e1e6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(MyApplication) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -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) -add_library(entry1 SHARED thread_safety.cpp) -target_link_libraries(entry1 PUBLIC libace_napi.z.so libhilog_ndk.z.so) diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index ec9b10d9e5fb4a5b85f81d1a3e88523bb12ed4e4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_call_threadsafe_function_with_priority_cpp] -// [Start napi_ark_runtime_cpp] -#include -#include "napi/native_api.h" -// [StartExclute napi_ark_runtime_cpp] -#include -#include -#include - -static constexpr int INT_ARG_2 = 2; // 入参索引 -static constexpr int INT_ARG_12 = 12; // 入参索引 -static constexpr int INT_ARG_15 = 15; // 入参索引 -// [EndExclute napi_ark_runtime_cpp] -// [StartExclute napi_call_threadsafe_function_with_priority_cpp] -static void *CreateArkRuntimeFunc(void *arg) -{ - // 1. 创建基础运行环境 - napi_env env; - napi_status ret = napi_create_ark_runtime(&env); - if (ret != napi_ok) { - return nullptr; - } - - // 2. 加载自定义模块 - napi_value objUtils; - ret = napi_load_module_with_info(env, "entry/src/main/ets/pages/ObjectUtils", "com.example.myapplication/entry", - &objUtils); - if (ret != napi_ok) { - return nullptr; - } - - // 3. 使用ArkTS中的logger - napi_value logger; - ret = napi_get_named_property(env, objUtils, "Logger", &logger); - if (ret != napi_ok) { - return nullptr; - } - ret = napi_call_function(env, objUtils, logger, 0, nullptr, nullptr); - - // 4. 销毁ArkTS环境 - ret = napi_destroy_ark_runtime(&env); - - return nullptr; -} - -static napi_value CreateArkRuntime(napi_env env, napi_callback_info info) -{ - pthread_t tid; - pthread_create(&tid, nullptr, CreateArkRuntimeFunc, nullptr); - pthread_join(tid, nullptr); - return nullptr; -} -// [StartExclute napi_ark_runtime_cpp] -// [Start napi_event_loop_cpp] -static napi_value ResolvedCallback(napi_env env, napi_callback_info info) -{ - napi_stop_event_loop(env); - return nullptr; -} - -static napi_value RejectedCallback(napi_env env, napi_callback_info info) -{ - napi_stop_event_loop(env); - return nullptr; -} - -static void *RunEventLoopFunc(void *arg) -{ - // 1. 创建ArkTS实例 - napi_env env; - napi_status ret = napi_create_ark_runtime(&env); - if (ret != napi_ok) { - return nullptr; - } - - // 2. 加载自定义的模块 - napi_value objectUtils; - // 'com.example.myapplication' 为当前应用的bundleName - ret = napi_load_module_with_info(env, "ets/pages/ObjectUtils", "com.example.myapplication/entry", &objectUtils); - if (ret != napi_ok) { - return nullptr; - } - - // 3. 调用异步SetTimeout接口 - napi_value setTimeout = nullptr; - napi_value promise = nullptr; - - napi_get_named_property(env, objectUtils, "SetTimeout", &setTimeout); - napi_call_function(env, objectUtils, setTimeout, 0, nullptr, &promise); - - napi_value theFunc = nullptr; - if (napi_get_named_property(env, promise, "then", &theFunc) != napi_ok) { - return nullptr; - } - - napi_value resolvedCallback = nullptr; - napi_value rejectedCallback = nullptr; - napi_create_function(env, "resolvedCallback", NAPI_AUTO_LENGTH, ResolvedCallback, nullptr, &resolvedCallback); - napi_create_function(env, "rejectedCallback", NAPI_AUTO_LENGTH, RejectedCallback, nullptr, &rejectedCallback); - napi_value argv[2] = {resolvedCallback, rejectedCallback}; - napi_call_function(env, promise, theFunc, INT_ARG_2, argv, nullptr); - - auto flag = reinterpret_cast(arg); - if (*flag == true) { - napi_run_event_loop(env, napi_event_mode_default); - } else { - // 非阻塞式的处理任务,有可能队列中还没有任务就已经返回了 - napi_run_event_loop(env, napi_event_mode_nowait); - } - return nullptr; -} - -static napi_value RunEventLoop(napi_env env, napi_callback_info info) -{ - pthread_t tid; - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - bool flag = false; - napi_get_value_bool(env, argv[0], &flag); - // 创建异步线程 - pthread_create(&tid, nullptr, RunEventLoopFunc, &flag); - pthread_join(tid, nullptr); - - return nullptr; -} -// [StartExclute napi_event_loop_cpp] -// [EndExclute napi_call_threadsafe_function_with_priority_cpp] -struct CallbackData { - napi_threadsafe_function tsfn; - napi_async_work work; -}; -// ArkTS线程的回调实现 -static void CallJs(napi_env env, napi_value jsCb, void *context, void *data) -{ - if (env == nullptr) { - return; - } - napi_value resultNumber = nullptr; - napi_value undefined = nullptr; - napi_get_undefined(env, &undefined); - napi_value number1 = nullptr; - napi_create_int32(env, INT_ARG_12, &number1); - napi_value number2 = nullptr; - napi_create_int32(env, INT_ARG_15, &number2); - napi_value argv[2] = {number1, number2}; - napi_call_function(env, undefined, jsCb, INT_ARG_2, argv, &resultNumber); - int32_t res = 0; - napi_get_value_int32(env, resultNumber, &res); -} - -// 异步线程中调用该接口向ArkTS线程投递指定优先级和入队方式的任务 -static void ExecuteWork(napi_env env, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - // 执行任务为napi_priority_idle优先级,入队方式为队列尾部入队 - napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_idle, true); - napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_low, true); - napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_high, true); - napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_immediate, true); - // 执行任务为napi_priority_high优先级,入队方式为队列头部入队 - napi_call_threadsafe_function_with_priority(callbackData->tsfn, nullptr, napi_priority_high, false); -} - -static void WorkComplete(napi_env env, napi_status status, void *data) -{ - CallbackData *callbackData = reinterpret_cast(data); - napi_release_threadsafe_function(callbackData->tsfn, napi_tsfn_release); - napi_delete_async_work(env, callbackData->work); - callbackData->work = nullptr; - callbackData->tsfn = nullptr; -} - -static napi_value CallThreadSafeWithPriority(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value jsCb = nullptr; - CallbackData *callbackData = nullptr; - napi_get_cb_info(env, info, &argc, &jsCb, nullptr, reinterpret_cast(&callbackData)); - napi_value resourceName = nullptr; - napi_create_string_utf8(env, "Thread-safe Function Demo", NAPI_AUTO_LENGTH, &resourceName); - napi_create_threadsafe_function(env, jsCb, nullptr, resourceName, 0, 1, callbackData, nullptr, callbackData, CallJs, - &callbackData->tsfn); - napi_create_async_work(env, nullptr, resourceName, ExecuteWork, WorkComplete, callbackData, &callbackData->work); - napi_queue_async_work(env, callbackData->work); - return nullptr; -} -// [EndExclute napi_event_loop_cpp] -// [EndExclute napi_ark_runtime_cpp] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - CallbackData *callbackData = new CallbackData(); - napi_property_descriptor desc[] = { - {"createArkRuntime", nullptr, CreateArkRuntime, nullptr, nullptr, nullptr, napi_static, nullptr}, - {"runEventLoop", nullptr, RunEventLoop, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"callThreadSafeWithPriority", nullptr, CallThreadSafeWithPriority, nullptr, nullptr, nullptr, - napi_default, callbackData}}; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} -EXTERN_C_END - -static napi_module nativeModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "entry", - .nm_priv = nullptr, - .reserved = {0}, -}; - -extern "C" __attribute__((constructor)) void RegisterQueueWorkModule() { napi_module_register(&nativeModule); } -// [End napi_call_threadsafe_function_with_priority_cpp] -// [End napi_event_loop_cpp] -// [End napi_ark_runtime_cpp] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 02cad6e4e360d9319894bd82fed7bdde7a2ff6c3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_ark_runtime_dts] -export const createArkRuntime: () => object; -// [End napi_ark_runtime_dts] -// [Start napi_event_loop_dts] -export const runEventLoop: (isDefault: boolean) => object; -// [End napi_event_loop_dts] -// [Start napi_call_threadsafe_function_with_priority_dts] -export const callThreadSafeWithPriority: (cb: (a: number, b: number) => number) => void; -// [End napi_call_threadsafe_function_with_priority_dts] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/Index.d.ts deleted file mode 100755 index dd21c1bcca61780eb1b6af8ecd5fb35bf273447d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/Index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_thread_safety_dts] -export const startThread: (a: () => Promise) => void; -// [End napi_thread_safety_dts] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/oh-package.json5 deleted file mode 100755 index 36e064ade2d3bc1ea4cfa7328074c55700ad0d91..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/cpp/types/libentry1/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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": "libentry1.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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 0df5e4a1b9afa0f1196fe4bc2f75c8eaf83d2dbe..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -// [Start napi_call_threadsafe_function_with_priority_ets] -// [Start napi_event_loop_ets] -// [Start napi_ark_runtime_ets] -import testNapi from 'libentry.so'; -// [StartExclute napi_call_threadsafe_function_with_priority_ets] -// [StartExclute napi_event_loop_ets] -// [StartExclute napi_ark_runtime_ets] -// [Start napi_thread_safety_ets] -import nativeModule from 'libentry1.so'; -// [StartExclute napi_thread_safety_ets] -@Entry -@Component -struct Index { - @State message: string = 'NodeAPI'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(30) - .fontWeight(FontWeight.Bold) - Button($r('app.string.createArkRuntime')) - .width('70%') - .onClick(() => { - // [EndExclute napi_ark_runtime_ets] - testNapi.createArkRuntime(); - // [End napi_ark_runtime_ets] - this.message = 'ArkRuntime success'; - }) - Button($r('app.string.runEventLoop')) - .width('70%') - .onClick(() => { - // [EndExclute napi_event_loop_ets] - testNapi.runEventLoop(true); - // [End napi_event_loop_ets] - this.message = 'EventLoop success'; - }) - Button($r('app.string.CallThreadSafeWithPriority')) - .width('70%') - .onClick(() => { - // [EndExclute napi_call_threadsafe_function_with_priority_ets] - let callback = (a: number, b: number): number => { - console.info('result is ' + (a + b)) - return a + b; - } - testNapi.callThreadSafeWithPriority(callback); - // [End napi_call_threadsafe_function_with_priority_ets] - this.message = 'ThreadSafeWithPriority success'; - }) - Button($r('app.string.startThread')) - .width('70%') - .onClick(() => { - // [EndExclute napi_thread_safety_ets] - let callback = (): Promise => { - return new Promise((resolve) => { - setTimeout(() => { - resolve('string from promise'); - }, 5000); - }); - } - nativeModule.startThread(callback); - // [End napi_thread_safety_ets] - this.message = 'StartThread success'; - }) - } - .width('100%') - .height('100%') - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/ohosTest.md deleted file mode 100755 index b6660114f126e9312a8e1d77a2dff7f7edc5696d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiClassicUseCases/NodeApiApplicationScenario/ohosTest.md +++ /dev/null @@ -1,11 +0,0 @@ -# Node-API使用场景用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| -------------------------------------------------------- | ------------ | ----------------------------------------------- | --------------------------------------------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口createArkRuntime | 位于主页 | 点击Call createArkRuntime的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | -| ArkTS端成功调用native侧接口 callThreadSafeWithPriority | 位于主页 | 点击Call CallThreadSafeWithPriority的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | -| ArkTS端成功调用native侧接口runEventLoop | 位于主页 | 点击按钮为调用runEventLoop的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | -| ArkTS端成功调用native侧接口startThread | 位于主页 | 点击按钮为调用startThread的Button组件 | 成功调用函数输出日志,页面顶端文本变为success | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/app.json5 deleted file mode 100755 index 6ad8b4f7f760f0f5505d46aca2d3dee1f7a75e92..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiarray", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/element/string.json deleted file mode 100755 index 6af9a7ec9e6be505a368d926df402f87217e0394..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIArray" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/README.md deleted file mode 100755 index 5d2b33db6a40235c0fa71fc3582144f82b7d5d2f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API接口进行array相关开发 - -### 介绍 - -使用Node-API接口进行array相关开发时,调用相关接口可以在Node-API模块中直接操作和处理ArkTS中的数组,使用Node-API接口进行数组(array)相关开发时,涉及的基本概念主要包括数组的创建、访问、修改、遍历以及与数组相关的操作。 - -该工程中展示了在Node-API模块中进行数组创建、获取数组长度、通过索引获得对应值等场景,其中代码详细描述可查如下链接。 - -- [使用Node-API接口进行array相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-array.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIArray.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API接口进行array相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIArray.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIArray/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 6700d5f02f40643afec4c1b0fb7127331bc0a78c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPI_array) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index bc1c616708d72f587cd7d5f551d40a7bf29169ab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,475 +0,0 @@ -/* - * 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 -#include "napi/native_api.h" - -// [Start napi_create_array] -static constexpr int INT_NUMBER_5 = 5; // 入参索引 -static constexpr int INT_ARGS_2 = 2; // 入参索引 - -// 使用Node-API接口进行array相关开发 napi_create_array -static napi_value CreateArray(napi_env env, napi_callback_info info) -{ - // 创建一个空数组 - napi_value jsArray = nullptr; - napi_create_array(env, &jsArray); - // 将创建好的数组进行赋值 - for (int i = 0; i < INT_NUMBER_5; i++) { - napi_value element; - napi_create_int32(env, i, &element); - napi_set_element(env, jsArray, i, element); - } - // 返回已创建好的数组 - return jsArray; -} -// [End napi_create_array] - -// [Start napi_create_array_with_length] -// 使用Node-API接口进行array相关开发 napi_create_array_with_length -static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_value jsArray = nullptr; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 获取传递的数组长度 - int32_t length = 0; - napi_get_value_int32(env, argv[0], &length); - // 使用napi_create_array_with_length创建指定长度的数组 - napi_create_array_with_length(env, length, &jsArray); - // 返回数组 - return jsArray; -} -// [End napi_create_array_with_length] - -// [Start napi_get_array_length] -// 使用Node-API接口进行array相关开发 napi_get_array_length -static napi_value GetArrayLength(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_value result; - uint32_t length; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 检查参数是否为数组 - bool isArray; - napi_is_array(env, args[0], &isArray); - if (!isArray) { - napi_throw_type_error(env, nullptr, "Argument must be an array"); - return nullptr; - } - napi_get_array_length(env, args[0], &length); - // 创建返回值 - napi_create_uint32(env, length, &result); - return result; -} -// [End napi_get_array_length] - -// [Start napi_is_array] -// 使用Node-API接口进行array相关开发 napi_is_array -static napi_value IsArray(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 调用napi_is_array接口判断给定入参是否为array数组 - bool result; - napi_status status = napi_is_array(env, args[0], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_is_array fail"); - return nullptr; - } - // 将结果转成napi_value类型返回 - napi_value returnValue; - napi_get_boolean(env, result, &returnValue); - - return returnValue; -} -// [End napi_is_array] - -// [Start napi_set_element] -// 使用Node-API接口进行array相关开发 napi_set_element -static napi_value NapiSetElement(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 3; - napi_value args[3] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 检查第一个参数是否为数组 - bool isArr = false; - napi_is_array(env, args[0], &isArr); - if (!isArr) { - napi_throw_type_error(env, nullptr, "Argument should be an object of type array"); - return nullptr; - } - // 获取要设置的元素索引 - double index = 0; - napi_get_value_double(env, args[1], &index); - // 将传入的值设置到数组指定索引位置 - napi_set_element(env, args[0], static_cast(index), args[INT_ARGS_2]); - - return nullptr; -} -// [End napi_set_element] - -// [Start napi_get_element] -// 使用Node-API接口进行array相关开发 napi_get_element -static napi_value NapiGetElement(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取请求元素的索引值 - uint32_t index; - napi_get_value_uint32(env, args[1], &index); - // 获取请求索引位置的元素值并存储在result中 - napi_value result; - napi_get_element(env, args[0], index, &result); - - return result; -} -// [End napi_get_element] - -// [Start napi_has_element] -// 使用Node-API接口进行array相关开发 napi_has_element -static napi_value NapiHasElement(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取要判断的元素的索引 - uint32_t index; - napi_get_value_uint32(env, args[1], &index); - // 判断指定索引位置的元素是否存在 - bool hasElement = true; - napi_has_element(env, args[0], index, &hasElement); - // 将bool结果转换为napi_value并返回 - napi_value result; - napi_get_boolean(env, hasElement, &result); - return result; -} -// [End napi_has_element] - -// [Start napi_delete_element] -// 使用Node-API接口进行array相关开发 napi_delete_element -static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取要删除的元素的索引 - uint32_t index; - napi_get_value_uint32(env, args[1], &index); - // 尝试删除请求索引位置的元素 - bool deleted = true; - napi_delete_element(env, args[0], index, &deleted); - // 将bool结果转换为napi_value并返回 - napi_value result; - napi_get_boolean(env, deleted, &result); - return result; -} -// [End napi_delete_element] - -// [Start napi_create_typed_array] -// 使用Node-API接口进行array相关开发 napi_create_typedarray -static napi_value CreateTypedArray(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - int32_t typeNum = 0; - napi_get_value_int32(env, args[0], &typeNum); - napi_typedarray_type arrayType; - // 用于存储每个元素的大小 - size_t elementSize = 0; - // 根据传递的类型值选择创建对应的类型数组 - arrayType = static_cast(typeNum); - switch (typeNum) { - case napi_int8_array: - case napi_uint8_array: - case napi_uint8_clamped_array: - elementSize = sizeof(int8_t); - break; - case napi_int16_array: - case napi_uint16_array: - elementSize = sizeof(int16_t); - break; - case napi_int32_array: - case napi_uint32_array: - elementSize = sizeof(int32_t); - break; - case napi_float32_array: - elementSize = sizeof(float); - break; - case napi_float64_array: - elementSize = sizeof(double); - break; - case napi_bigint64_array: - case napi_biguint64_array: - elementSize = sizeof(int64_t); - break; - default: - // 默认创建napi_int8_array类型 - arrayType = napi_int8_array; - elementSize = sizeof(int8_t); - break; - } - size_t length = 3; - napi_value arrayBuffer = nullptr; - napi_value typedArray = nullptr; - void *data; - // 创建一个ArrayBuffer - napi_create_arraybuffer(env, length * elementSize, (void **)&data, &arrayBuffer); - // 根据给定类型创建TypedArray - napi_create_typedarray(env, arrayType, length, arrayBuffer, 0, &typedArray); - return typedArray; -} -// [End napi_create_typed_array] - -// [Start napi_is_typed_array] -// 使用Node-API接口进行array相关开发 napi_is_typedarray -static napi_value IsTypedarray(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 调用napi_is_typedarray接口判断给定入参类型是否为TypedArray。 - bool result = false; - napi_status status = napi_is_typedarray(env, args[0], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_is_typedarray fail"); - return nullptr; - } - // 将结果转成napi_value类型返回。 - napi_value returnValue = nullptr; - napi_get_boolean(env, result, &returnValue); - - return returnValue; -} -// [End napi_is_typed_array] - -// [Start napi_get_typed_array_info] -// 使用Node-API接口进行array相关开发 napi_get_typedarray_info -static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数,第一个参数为需要获得的信息的TypedArray类型数据,第二个参数为需要获得的信息类型的枚举值 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将第二个参数转为int32类型便于比较 - int32_t infoTypeParam; - napi_get_value_int32(env, args[1], &infoTypeParam); - // 定义枚举类型与ArkTS侧枚举类型InfoType顺序含义一致 - enum InfoType { INFO_TYPE = 1, INFO_LENGTH, INFO_ARRAY_BUFFER, INFO_BYTE_OFFSET }; - void *data; - napi_typedarray_type type; - size_t byteOffset; - size_t length; - napi_value arraybuffer; - // 调用接口napi_get_typedarray_info获得TypedArray类型数据的信息 - napi_get_typedarray_info(env, args[0], &type, &length, &data, &arraybuffer, &byteOffset); - napi_value result; - // 根据属性名,返回TypedArray对应的属性值 - switch (infoTypeParam) { - case INFO_TYPE: - // 如果传入的参数是int8类型的TypedArray数据,它的类型(type)为napi_int8_array - napi_value int8_type; - napi_get_boolean(env, type == napi_int8_array, &int8_type); - result = int8_type; - break; - case INFO_LENGTH: - // TypedArray中的元素数 - napi_value napiLength; - napi_create_int32(env, length, &napiLength); - result = napiLength; - break; - case INFO_BYTE_OFFSET: - // TypedArray数组的第一个元素所在的基础原生数组中的字节偏移量 - napi_value napiByteOffset; - napi_create_int32(env, byteOffset, &napiByteOffset); - result = napiByteOffset; - break; - case INFO_ARRAY_BUFFER: - // TypedArray下的ArrayBuffer - result = arraybuffer; - break; - default: - break; - } - return result; -} -// [End napi_get_typed_array_info] - -// [Start napi_create_data_view] -// 使用Node-API接口进行array相关开发 napi_create_dataview -static napi_value CreateDataView(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_value arraybuffer = nullptr; - napi_value result = nullptr; - // DataView的字节长度 - size_t byteLength = 12; - // 字节偏移量 - size_t byteOffset = 4; - // 获取回调函数的参数信息 - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将参数转换为对象类型 - napi_coerce_to_object(env, args[0], &arraybuffer); - // 创建一个数据视图对象,并指定字节长度和字节偏移量 - napi_status status = napi_create_dataview(env, byteLength, arraybuffer, byteOffset, &result); - if (status != napi_ok) { - // 抛出创建DataView内容失败的错误 - napi_throw_error(env, nullptr, "Failed to create DataView"); - return nullptr; - } - // 获取DataView的指针和长度信息 - uint8_t *data = nullptr; - size_t length = 0; - napi_get_dataview_info(env, result, &length, (void **)&data, nullptr, nullptr); - // 为DataView赋值 - for (size_t i = 0; i < length; i++) { - data[i] = static_cast(i + 1); - } - return result; -} -// [End napi_create_data_view] - -// [Start napi_is_data_view] -// 使用Node-API接口进行array相关开发 napi_is_dataview -static napi_value IsDataView(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 调用napi_is_dataview接口判断给定入参是否为DataView数据。 - bool result; - napi_status status = napi_is_dataview(env, args[0], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_is_dataview fail"); - return nullptr; - } - // 将结果转成napi_value类型返回。 - napi_value returnValue; - napi_get_boolean(env, result, &returnValue); - - return returnValue; -} -// [End napi_is_data_view] - -// [Start napi_get_data_view_info] -// 使用Node-API接口进行array相关开发 napi_get_dataview_info -static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传入的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将第二个参数转为int32类型的数字 - int32_t infoType; - napi_get_value_int32(env, args[1], &infoType); - size_t byteLength; - void *data; - napi_value arrayBuffer; - size_t byteOffset; - // 定义枚举类型与ArkTS侧枚举类型InfoType顺序含义一致 - enum InfoType { BYTE_LENGTH = 0, ARRAY_BUFFER, BYTE_OFFSET }; - // 获取dataview信息 - napi_get_dataview_info(env, args[0], &byteLength, &data, &arrayBuffer, &byteOffset); - napi_value result; - switch (infoType) { - case BYTE_LENGTH: - // 返回查询DataView的字节数 - napi_value napiByteLength; - napi_create_int32(env, byteLength, &napiByteLength); - result = napiByteLength; - break; - case ARRAY_BUFFER: - // 返回查询DataView的arraybuffer - result = arrayBuffer; - break; - case BYTE_OFFSET: - // 返回查询DataView的偏移字节量 - napi_value napiByteOffset; - napi_create_int32(env, byteOffset, &napiByteOffset); - result = napiByteOffset; - break; - default: - break; - } - return result; -} -// [End napi_get_data_view_info] - -// [Start change_use_napi_process] -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_value typedArrayTypes; - napi_create_object(env, &typedArrayTypes); - napi_value typeIndex; - std::string typeKeys[] = { - "INT8_ARRAY", "UINT8_ARRAY", "UINT8_CLAMPED_ARRAY", "INT16_ARRAY", "UINT16_ARRAY", "INT32_ARRAY", - "UINT32_ARRAY", "FLOAT32_ARRAY", "FLOAT64_ARRAY", "BIGINT64_ARRAY", "BIGUINT64_ARRAY", - }; - for (int32_t i = 0; i < sizeof(typeKeys) / sizeof(typeKeys[0]); i++) { - napi_create_int32(env, i, &typeIndex); - napi_set_named_property(env, typedArrayTypes, typeKeys[i].c_str(), typeIndex); - } - napi_property_descriptor desc[] = { - {"createArray", nullptr, CreateArray, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createArrayWithLength", nullptr, CreateArrayWithLength, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getArrayLength", nullptr, GetArrayLength, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"isArray", nullptr, IsArray, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiSetElement", nullptr, NapiSetElement, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiGetElement", nullptr, NapiGetElement, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiHasElement", nullptr, NapiHasElement, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiDeleteElement", nullptr, NapiDeleteElement, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createTypedArray", nullptr, CreateTypedArray, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"TypedArrayTypes", nullptr, nullptr, nullptr, nullptr, typedArrayTypes, napi_default, nullptr}, - {"isTypedarray", nullptr, IsTypedarray, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getTypedarrayInfo", nullptr, GetTypedarrayInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createDataView", nullptr, CreateDataView, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"isDataView", nullptr, IsDataView, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getDataViewInfo", nullptr, GetDataViewInfo, nullptr, nullptr, nullptr, napi_default, nullptr}}; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} -EXTERN_C_END -// [End change_use_napi_process] - -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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 655f5726fddd983bb692c96b87b02df4a7b4572e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_create_array_api] -export const createArray: () => number[]; // 使用Node-API接口进行array相关开发 napi_create_array -// [End napi_create_array_api] - -// [Start napi_create_array_with_length_api] -export const createArrayWithLength: (length: number) => void[]; // 使用Node-API接口进行array相关开发 napi_create_array_with_length -// [End napi_create_array_with_length_api] - -// [Start napi_get_array_length_api] -export const getArrayLength: (arr: Array) => number | void; // 使用Node-API接口进行array相关开发 napi_get_array_length -// [End napi_get_array_length_api] - -// [Start napi_is_array_api] -export const isArray: (data: Array | T) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_array -// [End napi_is_array_api] - -// [Start napi_set_element_api] -export const napiSetElement: (arr: Array, index: number, - value: T) => void; // 使用Node-API接口进行array相关开发 napi_set_element -// [End napi_set_element_api] - -// [Start napi_get_element_api] -export const napiGetElement: (arr: Array, - index: number) => number | string | Object | boolean | undefined; // 使用Node-API接口进行array相关开发 napi_get_element -// [End napi_get_element_api] - -// [Start napi_has_element_api] -export const napiHasElement: (arr: Array, index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_has_element -// [End napi_has_element_api] - -// [Start napi_delete_element_api] -export const napiDeleteElement: (arr: Array, - index: number) => boolean; // 使用Node-API接口进行array相关开发 napi_delete_element -// [End napi_delete_element_api] - -// [Start napi_create_typed_array_api] -export const enum TypedArrayTypes { - INT8_ARRAY = 0, - UINT8_ARRAY, - UINT8_CLAMPED_ARRAY, - INT16_ARRAY, - UINT16_ARRAY, - INT32_ARRAY, - UINT32_ARRAY, - FLOAT32_ARRAY, - FLOAT64_ARRAY, - BIGINT64_ARRAY, - BIGuINT64_ARRAY, -} - -export const createTypedArray: (type: TypedArrayTypes) => T; // 使用Node-API接口进行array相关开发 napi_create_typedarray -// [End napi_create_typed_array_api] - -// [Start napi_is_typed_array_api] -export const isTypedarray: (data: Object) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_typedarray -// [End napi_is_typed_array_api] - -// [Start napi_get_typed_array_info_api] -export const getTypedarrayInfo: (typeArray: T, - infoType: number) => ArrayBuffer | number | boolean; // 使用Node-API接口进行array相关开发 napi_get_typedarray_info -// [End napi_get_typed_array_info_api] - -// [Start napi_create_data_view_api] -export const createDataView: (arraybuffer: ArrayBuffer) => DataView | void; // 使用Node-API接口进行array相关开发 napi_create_dataview -// [End napi_create_data_view_api] - -// [Start napi_is_data_view_api] -export const isDataView: (date: DataView | string) => boolean | void; // 使用Node-API接口进行array相关开发 napi_is_dataview -// [End napi_is_data_view_api] - -// [Start napi_get_data_view_info_api] -export const getDataViewInfo: (dataView: DataView, - infoType: number) => ArrayBuffer | number; // 使用Node-API接口进行array相关开发 napi_get_dataview_info -// [End napi_get_data_view_info_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index c85ea228c169b9174c1f1b01c83b27c7bd507a8f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,310 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiCreateArray', - '2.napiCreateArrayWithLength', - '3.napiGetArrayLength', - '4.napiIsArray', - '5.napiSetElement', - '6.napiGetElement', - '7.napiHasElement', - '8.napiDeleteElement', - '9.napiCreateTypedArray', - '10.napiIsTypedArray', - '11.napiGetTypedArrayInfo', - '12.napiCreateDataView', - '13.napiIsDataView', - '14.napiGetDataViewInfo' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(23) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 4 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiCreateArray') { - // [Start ark_napi_create_array] - //使用Node-API接口进行array相关开发 napi_create_array - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array:%{public}s', - JSON.stringify(testNapi.createArray())); - // [End ark_napi_create_array] - this.result = 'napiCreateArraySuccess'; - } else if (item === '2.napiCreateArrayWithLength') { - // [Start ark_napi_create_array_with_length] - // 使用Node-API接口进行array相关开发 napi_create_array_with_length - let array = testNapi.createArrayWithLength(6); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array_with_length:%{public}d', array.length); - // [End ark_napi_create_array_with_length] - this.result = 'napiCreateArrayWithLengthSuccess'; - } else if (item === '3.napiGetArrayLength') { - // [Start ark_napi_get_array_length] - // 使用Node-API接口进行array相关开发 napi_get_array_length - const arr = [0, 1, 2, 3, 4, 5]; - hilog.info(0x0000, 'testTag', 'Test Node-API get_array_length:%{public}d', - testNapi.getArrayLength(arr)); - // [End ark_napi_get_array_length] - this.result = 'napiGetArrayLengthSuccess'; - } else if (item === '4.napiIsArray') { - // [Start ark_napi_is_array] - // 使用Node-API接口进行array相关开发 napi_is_array - try { - let value = new Array(1); - let data = "123"; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_array: %{public}s', - testNapi.isArray(value)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_array: %{public}s', - testNapi.isArray(data)); - // [StartExclude ark_napi_is_array] - this.result = 'napiIsArraySuccess'; - // [EndExclude ark_napi_is_array] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_array error: %{public}s', error.message); - // [StartExclude ark_napi_is_array] - this.result = 'napiIsArrayFail'; - // [EndExclude ark_napi_is_array] - } - // [End ark_napi_is_array] - } else if (item === '5.napiSetElement') { - // [Start ark_napi_set_element] - // 使用Node-API接口进行array相关开发 napi_set_element - let arr = [10, 20, 30]; - testNapi.napiSetElement(arr, 1, 'newElement'); - testNapi.napiSetElement(arr, 2, 50); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr: %{public}s', arr.toString()); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[3]: %{public}s', arr[3]); - - interface MyObject { - first: number; - second: number; - } - - let obj: MyObject = { - first: 1, - second: 2 - }; - testNapi.napiSetElement(arr, 4, obj); - let objAsString = JSON.stringify(arr[4]); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[4]: %{public}s', objAsString); - // [End ark_napi_set_element] - this.result = 'napiSetElementSuccess'; - } else if (item === '6.napiGetElement') { - // [Start ark_napi_get_element] - // 使用Node-API接口进行array相关开发 napi_get_element - interface MyObject { - first: number; - second: number; - } - - let obj: MyObject = { - first: 1, - second: 2 - }; - let arr = [10, 'hello', null, obj]; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', - testNapi.napiGetElement(arr, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[1]: %{public}s', - testNapi.napiGetElement(arr, 1)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[2]: %{public}s', - testNapi.napiGetElement(arr, 2)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[3]: %{public}s', - testNapi.napiGetElement(arr, 3)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[4]: %{public}s', - JSON.stringify(testNapi.napiGetElement(arr, 4))); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[null]: %{public}s', - testNapi.napiGetElement(arr, 5)); - // [End ark_napi_get_element] - this.result = 'napiGetElementSuccess'; - } else if (item === '7.napiHasElement') { - // [Start ark_napi_has_element] - // 使用Node-API接口进行array相关开发 napi_has_element - let arr = [10, 'hello', null, 'world']; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', - testNapi.napiHasElement(arr, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[7]: %{public}s', - testNapi.napiHasElement(arr, 7)); - // [End ark_napi_has_element] - this.result = 'napiHasElementSuccess'; - } else if (item === '8.napiDeleteElement') { - // [Start ark_napi_delete_element] - // 使用Node-API接口进行array相关开发 napi_delete_element - let arr = [10, 'hello', null, 'world']; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', - testNapi.napiHasElement(arr, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_element arr[0]: %{public}s', - testNapi.napiDeleteElement(arr, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element deleted arr[0]: %{public}s', - testNapi.napiHasElement(arr, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', - testNapi.napiGetElement(arr, 0)); - // [End ark_napi_delete_element] - this.result = 'napiDeleteElementSuccess'; - } else if (item === '9.napiCreateTypedArray') { - // [Start ark_napi_create_typed_array] - // 使用Node-API接口进行array相关开发 napi_create_typedarray - let typedArray = testNapi.createTypedArray(testNapi.TypedArrayTypes["INT8_ARRAY"]); - if (typedArray instanceof Int8Array) { - hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Int8Array'); - // [StartExclude ark_napi_create_typed_array] - this.result = 'napiCreateInt8ArraySuccess'; - // [EndExclude ark_napi_create_typed_array] - } - let uint8Array = testNapi.createTypedArray(testNapi.TypedArrayTypes["UINT8_ARRAY"]); - if (uint8Array instanceof Uint8Array) { - hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Uint8Array'); - // [StartExclude ark_napi_create_typed_array] - this.result = 'napiCreateUint8ArraySuccess'; - // [EndExclude ark_napi_create_typed_array] - } - // [End ark_napi_create_typed_array] - } else if (item === '10.napiIsTypedArray') { - // [Start ark_napi_is_typed_array] - // 使用Node-API接口进行array相关开发 napi_is_typedarray - try { - let value = new Uint8Array([1, 2, 3, 4]); - let data = "123"; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_typedarray: %{public}s', - testNapi.isTypedarray(value)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_typedarray: %{public}s', - testNapi.isTypedarray(data)); - // [StartExclude ark_napi_is_typed_array] - this.result = 'napiIsTypedArraySuccess'; - // [EndExclude ark_napi_is_typed_array] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_typedarray error: %{public}s', error.message); - // [StartExclude ark_napi_is_typed_array] - this.result = 'napiIsTypedArrayFail'; - // [EndExclude ark_napi_is_typed_array] - } - // [End ark_napi_is_typed_array] - } else if (item === '11.napiGetTypedArrayInfo') { - // [Start ark_napi_get_typed_array_info] - // 使用Node-API接口进行array相关开发 napi_get_typedarray_info - // 传入TypedArray类型数据。TypedArray是一种用来描述二进制数据的类数组数据视图,没有直接构造器,可以用其子类构造类数组 - // TypedArray的子类有: Int8Array Uint8Array Uint8ClampedArray Int16Array Int32Array等 - let int8Array = new Int8Array([15, 7]); - // 定义枚举类型 这些都是TypedArray的属性 - enum InfoType { - TYPE = 1, // 传入的TypedArray的类型 - LENGTH = 2, // 传入的TypedArray的长度 - ARRAY_BUFFER = 3, // TypedArray下的ArrayBuffer - BYTE_OFFSET = 4 // 数组的第一个元素所在的基础原生数组中的字节偏移量 - }; - let arrbuff = testNapi.getTypedarrayInfo(int8Array, InfoType.ARRAY_BUFFER) as ArrayBuffer; - // 将arraybuffer转为数组 - let arr = new Array(new Int8Array(arrbuff)); - hilog.info(0x0000, 'Node-API', 'get_typedarray_info_arraybuffer: %{public}s', arr.toString()); - hilog.info(0x0000, 'Node-API', 'get_typedarray_info_isIn8Array: %{public}s', - testNapi.getTypedarrayInfo(int8Array, InfoType.TYPE).toString()); - hilog.info(0x0000, 'Node-API', 'get_typedarray_info_length: %{public}d', - testNapi.getTypedarrayInfo(int8Array, InfoType.LENGTH)); - hilog.info(0x0000, 'Node-API', 'get_typedarray_info_byte_offset: %{public}d', - testNapi.getTypedarrayInfo(int8Array, InfoType.BYTE_OFFSET)); - // [End ark_napi_get_typed_array_info] - this.result = 'napiGetTypedArrayInfoSuccess'; - } else if (item === '12.napiCreateDataView') { - // [Start ark_napi_create_data_view] - // 使用Node-API接口进行array相关开发 napi_create_dataview - const arrayBuffer = new ArrayBuffer(16); - const dataView = testNapi.createDataView(arrayBuffer) as DataView; - hilog.info(0x0000, 'testTag', 'Test Node-API dataView:%{public}d', dataView.byteLength); - hilog.info(0x0000, 'testTag', 'Test Node-API dataView第一个数据:%{public}d', dataView.getInt8(0)); - // [End ark_napi_create_data_view] - this.result = 'napiCreateDataViewSuccess'; - } else if (item === '13.napiIsDataView') { - // [Start ark_napi_is_data_view] - // 使用Node-API接口进行array相关开发 napi_is_dataview - try { - let buffer = new ArrayBuffer(16); - let dataView = new DataView(buffer); - let data = "123"; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_dataview: %{public}s', - testNapi.isDataView(dataView)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_dataview: %{public}s', - testNapi.isDataView(data)); - // [StartExclude ark_napi_is_data_view] - this.result = 'napiIsDataViewSuccess'; - // [EndExclude ark_napi_is_data_view] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_dataview error: %{public}s', error.message); - // [StartExclude ark_napi_is_data_view] - this.result = 'napiIsDataViewFail'; - // [EndExclude ark_napi_is_data_view] - } - // [End ark_napi_is_data_view] - } else if (item === '14.napiGetDataViewInfo') { - // [Start ark_napi_get_data_view_info] - // 使用Node-API接口进行array相关开发 napi_get_dataview_info - // 创建一个ArrayBuffer - let arrayBuffer = new Int8Array([2, 5]).buffer; - // 使用arrayBuffer创建一个dataView - let dataView = new DataView(arrayBuffer); - // 定义一个枚举类型 - enum InfoType { - BYTE_LENGTH = 0, - ARRAY_BUFFER = 1, - BYTE_OFFSET = 2, - }; - // 传入DataView类型参数查询DataView的字节数 - hilog.info(0x0000, 'Node-API', 'get_dataview_info_bytelength %{public}d', - testNapi.getDataViewInfo(dataView, InfoType.BYTE_LENGTH)); - // 传入DataView类型参数查询DataView的ArrayBuffer - let arrbuff = testNapi.getDataViewInfo(dataView, InfoType.ARRAY_BUFFER) as ArrayBuffer; - // 将arraybuffer转为数组 - let arr = Array.from(new Int8Array(arrbuff)); - hilog.info(0x0000, 'Node-API', 'get_dataview_info_arraybuffer %{public}s', arr.toString()); - // 传入DataView类型参数查询DataView开始投影的数据缓冲区中的字节偏移量 - hilog.info(0x0000, 'Node-API', 'get_dataview_info_byteoffset %{public}d', - testNapi.getDataViewInfo(dataView, InfoType.BYTE_OFFSET)); - // [End ark_napi_get_data_view_info] - this.result = 'napiGetDataViewInfoSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - .id('List') - } - .width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} - diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArray/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/ohosTest.md deleted file mode 100755 index a480dd668dd252454342096ba664ee09a07d0b0d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArray/ohosTest.md +++ /dev/null @@ -1,21 +0,0 @@ -# 使用Node-API进行array相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------ | ------------ | ----------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 createArray | 位于主页 | 点击文本为1.napiCreateArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateArraySuccess | Pass | -| ArkTS端成功调用native侧接口createArrayWithLength | 位于主页 | 点击文本为2.napiCreateArrayWithLength的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateArrayWithLengthSuccess | Pass | -| ArkTS端成功调用native侧接口getArrayLength | 位于主页 | 点击文本为3.napiGetArrayLength的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetArrayLengthSuccess | Pass | -| ArkTS端成功调用native侧接口isArray | 位于主页 | 点击文本为4.napiIsArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsArraySuccess | Pass | -| ArkTS端成功调用native侧接口napiSetElement | 位于主页 | 点击文本为5.napiSetElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetElementSuccess | Pass | -| ArkTS端成功调用native侧接口napiGetElement | 位于主页 | 点击文本为6.napiGetElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetElementSuccess | Pass | -| ArkTS端成功调用native侧接口napiHasElement | 位于主页 | 点击文本为7.napiHasElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasElementSuccess | Pass | -| ArkTS端成功调用native侧接口napiDeleteElement | 位于主页 | 点击文本为8.napiDeleteElement的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDeleteElementSuccess | Pass | -| ArkTS端成功调用native侧接口createTypedArray | 位于主页 | 点击文本为9.napiCreateTypedArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateUint8ArraySuccess | Pass | -| ArkTS端成功调用native侧接口isTypedarray | 位于主页 | 点击文本为10.napiIsTypedArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsTypedArraySuccess | Pass | -| ArkTS端成功调用native侧接口getTypedarrayInfo | 位于主页 | 点击文本为11.napiGetTypedArrayInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetTypedArrayInfoSuccess | Pass | -| ArkTS端成功调用native侧接口createDataView | 位于主页 | 点击文本为12.napiCreateDataView的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateDataViewSuccess | Pass | -| ArkTS端成功调用native侧接口isDataView | 位于主页 | 点击文本为13.napiIsDataView的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsDataViewSuccess | Pass | -| ArkTS端成功调用native侧接口getDataViewInfo | 位于主页 | 点击文本为14.napiGetDataViewInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetDataViewInfoSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/app.json5 deleted file mode 100755 index 68c6ac460037ead1d06ec2ae28d37713e0b002b9..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiarraybuffer", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/element/string.json deleted file mode 100755 index 1a06c8079db5c65169f0778b53a8c6c28addc978..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIArraybuffer" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/README.md deleted file mode 100755 index b8e56d852b0678dbefd00cddcd5f8c8adbf3499f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API接口进行ArrayBuffer相关开发 - -### 介绍 - -ArrayBuffer是ArkTS中的一种数据类型,用于表示通用的、固定长度的原始二进制数据缓冲区。它提供了一种在ArkTS中有效地表示和操作原始二进制数据的方式 - -该工程主要展示了使用Node-API接口进行检查值是否为ArrayBuffer、获取给定的ArrayBuffer对象信息、分离ArrayBuffer信息、判定是否分离ArrayBuffer以及创建指定长度的ArrayBuffer对象,其中展示的代码详细描述可查如下链接。 - -- [使用Node-API接口进行ArrayBuffer相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-arraybuffer.md) - -### 效果预览 - -| 首页 | 执行效果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIArraybuffer.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API接口进行Arraybuffer相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIArraybuffer.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 590b7279a293429b501d252646253991621f0018..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPI_arraybuffer) - -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_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -add_library(entry SHARED napi_init.cpp) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 0371f4cf45ce542e5c06667d3c23c934e80949ff..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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" - -// [Start napi_is_arraybuffer] -// napi_is_arraybuffer -static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) -{ - // 接受一个入参 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 调用napi_is_arraybuffer接口判断给定入参是否为ArrayBuffer数据 - bool result = false; - napi_status status = napi_is_arraybuffer(env, args[0], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_is_arraybuffer fail"); - return nullptr; - } - // 将结果转成napi_value类型返回 - napi_value returnValue = nullptr; - napi_get_boolean(env, result, &returnValue); - return returnValue; -} -// [End napi_is_arraybuffer] - -// [Start napi_get_arraybuffer_info] -// napi_get_arraybuffer_info -static napi_value GetArraybufferInfo(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 检查参数是否为ArrayBuffer - bool isArraybuffer = false; - napi_is_arraybuffer(env, args[0], &isArraybuffer); - if (!isArraybuffer) { - napi_throw_type_error(env, nullptr, "Argument must be an ArrayBuffer"); - return nullptr; - } - - void *data = nullptr; - size_t byteLength = 0; - // 获取ArrayBuffer的底层数据缓冲区和长度 - napi_status status = napi_get_arraybuffer_info(env, args[0], &data, &byteLength); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Failed to get ArrayBuffer info"); - return nullptr; - } - // 创建结果对象 - napi_value result = nullptr; - napi_create_object(env, &result); - // 创建数据缓冲区的字节长度属性 - napi_value byteLengthValue = nullptr; - napi_create_uint32(env, byteLength, &byteLengthValue); - napi_set_named_property(env, result, "byteLength", byteLengthValue); - napi_value bufferData; - napi_create_arraybuffer(env, byteLength, &data, &bufferData); - napi_set_named_property(env, result, "buffer", bufferData); - return result; -} -// [End napi_get_arraybuffer_info] - -// [Start napi_detach_arraybuffer] -// napi_detach_arraybuffer -static napi_value DetachedArraybuffer(napi_env env, napi_callback_info info) -{ - // 调用napi_detach_arraybuffer接口分离给定ArrayBuffer的底层数据 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_value arrayBuffer = args[0]; - napi_detach_arraybuffer(env, arrayBuffer); - // 将分离后的arraybuffer传出去 - return arrayBuffer; -} - -// napi_is_detach_arraybuffer -static napi_value IsDetachedArraybuffer(napi_env env, napi_callback_info info) -{ - // 调用napi_is_detached_arraybuffer判断给定的arraybuffer是否已被分离 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_value arrayBuffer = args[0]; - bool result = false; - napi_is_detached_arraybuffer(env, arrayBuffer, &result); - // 将返回值通过napi_get_boolean接口转成napi_value传出去做打印 - napi_value returnValue; - napi_get_boolean(env, result, &returnValue); - return returnValue; -} -// [End napi_detach_arraybuffer] - -// [Start napi_create_arraybuffer] -// napi_create_arraybuffer -static napi_value CreateArraybuffer(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_value result = nullptr; - // 解析传递的参数 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - int32_t value; - size_t length; - // 将ArkTS侧传递的参数转换为size_t类型,作为napi_create_arraybuffer的参数 - napi_get_value_int32(env, argv[0], &value); - length = size_t(value); - void *data; - // 创建一个新的ArrayBuffer - napi_create_arraybuffer(env, length, &data, &result); - if (data != nullptr) { - // 确保安全后才能使用data进行操作 - } - // 返回ArrayBuffer - return result; -} -// [End napi_create_arraybuffer] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"isArrayBuffer", nullptr, IsArrayBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getArraybufferInfo", nullptr, GetArraybufferInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"detachedArraybuffer", nullptr, DetachedArraybuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"isDetachedArraybuffer", nullptr, IsDetachedArraybuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createArraybuffer", nullptr, CreateArraybuffer, 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 3bcabf7866b12bc1291c2c8e68259966208b6934..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_is_arraybuffer_api] -export const isArrayBuffer: (arrayBuffer: T) => boolean | void; // napi_is_arraybuffer -// [End napi_is_arraybuffer_api] - -// [Start napi_get_arraybuffer_info_api] -export class ArrayBufferInfo { - byteLength: number; - buffer: Object; -} - -export const getArraybufferInfo: (data: ArrayBuffer) => ArrayBufferInfo | void; // napi_get_arraybuffer_info -// [End napi_get_arraybuffer_info_api] - -// [Start napi_detach_arraybuffer_api] -export const detachedArraybuffer: (buffer: ArrayBuffer) => ArrayBuffer; // napi_detach_arraybuffer - -export const isDetachedArraybuffer: (arrarBeffer: ArrayBuffer) => boolean; //napi_is_detached_arraybuffer -// [End napi_detach_arraybuffer_api] - -// [Start napi_create_arraybuffer_api] -export const createArraybuffer: (size: number) => ArrayBuffer; // napi_create_arraybuffer -// [End napi_create_arraybuffer_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 3b51abe806f5354d26375c1dbdcc9786614870d8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiIsArraybuffer', - '2.napiGetArraybufferInfo', - '3.napiDetachArraybuffer', - '4.napiCreateArraybuffer' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(25) - .fontWeight(FontWeight.Bold) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiIsArraybuffer') { - // [Start ark_napi_is_arraybuffer] - // napi_is_arraybuffer - try { - let value = new ArrayBuffer(1); - let data = "123"; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer: %{public}s', - testNapi.isArrayBuffer(value)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer: %{public}s', - testNapi.isArrayBuffer(data)); - // [StartExclude ark_napi_is_arraybuffer] - this.result = 'napiIsArraybufferSuccess'; - // [EndExclude ark_napi_is_arraybuffer] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer error: %{public}s', - error.message); - // [StartExclude ark_napi_is_arraybuffer] - this.result = 'napiIsArraybufferFail'; - // [EndExclude ark_napi_is_arraybuffer] - } - // [End ark_napi_is_arraybuffer] - } else if (item === '2.napiGetArraybufferInfo') { - // [Start ark_napi_get_arraybuffer_info - // napi_get_arraybuffer_info - const buffer = new ArrayBuffer(10); - hilog.info(0x0000, 'testTag', 'Test Node-API get_arraybuffer_info:%{public}s ', - JSON.stringify(testNapi.getArraybufferInfo(buffer))); - // [End ark_napi_get_arraybuffer_info] - this.result = 'napiGetArraybufferInfoSuccess'; - } else if (item === '3.napiDetachArraybuffer') { - // [Start ark_napi_detach_arraybuffer] - // napi_detach_arraybuffer and napi_is_detached_arraybuffer - try { - const bufferArray = new ArrayBuffer(8); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer one: %{public}s', - testNapi.isDetachedArraybuffer(bufferArray)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer two: %{public}s ', - testNapi.isDetachedArraybuffer(testNapi.detachedArraybuffer(bufferArray))); - // [StartExclude ark_napi_detach_arraybuffer] - this.result = 'napiDetachArraybufferSuccess'; - // [EndExclude ark_napi_detach_arraybuffer] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer error: %{public}s', - error.message); - // [StartExclude ark_napi_detach_arraybuffer] - this.result = 'napiDetachArraybufferFail'; - // [EndExclude ark_napi_detach_arraybuffer] - } - // [End ark_napi_detach_arraybuffer] - } else if (item === '4.napiCreateArraybuffer') { - // [Start ark_napi_create_arraybuffer] - // napi_create_arraybuffer - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_arraybuffer:%{public}s', - testNapi.createArraybuffer(10).toString()); - // [End ark_napi_create_arraybuffer] - this.result = 'napiCreateArraybufferSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - } - .width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIArraybuffer/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/ohosTest.md deleted file mode 100755 index db3693318a49cc002f04036e6e28963fa1ccea55..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIArraybuffer/ohosTest.md +++ /dev/null @@ -1,11 +0,0 @@ -# 使用Node-API进行arraybuffer相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------ | ------------ | -------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口isArrayBuffer | 位于主页 | 点击文本为1.napiIsArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsArraybufferSuccess | Pass | -| ArkTS端成功调用native侧接口getArraybufferInfo | 位于主页 | 点击文本为2.napiGetArraybufferInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetArraybufferInfoSuccess | Pass | -| ArkTS端成功调用native侧接口isDetachedArraybuffer | 位于主页 | 点击文本为3.napiDetachArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDetachArraybufferSuccess | Pass | -| ArkTS端成功调用native侧接口createArraybuffer | 位于主页 | 点击文本为4.napiCreateArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateArraybufferSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/app.json5 deleted file mode 100755 index 4a5324e5298ad016a45e3ae87213389a1b767fa2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapibasicdatatypes", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/element/string.json deleted file mode 100755 index a5255df568e0f7ae5a6f48c1c2da68a6aaf10c85..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIBasicDataTypes" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/README.md deleted file mode 100755 index cfec2108aad7f7361d62a7a2478fa9b194bd15cd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API进行basic_data_types相关开发 - -### 介绍 - -ArkTS的Number类型是一个双精度64位二进制格式IEEE 754值。只有在-2^53+1到2^53-1范围内(闭区间)的整数才能在不丢失精度的情况下被表示,在超过该取值范围的情况下,需要使用BigInt对应的NPI接口来处理更大范围的整数。 - -该工程主要展示了使用Node-API接口将number类型转换为uint32、int32、int64、double以及前述四种类型转换回number类型,其中展示的代码详细描述可查如下链接。 - -- [使用Node-API进行basic_data_types相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-basic-data-types.md) - -### 效果预览 - -| 首页 | 执行效果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIBasicDataTypes.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API接口进行basic_data_types相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIBasicDataTypes.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 6ea17b5242b0d81cab320659ce9ba6bb7e386c15..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIBasicDataTypes) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index e752683274f9874834d213a1ed4bd58aa24398b2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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" - -// [Start napi_get_value_uint32] -// napi_get_value_uint32 -static napi_value GetValueUint32(napi_env env, napi_callback_info info) -{ - // 获取传入的数字类型参数 - size_t argc = 1; - napi_value argv[1] = {nullptr}; - // 解析传入的参数 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - uint32_t number = 0; - // 获取传入参数的值中的无符号32位整数 - napi_status status = napi_get_value_uint32(env, argv[0], &number); - // 如果传递的参数不是数字,将会返回napi_number_expected,设置函数返回nullptr - if (status == napi_number_expected) { - return nullptr; - } - napi_value result = nullptr; - // 创建传入参数无符号32位整数,并传出 - napi_create_uint32(env, number, &result); - return result; -} -// [End napi_get_value_uint32] - -// [Start napi_get_value_int32] -// napi_get_value_int32 -static napi_value GetValueInt32(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - int32_t result32 = 0; - // 解析传递的参数 - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将前端传过来的参数转为Node-API模块的int32类型 - napi_status status = napi_get_value_int32(env, args[0], &result32); - // 如果传递的参数不是数字napi_get_value_int32接口将会返回napi_number_expected,设置函数返回nullptr - if (status == napi_number_expected) { - return nullptr; - } - // 调用napi_create_int32接口将int32类型的数据转为napi_value返回 - napi_value napiResult32 = nullptr; - napi_create_int32(env, result32, &napiResult32); - return napiResult32; -} -// [End napi_get_value_int32] - -// [Start napi_get_value_int64] -// napi_get_value_int64 -static napi_value GetValueInt64(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - int64_t result64 = 0; - // 解析传递的值 - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将前端传过来的参数转为Node-API模块的int64类型 - napi_status status = napi_get_value_int64(env, args[0], &result64); - // 如果传递的参数不是数字, 返回napi_number_expected. - if (status == napi_number_expected) { - return nullptr; - } - // 调用napi_create_int64接口将int64类型的数据转为napi_value返回前端 - napi_value napiResult64 = nullptr; - napi_create_int64(env, result64, &napiResult64); - return napiResult64; -} -// [End napi_get_value_int64] - -// [Start napi_get_value_double] -// napi_get_value_double -static napi_value GetDouble(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - double value = 0; - napi_status status = napi_get_value_double(env, args[0], &value); - // 传入非数字接口返回napi_number_expected - if (status == napi_number_expected) { - return nullptr; - } - napi_value result = nullptr; - napi_create_double(env, value, &result); - return result; -} -// [End napi_get_value_double] - -// [Start napi_create_int32] -// napi_create_int32 -static napi_value CreateInt32(napi_env env, napi_callback_info info) -{ - // int32_t是有符号的32位整数类型,表示带有符号的整数,它的范围是从-2^31到2^31 - 1,也就是-2147483648到2147483647 - // 要表示的整数值 - int32_t value = -26; - // 创建ArkTS中的int32数字 - napi_value result = nullptr; - napi_status status = napi_create_int32(env, value, &result); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Failed to create int32 value"); - } - return result; -} -// [End napi_create_int32] - -// [Start napi_create_uint32] -// napi_create_uint32 -static napi_value CreateUInt32(napi_env env, napi_callback_info info) -{ - // 如果使用 - // uint32_t类型来定义-26,会发生溢出,溢出时会对结果进行模运算,将负数的二进制补码转换为相应的正数。-26输出4294967270 - // uint32_t是无符号的32位整数类型,只能表示非负整数。它的范围是从0到2 ^32 - 1,即0到4294967295 - // 要表示的整数值 - uint32_t value = 26; - // 创建ArkTS中的uint32数字 - napi_value result = nullptr; - napi_status status = napi_create_uint32(env, value, &result); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Failed to create uint32 value"); - } - return result; -} -// [End napi_create_uint32] - -// [Start napi_create_int64] -// napi_create_int64 -static napi_value CreateInt64(napi_env env, napi_callback_info info) -{ - // int64是有符号的64位整数类型,可以表示范围从-2^63到2^63 - 1的整数,即 -9223372036854775808到9223372036854775807 - // 要表示的整数值 - int64_t value = 2147483648; - // 创建ArkTS中的int64数字 - napi_value result = nullptr; - napi_status status = napi_create_int64(env, value, &result); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Failed to create int64 value"); - } - return result; -} -// [End napi_create_int64] - -// [Start napi_create_double] -// napi_create_double -static napi_value CreateDouble(napi_env env, napi_callback_info info) -{ - double value = 1.234; - // 创建ArkTS中的double数字 - napi_value result = nullptr; - napi_status status = napi_create_double(env, value, &result); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Failed to create double value"); - } - return result; -} -// [End napi_create_double] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getValueUint32", nullptr, GetValueUint32, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueInt32", nullptr, GetValueInt32, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueInt64", nullptr, GetValueInt64, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getDouble", nullptr, GetDouble, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createInt32", nullptr, CreateInt32, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createUInt32", nullptr, CreateUInt32, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createInt64", nullptr, CreateInt64, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createDouble", nullptr, CreateDouble, 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 1901dd8f17bf869c5e3357e4cbac52b5fbffebed..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_get_value_uint32_api] -export const getValueUint32: (data: T) => number | void; // napi_get_value_uint32 -// [End napi_get_value_uint32_api] - -// [Start napi_get_value_int32_api] -export const getValueInt32: (value: number | string) => number | void; // napi_get_value_int32 -// [End napi_get_value_int32_api] - -// [Start napi_get_value_int64_api] -export const getValueInt64: (value: number | string) => number | void; // napi_get_value_int64 -// [End napi_get_value_int64_api] - -// [Start napi_get_value_double_api] -export const getDouble: (value: number | string) => number | void; // napi_get_value_double -// [End napi_get_value_double_api] - -// [Start napi_create_int32_api] -export const createInt32: () => number; // napi_create_int32 -// [End napi_create_int32_api] - -// [Start napi_create_uint32_api] -export const createUInt32: () => number; // napi_create_uint32 -// [End napi_create_uint32_api] - -// [Start napi_create_int64_api] -export const createInt64: () => number; // napi_create_int64 -// [End napi_create_int64_api] - -// [Start napi_create_double_api] -export const createDouble: () => number; // napi_create_double -// [End napi_create_double_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 20023e52c93bdf946ccd234b71fc3af77213ccb4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiGetValueUint32', - '2.napiGetValueInt32', - '3.napiGetValueInt64', - '4.napiGetValueDouble', - '5.napiCreateInt32', - '6.napiCreateUint32', - '7.napiCreateInt64', - '8.napiCreateDouble' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(25) - .fontWeight(FontWeight.Bold) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiGetValueUint32') { - // [Start ark_napi_get_value_uint32] - // napi_get_value_uint32 - let value = testNapi.getValueUint32(111111111111); - let data = testNapi.getValueUint32("sssss"); - hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', value); - // 传入非数字"sssss"时函数返回undefined - hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}s', data); - // 传入uint32范围内的数字100时函数返回原数字 - hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', - testNapi.getValueUint32(100)); - // [End ark_napi_get_value_uint32] - this.result = 'napiGetValueUint32Success'; - } else if (item === '2.napiGetValueInt32') { - // [Start ark_napi_get_value_int32] - // napi_get_value_int32 - // 传入非数字“ss”时函数返回undefined - hilog.info(0x0000, 'Node-API', 'get_value_int32_not_number %{public}s', testNapi.getValueInt32('ss')); - // 传入int32范围内的数字100时函数返回原数字 - hilog.info(0x0000, 'Node-API', 'get_value_int32_number %{public}d', testNapi.getValueInt32(100)); - // 传入68719476735,此数字的二进制为111111111111111111111111111111111111,在int32类型中此二进制代表数字-1 - hilog.info(0x0000, 'Node-API', 'get_value_int32_oversize %{public}d', - testNapi.getValueInt32(68719476735)); - // 大于2的31次-1的数字且不是二进制为111111111111111111111111111111111111这样的在int32中有特殊含义的数字也会溢出,导致数值发生改变,返回值按后32位二进制编码解码 - hilog.info(0x0000, 'Node-API', 'get_value_int32_oversize %{public}d', - testNapi.getValueInt32(687194767355)); - // 传入NAN(not a number)、+Infinity(正无穷)或-Infinity(负无穷),会返回数字0 - hilog.info(0x0000, 'Node-API', 'get_value_int32_number_NAN %{public}d', testNapi.getValueInt32(NaN)); - hilog.info(0x0000, 'Node-API', 'get_value_int32_number_+Infinity %{public}d', - testNapi.getValueInt32(+Infinity)); - hilog.info(0x0000, 'Node-API', 'get_value_int32_number_-Infinity %{public}d', - testNapi.getValueInt32(-Infinity)); - // [End ark_napi_get_value_int32] - this.result = 'napiGetValueInt32Success'; - } else if (item === '3.napiGetValueInt64') { - // [Start ark_napi_get_value_int64] - // napi_get_value_int64 - // 输入不超过int64表示范围的数字,会返回该数字 - hilog.info(0x0000, 'Node-API', 'get_value_int64_number %{public}d', testNapi.getValueInt64(80)); - // 传入非数字“ss”,获得函数返回的值应为undefined - hilog.info(0x0000, 'Node-API', 'get_value_int64_not_number %{public}s', - testNapi.getValueInt64('sAs')); - // 输入超过int64表示范围的数字会溢出,失去精度,导致输入数字与返回数字不相等 - hilog.info(0x0000, 'Node-API', 'get_value_int64_number_oversize %{public}d', - testNapi.getValueInt64(9223372036854775809)); - // 传入NAN(not a number)、+Infinity(正无穷)或-Infinity(负无穷)接口返回数字0 - hilog.info(0x0000, 'Node-API', 'get_value_int64_number_NAN %{public}d', testNapi.getValueInt64(NaN)); - hilog.info(0x0000, 'Node-API', 'get_value_int64_number_+Infinity %{public}d', - testNapi.getValueInt64(+Infinity)); - hilog.info(0x0000, 'Node-API', 'get_value_int64_number_-Infinity %{public}d', - testNapi.getValueInt64(-Infinity)); - // [End ark_napi_get_value_int64] - this.result = 'napiGetValueInt64Success'; - } else if (item === '4.napiGetValueDouble') { - // [Start ark_napi_get_value_double] - // napi_get_value_double - // 输入数字,返回该数字 - hilog.info(0x0000, 'Node-API', 'get_value_double_number %{public}d', testNapi.getDouble(80.885)); - // 传入非数字,获得函数返回的值应为undefined - hilog.info(0x0000, 'Node-API', 'get_value_double_not_number %{public}s', testNapi.getDouble('sAs')); - // [End ark_napi_get_value_double] - this.result = 'napiGetValueDoubleSuccess'; - } else if (item === '5.napiCreateInt32') { - // [Start ark_napi_create_int32] - // napi_create_int32 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int32:' + testNapi.createInt32()); - // [End ark_napi_create_int32] - this.result = 'napiCreateInt32Success'; - } else if (item === '6.napiCreateUint32') { - // [Start ark_napi_create_uint32] - // napi_create_uint32 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_uint32: ' + testNapi.createUInt32()); - // [End ark_napi_create_uint32] - this.result = 'napiCreateUint32Success'; - } else if (item === '7.napiCreateInt64') { - // [Start ark_napi_create_int64] - // napi_create_int64 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_int64: ' + testNapi.createInt64()); - // [End ark_napi_create_int64] - this.result = 'napiCreateInt64Success'; - } else if (item === '8.napiCreateDouble') { - // [Start ark_napi_create_double] - // napi_create_double - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_double: ' + testNapi.createDouble()); - // [End ark_napi_create_double] - this.result = 'napiCreateDoubleSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - } - .width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/ohosTest.md deleted file mode 100755 index 3adc3c6a077b53bbc4533f4409cc8f40bf118caf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBasicDataTypes/ohosTest.md +++ /dev/null @@ -1,15 +0,0 @@ -# 使用Node-API进行basic_data_types相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ----------------------------------------- | ------------ | ---------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口getValueUint32 | 位于主页 | 点击文本为1.napiGetValueUint32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueUint32Success | Pass | -| ArkTS端成功调用native侧接口getValueInt32 | 位于主页 | 点击文本为2.napiGetValueInt32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueInt32Success | Pass | -| ArkTS端成功调用native侧接口getValueInt64 | 位于主页 | 点击文本为3.napiGetValueInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueInt64Success | Pass | -| ArkTS端成功调用native侧接口getDouble | 位于主页 | 点击文本为4.napiGetValueDouble的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueDoubleSuccess | Pass | -| ArkTS端成功调用native侧接口createInt32 | 位于主页 | 点击文本为5.napiCreateInt32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateInt32Success | Pass | -| ArkTS端成功调用native侧接口createUInt32 | 位于主页 | 点击文本为6.napiCreateUint32的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateUint32Success | Pass | -| ArkTS端成功调用native侧接口createInt64 | 位于主页 | 点击文本为7.napiCreateInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateInt64Success | Pass | -| ArkTS端成功调用native侧接口createDouble | 位于主页 | 点击文本为8.napiCreateDouble的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateDoubleSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/app.json5 deleted file mode 100755 index eee9280a089a84b876b2775363fad1afec00d624..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapibigint", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/element/string.json deleted file mode 100755 index 104c90557364917d47b8cc5721fda337268387e0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIBigint" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/README.md deleted file mode 100755 index 9d5ca289257ce088f34cdc5dce299275d63dca8b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API进行bigint相关开发 - -### 介绍 - -BigInt是ArkTS中用于表示任意精度整数的数据类型,它能够处理比Number类型更大范围的整数值。通过Node-API提供的接口,可以在Node-API模块中创建、获取和操作BigInt类型值,从而实现与BigInt相关的功能扩展。 - -该工程主要展示使用Node-API创建中展示使用int64、uint64类型和给定字节数的uint64创建BigInt对象等场景。其中代码详细描述可查如下链接。 - -- [使用Node-API进行bigint相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-bigint.md) - -### 效果预览 - -| 执行结果图 | | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIBigint.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行bigint相关开发 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIBigint.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9b135d06f6782f8a460f880bedabd2c0cd82a90e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIBigint) - -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_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -add_library(entry SHARED napi_init.cpp) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 0dc16e8bebe36cb06e4246d118b02851783dd24a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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" - -// [Start napi_create_bigint_int64] -// napi_create_bigint_int64 -static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) -{ - // 声明int64_t的变量value - int64_t value = -5555555555555555555; - // 将value转化为napi_value类型返回 - napi_value returnValue = nullptr; - napi_create_bigint_int64(env, value, &returnValue); - return returnValue; -} -// [End napi_create_bigint_int64] - -// [Start napi_create_bigint_uint64] -// napi_create_bigint_uint64 -static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) -{ - // 声明uint64_t的变量value - uint64_t value = 5555555555555555555; - // 将value转化为napi_value类型返回 - napi_value returnValue = nullptr; - napi_create_bigint_uint64(env, value, &returnValue); - return returnValue; -} -// [End napi_create_bigint_uint64] - -// [Start napi_create_bigint_words] -// napi_create_bigint_words -static napi_value CreateBigintWords(napi_env env, napi_callback_info info) -{ - // 使用napi_create_bigint_words接口创建一个BigInt对象 - int signBit = 0; - size_t wordCount = 3; - uint64_t words[] = {12ULL, 34ULL, 56ULL}; - napi_value returnValue = nullptr; - napi_status status = napi_create_bigint_words(env, signBit, wordCount, words, &returnValue); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_create_bigint_words fail"); - return nullptr; - } - return returnValue; -} -// [End napi_create_bigint_words] - -// [Start napi_get_value_bigint_int64] -// napi_get_value_bigint_int64 -static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 从传入的参数中提取64位整数的BigInt数据 - int64_t value = 0; - bool lossLess = false; - napi_status status = napi_get_value_bigint_int64(env, args[0], &value, &lossLess); - // 判断从ArkTS侧获取bigint是否为无损转换,如果不是抛出异常 - if (!lossLess) { - napi_throw_error(env, nullptr, "BigInt values have not been lossless converted"); - return nullptr; - } - // 如果接口调用成功正常调用则返回true给ArkTS侧 - napi_value returnValue = nullptr; - napi_get_boolean(env, status == napi_ok, &returnValue); - return returnValue; -} -// [End napi_get_value_bigint_int64] - -// [Start napi_get_value_bigint_uint64] -// napi_get_value_bigint_uint64 -static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 从参数值中获取BigInt的数值 - uint64_t value = 0; - bool lossLess = false; - napi_status status = napi_get_value_bigint_uint64(env, args[0], &value, &lossLess); - // 判断从ArkTS侧获取bigint是否为无损转换,如果不是抛出异常 - if (!lossLess) { - napi_throw_error(env, nullptr, "BigInt values have no lossless converted"); - return nullptr; - } - // 如果接口调用成功正常调用则返回true给ArkTS侧 - napi_value returnValue = nullptr; - napi_get_boolean(env, status == napi_ok, &returnValue); - return returnValue; -} -// [End napi_get_value_bigint_uint64] - -// [Start napi_get_value_bigint_words] -// napi_get_value_bigint_words -static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - int signBit = 0; - size_t wordCount = 0; - uint64_t words = 0; - // 调用napi_get_value_bigint_words接口获取wordCount - napi_status status = napi_get_value_bigint_words(env, args[0], nullptr, &wordCount, nullptr); - OH_LOG_INFO(LOG_APP, "Node-API , wordCount:%{public}d.", wordCount); - // 调用napi_get_value_bigint_words接口获取传入bigInt相关信息,如:signBit传入bigInt正负信息 - status = napi_get_value_bigint_words(env, args[0], &signBit, &wordCount, &words); - OH_LOG_INFO(LOG_APP, "Node-API , signBit: %{public}d.", signBit); - if (status != napi_ok) { - OH_LOG_ERROR(LOG_APP, "Node-API , reason:%{public}d.", status); - napi_throw_error(env, nullptr, "napi_get_date_value fail"); - return nullptr; - } - // 将符号位转化为int类型传出去 - napi_value returnValue = nullptr; - napi_create_int32(env, signBit, &returnValue); - return returnValue; -} -// [End napi_get_value_bigint_words] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"createBigintInt64t", nullptr, CreateBigintInt64t, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createBigintUint64t", nullptr, CreateBigintUint64t, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createBigintWords", nullptr, CreateBigintWords, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueBigintInt64t", nullptr, GetValueBigintInt64t, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueBigintUint64t", nullptr, GetValueBigintUint64t, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueBigintWords", nullptr, GetValueBigintWords, 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 9a160cff4e70a20d2556da8fe782d46ade730bde..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_create_bigint_int64_api] -export const createBigintInt64t: () => bigint; // napi_create_bigint_int64 -// [End napi_create_bigint_int64_api] - -// [Start napi_create_bigint_uint64_api] -export const createBigintUint64t: () => bigint; // napi_create_bigint_uint64 -// [End napi_create_bigint_uint64_api] - -// [Start napi_create_bigint_words_api] -export const createBigintWords: () => bigint | void; // napi_create_bigint_words -// [End napi_create_bigint_words_api] - -// [Start napi_get_value_bigint_int64_api] -export const getValueBigintInt64t: (bigInt64: bigint) => boolean | void; // napi_get_value_bigint_int64 -// [End napi_get_value_bigint_int64_api] - -// [Start napi_get_value_bigint_uint64_api] -export const getValueBigintUint64t: (bigUint64: bigint) => boolean | void; // napi_get_value_bigint_uint64 -// [End napi_get_value_bigint_uint64_api] - -// [Start napi_get_value_bigint_words_api] -export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; // napi_get_value_bigint_words -// [End napi_get_value_bigint_words_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 2da3dcf00cba72d736c8097bf2f17383edcd0fa4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,149 +0,0 @@ -/* - * 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'; - - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiCreateBigintInt64', - '2.napiCreateBigintUint64', - '3.napiCreateBigintWords', - '4.napiGetValueBigintInt64', - '5.napiGetValueBigintUint64', - '6.napiGetValueBigintWords' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(22) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiCreateBigintInt64') { - // [Start ark_napi_create_bigint_int64] - // napi_create_bigint_int64 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_int64: %{public}d', - testNapi.createBigintInt64t()); - // [End ark_napi_create_bigint_int64] - this.result = 'napiCreateBigintInt64Success'; - } else if (item === '2.napiCreateBigintUint64') { - // [Start ark_napi_create_bigint_uint64] - // napi_create_bigint_uint64 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_uint64: %{public}d', - testNapi.createBigintUint64t()); - // [End ark_napi_create_bigint_uint64] - this.result = 'napiCreateBigintUint64Success'; - } else if (item === '3.napiCreateBigintWords') { - // [Start ark_napi_create_bigint_words] - // napi_create_bigint_words - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_words: %{public}d', - testNapi.createBigintWords()); - // [StartExclude ark_napi_create_bigint_words] - this.result = 'napiCreateBigintWordsSuccess'; - // [EndExclude ark_napi_create_bigint_words] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); - // [StartExclude ark_napi_create_bigint_words] - this.result = 'napiCreateBigintWordsFail'; - // [EndExclude ark_napi_create_bigint_words] - } - // [End ark_napi_create_bigint_words] - } else if (item === '4.napiGetValueBigintInt64') { - // [Start ark_napi_get_value_bigint_int64] - // napi_get_value_bigint_int64 - let bigInt = BigInt(-5555555555555555); - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_int64: %{public}s', - JSON.stringify(testNapi.getValueBigintInt64t(bigInt))); - // [StartExclude ark_napi_get_value_bigint_int64] - this.result = 'napiGetValueBigintInt64Success'; - // [EndExclude ark_napi_get_value_bigint_int64] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); - // [StartExclude ark_napi_get_value_bigint_int64] - this.result = 'napiGetValueBigintInt64Fail'; - // [EndExclude ark_napi_get_value_bigint_int64] - } - // [End ark_napi_get_value_bigint_int64] - } else if (item === '5.napiGetValueBigintUint64') { - // [Start ark_napi_get_value_bigint_uint64] - // napi_get_value_bigint_uint64 - let bigUint = BigInt(5555555555555555); - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_uint64: %{public}s', - JSON.stringify(testNapi.getValueBigintUint64t(bigUint))); - // [StartExclude ark_napi_get_value_bigint_uint64] - this.result = 'napiGetValueBigintUint64Success'; - // [EndExclude ark_napi_get_value_bigint_uint64] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); - // [StartExclude ark_napi_get_value_bigint_uint64] - this.result = 'napiGetValueBigintUint64Fail'; - // [EndExclude ark_napi_get_value_bigint_uint64] - } - // [End ark_napi_get_value_bigint_uint64] - } else if (item === '6.napiGetValueBigintWords') { - // [Start ark_napi_get_value_bigint_words] - // napi_get_value_bigint_words - let bigInt = BigInt(-5555555555555555); - let bigUint = BigInt(5555555555555555); - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', - testNapi.getValueBigintWords(bigInt)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_value_bigint_words signBit is: %{public}d', - testNapi.getValueBigintWords(bigUint)); - // [StartExclude ark_napi_get_value_bigint_words] - this.result = 'napiGetValueBigintWordsSuccess'; - // [EndExclude ark_napi_get_value_bigint_words] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); - // [StartExclude ark_napi_get_value_bigint_words] - this.result = 'napiGetValueBigintWordsFail'; - // [EndExclude ark_napi_get_value_bigint_words] - } - // [End ark_napi_get_value_bigint_words] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBigint/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/ohosTest.md deleted file mode 100755 index b1dd34f4cf8300bad9c9bb9b29caed116952e259..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBigint/ohosTest.md +++ /dev/null @@ -1,13 +0,0 @@ -# 使用Node-API进行bigInt相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------ | ------------ | ---------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口createBigintInt64t | 位于主页 | 点击文本为1.napiCreateBigintInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBigintInt64Success | Pass | -| ArkTS端成功调用native侧接口createBigintUint64t | 位于主页 | 点击文本为2.napiCreateBigintUint64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBigintUint64Success | Pass | -| ArkTS端成功调用native侧接口createBigintWords | 位于主页 | 点击文本为3.napiCreateBigintWords的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBigintWordsSuccess | Pass | -| ArkTS端成功调用native侧接口getValueBigintInt64t | 位于主页 | 点击文本为4.napiGetValueBigintInt64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBigintInt64Success | Pass | -| ArkTS端成功调用native侧接口getValueBigintUint64t | 位于主页 | 点击文本为5.napiGetValueBigintUint64的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBigintUint64Success | Pass | -| ArkTS端成功调用native侧接口getValueBigintWords | 位于主页 | 点击文本为6.napiGetValueBigintWords的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBigintWordsSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/app.json5 deleted file mode 100755 index 010dd71fa486bf020b3e2aac95c888273a933793..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapibuffer", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/element/string.json deleted file mode 100755 index 501ac3971c678a165fb0e9780cc3aaf1975f3a37..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIBuffer" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/README.md deleted file mode 100755 index 8e7882c890ab3321708a226737bf494c44ede7f6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API进行buffer相关开发 - -### 介绍 - -在ArkTS中,Buffer是一种用于处理二进制数据的数据类型,使用Node-API接口进行buffer相关开发时,使用Buffer对象与ArkTS代码之间进行二进制数据的有效交互,以便在Node-API模块创建、操纵和传递Buffer对象到ArkTS,从而处理和传递二进制数据,比如文件I/O、网络传输等。 - -该工程主要展示了使用Node-API进行创建指定大小ArkTS Buffer、创建并获取指定大小ArkTS Buffer、判断给定value是否为Buffer对象等功能场景,其中代码详细描述可查如下链接。 - -- [使用Node-API进行buffer相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-buffer.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIBuffer.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API接口进行array相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIBuffer.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 428a5b0714149c38cf5a3a1fec7560d8ee86b501..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIBuffer) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 34ae2cfb87f75f0fc0b1ad5b0265c1c625ccca79..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 -#include "hilog/log.h" -#include "napi/native_api.h" - -static constexpr int INT_ARG_5 = 5; // 入参索引 - -// napi_create_buffer -static napi_value CreateBuffer(napi_env env, napi_callback_info info) -{ - std::string str("CreateBuffer"); - void *bufferPtr = nullptr; - size_t bufferSize = str.size(); - napi_value buffer = nullptr; - // 调用napi_create_buffer接口创建并获取一个指定大小的ArkTS Buffer - napi_create_buffer(env, bufferSize, &bufferPtr, &buffer); - // 将字符串str的值复制到buffer的内存中 - strcpy((char *)bufferPtr, str.data()); - return buffer; -} - -// napi_create_buffer_copy -static napi_value CreateBufferCopy(napi_env env, napi_callback_info info) -{ - // 要copy的内容 - std::string str("CreateBufferCopy"); - napi_value buffer = nullptr; - // 调用napi_create_buffer_copy接口创建buffer并将str的内容copy到buffer - void *resultData = nullptr; - napi_create_buffer_copy(env, str.size(), str.data(), &resultData, &buffer); - OH_LOG_INFO(LOG_APP, "Node-API resultData is : %{public}s.", resultData); - return buffer; -} - -// 回调函数,用于释放内存 -void FinalizeCallback(napi_env env, void *data, void *hint) -{ - if (data == nullptr) { - return; - } - free(data); - data = nullptr; -} - -// napi_create_external_buffer -static napi_value CreateExternalBuffer(napi_env env, napi_callback_info info) -{ - // 创建一个字符串 - std::string str("CreateExternalBuffer"); - // 在堆上分配内存,大小为字符串的长度 - void *data = malloc(str.size()); - // 将字符串复制到分配的内存中 - strcpy(static_cast(data), str.data()); - // 使用napi_create_external_buffer接口创建并获取一个指定大小buffer - napi_value buffer = nullptr; - napi_create_external_buffer(env, str.size(), data, FinalizeCallback, nullptr, &buffer); - return buffer; -} - -// napi_get_buffer_info -static napi_value GetBufferInfo(napi_env env, napi_callback_info info) -{ - // 创建一个字符串 - std::string str("GetBufferInfo"); - napi_value buffer = nullptr; - void *bufferPtr = nullptr; - size_t bufferSize = str.size(); - napi_create_buffer(env, bufferSize, &bufferPtr, &buffer); - strcpy((char *)bufferPtr, str.data()); - - // 获取Buffer的信息 - void *tmpBufferPtr = nullptr; - size_t bufferLength = 0; - napi_get_buffer_info(env, buffer, &tmpBufferPtr, &bufferLength); - - // 创建一个新的ArkTS字符串来保存Buffer的内容并返出去 - napi_value returnValue = nullptr; - napi_create_string_utf8(env, (char *)tmpBufferPtr, bufferLength, &returnValue); - return returnValue; -} - -// napi_is_buffer -static napi_value IsBuffer(napi_env env, napi_callback_info info) -{ - // 创建一个Buffer对象 - std::string str = "buffer"; - napi_value buffer = nullptr; - napi_create_buffer(env, strlen(str.data()), (void **)(str.data()), &buffer); - - // 调用napi_is_buffer接口判断创建的对象是否为buffer - bool result = false; - napi_is_buffer(env, buffer, &result); - // 将结果返回出去 - napi_value returnValue = nullptr; - napi_get_boolean(env, result, &returnValue); - return returnValue; -} - -typedef struct { - uint8_t *data; - size_t length; -} BufferData; - -void FinalizeCallback1(napi_env env, void *finalizeData, void *finalizeHint) -{ - // 获取终结时的数据 - BufferData *bufferData = static_cast(finalizeData); - - // 执行清理操作,比如释放资源 - delete[] bufferData->data; - delete bufferData; -} - -// napi_create_external_arraybuffer -napi_value CreateExternalArraybuffer(napi_env env, napi_callback_info info) -{ - // 创建一个有五个元素的C++数组 - uint8_t *dataArray = new uint8_t[5]{1, 2, 3, 4, 5}; - napi_value externalBuffer = nullptr; - BufferData *bufferData = new BufferData{dataArray, 5}; - - // 使用napi_create_external_arraybuffer创建一个外部Array Buffer对象,并指定终结回调函数 - napi_status status = - napi_create_external_arraybuffer(env, dataArray, 5, FinalizeCallback1, bufferData, &externalBuffer); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Node-API napi_create_external_arraybuffer fail"); - return nullptr; - } - napi_value outputArray; - // 使用napi_create_typedarray创建一个Array对象,并将externalBuffer对象作为参数传入 - status = napi_create_typedarray(env, napi_int8_array, INT_ARG_5, externalBuffer, 0, &outputArray); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Node-API napi_create_typedarray fail"); - return nullptr; - } - return outputArray; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"createBuffer", nullptr, CreateBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createBufferCopy", nullptr, CreateBufferCopy, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createExternalBuffer", nullptr, CreateExternalBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getBufferInfo", nullptr, GetBufferInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"isBuffer", nullptr, IsBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createExternalArraybuffer", nullptr, CreateExternalArraybuffer, 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index e7e49a697667638b1a60e025ed64a9db943de8b6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 createBuffer: () => string; // napi_create_buffer - -export const createBufferCopy: () => string; // napi_create_buffer_copy - -export const createExternalBuffer: () => string; // napi_create_external_buffer - -export const getBufferInfo: () => string; // napi_get_buffer_info - -export const isBuffer: () => boolean; // napi_is_buffer - -export const createExternalArraybuffer: () => ArrayBuffer | void; // napi_create_external_arraybuffer \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 9841b4ca2a36cfd0d1adf3a46acdeb10c2e16a67..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiCreateBuffer', - '2.napiCreateBufferCopy', - '3.napiCreateExternalBuffer', - '4.napiGetBufferInfo', - '5.napiIsBuffer', - '6.napiCreateExternalArraybuffer' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiCreateBuffer') { - // napi_create_buffer - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_buffer: %{public}s', - testNapi.createBuffer().toString()); - this.result = 'napiCreateBufferSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_buffer error'); - this.result = 'napiCreateBufferFail'; - } - } else if (item === '2.napiCreateBufferCopy') { - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_buffer_copy: %{public}s', - testNapi.createBufferCopy().toString()); - this.result = 'napiCreateBufferCopySuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_buffer_copy error'); - this.result = 'napiCreateBufferCopyFail'; - } - } else if (item === '3.napiCreateExternalBuffer') { - // napi_create_external_buffer - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_external_buffer: %{public}s', - testNapi.createExternalBuffer() - .toString()); - this.result = 'napiCreateExternalBufferSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_external_buffer error'); - this.result = 'napiCreateExternalBufferFail'; - } - } else if (item === '4.napiGetBufferInfo') { - // napi_get_buffer_info - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_buffer_info: %{public}s', - testNapi.getBufferInfo().toString()); - this.result = 'napiGetBufferInfoSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_buffer_info error'); - this.result = 'napiGetBufferInfoFail'; - } - } else if (item === '5.napiIsBuffer') { - // napi_is_buffer - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_buffer: %{public}s', - JSON.stringify(testNapi.isBuffer())); - this.result = 'napiIsBufferSuccess'; - } catch (error) { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_buffer error'); - this.result = 'napiIsBufferFail'; - } - } else if (item === '6.napiCreateExternalArraybuffer') { - // napi_create_external_arraybuffer - hilog.info(0x0000, 'testTag', 'Node-API createExternalArraybuffer: %{public}s', - JSON.stringify(testNapi.createExternalArraybuffer())); - this.result = 'napiCreateExternalArraybufferSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - } - .width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIBuffer/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/ohosTest.md deleted file mode 100755 index 3d51411013024ae52d8040430da4a2c1c9f4faa4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIBuffer/ohosTest.md +++ /dev/null @@ -1,12 +0,0 @@ -# 使用Node-API进行buffer相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ---------------------------------------------------- | ------------ | --------------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口createBuffer | 位于主页 | 点击文本为1.napiCreateBuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateBufferSuccess | Pass | -| ArkTS端成功调用native侧接口createExternalBuffer | 位于主页 | 点击文本为2.napiCreateExternalBuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateExternalBufferSuccess | Pass | -| ArkTS端成功调用native侧接口getBufferInfo | 位于主页 | 点击文本为3.napiGetBufferInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetBufferInfoSuccess | Pass | -| ArkTS端成功调用native侧接口isBuffer | 位于主页 | 点击文本为4.napiIsBuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsBufferSuccess | Pass | -| ArkTS端成功调用native侧接口createExternalArraybuffer | 位于主页 | 点击文本为5.napiCreateExternalArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateExternalArraybufferSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/app.json5 deleted file mode 100755 index f13a0fe4e97d3d17b2a1e9520ecf7876f4467257..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiclass", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/element/string.json deleted file mode 100755 index cfcf2c9cd884b074b978798fb74154717b8c2e9a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIClass" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/README.md deleted file mode 100755 index 862d45ca29f3a9d5ac17ea48087b164d85da6db0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行class相关开发 - -### 介绍 - -该工程主要展示了使用Node-API接口进行class相关开发,处理ArkTS中的类,例如定义类、构造实例等,其中代码详细描述可查如下链接。 - -- [使用Node-API进行class相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-class.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIClass.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行class相关开发 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIClass.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIClass/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 53c02323519057d254c7996915f4951c2e00ad1f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIClass) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 22f52d776fdf54e196c50fdda0816331708d6541..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 -#include -#include "napi/native_api.h" - -static constexpr int INT_ARG_18 = 18; // 入参索引 - -// [Start napi_new_instance] -// napi_new_instance -static napi_value NewInstance(napi_env env, napi_callback_info info) -{ - // 传入并解析参数,第一个参数为传入的构造函数,第二个参数为需要传入构造函数的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 调用napi_new_instance接口,实例化一个对象,将这个对象返回 - napi_value result = nullptr; - napi_new_instance(env, args[0], 1, &args[1], &result); - return result; -} -// [End napi_new_instance] - -// [Start napi_wrap_unwrap_remove_wrap] -struct Object { - std::string name; - int32_t age; -}; - -static void DerefItem(napi_env env, void *data, void *hint) -{ - // 可选的原生回调,用于在ArkTS对象被垃圾回收时释放原生实例 - OH_LOG_INFO(LOG_APP, "Node-API DerefItem"); - (void)hint; -} - -// napi_wrap -static napi_value Wrap(napi_env env, napi_callback_info info) -{ - OH_LOG_INFO(LOG_APP, "Node-API wrap"); - // 初始化Node-API模块的object - struct Object *obj = new struct Object(); - obj->name = "lilei"; - obj->age = INT_ARG_18; - size_t argc = 1; - napi_value toWrap; - // 调用napi_wrap将Node-API模块的object绑定到ArkTS object上 - napi_get_cb_info(env, info, &argc, &toWrap, NULL, NULL); - napi_wrap(env, toWrap, reinterpret_cast(obj), DerefItem, NULL, NULL); - - return toWrap; -} - -// napi_remove_wrap -static napi_value RemoveWrap(napi_env env, napi_callback_info info) -{ - OH_LOG_INFO(LOG_APP, "Node-API removeWrap"); - size_t argc = 1; - napi_value wrapped = nullptr; - void *data = nullptr; - // 调用napi_remove_wrap从一个被包装的对象中解除包装 - napi_get_cb_info(env, info, &argc, &wrapped, nullptr, nullptr); - napi_remove_wrap(env, wrapped, &data); - - return nullptr; -} - -// napi_unwrap -static napi_value UnWrap(napi_env env, napi_callback_info info) -{ - OH_LOG_INFO(LOG_APP, "Node-API unWrap"); - size_t argc = 1; - napi_value wrapped = nullptr; - napi_get_cb_info(env, info, &argc, &wrapped, nullptr, nullptr); - // 调用napi_unwrap取出绑定在ArkTS object中的数据并打印 - struct Object *data; - napi_unwrap(env, wrapped, reinterpret_cast(&data)); - OH_LOG_INFO(LOG_APP, "Node-API name: %{public}s", data->name.c_str()); - OH_LOG_INFO(LOG_APP, "Node-API age: %{public}d", data->age); - return nullptr; -} -// [End napi_wrap_unwrap_remove_wrap] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"newInstance", nullptr, NewInstance, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"wrap", nullptr, Wrap, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"removeWrap", nullptr, RemoveWrap, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"unWrap", nullptr, UnWrap, 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 9e0e5aa76de9946bc3dd33a0dfe55fd720debdae..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_new_instance_api] -export const newInstance: (obj: Object, param: string) => Object // napi_new_instance -// [End napi_new_instance_api] - -// [Start napi_wrap_unwrap_remove_wrap_api] -export const wrap: (obj: Object) => Object; // napi_wrap - -export const unWrap: (obj: Object) => void; // napi_unwrap - -export const removeWrap: (obj: Object) => void; // napi_remove_wrap -// [End napi_wrap_unwrap_remove_wrap_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index c3092dc54e1ef5f757bfc8e33bfbc259c3abd752..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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'; - -// [Start ark_napi_new_instance] -class Fruit { - name: string; - - constructor(name: string) { - this.name = name; - } -} - -// [StartExclude ark_napi_new_instance] -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiNewInstance', - '2.napiRemoveWrap' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(25) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiNewInstance') { - // [EndExclude ark_napi_new_instance] - // napi_new_instance - // 调用函数,用变量obj接收函数返回的实例化对象 - let obj = testNapi.newInstance(Fruit, 'test'); - // 打印实例化对象obj的信息 - hilog.info(0x0000, 'Node-API', 'napi_new_instance %{public}s', JSON.stringify(obj)); - // [End ark_napi_new_instance] - this.result = 'napiNewInstanceSuccess'; - } else if (item === '2.napiRemoveWrap') { - // [Start ark_napi_wrap_unwrap_remove_wrap] - try { - class Obj { - } - - let obj: Obj = {}; - testNapi.wrap(obj) // napi_wrap - testNapi.unWrap(obj) // napi_unwrap - testNapi.removeWrap(obj) // napi_remove_wrap - // [StartExclude ark_napi_wrap_unwrap_remove_wrap] - this.result = 'napiRemoveWrapSuccess'; - // [EndExclude ark_napi_wrap_unwrap_remove_wrap] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API error: %{public}s', error.message); - // [StartExclude ark_napi_wrap_unwrap_remove_wrap] - this.result = 'napiRemoveWrapFail'; - // [EndExclude ark_napi_wrap_unwrap_remove_wrap] - } - // [End ark_napi_wrap_unwrap_remove_wrap] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIClass/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/ohosTest.md deleted file mode 100755 index 3342c2311d13c18d1269877532a2d972feb888ce..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIClass/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 使用Node-API进行class相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------- | ------------ | ------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口newInstance | 位于主页 | 点击文本为1.napiNewInstance的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiNewInstanceSuccess | Pass | -| ArkTS端成功调用native侧接口wrap,unWrap,removeWrap | 位于主页 | 点击文本为2.napiRemoveWrap的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveWrapSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/app.json5 deleted file mode 100755 index fcea5f34a3de7b56d185c1de555735e7e40e248a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapicleanuphook", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/element/string.json deleted file mode 100755 index fd2b8858545272ab9f3ab56471403341070af3eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPICleanuphook" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/README.md deleted file mode 100755 index 82af9b29e419a5d58e55b210ebce864d40e5424c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API进行cleanuphook相关开发 - -### 介绍 - -使用Node-API接口在进程退出时处理未释放资源,在Node-API模块注册清理钩子,一旦当前环境退出,这些钩子就会运行,使所有资源都被正确释放。 - -本工程主要展示了使用Node-API注册钩子函数、取消钩子函数等场景,其中代码详细描述可查如下链接。 - -- [使用Node-API进行cleanuphook相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-cleanuphook.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPICleanuphook.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行cleanuphook相关开发 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPICleanuphook.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/build-profile.json5 deleted file mode 100755 index 63f7a6918b834e2650374c760ab8a7d3104f21e0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/build-profile.json5 +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - }, - "sourceOption": { - "workers": [ - "./src/main/ets/workers/worker.ts" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 796387181d9dc6a3a0d1318782fe7d6d2fd39f23..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPICleanuphook) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libuv.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 0d5588f21e2dbe152501dc27e5826b1c49bab53b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_remove_add_env_cleanup_hook] -#include -#include -#include -#include "napi/native_api.h" -#include "uv.h" - -// 定义内存结构,包含指向数据的指针和数据的大小 -typedef struct { - char *data; - size_t size; -} Memory; - -// 外部缓冲区清理回调函数,用于释放分配的内存 -void ExternalFinalize(napi_env env, void *finalizeData, void *finalizeHint) -{ - Memory *wrapper = (Memory *)finalizeHint; - // [StartExclude napi_remove_add_env_cleanup_hook] - if (wrapper == nullptr) { - //处理内存分配失败的情况 - return; - } - // [EndExclude napi_remove_add_env_cleanup_hook] - free(wrapper->data); - free(wrapper); - OH_LOG_INFO(LOG_APP, "Node-API napi_add_env_cleanup_hook ExternalFinalize"); -} - -// 在环境关闭时执行一些清理操作,如清理全局变量或其他需要在环境关闭时处理的资源 -static void Cleanup(void *arg) -{ - // 执行清理操作 - OH_LOG_INFO(LOG_APP, "Node-API napi_add_env_cleanup_hook cleanuped: %{public}d", *(int *)(arg)); -} - -// 创建外部缓冲区并注册环境清理钩子函数 -static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) -{ - // 分配内存并复制字符串数据到内存中 - std::string str("Hello from Node-API!"); - Memory *wrapper = (Memory *)malloc(sizeof(Memory)); - // [StartExclude napi_remove_add_env_cleanup_hook] - if (wrapper == nullptr) { - //处理内存分配失败的情况 - return nullptr; - } - // [End napi_remove_add_env_cleanup_hook] - wrapper->data = static_cast(malloc(str.size())); - strcpy(wrapper->data, str.c_str()); - wrapper->size = str.size(); - // 创建外部缓冲区对象,并指定清理回调函数 - napi_value buffer = nullptr; - napi_create_external_buffer(env, wrapper->size, (void *)wrapper->data, ExternalFinalize, wrapper, &buffer); - // 静态变量作为钩子函数参数 - static int hookArg = 42; - static int hookParameter = 1; - // 注册环境清理钩子函数 - napi_status status = napi_add_env_cleanup_hook(env, Cleanup, &hookArg); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Test Node-API napi_add_env_cleanup_hook failed."); - return nullptr; - } - // 注册环境清理钩子函数,此处不移除环境清理钩子,为了在Java环境被销毁时,这个钩子函数被调用,用来模拟执行一些清理操作,例如释放资源、关闭文件等。 - status = napi_add_env_cleanup_hook(env, Cleanup, &hookParameter); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Test Node-API napi_add_env_cleanup_hook failed."); - return nullptr; - } - // 立即移除环境清理钩子函数,确保不会在后续环境清理时被调用 - // 通常,当为其添加此钩子的资源无论如何都被拆除时调用这个接口 - napi_remove_env_cleanup_hook(env, Cleanup, &hookArg); - // 返回创建的外部缓冲区对象 - return buffer; -} -// [End napi_remove_add_env_cleanup_hook] - -// [Start napi_add_remove_async_cleanup_hook] -typedef struct { - napi_env env; - void *testData; - uv_async_s asyncUv; - napi_async_cleanup_hook_handle cleanupHandle; -} AsyncContent; - -// 删除异步工作对象并注销钩子函数 -static void FinalizeWork(uv_handle_s *handle) -{ - AsyncContent *asyncData = reinterpret_cast(handle->data); - // 不再需要异步清理钩子函数的情况下,尝试将其从环境中移除 - napi_status result = napi_remove_async_cleanup_hook(asyncData->cleanupHandle); - if (result != napi_ok) { - napi_throw_error(asyncData->env, nullptr, "Test Node-API napi_remove_async_cleanup_hook failed"); - } - // 释放AsyncContent - free(asyncData); -} - -// 异步执行环境清理工作 -static void AsyncWork(uv_async_s *async) -{ - // 执行一些清理工作,比如释放动态分配的内存 - AsyncContent *asyncData = reinterpret_cast(async->data); - if (asyncData->testData != nullptr) { - free(asyncData->testData); - asyncData->testData = nullptr; - } - // 关闭libuv句柄,并触发FinalizeWork回调清理 - uv_close((uv_handle_s *)async, FinalizeWork); -} - -// 异步清理钩子函数,创建异步工作对象并执行 -static void AsyncCleanup(napi_async_cleanup_hook_handle handle, void *info) -{ - AsyncContent *data = reinterpret_cast(info); - // 获取libUv循环实例并初始化一个异步句柄,以便后续执行异步工作 - uv_loop_s *uvLoop; - napi_get_uv_event_loop(data->env, &uvLoop); - uv_async_init(uvLoop, &data->asyncUv, AsyncWork); - - data->asyncUv.data = data; - data->cleanupHandle = handle; - // 发送异步信号触发AsyncWork函数执行清理工作 - uv_async_send(&data->asyncUv); -} - -static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) -{ - // 分配AsyncContent内存 - AsyncContent *data = reinterpret_cast(malloc(sizeof(AsyncContent))); - // StartExclude napi_add_remove_async_cleanup_hook] - if (data == nullptr) { - //处理内存分配失败的情况 - return nullptr; - } - // [EndExclude napi_add_remove_async_cleanup_hook] - data->env = env; - data->cleanupHandle = nullptr; - // 分配内存并复制字符串数据 - const char *testDataStr = "TestNapiAsyncCleanUpHook"; - data->testData = strdup(testDataStr); - if (data->testData == nullptr) { - napi_throw_error(env, nullptr, "Test Node-API data->testData is nullptr"); - } - // 添加异步清理钩子函数 - napi_status status = napi_add_async_cleanup_hook(env, AsyncCleanup, data, &data->cleanupHandle); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Test Node-API napi_add_async_cleanup_hook failed"); - } - napi_value result = nullptr; - napi_get_boolean(env, true, &result); - return result; -} -// [End napi_add_remove_async_cleanup_hook] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"napiEnvCleanUpHook", nullptr, NapiEnvCleanUpHook, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiAsyncCleanUpHook", nullptr, NapiAsyncCleanUpHook, 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index b48f7cfd466f8f5e34d86a59e05f5460583af8bd..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_remove_add_env_cleanup_hook_api] -export const napiEnvCleanUpHook: () => Object | void; -// [End napi_remove_add_env_cleanup_hook_api] - -// [Start napi_add_remove_async_cleanup_hook_api] -export const napiAsyncCleanUpHook: () => boolean | void; -// [End napi_add_remove_async_cleanup_hook_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 6b502b025668f190e817b190f1b240b3991498b4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import worker from '@ohos.worker'; -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State result: string = ''; - private items: string[] = [ - 'Reset Result Message', - '1.napiRemoveEnvCleanupHook', - '2.napiRemoveAsyncCleanupHook' - ]; - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiRemoveEnvCleanupHook') { - // [Start connect_with_worker] - let wk = new worker.ThreadWorker('entry/ets/workers/worker.ts'); - // 发送消息到worker线程 - wk.postMessage('test NapiEnvCleanUpHook'); - // 处理来自worker线程的消息 - wk.onmessage = (message) => { - hilog.info(0x0000, 'testTag', 'Test Node-API message from worker: %{public}s', - JSON.stringify(message)); - wk.terminate(); - }; - // [End connect_with_worker] - this.result = 'napiRemoveEnvCleanupHookSuccess'; - } else if (item === '2.napiRemoveAsyncCleanupHook') { - // [Start ark_napi_remove_add_env_cleanup_hook] - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook: %{public}s', - testNapi.napiAsyncCleanUpHook()); - // [StartExclude ark_napi_remove_add_env_cleanup_hook] - this.result = 'napiRemoveAsyncCleanupHookSuccess'; - // [EndExclude ark_napi_remove_add_env_cleanup_hook] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_add_async_cleanup_hook error.message: %{public}s', - error.message); - // [StartExclude ark_napi_remove_add_env_cleanup_hook] - this.result = 'napiRemoveAsyncCleanupHookFail'; - // [EndExclude ark_napi_remove_add_env_cleanup_hook] - } - // [End ark_napi_remove_add_env_cleanup_hook] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - } - .width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPICleanuphook/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/ohosTest.md deleted file mode 100755 index 48166fa83a2c28c9225e38d9b59432f0aa55cbcf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPICleanuphook/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 使用Node-API进行cleanuphook相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ----------------------------------------------- | ------------ | ------------------------------------------------ | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口napiEnvCleanUpHook | 位于主页 | 点击文本为1.napiRemoveEnvCleanupHook的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveEnvCleanupHookSuccess | Pass | -| ArkTS端成功调用native侧接口napiAsyncCleanUpHook | 位于主页 | 点击文本为2.napiRemoveAsyncCleanupHook的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveAsyncCleanupHookSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/app.json5 deleted file mode 100755 index 2ca6010d5615031b7c806c1a5e727b39d1017725..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapidate", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/element/string.json deleted file mode 100755 index 022111c88cde7eb5d7ea36f9e120fd2a0dbf2ece..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIDate" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/README.md deleted file mode 100755 index ee3554ee0f6e5ea152f2807bd19d388323130019..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行Date相关开发 - -### 介绍 - -Node-API中date相关接口用于处理ArkTS Date对象,并在Node-API模块和ArkTS代码之间进行日期数据的转换和处理。这对于在Node-API模块中处理时间和日期相关逻辑非常有用,工程中展示的代码详细描述可查如下链接。 - -- [使用Node-API进行Date相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-date.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIDate.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行Date相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIDate.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIDate/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 2da23c8ff43fa49e56fac58edfa7e825b3fd3844..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIDate) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index f4fc6dc4926ddf520cc70ff22c601d496f3698d3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_create_date] -#include -#include "napi/native_api.h" - -// napi_create_date -static napi_value CreateDate(napi_env env, napi_callback_info info) -{ - // 获取传入的Unix Time Stamp时间 - double value = 1501924876711; - // 调用napi_create_date接口将double值转换成表示日期时间,并创建成一个ArkTS对象放入returnValue中 - napi_value returnValue = nullptr; - napi_create_date(env, value, &returnValue); - return returnValue; -} -// [End napi_create_date] - -// [Start napi_get_date_value] -// napi_get_date_value -static napi_value GetDateValue(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取传入的Unix Time Stamp时间 - double value = 0; - napi_status status = napi_get_date_value(env, args[0], &value); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_get_date_value fail"); - return nullptr; - } - - // 将获取到的Unix Time Stamp时间打印 - OH_LOG_INFO(LOG_APP, "Node-API gets unix time stamp is:%{public}lf.", value); - - // 把转换后的Unix Time Stamp时间创建成ArkTS double数值,并放入returnValue中 - napi_value returnValue = nullptr; - napi_create_double(env, value, &returnValue); - return returnValue; -} -// [End napi_get_date_value] - -// [Start napi_is_date] -// napi_is_date -static napi_value IsDate(napi_env env, napi_callback_info info) -{ - // 接受一个入参 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 调用napi_is_date接口判断给定入参是否为Date数据 - bool result = false; - napi_status status = napi_is_date(env, args[0], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_is_date fail"); - return nullptr; - } - // 将结果转成napi_value类型返回 - napi_value returnValue = nullptr; - napi_get_boolean(env, result, &returnValue); - - return returnValue; -} -// [End napi_is_date] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"createDate", nullptr, CreateDate, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getDateValue", nullptr, GetDateValue, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"isDate", nullptr, IsDate, 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8492f673288d7b15cfa02aa7134b9aca9866c4c2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_create_date_api] -export const createDate: () => Date; // napi_create_date -// [End napi_create_date_api] - -// [Start napi_get_date_value_api] -export const getDateValue: (date: Date) => number | void; // napi_get_date_value -// [End napi_get_date_value_api] - -// [Start napi_is_date_api] -export const isDate: (date: T) => boolean | void; // napi_is_date -// [End napi_is_date_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index ef8032c3650b9ede7bfe73d4a8329d20a3521a71..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiCreateDate', - '2.napiGetDateValue', - '3.napiIsDate' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(25) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiCreateDate') { - // [Start ark_napi_create_date] - // napi_create_date - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_date: %{public}s', - testNapi.createDate().toString()); - // [End ark_napi_create_date] - this.result = 'napiCreateDateSuccess'; - } else if (item === '2.napiGetDateValue') { - // [Start ark_napi_get_date_value] - // napi_get_date_value - try { - const date = new Date(); - hilog.info(0x0000, 'testTag', 'Node-API: output the Unix Time Stamp: %{public}d', date.getTime()); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_date_value: %{public}d', - testNapi.getDateValue(date)); - // [StartExclude ark_napi_get_date_value] - this.result = 'napiGetDateValueSuccess'; - // [EndExclude ark_napi_get_date_value] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_date_value error: %{public}s', - error.message); - // [StartExclude ark_napi_get_date_value] - this.result = 'napiGetDateValueFail'; - // [EndExclude ark_napi_get_date_value] - } - // [End ark_napi_get_date_value] - } else if (item === '3.napiIsDate') { - // [Start ark_napi_is_date] - // napi_is_date - try { - let now: Date = new Date(); - let date = "123"; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(now)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_date: %{public}s', testNapi.isDate(date)); - // [StartExclude ark_napi_is_date] - this.result = 'napiIsDateSuccess'; - // [EndExclude ark_napi_is_date] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_date error: %{public}s', error.message); - // [StartExclude ark_napi_is_date] - this.result = 'napiIsDateFail'; - // [EndExclude ark_napi_is_date] - } - // [End ark_napi_is_date] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIDate/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/ohosTest.md deleted file mode 100755 index e9f4a92c4a960d7fe5dea28febeb6b1da1b6f22c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIDate/ohosTest.md +++ /dev/null @@ -1,10 +0,0 @@ -# 使用Node-API进行date相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| --------------------------------------- | ------------ | -------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口createDate | 位于主页 | 点击文本为1.napiCreateDate的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateDateSuccess | Pass | -| ArkTS端成功调用native侧接口getDateValue | 位于主页 | 点击文本为2.napiGetDateValue的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetDateValueSuccess | Pass | -| ArkTS端成功调用native侧接口isDate | 位于主页 | 点击文本为3.napiIsDate的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsDateSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/app.json5 deleted file mode 100755 index 7db9917074fc9b619d0027a2dbe79bd88bfd5a34..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapienvironmentallifecycle", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/element/string.json deleted file mode 100755 index ccd8c94a69665ee95ae31d3cbbf1906da02c0420..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIEnvironmentalLifeCycle" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/README.md deleted file mode 100755 index 1fbd6522e665df98afc83e31cebfd3d26063c979..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行environmental-life-cycle相关开发 - -### 介绍 - -在Node-API模块中,可以使用Node-API接口将特定数据与当前的环境相关联,并在需要时检索该数据,本工程主要展示绑定和检索与当前运行环境相关联的数据项,其中代码详细描述可查如下链接。 - -- [使用Node-API进行environmental-life-cycle相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-environmental-life-cycle.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| :----------------------------------------------------------- | :----------------------------------------------------------- | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIEnvironmentalLifeCycle.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行environmental-life-cycle相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIEnvironmentalLifeCycle.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9ebcc97b79c6a6cfb969978caf457c507dcbd593..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIEnviornmentalLifeCycle) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 4edf62a527fde6747aff0038f86a2bd53c8bc57a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_set_instance_data] -#include -#include "napi/native_api.h" - -// 定义一个结构来存储实例数据 -struct InstanceData { - int32_t value; -}; - -// 对象被释放时的回调函数,用于清理实例数据 -void FinalizeCallback(napi_env env, void *finalizeData, void *finalizeHint) -{ - if (finalizeData) { - InstanceData *data = reinterpret_cast(finalizeData); - // 释放内存,清除指针指向地址 - delete (data); - *(InstanceData **)finalizeData = nullptr; - } -} - -// napi_set_instance_data -static napi_value SetInstanceData(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value argv[1]; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - int32_t instanceDataValue; - napi_get_value_int32(env, argv[0], &instanceDataValue); - InstanceData *instanceData = new InstanceData; - instanceData->value = instanceDataValue; - // 调用napi_set_instance_data将实例数据关联到Node-API环境,并指定FinalizeCallback函数 - napi_status status = napi_set_instance_data(env, instanceData, FinalizeCallback, nullptr); - bool success = true; - napi_value result; - if (status == napi_ok) { - napi_get_boolean(env, success, &result); - } - return result; -} -// [End napi_set_instance_data] - -// [Start napi_get_instance_data] -// napi_get_instance_data -static napi_value GetInstanceData(napi_env env, napi_callback_info info) -{ - InstanceData *resData = nullptr; - // napi_get_instance_data获取之前想关联的数据项 - napi_get_instance_data(env, (void **)&resData); - napi_value result; - napi_create_int32(env, resData->value, &result); - return result; -} -// [End napi_get_instance_data] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"setInstanceData", nullptr, SetInstanceData, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getInstanceData", nullptr, GetInstanceData, 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 2ed58066893cc90d6037199a635616821e58d221..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_set_instance_data_api] -export const setInstanceData: (data: number) => boolean; // napi_set_instance_data -// [End napi_set_instance_data_api] - -// [Start napi_get_instance_data_api] -export const getInstanceData: () => number; // napi_get_instance_data -// [End napi_get_instance_data_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 2d276e0e8d91fa7013602965df758ccb14403d08..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiSetInstanceData', - '2.napiGetInstanceData' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(22) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiSetInstanceData') { - // [Start ark_napi_set_instance_data] - // napi_set_instance_data - let data = 5; - let value = testNapi.setInstanceData(data); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}s', value); - // [End ark_napi_set_instance_data] - this.result = 'napiSetInstanceDataSuccess'; - } else if (item === '2.napiGetInstanceData') { - // [Start ark_napi_get_instance_data] - // napi_get_instance_data - let data = 5; - testNapi.setInstanceData(data); - let value = testNapi.getInstanceData(); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_instance_data:%{public}d', value); - // [End ark_napi_get_instance_data] - this.result = 'napiGetInstanceDataSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/ohosTest.md deleted file mode 100755 index feebcef90862b90f64120fa3d8f7943c737d9d79..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIEnvironmentalLifeCycle/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 使用Node-API进行environmental-life-cycle相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| --------------------------------------------- | ------------ | ----------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 setInstanceData | 位于主页 | 点击文本为1.napiSetInstanceData的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetInstanceDataSuccess | Pass | -| ArkTS端成功调用native侧接口getInstanceData | 位于主页 | 点击文本为2.napiGetInstanceData的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetInstanceDataSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/app.json5 deleted file mode 100755 index ee9b5cbb6a7014f8d8437961dd341ed2c8a82b49..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapierror", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/element/string.json deleted file mode 100755 index 70210c9807e61e0da0d17ce6c4079f63b3bad222..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIError" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/README.md deleted file mode 100755 index 9f99e9c3c4207b31ce1cd59943b19241f7493188..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行错误处理开发 - -### 介绍 - -使用Node-API接口进行错误处理开发,使得在Node-API模块中能够更好地管理和响应错误情况。通过合理使用这些函数,可以提高模块的稳定性和可靠性,本工程主要展示使用Node-API进行创建错误对象并抛出、获取错误对象、检查napi_value是否代表错误对象和抛出致命异常终止进程等场景,其中代码详细描述可查如下链接。 - -- [使用Node-API进行错误处理开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-error.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIError.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行错误处理开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIError.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIError/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 8531edd27c336824e2380b32318ab79b583fae34..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIError) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index e589bfa6570cacbe8cb7f9aa2018f6ac23f1699f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/* - * 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 "hilog/log.h" -#include "napi/native_api.h" - -// [Start napi_get_last_error_info] -// napi_get_last_error_info -static napi_value GetLastErrorInfo(napi_env env, napi_callback_info info) -{ - // 获取输入参数(这里以字符串message作为参数传入) - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将传入的字符串参数以napi_get_value_int32取出,主动制造错误 - int32_t value = 0; - napi_status status = napi_get_value_int32(env, args[0], &value); - // 接口使用错误,故返回值不为napi_ok - if (status != napi_ok) { - OH_LOG_INFO(LOG_APP, "napi_get_value_int32 return status, status is not equal to napi_ok."); - } - // 调用接口napi_get_last_error_info获取最后一次错误信息 - const napi_extended_error_info *errorInfo; - napi_get_last_error_info(env, &errorInfo); - // 取出错误码与接口调用错误后其返回值作比较 - if (errorInfo->error_code == status) { - OH_LOG_INFO(LOG_APP, "napi_get_last_error_info return errorInfo, error_code equal to status."); - } - // 取出错误消息作为返回值带出去打印 - napi_value result = nullptr; - napi_create_string_utf8(env, errorInfo->error_message, NAPI_AUTO_LENGTH, &result); - return result; -} -// [End napi_get_last_error_info] - -// [Start napi_create_type_error] -// napi_create_type_error -static napi_value CreatTypeError(napi_env env, napi_callback_info info) -{ - // 构造errorCode和errorMessage - napi_value errorCode = nullptr; - napi_create_string_utf8(env, "napi_create_error errorCode", NAPI_AUTO_LENGTH, &errorCode); - napi_value errorMessage = nullptr; - napi_create_string_utf8(env, "napi_create_error errorMessage", NAPI_AUTO_LENGTH, &errorMessage); - // 调用napi_create_type_error创建一个typeError错误对象 - napi_value error = nullptr; - napi_create_type_error(env, errorCode, errorMessage, &error); - return error; -} -// [End napi_create_type_error] - -// [Start napi_create_range_error] -// napi_create_range_error -static napi_value CreatRangeError(napi_env env, napi_callback_info info) -{ - // 构造errorCode和errorMessage - napi_value errorCode = nullptr; - napi_create_string_utf8(env, "napi_create_error errorCode", NAPI_AUTO_LENGTH, &errorCode); - napi_value errorMessage = nullptr; - napi_create_string_utf8(env, "napi_create_error errorMessage", NAPI_AUTO_LENGTH, &errorMessage); - // 调用napi_create_range_error创建一个typeError错误对象 - napi_value error = nullptr; - napi_create_range_error(env, errorCode, errorMessage, &error); - return error; -} -// [End napi_create_range_error] - -// [Start napi_create_error] -// napi_create_error and napi_throw -static napi_value NapiThrow(napi_env env, napi_callback_info info) -{ - // 代码中发生某些错误后,可执行以下操作抛出异常 - // 在Node-API环境中创建一个字符串,并将其存储在errorCode变量中 - napi_value errorCode = nullptr; - napi_create_string_utf8(env, "throw errorCode", NAPI_AUTO_LENGTH, &errorCode); - // 在Node-API环境中创建一个字符串,并将其存储在errorMessage变量中 - napi_value errorMessage = nullptr; - napi_create_string_utf8(env, "throw errorMessage", NAPI_AUTO_LENGTH, &errorMessage); - // 创建一个ArkTS对象error - napi_value error = nullptr; - napi_create_error(env, errorCode, errorMessage, &error); - // 通过napi_throw接口将对象抛出 - napi_throw(env, error); - return nullptr; -} -// [End napi_create_error] - -// [Start napi_throw_error] -// napi_throw_error -// 这里直接抛出一个带有errorMessage的错误 -static napi_value NapiThrowErrorMessage(napi_env env, napi_callback_info info) -{ - napi_throw_error(env, nullptr, "napi_throw_error throwing an error"); - return nullptr; -} - -// 传入两个参数,在第二个参数,也就是除数为0的时候抛出一个错误 -static napi_value NapiThrowError(napi_env env, napi_callback_info info) -{ - // ArkTS侧传入两个参数 - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 将其转换为double类型的值作为被除数和除数 - double dividend; - double divisor; - napi_get_value_double(env, argv[0], ÷nd); - napi_get_value_double(env, argv[1], &divisor); - // 在这里判断除数如果为0则直接抛出一个错误,errorCode为:DIVIDE_BY_ZERO,errorMessage为:Cannot divide by zero - if (divisor == 0) { - napi_throw_error(env, "DIVIDE_BY_ZERO", "Cannot divide by zero"); - } - return nullptr; -} -// [End napi_throw_error] - -// [Start napi_throw_type_error] -// napi_throw_type_error -// 这里直接抛出一个带有errorMessage的TypeError -static napi_value ThrowTypeErrorMessage(napi_env env, napi_callback_info info) -{ - napi_throw_type_error(env, nullptr, "napi_throw_type_error throwing an error"); - return nullptr; -} - -// 传入一个类型不匹配的参数,判断类型不匹配之后抛出typeError -static napi_value ThrowTypeError(napi_env env, napi_callback_info info) -{ - // ArkTS侧传入一个参数 - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 将传入参数转换为napi_valuetype类型的值 - napi_valuetype valueType; - napi_typeof(env, argv[0], &valueType); - // 如果传入参数不为napi_number类型的值则抛出TypeError - if (valueType != napi_number) { - // 这里抛出一个既带有errorCode也带有errorMessage的TypeError - napi_throw_type_error(env, "napi_throw_type_error", "Argument must be a number"); - } - return nullptr; -} -// [End napi_throw_type_error] - -// [Start napi_throw_range_error] -// napi_throw_range_error -// 这里直接抛出一个带有errorMessage的RangeError -static napi_value ThrowRangeErrorMessage(napi_env env, napi_callback_info info) -{ - napi_throw_range_error(env, nullptr, "napi_throw_range_error one"); - return nullptr; -} - -// 传入不匹配的参数个数,判断不匹配之后抛出rangeError -static napi_value ThrowRangeError(napi_env env, napi_callback_info info) -{ - // ArkTS侧传入两个参数 - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 如果传入参数个数不为2 - if (argc != 2) { - // 这里抛出一个RangeError - napi_throw_range_error(env, "napi_throw_range_error", "Expected two numbers as arguments"); - return nullptr; - } - // 下面将传入的两值相加并传出去 - double numOne = 0; - double numTwo = 0; - napi_get_value_double(env, argv[0], &numOne); - napi_get_value_double(env, argv[1], &numTwo); - double result = numOne + numTwo; - napi_value resultValue; - napi_create_double(env, result, &resultValue); - return resultValue; -} -// [End napi_throw_range_error] - -// [Start napi_is_error] -// napi_is_error -static napi_value NapiIsError(napi_env env, napi_callback_info info) -{ - // 接收一个入参 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 调用接口napi_is_error判断入参是否为一个error对象 - bool result = false; - // 如果napi_value为一个error对象,则设置result为true的布尔值,否则设置为false - napi_is_error(env, args[0], &result); - // 取出result通过napi_get_boolean接口将取出的bool值转换为napi_value类型的值返回出去 - napi_value returnValue = nullptr; - napi_get_boolean(env, result, &returnValue); - return returnValue; -} -// [End napi_is_error] - -// [Start napi_get_and_clear_last_exception] -// napi_get_and_clear_last_exception -static napi_value GetAndClearLastException(napi_env env, napi_callback_info info) -{ - // 抛出异常,创造异常情况 - napi_throw_error(env, "napi_create_error errorCode", "napi_create_error errorMessage"); - // 调用napi_get_and_clear_last_exception接口获取并清除最后一个未处理的异常。即使存在挂起的ArkTS异常,也可以调用此API - napi_value result = nullptr; - napi_status status = napi_get_and_clear_last_exception(env, &result); - if (status != napi_ok) { - return nullptr; - } - return result; -} -// [End napi_get_and_clear_last_exception] - -// [Start napi_is_exception_pending] -// napi_is_exception_pending -static napi_value IsExceptionPending(napi_env env, napi_callback_info info) -{ - napi_status status; - bool isExceptionPending = false; - // 在执行一些可能引发异常的操作后 - napi_throw_error(env, "napi_create_error errorCode", "napi_create_error errorMessage"); - // 检查当前环境中是否有异常挂起 - status = napi_is_exception_pending(env, &isExceptionPending); - if (status != napi_ok) { - return nullptr; - } - if (isExceptionPending) { - // 处理异常挂起的情况 - napi_value result = nullptr; - status = napi_get_and_clear_last_exception(env, &result); - if (status != napi_ok) { - return nullptr; - } - // 将处理的异常返回出去 - return result; - } - return nullptr; -} -// [End napi_is_exception_pending] - -// [Start napi_fatal_error] -// napi_fatal_error -static napi_value FatalError(napi_env env, napi_callback_info info) -{ - // 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 - // 模拟一个致命错误条件 - bool errorCondition = true; - if (errorCondition) { - // 创建一个致命错误信息 - napi_fatal_error("napi_fatal_error test", NAPI_AUTO_LENGTH, "napi_create_error errorMessage", NAPI_AUTO_LENGTH); - } - return nullptr; -} -// [End napi_fatal_error] - -// [Start napi_fatal_exception] -// napi_fatal_exception -static napi_value FatalException(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - - napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - if (status != napi_ok) { - return nullptr; - } - // 请注意,使用napi_fatal_exception函数会导致应用进程直接终止,因此应该谨慎使用,仅在主线程遇到无法恢复的严重错误时才应该调用该函数 - // 模拟一个致命错误条件 - status = napi_fatal_exception(env, args[0]); - if (status != napi_ok) { - return nullptr; - } - return nullptr; -} -// [End napi_fatal_exception] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getLastErrorInfo", nullptr, GetLastErrorInfo, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"creatTypeError", nullptr, CreatTypeError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"creatRangeError", nullptr, CreatRangeError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiThrow", nullptr, NapiThrow, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiThrowErrorMessage", nullptr, NapiThrowErrorMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiThrowError", nullptr, NapiThrowError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"throwTypeErrorMessage", nullptr, ThrowTypeErrorMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"throwTypeError", nullptr, ThrowTypeError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"throwRangeErrorMessage", nullptr, ThrowRangeErrorMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"throwRangeError", nullptr, ThrowRangeError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiIsError", nullptr, NapiIsError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getAndClearLastException", nullptr, GetAndClearLastException, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"isExceptionPending", nullptr, IsExceptionPending, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"fatalError", nullptr, FatalError, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"fatalException", nullptr, FatalException, 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 6458d55543619b58032d3e77de2462da0920af14..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_get_last_error_info_api] -export const getLastErrorInfo: (str: string) => string; // napi_get_last_error_info -// [End napi_get_last_error_info_api] - -// [Start napi_create_type_error_api] -export const creatTypeError: () => Error; // napi_create_type_error -// [End napi_create_type_error_api] - -// [Start napi_create_range_error_api] -export const creatRangeError: () => Error; // napi_create_range_error -// [End napi_create_range_error_api] - -// [Start napi_create_error_api] -export const napiThrow: () => void; // napi_create_error and napi_throw -// [End napi_create_error_api] - -// [Start napi_throw_error_api] -export const napiThrowErrorMessage: () => void; // napi_throw_error - -export const napiThrowError: (dividend: number, divisor: number) => void; // napi_throw_error -// [End napi_throw_error_api] - -// [Start napi_throw_type_error_api] -export const throwTypeErrorMessage: () => void; // napi_throw_type_error - -export const throwTypeError: (message: string) => void; // napi_throw_type_error -// [End napi_throw_type_error_api] - -// [Start napi_throw_range_error_api] -export const throwRangeErrorMessage: () => void; // napi_throw_range_error - -export const throwRangeError: (num: number) => number | void; // napi_throw_range_error -// [End napi_throw_range_error_api] - -// [Start napi_is_error_api] -export const napiIsError: (obj: T) => boolean; // napi_is_error -// [End napi_is_error_api] - -// [Start napi_get_and_clear_last_exception_api] -export const getAndClearLastException: () => Error | void; // napi_get_and_clear_last_exception -// [End napi_get_and_clear_last_exception_api] - -// [Start ark_napi_is_exception_pending_interface] -export interface MyObject { - code: string; - message: string; -} -// [End ark_napi_is_exception_pending_interface] - -// [Start napi_is_exception_pending_api] -export const isExceptionPending: () => Object | void; // napi_is_exception_pending -// [End napi_is_exception_pending_api] - -// [Start napi_fatal_error_api] -export const fatalError: () => void; // napi_fatal_error -// [End napi_fatal_error_api] - -// [Start napi_fatal_exception_api] -export const fatalException: (err: Error) => void; // napi_fatal_exception -// [End napi_fatal_exception_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 117809f4f7503145892a08e6cf735c32c33c8936..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,308 +0,0 @@ -/* - * 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, { MyObject } from 'libentry.so'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiGetLastErrorInfo', - '2.napiCreateTypeError', - '3.napiCreateRangeError', - '4.napiCreateErrorAndNapiThrow', - '5.napiThrowError', - '6.napiThrowTypeError', - '7.napiThrowRangeError', - '8.napiIsError', - '9.napiGetAndClearLastException', - '10.napiIsExceptionPending', - '11.napiFatalError', - '12.napiFatalException' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiGetLastErrorInfo') { - // [Start ark_napi_get_last_error_info] - // napi_get_last_error_info - try { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info: %{public}s', - testNapi.getLastErrorInfo('message')); - // [StartExclude ark_napi_get_last_error_info] - this.result = 'napiGetLastErrorInfoSuccess'; - // [EndExclude ark_napi_get_last_error_info] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_last_error_info error: %{public}s', error); - // [StartExclude ark_napi_get_last_error_info] - this.result = 'napiGetLastErrorInfoFail'; - // [EndExclude ark_napi_get_last_error_info] - } - // [End ark_napi_get_last_error_info] - } else if (item === '2.napiCreateTypeError') { - // [Start ark_napi_create_type_error] - try { - // [StartExclude ark_napi_create_type_error] - this.result = 'napiCreateTypeErrorSuccess'; - // [EndExclude ark_napi_create_type_error] - throw testNapi.creatTypeError(); - } catch (error) { // napi_create_type_error - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_create_type_error errorCode: %{public}s, errorMessage %{public}s', error.code, - error.message); - // [StartExclude ark_napi_create_type_error] - this.result = 'napiCreateTypeErrorFail'; - // [EndExclude ark_napi_create_type_error] - } - // [End ark_napi_create_type_error] - } else if (item === '3.napiCreateRangeError') { - // [Start ark_napi_create_range_error] - // napi_create_range_error - try { - // [StartExclude ark_napi_create_range_error] - this.result = 'napiCreateRangeErrorSuccess'; - // [EndExclude ark_napi_create_range_error] - throw testNapi.creatRangeError(); - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_create_range_error errorCode: %{public}s, errorMessage: %{public}s', - error.code, - error.message); - // [StartExclude ark_napi_create_range_error] - this.result = 'napiCreateRangeErrorFail'; - // [EndExclude ark_napi_create_range_error] - } - // [End ark_napi_create_range_error] - } else if (item === '4.napiCreateErrorAndNapiThrow') { - // [Start ark_napi_create_error] - // napi_create_error and napi_throw - try { - testNapi.napiThrow(); - // [StartExclude ark_napi_create_error] - this.result = 'napiCreateErrorAndNapiThrowSuccess'; - // [EndExclude ark_napi_create_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw errorCode: %{public}s, errorMessage: %{public}s', - error.code, error.message); - // [StartExclude ark_napi_create_error] - this.result = 'napiCreateErrorAndNapiThrowFail'; - // [EndExclude ark_napi_create_error] - } - // [End ark_napi_create_error] - } else if (item === '5.napiThrowError') { - // [Start ark_napi_throw_error] - // napi_throw_error - try { - testNapi.napiThrowErrorMessage(); - // [StartExclude ark_napi_throw_error] - this.result = 'napiThrowErrorMessageSuccess'; - // [EndExclude ark_napi_throw_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw_error error code: %{public}s , message: %{public}s', error.code, - error.message); - // [StartExclude ark_napi_throw_error] - this.result = 'napiThrowErrorMessageFail'; - // [EndExclude ark_napi_throw_error] - } - try { - testNapi.napiThrowError(5, 0); - // [StartExclude ark_napi_throw_error] - this.result = 'napiThrowErrorSuccess'; - // [EndExclude ark_napi_throw_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw_error errorCode: %{public}s , errorManager: %{public}s', error.code, - error.message); - // [StartExclude ark_napi_throw_error] - this.result = 'napiThrowErrorFail'; - // [EndExclude ark_napi_throw_error] - } - // [End ark_napi_throw_error] - } else if (item === '6.napiThrowTypeError') { - // [Start ark_napi_throw_type_error] - // napi_throw_type_error - try { - testNapi.throwTypeErrorMessage(); - // [StartExclude ark_napi_throw_type_error] - this.result = 'throwTypeErrorMessageSuccess'; - // [EndExclude ark_napi_throw_type_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', - error.code, - error.message); - // [StartExclude ark_napi_throw_type_error] - this.result = 'throwTypeErrorMessageFail'; - // [EndExclude ark_napi_throw_type_error] - } - try { - testNapi.throwTypeError('str'); - // [StartExclude ark_napi_throw_type_error] - this.result = 'throwTypeErrorSuccess'; - // [EndExclude ark_napi_throw_type_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw_type_error errorCode: %{public}s, errorMessage: %{public}s', - error.code, - error.message); - // [StartExclude ark_napi_throw_type_error] - this.result = 'throwTypeErrorFail'; - // [EndExclude ark_napi_throw_type_error] - } - // [End ark_napi_throw_type_error] - } else if (item === '7.napiThrowRangeError') { - // [Start ark_napi_throw_range_error] - // napi_throw_range_error - try { - testNapi.throwRangeErrorMessage(); - // [StartExclude ark_napi_throw_range_error] - this.result = 'throwRangeErrorMessageSuccess'; - // [EndExclude ark_napi_throw_range_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', - error.code, - error.message); - // [StartExclude ark_napi_throw_range_error] - this.result = 'throwRangeErrorMessageFail'; - // [EndExclude ark_napi_throw_range_error] - } - - try { - testNapi.throwRangeError(1); - // [StartExclude ark_napi_throw_range_error] - this.result = 'throwRangeErrorSuccess'; - // [EndExclude ark_napi_throw_range_error] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_throw_range_error errorCode: %{public}s, errorMessage: %{public}s', - error.code, - error.message); - // [StartExclude ark_napi_throw_range_error] - this.result = 'throwRangeErrorFail'; - // [EndExclude ark_napi_throw_range_error] - } - // [End ark_napi_throw_range_error] - } else if (item === '8.napiIsError') { - // [Start ark_napi_is_error] - // napi_is_error - try { - // [StartExclude ark_napi_is_error] - this.result = 'napiIsErrorSuccess'; - // [EndExclude ark_napi_is_error] - throw new Error("throwing an error"); - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', - testNapi.napiIsError(error) - .toString()); - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_error error: %{public}s', - testNapi.napiIsError(1) - .toString()); - // [StartExclude ark_napi_is_error] - this.result = 'napiIsErrorFail'; - // [EndExclude ark_napi_is_error] - } - // [End ark_napi_is_error] - } else if (item === '9.napiGetAndClearLastException') { - // [Start ark_napi_get_and_clear_last_exception] - // napi_get_and_clear_last_exception - // 这里获取到最后一个未处理的异常 - hilog.info(0x0000, 'testTag', - 'Test Node-API napi_get_and_clear_last_exception, error.message: %{public}s', - testNapi.getAndClearLastException()); - // [End ark_napi_get_and_clear_last_exception] - this.result = 'napiGetAndClearLastExceptionSuccess'; - } else if (item === '10.napiIsExceptionPending') { - // [Start ark_napi_is_exception_pending] - // napi_is_exception_pending - try { - let result = testNapi.isExceptionPending() as MyObject; - hilog.info(0x0000, 'testTag', - 'Test Node-API napi_is_exception_pending, error.Code: %{public}s, error.message: %{public}s', - result.code, result.message); - // [StartExclude ark_napi_is_exception_pending] - this.result = 'napiIsExceptionPendingSuccess'; - // [EndExclude ark_napi_is_exception_pending] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_exception_pending error'); - // [StartExclude ark_napi_is_exception_pending] - this.result = 'napiIsExceptionPendingFail'; - // [EndExclude ark_napi_is_exception_pending] - } - // [End ark_napi_is_exception_pending] - } else if (item === '11.napiFatalError') { - // [Start ark_napi_fatal_error] - // napi_fatal_error 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 - // 模拟一个致命错误条件 - try { - testNapi.fatalError(); - // [StartExclude ark_napi_fatal_error] - this.result = 'napiFatalErrorSuccess'; - // [EndExclude ark_napi_fatal_error] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_error error'); - // [StartExclude ark_napi_fatal_error] - this.result = 'napiFatalErrorFail'; - // [EndExclude ark_napi_fatal_error] - } - // [End ark_napi_fatal_error] - } else if (item === '12.napiFatalException') { - // napi_fatal_exception 请注意,使用napi_fatal_error函数会导致应用进程直接终止,因此应该谨慎使用,仅在遇到无法恢复的严重错误时才应该调用该函数 - // 模拟一个致命错误条件 - try { - // [Start ark_napi_fatal_exception] - const err = new Error("a fatal exception occurred"); - testNapi.fatalException(err); - // [End ark_napi_fatal_exception] - this.result = 'napiFatalExceptionSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_fatal_exception error'); - this.result = 'napiFatalExceptionFail'; - } - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIError/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/ohosTest.md deleted file mode 100755 index efd0513e1d4a5be8a886c3af308541fe48fc5a6e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIError/ohosTest.md +++ /dev/null @@ -1,17 +0,0 @@ -# 使用Node-API进行错误处理开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| --------------------------------------------------- | ------------ | -------------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 getLastErrorInfo | 位于主页 | 点击文本为1.napiGetLastErrorInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetLastErrorInfoSuccess | Pass | -| ArkTS端成功调用native侧接口creatTypeError | 位于主页 | 点击文本为2.napiCreateTypeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateTypeErrorSuccess | Pass | -| ArkTS端成功调用native侧接口creatRangeError | 位于主页 | 点击文本为3.napiCreateRangeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateRangeErrorSuccess | Pass | -| ArkTS端成功调用native侧接口napiThrow | 位于主页 | 点击文本为4.napiCreateErrorAndNapiThrow的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateErrorAndNapiThrowSuccess | Pass | -| ArkTS端成功调用native侧接口napiThrowError | 位于主页 | 点击文本为5.napiThrowError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiThrowErrorSuccess | Pass | -| ArkTS端成功调用native侧接口throwTypeError | 位于主页 | 点击文本为6.napiThrowTypeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: throwTypeErrorSuccess | Pass | -| ArkTS端成功调用native侧接口throwRangeError | 位于主页 | 点击文本为7.napiThrowRangeError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: throwRangeErrorSuccess | Pass | -| ArkTS端成功调用native侧接口napiIsError | 位于主页 | 点击文本为8.napiIsError的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsErrorSuccess | Pass | -| ArkTS端成功调用native侧接口getAndClearLastException | 位于主页 | 点击文本为9.napiGetAndClearLastException的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetAndClearLastExceptionSuccess | Pass | -| ArkTS端成功调用native侧接口isExceptionPending | 位于主页 | 点击文本为10.napiIsExceptionPending的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsExceptionPendingSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/app.json5 deleted file mode 100755 index fea2df754946019a40b6877f4250b86d38c2b992..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiextendcapabilities", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/element/string.json deleted file mode 100755 index 5cb53b4b9fe3c501b909d4b8370819e7beb0b5ae..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIExtendCapabilities" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/README.md deleted file mode 100755 index 96980a88823ccad55e7769ee8d027a122792cb37..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行扩展能力功能开发 - -### 介绍 - -扩展能力接口进一步扩展了Node-API的功能,提供了一些额外的接口,用于在Node-API模块中与ArkTS进行更灵活的交互和定制,这些接口可以用于创建自定义ArkTS对象等场景,本工程主要展示了使用Node-API对模块加载、ArkTS Object相关、运行指定abc文件、异步工作对象加入队列并指定优先级、给ArkTS对象绑定回调和回调所需的参数等场景,其中展示的代码详细描述可查如下链接。 - -- [使用Node-API进行扩展能力功能开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-extension.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIExtendCapabilities.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行扩展能力功能开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIExtendCapabilities.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 37b14bbfc960acd33273b3b8714551421be04c03..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(using_NodeAPI_extend_capabilities) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 6eabbeacfd84e04fc5b8e844cb6c35d9dca9bcf0..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,578 +0,0 @@ -/* - * 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 -#include -#include -#include -#include "hilog/log.h" - -static constexpr int INT_ARG_100 = 100; // 入参索引 - -// [Start node_api_module_add] -// 模块加载 -static napi_value Add(napi_env env, napi_callback_info info) -{ - // 接受传入两个参数 - size_t requireArgc = 2; - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 将传入的napi_value类型的参数转化为double类型 - double valueLeft; - double valueRight; - napi_get_value_double(env, args[0], &valueLeft); - napi_get_value_double(env, args[1], &valueRight); - - // 将转化后的double值相加并转成napi_value返回给ArkTS代码使用 - napi_value sum; - napi_create_double(env, valueLeft + valueRight, &sum); - - return sum; -} - -// [StartExclude node_api_module_add] -// [Start node_api_module_create_object_properties] -// ArkTS Object相关 napi_create_object_with_properties -static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value argv[1] = {nullptr}; - // 获取解析传递的参数 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 声明了一个napi_property_descriptor数组desc,其中包含了一个名为"name"的属性,其值为传入的第一个参数argv[0]。 - napi_property_descriptor desc[] = { - {"name", nullptr, nullptr, nullptr, nullptr, argv[0], napi_default_jsproperty, nullptr}}; - napi_value object = nullptr; - // 调用napi_create_object_with_properties来创建一个新的ArkTS对象,并将属性值添加到该对象中。 - napi_create_object_with_properties(env, &object, sizeof(desc) / sizeof(desc[0]), desc); - napi_valuetype valueType; - napi_typeof(env, object, &valueType); - if (valueType == napi_object) { - return object; - } -} -// [End node_api_module_create_object_properties] -// [Start node_api_module_create_object_name_properties] -// ArkTS Object相关 napi_create_object_with_named_properties -static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value argv[1] = {nullptr}; - // 获取解析传递的参数 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - napi_value obj = nullptr; - const char *key[] = { - "name", - }; - const napi_value values[] = { - argv[0], - }; - napi_property_descriptor desc[] = {{"name", nullptr, nullptr, nullptr, nullptr, nullptr, napi_default, nullptr}}; - napi_status status = napi_create_object_with_named_properties( - env, &obj, sizeof(desc) / sizeof(desc[0]), key, values); - if (status != napi_ok) { - return argv[0]; - } - return obj; -} -// [End node_api_module_create_object_name_properties] -// [Start node_api_module_run_script_path] -// 运行指定abc文件 napi_run_script_path -static napi_value RunScriptPath(napi_env env, napi_callback_info info) -{ - napi_value value = nullptr; - // 注意:记得在应用rawfile目录下放置.abc文件 - const char *scriptPath = "/entry/src/main/resources/rawfile/test.abc"; - // 使用napi_run_script_path函数执行指定路径中的文件 - napi_status status = napi_run_script_path(env, scriptPath, &value); - // 检查是否执行成功,如果失败,返回false - napi_value returnValue = nullptr; - if (value == nullptr || status != napi_ok) { - napi_get_boolean(env, false, &returnValue); - } else { - napi_get_boolean(env, true, &returnValue); - } - return returnValue; -} -// [End node_api_module_run_script_path] -// 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object -// [Start napi_coerce_to_native_binding_object] -class Object { -public: - Object() = default; - ~Object() = default; - - static Object *GetInstance() - { - Object *instance = new Object(); - return instance; - } - - static napi_value GetAddress(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - if (thisVar == nullptr) { - return nullptr; - } - void *object = nullptr; - napi_unwrap(env, thisVar, &object); - if (object == nullptr) { - return nullptr; - } - uint64_t addressVal = reinterpret_cast(object); - napi_value address = nullptr; - napi_create_bigint_uint64(env, addressVal, &address); - return address; - } - - // 获取数组大小 - static napi_value GetSetSize(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - if (thisVar == nullptr) { - return nullptr; - } - void *object = nullptr; - napi_unwrap(env, thisVar, &object); - if (object == nullptr) { - return nullptr; - } - std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); - uint32_t setSize = reinterpret_cast(object)->numberSet_.size(); - napi_value napiSize = nullptr; - napi_create_uint32(env, setSize, &napiSize); - return napiSize; - } - - // 往数组里插入元素 - static napi_value Store(napi_env env, napi_callback_info info) - { - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr); - if (argc != 1) { - napi_throw_error(env, nullptr, "Store args number must be one."); - return nullptr; - } - napi_valuetype type = napi_undefined; - napi_typeof(env, args[0], &type); - if (type != napi_number) { - napi_throw_error(env, nullptr, "Store args is not number."); - return nullptr; - } - if (thisVar == nullptr) { - return nullptr; - } - uint32_t value = 0; - napi_get_value_uint32(env, args[0], &value); - void *object = nullptr; - napi_unwrap(env, thisVar, &object); - if (object == nullptr) { - return nullptr; - } - std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); - reinterpret_cast(object)->numberSet_.insert(value); - return nullptr; - } - - // 删除数组元素 - static napi_value Erase(napi_env env, napi_callback_info info) - { - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, &argc, args, &thisVar, nullptr); - if (argc != 1) { - napi_throw_error(env, nullptr, "Erase args number must be one."); - return nullptr; - } - napi_valuetype type = napi_undefined; - napi_typeof(env, args[0], &type); - if (type != napi_number) { - napi_throw_error(env, nullptr, "Erase args is not number."); - return nullptr; - } - if (thisVar == nullptr) { - return nullptr; - } - uint32_t value = 0; - napi_get_value_uint32(env, args[0], &value); - void *object = nullptr; - napi_unwrap(env, thisVar, &object); - if (object == nullptr) { - return nullptr; - } - std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); - reinterpret_cast(object)->numberSet_.erase(value); - return nullptr; - } - - // 清空数组 - static napi_value Clear(napi_env env, napi_callback_info info) - { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - if (thisVar == nullptr) { - return nullptr; - } - void *object = nullptr; - napi_unwrap(env, thisVar, &object); - if (object == nullptr) { - return nullptr; - } - std::lock_guard lock(reinterpret_cast(object)->numberSetMutex_); - reinterpret_cast(object)->numberSet_.clear(); - return nullptr; - } - -private: - Object(const Object &) = delete; - Object &operator=(const Object &) = delete; - - std::unordered_set numberSet_{}; - std::mutex numberSetMutex_{}; -}; - -void FinializeCallback(napi_env env, void *data, void *hint) { return; } - -// 解绑回调,在序列化时调用,可在对象解绑时执行一些清理操作 -void *DetachCallback(napi_env env, void *value, void *hint) { return value; } - -// 绑定回调,在反序列化时调用 -napi_value AttachCallback(napi_env env, void *value, void *hint) -{ - napi_value object = nullptr; - napi_create_object(env, &object); - napi_property_descriptor desc[] = { - {"getAddress", nullptr, Object::GetAddress, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getSetSize", nullptr, Object::GetSetSize, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"store", nullptr, Object::Store, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"erase", nullptr, Object::Erase, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"clear", nullptr, Object::Clear, nullptr, nullptr, nullptr, napi_default, nullptr}}; - napi_define_properties(env, object, sizeof(desc) / sizeof(desc[0]), desc); - // 将JS对象object和native对象value生命周期进行绑定 - napi_wrap(env, object, value, FinializeCallback, nullptr, nullptr); - // JS对象携带native信息 - napi_coerce_to_native_binding_object(env, object, DetachCallback, AttachCallback, value, hint); - return object; -} -// [StartExclude napi_coerce_to_native_binding_object] -// [Start napi_serialize_deserialize_delete_serialization_data] -// 序列化和反序列化 -static napi_value AboutSerialize(napi_env env, napi_callback_info info) -{ - // 获取传入的ts的一个对象作为参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_value undefined = nullptr; - // 构造napi_serialize方法所需参数 - napi_get_undefined(env, &undefined); - void *data = nullptr; - // 调用napi_serialize方法将ts对象转化为native数据 - napi_status status = napi_serialize(env, args[0], undefined, undefined, &data); - if (status != napi_ok || data == nullptr) { - napi_throw_error(env, nullptr, "Node-API napi_serialize fail"); - return nullptr; - } - // 构造napi_value类型的数据,用于接收将native数据转化为ts对象后的数据 - napi_value result = nullptr; - napi_deserialize(env, data, &result); - napi_value number = nullptr; - // 获取native数据转化为ts对象后的数据中的numKey属性的值 - napi_get_named_property(env, result, "numKey", &number); - // 判断获取到的属性值是否为number类型 - napi_valuetype valuetype; - napi_typeof(env, number, &valuetype); - if (valuetype != napi_number) { - napi_throw_error(env, nullptr, "Node-API Wrong type of argment. Expects a number."); - return nullptr; - } - // 调用napi_delete_serialization_data方法删除序列化数据 - napi_delete_serialization_data(env, data); - // 返回获取到的属性值 - return number; -} -// [End napi_serialize_deserialize_delete_serialization_data] -// [Start napi_is_sendable] -// Sendable相关 napi_is_sendable -static napi_value IsSendable(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - bool isSendable = false; - napi_is_sendable(env, args[0], &isSendable); - napi_value result; - napi_get_boolean(env, isSendable, &result); - return result; -} -// [End napi_is_sendable] - -// [Start napi_define_sendable_class] -static napi_value func(napi_env env, napi_callback_info info) -{ - napi_value val; - napi_create_string_utf8(env, "func result", NAPI_AUTO_LENGTH, &val); - return val; -} - -static napi_value DefineSendableClass(napi_env env) -{ - napi_value str; - napi_create_string_utf8(env, "str", NAPI_AUTO_LENGTH, &str); - - napi_property_descriptor props[] = { - {"staticStr", nullptr, nullptr, nullptr, nullptr, str, - static_cast(napi_static | napi_writable), nullptr}, - {"staticFunc", nullptr, func, nullptr, nullptr, nullptr, napi_static, nullptr}, - {"str", nullptr, nullptr, nullptr, nullptr, str, static_cast(1 << 9 | napi_writable), - nullptr}, - {"func", nullptr, nullptr, nullptr, nullptr, nullptr, - static_cast(1 << 11 | napi_writable), nullptr}, - }; - - napi_value sendableClass = nullptr; - napi_define_sendable_class( - env, "SendableClass", NAPI_AUTO_LENGTH, - [](napi_env env, napi_callback_info info) -> napi_value { - napi_value thisVar = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr); - napi_value str; - napi_create_string_utf8(env, "instance str", NAPI_AUTO_LENGTH, &str); - napi_property_descriptor props[] = { - {"str", nullptr, nullptr, nullptr, nullptr, str, napi_default, nullptr}, - {"func", nullptr, func, nullptr, nullptr, nullptr, napi_default, nullptr}, - }; - napi_define_properties(env, thisVar, sizeof(props) / sizeof(props[0]), props); - return thisVar; - }, - nullptr, sizeof(props) / sizeof(props[0]), props, nullptr, &sendableClass); - - return sendableClass; -} -// [End napi_define_sendable_class] -// [Start napi_create_sendable_object_with_properties] -// Sendable相关 napi_create_sendable_object_with_properties -static napi_value GetSendableObject(napi_env env, napi_callback_info info) -{ - napi_value val_true; - napi_get_boolean(env, true, &val_true); - napi_property_descriptor desc1[] = { - {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, - }; - napi_value obj; - napi_create_sendable_object_with_properties(env, 1, desc1, &obj); - return obj; -} -// [End napi_create_sendable_object_with_properties -// [Start napi_create_sendable_array] -// Sendable相关 napi_create_sendable_array -static napi_value GetSendableArray(napi_env env, napi_callback_info info) -{ - napi_value result = nullptr; - napi_create_sendable_array(env, &result); - return result; -} -// [End napi_create_sendable_array] -// [Start napi_create_sendable_array_with_length] -// Sendable相关 napi_create_sendable_array_with_length -static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info info) -{ - napi_value result = nullptr; - napi_create_sendable_array_with_length(env, 1, &result); - return result; -} -// End napi_create_sendable_array_with_length] -// [Start napi_create_sendable_arraybuffer] -// Sendable相关 napi_create_sendable_arraybuffer -static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) -{ - static size_t length = 1024; - void *data; - napi_value result = nullptr; - napi_create_sendable_arraybuffer(env, length, &data, &result); - bool isArrayBuffer = false; - napi_is_arraybuffer(env, result, &isArrayBuffer); - OH_LOG_INFO(LOG_APP, "isArrayBuffer: %{public}d", isArrayBuffer); - return result; -} -// [End napi_create_sendable_arraybuffer] -// [Start napi_create_sendable_typed_array] -// Sendable相关 napi_create_sendable_typedarray -static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) -{ - static size_t length = 1024; - static size_t offset = 0; - void *data; - napi_value arraybuffer = nullptr; - napi_create_sendable_arraybuffer(env, length, &data, &arraybuffer); - - napi_value result = nullptr; - napi_create_sendable_typedarray(env, napi_uint8_array, length, arraybuffer, offset, &result); - bool isTypedArray = false; - napi_is_typedarray(env, result, &isTypedArray); - OH_LOG_INFO(LOG_APP, "isTypedArray: %{public}d", isTypedArray); - return result; -} -// [End napi_create_sendable_typed_array] -// [Start napi_wrap_sendable] -// Sendable相关 napi_wrap_sendable -static napi_value WrapSendable(napi_env env, napi_callback_info info) -{ - napi_value val_true; - napi_get_boolean(env, true, &val_true); - napi_property_descriptor desc1[] = { - {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, - }; - napi_value obj; - napi_create_sendable_object_with_properties(env, 1, desc1, &obj); - - const char *testStr = "test"; - napi_wrap_sendable( - env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr); - - return nullptr; -} -// [End napi_wrap_sendable] -// [Start napi_wrap_sendable_with_size] -// Sendable相关 napi_wrap_sendable_with_size -static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) -{ - napi_value val_true; - napi_get_boolean(env, true, &val_true); - napi_property_descriptor desc1[] = { - {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, - }; - napi_value obj; - napi_create_sendable_object_with_properties(env, 1, desc1, &obj); - - const char *testStr = "test"; - napi_wrap_sendable_with_size( - env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr, INT_ARG_100); - - return nullptr; -} -// [End napi_wrap_sendable_with_size] -// [Start napi_unwrap_sendable] -// Sendable相关 napi_unwrap_sendable -static napi_value UnwrapSendable(napi_env env, napi_callback_info info) -{ - napi_value val_true; - napi_get_boolean(env, true, &val_true); - napi_property_descriptor desc1[] = { - {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, - }; - napi_value obj; - napi_create_sendable_object_with_properties(env, 1, desc1, &obj); - - const char *testStr = "test"; - napi_wrap_sendable( - env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr); - - char *tmpTestStr = nullptr; - napi_unwrap_sendable(env, obj, (void **)&tmpTestStr); - OH_LOG_INFO(LOG_APP, "native value is %{public}s", tmpTestStr); - - return nullptr; -} -// [End napi_unwrap_sendable] -// [Start napi_remove_wrap_sendable] -// Sendable相关 napi_remove_wrap_sendable -static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) -{ - napi_value val_true; - napi_get_boolean(env, true, &val_true); - napi_property_descriptor desc1[] = { - {"x", nullptr, nullptr, nullptr, nullptr, val_true, napi_default_jsproperty, nullptr}, - }; - napi_value obj; - napi_create_sendable_object_with_properties(env, 1, desc1, &obj); - - const char *testStr = "test"; - napi_wrap_sendable( - env, obj, (void *)testStr, [](napi_env env, void *data, void *hint) {}, nullptr); - - char *tmpTestStr = nullptr; - napi_remove_wrap_sendable(env, obj, (void **)&tmpTestStr); - OH_LOG_INFO(LOG_APP, "native value is %{public}s", tmpTestStr); - - return nullptr; -} -// [End napi_remove_wrap_sendable] -// [EndExclude napi_coerce_to_native_binding_object] -// [EndExclude node_api_module_add] - -// C++函数Init用于初始化插件,用于将ArkTS层的函数或属性与C++层的函数进行关联 -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - // 通过napi_property_descriptor结构体,可以定义需要导出的属性,并在Node-API模块中使用。napi_define_properties将属性与实际的C++函数进行关联,使其可以被ArkTS层访问和调用 - napi_property_descriptor desc[] = { - {"add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createObjectWithProperties", nullptr, CreateObjectWithProperties, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"createObjectWithNameProperties", nullptr, CreateObjectWithNameProperties, nullptr, nullptr, nullptr, - napi_default, nullptr}, - {"runScriptPath", nullptr, RunScriptPath, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getAddress", nullptr, Object::GetAddress, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getSetSize", nullptr, Object::GetSetSize, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"store", nullptr, Object::Store, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"erase", nullptr, Object::Erase, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"clear", nullptr, Object::Clear, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"aboutSerialize", nullptr, AboutSerialize, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"isSendable", nullptr, IsSendable, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getSendableObject", nullptr, GetSendableObject, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getSendableArray", nullptr, GetSendableArray, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getSendableArrayWithLength", nullptr, GetSendableArrayWithLength, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"getSendableArrayBuffer", nullptr, GetSendableArrayBuffer, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getSendableTypedArray", nullptr, GetSendableTypedArray, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"wrapSendable", nullptr, WrapSendable, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"wrapSendableWithSize", nullptr, WrapSendableWithSize, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"unwrapSendable", nullptr, UnwrapSendable, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"removeWrapSendable", nullptr, RemoveWrapSendable, nullptr, nullptr, nullptr, napi_default, nullptr}}; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - auto object = Object::GetInstance(); - napi_wrap(env, exports, reinterpret_cast(object), FinializeCallback, nullptr, nullptr); - napi_coerce_to_native_binding_object(env, exports, DetachCallback, AttachCallback, reinterpret_cast(object), - nullptr); - napi_value cons = DefineSendableClass(env); - napi_set_named_property(env, exports, "SendableClass", cons); - return exports; -} -EXTERN_C_END - -// 插件的初始化被定义在一个名为demoModule的结构体中,其中包含了模块的基本信息,比如模块的版本号、注册函数等 -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}, -}; - -// 在RegisterEntryModule函数中,使用napi_module_register函数注册并导出了这个插件 -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } -// [End napi_coerce_to_native_binding_object] -// [End node_api_module_add] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 4f111a684b312d30bdbc185139a80dae0d9220e6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start node_api_module_add_api] -export const add: (a: number, b: number) => number; // 模块加载 -// [End node_api_module_add_api] - -// [Start node_api_module_create_object_properties_api] -export const createObjectWithProperties: (data: string) => Object; // ArkTS Object相关 napi_create_object_with_properties -// [End node_api_module_create_object_properties_api] - -// [Start node_api_module_create_object_name_properties_api] -export const createObjectWithNameProperties: (data: string) => string | { name: string }; // ArkTS Object相关 napi_create_object_with_named_properties -// [End node_api_module_create_object_name_properties_api] - -// [Start node_api_module_run_script_path_api] -export const runScriptPath: () => boolean; // 运行指定abc文件 napi_run_script_path -// [End node_api_module_run_script_path_api] -// [Start napi_coerce_to_native_binding_object_api] -// 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object -export const getAddress: () => number; - -export const getSetSize: () => number; - -export const store: (a: number) => void; - -export const erase: (a: number) => void; - -export const clear: () => void; -// [End napi_coerce_to_native_binding_object_api] - -// [Start napi_serialize_deserialize_delete_serialization_data_api] -export const aboutSerialize: (obj: Object) => number; // 序列化和反序列化 -// [End napi_serialize_deserialize_delete_serialization_data_api] - -// [Start napi_is_sendable_api] -export const isSendable: (a: T) => boolean; // Sendable相关 napi_is_sendable -// [End napi_is_sendable_api] - -// [Start napi_define_sendable_class_api] -@Sendable -export class SendableClass { - static staticStr: string; - static staticFunc(): string; - str: string; - func(): string; -} // Sendable相关 napi_define_sendable_class -// [End napi_define_sendable_class_api] - -// [Start napi_create_sendable_object_with_properties_api] -export const getSendableObject: () => { x: true }; // Sendable相关 napi_create_sendable_object_with_properties -// [End napi_create_sendable_object_with_properties_api] - -// [Start napi_create_sendable_array_api] -export const getSendableArray: () => []; // Sendable相关 napi_create_sendable_array -// [End napi_create_sendable_array_api] - -// [Start napi_create_sendable_array_with_length_api] -export const getSendableArrayWithLength: () => []; // Sendable相关 napi_create_sendable_array_with_length -// [End napi_create_sendable_array_with_length_api] - -// [Start napi_create_sendable_arraybuffer_api] -export const getSendableArrayBuffer: () => void; // Sendable相关 napi_create_sendable_arraybuffer -// [End napi_create_sendable_arraybuffer_api] - -// [Start napi_create_sendable_typed_array_api] -export const getSendableTypedArray: () => void; // Sendable相关 napi_create_sendable_typedarray -// [End napi_create_sendable_typed_array_api] - -// [Start napi_wrap_sendable_api] -export const wrapSendable: () => void; // Sendable相关 napi_wrap_sendable -// [End napi_wrap_sendable_api] - -// [Start napi_wrap_sendable_with_size_api] -export const wrapSendableWithSize: () => void; // Sendable相关 napi_wrap_sendable_with_size -// [End napi_wrap_sendable_with_size_api] - -// [Start napi_unwrap_sendable_api] -export const unwrapSendable: () => void; // Sendable相关 napi_unwrap_sendable -// [End napi_unwrap_sendable_api] - -// [Start napi_remove_wrap_sendable_api] -export const removeWrapSendable: () => void; // Sendable相关 napi_remove_wrap_sendable -// [End napi_remove_wrap_sendable_api] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index f1dc444030c2482a8a7d7531f058dee6c4d9d48d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,267 +0,0 @@ -/* - * 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 taskpool from '@ohos.taskpool'; - -// [Start ark_napi_coerce_to_native_binding_object] -@Concurrent -function getAddress() { - let address: number = testNapi.getAddress(); - console.info('taskpool:: address is' + address); -} - -@Concurrent -function store(a: number, b: number, c: number) { - let size: number = testNapi.getSetSize(); - console.info('set size is' + size + 'before store'); - testNapi.store(a); - testNapi.store(b); - testNapi.store(c); - size = testNapi.getSetSize(); - console.info('set size is' + size + 'after store'); -} - -@Concurrent -function erase(a: number) { - let size: number = testNapi.getSetSize(); - console.info('set size is' + size + 'before erase'); - testNapi.erase(a); - size = testNapi.getSetSize(); - console.info('set size is' + size + 'after erase'); -} - -@Concurrent -function clear() { - let size: number = testNapi.getSetSize(); - console.info('set size is' + size + 'before clear'); - testNapi.clear(); - size = testNapi.getSetSize(); - console.info('set size is' + size + 'after clear'); -} - -async function test01(): Promise { - let address: number = testNapi.getAddress(); - console.info('host thread address is' + address); - - let task1 = new taskpool.Task(getAddress); - await taskpool.execute(task1); - - let task2 = new taskpool.Task(store, 1, 2, 3); - await taskpool.execute(task2); - - let task3 = new taskpool.Task(store, 4, 5, 6); - await taskpool.execute(task3); - - let task4 = new taskpool.Task(erase, 3); - await taskpool.execute(task4); - - let task5 = new taskpool.Task(erase, 5); - await taskpool.execute(task5); - - let task6 = new taskpool.Task(clear); - await taskpool.execute(task6); -} -// [End ark_napi_coerce_to_native_binding_object] - -// [Start ark_napi_serialize_deserialize_delete_serialization_data] -class Obj { - numKey: number = 0; -} -// [StartExclude ark_napi_serialize_deserialize_delete_serialization_data] - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiLoadModule', - '2.napiCreateObjectWithProperties', - '3.napiCreateObjectWithNamedProperties', - '4.napiRunScriptPath', - '5.napiCoerceToNativeBindingObject', - '6.napiAboutSerialize', - '7.napiIsSendable', - '8.napiDefineSendableClass', - '9.napiCreateSendableObjectWithProperties', - '10.napiCreateSendableArray', - '11.napiCreateSendableArrayWithLength', - '12.napiCreateSendableArraybuffer', - '13.napiCreateSendableTypedArray', - '14.napiWrapSendable', - '15.napiWrapSendableWithSize', - '16.napiUnwrapSendable', - '17.napiRemoveWrapSendable' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(17) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiLoadModule') { - // [Start ark_node_api_module_add] - hilog.info(0x0000, 'testTag', 'Test Node-API 2 + 3 = %{public}d', testNapi.add(2, 3)); - // [End ark_node_api_module_add] - this.result = 'napiLoadModuleSuccess'; - } else if (item === '2.napiCreateObjectWithProperties') { - // [Start ark_node_api_module_create_object_properties] - // ArkTS Object相关 napi_create_object_with_properties - let value1 = testNapi.createObjectWithProperties('createObject'); - hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_properties:%{public}s', - JSON.stringify(value1)); - // [End ark_node_api_module_create_object_properties] - this.result = 'napiCreateObjectWithPropertiesSuccess'; - } else if (item === '3.napiCreateObjectWithNamedProperties') { - // [Start ark_node_api_module_create_object_name_properties] - // ArkTS Object相关 napi_create_object_with_named_properties - let value2 = testNapi.createObjectWithNameProperties('ls'); - hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_named_properties:%{public}s', - JSON.stringify(value2)); - // [End ark_node_api_module_create_object_name_properties] - this.result = 'napiCreateObjectWithNamedPropertiesSuccess'; - } else if (item === '4.napiRunScriptPath') { - // [Start ark_node_api_module_run_script_path] - // 运行指定abc文件 napi_run_script_path - try { // 在此处执行错误返回false,成功就返回true - hilog.info(0x0000, 'testTag', 'Test Node-API napi_run_script_path: %{public}s', - testNapi.runScriptPath()); - // [StartExclude ark_node_api_module_run_script_path] - this.result = 'napiRunScriptPathSuccess'; - // [EndExclude ark_node_api_module_run_script_path] - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_run_script_path errorMessage: %{public}s', - error.message); - // [StartExclude ark_node_api_module_run_script_path] - this.result = 'napiRunScriptPathFail'; - // [EndExclude ark_node_api_module_run_script_path] - } - // [End ark_node_api_module_run_script_path] - } else if (item === '5.napiCoerceToNativeBindingObject') { - // 给ArkTS对象绑定回调和回调所需的参数 napi_coerce_to_native_binding_object - test01(); - this.result = 'napiCoerceToNativeBindingObjectSuccess'; - } else if (item === '6.napiAboutSerialize') { - // [EndExclude ark_napi_serialize_deserialize_delete_serialization_data] - // 序列化和反序列化 - let obj: Obj = { numKey: 500 }; - hilog.info(0x0000, 'testTag', ' Node-API aboutSerialize: %{public}d', testNapi.aboutSerialize(obj)); - // [End ark_napi_serialize_deserialize_delete_serialization_data] - this.result = 'napiAboutSerializeSuccess'; - } else if (item === '7.napiIsSendable') { - // [Start ark_napi_is_sendable] - // Sendable相关 napi_is_sendable - let value = testNapi.isSendable('createObject'); - hilog.info(0x0000, 'testTag', 'Node-API napi_is_sendable: %{public}s', JSON.stringify(value)); - // [End ark_napi_is_sendable] - this.result = 'napiIsSendableSuccess'; - } else if (item === '8.napiDefineSendableClass') { - // [Start ark_napi_define_sendable_class] - // Sendable相关 napi_define_sendable_class - let value = new testNapi.SendableClass(); - hilog.info(0x0000, 'testTag', 'Node-API napi_define_sendable_class: %{public}s', value.str); - // [End ark_napi_define_sendable_class] - this.result = 'napiDefineSendableClassSuccess'; - } else if (item === '9.napiCreateSendableObjectWithProperties') { - // [Start ark_napi_create_sendable_object_with_properties] - // Sendable相关 napi_create_sendable_object_with_properties - let value = testNapi.getSendableObject(); - hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_object_with_properties: %{public}s', - JSON.stringify(value)); - // [End ark_napi_create_sendable_object_with_properties] - this.result = 'napiCreateSendableObjectWithPropertiesSuccess'; - } else if (item === '10.napiCreateSendableArray') { - // [Start ark_napi_create_sendable_array] - // Sendable相关 napi_create_sendable_array - let value = testNapi.getSendableArray(); - hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array: %{public}s', - JSON.stringify(value)); - // [End ark_napi_create_sendable_array] - this.result = 'napiCreateSendableArraySuccess'; - } else if (item === '11.napiCreateSendableArrayWithLength') { - // [Start ark_napi_create_sendable_array_with_length] - // Sendable相关 napi_create_sendable_array_with_length - let value = testNapi.getSendableArrayWithLength(); - hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array_with_length: %{public}s', - JSON.stringify(value.length)); - // [End ark_napi_create_sendable_array_with_length] - this.result = 'napiCreateSendableArrayWithLengthSuccess'; - } else if (item === '12.napiCreateSendableArraybuffer') { - // [Start ark_napi_create_sendable_arraybuffer] - // Sendable相关 napi_create_sendable_arraybuffer - testNapi.getSendableArrayBuffer(); - // [End ark_napi_create_sendable_arraybuffer] - this.result = 'napiCreateSendableArraybufferSuccess'; - } else if (item === '13.napiCreateSendableTypedArray') { - // [Start ark_napi_create_sendable_typed_array] - // Sendable相关 napi_create_sendable_typedarray - testNapi.getSendableTypedArray(); - // [End ark_napi_create_sendable_typed_array] - this.result = 'napiCreateSendableTypedArraySuccess'; - } else if (item === '14.napiWrapSendable') { - // [Start ark_napi_wrap_sendable] - // Sendable相关 napi_wrap_sendable - testNapi.wrapSendable(); - // [End ark_napi_wrap_sendable] - this.result = 'napiWrapSendableSuccess'; - } else if (item === '15.napiWrapSendableWithSize') { - // [Start ark_napi_wrap_sendable_with_size] - // Sendable相关 napi_wrap_sendable_with_size - testNapi.wrapSendableWithSize(); - // [End ark_napi_wrap_sendable_with_size] - this.result = 'napiWrapSendableWithSizeSuccess'; - } else if (item === '16.napiUnwrapSendable') { - // [Start ark_napi_unwrap_sendable] - // Sendable相关 napi_unwrap_sendable - testNapi.unwrapSendable(); - // [End ark_napi_unwrap_sendable] - this.result = 'napiUnwrapSendableSuccess'; - } else if (item === '17.napiRemoveWrapSendable') { - // [Start ark_napi_remove_wrap_sendable] - // Sendable相关 napi_remove_wrap_sendable - testNapi.removeWrapSendable(); - // [End ark_napi_remove_wrap_sendable] - this.result = 'napiRemoveWrapSendableSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - .id('List') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/ohosTest.md deleted file mode 100755 index 32212f4447f4ae863dc6b0822e5c27028e7aac40..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIExtendCapabilities/ohosTest.md +++ /dev/null @@ -1,23 +0,0 @@ -# 使用Node-API进行扩展能力功能开发测试用例归档 - -## 用例表 - -| 测试功能 | 预 置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------------------ | ------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 createObjectWithProperties | 位于主页 | 点击文本为1.napiCreateObjectWithProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateObjectWithPropertiesSuccess | Pass | -| ArkTS端成功调用native侧接口createObjectWithNameProperties | 位于主页 | 点击文本为2.napiCreateObjectWithNamedProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateObjectWithNamedPropertiesSuccess | Pass | -| ArkTS端成功调用native侧接口runScriptPath | 位于主页 | 点击文本为3.napiRunScriptPath的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRunScriptPathSuccess | Pass | -| ArkTS端成功调用native侧接口getAddress,getSetSize,store,erase,clear | 位于主页 | 点击文本为4.napiCoerceToNativeBindingObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToNativeBindingObjectSuccess | Pass | -| ArkTS端成功调用native侧接口aboutSerialize | 位于主页 | 点击文本为5.napiAboutSerialize的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiAboutSerializeSuccess | Pass | -| ArkTS端成功调用native侧接口isSendable | 位于主页 | 点击文本为6.napiIsSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsSendableSuccess | Pass | -| ArkTS端成功调用native侧接口SendableClass | 位于主页 | 点击文本为7.napiDefineSendableClass的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDefineSendableClassSuccess | Pass | -| ArkTS端成功调用native侧接口getSendableObject | 位于主页 | 点击文本为8.napiCreateSendableObjectWithProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableObjectWithPropertiesSuccess | Pass | -| ArkTS端成功调用native侧接口getSendableArray | 位于主页 | 点击文本为9.napiCreateSendableArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableArraySuccess | Pass | -| ArkTS端成功调用native侧接口getSendableArrayWithLength | 位于主页 | 点击文本为10.napiCreateSendableArrayWithLength的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableArrayWithLengthSuccess | Pass | -| ArkTS端成功调用native侧接口getSendableArrayBuffer | 位于主页 | 点击文本为11.napiCreateSendableArraybuffer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableArraybufferSuccess | Pass | -| ArkTS端成功调用native侧接口getSendableTypedArray | 位于主页 | 点击文本为12.napiCreateSendableTypedArray的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSendableTypedArraySuccess | Pass | -| ArkTS端成功调用native侧接口wrapSendable | 位于主页 | 点击文本为13.napiWrapSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiWrapSendableSuccess | Pass | -| ArkTS端成功调用native侧接口wrapSendableWithSize | 位于主页 | 点击文本为14.napiWrapSendableWithSize的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiWrapSendableWithSizeSuccess | Pass | -| ArkTS端成功调用native侧接口unwrapSendable | 位于主页 | 点击文本为15.napiUnwrapSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiUnwrapSendableSuccess | Pass | -| ArkTS端成功调用native侧接口removeWrapSendable | 位于主页 | 点击文本为16.napiRemoveWrapSendable的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiRemoveWrapSendableSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/app.json5 deleted file mode 100755 index 6550eba95dce4715602fce1f09d30fce25c98f48..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapifunction", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/element/string.json deleted file mode 100755 index ac005ab95065f2305cf6bb5bca6451101e0d5bb7..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIFunction" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/README.md deleted file mode 100755 index 2a7785e1568c279c30cf54a835ac345892758626..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行function相关开发 - -### 介绍 - -函数调用允许开发者从Node-API模块中调用ArkTS函数,并传递参数进行调用,或者直接在Node-API模块中创建一个ArkTS方法,本工程中展示的代码详细描述可查如下链接。 - -- [使用Node-API进行function相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-function.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIFunction.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行function相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIFunction.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 11eb088d96d7cd3300eb4c11d56f87cb7a4d0552..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIFunctio) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 22cb880f7b51477e0721a2532696abb6d89ea750..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_get_cb_info] -#include "napi/native_api.h" - -// napi_get_cb_info -// 获取ArkTS侧入参的的参数信息 -static napi_value GetCbArgs(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - return args[0]; -} - -// 获取ArkTS侧入参的参数个数 -static napi_value GetCbArgQuantity(napi_env env, napi_callback_info info) -{ - size_t argc = 0; - napi_value result = nullptr; - napi_get_cb_info(env, info, &argc, nullptr, nullptr, nullptr); - napi_create_int32(env, argc, &result); - return result; -} - -// 获取ArkTS侧this参数 -static napi_value GetCbContext(napi_env env, napi_callback_info info) -{ - napi_value thisArg = nullptr; - napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, nullptr); - return thisArg; -} -// [End napi_get_cb_info] - -// [Start napi_call_function] -// napi_call_function -static napi_value CallFunction(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value argv[1] = {nullptr}; - // 获取ArkTS侧入参 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 获取全局对象,这里用global是因为napi_call_function的第二个参数是JS函数的this入参。 - napi_value global = nullptr; - napi_get_global(env, &global); - // 调用ArkTS方法 - napi_value result = nullptr; - // 调用napi_call_function时传入的argv的长度必须大于等于argc声明的数量,且被初始化成nullptr - napi_call_function(env, global, argv[0], argc, argv, &result); - return result; -} - -static napi_value ObjCallFunction(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传递的两个参数 - size_t argc = 2; - napi_value argv[2] = {nullptr}; - // 获取ArkTS侧入参 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 调用ArkTS方法 - napi_value result = nullptr; - // 调用napi_call_function时传入的argv的长度必须大于等于argc声明的数量,且被初始化成nullptr - napi_call_function(env, argv[0], argv[1], argc, argv, &result); - return result; -} -// [End napi_call_function] - -// [Start napi_create_function] -// napi_create_function -static napi_value CalculateArea(napi_env env, napi_callback_info info) -{ - // 获取ArkTS侧传递的两个参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - double width = 0; - napi_get_value_double(env, args[0], &width); - double height = 0; - napi_get_value_double(env, args[1], &height); - napi_value area = nullptr; - napi_create_double(env, width * height, &area); - return area; -} -// [End napi_create_function] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getCbArgs", nullptr, GetCbArgs, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getCbArgQuantity", nullptr, GetCbArgQuantity, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getCbContext", nullptr, GetCbContext, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"callFunction", nullptr, CallFunction, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"objCallFunction", nullptr, ObjCallFunction, nullptr, nullptr, nullptr, napi_default, nullptr}}; - napi_value fn = nullptr; - napi_create_function(env, nullptr, 0, CalculateArea, nullptr, &fn); - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - napi_set_named_property(env, exports, "calculateArea", fn); - 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index ceacdececee0e5fa1b91eef00e7d814a977edafa..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_get_cb_info_api] -export const getCbArgs: (arg: T) => T; // napi_get_cb_info - -// getCbArgQuantity的入参由用户自定义,在此用例中,我们用两个入参,一个是string,一个是number -export const getCbArgQuantity: (str: string, num: number) => number; - -export const getCbContext: () => Object; -// [End napi_get_cb_info_api] - -// [Start napi_call_function_api] -export const callFunction: (func: Function) => number; // napi_call_function - -export const objCallFunction: (obj: Object, func: Function) => number; -// [End napi_call_function_api] - -// [Start napi_create_function_api] -export const calculateArea: (width: number, height: number) => number; // napi_create_function -// [End napi_create_function_api] diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 1734ab6667ce6688a375971976dc3382d9f47505..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start ark_napi_get_cb_info] -import { hilog } from '@kit.PerformanceAnalysisKit'; -import testNapi from 'libentry.so'; - -function summation(arr: Array) { - let sum: number = 0; - for (let i = 0; i < arr.length; i++) { - sum += arr[i]; - } - return sum; -} - -const str = 'message'; -const arr = [0, 1, 2, 3, 4, 5]; -const num = 526; - -class Student { - name: string; - age: number; - score: number; - - constructor(name: string, age: number, score: number) { - this.name = name; - this.age = age; - this.score = score; - } -} - -// [StartExclude ark_napi_get_cb_info] -// [Start ark_napi_call_function] -function returnNumber() { - return 10; -} - -class Person { - age(): number { - return 11; - } -} - -// [StartExclude ark_napi_call_function] -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiGetCbInfo', - '2.napiCallFunction', - '3.napiCreateFunction' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(25) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiGetCbInfo') { - // [EndExclude ark_napi_get_cb_info] - // napi_get_cb_info - let student = new Student('Alice', 18, 100); - // 获取参数 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get string arg:%{public}s', - testNapi.getCbArgs(str)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get array arg:%{public}s ', - testNapi.getCbArgs(arr).toString()); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get num arg:%{public}d ', - testNapi.getCbArgs(num)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get undefined arg:%{public}s ', - testNapi.getCbArgs(undefined)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get object arg:%{public}s ', - JSON.stringify(testNapi.getCbArgs(student))); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get function arg:%{public}d ', - testNapi.getCbArgs(summation(arr))); - // 获取参数个数 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get arg quantity:%{public}d ', - testNapi.getCbArgQuantity(str, num)); - // 获取上下文 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_cb_info get thisArg:%{public}s ', - testNapi.getCbContext().toString()); - // [End ark_napi_get_cb_info] - this.result = 'napiGetCbInfoSuccess'; - } else if (item === '2.napiCallFunction') { - // [EndExclude ark_napi_call_function] - // napi_call_function - const person = new Person(); - hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', - testNapi.callFunction(returnNumber)); - hilog.info(0x0000, 'testTag', 'Test Node-API call_function:%{public}d', - testNapi.objCallFunction(person, person.age)); - // [End ark_napi_call_function] - this.result = 'napiCallFunctionSuccess'; - } else if (item === '3.napiCreateFunction') { - // [Start ark_napi_create_function] - // napi_create_function - hilog.info(0x0000, 'testTag', 'Test Node-API create_function:%{public}d ', - testNapi.calculateArea(1.2, 4)); - // [End ark_napi_create_function] - this.result = 'napiCreateFunctionSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIFunction/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/ohosTest.md deleted file mode 100755 index 55d56487abcf3bc6ab46d6d311aee566bd5f348f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIFunction/ohosTest.md +++ /dev/null @@ -1,10 +0,0 @@ -# 使用Node-API进行function相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 getCbArgs,getCbArgQuantity,getCbContext | 位于主页 | 点击文本为1.napiGetCbInfo的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetCbInfoSuccess | Pass | -| ArkTS端成功调用native侧接口callFunction,objCallFunction | 位于主页 | 点击文本为2.napiCallFunction的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCallFunctionSuccess | Pass | -| ArkTS端成功调用native侧接口calculateArea | 位于主页 | 点击文本为3.napiCreateFunction的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateFunctionSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/app.json5 deleted file mode 100755 index 0f394f428104cbcdd9b98235fd015506596deecf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapilifecycle", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/element/string.json deleted file mode 100755 index 76f1edf47c885cbb3b6d2edcb5a8d383dcfd8fc2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPILifeCycle" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/README.md deleted file mode 100755 index 3a95e5bfa439574c1809b75032b97605d7ace272..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行life-cycle相关开发 - -### 介绍 - -在Node-API中,napi_value是一个表示ArkTS值的抽象类型,它可以表示任何ArkTS值,包括基本类型(如数字、字符串、布尔值)和复杂对象类型(如数组、函数、对象等),napi_value的生命周期与其在ArkTS中的对应值的生命周期紧密相关。当ArkTS值被垃圾回收时,与之关联的napi_value也将不再有效。重要的是不要在ArkTS值不再存在时尝试使用napi_value,框架层的scope通常用于管理napi_value的生命周期。在Node-API中,可以使用napi_open_handle_scope和napi_close_handle_scope函数来创建和销毁scope。通过在scope内创建napi_value,可以确保在scope结束时自动释放napi_value,避免内存泄漏,napi_ref是一个Node-API类型,用于管理napi_value的生命周期。napi_ref允许您在napi_value的生命周期内保持对其的引用,即使它已经超出了其原始上下文的范围。这使得您可以在不同的上下文中共享napi_value,并确保在不再需要时正确释放其内存,本工程中展示的代码详细描述可查如下链接。 - -- [使用Node-API进行life-cycle相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-life-cycle.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPILifeCycle.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行life-cycle相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPILifeCycle.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 9cb24a5a1f025237dea1545c126a5c6b95294db8..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPILifeCycle) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index cdc6424c3e792be4a362d4808b767d9d74594fb4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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 "hilog/log.h" -#include "napi/native_api.h" - -// [Start napi_open_close_handle_scope] -// napi_open_handle_scope、napi_close_handle_scope -static napi_value HandleScopeTest(napi_env env, napi_callback_info info) -{ - // 通过调用napi_open_handle_scope来创建一个句柄作用域 - napi_handle_scope scope; - napi_open_handle_scope(env, &scope); - // 在句柄作用域内创建一个obj - napi_value obj = nullptr; - napi_create_object(env, &obj); - // 在对象中添加属性 - napi_value value = nullptr; - napi_create_string_utf8(env, "handleScope", NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, obj, "key", value); - // 在作用域内获取obj的属性并返回 - napi_value result = nullptr; - napi_get_named_property(env, obj, "key", &result); - // 关闭句柄作用域,自动释放在该作用域内创建的对象句柄 - napi_close_handle_scope(env, scope); - // 此处的result能够得到值“handleScope” - return result; -} - -static napi_value HandleScope(napi_env env, napi_callback_info info) -{ - // 通过调用napi_open_handle_scope来创建一个句柄作用域 - napi_handle_scope scope; - napi_open_handle_scope(env, &scope); - // 在句柄作用域内创建一个obj - napi_value obj = nullptr; - napi_create_object(env, &obj); - // 在对象中添加属性 - napi_value value = nullptr; - napi_create_string_utf8(env, "handleScope", NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, obj, "key", value); - // 关闭句柄作用域,自动释放在该作用域内创建的对象句柄 - napi_close_handle_scope(env, scope); - // 在作用域外获取obj的属性并返回,此处只能得到“undefined” - napi_value result = nullptr; - napi_get_named_property(env, obj, "key", &result); - return result; -} -// [End napi_open_close_handle_scope] - -// [Start napi_open_close_escapable_handle_scope] -// napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle -static napi_value EscapableHandleScopeTest(napi_env env, napi_callback_info info) -{ - // 创建一个可逃逸的句柄作用域 - napi_escapable_handle_scope scope; - napi_open_escapable_handle_scope(env, &scope); - // 在可逃逸的句柄作用域内创建一个obj - napi_value obj = nullptr; - napi_create_object(env, &obj); - // 在对象中添加属性 - napi_value value = nullptr; - napi_create_string_utf8(env, "Test napi_escapable_handle_scope", NAPI_AUTO_LENGTH, &value); - napi_set_named_property(env, obj, "key", value); - // 调用napi_escape_handle将对象逃逸到作用域之外 - napi_value escapedObj = nullptr; - napi_escape_handle(env, scope, obj, &escapedObj); - // 关闭可逃逸的句柄作用域,清理资源 - napi_close_escapable_handle_scope(env, scope); - // 在获取逃逸后的obj:escapedObj的属性并返回,此处也能够得到“napi_escapable_handle_scope” - napi_value result = nullptr; - // 为了验证逃逸的实现,可以在此处获取obj的属性,此处会得到“undefined” - napi_get_named_property(env, escapedObj, "key", &result); - return result; -} -// [End napi_open_close_escapable_handle_scope] - -// [Start napi_create_delete_reference] -// 创建一个指向napi_ref类型的指针,用于存储创建的引用。在调用napi_create_reference函数之前,你需要分配一个napi_ref类型的变量,并将其地址传递给result位置的参数 -napi_ref g_ref; - -void Finalizer(napi_env env, void *data, void *hint) -{ - // 执行资源清理操作 - OH_LOG_INFO(LOG_APP, "Node-API: Use terminators to release resources."); -} - -static napi_value CreateReference(napi_env env, napi_callback_info info) -{ - napi_value obj = nullptr; - napi_create_object(env, &obj); - napi_value value = nullptr; - napi_create_string_utf8(env, "CreateReference", NAPI_AUTO_LENGTH, &value); - // 将键值对添加到对象中 - napi_set_named_property(env, obj, "key", value); - // [StartExclude napi_create_delete_reference] - // 创建对ArkTS对象的引用 - napi_status status = napi_create_reference(env, obj, 1, &g_ref); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_create_reference fail"); - return nullptr; - } - // [EndExclude napi_create_delete_reference] - // 添加终结器 - void *data = {}; - napi_add_finalizer(env, obj, data, Finalizer, nullptr, &g_ref); - // 增加传入引用的引用计数并返回生成的引用计数 - uint32_t result = 0; - napi_reference_ref(env, g_ref, &result); - OH_LOG_INFO(LOG_APP, "napi_reference_ref, count = %{public}d.", result); - uint32_t numCount = 2; - if (result != numCount) { - // 若传入引用的引用计数未增加,则抛出错误 - napi_throw_error(env, nullptr, "napi_reference_ref fail"); - return nullptr; - } - return obj; -} - -static napi_value UseReference(napi_env env, napi_callback_info info) -{ - napi_value obj = nullptr; - // 通过调用napi_get_reference_value获取引用的ArkTS对象 - napi_status status = napi_get_reference_value(env, g_ref, &obj); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_get_reference_value fail"); - return nullptr; - } - // 将获取到的对象返回 - return obj; -} - -static napi_value DeleteReference(napi_env env, napi_callback_info info) -{ - // 减少传入引用的引用计数并返回生成的引用计数 - uint32_t result = 0; - napi_value count = nullptr; - napi_reference_unref(env, g_ref, &result); - OH_LOG_INFO(LOG_APP, "napi_reference_ref, count = %{public}d.", result); - uint32_t numCount = 1; - if (result != numCount) { - // 若传入引用的引用计数未减少,则抛出错误 - napi_throw_error(env, nullptr, "napi_reference_unref fail"); - return nullptr; - } - // 通过调用napi_delete_reference删除对ArkTS对象的引用 - napi_status status = napi_delete_reference(env, g_ref); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_delete_reference fail"); - return nullptr; - } - napi_value returnResult = nullptr; - napi_create_string_utf8(env, "napi_delete_reference success", NAPI_AUTO_LENGTH, &returnResult); - return returnResult; -} -// [End napi_create_delete_reference] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"handleScopeTest", nullptr, HandleScopeTest, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"handleScope", nullptr, HandleScope, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"escapableHandleScopeTest", nullptr, EscapableHandleScopeTest, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"createReference", nullptr, CreateReference, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"useReference", nullptr, UseReference, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"deleteReference", nullptr, DeleteReference, 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 23c45532e0d4bed5dffbb8066daa7914739182ef..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_open_close_handle_scope_api] -export const handleScopeTest: () => string; // napi_open_handle_scope、napi_close_handle_scope - -export const handleScope: () => string; -// [End napi_open_close_handle_scope_api] - -// [Start napi_open_close_escapable_handle_scope_api] -export const escapableHandleScopeTest: () => string; // napi_open_escapable_handle_scope、napi_close_escapable_handle_scope、napi_escape_handle -// [End napi_open_close_escapable_handle_scope_api] - -// [Start napi_create_delete_reference_api] -export const createReference: () => Object | void; // napi_add_finalizer - -export const useReference: () => Object | void; - -export const deleteReference: () => string | void; -// [End napi_create_delete_reference_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 4d86ca8563117a28404d3a418541002143cdd23e..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiOpenHandleScope', - '2.napiOpenEscapableHandleScope', - '3.napiAddFinalizer' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiOpenHandleScope') { - // [Start ark_napi_open_close_handle_scope] - // napi_open_handle_scope napi_close_handle_scope - try { - hilog.info(0x0000, 'testTag', 'Test Node-API handleScopeTest: %{public}s', - testNapi.handleScopeTest()); - hilog.info(0x0000, 'testTag', 'Test Node-API handleScope: %{public}s', testNapi.handleScope()); - // [StartExclude ark_napi_open_close_handle_scope] - this.result = 'napiOpenHandleScopeSuccess'; - // [EndExclude ark_napi_open_close_handle_scope] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API handleScopeTest errorCode: %{public}s, errorMessage: %{public}s', error.code, - error.message); - // [StartExclude ark_napi_open_close_handle_scope] - this.result = 'napiOpenHandleScopeFail'; - // [EndExclude ark_napi_open_close_handle_scope] - } - // [End ark_napi_open_close_handle_scope] - } else if (item === '2.napiOpenEscapableHandleScope') { - // [Start ark_napi_open_close_escapable_handle_scope] - // napi_open_escapable_handle_scope napi_close_escapable_handle_scope、napi_escape_handle - try { - hilog.info(0x0000, 'testTag', 'Test Node-API EscapableHandleScopeTest: %{public}s', - testNapi.escapableHandleScopeTest()); - // [StartExclude ark_napi_open_close_escapable_handle_scope] - this.result = 'napiOpenEscapableHandleScopeSuccess'; - // [EndExclude ark_napi_open_close_escapable_handle_scope] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API EscapableHandleScopeTest errorCode: %{public}s, errorMessage: %{public}s', - error.code, - error.message); - // [StartExclude ark_napi_open_close_escapable_handle_scope] - this.result = 'napiOpenEscapableHandleScopeFail'; - // [EndExclude ark_napi_open_close_escapable_handle_scope] - } - // [End ark_napi_open_close_escapable_handle_scope] - } else if (item === '3.napiAddFinalizer') { - // [Start ark_napi_create_delete_reference] - // napi_add_finalizer - try { - hilog.info(0x0000, 'testTag', 'Test Node-API createReference: %{public}s', - JSON.stringify(testNapi.createReference())); - hilog.info(0x0000, 'testTag', 'Test Node-API useReference: %{public}s', - JSON.stringify(testNapi.useReference())); - hilog.info(0x0000, 'testTag', 'Test Node-API deleteReference: %{public}s', - testNapi.deleteReference()); - // [StartExclude ark_napi_create_delete_reference] - this.result = 'napiAddFinalizerSuccess'; - // [EndExclude ark_napi_create_delete_reference] - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API ReferenceTest errorCode: %{public}s, errorMessage: %{public}s', error.code, - error.message); - // [StartExclude ark_napi_create_delete_reference] - this.result = 'napiAddFinalizerFail'; - // [EndExclude ark_napi_create_delete_reference] - } - // [End ark_napi_create_delete_reference] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPILifeCycle/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/ohosTest.md deleted file mode 100755 index da6467447e249a51fbfcb50a099d00cb890684cf..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPILifeCycle/ohosTest.md +++ /dev/null @@ -1,10 +0,0 @@ -# 使用Node-API进行life-cycle相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 handleScopeTest,handleScope | 位于主页 | 点击文本为1.napiOpenHandleScope的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiOpenHandleScopeSuccess | Pass | -| ArkTS端成功调用native侧接口createArrayWithLength | 位于主页 | 点击文本为2.escapableHandleScopeTest的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiOpenEscapableHandleScopeSuccess | Pass | -| ArkTS端成功调用native侧接口createReference,useReference,deleteReference | 位于主页 | 点击文本为3.napiAddFinalizer的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiAddFinalizerSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/app.json5 deleted file mode 100755 index c0e25e886aecbd16b100c4b70de4045467cc5148..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiobject", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/element/string.json deleted file mode 100755 index 6177c3d7c8873d65727a4e4144ace6e596afbe73..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIObject" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/README.md deleted file mode 100755 index dcffc96cc1095bc06b1851c9fed04dd9a8621680..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行object相关开发 - -### 介绍 - -使用Node-API接口进行object相关开发,处理ArkTS对象的基本操作的功能,例如创建对象、获取原型、冻结和密封对象,检查对象的类型等。这些操作是在处理ArkTS对象时非常常见的,提供了一种与ArkTS对象交互的方式,本工程中展示的代码详细描述可查如下链接。 - -- [使用Node-API进行object相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-object.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIObject.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行object相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIObject.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIObject/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 63f331b9285eca649c56038921fd05a062e63207..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIObject) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index e5259d2a34d8dd3bdb33e0e81f00fe7a922bccf6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * 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 -#include -#include "hilog/log.h" -#include "napi/native_api.h" - -// napi_get_prototype -static napi_value GetPrototype(napi_env env, napi_callback_info info) -{ - // 获取并解析传参 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_value result = nullptr; - // 获取此对象的原型对象,将结果返回到napi_value类型的变量result中 - napi_get_prototype(env, args[0], &result); - return result; -} -// napi_create_object -napi_value NewObject(napi_env env, napi_callback_info info) -{ - napi_value object = nullptr; - // 创建一个空对象 - napi_create_object(env, &object); - // 设置对象的属性 - napi_value name = nullptr; - // 设置属性名为"name" - napi_create_string_utf8(env, "name", NAPI_AUTO_LENGTH, &name); - napi_value value = nullptr; - // 设置属性值为"Hello from Node-API!" - napi_create_string_utf8(env, "Hello from Node-API!", NAPI_AUTO_LENGTH, &value); - // 将属性设置到对象上 - napi_set_property(env, object, name, value); - return object; -} -// napi_object_freeze -static napi_value ObjectFreeze(napi_env env, napi_callback_info info) -{ - // 接受一个ArkTS侧传入的object - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - - // 调用接口napi_object_freeze将传入的object冻结 - napi_value objFreeze = argv[0]; - napi_status status = napi_object_freeze(env, objFreeze); - if (status == napi_ok) { - OH_LOG_INFO(LOG_APP, "Node-API napi_object_freeze success"); - } - // 将冻结后的object传回ArkTS侧 - return objFreeze; -} -// napi_object_seal -static napi_value ObjectSeal(napi_env env, napi_callback_info info) -{ - // 接受一个ArkTS侧传入的object - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 调用接口napi_object_seal将传入的object封闭,使其无法添加新的属性 - napi_value objSeal = argv[0]; - napi_status status = napi_object_seal(env, objSeal); - if (status == napi_ok) { - OH_LOG_INFO(LOG_APP, "Node-API napi_object_seal success"); - } - // 将封闭后的object传回ArkTS侧 - return objSeal; -} -// napi_typeof -static napi_value NapiTypeof(napi_env env, napi_callback_info info) -{ - // 接受一个入参 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 调用napi_typeof判断传入ArkTS参数类型 - napi_valuetype valueType; - napi_status status = napi_typeof(env, args[0], &valueType); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_typeof fail"); - return nullptr; - } - // 将结果转成napi_value类型返回。 - napi_value returnValue = nullptr; - switch (valueType) { - case napi_undefined: - napi_create_string_utf8(env, "Input type is napi_undefined", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_null: - napi_create_string_utf8(env, "Input type is napi_null", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_boolean: - napi_create_string_utf8(env, "Input type is napi_boolean", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_number: - napi_create_string_utf8(env, "Input type is napi_number", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_string: - napi_create_string_utf8(env, "Input type is napi_string", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_object: - napi_create_string_utf8(env, "Input type is napi_object", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_function: - napi_create_string_utf8(env, "Input type is napi_function", NAPI_AUTO_LENGTH, &returnValue); - break; - case napi_bigint: - napi_create_string_utf8(env, "Input type is napi_bigint", NAPI_AUTO_LENGTH, &returnValue); - break; - default: - napi_create_string_utf8(env, "unknown", NAPI_AUTO_LENGTH, &returnValue); - } - return returnValue; -} -// napi_instanceof -static napi_value NapiInstanceof(napi_env env, napi_callback_info info) -{ - // 接受两个入参 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 调用napi_instanceof接口判断给定object是否为给定constructor的实例 - bool result = true; - napi_status status = napi_instanceof(env, args[0], args[1], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_instanceof fail"); - return nullptr; - } - // 将结果转成napi_value类型返回 - napi_value returnValue = nullptr; - napi_get_boolean(env, result, &returnValue); - - return returnValue; -} - -#define NUMBERINT_FOUR 4 -// 定义一个静态常量napi_type_tag数组存储类型标签 -static const napi_type_tag TagsData[NUMBERINT_FOUR] = { - {0x9e4b2449547061b3, 0x33999f8a6516c499}, - {0x1d55a794c53a726d, 0x43633f509f9c944e}, - // 用于表示无标签或默认标签 - {0, 0}, - {0x6a971439f5b2e5d7, 0x531dc28a7e5317c0}, -}; -// napi_type_tag_object -static napi_value SetTypeTagToObject(napi_env env, napi_callback_info info) -{ - // 获取函数调用信息和参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取索引数字转换为napi_value - int32_t index = 0; - napi_get_value_int32(env, args[1], &index); - // 给参数(对象)设置类型标签 - napi_status status = napi_type_tag_object(env, args[0], &TagsData[index]); - if (status != napi_ok) { - napi_throw_error(env, "Reconnect error", "napi_type_tag_object failed"); - return nullptr; - } - // 将bool结果转换为napi_value并返回 - napi_value result = nullptr; - napi_get_boolean(env, true, &result); - return result; -} -// napi_check_object_type_tag -static napi_value CheckObjectTypeTag(napi_env env, napi_callback_info info) -{ - // 获取函数调用信息和参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取索引数字转换为napi_value - int32_t index = 0; - napi_get_value_int32(env, args[1], &index); - // 检查对象的类型标签 - bool checkResult = true; - napi_check_object_type_tag(env, args[0], &TagsData[index], &checkResult); - // 将bool结果转换为napi_value并返回 - napi_value checked = nullptr; - napi_get_boolean(env, checkResult, &checked); - - return checked; -} - -// 用于释放外部数据的回调函数 -void finalizeCallback(napi_env env, void *data, void *hint) -{ - // 释放外部数据 - free(data); -} -// napi_create_external -static napi_value GetExternalType(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取参数的数据类型 - napi_valuetype valueType; - napi_typeof(env, args[0], &valueType); - napi_value returnValue = nullptr; - if (valueType == napi_external) { - // 如果数据类型是napi_external,则返回true - napi_get_boolean(env, true, &returnValue); - } else { - napi_get_boolean(env, false, &returnValue); - } - return returnValue; -} - -static napi_value CreateExternal(napi_env env, napi_callback_info info) -{ - // 设置外部数据大小为10 - const size_t dataSize = 10; - // 分配外部数据 - void *data = malloc(dataSize); - // 初始化外部数据 - memset(data, 0, dataSize); - napi_value result = nullptr; - // 返回带有外部数据的对象 - napi_status status = napi_create_external(env, data, finalizeCallback, nullptr, &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, " Node-API Failed to create external data"); - return nullptr; - } - return result; -} -// napi_get_value_external -static int g_external = 5; -static napi_value GetValueExternal(napi_env env, napi_callback_info info) -{ - // 创建外部数据 - int *data = &g_external; - napi_value setExternal = nullptr; - napi_create_external(env, data, nullptr, nullptr, &setExternal); - // 获得外部数据的值 - void *getExternal; - napi_get_value_external(env, setExternal, &getExternal); - // 返回获得到的外部数据 - napi_value result = nullptr; - napi_create_int32(env, *(int *)getExternal, &result); - return result; -} -// napi_create_symbol -static napi_value CreateSymbol(napi_env env, napi_callback_info info) -{ - napi_value result = nullptr; - const char *des = "only"; - // 使用napi_create_string_utf8创建描述字符串 - napi_create_string_utf8(env, des, NAPI_AUTO_LENGTH, &result); - napi_value returnSymbol = nullptr; - // 创建一个symbol类型,并返回 - napi_create_symbol(env, result, &returnSymbol); - return returnSymbol; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getPrototype", nullptr, GetPrototype, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createObject", nullptr, NewObject, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"objectFreeze", nullptr, ObjectFreeze, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"objectSeal", nullptr, ObjectSeal, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiTypeof", nullptr, NapiTypeof, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiInstanceof", nullptr, NapiInstanceof, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"setTypeTagToObject", nullptr, SetTypeTagToObject, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"checkObjectTypeTag", nullptr, CheckObjectTypeTag, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createExternal", nullptr, GetExternalType, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getExternalType", nullptr, CreateExternal, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueExternal", nullptr, GetValueExternal, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createSymbol", nullptr, CreateSymbol, 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 8a29db27527eb2437e6a7d1a7ef00746370ad6c1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 getPrototype: (object: Object) => Object; // napi_get_prototype - -export const createObject: () => { name: string }; // napi_create_object - -export interface Obj { - data: number - message: string -} - -export const objectFreeze: (objFreeze: Object) => Obj; // napi_object_freeze - -export interface Obj1 { - data: number - message: string - id: number -} - -export const objectSeal: (objSeal: Object) => Obj1; // napi_object_seal - -export const napiTypeof: (value: T) => string | void; // napi_typeof - -export const napiInstanceof: (date: Object, construct: Object) => boolean | void; // napi_instanceof - -export const setTypeTagToObject: (obj: Object, index: number) => boolean | void; // napi_type_tag_object - -export const checkObjectTypeTag: (obj: Object, index: number) => boolean; // napi_check_object_type_tag - -export const createExternal: () => Object; // napi_create_external - -export const getExternalType: (externalData: Object) => boolean; // napi_create_external - -export const getValueExternal: () => number; // napi_get_value_external - -export const createSymbol: () => symbol; // napi_create_symbol \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 42e73a977b7882433509916aae0e81de7a6ca8c2..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,234 +0,0 @@ -/* - * 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 { napiGetPrototype } from './napiGetPrototype'; - -// 定义一个类 -class Person { - // 属性 - name: string; - age: number; - - // 构造函数 - constructor(name: string, age: number) { - this.name = name; - this.age = age; - } -} - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiGetPrototype', - '2.napiCreateObject', - '3.napiObjectFreeze', - '4.napiObjectSeal', - '5.napiTypeof', - '6.napiInstanceof', - '7.napiTypeTagObject', - '8.napiCreateExternal', - '9.napiGetValueExternal', - '10.napiCreateSymbol' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(22) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiGetPrototype') { - napiGetPrototype(); - this.result = 'napiGetPrototypeSuccess'; - } else if (item === '2.napiCreateObject') { - // napi_create_object - try { - const myObject = testNapi.createObject(); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_object: %{public}s', myObject.name); - this.result = 'napiCreateObjectSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', - 'Test Node-API napi_create_object errorCode: %{public}s, errorMessage: %{public}s', error.code, - error.message); - this.result = 'napiCreateObjectFail'; - } - } else if (item === '3.napiObjectFreeze') { - // napi_object_freeze - try { - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - let objFreeze = testNapi.objectFreeze(obj); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_freeze: %{public}s', (objFreeze.data = 1)); - this.result = 'napiObjectFreezeSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_object_freeze error: %{public}s', error.message); - this.result = 'napiObjectFreezeFail'; - } - } else if (item === '4.napiObjectSeal') { - // napi_object_seal - try { - class Obj { - public data: number = 0 - public message: string = '' - // 可选属性 - public address?: number = 0 - } - - let obj: Obj = { data: 0, message: 'hello world' }; - let objSeal = testNapi.objectSeal(obj); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_seal: %{public}s', objSeal.message); - objSeal.data = 1; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_seal: %{public}d', objSeal.data); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_object_seal: %{public}d', (objSeal.id = 1)); - this.result = 'napiObjectSealSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_object_seal error: %{public}s', error.message); - this.result = 'napiObjectSealFail'; - } - } else if (item === '5.napiTypeof') { - // napi_typeof - try { - let varUndefined: undefined; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', - testNapi.napiTypeof(varUndefined)); - let varNull: null = null; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', - testNapi.napiTypeof(varNull)); - let varTrue = true; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', - testNapi.napiTypeof(varTrue)); - let varNum = 1; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', testNapi.napiTypeof(varNum)); - let varString = 'str'; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', - testNapi.napiTypeof(varString)); - - class Obj { - public id: number = 0 - public name: string = '' - } - - let varObject: Obj = { id: 1, name: 'LiLei' }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', - testNapi.napiTypeof(varObject)); - const addNum = (a: number, b: number): number => a * b; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', testNapi.napiTypeof(addNum)); - let varBigint = BigInt('1234567890123456789012345678901234567890'); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_typeof: %{public}s', - testNapi.napiTypeof(varBigint)); - this.result = 'napiTypeofSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_typeof error: %{public}s', error.message); - this.result = 'napiTypeofFail'; - } - } else if (item === '6.napiInstanceof') { - // napi_instanceof - try { - class Person { - public name: string; - public age: number; - - constructor(name: string, age: number) { - this.name = name; - this.age = age; - } - } - - const person = new Person('Alice', 30); - - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_instanceof: %{public}s', - testNapi.napiInstanceof(person, Person)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_instanceof: %{public}s', - testNapi.napiInstanceof(obj, Person)); - this.result = 'napiInstanceofSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_instanceof error: %{public}s', error.message); - this.result = 'napiInstanceofFail'; - } - } else if (item === '7.napiTypeTagObject') { - - // napi_type_tag_object and napi_check_object_type_tag - class Obj { - public data: number = 0 - public message: string = '' - } - - let objA: Obj = { data: 0, message: 'hello world' }; - let objB: Obj = { data: 10, message: 'typetag' }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_type_tag_object objA -> 0: %{public}s', - testNapi.setTypeTagToObject(objA, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_type_tag_object objB -> 0: %{public}s', - testNapi.setTypeTagToObject(objB, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_check_object_type_tag objA -> 0: %{public}s', - testNapi.checkObjectTypeTag(objA, 0)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_check_object_type_tag objB -> 1: %{public}s', - testNapi.checkObjectTypeTag(objB, 1)); - this.result = 'napiTypeTagObjectSuccess'; - } else if (item === '8.napiCreateExternal') { - // napi_create_external - const externalData = testNapi.createExternal(); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_external:%{public}s', - testNapi.getExternalType(externalData)); - this.result = 'napiCreateExternalSuccess'; - } else if (item === '9.napiGetValueExternal') { - // napi_get_value_external - hilog.info(0x0000, 'Node-API', 'get_value_external:%{public}d', testNapi.getValueExternal()); - this.result = 'napiGetValueExternalSuccess'; - } else if (item === '10.napiCreateSymbol') { - // napi_create_symbol - let varSymbol = testNapi.createSymbol(); - hilog.info(0x0000, 'Node-API', 'createSymbol:%{public}s', typeof varSymbol); - this.result = 'napiCreateSymbolSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIObject/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/ohosTest.md deleted file mode 100755 index a08063b27f773bb9a41da8136570e3edbc901224..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIObject/ohosTest.md +++ /dev/null @@ -1,17 +0,0 @@ -# 使用Node-API进行object相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ------------------------------------------ | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 napiGetPrototype | 位于主页 | 点击文本为1.napiGetPrototype的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetPrototypeSuccess | Pass | -| ArkTS端成功调用native侧接口createObject | 位于主页 | 点击文本为2.napiCreateObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateObjectSuccess | Pass | -| ArkTS端成功调用native侧接口objectFreeze | 位于主页 | 点击文本为3.napiObjectFreeze的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiObjectFreezeSuccess | Pass | -| ArkTS端成功调用native侧接口objectSeal | 位于主页 | 点击文本为4.napiObjectSeal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiObjectSealSuccess | Pass | -| ArkTS端成功调用native侧接口napiTypeOf | 位于主页 | 点击文本为5.napiTypeof的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiTypeofSuccess | Pass | -| ArkTS端成功调用native侧接口napiInstanceof | 位于主页 | 点击文本为6.napiInstanceof的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiInstanceofSuccess | Pass | -| ArkTS端成功调用native侧接口setTypeTagToObject,checkObjectTypeTag | 位于主页 | 点击文本为7.napiTypeTagObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiTypeTagObjectSuccess | Pass | -| ArkTS端成功调用native侧接口createExternal,getExternalType | 位于主页 | 点击文本为8.napiCreateExternal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateExternalSuccess | Pass | -| ArkTS端成功调用native侧接口getValueExternal | 位于主页 | 点击文本为9.napiGetValueExternal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueExternalSuccess | Pass | -| ArkTS端成功调用native侧接口createSymbol | 位于主页 | 点击文本为10.napiCreateSymbol的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCreateSymbolSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/app.json5 deleted file mode 100755 index 41d00c9b127b647e3399ef42ce52ed2334f5a6a3..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiprimitive", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/element/string.json deleted file mode 100755 index 95d1cf67e20bf8777eb5530ed20166b9ea58046d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIPrimitive" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/README.md deleted file mode 100755 index 86c2a03108a225d137a11cb22485e80aa9954dc6..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API接口进行primitiv类相关开发 - -### 介绍 - -在使用Node-API接口时,开发人员可以实现在Node-API模块中与ArkTS对象的交互,并进行数据转换和获取特定对象的操作,它们在不同的场景中发挥着重要的作用,使开发人员能够更灵活地处理ArkTS值和对象,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [使用Node-API接口进行primitiv类相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-primitive.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIPrimitive.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API接口进行primitiv类相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIPrimitive.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 409f10fe25dbfb8a903e664da1302529a6c14dec..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIPrimitive) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index be73865685ad6cd3b7a88416d748eceb1010747f..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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" - -// [Start napi_coerce_to_bool] -// napi_coerce_to_bool -static napi_value CoerceToBool(napi_env env, napi_callback_info info) -{ - // 获取并解析传进的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将传入的值转换为布尔值 - napi_value result = nullptr; - napi_coerce_to_bool(env, args[0], &result); - // 返回强转之后的ArkTS boolean值 - return result; -} -// [End napi_coerce_to_bool] - -// [Start napi_coerce_to_number] -// napi_coerce_to_number -static napi_value CoerceToNumber(napi_env env, napi_callback_info info) -{ - // 获取并解析传进的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将传入的值转换为number值 - napi_value result = nullptr; - napi_coerce_to_number(env, args[0], &result); - return result; -} -// [End napi_coerce_to_number] - -// [Start napi_coerce_to_object] -// napi_coerce_to_object -static napi_value CoerceToObject(napi_env env, napi_callback_info info) -{ - // 获取并解析传进的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_value obj = nullptr; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将传入的值转换为Object值 - napi_coerce_to_object(env, args[0], &obj); - return obj; -} -// [End napi_coerce_to_object] - -// [Start napi_coerce_to_string] -// napi_coerce_to_string -static napi_value CoerceToString(napi_env env, napi_callback_info info) -{ - // 获取并解析传进的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 将传入的值转换为string - napi_value str = nullptr; - napi_coerce_to_string(env, args[0], &str); - return str; -} -// [End napi_coerce_to_string] - -// [Start napi_get_boolean] -// napi_get_boolean -static napi_value GetBoolean(napi_env env, napi_callback_info info) -{ - // 传入两个参数并解析 - size_t argc = 2; - napi_value argv[2]; - napi_valuetype data; - napi_valuetype value; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - // 判断两个参数类型值 - napi_typeof(env, argv[0], &data); - napi_typeof(env, argv[1], &value); - - napi_value returnValue = nullptr; - // 判断两个类型值是否相等,获取结果的布尔值 - napi_get_boolean(env, data == value, &returnValue); - // 返回结果 - return returnValue; -} -// [End napi_get_boolean] - -// [Start napi_get_value_bool] -// napi_get_value_bool -static napi_value GetValueBool(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - bool boolC = false; - napi_status status = napi_get_value_bool(env, args[0], &boolC); - if (status == napi_boolean_expected) { - // 如果napi_get_value_bool成功会返回napi_ok,如果传入一个非布尔值则会返回napi_boolean_expected - return nullptr; - } - napi_value boolNapi = nullptr; - napi_get_boolean(env, boolC, &boolNapi); - return boolNapi; -} -// [End napi_get_value_bool] - -// [Start napi_get_global] -// napi_get_global -static napi_value GetGlobal(napi_env env, napi_callback_info info) -{ - napi_value global = nullptr; - // 获取global对象 - napi_get_global(env, &global); - return global; -} -// [End napi_get_global] - -// [Start napi_get_null] -// napi_get_null -static napi_value GetNull(napi_env env, napi_callback_info info) -{ - napi_value nullValue = nullptr; - napi_get_null(env, &nullValue); - return nullValue; -} -// [End napi_get_null] - -// [Start napi_get_undefined] -// napi_get_undefined -static napi_value GetUndefined(napi_env env, napi_callback_info info) -{ - // 获取并解析传进的参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_value value = nullptr; - napi_get_undefined(env, &value); - // 判断传入参数的类型与undefined值的类型是否一致 - bool isEqual = false; - napi_strict_equals(env, args[0], value, &isEqual); - // 参数与undefined值相等 - napi_value result = nullptr; - // 返回判断类型之后的结果,相等返回为true,不等则为false - napi_get_boolean(env, isEqual, &result); - return result; -} -// [End napi_get_undefined] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"coerceToBool", nullptr, CoerceToBool, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"coerceToNumber", nullptr, CoerceToNumber, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"coerceToObject", nullptr, CoerceToObject, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"coerceToString", nullptr, CoerceToString, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getBoolean", nullptr, GetBoolean, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueBool", nullptr, GetValueBool, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getGlobal", nullptr, GetGlobal, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getNull", nullptr, GetNull, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getUndefined", nullptr, GetUndefined, 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index c1f99a1279c4d6cfce7f73d6573b38e400db5a53..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_coerce_to_bool_api] -export const coerceToBool: (data: T) => boolean; // napi_coerce_to_bool -// [End napi_coerce_to_bool_api] - -// [Start napi_coerce_to_number_api] -export const coerceToNumber: (data: T) => number; // napi_coerce_to_number -// [End napi_coerce_to_number_api] - -// [Start napi_coerce_to_object_api] -export const coerceToObject: (data: T) => Object; // napi_coerce_to_object -// [End napi_coerce_to_object_api] - -// [Start napi_coerce_to_string_api] -export const coerceToString: (data: T) => string; // napi_coerce_to_string -// [End napi_coerce_to_string_api] - -// [Start napi_get_boolean_api] -export const getBoolean: (data: T, value: String) => boolean; // napi_get_boolean -// [End napi_get_boolean_api] - -// [Start napi_get_value_bool_api] -export const getValueBool: (value: boolean | string) => boolean | void; // napi_get_value_bool -// [End napi_get_value_bool_api] - -// [Start napi_get_global_api] -export const getGlobal: () => Object; // napi_get_global -// [End napi_get_global_api] - -// [Start napi_get_null_api] -export const getNull: () => null; // napi_get_null -// [End napi_get_null_api] - -// [Start napi_get_undefined_api] -export const getUndefined: (value: undefined) => boolean; // napi_get_undefined -// [End napi_get_undefined_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index c2c5c922289138ffe28d225db64fc0f809134d35..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiCoerceToBool', - '2.napiCoerceToNumber', - '3.napiCoerceToObject', - '4.napiCoerceToString', - '5.napiGetBoolean', - '6.napiGetValueBool', - '7.napiGetGlobal', - '8.napiGetNull', - '9.napiGetUndefined' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(22) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiCoerceToBool') { - // [Start ark_napi_coerce_to_bool] - // napi_coerce_to_bool - let value = testNapi.coerceToBool(0); - let str = testNapi.coerceToBool('111111111'); - let obj = new Object(); - let res = testNapi.coerceToBool(obj); - let result = testNapi.coerceToBool(null); - // false - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', value); - // true - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', str); - // true - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', res); - // false - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_bool:%{public}s', result); - // [End ark_napi_coerce_to_bool] - this.result = 'napiCoerceToBoolSuccess'; - } else if (item === '2.napiCoerceToNumber') { - // [Start ark_napi_coerce_to_number] - // napi_coerce_to_number - let value = testNapi.coerceToNumber('2556'); - let str = testNapi.coerceToNumber('sssss'); - let bool = testNapi.coerceToNumber(true); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', value); - // 返回的为NAN - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', str); - // 返回的是1 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_number:%{public}d', bool); - // [End ark_napi_coerce_to_number] - this.result = 'napiCoerceToNumberSuccess'; - } else if (item === '3.napiCoerceToObject') { - // [Start ark_napi_coerce_to_object] - // napi_coerce_to_object - let value = testNapi.coerceToObject('222222'); - let result = testNapi.coerceToObject(111); - hilog.info(0x0000, 'testTag', 'Node-API coerceToObject:%{public}s.', typeof result); - if (typeof value === 'object') { - hilog.info(0x0000, 'testTag', 'Node-API The value is an object.'); - } else { - hilog.info(0x0000, 'testTag', 'Node-API The value is not an object.'); - } - // [End ark_napi_coerce_to_object] - this.result = 'napiCoerceToObjectSuccess'; - } else if (item === '4.napiCoerceToString') { - // [Start ark_napi_coerce_to_string] - // napi_coerce_to_string - let value = testNapi.coerceToString(212); - let obj = new Object(); - let res = testNapi.coerceToString(obj); - let bool = testNapi.coerceToString(false); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', value); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', typeof res); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_coerce_to_string:%{public}s', bool); - // [End ark_napi_coerce_to_string] - this.result = 'napiCoerceToStringSuccess'; - } else if (item === '5.napiGetBoolean') { - // [Start ark_napi_get_boolean] - // napi_get_boolean - let value = testNapi.getBoolean(1, '1'); - let data = testNapi.getBoolean('sss', '1'); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', value); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_boolean:%{public}s', data); - // [End ark_napi_get_boolean] - this.result = 'napiGetBooleanSuccess'; - } else if (item === '6.napiGetValueBool') { - // [Start ark_napi_get_value_bool] - // napi_get_value_bool - // // 分别传入布尔值和非布尔值检测接口,传入布尔值将返回原布尔值,传入其他类型返回undefined - hilog.info(0x0000, 'Node-API', 'get_value_bool_not_bool %{public}s', - testNapi.getValueBool('你好123')); - hilog.info(0x0000, 'Node-API', 'get_value_bool_true %{public}s', testNapi.getValueBool(true)); - hilog.info(0x0000, 'Node-API', 'get_value_bool_false %{public}s', testNapi.getValueBool(false)); - // [End ark_napi_get_value_bool] - this.result = 'napiGetValueBoolSuccess'; - } else if (item === '7.napiGetGlobal') { - // [Start ark_napi_get_global] - // napi_get_global - let globalObj = testNapi.getGlobal(); - // 判断获取的global是否具有global的自身属性 - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_global:%{public}s', - globalObj.hasOwnProperty!("undefined")); - // [End ark_napi_get_global] - this.result = 'napiGetGlobalSuccess'; - } else if (item === '8.napiGetNull') { - // [Start ark_napi_get_null] - // napi_get_null - let value = testNapi.getNull(); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_null:%{public}s', value); - // [End ark_napi_get_null] - this.result = 'napiGetNullSuccess'; - } else if (item === '9.napiGetUndefined') { - // [Start ark_napi_get_undefined] - // napi_get_undefined - let data: undefined = undefined; - let value = testNapi.getUndefined(data); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_undefined:%{public}s', value); - // [End ark_napi_get_undefined] - this.result = 'napiGetUndefinedSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPrimitive/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/ohosTest.md deleted file mode 100755 index 5640f18f014c8ca8cfeb8359c30e9f5bae332b97..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPrimitive/ohosTest.md +++ /dev/null @@ -1,16 +0,0 @@ -# 使用Node-API进行primitive相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------ | ------------ | ---------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 coerceToBool | 位于主页 | 点击文本为1.napiCoerceToBool的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToBoolSuccess | Pass | -| ArkTS端成功调用native侧接口coerceToNumber | 位于主页 | 点击文本为2.napiCoerceToNumber的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToNumberSuccess | Pass | -| ArkTS端成功调用native侧接口coerceToObject | 位于主页 | 点击文本为3.napiCoerceToObject的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToObjectSuccess | Pass | -| ArkTS端成功调用native侧接口coerceToString | 位于主页 | 点击文本为4.napiCoerceToString的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiCoerceToStringSuccess | Pass | -| ArkTS端成功调用native侧接口getBoolean | 位于主页 | 点击文本为5.napiGetBoolean的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetBooleanSuccess | Pass | -| ArkTS端成功调用native侧接口getValueBool | 位于主页 | 点击文本为6.napiGetValueBool的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetValueBoolSuccess | Pass | -| ArkTS端成功调用native侧接口getGlobal | 位于主页 | 点击文本为7.napiGetGlobal的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetGlobalSuccess | Pass | -| ArkTS端成功调用native侧接口getNull | 位于主页 | 点击文本为8.napiGetNull的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetNullSuccess | Pass | -| ArkTS端成功调用native侧接口getUndefined | 位于主页 | 点击文本为9.napiGetUndefined的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetUndefinedSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/app.json5 deleted file mode 100755 index be09964d9e5bb5587eaa5d5684f34de6290f7a88..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapipromise", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/element/string.json deleted file mode 100755 index 15ca23f62b3f1be6a05006c08d6c2573049023af..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIPromise" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/README.md deleted file mode 100755 index 39ecac32434378fca7d30516d4fb630b4f85e046..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行promise相关开发 - -### 介绍 - -使用Node-API接口处理异步操作。异步操作是指需要一定时间才能完成的操作,例如从网络下载数据或读取大型文件。与同步操作不同,异步操作不会阻塞主线程,而是会在后台执行。当异步操作完成后,事件循环将把它放入任务队列中,等待主线程空闲时执行,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [使用Node-API进行promise相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-promise.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIPromise.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行promise相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIPromise.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index e8c0971277aec3168314e6db8c9591d5a044b116..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIPromise) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 9e72fdba12e91d25a44542b63a2d5088157c213d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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" - -static constexpr int INT_ARGS_2 = 2; // 入参索引 - -// [Start napi_is_promise] -// napi_is_promise -static napi_value IsPromise(napi_env env, napi_callback_info info) -{ - napi_value argv[1] = {nullptr}; - size_t argc = 1; - napi_status status; - // 获取传入的参数 - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - bool isPromise = false; - // 检查给定的入参是否为Promise对象,将结果保存在isPromise变量中 - status = napi_is_promise(env, argv[0], &isPromise); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_is_promise failed"); - return nullptr; - } - napi_value result = nullptr; - // 将isPromise的值转换为napi_value中的类型返回 - napi_get_boolean(env, isPromise, &result); - return result; -} -// [End napi_is_promise] - -// [Start napi_resolve_reject_deferred] -// napi_resolve_deferred & napi_reject_deferred -static napi_value CreatePromise(napi_env env, napi_callback_info info) -{ - // deferred是一个延迟对象,作用是将函数延迟一定时间再执行 - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - // 调用接口创建Promise对象 - napi_status status = napi_create_promise(env, &deferred, &promise); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Create promise failed"); - return nullptr; - } - // 调用napi_is_promise判断napi_create_promise接口创建的是不是Promise对象 - bool isPromise = false; - napi_value returnIsPromise = nullptr; - napi_is_promise(env, promise, &isPromise); - // 将布尔值转为可以返回的napi_value - napi_get_boolean(env, isPromise, &returnIsPromise); - return returnIsPromise; -} - -static napi_value ResolveRejectDeferred(napi_env env, napi_callback_info info) -{ - // 获得并解析参数 - size_t argc = 3; - napi_value args[3] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 第一个参数为向resolve传入的信息,第二个参数为向reject传入的信息,第三个参数为Promise的状态 - bool status; - napi_get_value_bool(env, args[INT_ARGS_2], &status); - // 创建Promise对象 - napi_deferred deferred = nullptr; - napi_value promise = nullptr; - napi_status createStatus = napi_create_promise(env, &deferred, &promise); - if (createStatus != napi_ok) { - napi_throw_error(env, nullptr, "Create promise failed"); - return nullptr; - } - // 根据第三个参数设置resolve或reject - if (status) { - napi_resolve_deferred(env, deferred, args[0]); - } else { - napi_reject_deferred(env, deferred, args[1]); - } - // 返回设置了resolve或reject的Promise对象 - return promise; -} -// [End napi_resolve_reject_deferred] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"isPromise", nullptr, IsPromise, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createPromise", nullptr, CreatePromise, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"resolveRejectDeferred", nullptr, ResolveRejectDeferred, 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 2f3624c69c21e659798cd3f64d9e4ae64ad26875..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_is_promise_api] -export const isPromise: (value: T) => boolean; // napi_is_promise -// [End napi_is_promise_api] - -// [Start napi_resolve_reject_deferred_api] -export const createPromise: () => boolean | void; // napi_resolve_deferred & napi_reject_deferred - -export const resolveRejectDeferred: (resolve: string, reject: string, status: boolean) => Promise | void; -// [End napi_resolve_reject_deferred_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index b9820ecdd9cb094126273774290fa8a5e235a283..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiIsPromise', - '2.napiDeferred' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(22) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiIsPromise') { - // [Start ark_napi_is_promise] - // napi_is_promise - let value = Promise.resolve(); - // 传入的对象为Promise时,返回true,否则返回false - hilog.info(0x0000, 'Node-API', 'napi_is_promise %{public}s', testNapi.isPromise(value)); - hilog.info(0x0000, 'Node-API', 'napi_is_promise string %{public}s', testNapi.isPromise('')); - // [End ark_napi_is_promise] - this.result = 'napiIsPromiseSuccess'; - } else if (item === '2.napiDeferred') { - // [Start ark_napi_resolve_reject_deferred] - // napi_resolve_deferred & napi_reject_deferred - // 创建promise如果创建成功返回true,创建失败返回false - hilog.info(0x0000, 'Node-API', 'napi_create_promise %{public}s', testNapi.createPromise()); - // 调用resolveRejectDeferred函数设置resolve和reject的返回结果以及Promise状态 - // Promise状态为true时设置resolve,返回结果在then函数中获得 - let promiseSuccess: Promise = - testNapi.resolveRejectDeferred('success', 'fail', true) as Promise; - promiseSuccess.then((res) => { - hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) - // [StartExclude ark_napi_resolve_reject_deferred] - this.result = 'napiDeferredSuccess'; - // [EndExclude ark_napi_resolve_reject_deferred] - }).catch((err: Error) => { - hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) - // [StartExclude ark_napi_resolve_reject_deferred] - this.result = 'napiDeferredFail'; - // [EndExclude ark_napi_resolve_reject_deferred] - }) - // Promise状态为false时设置reject,返回结果在catch函数中获得 - let promiseFail: Promise = - testNapi.resolveRejectDeferred('success', 'fail', false) as Promise; - promiseFail.then((res) => { - hilog.info(0x0000, 'Node-API', 'get_resolve_deferred resolve %{public}s', res) - // [StartExclude ark_napi_resolve_reject_deferred] - this.result = 'napiDeferredSuccess'; - // [EndExclude ark_napi_resolve_reject_deferred] - }).catch((err: Error) => { - hilog.info(0x0000, 'Node-API', 'get_resolve_deferred reject %{public}s', err) - // [StartExclude ark_napi_resolve_reject_deferred] - this.result = 'napiDeferredFail'; - // [EndExclude ark_napi_resolve_reject_deferred] - }) - // [End ark_napi_resolve_reject_deferred] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIPromise/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/ohosTest.md deleted file mode 100755 index 23bc29983ec545f984e6f8c98b512cc818408b7b..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIPromise/ohosTest.md +++ /dev/null @@ -1,9 +0,0 @@ -# 使用Node-API进行promise相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ----------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口isPromise | 位于主页 | 点击文本为1.napiIsPromise的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiIsPromiseSuccess | Pass | -| ArkTS端成功调用native侧接口createPromise,resolveRejectDeferred | 位于主页 | 点击文本为2.napiDeferred的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDeferredSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/app.json5 deleted file mode 100755 index 1f7238eae6603d2638a3a7c4c4c0282a41c24c4d..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapiproperty", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/element/string.json deleted file mode 100755 index 1d1b5e602c4673dc124f9047c82ee743d9103147..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeAPIProperty" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/README.md deleted file mode 100755 index 3e6e49a7e7667e1e7c27495b6a9c598f013c16f5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行property相关开发 - -### 介绍 - -使用Node-API接口获取和设置ArkTS对象的属性。通过合理使用这些函数,实现更复杂的功能和逻辑,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [使用Node-API进行property相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-property.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeAPIProperty.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行property相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeAPIProperty.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index feb418a6dbdfd15ec74b2047f6e76d9b830f1548..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NodeAPIProperty) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 115c9bd479733b830d009b59c79611da1a297993..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,391 +0,0 @@ -/* - * 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 -#include "napi/native_api.h" - -static constexpr int INT_ARG_2 = 2; // 入参索引 - -// [Start napi_get_property_names] -// napi_get_property_names -static napi_value GetPropertyNames(napi_env env, napi_callback_info info) -{ - // 解析ArkTS的传参 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 以字符串数组的形式获取对象的可枚举属性的名称,以result传出 - napi_value result; - napi_status status = napi_get_property_names(env, args[0], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_get_property_names fail"); - return nullptr; - } - return result; -} -// [End napi_get_property_names] - -// [Start napi_set_property] -// napi_set_property -static napi_value SetProperty(napi_env env, napi_callback_info info) -{ - // 接收ArkTS侧传入的三个参数:第一个参数为想要设置的object,第二个参数为属性,第三个参数为属性对应的值 - size_t argc = 3; - napi_value args[3] = {nullptr}; - napi_status status = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_get_cb_info fail"); - } - // 通过调用napi_set_property接口将属性与值设置入object,如果失败,直接抛出错误 - status = napi_set_property(env, args[0], args[1], args[INT_ARG_2]); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_set_property fail"); - return nullptr; - } - // 返回设置成功的object对象 - return args[0]; -} -// [End napi_set_property] - -// [Start napi_get_property] -// napi_get_property -static napi_value GetProperty(napi_env env, napi_callback_info info) -{ - // 接收两个ArkTS传来的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 传入的第一个参数为要检测的object,第二个对象为要检测的属性,通过调用napi_get_property接口获取对应的值 - napi_value result; - napi_status status = napi_get_property(env, args[0], args[1], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_get_property fail"); - return nullptr; - } - return result; -} -// [End napi_get_property] - -// [Start napi_has_property] -// napi_has_property -static napi_value HasProperty(napi_env env, napi_callback_info info) -{ - // 从ArkTS侧传入两个参数:第一个参数为要检验的对象,第二个参数为要检测是否存在对象的属性 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 将参数传入napi_has_property方法中,若接口调用成功则将结果转化为napi_value类型抛出,否则抛出错误 - bool result; - napi_status status = napi_has_property(env, args[0], args[1], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_has_property fail"); - return nullptr; - } - - // 若传入属性存在传入对象中,则输出true将结果转化为napi_value类型抛出 - napi_value returnResult; - napi_get_boolean(env, result, &returnResult); - return returnResult; -} -// [End napi_has_property] - -// [Start napi_delete_property] -// napi_delete_property -// 从传入的Object对象中删除指定属性,返回是否删除成功的bool结果值 -static napi_value DeleteProperty(napi_env env, napi_callback_info info) -{ - // 接收两个ArkTS传来的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_valuetype valueType; - napi_typeof(env, args[0], &valueType); - if (valueType != napi_object) { - napi_throw_error(env, nullptr, "Expects an object as argument."); - return nullptr; - } - // 删除指定属性,结果存储在result中 - bool result = false; - napi_status status = napi_delete_property(env, args[0], args[1], &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_delete_property failed"); - return nullptr; - } - // 将bool结果转换为napi_value并返回 - napi_value ret; - napi_get_boolean(env, result, &ret); - return ret; -} -// [End napi_delete_property] - -// [Start napi_has_own_property] -// napi_has_own_property -static napi_value NapiHasOwnProperty(napi_env env, napi_callback_info info) -{ - // 接收两个ArkTS传来的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 检查第一个参数是否为对象 - napi_valuetype valueTypeObj; - napi_typeof(env, args[0], &valueTypeObj); - if (valueTypeObj != napi_object) { - napi_throw_error(env, nullptr, "First argument must be an object."); - return nullptr; - } - // 检查第二个参数是否为string - napi_valuetype valuetypeStr; - napi_typeof(env, args[1], &valuetypeStr); - if (valuetypeStr != napi_string) { - napi_throw_error(env, nullptr, "Second argument must be a string."); - return nullptr; - } - // 检查对象是否具有指定属性,结果存储在hasProperty中 - bool hasProperty; - napi_status status = napi_has_own_property(env, args[0], args[1], &hasProperty); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_has_own_property failed"); - return nullptr; - } - // 将bool结果转换为napi_value并返回 - napi_value result; - napi_get_boolean(env, hasProperty, &result); - return result; -} -// [End napi_has_own_property] - -// [Start napi_set_named_property] -// napi_set_named_property -static napi_value NapiSetNamedProperty(napi_env env, napi_callback_info info) -{ - // 接收一个ArkTS传来的参数 - size_t argc = 1; - napi_value str; - const int32_t strLength = 32; - char strKey[strLength] = ""; - napi_get_cb_info(env, info, &argc, &str, nullptr, nullptr); - // 获取传入参数字符串并存储在strKey中 - size_t keyLength; - napi_get_value_string_utf8(env, str, strKey, strLength, &keyLength); - // 创建一个新对象 - napi_value newObj; - napi_create_object(env, &newObj); - // 设置整数值1234为属性值 - int32_t value = 1234; - napi_value numValue; - napi_create_int32(env, value, &numValue); - // 将整数值与指定属性名关联 - napi_status status = napi_set_named_property(env, newObj, strKey, numValue); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_set_named_property failed"); - return nullptr; - } - // 返回设置了命名属性的对象newObj - return newObj; -} -// [End napi_set_named_property] - -// [Start napi_get_named_property] -// napi_get_named_property -static napi_value NapiGetNamedProperty(napi_env env, napi_callback_info info) -{ - // 接收两个ArkTS传来的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - const int32_t strLength = 32; - char strKey[strLength] = ""; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取要获取的属性名 - size_t keyLength; - napi_get_value_string_utf8(env, args[1], strKey, strLength, &keyLength); - // 获取指定属性的值并存储在result中 - napi_value result; - napi_status status = napi_get_named_property(env, args[0], strKey, &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_get_named_property failed"); - return nullptr; - } - // 返回result - return result; -} -// [End napi_get_named_property] - -// [Start napi_has_named_property] -// napi_has_named_property -static napi_value NapiHasNamedProperty(napi_env env, napi_callback_info info) -{ - // 接收两个ArkTS传来的参数 - size_t argc = 2; - napi_value args[2] = {nullptr}; - const int32_t strLength = 32; - char strKey[strLength] = ""; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取要检查的属性名 - size_t keyLength; - napi_get_value_string_utf8(env, args[1], strKey, strLength, &keyLength); - // 检查对象是否具有指定命名的属性,并将结果存储在hasProperty中 - bool hasProperty = false; - napi_status status = napi_has_named_property(env, args[0], strKey, &hasProperty); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_has_named_property failed"); - return nullptr; - } - // 将bool结果转换为napi_value并返回 - napi_value result; - napi_get_boolean(env, hasProperty, &result); - return result; -} -// [End napi_has_named_property] - -// [Start napi_define_properties] -// napi_define_properties -static napi_value DefineMethodPropertiesExample(napi_env env, napi_callback_info info) -{ - // 创建一个int32类型的属性值 - int32_t propValue = 26; - napi_value returnValue = nullptr; - napi_create_int32(env, propValue, &returnValue); - return returnValue; -} - -// Getter回调函数 -static napi_value GetterCallback(napi_env env, napi_callback_info info) -{ - napi_value result; - const char *str = u8"World!"; - size_t length = strlen(str); - // 创建属性的值 - napi_create_string_utf8(env, str, length, &result); - return result; -} - -// Setter回调函数 -static napi_value SetterCallback(napi_env env, napi_callback_info info) -{ - // 获取传递给setter的参数 - size_t argc = 1; - napi_value argv[1] = {nullptr}; - napi_value result; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - std::string buf; - size_t length; - napi_get_value_string_utf8(env, argv[0], (char *)buf.c_str(), NAPI_AUTO_LENGTH, &length); - napi_create_string_utf8(env, buf.c_str(), length, &result); - return result; -} - -static napi_value DefineMethodProperties(napi_env env, napi_callback_info info) -{ - napi_value obj; - napi_create_object(env, &obj); - // 在obj对象上定义了一个函数defineMethodPropertiesExample,在函数defineMethodPropertiesExample中定义了一个变量并返回,在调用obj的这个对象时可以调用这个函数 - napi_property_descriptor descriptor[] = {{"defineMethodPropertiesExample", nullptr, DefineMethodPropertiesExample, - nullptr, nullptr, nullptr, napi_default, nullptr}}; - napi_define_properties(env, obj, sizeof(descriptor) / sizeof(descriptor[0]), descriptor); - return obj; -} - -static napi_value DefineStringProperties(napi_env env, napi_callback_info info) -{ - napi_value obj; - napi_create_object(env, &obj); - // 创建一个string类型的属性值 - napi_value string_value; - napi_create_string_utf8(env, "Hello!", NAPI_AUTO_LENGTH, &string_value); - napi_property_descriptor descriptor[] = { - {"defineStringPropertiesExample", nullptr, nullptr, nullptr, nullptr, string_value, napi_default, nullptr}}; - napi_define_properties(env, obj, sizeof(descriptor) / sizeof(descriptor[0]), descriptor); - return obj; -} - -static napi_value CreateStringWithGetterSetter(napi_env env, napi_callback_info info) -{ - napi_value obj; - napi_create_object(env, &obj); - // 定义getter函数 - napi_value getterFn; - napi_create_function(env, nullptr, 0, GetterCallback, nullptr, &getterFn); - napi_set_named_property(env, obj, "getterCallback", getterFn); - // 定义setter函数 - napi_value setterFn; - napi_create_function(env, nullptr, 0, SetterCallback, nullptr, &setterFn); - napi_set_named_property(env, obj, "setterCallback", setterFn); - // 定义带有getter和setter的属性 - napi_property_descriptor desc = {"defineGetterSetter", nullptr, GetterCallback, SetterCallback, nullptr, obj, - napi_enumerable, nullptr}; - napi_define_properties(env, obj, 1, &desc); - return obj; -} -// [End napi_define_properties] - -// [Start napi_get_all_property_names] -// napi_get_all_property_names -static napi_value GetAllPropertyNames(napi_env env, napi_callback_info info) -{ - // 传入一个参数 - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取给定对象的所有属性名称 - napi_value result; - napi_status status = napi_get_all_property_names(env, args[0], napi_key_own_only, napi_key_writable, - napi_key_numbers_to_strings, &result); - // 如果获取属性名失败,抛出一个错误 - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Node-API napi_get_all_property_names fail"); - return nullptr; - } - - return result; -} -// [End napi_get_all_property_names] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getPropertyNames", nullptr, GetPropertyNames, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"setProperty", nullptr, SetProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getProperty", nullptr, GetProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"hasProperty", nullptr, HasProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"deleteProperty", nullptr, DeleteProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiHasOwnProperty", nullptr, NapiHasOwnProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiSetNamedProperty", nullptr, NapiSetNamedProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiGetNamedProperty", nullptr, NapiGetNamedProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"napiHasNamedProperty", nullptr, NapiHasNamedProperty, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"defineMethodProperties", nullptr, DefineMethodProperties, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"defineStringProperties", nullptr, DefineStringProperties, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createStringWithGetterSetter", nullptr, CreateStringWithGetterSetter, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"getAllPropertyNames", nullptr, GetAllPropertyNames, 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index e2f3372d4c6df3002b515aaf21c5747252096900..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_get_property_names_api] -export const getPropertyNames: (obj: Object) => Array | void; // napi_get_property_names -// [End napi_get_property_names_api] - -// [Start napi_set_property_api] -export const setProperty: (obj: Object, key: String, value: string) => Object | void; // napi_set_property -// [End napi_set_property_api] - -// [Start napi_get_property_api] -export const getProperty: (obj: Object, key: string) => string | void; // napi_get_property -// [End napi_get_property_api] - -// [Start napi_has_property_api] -export const hasProperty: (obj: Object, key: number | string) => boolean | void; // napi_has_property -// [End napi_has_property_api] - -// [Start napi_delete_property_api] -export const deleteProperty: (obj: Object, key: string) => boolean; // napi_delete_property -// [End napi_delete_property_api] - -// [Start napi_has_own_property_api] -export const napiHasOwnProperty: (obj: Object, key: string) => boolean | void; // napi_has_own_property -// [End napi_has_own_property_api] - -// [Start napi_set_named_property_api] -export const napiSetNamedProperty: (key: string) => Object | void; // napi_set_named_property -// [End napi_set_named_property_api] - -// [Start napi_get_named_property_api] -export const napiGetNamedProperty: (obj: Object, - key: string) => boolean | number | string | Object | void; // napi_get_named_property -// [End napi_get_named_property_api] - -// [Start napi_has_named_property_api] -export const napiHasNamedProperty: (obj: Object, key: string) => boolean | void; // napi_has_named_property -// [End napi_has_named_property_api] - -// [Start napi_define_properties_api] -export class DefineMethodObj { - defineMethodPropertiesExample: Function; -} - -export class DefineStringObj { - defineStringPropertiesExample: string; -} - -export class DefineGetterSetterObj { - getterCallback: Function; - setterCallback: Function; -} - -export const defineMethodProperties: () => DefineMethodObj; // napi_define_properties - -export const defineStringProperties: () => DefineStringObj; - -export const createStringWithGetterSetter: () => DefineGetterSetterObj; -// [End napi_define_properties_api] - -// [Start napi_get_all_property_names_api] -export const getAllPropertyNames: (obj: Object) => Array | void; // napi_get_all_property_names -// [End napi_get_all_property_names_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index a8e26c51f7a544c359f25a21fbaad99fec02da59..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,294 +0,0 @@ -/* - * 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 { napiDeleteProperty } from './napiDeleteProperty'; -import { napiHasOwnProperty } from './napiHasOwnProperty'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiGetPropertyNames', - '2.napiSetProperty', - '3.napiGetProperty', - '4.napiHasProperty', - '5.napiDeleteProperty', - '6.napiHasOwnProperty', - '7.napiSetNamedProperty', - '8.napiGetNamedProperty', - '9.napiHasNamedProperty', - '10.napiDefineProperties', - '11.napiGetAllPropertyNames' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 4 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiGetPropertyNames') { - // [Start ark_napi_get_property_names] - // napi_get_property_names - try { - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - let propertyNames = testNapi.getPropertyNames(obj); - if (Array.isArray(propertyNames) && propertyNames.length > 0) { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property_names: %{public}s', - propertyNames[0]); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property_names: %{public}s', - propertyNames[1]); - // [StartExclude ark_napi_get_property_names] - this.result = 'napiGetPropertyNamesSuccess'; - // [EndExclude ark_napi_get_property_names] - } - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_property_names error: %{public}s', - error.message); - // [StartExclude ark_napi_get_property_names] - this.result = 'napiGetPropertyNamesFail'; - // [EndExclude ark_napi_get_property_names] - } - // [End ark_napi_get_property_names] - } else if (item === '2.napiSetProperty') { - // [Start ark_napi_set_property] - // napi_set_property - try { - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - let result = testNapi.setProperty(obj, 'code', 'hi'); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property: %{public}s', - JSON.stringify(result)); - // [StartExclude ark_napi_set_property] - this.result = 'napiSetPropertySuccess'; - // [EndExclude ark_napi_set_property] - } catch (error) { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_property error: %{public}s', error.message); - // [StartExclude ark_napi_set_property] - this.result = 'napiSetPropertyFail'; - // [EndExclude ark_napi_set_property] - } - // [End ark_napi_set_property] - } else if (item === '3.napiGetProperty') { - // [Start ark_napi_get_property] - // napi_get_property - try { - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property: %{public}s', - testNapi.getProperty(obj, 'message')); - // [StartExclude ark_napi_get_property] - this.result = 'napiGetPropertySuccess'; - // [EndExclude ark_napi_get_property] - } catch (error) { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_property error: %{public}s', error.message); - // [StartExclude ark_napi_get_property] - this.result = 'napiGetPropertyFail'; - // [EndExclude ark_napi_get_property] - } - // [End ark_napi_get_property] - } else if (item === '4.napiHasProperty') { - // [Start ark_napi_has_property] - // napi_has_property - try { - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - let resultFalse = testNapi.hasProperty(obj, 0); - let resultTrue = testNapi.hasProperty(obj, 'data'); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property: %{public}s', - JSON.stringify(resultFalse)); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property: %{public}s', - JSON.stringify(resultTrue)); - // [StartExclude ark_napi_has_property] - this.result = 'napiHasPropertySuccess'; - // [EndExclude ark_napi_has_property] - } catch (error) { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_property error: %{public}s', error.message); - // [StartExclude ark_napi_has_property] - this.result = 'napiHasPropertyFail'; - // [EndExclude ark_napi_has_property] - } - // [End ark_napi_has_property] - } else if (item === '5.napiDeleteProperty') { - // napi_delete_property - napiDeleteProperty(); - this.result = 'napiDeletePropertySuccess'; - } else if (item === '6.napiHasOwnProperty') { - // napi_has_own_property - napiHasOwnProperty(); - this.result = 'napiHasOwnPropertySuccess'; - } else if (item === '7.napiSetNamedProperty') { - // [Start ark_napi_set_named_property] - // napi_set_named_property - let obj = testNapi.napiSetNamedProperty('myProperty'); - let objAsString = JSON.stringify(obj); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_named_property: %{public}s', objAsString); - // [End ark_napi_set_named_property] - this.result = 'napiSetNamedPropertySuccess'; - } else if (item === '8.napiGetNamedProperty') { - // [Start ark_napi_get_named_property] - // napi_get_named_property - interface NestedObj { - nestedStr: string; - nestedNum: number; - } - - class Obj { - public str: string = ''; - public num: number = 0; - public bol: boolean = false; - public nestedObj: NestedObj = { nestedStr: '', nestedNum: 0 }; - } - - let obj: Obj = { - str: 'bar', - num: 42, - bol: true, - nestedObj: { nestedStr: 'nestedValue', nestedNum: 123 } - }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', - testNapi.napiGetNamedProperty(obj, 'str')); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}d', - testNapi.napiGetNamedProperty(obj, 'num')); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', - testNapi.napiGetNamedProperty(obj, 'bol')); - let nestedObj = testNapi.napiGetNamedProperty(obj, 'nestedObj'); - let objAsString = JSON.stringify(nestedObj); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', objAsString); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_named_property : %{public}s', - testNapi.napiGetNamedProperty(obj, 'null')); - // [End ark_napi_get_named_property] - this.result = 'napiGetNamedPropertySuccess'; - } else if (item === '9.napiHasNamedProperty') { - // [Start ark_napi_has_named_property] - // napi_has_named_property - interface NestedObj { - nestedStr: string; - nestedNum: number; - } - - class Obj { - public str: string = ''; - public num: number = 0; - public bol: boolean = false; - public nestedObj: NestedObj = { nestedStr: '', nestedNum: 0 }; - } - - let obj: Obj = { - str: 'bar', - num: 42, - bol: true, - nestedObj: { nestedStr: 'nestedValue', nestedNum: 123 } - }; - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', - testNapi.napiHasNamedProperty(obj, 'str')); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', - testNapi.napiHasNamedProperty(obj, 'nestedStr')); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_named_property : %{public}s', - testNapi.napiHasNamedProperty(obj, 'bol')); - // [End ark_napi_has_named_property] - this.result = 'napiHasNamedPropertySuccess'; - } else if (item === '10.napiDefineProperties') { - // [Start ark_napi_define_properties] - // napi_define_properties - // 定义method类型的属性 - hilog.info(0x0000, 'testTag', 'Test Node-API define_method_properties:%{public}d', - testNapi.defineMethodProperties() - .defineMethodPropertiesExample()); - // 定义string类型的属性 - hilog.info(0x0000, 'testTag', 'Test Node-API define_string_properties::%{public}s ', - testNapi.defineStringProperties() - .defineStringPropertiesExample); - // getter和setter - hilog.info(0x0000, 'testTag', 'Test Node-API get::%{public}s ', - testNapi.createStringWithGetterSetter() - .getterCallback()); - hilog.info(0x0000, 'testTag', 'Test Node-API setter::%{public}s ', - testNapi.createStringWithGetterSetter() - .setterCallback('set data')); - // [End ark_napi_define_properties] - this.result = 'napiDefinePropertiesSuccess'; - } else if (item === '11.napiGetAllPropertyNames') { - // [Start ark_napi_get_all_property_names] - // napi_get_all_property_names - try { - class Obj { - public data: number = 0 - public message: string = '' - } - - let obj: Obj = { data: 0, message: 'hello world' }; - let propertyNames = testNapi.getAllPropertyNames(obj); - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names: %{public}s', - JSON.stringify(propertyNames)); - // [StartExclude ark_napi_get_all_property_names] - this.result = 'napiGetAllPropertyNamesSuccess'; - // [EndExclude ark_napi_get_all_property_names] - } catch (error) { - hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_all_property_names error: %{public}s', - error.message); - // [StartExclude ark_napi_get_all_property_names] - this.result = 'napiGetAllPropertyNamesFail'; - // [EndExclude ark_napi_get_all_property_names] - } - // [End ark_napi_get_all_property_names] - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - .id('List') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeAPIProperty/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/ohosTest.md deleted file mode 100755 index f4ff2dfc6c8c9a6b8005ed3f47706b8ccf631a34..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeAPIProperty/ohosTest.md +++ /dev/null @@ -1,18 +0,0 @@ -# 使用Node-API进行property相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------- | ------------ | ---------------------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 getPropertyNames | 位于主页 | 点击文本为1.napiGetPropertyNames的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetPropertyNamesSuccess | Pass | -| ArkTS端成功调用native侧接口setProperty | 位于主页 | 点击文本为2.napiSetProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetPropertySuccess | Pass | -| ArkTS端成功调用native侧接口getProperty | 位于主页 | 点击文本为3.napiGetProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetPropertySuccess | Pass | -| ArkTS端成功调用native侧接口hasProperty | 位于主页 | 点击文本为4.napiHasProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasPropertySuccess | Pass | -| ArkTS端成功调用native侧接口napiDeleteProperty | 位于主页 | 点击文本为5.napiDeleteProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDeletePropertySuccess | Pass | -| ArkTS端成功调用native侧接口napiHasOwnProperty | 位于主页 | 点击文本为6.napiHasOwnProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasOwnPropertySuccess | Pass | -| ArkTS端成功调用native侧接口napiSetNamedProperty | 位于主页 | 点击文本为7.napiSetNamedProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiSetNamedPropertySuccess | Pass | -| ArkTS端成功调用native侧接口napiGetNamedProperty | 位于主页 | 点击文本为8.napiGetNamedProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetNamedPropertySuccess | Pass | -| ArkTS端成功调用native侧接口napiHasNamedProperty | 位于主页 | 点击文本为9.napiHasNamedProperty的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiHasNamedPropertySuccess | Pass | -| ArkTS端成功调用native侧接口defineStringProperties | 位于主页 | 点击文本为10.napiDefineProperties的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiDefinePropertiesSuccess | Pass | -| ArkTS端成功调用native侧接口getAllPropertyNames | 位于主页 | 点击文本为11.napiGetAllPropertyNames的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiGetAllPropertyNamesSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/app.json5 deleted file mode 100755 index 086121a9d82fc6cc7a95272500525b0550fac0d5..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapicustomasynchronousoperations", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/element/string.json deleted file mode 100755 index 82222f6bc7b661191f5b6be67115fead8ec2ca75..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeApiCustomAsynchronousOperations" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/README.md deleted file mode 100755 index 09e0b21ff903be0266b8731740aa3f3eeaaf9027..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# ArkTS使用Node-API进行自定义异步操作相关开发 - -### 介绍 - -使用Node-API的自定义异步操作功能,可以使ArkTS的使用更加灵活和高效,可以处理那些可能阻塞事件循环的长时间运行任务,同时保持ArkTS应用的响应性和性能。 - -本工程主要展示了使用Node-API进行创建和销毁异步资源上下文环境、在异步资源上下文环境中执行ArkTS回调函数和创建关闭回调作用域实现场景,其中代码详细描述可查如下链接。 - -- [使用Node-API进行自定义异步操作相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-custom-asynchronous-operations.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeApiCustomAsynchronousOperations.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行自定义异步操作相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeApiCustomAsynchronousOperations.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 43195022194e30b2d7511f3b8a52ed52936c1e70..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(use_napi_about_custom_asynchronous_operations) - -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) - -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libhilog_ndk.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index 40da20536c6dd2181b10e5c06b7ec00d6586cc45..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_async_open_close_callback_scope] -#include "napi/native_api.h" - -static constexpr int INT_ARG_3 = 3; // 入参索引 - -static napi_value AsynchronousWork(napi_env env, napi_callback_info info) -{ - // 接受四个参数 - size_t argc = 4; - napi_value args[4] = {nullptr}; - // 从回调信息中获取参数 - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 提取参数中的资源、接收器对象和函数 - napi_value resource = args[0]; - napi_value recv = args[1]; - napi_value func = args[2]; - napi_value argv[1] = {nullptr}; - argv[0] = args[INT_ARG_3]; - // 获取函数的类型 - napi_valuetype funcType; - napi_typeof(env, func, &funcType); - // 创建一个资源名称为"test"的字符串 - napi_value resourceName = nullptr; - napi_create_string_utf8(env, "test", NAPI_AUTO_LENGTH, &resourceName); - // 初始化异步上下文 - napi_async_context context; - napi_status status = napi_async_init(env, resource, resourceName, &context); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_async_init fail"); - return nullptr; - } - // 打开回调作用域 - napi_callback_scope scope = nullptr; - napi_open_callback_scope(env, resource, context, &scope); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_open_callback_scope fail"); - return nullptr; - } - // 调用回调函数 - napi_value result = nullptr; - if (funcType == napi_function) { - napi_make_callback(env, context, recv, func, 1, argv, &result); - } else { - napi_throw_error(env, nullptr, "Unexpected argument type"); - return nullptr; - } - // 关闭回调作用域 - napi_close_callback_scope(env, scope); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "napi_close_callback_scope fail"); - return nullptr; - } - // 销毁异步上下文 - napi_async_destroy(env, context); - return result; -} -// [End napi_async_open_close_callback_scope] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"asynchronousWork", nullptr, AsynchronousWork, 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 9c9248788fc85a8c6867c39e5eaf52d45dae4874..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_async_open_close_callback_scope_api] -export const asynchronousWork: (object: Object, obj: Object, fun: Function, num: number) => number | void; -// [End napi_async_open_close_callback_scope_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index e4e96d5ce3e21044466eabdc935a27907f9ee299..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start ark_napi_async_open_close_callback_scope] -import { hilog } from '@kit.PerformanceAnalysisKit'; -import testNapi from 'libentry.so'; -import process from '@ohos.process'; - -// [StartExclude ark_napi_async_open_close_callback_scope] -@Entry -@Component -struct Index { - @State result: string = ''; - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(25) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 3 }) - List({ space: '10vp' }) { - ListItem() { - Text('1.customAsync') - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - // [EndExclude ark_napi_async_open_close_callback_scope] - try { - hilog.info(0x0000, 'testTag', 'Test Node-API asynchronousWork: %{public}d', - testNapi.asynchronousWork({}, process.ProcessManager, (num: number) => { - return num; - }, 123)); - this.result = 'customAsyncSuccess'; - } catch (error) { - hilog.error(0x0000, 'testTag', 'Test Node-API asynchronousWork error: %{public}s', error.message); - this.result = 'customAsyncFail'; - } - // [End ark_napi_async_open_close_callback_scope] - }) - } - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/ohosTest.md deleted file mode 100755 index 97fd0ca5628ce851f2214a2dc77ea69e4eb38f94..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiCustomAsynchronousOperations/ohosTest.md +++ /dev/null @@ -1,8 +0,0 @@ -# 使用Node-API进行自定义异步操作相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------- | ------------ | --------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口asynchronousWork | 位于主页 | 点击文本为1.customAsync的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: customAsyncSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/app.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/app.json5 deleted file mode 100755 index ddd54162f1f0620ff0abf7515777f1abe9422368..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/app.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.nodeapistring", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/element/string.json deleted file mode 100755 index a872f762a36554b043785984b106f2cad6f0eeab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/AppScope/resources/base/element/string.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NodeApiString" - } - ] -} diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/README.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/README.md deleted file mode 100755 index 7b8fb028ebb02653d7741a41b5216b3a3158c6c1..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# ArkTS使用Node-API进行string相关开发 - -### 介绍 - -使用Node-API关于string的六个接口,可以让Node-API模块和ArkTS字符串进行交互,本工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [使用Node-API进行string相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-napi-about-string.md) - -### 效果预览 - -| 首页 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述首页效果,分别点击ListItem组件可以执行对应文本内容的Node-API接口并将文本Result:改为执行成功结果,然后在控制台中打印出对应日志。 -3. 运行测试用例NodeApiString.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── Index.d.ts - │ │ ├── oh-package.json5 - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用Node-API进行string相关开发示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── NodeApiString.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/build-profile.json5 deleted file mode 100755 index df8b8004f9207069a86cc1b12716cdcdb73f9072..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/build-profile.json5 +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/build-profile.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/build-profile.json5 deleted file mode 100755 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/build-profile.json5 +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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", - "armeabi-v7a" - ] - } - }, - "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/NodeAPI/NodeApiUse/NodeApiString/entry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/oh-package.json5 deleted file mode 100755 index 5d993e5251fd56950970aa593aefef1b8d71e976..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/oh-package.json5 +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/CMakeLists.txt deleted file mode 100755 index 603a636c479e6735f639475d16c1c1750770283c..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(use_napi_about_string) - -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) -add_definitions( "-DLOG_DOMAIN=0xd0d0" ) -add_definitions( "-DLOG_TAG=\"testTag\"" ) -target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp deleted file mode 100755 index ca0393188e61dae127322c2ddb3d6b6b61010a94..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/napi_init.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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 -#include - -static const int MAX_BUFFER_SIZE = 128; - -// [Start napi_get_value_string_utf8] -static napi_value GetValueStringUtf8(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取字符串的长度 - size_t length = 0; - napi_status status = napi_get_value_string_utf8(env, args[0], nullptr, 0, &length); - // 传入一个非字符串 napi_get_value_string_utf8接口会返回napi_string_expected - if (status != napi_ok) { - return nullptr; - } - char *buf = new char[length + 1]; - std::memset(buf, 0, length + 1); - napi_get_value_string_utf8(env, args[0], buf, length + 1, &length); - napi_value result = nullptr; - status = napi_create_string_utf8(env, buf, length, &result); - delete buf; - if (status != napi_ok) { - return nullptr; - }; - return result; -} -// [End napi_get_value_string_utf8] - -// [Start napi_create_string_utf8] -static napi_value CreateStringUtf8(napi_env env, napi_callback_info info) -{ - const char *str = u8"你好, World!, successes to create UTF-8 string! 111"; - size_t length = strlen(str); - napi_value result = nullptr; - napi_status status = napi_create_string_utf8(env, str, length, &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Failed to create UTF-8 string"); - return nullptr; - } - return result; -} -// [End napi_create_string_utf8] - -// [Start napi_get_value_string_utf16] -static napi_value GetValueStringUtf16(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1]; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - napi_value result = nullptr; - // 字符串的缓冲区 - char16_t buffer[MAX_BUFFER_SIZE]; - // 字符串的缓冲区大小 - size_t bufferSize = MAX_BUFFER_SIZE; - // 字符串的长度 - size_t stringLen; - // 获取字符串的数据和长度 - napi_get_value_string_utf16(env, args[0], buffer, bufferSize, &stringLen); - // 获取字符串返回结果 - napi_create_string_utf16(env, buffer, stringLen, &result); - // 返回结果 - return result; -} -// [End napi_get_value_string_utf16] - -// [Start napi_create_string_utf16] -static napi_value CreateStringUtf16(napi_env env, napi_callback_info info) -{ - const char16_t *str = u"你好, World!, successes to create UTF-16 string! 111"; - size_t length = NAPI_AUTO_LENGTH; - napi_value result = nullptr; - napi_status status = napi_create_string_utf16(env, str, length, &result); - if (status != napi_ok) { - napi_throw_error(env, nullptr, "Failed to create UTF-16 string"); - return nullptr; - } - return result; -} -// [End napi_create_string_utf16] - -// [Start napi_get_value_string_latin1] -static napi_value GetValueStringLatin1(napi_env env, napi_callback_info info) -{ - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - char buf[MAX_BUFFER_SIZE]; - size_t length = 0; - napi_value napi_Res = nullptr; - napi_status status = napi_get_value_string_latin1(env, args[0], buf, MAX_BUFFER_SIZE, &length); - // 当输入的值不是字符串时,接口会返回napi_string_expected - if (status == napi_string_expected) { - return nullptr; - } - napi_create_string_latin1(env, buf, length, &napi_Res); - return napi_Res; -} -// [End napi_get_value_string_latin1] - -// [Start napi_create_string_latin1] -static napi_value CreateStringLatin1(napi_env env, napi_callback_info info) -{ - const char *str = "Hello, World! éçñ, successes to create Latin1 string! 111"; - size_t length = NAPI_AUTO_LENGTH; - napi_value result = nullptr; - napi_status status = napi_create_string_latin1(env, str, length, &result); - if (status != napi_ok) { - // 处理错误 - napi_throw_error(env, nullptr, "Failed to create Latin1 string"); - return nullptr; - } - return result; -} -// [End napi_create_string_latin1] - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"getValueStringUtf8", nullptr, GetValueStringUtf8, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createStringUtf8", nullptr, CreateStringUtf8, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueStringUtf16", nullptr, GetValueStringUtf16, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createStringUtf16", nullptr, CreateStringUtf16, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"getValueStringLatin1", nullptr, GetValueStringLatin1, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createStringLatin1", nullptr, CreateStringLatin1, 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts deleted file mode 100755 index 905a15b94b99fd538f941e31bf2548463e4df799..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/Index.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// [Start napi_get_value_string_utf8_api] -export const getValueStringUtf8: (param: string | number) => string | void; -// [End napi_get_value_string_utf8_api] - -// [Start napi_create_string_utf8_api] -export const createStringUtf8: () => string | void; -// [End napi_create_string_utf8_api] - -// [Start napi_get_value_string_utf16_api] -export const getValueStringUtf16: (data: string) => string; -// [End napi_get_value_string_utf16_api] - -// [Start napi_create_string_utf16_api] -export const createStringUtf16: () => string | void; -// [End napi_create_string_utf16_api] - -// [Start napi_get_value_string_latin1_api] -export const getValueStringLatin1: (param: number | string) => string | void; -// [End napi_get_value_string_latin1_api] - -// [Start napi_create_string_latin1_api] -export const createStringLatin1: () => string | void; -// [End napi_create_string_latin1_api] \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/oh-package.json5 deleted file mode 100755 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/cpp/types/libentry/oh-package.json5 +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entryability/EntryAbility.ets deleted file mode 100755 index a36ca588fe1aa322e8fca13744debe6f29d41d44..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entryability/EntryAbility.ets +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets deleted file mode 100755 index 1504a74f09dfdcfae408be979f99369a2c5affab..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets deleted file mode 100755 index 01466b983d3f514bf81df8212e8e56e4c1628540..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/ets/pages/Index.ets +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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'; - -@Entry -@Component -struct Index { - @State result: string = '' - private items: string[] = [ - 'Reset Result Message', - '1.napiString' - ] - - build() { - Column() { - Text('Result: ' + this.result) - .fontSize(22) - .fontWeight(FontWeight.Bold) - .margin({ bottom: 4 }) - List({ space: '10vp' }) { - ForEach(this.items, (item: string) => { - ListItem() { - Text(item) - .fontSize(16) - .width('100%') - .height(60) - .textAlign(TextAlign.Center) - .fontWeight(FontWeight.Bold) - .borderRadius(30) - .backgroundColor(Color.White) - .onClick(() => { - if (item === 'Reset Result Message') { - this.result = ''; - } else if (item === '1.napiString') { - // [Start ark_napi_get_value_string_utf8] - // 分别传入字符和非字符检测接口,传入字符串类型的数据将返回原字符串,传入其他类型返回undefined - hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_string %{public}s', - testNapi.getValueStringUtf8('aaBC+-$%^你好123')); - hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_utf8_not_string %{public}s', - testNapi.getValueStringUtf8(50)); - // [End ark_napi_get_value_string_utf8] - // [Start ark_napi_create_string_utf8] - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf8:%{public}s', - testNapi.createStringUtf8()); - // [End ark_napi_create_string_utf8] - // [Start ark_napi_get_value_string_utf16] - let result = testNapi.getValueStringUtf16('hello,'); - hilog.info(0x0000, 'testTag', 'Node-API napi_get_value_string_utf16:%{public}s', result); - // [End ark_napi_get_value_string_utf16] - // [Start ark_napi_create_string_utf16] - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_utf16:%{public}s ', - testNapi.createStringUtf16()); - // [End ark_napi_create_string_utf16] - // [Start ark_napi_get_value_string_latin1] - // 传入非字符型数据,函数返回undefined - hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_not_string %{public}s', - testNapi.getValueStringLatin1(10)); - // ISO-8859-1编码不支持中文,传入中文字符会乱码 - hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_string_chinese %{public}s', - testNapi.getValueStringLatin1('中文')); - // 传入其他字符,不会乱码 - hilog.info(0x0000, 'testTag', 'Test Node-API get_value_string_latin1_string %{public}s', - testNapi.getValueStringLatin1('abo ABP=-&*/')); - // [End ark_napi_get_value_string_latin1] - // [Start ark_napi_create_string_latin1] - hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_string_latin1:%{public}s', - testNapi.createStringLatin1()); - // End ark_napi_create_string_latin1] - this.result = 'napiStringSuccess'; - } - }) - } - }) - }.scrollBar(BarState.Off) - .width('90%') - }.width('100%') - .height('100%') - .backgroundColor(0xDCDCDC) - .padding({ top: 5 }) - } -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/module.json5 deleted file mode 100755 index 776ce01475229d674487a2830790c4c87b777379..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/module.json5 +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/color.json deleted file mode 100755 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/backup_config.json deleted file mode 100755 index d742c2f96e7dd0f406f499941f3147345e998f95..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/base/profile/backup_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "allowToBackupRestore": true -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/dark/element/color.json b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/dark/element/color.json deleted file mode 100755 index 438d5bc43bb23c59c210d586b96635a72da5b64a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/main/resources/dark/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] -} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/module.json5 deleted file mode 100755 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/hvigor/hvigor-config.json5 deleted file mode 100755 index cef74543b1f97c82275e4bf3434b162395bff2eb..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/hvigor/hvigor-config.json5 +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/oh-package.json5 b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/oh-package.json5 deleted file mode 100755 index eaef52736f22c14e04fca386ba01611ab32a7e4a..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/oh-package.json5 +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/NodeAPI/NodeApiUse/NodeApiString/ohosTest.md b/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/ohosTest.md deleted file mode 100755 index b476a5dddbd34573c7950e3ba8b6966e68d42d89..0000000000000000000000000000000000000000 --- a/code/DocsSample/ArkTs/NodeAPI/NodeApiUse/NodeApiString/ohosTest.md +++ /dev/null @@ -1,8 +0,0 @@ -# 使用Node-API进行string相关开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | -| ------------------------------------------------------------ | ------------ | -------------------------------- | ------------------------------------------------------------ | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | Pass | -| ArkTS端成功调用native侧接口 getValueStringUtf8,createStringUtf8,getValueStringUtf16, createStringUtf16, getValueStringLatin1,createStringLatin1 | 位于主页 | 点击文本为1.napiString的文本组件 | 成功调用函数输出日志,页面顶端文本变为Result: napiStringSuccess | Pass | \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/app.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/app.json5 index 64b99a033e76ea4541fcbbc80786d006e696b9b0..f7577827b36afb6290cc582112dc8fca4c8b4d26 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/app.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/app.json5 @@ -1,26 +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. - * -*/ - -{ - "app": { - "bundleName": "com.samples.statemgmtv2mvvm", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.statemgmtv2mvvm", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/resources/base/element/string.json b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/resources/base/element/string.json index dc01ed969af3f2ddb82c281ad6ba631a48d0f0b5..cf5987edb18c933a791e998503844448e32a6da3 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "StateMgmtV2MVVM" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "StateMgmtV2MVVM" + } + ] +} diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/README.md b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/README.md index 9ea5138d6023bc2070f6afde7cfa11d0c24bca59..b96a86d0acf011411420defa423083c9ea760b98 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/README.md +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/README.md @@ -1,71 +1,71 @@ -# MVVM模式(状态管理V2)示例 - -### 介绍 -本教程通过一个简单的待办事项应用示例,逐步引入了状态管理V2装饰器,并通过代码重构实现了MVVM架构。最终,将数据、逻辑和视图分层,使得代码结构更加清晰、易于维护。 - -### 效果预览 -|TodoList页面 | -|----------------------------------------------| -|![todolist](./screenshots/MVVMV2-todolist.gif)| - -使用说明 -1. 点击任务切换任务完成状态; -2. 点击删除、输入添加新任务完成任务增删; -3. 点击全部完成、全部未完成更新所有任务完成状态; -4. 点击设置,更新是否显示已完成任务。 - -### 工程目录 -``` -/src -├── /main -│ ├── /ets -│ │ ├── /entryability -│ │ ├── /model //重构后的Model层 -│ │ │ ├── TaskListModel.ets -│ │ │ └── TaskModel.ets -│ │ ├── /pages //通过状态管理V2版本实现ViewModel -│ │ │ ├── 1-Basic.ets -│ │ │ ├── 2-Local.ets -│ │ │ ├── 3-Param.ets -│ │ │ ├── 4-Event.ets -│ │ │ ├── 5-Repeat.ets -│ │ │ ├── 6-ObservedV2Trace.ets -│ │ │ ├── 7-MonitorComputed.ets -│ │ │ ├── 8-AppStorageV2.ets -│ │ │ ├── 9-PersistenceV2.ets -│ │ │ ├── 10-Builder.ets -│ │ │ ├── SettingPage.ets //设置页 -│ │ │ └── TodoListPage.ets //重构后的主页面 -│ │ ├── /settingability -│ │ ├── /view //重构后的View层 -│ │ │ ├── BottomView.ets -│ │ │ ├── ListView.ets -│ │ │ └── TitleView.ets -│ │ ├── /viewmodel //重构后的ViewModel层 -│ │ │ ├── TaskListViewModel.ets -│ │ │ └── TaskViewModel.ets -│ └── /resources -│ ├── ... -├─── ... -``` - -### 相关权限 -不涉及。 - -### 依赖 -不涉及。 - -### 约束与限制 -1. 本示例仅支持标准系统上运行,支持设备:RK3568; -2. 本示例为Stage模型,已适配API12版本SDK,SDK版本号5.0.0.71; -3. 本示例需要使用DevEco Studio 版本号(5.0.3.900)版本才可编译运行。 - -### 下载 -如需单独下载本工程,执行如下命令: -``` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkUISample/StateMgmtV2MVVM > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` +# MVVM模式(状态管理V2)示例 + +### 介绍 +本教程通过一个简单的待办事项应用示例,逐步引入了状态管理V2装饰器,并通过代码重构实现了MVVM架构。最终,将数据、逻辑和视图分层,使得代码结构更加清晰、易于维护。 + +### 效果预览 +|TodoList页面 | +|----------------------------------------------| +|![todolist](./screenshots/MVVMV2-todolist.gif)| + +使用说明 +1. 点击任务切换任务完成状态; +2. 点击删除、输入添加新任务完成任务增删; +3. 点击全部完成、全部未完成更新所有任务完成状态; +4. 点击设置,更新是否显示已完成任务。 + +### 工程目录 +``` +/src +├── /main +│ ├── /ets +│ │ ├── /entryability +│ │ ├── /model //重构后的Model层 +│ │ │ ├── TaskListModel.ets +│ │ │ └── TaskModel.ets +│ │ ├── /pages //通过状态管理V2版本实现ViewModel +│ │ │ ├── 1-Basic.ets +│ │ │ ├── 2-Local.ets +│ │ │ ├── 3-Param.ets +│ │ │ ├── 4-Event.ets +│ │ │ ├── 5-Repeat.ets +│ │ │ ├── 6-ObservedV2Trace.ets +│ │ │ ├── 7-MonitorComputed.ets +│ │ │ ├── 8-AppStorageV2.ets +│ │ │ ├── 9-PersistenceV2.ets +│ │ │ ├── 10-Builder.ets +│ │ │ ├── SettingPage.ets //设置页 +│ │ │ └── TodoListPage.ets //重构后的主页面 +│ │ ├── /settingability +│ │ ├── /view //重构后的View层 +│ │ │ ├── BottomView.ets +│ │ │ ├── ListView.ets +│ │ │ └── TitleView.ets +│ │ ├── /viewmodel //重构后的ViewModel层 +│ │ │ ├── TaskListViewModel.ets +│ │ │ └── TaskViewModel.ets +│ └── /resources +│ ├── ... +├─── ... +``` + +### 相关权限 +不涉及。 + +### 依赖 +不涉及。 + +### 约束与限制 +1. 本示例仅支持标准系统上运行,支持设备:RK3568; +2. 本示例为Stage模型,已适配API12版本SDK,SDK版本号5.0.0.71; +3. 本示例需要使用DevEco Studio 版本号(5.0.3.900)版本才可编译运行。 + +### 下载 +如需单独下载本工程,执行如下命令: +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/StateMgmtV2MVVM > .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/ArkUISample/StateMgmtV2MVVM/build-profile.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/build-profile.json5 index 068fb1d5130a2e7a20f4c00d3d1d39c8a0331a6c..71b86b9431cd01ba5398380316ee1395b015a482 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/build-profile.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/build-profile.json5 @@ -1,59 +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. - * -*/ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 12, - "compatibleSdkVersion": 12, - "targetSdkVersion": 12, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 12, + "compatibleSdkVersion": 12, + "targetSdkVersion": 12, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/build-profile.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/build-profile.json5 index e0c30185bef05e67eda9977d8463414bc1c6ab0a..8aa2bcfce36d1ffcf3270c31ababe454db140d49 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/build-profile.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/build-profile.json5 @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/oh-package.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/oh-package.json5 index 887dfe3d461cb1e08f9b039e1866bf0ea31b5c94..f39a70cf782d6b466aab699e20c7679d9d3e8269 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/oh-package.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/oh-package.json5 @@ -1,26 +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": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/entryability/EntryAbility.ets index ef43aaabee47a8a27b9a567c048ddc858941db68..98e92a1c2a375f10ee5662d91d247a64fd5cfbc7 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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, 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/TodoListPage', (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'); - } -} +/* + * 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/TodoListPage', (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/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskListModel.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskListModel.ets index 325579b96a0e23c7ef7a9dff6aeddc54486c45e5..9167605416e7308fb01ad9048d8632ea999b1075 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskListModel.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskListModel.ets @@ -1,42 +1,42 @@ -/* - * 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. - * -*/ - -// src/main/ets/model/TaskListModel.ets - -import { common } from '@kit.AbilityKit'; -import util from '@ohos.util'; -import TaskModel from'./TaskModel'; - -export default class TaskListModel { - public tasks: TaskModel[] = []; - - constructor(tasks: TaskModel[]) { - this.tasks = tasks; - } - - async loadTasks(context: common.UIAbilityContext){ - let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); - let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; - let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); - let result = textDecoder.decodeToString(getJson); - this.tasks =JSON.parse(result).map((task: TaskModel)=>{ - let newTask = new TaskModel(); - newTask.taskName = task.taskName; - newTask.isFinish = task.isFinish; - return newTask; - }); - } +/* + * 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. + * +*/ + +// src/main/ets/model/TaskListModel.ets + +import { common } from '@kit.AbilityKit'; +import util from '@ohos.util'; +import TaskModel from'./TaskModel'; + +export default class TaskListModel { + public tasks: TaskModel[] = []; + + constructor(tasks: TaskModel[]) { + this.tasks = tasks; + } + + async loadTasks(context: common.UIAbilityContext){ + let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); + let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; + let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); + let result = textDecoder.decodeToString(getJson); + this.tasks =JSON.parse(result).map((task: TaskModel)=>{ + let newTask = new TaskModel(); + newTask.taskName = task.taskName; + newTask.isFinish = task.isFinish; + return newTask; + }); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskModel.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskModel.ets index 10fe902b6a0b1ac86cd86cfbc30ab70e47d5d215..4fda48d268eed03fa5f89784626fb046e134073f 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskModel.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/model/TaskModel.ets @@ -1,22 +1,22 @@ -/* - * 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. - * -*/ - -// src/main/ets/model/TaskModel.ets - -export default class TaskModel { - public taskName: string = 'Todo'; - public isFinish: boolean = false; +/* + * 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. + * +*/ + +// src/main/ets/model/TaskModel.ets + +export default class TaskModel { + public taskName: string = 'Todo'; + public isFinish: boolean = false; } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/10-Builder.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/10-Builder.ets index 5805f767d50611c2a122a1b58c6a3bd17261c020..a02aa9a48f06d0b1e3704cc75bc505e24f150692 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/10-Builder.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/10-Builder.ets @@ -1,160 +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. - * -*/ - -// src/main/ets/pages/10-Builder.ets - -import { AppStorageV2, PersistenceV2, Type } from '@kit.ArkUI'; -import { common, Want } from '@kit.AbilityKit'; -import { Setting } from './SettingPage'; -import util from '@ohos.util'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -@ObservedV2 -class Task { - // 未实现构造函数,因为@Type当前不支持带参数的构造函数 - @Trace public taskName: string = 'Todo'; - @Trace public isFinish: boolean = false; -} - -@Builder function actionButton(text: string|Resource, onClick:() => void) { - Button(text, { buttonStyle: ButtonStyleMode.NORMAL }) - .onClick(onClick) - .margin({ left: 10, right: 10, top: 5, bottom: 5 }) -} - -@ObservedV2 -class TaskList { - // 对于复杂对象需要@Type修饰,确保序列化成功 - @Type(Task) - @Trace public tasks: Task[] = []; - - constructor(tasks: Task[]) { - this.tasks = tasks; - } - - async loadTasks(context: common.UIAbilityContext) { - let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); - let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; - let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); - let result = textDecoder.decodeToString(getJson); - this.tasks =JSON.parse(result).map((task: Task)=>{ - let newTask = new Task(); - newTask.taskName = task.taskName; - newTask.isFinish = task.isFinish; - return newTask; - }); - } -} - -@ComponentV2 -struct TaskItem { - @Param task: Task = new Task(); - @Event deleteTask: () => void = () => {}; - @Monitor('task.isFinish') - onTaskFinished(mon: IMonitor) { - hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); - } - - build() { - Row() { - Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - .margin({ left : 15, right : 10 }) - Text(this.task.taskName) - .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - .fontSize(18) - actionButton($r('app.string.Delete_task'), () => this.deleteTask()) - } - .height('7%') - .width('90%') - .backgroundColor('#90f1f3f5') - .borderRadius(25) - .onClick(() => this.task.isFinish = !this.task.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local taskList: TaskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; - @Local newTaskName: string = ''; - @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; - private context = getContext(this) as common.UIAbilityContext; - - async aboutToAppear() { - this.taskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; - if (this.taskList.tasks.length === 0) { - await this.taskList.loadTasks(this.context); - } - } - - finishAll(ifFinish: boolean) { - for (let task of this.taskList.tasks) { - task.isFinish = ifFinish; - } - } - - @Computed - get tasksUnfinished(): number { - return this.taskList.tasks.filter(task => !task.isFinish).length; - } - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin(10) - Text(`${this.context.resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) - .margin({ left: 10, bottom: 10 }) - Repeat(this.taskList.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) - .each((obj: RepeatItem) => { - TaskItem({ - task: obj.item, - deleteTask: () => this.taskList.tasks.splice(this.taskList.tasks.indexOf(obj.item), 1) - }).margin(5) - }) - Row() { - actionButton($r('app.string.Finish_all_tasks'), (): void => this.finishAll(true)) - actionButton($r('app.string.Unfinish_all_tasks'), (): void => this.finishAll(false)) - actionButton($r('app.string.Setting'), (): void => { - let wantInfo: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName - abilityName: 'SettingAbility', - }; - this.context.startAbility(wantInfo); - }) - } - .margin({ top: 10, bottom: 5 }) - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - actionButton('+', (): void => { - let newTask = new Task(); - newTask.taskName = this.newTaskName; - this.taskList.tasks.push(newTask); - this.newTaskName = ''; - }) - } - } - .height('100%') - .width('100%') - .alignItems(HorizontalAlign.Start) - .margin({ left: 15 }) - } +/* + * 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. + * +*/ + +// src/main/ets/pages/10-Builder.ets + +import { AppStorageV2, PersistenceV2, Type } from '@kit.ArkUI'; +import { common, Want } from '@kit.AbilityKit'; +import { Setting } from './SettingPage'; +import util from '@ohos.util'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +@ObservedV2 +class Task { + // 未实现构造函数,因为@Type当前不支持带参数的构造函数 + @Trace public taskName: string = 'Todo'; + @Trace public isFinish: boolean = false; +} + +@Builder function actionButton(text: string|Resource, onClick:() => void) { + Button(text, { buttonStyle: ButtonStyleMode.NORMAL }) + .onClick(onClick) + .margin({ left: 10, right: 10, top: 5, bottom: 5 }) +} + +@ObservedV2 +class TaskList { + // 对于复杂对象需要@Type修饰,确保序列化成功 + @Type(Task) + @Trace public tasks: Task[] = []; + + constructor(tasks: Task[]) { + this.tasks = tasks; + } + + async loadTasks(context: common.UIAbilityContext) { + let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); + let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; + let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); + let result = textDecoder.decodeToString(getJson); + this.tasks =JSON.parse(result).map((task: Task)=>{ + let newTask = new Task(); + newTask.taskName = task.taskName; + newTask.isFinish = task.isFinish; + return newTask; + }); + } +} + +@ComponentV2 +struct TaskItem { + @Param task: Task = new Task(); + @Event deleteTask: () => void = () => {}; + @Monitor('task.isFinish') + onTaskFinished(mon: IMonitor) { + hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); + } + + build() { + Row() { + Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + .margin({ left : 15, right : 10 }) + Text(this.task.taskName) + .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + .fontSize(18) + actionButton($r('app.string.Delete_task'), () => this.deleteTask()) + } + .height('7%') + .width('90%') + .backgroundColor('#90f1f3f5') + .borderRadius(25) + .onClick(() => this.task.isFinish = !this.task.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local taskList: TaskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; + @Local newTaskName: string = ''; + @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; + private context = getContext(this) as common.UIAbilityContext; + + async aboutToAppear() { + this.taskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; + if (this.taskList.tasks.length === 0) { + await this.taskList.loadTasks(this.context); + } + } + + finishAll(ifFinish: boolean) { + for (let task of this.taskList.tasks) { + task.isFinish = ifFinish; + } + } + + @Computed + get tasksUnfinished(): number { + return this.taskList.tasks.filter(task => !task.isFinish).length; + } + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin(10) + Text(`${this.context.resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) + .margin({ left: 10, bottom: 10 }) + Repeat(this.taskList.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) + .each((obj: RepeatItem) => { + TaskItem({ + task: obj.item, + deleteTask: () => this.taskList.tasks.splice(this.taskList.tasks.indexOf(obj.item), 1) + }).margin(5) + }) + Row() { + actionButton($r('app.string.Finish_all_tasks'), (): void => this.finishAll(true)) + actionButton($r('app.string.Unfinish_all_tasks'), (): void => this.finishAll(false)) + actionButton($r('app.string.Setting'), (): void => { + let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName + abilityName: 'SettingAbility', + }; + this.context.startAbility(wantInfo); + }) + } + .margin({ top: 10, bottom: 5 }) + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + actionButton('+', (): void => { + let newTask = new Task(); + newTask.taskName = this.newTaskName; + this.taskList.tasks.push(newTask); + this.newTaskName = ''; + }) + } + } + .height('100%') + .width('100%') + .alignItems(HorizontalAlign.Start) + .margin({ left: 15 }) + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/2-Local.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/2-Local.ets index 6dd42e7a28d056bc218cd14ee569335f220ac823..485bbd5ef4fc0f98a70e16191c4709c42b5bf874 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/2-Local.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/2-Local.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -// src/main/ets/pages/2-Local.ets - -@Entry -@ComponentV2 -struct TodoList { - @Local isFinish: boolean = false; - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - Row() { - Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text('task1') - .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - } - .onClick(() => this.isFinish = !this.isFinish) - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/2-Local.ets + +@Entry +@ComponentV2 +struct TodoList { + @Local isFinish: boolean = false; + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + Row() { + Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text('task1') + .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + } + .onClick(() => this.isFinish = !this.isFinish) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/3-Param.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/3-Param.ets index ae80b7ce2797133f6014f7f443caa4a5cbf0e42b..c474a162bad5dce9ee453e0e8a679516fdb73cb3 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/3-Param.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/3-Param.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -// src/main/ets/pages/3-Param.ets - -@ComponentV2 -struct TaskItem { - @Param taskName: string = ''; - @Param @Once isFinish: boolean = false; - - build() { - Row() { - Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.taskName) - .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - } - .onClick(() => this.isFinish = !this.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - TaskItem({ taskName: 'Task 1', isFinish: false }) - TaskItem({ taskName: 'Task 2', isFinish: false }) - TaskItem({ taskName: 'Task 3', isFinish: false }) - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/3-Param.ets + +@ComponentV2 +struct TaskItem { + @Param taskName: string = ''; + @Param @Once isFinish: boolean = false; + + build() { + Row() { + Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.taskName) + .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + } + .onClick(() => this.isFinish = !this.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + TaskItem({ taskName: 'Task 1', isFinish: false }) + TaskItem({ taskName: 'Task 2', isFinish: false }) + TaskItem({ taskName: 'Task 3', isFinish: false }) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/4-Event.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/4-Event.ets index e1a31f5822e1bb65401b266ca93286f3c8e9be6e..7c7659f5893a5552c29f62d6cc24d1014c49db64 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/4-Event.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/4-Event.ets @@ -1,68 +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. - * -*/ - -// src/main/ets/pages/4-Event.ets - -@ComponentV2 -struct TaskItem { - @Param taskName: string = ''; - @Param @Once isFinish: boolean = false; - @Event deleteTask: () => void = () => {}; - - build() { - Row() { - Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.taskName) - .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - Button($r('app.string.Delete_task')) - .onClick(() => this.deleteTask()) - } - .onClick(() => this.isFinish = !this.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local tasks: string[] = ['task1','task2','task3']; - @Local newTaskName: string = ''; - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - ForEach(this.tasks, (task: string) => { - TaskItem({ - taskName: task, - isFinish: false, - deleteTask: () => this.tasks.splice(this.tasks.indexOf(task), 1) - }) - }) - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - Button('+') - .onClick(() => { - this.tasks.push(this.newTaskName); - this.newTaskName = ''; - }) - } - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/4-Event.ets + +@ComponentV2 +struct TaskItem { + @Param taskName: string = ''; + @Param @Once isFinish: boolean = false; + @Event deleteTask: () => void = () => {}; + + build() { + Row() { + Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.taskName) + .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + Button($r('app.string.Delete_task')) + .onClick(() => this.deleteTask()) + } + .onClick(() => this.isFinish = !this.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local tasks: string[] = ['task1','task2','task3']; + @Local newTaskName: string = ''; + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + ForEach(this.tasks, (task: string) => { + TaskItem({ + taskName: task, + isFinish: false, + deleteTask: () => this.tasks.splice(this.tasks.indexOf(task), 1) + }) + }) + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + Button('+') + .onClick(() => { + this.tasks.push(this.newTaskName); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/5-Repeat.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/5-Repeat.ets index e6b24ff3f2bb0ff9479aeb7842122201341c7fc0..d082c0b3e344227c767f7d1454ce9fe31a11870e 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/5-Repeat.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/5-Repeat.ets @@ -1,69 +1,69 @@ -/* - * 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. - * -*/ - -// src/main/ets/pages/5-Repeat.ets - -@ComponentV2 -struct TaskItem { - @Param taskName: string = ''; - @Param @Once isFinish: boolean = false; - @Event deleteTask: () => void = () => {}; - - build() { - Row() { - Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.taskName) - .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - Button($r('app.string.Delete_task')) - .onClick(() => this.deleteTask()) - } - .onClick(() => this.isFinish = !this.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local tasks: string[] = ['task1','task2','task3']; - @Local newTaskName: string = ''; - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - Repeat(this.tasks) - .each((obj: RepeatItem) => { - TaskItem({ - taskName: obj.item, - isFinish: false, - deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) - }) - }) - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - Button('+') - .onClick(() => { - this.tasks.push(this.newTaskName); - this.newTaskName = ''; - }) - } - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/5-Repeat.ets + +@ComponentV2 +struct TaskItem { + @Param taskName: string = ''; + @Param @Once isFinish: boolean = false; + @Event deleteTask: () => void = () => {}; + + build() { + Row() { + Image(this.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.taskName) + .decoration({ type: this.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + Button($r('app.string.Delete_task')) + .onClick(() => this.deleteTask()) + } + .onClick(() => this.isFinish = !this.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local tasks: string[] = ['task1','task2','task3']; + @Local newTaskName: string = ''; + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + Repeat(this.tasks) + .each((obj: RepeatItem) => { + TaskItem({ + taskName: obj.item, + isFinish: false, + deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) + }) + }) + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + Button('+') + .onClick(() => { + this.tasks.push(this.newTaskName); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/6-ObservedV2Trace.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/6-ObservedV2Trace.ets index 24cb0ed44d3f096d65e09d9225726ffc399f608a..5ab649817c0425fe91975306fee3e84895142a6c 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/6-ObservedV2Trace.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/6-ObservedV2Trace.ets @@ -1,95 +1,95 @@ -/* - * 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. - * -*/ - -// src/main/ets/pages/6-ObservedV2Trace.ets - -@ObservedV2 -class Task { - public taskName: string = ''; - @Trace public isFinish: boolean = false; - - constructor (taskName: string, isFinish: boolean) { - this.taskName = taskName; - this.isFinish = isFinish; - } -} - -@ComponentV2 -struct TaskItem { - @Param task: Task = new Task('', false); - @Event deleteTask: () => void = () => {}; - - build() { - Row() { - Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.task.taskName) - .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - Button($r('app.string.Delete_task')) - .onClick(() => this.deleteTask()) - } - .onClick(() => this.task.isFinish = !this.task.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local tasks: Task[] = [ - new Task('task1', false), - new Task('task2', false), - new Task('task3', false), - ]; - @Local newTaskName: string = ''; - - finishAll(ifFinish: boolean) { - for (let task of this.tasks) { - task.isFinish = ifFinish; - } - } - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - Repeat(this.tasks) - .each((obj: RepeatItem) => { - TaskItem({ - task: obj.item, - deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) - }) - }) - Row() { - Button($r('app.string.Finish_all_tasks')) - .onClick(() => this.finishAll(true)) - Button($r('app.string.Unfinish_all_tasks')) - .onClick(() => this.finishAll(false)) - } - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - Button('+') - .onClick(() => { - this.tasks.push(new Task(this.newTaskName, false)); - this.newTaskName = ''; - }) - } - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/6-ObservedV2Trace.ets + +@ObservedV2 +class Task { + public taskName: string = ''; + @Trace public isFinish: boolean = false; + + constructor (taskName: string, isFinish: boolean) { + this.taskName = taskName; + this.isFinish = isFinish; + } +} + +@ComponentV2 +struct TaskItem { + @Param task: Task = new Task('', false); + @Event deleteTask: () => void = () => {}; + + build() { + Row() { + Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.task.taskName) + .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + Button($r('app.string.Delete_task')) + .onClick(() => this.deleteTask()) + } + .onClick(() => this.task.isFinish = !this.task.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local tasks: Task[] = [ + new Task('task1', false), + new Task('task2', false), + new Task('task3', false), + ]; + @Local newTaskName: string = ''; + + finishAll(ifFinish: boolean) { + for (let task of this.tasks) { + task.isFinish = ifFinish; + } + } + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + Repeat(this.tasks) + .each((obj: RepeatItem) => { + TaskItem({ + task: obj.item, + deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) + }) + }) + Row() { + Button($r('app.string.Finish_all_tasks')) + .onClick(() => this.finishAll(true)) + Button($r('app.string.Unfinish_all_tasks')) + .onClick(() => this.finishAll(false)) + } + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + Button('+') + .onClick(() => { + this.tasks.push(new Task(this.newTaskName, false)); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/7-MonitorComputed.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/7-MonitorComputed.ets index 5715069a8e71727c87cb0ed1cd1fce9c3d62af59..728de6be3cda48b95d7065469eab040df97c4405 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/7-MonitorComputed.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/7-MonitorComputed.ets @@ -1,106 +1,106 @@ -/* - * 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'; - -// src/main/ets/pages/7-MonitorComputed.ets - -@ObservedV2 -class Task { - public taskName: string = ''; - @Trace public isFinish: boolean = false; - - constructor (taskName: string, isFinish: boolean) { - this.taskName = taskName; - this.isFinish = isFinish; - } -} - -@ComponentV2 -struct TaskItem { - @Param task: Task = new Task('', false); - @Event deleteTask: () => void = () => {}; - @Monitor('task.isFinish') - onTaskFinished(mon: IMonitor) { - hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); - } - - build() { - Row() { - Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.task.taskName) - .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - Button($r('app.string.Delete_task')) - .onClick(() => this.deleteTask()) - } - .onClick(() => this.task.isFinish = !this.task.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local tasks: Task[] = [ - new Task('task1', false), - new Task('task2', false), - new Task('task3', false), - ]; - @Local newTaskName: string = ''; - - finishAll(ifFinish: boolean) { - for (let task of this.tasks) { - task.isFinish = ifFinish; - } - } - - @Computed - get tasksUnfinished(): number { - return this.tasks.filter(task => !task.isFinish).length; - } - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - Text(`${getContext(this).resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) - Repeat(this.tasks) - .each((obj: RepeatItem) => { - TaskItem({ - task: obj.item, - deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) - }) - }) - Row() { - Button($r('app.string.Finish_all_tasks')) - .onClick(() => this.finishAll(true)) - Button($r('app.string.Unfinish_all_tasks')) - .onClick(() => this.finishAll(false)) - } - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - Button('+') - .onClick(() => { - this.tasks.push(new Task(this.newTaskName, false)); - this.newTaskName = ''; - }) - } - } - } +/* + * 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'; + +// src/main/ets/pages/7-MonitorComputed.ets + +@ObservedV2 +class Task { + public taskName: string = ''; + @Trace public isFinish: boolean = false; + + constructor (taskName: string, isFinish: boolean) { + this.taskName = taskName; + this.isFinish = isFinish; + } +} + +@ComponentV2 +struct TaskItem { + @Param task: Task = new Task('', false); + @Event deleteTask: () => void = () => {}; + @Monitor('task.isFinish') + onTaskFinished(mon: IMonitor) { + hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); + } + + build() { + Row() { + Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.task.taskName) + .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + Button($r('app.string.Delete_task')) + .onClick(() => this.deleteTask()) + } + .onClick(() => this.task.isFinish = !this.task.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local tasks: Task[] = [ + new Task('task1', false), + new Task('task2', false), + new Task('task3', false), + ]; + @Local newTaskName: string = ''; + + finishAll(ifFinish: boolean) { + for (let task of this.tasks) { + task.isFinish = ifFinish; + } + } + + @Computed + get tasksUnfinished(): number { + return this.tasks.filter(task => !task.isFinish).length; + } + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + Text(`${getContext(this).resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) + Repeat(this.tasks) + .each((obj: RepeatItem) => { + TaskItem({ + task: obj.item, + deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) + }) + }) + Row() { + Button($r('app.string.Finish_all_tasks')) + .onClick(() => this.finishAll(true)) + Button($r('app.string.Unfinish_all_tasks')) + .onClick(() => this.finishAll(false)) + } + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + Button('+') + .onClick(() => { + this.tasks.push(new Task(this.newTaskName, false)); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/8-AppStorageV2.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/8-AppStorageV2.ets index 6fba3c67c16d109330d43ce5ce03970cba34eb1a..1ab1e0441d0f8b93b54fb564633371c41ef943d2 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/8-AppStorageV2.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/8-AppStorageV2.ets @@ -1,121 +1,121 @@ -/* - * 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. - * -*/ - -// src/main/ets/pages/8-AppStorageV2.ets - -import { AppStorageV2 } from '@kit.ArkUI'; -import { common, Want } from '@kit.AbilityKit'; -import { Setting } from './SettingPage'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -@ObservedV2 -class Task { - public taskName: string = ''; - @Trace public isFinish: boolean = false; - - constructor (taskName: string, isFinish: boolean) { - this.taskName = taskName; - this.isFinish = isFinish; - } -} - -@ComponentV2 -struct TaskItem { - @Param task: Task = new Task('', false); - @Event deleteTask: () => void = () => {}; - @Monitor('task.isFinish') - onTaskFinished(mon: IMonitor) { - hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); - } - - build() { - Row() { - Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.task.taskName) - .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - Button($r('app.string.Delete_task')) - .onClick(() => this.deleteTask()) - } - .onClick(() => this.task.isFinish = !this.task.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local tasks: Task[] = [ - new Task('task1', false), - new Task('task2', false), - new Task('task3', false), - ]; - @Local newTaskName: string = ''; - @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; - private context = getContext(this) as common.UIAbilityContext; - - finishAll(ifFinish: boolean) { - for (let task of this.tasks) { - task.isFinish = ifFinish; - } - } - - @Computed - get tasksUnfinished(): number { - return this.tasks.filter(task => !task.isFinish).length; - } - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - Text(`${this.context.resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) - Repeat(this.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) - .each((obj: RepeatItem) => { - TaskItem({ - task: obj.item, - deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) - }) - }) - Row() { - Button($r('app.string.Finish_all_tasks')) - .onClick(() => this.finishAll(true)) - Button($r('app.string.Unfinish_all_tasks')) - .onClick(() => this.finishAll(false)) - Button($r('app.string.Setting')) - .onClick(() => { - let wantInfo: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName - abilityName: 'SettingAbility', - }; - this.context.startAbility(wantInfo); - }) - } - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - Button('+') - .onClick(() => { - this.tasks.push(new Task(this.newTaskName, false)); - this.newTaskName = ''; - }) - } - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/8-AppStorageV2.ets + +import { AppStorageV2 } from '@kit.ArkUI'; +import { common, Want } from '@kit.AbilityKit'; +import { Setting } from './SettingPage'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +@ObservedV2 +class Task { + public taskName: string = ''; + @Trace public isFinish: boolean = false; + + constructor (taskName: string, isFinish: boolean) { + this.taskName = taskName; + this.isFinish = isFinish; + } +} + +@ComponentV2 +struct TaskItem { + @Param task: Task = new Task('', false); + @Event deleteTask: () => void = () => {}; + @Monitor('task.isFinish') + onTaskFinished(mon: IMonitor) { + hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); + } + + build() { + Row() { + Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.task.taskName) + .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + Button($r('app.string.Delete_task')) + .onClick(() => this.deleteTask()) + } + .onClick(() => this.task.isFinish = !this.task.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local tasks: Task[] = [ + new Task('task1', false), + new Task('task2', false), + new Task('task3', false), + ]; + @Local newTaskName: string = ''; + @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; + private context = getContext(this) as common.UIAbilityContext; + + finishAll(ifFinish: boolean) { + for (let task of this.tasks) { + task.isFinish = ifFinish; + } + } + + @Computed + get tasksUnfinished(): number { + return this.tasks.filter(task => !task.isFinish).length; + } + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + Text(`${this.context.resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) + Repeat(this.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) + .each((obj: RepeatItem) => { + TaskItem({ + task: obj.item, + deleteTask: () => this.tasks.splice(this.tasks.indexOf(obj.item), 1) + }) + }) + Row() { + Button($r('app.string.Finish_all_tasks')) + .onClick(() => this.finishAll(true)) + Button($r('app.string.Unfinish_all_tasks')) + .onClick(() => this.finishAll(false)) + Button($r('app.string.Setting')) + .onClick(() => { + let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName + abilityName: 'SettingAbility', + }; + this.context.startAbility(wantInfo); + }) + } + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + Button('+') + .onClick(() => { + this.tasks.push(new Task(this.newTaskName, false)); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/9-PersistenceV2.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/9-PersistenceV2.ets index 41d716edc58e4734aaaadb8f4191f6cc69727d6e..ec18b61f878e01b1ef90d60b625208658c6d2887 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/9-PersistenceV2.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/9-PersistenceV2.ets @@ -1,147 +1,147 @@ -/* - * 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. - * -*/ - -// src/main/ets/pages/9-PersistenceV2.ets - -import { AppStorageV2, PersistenceV2, Type } from '@kit.ArkUI'; -import { common, Want } from '@kit.AbilityKit'; -import { Setting } from './SettingPage'; -import util from '@ohos.util'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -@ObservedV2 -class Task { - // 未实现构造函数,因为@Type当前不支持带参数的构造函数 - @Trace public taskName: string = 'Todo'; - @Trace public isFinish: boolean = false; -} - -@ObservedV2 -class TaskList { - // 对于复杂对象需要@Type修饰,确保序列化成功 - @Type(Task) - @Trace public tasks: Task[] = []; - - constructor(tasks: Task[]) { - this.tasks = tasks; - } - - async loadTasks(context: common.UIAbilityContext) { - let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); - let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; - let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); - let result = textDecoder.decodeToString(getJson); - this.tasks =JSON.parse(result).map((task: Task)=>{ - let newTask = new Task(); - newTask.taskName = task.taskName; - newTask.isFinish = task.isFinish; - return newTask; - }); - } -} - -@ComponentV2 -struct TaskItem { - @Param task: Task = new Task(); - @Event deleteTask: () => void = () => {}; - @Monitor('task.isFinish') - onTaskFinished(mon: IMonitor) { - hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); - } - - build() { - Row() { - Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - Text(this.task.taskName) - .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - Button($r('app.string.Delete_task')) - .onClick(() => this.deleteTask()) - } - .onClick(() => this.task.isFinish = !this.task.isFinish) - } -} - -@Entry -@ComponentV2 -struct TodoList { - @Local taskList: TaskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; - @Local newTaskName: string = ''; - @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; - private context = getContext(this) as common.UIAbilityContext; - - async aboutToAppear() { - this.taskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; - if (this.taskList.tasks.length === 0) { - await this.taskList.loadTasks(this.context); - } - } - - finishAll(ifFinish: boolean) { - for (let task of this.taskList.tasks) { - task.isFinish = ifFinish; - } - } - - @Computed - get tasksUnfinished(): number { - return this.taskList.tasks.filter(task => !task.isFinish).length; - } - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin({ bottom: 10 }) - Text(`${this.context.resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) - Repeat(this.taskList.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) - .each((obj: RepeatItem) => { - TaskItem({ - task: obj.item, - deleteTask: () => this.taskList.tasks.splice(this.taskList.tasks.indexOf(obj.item), 1) - }) - }) - Row() { - Button($r('app.string.Finish_all_tasks')) - .onClick(() => this.finishAll(true)) - Button($r('app.string.Unfinish_all_tasks')) - .onClick(() => this.finishAll(false)) - Button($r('app.string.Setting')) - .onClick(() => { - let wantInfo: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName - abilityName: 'SettingAbility', - }; - this.context.startAbility(wantInfo); - }) - } - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - Button('+') - .onClick(() => { - let newTask = new Task(); - newTask.taskName = this.newTaskName; - this.taskList.tasks.push(newTask); - this.newTaskName = ''; - }) - } - } - } +/* + * 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. + * +*/ + +// src/main/ets/pages/9-PersistenceV2.ets + +import { AppStorageV2, PersistenceV2, Type } from '@kit.ArkUI'; +import { common, Want } from '@kit.AbilityKit'; +import { Setting } from './SettingPage'; +import util from '@ohos.util'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +@ObservedV2 +class Task { + // 未实现构造函数,因为@Type当前不支持带参数的构造函数 + @Trace public taskName: string = 'Todo'; + @Trace public isFinish: boolean = false; +} + +@ObservedV2 +class TaskList { + // 对于复杂对象需要@Type修饰,确保序列化成功 + @Type(Task) + @Trace public tasks: Task[] = []; + + constructor(tasks: Task[]) { + this.tasks = tasks; + } + + async loadTasks(context: common.UIAbilityContext) { + let getJson = await context.resourceManager.getRawFileContent('defaultTasks.json'); + let textDecoderOptions: util.TextDecoderOptions = { ignoreBOM : true }; + let textDecoder = util.TextDecoder.create('utf-8',textDecoderOptions); + let result = textDecoder.decodeToString(getJson); + this.tasks =JSON.parse(result).map((task: Task)=>{ + let newTask = new Task(); + newTask.taskName = task.taskName; + newTask.isFinish = task.isFinish; + return newTask; + }); + } +} + +@ComponentV2 +struct TaskItem { + @Param task: Task = new Task(); + @Event deleteTask: () => void = () => {}; + @Monitor('task.isFinish') + onTaskFinished(mon: IMonitor) { + hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); + } + + build() { + Row() { + Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + Text(this.task.taskName) + .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + Button($r('app.string.Delete_task')) + .onClick(() => this.deleteTask()) + } + .onClick(() => this.task.isFinish = !this.task.isFinish) + } +} + +@Entry +@ComponentV2 +struct TodoList { + @Local taskList: TaskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; + @Local newTaskName: string = ''; + @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; + private context = getContext(this) as common.UIAbilityContext; + + async aboutToAppear() { + this.taskList = PersistenceV2.connect(TaskList, 'TaskList', () => new TaskList([]))!; + if (this.taskList.tasks.length === 0) { + await this.taskList.loadTasks(this.context); + } + } + + finishAll(ifFinish: boolean) { + for (let task of this.taskList.tasks) { + task.isFinish = ifFinish; + } + } + + @Computed + get tasksUnfinished(): number { + return this.taskList.tasks.filter(task => !task.isFinish).length; + } + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin({ bottom: 10 }) + Text(`${this.context.resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) + Repeat(this.taskList.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) + .each((obj: RepeatItem) => { + TaskItem({ + task: obj.item, + deleteTask: () => this.taskList.tasks.splice(this.taskList.tasks.indexOf(obj.item), 1) + }) + }) + Row() { + Button($r('app.string.Finish_all_tasks')) + .onClick(() => this.finishAll(true)) + Button($r('app.string.Unfinish_all_tasks')) + .onClick(() => this.finishAll(false)) + Button($r('app.string.Setting')) + .onClick(() => { + let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName + abilityName: 'SettingAbility', + }; + this.context.startAbility(wantInfo); + }) + } + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + Button('+') + .onClick(() => { + let newTask = new Task(); + newTask.taskName = this.newTaskName; + this.taskList.tasks.push(newTask); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/SettingPage.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/SettingPage.ets index a5b2227f78e37b8c9b253a27d20be0301c92b1d8..e427401259fd0f1f93e87cc8a97a6310718fb151 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/SettingPage.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/SettingPage.ets @@ -1,51 +1,51 @@ -/* - * 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. - * -*/ - -// src/main/ets/pages/SettingPage.ets - -import { AppStorageV2 } from '@kit.ArkUI'; -import { common } from '@kit.AbilityKit'; - -@ObservedV2 -export class Setting { - @Trace public showCompletedTask: boolean = true; -} - -@Entry -@ComponentV2 -struct SettingPage { - @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; - private context = getContext(this) as common.UIAbilityContext; - - build(){ - Column(){ - Text($r('app.string.Setting')) - .fontSize(40) - .margin({ bottom: 10 }) - Row() { - Text($r('app.string.Show_finished_tasks')) - Toggle({ type: ToggleType.Switch, isOn:this.setting.showCompletedTask }) - .onChange((isOn) => { - this.setting.showCompletedTask = isOn; - }) - } - Button($r('app.string.Back')) - .onClick(()=>this.context.terminateSelf()) - .margin({ top: 10 }) - } - .alignItems(HorizontalAlign.Start) - } +/* + * 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. + * +*/ + +// src/main/ets/pages/SettingPage.ets + +import { AppStorageV2 } from '@kit.ArkUI'; +import { common } from '@kit.AbilityKit'; + +@ObservedV2 +export class Setting { + @Trace public showCompletedTask: boolean = true; +} + +@Entry +@ComponentV2 +struct SettingPage { + @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; + private context = getContext(this) as common.UIAbilityContext; + + build(){ + Column(){ + Text($r('app.string.Setting')) + .fontSize(40) + .margin({ bottom: 10 }) + Row() { + Text($r('app.string.Show_finished_tasks')) + Toggle({ type: ToggleType.Switch, isOn:this.setting.showCompletedTask }) + .onChange((isOn) => { + this.setting.showCompletedTask = isOn; + }) + } + Button($r('app.string.Back')) + .onClick(()=>this.context.terminateSelf()) + .margin({ top: 10 }) + } + .alignItems(HorizontalAlign.Start) + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/TodoListPage.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/TodoListPage.ets index 3b2e89ffc816a305a1dfe836d547a957d7700689..5515ae13b3d121746d24903728cf9efb0d2ef266 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/TodoListPage.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/pages/TodoListPage.ets @@ -1,57 +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. - * -*/ - -// src/main/ets/pages/TodoListPage.ets - -import TaskListViewModel from '../viewmodel/TaskListViewModel'; -import { common } from '@kit.AbilityKit'; -import { AppStorageV2, PersistenceV2 } from '@kit.ArkUI'; -import { Setting } from '../pages/SettingPage'; -import TitleView from '../view/TitleView'; -import ListView from '../view/ListView'; -import BottomView from '../view/BottomView'; - -@Entry -@ComponentV2 -struct TodoList { - @Local taskList: TaskListViewModel = PersistenceV2.connect(TaskListViewModel, 'TaskList', () => new TaskListViewModel())!; - @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; - private context = getContext(this) as common.UIAbilityContext; - - async aboutToAppear() { - this.taskList = PersistenceV2.connect(TaskListViewModel, 'TaskList', () => new TaskListViewModel())!; - if (this.taskList.tasks.length === 0) { - await this.taskList.loadTasks(this.context); - } - } - - @Computed - get tasksUnfinished(): number { - return this.taskList.tasks.filter(task => !task.isFinish).length; - } - - build() { - Column() { - TitleView({ tasksUnfinished: this.tasksUnfinished }) - ListView({ taskList: this.taskList, setting: this.setting }); - BottomView({ taskList: this.taskList }); - } - .height('100%') - .width('100%') - .alignItems(HorizontalAlign.Start) - .margin({ left: 15 }) - } +/* + * 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. + * +*/ + +// src/main/ets/pages/TodoListPage.ets + +import TaskListViewModel from '../viewmodel/TaskListViewModel'; +import { common } from '@kit.AbilityKit'; +import { AppStorageV2, PersistenceV2 } from '@kit.ArkUI'; +import { Setting } from '../pages/SettingPage'; +import TitleView from '../view/TitleView'; +import ListView from '../view/ListView'; +import BottomView from '../view/BottomView'; + +@Entry +@ComponentV2 +struct TodoList { + @Local taskList: TaskListViewModel = PersistenceV2.connect(TaskListViewModel, 'TaskList', () => new TaskListViewModel())!; + @Local setting: Setting = AppStorageV2.connect(Setting, 'Setting', () => new Setting())!; + private context = getContext(this) as common.UIAbilityContext; + + async aboutToAppear() { + this.taskList = PersistenceV2.connect(TaskListViewModel, 'TaskList', () => new TaskListViewModel())!; + if (this.taskList.tasks.length === 0) { + await this.taskList.loadTasks(this.context); + } + } + + @Computed + get tasksUnfinished(): number { + return this.taskList.tasks.filter(task => !task.isFinish).length; + } + + build() { + Column() { + TitleView({ tasksUnfinished: this.tasksUnfinished }) + ListView({ taskList: this.taskList, setting: this.setting }); + BottomView({ taskList: this.taskList }); + } + .height('100%') + .width('100%') + .alignItems(HorizontalAlign.Start) + .margin({ left: 15 }) + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/settingability/SettingAbility.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/settingability/SettingAbility.ets index dc977a8e36d035f2a1ece5a7070867b62d37be1b..6461ffff9f6f46d8b16fa873a72b2663881b5d2d 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/settingability/SettingAbility.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/settingability/SettingAbility.ets @@ -1,57 +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, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -export default class SettingAbility 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/SettingPage', (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'); - } -} +/* + * 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 SettingAbility 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/SettingPage', (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/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/BottomView.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/BottomView.ets index 5a67dcb2aad36e0ed9a8c64a815ee6e28b128895..a5f85fd494b7d3d1ba1ff1a0efac2dfd34e58266 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/BottomView.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/BottomView.ets @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -// src/main/ets/view/BottomView.ets - -import { common, Want } from '@kit.AbilityKit'; -import TaskViewModel from '../viewmodel/TaskViewModel'; -import TaskListViewModel from '../viewmodel/TaskListViewModel'; - -@Builder export function actionButton(text: string|Resource, onClick:() => void) { - Button(text, { buttonStyle: ButtonStyleMode.NORMAL }) - .onClick(onClick) - .margin({ left: 10, right: 10, top: 5, bottom: 5 }) -} - -@ComponentV2 -export default struct BottomView { - @Param taskList: TaskListViewModel = new TaskListViewModel(); - @Local newTaskName: string = ''; - private context = getContext() as common.UIAbilityContext; - - build() { - Column() { - Row() { - actionButton($r('app.string.Finish_all_tasks'), (): void => this.taskList.finishAll(true)) - actionButton($r('app.string.Unfinish_all_tasks'), (): void => this.taskList.finishAll(false)) - actionButton($r('app.string.Setting'), (): void => { - let wantInfo: Want = { - deviceId: '', // deviceId为空表示本设备 - bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName - abilityName: 'SettingAbility', - }; - this.context.startAbility(wantInfo); - }) - } - .margin({ top: 10, bottom: 5 }) - Row() { - TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) - .onChange((value) => this.newTaskName = value) - .width('70%') - actionButton('+', (): void => { - let newTask = new TaskViewModel(); - newTask.taskName = this.newTaskName; - this.taskList.addTask(newTask); - this.newTaskName = ''; - }) - } - } - } +/* + * 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. + * +*/ + +// src/main/ets/view/BottomView.ets + +import { common, Want } from '@kit.AbilityKit'; +import TaskViewModel from '../viewmodel/TaskViewModel'; +import TaskListViewModel from '../viewmodel/TaskListViewModel'; + +@Builder export function actionButton(text: string|Resource, onClick:() => void) { + Button(text, { buttonStyle: ButtonStyleMode.NORMAL }) + .onClick(onClick) + .margin({ left: 10, right: 10, top: 5, bottom: 5 }) +} + +@ComponentV2 +export default struct BottomView { + @Param taskList: TaskListViewModel = new TaskListViewModel(); + @Local newTaskName: string = ''; + private context = getContext() as common.UIAbilityContext; + + build() { + Column() { + Row() { + actionButton($r('app.string.Finish_all_tasks'), (): void => this.taskList.finishAll(true)) + actionButton($r('app.string.Unfinish_all_tasks'), (): void => this.taskList.finishAll(false)) + actionButton($r('app.string.Setting'), (): void => { + let wantInfo: Want = { + deviceId: '', // deviceId为空表示本设备 + bundleName: 'com.samples.statemgmtv2mvvm', // 替换成AppScope/app.json5里的bundleName + abilityName: 'SettingAbility', + }; + this.context.startAbility(wantInfo); + }) + } + .margin({ top: 10, bottom: 5 }) + Row() { + TextInput({ placeholder: $r('app.string.Add_new_task'), text: this.newTaskName }) + .onChange((value) => this.newTaskName = value) + .width('70%') + actionButton('+', (): void => { + let newTask = new TaskViewModel(); + newTask.taskName = this.newTaskName; + this.taskList.addTask(newTask); + this.newTaskName = ''; + }) + } + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/ListView.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/ListView.ets index 1410409257c8f44bc5874ae271f01eb2954400d3..2807f2af8ffbb89c3cf31bf2f24f37e27a9d9786 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/ListView.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/ListView.ets @@ -1,67 +1,67 @@ -/* - * 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. - * -*/ - -// src/main/ets/view/ListView.ets - -import TaskViewModel from '../viewmodel/TaskViewModel'; -import TaskListViewModel from '../viewmodel/TaskListViewModel'; -import { Setting } from '../pages/SettingPage'; -import { actionButton } from './BottomView'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -@ComponentV2 -struct TaskItem { - @Param task: TaskViewModel = new TaskViewModel(); - @Event deleteTask: () => void = () => {}; - @Monitor('task.isFinish') - onTaskFinished(mon: IMonitor) { - hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); - } - - build() { - Row() { - Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) - .width(28) - .height(28) - .margin({ left: 15, right: 10 }) - Text(this.task.taskName) - .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) - .fontSize(18) - actionButton($r('app.string.Delete_task'), () => this.deleteTask()); - } - .height('7%') - .width('90%') - .backgroundColor('#90f1f3f5') - .borderRadius(25) - .onClick(() => this.task.updateIsFinish()) - } -} - -@ComponentV2 -export default struct ListView { - @Param taskList: TaskListViewModel = new TaskListViewModel(); - @Param setting: Setting = new Setting(); - - build() { - Repeat(this.taskList.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) - .each((obj: RepeatItem) => { - TaskItem({ - task: obj.item, - deleteTask: () => this.taskList.removeTask(obj.item) - }).margin(5) - }) - } +/* + * 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. + * +*/ + +// src/main/ets/view/ListView.ets + +import TaskViewModel from '../viewmodel/TaskViewModel'; +import TaskListViewModel from '../viewmodel/TaskListViewModel'; +import { Setting } from '../pages/SettingPage'; +import { actionButton } from './BottomView'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +@ComponentV2 +struct TaskItem { + @Param task: TaskViewModel = new TaskViewModel(); + @Event deleteTask: () => void = () => {}; + @Monitor('task.isFinish') + onTaskFinished(mon: IMonitor) { + hilog.debug(0x0000, 'testTag', '%{public}s', '任务' + this.task.taskName + '的完成状态从' + mon.value()?.before + '变为了' + mon.value()?.now); + } + + build() { + Row() { + Image(this.task.isFinish ? $r('app.media.finished') : $r('app.media.unfinished')) + .width(28) + .height(28) + .margin({ left: 15, right: 10 }) + Text(this.task.taskName) + .decoration({ type: this.task.isFinish ? TextDecorationType.LineThrough : TextDecorationType.None }) + .fontSize(18) + actionButton($r('app.string.Delete_task'), () => this.deleteTask()); + } + .height('7%') + .width('90%') + .backgroundColor('#90f1f3f5') + .borderRadius(25) + .onClick(() => this.task.updateIsFinish()) + } +} + +@ComponentV2 +export default struct ListView { + @Param taskList: TaskListViewModel = new TaskListViewModel(); + @Param setting: Setting = new Setting(); + + build() { + Repeat(this.taskList.tasks.filter(task => this.setting.showCompletedTask || !task.isFinish)) + .each((obj: RepeatItem) => { + TaskItem({ + task: obj.item, + deleteTask: () => this.taskList.removeTask(obj.item) + }).margin(5) + }) + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/TitleView.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/TitleView.ets index 66fe89fd9cd0293c2bf56d52d6c3b5b9741c733d..b72f0c7a2a04757c80a8f69e28739994bf6483a3 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/TitleView.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/view/TitleView.ets @@ -1,32 +1,32 @@ -/* - * 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. - * -*/ - -// src/main/ets/view/TitleView.ets - -@ComponentV2 -export default struct TitleView { - @Param tasksUnfinished: number = 0; - - build() { - Column() { - Text($r('app.string.TodoList_title')) - .fontSize(40) - .margin(10) - Text(`${getContext(this).resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) - .margin({ left: 10, bottom: 10 }) - } - } +/* + * 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. + * +*/ + +// src/main/ets/view/TitleView.ets + +@ComponentV2 +export default struct TitleView { + @Param tasksUnfinished: number = 0; + + build() { + Column() { + Text($r('app.string.TodoList_title')) + .fontSize(40) + .margin(10) + Text(`${getContext(this).resourceManager.getStringSync($r('app.string.Unfinish_count').id)}:${this.tasksUnfinished}`) + .margin({ left: 10, bottom: 10 }) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskListViewModel.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskListViewModel.ets index acf454e0d27b92bde4bdb776ba7c81423b5d9704..f0fe8481cabd36a8e0e54e3d74bde500d8476b0c 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskListViewModel.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskListViewModel.ets @@ -1,52 +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. - * -*/ - -// src/main/ets/viewmodel/TaskListViewModel.ets - -import { common } from '@kit.AbilityKit'; -import { Type } from '@kit.ArkUI'; -import TaskListModel from '../model/TaskListModel'; -import TaskViewModel from'./TaskViewModel'; - -@ObservedV2 -export default class TaskListViewModel { - @Type(TaskViewModel) - @Trace public tasks: TaskViewModel[] = []; - - async loadTasks(context: common.UIAbilityContext) { - let taskList = new TaskListModel([]); - await taskList.loadTasks(context); - for(let task of taskList.tasks){ - let taskViewModel = new TaskViewModel(); - taskViewModel.updateTask(task); - this.tasks.push(taskViewModel); - } - } - - finishAll(ifFinish: boolean): void { - for(let task of this.tasks){ - task.isFinish = ifFinish; - } - } - - addTask(newTask: TaskViewModel): void { - this.tasks.push(newTask); - } - - removeTask(removedTask: TaskViewModel): void { - this.tasks.splice(this.tasks.indexOf(removedTask), 1); - } +/* + * 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. + * +*/ + +// src/main/ets/viewmodel/TaskListViewModel.ets + +import { common } from '@kit.AbilityKit'; +import { Type } from '@kit.ArkUI'; +import TaskListModel from '../model/TaskListModel'; +import TaskViewModel from'./TaskViewModel'; + +@ObservedV2 +export default class TaskListViewModel { + @Type(TaskViewModel) + @Trace public tasks: TaskViewModel[] = []; + + async loadTasks(context: common.UIAbilityContext) { + let taskList = new TaskListModel([]); + await taskList.loadTasks(context); + for(let task of taskList.tasks){ + let taskViewModel = new TaskViewModel(); + taskViewModel.updateTask(task); + this.tasks.push(taskViewModel); + } + } + + finishAll(ifFinish: boolean): void { + for(let task of this.tasks){ + task.isFinish = ifFinish; + } + } + + addTask(newTask: TaskViewModel): void { + this.tasks.push(newTask); + } + + removeTask(removedTask: TaskViewModel): void { + this.tasks.splice(this.tasks.indexOf(removedTask), 1); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskViewModel.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskViewModel.ets index 16bab0db911673fcf328773d6ac8d438ec3009a4..b412dcc9c11f62c73dee3d588c13b8b1f0ff5c73 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskViewModel.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/ets/viewmodel/TaskViewModel.ets @@ -1,34 +1,34 @@ -/* - * 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. - * -*/ - -// src/main/ets/viewmodel/TaskViewModel.ets - -import TaskModel from '../model/TaskModel'; - -@ObservedV2 -export default class TaskViewModel { - @Trace public taskName: string = 'Todo'; - @Trace public isFinish: boolean = false; - - updateTask(task: TaskModel) { - this.taskName = task.taskName; - this.isFinish = task.isFinish; - } - - updateIsFinish(): void { - this.isFinish = !this.isFinish; - } +/* + * 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. + * +*/ + +// src/main/ets/viewmodel/TaskViewModel.ets + +import TaskModel from '../model/TaskModel'; + +@ObservedV2 +export default class TaskViewModel { + @Trace public taskName: string = 'Todo'; + @Trace public isFinish: boolean = false; + + updateTask(task: TaskModel) { + this.taskName = task.taskName; + this.isFinish = task.isFinish; + } + + updateIsFinish(): void { + this.isFinish = !this.isFinish; + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/module.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/module.json5 index 3e96d96f8241ef3a325ea96ab9fcb09aa536daf9..c90903e9e30bfb8444113de487a9f1df1d8de462 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/module.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/module.json5 @@ -1,61 +1,61 @@ -/* - * 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" - ] - } - ] - }, - { - "name": "SettingAbility", - "srcEntry": "./ets/settingability/SettingAbility.ets", - "description": "$string:SettingAbility_desc", - "icon": "$media:layered_image", - "label": "$string:SettingAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background" - } - ] - } +/* + * 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" + ] + } + ] + }, + { + "name": "SettingAbility", + "srcEntry": "./ets/settingability/SettingAbility.ets", + "description": "$string:SettingAbility_desc", + "icon": "$media:layered_image", + "label": "$string:SettingAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/rawfile/defaultTasks.json b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/rawfile/defaultTasks.json index f840413bcfca153166ab4792ae4be535751cf39a..bd049d2be3389d9a9b32273e6de8a6dbda598107 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/rawfile/defaultTasks.json +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/main/resources/rawfile/defaultTasks.json @@ -1,7 +1,7 @@ -[ - {"taskName": "学习ArkTS开发", "isFinish": false}, - {"taskName": "健身", "isFinish": false}, - {"taskName": "买水果", "isFinish": true}, - {"taskName": "取快递", "isFinish": true}, - {"taskName": "刷题", "isFinish": true} +[ + {"taskName": "学习ArkTS开发", "isFinish": false}, + {"taskName": "健身", "isFinish": false}, + {"taskName": "买水果", "isFinish": true}, + {"taskName": "取快递", "isFinish": true}, + {"taskName": "刷题", "isFinish": true} ] \ No newline at end of file diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/ets/test/TodoList.test.ets b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/ets/test/TodoList.test.ets index 9632adc41812aeaf5bb74ab0ba9f3b5994994cac..c3524a32fde1e75fc31e761a9e76dbb603cfb8be 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/ets/test/TodoList.test.ets +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/ets/test/TodoList.test.ets @@ -1,152 +1,152 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -import hilog from '@ohos.hilog' -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -import { abilityDelegatorRegistry, Driver, ON, MatchPattern } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -function sleep(time: number) { - return new Promise((resolve: Function) => setTimeout(resolve, time)); -} - -export default function TodoListTest () { - - describe('TodoListTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - await sleep(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击单个任务,测试切换单项任务的完成状态 - */ - it('testTask',0, async (done: Function) => { - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testTask begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - let text = await driver.findComponent(ON.text('未完成任务:', MatchPattern.CONTAINS)); - await text.getText().then(result => { - expect(result).assertEqual('未完成任务:2'); - }); - let task = await driver.findComponent(ON.text('刷题')); - await task.click(); - await driver.delayMs(1000); - await text.getText().then(result => { - expect(result).assertEqual('未完成任务:3'); - }); - await task.click(); - await driver.delayMs(1000); - await text.getText().then(result => { - expect(result).assertEqual('未完成任务:2'); - }); - done(); - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testTask end'); - }) - - /** - * 点击全部完成,全部未完成按钮,测试切换全部任务的完成状态 - */ - it('testFinishAll_UnfinishAll',0, async (done: Function) => { - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testFinishAll_UnfinishAll begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - let unfinishAll = await driver.findComponent(ON.text('全部未完成')); - await unfinishAll.click(); - await driver.delayMs(1000); - let text = await driver.findComponent(ON.text('未完成任务:', MatchPattern.CONTAINS)); - await text.getText().then(result => { - expect(result).assertEqual('未完成任务:5'); - }); - let finishAll = await driver.findComponent(ON.text('全部完成')); - await finishAll.click(); - await driver.delayMs(1000); - await text.getText().then(result => { - expect(result).assertEqual('未完成任务:0'); - }); - done(); - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testFinishAll_UnfinishAll end'); - }) - - /** - * 点击删除添加新任务,测试增删功能 - */ - it('testDeleteAddTask',0, async (done: Function) => { - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testDeleteAddTask begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - let deleteButton = await driver.findComponent(ON.text('删除')); - await deleteButton.click(); - await driver.delayMs(1000); - let button_search = await driver.findComponent(ON.text('学习ArkTS开发')); - expect(button_search === null).assertTrue(); - let inputField = await driver.findComponent(ON.type('TextInput')); - await inputField.inputText('test123') - let addButton = await driver.findComponent(ON.text('+')); - await addButton.click(); - await driver.delayMs(1000); - let newTask = await driver.findComponent(ON.text('test123')); - expect(newTask === null).assertFalse(); - done(); - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testDeleteAddTask end'); - }) - - /** - * 点击设置按钮,测试切换显示已完成任务功能 - */ - it('testSetting',0, async (done: Function) => { - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testSetting begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - let settingButton = await driver.findComponent(ON.text('设置')); - await settingButton.click(); - await driver.delayMs(1000); - let switchToggle = await driver.findComponent(ON.type('Toggle')); - await switchToggle.click(); - await driver.delayMs(1000); - let backButton = await driver.findComponent(ON.text('返回待办')); - await backButton.click(); - await driver.delayMs(1000); - let finishTask = await driver.findComponent(ON.text('健身')); - expect(finishTask === null).assertTrue(); - await settingButton.click(); - await driver.delayMs(1000); - let switchToggle1 = await driver.findComponent(ON.type('Toggle')); - await switchToggle1.click(); - await driver.delayMs(1000); - let backButton1 = await driver.findComponent(ON.text('返回待办')); - await backButton1.click(); - await driver.delayMs(1000); - let finishTask1 = await driver.findComponent(ON.text('健身')); - expect(finishTask1 === null).assertFalse(); - done(); - hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testSetting end'); - }) - }) -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +import hilog from '@ohos.hilog' +import { describe, it, expect, beforeAll } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON, MatchPattern } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +function sleep(time: number) { + return new Promise((resolve: Function) => setTimeout(resolve, time)); +} + +export default function TodoListTest () { + + describe('TodoListTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + await sleep(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击单个任务,测试切换单项任务的完成状态 + */ + it('testTask',0, async (done: Function) => { + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testTask begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let text = await driver.findComponent(ON.text('未完成任务:', MatchPattern.CONTAINS)); + await text.getText().then(result => { + expect(result).assertEqual('未完成任务:2'); + }); + let task = await driver.findComponent(ON.text('刷题')); + await task.click(); + await driver.delayMs(1000); + await text.getText().then(result => { + expect(result).assertEqual('未完成任务:3'); + }); + await task.click(); + await driver.delayMs(1000); + await text.getText().then(result => { + expect(result).assertEqual('未完成任务:2'); + }); + done(); + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testTask end'); + }) + + /** + * 点击全部完成,全部未完成按钮,测试切换全部任务的完成状态 + */ + it('testFinishAll_UnfinishAll',0, async (done: Function) => { + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testFinishAll_UnfinishAll begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let unfinishAll = await driver.findComponent(ON.text('全部未完成')); + await unfinishAll.click(); + await driver.delayMs(1000); + let text = await driver.findComponent(ON.text('未完成任务:', MatchPattern.CONTAINS)); + await text.getText().then(result => { + expect(result).assertEqual('未完成任务:5'); + }); + let finishAll = await driver.findComponent(ON.text('全部完成')); + await finishAll.click(); + await driver.delayMs(1000); + await text.getText().then(result => { + expect(result).assertEqual('未完成任务:0'); + }); + done(); + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testFinishAll_UnfinishAll end'); + }) + + /** + * 点击删除添加新任务,测试增删功能 + */ + it('testDeleteAddTask',0, async (done: Function) => { + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testDeleteAddTask begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let deleteButton = await driver.findComponent(ON.text('删除')); + await deleteButton.click(); + await driver.delayMs(1000); + let button_search = await driver.findComponent(ON.text('学习ArkTS开发')); + expect(button_search === null).assertTrue(); + let inputField = await driver.findComponent(ON.type('TextInput')); + await inputField.inputText('test123') + let addButton = await driver.findComponent(ON.text('+')); + await addButton.click(); + await driver.delayMs(1000); + let newTask = await driver.findComponent(ON.text('test123')); + expect(newTask === null).assertFalse(); + done(); + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testDeleteAddTask end'); + }) + + /** + * 点击设置按钮,测试切换显示已完成任务功能 + */ + it('testSetting',0, async (done: Function) => { + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testSetting begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + let settingButton = await driver.findComponent(ON.text('设置')); + await settingButton.click(); + await driver.delayMs(1000); + let switchToggle = await driver.findComponent(ON.type('Toggle')); + await switchToggle.click(); + await driver.delayMs(1000); + let backButton = await driver.findComponent(ON.text('返回待办')); + await backButton.click(); + await driver.delayMs(1000); + let finishTask = await driver.findComponent(ON.text('健身')); + expect(finishTask === null).assertTrue(); + await settingButton.click(); + await driver.delayMs(1000); + let switchToggle1 = await driver.findComponent(ON.type('Toggle')); + await switchToggle1.click(); + await driver.delayMs(1000); + let backButton1 = await driver.findComponent(ON.text('返回待办')); + await backButton1.click(); + await driver.delayMs(1000); + let finishTask1 = await driver.findComponent(ON.text('健身')); + expect(finishTask1 === null).assertFalse(); + done(); + hilog.info(0x0000, 'testTag', '%{public}s', 'uitest: testSetting end'); + }) + }) +} diff --git a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/module.json5 index 7785c1ef0953d2739bc3f787dab0b2c3fa902ecb..229daaf602c9f4ad2d355a6d15b6caf43bdd8d3d 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/entry/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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/ArkUISample/StateMgmtV2MVVM/hvigor/hvigor-config.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/hvigor/hvigor-config.json5 index cf31b248c8bee6b7aa1a3cf2119e814b4334d1a8..c6e3f1bbca4ebd18ccab0389cb826fa6efb935a0 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/hvigor/hvigor-config.json5 @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * -*/ - -{ - "modelVersion": "5.0.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkUISample/StateMgmtV2MVVM/oh-package.json5 b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/oh-package.json5 index 85654c41cc6bb0182f886cd7cb085092f1c22ab9..6f7a200b4f5a8c20bde08bdd890338d743b15c49 100644 --- a/code/DocsSample/ArkUISample/StateMgmtV2MVVM/oh-package.json5 +++ b/code/DocsSample/ArkUISample/StateMgmtV2MVVM/oh-package.json5 @@ -1,26 +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. - * -*/ - -{ - "modelVersion": "5.0.0", - "description": "Please describe the basic information.", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.19", - "@ohos/hamock": "1.0.0" - } -} +/* + * 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/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ArkWebSchemeHandler/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ArkWebSchemeHandler/ohosTest.md b/code/DocsSample/ArkWeb/ArkWebSchemeHandler/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/.gitignore b/code/DocsSample/ArkWeb/LifecycleWebComp/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/app.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/app.json5 old mode 100755 new mode 100644 index eb9fbe57f49f96a77bcb145b91a6263644b2b049..c280ad8998ec933a13d5f497a6d439143c5eb8c2 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.lifecyclewebcomp", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.lifecyclewebcomp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index c5e75bb9ea567447aa93d5e5ee84a4021dc7158a..db726d0837ef849bc208a86e9467181653f73010 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "LifecycleWebComp" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "LifecycleWebComp" + } + ] +} diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/LifecycleWebComp/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/README.md b/code/DocsSample/ArkWeb/LifecycleWebComp/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 old mode 100755 new mode 100644 index 20e9fa86a96ec102bf5a1b534dc8f6e8551c07df..fe9f102c8144d761316a4a2fad5e080f84aa757d --- a/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/build-profile.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/LifecycleWebComp/code-linter.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/.gitignore b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/build-profile.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/build-profile.json5 old mode 100755 new mode 100644 index 90b14923bfc8eb7450488a9312783c21aa1966db..31bf2f4c4df15f0403582b255ebdff1354312357 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/oh-package.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/oh-package.json5 old mode 100755 new mode 100644 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..4e54d14e1b444a338b2c922f94a4fe4deed5be45 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": {} -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index d91a720cecfabf830b9e63a5949b2a24bebe0ccf..217744d8eb6d893e1138cd660209ce4d0441ac4f --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2024 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'); - } -} +/* + * Copyright (c) 2024 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/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1755a4686cf9f79996fdcd75b26f06b555c3ad3f..6b744d7eaa66e51e79fc4e0896e251292ee767c5 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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)); - } +/* + * Copyright (c) 2024 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/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 old mode 100755 new mode 100644 index b541792385cb5a1a925f93ae8c9242b9596ec27e..cb5df2316a385286bf09b1aab230f0bf56d8b993 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/module.json5 @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2024 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" - } - ] - } - ] - } +/* + * Copyright (c) 2024 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/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index f7fceda00c2bd2ff398912e9a5fe07a1c18dafa4..844921321627bd854c9219a879ff5c656da188e9 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/rawfile/index.html @@ -1,9 +1,9 @@ - - - - - - -

Hello, ArkWeb

- - + + + + + + +

Hello, ArkWeb

+ + diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 1f646ea03f584d15f4a5406ea548af0214a093d4..5f63462032245655b8df990c83c5d7312015c089 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/ohosTest/module.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/LifecycleWebComp/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index 5f9d8a57584fa98d3e8f6c63a304213b801d0dff..76e3231223076011f7f4400f54fa73a5ab0141d4 --- a/code/DocsSample/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/hvigor/hvigor-config.json5 @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2024 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": { - }, - "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*/ - } -} +/* + * Copyright (c) 2024 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": { + }, + "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/ArkWeb/LifecycleWebComp/hvigorfile.ts b/code/DocsSample/ArkWeb/LifecycleWebComp/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/oh-package.json5 b/code/DocsSample/ArkWeb/LifecycleWebComp/oh-package.json5 old mode 100755 new mode 100644 index fb70d168e165b1212a708f14edd3945c775d6543..d7622199b7ba60be5983122081f71ae9ebef0c4b --- a/code/DocsSample/ArkWeb/LifecycleWebComp/oh-package.json5 +++ b/code/DocsSample/ArkWeb/LifecycleWebComp/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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" - } -} +/* + * Copyright (c) 2024 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/DocsSample/ArkWeb/LifecycleWebComp/ohosTest.md b/code/DocsSample/ArkWeb/LifecycleWebComp/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png b/code/DocsSample/ArkWeb/LifecycleWebComp/screenshots/LifecycleWebComp.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/.gitignore b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 old mode 100755 new mode 100644 index 75ab31d09326c84c9b6d40429a85de7ffee3954a..f3bfcf54902f2bda4cd2cee4b827b89e2ba7ee37 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/app.json5 @@ -1,25 +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.managewebcompsecpriv", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managewebcompsecpriv", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 32877db4dce4f96598ae38a0b9fa8ec5906093c1..8e172ff2061de12c25e977effcf18d7629db4cd7 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManageWebCompSecPriv" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebCompSecPriv" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/README.md b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/build-profile.json5 old mode 100755 new mode 100644 index 633b9956eedd3d758a6419222352ad43072eef0e..e8a4489c36e2c6d4c51775099f7d63da4bc462bf --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/build-profile.json5 @@ -1,52 +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. - */ - - { - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/ManageWebCompSecPriv/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/AddIntTrackPreventByPassList.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets old mode 100755 new mode 100644 index cee0fd0d0ce30eb90c97f2eef1028e7a5b30b941..e71aab7f748add109e3fab3de5086c1c2c7cb2d2 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/ClearIntTrackPreventByPassList.ets @@ -1,32 +1,32 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('clearIntelligentTrackingPreventionBypassingList') - .onClick(() => { - webview.WebviewController.clearIntelligentTrackingPreventionBypassingList(); - }) - Web({ src: $r('app.string.web_path'), controller: this.controller }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('clearIntelligentTrackingPreventionBypassingList') + .onClick(() => { + webview.WebviewController.clearIntelligentTrackingPreventionBypassingList(); + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets old mode 100755 new mode 100644 index 283ced2f34ecd9a3bd96950f6d5c48e97b10042c..ba98477ff52feed3cdb952f65dd16961be64bcbf --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/CollectingAdsBlockingInformation.ets @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct WebComponent { - @State totalAdsBlockCounts: number = 0; - @State myString: string = 'onAdsBlocked'; - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: $r('app.string.web_path'), controller: this.controller }) - .onAdsBlocked((details: AdsBlockedDetails) => { - if (details) { - console.log(' Blocked ' + details.adsBlocked.length + ' in ' + details.url); - let adList: string[] = Array.from(new Set(details.adsBlocked)); - this.totalAdsBlockCounts += adList.length; - console.log('Total blocked counts :' + this.totalAdsBlockCounts); - } - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + @State totalAdsBlockCounts: number = 0; + @State myString: string = 'onAdsBlocked'; + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.controller }) + .onAdsBlocked((details: AdsBlockedDetails) => { + if (details) { + console.log(' Blocked ' + details.adsBlocked.length + ' in ' + details.url); + let adList: string[] = Array.from(new Set(details.adsBlocked)); + this.totalAdsBlockCounts += adList.length; + console.log('Total blocked counts :' + this.totalAdsBlockCounts); + } + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets old mode 100755 new mode 100644 index d903a58c48d351147b1b33283d9ddcf943849c25..04b82a33c47640d3166037d39f00098380e98703 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_one.ets @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - mainUrl: string = resourceToString($r('app.string.web_path')); - textInputController: TextInputController = new TextInputController(); - controller: webview.WebviewController = new webview.WebviewController(); - - @State inputText: string = resourceToString($r('app.string.web_path')); - - build() { - Column() { - Row() { - Flex() { - TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) - .id('input_url') - .height(40) - .margin(5) - .borderColor(Color.Blue) - .onChange((value: string) => { - this.inputText = value; - }) - - Button({type: ButtonType.Capsule}) { Text('Go') } - .onClick(() => { - this.controller.loadUrl(this.inputText); - }) - - Button({type: ButtonType.Capsule}) { Text('addAdsBlockDisallowedList') } - .onClick(() => { - let arrDomainSuffixes: string[] = []; - arrDomainSuffixes.push('example.com'); - arrDomainSuffixes.push('abcdefg.cn'); - webview.AdsBlockManager.addAdsBlockDisallowedList(arrDomainSuffixes); - }) - } - } - Web({ src: this.mainUrl, controller: this.controller }) - .onControllerAttached(()=>{ - this.controller.enableAdsBlock(true); - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + textInputController: TextInputController = new TextInputController(); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) + .id('input_url') + .height(40) + .margin(5) + .borderColor(Color.Blue) + .onChange((value: string) => { + this.inputText = value; + }) + + Button({type: ButtonType.Capsule}) { Text('Go') } + .onClick(() => { + this.controller.loadUrl(this.inputText); + }) + + Button({type: ButtonType.Capsule}) { Text('addAdsBlockDisallowedList') } + .onClick(() => { + let arrDomainSuffixes: string[] = []; + arrDomainSuffixes.push('example.com'); + arrDomainSuffixes.push('abcdefg.cn'); + webview.AdsBlockManager.addAdsBlockDisallowedList(arrDomainSuffixes); + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets old mode 100755 new mode 100644 index fb11841153705f6707e2982a98fb1d098af29621..3eff92c8a284b1cde00e0a44b615595d1d380386 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/DisAdsBlockSpecDomPages_two.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - mainUrl: string = resourceToString($r('app.string.web_path')); - textInputController: TextInputController = new TextInputController(); - controller: webview.WebviewController = new webview.WebviewController(); - - @State inputText: string = resourceToString($r('app.string.web_path')); - - build() { - Column() { - Row() { - Flex() { - TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) - .id('input_url') - .height(40) - .margin(5) - .borderColor(Color.Blue) - .onChange((value: string) => { - this.inputText = value; - }) - - Button({type: ButtonType.Capsule}) { Text('Go'); } - .onClick(() => { - this.controller.loadUrl(this.inputText); - }) - - Button({type: ButtonType.Capsule}) { Text('addAdsBlockAllowedList'); } - .onClick(() => { - let arrDisallowDomainSuffixes = ['example.com']; - webview.AdsBlockManager.addAdsBlockDisallowedList(arrDisallowDomainSuffixes); - - let arrAllowedDomainSuffixes = ['news.example.com', 'sport.example.com']; - webview.AdsBlockManager.addAdsBlockAllowedList(arrAllowedDomainSuffixes); - }) - } - } - Web({ src: this.mainUrl, controller: this.controller }) - .onControllerAttached(()=>{ - this.controller.enableAdsBlock(true); - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + mainUrl: string = resourceToString($r('app.string.web_path')); + textInputController: TextInputController = new TextInputController(); + controller: webview.WebviewController = new webview.WebviewController(); + + @State inputText: string = resourceToString($r('app.string.web_path')); + + build() { + Column() { + Row() { + Flex() { + TextInput({ text: this.inputText, placeholder: this.mainUrl, controller: this.textInputController}) + .id('input_url') + .height(40) + .margin(5) + .borderColor(Color.Blue) + .onChange((value: string) => { + this.inputText = value; + }) + + Button({type: ButtonType.Capsule}) { Text('Go'); } + .onClick(() => { + this.controller.loadUrl(this.inputText); + }) + + Button({type: ButtonType.Capsule}) { Text('addAdsBlockAllowedList'); } + .onClick(() => { + let arrDisallowDomainSuffixes = ['example.com']; + webview.AdsBlockManager.addAdsBlockDisallowedList(arrDisallowDomainSuffixes); + + let arrAllowedDomainSuffixes = ['news.example.com', 'sport.example.com']; + webview.AdsBlockManager.addAdsBlockAllowedList(arrAllowedDomainSuffixes); + }) + } + } + Web({ src: this.mainUrl, controller: this.controller }) + .onControllerAttached(()=>{ + this.controller.enableAdsBlock(true); + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets old mode 100755 new mode 100644 index 2abfd30abb9173efd02d23456f9af5d0aa6f7190..1259bb6524824eb953cfbcc9bce67b7261010718 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnableIntTrackPrevent.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('enableIntelligentTrackingPrevention') - .onClick(() => { - try { - this.controller.enableIntelligentTrackingPrevention(true); - console.log('enableIntelligentTrackingPrevention: true'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Web({ src: $r('app.string.web_path'), controller: this.controller }); - } - } +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('enableIntelligentTrackingPrevention') + .onClick(() => { + try { + this.controller.enableIntelligentTrackingPrevention(true); + console.log('enableIntelligentTrackingPrevention: true'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/EnablingAdsBlocking.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index b70ec5f3e395ad692cab86d2bfbb100643e4bdca..cb5f033b5edc90ee98d926d2590e6c02294df4b6 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/Index.ets @@ -1,74 +1,74 @@ -/* - * 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 { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('LocCrossOriginResAccSol_one') - .onClick(() => { - router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_one' }); - }) - Button('LocCrossOriginResAccSol_two') - .onClick(() => { - router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_two' }); - }) - Button('AddIntTrackPreventByPassList') - .onClick(() => { - router.pushUrl({ url: 'pages/AddIntTrackPreventByPassList' }); - }) - Button('ClearIntTrackPreventByPassList') - .onClick(() => { - router.pushUrl({ url: 'pages/ClearIntTrackPreventByPassList' }); - }) - Button('EnableIntTrackPrevent') - .onClick(() => { - router.pushUrl({ url: 'pages/EnableIntTrackPrevent' }); - }) - Button('IsIntTrackPreventEnabled') - .onClick(() => { - router.pushUrl({ url: 'pages/IsIntTrackPreventEnabled' }); - }) - Button('OnIntTrackPreventResult') - .onClick(() => { - router.pushUrl({ url: 'pages/OnIntTrackPreventResult' }); - }) - Button('RemoveIntTrackPreventByPassList') - .onClick(() => { - router.pushUrl({ url: 'pages/RemoveIntTrackPreventByPassList' }); - }) - Button('EnablingAdsBlocking') - .onClick(() => { - router.pushUrl({ url: 'pages/EnablingAdsBlocking' }); - }) - Button('DisAdsBlockSpecDomPages_one') - .onClick(() => { - router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_one' }); - }) - Button('DisAdsBlockSpecDomPages_two') - .onClick(() => { - router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_two' }); - }) - Button('CollectingAdsBlockingInformation') - .onClick(() => { - router.pushUrl({ url: 'pages/CollectingAdsBlockingInformation' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('LocCrossOriginResAccSol_one') + .onClick(() => { + router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_one' }); + }) + Button('LocCrossOriginResAccSol_two') + .onClick(() => { + router.pushUrl({ url: 'pages/LocCrossOriginResAccSol_two' }); + }) + Button('AddIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/AddIntTrackPreventByPassList' }); + }) + Button('ClearIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/ClearIntTrackPreventByPassList' }); + }) + Button('EnableIntTrackPrevent') + .onClick(() => { + router.pushUrl({ url: 'pages/EnableIntTrackPrevent' }); + }) + Button('IsIntTrackPreventEnabled') + .onClick(() => { + router.pushUrl({ url: 'pages/IsIntTrackPreventEnabled' }); + }) + Button('OnIntTrackPreventResult') + .onClick(() => { + router.pushUrl({ url: 'pages/OnIntTrackPreventResult' }); + }) + Button('RemoveIntTrackPreventByPassList') + .onClick(() => { + router.pushUrl({ url: 'pages/RemoveIntTrackPreventByPassList' }); + }) + Button('EnablingAdsBlocking') + .onClick(() => { + router.pushUrl({ url: 'pages/EnablingAdsBlocking' }); + }) + Button('DisAdsBlockSpecDomPages_one') + .onClick(() => { + router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_one' }); + }) + Button('DisAdsBlockSpecDomPages_two') + .onClick(() => { + router.pushUrl({ url: 'pages/DisAdsBlockSpecDomPages_two' }); + }) + Button('CollectingAdsBlockingInformation') + .onClick(() => { + router.pushUrl({ url: 'pages/CollectingAdsBlockingInformation' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets old mode 100755 new mode 100644 index cf899e8d3fd84841e969a12d2487d4ab8e392716..6084cb9cf6e37650c55c78a03a9e30035352c3b5 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/IsIntTrackPreventEnabled.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('isIntelligentTrackingPreventionEnabled') - .onClick(() => { - try { - let result = this.controller.isIntelligentTrackingPreventionEnabled(); - console.log('result: ' + result); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Web({ src: $r('app.string.web_path'), controller: this.controller }); - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('isIntelligentTrackingPreventionEnabled') + .onClick(() => { + try { + let result = this.controller.isIntelligentTrackingPreventionEnabled(); + console.log('result: ' + result); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }); + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/LocCrossOriginResAccSol_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets old mode 100755 new mode 100644 index 6312ba16347037977791cf218c00665726a06434..edf2b4276a7e23efb88a6c035b19a1fc1b4a1462 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/OnIntTrackPreventResult.ets @@ -1,43 +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 { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - // 需要打开智能防跟踪功能,才会触发onIntelligentTrackingPreventionResult回调 - Button('enableIntelligentTrackingPrevention') - .onClick(() => { - try { - this.controller.enableIntelligentTrackingPrevention(true); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Web({ src: $r('app.string.web_path'), controller: this.controller }) - .onIntelligentTrackingPreventionResult((details) => { - console.log('onIntelligentTrackingPreventionResult: [websiteHost]= ' + details.host + - ', [trackerHost]=' + details.trackerHost); - }) - } - } +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + // 需要打开智能防跟踪功能,才会触发onIntelligentTrackingPreventionResult回调 + Button('enableIntelligentTrackingPrevention') + .onClick(() => { + try { + this.controller.enableIntelligentTrackingPrevention(true); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: $r('app.string.web_path'), controller: this.controller }) + .onIntelligentTrackingPreventionResult((details) => { + console.log('onIntelligentTrackingPreventionResult: [websiteHost]= ' + details.host + + ', [trackerHost]=' + details.trackerHost); + }) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets old mode 100755 new mode 100644 index 86a03f28a7406192364d036f6c8d1a08cb6a1bbe..2c8b69cf9d8c4e5f5d87d66997fcfc00c0092d74 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/ets/pages/RemoveIntTrackPreventByPassList.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('removeIntelligentTrackingPreventionBypassingList') - .onClick(() => { - try { - let hostList = [ 'www.test1.com', 'www.test2.com' ]; - webview.WebviewController.removeIntelligentTrackingPreventionBypassingList(hostList); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Web({ src: 'www.example.com', controller: this.controller }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('removeIntelligentTrackingPreventionBypassingList') + .onClick(() => { + try { + let hostList = [ 'www.test1.com', 'www.test2.com' ]; + webview.WebviewController.removeIntelligentTrackingPreventionBypassingList(hostList); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 56e1d4c80691e8bee4c3b69dedb29cbc2791fbfb..01ba29a16a4306f3ed6bd10c2c7a9cdb84e5285e --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/index.html @@ -1,23 +1,23 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js old mode 100755 new mode 100644 index 9fbf275c8df135975b1d989a8dd9320bef13bd59..c01c058e8dbd44c1b4ce2ed1fc460664c58a2d94 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/rawfile/js/script.js @@ -1,19 +1,19 @@ -/* - * 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. - */ - -const body = document.body; -const element = document.createElement('div'); -element.textContent = 'success'; -body.appendChild(element); +/* + * 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. + */ + +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'success'; +body.appendChild(element); diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html old mode 100755 new mode 100644 index b9fd97fc2074cf4477c871a83b2c2cff99dacddb..e8aa15081537f3f522e4ed361345524ca955f8f3 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/index.html @@ -1,56 +1,56 @@ - - - - - - - - Demo - - - - - -
- -
-
- - - + + + + + + + + Demo + + + + + +
+ +
+
+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js old mode 100755 new mode 100644 index 9fbf275c8df135975b1d989a8dd9320bef13bd59..c01c058e8dbd44c1b4ce2ed1fc460664c58a2d94 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/resfile/js/script.js @@ -1,19 +1,19 @@ -/* - * 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. - */ - -const body = document.body; -const element = document.createElement('div'); -element.textContent = 'success'; -body.appendChild(element); +/* + * 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. + */ + +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'success'; +body.appendChild(element); diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebCompSecPriv/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebCompSecPriv/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebCompSecPriv/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/AddIntTrackPreventByPassList.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/ClearIntTrackPreventByPassList.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/CollectingAdsBlockingInformation.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/DisAdsBlockSpecDomPages_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/EnableIntTrackPrevent.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/EnablingAdsBlocking_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/IsIntTrackPreventEnabled.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/LocCrossOriginResAccSol_two_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/OnIntTrackPreventResult.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png b/code/DocsSample/ArkWeb/ManageWebCompSecPriv/screenshots/RemoveIntTrackPreventByPassList.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageFileIO/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 old mode 100755 new mode 100644 index a955b9b44407782455417846be9e37ba78a8097f..c81be320936ad21787cdb02b4d04f1015bfae2ea --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/app.json5 @@ -1,25 +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.managewebpagefileio", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managewebpagefileio", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index fd4f95881b9bea16ec29410b96b60ceccc8c6435..651c9e36903ecf6afe4187bce123a1a3ab00c38d --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManageWebPageFileIO" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebPageFileIO" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/README.md b/code/DocsSample/ArkWeb/ManageWebPageFileIO/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/ManageWebPageFileIO/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 611bcc25b1680def327436f7182095817384f58f..80e8214f747914b9b3b64331d9eb37fd1619a007 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/Index.ets @@ -1,42 +1,42 @@ -/* - * 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 { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('UploadFiles') - .onClick(() => { - router.pushUrl({ url: 'pages/UploadFiles' }); - }) - Button('ListenForPageDown') - .onClick(() => { - router.pushUrl({ url: 'pages/ListenForPageDown' }); - }) - Button('InitiatingADownloadTask') - .onClick(() => { - router.pushUrl({ url: 'pages/InitiatingADownloadTask' }); - }) - Button('ResumeDownload') - .onClick(() => { - router.pushUrl({ url: 'pages/ResumeDownload' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('UploadFiles') + .onClick(() => { + router.pushUrl({ url: 'pages/UploadFiles' }); + }) + Button('ListenForPageDown') + .onClick(() => { + router.pushUrl({ url: 'pages/ListenForPageDown' }); + }) + Button('InitiatingADownloadTask') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatingADownloadTask' }); + }) + Button('ResumeDownload') + .onClick(() => { + router.pushUrl({ url: 'pages/ResumeDownload' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets old mode 100755 new mode 100644 index 3a845244f9ca8c3dfdd5f00e6eb0b3a9fbc93e4f..bf6439d94578ae8e982fa161148883a472034e3e --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/InitiatingADownloadTask.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); - @State myText: string = 'download'; - - build() { - Column() { - Text(this.myText) - Button('setDownloadDelegate') - .onClick(() => { - try { - this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { - console.log('will start a download.'); - // 传入一个下载路径,并开始下载。 - webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); - }) - this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { - console.log('download update guid: ' + webDownloadItem.getGuid()); - }) - this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { - console.log('download failed guid: ' + webDownloadItem.getGuid()); - }) - this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { - console.log('download finish guid: ' + webDownloadItem.getGuid()); - this.myText = 'download finish'; - }) - this.controller.setDownloadDelegate(this.delegate); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('startDownload') - .onClick(() => { - try { - // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 - // 开发者需要替换为自己想要下载的内容的地址。 - this.controller.startDownload(resourceToString($r('app.string.web_path'))); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Web({ src: 'www.example.com', controller: this.controller }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + @State myText: string = 'download'; + + build() { + Column() { + Text(this.myText) + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // 传入一个下载路径,并开始下载。 + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + console.log('download update guid: ' + webDownloadItem.getGuid()); + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + this.myText = 'download finish'; + }) + this.controller.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('startDownload') + .onClick(() => { + try { + // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 + // 开发者需要替换为自己想要下载的内容的地址。 + this.controller.startDownload(resourceToString($r('app.string.web_path'))); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ListenForPageDown.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets old mode 100755 new mode 100644 index fa69ed291fe6f405122648403b039d9a5109dd2d..995ae70e08c0b604131361136cecdd52e7d0372f --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/ResumeDownload.ets @@ -1,104 +1,104 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { DownloadUtil, fileName, filePath } from './downloadUtil'; // downloadUtil.ets 见下文 - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); - download: webview.WebDownloadItem = new webview.WebDownloadItem(); - // 用于记录失败的下载任务。 - failedData: Uint8Array = new Uint8Array(); - - build() { - Column() { - Button('setDownloadDelegate') - .onClick(() => { - try { - this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { - console.log('will start a download.'); - // 传入一个下载路径,并开始下载。 - webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); - }) - this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { - console.log('download update percent complete: ' + webDownloadItem.getPercentComplete()); - this.download = webDownloadItem; - }) - this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { - console.log('download failed guid: ' + webDownloadItem.getGuid()); - // 序列化失败的下载任务到一个字节数组。 - this.failedData = webDownloadItem.serialize(); - }) - this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { - console.log('download finish guid: ' + webDownloadItem.getGuid()); - }) - this.controller.setDownloadDelegate(this.delegate); - webview.WebDownloadManager.setDownloadDelegate(this.delegate); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('startDownload') - .onClick(() => { - try { - // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 - // 开发者需要替换为自己想要下载的内容的地址。 - this.controller.startDownload(resourceToString($r('app.string.web_path'))); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - // 将当前的下载任务信息序列化保存,用于后续恢复下载任务。 - // 当前用例仅展示下载一个任务的场景,多任务场景请按需扩展。 - Button('record') - .onClick(() => { - try { - // 保存当前下载数据到持久化文档中。 - DownloadUtil.saveDownloadInfo(DownloadUtil.uint8ArrayToStr(this.download.serialize())); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - // 从序列化的下载任务信息中,恢复下载任务。 - // 按钮触发时必须保证WebDownloadManager.setDownloadDelegate设置完成。 - Button('recovery') - .onClick(() => { - try { - // 当前默认持久化文件存在,用户根据实际情况增加判断。 - let webDownloadItem = - webview.WebDownloadItem.deserialize( - DownloadUtil.strToUint8Array(DownloadUtil.readFileSync(filePath, fileName))); - webview.WebDownloadManager.resumeDownload(webDownloadItem); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - - Web({ src: 'www.example.com', controller: this.controller }) - } - } +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { DownloadUtil, fileName, filePath } from './downloadUtil'; // downloadUtil.ets 见下文 + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + delegate: webview.WebDownloadDelegate = new webview.WebDownloadDelegate(); + download: webview.WebDownloadItem = new webview.WebDownloadItem(); + // 用于记录失败的下载任务。 + failedData: Uint8Array = new Uint8Array(); + + build() { + Column() { + Button('setDownloadDelegate') + .onClick(() => { + try { + this.delegate.onBeforeDownload((webDownloadItem: webview.WebDownloadItem) => { + console.log('will start a download.'); + // 传入一个下载路径,并开始下载。 + webDownloadItem.start('/data/storage/el2/base/cache/web/' + webDownloadItem.getSuggestedFileName()); + }) + this.delegate.onDownloadUpdated((webDownloadItem: webview.WebDownloadItem) => { + console.log('download update percent complete: ' + webDownloadItem.getPercentComplete()); + this.download = webDownloadItem; + }) + this.delegate.onDownloadFailed((webDownloadItem: webview.WebDownloadItem) => { + console.log('download failed guid: ' + webDownloadItem.getGuid()); + // 序列化失败的下载任务到一个字节数组。 + this.failedData = webDownloadItem.serialize(); + }) + this.delegate.onDownloadFinish((webDownloadItem: webview.WebDownloadItem) => { + console.log('download finish guid: ' + webDownloadItem.getGuid()); + }) + this.controller.setDownloadDelegate(this.delegate); + webview.WebDownloadManager.setDownloadDelegate(this.delegate); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('startDownload') + .onClick(() => { + try { + // 这里指定下载地址为 https://www.example.com/,Web组件会发起一个下载任务将该页面下载下来。 + // 开发者需要替换为自己想要下载的内容的地址。 + this.controller.startDownload(resourceToString($r('app.string.web_path'))); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 将当前的下载任务信息序列化保存,用于后续恢复下载任务。 + // 当前用例仅展示下载一个任务的场景,多任务场景请按需扩展。 + Button('record') + .onClick(() => { + try { + // 保存当前下载数据到持久化文档中。 + DownloadUtil.saveDownloadInfo(DownloadUtil.uint8ArrayToStr(this.download.serialize())); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 从序列化的下载任务信息中,恢复下载任务。 + // 按钮触发时必须保证WebDownloadManager.setDownloadDelegate设置完成。 + Button('recovery') + .onClick(() => { + try { + // 当前默认持久化文件存在,用户根据实际情况增加判断。 + let webDownloadItem = + webview.WebDownloadItem.deserialize( + DownloadUtil.strToUint8Array(DownloadUtil.readFileSync(filePath, fileName))); + webview.WebDownloadManager.resumeDownload(webDownloadItem); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + + Web({ src: 'www.example.com', controller: this.controller }) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/UploadFiles.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets old mode 100755 new mode 100644 index 7f24d7ddfced52a4352da6174243d98f6bd399c5..9cc55e2875c16579d72cb67d234c2dbccde1f238 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/ets/pages/downloadUtil.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { util } from '@kit.ArkTS'; -import fileStream from '@ohos.file.fs'; - -const helper = new util.Base64Helper(); - -export const filePath = getContext().filesDir; -export const fileName = 'demoFile.txt'; -export namespace DownloadUtil { - - export function uint8ArrayToStr(uint8Array: Uint8Array): string { - return helper.encodeToStringSync(uint8Array); - } - - export function strToUint8Array(str: string): Uint8Array { - return helper.decodeSync(str); - } - - export function saveDownloadInfo(downloadInfo: string): void { - if (!fileExists(filePath)) { - mkDirectorySync(filePath); - } - - writeToFileSync(filePath, fileName, downloadInfo); - } - - export function fileExists(filePath: string): boolean { - try { - return fileStream.accessSync(filePath); - } catch (error) { - return false; - } - } - - export function mkDirectorySync(directoryPath: string, recursion?: boolean): void { - try { - fileStream.mkdirSync(directoryPath, recursion ?? false); - } catch (error) { - console.error(`mk dir error. err message: ${error.message}, err code: ${error.code}`); - } - } - - export function writeToFileSync(dir: string, fileName: string, msg: string): void { - let file = fileStream.openSync(dir + '/' + fileName, fileStream.OpenMode.WRITE_ONLY | fileStream.OpenMode.CREATE); - fileStream.writeSync(file.fd, msg); - } - - export function readFileSync(dir: string, fileName: string): string { - return fileStream.readTextSync(dir + '/' + fileName); - } - +/* + * 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 { util } from '@kit.ArkTS'; +import fileStream from '@ohos.file.fs'; + +const helper = new util.Base64Helper(); + +export const filePath = getContext().filesDir; +export const fileName = 'demoFile.txt'; +export namespace DownloadUtil { + + export function uint8ArrayToStr(uint8Array: Uint8Array): string { + return helper.encodeToStringSync(uint8Array); + } + + export function strToUint8Array(str: string): Uint8Array { + return helper.decodeSync(str); + } + + export function saveDownloadInfo(downloadInfo: string): void { + if (!fileExists(filePath)) { + mkDirectorySync(filePath); + } + + writeToFileSync(filePath, fileName, downloadInfo); + } + + export function fileExists(filePath: string): boolean { + try { + return fileStream.accessSync(filePath); + } catch (error) { + return false; + } + } + + export function mkDirectorySync(directoryPath: string, recursion?: boolean): void { + try { + fileStream.mkdirSync(directoryPath, recursion ?? false); + } catch (error) { + console.error(`mk dir error. err message: ${error.message}, err code: ${error.code}`); + } + } + + export function writeToFileSync(dir: string, fileName: string, msg: string): void { + let file = fileStream.openSync(dir + '/' + fileName, fileStream.OpenMode.WRITE_ONLY | fileStream.OpenMode.CREATE); + fileStream.writeSync(file.fd, msg); + } + + export function readFileSync(dir: string, fileName: string): string { + return fileStream.readTextSync(dir + '/' + fileName); + } + } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html old mode 100755 new mode 100644 index c890546eb8380e53be05277ce3dce5404d846a29..79e8cc88be2c00e1a49303cd9ddffeb2e55b6c25 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/download.html @@ -1,21 +1,21 @@ - - - - - -

download test

- + + + + + +

download test

+ \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 006195d7f7e4558ccf102fbf1d1259b4ab30d172..3dab642cbf493c630cec7194e2ea9c24d9dfadc8 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/index.html @@ -1,21 +1,21 @@ - - - - - -Download - - + + + + + +Download + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html old mode 100755 new mode 100644 index d7bb4919a5ce7d64f8c92975b6494b0d92f163fa..a02fa4eb2b9854bcea11238cd13e25bafc9e9156 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/rawfile/local.html @@ -1,28 +1,28 @@ - - - - - - - Document - - - - -
- - - + + + + + + + Document + + + + +
+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageFileIO/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageFileIO/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebPageFileIO/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageFileIO/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageFileIO/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebPageFileIO/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageFileIO/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageFileIO/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebPageFileIO/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/InitiatingADownloadTask_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/ListenForPageDown_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/ResumeDownload.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/ResumeDownload.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_1.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_2.png b/code/DocsSample/ArkWeb/ManageWebPageFileIO/screenshots/UploadFiles_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageInteracts/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 old mode 100755 new mode 100644 index 46003233ad201f8c33d2e2f5c63aa70db3598ec1..ce3d05eda7baad507acf0e8de81df905cdf32d67 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/app.json5 @@ -1,25 +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.managewebpageinteracts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managewebpageinteracts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 520a651cc4795ee9a436e1a021c18c14d21cfd66..be8d935f6276f0e2833fde78d0f8320e6447b4f7 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManageWebPageInteracts" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManageWebPageInteracts" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/README.md b/code/DocsSample/ArkWeb/ManageWebPageInteracts/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/build-profile.json5 old mode 100755 new mode 100644 index 5209cd7eb7db278c854ae5ba2ef02ed8c367ecc0..aa5718fb8d16de5b49a6ce9642d27b893923b191 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/build-profile.json5 @@ -1,64 +1,64 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry2", - "srcPath": "./entry2", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/ImpNestedScroll.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 94ee9bb21857bb404c04bb662d1a3bcc5b0c86f9..f9b6f41e802970502c50ee0ea64b70bc455da97a --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/Index.ets @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('ImpNestedScroll') - .onClick(() => { - router.pushUrl({ url: 'pages/ImpNestedScroll' }); - }) - Button('OnIntKbdAttachSysCustIn') - .onClick(() => { - router.pushUrl({ url: 'pages/OnIntKbdAttachSysCustIn' }); - }) - Button('SetSKBMode_one') - .onClick(() => { - router.pushUrl({ url: 'pages/SetSKBMode_one' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('ImpNestedScroll') + .onClick(() => { + router.pushUrl({ url: 'pages/ImpNestedScroll' }); + }) + Button('OnIntKbdAttachSysCustIn') + .onClick(() => { + router.pushUrl({ url: 'pages/OnIntKbdAttachSysCustIn' }); + }) + Button('SetSKBMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/SetSKBMode_one' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets old mode 100755 new mode 100644 index 277a41f652acae4748c95193d3a69a4032583bab..eb95328680d0c12329a6f5692849c9b8354cb65a --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/OnIntKbdAttachSysCustIn.ets @@ -1,120 +1,120 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { inputMethodEngine } from '@kit.IMEKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - webKeyboardController: WebKeyboardController = new WebKeyboardController(); - inputAttributeMap: Map = new Map([ - ['UNSPECIFIED', inputMethodEngine.ENTER_KEY_TYPE_UNSPECIFIED], - ['GO', inputMethodEngine.ENTER_KEY_TYPE_GO], - ['SEARCH', inputMethodEngine.ENTER_KEY_TYPE_SEARCH], - ['SEND', inputMethodEngine.ENTER_KEY_TYPE_SEND], - ['NEXT', inputMethodEngine.ENTER_KEY_TYPE_NEXT], - ['DONE', inputMethodEngine.ENTER_KEY_TYPE_DONE], - ['PREVIOUS', inputMethodEngine.ENTER_KEY_TYPE_PREVIOUS] - ]); - - /** - * 自定义键盘组件Builder - */ - @Builder - customKeyboardBuilder() { - // 这里实现自定义键盘组件,对接WebKeyboardController实现输入、删除、关闭等操作。 - Row() { - Text('finish') - .fontSize(20) - .fontColor(Color.Blue) - .onClick(() => { - this.webKeyboardController.close(); - }) - // 插入字符。 - Button('insertText').onClick(() => { - this.webKeyboardController.insertText('insert '); - }).margin({ - bottom: 200, - }); - // 从后往前删除length参数指定长度的字符。 - Button('deleteForward').onClick(() => { - this.webKeyboardController.deleteForward(1); - }).margin({ - bottom: 200, - }); - // 从前往后删除length参数指定长度的字符。 - Button('deleteBackward').onClick(() => { - this.webKeyboardController.deleteBackward(1); - }).margin({ - left: -220, - }); - // 插入功能按键。 - Button('sendFunctionKey').onClick(() => { - this.webKeyboardController.sendFunctionKey(6); - }) - } - } - - build() { - Column() { - Web({ src: $rawfile('index.html'), controller: this.controller }) - .onInterceptKeyboardAttach((keyBoardCallBackInfo) => { - // option初始化,默认使用系统默认键盘 - let option: WebKeyboardOptions = { - useSystemKeyboard: true, - }; - if (!keyBoardCallBackInfo) { - return option; - } - - // 保存WebKeyboardController,使用自定义键盘时候,需要使用该handler控制输入、删除、软键盘关闭等行为 - this.webKeyboardController = keyBoardCallBackInfo.controller; - let attributes: Record = keyBoardCallBackInfo.attributes; - // 遍历attributes - let attributeKeys = Object.keys(attributes); - for (let i = 0; i < attributeKeys.length; i++) { - console.log('WebCustomKeyboard key = ' + attributeKeys[i] + ', value = ' + attributes[attributeKeys[i]]); - } - - if (attributes) { - if (attributes['data-keyboard'] == 'customKeyboard') { - // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有data-keyboard,且值为customKeyboard,则使用自定义键盘 - console.log('WebCustomKeyboard use custom keyboard'); - option.useSystemKeyboard = false; - // 设置自定义键盘builder - option.customKeyboard = () => { - this.customKeyboardBuilder(); - } - return option; - } - - if (attributes['keyboard-return'] != undefined) { - // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有keyboard-return,使用系统键盘,并且指定系统软键盘enterKey类型 - option.useSystemKeyboard = true; - let enterKeyType: number | undefined = this.inputAttributeMap.get(attributes['keyboard-return']); - if (enterKeyType != undefined) { - option.enterKeyType = enterKeyType; - } - return option; - } - } - - return option; - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { inputMethodEngine } from '@kit.IMEKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + webKeyboardController: WebKeyboardController = new WebKeyboardController(); + inputAttributeMap: Map = new Map([ + ['UNSPECIFIED', inputMethodEngine.ENTER_KEY_TYPE_UNSPECIFIED], + ['GO', inputMethodEngine.ENTER_KEY_TYPE_GO], + ['SEARCH', inputMethodEngine.ENTER_KEY_TYPE_SEARCH], + ['SEND', inputMethodEngine.ENTER_KEY_TYPE_SEND], + ['NEXT', inputMethodEngine.ENTER_KEY_TYPE_NEXT], + ['DONE', inputMethodEngine.ENTER_KEY_TYPE_DONE], + ['PREVIOUS', inputMethodEngine.ENTER_KEY_TYPE_PREVIOUS] + ]); + + /** + * 自定义键盘组件Builder + */ + @Builder + customKeyboardBuilder() { + // 这里实现自定义键盘组件,对接WebKeyboardController实现输入、删除、关闭等操作。 + Row() { + Text('finish') + .fontSize(20) + .fontColor(Color.Blue) + .onClick(() => { + this.webKeyboardController.close(); + }) + // 插入字符。 + Button('insertText').onClick(() => { + this.webKeyboardController.insertText('insert '); + }).margin({ + bottom: 200, + }); + // 从后往前删除length参数指定长度的字符。 + Button('deleteForward').onClick(() => { + this.webKeyboardController.deleteForward(1); + }).margin({ + bottom: 200, + }); + // 从前往后删除length参数指定长度的字符。 + Button('deleteBackward').onClick(() => { + this.webKeyboardController.deleteBackward(1); + }).margin({ + left: -220, + }); + // 插入功能按键。 + Button('sendFunctionKey').onClick(() => { + this.webKeyboardController.sendFunctionKey(6); + }) + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onInterceptKeyboardAttach((keyBoardCallBackInfo) => { + // option初始化,默认使用系统默认键盘 + let option: WebKeyboardOptions = { + useSystemKeyboard: true, + }; + if (!keyBoardCallBackInfo) { + return option; + } + + // 保存WebKeyboardController,使用自定义键盘时候,需要使用该handler控制输入、删除、软键盘关闭等行为 + this.webKeyboardController = keyBoardCallBackInfo.controller; + let attributes: Record = keyBoardCallBackInfo.attributes; + // 遍历attributes + let attributeKeys = Object.keys(attributes); + for (let i = 0; i < attributeKeys.length; i++) { + console.log('WebCustomKeyboard key = ' + attributeKeys[i] + ', value = ' + attributes[attributeKeys[i]]); + } + + if (attributes) { + if (attributes['data-keyboard'] == 'customKeyboard') { + // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有data-keyboard,且值为customKeyboard,则使用自定义键盘 + console.log('WebCustomKeyboard use custom keyboard'); + option.useSystemKeyboard = false; + // 设置自定义键盘builder + option.customKeyboard = () => { + this.customKeyboardBuilder(); + } + return option; + } + + if (attributes['keyboard-return'] != undefined) { + // 根据html可编辑元素的属性,判断使用不同的软键盘,例如这里如果属性包含有keyboard-return,使用系统键盘,并且指定系统软键盘enterKey类型 + option.useSystemKeyboard = true; + let enterKeyType: number | undefined = this.inputAttributeMap.get(attributes['keyboard-return']); + if (enterKeyType != undefined) { + option.enterKeyType = enterKeyType; + } + return option; + } + } + + return option; + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/ets/pages/SetSKBMode_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html old mode 100755 new mode 100644 index 4ca7b500a153dcfa0fbe6e183996f3f480bdd134..61538c5f011d7b79e613fa0ff14c35ff008e246a --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/SetSKBModeIndex.html @@ -1,25 +1,25 @@ - - - - - - 测试网页 - - -

DEMO

- - - + + + + + + 测试网页 + + +

DEMO

+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 5c81f6e49a043e1c23a87a00516d085e1dd52a6d..126ebbb351a2ec7d26f2c3024eb907935eb13a11 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/rawfile/index.html @@ -1,63 +1,63 @@ - - - - - - - - - - - - -

input标签,原有默认行为:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key UNSPECIFIED:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key GO:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key SEARCH:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key SEND:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key NEXT:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key DONE:

-
-
- -

input标签,系统键盘自定义enterKeyType属性 enter key PREVIOUS:

-
-
- -

input标签,应用自定义键盘:

-
- - - - + + + + + + + + + + + + +

input标签,原有默认行为:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key UNSPECIFIED:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key GO:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key SEARCH:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key SEND:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key NEXT:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key DONE:

+
+
+ +

input标签,系统键盘自定义enterKeyType属性 enter key PREVIOUS:

+
+
+ +

input标签,应用自定义键盘:

+
+ + + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageInteracts/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 old mode 100755 new mode 100644 index 154bdd087521da4954d20dc9aaabcfb3f032fb65..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/build-profile.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 old mode 100755 new mode 100644 index 3fc6e6bee34614116bbbb42e7feaad0760b3fe1c..2944307304532e967f4956384cc91447f2c9bf8c --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/oh-package.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "name": "entry2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* +* 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": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets old mode 100755 new mode 100644 index bbaa7e59073348bdc9362a002ff9850821fbd887..602dfcc85e69419a29535345a49e0edfd96541a9 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window, KeyboardAvoidMode } from '@kit.ArkUI'; - -export default class Entry2Ability 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) => { - let keyboardAvoidMode = windowStage.getMainWindowSync().getUIContext().getKeyboardAvoidMode(); - // 设置虚拟键盘抬起时压缩页面大小为减去键盘的高度 - windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); - 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'); - } -} +/* + * 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, KeyboardAvoidMode } from '@kit.ArkUI'; + +export default class Entry2Ability 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) => { + let keyboardAvoidMode = windowStage.getMainWindowSync().getUIContext().getKeyboardAvoidMode(); + // 设置虚拟键盘抬起时压缩页面大小为减去键盘的高度 + windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); + 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/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets old mode 100755 new mode 100644 index a9c5227a98f85362a6acd1da493248d0675e204f..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets @@ -1,27 +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 Entry2BackupAbility 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)); - } +/* + * 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 Entry2BackupAbility 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/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 old mode 100755 new mode 100644 index f53d2229b671a367d4e73c70f69b61a6caf7eca5..ab84ff3b2ed0d5059adba2ac15d84ad6e058dff9 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/module.json5 @@ -1,67 +1,67 @@ -/* -* 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": "entry2", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "Entry2Ability", - "deviceTypes": [ - "phone", - "2in1", - "car" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry2Ability", - "srcEntry": "./ets/entry2ability/Entry2Ability.ets", - "description": "$string:Entry2Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry2Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "Entry2BackupAbility", - "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ], - } - ] - } +/* +* 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": "entry2", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "phone", + "2in1", + "car" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry2BackupAbility", + "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.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/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 4ca7b500a153dcfa0fbe6e183996f3f480bdd134..61538c5f011d7b79e613fa0ff14c35ff008e246a --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/main/resources/rawfile/index.html @@ -1,25 +1,25 @@ - - - - - - 测试网页 - - -

DEMO

- - - + + + + + + 测试网页 + + +

DEMO

+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 old mode 100755 new mode 100644 index f21d1578ed58706d782e97f168787f106cc35dd7..e20f24eae372c0eb8c3c01064957d911552b482b --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/ohosTest/module.json5 @@ -1,28 +1,28 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "module": { - "name": "entry2_test", - "type": "feature", - "deviceTypes": [ - "phone", - "2in1", - "car" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* +* 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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "phone", + "2in1", + "car" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageInteracts/entry2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebPageInteracts/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageInteracts/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageInteracts/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebPageInteracts/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageInteracts/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageInteracts/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebPageInteracts/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/ImpNestedScroll.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/ImpNestedScroll.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/OnIntKbdAttachSysCustIn.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_one_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png b/code/DocsSample/ArkWeb/ManageWebPageInteracts/screenshots/SetSKBMode_two_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 old mode 100755 new mode 100644 index 9e9d3da1dc5c49dfd8ad61c60a6788ceaf10c4d5..b0c7bc7d9468973a02c86fae0a80050c9598dcc2 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/app.json5 @@ -1,25 +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.acceleratepageaccess", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.acceleratepageaccess", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 44391627e85411e07d75892e68bc02ca1ebf4c9b..09408da82ddf7aa37250665e2742bc8e2069dc22 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AcceleratePageAccess" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AcceleratePageAccess" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 old mode 100755 new mode 100644 index 5ff7c51f919cd335edfc14f4d2f1147bbbeb783a..eb8b316a35f64ae4bdeabe1c9a18d732c3babc09 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/build-profile.json5 @@ -1,100 +1,100 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry1", - "srcPath": "./entry1", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry2", - "srcPath": "./entry2", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry3", - "srcPath": "./entry3", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry4", - "srcPath": "./entry4", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry1", + "srcPath": "./entry1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry3", + "srcPath": "./entry3", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry4", + "srcPath": "./entry4", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b865efd626c466d6a334efc1e8111c6e88807a82..82e98bec44d83d2df03deb52508045cb06cc8604 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 7aaec79f5a28d765725aede370d8344f3839638c..29feaca7669174be5c2b0e2366529ee94ab7e726 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 old mode 100755 new mode 100644 index 4628f905e04f04e452fa5f8f9a43e8d641e3e7e8..c4e8768835e5e869bbd19dfb80d2e323afaa6f2d --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry1", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets old mode 100755 new mode 100644 index d9e4566e76ab32f3b564b3fb66bb6381bd623d3e..777f3cba719dbde6af1553b34045e839443dc948 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/entry1ability/Entry1Ability.ets @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; - -export default class Entry1Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - console.log('EntryAbility onCreate'); - webview.WebviewController.initializeWebEngine(); - // 预连接时,需要將'https://www.example.com'替换成真实要访问的网站地址。 - - webview.WebviewController.prepareForPageLoad(this.context.resourceManager.getStringSync($r('app.string.web_path_one')), true, 2); - AppStorage.setOrCreate('abilityWant', want); - console.log('EntryAbility onCreate done'); - } - - 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'); - } -} +/* + * 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'; +import { webview } from '@kit.ArkWeb'; + +export default class Entry1Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + console.log('EntryAbility onCreate'); + webview.WebviewController.initializeWebEngine(); + // 预连接时,需要將'https://www.example.com'替换成真实要访问的网站地址。 + + webview.WebviewController.prepareForPageLoad(this.context.resourceManager.getStringSync($r('app.string.web_path_one')), true, 2); + AppStorage.setOrCreate('abilityWant', want); + console.log('EntryAbility onCreate done'); + } + + 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 old mode 100755 new mode 100644 index 465872d2309126fd7bbf697c9395c155c717a4bf..5303c59d21b19cfd2c0a4299ec6ea72fede11eba --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/module.json5 @@ -1,47 +1,47 @@ -/* - * 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": "entry1", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry1Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry1Ability", - "srcEntry": "./ets/entry1ability/Entry1Ability.ets", - "description": "$string:Entry1Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry1Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry1Ability", + "srcEntry": "./ets/entry1ability/Entry1Ability.ets", + "description": "$string:Entry1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 old mode 100755 new mode 100644 index b463f808d133416ec65c5c4ef3f4d1dd9528e592..a8392c11cf0dbecb4cdc78dc93d456a3a8e6ff41 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/ohosTest/module.json5 @@ -1,27 +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": "entry1_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry1/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 old mode 100755 new mode 100644 index bcb70ff878510fb523d011c47eb563dc4edbd9ea..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets old mode 100755 new mode 100644 index cf7edaa3ca7fb433ec4145438a5c4a3791e13c31..dab8f3ea7260551b9dc6606eb397e396d241e701 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -1,56 +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 Entry2Ability 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'); - } -} +/* + * 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 Entry2Ability 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/Prefetching.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets old mode 100755 new mode 100644 index fec3d997018d986a26117953bb2f147f1203e23c..0409ab711f73f40c38c88fbfd81a537163fde84a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_one.ets @@ -1,46 +1,46 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - webviewController: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: $r('app.string.web_path'), controller: this.webviewController}) - .onAppear(() => { - // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 - webview.WebviewController.prefetchResource( - {url:resourceToString($r('app.string.post_path')), - method:'POST', - formData:'a=x&b=y',}, - [{headerKey:'c', - headerValue:'z',},], - 'KeyX', 500); - }) - .onPageEnd(() => { - // 清除后续不再使用的预获取资源缓存。 - webview.WebviewController.clearPrefetchedResource(['KeyX',]); - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onAppear(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + {url:resourceToString($r('app.string.post_path')), + method:'POST', + formData:'a=x&b=y',}, + [{headerKey:'c', + headerValue:'z',},], + 'KeyX', 500); + }) + .onPageEnd(() => { + // 清除后续不再使用的预获取资源缓存。 + webview.WebviewController.clearPrefetchedResource(['KeyX',]); + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets old mode 100755 new mode 100644 index 7fec456ea93d7a4fc9c7e4395af0ecf5976bd6b6..ed12d5245b20ce930a9ce0042bfd2e926617300b --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_three.ets @@ -1,43 +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 { webview } from '@kit.ArkWeb'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - webviewController: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: $r('app.string.web_path'), controller: this.webviewController}) - .onPageEnd(() => { - // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 - webview.WebviewController.prefetchResource( - {url:resourceToString($r('app.string.web_path')) + '/post?e=f&g=h', - method:'POST', - formData:'a=x&b=y',}, - [{headerKey:'c', - headerValue:'z',},], - 'KeyX', 500); - }) - } - } -} - +/* + * 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 { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onPageEnd(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + {url:resourceToString($r('app.string.web_path')) + '/post?e=f&g=h', + method:'POST', + formData:'a=x&b=y',}, + [{headerKey:'c', + headerValue:'z',},], + 'KeyX', 500); + }) + } + } +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets old mode 100755 new mode 100644 index 7d47160e54dbd15fe617ce5096d3960f9990d0c0..aef210f496e1e895bd330e28b57789c1a1b65f1d --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/ets/pages/PrefetchingAPOSTRequest_two.ets @@ -1,42 +1,42 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -@Entry -@Component -struct WebComponent { - webviewController: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: $r('app.string.web_path'), controller: this.webviewController}) - .onPageEnd(() => { - // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 - webview.WebviewController.prefetchResource( - {url:resourceToString($r('app.string.post_path')), - method:'POST', - formData:'a=x&b=y',}, - [{headerKey:'c', - headerValue:'z',},], - 'KeyX', 500); - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $r('app.string.web_path'), controller: this.webviewController}) + .onPageEnd(() => { + // 预获取时,需要將'https://www.example1.com/post?e=f&g=h'替换成真实要访问的网站地址。 + webview.WebviewController.prefetchResource( + {url:resourceToString($r('app.string.post_path')), + method:'POST', + formData:'a=x&b=y',}, + [{headerKey:'c', + headerValue:'z',},], + 'KeyX', 500); + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 old mode 100755 new mode 100644 index fc96afe421ecc484ebbbeae15a26566355c8d18d..7c87a975ff65dac27497e22e35d2efa530f8064f --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/module.json5 @@ -1,47 +1,47 @@ -/* - * 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": "entry2", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry2Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry2Ability", - "srcEntry": "./ets/entry2ability/Entry2Ability.ets", - "description": "$string:Entry2Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry2Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry2", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 87a1b504873368e9fba4674048215376b52ec579..031b54bde39f1b8ca1884b863026dbc91fd5a75a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/ohosTest/module.json5 @@ -1,27 +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": "entry2_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 old mode 100755 new mode 100644 index 401ea2ff2de9d5a85b272557fd72f6d8e2d9440d..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry3", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry3", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets old mode 100755 new mode 100644 index 22b3bbdccc6b164dc9b9a136aeac1064a8381cc4..2a423e1c7f8fe141023461ad628dfecc14974147 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -1,56 +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'; - -const localStorage: LocalStorage = new LocalStorage('uiContext'); - -export default class Entry3Ability extends UIAbility { - public storage: LocalStorage = localStorage; - 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) { - windowStage.loadContent('pages/Index', this.storage, (err, data) => { - if (err.code) { - return; - } - - this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); - }); - } - - 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'); - } -} +/* + * 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'; + +const localStorage: LocalStorage = new LocalStorage('uiContext'); + +export default class Entry3Ability extends UIAbility { + public storage: LocalStorage = localStorage; + 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) { + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + return; + } + + this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + + 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets old mode 100755 new mode 100644 index abc50a3c5b529609e44a7660f2482b3583663087..becf118a932d116499ba9d358ff816c126613108 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/BusinessWebview.ets @@ -1,25 +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. - */ - -import { BuilderData } from './DynamicComponent'; - -@Builder -function webBuilder(data: BuilderData) { - // 此处组件可根据业务需要自行扩展 - Web({ src: data.url, controller: data.controller }) - .cacheMode(CacheMode.Default) -} - -export const businessWebview = wrapBuilder(webBuilder); +/* + * 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 { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + // 此处组件可根据业务需要自行扩展 + Web({ src: data.url, controller: data.controller }) + .cacheMode(CacheMode.Default) +} + +export const businessWebview = wrapBuilder(webBuilder); diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets old mode 100755 new mode 100644 index ff0f85f0e5d16ba9bb59dc5fe7659cc67adc5f41..4e4bd243f01741c9c110f5cfe360fef866e561b8 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/DynamicComponent.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; - -export interface BuilderData { - url: string; - controller: WebviewController; -} - -const storage = LocalStorage.getShared(); - -export class NodeControllerImpl extends NodeController { - private rootNode: BuilderNode | null = null; - private wrappedBuilder: WrappedBuilder | null = null; - - constructor(wrappedBuilder: WrappedBuilder) { - super(); - this.wrappedBuilder = wrappedBuilder; - } - - makeNode(): FrameNode | null { - if (this.rootNode != null) { - return this.rootNode.getFrameNode(); - } - return null; - } - - initWeb(url: string, controller: WebviewController) { - if(this.rootNode != null) { - return; - } - - const uiContext: UIContext = storage.get('uiContext') as UIContext; - if (!uiContext) { - return; - } - this.rootNode = new BuilderNode(uiContext); - this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); - } -} - -export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { - const baseNode = new NodeControllerImpl(wrappedBuilder); - baseNode.initWeb(data.url, data.controller); - return baseNode; -} +/* + * 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 { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +export interface BuilderData { + url: string; + controller: WebviewController; +} + +const storage = LocalStorage.getShared(); + +export class NodeControllerImpl extends NodeController { + private rootNode: BuilderNode | null = null; + private wrappedBuilder: WrappedBuilder | null = null; + + constructor(wrappedBuilder: WrappedBuilder) { + super(); + this.wrappedBuilder = wrappedBuilder; + } + + makeNode(): FrameNode | null { + if (this.rootNode != null) { + return this.rootNode.getFrameNode(); + } + return null; + } + + initWeb(url: string, controller: WebviewController) { + if(this.rootNode != null) { + return; + } + + const uiContext: UIContext = storage.get('uiContext') as UIContext; + if (!uiContext) { + return; + } + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); + } +} + +export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { + const baseNode = new NodeControllerImpl(wrappedBuilder); + baseNode.initWeb(data.url, data.controller); + return baseNode; +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets old mode 100755 new mode 100644 index ed7f2c6e94140135d7c464b47cf5f6b1769cc66a..60050f43d7237a409ce3b2a69c85dde76d37e8e9 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileConfig.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb' - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -export interface Config { - url: string, - localPath: string, // 本地资源路径 - options: webview.CacheOptions -} - -export let configs: Config[] = [ - { - url: resourceToString($r('app.string.web_path')), - localPath: 'example.js', - options: { - responseHeaders: [ - { headerKey: 'E-Tag', headerValue: 'aWO42N9P9dG/5xqYQCxsx+vDOoU='}, - { headerKey: 'Last-Modified', headerValue: 'Wed, 21 Mar 2025 10:38:41 GMT'} - ] - } - } -] +/* + * 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 { webview } from '@kit.ArkWeb' + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +export interface Config { + url: string, + localPath: string, // 本地资源路径 + options: webview.CacheOptions +} + +export let configs: Config[] = [ + { + url: resourceToString($r('app.string.web_path')), + localPath: 'example.js', + options: { + responseHeaders: [ + { headerKey: 'E-Tag', headerValue: 'aWO42N9P9dG/5xqYQCxsx+vDOoU='}, + { headerKey: 'Last-Modified', headerValue: 'Wed, 21 Mar 2025 10:38:41 GMT'} + ] + } + } +] diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets old mode 100755 new mode 100644 index 214da820e83610d05d425b2ed54c40ca58909ae4..471805f1e97c6c179c303b21268a48489440645d --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/ets/pages/PrecompileWebview.ets @@ -1,53 +1,53 @@ -/* - * 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 { BuilderData } from './DynamicComponent'; -import { Config, configs } from './PrecompileConfig'; - -@Builder -function webBuilder(data: BuilderData) { - Web({ src: data.url, controller: data.controller }) - .onControllerAttached(() => { - precompile(data.controller, configs); - }) - .fileAccess(true) -} - -export const precompileWebview = wrapBuilder(webBuilder); - -export const precompile = async (controller: WebviewController, configs: Array) => { - for (const config of configs) { - let content = await readRawFile(config.localPath); - - try { - controller.precompileJavaScript(config.url, content, config.options) - .then(errCode => { - console.error('precompile successfully! ' + errCode); - }).catch((errCode: number) => { - console.error('precompile failed. ' + errCode); - }); - } catch (err) { - console.error('precompile failed. ' + err.code + ' ' + err.message); - } - } -} - -async function readRawFile(path: string) { - try { - return await getContext().resourceManager.getRawFileContent(path);; - } catch (err) { - return new Uint8Array(0); - } -} +/* + * 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 { BuilderData } from './DynamicComponent'; +import { Config, configs } from './PrecompileConfig'; + +@Builder +function webBuilder(data: BuilderData) { + Web({ src: data.url, controller: data.controller }) + .onControllerAttached(() => { + precompile(data.controller, configs); + }) + .fileAccess(true) +} + +export const precompileWebview = wrapBuilder(webBuilder); + +export const precompile = async (controller: WebviewController, configs: Array) => { + for (const config of configs) { + let content = await readRawFile(config.localPath); + + try { + controller.precompileJavaScript(config.url, content, config.options) + .then(errCode => { + console.error('precompile successfully! ' + errCode); + }).catch((errCode: number) => { + console.error('precompile failed. ' + errCode); + }); + } catch (err) { + console.error('precompile failed. ' + err.code + ' ' + err.message); + } + } +} + +async function readRawFile(path: string) { + try { + return await getContext().resourceManager.getRawFileContent(path);; + } catch (err) { + return new Uint8Array(0); + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 old mode 100755 new mode 100644 index db35d4bff47b7647ddc86c9ab2e4c31ae43e90e2..5566c38cae3156d6470062ff659b9f0a54160541 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/module.json5 @@ -1,47 +1,47 @@ -/* - * 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": "entry3", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry3Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry3Ability", - "srcEntry": "./ets/entry3ability/Entry3Ability.ets", - "description": "$string:Entry3Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry3Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry3", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry3Ability", + "srcEntry": "./ets/entry3ability/Entry3Ability.ets", + "description": "$string:Entry3Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry3Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9fec93324fb8655cf1fac5683305c468a26c135e..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/ohosTest/module.json5 @@ -1,27 +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": "entry3_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry3/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 old mode 100755 new mode 100644 index 0291d967fe2ab60ebdbcd4dbd691320edf31e5bf..ac50b7be8601621317e98fd352affe020e0897c7 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry4", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry4", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets old mode 100755 new mode 100644 index 0f4fa9bb16babfedfc5fd94fd56d68d74407ddfa..134fc466dbc5c6cb08145ebd3b57bacd73f8ed17 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/entry4ability/Entry4Ability.ets @@ -1,56 +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'; - -const localStorage: LocalStorage = new LocalStorage('uiContext'); - -export default class Entry4Ability extends UIAbility { - public storage: LocalStorage = localStorage; - 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) { - windowStage.loadContent('pages/Index', this.storage, (err, data) => { - if (err.code) { - return; - } - - this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); - }); - } - - 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'); - } -} +/* + * 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'; + +const localStorage: LocalStorage = new LocalStorage('uiContext'); + +export default class Entry4Ability extends UIAbility { + public storage: LocalStorage = localStorage; + 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) { + windowStage.loadContent('pages/Index', this.storage, (err, data) => { + if (err.code) { + return; + } + + this.storage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + + 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets old mode 100755 new mode 100644 index abc50a3c5b529609e44a7660f2482b3583663087..becf118a932d116499ba9d358ff816c126613108 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/BusinessWebview.ets @@ -1,25 +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. - */ - -import { BuilderData } from './DynamicComponent'; - -@Builder -function webBuilder(data: BuilderData) { - // 此处组件可根据业务需要自行扩展 - Web({ src: data.url, controller: data.controller }) - .cacheMode(CacheMode.Default) -} - -export const businessWebview = wrapBuilder(webBuilder); +/* + * 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 { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + // 此处组件可根据业务需要自行扩展 + Web({ src: data.url, controller: data.controller }) + .cacheMode(CacheMode.Default) +} + +export const businessWebview = wrapBuilder(webBuilder); diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets old mode 100755 new mode 100644 index ff0f85f0e5d16ba9bb59dc5fe7659cc67adc5f41..4e4bd243f01741c9c110f5cfe360fef866e561b8 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/DynamicComponent.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; - -export interface BuilderData { - url: string; - controller: WebviewController; -} - -const storage = LocalStorage.getShared(); - -export class NodeControllerImpl extends NodeController { - private rootNode: BuilderNode | null = null; - private wrappedBuilder: WrappedBuilder | null = null; - - constructor(wrappedBuilder: WrappedBuilder) { - super(); - this.wrappedBuilder = wrappedBuilder; - } - - makeNode(): FrameNode | null { - if (this.rootNode != null) { - return this.rootNode.getFrameNode(); - } - return null; - } - - initWeb(url: string, controller: WebviewController) { - if(this.rootNode != null) { - return; - } - - const uiContext: UIContext = storage.get('uiContext') as UIContext; - if (!uiContext) { - return; - } - this.rootNode = new BuilderNode(uiContext); - this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); - } -} - -export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { - const baseNode = new NodeControllerImpl(wrappedBuilder); - baseNode.initWeb(data.url, data.controller); - return baseNode; -} +/* + * 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 { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +export interface BuilderData { + url: string; + controller: WebviewController; +} + +const storage = LocalStorage.getShared(); + +export class NodeControllerImpl extends NodeController { + private rootNode: BuilderNode | null = null; + private wrappedBuilder: WrappedBuilder | null = null; + + constructor(wrappedBuilder: WrappedBuilder) { + super(); + this.wrappedBuilder = wrappedBuilder; + } + + makeNode(): FrameNode | null { + if (this.rootNode != null) { + return this.rootNode.getFrameNode(); + } + return null; + } + + initWeb(url: string, controller: WebviewController) { + if(this.rootNode != null) { + return; + } + + const uiContext: UIContext = storage.get('uiContext') as UIContext; + if (!uiContext) { + return; + } + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrappedBuilder, { url: url, controller: controller }); + } +} + +export const createNode = (wrappedBuilder: WrappedBuilder, data: BuilderData) => { + const baseNode = new NodeControllerImpl(wrappedBuilder); + baseNode.initWeb(data.url, data.controller); + return baseNode; +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets old mode 100755 new mode 100644 index 1342d480f1ed850658435d8955cb19e34fce3d79..49c7310cef016a7fe31db1504a765ec928b436b8 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/InjectWebview.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { resourceConfigs } from './Resource'; -import { BuilderData } from './DynamicComponent'; - -@Builder -function webBuilder(data: BuilderData) { - Web({ src: data.url, controller: data.controller }) - .onControllerAttached(async () => { - try { - data.controller.injectOfflineResources(await getData ()); - } catch (err) { - console.error('error: ' + err.code + ' ' + err.message); - } - }) - .fileAccess(true) -} - -export const injectWebview = wrapBuilder(webBuilder); - -export async function getData() { - const resourceMapArr: webview.OfflineResourceMap[] = []; - - // 读取配置,从rawfile目录中读取文件内容 - for (let config of resourceConfigs) { - let buf: Uint8Array = new Uint8Array(0); - if (config.localPath) { - buf = await readRawFile(config.localPath); - } - - resourceMapArr.push({ - urlList: config.urlList, - resource: buf, - responseHeaders: config.responseHeaders, - type: config.type, - }) - } - - return resourceMapArr; -} - -export async function readRawFile(url: string) { - try { - return await getContext().resourceManager.getRawFileContent(url); - } catch (err) { - return new Uint8Array(0); - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { resourceConfigs } from './Resource'; +import { BuilderData } from './DynamicComponent'; + +@Builder +function webBuilder(data: BuilderData) { + Web({ src: data.url, controller: data.controller }) + .onControllerAttached(async () => { + try { + data.controller.injectOfflineResources(await getData ()); + } catch (err) { + console.error('error: ' + err.code + ' ' + err.message); + } + }) + .fileAccess(true) +} + +export const injectWebview = wrapBuilder(webBuilder); + +export async function getData() { + const resourceMapArr: webview.OfflineResourceMap[] = []; + + // 读取配置,从rawfile目录中读取文件内容 + for (let config of resourceConfigs) { + let buf: Uint8Array = new Uint8Array(0); + if (config.localPath) { + buf = await readRawFile(config.localPath); + } + + resourceMapArr.push({ + urlList: config.urlList, + resource: buf, + responseHeaders: config.responseHeaders, + type: config.type, + }) + } + + return resourceMapArr; +} + +export async function readRawFile(url: string) { + try { + return await getContext().resourceManager.getRawFileContent(url); + } catch (err) { + return new Uint8Array(0); + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets old mode 100755 new mode 100644 index c4c6d0ac106a3472a5b6a33bb9806c1fe9ce941c..fcf0747d144d13541b042518a44129fc5109e4aa --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/AcceleratePageAccess/entry4/src/main/ets/pages/Resource.ets @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -export interface ResourceConfig { - urlList: Array, - type: webview.OfflineResourceType, - responseHeaders: Array
, - localPath: string, // 本地资源存放在rawfile目录下的路径 -} - -export const resourceConfigs: ResourceConfig[] = [ - { - localPath: 'example.png', - urlList: [ - resourceToString($r('app.string.web_path')), - resourceToString($r('app.string.web_path')) + 'path1/example.png', - resourceToString($r('app.string.web_path')) + 'path2/example.png', - ], - type: webview.OfflineResourceType.IMAGE, - responseHeaders: [ - { headerKey: 'Cache-Control', headerValue: 'max-age=1000' }, - { headerKey: 'Content-Type', headerValue: 'image/png' }, - ] - }, - { - localPath: 'example.js', - urlList: [ // 仅提供一个url,这个url既作为资源的源,也作为资源的网络请求地址 - resourceToString($r('app.string.web_path_one')), - ], - type: webview.OfflineResourceType.CLASSIC_JS, - responseHeaders: [ - // 以 - + + + + + + + + + +
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+
this is a test div
+ + + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_one_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_two.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/CustomizePageResp/screenshots/OnInterceptRequest_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/app.json5 old mode 100755 new mode 100644 index ba45a3b3a9d8ed72afa17c5aa8845debc1e3360d..a0839764e9f5191469c5b58f2a8ec6114aa3bdcd --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/app.json5 @@ -1,25 +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.loadpages", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.loadpages", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 9b49e3610ebb78cb93086bd8594524a4346e5617..20d3fed609c211fb436f66442a2576b24d1a59ac --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "LoadPages" - } - ] +{ + "string": [ + { + "name": "app_name", + "value": "LoadPages" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/README.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/ManageWebPageLoadBrowse/LoadPages/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b865efd626c466d6a334efc1e8111c6e88807a82..82e98bec44d83d2df03deb52508045cb06cc8604 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 7aaec79f5a28d765725aede370d8344f3839638c..29feaca7669174be5c2b0e2366529ee94ab7e726 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets old mode 100755 new mode 100644 index d925275dbab17b7ccbc7f881c287e0b227e1994b..5962cda39af660dbe631505a66394417c91ecaf7 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/GlobalContext.ets @@ -1,35 +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. - */ - -export class GlobalContext { - private constructor() {} - private static instance: GlobalContext; - private _objects = new Map(); - - public static getContext(): GlobalContext { - if (!GlobalContext.instance) { - GlobalContext.instance = new GlobalContext(); - } - return GlobalContext.instance; - } - - getObject(value: string): Object | undefined { - return this._objects.get(value); - } - - setObject(key: string, objectClass: Object): void { - this._objects.set(key, objectClass); - } -} +/* + * 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 class GlobalContext { + private constructor() {} + private static instance: GlobalContext; + private _objects = new Map(); + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getObject(value: string): Object | undefined { + return this._objects.get(value); + } + + setObject(key: string, objectClass: Object): void { + this._objects.set(key, objectClass); + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.ets old mode 100755 new mode 100644 index a95b79c366950b1ca436c5f385f3b0b5ae8f7a1e..6976ca815265ab405eae5558d31e14824128f6df --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_one.ets @@ -1,33 +1,33 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; -import { GlobalContext } from './GlobalContext'; - -let url = 'file://' + GlobalContext.getContext().getObject('filesDir') + '/index.html'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Text('loading success'); - // 加载沙箱路径文件。 - Web({ src: url, controller: this.controller }); - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { GlobalContext } from './GlobalContext'; + +let url = 'file://' + GlobalContext.getContext().getObject('filesDir') + '/index.html'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Text('loading success'); + // 加载沙箱路径文件。 + Web({ src: url, controller: this.controller }); + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.ets old mode 100755 new mode 100644 index c85ba6a2e277da624eb8d9260b84edd1debda016..98175b1c9306188f2d0cd14b6d28ca1516aacb19 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadLocalPageFileInSandboxPath_two.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - htmlStr: string = 'data:text/html, Source:
source
'; - - build() { - Column() { - // 组件创建时,加载htmlStr - Web({ src: this.htmlStr, controller: this.controller }); - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + htmlStr: string = 'data:text/html, Source:
source
'; + + build() { + Column() { + // 组件创建时,加载htmlStr + Web({ src: this.htmlStr, controller: this.controller }); + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets old mode 100755 new mode 100644 index 826021cc5c3417b5ee5a622c349434e13e107d3d..2fce4124cc9f6a949805359bd6be3f2f9799127b --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingHTMLRichTextData.ets @@ -1,43 +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 { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('loadData') - .onClick(() => { - try { - // 点击按钮时,通过loadData,加载HTML格式的文本数据 - this.controller.loadData( - 'Source:
source
', - 'text/html', - 'UTF-8' - ); - } catch (error) { - console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - // 组件创建时,加载www.example.com - Web({ src: 'www.example.com', controller: this.controller }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadData') + .onClick(() => { + try { + // 点击按钮时,通过loadData,加载HTML格式的文本数据 + this.controller.loadData( + 'Source:
source
', + 'text/html', + 'UTF-8' + ); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 组件创建时,加载www.example.com + Web({ src: 'www.example.com', controller: this.controller }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.ets old mode 100755 new mode 100644 index aa7357bd6e6bb6297aef2ca2de635ba05461b7bf..729b5d21941b3a00420f55748a43bba096e7dc3e --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingLocalPages.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('loadUrl') - .onClick(() => { - try { - // 点击按钮时,通过loadUrl,跳转到local1.html - this.controller.loadUrl($rawfile('local1.html')); - } catch (error) { - console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - // 组件创建时,通过$rawfile加载本地文件local.html - Web({ src: $rawfile('local.html'), controller: this.controller }); - } - } +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadUrl') + .onClick(() => { + try { + // 点击按钮时,通过loadUrl,跳转到local1.html + this.controller.loadUrl($rawfile('local1.html')); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 组件创建时,通过$rawfile加载本地文件local.html + Web({ src: $rawfile('local.html'), controller: this.controller }); + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.ets old mode 100755 new mode 100644 index 28abb21e0386a29a6c4c133ac28fc3536e8ca445..ee28bc8715059335f8358429c0fbf0e6134e9618 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/ets/pages/LoadingWebPages.ets @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Button('loadUrl') - .onClick(() => { - try { - // 点击按钮时,通过loadUrl,跳转到www.example1.com - this.controller.loadUrl('www.example1.com'); - } catch (error) { - console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - // 组件创建时,加载www.example.com - Web({ src: 'www.example.com', controller: this.controller }); - } - } +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Button('loadUrl') + .onClick(() => { + try { + // 点击按钮时,通过loadUrl,跳转到www.example1.com + this.controller.loadUrl('www.example1.com'); + } catch (error) { + console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + // 组件创建时,加载www.example.com + Web({ src: 'www.example.com', controller: this.controller }); + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/module.json5 old mode 100755 new mode 100644 index 773b91ff67279367993a592066b520721cb154aa..ee18f9ce4fbbaa1861e1de23ff3e4846c93efc87 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions":[ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions":[ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html old mode 100755 new mode 100644 index 7c614d61c1d957ee99d7ed579693e639003bda0d..4e7956396344e0db753afb9431de6cfa7b0a1e07 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local.html @@ -1,21 +1,21 @@ - - - - - -

Hello World

- - + + + + + +

Hello World

+ + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html old mode 100755 new mode 100644 index 9287b82f7ade867a8ff152e64a5d32eb8b88ae29..5b3b0b03bbf5da5ac6fc1287737a776b2a9e3d4d --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/rawfile/local1.html @@ -1,21 +1,21 @@ - - - - - -

This is local1 page

- - + + + + + +

This is local1 page

+ + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebPageLoadBrowse/LoadPages/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_one.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_two.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadLocalPageFileInSandboxPath_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingHTMLRichTextData_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingLocalPages_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/LoadPages/screenshots/LoadingWebPages_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/app.json5 old mode 100755 new mode 100644 index 92cd9950ecc28f44b5fcdb0039d97ae2ca68a5e4..829e8ba122dafa9aad9d543ebd9a3a6e1fb0dd10 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/app.json5 @@ -1,25 +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.managepageredirectnav", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.managepageredirectnav", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index d63596ddd91bd58069ba6cced465d30337ebd007..f2843105d1f0874209a5c4a51a1d2c67d51e296c --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ManagePageRedirectNav" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ManagePageRedirectNav" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/README.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index f7776d248a712a50c07752a86f67b757f115e20a..23a5f218909827e91bf6f66ce3d472c99df7c7c2 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,55 +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. - */ -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'); - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.ets old mode 100755 new mode 100644 index b65fcd6f3e5e653d36efdef0823807177c805f8e..b812523763a062d749522c0371ee3cffbf4ddb72 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/CrossApplicationRedirection.ets @@ -1,47 +1,47 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; -import { call } from '@kit.TelephonyKit'; - -@Entry -@Component -struct WebComponent { - webviewController: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: $rawfile('call.html'), controller: this.webviewController }) - .onLoadIntercept((event) => { - if (event) { - let url: string = event.data.getRequestUrl(); - // 判断链接是否为拨号链接 - if (url.indexOf('tel://') === 0) { - // 跳转拨号界面 - call.makeCall(url.substring(6), (err) => { - if (!err) { - console.info('make call succeeded.'); - } else { - console.info('make call fail, err is:' + JSON.stringify(err)); - } - }); - return true; - } - } - return false; - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { call } from '@kit.TelephonyKit'; + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('call.html'), controller: this.webviewController }) + .onLoadIntercept((event) => { + if (event) { + let url: string = event.data.getRequestUrl(); + // 判断链接是否为拨号链接 + if (url.indexOf('tel://') === 0) { + // 跳转拨号界面 + call.makeCall(url.substring(6), (err) => { + if (!err) { + console.info('make call succeeded.'); + } else { + console.info('make call fail, err is:' + JSON.stringify(err)); + } + }); + return true; + } + } + return false; + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/HistoryNavigati.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/HistoryNavigati.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.ets old mode 100755 new mode 100644 index db97926478b9036088b75bced3f185db6a9feb5a..ff4a1e1e642eb98c225ef3d1409cc6c1031be3b0 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/PageRedirection.ets @@ -1,41 +1,41 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; -import { router } from '@kit.ArkUI'; - -@Entry -@Component -struct WebComponent { - webviewController: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - // 资源文件route.html存放路径src/main/resources/rawfile - Web({ src: $rawfile('route.html'), controller: this.webviewController }) - .onLoadIntercept((event) => { - if (event) { - let url: string = event.data.getRequestUrl(); - if (url.indexOf('native://') === 0) { - // 跳转其他界面 - router.pushUrl({ url: url.substring(9) }); - return true; - } - } - return false; - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct WebComponent { + webviewController: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + // 资源文件route.html存放路径src/main/resources/rawfile + Web({ src: $rawfile('route.html'), controller: this.webviewController }) + .onLoadIntercept((event) => { + if (event) { + let url: string = event.data.getRequestUrl(); + if (url.indexOf('native://') === 0) { + // 跳转其他界面 + router.pushUrl({ url: url.substring(9) }); + return true; + } + } + return false; + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets old mode 100755 new mode 100644 index 34f30365557ce8c1c895c002c639cac997111827..1743980f9f197ba9315bc701301966644de1ec67 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/ets/pages/ProfilePage.ets @@ -1,27 +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. - */ - -@Entry -@Component -struct ProfilePage { - @State message: string = 'Hello World'; - - build() { - Column() { - Text(this.message) - .fontSize(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. + */ + +@Entry +@Component +struct ProfilePage { + @State message: string = 'Hello World'; + + build() { + Column() { + Text(this.message) + .fontSize(20) + } + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html old mode 100755 new mode 100644 index 5103a528c59db1ee661938acb0a2c421fb2b515b..96cb6a1f804bd7d5dff5d7e3197cf4585155726b --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/call.html @@ -1,23 +1,23 @@ -/* -* 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. -*/ - - - - - - - +/* +* 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. +*/ + + + + + + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html old mode 100755 new mode 100644 index c597d31c9ac927af32fc6ab8db9cbac123753a3c..078bb6de0e7502bcb18ef9d3310e293c1af1b0f5 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/rawfile/route.html @@ -1,23 +1,23 @@ -/* -* 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. -*/ - - - - - - - +/* +* 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. +*/ + + + + + + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/CrossApplicationRedirection_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/HistoryNavigati_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/ManagePageRedirectNav/screenshots/PageRedirection_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/app.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/app.json5 old mode 100755 new mode 100644 index bb62a8d4a909019739a3b6d01c69f71eadafcadb..e5c664911c57e8483759f0ead8b22ff2e2af1005 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/app.json5 @@ -1,25 +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.netreqinterceptcachewinops", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.netreqinterceptcachewinops", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 969b8196a357eab7ad591615595a97050794c23b..ac0ab70b4d42157f3ba34fcf9e9a4608fcb1a4c0 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NetReqInterceptCacheWinOps" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NetReqInterceptCacheWinOps" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/README.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 old mode 100755 new mode 100644 index 22c5348e27e8c1f79b2432e085c66a519de9eba4..fa898913bfaae497e94355b9c9737ac75717a90e --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/build-profile.json5 @@ -1,76 +1,76 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry2", - "srcPath": "./entry2", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry3", - "srcPath": "./entry3", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry3", + "srcPath": "./entry3", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/code-linter.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/build-profile.json5 old mode 100755 new mode 100644 index 78c972d3cbca90ea057874f8761bc5284adc7b44..3c342f5bdbdc792ac81ce281fdd77d086590aa25 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/build-profile.json5 @@ -1,55 +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": { - "abiFilters": ["arm64-v8a", "x86_64", "armeabi-v7a"], - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "abiFilters": ["arm64-v8a", "x86_64", "armeabi-v7a"], + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 7086685affe8e93e804e9fb2ac4c335d92eb497f..1686eb5df713cd6fd4c5da0dd7aeeb5d580861a9 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(schemehandler) - -set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -if(DEFINED PACKAGE_INFO_FILE) - include(${PACKAGE_INFO_FILE}) -endif() - -include_directories(${NATIVERENDER_ROOT_PATH} - ${NATIVERENDER_ROOT_PATH}/include) - -add_library(entry SHARED rawfile_request.cpp hello.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(schemehandler) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_INFO_FILE) + include(${PACKAGE_INFO_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED rawfile_request.cpp hello.cpp) target_link_libraries(entry PUBLIC librawfile.z.so libace_napi.z.so libohweb.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp old mode 100755 new mode 100644 index f14eb24d0031ba09886a6d712e16888291afe1a4..8f1d5edf5007ff4869a96f9d61ca8f598abd3080 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/hello.cpp @@ -1,153 +1,153 @@ -/* - * 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 "hilog/log.h" -#include "napi/native_api.h" -#include "rawfile_request.h" -#include "rawfile/raw_file_manager.h" -#include "web/arkweb_scheme_handler.h" -#include "web/arkweb_net_error_list.h" - -#undef LOG_TAG -#define LOG_TAG "ss-handler" - -ArkWeb_SchemeHandler *g_schemeHandler; -ArkWeb_SchemeHandler *g_schemeHandlerForSW; -NativeResourceManager *g_resourceManager; - -// 注册三方协议的配置,需要在Web内核初始化之前调用,否则会注册失败。 -static napi_value RegisterCustomSchemes(napi_env env, napi_callback_info info) -{ - OH_LOG_INFO(LOG_APP, "register custom schemes"); - OH_ArkWeb_RegisterCustomSchemes("custom", ARKWEB_SCHEME_OPTION_STANDARD | ARKWEB_SCHEME_OPTION_CORS_ENABLED); - OH_ArkWeb_RegisterCustomSchemes("custom-local", ARKWEB_SCHEME_OPTION_LOCAL); - OH_ArkWeb_RegisterCustomSchemes( - "custom-csp-bypassing", ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD); - OH_ArkWeb_RegisterCustomSchemes("custom-isolated", ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED); - return nullptr; -} - -// 请求开始的回调,在该函数中我们创建一个RawfileRequest来实现对Web内核请求的拦截。 -void OnURLRequestStart(const ArkWeb_SchemeHandler *schemeHandler, - ArkWeb_ResourceRequest *resourceRequest, - const ArkWeb_ResourceHandler *resourceHandler, - bool *intercept) -{ - *intercept = true; - RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); - OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); - request->Start(); -} - -// 请求结束的回调,在该函数中我们需要标记RawfileRequest已经结束了,内部不应该再使用ResourceHandler。 -void OnURLRequestStop(const ArkWeb_SchemeHandler *schemeHandler, - const ArkWeb_ResourceRequest *request) -{ - if (!request) { - OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); - return; - } - - RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); - if (rawfileRequest) { - rawfileRequest->Stop(); - } -} - -void OnURLRequestStartForSW(const ArkWeb_SchemeHandler *schemeHandler, - ArkWeb_ResourceRequest *resourceRequest, - const ArkWeb_ResourceHandler *resourceHandler, - bool *intercept) -{ - *intercept = true; - RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); - OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); - request->Start(); -} - -void OnURLRequestStopForSW(const ArkWeb_SchemeHandler *schemeHandler, - const ArkWeb_ResourceRequest *request) -{ - if (!request) { - OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); - return; - } - - RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); - if (rawfileRequest) { - rawfileRequest->Stop(); - } -} - -// 设置SchemeHandler。 -static napi_value SetSchemeHandler(napi_env env, napi_callback_info info) -{ - OH_LOG_INFO(LOG_APP, "set scheme handler"); - OH_ArkWeb_CreateSchemeHandler(&g_schemeHandler); - OH_ArkWeb_CreateSchemeHandler(&g_schemeHandlerForSW); - - OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandler, OnURLRequestStart); - OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandler, OnURLRequestStop); - - OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandlerForSW, OnURLRequestStart); - OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandlerForSW, OnURLRequestStop); - - OH_ArkWeb_SetSchemeHandler("custom", "scheme-handler", g_schemeHandler); - OH_ArkWeb_SetSchemeHandler("custom-csp-bypassing", "scheme-handler", g_schemeHandler); - OH_ArkWeb_SetSchemeHandler("custom-isolated", "scheme-handler", g_schemeHandler); - OH_ArkWeb_SetSchemeHandler("custom-local", "scheme-handler", g_schemeHandler); - OH_ArkWeb_SetSchemeHandler("https", "scheme-handler", g_schemeHandler); - OH_ArkWeb_SetSchemeHandler("http", "scheme-handler", g_schemeHandler); - - OH_ArkWebServiceWorker_SetSchemeHandler("https", g_schemeHandlerForSW); - return nullptr; -} - -static napi_value InitResourceManager(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value argv[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); - g_resourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); - return nullptr; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"setSchemeHandler", nullptr, SetSchemeHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"initResourceManager", nullptr, InitResourceManager, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"registerCustomSchemes", nullptr, RegisterCustomSchemes, 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); +/* + * 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 "hilog/log.h" +#include "napi/native_api.h" +#include "rawfile_request.h" +#include "rawfile/raw_file_manager.h" +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + +ArkWeb_SchemeHandler *g_schemeHandler; +ArkWeb_SchemeHandler *g_schemeHandlerForSW; +NativeResourceManager *g_resourceManager; + +// 注册三方协议的配置,需要在Web内核初始化之前调用,否则会注册失败。 +static napi_value RegisterCustomSchemes(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "register custom schemes"); + OH_ArkWeb_RegisterCustomSchemes("custom", ARKWEB_SCHEME_OPTION_STANDARD | ARKWEB_SCHEME_OPTION_CORS_ENABLED); + OH_ArkWeb_RegisterCustomSchemes("custom-local", ARKWEB_SCHEME_OPTION_LOCAL); + OH_ArkWeb_RegisterCustomSchemes( + "custom-csp-bypassing", ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD); + OH_ArkWeb_RegisterCustomSchemes("custom-isolated", ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED); + return nullptr; +} + +// 请求开始的回调,在该函数中我们创建一个RawfileRequest来实现对Web内核请求的拦截。 +void OnURLRequestStart(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +// 请求结束的回调,在该函数中我们需要标记RawfileRequest已经结束了,内部不应该再使用ResourceHandler。 +void OnURLRequestStop(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +void OnURLRequestStartForSW(const ArkWeb_SchemeHandler *schemeHandler, + ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + bool *intercept) +{ + *intercept = true; + RawfileRequest* request = new RawfileRequest(resourceRequest, resourceHandler, g_resourceManager); + OH_ArkWebResourceRequest_SetUserData(resourceRequest, request); + request->Start(); +} + +void OnURLRequestStopForSW(const ArkWeb_SchemeHandler *schemeHandler, + const ArkWeb_ResourceRequest *request) +{ + if (!request) { + OH_LOG_ERROR(LOG_APP, "on request stop request is nullptr."); + return; + } + + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebResourceRequest_GetUserData(request); + if (rawfileRequest) { + rawfileRequest->Stop(); + } +} + +// 设置SchemeHandler。 +static napi_value SetSchemeHandler(napi_env env, napi_callback_info info) +{ + OH_LOG_INFO(LOG_APP, "set scheme handler"); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandler); + OH_ArkWeb_CreateSchemeHandler(&g_schemeHandlerForSW); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandler, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandler, OnURLRequestStop); + + OH_ArkWebSchemeHandler_SetOnRequestStart(g_schemeHandlerForSW, OnURLRequestStart); + OH_ArkWebSchemeHandler_SetOnRequestStop(g_schemeHandlerForSW, OnURLRequestStop); + + OH_ArkWeb_SetSchemeHandler("custom", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-csp-bypassing", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-isolated", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("custom-local", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("https", "scheme-handler", g_schemeHandler); + OH_ArkWeb_SetSchemeHandler("http", "scheme-handler", g_schemeHandler); + + OH_ArkWebServiceWorker_SetSchemeHandler("https", g_schemeHandlerForSW); + return nullptr; +} + +static napi_value InitResourceManager(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value argv[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + g_resourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[0]); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"setSchemeHandler", nullptr, SetSchemeHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"initResourceManager", nullptr, InitResourceManager, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"registerCustomSchemes", nullptr, RegisterCustomSchemes, 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); } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 5e824d1654e91454e6590a68a51d9fa41582aefe..3c11c8b57c075b5322df845f7fdc371f8b49caa0 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/napi_init.cpp @@ -1,67 +1,67 @@ -/* - * 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" - -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - - double value0; - napi_get_value_double(env, args[0], &value0); - - double value1; - napi_get_value_double(env, args[1], &value1); - - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - - return sum; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "add", nullptr, Add, 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); -} +/* + * 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" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, 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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp old mode 100755 new mode 100644 index 233eb0c157de78cca7000c937e1aa08019ffff1a..c017efb9831a0e7f4ec6be1584ca6a3b100e446d --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.cpp @@ -1,267 +1,267 @@ -/* - * 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 "rawfile_request.h" -#include "threads.h" - -#include "hilog/log.h" -#include "rawfile/raw_file.h" -#include "rawfile/raw_file_manager.h" - -#undef LOG_TAG -#define LOG_TAG "ss-handler" - -namespace { - -uint8_t g_buffer[1024]; -cnd_t g_httpBodyCnd; -mtx_t g_httpBodyMtx; -const int HTTP_OK = 200; -const int HTTP_NOT_FOUND = 404; -const int BUFFER_SIZE = 1000; - -// HttpBodyStream的读回调。 -void ReadCallback(const ArkWeb_HttpBodyStream *httpBodyStream, uint8_t* buffer, int bytesRead) -{ - OH_LOG_INFO(LOG_APP, "read http body back."); - bool isEof = OH_ArkWebHttpBodyStream_IsEof(httpBodyStream); - if (!isEof && bytesRead != 0) { - memset(buffer, 0, BUFFER_SIZE); - OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, BUFFER_SIZE); - } else { - RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebHttpBodyStream_GetUserData(httpBodyStream); - if (rawfileRequest) { - rawfileRequest->ReadRawfileDataOnWorkerThread(); - cnd_signal(&g_httpBodyCnd); - } - } -} - -int ReadHttpBodyOnWorkerThread(void* userData) -{ - memset(g_buffer, 0, BUFFER_SIZE); - ArkWeb_HttpBodyStream *httpBodyStream = (ArkWeb_HttpBodyStream *)userData; - OH_ArkWebHttpBodyStream_Read(httpBodyStream, g_buffer, BUFFER_SIZE); - int initResult = cnd_init(&g_httpBodyCnd); - if (initResult == 0) { - OH_LOG_INFO(LOG_APP, "cnd_init success."); - } else { - OH_LOG_INFO(LOG_APP, "cnd_init fail."); - } - int mtxResult = mtx_init(&g_httpBodyMtx, mtx_plain); - if (mtxResult == 0) { - OH_LOG_INFO(LOG_APP, "mtx_init success."); - } else { - OH_LOG_INFO(LOG_APP, "mtx_init fail."); - } - int waitResult = cnd_wait(&g_httpBodyCnd, &g_httpBodyMtx); - if (waitResult == 0) { - OH_LOG_INFO(LOG_APP, "cnd_wait success."); - } else { - OH_LOG_INFO(LOG_APP, "cnd_wait fail."); - } - return 0; -} - -int ReadRawfileOnWorkerThread(void* userData) -{ - RawfileRequest* rawfileRequest = (RawfileRequest*)userData; - if (rawfileRequest) { - rawfileRequest->ReadRawfileDataOnWorkerThread(); - } - return 0; -} - -// ArkWeb_HttpBodyStream的初始化回调。 -void InitCallback(const ArkWeb_HttpBodyStream *httpBodyStream, ArkWeb_NetError result) -{ - OH_LOG_INFO(LOG_APP, "init http body stream done %{public}d.", result); - bool isChunked = OH_ArkWebHttpBodyStream_IsChunked(httpBodyStream); - OH_LOG_INFO(LOG_APP, "http body stream is chunked %{public}d.", isChunked); - thrd_t th; - if (thrd_create(&th, ReadHttpBodyOnWorkerThread, (void *)httpBodyStream) != thrd_success) { - OH_LOG_ERROR(LOG_APP, "create thread failed."); - return; - } - - if (thrd_detach(th) != thrd_success) { - OH_LOG_ERROR(LOG_APP, "detach thread failed."); - } -} - -const int BLOCK_SIZE = 1024 * 8; -const int MAXWHILE = 100; - -} // namespace - -RawfileRequest::RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, - const ArkWeb_ResourceHandler *resourceHandler, - const NativeResourceManager* resourceManager) - : resourceRequest_(resourceRequest), - resourceHandler_(resourceHandler), - resourceManager_(resourceManager) {} - -RawfileRequest::~RawfileRequest() {} - -void RawfileRequest::Start() -{ - OH_LOG_INFO(LOG_APP, "start a rawfile request."); - char* url; - OH_ArkWebResourceRequest_GetUrl(resourceRequest_, &url); - std::string urlStr(url); - std::size_t position = urlStr.rfind('/'); - if (position != std::string::npos) { - rawfilePath_ = urlStr.substr(position + 1); - } - OH_ArkWeb_ReleaseString(url); - - OH_ArkWeb_CreateResponse(&response_); - OH_ArkWebResourceRequest_GetHttpBodyStream(resourceRequest(), &stream_); - if (stream_) { - OH_LOG_ERROR(LOG_APP, "have http body stream"); - OH_ArkWebHttpBodyStream_SetUserData(stream_, this); - OH_ArkWebHttpBodyStream_SetReadCallback(stream_, ReadCallback); - OH_ArkWebHttpBodyStream_Init(stream_, InitCallback); - } else { - thrd_t th; - if (thrd_create(&th, ReadRawfileOnWorkerThread, static_cast(this)) != thrd_success) { - OH_LOG_ERROR(LOG_APP, "create thread failed."); - return; - } - - if (thrd_detach(th) != thrd_success) { - OH_LOG_ERROR(LOG_APP, "detach thread failed."); - } - } -} - -// 在worker线程中读取rawfile,并通过ResourceHandler返回给Web内核。 -void RawfileRequest::ReadRawfileDataOnWorkerThread() -{ - OH_LOG_INFO(LOG_APP, "read rawfile in worker thread."); - const struct UrlInfo { - std::string resource; - std::string mimeType; - } urlInfos[] = { - {"test.html", "text/html"}, - {"video.html", "text/html"}, - {"isolated.html", "text/html"}, - {"csp_bypassing.html", "text/html"}, - {"post_data.html", "text/html"}, - {"chunked_post_stream.html", "text/html"}, - {"local.html", "text/html"}, - {"service_worker.html", "text/html"}, - {"csp_script.js", "text/javascript"}, - {"sw.js", "text/javascript"}, - {"isolated_script.js", "text/javascript"}, - {"local_script.js", "text/javascript"}, - {"test.mp4", "video/mp4"}, - {"xhr", "application/json"} - }; - - if (!resourceManager()) { - OH_LOG_ERROR(LOG_APP, "read rawfile error, resource manager is nullptr."); - return; - } - - RawFile *rawfile = OH_ResourceManager_OpenRawFile(resourceManager(), RawfilePath().c_str()); - if (!rawfile) { - OH_ArkWebResponse_SetStatus(response(), HTTP_NOT_FOUND); - } else { - OH_ArkWebResponse_SetStatus(response(), HTTP_OK); - } - - for (auto &urlInfo : urlInfos) { - if (urlInfo.resource == RawfilePath()) { - OH_ArkWebResponse_SetMimeType(response(), urlInfo.mimeType.c_str()); - break; - } - } - OH_ArkWebResponse_SetCharset(response(), "UTF-8"); - - long len = OH_ResourceManager_GetRawFileSize(rawfile); - OH_ArkWebResponse_SetHeaderByName(response(), "content-length", std::to_string(len).c_str(), false); - DidReceiveResponse(); - - long consumed = 0; - uint8_t buffer[BLOCK_SIZE]; - int i = 0; - while (++i < MAXWHILE) { - int ret = OH_ResourceManager_ReadRawFile(rawfile, buffer, BLOCK_SIZE); - if (ret > 0) { - OH_LOG_INFO(LOG_APP, "read rawfile %{public}d bytes.", ret); - } else if (ret == 0) { - OH_LOG_INFO(LOG_APP, "read rawfile Reached end of file, %{public}d bytes read.", ret); - break; - } else { - OH_LOG_ERROR(LOG_APP, "read rawfile Error, %{public}d bytes read.", ret); - break; - } - consumed += ret; - OH_ResourceManager_SeekRawFile(rawfile, consumed, 0); - DidReceiveData(buffer, ret); - memset(buffer, 0, BLOCK_SIZE); - } - - OH_ResourceManager_CloseRawFile(rawfile); - DidFinish(); -} - -void RawfileRequest::Stop() -{ - OH_LOG_INFO(LOG_APP, "stop the rawfile request."); - std::lock_guard guard(mutex_); - stopped_ = true; - if (response_) { - OH_ArkWeb_DestroyResponse(response_); - } - OH_ArkWebResourceRequest_Destroy(resourceRequest_); - OH_ArkWebResourceHandler_Destroy(resourceHandler_); -} - -void RawfileRequest::DidReceiveResponse() -{ - OH_LOG_INFO(LOG_APP, "did receive response."); - std::lock_guard guard(mutex_); - if (!stopped_) { - OH_ArkWebResourceHandler_DidReceiveResponse(resourceHandler_, response_); - } -} - -void RawfileRequest::DidReceiveData(const uint8_t *buffer, int64_t bufLen) -{ - OH_LOG_INFO(LOG_APP, "did receive data."); - std::lock_guard guard(mutex_); - if (!stopped_) { - OH_ArkWebResourceHandler_DidReceiveData(resourceHandler_, buffer, bufLen); - } -} - -void RawfileRequest::DidFinish() -{ - OH_LOG_INFO(LOG_APP, "did finish."); - std::lock_guard guard(mutex_); - if (!stopped_) { - OH_ArkWebResourceHandler_DidFinish(resourceHandler_); - } -} - -void RawfileRequest::DidFailWithError(ArkWeb_NetError errorCode) -{ - OH_LOG_INFO(LOG_APP, "did finish with error %{public}d.", errorCode); - if (!stopped_) { - OH_ArkWebResourceHandler_DidFailWithError(resourceHandler_, errorCode); - } +/* + * 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 "rawfile_request.h" +#include "threads.h" + +#include "hilog/log.h" +#include "rawfile/raw_file.h" +#include "rawfile/raw_file_manager.h" + +#undef LOG_TAG +#define LOG_TAG "ss-handler" + +namespace { + +uint8_t g_buffer[1024]; +cnd_t g_httpBodyCnd; +mtx_t g_httpBodyMtx; +const int HTTP_OK = 200; +const int HTTP_NOT_FOUND = 404; +const int BUFFER_SIZE = 1000; + +// HttpBodyStream的读回调。 +void ReadCallback(const ArkWeb_HttpBodyStream *httpBodyStream, uint8_t* buffer, int bytesRead) +{ + OH_LOG_INFO(LOG_APP, "read http body back."); + bool isEof = OH_ArkWebHttpBodyStream_IsEof(httpBodyStream); + if (!isEof && bytesRead != 0) { + memset(buffer, 0, BUFFER_SIZE); + OH_ArkWebHttpBodyStream_Read(httpBodyStream, buffer, BUFFER_SIZE); + } else { + RawfileRequest *rawfileRequest = (RawfileRequest *)OH_ArkWebHttpBodyStream_GetUserData(httpBodyStream); + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + cnd_signal(&g_httpBodyCnd); + } + } +} + +int ReadHttpBodyOnWorkerThread(void* userData) +{ + memset(g_buffer, 0, BUFFER_SIZE); + ArkWeb_HttpBodyStream *httpBodyStream = (ArkWeb_HttpBodyStream *)userData; + OH_ArkWebHttpBodyStream_Read(httpBodyStream, g_buffer, BUFFER_SIZE); + int initResult = cnd_init(&g_httpBodyCnd); + if (initResult == 0) { + OH_LOG_INFO(LOG_APP, "cnd_init success."); + } else { + OH_LOG_INFO(LOG_APP, "cnd_init fail."); + } + int mtxResult = mtx_init(&g_httpBodyMtx, mtx_plain); + if (mtxResult == 0) { + OH_LOG_INFO(LOG_APP, "mtx_init success."); + } else { + OH_LOG_INFO(LOG_APP, "mtx_init fail."); + } + int waitResult = cnd_wait(&g_httpBodyCnd, &g_httpBodyMtx); + if (waitResult == 0) { + OH_LOG_INFO(LOG_APP, "cnd_wait success."); + } else { + OH_LOG_INFO(LOG_APP, "cnd_wait fail."); + } + return 0; +} + +int ReadRawfileOnWorkerThread(void* userData) +{ + RawfileRequest* rawfileRequest = (RawfileRequest*)userData; + if (rawfileRequest) { + rawfileRequest->ReadRawfileDataOnWorkerThread(); + } + return 0; +} + +// ArkWeb_HttpBodyStream的初始化回调。 +void InitCallback(const ArkWeb_HttpBodyStream *httpBodyStream, ArkWeb_NetError result) +{ + OH_LOG_INFO(LOG_APP, "init http body stream done %{public}d.", result); + bool isChunked = OH_ArkWebHttpBodyStream_IsChunked(httpBodyStream); + OH_LOG_INFO(LOG_APP, "http body stream is chunked %{public}d.", isChunked); + thrd_t th; + if (thrd_create(&th, ReadHttpBodyOnWorkerThread, (void *)httpBodyStream) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } +} + +const int BLOCK_SIZE = 1024 * 8; +const int MAXWHILE = 100; + +} // namespace + +RawfileRequest::RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager) + : resourceRequest_(resourceRequest), + resourceHandler_(resourceHandler), + resourceManager_(resourceManager) {} + +RawfileRequest::~RawfileRequest() {} + +void RawfileRequest::Start() +{ + OH_LOG_INFO(LOG_APP, "start a rawfile request."); + char* url; + OH_ArkWebResourceRequest_GetUrl(resourceRequest_, &url); + std::string urlStr(url); + std::size_t position = urlStr.rfind('/'); + if (position != std::string::npos) { + rawfilePath_ = urlStr.substr(position + 1); + } + OH_ArkWeb_ReleaseString(url); + + OH_ArkWeb_CreateResponse(&response_); + OH_ArkWebResourceRequest_GetHttpBodyStream(resourceRequest(), &stream_); + if (stream_) { + OH_LOG_ERROR(LOG_APP, "have http body stream"); + OH_ArkWebHttpBodyStream_SetUserData(stream_, this); + OH_ArkWebHttpBodyStream_SetReadCallback(stream_, ReadCallback); + OH_ArkWebHttpBodyStream_Init(stream_, InitCallback); + } else { + thrd_t th; + if (thrd_create(&th, ReadRawfileOnWorkerThread, static_cast(this)) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "create thread failed."); + return; + } + + if (thrd_detach(th) != thrd_success) { + OH_LOG_ERROR(LOG_APP, "detach thread failed."); + } + } +} + +// 在worker线程中读取rawfile,并通过ResourceHandler返回给Web内核。 +void RawfileRequest::ReadRawfileDataOnWorkerThread() +{ + OH_LOG_INFO(LOG_APP, "read rawfile in worker thread."); + const struct UrlInfo { + std::string resource; + std::string mimeType; + } urlInfos[] = { + {"test.html", "text/html"}, + {"video.html", "text/html"}, + {"isolated.html", "text/html"}, + {"csp_bypassing.html", "text/html"}, + {"post_data.html", "text/html"}, + {"chunked_post_stream.html", "text/html"}, + {"local.html", "text/html"}, + {"service_worker.html", "text/html"}, + {"csp_script.js", "text/javascript"}, + {"sw.js", "text/javascript"}, + {"isolated_script.js", "text/javascript"}, + {"local_script.js", "text/javascript"}, + {"test.mp4", "video/mp4"}, + {"xhr", "application/json"} + }; + + if (!resourceManager()) { + OH_LOG_ERROR(LOG_APP, "read rawfile error, resource manager is nullptr."); + return; + } + + RawFile *rawfile = OH_ResourceManager_OpenRawFile(resourceManager(), RawfilePath().c_str()); + if (!rawfile) { + OH_ArkWebResponse_SetStatus(response(), HTTP_NOT_FOUND); + } else { + OH_ArkWebResponse_SetStatus(response(), HTTP_OK); + } + + for (auto &urlInfo : urlInfos) { + if (urlInfo.resource == RawfilePath()) { + OH_ArkWebResponse_SetMimeType(response(), urlInfo.mimeType.c_str()); + break; + } + } + OH_ArkWebResponse_SetCharset(response(), "UTF-8"); + + long len = OH_ResourceManager_GetRawFileSize(rawfile); + OH_ArkWebResponse_SetHeaderByName(response(), "content-length", std::to_string(len).c_str(), false); + DidReceiveResponse(); + + long consumed = 0; + uint8_t buffer[BLOCK_SIZE]; + int i = 0; + while (++i < MAXWHILE) { + int ret = OH_ResourceManager_ReadRawFile(rawfile, buffer, BLOCK_SIZE); + if (ret > 0) { + OH_LOG_INFO(LOG_APP, "read rawfile %{public}d bytes.", ret); + } else if (ret == 0) { + OH_LOG_INFO(LOG_APP, "read rawfile Reached end of file, %{public}d bytes read.", ret); + break; + } else { + OH_LOG_ERROR(LOG_APP, "read rawfile Error, %{public}d bytes read.", ret); + break; + } + consumed += ret; + OH_ResourceManager_SeekRawFile(rawfile, consumed, 0); + DidReceiveData(buffer, ret); + memset(buffer, 0, BLOCK_SIZE); + } + + OH_ResourceManager_CloseRawFile(rawfile); + DidFinish(); +} + +void RawfileRequest::Stop() +{ + OH_LOG_INFO(LOG_APP, "stop the rawfile request."); + std::lock_guard guard(mutex_); + stopped_ = true; + if (response_) { + OH_ArkWeb_DestroyResponse(response_); + } + OH_ArkWebResourceRequest_Destroy(resourceRequest_); + OH_ArkWebResourceHandler_Destroy(resourceHandler_); +} + +void RawfileRequest::DidReceiveResponse() +{ + OH_LOG_INFO(LOG_APP, "did receive response."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidReceiveResponse(resourceHandler_, response_); + } +} + +void RawfileRequest::DidReceiveData(const uint8_t *buffer, int64_t bufLen) +{ + OH_LOG_INFO(LOG_APP, "did receive data."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidReceiveData(resourceHandler_, buffer, bufLen); + } +} + +void RawfileRequest::DidFinish() +{ + OH_LOG_INFO(LOG_APP, "did finish."); + std::lock_guard guard(mutex_); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFinish(resourceHandler_); + } +} + +void RawfileRequest::DidFailWithError(ArkWeb_NetError errorCode) +{ + OH_LOG_INFO(LOG_APP, "did finish with error %{public}d.", errorCode); + if (!stopped_) { + OH_ArkWebResourceHandler_DidFailWithError(resourceHandler_, errorCode); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h old mode 100755 new mode 100644 index 047e3fbe96aeb8a0327bbc26c2960f6e7a74d3a6..e62d821e42c69565f4d057a8b29fd884b4812227 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/rawfile_request.h @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef RAWFILE_REQUEST_H -#define RAWFILE_REQUEST_H - -#include -#include - -#include -#include "web/arkweb_scheme_handler.h" -#include "web/arkweb_net_error_list.h" - -class RawfileRequest { -public: - RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, - const ArkWeb_ResourceHandler *resourceHandler, - const NativeResourceManager* resourceManager); - ~RawfileRequest(); - - void Start(); - void Stop(); - void ReadRawfileDataOnWorkerThread(); - - const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } - const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } - const NativeResourceManager *resourceManager() { return resourceManager_; } - ArkWeb_Response *response() { return response_; } - ArkWeb_HttpBodyStream *stream() { return stream_; } - const std::string RawfilePath() { return rawfilePath_; } - - void DidReceiveResponse(); - void DidReceiveData(const uint8_t *buffer, int64_t bufLen); - void DidFinish(); - void DidFailWithError(ArkWeb_NetError errorCode); - -private: - const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; - const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; - const NativeResourceManager *resourceManager_{nullptr}; - ArkWeb_Response *response_; - bool stopped_{false}; - std::string rawfilePath_; - ArkWeb_HttpBodyStream *stream_{nullptr}; - std::mutex mutex_; -}; - +/* + * 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 RAWFILE_REQUEST_H +#define RAWFILE_REQUEST_H + +#include +#include + +#include +#include "web/arkweb_scheme_handler.h" +#include "web/arkweb_net_error_list.h" + +class RawfileRequest { +public: + RawfileRequest(const ArkWeb_ResourceRequest *resourceRequest, + const ArkWeb_ResourceHandler *resourceHandler, + const NativeResourceManager* resourceManager); + ~RawfileRequest(); + + void Start(); + void Stop(); + void ReadRawfileDataOnWorkerThread(); + + const ArkWeb_ResourceHandler *resourceHandler() { return resourceHandler_; } + const ArkWeb_ResourceRequest *resourceRequest() { return resourceRequest_; } + const NativeResourceManager *resourceManager() { return resourceManager_; } + ArkWeb_Response *response() { return response_; } + ArkWeb_HttpBodyStream *stream() { return stream_; } + const std::string RawfilePath() { return rawfilePath_; } + + void DidReceiveResponse(); + void DidReceiveData(const uint8_t *buffer, int64_t bufLen); + void DidFinish(); + void DidFailWithError(ArkWeb_NetError errorCode); + +private: + const ArkWeb_ResourceRequest *resourceRequest_{nullptr}; + const ArkWeb_ResourceHandler *resourceHandler_{nullptr}; + const NativeResourceManager *resourceManager_{nullptr}; + ArkWeb_Response *response_; + bool stopped_{false}; + std::string rawfilePath_; + ArkWeb_HttpBodyStream *stream_{nullptr}; + std::mutex mutex_; +}; + #endif // RAWFILE_REQUEST_H \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 421d8dd56c181c43f04ba1950bad7776d88419c3..176550bb734d1a92a6804e3414f4dc27621bfe77 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,20 +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 { resourceManager } from "@kit.LocalizationKit"; - -export const registerCustomSchemes: () => void; -export const setSchemeHandler: () => void; +/* + * 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 { resourceManager } from "@kit.LocalizationKit"; + +export const registerCustomSchemes: () => void; +export const setSchemeHandler: () => void; export const initResourceManager: (resmgr: resourceManager.ResourceManager) => void; \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index becf66a83e050134286b4ce280bf32e8b33931c0..5c663b03cee9c30ca291b6171ee8c56f6daf2202 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,55 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import testNapi from 'libentry.so'; -import { webview } from '@kit.ArkWeb'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - // 注册三方协议的配置。 - testNapi.registerCustomSchemes(); - // 初始化Web组件内核,该操作会初始化Browser进程以及创建BrowserContext。 - webview.WebviewController.initializeWebEngine(); - // 设置SchemeHandler。 - testNapi.setSchemeHandler(); - } - - onDestroy(): void { - - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - return; - } - }); - } - - onWindowStageDestroy(): void { - - } - - onForeground(): void { - - } - - onBackground(): void { - - } +/* + * 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'; +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + // 注册三方协议的配置。 + testNapi.registerCustomSchemes(); + // 初始化Web组件内核,该操作会初始化Browser进程以及创建BrowserContext。 + webview.WebviewController.initializeWebEngine(); + // 设置SchemeHandler。 + testNapi.setSchemeHandler(); + } + + onDestroy(): void { + + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + }); + } + + onWindowStageDestroy(): void { + + } + + onForeground(): void { + + } + + onBackground(): void { + + } }; \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 26f1b893f9dbe047664a1bdd484b38bb176e192b..048e968dced033569f457a32e18bf4ce5d2f9c84 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/ets/pages/Index.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import testNapi from 'libentry.so'; -import { webview } from '@kit.ArkWeb'; -import { resourceManager } from '@kit.LocalizationKit'; - -@Entry -@Component -struct Index { - mycontroller: webview.WebviewController = new webview.WebviewController('scheme-handler'); - - build() { - Row() { - Column() { - Button('goback').onClick( event => { - this.mycontroller.backward(); - }) - - Web({ src: $rawfile('test.html'), controller: this.mycontroller}) - .javaScriptAccess(true) - .width('100%') - .height('100%') - .databaseAccess(true) - .fileAccess(false) - .domStorageAccess(true) - .cacheMode(CacheMode.Default) - .onPageBegin( event => { - testNapi.initResourceManager(getContext().resourceManager); - }) - } - .width('100%') - } - .height('100%') - } +/* + * 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 { webview } from '@kit.ArkWeb'; +import { resourceManager } from '@kit.LocalizationKit'; + +@Entry +@Component +struct Index { + mycontroller: webview.WebviewController = new webview.WebviewController('scheme-handler'); + + build() { + Row() { + Column() { + Button('goback').onClick( event => { + this.mycontroller.backward(); + }) + + Web({ src: $rawfile('test.html'), controller: this.mycontroller}) + .javaScriptAccess(true) + .width('100%') + .height('100%') + .databaseAccess(true) + .fileAccess(false) + .domStorageAccess(true) + .cacheMode(CacheMode.Default) + .onPageBegin( event => { + testNapi.initResourceManager(getContext().resourceManager); + }) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html old mode 100755 new mode 100644 index 5d0e9d1b0fce547231de66b5100d4baa2d806686..645cd7833b21a64e904b8747e2824e7f9ef6dcb7 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/chunked_post_stream.html @@ -1,46 +1,46 @@ - - - - - - - - -
test post chunked http body.
- - + + + + + + + + +
test post chunked http body.
+ + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html old mode 100755 new mode 100644 index 59d38ff73de244271368552f7411514bdecbd2cb..c80c78270a1b8ad62a0b46b5085789b1d4c3673f --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_bypassing.html @@ -1,26 +1,26 @@ - - - - - - - - -

scheme: custom-csp-bypassing

-

options: ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD

- - - + + + + + + + + +

scheme: custom-csp-bypassing

+

options: ARKWEB_SCHEME_OPTION_CSP_BYPASSING | ARKWEB_SCHEME_OPTION_STANDARD

+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js old mode 100755 new mode 100644 index 1c4da6421155719389a427a144544549b7e76645..ab74f8192b4fe6618ea410e26eaf44212fd785cc --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/csp_script.js @@ -1,19 +1,19 @@ -/* -* 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. -*/ - -const body = document.body; -const element = document.createElement('div'); -element.textContent = 'csp_script.js bypass the csp rules'; -body.appendChild(element); +/* +* 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. +*/ + +const body = document.body; +const element = document.createElement('div'); +element.textContent = 'csp_script.js bypass the csp rules'; +body.appendChild(element); diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html old mode 100755 new mode 100644 index 5ca027298379aa19b0db3846b6167081974641c1..bc04b313506d81f61fb720c4df39f99f9138d500 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated.html @@ -1,26 +1,26 @@ - - - - - - - -

scheme: custom-isolated

-

options: ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED

-
isolated_script.js 被拦截
- - - + + + + + + + +

scheme: custom-isolated

+

options: ARKWEB_SCHEME_OPTION_DISPLAY_ISOLATED

+
isolated_script.js 被拦截
+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js old mode 100755 new mode 100644 index 2e2dde4c9f107b616d3c897b7cc0ddbe29992734..c514c5cb83de7ee9de46a32ba867d625e091b2db --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/isolated_script.js @@ -1,17 +1,17 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -const element = document.getElementById('isolated_test'); -element.textContent = 'isolated_script.js not blocked'; +/* +* 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. +*/ + +const element = document.getElementById('isolated_test'); +element.textContent = 'isolated_script.js not blocked'; diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html old mode 100755 new mode 100644 index bbd9de16620cf3296557f9d253ffd9f230bd9524..48ae7287bb6eb547f3e6af93822a6a2395554b28 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local.html @@ -1,26 +1,26 @@ - - - - - - - -

scheme: custom-local

-

options: ARKWEB_SCHEME_OPTION_LOCAL

-
local_script.js 被拦截
- - - + + + + + + + +

scheme: custom-local

+

options: ARKWEB_SCHEME_OPTION_LOCAL

+
local_script.js 被拦截
+ + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js old mode 100755 new mode 100644 index b68be374a917688cc814fdb498b61c0b4d346c40..6477b82cf15642403b66696979b887322bcc9bf5 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/local_script.js @@ -1,17 +1,17 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -const element = document.getElementById('local_test'); -element.textContent = 'local_script.js not blocked.'; +/* +* 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. +*/ + +const element = document.getElementById('local_test'); +element.textContent = 'local_script.js not blocked.'; diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html old mode 100755 new mode 100644 index 573507058f4dff7853136aa7491fe671bcbadcbe..cbb19dd30b4670af0cd983c6b86e91ffd283bc1f --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/post_data.html @@ -1,48 +1,48 @@ - - - - - - - - -
test xhr post
-
test xhr put
- - + + + + + + + + +
test xhr post
+
test xhr put
+ + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html old mode 100755 new mode 100644 index b6188583c6f5269474fb1976babd01c8407de966..e971e1c41387fc0a6e34e39d7a5ec6477419a3e2 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/service_worker.html @@ -1,34 +1,34 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js old mode 100755 new mode 100644 index 05bca835cd697dda090f9b16cf0ea3df08366240..0b442d256cfef7292d784b06d7b0c7beff924a43 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/sw.js @@ -1,25 +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. -*/ - -self.addEventListener('install', event => { - console.log('v1 installing'); - event.waitUntil( - caches.open('static-v1').then(cache => cache.add('/cat.svg')) - ); -}); - -self.addEventListener('activate', event => { - console.log('v1 now redy to handle fetches.'); -}); +/* +* 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. +*/ + +self.addEventListener('install', event => { + console.log('v1 installing'); + event.waitUntil( + caches.open('static-v1').then(cache => cache.add('/cat.svg')) + ); +}); + +self.addEventListener('activate', event => { + console.log('v1 now redy to handle fetches.'); +}); diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html old mode 100755 new mode 100644 index 03e9dfb9387b65525ab2fc964f0b975e9ae17e7e..957e0b9cc9468930d06bade7bf15c6ea0ebbc90e --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.html @@ -1,31 +1,31 @@ - - - - - - - - -

网络拦截测试demo

-拦截视频资源请求,读取本地mp4文件
-测试三方协议忽略csp检查,并成功拦截
-测试拦截设置ISOLATED属性的三方协议
-测试拦截设置LOCAL属性的三方协议
-测试拦截service worker触发的请求
-测试读取blob类型http body stream
-测试读取chunked类型http body stream - + + + + + + + + +

网络拦截测试demo

+拦截视频资源请求,读取本地mp4文件
+测试三方协议忽略csp检查,并成功拦截
+测试拦截设置ISOLATED属性的三方协议
+测试拦截设置LOCAL属性的三方协议
+测试拦截service worker触发的请求
+测试读取blob类型http body stream
+测试读取chunked类型http body stream + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.mp4 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/test.mp4 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html old mode 100755 new mode 100644 index 657b5598546f9b29d74cff3ed8a695d7a120cc3e..87ccf17357ff0339a98a46c4f4f2077bac25699b --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/video.html @@ -1,25 +1,25 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr old mode 100755 new mode 100644 index 81d8352ea1efd7420a49c007abf0f84f10028b4b..42d4264b05a9fa4c2a5bf7e90c6f003e17588137 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/rawfile/xhr @@ -1,16 +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. -*/ - +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + {} \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/Libentry.mock.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/Libentry.mock.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/oh-package.json5 old mode 100755 new mode 100644 index bcb70ff878510fb523d011c47eb563dc4edbd9ea..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets old mode 100755 new mode 100644 index 772019f7dbf631ec081f1e1a88611f34c37033ac..6055f87c9830bf4e9b642763003b378ce0d93cc2 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; - -export default class Entry2Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - let features = new webview.BackForwardCacheSupportedFeatures(); - features.nativeEmbed = true; - features.mediaTakeOver = true; - webview.WebviewController.enableBackForwardCache(features); - webview.WebviewController.initializeWebEngine(); - AppStorage.setOrCreate('abilityWant', want); - } - - 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'); - } -} +/* + * 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'; +import { webview } from '@kit.ArkWeb'; + +export default class Entry2Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + let features = new webview.BackForwardCacheSupportedFeatures(); + features.nativeEmbed = true; + features.mediaTakeOver = true; + webview.WebviewController.enableBackForwardCache(features); + webview.WebviewController.initializeWebEngine(); + AppStorage.setOrCreate('abilityWant', want); + } + + 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets old mode 100755 new mode 100644 index a9c5227a98f85362a6acd1da493248d0675e204f..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets @@ -1,27 +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 Entry2BackupAbility 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)); - } +/* + * 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 Entry2BackupAbility 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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/module.json5 old mode 100755 new mode 100644 index b171fdbc82e9e1d2c1e9ba4542c157ce3f18848e..90a4604809422135bc23f5a1d55f88ba15ad078d --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/module.json5 @@ -1,70 +1,70 @@ -/* - * 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": "entry2", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "Entry2Ability", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry2Ability", - "srcEntry": "./ets/entry2ability/Entry2Ability.ets", - "description": "$string:Entry2Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry2Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "Entry2BackupAbility", - "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry2", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry2BackupAbility", + "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/module.json5 old mode 100755 new mode 100644 index f877d50cb78d8e6ec5caf058ff23e3b46a25ba86..17410acb16bcc114982071879ee6b1f000794e19 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry2_test", - "type": "feature", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/.gitignore b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/build-profile.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/oh-package.json5 old mode 100755 new mode 100644 index 401ea2ff2de9d5a85b272557fd72f6d8e2d9440d..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry3", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry3", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets old mode 100755 new mode 100644 index aad8855ea697dce833c927d3ea957701800947fe..e27948c8d6eb8c0fe9de77da4aa4b97e80415aea --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import { createNWeb, defaultUrl } from '../pages/common'; - -export default class Entry3Ability 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; - } - // 创建Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建,应用仅创建一个Web组件 - createNWeb(defaultUrl, windowStage.getMainWindowSync().getUIContext()); - 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'); - } -} +/* + * 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'; +import { createNWeb, defaultUrl } from '../pages/common'; + +export default class Entry3Ability 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; + } + // 创建Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建,应用仅创建一个Web组件 + createNWeb(defaultUrl, windowStage.getMainWindowSync().getUIContext()); + 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets old mode 100755 new mode 100644 index b096393478eac3afd1e3c68d6d669646a417dbea..93be298e5625a736b6faafea78bf1a0db149990e --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/ets/pages/common.ets @@ -1,116 +1,116 @@ -/* - * 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. - */ - -// 提供动态挂载Web组件能力 -import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -export const defaultUrl : string = 'www.example.com'; - -// Data为入参封装类 -class Data{ - public url: string = ''; - public webController: webview.WebviewController | null = null; - - constructor(url: string, webController: webview.WebviewController) { - this.url = url; - this.webController = webController; - } -} - -// @Builder中为动态组件的具体组件内容 -@Builder -function webBuilder(data:Data) { - Web({ src: data.url, controller: data.webController }) - .width('100%') - .height('100%') - .borderStyle(BorderStyle.Dashed) - .borderWidth(2) -} - -let wrap = wrapBuilder<[Data]>(webBuilder); - -// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 -export class MyNodeController extends NodeController { - private builderNode: BuilderNode<[Data]> | null | undefined = null; - private webController : webview.WebviewController | null | undefined = null; - private rootNode : FrameNode | null = null; - - constructor(builderNode : BuilderNode<[Data]> | undefined, webController : webview.WebviewController | undefined) { - super(); - this.builderNode = builderNode; - this.webController = webController; - } - - // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 - // 在对应NodeContainer创建的时候调用或者通过rebuild方法调用刷新 - makeNode(uiContext: UIContext): FrameNode | null { - // 该节点会被挂载在NodeContainer的父节点下 - return this.rootNode; - } - - // 挂载Webview - attachWeb() : void { - if (this.builderNode) { - let frameNode : FrameNode | null = this.builderNode.getFrameNode(); - if (frameNode?.getParent() != null) { - // 挂载自定义节点前判断该节点是否已经被挂载 - hilog.error(0x0000, 'testTag', '%{public}s', 'The frameNode is already attached'); - return; - } - this.rootNode = this.builderNode.getFrameNode(); - } - } - - // 卸载Webview - detachWeb() : void { - this.rootNode = null; - } - - getWebController() : webview.WebviewController | null | undefined { - return this.webController; - } -} - -// 创建Map保存所需要的BuilderNode -let builderNodeMap : Map | undefined> = new Map(); -// 创建Map保存所需要的webview.WebviewController -let webControllerMap : Map = new Map(); - -// 初始化需要UIContext对象,UIContext对象可通过窗口或自定义组件的getUIContext方法获取 -export const createNWeb = (url: string, uiContext: UIContext) => { - // 创建WebviewController - let webController = new webview.WebviewController() ; - // 创建BuilderNode - let builderNode : BuilderNode<[Data]> = new BuilderNode(uiContext); - // 创建动态Web组件 - builderNode.build(wrap, new Data(url, webController)); - - // 保存BuilderNode - builderNodeMap.set(url, builderNode); - // 保存WebviewController - webControllerMap.set(url, webController); -} - -// 自定义获取BuilderNode的接口 -export const getBuilderNode = (url : string) : BuilderNode<[Data]> | undefined => { - return builderNodeMap.get(url); -} -// 自定义获取WebviewController的接口 -export const getWebviewController = (url : string) : webview.WebviewController | undefined => { - return webControllerMap.get(url); -} - +/* + * 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. + */ + +// 提供动态挂载Web组件能力 +import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +export const defaultUrl : string = 'www.example.com'; + +// Data为入参封装类 +class Data{ + public url: string = ''; + public webController: webview.WebviewController | null = null; + + constructor(url: string, webController: webview.WebviewController) { + this.url = url; + this.webController = webController; + } +} + +// @Builder中为动态组件的具体组件内容 +@Builder +function webBuilder(data:Data) { + Web({ src: data.url, controller: data.webController }) + .width('100%') + .height('100%') + .borderStyle(BorderStyle.Dashed) + .borderWidth(2) +} + +let wrap = wrapBuilder<[Data]>(webBuilder); + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private builderNode: BuilderNode<[Data]> | null | undefined = null; + private webController : webview.WebviewController | null | undefined = null; + private rootNode : FrameNode | null = null; + + constructor(builderNode : BuilderNode<[Data]> | undefined, webController : webview.WebviewController | undefined) { + super(); + this.builderNode = builderNode; + this.webController = webController; + } + + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 + // 在对应NodeContainer创建的时候调用或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + // 该节点会被挂载在NodeContainer的父节点下 + return this.rootNode; + } + + // 挂载Webview + attachWeb() : void { + if (this.builderNode) { + let frameNode : FrameNode | null = this.builderNode.getFrameNode(); + if (frameNode?.getParent() != null) { + // 挂载自定义节点前判断该节点是否已经被挂载 + hilog.error(0x0000, 'testTag', '%{public}s', 'The frameNode is already attached'); + return; + } + this.rootNode = this.builderNode.getFrameNode(); + } + } + + // 卸载Webview + detachWeb() : void { + this.rootNode = null; + } + + getWebController() : webview.WebviewController | null | undefined { + return this.webController; + } +} + +// 创建Map保存所需要的BuilderNode +let builderNodeMap : Map | undefined> = new Map(); +// 创建Map保存所需要的webview.WebviewController +let webControllerMap : Map = new Map(); + +// 初始化需要UIContext对象,UIContext对象可通过窗口或自定义组件的getUIContext方法获取 +export const createNWeb = (url: string, uiContext: UIContext) => { + // 创建WebviewController + let webController = new webview.WebviewController() ; + // 创建BuilderNode + let builderNode : BuilderNode<[Data]> = new BuilderNode(uiContext); + // 创建动态Web组件 + builderNode.build(wrap, new Data(url, webController)); + + // 保存BuilderNode + builderNodeMap.set(url, builderNode); + // 保存WebviewController + webControllerMap.set(url, webController); +} + +// 自定义获取BuilderNode的接口 +export const getBuilderNode = (url : string) : BuilderNode<[Data]> | undefined => { + return builderNodeMap.get(url); +} +// 自定义获取WebviewController的接口 +export const getWebviewController = (url : string) : webview.WebviewController | undefined => { + return webControllerMap.get(url); +} + diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 old mode 100755 new mode 100644 index db35d4bff47b7647ddc86c9ab2e4c31ae43e90e2..5566c38cae3156d6470062ff659b9f0a54160541 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/module.json5 @@ -1,47 +1,47 @@ -/* - * 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": "entry3", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry3Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry3Ability", - "srcEntry": "./ets/entry3ability/Entry3Ability.ets", - "description": "$string:Entry3Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry3Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry3", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry3Ability", + "srcEntry": "./ets/entry3ability/Entry3Ability.ets", + "description": "$string:Entry3Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry3Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9fec93324fb8655cf1fac5683305c468a26c135e..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/ohosTest/module.json5 @@ -1,27 +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": "entry3_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/List.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/entry3/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigorfile.ts b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/oh-package.json5 b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/ohosTest.md b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/InterceptNetRequest_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/MigrateWebCompWin_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_1.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_2.png b/code/DocsSample/ArkWeb/ManageWebPageLoadBrowse/NetReqInterceptCacheWinOps/screenshots/SetBackForwardCache_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/.gitignore b/code/DocsSample/ArkWeb/ProcessWebPageCont/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/app.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/app.json5 old mode 100755 new mode 100644 index 139b247a26cf39f5951a8bbcd51272286f5187a4..4b1ce53f111420364c0803811493cd969dc80603 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/app.json5 @@ -1,25 +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.processwebpagecont", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.processwebpagecont", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 9884e6c4b082475eb69bf40c3140f7232c843183..4779102effef55e6d1414c9166b60b0783cdc210 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ProcessWebPageCont" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ProcessWebPageCont" + } + ] +} diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/README.md b/code/DocsSample/ArkWeb/ProcessWebPageCont/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/build-profile.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/ProcessWebPageCont/code-linter.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/.gitignore b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b865efd626c466d6a334efc1e8111c6e88807a82..82e98bec44d83d2df03deb52508045cb06cc8604 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 7aaec79f5a28d765725aede370d8344f3839638c..29feaca7669174be5c2b0e2366529ee94ab7e726 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets old mode 100755 new mode 100644 index f2e0e972c8c328d93ba38add78c67350b50c9986..d85b285f9472f74c0627c8b99a75c5538f3fb33b --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/CalcAdjustSafeArea.ets @@ -1,30 +1,30 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: 'www.example.com', controller: this.controller }) - .width('100%').height('100%') - .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: 'www.example.com', controller: this.controller }) + .width('100%').height('100%') + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) + } + } +} diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 28727bc7147174557a51ae66ec8b8a59039a8048..1def271b5633e957e9dd40c3b9591542f5cae01f --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/Index.ets @@ -1,42 +1,42 @@ -/* - * 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 { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('InitiatePrintW3CAPI') - .onClick(() => { - router.pushUrl({ url: 'pages/InitiatePrintW3CAPI' }); - }) - Button('InitiatePrintAppAPI') - .onClick(() => { - router.pushUrl({ url: 'pages/InitiatePrintAppAPI' }); - }) - Button('PreviewPDF') - .onClick(() => { - router.pushUrl({ url: 'pages/PreviewPDF' }); - }) - Button('CalcAdjustSafeArea') - .onClick(() => { - router.pushUrl({ url: 'pages/CalcAdjustSafeArea' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('InitiatePrintW3CAPI') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatePrintW3CAPI' }); + }) + Button('InitiatePrintAppAPI') + .onClick(() => { + router.pushUrl({ url: 'pages/InitiatePrintAppAPI' }); + }) + Button('PreviewPDF') + .onClick(() => { + router.pushUrl({ url: 'pages/PreviewPDF' }); + }) + Button('CalcAdjustSafeArea') + .onClick(() => { + router.pushUrl({ url: 'pages/CalcAdjustSafeArea' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintAppAPI.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/InitiatePrintW3CAPI.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets old mode 100755 new mode 100644 index 4314ecdac9649a5c608c38b2b8d628048d1edc77..930d3af17d78eff8091881f2a20ec671a3206c54 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/ets/pages/PreviewPDF.ets @@ -1,36 +1,36 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ - src: - $r('app.string.web_path'), // 方式一 加载网络PDF文档 - // getContext(this).filesDir + '/test.pdf', // 方式二 加载本地应用沙箱内PDF文档 - // 'resource://rawfile/test.pdf', // 方式三 应用内resource资源PDF文档 - // $rawfile('test.pdf'), // 方式四 应用内resource资源PDF文档 - controller: this.controller - }) - .domStorageAccess(true) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ + src: + $r('app.string.web_path'), // 方式一 加载网络PDF文档 + // getContext(this).filesDir + '/test.pdf', // 方式二 加载本地应用沙箱内PDF文档 + // 'resource://rawfile/test.pdf', // 方式三 应用内resource资源PDF文档 + // $rawfile('test.pdf'), // 方式四 应用内resource资源PDF文档 + controller: this.controller + }) + .domStorageAccess(true) + } + } +} diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 old mode 100755 new mode 100644 index 3bd75df6f68922e5bb0e9020d8a692b688acc2e0..325ae89273a828848850c261ddb1abde73c23c5a --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/module.json5 @@ -1,74 +1,74 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions":[ - { - "name" : "ohos.permission.PRINT" - }, - { - "name" : "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions":[ + { + "name" : "ohos.permission.PRINT" + }, + { + "name" : "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html old mode 100755 new mode 100644 index d286a9756eac8f3612e95c90a75974ea2aa03de2..7225f16ebc840f16091bc9e7c75380f4c1104470 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/print.html @@ -1,63 +1,63 @@ - - - - - - - - printTest - - - - -
-

-
This is a test page for printing
-
-
-

- -

content content content

-
- - - - - - - - - - - - - - - - - -
ThingChairs
1blue
2green
-
-

content content content

-

content content content

-
- + + + + + + + + printTest + + + + +
+

+
This is a test page for printing
+
+
+

+ +

content content content

+
+ + + + + + + + + + + + + + + + + +
ThingChairs
1blue
2green
+
+

content content content

+

content content content

+
+ diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/rawfile/test.pdf old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/ProcessWebPageCont/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/ProcessWebPageCont/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/ProcessWebPageCont/hvigorfile.ts b/code/DocsSample/ArkWeb/ProcessWebPageCont/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/oh-package.json5 b/code/DocsSample/ArkWeb/ProcessWebPageCont/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/ProcessWebPageCont/oh-package.json5 +++ b/code/DocsSample/ArkWeb/ProcessWebPageCont/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/ProcessWebPageCont/ohosTest.md b/code/DocsSample/ArkWeb/ProcessWebPageCont/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/CalcAdjustSafeArea.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintAppAPI.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/InitiatePrintW3CAPI.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/PreviewPDF.png b/code/DocsSample/ArkWeb/ProcessWebPageCont/screenshots/PreviewPDF.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 old mode 100755 new mode 100644 index 67a31a5bae968500f31b64abd5e4d290b5f13347..0f85c5557290b6c5fe654a0173b9db71c296633d --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/app.json5 @@ -1,25 +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.setbasicattrsevtsone", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.setbasicattrsevtsone", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 5b7841812368e2594acd000be1bb8f4c994ad6c5..f3bc9e64fec3aceeac9b80739ca1dae60be59090 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SetBasicAttrsEvtsOne" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SetBasicAttrsEvtsOne" + } + ] +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/AllowGeolocation.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ClearAllCookiesSync.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ConfigCookieSync.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DarkMode_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteAllData.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/DeleteGeolocation.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ExistCookie.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/FetchCookieSync.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/GetAccessibleGeolocation.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/IncognitoMode_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 17271bb68e81480fbfddfac6abb27e1150b6d602..420f733900a18591c4b182d382f7b6e6bede3d61 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/Index.ets @@ -1,82 +1,82 @@ -/* - * 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 { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('DarkMode_one') - .onClick(() => { - router.pushUrl({ url: 'pages/DarkMode_one' }); - }) - Button('DarkMode_two') - .onClick(() => { - router.pushUrl({ url: 'pages/DarkMode_two' }); - }) - Button('AllowGeolocation') - .onClick(() => { - router.pushUrl({ url: 'pages/AllowGeolocation' }); - }) - Button('ClearAllCookiesSync') - .onClick(() => { - router.pushUrl({ url: 'pages/ClearAllCookiesSync' }); - }) - Button('ConfigCookieSync') - .onClick(() => { - router.pushUrl({ url: 'pages/ConfigCookieSync' }); - }) - Button('DeleteAllData') - .onClick(() => { - router.pushUrl({ url: 'pages/DeleteAllData' }); - }) - Button('DeleteGeolocation') - .onClick(() => { - router.pushUrl({ url: 'pages/DeleteGeolocation' }); - }) - Button('ExistCookie') - .onClick(() => { - router.pushUrl({ url: 'pages/ExistCookie' }); - }) - Button('FetchCookieSync') - .onClick(() => { - router.pushUrl({ url: 'pages/FetchCookieSync' }); - }) - Button('GetAccessibleGeolocation') - .onClick(() => { - router.pushUrl({ url: 'pages/GetAccessibleGeolocation' }); - }) - Button('IncognitoMode_one') - .onClick(() => { - router.pushUrl({ url: 'pages/IncognitoMode_one' }); - }) - Button('IncognitoMode_two') - .onClick(() => { - router.pushUrl({ url: 'pages/IncognitoMode_two' }); - }) - Button('OpenPageNewWin') - .onClick(() => { - router.pushUrl({ url: 'pages/OpenPageNewWin' }); - }) - Button('ManageLocPerms') - .onClick(() => { - router.pushUrl({ url: 'pages/ManageLocPerms' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('DarkMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/DarkMode_one' }); + }) + Button('DarkMode_two') + .onClick(() => { + router.pushUrl({ url: 'pages/DarkMode_two' }); + }) + Button('AllowGeolocation') + .onClick(() => { + router.pushUrl({ url: 'pages/AllowGeolocation' }); + }) + Button('ClearAllCookiesSync') + .onClick(() => { + router.pushUrl({ url: 'pages/ClearAllCookiesSync' }); + }) + Button('ConfigCookieSync') + .onClick(() => { + router.pushUrl({ url: 'pages/ConfigCookieSync' }); + }) + Button('DeleteAllData') + .onClick(() => { + router.pushUrl({ url: 'pages/DeleteAllData' }); + }) + Button('DeleteGeolocation') + .onClick(() => { + router.pushUrl({ url: 'pages/DeleteGeolocation' }); + }) + Button('ExistCookie') + .onClick(() => { + router.pushUrl({ url: 'pages/ExistCookie' }); + }) + Button('FetchCookieSync') + .onClick(() => { + router.pushUrl({ url: 'pages/FetchCookieSync' }); + }) + Button('GetAccessibleGeolocation') + .onClick(() => { + router.pushUrl({ url: 'pages/GetAccessibleGeolocation' }); + }) + Button('IncognitoMode_one') + .onClick(() => { + router.pushUrl({ url: 'pages/IncognitoMode_one' }); + }) + Button('IncognitoMode_two') + .onClick(() => { + router.pushUrl({ url: 'pages/IncognitoMode_two' }); + }) + Button('OpenPageNewWin') + .onClick(() => { + router.pushUrl({ url: 'pages/OpenPageNewWin' }); + }) + Button('ManageLocPerms') + .onClick(() => { + router.pushUrl({ url: 'pages/ManageLocPerms' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets old mode 100755 new mode 100644 index 4c1a0eff1d2b763710abb8ecdb37d1a1362aa150..a0076820b5d22e7f9257d81d4341e320480477bf --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/ManageLocPerms.ets @@ -1,70 +1,70 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { abilityAccessCtrl, common } from '@kit.AbilityKit'; - -let context = getContext(this) as common.UIAbilityContext; -let atManager = abilityAccessCtrl.createAtManager(); - -// 向用户请求位置权限设置。 -atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION']).then((data) => { - console.info('data:' + JSON.stringify(data)); - console.info('data permissions:' + data.permissions); - console.info('data authResults:' + data.authResults); -}).catch((error: BusinessError) => { - console.error(`Failed to request permissions from user. Code is ${error.code}, message is ${error.message}`); -}) - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: $rawfile('getLocation.html'), controller: this.controller }) - .geolocationAccess(true) - .onGeolocationShow((event) => { // 地理位置权限申请通知 - AlertDialog.show({ - title: 'Location permission requests', - message: 'Whether to allow access to location information', - primaryButton: { - value: 'cancel', - action: () => { - if (event) { - event.geolocation.invoke(event.origin, false, false); // 不允许此站点地理位置权限请求 - } - } - }, - secondaryButton: { - value: 'ok', - action: () => { - if (event) { - event.geolocation.invoke(event.origin, true, false); // 允许此站点地理位置权限请求 - } - } - }, - cancel: () => { - if (event) { - event.geolocation.invoke(event.origin, false, false); // 不允许此站点地理位置权限请求 - } - } - }) - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { abilityAccessCtrl, common } from '@kit.AbilityKit'; + +let context = getContext(this) as common.UIAbilityContext; +let atManager = abilityAccessCtrl.createAtManager(); + +// 向用户请求位置权限设置。 +atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION']).then((data) => { + console.info('data:' + JSON.stringify(data)); + console.info('data permissions:' + data.permissions); + console.info('data authResults:' + data.authResults); +}).catch((error: BusinessError) => { + console.error(`Failed to request permissions from user. Code is ${error.code}, message is ${error.message}`); +}) + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: $rawfile('getLocation.html'), controller: this.controller }) + .geolocationAccess(true) + .onGeolocationShow((event) => { // 地理位置权限申请通知 + AlertDialog.show({ + title: 'Location permission requests', + message: 'Whether to allow access to location information', + primaryButton: { + value: 'cancel', + action: () => { + if (event) { + event.geolocation.invoke(event.origin, false, false); // 不允许此站点地理位置权限请求 + } + } + }, + secondaryButton: { + value: 'ok', + action: () => { + if (event) { + event.geolocation.invoke(event.origin, true, false); // 允许此站点地理位置权限请求 + } + } + }, + cancel: () => { + if (event) { + event.geolocation.invoke(event.origin, false, false); // 不允许此站点地理位置权限请求 + } + } + }) + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets old mode 100755 new mode 100644 index 1d0c7137f85fb0ccf0367934b9bb3a15b8b03b7c..4d1f828aa02ab9448d0dc1ef49d3e441f723a1a9 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/ets/pages/OpenPageNewWin.ets @@ -1,68 +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 { webview } from '@kit.ArkWeb'; - -// 在同一page页有两个Web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。 -@CustomDialog -struct NewWebViewComp { - controller?: CustomDialogController; - webviewController1: webview.WebviewController = new webview.WebviewController(); - - build() { - Column() { - Web({ src: '', controller: this.webviewController1 }) - .javaScriptAccess(true) - .multiWindowAccess(false) - .onWindowExit(() => { - console.info('NewWebViewComp onWindowExit'); - if (this.controller) { - this.controller.close(); - } - }) - } - } -} - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - dialogController: CustomDialogController | null = null; - - build() { - Column() { - Web({ src: $rawfile('window.html'), controller: this.controller }) - .javaScriptAccess(true) - // 需要使能multiWindowAccess - .multiWindowAccess(true) - .allowWindowOpenMethod(true) - .onWindowNew((event) => { - if (this.dialogController) { - this.dialogController.close(); - } - let popController: webview.WebviewController = new webview.WebviewController(); - this.dialogController = new CustomDialogController({ - builder: NewWebViewComp({ webviewController1: popController }) - }); - this.dialogController.open(); - // 将新窗口对应WebviewController返回给Web内核。 - // 如果不需要打开新窗口请调用event.handler.setWebController接口设置成null。 - // 若不调用event.handler.setWebController接口,会造成render进程阻塞。 - event.handler.setWebController(popController); - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +// 在同一page页有两个Web组件。在WebComponent新开窗口时,会跳转到NewWebViewComp。 +@CustomDialog +struct NewWebViewComp { + controller?: CustomDialogController; + webviewController1: webview.WebviewController = new webview.WebviewController(); + + build() { + Column() { + Web({ src: '', controller: this.webviewController1 }) + .javaScriptAccess(true) + .multiWindowAccess(false) + .onWindowExit(() => { + console.info('NewWebViewComp onWindowExit'); + if (this.controller) { + this.controller.close(); + } + }) + } + } +} + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + dialogController: CustomDialogController | null = null; + + build() { + Column() { + Web({ src: $rawfile('window.html'), controller: this.controller }) + .javaScriptAccess(true) + // 需要使能multiWindowAccess + .multiWindowAccess(true) + .allowWindowOpenMethod(true) + .onWindowNew((event) => { + if (this.dialogController) { + this.dialogController.close(); + } + let popController: webview.WebviewController = new webview.WebviewController(); + this.dialogController = new CustomDialogController({ + builder: NewWebViewComp({ webviewController1: popController }) + }); + this.dialogController.open(); + // 将新窗口对应WebviewController返回给Web内核。 + // 如果不需要打开新窗口请调用event.handler.setWebController接口设置成null。 + // 若不调用event.handler.setWebController接口,会造成render进程阻塞。 + event.handler.setWebController(popController); + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 old mode 100755 new mode 100644 index 2978d8982a7379485f334ba1e14a5608b910dd87..394d2a4703ff31b1662e4f09fba46876e701c984 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/module.json5 @@ -1,98 +1,98 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - }, - { - "name" : "ohos.permission.LOCATION", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - } - }, - { - "name" : "ohos.permission.APPROXIMATELY_LOCATION", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - } - }, - { - "name" : "ohos.permission.LOCATION_IN_BACKGROUND", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - } - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name" : "ohos.permission.LOCATION", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + } + }, + { + "name" : "ohos.permission.APPROXIMATELY_LOCATION", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + } + }, + { + "name" : "ohos.permission.LOCATION_IN_BACKGROUND", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html old mode 100755 new mode 100644 index e075d76ba4aa25252a63b28389b6b0e9802fa546..43497f5df3fabd7205aa28942e6dc63e24892b4a --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/darkModePage.html @@ -1,35 +1,35 @@ - - - - - - - - - -
-

Dark mode debug page

-
- + + + + + + + + + +
+

Dark mode debug page

+
+ \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html old mode 100755 new mode 100644 index d67a1ca9b33c531e68773e4f3378c2578c3d6e4e..4ae442f92a0e6145b5979fd8f571722c6ca83d10 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/getLocation.html @@ -1,34 +1,34 @@ - - - - - -

位置信息

- - - - + + + + + +

位置信息

+ + + + diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 077a0a6b74d8bae67c41416ac22eca6105bf05aa..25c6d7f99692719d79c63898f8bb68a9e8e6d9cc --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/index.html @@ -1,55 +1,55 @@ - - - - - - - test - - - -
状态信息
- - + + + + + + + test + + + +
状态信息
+ + diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html old mode 100755 new mode 100644 index ff3a612e76790c3ef735a90e926ccaac87581a4a..e1a15e6a52b74bd26ba93ef26e4da665427aadec --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/rawfile/window.html @@ -1,34 +1,34 @@ - - - - - - - WindowEvent - - - - - + + + + + + + WindowEvent + + + + + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/AllowGeolocation.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ClearAllCookiesSync.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ConfigCookieSync.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DarkMode_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteAllData.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/DeleteGeolocation.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ExistCookie.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/FetchCookieSync.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/GetAccessibleGeolocation.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/IncognitoMode_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/ManageLocPerms_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsOne/screenshots/OpenPageNewWin_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 old mode 100755 new mode 100644 index 23063cfa6ea209d308fc068f45b19c91456ebd6f..31ec642dd4cac388ed77191691e319de60e07db4 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/app.json5 @@ -1,25 +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.setbasicsttrsrvtstwo", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.setbasicsttrsrvtstwo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 67e05c262ae49c9cd0085e97c6f314f8c3429f04..4f29f2384417aa862af49ba47c6479c7830b8573 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SetBasicAttrsEvtsTwo" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SetBasicAttrsEvtsTwo" + } + ] +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Cache_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/CookieManagement.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/DomStorage.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 027763ceb64c82a6515c543917047fa40da07472..e5fb4c112b7bb8fcac763cdee5dadeba13f4266b --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/Index.ets @@ -1,58 +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. - */ - -import { router } from '@kit.ArkUI' - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('UserAgent_one') - .onClick(() => { - router.pushUrl({ url: 'pages/UserAgent_one' }); - }) - Button('UserAgent_two') - .onClick(() => { - router.pushUrl({ url: 'pages/UserAgent_two' }); - }) - Button('UserAgent_three') - .onClick(() => { - router.pushUrl({ url: 'pages/UserAgent_three' }); - }) - Button('CookieManagement') - .onClick(() => { - router.pushUrl({ url: 'pages/CookieManagement' }); - }) - Button('Cache_one') - .onClick(() => { - router.pushUrl({ url: 'pages/Cache_one' }); - }) - Button('Cache_two') - .onClick(() => { - router.pushUrl({ url: 'pages/Cache_two' }); - }) - Button('DomStorage') - .onClick(() => { - router.pushUrl({ url: 'pages/DomStorage' }); - }) - Button('UseMotionDirSensor') - .onClick(() => { - router.pushUrl({ url: 'pages/UseMotionDirSensor' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI' + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('UserAgent_one') + .onClick(() => { + router.pushUrl({ url: 'pages/UserAgent_one' }); + }) + Button('UserAgent_two') + .onClick(() => { + router.pushUrl({ url: 'pages/UserAgent_two' }); + }) + Button('UserAgent_three') + .onClick(() => { + router.pushUrl({ url: 'pages/UserAgent_three' }); + }) + Button('CookieManagement') + .onClick(() => { + router.pushUrl({ url: 'pages/CookieManagement' }); + }) + Button('Cache_one') + .onClick(() => { + router.pushUrl({ url: 'pages/Cache_one' }); + }) + Button('Cache_two') + .onClick(() => { + router.pushUrl({ url: 'pages/Cache_two' }); + }) + Button('DomStorage') + .onClick(() => { + router.pushUrl({ url: 'pages/DomStorage' }); + }) + Button('UseMotionDirSensor') + .onClick(() => { + router.pushUrl({ url: 'pages/UseMotionDirSensor' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets old mode 100755 new mode 100644 index f0c847ef6f63c0ca36017cc3c5f31b22ba5b0dcb..be61edc2190d5cae9dad81532a640946a973c998 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UseMotionDirSensor.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; -import { abilityAccessCtrl, PermissionRequestResult } from '@kit.AbilityKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct WebComponent { - controller: webview.WebviewController = new webview.WebviewController(); - aboutToAppear() { - // 配置Web开启调试模式 - webview.WebviewController.setWebDebuggingAccess(true); - // 访问控制管理, 获取访问控制模块对象。 - let atManager = abilityAccessCtrl.createAtManager(); - try { - atManager.requestPermissionsFromUser(getContext(this) - , ['ohos.permission.ACCELEROMETER', 'ohos.permission.GYROSCOPE'] - , (err: BusinessError, data: PermissionRequestResult) => { - console.info('data:' + JSON.stringify(data)); - console.info('data permissions:' + data.permissions); - console.info('data authResults:' + data.authResults); - }) - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - } - - build() { - Column() { - Web({ src: $rawfile('index.html'), controller: this.controller }) - .onPermissionRequest((event) => { - if (event) { - AlertDialog.show({ - title: 'title', - message: 'text', - primaryButton: { - value: 'deny', - action: () => { - event.request.deny(); - } - }, - secondaryButton: { - value: 'onConfirm', - action: () => { - event.request.grant(event.request.getAccessibleResource()); - } - }, - autoCancel: false, - cancel: () => { - event.request.deny(); - } - }) - } - }) - } - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; +import { abilityAccessCtrl, PermissionRequestResult } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct WebComponent { + controller: webview.WebviewController = new webview.WebviewController(); + aboutToAppear() { + // 配置Web开启调试模式 + webview.WebviewController.setWebDebuggingAccess(true); + // 访问控制管理, 获取访问控制模块对象。 + let atManager = abilityAccessCtrl.createAtManager(); + try { + atManager.requestPermissionsFromUser(getContext(this) + , ['ohos.permission.ACCELEROMETER', 'ohos.permission.GYROSCOPE'] + , (err: BusinessError, data: PermissionRequestResult) => { + console.info('data:' + JSON.stringify(data)); + console.info('data permissions:' + data.permissions); + console.info('data authResults:' + data.authResults); + }) + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + } + + build() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onPermissionRequest((event) => { + if (event) { + AlertDialog.show({ + title: 'title', + message: 'text', + primaryButton: { + value: 'deny', + action: () => { + event.request.deny(); + } + }, + secondaryButton: { + value: 'onConfirm', + action: () => { + event.request.grant(event.request.getAccessibleResource()); + } + }, + autoCancel: false, + cancel: () => { + event.request.deny(); + } + }) + } + }) + } + } +} diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_three.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/ets/pages/UserAgent_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 old mode 100755 new mode 100644 index 3e9e30c87ccd2e805632b79f4426344551a29d6c..ce51215daecfe9adc4e20d5c2e8ffdc2941d07a8 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/module.json5 @@ -1,77 +1,77 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - }, - { - "name" : "ohos.permission.ACCELEROMETER" // 加速度权限 - }, - { - "name" : "ohos.permission.GYROSCOPE" // 陀螺仪权限 - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + }, + { + "name" : "ohos.permission.ACCELEROMETER" // 加速度权限 + }, + { + "name" : "ohos.permission.GYROSCOPE" // 陀螺仪权限 + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 014f7fad0fb152053e66a741678cae0c48df1176..fea52d652492c9a1a9e650add17bc74d43b82e03 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/rawfile/index.html @@ -1,154 +1,154 @@ - - - - - - - - - - - 运动和方向传感器 - - - - - -
-

运动和方向:

-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
- - + + + + + + + + + + + 运动和方向传感器 + + + + + +
+

运动和方向:

+
    +
  • +
  • +
  • +
  • +
  • +
  • +
+
+ + diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 +++ b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/Cache_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/CookieManagement.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/DomStorage.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UseMotionDirSensor_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_three.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png b/code/DocsSample/ArkWeb/SetBasicAttrsEvts/SetBasicAttrsEvtsTwo/screenshots/UserAgent_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/.gitignore b/code/DocsSample/ArkWeb/UseFrontendJSApp/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/app.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/app.json5 old mode 100755 new mode 100644 index 68bbfe1e1488137396228accf1d7f01bb5e191f4..fb2771a6d1ebbcd7b796d98179f3dddaac3c9efd --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/app.json5 @@ -1,25 +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.usefrontendjsapp", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.usefrontendjsapp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 3aba7e3f9126485f3865141d03e1ddfa73972adb..d98b87fae58bdc64df1c8a60281d29644dff9f00 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UseFrontendJSApp" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UseFrontendJSApp" + } + ] +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/README.md b/code/DocsSample/ArkWeb/UseFrontendJSApp/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/build-profile.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/build-profile.json5 old mode 100755 new mode 100644 index 44608d7953b2076c8ffe90cf0383afaed0717076..e1f2fec7b0fcded64fac2357e096b7b761c6229f --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/build-profile.json5 @@ -1,100 +1,100 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry2", - "srcPath": "./entry2", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry3", - "srcPath": "./entry3", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry4", - "srcPath": "./entry4", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry5", - "srcPath": "./entry5", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry3", + "srcPath": "./entry3", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry4", + "srcPath": "./entry4", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry5", + "srcPath": "./entry5", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/code-linter.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/.gitignore b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b865efd626c466d6a334efc1e8111c6e88807a82..82e98bec44d83d2df03deb52508045cb06cc8604 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 7aaec79f5a28d765725aede370d8344f3839638c..29feaca7669174be5c2b0e2366529ee94ab7e726 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 7f1578abee9d30de4b7402140bd360158b8ed2ee..3db83981023a1e30aa99b51b7c0ac4be7ebf2bda --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/rawfile/index.html @@ -1,39 +1,39 @@ - - - - - - - -

这是一个测试信息,默认字体为黑色,调用runJavaScript方法后字体为绿色,调用runJavaScriptCodePassed方法后字体为红色

- - - + + + + + + + +

这是一个测试信息,默认字体为黑色,调用runJavaScript方法后字体为绿色,调用runJavaScriptCodePassed方法后字体为红色

+ + + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/UseFrontendJSApp/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/.gitignore b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/hvigorfile.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 old mode 100755 new mode 100644 index bcb70ff878510fb523d011c47eb563dc4edbd9ea..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets old mode 100755 new mode 100644 index cf7edaa3ca7fb433ec4145438a5c4a3791e13c31..dab8f3ea7260551b9dc6606eb397e396d241e701 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -1,56 +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 Entry2Ability 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'); - } -} +/* + * 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 Entry2Ability 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/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets old mode 100755 new mode 100644 index 8e31827bb912ef1730fe85734e2fc0a2a4eb8af1..213e60d6187ea841335f6263f3072b8e1c20e395 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets @@ -1,27 +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 Entry2BackupAbility 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)); - } +/* + * 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 Entry2BackupAbility 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/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index f1c2b9b420acc5720dacb8d2d43543920350a35c..730f850ab03976dfd6e0c92ad1dffdeacf6cad03 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Index.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('JavaScriptProxy') - .onClick(() => { - router.pushUrl({ url: 'pages/JavaScriptProxy' }); - }) - Button('Promise_one') - .onClick(() => { - router.pushUrl({ url: 'pages/Promise_one' }); - }) - Button('Promise_two') - .onClick(() => { - router.pushUrl({ url: 'pages/Promise_two' }); - }) - Button('RegisterJavaScriptProxy') - .onClick(() => { - router.pushUrl({ url: 'pages/RegisterJavaScriptProxy' }); - }) - Button('UsageOfComplexTypes_one') - .onClick(() => { - router.pushUrl({ url: 'pages/UsageOfComplexTypes_one' }); - }) - Button('UsageOfComplexTypes_two') - .onClick(() => { - router.pushUrl({ url: 'pages/UsageOfComplexTypes_two' }); - }) - Button('UsageOfComplexTypes_three') - .onClick(() => { - router.pushUrl({ url: 'pages/UsageOfComplexTypes_three' }); - }) - Button('UsageOfComplexTypes_four') - .onClick(() => { - router.pushUrl({ url: 'pages/UsageOfComplexTypes_four' }); - }) - Button('UsageOfComplexTypes_five') - .onClick(() => { - router.pushUrl({ url: 'pages/UsageOfComplexTypes_five' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('JavaScriptProxy') + .onClick(() => { + router.pushUrl({ url: 'pages/JavaScriptProxy' }); + }) + Button('Promise_one') + .onClick(() => { + router.pushUrl({ url: 'pages/Promise_one' }); + }) + Button('Promise_two') + .onClick(() => { + router.pushUrl({ url: 'pages/Promise_two' }); + }) + Button('RegisterJavaScriptProxy') + .onClick(() => { + router.pushUrl({ url: 'pages/RegisterJavaScriptProxy' }); + }) + Button('UsageOfComplexTypes_one') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_one' }); + }) + Button('UsageOfComplexTypes_two') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_two' }); + }) + Button('UsageOfComplexTypes_three') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_three' }); + }) + Button('UsageOfComplexTypes_four') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_four' }); + }) + Button('UsageOfComplexTypes_five') + .onClick(() => { + router.pushUrl({ url: 'pages/UsageOfComplexTypes_five' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/JavaScriptProxy.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/Promise_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/RegisterJavaScriptProxy.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_five.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_four.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_three.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/ets/pages/UsageOfComplexTypes_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 old mode 100755 new mode 100644 index b171fdbc82e9e1d2c1e9ba4542c157ce3f18848e..90a4604809422135bc23f5a1d55f88ba15ad078d --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/module.json5 @@ -1,70 +1,70 @@ -/* - * 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": "entry2", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "Entry2Ability", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry2Ability", - "srcEntry": "./ets/entry2ability/Entry2Ability.ets", - "description": "$string:Entry2Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry2Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "Entry2BackupAbility", - "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry2", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry2BackupAbility", + "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html old mode 100755 new mode 100644 index 3958298a5b267b58c41f5da25411eddedd0e926c..f191e18ba4a95fff3e0c00a06b8efc58042bed0e --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index1.html @@ -1,29 +1,29 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html old mode 100755 new mode 100644 index 48629c468857e9772e0b9689bc895dde823b01b7..7ce3b4e0f6e7224d2d374d758218d12762074285 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index2.html @@ -1,27 +1,27 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html old mode 100755 new mode 100644 index 962d597f49ce51fc56c144cbebbc2f0d4b6a590c..e8d5f8a4bc6bb2a5e7c71dd1755b2163640762d4 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index3.html @@ -1,30 +1,30 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html old mode 100755 new mode 100644 index 3958298a5b267b58c41f5da25411eddedd0e926c..f191e18ba4a95fff3e0c00a06b8efc58042bed0e --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index4.html @@ -1,29 +1,29 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html old mode 100755 new mode 100644 index feaddcf9a7efd10a2c6fdb411132a9e239b31a30..39411f1290bcb77735a74018e21440838badf590 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index5.html @@ -1,27 +1,27 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html old mode 100755 new mode 100644 index 3757d69e80a0d43f26c47862e7f0d5d12a45d785..139cccc5c8e66579033566092b69e28f256fc329 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index6.html @@ -1,51 +1,51 @@ - - - - - - -

- - - + + + + + + +

+ + + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html old mode 100755 new mode 100644 index 2fc570446f14c02384ad942794b4b8951879ce10..a40f4ca5f942a89dd8b4fc5867302f142e3c53dd --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index7.html @@ -1,27 +1,27 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html old mode 100755 new mode 100644 index d22db3ddf488077b44d9a3de1211188058e039aa..b7092a6123176ec10e701a02f16b038a80db4fc3 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index8.html @@ -1,27 +1,27 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html old mode 100755 new mode 100644 index 2fc570446f14c02384ad942794b4b8951879ce10..a40f4ca5f942a89dd8b4fc5867302f142e3c53dd --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/main/resources/rawfile/index9.html @@ -1,27 +1,27 @@ - - - - - - -

- - + + + + + + +

+ + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 old mode 100755 new mode 100644 index f877d50cb78d8e6ec5caf058ff23e3b46a25ba86..17410acb16bcc114982071879ee6b1f000794e19 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry2_test", - "type": "feature", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/.gitignore b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/hvigorfile.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 old mode 100755 new mode 100644 index 401ea2ff2de9d5a85b272557fd72f6d8e2d9440d..655d244a4ec5c8e387d7ebfb66967132c8c952f6 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry3", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry3", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets old mode 100755 new mode 100644 index c34db223b28875b88c86f52f32cd2b39814a0b82..e62e0723b2780a459f90447d95ff110ba058fc00 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -1,56 +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 Entry3Ability 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'); - } -} +/* + * 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 Entry3Ability 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/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 old mode 100755 new mode 100644 index f7927bcf5c53658327ae71bdfac9e1be3a1a4d53..a9345ab1e0f0dbf59e896cd74d2ced8094e7fb9b --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "entry3", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry3Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry3Ability", - "srcEntry": "./ets/entry3ability/Entry3Ability.ets", - "description": "$string:Entry3Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry3Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "entry3", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry3Ability", + "srcEntry": "./ets/entry3ability/Entry3Ability.ets", + "description": "$string:Entry3Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry3Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 3cb37326b7ff4b9c0fecf94d7cef2a0c3032010a..7e67007432b4e000fab6254a4fd81bd071066193 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/main/resources/rawfile/index.html @@ -1,69 +1,69 @@ - - - - - - - WebView Message Port Demo - - -

WebView Message Port Demo

-
- -
-
-

display received message send from ets

- - - + + + + + + + WebView Message Port Demo + + +

WebView Message Port Demo

+
+ +
+
+

display received message send from ets

+ + + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9fec93324fb8655cf1fac5683305c468a26c135e..edaba8aaabfc3819914b5d624d6d0143e85b5b86 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/ohosTest/module.json5 @@ -1,27 +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": "entry3_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry3/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/.gitignore b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 old mode 100755 new mode 100644 index 21cff554210e7ead0baebebb58a5da1a84dd5fd8..471250ade0685f26d9ed6c8fb7761e0f0882c8ec --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/build-profile.json5 @@ -1,55 +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", "armeabi-v7a"] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", "armeabi-v7a"] + } + }, + "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/ArkWeb/UseFrontendJSApp/entry4/hvigorfile.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 old mode 100755 new mode 100644 index 894d9a4f4797dbd15407b8bcc22009131c59db8b..00f4289f03ded4fc5b05708a28cd06c44a0ad53e --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/oh-package.json5 @@ -1,26 +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": "entry4", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libentry4.so": "file:./src/main/cpp/types/libentry4" - } +/* + * 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": "entry4", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry4.so": "file:./src/main/cpp/types/libentry4" + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 4fe97190795e36d34750a8c6475262ffd8827cd8..14607faba853fe717a19495cfc2364bc8be66216 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/CMakeLists.txt @@ -1,24 +1,24 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(NDKJSBridg) - -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 hello.cpp jsbridge_object.cpp) - -find_library( - # Sets the name of the path variable. - hilog-lib - # Specifies the name of the NDK library that - # you want CMake to locate. - hilog_ndk.z -) - +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(NDKJSBridg) + +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 hello.cpp jsbridge_object.cpp) + +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + target_link_libraries(entry PUBLIC libace_napi.z.so ${hilog-lib} libohweb.so) \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp old mode 100755 new mode 100644 index aace11b1984527131f05ff8bd145d11b142e8e88..aac8d869f54fb2f48535bfd582cb3697eb12f9bf --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/hello.cpp @@ -1,319 +1,319 @@ -/* - * 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 -#include -#include -#include -#include - -#include "hilog/log.h" -#include "web/arkweb_interface.h" -#include "jsbridge_object.h" - -constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; -std::shared_ptr jsbridge_object_ptr = nullptr; -static ArkWeb_ControllerAPI *controller = nullptr; -static ArkWeb_ComponentAPI *component = nullptr; - -// 发送JS脚本到H5侧执行,该方法为执行结果的回调。 -static void RunJavaScriptCallback(const char *webTag, const char *result, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit RunJavaScriptCallback webTag:%{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit RunJavaScriptCallback userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->RunJavaScriptCallback(result); - } else { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit RunJavaScriptCallback jsb_weak_ptr lock failed"); - } -} - -// 示例代码 ,注册了1个对象,2个方法 -static void ProxyMethod1( - const char *webTag, const ArkWeb_JavaScriptBridgeData *dataArray, size_t arraySize, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ProxyMethod1 webTag:%{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ProxyMethod1 userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->ProxyMethod1(dataArray, arraySize); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ProxyMethod1 jsb_weak_ptr lock failed"); - } -} - -static void ProxyMethod2( - const char *webTag, const ArkWeb_JavaScriptBridgeData *dataArray, size_t arraySize, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ProxyMethod2 webTag:%{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ProxyMethod2 userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - - std::string jsCode = "runJSRetStr()"; - ArkWeb_JavaScriptObject object = { - (uint8_t *)jsCode.c_str(), jsCode.size(), - &JSBridgeObject::StaticRunJavaScriptCallback, - static_cast(jsbridge_object_ptr->GetWeakPtr()) - }; - controller->runJavaScript(webTag, &object); - - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->ProxyMethod2(dataArray, arraySize); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ProxyMethod2 JsWeakPtr lock failed"); - } -} - -void ValidCallback(const char *webTag, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ValidCallback webTag: %{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ValidCallback userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->SaySomething("ValidCallback"); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit ValidCallback jsb_weak_ptr lock failed"); - } - - // 注册对象 - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit RegisterJavaScriptProxy begin"); - ArkWeb_ProxyMethod method1 = {"method1", ProxyMethod1, static_cast(jsbridge_object_ptr->GetWeakPtr())}; - ArkWeb_ProxyMethod method2 = {"method2", ProxyMethod2, static_cast(jsbridge_object_ptr->GetWeakPtr())}; - ArkWeb_ProxyMethod methodList[2] = {method1, method2}; - // 调用Native Development Kit接口注册对象 - // 如此注册的情况下,在H5页面就可以使用proxy.method1、proxy.method1调用此文件下的ProxyMethod1和ProxyMethod2方法了 - ArkWeb_ProxyObject proxyObject = {"ndkProxy", methodList, 2}; - controller->registerJavaScriptProxy(webTag, &proxyObject); - - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit RegisterJavaScriptProxy end"); -} - -void LoadStartCallback(const char *webTag, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit LoadStartCallback webTag: %{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit LoadStartCallback userData is null"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->SaySomething("LoadStartCallback"); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, - "ArkWeb", "Native Development Kit LoadStartCallback jsb_weak_ptr lock failed"); - } -} - -void LoadEndCallback(const char *webTag, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit LoadEndCallback webTag: %{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit LoadEndCallback userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->SaySomething("LoadEndCallback"); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit LoadEndCallback jsb_weak_ptr lock failed"); - } -} - -void DestroyCallback(const char *webTag, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit DestoryCallback webTag: %{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit DestroyCallback userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - jsb_ptr->SaySomething("DestroyCallback"); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit DestroyCallback jsb_weak_ptr lock failed"); - } -} - -void SetComponentCallback(ArkWeb_ComponentAPI * component, const char* webTagValue) -{ - if (!ARKWEB_MEMBER_MISSING(component, onControllerAttached)) { - component->onControllerAttached( - webTagValue, ValidCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); - } else { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onControllerAttached func not exist"); - } - - if (!ARKWEB_MEMBER_MISSING(component, onPageBegin)) { - component->onPageBegin(webTagValue, LoadStartCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); - } else { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onPageBegin func not exist"); - } - - if (!ARKWEB_MEMBER_MISSING(component, onPageEnd)) { - component->onPageEnd(webTagValue, LoadEndCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); - } else { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onPageEnd func not exist"); - } - - if (!ARKWEB_MEMBER_MISSING(component, onDestroy)) { - component->onDestroy(webTagValue, DestroyCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); - } else { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onDestroy func not exist"); - } -} - -// 解析存储webTag -static napi_value NativeWebInit(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit start"); - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit NativeWebInit webTag:%{public}s", webTagValue); - - // 将webTag保存在实例对象中 - jsbridge_object_ptr = std::make_shared(webTagValue); - if (jsbridge_object_ptr) - jsbridge_object_ptr->Init(); - - controller = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_CONTROLLER)); - component = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_COMPONENT)); - SetComponentCallback(component, webTagValue); - - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit end"); - return nullptr; -} - -// 发送JS脚本到H5侧执行 -static napi_value RunJavaScript(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit OH_NativeArkWeb_RunJavaScript webTag:%{public}s", webTagValue); - - // 获取第二个参数 jsCode - size_t bufferSize = 0; - napi_get_value_string_utf8(env, args[1], nullptr, 0, &bufferSize); - char *jsCode = new (std::nothrow) char[bufferSize + 1]; - size_t byteLength = 0; - napi_get_value_string_utf8(env, args[1], jsCode, bufferSize + 1, &byteLength); - - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit OH_NativeArkWeb_RunJavaScript jsCode len:%{public}zu", strlen(jsCode)); - - // 构造runJS执行的结构体 - ArkWeb_JavaScriptObject object = {(uint8_t *)jsCode, bufferSize, &JSBridgeObject::StaticRunJavaScriptCallback, - static_cast(jsbridge_object_ptr->GetWeakPtr())}; - controller->runJavaScript(webTagValue, &object); - return nullptr; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"nativeWebInit", nullptr, NativeWebInit, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"runJavaScript", nullptr, RunJavaScript, 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); } +/* + * 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 +#include +#include +#include +#include + +#include "hilog/log.h" +#include "web/arkweb_interface.h" +#include "jsbridge_object.h" + +constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; +std::shared_ptr jsbridge_object_ptr = nullptr; +static ArkWeb_ControllerAPI *controller = nullptr; +static ArkWeb_ComponentAPI *component = nullptr; + +// 发送JS脚本到H5侧执行,该方法为执行结果的回调。 +static void RunJavaScriptCallback(const char *webTag, const char *result, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit RunJavaScriptCallback webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit RunJavaScriptCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->RunJavaScriptCallback(result); + } else { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit RunJavaScriptCallback jsb_weak_ptr lock failed"); + } +} + +// 示例代码 ,注册了1个对象,2个方法 +static void ProxyMethod1( + const char *webTag, const ArkWeb_JavaScriptBridgeData *dataArray, size_t arraySize, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod1 webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod1 userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->ProxyMethod1(dataArray, arraySize); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod1 jsb_weak_ptr lock failed"); + } +} + +static void ProxyMethod2( + const char *webTag, const ArkWeb_JavaScriptBridgeData *dataArray, size_t arraySize, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod2 webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod2 userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + + std::string jsCode = "runJSRetStr()"; + ArkWeb_JavaScriptObject object = { + (uint8_t *)jsCode.c_str(), jsCode.size(), + &JSBridgeObject::StaticRunJavaScriptCallback, + static_cast(jsbridge_object_ptr->GetWeakPtr()) + }; + controller->runJavaScript(webTag, &object); + + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->ProxyMethod2(dataArray, arraySize); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ProxyMethod2 JsWeakPtr lock failed"); + } +} + +void ValidCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ValidCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ValidCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("ValidCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit ValidCallback jsb_weak_ptr lock failed"); + } + + // 注册对象 + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit RegisterJavaScriptProxy begin"); + ArkWeb_ProxyMethod method1 = {"method1", ProxyMethod1, static_cast(jsbridge_object_ptr->GetWeakPtr())}; + ArkWeb_ProxyMethod method2 = {"method2", ProxyMethod2, static_cast(jsbridge_object_ptr->GetWeakPtr())}; + ArkWeb_ProxyMethod methodList[2] = {method1, method2}; + // 调用Native Development Kit接口注册对象 + // 如此注册的情况下,在H5页面就可以使用proxy.method1、proxy.method1调用此文件下的ProxyMethod1和ProxyMethod2方法了 + ArkWeb_ProxyObject proxyObject = {"ndkProxy", methodList, 2}; + controller->registerJavaScriptProxy(webTag, &proxyObject); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit RegisterJavaScriptProxy end"); +} + +void LoadStartCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadStartCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadStartCallback userData is null"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("LoadStartCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, + "ArkWeb", "Native Development Kit LoadStartCallback jsb_weak_ptr lock failed"); + } +} + +void LoadEndCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadEndCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadEndCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("LoadEndCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit LoadEndCallback jsb_weak_ptr lock failed"); + } +} + +void DestroyCallback(const char *webTag, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit DestoryCallback webTag: %{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit DestroyCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + jsb_ptr->SaySomething("DestroyCallback"); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit DestroyCallback jsb_weak_ptr lock failed"); + } +} + +void SetComponentCallback(ArkWeb_ComponentAPI * component, const char* webTagValue) +{ + if (!ARKWEB_MEMBER_MISSING(component, onControllerAttached)) { + component->onControllerAttached( + webTagValue, ValidCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onControllerAttached func not exist"); + } + + if (!ARKWEB_MEMBER_MISSING(component, onPageBegin)) { + component->onPageBegin(webTagValue, LoadStartCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onPageBegin func not exist"); + } + + if (!ARKWEB_MEMBER_MISSING(component, onPageEnd)) { + component->onPageEnd(webTagValue, LoadEndCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onPageEnd func not exist"); + } + + if (!ARKWEB_MEMBER_MISSING(component, onDestroy)) { + component->onDestroy(webTagValue, DestroyCallback, static_cast(jsbridge_object_ptr->GetWeakPtr())); + } else { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "component onDestroy func not exist"); + } +} + +// 解析存储webTag +static napi_value NativeWebInit(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit NativeWebInit webTag:%{public}s", webTagValue); + + // 将webTag保存在实例对象中 + jsbridge_object_ptr = std::make_shared(webTagValue); + if (jsbridge_object_ptr) + jsbridge_object_ptr->Init(); + + controller = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_CONTROLLER)); + component = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_COMPONENT)); + SetComponentCallback(component, webTagValue); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit end"); + return nullptr; +} + +// 发送JS脚本到H5侧执行 +static napi_value RunJavaScript(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit OH_NativeArkWeb_RunJavaScript webTag:%{public}s", webTagValue); + + // 获取第二个参数 jsCode + size_t bufferSize = 0; + napi_get_value_string_utf8(env, args[1], nullptr, 0, &bufferSize); + char *jsCode = new (std::nothrow) char[bufferSize + 1]; + size_t byteLength = 0; + napi_get_value_string_utf8(env, args[1], jsCode, bufferSize + 1, &byteLength); + + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit OH_NativeArkWeb_RunJavaScript jsCode len:%{public}zu", strlen(jsCode)); + + // 构造runJS执行的结构体 + ArkWeb_JavaScriptObject object = {(uint8_t *)jsCode, bufferSize, &JSBridgeObject::StaticRunJavaScriptCallback, + static_cast(jsbridge_object_ptr->GetWeakPtr())}; + controller->runJavaScript(webTagValue, &object); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"nativeWebInit", nullptr, NativeWebInit, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"runJavaScript", nullptr, RunJavaScript, 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/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp old mode 100755 new mode 100644 index ac82ae5673d171daf8a7b3fa13bcb338c6abca33..d132991da879d40528da3ea91879d2268ad05431 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.cpp @@ -1,88 +1,88 @@ -/* - * 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 "jsbridge_object.h" - -#include "hilog/log.h" - -constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; - -JSBridgeObject::JSBridgeObject(const char *webTag) : webTag_(webTag) {} - -void JSBridgeObject::Init() { weak_ptr_ = shared_from_this(); } - -std::weak_ptr *JSBridgeObject::GetWeakPtr() { return &weak_ptr_; } - -void JSBridgeObject::StaticRunJavaScriptCallback( - const char *webTag, const ArkWeb_JavaScriptBridgeData *data, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject StaticRunJavaScriptCallback webTag:%{public}s", webTag); - if (!userData) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject StaticRunJavaScriptCallback userData is nullptr"); - return; - } - std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); - if (auto jsb_ptr = jsb_weak_ptr.lock()) { - std::string result((char *)data->buffer, data->size); - jsb_ptr->RunJavaScriptCallback(result.c_str()); - } else { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject StaticRunJavaScriptCallback jsb_weak_ptr lock failed"); - } -} - -void JSBridgeObject::RunJavaScriptCallback(const char *result) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject OH_NativeArkWeb_RunJavaScript result:%{public}s", result); -} - -void JSBridgeObject::ProxyMethod1(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "JSBridgeObject ProxyMethod1 argc:%{public}d", - arraySize); - for (int i = 0; i < arraySize; i++) { - std::string result((char *)dataArray[i].buffer, dataArray[i].size); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject ProxyMethod1 argv[%{public}d]:%{public}s, size:%{public}d", - i, result.c_str(), dataArray[i].size); - } -} - -void JSBridgeObject::ProxyMethod2(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject ProxyMethod2 argc:%{public}d", arraySize); - for (int i = 0; i < arraySize; i++) { - std::string result((char *)dataArray[i].buffer, dataArray[i].size); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "JSBridgeObject ProxyMethod2 argv[%{public}d]:%{public}s, size:%{public}d", - i, result.c_str(), dataArray[i].size); - } -} - -void JSBridgeObject::SaySomething(const char *say) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "JSBridgeObject SaySomething argc:%{public}s", say); -} +/* + * 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 "jsbridge_object.h" + +#include "hilog/log.h" + +constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; + +JSBridgeObject::JSBridgeObject(const char *webTag) : webTag_(webTag) {} + +void JSBridgeObject::Init() { weak_ptr_ = shared_from_this(); } + +std::weak_ptr *JSBridgeObject::GetWeakPtr() { return &weak_ptr_; } + +void JSBridgeObject::StaticRunJavaScriptCallback( + const char *webTag, const ArkWeb_JavaScriptBridgeData *data, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject StaticRunJavaScriptCallback webTag:%{public}s", webTag); + if (!userData) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject StaticRunJavaScriptCallback userData is nullptr"); + return; + } + std::weak_ptr jsb_weak_ptr = *static_cast *>(userData); + if (auto jsb_ptr = jsb_weak_ptr.lock()) { + std::string result((char *)data->buffer, data->size); + jsb_ptr->RunJavaScriptCallback(result.c_str()); + } else { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject StaticRunJavaScriptCallback jsb_weak_ptr lock failed"); + } +} + +void JSBridgeObject::RunJavaScriptCallback(const char *result) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject OH_NativeArkWeb_RunJavaScript result:%{public}s", result); +} + +void JSBridgeObject::ProxyMethod1(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "JSBridgeObject ProxyMethod1 argc:%{public}d", + arraySize); + for (int i = 0; i < arraySize; i++) { + std::string result((char *)dataArray[i].buffer, dataArray[i].size); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject ProxyMethod1 argv[%{public}d]:%{public}s, size:%{public}d", + i, result.c_str(), dataArray[i].size); + } +} + +void JSBridgeObject::ProxyMethod2(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject ProxyMethod2 argc:%{public}d", arraySize); + for (int i = 0; i < arraySize; i++) { + std::string result((char *)dataArray[i].buffer, dataArray[i].size); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "JSBridgeObject ProxyMethod2 argv[%{public}d]:%{public}s, size:%{public}d", + i, result.c_str(), dataArray[i].size); + } +} + +void JSBridgeObject::SaySomething(const char *say) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "JSBridgeObject SaySomething argc:%{public}s", say); +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h old mode 100755 new mode 100644 index fdc9ba300ebc188a2cac2557bc65bcf40ab430a1..d54685f08e89eb33f8978d9966ea1c88f949ea8b --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/jsbridge_object.h @@ -1,39 +1,39 @@ -#ifndef HEADER_GUARD_H -#define HEADER_GUARD_H -/* - * 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 "web/arkweb_type.h" -#include - -class JSBridgeObject : public std::enable_shared_from_this { -public: - explicit JSBridgeObject(const char* webTag); - ~JSBridgeObject() = default; - void Init(); - std::weak_ptr* GetWeakPtr(); - static void StaticRunJavaScriptCallback(const char *webTag, const ArkWeb_JavaScriptBridgeData *data, - void *userData); - void RunJavaScriptCallback(const char *result); - void ProxyMethod1(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize); - void ProxyMethod2(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize); - void SaySomething(const char* say); - -private: - std::string webTag_; - std::weak_ptr weak_ptr_; -}; +#ifndef HEADER_GUARD_H +#define HEADER_GUARD_H +/* + * 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 "web/arkweb_type.h" +#include + +class JSBridgeObject : public std::enable_shared_from_this { +public: + explicit JSBridgeObject(const char* webTag); + ~JSBridgeObject() = default; + void Init(); + std::weak_ptr* GetWeakPtr(); + static void StaticRunJavaScriptCallback(const char *webTag, const ArkWeb_JavaScriptBridgeData *data, + void *userData); + void RunJavaScriptCallback(const char *result); + void ProxyMethod1(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize); + void ProxyMethod2(const ArkWeb_JavaScriptBridgeData *dataArray, int32_t arraySize); + void SaySomething(const char* say); + +private: + std::string webTag_; + std::weak_ptr weak_ptr_; +}; #endif // HEADER_GUARD_H \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 0deb1bb76fd2f0a203d2e8dc07e2e990783ea1ff..820107b7d23aac8e97b4f6ce2d6517ea2eea824b --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/napi_init.cpp @@ -1,67 +1,67 @@ -/* - * 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" - -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - - double value0; - napi_get_value_double(env, args[0], &value0); - - double value1; - napi_get_value_double(env, args[1], &value1); - - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - - return sum; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "add", nullptr, Add, 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); -} +/* + * 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" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, 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/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts old mode 100755 new mode 100644 index 9b96879e772bf9d29575bbf5176cfc0ab7596b94..b733d0cf26bbbb47b70d660dd7b5f38b0740dfd6 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/Index.d.ts @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const nativeWebInit: (webName: string) => void; -export const runJavaScript: (webName: string, jsCode: string) => void; +/* + * 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 nativeWebInit: (webName: string) => void; +export const runJavaScript: (webName: string, jsCode: string) => void; diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 old mode 100755 new mode 100644 index 3b5002fcabb4ae914b40d9bee603ce05fb0bf357..1228596cfe7eb84f89b7125abb95de5246a5829c --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/cpp/types/libentry4/oh-package.json5 @@ -1,21 +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": "libentry4.so", - "types": "./Index.d.ts", - "version": "1.0.0", - "description": "Please describe the basic information." +/* + * 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": "libentry4.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/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets old mode 100755 new mode 100644 index af4f86a3ab8327e474bce5697e1e70e1f552c0f9..84e3ab74f2a987f3a4cf9c6e380c5901b3491478 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/entry4ability/Entry4Ability.ets @@ -1,56 +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 Entry4Ability 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'); - } -}; +/* + * 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 Entry4Ability 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/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index bd898bac225fa43aea8abcaf9df4492b7163bbb1..24c18bcb51bf0049a84a795ee115f6375aa9548f --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/ets/pages/Index.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import testNapi from 'libentry.so'; -import { webview } from '@kit.ArkWeb'; - -class testObj { - constructor() { - } - - test(): string { - console.log('ArkUI Web Component'); - return 'ArkUI Web Component'; - } - - toString(): void { - console.log('Web Component toString'); - } -} - -@Entry -@Component -struct Index { - webTag: string = 'ArkWeb1'; - controller: webview.WebviewController = new webview.WebviewController(this.webTag); - @State testObjtest: testObj = new testObj(); - - aboutToAppear() { - console.info('aboutToAppear'); - //初始化web Native Development Kit - testNapi.nativeWebInit(this.webTag); - } - - build() { - Column() { - Row() { - Button('runJS hello') - .fontSize(12) - .onClick(() => { - testNapi.runJavaScript(this.webTag, 'runJSRetStr(\"" + "hello" + "\")'); - }) - }.height('20%') - - Row() { - Web({ src: $rawfile('runJS.html'), controller: this.controller }) - .javaScriptAccess(true) - .fileAccess(true) - .onControllerAttached(() => { - console.error('Native Development Kit onControllerAttached webId: ' + this.controller.getWebId()); - }) - }.height('80%') - } - } -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import testNapi from 'libentry.so'; +import { webview } from '@kit.ArkWeb'; + +class testObj { + constructor() { + } + + test(): string { + console.log('ArkUI Web Component'); + return 'ArkUI Web Component'; + } + + toString(): void { + console.log('Web Component toString'); + } +} + +@Entry +@Component +struct Index { + webTag: string = 'ArkWeb1'; + controller: webview.WebviewController = new webview.WebviewController(this.webTag); + @State testObjtest: testObj = new testObj(); + + aboutToAppear() { + console.info('aboutToAppear'); + //初始化web Native Development Kit + testNapi.nativeWebInit(this.webTag); + } + + build() { + Column() { + Row() { + Button('runJS hello') + .fontSize(12) + .onClick(() => { + testNapi.runJavaScript(this.webTag, 'runJSRetStr(\"" + "hello" + "\")'); + }) + }.height('20%') + + Row() { + Web({ src: $rawfile('runJS.html'), controller: this.controller }) + .javaScriptAccess(true) + .fileAccess(true) + .onControllerAttached(() => { + console.error('Native Development Kit onControllerAttached webId: ' + this.controller.getWebId()); + }) + }.height('80%') + } + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 old mode 100755 new mode 100644 index f98aa30d843342de1bb96c30a8883a9c801dd4c0..afa13b4ebdc29a9cb812bfbb16d66e97039a14e5 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "entry4", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry4Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry4Ability", - "srcEntry": "./ets/entry4ability/Entry4Ability.ets", - "description": "$string:Entry4Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry4Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "entry4", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry4Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry4Ability", + "srcEntry": "./ets/entry4ability/Entry4Ability.ets", + "description": "$string:Entry4Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry4Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html old mode 100755 new mode 100644 index 34c305147cc788b1409980ae122c9d3ab9ccf15d..a6ebe9e4665f309fd2ecbe9b256af033154bb055 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/main/resources/rawfile/runJS.html @@ -1,93 +1,93 @@ - - - - - - - - - run javascript demo - - -

run JavaScript Ext demo

-

-
- -
-
- -
- - - + + + + + + + + + run javascript demo + + +

run JavaScript Ext demo

+

+
+ +
+
+ +
+ + + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/mock/Libentry4.mock.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 4d2bdff32bae9e243494c6a024de6cb6cd102f6b..12ba91e94655586fb5e48c90b290e66be7e85db2 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/ohosTest/module.json5 @@ -1,27 +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": "entry4_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry4_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry4/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/.gitignore b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 old mode 100755 new mode 100644 index 21cff554210e7ead0baebebb58a5da1a84dd5fd8..471250ade0685f26d9ed6c8fb7761e0f0882c8ec --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/build-profile.json5 @@ -1,55 +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", "armeabi-v7a"] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", "armeabi-v7a"] + } + }, + "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/ArkWeb/UseFrontendJSApp/entry5/hvigorfile.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 old mode 100755 new mode 100644 index 15af4af3a328240684b20c344da90b0f336b9ee6..b58415e4585a7d2d30f02bba160d4401c9575b19 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/oh-package.json5 @@ -1,26 +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": "entry5", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": { - "libentry5.so": "file:./src/main/cpp/types/libentry5" - } +/* + * 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": "entry5", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry5.so": "file:./src/main/cpp/types/libentry5" + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index deaa05dd7adfc38de3dd26601f4bbd62432c7a76..46be202fc230d85a6eade7ed2cedec2ad189af17 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/CMakeLists.txt @@ -1,25 +1,25 @@ -# entry/src/main/cpp/CMakeLists.txt -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.4.1) -project(NDKPostMessage) - -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 hello.cpp) - -find_library( - # Sets the name of the path variable. - hilog-lib - # Specifies the name of the NDK library that - # you want CMake to locate. - hilog_ndk.z -) - -target_link_libraries(entry PUBLIC libace_napi.z.so ${hilog-lib} libohweb.so) +# entry/src/main/cpp/CMakeLists.txt +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(NDKPostMessage) + +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 hello.cpp) + +find_library( + # Sets the name of the path variable. + hilog-lib + # Specifies the name of the NDK library that + # you want CMake to locate. + hilog_ndk.z +) + +target_link_libraries(entry PUBLIC libace_napi.z.so ${hilog-lib} libohweb.so) diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp old mode 100755 new mode 100644 index e33e1bc0e3f9312d59ae811ac806f1516216d514..b1706d9634c01723929073b630e4185138aa170d --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/hello.cpp @@ -1,467 +1,467 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include "hilog/log.h" -#include "web/arkweb_interface.h" -#include - -constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; -ArkWeb_ControllerAPI *controller = nullptr; - -ArkWeb_WebMessagePortAPI *webMessagePort = nullptr; -ArkWeb_WebMessageAPI *webMessage = nullptr; -size_t g_webMessagePortSize = 0; -ArkWeb_WebMessagePortPtr *g_web_message_port_arr = nullptr; - -static void WebMessagePortCallback( - const char *webTag, const ArkWeb_WebMessagePortPtr port, const ArkWeb_WebMessagePtr message, void *userData) -{ - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit WebMesagePortCallback webTag:%{public}s,messageType:%{public}d", - webTag, webMessage->getType(message)); - size_t len = 0; - void *back = webMessage->getData(message, &len); - if (webMessage->getType(message) == ArkWeb_WebMessageType::ARKWEB_STRING) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit WebMesagePortCallback message:%{public}s,messageSize:%{public}d", back, len); - } else if (webMessage->getType(message) == ArkWeb_WebMessageType::ARKWEB_BUFFER) { - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit WebMesagePortCallback messageSize:%{public}d", len); - } -} - -static napi_value NativeWebInit(napi_env env, napi_callback_info info) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit start"); - size_t argc = 1; - napi_value args[1] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit NativeWebInit webTag:%{public}s", webTagValue); - - controller = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_CONTROLLER)); - if (controller) - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_ControllerAPI success"); - - webMessagePort = - reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_WEB_MESSAGE_PORT)); - if (webMessagePort) - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_WebMessagePortAPI success"); - - webMessage = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_WEB_MESSAGE)); - if (webMessage) - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_WebMessageAPI success"); - - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit end"); - - return nullptr; -} - -static napi_value createWebMessagePorts(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 初始化端口 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit createWebMessagePorts begin"); - g_web_message_port_arr = controller->createWebMessagePorts(webTagValue, &g_webMessagePortSize); - // 把其中一个端口发送给HTML - ArkWeb_ErrorCode code = - controller->postWebMessage(webTagValue, "init_web_messageport", g_web_message_port_arr, 1, "*"); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit postWebMessage ArkWeb_ErrorCode:%{public}d", code); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit createWebMessagePorts end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - -static napi_value postMessage(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 发送消息 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); - - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); - webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_STRING); - std::string str = "send string from native"; - webMessage->setData(message, (void *)str.c_str(), str.length() + 1); - ArkWeb_ErrorCode code = webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit postMessage ArkWeb_ErrorCode:%{public}d", code); - webMessage->destroyWebMessage(&message); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - - -// 在线程中发消息 -void sendMessage(const char *webTag, const ArkWeb_WebMessagePtr message) -{ - // 发送1000次 - for (int i = 0; i < 1000; i++) { - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "sendMessage in thread %{public}d", i); - if (g_web_message_port_arr && webTag && message) { - webMessagePort->postMessage(g_web_message_port_arr[1], webTag, message); - } - } -} -static napi_value postMessageThread(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 构造消息 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); - - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); - webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_STRING); - std::string str = "thread message"; - webMessage->setData(message, (void *)str.c_str(), str.length() + 1); - const int numThreads = 5; - std::thread threads[numThreads]; - - // 创建线程 - for (int i = 0; i < numThreads; ++i) { - threads[i] = std::thread(sendMessage, webTagValue, message); - } - - // 等待所有线程完成 - for (int i = 0; i < numThreads; ++i) { - threads[i].detach(); - } - return nullptr; -} - -// 在线程中注册回调 -void SetHandler(const char *webTag) -{ - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "setMessageEventHandler in thread"); - webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTag, WebMessagePortCallback, NULL); -} - -static napi_value setMessageEventHandlerThread(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 注册回调 - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit SetMessageEventHandler begin"); - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - std::thread thread(SetHandler, webTagValue); - thread.detach(); - webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTagValue, WebMessagePortCallback, NULL); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} -static napi_value postNoneMessage(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, - "ArkWeb", "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 发送消息 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit 发消息开始"); - - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); - webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_NONE); - std::string str = "send string from native"; - webMessage->setData(message, (void *)str.c_str(), str.length() + 1); - webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message); - webMessage->destroyWebMessage(&message); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - -static napi_value postBufferMessage(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 发送消息 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); - - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - ArkWeb_WebMessagePtr message1 = webMessage->createWebMessage(); - webMessage->setType(message1, ArkWeb_WebMessageType::ARKWEB_BUFFER); - std::string str1 = "send buffer from native"; - webMessage->setData(message1, (void *)str1.c_str(), str1.length()); - webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message1); - webMessage->destroyWebMessage(&message1); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - -static napi_value setMessageEventHandler(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 注册回调 - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTagValue, WebMessagePortCallback, NULL); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - -static napi_value closeMessagePort(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 关闭端口,先调用close,再调用destroyWebMessagePorts - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - webMessagePort->close(g_web_message_port_arr[0], webTagValue); - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); - controller->refresh(webTagValue); - return nullptr; -} - -static napi_value destroyMessagePort(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 释放内存,先调用close,再调用destroyWebMessagePorts - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); - if (g_web_message_port_arr == nullptr) { - OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); - return nullptr; - } - controller->destroyWebMessagePorts(&g_web_message_port_arr, g_webMessagePortSize); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - -static napi_value destroyNullMessagePort(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - // 获取第一个参数webTag - size_t webTagSize = 0; - napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); - char *webTagValue = new (std::nothrow) char[webTagSize + 1]; - size_t webTagLength = 0; - napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit Refresh webTag:%{public}s", webTagValue); - - // 释放内存,先调用close,再调用destroyWebMessagePorts - OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); - - controller->destroyWebMessagePorts(&g_web_message_port_arr, g_webMessagePortSize); - - OH_LOG_Print( - LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", - "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); - return nullptr; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"nativeWebInit", nullptr, NativeWebInit, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"createWebMessagePorts", nullptr, createWebMessagePorts, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"postMessage", nullptr, postMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"postNoneMessage", nullptr, postNoneMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"postBufferMessage", nullptr, postBufferMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"setMessageEventHandler", nullptr, setMessageEventHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"closeMessagePort", nullptr, closeMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"destroyMessagePort", nullptr, destroyMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"postMessageThread", nullptr, postMessageThread, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"setMessageEventHandlerThread", nullptr, setMessageEventHandlerThread, nullptr, nullptr, nullptr, - napi_default, nullptr}, - {"destroyNullMessagePort", nullptr, destroyNullMessagePort, 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); } +/* + * 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 +#include +#include +#include +#include +#include +#include "hilog/log.h" +#include "web/arkweb_interface.h" +#include + +constexpr unsigned int LOG_PRINT_DOMAIN = 0xFF00; +ArkWeb_ControllerAPI *controller = nullptr; + +ArkWeb_WebMessagePortAPI *webMessagePort = nullptr; +ArkWeb_WebMessageAPI *webMessage = nullptr; +size_t g_webMessagePortSize = 0; +ArkWeb_WebMessagePortPtr *g_web_message_port_arr = nullptr; + +static void WebMessagePortCallback( + const char *webTag, const ArkWeb_WebMessagePortPtr port, const ArkWeb_WebMessagePtr message, void *userData) +{ + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit WebMesagePortCallback webTag:%{public}s,messageType:%{public}d", + webTag, webMessage->getType(message)); + size_t len = 0; + void *back = webMessage->getData(message, &len); + if (webMessage->getType(message) == ArkWeb_WebMessageType::ARKWEB_STRING) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit WebMesagePortCallback message:%{public}s,messageSize:%{public}d", back, len); + } else if (webMessage->getType(message) == ArkWeb_WebMessageType::ARKWEB_BUFFER) { + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit WebMesagePortCallback messageSize:%{public}d", len); + } +} + +static napi_value NativeWebInit(napi_env env, napi_callback_info info) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit start"); + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit NativeWebInit webTag:%{public}s", webTagValue); + + controller = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_CONTROLLER)); + if (controller) + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_ControllerAPI success"); + + webMessagePort = + reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_WEB_MESSAGE_PORT)); + if (webMessagePort) + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_WebMessagePortAPI success"); + + webMessage = reinterpret_cast(OH_ArkWeb_GetNativeAPI(ARKWEB_NATIVE_WEB_MESSAGE)); + if (webMessage) + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "get ArkWeb_WebMessageAPI success"); + + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit NativeWebInit end"); + + return nullptr; +} + +static napi_value createWebMessagePorts(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 初始化端口 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit createWebMessagePorts begin"); + g_web_message_port_arr = controller->createWebMessagePorts(webTagValue, &g_webMessagePortSize); + // 把其中一个端口发送给HTML + ArkWeb_ErrorCode code = + controller->postWebMessage(webTagValue, "init_web_messageport", g_web_message_port_arr, 1, "*"); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postWebMessage ArkWeb_ErrorCode:%{public}d", code); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit createWebMessagePorts end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value postMessage(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 发送消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); + webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_STRING); + std::string str = "send string from native"; + webMessage->setData(message, (void *)str.c_str(), str.length() + 1); + ArkWeb_ErrorCode code = webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage ArkWeb_ErrorCode:%{public}d", code); + webMessage->destroyWebMessage(&message); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + + +// 在线程中发消息 +void sendMessage(const char *webTag, const ArkWeb_WebMessagePtr message) +{ + // 发送1000次 + for (int i = 0; i < 1000; i++) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "sendMessage in thread %{public}d", i); + if (g_web_message_port_arr && webTag && message) { + webMessagePort->postMessage(g_web_message_port_arr[1], webTag, message); + } + } +} +static napi_value postMessageThread(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 构造消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); + webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_STRING); + std::string str = "thread message"; + webMessage->setData(message, (void *)str.c_str(), str.length() + 1); + const int numThreads = 5; + std::thread threads[numThreads]; + + // 创建线程 + for (int i = 0; i < numThreads; ++i) { + threads[i] = std::thread(sendMessage, webTagValue, message); + } + + // 等待所有线程完成 + for (int i = 0; i < numThreads; ++i) { + threads[i].detach(); + } + return nullptr; +} + +// 在线程中注册回调 +void SetHandler(const char *webTag) +{ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "setMessageEventHandler in thread"); + webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTag, WebMessagePortCallback, NULL); +} + +static napi_value setMessageEventHandlerThread(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 注册回调 + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + std::thread thread(SetHandler, webTagValue); + thread.detach(); + webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTagValue, WebMessagePortCallback, NULL); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} +static napi_value postNoneMessage(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, + "ArkWeb", "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 发送消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit 发消息开始"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message = webMessage->createWebMessage(); + webMessage->setType(message, ArkWeb_WebMessageType::ARKWEB_NONE); + std::string str = "send string from native"; + webMessage->setData(message, (void *)str.c_str(), str.length() + 1); + webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message); + webMessage->destroyWebMessage(&message); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value postBufferMessage(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 发送消息 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit postMessage begin"); + + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + ArkWeb_WebMessagePtr message1 = webMessage->createWebMessage(); + webMessage->setType(message1, ArkWeb_WebMessageType::ARKWEB_BUFFER); + std::string str1 = "send buffer from native"; + webMessage->setData(message1, (void *)str1.c_str(), str1.length()); + webMessagePort->postMessage(g_web_message_port_arr[1], webTagValue, message1); + webMessage->destroyWebMessage(&message1); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit postMessage end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value setMessageEventHandler(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 注册回调 + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + webMessagePort->setMessageEventHandler(g_web_message_port_arr[1], webTagValue, WebMessagePortCallback, NULL); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value closeMessagePort(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 关闭端口,先调用close,再调用destroyWebMessagePorts + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + webMessagePort->close(g_web_message_port_arr[0], webTagValue); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + controller->refresh(webTagValue); + return nullptr; +} + +static napi_value destroyMessagePort(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 释放内存,先调用close,再调用destroyWebMessagePorts + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + if (g_web_message_port_arr == nullptr) { + OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "ArkWeb", "webMessagePort is nullptr"); + return nullptr; + } + controller->destroyWebMessagePorts(&g_web_message_port_arr, g_webMessagePortSize); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +static napi_value destroyNullMessagePort(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + // 获取第一个参数webTag + size_t webTagSize = 0; + napi_get_value_string_utf8(env, args[0], nullptr, 0, &webTagSize); + char *webTagValue = new (std::nothrow) char[webTagSize + 1]; + size_t webTagLength = 0; + napi_get_value_string_utf8(env, args[0], webTagValue, webTagSize + 1, &webTagLength); + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit Refresh webTag:%{public}s", webTagValue); + + // 释放内存,先调用close,再调用destroyWebMessagePorts + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", "Native Development Kit SetMessageEventHandler begin"); + + controller->destroyWebMessagePorts(&g_web_message_port_arr, g_webMessagePortSize); + + OH_LOG_Print( + LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "ArkWeb", + "Native Development Kit SetMessageEventHandler end, web message port size:%{public}d", g_webMessagePortSize); + return nullptr; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"nativeWebInit", nullptr, NativeWebInit, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"createWebMessagePorts", nullptr, createWebMessagePorts, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postMessage", nullptr, postMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postNoneMessage", nullptr, postNoneMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postBufferMessage", nullptr, postBufferMessage, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setMessageEventHandler", nullptr, setMessageEventHandler, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"closeMessagePort", nullptr, closeMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"destroyMessagePort", nullptr, destroyMessagePort, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"postMessageThread", nullptr, postMessageThread, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"setMessageEventHandlerThread", nullptr, setMessageEventHandlerThread, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"destroyNullMessagePort", nullptr, destroyNullMessagePort, 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/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 5e824d1654e91454e6590a68a51d9fa41582aefe..3c11c8b57c075b5322df845f7fdc371f8b49caa0 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/napi_init.cpp @@ -1,67 +1,67 @@ -/* - * 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" - -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); - - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - - double value0; - napi_get_value_double(env, args[0], &value0); - - double value1; - napi_get_value_double(env, args[1], &value1); - - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - - return sum; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "add", nullptr, Add, 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); -} +/* + * 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" + +static napi_value Add(napi_env env, napi_callback_info info) +{ + size_t argc = 2; + napi_value args[2] = {nullptr}; + + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + napi_valuetype valuetype0; + napi_typeof(env, args[0], &valuetype0); + + napi_valuetype valuetype1; + napi_typeof(env, args[1], &valuetype1); + + double value0; + napi_get_value_double(env, args[0], &value0); + + double value1; + napi_get_value_double(env, args[1], &value1); + + napi_value sum; + napi_create_double(env, value0 + value1, &sum); + + return sum; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "add", nullptr, Add, 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/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts old mode 100755 new mode 100644 index 1a2ac4beab9e07ce3d8f1e62db0640c1376a60c6..0a4518a33ee04c911801293f2aec49d8ff188e98 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/Index.d.ts @@ -1,26 +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. - */ - -export const nativeWebInit: (webName: string) => void; -export const createWebMessagePorts: (webName: string) => void; -export const postMessage: (webName: string) => void; -export const postNoneMessage: (webName: string) => void; -export const setMessageEventHandler: (webName: string) => void; -export const closeMessagePort: (webName: string) => void; -export const destroyMessagePort: (webName: string) => void; -export const postBufferMessage: (webName: string) => void; -export const destroyNullMessagePort: (webName: string) => void; -export const setMessageEventHandlerThread: (webName: string) => void; -export const postMessageThread: (webName: string) => void; +/* + * 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 nativeWebInit: (webName: string) => void; +export const createWebMessagePorts: (webName: string) => void; +export const postMessage: (webName: string) => void; +export const postNoneMessage: (webName: string) => void; +export const setMessageEventHandler: (webName: string) => void; +export const closeMessagePort: (webName: string) => void; +export const destroyMessagePort: (webName: string) => void; +export const postBufferMessage: (webName: string) => void; +export const destroyNullMessagePort: (webName: string) => void; +export const setMessageEventHandlerThread: (webName: string) => void; +export const postMessageThread: (webName: string) => void; diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 old mode 100755 new mode 100644 index 58cb547be035ce5f973b4795bc9bb396e2137a33..98c81afabac4d3f9d57c741379ffcd83981d7741 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/cpp/types/libentry5/oh-package.json5 @@ -1,21 +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": "libentry5.so", - "types": "./Index.d.ts", - "version": "1.0.0", - "description": "Please describe the basic information." +/* + * 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": "libentry5.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/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets old mode 100755 new mode 100644 index b95e7a9bb2dcae6585448925815246d7ac4e5e07..d0e606032c1d06947096a1714fd9401b639ac132 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/entry5ability/Entry5Ability.ets @@ -1,56 +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 Entry5Ability 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'); - } -}; +/* + * 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 Entry5Ability 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/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index de0a91e4a276b858ce9ee50b3d65a71aa34e51b0..08715d896921a92ab1993afe93a8adc34a8a36c3 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/ets/pages/Index.ets @@ -1,272 +1,272 @@ -/* - * 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 web_webview from '@ohos.web.webview'; -import { BusinessError } from '@ohos.base'; - -@Entry -@Component -struct Index { - @State webTag: string = 'postMessage'; - controller: web_webview.WebviewController = new web_webview.WebviewController(this.webTag); - @State h5Log: string = 'Display received message send from HTML'; - - aboutToAppear() { - web_webview.WebviewController.setWebDebuggingAccess(true); - // 初始化web Native Development Kit - testNapi.nativeWebInit(this.webTag); - } - - aboutToDisAppear() { - console.error('aboutToDisAppear'); - } - - build() { - Scroll() { - Column({ space: 10 }) { - // 展示H5接收到的内容 - Text($r('app.string.H5_Side_Message_Display_From_App')) - TextArea({text: this.h5Log}) - .id('log_area') - .width('100%') - .height(100) - .border({ width: 1 }) - Text($r('app.string.App_Side_Button')) - Row() { - Button('createNoControllerTagPort') - .id('create_no_tag_btn') - .onClick(() => { - try { - testNapi.createWebMessagePorts('noTag'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('createPort') - .id('create_port_btn') - .onClick(() => { - try { - testNapi.createWebMessagePorts(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - - Row({ space: 10 }) { - - Button('setHandler') - .id('set_handler_btn') - .onClick(() => { - try { - testNapi.setMessageEventHandler(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - - Button('setHandlerThread') - .id('set_handler_thread_btn') - .onClick(() => { - try { - testNapi.setMessageEventHandlerThread(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - - Row({ space: 10 }) { - Button('SendString') - .id('send_string_btn') - .onClick(() => { - try { - this.h5Log = '' - testNapi.postMessage(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('SendStringThread') - .id('send_string_thread_btn') - .onClick(() => { - try { - this.h5Log = '' - testNapi.postMessageThread(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - - Row({ space: 10 }) { - Button('SendBuffer') - .id('send_buffer_btn') - .onClick(() => { - try { - this.h5Log = '' - testNapi.postBufferMessage(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('SendNone') - .id('send_none_btn') - .onClick(() => { - try { - this.h5Log = '' - testNapi.postNoneMessage(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - - Row({ space: 10 }) { - - Button('closePort') - .id('close_port_btn') - .onClick(() => { - try { - testNapi.closeMessagePort(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('destroyNullPort') - .id('destroy_null_btn') - .onClick(() => { - try { - testNapi.destroyNullMessagePort(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('destroyPort') - .id('destroy_port_btn') - .onClick(() => { - try { - testNapi.destroyMessagePort(this.webTag); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - .width('100%') - .padding(10) - .border({ width: 1 }) - - Column({ space: 10 }) { - Text($r('app.string.H5_Side_Send_Button')) - Row({ space: 10 }) { - Button('H5String') - .id('h5_send_string_btn') - .onClick(() => { - try { - this.controller.runJavaScript('for(var i = 0; i < 2000; i++) postStringToApp()'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('H5Buffer') - .id('h5_send_buffer_btn') - .onClick(() => { - try { - this.controller.runJavaScript('postBufferToApp()'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('H5Number') - .id('h5_send_number_btn') - .onClick(() => { - try { - this.controller.runJavaScript('postNumberToApp()'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - - Row({ space: 10 }) { - Button('H5Json') - .id('h5_send_json_btn') - .onClick(() => { - try { - this.controller.runJavaScript('postJsonToApp()'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('H5Array') - .id('h5_send_array_btn') - .onClick(() => { - try { - this.controller.runJavaScript('postArrayStringToApp()'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - Button('H5Object') - .id('h5_send_object_btn') - .onClick(() => { - try { - this.controller.runJavaScript('postObjectToApp()'); - } catch (error) { - console.error( - `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); - } - }) - } - } - .width('100%') - .margin(10) - .padding(10) - .border({ width: 1 }) - - Web({ src: $rawfile('index.html'), controller: this.controller }) - .onConsole((event) => { - if (event) { - let msg = event.message.getMessage(); - if (msg.startsWith('H5')) { - this.h5Log = event.message.getMessage() + '\n' + this.h5Log; - } - } - return false; - }) - } - }.height('100%') - .scrollable(ScrollDirection.Vertical) - .scrollBar(BarState.Off) - .edgeEffect(EdgeEffect.Spring) - } -} +/* + * 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 web_webview from '@ohos.web.webview'; +import { BusinessError } from '@ohos.base'; + +@Entry +@Component +struct Index { + @State webTag: string = 'postMessage'; + controller: web_webview.WebviewController = new web_webview.WebviewController(this.webTag); + @State h5Log: string = 'Display received message send from HTML'; + + aboutToAppear() { + web_webview.WebviewController.setWebDebuggingAccess(true); + // 初始化web Native Development Kit + testNapi.nativeWebInit(this.webTag); + } + + aboutToDisAppear() { + console.error('aboutToDisAppear'); + } + + build() { + Scroll() { + Column({ space: 10 }) { + // 展示H5接收到的内容 + Text($r('app.string.H5_Side_Message_Display_From_App')) + TextArea({text: this.h5Log}) + .id('log_area') + .width('100%') + .height(100) + .border({ width: 1 }) + Text($r('app.string.App_Side_Button')) + Row() { + Button('createNoControllerTagPort') + .id('create_no_tag_btn') + .onClick(() => { + try { + testNapi.createWebMessagePorts('noTag'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('createPort') + .id('create_port_btn') + .onClick(() => { + try { + testNapi.createWebMessagePorts(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + + Button('setHandler') + .id('set_handler_btn') + .onClick(() => { + try { + testNapi.setMessageEventHandler(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + + Button('setHandlerThread') + .id('set_handler_thread_btn') + .onClick(() => { + try { + testNapi.setMessageEventHandlerThread(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + Button('SendString') + .id('send_string_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postMessage(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('SendStringThread') + .id('send_string_thread_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postMessageThread(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + Button('SendBuffer') + .id('send_buffer_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postBufferMessage(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('SendNone') + .id('send_none_btn') + .onClick(() => { + try { + this.h5Log = '' + testNapi.postNoneMessage(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + + Button('closePort') + .id('close_port_btn') + .onClick(() => { + try { + testNapi.closeMessagePort(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('destroyNullPort') + .id('destroy_null_btn') + .onClick(() => { + try { + testNapi.destroyNullMessagePort(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('destroyPort') + .id('destroy_port_btn') + .onClick(() => { + try { + testNapi.destroyMessagePort(this.webTag); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + .width('100%') + .padding(10) + .border({ width: 1 }) + + Column({ space: 10 }) { + Text($r('app.string.H5_Side_Send_Button')) + Row({ space: 10 }) { + Button('H5String') + .id('h5_send_string_btn') + .onClick(() => { + try { + this.controller.runJavaScript('for(var i = 0; i < 2000; i++) postStringToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Buffer') + .id('h5_send_buffer_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postBufferToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Number') + .id('h5_send_number_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postNumberToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + + Row({ space: 10 }) { + Button('H5Json') + .id('h5_send_json_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postJsonToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Array') + .id('h5_send_array_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postArrayStringToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + Button('H5Object') + .id('h5_send_object_btn') + .onClick(() => { + try { + this.controller.runJavaScript('postObjectToApp()'); + } catch (error) { + console.error( + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); + } + }) + } + } + .width('100%') + .margin(10) + .padding(10) + .border({ width: 1 }) + + Web({ src: $rawfile('index.html'), controller: this.controller }) + .onConsole((event) => { + if (event) { + let msg = event.message.getMessage(); + if (msg.startsWith('H5')) { + this.h5Log = event.message.getMessage() + '\n' + this.h5Log; + } + } + return false; + }) + } + }.height('100%') + .scrollable(ScrollDirection.Vertical) + .scrollBar(BarState.Off) + .edgeEffect(EdgeEffect.Spring) + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 old mode 100755 new mode 100644 index 93341c64f10f145cc087ac59fc9723b1cb80d8fd..e5f83a19012c5aeed889f2500740ef21005ce465 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/module.json5 @@ -1,42 +1,42 @@ -/* - * 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": "entry5", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry5Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry5Ability", - "srcEntry": "./ets/entry5ability/Entry5Ability.ets", - "description": "$string:Entry5Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry5Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ] - } +/* + * 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": "entry5", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry5Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry5Ability", + "srcEntry": "./ets/entry5ability/Entry5Ability.ets", + "description": "$string:Entry5Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry5Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index ebfeb5b327b0b41e905d0943bfba4e245fc2f2e8..d2925296ddd927dee795dba32254d6e182c4e8f8 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/main/resources/rawfile/index.html @@ -1,138 +1,138 @@ - - - - - -

etsRunJavaScriptExt测试demo

-

-

Receive string:

-

Receive arraybuffer:

- - - - + + + + + +

etsRunJavaScriptExt测试demo

+

+

Receive string:

+

Receive arraybuffer:

+ + + + diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/mock/Libentry5.mock.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 old mode 100755 new mode 100644 index b9137f46ef9249e16290691b08f9fba309bc1cfd..5ee7a310ffadc8ca0196f9fbc0b4a62ccc8c575d --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/ohosTest/module.json5 @@ -1,27 +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": "entry5_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry5_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseFrontendJSApp/entry5/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/UseFrontendJSApp/hvigorfile.ts b/code/DocsSample/ArkWeb/UseFrontendJSApp/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/oh-package.json5 b/code/DocsSample/ArkWeb/UseFrontendJSApp/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/UseFrontendJSApp/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseFrontendJSApp/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/UseFrontendJSApp/ohosTest.md b/code/DocsSample/ArkWeb/UseFrontendJSApp/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/AppCallFrontendFn_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannelC_C_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_1.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_2.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_3.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/EstabDataChannel_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/JavaScriptProxy_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/MutualInvokeCCpp.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/Promise_one.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/Promise_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/Promise_two.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/Promise_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/RegisterJavaScriptProxy_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_five.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_four.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_three.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png b/code/DocsSample/ArkWeb/UseFrontendJSApp/screenshots/UsageOfComplexTypes_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/.gitignore b/code/DocsSample/ArkWeb/UseOfflineWebComp/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/app.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/app.json5 old mode 100755 new mode 100644 index 8010ebfedd07ff754ce68fbe5e2499b04b3fc79f..5f862a961c7301f8f3f7a1639e5b59099e70e83c --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/app.json5 @@ -1,25 +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.useofflinewebcomp", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.useofflinewebcomp", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 9c1aa635756626d6f1f2c2b3850ee32d93d9b528..16490fd4d57af415efa5b69d512c3cce31db1e47 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UseOfflineWebComp" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UseOfflineWebComp" + } + ] +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/README.md b/code/DocsSample/ArkWeb/UseOfflineWebComp/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/build-profile.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/build-profile.json5 old mode 100755 new mode 100644 index 104fe4ce6a81217861b80feb042ce2cf2b7db0dc..13931b86668765c90141812d649565405dd2f25e --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/build-profile.json5 @@ -1,76 +1,76 @@ -/* - * 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry1", - "srcPath": "./entry1", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry2", - "srcPath": "./entry2", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry1", + "srcPath": "./entry1", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/code-linter.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/.gitignore b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/build-profile.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/oh-package.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index c3a1c8a89fcc4cc1dfb9ef6b5ff4627253d98e9c..88152c42fb1267f89c0bfbc723919a8b8bbf79ea --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import { createNWeb } from "../pages/common"; - -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 { - windowStage.loadContent('pages/Index', (err, data) => { - // 创建Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建 - createNWeb('www.example.com', windowStage.getMainWindowSync().getUIContext()); - if (err.code) { - return; - } - }); - } - - 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'); - } -} +/* + * 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'; +import { createNWeb } from "../pages/common"; + +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 { + windowStage.loadContent('pages/Index', (err, data) => { + // 创建Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建 + createNWeb('www.example.com', windowStage.getMainWindowSync().getUIContext()); + if (err.code) { + return; + } + }); + } + + 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/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/UseOfflineWebComp/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/pages/common.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/pages/common.ets old mode 100755 new mode 100644 index e22c3cd336dec67549ce52b69cb2f0ca33bed47a..8f184a9cd41d125ccbf926d7737ac53583618acd --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/pages/common.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/ets/pages/common.ets @@ -1,98 +1,98 @@ -/* - * 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. - */ - -// 创建NodeController -// common.ets -import { UIContext, NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; - -// @Builder中为动态组件的具体组件内容 -// Data为入参封装类 -class Data{ - public url: ResourceStr = 'www.example.com'; - public controller: WebviewController = new webview.WebviewController(); -} - -@Builder -function webBuilder(data:Data) { - Column() { - Web({ src: data.url, controller: data.controller }) - .width('100%') - .height('100%') - } -} - -let wrap = wrapBuilder(webBuilder); - -// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 -export class MyNodeController extends NodeController { - private rootnode: BuilderNode | null = null; - // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 - // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新 - makeNode(uiContext: UIContext): FrameNode | null { - console.log(' uicontext is undefined : '+ (uiContext === undefined)); - if (this.rootnode != null) { - // 返回FrameNode节点 - return this.rootnode.getFrameNode(); - } - // 返回null控制动态组件脱离绑定节点 - return null; - } - // 当布局大小发生变化时进行回调 - aboutToResize(size: Size) { - console.log('aboutToResize width : ' + size.width + ' height : ' + size.height ); - } - - // 当controller对应的NodeContainer在Appear的时候进行回调 - aboutToAppear() { - console.log('aboutToAppear'); - } - - // 当controller对应的NodeContainer在Disappear的时候进行回调 - aboutToDisappear() { - console.log('aboutToDisappear'); - } - - // 此函数为自定义函数,可作为初始化函数使用 - // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 - initWeb(url:ResourceStr, uiContext:UIContext, control:WebviewController) { - if (this.rootnode != null) { - return; - } - // 创建节点,需要uiContext - this.rootnode = new BuilderNode(uiContext); - // 创建动态Web组件 - this.rootnode.build(wrap, { url:url, controller:control }); - } -} -// 创建Map保存所需要的NodeController -let nodeMap:Map = new Map(); -// 创建Map保存所需要的WebViewController -let controllerMap:Map = new Map(); - -// 初始化需要UIContext 需在Ability获取 -export const createNWeb = (url: ResourceStr, uiContext: UIContext) => { - // 创建NodeController - let baseNode = new MyNodeController(); - let controller = new webview.WebviewController() ; - // 初始化自定义Web组件 - baseNode.initWeb(url, uiContext, controller); - controllerMap.set(url, controller); - nodeMap.set(url, baseNode); -} -// 自定义获取NodeController接口 -export const getNWeb = (url: ResourceStr) : MyNodeController | undefined => { - return nodeMap.get(url); -} +/* + * 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. + */ + +// 创建NodeController +// common.ets +import { UIContext, NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +// @Builder中为动态组件的具体组件内容 +// Data为入参封装类 +class Data{ + public url: ResourceStr = 'www.example.com'; + public controller: WebviewController = new webview.WebviewController(); +} + +@Builder +function webBuilder(data:Data) { + Column() { + Web({ src: data.url, controller: data.controller }) + .width('100%') + .height('100%') + } +} + +let wrap = wrapBuilder(webBuilder); + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private rootnode: BuilderNode | null = null; + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + console.log(' uicontext is undefined : '+ (uiContext === undefined)); + if (this.rootnode != null) { + // 返回FrameNode节点 + return this.rootnode.getFrameNode(); + } + // 返回null控制动态组件脱离绑定节点 + return null; + } + // 当布局大小发生变化时进行回调 + aboutToResize(size: Size) { + console.log('aboutToResize width : ' + size.width + ' height : ' + size.height ); + } + + // 当controller对应的NodeContainer在Appear的时候进行回调 + aboutToAppear() { + console.log('aboutToAppear'); + } + + // 当controller对应的NodeContainer在Disappear的时候进行回调 + aboutToDisappear() { + console.log('aboutToDisappear'); + } + + // 此函数为自定义函数,可作为初始化函数使用 + // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 + initWeb(url:ResourceStr, uiContext:UIContext, control:WebviewController) { + if (this.rootnode != null) { + return; + } + // 创建节点,需要uiContext + this.rootnode = new BuilderNode(uiContext); + // 创建动态Web组件 + this.rootnode.build(wrap, { url:url, controller:control }); + } +} +// 创建Map保存所需要的NodeController +let nodeMap:Map = new Map(); +// 创建Map保存所需要的WebViewController +let controllerMap:Map = new Map(); + +// 初始化需要UIContext 需在Ability获取 +export const createNWeb = (url: ResourceStr, uiContext: UIContext) => { + // 创建NodeController + let baseNode = new MyNodeController(); + let controller = new webview.WebviewController() ; + // 初始化自定义Web组件 + baseNode.initWeb(url, uiContext, controller); + controllerMap.set(url, controller); + nodeMap.set(url, baseNode); +} +// 自定义获取NodeController接口 +export const getNWeb = (url: ResourceStr) : MyNodeController | undefined => { + return nodeMap.get(url); +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/UseOfflineWebComp/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/.gitignore b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/build-profile.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/hvigorfile.ts b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/oh-package.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/oh-package.json5 old mode 100755 new mode 100644 index 4628f905e04f04e452fa5f8f9a43e8d641e3e7e8..c4e8768835e5e869bbd19dfb80d2e323afaa6f2d --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry1", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry1", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.ets old mode 100755 new mode 100644 index 552e7abe0be2b36dae4a85f53b50f532b6e487e3..7c81e2a6305a1ed6c16a75c7d91267129668cf31 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/entry1ability/Entry1Ability.ets @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import { createNWeb } from '../pages/common'; - -export default class Entry1Ability 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 { - windowStage.loadContent('pages/Index', (err, data) => { - // 创建空的Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建 - createNWeb('about:blank', windowStage.getMainWindowSync().getUIContext()); - if (err.code) { - return; - } - }); - } - - 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'); - } -} +/* + * 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'; +import { createNWeb } from '../pages/common'; + +export default class Entry1Ability 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 { + windowStage.loadContent('pages/Index', (err, data) => { + // 创建空的Web动态组件(需传入UIContext),loadContent之后的任意时机均可创建 + createNWeb('about:blank', windowStage.getMainWindowSync().getUIContext()); + if (err.code) { + return; + } + }); + } + + 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/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets old mode 100755 new mode 100644 index 999e9909b658c07ec2a2fbf3e3f8a47d4b79a31d..31cbee19a2a8aabba98643736de67aae0a7e9693 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/common.ets @@ -1,97 +1,97 @@ -/* - * 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. - */ - -// 创建NodeController -import { UIContext, NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; - -// @Builder中为动态组件的具体组件内容 -// Data为入参封装类 -class Data{ - public url: ResourceStr = 'www.example.com'; - public controller: WebviewController = new webview.WebviewController(); -} - -@Builder -function webBuilder(data:Data) { - Column() { - Web({ src: data.url, controller: data.controller }) - .width('100%') - .height('100%') - } -} - -let wrap = wrapBuilder(webBuilder); - -// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 -export class MyNodeController extends NodeController { - private rootnode: BuilderNode | null = null; - // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 - // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新 - makeNode(uiContext: UIContext): FrameNode | null { - console.log(' uicontext is undefined : '+ (uiContext === undefined)); - if (this.rootnode != null) { - // 返回FrameNode节点 - return this.rootnode.getFrameNode(); - } - // 返回null控制动态组件脱离绑定节点 - return null; - } - // 当布局大小发生变化时进行回调 - aboutToResize(size: Size) { - console.log('aboutToResize width : ' + size.width + ' height : ' + size.height ); - } - - // 当controller对应的NodeContainer在Appear的时候进行回调 - aboutToAppear() { - console.log('aboutToAppear'); - } - - // 当controller对应的NodeContainer在Disappear的时候进行回调 - aboutToDisappear() { - console.log('aboutToDisappear'); - } - - // 此函数为自定义函数,可作为初始化函数使用 - // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 - initWeb(url:ResourceStr, uiContext:UIContext, control:WebviewController) { - if (this.rootnode != null) { - return; - } - // 创建节点,需要uiContext - this.rootnode = new BuilderNode(uiContext); - // 创建动态Web组件 - this.rootnode.build(wrap, { url:url, controller:control }); - } -} -// 创建Map保存所需要的NodeController -let nodeMap:Map = new Map(); -// 创建Map保存所需要的WebViewController -let controllerMap:Map = new Map(); - -// 初始化需要UIContext 需在Ability获取 -export const createNWeb = (url: ResourceStr, uiContext: UIContext) => { - // 创建NodeController - let baseNode = new MyNodeController(); - let controller = new webview.WebviewController() ; - // 初始化自定义Web组件 - baseNode.initWeb(url, uiContext, controller); - controllerMap.set(url, controller); - nodeMap.set(url, baseNode); -} -// 自定义获取NodeController接口 -export const getNWeb = (url: ResourceStr) : MyNodeController | undefined => { - return nodeMap.get(url); -} +/* + * 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. + */ + +// 创建NodeController +import { UIContext, NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +// @Builder中为动态组件的具体组件内容 +// Data为入参封装类 +class Data{ + public url: ResourceStr = 'www.example.com'; + public controller: WebviewController = new webview.WebviewController(); +} + +@Builder +function webBuilder(data:Data) { + Column() { + Web({ src: data.url, controller: data.controller }) + .width('100%') + .height('100%') + } +} + +let wrap = wrapBuilder(webBuilder); + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private rootnode: BuilderNode | null = null; + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContainer中 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + console.log(' uicontext is undefined : '+ (uiContext === undefined)); + if (this.rootnode != null) { + // 返回FrameNode节点 + return this.rootnode.getFrameNode(); + } + // 返回null控制动态组件脱离绑定节点 + return null; + } + // 当布局大小发生变化时进行回调 + aboutToResize(size: Size) { + console.log('aboutToResize width : ' + size.width + ' height : ' + size.height ); + } + + // 当controller对应的NodeContainer在Appear的时候进行回调 + aboutToAppear() { + console.log('aboutToAppear'); + } + + // 当controller对应的NodeContainer在Disappear的时候进行回调 + aboutToDisappear() { + console.log('aboutToDisappear'); + } + + // 此函数为自定义函数,可作为初始化函数使用 + // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 + initWeb(url:ResourceStr, uiContext:UIContext, control:WebviewController) { + if (this.rootnode != null) { + return; + } + // 创建节点,需要uiContext + this.rootnode = new BuilderNode(uiContext); + // 创建动态Web组件 + this.rootnode.build(wrap, { url:url, controller:control }); + } +} +// 创建Map保存所需要的NodeController +let nodeMap:Map = new Map(); +// 创建Map保存所需要的WebViewController +let controllerMap:Map = new Map(); + +// 初始化需要UIContext 需在Ability获取 +export const createNWeb = (url: ResourceStr, uiContext: UIContext) => { + // 创建NodeController + let baseNode = new MyNodeController(); + let controller = new webview.WebviewController() ; + // 初始化自定义Web组件 + baseNode.initWeb(url, uiContext, controller); + controllerMap.set(url, controller); + nodeMap.set(url, baseNode); +} +// 自定义获取NodeController接口 +export const getNWeb = (url: ResourceStr) : MyNodeController | undefined => { + return nodeMap.get(url); +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/index2.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/index2.ets old mode 100755 new mode 100644 index 46b3ca95cbd8a28de2800255aa05a0aae127029a..f722dafb6de1af723de93855601f25b30525f090 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/index2.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/ets/pages/index2.ets @@ -1,34 +1,34 @@ -/* - * 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 web_webview from '@ohos.web.webview'; - -@Entry -@Component -struct index2 { - webviewController: web_webview.WebviewController = new web_webview.WebviewController(); - - build() { - Row() { - Column() { - Web({src: 'www.example.com', controller: this.webviewController}) - .width('100%') - .height('100%') - } - .width('100%') - } - .height('100%') - } -} +/* + * 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 web_webview from '@ohos.web.webview'; + +@Entry +@Component +struct index2 { + webviewController: web_webview.WebviewController = new web_webview.WebviewController(); + + build() { + Row() { + Column() { + Web({src: 'www.example.com', controller: this.webviewController}) + .width('100%') + .height('100%') + } + .width('100%') + } + .height('100%') + } +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/module.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/module.json5 old mode 100755 new mode 100644 index 465872d2309126fd7bbf697c9395c155c717a4bf..5303c59d21b19cfd2c0a4299ec6ea72fede11eba --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/module.json5 @@ -1,47 +1,47 @@ -/* - * 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": "entry1", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry1Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry1Ability", - "srcEntry": "./ets/entry1ability/Entry1Ability.ets", - "description": "$string:Entry1Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry1Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry1", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry1Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry1Ability", + "srcEntry": "./ets/entry1ability/Entry1Ability.ets", + "description": "$string:Entry1Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry1Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/module.json5 old mode 100755 new mode 100644 index b463f808d133416ec65c5c4ef3f4d1dd9528e592..a8392c11cf0dbecb4cdc78dc93d456a3a8e6ff41 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/ohosTest/module.json5 @@ -1,27 +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": "entry1_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry1_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry1/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/.gitignore b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/build-profile.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/hvigorfile.ts b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/oh-package.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/oh-package.json5 old mode 100755 new mode 100644 index bcb70ff878510fb523d011c47eb563dc4edbd9ea..6f8ebfffe80a99a9743e76a638cdd63c2b6ec72f --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * 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": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/entry2ability/Entry2Ability.ets old mode 100755 new mode 100644 index 502c9fd6ee120d37a42e70df740fe1ecd7a2eefc..1270a900ce0da82cfabf25a43b7ae5087891d0d1 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -1,56 +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 Entry2Ability 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'); - } -} +/* + * 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 Entry2Ability 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/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets old mode 100755 new mode 100644 index 82c5f1fb98ff97fe063a39c14a5278b239f9b7e6..578e567272842ff78fa4085c2c8c7305ffd09399 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/common.ets @@ -1,107 +1,107 @@ -/* - * 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. - */ - -// 创建NodeController -// common.ets -import { UIContext } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; -import { NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; -// @Builder中为动态组件的具体组件内容 -// Data为入参封装类 -class Data{ - public url: string = 'www.example.com'; - public controller: WebviewController = new webview.WebviewController(); -} -// 通过布尔变量shouldInactive控制网页在后台完成预渲染后停止渲染 -let shouldInactive: boolean = true; -@Builder -function webBuilder(data:Data) { - Column() { - Web({ src: data.url, controller: data.controller }) - .onPageBegin(() => { - // 调用onActive,开启渲染 - data.controller.onActive(); - }) - .onFirstMeaningfulPaint(() =>{ - if (!shouldInactive) { - return; - } - // 在预渲染完成时触发,停止渲染 - data.controller.onInactive(); - shouldInactive = false; - }) - .width('100%') - .height('100%') - } -} -let wrap = wrapBuilder(webBuilder); -// 用于控制和反馈对应的NodeContianer上的节点的行为,需要与NodeContainer一起使用 -export class MyNodeController extends NodeController { - private rootnode: BuilderNode | null = null; - // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContianer中 - // 在对应NodeContianer创建的时候调用、或者通过rebuild方法调用刷新 - makeNode(uiContext: UIContext): FrameNode | null { - console.info(' uicontext is undifined : '+ (uiContext === undefined)); - if (this.rootnode != null) { - // 返回FrameNode节点 - return this.rootnode.getFrameNode(); - } - // 返回null控制动态组件脱离绑定节点 - return null; - } - // 当布局大小发生变化时进行回调 - aboutToResize(size: Size) { - console.info('aboutToResize width : ' + size.width + ' height : ' + size.height ); - } - // 当controller对应的NodeContainer在Appear的时候进行回调 - aboutToAppear() { - console.info('aboutToAppear'); - // 切换到前台后,不需要停止渲染 - shouldInactive = false; - } - // 当controller对应的NodeContainer在Disappear的时候进行回调 - aboutToDisappear() { - console.info('aboutToDisappear'); - } - // 此函数为自定义函数,可作为初始化函数使用 - // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 - initWeb(url:string, uiContext:UIContext, control:WebviewController) { - if (this.rootnode != null) { - return; - } - // 创建节点,需要uiContext - this.rootnode = new BuilderNode(uiContext); - // 创建动态Web组件 - this.rootnode.build(wrap, { url:url, controller:control }); - } -} -// 创建Map保存所需要的NodeController -let nodeMap:Map = new Map(); -// 创建Map保存所需要的WebViewController -let controllerMap:Map = new Map(); -// 初始化需要UIContext 需在Ability获取 -export const createNWeb = (url: string, uiContext: UIContext) => { - // 创建NodeController - let baseNode = new MyNodeController(); - let controller = new webview.WebviewController(); - // 初始化自定义Web组件 - baseNode.initWeb(url, uiContext, controller); - controllerMap.set(url, controller) - nodeMap.set(url, baseNode); -} -// 自定义获取NodeController接口 -export const getNWeb = (url : string) : MyNodeController | undefined => { - return nodeMap.get(url); +/* + * 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. + */ + +// 创建NodeController +// common.ets +import { UIContext } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; +import { NodeController, BuilderNode, Size, FrameNode } from '@kit.ArkUI'; +// @Builder中为动态组件的具体组件内容 +// Data为入参封装类 +class Data{ + public url: string = 'www.example.com'; + public controller: WebviewController = new webview.WebviewController(); +} +// 通过布尔变量shouldInactive控制网页在后台完成预渲染后停止渲染 +let shouldInactive: boolean = true; +@Builder +function webBuilder(data:Data) { + Column() { + Web({ src: data.url, controller: data.controller }) + .onPageBegin(() => { + // 调用onActive,开启渲染 + data.controller.onActive(); + }) + .onFirstMeaningfulPaint(() =>{ + if (!shouldInactive) { + return; + } + // 在预渲染完成时触发,停止渲染 + data.controller.onInactive(); + shouldInactive = false; + }) + .width('100%') + .height('100%') + } +} +let wrap = wrapBuilder(webBuilder); +// 用于控制和反馈对应的NodeContianer上的节点的行为,需要与NodeContainer一起使用 +export class MyNodeController extends NodeController { + private rootnode: BuilderNode | null = null; + // 必须要重写的方法,用于构建节点数、返回节点挂载在对应NodeContianer中 + // 在对应NodeContianer创建的时候调用、或者通过rebuild方法调用刷新 + makeNode(uiContext: UIContext): FrameNode | null { + console.info(' uicontext is undifined : '+ (uiContext === undefined)); + if (this.rootnode != null) { + // 返回FrameNode节点 + return this.rootnode.getFrameNode(); + } + // 返回null控制动态组件脱离绑定节点 + return null; + } + // 当布局大小发生变化时进行回调 + aboutToResize(size: Size) { + console.info('aboutToResize width : ' + size.width + ' height : ' + size.height ); + } + // 当controller对应的NodeContainer在Appear的时候进行回调 + aboutToAppear() { + console.info('aboutToAppear'); + // 切换到前台后,不需要停止渲染 + shouldInactive = false; + } + // 当controller对应的NodeContainer在Disappear的时候进行回调 + aboutToDisappear() { + console.info('aboutToDisappear'); + } + // 此函数为自定义函数,可作为初始化函数使用 + // 通过UIContext初始化BuilderNode,再通过BuilderNode中的build接口初始化@Builder中的内容 + initWeb(url:string, uiContext:UIContext, control:WebviewController) { + if (this.rootnode != null) { + return; + } + // 创建节点,需要uiContext + this.rootnode = new BuilderNode(uiContext); + // 创建动态Web组件 + this.rootnode.build(wrap, { url:url, controller:control }); + } +} +// 创建Map保存所需要的NodeController +let nodeMap:Map = new Map(); +// 创建Map保存所需要的WebViewController +let controllerMap:Map = new Map(); +// 初始化需要UIContext 需在Ability获取 +export const createNWeb = (url: string, uiContext: UIContext) => { + // 创建NodeController + let baseNode = new MyNodeController(); + let controller = new webview.WebviewController(); + // 初始化自定义Web组件 + baseNode.initWeb(url, uiContext, controller); + controllerMap.set(url, controller) + nodeMap.set(url, baseNode); +} +// 自定义获取NodeController接口 +export const getNWeb = (url : string) : MyNodeController | undefined => { + return nodeMap.get(url); } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/index2.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/ets/pages/index2.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/module.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/module.json5 old mode 100755 new mode 100644 index c795511fa6f3e59972d74471cb44c0b9a91f67af..d90aa2e323415a88f31a2cab7f8372d3ef14d7e0 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/module.json5 @@ -1,47 +1,47 @@ -/* - * 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": "entry2", - "type": "feature", - "description": "$string:module_desc", - "mainElement": "Entry2Ability", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry2Ability", - "srcEntry": "./ets/entry2ability/Entry2Ability.ets", - "description": "$string:Entry2Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry2Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true - } - ], - "requestPermissions":[ - { - "name" : "ohos.permission.INTERNET" - } - ] - } +/* + * 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": "entry2", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ], + "requestPermissions":[ + { + "name" : "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 87a1b504873368e9fba4674048215376b52ec579..031b54bde39f1b8ca1884b863026dbc91fd5a75a --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/ohosTest/module.json5 @@ -1,27 +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": "entry2_test", - "type": "feature", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* + * 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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseOfflineWebComp/entry2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/UseOfflineWebComp/hvigorfile.ts b/code/DocsSample/ArkWeb/UseOfflineWebComp/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/oh-package.json5 b/code/DocsSample/ArkWeb/UseOfflineWebComp/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/UseOfflineWebComp/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseOfflineWebComp/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/UseOfflineWebComp/ohosTest.md b/code/DocsSample/ArkWeb/UseOfflineWebComp/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/CreatingOfflineWebComponents.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/CreatingOfflineWebComponents.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_1.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_2.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_one_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_1.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_2.png b/code/DocsSample/ArkWeb/UseOfflineWebComp/screenshots/PreLaunchingRenderingProcess_two_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/.gitignore b/code/DocsSample/ArkWeb/UseSameLayerRender/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/app.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/app.json5 old mode 100755 new mode 100644 index fc7f6d18d6ea0cc3b58bb4c8adbc56d8295c2564..5b18054bf88655b05cb4d3f97880b8a465aaa700 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/app.json5 @@ -1,25 +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.usesamelayerrender", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.usesamelayerrender", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index c09b1adba39c17825052c34fed9b801d49abc02e..030dffd09fc244d49ff44a13c13f61872c724578 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UseSameLayerRender" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UseSameLayerRender" + } + ] +} diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/UseSameLayerRender/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/README.md b/code/DocsSample/ArkWeb/UseSameLayerRender/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/build-profile.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/UseSameLayerRender/code-linter.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/.gitignore b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/build-profile.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/oh-package.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets old mode 100755 new mode 100644 index f1725a0155ea31cd34f47a5681b38a1ded6bf503..e3ef1ec638db7e5632ae0692984a59a60fba60b2 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/DrawXCompAVPBtn.ets @@ -1,214 +1,214 @@ -/* - * 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. - */ - -// 创建NodeController -import { webview } from '@kit.ArkWeb'; -import { UIContext, NodeController, BuilderNode, NodeRenderType, FrameNode } from '@kit.ArkUI'; -import { AVPlayerDemo } from './PlayerDemo'; - -@Observed -declare class Params { - public textOne : string - public textTwo : string - public width : number - public height : number -} - -declare class NodeControllerParams { - public surfaceId : string - public type : string - public renderType : NodeRenderType - public embedId : string - public width : number - public height : number -} - -// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用。 -class MyNodeController extends NodeController { - private rootNode: BuilderNode<[Params]> | undefined | null; - private embedId_ : string = ''; - private surfaceId_ : string = ''; - private renderType_ :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; - private width_ : number = 0; - private height_ : number = 0; - private type_ : string = ''; - private isDestroy_ : boolean = false; - - setRenderOption(params : NodeControllerParams) { - this.surfaceId_ = params.surfaceId; - this.renderType_ = params.renderType; - this.embedId_ = params.embedId; - this.width_ = params.width; - this.height_ = params.height; - this.type_ = params.type; - } - // 必须要重写的方法,用于构建节点数、返回节点数挂载在对应NodeContainer中。 - // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新。 - makeNode(uiContext: UIContext): FrameNode | null{ - if (this.isDestroy_) { // rootNode为null - return null; - } - if (!this.rootNode) { // rootNode 为undefined时 - this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_}); - if (this.type_ === 'native/video') { - this.rootNode.build( - wrapBuilder(videoBuilder), {textOne: 'myButton', width : this.width_, height : this.height_}); - } else { - // other - } - } - // 返回FrameNode节点。 - return this.rootNode.getFrameNode(); - } - - setBuilderNode(rootNode: BuilderNode | null): void{ - this.rootNode = rootNode; - } - - getBuilderNode(): BuilderNode<[Params]> | undefined | null{ - return this.rootNode; - } - - updateNode(arg: Object): void { - this.rootNode?.update(arg); - } - getEmbedId() : string { - return this.embedId_; - } - - setDestroy(isDestroy : boolean) : void { - this.isDestroy_ = isDestroy; - if (this.isDestroy_) { - this.rootNode = null; - } - } - - postEvent(event: TouchEvent | undefined) : boolean { - return this.rootNode?.postTouchEvent(event) as boolean; - } -} - -@Component -struct VideoComponent { - @ObjectLink params: Params; - @State bkColor: Color = Color.Red; - mXComponentController: XComponentController = new XComponentController(); - @State playerChanged: boolean = false; - player?: AVPlayerDemo; - - build() { - Column() { - Button(this.params.textOne); - - XComponent({ id: 'video_player_id', type: XComponentType.SURFACE, controller: this.mXComponentController}) - .border({width: 1, color: Color.Red}) - .onLoad(() => { - this.player = new AVPlayerDemo(); - this.player.setSurfaceID(this.mXComponentController.getXComponentSurfaceId()); - this.playerChanged = !this.playerChanged; - this.player.avPlayerLiveDemo(); - }) - .width(300) - .height(200) - } - //自定义组件中的最外层容器组件宽高应该为同层标签的宽高 - .width(this.params.width) - .height(this.params.height) - } -} -// @Builder中为动态组件的具体组件内容。 -@Builder -function videoBuilder(params: Params) { - VideoComponent({ params: params }) - .backgroundColor(Color.Gray) -} - -@Entry -@Component -struct WebIndex { - browserTabController: WebviewController = new webview.WebviewController() - private nodeControllerMap: Map = new Map(); - @State componentIdArr: Array = []; - - aboutToAppear() { - // 配置web开启调试模式。 - webview.WebviewController.setWebDebuggingAccess(true); - } - - build(){ - Row() { - Column() { - Stack() { - ForEach(this.componentIdArr, (componentId: string) => { - NodeContainer(this.nodeControllerMap.get(componentId)); - }, (embedId: string) => embedId) - // Web组件加载本地test.html页面。 - Web({ src: $rawfile('test3.html'), controller: this.browserTabController }) - // 配置同层渲染开关开启。 - .enableNativeEmbedMode(true) - // 获取embed标签的生命周期变化数据。 - .onNativeEmbedLifecycleChange((embed) => { - console.log('NativeEmbed surfaceId' + embed.surfaceId); - // 1. 如果使用embed.info.id作为映射nodeController的key,请在h5页面显式指定id - const componentId = embed.info?.id?.toString() as string - if (embed.status == NativeEmbedStatus.CREATE) { - console.log('NativeEmbed create' + JSON.stringify(embed.info)) - // 创建节点控制器,设置参数并rebuild。 - let nodeController = new MyNodeController() - // 1. embed.info.width和embed.info.height单位是px格式,需要转换成ets侧的默认单位vp - nodeController.setRenderOption({ - surfaceId : embed.surfaceId as string, type : embed.info?.type as string, - renderType : NodeRenderType.RENDER_TYPE_TEXTURE, embedId : embed.embedId as string, - width : px2vp(embed.info?.width), height : px2vp(embed.info?.height)}); - nodeController.setDestroy(false); - // 根据web传入的embed的id属性作为key,将nodeController存入map。 - this.nodeControllerMap.set(componentId, nodeController) - // 将web传入的embed的id属性存入@State状态数组变量中,用于动态创建nodeContainer节点容器,需要将push动作放在set之后。 - this.componentIdArr.push(componentId) - } else if (embed.status == NativeEmbedStatus.UPDATE) { - let nodeController = this.nodeControllerMap.get(componentId); - nodeController?.updateNode({ - textOne: 'update', width: px2vp(embed.info?.width), height: px2vp(embed.info?.height)} as ESObject); - } else { - let nodeController = this.nodeControllerMap.get(componentId); - nodeController?.setDestroy(true); - this.nodeControllerMap.clear(); - this.componentIdArr.length = 0; - } - })// 获取同层渲染组件触摸事件信息。 - .onNativeEmbedGestureEvent((touch) => { - console.log('NativeEmbed onNativeEmbedGestureEvent' + JSON.stringify(touch.touchEvent)); - this.componentIdArr.forEach((componentId: string) => { - let nodeController = this.nodeControllerMap.get(componentId) - // 将获取到的同层区域的事件发送到该区域embedId对应的nodeController上 - if (nodeController?.getEmbedId() === touch.embedId) { - let ret = nodeController?.postEvent(touch.touchEvent) - if (ret) { - console.log('onNativeEmbedGestureEvent success ' + componentId); - } else { - console.log('onNativeEmbedGestureEvent fail ' + componentId); - } - if (touch.result) { - // 通知Web组件手势事件消费结果 - touch.result.setGestureEventResult(ret); - } - } - }) - }) - } - } - } - } -} +/* + * 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. + */ + +// 创建NodeController +import { webview } from '@kit.ArkWeb'; +import { UIContext, NodeController, BuilderNode, NodeRenderType, FrameNode } from '@kit.ArkUI'; +import { AVPlayerDemo } from './PlayerDemo'; + +@Observed +declare class Params { + public textOne : string + public textTwo : string + public width : number + public height : number +} + +declare class NodeControllerParams { + public surfaceId : string + public type : string + public renderType : NodeRenderType + public embedId : string + public width : number + public height : number +} + +// 用于控制和反馈对应的NodeContainer上的节点的行为,需要与NodeContainer一起使用。 +class MyNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | undefined | null; + private embedId_ : string = ''; + private surfaceId_ : string = ''; + private renderType_ :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; + private width_ : number = 0; + private height_ : number = 0; + private type_ : string = ''; + private isDestroy_ : boolean = false; + + setRenderOption(params : NodeControllerParams) { + this.surfaceId_ = params.surfaceId; + this.renderType_ = params.renderType; + this.embedId_ = params.embedId; + this.width_ = params.width; + this.height_ = params.height; + this.type_ = params.type; + } + // 必须要重写的方法,用于构建节点数、返回节点数挂载在对应NodeContainer中。 + // 在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新。 + makeNode(uiContext: UIContext): FrameNode | null{ + if (this.isDestroy_) { // rootNode为null + return null; + } + if (!this.rootNode) { // rootNode 为undefined时 + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId_, type: this.renderType_}); + if (this.type_ === 'native/video') { + this.rootNode.build( + wrapBuilder(videoBuilder), {textOne: 'myButton', width : this.width_, height : this.height_}); + } else { + // other + } + } + // 返回FrameNode节点。 + return this.rootNode.getFrameNode(); + } + + setBuilderNode(rootNode: BuilderNode | null): void{ + this.rootNode = rootNode; + } + + getBuilderNode(): BuilderNode<[Params]> | undefined | null{ + return this.rootNode; + } + + updateNode(arg: Object): void { + this.rootNode?.update(arg); + } + getEmbedId() : string { + return this.embedId_; + } + + setDestroy(isDestroy : boolean) : void { + this.isDestroy_ = isDestroy; + if (this.isDestroy_) { + this.rootNode = null; + } + } + + postEvent(event: TouchEvent | undefined) : boolean { + return this.rootNode?.postTouchEvent(event) as boolean; + } +} + +@Component +struct VideoComponent { + @ObjectLink params: Params; + @State bkColor: Color = Color.Red; + mXComponentController: XComponentController = new XComponentController(); + @State playerChanged: boolean = false; + player?: AVPlayerDemo; + + build() { + Column() { + Button(this.params.textOne); + + XComponent({ id: 'video_player_id', type: XComponentType.SURFACE, controller: this.mXComponentController}) + .border({width: 1, color: Color.Red}) + .onLoad(() => { + this.player = new AVPlayerDemo(); + this.player.setSurfaceID(this.mXComponentController.getXComponentSurfaceId()); + this.playerChanged = !this.playerChanged; + this.player.avPlayerLiveDemo(); + }) + .width(300) + .height(200) + } + //自定义组件中的最外层容器组件宽高应该为同层标签的宽高 + .width(this.params.width) + .height(this.params.height) + } +} +// @Builder中为动态组件的具体组件内容。 +@Builder +function videoBuilder(params: Params) { + VideoComponent({ params: params }) + .backgroundColor(Color.Gray) +} + +@Entry +@Component +struct WebIndex { + browserTabController: WebviewController = new webview.WebviewController() + private nodeControllerMap: Map = new Map(); + @State componentIdArr: Array = []; + + aboutToAppear() { + // 配置web开启调试模式。 + webview.WebviewController.setWebDebuggingAccess(true); + } + + build(){ + Row() { + Column() { + Stack() { + ForEach(this.componentIdArr, (componentId: string) => { + NodeContainer(this.nodeControllerMap.get(componentId)); + }, (embedId: string) => embedId) + // Web组件加载本地test.html页面。 + Web({ src: $rawfile('test3.html'), controller: this.browserTabController }) + // 配置同层渲染开关开启。 + .enableNativeEmbedMode(true) + // 获取embed标签的生命周期变化数据。 + .onNativeEmbedLifecycleChange((embed) => { + console.log('NativeEmbed surfaceId' + embed.surfaceId); + // 1. 如果使用embed.info.id作为映射nodeController的key,请在h5页面显式指定id + const componentId = embed.info?.id?.toString() as string + if (embed.status == NativeEmbedStatus.CREATE) { + console.log('NativeEmbed create' + JSON.stringify(embed.info)) + // 创建节点控制器,设置参数并rebuild。 + let nodeController = new MyNodeController() + // 1. embed.info.width和embed.info.height单位是px格式,需要转换成ets侧的默认单位vp + nodeController.setRenderOption({ + surfaceId : embed.surfaceId as string, type : embed.info?.type as string, + renderType : NodeRenderType.RENDER_TYPE_TEXTURE, embedId : embed.embedId as string, + width : px2vp(embed.info?.width), height : px2vp(embed.info?.height)}); + nodeController.setDestroy(false); + // 根据web传入的embed的id属性作为key,将nodeController存入map。 + this.nodeControllerMap.set(componentId, nodeController) + // 将web传入的embed的id属性存入@State状态数组变量中,用于动态创建nodeContainer节点容器,需要将push动作放在set之后。 + this.componentIdArr.push(componentId) + } else if (embed.status == NativeEmbedStatus.UPDATE) { + let nodeController = this.nodeControllerMap.get(componentId); + nodeController?.updateNode({ + textOne: 'update', width: px2vp(embed.info?.width), height: px2vp(embed.info?.height)} as ESObject); + } else { + let nodeController = this.nodeControllerMap.get(componentId); + nodeController?.setDestroy(true); + this.nodeControllerMap.clear(); + this.componentIdArr.length = 0; + } + })// 获取同层渲染组件触摸事件信息。 + .onNativeEmbedGestureEvent((touch) => { + console.log('NativeEmbed onNativeEmbedGestureEvent' + JSON.stringify(touch.touchEvent)); + this.componentIdArr.forEach((componentId: string) => { + let nodeController = this.nodeControllerMap.get(componentId) + // 将获取到的同层区域的事件发送到该区域embedId对应的nodeController上 + if (nodeController?.getEmbedId() === touch.embedId) { + let ret = nodeController?.postEvent(touch.touchEvent) + if (ret) { + console.log('onNativeEmbedGestureEvent success ' + componentId); + } else { + console.log('onNativeEmbedGestureEvent fail ' + componentId); + } + if (touch.result) { + // 通知Web组件手势事件消费结果 + touch.result.setGestureEventResult(ret); + } + } + }) + }) + } + } + } + } +} diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index b5f3b4332de4db1b801d0eb93c53fb566889923b..be598b7d155a0ab9f72e9841e8736b663fd3ad67 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/Index.ets @@ -1,38 +1,38 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('RenderTxtBoxSameLayer_one') - .onClick(() => { - router.pushUrl({ url: 'pages/RenderTxtBoxSameLayer_one' }); - }) - Button('RenderTxtBoxSameLayer_two') - .onClick(() => { - router.pushUrl({ url: 'pages/RenderTxtBoxSameLayer_two' }); - }) - Button('DrawXCompAVPBtn') - .onClick(() => { - router.pushUrl({ url: 'pages/DrawXCompAVPBtn' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('RenderTxtBoxSameLayer_one') + .onClick(() => { + router.pushUrl({ url: 'pages/RenderTxtBoxSameLayer_one' }); + }) + Button('RenderTxtBoxSameLayer_two') + .onClick(() => { + router.pushUrl({ url: 'pages/RenderTxtBoxSameLayer_two' }); + }) + Button('DrawXCompAVPBtn') + .onClick(() => { + router.pushUrl({ url: 'pages/DrawXCompAVPBtn' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets old mode 100755 new mode 100644 index 7e298f41f40aab35e88dad2477b7e8b4d1d7d0a1..1d785f7b0575f302d1fa5d27ced59260a80a8104 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/PlayerDemo.ets @@ -1,101 +1,101 @@ -/* - * 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 { media } from '@kit.MediaKit'; -import { BusinessError } from '@ohos.base'; - -export class AVPlayerDemo { - private count: number = 0; - private surfaceId: string = ''; // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法。 - private isSeek: boolean = true; // 用于区分模式是否支持seek操作。 - - setSurfaceID(id: string){ - console.log('setSurfaceID : ' + id); - this.surfaceId = id; - } - // 注册avplayer回调函数。 - setAVPlayerCallback(avPlayer: media.AVPlayer) { - // seek操作结果回调函数。 - avPlayer.on('seekDone', (seekDoneTime: number) => { - console.info(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`); - }) - // error回调监听函数,当avplayer在操作过程中出现错误时,调用reset接口触发重置流程。 - avPlayer.on('error', (err: BusinessError) => { - console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); - avPlayer.reset(); - }) - // 状态机变化回调函数。 - avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => { - switch (state) { - case 'idle': // 成功调用reset接口后触发该状态机上报。 - console.info('AVPlayer state idle called.'); - avPlayer.release(); // 调用release接口销毁实例对象。 - break; - case 'initialized': // avplayer 设置播放源后触发该状态上报。 - console.info('AVPlayer state initialized called.'); - avPlayer.surfaceId = this.surfaceId; // 设置显示画面,当播放的资源为纯音频时无需设置。 - avPlayer.prepare(); - break; - case 'prepared': // prepared调用成功后上报该状态机。 - console.info('AVPlayer state prepared called.'); - avPlayer.play(); // 调用播放接口开始播放。 - break; - case 'playing': // play成功调用后触发该状态机上报。 - console.info('AVPlayer state prepared called.'); - if(this.count !== 0) { - if (this.isSeek) { - console.info('AVPlayer start to seek.'); - avPlayer.seek(avPlayer.duration); // seek到视频末尾。 - } else { - // 当播放模式不支持seek操作时继续播放到结尾。 - console.info('AVPlayer wait to play end.'); - } - } else { - avPlayer.pause(); // 调用暂停接口暂停播放。 - } - this.count++; - break; - case 'paused': // pause成功调用后触发该状态机上报。 - console.info('AVPlayer state paused called.'); - avPlayer.play(); // 再次播放接口开始播放。 - break; - case 'completed': //播放接口后触发该状态机上报。 - console.info('AVPlayer state paused called.'); - avPlayer.stop(); // 调用播放接口接口。 - break; - case 'stopped': // stop接口后触发该状态机上报。 - console.info('AVPlayer state stopped called.'); - avPlayer.reset(); // 调用reset接口初始化avplayer状态。 - break; - case 'released': //播放接口后触发该状态机上报。 - console.info('AVPlayer state released called.'); - break; - default: - break; - } - }) - } - - // 通过url设置网络地址来实现播放直播码流。 - async avPlayerLiveDemo(){ - // 创建avPlayer实例对象 - let avPlayer: media.AVPlayer = await media.createAVPlayer(); - // 创建状态机变化回调函数。 - this.setAVPlayerCallback(avPlayer); - this.isSeek = false; // 不支持seek操作。 - // 使用时需要自行替换视频链接 - avPlayer.url = 'xxx/demo.mp4'; - } -} +/* + * 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 { media } from '@kit.MediaKit'; +import { BusinessError } from '@ohos.base'; + +export class AVPlayerDemo { + private count: number = 0; + private surfaceId: string = ''; // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法。 + private isSeek: boolean = true; // 用于区分模式是否支持seek操作。 + + setSurfaceID(id: string){ + console.log('setSurfaceID : ' + id); + this.surfaceId = id; + } + // 注册avplayer回调函数。 + setAVPlayerCallback(avPlayer: media.AVPlayer) { + // seek操作结果回调函数。 + avPlayer.on('seekDone', (seekDoneTime: number) => { + console.info(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`); + }) + // error回调监听函数,当avplayer在操作过程中出现错误时,调用reset接口触发重置流程。 + avPlayer.on('error', (err: BusinessError) => { + console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); + avPlayer.reset(); + }) + // 状态机变化回调函数。 + avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => { + switch (state) { + case 'idle': // 成功调用reset接口后触发该状态机上报。 + console.info('AVPlayer state idle called.'); + avPlayer.release(); // 调用release接口销毁实例对象。 + break; + case 'initialized': // avplayer 设置播放源后触发该状态上报。 + console.info('AVPlayer state initialized called.'); + avPlayer.surfaceId = this.surfaceId; // 设置显示画面,当播放的资源为纯音频时无需设置。 + avPlayer.prepare(); + break; + case 'prepared': // prepared调用成功后上报该状态机。 + console.info('AVPlayer state prepared called.'); + avPlayer.play(); // 调用播放接口开始播放。 + break; + case 'playing': // play成功调用后触发该状态机上报。 + console.info('AVPlayer state prepared called.'); + if(this.count !== 0) { + if (this.isSeek) { + console.info('AVPlayer start to seek.'); + avPlayer.seek(avPlayer.duration); // seek到视频末尾。 + } else { + // 当播放模式不支持seek操作时继续播放到结尾。 + console.info('AVPlayer wait to play end.'); + } + } else { + avPlayer.pause(); // 调用暂停接口暂停播放。 + } + this.count++; + break; + case 'paused': // pause成功调用后触发该状态机上报。 + console.info('AVPlayer state paused called.'); + avPlayer.play(); // 再次播放接口开始播放。 + break; + case 'completed': //播放接口后触发该状态机上报。 + console.info('AVPlayer state paused called.'); + avPlayer.stop(); // 调用播放接口接口。 + break; + case 'stopped': // stop接口后触发该状态机上报。 + console.info('AVPlayer state stopped called.'); + avPlayer.reset(); // 调用reset接口初始化avplayer状态。 + break; + case 'released': //播放接口后触发该状态机上报。 + console.info('AVPlayer state released called.'); + break; + default: + break; + } + }) + } + + // 通过url设置网络地址来实现播放直播码流。 + async avPlayerLiveDemo(){ + // 创建avPlayer实例对象 + let avPlayer: media.AVPlayer = await media.createAVPlayer(); + // 创建状态机变化回调函数。 + this.setAVPlayerCallback(avPlayer); + this.isSeek = false; // 不支持seek操作。 + // 使用时需要自行替换视频链接 + avPlayer.url = 'xxx/demo.mp4'; + } +} diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_one.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_one.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/ets/pages/RenderTxtBoxSameLayer_two.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 old mode 100755 new mode 100644 index 2c83e592f05cb9ca9a559f88072d1aa0994dc389..7c6d9ac0d5c9835d7df257bee8d08da59641f8e8 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/module.json5 @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "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" - } - ] - } - ], - "requestPermissions":[ - { - "name" : "ohos.permission.INTERNET" - } - ] - - } +/* + * 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" + } + ] + } + ], + "requestPermissions":[ + { + "name" : "ohos.permission.INTERNET" + } + ] + + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html old mode 100755 new mode 100644 index 767ff7705bbeb0a6898472c8557413c67ce5aebb..0417d261ed1318fd12c337cb4c18868d212c88b0 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test1.html @@ -1,33 +1,33 @@ - - - - - - - 同层渲染测试html - - - - - - - - - - - - - + + + + + + + 同层渲染测试html + + + + + + + + + + + + + diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html old mode 100755 new mode 100644 index 0b21253492a40cd3734f16fb3bea376a9bd29c71..a87df34562671a9c9c06b0cfe6161df49876b9ba --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test2.html @@ -1,33 +1,33 @@ - - - - - - - 同层渲染测试html - - - - - - - - - - - - - + + + + + + + 同层渲染测试html + + + + + + + + + + + + + diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html old mode 100755 new mode 100644 index 6216179164977c093b30c86b9b3b2918b17405db..641bb291f12a36c0fbaa7b68519c974494be2082 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/rawfile/test3.html @@ -1,29 +1,29 @@ - - - - - - 同层渲染测试html - - - -
-
- -
-
- + + + + + + 同层渲染测试html + + + +
+
+ +
+
+ \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/UseSameLayerRender/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UseSameLayerRender/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/UseSameLayerRender/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/UseSameLayerRender/hvigorfile.ts b/code/DocsSample/ArkWeb/UseSameLayerRender/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/oh-package.json5 b/code/DocsSample/ArkWeb/UseSameLayerRender/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/UseSameLayerRender/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UseSameLayerRender/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/UseSameLayerRender/ohosTest.md b/code/DocsSample/ArkWeb/UseSameLayerRender/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/screenshots/DrawXCompAVPBtn.png b/code/DocsSample/ArkWeb/UseSameLayerRender/screenshots/DrawXCompAVPBtn.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_one.png b/code/DocsSample/ArkWeb/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_one.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_two.png b/code/DocsSample/ArkWeb/UseSameLayerRender/screenshots/RenderTxtBoxSameLayer_two.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/.gitignore b/code/DocsSample/ArkWeb/UsingWebMultimedia/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/app.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/app.json5 old mode 100755 new mode 100644 index e797bbd562fe4fb0a76be7396e1f7e3dbc42d224..ed067223abed18cf6afb0dc022c9555edc5e3324 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/app.json5 @@ -1,25 +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.usingwebmultimedia", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.usingwebmultimedia", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index bff15b824ed9d072b855c7fb3cb98094a22274e6..201e95512e21670a1e1919950431b844e7376f2d --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UsingWebMultimedia" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UsingWebMultimedia" + } + ] +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/README.md b/code/DocsSample/ArkWeb/UsingWebMultimedia/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/build-profile.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/build-profile.json5 old mode 100755 new mode 100644 index 43f67ad37e65ddbcb3e97ece406f182f1b9c4d27..d5afe2afaefb379e978392276a326b2083b78b32 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/build-profile.json5 @@ -1,76 +1,76 @@ -/* -* 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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry2", - "srcPath": "./entry2", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "entry3", - "srcPath": "./entry3", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* +* 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry2", + "srcPath": "./entry2", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "entry3", + "srcPath": "./entry3", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/code-linter.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/.gitignore b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/build-profile.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/oh-package.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 6ba41b851a4ccce6796910b5d7cc45a4fcad6473..7582e04e8680aeb0224bcd7a2b42ed6932f80f29 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const ARK_WEB_MEDIA_LOG_INFO = 0x0000; -const ARK_WEB_MEDIA_LOG_ERROR = 0x0000; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(ARK_WEB_MEDIA_LOG_ERROR, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const ARK_WEB_MEDIA_LOG_INFO = 0x0000; +const ARK_WEB_MEDIA_LOG_ERROR = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(ARK_WEB_MEDIA_LOG_ERROR, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 2ed644a07665e9a4290f1a4c112d3178640d23e2..07890bf5a1996166c52502ac9b991ea114aa918d --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; - -const ARK_WEB_MEDIA_LOG_INFO = 0x0000; - -export default class EntryBackupAbility extends BackupExtensionAbility { - async onBackup() { - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'onBackup ok'); - } - - async onRestore(bundleVersion: BundleVersion) { - hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const ARK_WEB_MEDIA_LOG_INFO = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(ARK_WEB_MEDIA_LOG_INFO, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/module.json5 old mode 100755 new mode 100644 index 599faa0ffefbfb3e9485bc8bd14b8551eec817ac..54af2946ce321bd54d9423e8d3bd4543005f8dcc --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/module.json5 @@ -1,110 +1,110 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions":[ - { - "name" : "ohos.permission.CAMERA", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ] - } - }, - { - "name" : "ohos.permission.MICROPHONE", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ] - } - } - ], - "requestPermissions": [ - { - "name" : "ohos.permission.CAMERA", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ] - } - }, - { - "name" : "ohos.permission.MICROPHONE", - "reason": "$string:EntryAbility_desc", - "usedScene": { - "abilities": [ - "EntryAbility" - ] - } - }, - { - "name": "ohos.permission.INTERNET" - } - ] - - } +/* + * 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" + } + ] + } + ], + "requestPermissions":[ + { + "name" : "ohos.permission.CAMERA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + }, + { + "name" : "ohos.permission.MICROPHONE", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + } + ], + "requestPermissions": [ + { + "name" : "ohos.permission.CAMERA", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + }, + { + "name" : "ohos.permission.MICROPHONE", + "reason": "$string:EntryAbility_desc", + "usedScene": { + "abilities": [ + "EntryAbility" + ] + } + }, + { + "name": "ohos.permission.INTERNET" + } + ] + + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html old mode 100755 new mode 100644 index 3e4f8b4a2e9786dc76cfa11ffa0aa63b2760f8ce..9464d7b99d8a7202b56532f5a6fcd338b67ce151 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/rawfile/index.html @@ -1,45 +1,45 @@ - - - - - - - - - - -
- - - - + + + + + + + + + + +
+ + + + diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/UsingWebMultimedia/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/.gitignore b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/build-profile.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/build-profile.json5 old mode 100755 new mode 100644 index 154bdd087521da4954d20dc9aaabcfb3f032fb65..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/build-profile.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/hvigorfile.ts b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/obfuscation-rules.txt b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/obfuscation-rules.txt old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/oh-package.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/oh-package.json5 old mode 100755 new mode 100644 index 3fc6e6bee34614116bbbb42e7feaad0760b3fe1c..2944307304532e967f4956384cc91447f2c9bf8c --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/oh-package.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "name": "entry2", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* +* 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": "entry2", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets old mode 100755 new mode 100644 index 97f049833e8038360416009c62f83cdeb08cca19..ddb0ff63c5c3a81c48ef10d4840758207513efa9 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2ability/Entry2Ability.ets @@ -1,53 +1,53 @@ -/* - * 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 Entry2Ability 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 { - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - return; - } - // 保存 UIContext, 在后续的同层渲染绘制中会用到。 - AppStorage.setOrCreate('UIContext', windowStage.getMainWindowSync().getUIContext()); - }); - } - - 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'); - } -} +/* + * 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 Entry2Ability 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 { + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + return; + } + // 保存 UIContext, 在后续的同层渲染绘制中会用到。 + AppStorage.setOrCreate('UIContext', windowStage.getMainWindowSync().getUIContext()); + }); + } + + 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/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets old mode 100755 new mode 100644 index a9c5227a98f85362a6acd1da493248d0675e204f..f9a6b459004e1f1d0aefe9350f2c2ee907f66ff3 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/entry2backupability/Entry2BackupAbility.ets @@ -1,27 +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 Entry2BackupAbility 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)); - } +/* + * 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 Entry2BackupAbility 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/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets old mode 100755 new mode 100644 index 2708e2821ee54f560e2d0522c5f01169fa8d4488..11121d55c0a12fa2bc33696525556c3c33ec6d29 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/ets/pages/PlayerDemo.ets @@ -1,276 +1,276 @@ -/* - * 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 { media } from '@kit.MediaKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -export interface AVPlayerListener { - onPlaying() : void; - onPaused() : void; - onDurationChanged(duration: number) : void; - onBufferedTimeChanged(buffered: number) : void; - onTimeUpdate(time: number) : void; - onEnded() : void; - onError() : void; - onVideoSizeChanged(width: number, height: number): void; - onDestroyed(): void; -} - -interface PlayerParam { - url: string; - listener?: AVPlayerListener; - httpHeaders?: Record; -} - -interface PlayCommand { - func: Function; - name?: string; -} - -interface CheckPlayCommandResult { - ignore: boolean; - indexToRemove: number; -} - -export class AVPlayerDemo { - // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法 - private surfaceID: string = ''; - - public avPlayer?: media.AVPlayer; - public prepared: boolean = false; - - public commands: PlayCommand[] = []; - - setSurfaceID(id: string) { - console.log(`AVPlayerDemo.setSurfaceID : ${id}`); - this.surfaceID = id; - } - // 注册avplayer回调函数 - setAVPlayerCallback(avPlayer: media.AVPlayer, listener?: AVPlayerListener) { - // seek操作结果回调函数 - avPlayer.on('seekDone', (seekDoneTime: number) => { - console.info(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`); - }); - // error回调监听函数,当avPlayer在操作过程中出现错误时调用reset接口触发重置流程 - avPlayer.on('error', (err: BusinessError) => { - console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); - listener?.onError(); - avPlayer.reset(); // 调用reset重置资源,触发idle状态 - }); - // 状态机变化回调函数 - avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => { - switch (state) { - case 'idle': // 成功调用reset接口后触发该状态机上报 - console.info('AVPlayer state idle called.'); - avPlayer.release(); // 调用release接口销毁实例对象 - break; - case 'initialized': // avplayer 设置播放源后触发该状态上报 - console.info('AVPlayer state initialized called.'); - avPlayer.surfaceId = this.surfaceID; // 设置显示画面,当播放的资源为纯音频时无需设置 - avPlayer.prepare(); - break; - case 'prepared': // prepare调用成功后上报该状态机 - console.info('AVPlayer state prepared called.'); - this.prepared = true; - this.schedule(); - break; - case 'playing': // play成功调用后触发该状态机上报 - console.info('AVPlayer state playing called.'); - listener?.onPlaying(); - break; - case 'paused': // pause成功调用后触发该状态机上报 - console.info('AVPlayer state paused called.'); - listener?.onPaused(); - break; - case 'completed': // 播放结束后触发该状态机上报 - console.info('AVPlayer state completed called.'); - avPlayer.stop(); //调用播放结束接口 - break; - case 'stopped': // stop接口成功调用后触发该状态机上报 - console.info('AVPlayer state stopped called.'); - listener?.onEnded(); - break; - case 'released': - this.prepared = false; - listener?.onDestroyed(); - console.info('AVPlayer state released called.'); - break; - default: - console.info('AVPlayer state unknown called.'); - break; - } - }); - avPlayer.on('durationUpdate', (duration: number) => { - console.info(`AVPlayer state durationUpdate success,new duration is :${duration}`); - listener?.onDurationChanged(duration/1000); - }); - avPlayer.on('timeUpdate', (time:number) => { - listener?.onTimeUpdate(time/1000); - }); - avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { - console.info(`AVPlayer state bufferingUpdate success,and infoType value is:${infoType}, value is : ${value}`); - if (infoType == media.BufferingInfoType.BUFFERING_PERCENT) { - } - listener?.onBufferedTimeChanged(value); - }) - avPlayer.on('videoSizeChange', (width: number, height: number) => { - console.info(`AVPlayer state videoSizeChange success,and width is:${width}, height is : ${height}`); - listener?.onVideoSizeChanged(width, height); - }) - } - - // 以下demo为通过url设置网络地址来实现播放直播码流的demo - async avPlayerLiveDemo(playerParam: PlayerParam) { - // 创建avPlayer实例对象 - this.avPlayer = await media.createAVPlayer(); - // 创建状态机变化回调函数 - this.setAVPlayerCallback(this.avPlayer, playerParam.listener); - - let mediaSource: media.MediaSource = media.createMediaSourceWithUrl(playerParam.url, playerParam.httpHeaders); - let strategy: media.PlaybackStrategy = { - preferredWidth: 100, - preferredHeight: 100, - preferredBufferDuration: 100, - preferredHdr: false - }; - this.avPlayer.setMediaSource(mediaSource, strategy); - console.log(`AVPlayer url:[${playerParam.url}]`); - } - - schedule() { - if (!this.avPlayer) { - return; - } - if (!this.prepared) { - return; - } - if (this.commands.length > 0) { - let command = this.commands.shift(); - if (command) { - command.func(); - } - if (this.commands.length > 0) { - setTimeout(() => { - this.schedule(); - }); - } - } - } - - private checkCommand(selfName: string, oppositeName: string) { - let indexToRemove = -1; - let ignoreThisAction = false; - let index = this.commands.length - 1; - while (index >= 0) { - if (this.commands[index].name == selfName) { - ignoreThisAction = true; - break; - } - if (this.commands[index].name == oppositeName) { - indexToRemove = index; - break; - } - index--; - } - - let result : CheckPlayCommandResult = { - ignore: ignoreThisAction, - indexToRemove: indexToRemove, - }; - return result; - } - - play() { - let commandName = 'play'; - let checkResult = this.checkCommand(commandName, 'pause'); - if (checkResult.ignore) { - console.log(`AVPlayer ${commandName} ignored.`); - this.schedule(); - return; - } - if (checkResult.indexToRemove >= 0) { - let removedCommand = this.commands.splice(checkResult.indexToRemove, 1); - console.log(`AVPlayer ${JSON.stringify(removedCommand)} removed.`); - return; - } - this.commands.push({ func: ()=>{ - console.info('AVPlayer.play()'); - this.avPlayer?.play(); - }, name: commandName}); - this.schedule(); - } - pause() { - let commandName = 'pause'; - let checkResult = this.checkCommand(commandName, 'play'); - console.log(`checkResult:${JSON.stringify(checkResult)}`); - if (checkResult.ignore) { - console.log(`AVPlayer ${commandName} ignored.`); - this.schedule(); - return; - } - if (checkResult.indexToRemove >= 0) { - let removedCommand = this.commands.splice(checkResult.indexToRemove, 1); - console.log(`AVPlayer ${JSON.stringify(removedCommand)} removed.`); - return; - } - this.commands.push({ func: ()=>{ - console.info('AVPlayer.pause()'); - this.avPlayer?.pause(); - }, name: commandName}); - this.schedule(); - } - release() { - this.commands.push({ func: ()=>{ - console.info('AVPlayer.release()'); - this.avPlayer?.release(); - }}); - this.schedule(); - } - seek(time: number) { - this.commands.push({ func: ()=>{ - console.info(`AVPlayer.seek(${time})`); - this.avPlayer?.seek(time * 1000); - }}); - this.schedule(); - } - setVolume(volume: number) { - this.commands.push({ func: ()=>{ - console.info(`AVPlayer.setVolume(${volume})`); - this.avPlayer?.setVolume(volume); - }}); - this.schedule(); - } - setPlaybackRate(playbackRate: number) { - let speed = media.PlaybackSpeed.SPEED_FORWARD_1_00_X; - let delta = 0.05; - playbackRate += delta; - if (playbackRate < 1) { - speed = media.PlaybackSpeed.SPEED_FORWARD_0_75_X; - } else if (playbackRate < 1.25) { - speed = media.PlaybackSpeed.SPEED_FORWARD_1_00_X; - } else if (playbackRate < 1.5) { - speed = media.PlaybackSpeed.SPEED_FORWARD_1_25_X; - } else if (playbackRate < 2) { - speed = media.PlaybackSpeed.SPEED_FORWARD_1_75_X; - } else { - speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; - } - this.commands.push({ func: ()=>{ - console.info(`AVPlayer.setSpeed(${speed})`); - this.avPlayer?.setSpeed(speed); - }}); - this.schedule(); - } -} +/* + * 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 { media } from '@kit.MediaKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export interface AVPlayerListener { + onPlaying() : void; + onPaused() : void; + onDurationChanged(duration: number) : void; + onBufferedTimeChanged(buffered: number) : void; + onTimeUpdate(time: number) : void; + onEnded() : void; + onError() : void; + onVideoSizeChanged(width: number, height: number): void; + onDestroyed(): void; +} + +interface PlayerParam { + url: string; + listener?: AVPlayerListener; + httpHeaders?: Record; +} + +interface PlayCommand { + func: Function; + name?: string; +} + +interface CheckPlayCommandResult { + ignore: boolean; + indexToRemove: number; +} + +export class AVPlayerDemo { + // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法 + private surfaceID: string = ''; + + public avPlayer?: media.AVPlayer; + public prepared: boolean = false; + + public commands: PlayCommand[] = []; + + setSurfaceID(id: string) { + console.log(`AVPlayerDemo.setSurfaceID : ${id}`); + this.surfaceID = id; + } + // 注册avplayer回调函数 + setAVPlayerCallback(avPlayer: media.AVPlayer, listener?: AVPlayerListener) { + // seek操作结果回调函数 + avPlayer.on('seekDone', (seekDoneTime: number) => { + console.info(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`); + }); + // error回调监听函数,当avPlayer在操作过程中出现错误时调用reset接口触发重置流程 + avPlayer.on('error', (err: BusinessError) => { + console.error(`Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); + listener?.onError(); + avPlayer.reset(); // 调用reset重置资源,触发idle状态 + }); + // 状态机变化回调函数 + avPlayer.on('stateChange', async (state: string, reason: media.StateChangeReason) => { + switch (state) { + case 'idle': // 成功调用reset接口后触发该状态机上报 + console.info('AVPlayer state idle called.'); + avPlayer.release(); // 调用release接口销毁实例对象 + break; + case 'initialized': // avplayer 设置播放源后触发该状态上报 + console.info('AVPlayer state initialized called.'); + avPlayer.surfaceId = this.surfaceID; // 设置显示画面,当播放的资源为纯音频时无需设置 + avPlayer.prepare(); + break; + case 'prepared': // prepare调用成功后上报该状态机 + console.info('AVPlayer state prepared called.'); + this.prepared = true; + this.schedule(); + break; + case 'playing': // play成功调用后触发该状态机上报 + console.info('AVPlayer state playing called.'); + listener?.onPlaying(); + break; + case 'paused': // pause成功调用后触发该状态机上报 + console.info('AVPlayer state paused called.'); + listener?.onPaused(); + break; + case 'completed': // 播放结束后触发该状态机上报 + console.info('AVPlayer state completed called.'); + avPlayer.stop(); //调用播放结束接口 + break; + case 'stopped': // stop接口成功调用后触发该状态机上报 + console.info('AVPlayer state stopped called.'); + listener?.onEnded(); + break; + case 'released': + this.prepared = false; + listener?.onDestroyed(); + console.info('AVPlayer state released called.'); + break; + default: + console.info('AVPlayer state unknown called.'); + break; + } + }); + avPlayer.on('durationUpdate', (duration: number) => { + console.info(`AVPlayer state durationUpdate success,new duration is :${duration}`); + listener?.onDurationChanged(duration/1000); + }); + avPlayer.on('timeUpdate', (time:number) => { + listener?.onTimeUpdate(time/1000); + }); + avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { + console.info(`AVPlayer state bufferingUpdate success,and infoType value is:${infoType}, value is : ${value}`); + if (infoType == media.BufferingInfoType.BUFFERING_PERCENT) { + } + listener?.onBufferedTimeChanged(value); + }) + avPlayer.on('videoSizeChange', (width: number, height: number) => { + console.info(`AVPlayer state videoSizeChange success,and width is:${width}, height is : ${height}`); + listener?.onVideoSizeChanged(width, height); + }) + } + + // 以下demo为通过url设置网络地址来实现播放直播码流的demo + async avPlayerLiveDemo(playerParam: PlayerParam) { + // 创建avPlayer实例对象 + this.avPlayer = await media.createAVPlayer(); + // 创建状态机变化回调函数 + this.setAVPlayerCallback(this.avPlayer, playerParam.listener); + + let mediaSource: media.MediaSource = media.createMediaSourceWithUrl(playerParam.url, playerParam.httpHeaders); + let strategy: media.PlaybackStrategy = { + preferredWidth: 100, + preferredHeight: 100, + preferredBufferDuration: 100, + preferredHdr: false + }; + this.avPlayer.setMediaSource(mediaSource, strategy); + console.log(`AVPlayer url:[${playerParam.url}]`); + } + + schedule() { + if (!this.avPlayer) { + return; + } + if (!this.prepared) { + return; + } + if (this.commands.length > 0) { + let command = this.commands.shift(); + if (command) { + command.func(); + } + if (this.commands.length > 0) { + setTimeout(() => { + this.schedule(); + }); + } + } + } + + private checkCommand(selfName: string, oppositeName: string) { + let indexToRemove = -1; + let ignoreThisAction = false; + let index = this.commands.length - 1; + while (index >= 0) { + if (this.commands[index].name == selfName) { + ignoreThisAction = true; + break; + } + if (this.commands[index].name == oppositeName) { + indexToRemove = index; + break; + } + index--; + } + + let result : CheckPlayCommandResult = { + ignore: ignoreThisAction, + indexToRemove: indexToRemove, + }; + return result; + } + + play() { + let commandName = 'play'; + let checkResult = this.checkCommand(commandName, 'pause'); + if (checkResult.ignore) { + console.log(`AVPlayer ${commandName} ignored.`); + this.schedule(); + return; + } + if (checkResult.indexToRemove >= 0) { + let removedCommand = this.commands.splice(checkResult.indexToRemove, 1); + console.log(`AVPlayer ${JSON.stringify(removedCommand)} removed.`); + return; + } + this.commands.push({ func: ()=>{ + console.info('AVPlayer.play()'); + this.avPlayer?.play(); + }, name: commandName}); + this.schedule(); + } + pause() { + let commandName = 'pause'; + let checkResult = this.checkCommand(commandName, 'play'); + console.log(`checkResult:${JSON.stringify(checkResult)}`); + if (checkResult.ignore) { + console.log(`AVPlayer ${commandName} ignored.`); + this.schedule(); + return; + } + if (checkResult.indexToRemove >= 0) { + let removedCommand = this.commands.splice(checkResult.indexToRemove, 1); + console.log(`AVPlayer ${JSON.stringify(removedCommand)} removed.`); + return; + } + this.commands.push({ func: ()=>{ + console.info('AVPlayer.pause()'); + this.avPlayer?.pause(); + }, name: commandName}); + this.schedule(); + } + release() { + this.commands.push({ func: ()=>{ + console.info('AVPlayer.release()'); + this.avPlayer?.release(); + }}); + this.schedule(); + } + seek(time: number) { + this.commands.push({ func: ()=>{ + console.info(`AVPlayer.seek(${time})`); + this.avPlayer?.seek(time * 1000); + }}); + this.schedule(); + } + setVolume(volume: number) { + this.commands.push({ func: ()=>{ + console.info(`AVPlayer.setVolume(${volume})`); + this.avPlayer?.setVolume(volume); + }}); + this.schedule(); + } + setPlaybackRate(playbackRate: number) { + let speed = media.PlaybackSpeed.SPEED_FORWARD_1_00_X; + let delta = 0.05; + playbackRate += delta; + if (playbackRate < 1) { + speed = media.PlaybackSpeed.SPEED_FORWARD_0_75_X; + } else if (playbackRate < 1.25) { + speed = media.PlaybackSpeed.SPEED_FORWARD_1_00_X; + } else if (playbackRate < 1.5) { + speed = media.PlaybackSpeed.SPEED_FORWARD_1_25_X; + } else if (playbackRate < 2) { + speed = media.PlaybackSpeed.SPEED_FORWARD_1_75_X; + } else { + speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; + } + this.commands.push({ func: ()=>{ + console.info(`AVPlayer.setSpeed(${speed})`); + this.avPlayer?.setSpeed(speed); + }}); + this.schedule(); + } +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/module.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/module.json5 old mode 100755 new mode 100644 index 395d1acd094be0dbc973b4ad85c9bb384dae55e6..8b99132eae7ead0171b7952619e38a38db15406e --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/module.json5 @@ -1,70 +1,70 @@ -/* -* 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": "entry2", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "Entry2Ability", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry2Ability", - "srcEntry": "./ets/entry2ability/Entry2Ability.ets", - "description": "$string:Entry2Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry2Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "Entry2BackupAbility", - "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* +* 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": "entry2", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry2Ability", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry2Ability", + "srcEntry": "./ets/entry2ability/Entry2Ability.ets", + "description": "$string:Entry2Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry2Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry2BackupAbility", + "srcEntry": "./ets/entry2backupability/Entry2BackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html old mode 100755 new mode 100644 index dde8aedb68a7652531154340fd9246c982697b9e..f87d2d199170c56b2219813f0ff5788b3a7fe1ab --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/main/resources/rawfile/main.html @@ -1,27 +1,27 @@ - - - - - 视频托管测试html - - - -
- - -
- - + + + + + 视频托管测试html + + + +
+ + +
+ + diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 72b1fd5f3684cea2e82f57db638bbb25410916a1..275d4a7e53feffc965753732f517aa2fb1a9ba7e --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "module": { - "name": "entry2_test", - "type": "feature", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* +* 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": "entry2_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/test/List.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry2/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/build-profile.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/build-profile.json5 index 154bdd087521da4954d20dc9aaabcfb3f032fb65..9edfdf8c4a72db3313433e7366df25b6beb1c3a7 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/build-profile.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/build-profile.json5 @@ -1,43 +1,43 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/oh-package.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/oh-package.json5 index f34ecb68859fd59624be4c429be709718643951c..fdde2dca53a66167a411ea77e7804f0200b86663 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/oh-package.json5 @@ -1,25 +1,25 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "name": "entry3", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* +* 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": "entry3", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.ets index 5b2c6720cb3b223133036558d2615d757c8f9506..94de6f8cdbcc8368475625ab2473f464389fa297 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3ability/Entry3Ability.ets @@ -1,58 +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. - */ - -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const DOMAIN = 0x0000; - -export default class Entry3Ability extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); - return; - } - hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class Entry3Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.ets b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.ets index 1b3eee2847305f242191265c53bba19675eaa8e3..0370ffb34e8c7f6d75ff139c8bbed7aa57f739e3 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.ets +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/ets/entry3backupability/Entry3BackupAbility.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; - -const DOMAIN = 0x0000; - -export default class Entry3BackupAbility extends BackupExtensionAbility { - async onBackup() { - hilog.info(DOMAIN, 'testTag', 'onBackup ok'); - await Promise.resolve(); - } - - async onRestore(bundleVersion: BundleVersion) { - hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); - await Promise.resolve(); - } +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class Entry3BackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/module.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/module.json5 index 7cdc77b7fa16e8be82737e366d7bd21cbd3ec4ac..405a5183ab930aa877b589758a75862a2822a6fe 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/module.json5 @@ -1,65 +1,65 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "module": { - "name": "entry3", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "Entry3Ability", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "Entry3Ability", - "srcEntry": "./ets/entry3ability/Entry3Ability.ets", - "description": "$string:Entry3Ability_desc", - "icon": "$media:layered_image", - "label": "$string:Entry3Ability_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "Entry3BackupAbility", - "srcEntry": "./ets/entry3backupability/Entry3BackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ] - } +/* +* 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": "entry3", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "Entry3Ability", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Entry3Ability", + "srcEntry": "./ets/entry3ability/Entry3Ability.ets", + "description": "$string:Entry3Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Entry3Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "Entry3BackupAbility", + "srcEntry": "./ets/entry3backupability/Entry3BackupAbility.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/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json index a8a5d404dcd8b0466194afc3aa25d90a8a327470..33ea22304f9b1485b5f22d811023701b5d4e35b6 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/element/float.json @@ -1,8 +1,8 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] -} +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html index 7bf4266df60eb8040ca1cedea940dd3f8e6d3581..bf46d9515a2d629dab31874485d53520bba0c035 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/main/resources/rawfile/PictureInPicture.html @@ -1,87 +1,87 @@ - - - - - - - Picture-in-Picture Demo - - - - - - - - - - + + + + + + + Picture-in-Picture Demo + + + + + + + + + + \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/ohosTest/module.json5 index 86214f17e0af29863c4a4cbe9f92ee242dbed5e9..33e7ebcfda25a462ba4f3739cc88fac6f545c4d5 100644 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/entry3/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -{ - "module": { - "name": "entry3_test", - "type": "feature", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false - } -} +/* +* 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": "entry3_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/UsingWebMultimedia/hvigorfile.ts b/code/DocsSample/ArkWeb/UsingWebMultimedia/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/oh-package.json5 b/code/DocsSample/ArkWeb/UsingWebMultimedia/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/UsingWebMultimedia/oh-package.json5 +++ b/code/DocsSample/ArkWeb/UsingWebMultimedia/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/UsingWebMultimedia/ohosTest.md b/code/DocsSample/ArkWeb/UsingWebMultimedia/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_1.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_2.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_3.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/HoldVideoConfWebRTC_3.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/TakeOverMediaPlay.png b/code/DocsSample/ArkWeb/UsingWebMultimedia/screenshots/TakeOverMediaPlay.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/.gitignore b/code/DocsSample/ArkWeb/WebRenderLayout/.gitignore old mode 100755 new mode 100644 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..d2ff20141ceed86d87c0ea5d99481973005bab2b --- a/code/DocsSample/ArkWeb/WebRenderLayout/.gitignore +++ b/code/DocsSample/ArkWeb/WebRenderLayout/.gitignore @@ -1,12 +1,12 @@ -/node_modules -/oh_modules -/local.properties -/.idea -**/build -/.hvigor -.cxx -/.clangd -/.clang-format -/.clang-tidy -**/.test +/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/ArkWeb/WebRenderLayout/AppScope/app.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/app.json5 old mode 100755 new mode 100644 index d00f94d308767c0c8608346bc50966d0b61ff5a1..05d4077ce4a7d7033ee498e91542b02a57098a33 --- a/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/app.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/app.json5 @@ -1,25 +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.webrenderlayout", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.webrenderlayout", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json b/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 60150165cd7523c9007d98210fe9e399e858be12..d141695c97a80ba162c219dfd4c5afa0b1ae7772 --- a/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "WebRenderLayout" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "WebRenderLayout" + } + ] +} diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkWeb/WebRenderLayout/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/README.md b/code/DocsSample/ArkWeb/WebRenderLayout/README.md old mode 100755 new mode 100644 index 840e942011e335332ba315a37413a9d3a144a4a5..15a85277b81169d5f68dac91894d21f4eddd7da5 --- a/code/DocsSample/ArkWeb/WebRenderLayout/README.md +++ b/code/DocsSample/ArkWeb/WebRenderLayout/README.md @@ -1,78 +1,78 @@ -# Web组件渲染模式 - -## RenderMode - -### 介绍 - -1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-render-mode.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 - -### 效果预览 - -| 主页 | -| ------------------------------------------------------------ | -| | - -使用说明 - -1. 使用renderMode设置渲染模式为 ASYNC_RENDER (同步渲染模式)。 -# Web组件大小自适应页面内容布局 - -## FitPageContent - -### 介绍 - -1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-fit-content.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 - -### 效果预览 - -| 主页 | -| --------------------------------------------------------- | -| | - -使用说明 - -1. 使用Web组件大小自适应页面内容布局模式layoutMode(WebLayoutMode.FIT_CONTENT)时,能使Web组件的大小根据页面内容自适应变化。 - -## 工程目录 - -``` -entry/src/main/ -|---ets -|---|---entryability -|---|---|---EntryAbility.ets -|---|---pages -|---|---|---Index.ets // 首页 -|---|---|---FitPageContent.ets -|---|---|---RenderMode.ets -|---resources // 静态资源 -|---ohosTest -|---|---ets -|---|---|---tests -|---|---|---|---Ability.test.ets // 自动化测试用例 -``` - -## 相关权限 - -[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) - -## 依赖 - -不涉及。 - -## 约束与限制 - -1. 本示例仅支持标准系统上运行,支持设备:RK3568。 -2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 -3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 - -## 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/DocsSample/ArkWeb/WebRenderLayout > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# Web组件渲染模式 + +## RenderMode + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-render-mode.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | +| ------------------------------------------------------------ | +| | + +使用说明 + +1. 使用renderMode设置渲染模式为 ASYNC_RENDER (同步渲染模式)。 +# Web组件大小自适应页面内容布局 + +## FitPageContent + +### 介绍 + +1. 实现对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/web/web-fit-content.md 示例代码片段的工程化,保证指南中示例代码与sample工程文件同源。 + +### 效果预览 + +| 主页 | +| --------------------------------------------------------- | +| | + +使用说明 + +1. 使用Web组件大小自适应页面内容布局模式layoutMode(WebLayoutMode.FIT_CONTENT)时,能使Web组件的大小根据页面内容自适应变化。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---FitPageContent.ets +|---|---|---RenderMode.ets +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---Ability.test.ets // 自动化测试用例 +``` + +## 相关权限 + +[ohos.permission.INTERNET](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioninternet) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 +3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkWeb/WebRenderLayout > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/build-profile.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/build-profile.json5 old mode 100755 new mode 100644 index 87d40a385e30dc461bee671328ee541abfafd5de..7a9c78377eb963833422d699676b8fb5b20bae29 --- a/code/DocsSample/ArkWeb/WebRenderLayout/build-profile.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/build-profile.json5 @@ -1,52 +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. - */ - -{ - "app": { - "signingConfigs": [], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + } + ], + "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/ArkWeb/WebRenderLayout/code-linter.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/code-linter.json5 old mode 100755 new mode 100644 index 9deb9807637aa27ebde62e61e2362a417aacdc04..28586467ee7a761c737d8654a73aed6fddbc3c71 --- a/code/DocsSample/ArkWeb/WebRenderLayout/code-linter.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/code-linter.json5 @@ -1,35 +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": { - } +/* + * 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/ArkWeb/WebRenderLayout/entry/.gitignore b/code/DocsSample/ArkWeb/WebRenderLayout/entry/.gitignore old mode 100755 new mode 100644 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..e2713a2779c5a3e0eb879efe6115455592caeea5 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/.gitignore +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/.gitignore @@ -1,6 +1,6 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx +/node_modules +/oh_modules +/.preview +/build +/.cxx /.test \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/build-profile.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/build-profile.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/hvigorfile.ts b/code/DocsSample/ArkWeb/WebRenderLayout/entry/hvigorfile.ts old mode 100755 new mode 100644 index c9362b128ef10dad414a66d2df1069c8885b336f..98d52319cb1dee60511b5716dba03b76e68a6d8b --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/hvigorfile.ts +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/hvigorfile.ts @@ -1,21 +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. */ -} +/* +* 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/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt b/code/DocsSample/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt old mode 100755 new mode 100644 index 5ff2b5d0b0fe2e3d2559f39a7a8ad5a94745af6e..272efb6ca3f240859091bbbfc7c5802d52793b0b --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/obfuscation-rules.txt @@ -1,23 +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 +# 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/ArkWeb/WebRenderLayout/entry/oh-package.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/oh-package.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b23d2fe946b5f93ddc577864f9da7c6516f59209..0f2f8b94aa24b0a50e272270e4e18b6df93ac5fd --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,56 +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'); - } -} +/* + * 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/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets old mode 100755 new mode 100644 index 6afd79e917a37e6460965d058326319ff7a51cfc..a11946370009fc85fbdd124a6a6d667643484bdb --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/FitPageContent.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct WebHeightPage { - private webviewController: WebviewController = new webview.WebviewController(); - private scroller: Scroller = new Scroller(); - - build() { - Navigation() { - Column() { - Scroll(this.scroller) { - Column() { - Web({ - src: $rawfile('fit_content.html'), - controller: this.webviewController, - renderMode: RenderMode.SYNC_RENDER // 设置为同步渲染模式 - }) - .layoutMode(WebLayoutMode.FIT_CONTENT)// 设置为Web组件大小自适应页面内容 - .overScrollMode(OverScrollMode.NEVER) // 设置过滚动模式为关闭状态 - Text($r('app.string.Comment_area')) - .fontSize(28) - .fontColor('#FF0F0F') - .height(100) - .width('100%') - .backgroundColor('#f89f0f') - } - } - } - } - .title($r('app.string.Title_bar')) - } -} +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebHeightPage { + private webviewController: WebviewController = new webview.WebviewController(); + private scroller: Scroller = new Scroller(); + + build() { + Navigation() { + Column() { + Scroll(this.scroller) { + Column() { + Web({ + src: $rawfile('fit_content.html'), + controller: this.webviewController, + renderMode: RenderMode.SYNC_RENDER // 设置为同步渲染模式 + }) + .layoutMode(WebLayoutMode.FIT_CONTENT)// 设置为Web组件大小自适应页面内容 + .overScrollMode(OverScrollMode.NEVER) // 设置过滚动模式为关闭状态 + Text($r('app.string.Comment_area')) + .fontSize(28) + .fontColor('#FF0F0F') + .height(100) + .width('100%') + .backgroundColor('#f89f0f') + } + } + } + } + .title($r('app.string.Title_bar')) + } +} diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 1092ee0ead4520c2302dfdf46a218c6054f46f5b..df919e917f89291db2860580991977a30666f74e --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/Index.ets @@ -1,35 +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. - */ - -import { router } from '@kit.ArkUI'; -import { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct Index { - build() { - Column({ space: 10 }) { - Button('RenderMode') - .onClick(() => { - router.pushUrl({ url: 'pages/RenderMode' }); - }) - Button('FitPageContent') - .onClick(() => { - router.pushUrl({ url: 'pages/FitPageContent' }); - }) - }.height('100%') - .width('100%') - } +/* + * 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 { router } from '@kit.ArkUI'; +import { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct Index { + build() { + Column({ space: 10 }) { + Button('RenderMode') + .onClick(() => { + router.pushUrl({ url: 'pages/RenderMode' }); + }) + Button('FitPageContent') + .onClick(() => { + router.pushUrl({ url: 'pages/FitPageContent' }); + }) + }.height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets old mode 100755 new mode 100644 index 6cbb325ceaa95f90bab40c48efed24fedee42b45..b81cea5a74dd2d3472ed092f812d36a1682b187e --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/ets/pages/RenderMode.ets @@ -1,32 +1,32 @@ -/* - * 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 { webview } from '@kit.ArkWeb'; - -@Entry -@Component -struct WebHeightPage { - private webviewController: WebviewController = new webview.WebviewController() - - build() { - Column() { - Web({ - src: 'www.example.com', - controller: this.webviewController, - renderMode: RenderMode.ASYNC_RENDER // 设置渲染模式 - }) - } - } +/* + * 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 { webview } from '@kit.ArkWeb'; + +@Entry +@Component +struct WebHeightPage { + private webviewController: WebviewController = new webview.WebviewController() + + build() { + Column() { + Web({ + src: 'www.example.com', + controller: this.webviewController, + renderMode: RenderMode.ASYNC_RENDER // 设置渲染模式 + }) + } + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/module.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/module.json5 old mode 100755 new mode 100644 index 81751d0bc4dd4f2a057a34d8d37bb8c1396fcf7e..e9db80c0ac2d7edb8e5ed53f5e5eb5ccbb272a57 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/module.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.INTERNET" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 index f23e751204ee4765a91f2c3fdbde98042c2bfd53..6e797f7e8ed5cd498631cffb6be41435d3a4c35f --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/element/string.json @@ -1,24 +1,24 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "WebRenderLayout" - }, - { - "name": "Title_bar", - "value": "标题栏" - }, - { - "name": "Comment_area", - "value": "评论区" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "WebRenderLayout" + }, + { + "name": "Title_bar", + "value": "标题栏" + }, + { + "name": "Comment_area", + "value": "评论区" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/background.png b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..fb49920440fb4d246c82f9ada275e26123a2136a --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/layered_image.json @@ -1,7 +1,7 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 index 448826afada5bf5f252127b924ffd39625c19f65..a632b71f19e592ae7862ebda48f5b871bd93c7b9 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,7 @@ -{ - "src": [ - "pages/Index", - "pages/FitPageContent", - "pages/RenderMode" - ] -} +{ + "src": [ + "pages/Index", + "pages/FitPageContent", + "pages/RenderMode" + ] +} diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 index 28c2ed941a1de71252e6da754b8833b5778e0b7d..f618771a19f0dffbca09170f416db1ff866c5972 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/en_US/element/string.json @@ -1,16 +1,16 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "WebRenderLayout" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "WebRenderLayout" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html old mode 100755 new mode 100644 index ff8af6e0c91e6fe616310a0af392288250bab42a..46c149ed86bd171a04921aed7d9c4dc5b927eccf --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/rawfile/fit_content.html @@ -1,63 +1,63 @@ - - - - - - - - Fit-Content - - -
-

使用场景

-

ArkWeb(方舟Web)提供了Web组件,用于在应用程序中显示Web页面内容。常见使用场景包括:

-
    -
  • - 应用集成Web页面:应用可以在页面中使用Web组件,嵌入Web页面内容,以降低开发成本,提升开发、运营效率。

    -
  • -
  • - 浏览器网页浏览场景:浏览器类应用可以使用Web组件,打开三方网页,使用无痕模式浏览Web页面,设置广告拦截等。

    -
  • -
  • 小程序:小程序类宿主应用可以使用Web组件,渲染小程序的页面。

  • -
-
-

能力范围

-

Web组件为开发者提供了丰富的控制Web页面能力。包括:

-
    -
  • Web页面加载:声明式加载Web页面和离屏加载Web页面等。

  • -
  • 生命周期管理:组件生命周期状态变化,通知Web页面的加载状态变化等。

  • -
  • 常用属性与事件:UserAgent管理、Cookie与存储管理、字体与深色模式管理、权限管理等。

    -
  • -
  • - 与应用界面交互:自定义文本选择菜单、上下文菜单、文件上传界面等与应用界面交互能力。

    -
  • -
  • App通过JavaScriptProxy,与Web页面进行JavaScript交互。

  • -
  • 安全与隐私:无痕浏览模式、广告拦截、坚盾守护模式等。

  • -
  • 维测能力:DevTools工具调试能力,使用crashpad收集Web组件崩溃信息。 -

  • -
  • - 其他高阶能力:与原生组件同层渲染、Web组件的网络托管、Web组件的媒体播放托管、Web组件输入框拉起自定义输入法、等。

    -
  • -
-
-

约束与限制

-
    -
  • Web内核版本:ArkWeb基于谷歌Chromium内核开发,使用的Chromium版本为M114。
  • -
-
-
- - + + + + + + + + Fit-Content + + +
+

使用场景

+

ArkWeb(方舟Web)提供了Web组件,用于在应用程序中显示Web页面内容。常见使用场景包括:

+
    +
  • + 应用集成Web页面:应用可以在页面中使用Web组件,嵌入Web页面内容,以降低开发成本,提升开发、运营效率。

    +
  • +
  • + 浏览器网页浏览场景:浏览器类应用可以使用Web组件,打开三方网页,使用无痕模式浏览Web页面,设置广告拦截等。

    +
  • +
  • 小程序:小程序类宿主应用可以使用Web组件,渲染小程序的页面。

  • +
+
+

能力范围

+

Web组件为开发者提供了丰富的控制Web页面能力。包括:

+
    +
  • Web页面加载:声明式加载Web页面和离屏加载Web页面等。

  • +
  • 生命周期管理:组件生命周期状态变化,通知Web页面的加载状态变化等。

  • +
  • 常用属性与事件:UserAgent管理、Cookie与存储管理、字体与深色模式管理、权限管理等。

    +
  • +
  • + 与应用界面交互:自定义文本选择菜单、上下文菜单、文件上传界面等与应用界面交互能力。

    +
  • +
  • App通过JavaScriptProxy,与Web页面进行JavaScript交互。

  • +
  • 安全与隐私:无痕浏览模式、广告拦截、坚盾守护模式等。

  • +
  • 维测能力:DevTools工具调试能力,使用crashpad收集Web组件崩溃信息。 +

  • +
  • + 其他高阶能力:与原生组件同层渲染、Web组件的网络托管、Web组件的媒体播放托管、Web组件输入框拉起自定义输入法、等。

    +
  • +
+
+

约束与限制

+
    +
  • Web内核版本:ArkWeb基于谷歌Chromium内核开发,使用的Chromium版本为M114。
  • +
+
+
+ + diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 index 1e50186edc11beebfe93b69dcf1a472eda98c2e0..8b827c36ef821c56b3e6ef65fd4d64627a4a978b --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/main/resources/zh_CN/element/string.json @@ -1,16 +1,16 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "WebRenderLayout" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "WebRenderLayout" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 index aba5ed077b5cdc929a22668da42747a98504034a..b9a78e201535765168a92d3543c690273ecdc019 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/mock/mock-config.json5 @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 index 136bd3e551456c561aeaa7a557200d94873e744b..1375e7a47ea13527ce438c9327cb82226ebfed3e --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,97 +1,97 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; -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', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - - /* - * 打开应用,点击 RenderMode 按钮 - * 使用renderMode设置渲染模式为同步渲染模式 - */ - it('RenderMode',0, async (done: Function) => { - console.info('uitest: RenderMode begin'); - const want: Want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - await driver.delayMs(5000); - - const button1 = await driver.findComponent(ON.text('RenderMode')); - await button1.click(); - await driver.delayMs(1000); - - const web1 = await driver.findComponent(ON.type('Web')); - let src: string = await web1.getText(); - expect(src).assertContain('www.example.com'); - - await driver.pressBack(); - console.info('uitest: RenderMode end'); - done(); - }); - - /* - * 点击 FitPageContent 按钮 - * 使用Web组件大小自适应页面内容布局模式使Web组件的大小根据页面内容自适应变化 - */ - it('FitPageContent',0, async (done: Function) => { - console.info('uitest: FitPageContent begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - - const button1 = await driver.findComponent(ON.text('FitPageContent')); - await button1.click(); - await driver.delayMs(1000); - - const web1 = await driver.findComponent(ON.type('Web')); - let src: string = await web1.getText(); - expect(src).assertContain('fit_content.html'); - - await driver.pressBack(); - console.info('uitest: FitPageContent end'); - done(); - }); - }) -} +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +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', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /* + * 打开应用,点击 RenderMode 按钮 + * 使用renderMode设置渲染模式为同步渲染模式 + */ + it('RenderMode',0, async (done: Function) => { + console.info('uitest: RenderMode begin'); + const want: Want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + await driver.delayMs(5000); + + const button1 = await driver.findComponent(ON.text('RenderMode')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('www.example.com'); + + await driver.pressBack(); + console.info('uitest: RenderMode end'); + done(); + }); + + /* + * 点击 FitPageContent 按钮 + * 使用Web组件大小自适应页面内容布局模式使Web组件的大小根据页面内容自适应变化 + */ + it('FitPageContent',0, async (done: Function) => { + console.info('uitest: FitPageContent begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + + const button1 = await driver.findComponent(ON.text('FitPageContent')); + await button1.click(); + await driver.delayMs(1000); + + const web1 = await driver.findComponent(ON.type('Web')); + let src: string = await web1.getText(); + expect(src).assertContain('fit_content.html'); + + await driver.pressBack(); + console.info('uitest: FitPageContent end'); + done(); + }); + }) +} diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 index a10a79ed1d91b6040cc81d926b62c250e8f3866d..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +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(); +/* + * 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/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets old mode 100755 new mode 100644 index 234f7bd3c746fcb3f90e852a2a7099ecc01e730c..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/List.test.ets @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import localUnitTest from './LocalUnit.test'; - -export default function testsuite() { - localUnitTest(); +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 index 05912c780dc1638f69dcd41b8498ce91304edc5d..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- a/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets +++ b/code/DocsSample/ArkWeb/WebRenderLayout/entry/src/test/LocalUnit.test.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function localUnitTest() { - describe('localUnitTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }); - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }); - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }); - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }); - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }); - }); +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); } \ No newline at end of file diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index c61d3eed60978a00d9a67b754ec36c0c9dcde929..43beb743cbd25c3507b1cf8a744bf8197b3bf2fb --- a/code/DocsSample/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/hvigor/hvigor-config.json5 @@ -1,37 +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.0", - "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*/ - } -} +/* + * 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": { + }, + "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/ArkWeb/WebRenderLayout/hvigorfile.ts b/code/DocsSample/ArkWeb/WebRenderLayout/hvigorfile.ts old mode 100755 new mode 100644 index f82b71dd9d0056dd6780708b50bc34fb11f6cd74..1307c03303328d961439d1f6983b09e728b5e8ce --- a/code/DocsSample/ArkWeb/WebRenderLayout/hvigorfile.ts +++ b/code/DocsSample/ArkWeb/WebRenderLayout/hvigorfile.ts @@ -1,21 +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. */ -} +/* +* 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/ArkWeb/WebRenderLayout/oh-package.json5 b/code/DocsSample/ArkWeb/WebRenderLayout/oh-package.json5 old mode 100755 new mode 100644 index 4c8bad9bdbdd8da17793a0e43f29d9e7232dce00..93f097993a458e967d6d5239ea0580e79b5d6998 --- a/code/DocsSample/ArkWeb/WebRenderLayout/oh-package.json5 +++ b/code/DocsSample/ArkWeb/WebRenderLayout/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/DocsSample/ArkWeb/WebRenderLayout/ohosTest.md b/code/DocsSample/ArkWeb/WebRenderLayout/ohosTest.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/screenshots/FitPageContent.png b/code/DocsSample/ArkWeb/WebRenderLayout/screenshots/FitPageContent.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/ArkWeb/WebRenderLayout/screenshots/RenderModeWebComp.png b/code/DocsSample/ArkWeb/WebRenderLayout/screenshots/RenderModeWebComp.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/app.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/app.json5 index da5f910f00d95baa58178d920cd5c6c29a51634d..50601e9feb2188b80dbb0f1e8a84ac36077a2091 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/app.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.harsample", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.harsample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/resources/base/element/string.json b/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/resources/base/element/string.json index 0f9315e13721eb96c5d2065abf2187a3bf626889..6b9925cc18dbcb1dec4fc04e39ae4dbcd97a62a1 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/resources/base/element/string.json +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "HarSample" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "HarSample" + } + ] +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/build-profile.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/build-profile.json5 index d2571bfa54904c1a1b0719f525bf54a5dada57e3..480c508183cc8bb06d8c9518048becb268afc9ac 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/build-profile.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/build-profile.json5 @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "library", - "srcPath": "./library" - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "library", + "srcPath": "./library" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/build-profile.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/build-profile.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/oh-package.json5 index 45159edb792eca7841e3934523912550acf057c2..c8286b9e1d2d4642b250a74e26b2c2a112339ccd 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "library": "file:../library" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "library": "file:../library" + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/entryability/EntryAbility.ts index 714d4b5563974e401e79837509e426170c4518c8..964a26f8692bcd446b020735a8a929241f44a109 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Logger from '../logger/Logger'; - -const TAG = 'EntryAbility'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - Logger.info(TAG, `Ability onCreate want: ${JSON.stringify(want)}`, `launchParam: ${JSON.stringify(launchParam)}`); - } - - onDestroy() { - Logger.info(TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - Logger.info(TAG, 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(TAG, `Failed to load the content. Cause: ${JSON.stringify(err)}`); - return; - } - Logger.info(TAG, `Succeeded in loading the content. Data: ${JSON.stringify(data)}`); - }); - } - - onWindowStageDestroy() { - Logger.info(TAG, 'Ability onWindowStageDestroy'); - } - - onForeground() { - Logger.info(TAG, 'Ability onForeground'); - } - - onBackground() { - Logger.info(TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Logger from '../logger/Logger'; + +const TAG = 'EntryAbility'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + Logger.info(TAG, `Ability onCreate want: ${JSON.stringify(want)}`, `launchParam: ${JSON.stringify(launchParam)}`); + } + + onDestroy() { + Logger.info(TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + Logger.info(TAG, 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(TAG, `Failed to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + Logger.info(TAG, `Succeeded in loading the content. Data: ${JSON.stringify(data)}`); + }); + } + + onWindowStageDestroy() { + Logger.info(TAG, 'Ability onWindowStageDestroy'); + } + + onForeground() { + Logger.info(TAG, 'Ability onForeground'); + } + + onBackground() { + Logger.info(TAG, 'Ability onBackground'); + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/logger/Logger.ts b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/logger/Logger.ts index 6801aa8031b487f9e0e385cbb77b7f93cf765a1c..c973e6b26637063800ee916a72f657fcdebaa84f 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/logger/Logger.ts +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/ets/logger/Logger.ts @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -export class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_HarSample]'); \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/module.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/module.json5 index a61f5cbf7c93e99ea7adb05d04f9bf9a4c3e3756..bac72d95926679c3199ad00b9457707b6970fe38 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/module.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/resources/base/element/color.json b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/resources/base/element/color.json index 5682f26b177b6f7a24e260570819ee4d9bf7a733..20bf6d89a9020d7adc9ad29743f546ff411978e6 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/main/resources/base/element/color.json @@ -1,20 +1,20 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "page_background", - "value": "#F1F3F5" - }, - { - "name": "button_background", - "value": "#007DFF" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "page_background", + "value": "#F1F3F5" + }, + { + "name": "button_background", + "value": "#007DFF" + }, + { + "name": "text_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/ets/logger/Logger.ts b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/ets/logger/Logger.ts index 6f2887b72105d2264b705516afc6e48c123e63c2..59fa81f6987d71201ec98d4e29d68634eb8eda8b 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/ets/logger/Logger.ts +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/ets/logger/Logger.ts @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -export class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_HarSample_Test]'); \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/module.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/hvigor/hvigor-config.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/hvigor/hvigor-config.json5 index 7fcecec159df6759049a45fd7a400d1fbaffeab4..dba571014f1a9610f06d593adbcdf6c0097948e6 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/hvigor/hvigor-config.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/build-profile.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/library/build-profile.json5 index e9c00838cf4cbd3f73ae3dbfbb526c0af7f4717c..833db6086ec120d486862539d030af918471d030 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/build-profile.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/build-profile.json5 @@ -1,35 +1,35 @@ -/* - * Copyright (c) 2023-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", - "armeabi-v7a" - ] - }, - }, - "targets": [ - { - "name": "default" - } - ] -} +/* + * Copyright (c) 2023-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", + "armeabi-v7a" + ] + }, + }, + "targets": [ + { + "name": "default" + } + ] +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/index.ets b/code/DocsSample/BundleManagerDocsSample/HarSample/library/index.ets index 5c2adbf8c4ad6ae0fe5dd8ce5853b4f1f284ef03..ab44ac132cea043f8e543c28e1992d327b08e2c6 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/index.ets +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/index.ets @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2023 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 { MainPage } from './src/main/ets/components/mainpage/MainPage'; -export { Log } from './src/main/ts/test'; -export { func } from './src/main/ts/test'; -export { func2 } from './src/main/ts/test'; +/* + * Copyright (c) 2023 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 { MainPage } from './src/main/ets/components/mainpage/MainPage'; +export { Log } from './src/main/ts/test'; +export { func } from './src/main/ts/test'; +export { func2 } from './src/main/ts/test'; export { nativeAdd } from './src/main/ets/utils/nativeTest'; \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/library/oh-package.json5 index d5d81fe8a14a764d294926f2689e40e76e42b131..dff32d3a01de37ca640dc37a2887f6e1afb5216a 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "Apache-2.0", - "devDependencies": { - "@types/liblibrary.so": "file:./src/main/cpp/types/liblibrary" - }, - "author": "", - "name": "library", - "description": "Please describe the basic information.", - "main": "index.ets", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "Apache-2.0", + "devDependencies": { + "@types/liblibrary.so": "file:./src/main/cpp/types/liblibrary" + }, + "author": "", + "name": "library", + "description": "Please describe the basic information.", + "main": "index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/index.d.ts b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/index.d.ts index 2dfa9815bf58d868a2164d570627c09efb600cb4..57d8ff2271f396902af0b64849a3c8cd34c46341 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/index.d.ts +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/index.d.ts @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 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. - */ - +/* + * Copyright (c) 2023 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 add: (a: number, b: number) => number; \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/oh-package.json5 index 57886b03cbfeac0dc654155ae6cd0cc117500eef..e57a824ed98e94ae25222d1e5105c42036495829 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/cpp/types/liblibrary/oh-package.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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": "liblibrary.so", - "types": "./index.d.ts", - "version": "", - "description": "Please describe the basic information." +/* + * Copyright (c) 2023 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": "liblibrary.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/components/mainpage/MainPage.ets b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/components/mainpage/MainPage.ets index ad83c99ed7ae9b98a9af6169392eb20f5e7dd3ff..d4b9ea86bdfe36a0ccb7c396b6fb745909ab0995 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/components/mainpage/MainPage.ets +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/components/mainpage/MainPage.ets @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2023 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. - */ - -@Component -export struct MainPage { - @State message: string = 'HAR MainPage'; - - build() { - Column() { - Row() { - Text(this.message) - .fontSize(32) - .fontWeight(FontWeight.Bold) - } - .margin({ top: '32px' }) - .width('624px') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { - Column() { - Image($r('app.media.pic_empty')).width('33%') - Text($r('app.string.empty')) - .fontSize(14) - .fontColor($r('app.color.text_color')) - } - }.width('100%') - .height('90%') - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.page_background')) - } -} +/* + * Copyright (c) 2023 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. + */ + +@Component +export struct MainPage { + @State message: string = 'HAR MainPage'; + + build() { + Column() { + Row() { + Text(this.message) + .fontSize(32) + .fontWeight(FontWeight.Bold) + } + .margin({ top: '32px' }) + .width('624px') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { + Column() { + Image($r('app.media.pic_empty')).width('33%') + Text($r('app.string.empty')) + .fontSize(14) + .fontColor($r('app.color.text_color')) + } + }.width('100%') + .height('90%') + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.page_background')) + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/utils/nativeTest.ts b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/utils/nativeTest.ts index a093a75805e0298775c186fb125701307a6863f9..0d3d9a76bf1cbfae2fdb5487d7cd6f88571820c9 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/utils/nativeTest.ts +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ets/utils/nativeTest.ts @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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 native from 'liblibrary.so'; - -export function nativeAdd(a: number, b: number): number { - let result: number = native.add(a, b); - return result; +/* + * Copyright (c) 2023 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 native from 'liblibrary.so'; + +export function nativeAdd(a: number, b: number): number { + let result: number = native.add(a, b); + return result; } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/module.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/module.json5 index 7fe25c1fa5ec3833bbf0625ab0c09f789b28ba66..85c863fcf22c3a5e520039fb6fde6fc30ca913fd 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/module.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/module.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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": "library", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} +/* + * Copyright (c) 2023 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": "library", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/resources/base/element/color.json b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/resources/base/element/color.json index 5682f26b177b6f7a24e260570819ee4d9bf7a733..20bf6d89a9020d7adc9ad29743f546ff411978e6 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/resources/base/element/color.json +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/resources/base/element/color.json @@ -1,20 +1,20 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "page_background", - "value": "#F1F3F5" - }, - { - "name": "button_background", - "value": "#007DFF" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "page_background", + "value": "#F1F3F5" + }, + { + "name": "button_background", + "value": "#007DFF" + }, + { + "name": "text_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ts/test.ets b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ts/test.ets index 1109fa5b7f8caae9481d79ae55f721efa0f15d2f..b3526ba6963d04628fa557890635d92df5271afd 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ts/test.ets +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/library/src/main/ts/test.ets @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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 class Log { - static info(msg: string) { - console.info(msg); - } -} - -export function func() { - return 'har func'; -} - -export function func2() { - return 'har func2'; +/* + * Copyright (c) 2023 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 class Log { + static info(msg: string) { + console.info(msg); + } +} + +export function func() { + return 'har func'; +} + +export function func2() { + return 'har func2'; } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HarSample/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HarSample/oh-package.json5 index e30539c78b16610ee54cbd3a2fd5edf3e6a0e917..1dcc15ba8b4a020aa0d767c3edc1f3c27d7b876b 100644 --- a/code/DocsSample/BundleManagerDocsSample/HarSample/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HarSample/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "harsample", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "harsample", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/app.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/app.json5 index 1a6671675f024af86f7191b0bb63e4842f55ed26..f272e3f7ae21d0f99f253363b30a22a131617581 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/app.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.hspsample", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.hspsample", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/resources/base/element/string.json b/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/resources/base/element/string.json index ec33d38a522b1ad83f719a319b2c7d4001ec82f9..03637f7821fc75f15929d68838e5d54745f977fb 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/resources/base/element/string.json +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "HspSample" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "HspSample" + } + ] +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/build-profile.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/build-profile.json5 index fe8c14b574f3e5995d89cd8a4421ce167588d00a..d45be4b132869856ace15f59720e9e5d0ccec19b 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/build-profile.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/build-profile.json5 @@ -1,55 +1,55 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "library", - "srcPath": "./library", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "library", + "srcPath": "./library", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/build-profile.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/build-profile.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/oh-package.json5 index 45159edb792eca7841e3934523912550acf057c2..c8286b9e1d2d4642b250a74e26b2c2a112339ccd 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "library": "file:../library" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "library": "file:../library" + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/entryability/EntryAbility.ts b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/entryability/EntryAbility.ts index 714d4b5563974e401e79837509e426170c4518c8..964a26f8692bcd446b020735a8a929241f44a109 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Logger from '../logger/Logger'; - -const TAG = 'EntryAbility'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - Logger.info(TAG, `Ability onCreate want: ${JSON.stringify(want)}`, `launchParam: ${JSON.stringify(launchParam)}`); - } - - onDestroy() { - Logger.info(TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - Logger.info(TAG, 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(TAG, `Failed to load the content. Cause: ${JSON.stringify(err)}`); - return; - } - Logger.info(TAG, `Succeeded in loading the content. Data: ${JSON.stringify(data)}`); - }); - } - - onWindowStageDestroy() { - Logger.info(TAG, 'Ability onWindowStageDestroy'); - } - - onForeground() { - Logger.info(TAG, 'Ability onForeground'); - } - - onBackground() { - Logger.info(TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Logger from '../logger/Logger'; + +const TAG = 'EntryAbility'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + Logger.info(TAG, `Ability onCreate want: ${JSON.stringify(want)}`, `launchParam: ${JSON.stringify(launchParam)}`); + } + + onDestroy() { + Logger.info(TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + Logger.info(TAG, 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(TAG, `Failed to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + Logger.info(TAG, `Succeeded in loading the content. Data: ${JSON.stringify(data)}`); + }); + } + + onWindowStageDestroy() { + Logger.info(TAG, 'Ability onWindowStageDestroy'); + } + + onForeground() { + Logger.info(TAG, 'Ability onForeground'); + } + + onBackground() { + Logger.info(TAG, 'Ability onBackground'); + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/logger/Logger.ts b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/logger/Logger.ts index 0d85adbb7f64efe38bf65038a49a220782f298e2..ed0cb54fe75fa2eb1aea119aa391fb53bb99ffe1 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/logger/Logger.ts +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/ets/logger/Logger.ts @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -export class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_HSP]'); \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/module.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/module.json5 index a61f5cbf7c93e99ea7adb05d04f9bf9a4c3e3756..bac72d95926679c3199ad00b9457707b6970fe38 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/module.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/resources/base/element/color.json b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/resources/base/element/color.json index 6483db0e0b0384944a51e9b3c628559e977efff2..0d7a6759361cbd5527743270dacbd5e7ff07f9b6 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "text_color", - "value": "#182431" - }, - { - "name": "button_background", - "value": "#007DFF" - }, - { - "name": "page_background", - "value": "#F1F3F5" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "text_color", + "value": "#182431" + }, + { + "name": "button_background", + "value": "#007DFF" + }, + { + "name": "page_background", + "value": "#F1F3F5" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/ets/logger/Logger.ts b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/ets/logger/Logger.ts index 7bf60678feee09958f6f390b68261192bc861720..46fc9ccb3218382b6c802def9f88e38a8b28e065 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/ets/logger/Logger.ts +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/ets/logger/Logger.ts @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -export class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } - - fatal(...args: string[]): void { - hilog.fatal(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +export class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } + + fatal(...args: string[]): void { + hilog.fatal(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_HspSample_Test]'); \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/module.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/hvigor/hvigor-config.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/hvigor/hvigor-config.json5 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/hvigor/hvigor-config.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/build-profile.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/library/build-profile.json5 index afdd327d9b1e1ff600b6fbd81a7e9d7667963b3e..be7ab69a4254cbb8a660bf1d974a6495c6489901 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/build-profile.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/build-profile.json5 @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2023 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": "" - }, - }, - "targets": [ - { - "name": "default" - } - ] +/* + * Copyright (c) 2023 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": "" + }, + }, + "targets": [ + { + "name": "default" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/library/oh-package.json5 index 5fc598646d141b63e86064d89e2684a76a85815c..c18e5c28795bc279c68be5d5fa15d14fa1ce4c7c 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "Apache-2.0", - "devDependencies": { - "@types/liblibrary.so": "file:./src/main/cpp/types/liblibrary" - }, - "author": "", - "name": "library", - "description": "Please describe the basic information.", - "main": "./src/main/ets/Index.ets", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "Apache-2.0", + "devDependencies": { + "@types/liblibrary.so": "file:./src/main/cpp/types/liblibrary" + }, + "author": "", + "name": "library", + "description": "Please describe the basic information.", + "main": "./src/main/ets/Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/index.d.ts b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/index.d.ts index 0f453034d212927f59ae575875829c302aad3d04..aaa16bac9a9a6e82b0fe80bafe9db5e1ee11da99 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/index.d.ts +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/index.d.ts @@ -1,16 +1,16 @@ -/* - * Copyright (c) 2023 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. - */ - +/* + * Copyright (c) 2023 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 multi: (a: number, b: number) => number; \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/oh-package.json5 index d865f17539aeb54f90325ed392917b6f307318d1..c0b93707218e34031e037f9e09ed3b11469265e9 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/cpp/types/liblibrary/oh-package.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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": "libibrary.so", - "types": "./index.d.ts", - "version": "", - "description": "Please describe the basic information." +/* + * Copyright (c) 2023 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": "libibrary.so", + "types": "./index.d.ts", + "version": "", + "description": "Please describe the basic information." } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/Index.ets b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/Index.ets index adbf4d90f7501f247931d1cd38612ff918ba9e6b..1bee7e514a1f7f138084426c6cef8d0a227f41c1 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/Index.ets +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/Index.ets @@ -1,19 +1,19 @@ -/* - * Copyright (c) 2023 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 { Log, add, minus } from './utils/test'; -export { MyTitleBar } from './components/MyTitleBar'; -export { ResManager } from './ResManager'; +/* + * Copyright (c) 2023 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 { Log, add, minus } from './utils/test'; +export { MyTitleBar } from './components/MyTitleBar'; +export { ResManager } from './ResManager'; export { nativeMulti } from './utils/nativeTest'; \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/ResManager.ets b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/ResManager.ets index aaeef4e50d381def4891edccf039b41ca3ec3543..83492c54e3e408828807a1f4efb4304ea08e6aba 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/ResManager.ets +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/ResManager.ets @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2023 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 class ResManager{ - static getPic(): Resource{ - return $r('app.media.pic'); - } - static getDesc(): Resource{ - return $r('app.string.shared_desc'); - } +/* + * Copyright (c) 2023 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 class ResManager{ + static getPic(): Resource{ + return $r('app.media.pic'); + } + static getDesc(): Resource{ + return $r('app.string.shared_desc'); + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/components/MyTitleBar.ets b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/components/MyTitleBar.ets index 1b5139d3ca19cc2c82cd17a483a848571094be29..248d99a0d615ddc444065bb0eb1138419c1a0199 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/components/MyTitleBar.ets +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/components/MyTitleBar.ets @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2023 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. - */ - -@Component -export struct MyTitleBar { - build() { - Row() { - Text($r('app.string.library_title')) - .id('library') - .fontFamily('HarmonyHeiTi') - .fontWeight(FontWeight.Bold) - .fontSize(32) - .fontWeight(700) - .fontColor($r('app.color.text_color')) - } - .width('100%') - } +/* + * Copyright (c) 2023 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. + */ + +@Component +export struct MyTitleBar { + build() { + Row() { + Text($r('app.string.library_title')) + .id('library') + .fontFamily('HarmonyHeiTi') + .fontWeight(FontWeight.Bold) + .fontSize(32) + .fontWeight(700) + .fontColor($r('app.color.text_color')) + } + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Back.ets b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Back.ets index c5b772379c9cfa2951636ebdc0df1300e4b4cabb..e35f7348c224b760ead1c6eae579029fdbd0822b 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Back.ets +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Back.ets @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; - -@Entry -@Component -struct Index3 { // 路径为:`library/src/main/ets/pages/Back.ets - @State message: string = 'HSP back page'; - - build() { - Row() { - Column() { - Text(this.message) - .fontFamily('HarmonyHeiTi') - .fontWeight(FontWeight.Bold) - .fontSize(32) - .fontWeight(700) - .fontColor($r('app.color.text_color')) - .margin({ top: '32px' }) - .width('624px') - - Button($r('app.string.back_to_HAP')) - .id('backToHAP') - .fontFamily('HarmonyHeiTi') - .height(48) - .width('624px') - .margin({ top: 550 }) - .type(ButtonType.Capsule) - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('app.color.button_background')) - .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - // 绑定点击事件 - .onClick(() => { - router.back({ // 返回HAP的页面 - url: 'pages/Index' // 路径为:`entry/src/main/ets/pages/Index.ets` - }) - }) - - Button($r('app.string.back_to_HSP')) - .id('backToHSP') - .fontFamily('HarmonyHeiTi') - .height(48) - .width('624px') - .margin({ top: '4%' , bottom: '6%' }) - .type(ButtonType.Capsule) - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('app.color.button_background')) - .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - // 绑定点击事件 - .onClick(() => { - router.back({ // 返回HSP的页面 - url: '@bundle:com.samples.hspsample/library/ets/pages/Menu' //路径为:`library/src/main/ets/pages/Menu.ets - }) - }) - } - .width('100%') - } - .backgroundColor($r('app.color.page_background')) - .height('100%') - } +/* + * Copyright (c) 2023 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 router from '@ohos.router'; + +@Entry +@Component +struct Index3 { // 路径为:`library/src/main/ets/pages/Back.ets + @State message: string = 'HSP back page'; + + build() { + Row() { + Column() { + Text(this.message) + .fontFamily('HarmonyHeiTi') + .fontWeight(FontWeight.Bold) + .fontSize(32) + .fontWeight(700) + .fontColor($r('app.color.text_color')) + .margin({ top: '32px' }) + .width('624px') + + Button($r('app.string.back_to_HAP')) + .id('backToHAP') + .fontFamily('HarmonyHeiTi') + .height(48) + .width('624px') + .margin({ top: 550 }) + .type(ButtonType.Capsule) + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('app.color.button_background')) + .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + // 绑定点击事件 + .onClick(() => { + router.back({ // 返回HAP的页面 + url: 'pages/Index' // 路径为:`entry/src/main/ets/pages/Index.ets` + }) + }) + + Button($r('app.string.back_to_HSP')) + .id('backToHSP') + .fontFamily('HarmonyHeiTi') + .height(48) + .width('624px') + .margin({ top: '4%' , bottom: '6%' }) + .type(ButtonType.Capsule) + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('app.color.button_background')) + .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + // 绑定点击事件 + .onClick(() => { + router.back({ // 返回HSP的页面 + url: '@bundle:com.samples.hspsample/library/ets/pages/Menu' //路径为:`library/src/main/ets/pages/Menu.ets + }) + }) + } + .width('100%') + } + .backgroundColor($r('app.color.page_background')) + .height('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Menu.ets b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Menu.ets index cf2a096fba13321411f44cf78cd09e6828df0973..c23e9b016db89c3edb080f44f7436c2fad8f20a1 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Menu.ets +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/pages/Menu.ets @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; - -@Entry -@Component -struct MenuIndex { - @State message: string = 'HSP menu page'; - - build() { - Column() { - Text(this.message) - .fontFamily('HarmonyHeiTi') - .fontWeight(FontWeight.Bold) - .fontSize(32) - .fontWeight(700) - .fontColor($r('app.color.text_color')) - .margin({ top: '32px' }) - .width('624px') - - Button($r('app.string.router_to_HSP')) - .id('menuToBack') - .fontFamily('HarmonyHeiTi') - .height(48) - .width('624px') - .margin({ top: 620, bottom: '6%' }) - .type(ButtonType.Capsule) - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('app.color.button_background')) - .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) - .fontSize($r('sys.float.ohos_id_text_size_button1')) - // 绑定点击事件 - .onClick(() => { - router.pushUrl({ - url: '@bundle:com.samples.hspsample/library/ets/pages/Back' - }) - }) - } - .width('100%') - .backgroundColor($r('app.color.page_background')) - .height('100%') - } +/* + * Copyright (c) 2023 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 router from '@ohos.router'; + +@Entry +@Component +struct MenuIndex { + @State message: string = 'HSP menu page'; + + build() { + Column() { + Text(this.message) + .fontFamily('HarmonyHeiTi') + .fontWeight(FontWeight.Bold) + .fontSize(32) + .fontWeight(700) + .fontColor($r('app.color.text_color')) + .margin({ top: '32px' }) + .width('624px') + + Button($r('app.string.router_to_HSP')) + .id('menuToBack') + .fontFamily('HarmonyHeiTi') + .height(48) + .width('624px') + .margin({ top: 620, bottom: '6%' }) + .type(ButtonType.Capsule) + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('app.color.button_background')) + .fontColor($r('sys.color.ohos_id_color_foreground_contrary')) + .fontSize($r('sys.float.ohos_id_text_size_button1')) + // 绑定点击事件 + .onClick(() => { + router.pushUrl({ + url: '@bundle:com.samples.hspsample/library/ets/pages/Back' + }) + }) + } + .width('100%') + .backgroundColor($r('app.color.page_background')) + .height('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/utils/nativeTest.ts b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/utils/nativeTest.ts index a012ec0c3e3c3e3e2776aed0d6ae645fc3d8195c..3589c82009b11f1b1aac03073d0755e49eacf3b5 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/utils/nativeTest.ts +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/ets/utils/nativeTest.ts @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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 native from 'liblibrary.so'; - -export function nativeMulti(a: number, b: number): number { - let result: number = native.multi(a, b); - return result; +/* + * Copyright (c) 2023 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 native from 'liblibrary.so'; + +export function nativeMulti(a: number, b: number): number { + let result: number = native.multi(a, b); + return result; } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/module.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/module.json5 index 2721df92cb1f7828e453b9b0ecedb1ddc6f24bdf..d35a7ca8bad9a566833aefb63bff9466b5d492b7 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/module.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/module.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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": "library", - "type": "shared", - "description": "$string:shared_desc", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "pages": "$profile:main_pages" - } +/* + * Copyright (c) 2023 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": "library", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/resources/base/element/string.json b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/resources/base/element/string.json index e1e8dfcf674e2f6d933a7e261f0b66e5273ea698..3e455ad20b2dbd2dcca364423de30d1828c4bb87 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/resources/base/element/string.json +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/library/src/main/resources/base/element/string.json @@ -1,24 +1,24 @@ -{ - "string": [ - { - "name": "shared_desc", - "value": "shared" - }, - { - "name": "library_title", - "value": "library" - }, - { - "name": "back_to_HAP", - "value": "back to HAP page" - }, - { - "name": "back_to_HSP", - "value": "back to HSP page" - }, - { - "name": "router_to_HSP", - "value": "router to HSP page" - } - ] +{ + "string": [ + { + "name": "shared_desc", + "value": "shared" + }, + { + "name": "library_title", + "value": "library" + }, + { + "name": "back_to_HAP", + "value": "back to HAP page" + }, + { + "name": "back_to_HSP", + "value": "back to HSP page" + }, + { + "name": "router_to_HSP", + "value": "router to HSP page" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/BundleManagerDocsSample/HspSample/oh-package.json5 b/code/DocsSample/BundleManagerDocsSample/HspSample/oh-package.json5 index 70271a7050d4afc04b73306dcf8b9165726fd719..f50249172304247958d847555c65a1c49069971f 100644 --- a/code/DocsSample/BundleManagerDocsSample/HspSample/oh-package.json5 +++ b/code/DocsSample/BundleManagerDocsSample/HspSample/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "hspsample", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "hspsample", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/ohosTest.md b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/ohosTest.md old mode 100755 new mode 100644 index dd30e6501fcf12cdcda448d8b3f2988514c387fc..8287c8a8cb2939182fdda647f92bae69cef3a282 --- a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/ohosTest.md +++ b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/ohosTest.md @@ -1,7 +1,7 @@ -# HCE卡模拟开发示例代码工程化 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------- | ------------ | ----------------- | ------------------------|--------- | -------- | +# HCE卡模拟开发示例代码工程化 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ----------------- | ------------------------|--------- | -------- | | NFC功能正常启动 | 设备支持NFC | 启动应用 | 应用停留在启动界面,输出预期日志 |否 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/screenshots/image.jpeg b/code/DocsSample/ConnectivityKit/NFC/HCECardSimulationDevelopment/screenshots/image.jpeg old mode 100755 new mode 100644 diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/ohosTest.md b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/ohosTest.md old mode 100755 new mode 100644 index 5813f372f58f9b089b642ac2c8d8d80be96c1d13..4e057f15d29063614611820304830eb2fd93501b --- a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/ohosTest.md +++ b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/ohosTest.md @@ -1,7 +1,7 @@ -# NFC标签读写示例代码工程化 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------- | ------------ | ----------------- | ------------------------|--------- | -------- | +# NFC标签读写示例代码工程化 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ----------------- | ------------------------|--------- | -------- | | NFC功能正常启动 | 设备支持NFC | 启动应用 | 应用停留在启动界面,输出预期日志 |否 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/screenshots/image.jpeg b/code/DocsSample/ConnectivityKit/NFC/NFCReadAndWrite/screenshots/image.jpeg old mode 100755 new mode 100644 diff --git a/code/DocsSample/ConnectivityKit/NFC/SecureElement/ohosTest.md b/code/DocsSample/ConnectivityKit/NFC/SecureElement/ohosTest.md old mode 100755 new mode 100644 index dd54c176743ab08b9fa85559a50a85e4d2fc8477..f3c71387def5a32481b0aba1d60b71e7c4d08f64 --- a/code/DocsSample/ConnectivityKit/NFC/SecureElement/ohosTest.md +++ b/code/DocsSample/ConnectivityKit/NFC/SecureElement/ohosTest.md @@ -1,7 +1,7 @@ -# 安全单元访问示例代码工程化 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------- | ------------ | ----------------- | ------------------------|--------- | -------- | +# 安全单元访问示例代码工程化 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------- | ------------ | ----------------- | ------------------------|--------- | -------- | | NFC功能正常启动 | 设备支持NFC | 启动应用 | 应用停留在启动界面,输出预期日志 |否 | Pass | \ No newline at end of file diff --git a/code/DocsSample/ConnectivityKit/NFC/SecureElement/screenshots/image.jpeg b/code/DocsSample/ConnectivityKit/NFC/SecureElement/screenshots/image.jpeg old mode 100755 new mode 100644 diff --git a/code/DocsSample/ConnectivityKit/Wlan/ohosTest.md b/code/DocsSample/ConnectivityKit/Wlan/ohosTest.md old mode 100755 new mode 100644 index 8ba91e60bf4c202e31305aef7229b10a2a4bb0ed..e02cd4bf9d24860a970a0dcdae8402b7dc317bc5 --- a/code/DocsSample/ConnectivityKit/Wlan/ohosTest.md +++ b/code/DocsSample/ConnectivityKit/Wlan/ohosTest.md @@ -1,10 +1,10 @@ -# P2P模式开发测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------ | ------------ | ------------------------------ | ------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 |点击运行 | 成功拉起应用 | 否 | Pass | -| 主页点击create group按钮 | 打开WLAN,位于主页 |点击create group按钮 | 主页显示success文字 | 否 | Pass | -| 主页connect按钮点击 | 打开WLAN,点击create group按钮后,位于主页 |点击connect按钮 | 输出预期日志 | 否 | Pass | +# P2P模式开发测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ------------------------------ | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 |点击运行 | 成功拉起应用 | 否 | Pass | +| 主页点击create group按钮 | 打开WLAN,位于主页 |点击create group按钮 | 主页显示success文字 | 否 | Pass | +| 主页connect按钮点击 | 打开WLAN,点击create group按钮后,位于主页 |点击connect按钮 | 输出预期日志 | 否 | Pass | | 主页delete group按钮点击 | 打开WLAN,点击create group按钮后,位于主页 |点击delete group按钮 | 主页显示的文字被清除 | 否 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_brush.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_brush.cpp index 0c7191b1a101d4bd5a41a7a2c052f13484988736..a6cf5fb884d15c486f6709ffaeb4f5a5e37d4128 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_brush.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_brush.cpp @@ -1,277 +1,277 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" - -void SampleGraphics::DrawBrushBasic(OH_Drawing_Canvas *canvas) -{ - // 创建画刷 - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - // 设置填充颜色为红色 - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - // 开启抗锯齿效果 - OH_Drawing_BrushSetAntiAlias(brush, true); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(0, 0, value300_, value300_); - // 绘制矩形1 - OH_Drawing_CanvasDrawRect(canvas, rect1); - OH_Drawing_CanvasDetachBrush(canvas); - // 复制画刷 - OH_Drawing_Brush* brush_copy = OH_Drawing_BrushCopy(brush); - - // 画刷重置 - OH_Drawing_BrushReset(brush); - // 设置透明度 - OH_Drawing_BrushSetAlpha(brush, rgbaHalf_); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value400_, value400_, value700_, value700_); - // 绘制矩形2 - OH_Drawing_CanvasDrawRect(canvas, rect2); - OH_Drawing_CanvasDetachBrush(canvas); - - OH_Drawing_CanvasAttachBrush(canvas, brush_copy); - OH_Drawing_Rect* rect3 = OH_Drawing_RectCreate(value800_, value800_, value1100_, value1100_); - // 绘制矩形3 - OH_Drawing_CanvasDrawRect(canvas, rect3); - OH_Drawing_CanvasDetachBrush(canvas); - - // 销毁各类对象 - OH_Drawing_BrushDestroy(brush); - OH_Drawing_BrushDestroy(brush_copy); - OH_Drawing_RectDestroy(rect1); - OH_Drawing_RectDestroy(rect2); - OH_Drawing_RectDestroy(rect3); -} - -void SampleGraphics::DrawMixedMode(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_CanvasClear(canvas, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMin_)); - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value600_, value600_); - // 绘制矩形(目标像素) - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, 0xFF)); - // 设置混合模式为叠加模式 - OH_Drawing_BrushSetBlendMode(brush, OH_Drawing_BlendMode::BLEND_MODE_PLUS); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Point *point = OH_Drawing_PointCreate(value600_, value600_); - // 绘制圆(源像素) - OH_Drawing_CanvasDrawCircle(canvas, point, value300_); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_PointDestroy(point); -} - -void SampleGraphics::DrawShaderEffect1Line(OH_Drawing_Canvas *canvas) -{ - // 线性渐变着色器 - OH_Drawing_Point *startPt = OH_Drawing_PointCreate(value100_, value100_); - OH_Drawing_Point *endPt = OH_Drawing_PointCreate(value300_, value300_); - uint32_t colors[] = { - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMax_, rgbaMin_), - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_), - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMax_)}; - float pos[] = {0.0f, 0.5f, 1.0f}; - OH_Drawing_ShaderEffect *linearShaderEffect1 = - OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, colors, pos, indexThree_, - OH_Drawing_TileMode::CLAMP); - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - // 基于画刷设置着色器 - OH_Drawing_BrushSetShaderEffect(brush, linearShaderEffect1); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value300_, value300_); - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - // 使用矩阵创建线性渐变着色器 - OH_Drawing_CanvasTranslate(canvas, value300_, 0.f); - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate(); - OH_Drawing_MatrixScale(matrix, 2.0f, 1.0f, value200_, value200_); - OH_Drawing_Point2D startPt2{value100_, value100_}; - OH_Drawing_Point2D endPt2{value300_, value300_}; - OH_Drawing_ShaderEffect *linearShaderEffect2 = OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix( - &startPt2, &endPt2, colors, pos, indexThree_, OH_Drawing_TileMode::CLAMP, matrix); - OH_Drawing_BrushSetShaderEffect(brush, linearShaderEffect2); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - // 销毁各类对象 - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RectDestroy(rect); - OH_Drawing_ShaderEffectDestroy(linearShaderEffect1); - OH_Drawing_ShaderEffectDestroy(linearShaderEffect2); - OH_Drawing_PointDestroy(startPt); - OH_Drawing_PointDestroy(endPt); - OH_Drawing_MatrixDestroy(matrix); -} - -void SampleGraphics::DrawShaderEffect2Line(OH_Drawing_Canvas *canvas) -{ - uint32_t colors[] = { - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMax_, rgbaMin_), - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_), - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMax_)}; - float pos[] = {0.0f, 0.5f, 1.0f}; - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value300_, value300_); - - // 径向渐变着色器 - OH_Drawing_Point *centerPt = OH_Drawing_PointCreate(value200_, value200_); - OH_Drawing_ShaderEffect *radialShaderEffect = - OH_Drawing_ShaderEffectCreateRadialGradient(centerPt, value200_, colors, pos, indexThree_, - OH_Drawing_TileMode::REPEAT); - OH_Drawing_BrushSetShaderEffect(brush, radialShaderEffect); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - // 扇形渐变着色器 - OH_Drawing_CanvasTranslate(canvas, value300_, 0.f); - OH_Drawing_ShaderEffect* sweepShaderEffect = - OH_Drawing_ShaderEffectCreateSweepGradient(centerPt, colors, pos, indexThree_, OH_Drawing_TileMode::CLAMP); - OH_Drawing_BrushSetShaderEffect(brush, sweepShaderEffect); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - // 双圆锥渐变着色器 - OH_Drawing_CanvasTranslate(canvas, value300_, 0.f); - OH_Drawing_Point2D pt3{value200_, value200_}; - OH_Drawing_ShaderEffect *twoPointShaderEffect = OH_Drawing_ShaderEffectCreateTwoPointConicalGradient( - &pt3, value30_, &pt3, value100_, colors, pos, indexThree_, OH_Drawing_TileMode::CLAMP, nullptr); - OH_Drawing_BrushSetShaderEffect(brush, twoPointShaderEffect); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - // 销毁各类对象 - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RectDestroy(rect); - OH_Drawing_ShaderEffectDestroy(radialShaderEffect); - OH_Drawing_ShaderEffectDestroy(sweepShaderEffect); - OH_Drawing_ShaderEffectDestroy(twoPointShaderEffect); -} - -void SampleGraphics::DrawShaderEffect(OH_Drawing_Canvas *canvas) -{ - // 线性渐变着色器 - DrawShaderEffect1Line(canvas); - OH_Drawing_CanvasTranslate(canvas, -value300_, value300_); - DrawShaderEffect2Line(canvas); -} - -void SampleGraphics::DrawColorFilter(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetAntiAlias(brush, true); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value300_, value300_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - OH_Drawing_CanvasTranslate(canvas, 0.f, value300_); - // 创建luma亮度颜色滤波器 - OH_Drawing_ColorFilter* lumaColorFilter = OH_Drawing_ColorFilterCreateLuma(); - OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); - OH_Drawing_FilterSetColorFilter(filter, lumaColorFilter); - OH_Drawing_BrushSetFilter(brush, filter); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 绘制经过luma亮度颜色滤波器效果的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - OH_Drawing_CanvasTranslate(canvas, 0.f, value300_); - const float matrix[20] = { - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 0.5f, 0.5f, 0, - 0, 0, 0.5f, 0.5f, 0 - }; - // 创建5*4矩阵颜色滤波器 - OH_Drawing_ColorFilter* matrixColorFilter = OH_Drawing_ColorFilterCreateMatrix(matrix); - // 创建从SRGB转换到线性颜色空间的颜色滤波器 - OH_Drawing_ColorFilter* s2lColorFilter = OH_Drawing_ColorFilterCreateSrgbGammaToLinear(); - // 创建从线性颜色空间转换到SRGB的颜色滤波器 - OH_Drawing_ColorFilter* l2sColorFilter = OH_Drawing_ColorFilterCreateLinearToSrgbGamma(); - // 创建合成滤波器 - OH_Drawing_ColorFilter* composeColorFilter1 = - OH_Drawing_ColorFilterCreateCompose(matrixColorFilter, s2lColorFilter); - OH_Drawing_ColorFilter* composeColorFilter2 = - OH_Drawing_ColorFilterCreateCompose(composeColorFilter1, l2sColorFilter); - OH_Drawing_FilterSetColorFilter(filter, composeColorFilter1); - OH_Drawing_BrushSetFilter(brush, filter); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 绘制经过合成颜色滤波器效果的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - - // 销毁各类对象 - OH_Drawing_BrushDestroy(brush); - OH_Drawing_ColorFilterDestroy(matrixColorFilter); - OH_Drawing_ColorFilterDestroy(lumaColorFilter); - OH_Drawing_ColorFilterDestroy(s2lColorFilter); - OH_Drawing_ColorFilterDestroy(l2sColorFilter); - OH_Drawing_ColorFilterDestroy(composeColorFilter1); - OH_Drawing_ColorFilterDestroy(composeColorFilter2); - OH_Drawing_RectDestroy(rect); - OH_Drawing_FilterDestroy(filter); -} - -void SampleGraphics::DrawMaskFilterBrush(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetAntiAlias(brush, true); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - // 创建模糊蒙版滤波器 - OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType::NORMAL, 20, true); - OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); - OH_Drawing_FilterSetMaskFilter(filter, maskFilter); - // 设置画刷的滤波器效果 - OH_Drawing_BrushSetFilter(brush, filter); - OH_Drawing_CanvasAttachBrush(canvas, brush); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - // 销毁各类对象 - OH_Drawing_BrushDestroy(brush); - OH_Drawing_MaskFilterDestroy(maskFilter); - OH_Drawing_RectDestroy(rect); - OH_Drawing_FilterDestroy(filter); -} +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" + +void SampleGraphics::DrawBrushBasic(OH_Drawing_Canvas *canvas) +{ + // 创建画刷 + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + // 设置填充颜色为红色 + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + // 开启抗锯齿效果 + OH_Drawing_BrushSetAntiAlias(brush, true); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(0, 0, value300_, value300_); + // 绘制矩形1 + OH_Drawing_CanvasDrawRect(canvas, rect1); + OH_Drawing_CanvasDetachBrush(canvas); + // 复制画刷 + OH_Drawing_Brush* brush_copy = OH_Drawing_BrushCopy(brush); + + // 画刷重置 + OH_Drawing_BrushReset(brush); + // 设置透明度 + OH_Drawing_BrushSetAlpha(brush, rgbaHalf_); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value400_, value400_, value700_, value700_); + // 绘制矩形2 + OH_Drawing_CanvasDrawRect(canvas, rect2); + OH_Drawing_CanvasDetachBrush(canvas); + + OH_Drawing_CanvasAttachBrush(canvas, brush_copy); + OH_Drawing_Rect* rect3 = OH_Drawing_RectCreate(value800_, value800_, value1100_, value1100_); + // 绘制矩形3 + OH_Drawing_CanvasDrawRect(canvas, rect3); + OH_Drawing_CanvasDetachBrush(canvas); + + // 销毁各类对象 + OH_Drawing_BrushDestroy(brush); + OH_Drawing_BrushDestroy(brush_copy); + OH_Drawing_RectDestroy(rect1); + OH_Drawing_RectDestroy(rect2); + OH_Drawing_RectDestroy(rect3); +} + +void SampleGraphics::DrawMixedMode(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_CanvasClear(canvas, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMin_)); + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value600_, value600_); + // 绘制矩形(目标像素) + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, 0xFF)); + // 设置混合模式为叠加模式 + OH_Drawing_BrushSetBlendMode(brush, OH_Drawing_BlendMode::BLEND_MODE_PLUS); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Point *point = OH_Drawing_PointCreate(value600_, value600_); + // 绘制圆(源像素) + OH_Drawing_CanvasDrawCircle(canvas, point, value300_); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_PointDestroy(point); +} + +void SampleGraphics::DrawShaderEffect1Line(OH_Drawing_Canvas *canvas) +{ + // 线性渐变着色器 + OH_Drawing_Point *startPt = OH_Drawing_PointCreate(value100_, value100_); + OH_Drawing_Point *endPt = OH_Drawing_PointCreate(value300_, value300_); + uint32_t colors[] = { + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMax_, rgbaMin_), + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_), + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMax_)}; + float pos[] = {0.0f, 0.5f, 1.0f}; + OH_Drawing_ShaderEffect *linearShaderEffect1 = + OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, colors, pos, indexThree_, + OH_Drawing_TileMode::CLAMP); + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + // 基于画刷设置着色器 + OH_Drawing_BrushSetShaderEffect(brush, linearShaderEffect1); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value300_, value300_); + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + // 使用矩阵创建线性渐变着色器 + OH_Drawing_CanvasTranslate(canvas, value300_, 0.f); + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate(); + OH_Drawing_MatrixScale(matrix, 2.0f, 1.0f, value200_, value200_); + OH_Drawing_Point2D startPt2{value100_, value100_}; + OH_Drawing_Point2D endPt2{value300_, value300_}; + OH_Drawing_ShaderEffect *linearShaderEffect2 = OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix( + &startPt2, &endPt2, colors, pos, indexThree_, OH_Drawing_TileMode::CLAMP, matrix); + OH_Drawing_BrushSetShaderEffect(brush, linearShaderEffect2); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + // 销毁各类对象 + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RectDestroy(rect); + OH_Drawing_ShaderEffectDestroy(linearShaderEffect1); + OH_Drawing_ShaderEffectDestroy(linearShaderEffect2); + OH_Drawing_PointDestroy(startPt); + OH_Drawing_PointDestroy(endPt); + OH_Drawing_MatrixDestroy(matrix); +} + +void SampleGraphics::DrawShaderEffect2Line(OH_Drawing_Canvas *canvas) +{ + uint32_t colors[] = { + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMax_, rgbaMin_), + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_), + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMax_)}; + float pos[] = {0.0f, 0.5f, 1.0f}; + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value300_, value300_); + + // 径向渐变着色器 + OH_Drawing_Point *centerPt = OH_Drawing_PointCreate(value200_, value200_); + OH_Drawing_ShaderEffect *radialShaderEffect = + OH_Drawing_ShaderEffectCreateRadialGradient(centerPt, value200_, colors, pos, indexThree_, + OH_Drawing_TileMode::REPEAT); + OH_Drawing_BrushSetShaderEffect(brush, radialShaderEffect); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + // 扇形渐变着色器 + OH_Drawing_CanvasTranslate(canvas, value300_, 0.f); + OH_Drawing_ShaderEffect* sweepShaderEffect = + OH_Drawing_ShaderEffectCreateSweepGradient(centerPt, colors, pos, indexThree_, OH_Drawing_TileMode::CLAMP); + OH_Drawing_BrushSetShaderEffect(brush, sweepShaderEffect); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + // 双圆锥渐变着色器 + OH_Drawing_CanvasTranslate(canvas, value300_, 0.f); + OH_Drawing_Point2D pt3{value200_, value200_}; + OH_Drawing_ShaderEffect *twoPointShaderEffect = OH_Drawing_ShaderEffectCreateTwoPointConicalGradient( + &pt3, value30_, &pt3, value100_, colors, pos, indexThree_, OH_Drawing_TileMode::CLAMP, nullptr); + OH_Drawing_BrushSetShaderEffect(brush, twoPointShaderEffect); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + // 销毁各类对象 + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RectDestroy(rect); + OH_Drawing_ShaderEffectDestroy(radialShaderEffect); + OH_Drawing_ShaderEffectDestroy(sweepShaderEffect); + OH_Drawing_ShaderEffectDestroy(twoPointShaderEffect); +} + +void SampleGraphics::DrawShaderEffect(OH_Drawing_Canvas *canvas) +{ + // 线性渐变着色器 + DrawShaderEffect1Line(canvas); + OH_Drawing_CanvasTranslate(canvas, -value300_, value300_); + DrawShaderEffect2Line(canvas); +} + +void SampleGraphics::DrawColorFilter(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetAntiAlias(brush, true); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value100_, value100_, value300_, value300_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + OH_Drawing_CanvasTranslate(canvas, 0.f, value300_); + // 创建luma亮度颜色滤波器 + OH_Drawing_ColorFilter* lumaColorFilter = OH_Drawing_ColorFilterCreateLuma(); + OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); + OH_Drawing_FilterSetColorFilter(filter, lumaColorFilter); + OH_Drawing_BrushSetFilter(brush, filter); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 绘制经过luma亮度颜色滤波器效果的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + OH_Drawing_CanvasTranslate(canvas, 0.f, value300_); + const float matrix[20] = { + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 0.5f, 0.5f, 0, + 0, 0, 0.5f, 0.5f, 0 + }; + // 创建5*4矩阵颜色滤波器 + OH_Drawing_ColorFilter* matrixColorFilter = OH_Drawing_ColorFilterCreateMatrix(matrix); + // 创建从SRGB转换到线性颜色空间的颜色滤波器 + OH_Drawing_ColorFilter* s2lColorFilter = OH_Drawing_ColorFilterCreateSrgbGammaToLinear(); + // 创建从线性颜色空间转换到SRGB的颜色滤波器 + OH_Drawing_ColorFilter* l2sColorFilter = OH_Drawing_ColorFilterCreateLinearToSrgbGamma(); + // 创建合成滤波器 + OH_Drawing_ColorFilter* composeColorFilter1 = + OH_Drawing_ColorFilterCreateCompose(matrixColorFilter, s2lColorFilter); + OH_Drawing_ColorFilter* composeColorFilter2 = + OH_Drawing_ColorFilterCreateCompose(composeColorFilter1, l2sColorFilter); + OH_Drawing_FilterSetColorFilter(filter, composeColorFilter1); + OH_Drawing_BrushSetFilter(brush, filter); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 绘制经过合成颜色滤波器效果的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + + // 销毁各类对象 + OH_Drawing_BrushDestroy(brush); + OH_Drawing_ColorFilterDestroy(matrixColorFilter); + OH_Drawing_ColorFilterDestroy(lumaColorFilter); + OH_Drawing_ColorFilterDestroy(s2lColorFilter); + OH_Drawing_ColorFilterDestroy(l2sColorFilter); + OH_Drawing_ColorFilterDestroy(composeColorFilter1); + OH_Drawing_ColorFilterDestroy(composeColorFilter2); + OH_Drawing_RectDestroy(rect); + OH_Drawing_FilterDestroy(filter); +} + +void SampleGraphics::DrawMaskFilterBrush(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetAntiAlias(brush, true); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + // 创建模糊蒙版滤波器 + OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType::NORMAL, 20, true); + OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); + OH_Drawing_FilterSetMaskFilter(filter, maskFilter); + // 设置画刷的滤波器效果 + OH_Drawing_BrushSetFilter(brush, filter); + OH_Drawing_CanvasAttachBrush(canvas, brush); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + // 销毁各类对象 + OH_Drawing_BrushDestroy(brush); + OH_Drawing_MaskFilterDestroy(maskFilter); + OH_Drawing_RectDestroy(rect); + OH_Drawing_FilterDestroy(filter); +} diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_canvas.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_canvas.cpp index a42696723f09159bfbffd5fd08ca1136089b47bc..18a69c15902c893263c21e789b817d3a5c0b08d3 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_canvas.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_canvas.cpp @@ -1,194 +1,194 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" -#include "common/log_common.h" - -void SampleGraphics::DrawCreateCanvas(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); - OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; - uint64_t width = width_ / 2; - uint64_t height = height_ / 2; - OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); - // 创建一个canvas对象 - OH_Drawing_Canvas* newCanvas = OH_Drawing_CanvasCreate(); - // 将画布与bitmap绑定,画布画的内容会输出到绑定的bitmap内存中 - OH_Drawing_CanvasBind(newCanvas, bitmap); - // 使用红色清除画布内容 - OH_Drawing_CanvasClear(newCanvas, OH_Drawing_ColorSetArgb(rgbaHalf_, rgbaMax_, rgbaMin_, rgbaMin_)); - // 获取画布宽高 - SAMPLE_LOGI("Canvas-->width=%{public}d,height=%{public}d", OH_Drawing_CanvasGetWidth(newCanvas), - OH_Drawing_CanvasGetHeight(newCanvas)); - OH_Drawing_CanvasDrawBitmap(canvas, bitmap, 0, 0); - OH_Drawing_CanvasDestroy(newCanvas); - OH_Drawing_BitmapDestroy(bitmap); -} - -void SampleGraphics::DrawCanvasConcatMatrix(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix *matrix1 = OH_Drawing_MatrixCreateTranslation(value300_, value300_); - // 对画布进行矩阵操作 - OH_Drawing_CanvasConcatMatrix(canvas, matrix1); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreate(); - OH_Drawing_CanvasGetTotalMatrix(canvas, matrix2); - SAMPLE_LOGI("Canvas-->MatrixIsEqual=%{public}d", OH_Drawing_MatrixIsEqual(matrix1, matrix2) ? 1 : 0); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix1); - OH_Drawing_MatrixDestroy(matrix2); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawClipOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, 0xff0000ff); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value200_, value200_, value1000_, value1000_); - // 裁剪矩形区域 - OH_Drawing_CanvasClipRect(canvas, rect, OH_Drawing_CanvasClipOp::INTERSECT, true); - OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(0, 0, 0, 0); - OH_Drawing_CanvasGetLocalClipBounds(canvas, rect2); - SAMPLE_LOGI("Canvas-->ClipBounds:top=%{public}f,left=%{public}f,right=%{public}f,bottom=%{public}f", - OH_Drawing_RectGetTop(rect2), OH_Drawing_RectGetLeft(rect2), OH_Drawing_RectGetRight(rect2), - OH_Drawing_RectGetBottom(rect2)); - OH_Drawing_Path *path = OH_Drawing_PathCreate(); - OH_Drawing_PathAddCircle(path, value200_, value200_, value400_, PATH_DIRECTION_CCW); - // 裁剪圆形区域 - OH_Drawing_CanvasClipPath(canvas, path, OH_Drawing_CanvasClipOp::DIFFERENCE, true); - // 绘制背景 - OH_Drawing_CanvasDrawBackground(canvas, brush); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_PathDestroy(path); - OH_Drawing_RectDestroy(rect); - OH_Drawing_RectDestroy(rect2); -} - -void SampleGraphics::CanvasSaveOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - // 保存当前画布状态 - OH_Drawing_CanvasSave(canvas); - // 平移 - OH_Drawing_CanvasTranslate(canvas, 0.f, value200_); - // 保存当前画布状态 - OH_Drawing_CanvasSave(canvas); - // 获取画布状态数量 - SAMPLE_LOGI("Canvas-->saveCount=%{public}d", OH_Drawing_CanvasGetSaveCount(canvas)); - // 放大 - OH_Drawing_CanvasScale(canvas, 2.f, 2.f); - OH_Drawing_Point* point = OH_Drawing_PointCreate(value300_, value300_); - // 绘制圆形(经过放大和移动) - OH_Drawing_CanvasDrawCircle(canvas, point, value100_); - // 恢复操作 - OH_Drawing_CanvasRestore(canvas); - // 绘制圆形(仅经过移动) - OH_Drawing_CanvasDrawCircle(canvas, point, value100_); - // 恢复操作至最初状态 - OH_Drawing_CanvasRestoreToCount(canvas, 0); - // 绘制圆形(原始状态) - OH_Drawing_CanvasDrawCircle(canvas, point, value100_); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PenDestroy(pen); - OH_Drawing_PointDestroy(point); -} - -void SampleGraphics::CanvasSaveLayerOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush* brush1 = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush1, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush1); - OH_Drawing_Brush* brush2 = OH_Drawing_BrushCreate(); - // 创建图像滤波器实现模糊效果 - OH_Drawing_ImageFilter *imageFilter = - OH_Drawing_ImageFilterCreateBlur(value30_, value30_, OH_Drawing_TileMode::CLAMP, nullptr); - OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); - OH_Drawing_FilterSetImageFilter(filter, imageFilter); - OH_Drawing_BrushSetFilter(brush2, filter); - OH_Drawing_Rect* rect = OH_Drawing_RectCreate(0.f, 0.f, width_, height_); - // 保存当前画布状态 - OH_Drawing_CanvasSaveLayer(canvas, rect, brush2); - OH_Drawing_Point* point1 = OH_Drawing_PointCreate(value300_, value300_); - // 绘制圆形(经过模糊操作) - OH_Drawing_CanvasDrawCircle(canvas, point1, value100_); - // 恢复操作 - OH_Drawing_CanvasRestore(canvas); - OH_Drawing_Point* point2 = OH_Drawing_PointCreate(value300_, value700_); - // 绘制圆形 - OH_Drawing_CanvasDrawCircle(canvas, point2, value100_); - OH_Drawing_CanvasDetachBrush(canvas); - // 释放对象 - OH_Drawing_ImageFilterDestroy(imageFilter); - OH_Drawing_BrushDestroy(brush1); - OH_Drawing_BrushDestroy(brush2); - OH_Drawing_PointDestroy(point1); - OH_Drawing_PointDestroy(point2); - OH_Drawing_RectDestroy(rect); -} - -void SampleGraphics::DrawRegion(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 矩形区域1 - OH_Drawing_Region *region1 = OH_Drawing_RegionCreate(); - OH_Drawing_Rect *rect1 = OH_Drawing_RectCreate(value100_, value100_, value600_, value600_); - OH_Drawing_RegionSetRect(region1, rect1); - // 矩形区域2 - OH_Drawing_Region *region2 = OH_Drawing_RegionCreate(); - OH_Drawing_Rect *rect2 = OH_Drawing_RectCreate(value300_, value300_, value900_, value900_); - OH_Drawing_RegionSetRect(region2, rect2); - // 两个矩形区域组合 - OH_Drawing_RegionOp(region1, region2, OH_Drawing_RegionOpMode::REGION_OP_MODE_XOR); - OH_Drawing_CanvasDrawRegion(canvas, region1); - OH_Drawing_CanvasDetachBrush(canvas); - // 销毁各类对象 - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RegionDestroy(region1); - OH_Drawing_RegionDestroy(region2); - OH_Drawing_RectDestroy(rect1); - OH_Drawing_RectDestroy(rect2); -} +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" +#include "common/log_common.h" + +void SampleGraphics::DrawCreateCanvas(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); + OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; + uint64_t width = width_ / 2; + uint64_t height = height_ / 2; + OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); + // 创建一个canvas对象 + OH_Drawing_Canvas* newCanvas = OH_Drawing_CanvasCreate(); + // 将画布与bitmap绑定,画布画的内容会输出到绑定的bitmap内存中 + OH_Drawing_CanvasBind(newCanvas, bitmap); + // 使用红色清除画布内容 + OH_Drawing_CanvasClear(newCanvas, OH_Drawing_ColorSetArgb(rgbaHalf_, rgbaMax_, rgbaMin_, rgbaMin_)); + // 获取画布宽高 + SAMPLE_LOGI("Canvas-->width=%{public}d,height=%{public}d", OH_Drawing_CanvasGetWidth(newCanvas), + OH_Drawing_CanvasGetHeight(newCanvas)); + OH_Drawing_CanvasDrawBitmap(canvas, bitmap, 0, 0); + OH_Drawing_CanvasDestroy(newCanvas); + OH_Drawing_BitmapDestroy(bitmap); +} + +void SampleGraphics::DrawCanvasConcatMatrix(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix *matrix1 = OH_Drawing_MatrixCreateTranslation(value300_, value300_); + // 对画布进行矩阵操作 + OH_Drawing_CanvasConcatMatrix(canvas, matrix1); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreate(); + OH_Drawing_CanvasGetTotalMatrix(canvas, matrix2); + SAMPLE_LOGI("Canvas-->MatrixIsEqual=%{public}d", OH_Drawing_MatrixIsEqual(matrix1, matrix2) ? 1 : 0); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix1); + OH_Drawing_MatrixDestroy(matrix2); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawClipOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, 0xff0000ff); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value200_, value200_, value1000_, value1000_); + // 裁剪矩形区域 + OH_Drawing_CanvasClipRect(canvas, rect, OH_Drawing_CanvasClipOp::INTERSECT, true); + OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(0, 0, 0, 0); + OH_Drawing_CanvasGetLocalClipBounds(canvas, rect2); + SAMPLE_LOGI("Canvas-->ClipBounds:top=%{public}f,left=%{public}f,right=%{public}f,bottom=%{public}f", + OH_Drawing_RectGetTop(rect2), OH_Drawing_RectGetLeft(rect2), OH_Drawing_RectGetRight(rect2), + OH_Drawing_RectGetBottom(rect2)); + OH_Drawing_Path *path = OH_Drawing_PathCreate(); + OH_Drawing_PathAddCircle(path, value200_, value200_, value400_, PATH_DIRECTION_CCW); + // 裁剪圆形区域 + OH_Drawing_CanvasClipPath(canvas, path, OH_Drawing_CanvasClipOp::DIFFERENCE, true); + // 绘制背景 + OH_Drawing_CanvasDrawBackground(canvas, brush); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_PathDestroy(path); + OH_Drawing_RectDestroy(rect); + OH_Drawing_RectDestroy(rect2); +} + +void SampleGraphics::CanvasSaveOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + // 保存当前画布状态 + OH_Drawing_CanvasSave(canvas); + // 平移 + OH_Drawing_CanvasTranslate(canvas, 0.f, value200_); + // 保存当前画布状态 + OH_Drawing_CanvasSave(canvas); + // 获取画布状态数量 + SAMPLE_LOGI("Canvas-->saveCount=%{public}d", OH_Drawing_CanvasGetSaveCount(canvas)); + // 放大 + OH_Drawing_CanvasScale(canvas, 2.f, 2.f); + OH_Drawing_Point* point = OH_Drawing_PointCreate(value300_, value300_); + // 绘制圆形(经过放大和移动) + OH_Drawing_CanvasDrawCircle(canvas, point, value100_); + // 恢复操作 + OH_Drawing_CanvasRestore(canvas); + // 绘制圆形(仅经过移动) + OH_Drawing_CanvasDrawCircle(canvas, point, value100_); + // 恢复操作至最初状态 + OH_Drawing_CanvasRestoreToCount(canvas, 0); + // 绘制圆形(原始状态) + OH_Drawing_CanvasDrawCircle(canvas, point, value100_); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PenDestroy(pen); + OH_Drawing_PointDestroy(point); +} + +void SampleGraphics::CanvasSaveLayerOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush* brush1 = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush1, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush1); + OH_Drawing_Brush* brush2 = OH_Drawing_BrushCreate(); + // 创建图像滤波器实现模糊效果 + OH_Drawing_ImageFilter *imageFilter = + OH_Drawing_ImageFilterCreateBlur(value30_, value30_, OH_Drawing_TileMode::CLAMP, nullptr); + OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); + OH_Drawing_FilterSetImageFilter(filter, imageFilter); + OH_Drawing_BrushSetFilter(brush2, filter); + OH_Drawing_Rect* rect = OH_Drawing_RectCreate(0.f, 0.f, width_, height_); + // 保存当前画布状态 + OH_Drawing_CanvasSaveLayer(canvas, rect, brush2); + OH_Drawing_Point* point1 = OH_Drawing_PointCreate(value300_, value300_); + // 绘制圆形(经过模糊操作) + OH_Drawing_CanvasDrawCircle(canvas, point1, value100_); + // 恢复操作 + OH_Drawing_CanvasRestore(canvas); + OH_Drawing_Point* point2 = OH_Drawing_PointCreate(value300_, value700_); + // 绘制圆形 + OH_Drawing_CanvasDrawCircle(canvas, point2, value100_); + OH_Drawing_CanvasDetachBrush(canvas); + // 释放对象 + OH_Drawing_ImageFilterDestroy(imageFilter); + OH_Drawing_BrushDestroy(brush1); + OH_Drawing_BrushDestroy(brush2); + OH_Drawing_PointDestroy(point1); + OH_Drawing_PointDestroy(point2); + OH_Drawing_RectDestroy(rect); +} + +void SampleGraphics::DrawRegion(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 矩形区域1 + OH_Drawing_Region *region1 = OH_Drawing_RegionCreate(); + OH_Drawing_Rect *rect1 = OH_Drawing_RectCreate(value100_, value100_, value600_, value600_); + OH_Drawing_RegionSetRect(region1, rect1); + // 矩形区域2 + OH_Drawing_Region *region2 = OH_Drawing_RegionCreate(); + OH_Drawing_Rect *rect2 = OH_Drawing_RectCreate(value300_, value300_, value900_, value900_); + OH_Drawing_RegionSetRect(region2, rect2); + // 两个矩形区域组合 + OH_Drawing_RegionOp(region1, region2, OH_Drawing_RegionOpMode::REGION_OP_MODE_XOR); + OH_Drawing_CanvasDrawRegion(canvas, region1); + OH_Drawing_CanvasDetachBrush(canvas); + // 销毁各类对象 + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RegionDestroy(region1); + OH_Drawing_RegionDestroy(region2); + OH_Drawing_RectDestroy(rect1); + OH_Drawing_RectDestroy(rect2); +} diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_matrix.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_matrix.cpp index 04b17debe25e656bd59b2d5af0f4a238d5864e95..ded6e2098e732c5af95ce7bbf621b9ee2b0ab745 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_matrix.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_matrix.cpp @@ -1,306 +1,306 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" -#include "common/log_common.h" - -void SampleGraphics::DrawMatrixBasic(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - // 创建矩阵对象 - OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); - // 设置矩阵(平移) - OH_Drawing_MatrixSetMatrix(matrix, indexOne_, 0, value300_, 0, indexOne_, value300_, 0, 0, indexOne_); - OH_Drawing_Point2D src{value300_, value300_}; - OH_Drawing_Point2D dst; - // 源点坐标变换为目标点坐标 - OH_Drawing_MatrixMapPoints(matrix, &src, &dst, indexOne_); - SAMPLE_LOGI("DrawMatrixBasic-->point(src) x=%{public}f,y=%{public}f", src.x, src.y); - SAMPLE_LOGI("DrawMatrixBasic-->point(dst) x=%{public}f,y=%{public}f", dst.x, dst.y); - OH_Drawing_Rect *rect2 = OH_Drawing_RectCreate(0, 0, 0, 0); - // 源矩形变换为目标矩形 - OH_Drawing_MatrixMapRect(matrix, rect, rect2); - SAMPLE_LOGI("DrawMatrixBasic-->rect(src) left=%{public}f,top=%{public}f,right=%{public}f,bottom=%{public}f", - OH_Drawing_RectGetLeft(rect), OH_Drawing_RectGetTop(rect), OH_Drawing_RectGetRight(rect), - OH_Drawing_RectGetBottom(rect)); - SAMPLE_LOGI("DrawMatrixBasic-->rect(dst) left=%{public}f,top=%{public}f,right=%{public}f,bottom=%{public}f", - OH_Drawing_RectGetLeft(rect2), OH_Drawing_RectGetTop(rect2), OH_Drawing_RectGetRight(rect2), - OH_Drawing_RectGetBottom(rect2)); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreate(); - // 逆矩阵 - OH_Drawing_MatrixInvert(matrix2, matrix); - SAMPLE_LOGI( - "matrix2(%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f)", - OH_Drawing_MatrixGetValue(matrix, 0), OH_Drawing_MatrixGetValue(matrix, indexOne_), - OH_Drawing_MatrixGetValue(matrix, indexTwo_), OH_Drawing_MatrixGetValue(matrix, indexThree_), - OH_Drawing_MatrixGetValue(matrix, indexFour_), OH_Drawing_MatrixGetValue(matrix, indexFive_), - OH_Drawing_MatrixGetValue(matrix, indexSix_), OH_Drawing_MatrixGetValue(matrix, indexSeven_), - OH_Drawing_MatrixGetValue(matrix, indexNine_)); - // 重置矩阵 - OH_Drawing_MatrixReset(matrix); - OH_Drawing_CanvasDetachBrush(canvas); - // 释放对象 - OH_Drawing_RectDestroy(rect); - OH_Drawing_RectDestroy(rect2); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_MatrixDestroy(matrix2); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawTranslationOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - // 创建在水平和垂直方向分别平移300px的矩阵对象 - OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawPreTranslationOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); - // 旋转 - OH_Drawing_MatrixRotate(matrix, value45_, value300_, value300_); - // 左乘平移(先平移后旋转) - OH_Drawing_MatrixPreTranslate(matrix, value200_, value200_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawPostTranslationOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); - // 旋转 - OH_Drawing_MatrixRotate(matrix, value45_, value300_, value300_); - // 右乘平移(先旋转后平移) - OH_Drawing_MatrixPostTranslate(matrix, value200_, value200_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawRotationOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - // 创建旋转的矩阵对象 - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateRotation(value45_, value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawPreRotationOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate(); - // 平移 - OH_Drawing_MatrixTranslate(matrix, value200_, value200_); - // 左乘旋转(先旋转后平移) - OH_Drawing_MatrixPreRotate(matrix, value45_, value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawPostRotationOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate(); - // 平移 - OH_Drawing_MatrixTranslate(matrix, value200_, value200_); - // 右乘旋转(先平移后旋转) - OH_Drawing_MatrixPostRotate(matrix, value45_, value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_MatrixDestroy(matrix); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawScaleOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - // 创建缩放的矩阵对象 - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateScale(2, 2, value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_PenDestroy(pen); - OH_Drawing_MatrixDestroy(matrix); -} - -void SampleGraphics::DrawPreScaleOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateTranslation(value100_, value100_); - // 左乘缩放(先缩放后平移) - OH_Drawing_MatrixPreScale(matrix, indexTwo_, indexTwo_, value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_PenDestroy(pen); - OH_Drawing_MatrixDestroy(matrix); -} - -void SampleGraphics::DrawPostScaleOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateTranslation(value100_, value100_); - // 右乘缩放(先平移后缩放) - OH_Drawing_MatrixPostScale(matrix, indexTwo_, indexTwo_, value300_, value300_); - OH_Drawing_CanvasConcatMatrix(canvas, matrix); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_PenDestroy(pen); - OH_Drawing_MatrixDestroy(matrix); -} - -void SampleGraphics::DrawConcatOperation(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); - // 绘制原始矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_Matrix* matrix1 = OH_Drawing_MatrixCreateTranslation(value100_, value100_); - OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate(); - OH_Drawing_Matrix* matrix3 = OH_Drawing_MatrixCreate(); - OH_Drawing_MatrixScale(matrix2, indexTwo_, indexTwo_, value300_, value300_); - OH_Drawing_MatrixConcat(matrix3, matrix2, matrix1); - OH_Drawing_CanvasConcatMatrix(canvas, matrix3); - // 绘制变换后的矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_RectDestroy(rect); - OH_Drawing_PenDestroy(pen); - OH_Drawing_MatrixDestroy(matrix1); - OH_Drawing_MatrixDestroy(matrix2); - OH_Drawing_MatrixDestroy(matrix3); -} +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" +#include "common/log_common.h" + +void SampleGraphics::DrawMatrixBasic(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + // 创建矩阵对象 + OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); + // 设置矩阵(平移) + OH_Drawing_MatrixSetMatrix(matrix, indexOne_, 0, value300_, 0, indexOne_, value300_, 0, 0, indexOne_); + OH_Drawing_Point2D src{value300_, value300_}; + OH_Drawing_Point2D dst; + // 源点坐标变换为目标点坐标 + OH_Drawing_MatrixMapPoints(matrix, &src, &dst, indexOne_); + SAMPLE_LOGI("DrawMatrixBasic-->point(src) x=%{public}f,y=%{public}f", src.x, src.y); + SAMPLE_LOGI("DrawMatrixBasic-->point(dst) x=%{public}f,y=%{public}f", dst.x, dst.y); + OH_Drawing_Rect *rect2 = OH_Drawing_RectCreate(0, 0, 0, 0); + // 源矩形变换为目标矩形 + OH_Drawing_MatrixMapRect(matrix, rect, rect2); + SAMPLE_LOGI("DrawMatrixBasic-->rect(src) left=%{public}f,top=%{public}f,right=%{public}f,bottom=%{public}f", + OH_Drawing_RectGetLeft(rect), OH_Drawing_RectGetTop(rect), OH_Drawing_RectGetRight(rect), + OH_Drawing_RectGetBottom(rect)); + SAMPLE_LOGI("DrawMatrixBasic-->rect(dst) left=%{public}f,top=%{public}f,right=%{public}f,bottom=%{public}f", + OH_Drawing_RectGetLeft(rect2), OH_Drawing_RectGetTop(rect2), OH_Drawing_RectGetRight(rect2), + OH_Drawing_RectGetBottom(rect2)); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreate(); + // 逆矩阵 + OH_Drawing_MatrixInvert(matrix2, matrix); + SAMPLE_LOGI( + "matrix2(%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f,%{public}f)", + OH_Drawing_MatrixGetValue(matrix, 0), OH_Drawing_MatrixGetValue(matrix, indexOne_), + OH_Drawing_MatrixGetValue(matrix, indexTwo_), OH_Drawing_MatrixGetValue(matrix, indexThree_), + OH_Drawing_MatrixGetValue(matrix, indexFour_), OH_Drawing_MatrixGetValue(matrix, indexFive_), + OH_Drawing_MatrixGetValue(matrix, indexSix_), OH_Drawing_MatrixGetValue(matrix, indexSeven_), + OH_Drawing_MatrixGetValue(matrix, indexNine_)); + // 重置矩阵 + OH_Drawing_MatrixReset(matrix); + OH_Drawing_CanvasDetachBrush(canvas); + // 释放对象 + OH_Drawing_RectDestroy(rect); + OH_Drawing_RectDestroy(rect2); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_MatrixDestroy(matrix2); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawTranslationOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + // 创建在水平和垂直方向分别平移300px的矩阵对象 + OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreateTranslation(value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawPreTranslationOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); + // 旋转 + OH_Drawing_MatrixRotate(matrix, value45_, value300_, value300_); + // 左乘平移(先平移后旋转) + OH_Drawing_MatrixPreTranslate(matrix, value200_, value200_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawPostTranslationOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); + // 旋转 + OH_Drawing_MatrixRotate(matrix, value45_, value300_, value300_); + // 右乘平移(先旋转后平移) + OH_Drawing_MatrixPostTranslate(matrix, value200_, value200_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawRotationOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + // 创建旋转的矩阵对象 + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateRotation(value45_, value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawPreRotationOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate(); + // 平移 + OH_Drawing_MatrixTranslate(matrix, value200_, value200_); + // 左乘旋转(先旋转后平移) + OH_Drawing_MatrixPreRotate(matrix, value45_, value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawPostRotationOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreate(); + // 平移 + OH_Drawing_MatrixTranslate(matrix, value200_, value200_); + // 右乘旋转(先平移后旋转) + OH_Drawing_MatrixPostRotate(matrix, value45_, value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_MatrixDestroy(matrix); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawScaleOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + // 创建缩放的矩阵对象 + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateScale(2, 2, value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_PenDestroy(pen); + OH_Drawing_MatrixDestroy(matrix); +} + +void SampleGraphics::DrawPreScaleOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateTranslation(value100_, value100_); + // 左乘缩放(先缩放后平移) + OH_Drawing_MatrixPreScale(matrix, indexTwo_, indexTwo_, value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_PenDestroy(pen); + OH_Drawing_MatrixDestroy(matrix); +} + +void SampleGraphics::DrawPostScaleOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix* matrix = OH_Drawing_MatrixCreateTranslation(value100_, value100_); + // 右乘缩放(先平移后缩放) + OH_Drawing_MatrixPostScale(matrix, indexTwo_, indexTwo_, value300_, value300_); + OH_Drawing_CanvasConcatMatrix(canvas, matrix); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_PenDestroy(pen); + OH_Drawing_MatrixDestroy(matrix); +} + +void SampleGraphics::DrawConcatOperation(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value500_); + // 绘制原始矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_Matrix* matrix1 = OH_Drawing_MatrixCreateTranslation(value100_, value100_); + OH_Drawing_Matrix* matrix2 = OH_Drawing_MatrixCreate(); + OH_Drawing_Matrix* matrix3 = OH_Drawing_MatrixCreate(); + OH_Drawing_MatrixScale(matrix2, indexTwo_, indexTwo_, value300_, value300_); + OH_Drawing_MatrixConcat(matrix3, matrix2, matrix1); + OH_Drawing_CanvasConcatMatrix(canvas, matrix3); + // 绘制变换后的矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_RectDestroy(rect); + OH_Drawing_PenDestroy(pen); + OH_Drawing_MatrixDestroy(matrix1); + OH_Drawing_MatrixDestroy(matrix2); + OH_Drawing_MatrixDestroy(matrix3); +} diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_path.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_path.cpp index 7078c8ee41ccb63b1bb1c3b717a427293ff56c42..ae2265a1d9b1e8fbba0a865a3882fb848a1142e3 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_path.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_path.cpp @@ -1,453 +1,453 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" -#include "common/log_common.h" - -OH_Drawing_Path* SampleGraphics::DrawPathBasicTriangle(float startX, float startY, int32_t w) -{ - // 创建路径对象 - OH_Drawing_Path *path = OH_Drawing_PathCreate(); - // 设置填充路径规则 - OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_EVEN_ODD); - // 移动到起始点 - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - // 添加线段 - OH_Drawing_PathLineTo(path, startX + value15_, startY + value150_); - OH_Drawing_PathLineTo(path, startX + w - value15_, startY + value150_); - // 闭合路径 - OH_Drawing_PathClose(path); - // 判断路径是否包含坐标点 - SAMPLE_LOGI("PathBasic-->contains:%{public}d", - OH_Drawing_PathContains(path, startX + value30_, startY + value100_) ? 1 : 0); - // 判断路径是否闭合 - SAMPLE_LOGI("PathBasic-->isClosed:%{public}d", OH_Drawing_PathIsClosed(path, false) ? 1 : 0); - // 获取路径长度 - SAMPLE_LOGI("PathBasic-->getLength:%{public}f", OH_Drawing_PathGetLength(path, false)); - OH_Drawing_Rect* rect = OH_Drawing_RectCreate(0, 0, 0, 0); - // 获取边界 - OH_Drawing_PathGetBounds(path, rect); - SAMPLE_LOGI("PathBasic-->getBounds:left=%{public}f,top=%{public}f,right=%{public}f,bottom=%{public}f", - OH_Drawing_RectGetLeft(rect), OH_Drawing_RectGetTop(rect), OH_Drawing_RectGetRight(rect), - OH_Drawing_RectGetBottom(rect)); - OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); - // 获取变换矩阵 - OH_Drawing_PathGetMatrix(path, false, value50_, matrix, OH_Drawing_PathMeasureMatrixFlags::GET_POSITION_MATRIX); - OH_Drawing_Point2D point{startX + value30_, startY + value150_}; - OH_Drawing_Point2D tangent{0, 0}; - // 获取坐标点和切线 - OH_Drawing_PathGetPositionTangent(path, false, 1, &point, &tangent); - SAMPLE_LOGI("PathBasic-->tangent.x=%{public}f,tangent.y=%{public}f", tangent.x, tangent.y); - OH_Drawing_MatrixDestroy(matrix); - return path; -} - -void SampleGraphics::DrawPathBasic(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value100_; - OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetAntiAlias(pen, true); - float penWidth = 3.f; - OH_Drawing_PenSetWidth(pen, penWidth); - OH_Drawing_CanvasAttachPen(canvas, pen); - - // 三角形1 - OH_Drawing_Path *path = DrawPathBasicTriangle(startX, startY, w); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 三角形2 - // 复制路径 - OH_Drawing_Path *path_copy = OH_Drawing_PathCopy(path); - OH_Drawing_Matrix *matrix_translate = OH_Drawing_MatrixCreateTranslation(w, 0); - // 对路径进行矩阵变换 - OH_Drawing_PathTransform(path_copy, matrix_translate); - OH_Drawing_CanvasDrawPath(canvas, path_copy); - - // 三角形3 - OH_Drawing_Path *path_third = OH_Drawing_PathCreate(); - // 对路径进行矩阵变换 - OH_Drawing_PathTransformWithPerspectiveClip(path_copy, matrix_translate, path_third, false); - OH_Drawing_CanvasDrawPath(canvas, path_third); - - // 三角形4 - OH_Drawing_Path *path_fourth = OH_Drawing_PathCreate(); - OH_Drawing_PathOffset(path, path_fourth, w * indexThree_, 0); - OH_Drawing_CanvasDrawPath(canvas, path_fourth); - - // 梯形 - startX += indexFour_ * w; - OH_Drawing_Path *path_fifth = OH_Drawing_PathCreate(); - OH_Drawing_PathMoveTo(path_fifth, startX + value15_, startY); - OH_Drawing_PathLineTo(path_fifth, startX + value15_, startY + value100_); - OH_Drawing_PathLineTo(path_fifth, startX + w - value15_, startY + value100_); - OH_Drawing_PathTransform(path_fourth, matrix_translate); - // 将两个路径合并(取差集) - OH_Drawing_PathOp(path_fifth, path_fourth, OH_Drawing_PathOpMode::PATH_OP_MODE_REVERSE_DIFFERENCE); - OH_Drawing_CanvasDrawPath(canvas, path_fifth); - - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PathDestroy(path); - OH_Drawing_PathDestroy(path_copy); - OH_Drawing_PathDestroy(path_third); - OH_Drawing_PathDestroy(path_fourth); - OH_Drawing_PathDestroy(path_fifth); - OH_Drawing_MatrixDestroy(matrix_translate); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawPathTo1Line(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value100_; - OH_Drawing_Path *path = OH_Drawing_PathCreate(); - - // 线段 - OH_Drawing_PathMoveTo(path, startX + value15_, startY + value70_); - OH_Drawing_PathLineTo(path, startX + w - value15_, startY + value70_); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 弧线 - startX += w; - OH_Drawing_PathReset(path); - float startDeg = 60; - float sweepDeg = -240; - OH_Drawing_PathArcTo(path, startX + value15_, startY + value30_, startX + w - value15_, startY + value150_, - startDeg, sweepDeg); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 二阶贝塞尔曲线 - startX += w; - OH_Drawing_PathReset(path); - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - OH_Drawing_PathQuadTo(path, startX + value30_, startY + value100_, startX + w - value15_, startY + value150_); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 二阶贝塞尔曲线(带权重) - startX += w; - OH_Drawing_PathReset(path); - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - float weight = 5.f; - OH_Drawing_PathConicTo(path, startX + value30_, startY + value100_, startX + w - value15_, startY + value150_, - weight); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 三阶贝塞尔曲线 - startX += w; - OH_Drawing_PathReset(path); - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - OH_Drawing_PathCubicTo(path, startX + value30_, startY + value120_, startX + w - value30_, startY + value30_, - startX + w - value15_, startY + value150_); - OH_Drawing_CanvasDrawPath(canvas, path); - - OH_Drawing_PathDestroy(path); -} - -void SampleGraphics::DrawPathTo2Line(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value300_; - OH_Drawing_Path *path = OH_Drawing_PathCreate(); - - // 线段 - OH_Drawing_PathMoveTo(path, startX, startY); - OH_Drawing_PathRMoveTo(path, value15_, value70_); - OH_Drawing_PathRLineTo(path, w - value30_, 0); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 二阶贝塞尔曲线 - startX += w; - OH_Drawing_PathReset(path); - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - OH_Drawing_PathRQuadTo(path, value30_, value100_, w - value10_, value150_); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 二阶贝塞尔曲线(带权重) - startX += w; - OH_Drawing_PathReset(path); - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - float weight = 5.f; - OH_Drawing_PathRConicTo(path, value30_, value100_, w - value15_, value150_, weight); - OH_Drawing_CanvasDrawPath(canvas, path); - - // 三阶贝塞尔曲线 - startX += w; - OH_Drawing_PathReset(path); - OH_Drawing_PathMoveTo(path, startX + value15_, startY); - OH_Drawing_PathRCubicTo(path, value30_, value120_, w - value30_, value30_, w - value10_, value150_); - OH_Drawing_CanvasDrawPath(canvas, path); - - OH_Drawing_PathDestroy(path); -} - -void SampleGraphics::DrawPathTo(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetAntiAlias(pen, true); - float penWidth = 3.f; - OH_Drawing_PenSetWidth(pen, penWidth); - OH_Drawing_CanvasAttachPen(canvas, pen); - - DrawPathTo1Line(canvas); - OH_Drawing_CanvasTranslate(canvas, 0, value200_); - DrawPathTo2Line(canvas); - - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::DrawPathAdd1Line(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value100_; - // 圆 - OH_Drawing_Path *pathCircle = OH_Drawing_PathCreate(); - float radius = 40; - float startYAdded = 60; - OH_Drawing_PathAddCircle(pathCircle, startX + w / indexTwo_, startY + startYAdded, radius, PATH_DIRECTION_CCW); - OH_Drawing_CanvasDrawPath(canvas, pathCircle); - OH_Drawing_PathDestroy(pathCircle); - // 矩形 - startX += w; - OH_Drawing_Path *pathRect = OH_Drawing_PathCreate(); - OH_Drawing_PathAddRect(pathRect, startX + value10_, startY + value30_, startX + w - value10_, - startY + value90_, PATH_DIRECTION_CCW); - OH_Drawing_CanvasDrawPath(canvas, pathRect); - OH_Drawing_PathDestroy(pathRect); - // 椭圆 - startX += w; - OH_Drawing_Path *pathOval = OH_Drawing_PathCreate(); - OH_Drawing_Rect *rectOval = OH_Drawing_RectCreate(startX + value10_, startY + value30_, - startX + w - value10_, startY + value90_); - OH_Drawing_PathAddOval(pathOval, rectOval, OH_Drawing_PathDirection::PATH_DIRECTION_CW); - OH_Drawing_CanvasDrawPath(canvas, pathOval); - OH_Drawing_RectDestroy(rectOval); - OH_Drawing_PathDestroy(pathOval); - // 圆角矩形 - startX += w; - OH_Drawing_Path *pathRoundRect = OH_Drawing_PathCreate(); - OH_Drawing_Rect *rectRoundRect = OH_Drawing_RectCreate(startX + value10_, startY + value30_, - startX + w - value10_, startY + value90_); - OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rectRoundRect, value20_, value20_); - OH_Drawing_PathAddRoundRect(pathRoundRect, roundRect, PATH_DIRECTION_CCW); - OH_Drawing_CanvasDrawPath(canvas, pathRoundRect); - OH_Drawing_RectDestroy(rectRoundRect); - OH_Drawing_PathDestroy(pathRoundRect); - OH_Drawing_RoundRectDestroy(roundRect); -} - -void SampleGraphics::DrawPathAdd2Line(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value100_; - // 多边形 - OH_Drawing_Path *pathPolygon = OH_Drawing_PathCreate(); - float leftPointX = startX + value10_; - float rightPointX = startX + w - value10_; - float middlePointX = (leftPointX + rightPointX) / 2; - OH_Drawing_Point2D points[] = {{middlePointX, startY + value30_}, {leftPointX, startY + value90_}, - {rightPointX, startY + value90_}}; - OH_Drawing_PathAddPolygon(pathPolygon, points, 3, true); // 3 is the size of point array - OH_Drawing_CanvasDrawPath(canvas, pathPolygon); - OH_Drawing_PathDestroy(pathPolygon); - // 曲线 - startX += w; - OH_Drawing_Rect *rectArc = OH_Drawing_RectCreate(startX - value30_, startY + value30_, - startX + w - value10_, startY + value150_); - OH_Drawing_Path *pathArc = OH_Drawing_PathCreate(); - OH_Drawing_PathAddArc(pathArc, rectArc, 0, -value90_); - OH_Drawing_CanvasDrawPath(canvas, pathArc); - OH_Drawing_RectDestroy(rectArc); - OH_Drawing_PathDestroy(pathArc); -} - -void SampleGraphics::DrawPathAdd3Line(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value100_; - // 线段1 - OH_Drawing_Path *pathOuter1 = OH_Drawing_PathCreate(); - OH_Drawing_Path *pathInner1 = OH_Drawing_PathCreate(); - OH_Drawing_PathMoveTo(pathInner1, startX + value10_, startY); - OH_Drawing_PathLineTo(pathInner1, startX + w - value10_, startY); - OH_Drawing_Matrix *matrix1 = OH_Drawing_MatrixCreateTranslation(0, value50_); - OH_Drawing_PathAddPath(pathOuter1, pathInner1, matrix1); - OH_Drawing_CanvasDrawPath(canvas, pathOuter1); - OH_Drawing_PathDestroy(pathOuter1); - OH_Drawing_PathDestroy(pathInner1); - OH_Drawing_MatrixDestroy(matrix1); - // 线段2 - startX += w; - OH_Drawing_Path *pathOuter2 = OH_Drawing_PathCreate(); - OH_Drawing_Path *pathInner2 = OH_Drawing_PathCreate(); - OH_Drawing_PathMoveTo(pathInner2, startX + value10_, startY + value50_); - OH_Drawing_PathLineTo(pathInner2, startX + w - value10_, startY + value50_); - OH_Drawing_PathAddPathWithMode(pathOuter2, pathInner2, OH_Drawing_PathAddMode::PATH_ADD_MODE_APPEND); - OH_Drawing_CanvasDrawPath(canvas, pathOuter2); - OH_Drawing_PathDestroy(pathOuter2); - OH_Drawing_PathDestroy(pathInner2); - // 线段3 - startX += w; - OH_Drawing_Path *pathOuter3 = OH_Drawing_PathCreate(); - OH_Drawing_Path *pathInner3 = OH_Drawing_PathCreate(); - OH_Drawing_PathMoveTo(pathInner3, startX + value10_, startY); - OH_Drawing_PathLineTo(pathInner3, startX + w - value10_, startY); - OH_Drawing_PathAddPathWithOffsetAndMode(pathOuter3, pathInner3, 0, value50_, - OH_Drawing_PathAddMode::PATH_ADD_MODE_APPEND); - OH_Drawing_CanvasDrawPath(canvas, pathOuter3); - OH_Drawing_PathDestroy(pathOuter3); - OH_Drawing_PathDestroy(pathInner3); - // 线段4 - startX += w; - OH_Drawing_Path *pathOuter4 = OH_Drawing_PathCreate(); - OH_Drawing_Path *pathInner4 = OH_Drawing_PathCreate(); - OH_Drawing_PathMoveTo(pathInner4, startX + value10_, startY); - OH_Drawing_PathLineTo(pathInner4, startX + w - value10_, startY); - OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateTranslation(0, value50_); - OH_Drawing_PathAddPathWithMatrixAndMode(pathOuter4, pathInner4, matrix2, - OH_Drawing_PathAddMode::PATH_ADD_MODE_APPEND); - OH_Drawing_CanvasDrawPath(canvas, pathOuter4); - OH_Drawing_PathDestroy(pathOuter4); - OH_Drawing_PathDestroy(pathInner4); - OH_Drawing_MatrixDestroy(matrix2); -} - -void SampleGraphics::DrawPathAdd4Line(OH_Drawing_Canvas *canvas) -{ - int32_t w = width_ / indexFive_; - float startX = 0; - float startY = value100_; - // 椭圆 - OH_Drawing_Path *pathOval = OH_Drawing_PathCreate(); - OH_Drawing_Rect *rectOval = OH_Drawing_RectCreate(startX + value10_, startY + value30_, - startX + w - value10_, startY + value90_); - OH_Drawing_PathAddOvalWithInitialPoint(pathOval, rectOval, 1, OH_Drawing_PathDirection::PATH_DIRECTION_CW); - OH_Drawing_CanvasDrawPath(canvas, pathOval); - OH_Drawing_RectDestroy(rectOval); - OH_Drawing_PathDestroy(pathOval); - // 矩形 - startX += w; - OH_Drawing_Path *pathRect = OH_Drawing_PathCreate(); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(startX + value10_, startY + value30_, - startX + w - value10_, startY + value90_); - OH_Drawing_PathAddRectWithInitialCorner(pathRect, rect, PATH_DIRECTION_CCW, 1); - OH_Drawing_CanvasDrawPath(canvas, pathRect); - OH_Drawing_PathDestroy(pathRect); - OH_Drawing_RectDestroy(rect); -} - -void SampleGraphics::DrawPathAdd(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetAntiAlias(pen, true); - float penWidth = 3.f; - OH_Drawing_PenSetWidth(pen, penWidth); - OH_Drawing_CanvasAttachPen(canvas, pen); - - DrawPathAdd1Line(canvas); - OH_Drawing_CanvasTranslate(canvas, 0, value200_); - DrawPathAdd2Line(canvas); - OH_Drawing_CanvasTranslate(canvas, 0, value200_); - DrawPathAdd3Line(canvas); - OH_Drawing_CanvasTranslate(canvas, 0, value200_); - DrawPathAdd4Line(canvas); - - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PenDestroy(pen); -} - -void SampleGraphics::BuildFromSvgString(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush); - char* str = "M150 130L30 300L270 300Z"; - OH_Drawing_Path* path = OH_Drawing_PathCreate(); - // 通过svg构建path - OH_Drawing_PathBuildFromSvgString(path, str); - OH_Drawing_CanvasDrawPath(canvas, path); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_PathDestroy(path); -} - -void SampleGraphics::DrawStar(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - OH_Drawing_PenSetJoin(pen, LINE_ROUND_JOIN); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMax_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush); - int len = value551_; - float aX = value630_; - float aY = value551_; - float angle = 18.0f; - float dX = aX - len * std::sin(angle); - float dY = aY + len * std::cos(angle); - float cX = aX + len * std::sin(angle); - float cY = dY; - float bX = aX + (len / 2.0); - float bY = aY + std::sqrt((cX - dX) * (cX - dX) + (len / 2.0) * (len / 2.0)); - float eX = aX - (len / 2.0); - float eY = bY; - // 创建路径 - OH_Drawing_Path* path = OH_Drawing_PathCreate(); - // 到起始点 - OH_Drawing_PathMoveTo(path, aX, aY); - // 绘制直线 - OH_Drawing_PathLineTo(path, bX, bY); - OH_Drawing_PathLineTo(path, cX, cY); - OH_Drawing_PathLineTo(path, dX, dY); - OH_Drawing_PathLineTo(path, eX, eY); - // 直线闭合,形成五角星 - OH_Drawing_PathClose(path); - // 绘制闭合路径 - OH_Drawing_CanvasDrawPath(canvas, path); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_PenDestroy(pen); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_PathDestroy(path); +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" +#include "common/log_common.h" + +OH_Drawing_Path* SampleGraphics::DrawPathBasicTriangle(float startX, float startY, int32_t w) +{ + // 创建路径对象 + OH_Drawing_Path *path = OH_Drawing_PathCreate(); + // 设置填充路径规则 + OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_EVEN_ODD); + // 移动到起始点 + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + // 添加线段 + OH_Drawing_PathLineTo(path, startX + value15_, startY + value150_); + OH_Drawing_PathLineTo(path, startX + w - value15_, startY + value150_); + // 闭合路径 + OH_Drawing_PathClose(path); + // 判断路径是否包含坐标点 + SAMPLE_LOGI("PathBasic-->contains:%{public}d", + OH_Drawing_PathContains(path, startX + value30_, startY + value100_) ? 1 : 0); + // 判断路径是否闭合 + SAMPLE_LOGI("PathBasic-->isClosed:%{public}d", OH_Drawing_PathIsClosed(path, false) ? 1 : 0); + // 获取路径长度 + SAMPLE_LOGI("PathBasic-->getLength:%{public}f", OH_Drawing_PathGetLength(path, false)); + OH_Drawing_Rect* rect = OH_Drawing_RectCreate(0, 0, 0, 0); + // 获取边界 + OH_Drawing_PathGetBounds(path, rect); + SAMPLE_LOGI("PathBasic-->getBounds:left=%{public}f,top=%{public}f,right=%{public}f,bottom=%{public}f", + OH_Drawing_RectGetLeft(rect), OH_Drawing_RectGetTop(rect), OH_Drawing_RectGetRight(rect), + OH_Drawing_RectGetBottom(rect)); + OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate(); + // 获取变换矩阵 + OH_Drawing_PathGetMatrix(path, false, value50_, matrix, OH_Drawing_PathMeasureMatrixFlags::GET_POSITION_MATRIX); + OH_Drawing_Point2D point{startX + value30_, startY + value150_}; + OH_Drawing_Point2D tangent{0, 0}; + // 获取坐标点和切线 + OH_Drawing_PathGetPositionTangent(path, false, 1, &point, &tangent); + SAMPLE_LOGI("PathBasic-->tangent.x=%{public}f,tangent.y=%{public}f", tangent.x, tangent.y); + OH_Drawing_MatrixDestroy(matrix); + return path; +} + +void SampleGraphics::DrawPathBasic(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value100_; + OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetAntiAlias(pen, true); + float penWidth = 3.f; + OH_Drawing_PenSetWidth(pen, penWidth); + OH_Drawing_CanvasAttachPen(canvas, pen); + + // 三角形1 + OH_Drawing_Path *path = DrawPathBasicTriangle(startX, startY, w); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 三角形2 + // 复制路径 + OH_Drawing_Path *path_copy = OH_Drawing_PathCopy(path); + OH_Drawing_Matrix *matrix_translate = OH_Drawing_MatrixCreateTranslation(w, 0); + // 对路径进行矩阵变换 + OH_Drawing_PathTransform(path_copy, matrix_translate); + OH_Drawing_CanvasDrawPath(canvas, path_copy); + + // 三角形3 + OH_Drawing_Path *path_third = OH_Drawing_PathCreate(); + // 对路径进行矩阵变换 + OH_Drawing_PathTransformWithPerspectiveClip(path_copy, matrix_translate, path_third, false); + OH_Drawing_CanvasDrawPath(canvas, path_third); + + // 三角形4 + OH_Drawing_Path *path_fourth = OH_Drawing_PathCreate(); + OH_Drawing_PathOffset(path, path_fourth, w * indexThree_, 0); + OH_Drawing_CanvasDrawPath(canvas, path_fourth); + + // 梯形 + startX += indexFour_ * w; + OH_Drawing_Path *path_fifth = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(path_fifth, startX + value15_, startY); + OH_Drawing_PathLineTo(path_fifth, startX + value15_, startY + value100_); + OH_Drawing_PathLineTo(path_fifth, startX + w - value15_, startY + value100_); + OH_Drawing_PathTransform(path_fourth, matrix_translate); + // 将两个路径合并(取差集) + OH_Drawing_PathOp(path_fifth, path_fourth, OH_Drawing_PathOpMode::PATH_OP_MODE_REVERSE_DIFFERENCE); + OH_Drawing_CanvasDrawPath(canvas, path_fifth); + + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PathDestroy(path); + OH_Drawing_PathDestroy(path_copy); + OH_Drawing_PathDestroy(path_third); + OH_Drawing_PathDestroy(path_fourth); + OH_Drawing_PathDestroy(path_fifth); + OH_Drawing_MatrixDestroy(matrix_translate); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawPathTo1Line(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value100_; + OH_Drawing_Path *path = OH_Drawing_PathCreate(); + + // 线段 + OH_Drawing_PathMoveTo(path, startX + value15_, startY + value70_); + OH_Drawing_PathLineTo(path, startX + w - value15_, startY + value70_); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 弧线 + startX += w; + OH_Drawing_PathReset(path); + float startDeg = 60; + float sweepDeg = -240; + OH_Drawing_PathArcTo(path, startX + value15_, startY + value30_, startX + w - value15_, startY + value150_, + startDeg, sweepDeg); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 二阶贝塞尔曲线 + startX += w; + OH_Drawing_PathReset(path); + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + OH_Drawing_PathQuadTo(path, startX + value30_, startY + value100_, startX + w - value15_, startY + value150_); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 二阶贝塞尔曲线(带权重) + startX += w; + OH_Drawing_PathReset(path); + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + float weight = 5.f; + OH_Drawing_PathConicTo(path, startX + value30_, startY + value100_, startX + w - value15_, startY + value150_, + weight); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 三阶贝塞尔曲线 + startX += w; + OH_Drawing_PathReset(path); + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + OH_Drawing_PathCubicTo(path, startX + value30_, startY + value120_, startX + w - value30_, startY + value30_, + startX + w - value15_, startY + value150_); + OH_Drawing_CanvasDrawPath(canvas, path); + + OH_Drawing_PathDestroy(path); +} + +void SampleGraphics::DrawPathTo2Line(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value300_; + OH_Drawing_Path *path = OH_Drawing_PathCreate(); + + // 线段 + OH_Drawing_PathMoveTo(path, startX, startY); + OH_Drawing_PathRMoveTo(path, value15_, value70_); + OH_Drawing_PathRLineTo(path, w - value30_, 0); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 二阶贝塞尔曲线 + startX += w; + OH_Drawing_PathReset(path); + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + OH_Drawing_PathRQuadTo(path, value30_, value100_, w - value10_, value150_); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 二阶贝塞尔曲线(带权重) + startX += w; + OH_Drawing_PathReset(path); + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + float weight = 5.f; + OH_Drawing_PathRConicTo(path, value30_, value100_, w - value15_, value150_, weight); + OH_Drawing_CanvasDrawPath(canvas, path); + + // 三阶贝塞尔曲线 + startX += w; + OH_Drawing_PathReset(path); + OH_Drawing_PathMoveTo(path, startX + value15_, startY); + OH_Drawing_PathRCubicTo(path, value30_, value120_, w - value30_, value30_, w - value10_, value150_); + OH_Drawing_CanvasDrawPath(canvas, path); + + OH_Drawing_PathDestroy(path); +} + +void SampleGraphics::DrawPathTo(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetAntiAlias(pen, true); + float penWidth = 3.f; + OH_Drawing_PenSetWidth(pen, penWidth); + OH_Drawing_CanvasAttachPen(canvas, pen); + + DrawPathTo1Line(canvas); + OH_Drawing_CanvasTranslate(canvas, 0, value200_); + DrawPathTo2Line(canvas); + + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::DrawPathAdd1Line(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value100_; + // 圆 + OH_Drawing_Path *pathCircle = OH_Drawing_PathCreate(); + float radius = 40; + float startYAdded = 60; + OH_Drawing_PathAddCircle(pathCircle, startX + w / indexTwo_, startY + startYAdded, radius, PATH_DIRECTION_CCW); + OH_Drawing_CanvasDrawPath(canvas, pathCircle); + OH_Drawing_PathDestroy(pathCircle); + // 矩形 + startX += w; + OH_Drawing_Path *pathRect = OH_Drawing_PathCreate(); + OH_Drawing_PathAddRect(pathRect, startX + value10_, startY + value30_, startX + w - value10_, + startY + value90_, PATH_DIRECTION_CCW); + OH_Drawing_CanvasDrawPath(canvas, pathRect); + OH_Drawing_PathDestroy(pathRect); + // 椭圆 + startX += w; + OH_Drawing_Path *pathOval = OH_Drawing_PathCreate(); + OH_Drawing_Rect *rectOval = OH_Drawing_RectCreate(startX + value10_, startY + value30_, + startX + w - value10_, startY + value90_); + OH_Drawing_PathAddOval(pathOval, rectOval, OH_Drawing_PathDirection::PATH_DIRECTION_CW); + OH_Drawing_CanvasDrawPath(canvas, pathOval); + OH_Drawing_RectDestroy(rectOval); + OH_Drawing_PathDestroy(pathOval); + // 圆角矩形 + startX += w; + OH_Drawing_Path *pathRoundRect = OH_Drawing_PathCreate(); + OH_Drawing_Rect *rectRoundRect = OH_Drawing_RectCreate(startX + value10_, startY + value30_, + startX + w - value10_, startY + value90_); + OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rectRoundRect, value20_, value20_); + OH_Drawing_PathAddRoundRect(pathRoundRect, roundRect, PATH_DIRECTION_CCW); + OH_Drawing_CanvasDrawPath(canvas, pathRoundRect); + OH_Drawing_RectDestroy(rectRoundRect); + OH_Drawing_PathDestroy(pathRoundRect); + OH_Drawing_RoundRectDestroy(roundRect); +} + +void SampleGraphics::DrawPathAdd2Line(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value100_; + // 多边形 + OH_Drawing_Path *pathPolygon = OH_Drawing_PathCreate(); + float leftPointX = startX + value10_; + float rightPointX = startX + w - value10_; + float middlePointX = (leftPointX + rightPointX) / 2; + OH_Drawing_Point2D points[] = {{middlePointX, startY + value30_}, {leftPointX, startY + value90_}, + {rightPointX, startY + value90_}}; + OH_Drawing_PathAddPolygon(pathPolygon, points, 3, true); // 3 is the size of point array + OH_Drawing_CanvasDrawPath(canvas, pathPolygon); + OH_Drawing_PathDestroy(pathPolygon); + // 曲线 + startX += w; + OH_Drawing_Rect *rectArc = OH_Drawing_RectCreate(startX - value30_, startY + value30_, + startX + w - value10_, startY + value150_); + OH_Drawing_Path *pathArc = OH_Drawing_PathCreate(); + OH_Drawing_PathAddArc(pathArc, rectArc, 0, -value90_); + OH_Drawing_CanvasDrawPath(canvas, pathArc); + OH_Drawing_RectDestroy(rectArc); + OH_Drawing_PathDestroy(pathArc); +} + +void SampleGraphics::DrawPathAdd3Line(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value100_; + // 线段1 + OH_Drawing_Path *pathOuter1 = OH_Drawing_PathCreate(); + OH_Drawing_Path *pathInner1 = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(pathInner1, startX + value10_, startY); + OH_Drawing_PathLineTo(pathInner1, startX + w - value10_, startY); + OH_Drawing_Matrix *matrix1 = OH_Drawing_MatrixCreateTranslation(0, value50_); + OH_Drawing_PathAddPath(pathOuter1, pathInner1, matrix1); + OH_Drawing_CanvasDrawPath(canvas, pathOuter1); + OH_Drawing_PathDestroy(pathOuter1); + OH_Drawing_PathDestroy(pathInner1); + OH_Drawing_MatrixDestroy(matrix1); + // 线段2 + startX += w; + OH_Drawing_Path *pathOuter2 = OH_Drawing_PathCreate(); + OH_Drawing_Path *pathInner2 = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(pathInner2, startX + value10_, startY + value50_); + OH_Drawing_PathLineTo(pathInner2, startX + w - value10_, startY + value50_); + OH_Drawing_PathAddPathWithMode(pathOuter2, pathInner2, OH_Drawing_PathAddMode::PATH_ADD_MODE_APPEND); + OH_Drawing_CanvasDrawPath(canvas, pathOuter2); + OH_Drawing_PathDestroy(pathOuter2); + OH_Drawing_PathDestroy(pathInner2); + // 线段3 + startX += w; + OH_Drawing_Path *pathOuter3 = OH_Drawing_PathCreate(); + OH_Drawing_Path *pathInner3 = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(pathInner3, startX + value10_, startY); + OH_Drawing_PathLineTo(pathInner3, startX + w - value10_, startY); + OH_Drawing_PathAddPathWithOffsetAndMode(pathOuter3, pathInner3, 0, value50_, + OH_Drawing_PathAddMode::PATH_ADD_MODE_APPEND); + OH_Drawing_CanvasDrawPath(canvas, pathOuter3); + OH_Drawing_PathDestroy(pathOuter3); + OH_Drawing_PathDestroy(pathInner3); + // 线段4 + startX += w; + OH_Drawing_Path *pathOuter4 = OH_Drawing_PathCreate(); + OH_Drawing_Path *pathInner4 = OH_Drawing_PathCreate(); + OH_Drawing_PathMoveTo(pathInner4, startX + value10_, startY); + OH_Drawing_PathLineTo(pathInner4, startX + w - value10_, startY); + OH_Drawing_Matrix *matrix2 = OH_Drawing_MatrixCreateTranslation(0, value50_); + OH_Drawing_PathAddPathWithMatrixAndMode(pathOuter4, pathInner4, matrix2, + OH_Drawing_PathAddMode::PATH_ADD_MODE_APPEND); + OH_Drawing_CanvasDrawPath(canvas, pathOuter4); + OH_Drawing_PathDestroy(pathOuter4); + OH_Drawing_PathDestroy(pathInner4); + OH_Drawing_MatrixDestroy(matrix2); +} + +void SampleGraphics::DrawPathAdd4Line(OH_Drawing_Canvas *canvas) +{ + int32_t w = width_ / indexFive_; + float startX = 0; + float startY = value100_; + // 椭圆 + OH_Drawing_Path *pathOval = OH_Drawing_PathCreate(); + OH_Drawing_Rect *rectOval = OH_Drawing_RectCreate(startX + value10_, startY + value30_, + startX + w - value10_, startY + value90_); + OH_Drawing_PathAddOvalWithInitialPoint(pathOval, rectOval, 1, OH_Drawing_PathDirection::PATH_DIRECTION_CW); + OH_Drawing_CanvasDrawPath(canvas, pathOval); + OH_Drawing_RectDestroy(rectOval); + OH_Drawing_PathDestroy(pathOval); + // 矩形 + startX += w; + OH_Drawing_Path *pathRect = OH_Drawing_PathCreate(); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(startX + value10_, startY + value30_, + startX + w - value10_, startY + value90_); + OH_Drawing_PathAddRectWithInitialCorner(pathRect, rect, PATH_DIRECTION_CCW, 1); + OH_Drawing_CanvasDrawPath(canvas, pathRect); + OH_Drawing_PathDestroy(pathRect); + OH_Drawing_RectDestroy(rect); +} + +void SampleGraphics::DrawPathAdd(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetAntiAlias(pen, true); + float penWidth = 3.f; + OH_Drawing_PenSetWidth(pen, penWidth); + OH_Drawing_CanvasAttachPen(canvas, pen); + + DrawPathAdd1Line(canvas); + OH_Drawing_CanvasTranslate(canvas, 0, value200_); + DrawPathAdd2Line(canvas); + OH_Drawing_CanvasTranslate(canvas, 0, value200_); + DrawPathAdd3Line(canvas); + OH_Drawing_CanvasTranslate(canvas, 0, value200_); + DrawPathAdd4Line(canvas); + + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PenDestroy(pen); +} + +void SampleGraphics::BuildFromSvgString(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush); + char* str = "M150 130L30 300L270 300Z"; + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + // 通过svg构建path + OH_Drawing_PathBuildFromSvgString(path, str); + OH_Drawing_CanvasDrawPath(canvas, path); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_PathDestroy(path); +} + +void SampleGraphics::DrawStar(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + OH_Drawing_PenSetJoin(pen, LINE_ROUND_JOIN); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMax_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush); + int len = value551_; + float aX = value630_; + float aY = value551_; + float angle = 18.0f; + float dX = aX - len * std::sin(angle); + float dY = aY + len * std::cos(angle); + float cX = aX + len * std::sin(angle); + float cY = dY; + float bX = aX + (len / 2.0); + float bY = aY + std::sqrt((cX - dX) * (cX - dX) + (len / 2.0) * (len / 2.0)); + float eX = aX - (len / 2.0); + float eY = bY; + // 创建路径 + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + // 到起始点 + OH_Drawing_PathMoveTo(path, aX, aY); + // 绘制直线 + OH_Drawing_PathLineTo(path, bX, bY); + OH_Drawing_PathLineTo(path, cX, cY); + OH_Drawing_PathLineTo(path, dX, dY); + OH_Drawing_PathLineTo(path, eX, eY); + // 直线闭合,形成五角星 + OH_Drawing_PathClose(path); + // 绘制闭合路径 + OH_Drawing_CanvasDrawPath(canvas, path); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_PenDestroy(pen); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_PathDestroy(path); } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pen.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pen.cpp index a95bd5bb0f56d7d69be41dbdcb80f571bf47a3eb..acfd52e305cfe69765962f4168f91d94b0b4a945 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pen.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pen.cpp @@ -1,243 +1,243 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" - -void SampleGraphics::DrawPenBasic(OH_Drawing_Canvas *canvas) -{ - // 创建画笔对象 - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - // 设置画笔描边颜色为红色 - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - // 设置画笔线宽为20 - OH_Drawing_PenSetWidth(pen, value20_); - // 设置抗锯齿 - OH_Drawing_PenSetAntiAlias(pen, true); - // 在画布中设置画笔 - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(value100_, value100_, value400_, value400_); - // 绘制矩形1 - OH_Drawing_CanvasDrawRect(canvas, rect1); - OH_Drawing_CanvasDetachPen(canvas); - // 复制画笔 - OH_Drawing_Pen* pen_copy = OH_Drawing_PenCopy(pen); - - // 画刷重置 - OH_Drawing_PenReset(pen); - // 设置画笔线宽为20 - OH_Drawing_PenSetWidth(pen, value20_); - // 设置透明度 - OH_Drawing_PenSetAlpha(pen, rgbaHalf_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value500_, value500_, value800_, value800_); - // 绘制矩形2 - OH_Drawing_CanvasDrawRect(canvas, rect2); - OH_Drawing_CanvasDetachPen(canvas); - - OH_Drawing_CanvasAttachPen(canvas, pen_copy); - OH_Drawing_Rect* rect3 = OH_Drawing_RectCreate(value900_, value900_, value1200_, value1200_); - // 绘制矩形3 - OH_Drawing_CanvasDrawRect(canvas, rect3); - OH_Drawing_CanvasDetachBrush(canvas); - - // 销毁各类对象 - OH_Drawing_PenDestroy(pen); - OH_Drawing_PenDestroy(pen_copy); - OH_Drawing_RectDestroy(rect1); - OH_Drawing_RectDestroy(rect2); - OH_Drawing_RectDestroy(rect3); -} - -void SampleGraphics::DrawPenLinearGradient(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Point *startPt = OH_Drawing_PointCreate(value120_, value120_); - OH_Drawing_Point *endPt = OH_Drawing_PointCreate(value1000_, value1000_); - uint32_t colors[] = { - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMax_, rgbaMin_), - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_), - OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMax_)}; - float pos2 = 0.5f; - float pos[] = {0.0f, pos2, 1.0f}; - // 创建线性渐变着色器效果 - OH_Drawing_ShaderEffect *shaderEffect = - OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, colors, pos, 3, OH_Drawing_TileMode::CLAMP); - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetWidth(pen, value150_); - // 基于画笔设置着色器效果 - OH_Drawing_PenSetShaderEffect(pen, shaderEffect); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value200_, value200_, value1000_, value1000_); - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - // 销毁各类对象 - OH_Drawing_PenDestroy(pen); - OH_Drawing_RectDestroy(rect); - OH_Drawing_ShaderEffectDestroy(shaderEffect); - OH_Drawing_PointDestroy(startPt); - OH_Drawing_PointDestroy(endPt); -} - -void SampleGraphics::DrawMiterLimit(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - uint32_t color = OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_); - OH_Drawing_PenSetColor(pen, color); - float width = value50_; - OH_Drawing_PenSetWidth(pen, width); - OH_Drawing_PenSetAntiAlias(pen, true); - // 设置画笔转角样式 - OH_Drawing_PenSetJoin(pen, OH_Drawing_PenLineJoinStyle::LINE_MITER_JOIN); - // 设置折角尖角的限制值 - OH_Drawing_PenSetMiterLimit(pen, value15_); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Path* path = OH_Drawing_PathCreate(); - float aX = value100_; - float aY = value100_; - float bX = value100_; - float bY = value800_; - float cX = value200_; - float cY = value100_; - OH_Drawing_PathMoveTo(path, aX, aY); - OH_Drawing_PathLineTo(path, bX, bY); - OH_Drawing_PathLineTo(path, cX, cY); - OH_Drawing_CanvasDrawPath(canvas, path); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PenDestroy(pen); - OH_Drawing_PathDestroy(path); -} - -void SampleGraphics::DrawStroke(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); - uint32_t color = OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_); - OH_Drawing_PenSetColor(pen, color); - float width = value50_; - OH_Drawing_PenSetWidth(pen, width); - OH_Drawing_PenSetAntiAlias(pen, true); - // 设置画笔线帽样式 - OH_Drawing_PenSetCap(pen, OH_Drawing_PenLineCapStyle::LINE_ROUND_CAP); - // 设置画笔转角样式 - OH_Drawing_PenSetJoin(pen, OH_Drawing_PenLineJoinStyle::LINE_BEVEL_JOIN); - OH_Drawing_CanvasAttachPen(canvas, pen); - // 创建路径 - OH_Drawing_Path* path = OH_Drawing_PathCreate(); - float aX = value100_; - float aY = value100_; - float bX = value100_; - float bY = value800_; - float cX = value800_; - float cY = value800_; - float dX = value800_; - float dY = value100_; - // 到起始点 - OH_Drawing_PathMoveTo(path, aX, aY); - // 绘制直线 - OH_Drawing_PathLineTo(path, bX, bY); - OH_Drawing_PathLineTo(path, cX, cY); - OH_Drawing_PathLineTo(path, dX, dY); - OH_Drawing_CanvasDrawPath(canvas, path); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PenDestroy(pen); - OH_Drawing_PathDestroy(path); -} - -void SampleGraphics::DrawPathEffect(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value10_); - // 表示10px的实线,5px的间隔,2px的实线,5px的间隔,以此循环 - float intervals[] = {value10_, 5, 2, 5}; - // 创建虚线路径效果 - int count = 4; - OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, count, 0.0); - OH_Drawing_PenSetPathEffect(pen, pathEffect); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value900_, value900_); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - OH_Drawing_PenDestroy(pen); - OH_Drawing_RectDestroy(rect); - OH_Drawing_PathEffectDestroy(pathEffect); -} - -void SampleGraphics::DrawImageFilter(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetAntiAlias(pen, true); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value20_); - // 创建图像滤波器实现模糊效果 - OH_Drawing_ImageFilter *imageFilter = - OH_Drawing_ImageFilterCreateBlur(value20_, value20_, OH_Drawing_TileMode::CLAMP, nullptr); - OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); - // 为滤波器对象设置图像滤波器 - OH_Drawing_FilterSetImageFilter(filter, imageFilter); - // 设置画笔的滤波器效果 - OH_Drawing_PenSetFilter(pen, filter); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value900_, value900_); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - // 销毁各类对象 - OH_Drawing_PenDestroy(pen); - OH_Drawing_ImageFilterDestroy(imageFilter); - OH_Drawing_RectDestroy(rect); - OH_Drawing_FilterDestroy(filter); -} - -void SampleGraphics::DrawMaskFilterPen(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); - OH_Drawing_PenSetAntiAlias(pen, true); - OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_PenSetWidth(pen, value20_); - // 创建蒙版滤波器 - OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType::NORMAL, value20_, true); - OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); - OH_Drawing_FilterSetMaskFilter(filter, maskFilter); - // 设置画笔的滤波器效果 - OH_Drawing_PenSetFilter(pen, filter); - OH_Drawing_CanvasAttachPen(canvas, pen); - OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDetachPen(canvas); - // 销毁各类对象 - OH_Drawing_PenDestroy(pen); - OH_Drawing_MaskFilterDestroy(maskFilter); - OH_Drawing_RectDestroy(rect); - OH_Drawing_FilterDestroy(filter); -} +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" + +void SampleGraphics::DrawPenBasic(OH_Drawing_Canvas *canvas) +{ + // 创建画笔对象 + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + // 设置画笔描边颜色为红色 + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + // 设置画笔线宽为20 + OH_Drawing_PenSetWidth(pen, value20_); + // 设置抗锯齿 + OH_Drawing_PenSetAntiAlias(pen, true); + // 在画布中设置画笔 + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(value100_, value100_, value400_, value400_); + // 绘制矩形1 + OH_Drawing_CanvasDrawRect(canvas, rect1); + OH_Drawing_CanvasDetachPen(canvas); + // 复制画笔 + OH_Drawing_Pen* pen_copy = OH_Drawing_PenCopy(pen); + + // 画刷重置 + OH_Drawing_PenReset(pen); + // 设置画笔线宽为20 + OH_Drawing_PenSetWidth(pen, value20_); + // 设置透明度 + OH_Drawing_PenSetAlpha(pen, rgbaHalf_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value500_, value500_, value800_, value800_); + // 绘制矩形2 + OH_Drawing_CanvasDrawRect(canvas, rect2); + OH_Drawing_CanvasDetachPen(canvas); + + OH_Drawing_CanvasAttachPen(canvas, pen_copy); + OH_Drawing_Rect* rect3 = OH_Drawing_RectCreate(value900_, value900_, value1200_, value1200_); + // 绘制矩形3 + OH_Drawing_CanvasDrawRect(canvas, rect3); + OH_Drawing_CanvasDetachBrush(canvas); + + // 销毁各类对象 + OH_Drawing_PenDestroy(pen); + OH_Drawing_PenDestroy(pen_copy); + OH_Drawing_RectDestroy(rect1); + OH_Drawing_RectDestroy(rect2); + OH_Drawing_RectDestroy(rect3); +} + +void SampleGraphics::DrawPenLinearGradient(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Point *startPt = OH_Drawing_PointCreate(value120_, value120_); + OH_Drawing_Point *endPt = OH_Drawing_PointCreate(value1000_, value1000_); + uint32_t colors[] = { + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMax_, rgbaMin_), + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_), + OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMin_, rgbaMin_, rgbaMax_)}; + float pos2 = 0.5f; + float pos[] = {0.0f, pos2, 1.0f}; + // 创建线性渐变着色器效果 + OH_Drawing_ShaderEffect *shaderEffect = + OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, colors, pos, 3, OH_Drawing_TileMode::CLAMP); + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetWidth(pen, value150_); + // 基于画笔设置着色器效果 + OH_Drawing_PenSetShaderEffect(pen, shaderEffect); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value200_, value200_, value1000_, value1000_); + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + // 销毁各类对象 + OH_Drawing_PenDestroy(pen); + OH_Drawing_RectDestroy(rect); + OH_Drawing_ShaderEffectDestroy(shaderEffect); + OH_Drawing_PointDestroy(startPt); + OH_Drawing_PointDestroy(endPt); +} + +void SampleGraphics::DrawMiterLimit(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + uint32_t color = OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_); + OH_Drawing_PenSetColor(pen, color); + float width = value50_; + OH_Drawing_PenSetWidth(pen, width); + OH_Drawing_PenSetAntiAlias(pen, true); + // 设置画笔转角样式 + OH_Drawing_PenSetJoin(pen, OH_Drawing_PenLineJoinStyle::LINE_MITER_JOIN); + // 设置折角尖角的限制值 + OH_Drawing_PenSetMiterLimit(pen, value15_); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + float aX = value100_; + float aY = value100_; + float bX = value100_; + float bY = value800_; + float cX = value200_; + float cY = value100_; + OH_Drawing_PathMoveTo(path, aX, aY); + OH_Drawing_PathLineTo(path, bX, bY); + OH_Drawing_PathLineTo(path, cX, cY); + OH_Drawing_CanvasDrawPath(canvas, path); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PenDestroy(pen); + OH_Drawing_PathDestroy(path); +} + +void SampleGraphics::DrawStroke(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen* pen = OH_Drawing_PenCreate(); + uint32_t color = OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_); + OH_Drawing_PenSetColor(pen, color); + float width = value50_; + OH_Drawing_PenSetWidth(pen, width); + OH_Drawing_PenSetAntiAlias(pen, true); + // 设置画笔线帽样式 + OH_Drawing_PenSetCap(pen, OH_Drawing_PenLineCapStyle::LINE_ROUND_CAP); + // 设置画笔转角样式 + OH_Drawing_PenSetJoin(pen, OH_Drawing_PenLineJoinStyle::LINE_BEVEL_JOIN); + OH_Drawing_CanvasAttachPen(canvas, pen); + // 创建路径 + OH_Drawing_Path* path = OH_Drawing_PathCreate(); + float aX = value100_; + float aY = value100_; + float bX = value100_; + float bY = value800_; + float cX = value800_; + float cY = value800_; + float dX = value800_; + float dY = value100_; + // 到起始点 + OH_Drawing_PathMoveTo(path, aX, aY); + // 绘制直线 + OH_Drawing_PathLineTo(path, bX, bY); + OH_Drawing_PathLineTo(path, cX, cY); + OH_Drawing_PathLineTo(path, dX, dY); + OH_Drawing_CanvasDrawPath(canvas, path); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PenDestroy(pen); + OH_Drawing_PathDestroy(path); +} + +void SampleGraphics::DrawPathEffect(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value10_); + // 表示10px的实线,5px的间隔,2px的实线,5px的间隔,以此循环 + float intervals[] = {value10_, 5, 2, 5}; + // 创建虚线路径效果 + int count = 4; + OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, count, 0.0); + OH_Drawing_PenSetPathEffect(pen, pathEffect); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value900_, value900_); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + OH_Drawing_PenDestroy(pen); + OH_Drawing_RectDestroy(rect); + OH_Drawing_PathEffectDestroy(pathEffect); +} + +void SampleGraphics::DrawImageFilter(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetAntiAlias(pen, true); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value20_); + // 创建图像滤波器实现模糊效果 + OH_Drawing_ImageFilter *imageFilter = + OH_Drawing_ImageFilterCreateBlur(value20_, value20_, OH_Drawing_TileMode::CLAMP, nullptr); + OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); + // 为滤波器对象设置图像滤波器 + OH_Drawing_FilterSetImageFilter(filter, imageFilter); + // 设置画笔的滤波器效果 + OH_Drawing_PenSetFilter(pen, filter); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value900_, value900_); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + // 销毁各类对象 + OH_Drawing_PenDestroy(pen); + OH_Drawing_ImageFilterDestroy(imageFilter); + OH_Drawing_RectDestroy(rect); + OH_Drawing_FilterDestroy(filter); +} + +void SampleGraphics::DrawMaskFilterPen(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Pen *pen = OH_Drawing_PenCreate(); + OH_Drawing_PenSetAntiAlias(pen, true); + OH_Drawing_PenSetColor(pen, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_PenSetWidth(pen, value20_); + // 创建蒙版滤波器 + OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType::NORMAL, value20_, true); + OH_Drawing_Filter *filter = OH_Drawing_FilterCreate(); + OH_Drawing_FilterSetMaskFilter(filter, maskFilter); + // 设置画笔的滤波器效果 + OH_Drawing_PenSetFilter(pen, filter); + OH_Drawing_CanvasAttachPen(canvas, pen); + OH_Drawing_Rect *rect = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDetachPen(canvas); + // 销毁各类对象 + OH_Drawing_PenDestroy(pen); + OH_Drawing_MaskFilterDestroy(maskFilter); + OH_Drawing_RectDestroy(rect); + OH_Drawing_FilterDestroy(filter); +} diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pixelmap.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pixelmap.cpp index 0097d52e57c56fd3132f4bd00a82c5d8c7d583fb..28626ca9bd9412623b8d1a41c67b8f8bff9ca051 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pixelmap.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_pixelmap.cpp @@ -1,163 +1,163 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" -#include "common/log_common.h" - -void SampleGraphics::DrawCustomPixelMap(OH_Drawing_Canvas *canvas) -{ - uint32_t width = 600; - uint32_t height = 400; - // 字节长度,RGBA_8888每个像素占4字节 - size_t bufferSize = width * height * 4; - uint8_t *pixels = new uint8_t[bufferSize]; - for (uint32_t i = 0; i < width * height; ++i) { - // 遍历并编辑每个像素,从而形成红绿蓝相间的条纹,间隔20 - uint32_t n = i / 20 % 3; - pixels[i * rgbaSize_] = rgbaMin_; - pixels[i * rgbaSize_ + indexOne_] = rgbaMin_; - pixels[i * rgbaSize_ + indexTwo_] = rgbaMin_; - pixels[i * rgbaSize_ + indexThree_] = rgbaMax_; - if (n == 0) { - pixels[i * rgbaSize_] = rgbaMax_; - } else if (n == 1) { - pixels[i * rgbaSize_ + indexOne_] = rgbaMax_; - } else { - pixels[i * rgbaSize_ + indexTwo_] = rgbaMax_; - } - } - // 设置位图格式(长、宽、颜色类型、透明度类型) - OH_Pixelmap_InitializationOptions *createOps = nullptr; - OH_PixelmapInitializationOptions_Create(&createOps); - OH_PixelmapInitializationOptions_SetWidth(createOps, width); - OH_PixelmapInitializationOptions_SetHeight(createOps, height); - OH_PixelmapInitializationOptions_SetPixelFormat(createOps, PIXEL_FORMAT_RGBA_8888); - OH_PixelmapInitializationOptions_SetAlphaType(createOps, PIXELMAP_ALPHA_TYPE_UNKNOWN); - // 创建OH_PixelmapNative对象 - OH_PixelmapNative *pixelMapNative = nullptr; - OH_PixelmapNative_CreatePixelmap(pixels, bufferSize, createOps, &pixelMapNative); - // 利用OH_PixelmapNative对象创建PixelMap对象 - OH_Drawing_PixelMap *pixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMapNative); - OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, width, height); - OH_Drawing_Rect *dst = OH_Drawing_RectCreate(value200_, value200_, value800_, value600_); - OH_Drawing_SamplingOptions* samplingOptions = OH_Drawing_SamplingOptionsCreate( - OH_Drawing_FilterMode::FILTER_MODE_LINEAR, OH_Drawing_MipmapMode::MIPMAP_MODE_LINEAR); - // 绘制PixelMap - OH_Drawing_CanvasDrawPixelMapRect(canvas, pixelMap, src, dst, samplingOptions); - OH_PixelmapNative_Release(pixelMapNative); - OH_Drawing_PixelMapDissolve(pixelMap); - OH_Drawing_RectDestroy(src); - OH_Drawing_RectDestroy(dst); - OH_Drawing_SamplingOptionsDestroy(samplingOptions); - delete[] pixels; -} - -void SampleGraphics::DrawPixelMapRect(OH_Drawing_Canvas *canvas) -{ - // 从NativePixelMap中获取PixelMap对象 - OH_Drawing_PixelMap *pixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(nativePixelMap_); - OH_Drawing_SamplingOptions *sampling = OH_Drawing_SamplingOptionsCreate(FILTER_MODE_LINEAR, MIPMAP_MODE_NONE); - float width = value400_; - float height = value400_; - OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, width, height); - OH_Drawing_Rect *dst = OH_Drawing_RectCreate(value100_, value100_, value700_, value700_); - // 绘制PixelMap - OH_Drawing_CanvasDrawPixelMapRect(canvas, pixelMap, src, dst, sampling); - // 解除NativePixelMap和PixelMap的关联 - OH_Drawing_PixelMapDissolve(pixelMap); - OH_Drawing_SamplingOptionsDestroy(sampling); - OH_Drawing_RectDestroy(src); - OH_Drawing_RectDestroy(dst); -} - -void SampleGraphics::DrawBitmap(OH_Drawing_Canvas *canvas) -{ - // 创建一个bitmap对象 - OH_Drawing_Bitmap* bitmap1 = OH_Drawing_BitmapCreate(); - OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; - uint64_t width = width_ / 2; - uint64_t height = height_ / 2; - // 构建bitmap对象 - OH_Drawing_BitmapBuild(bitmap1, width, height, &cFormat); - OH_Drawing_Canvas* newCanvas = OH_Drawing_CanvasCreate(); - OH_Drawing_CanvasBind(newCanvas, bitmap1); - OH_Drawing_CanvasClear(newCanvas, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - // 获取位图宽高 - SAMPLE_LOGI("Bitmap-->width=%{public}d,height=%{public}d", OH_Drawing_BitmapGetWidth(bitmap1), - OH_Drawing_BitmapGetHeight(bitmap1)); - // 获取像素 - void *pixels = OH_Drawing_BitmapGetPixels(bitmap1); - OH_Drawing_Image_Info imageInfo; - imageInfo.width = width; - imageInfo.height = height; - imageInfo.colorType = COLOR_FORMAT_RGBA_8888; - imageInfo.alphaType = ALPHA_FORMAT_OPAQUE; - // 通过像素创建一个bitmap对象 - OH_Drawing_Bitmap* bitmap2 = OH_Drawing_BitmapCreateFromPixels(&imageInfo, pixels, width * 4); - OH_Drawing_CanvasDrawBitmap(canvas, bitmap1, 0, 0); - OH_Drawing_CanvasDrawBitmap(canvas, bitmap2, width, height); - OH_Drawing_CanvasDestroy(newCanvas); - OH_Drawing_BitmapDestroy(bitmap1); - OH_Drawing_BitmapDestroy(bitmap2); -} - -void SampleGraphics::DrawImage(OH_Drawing_Canvas *canvas) -{ - // 创建一个bitmap对象 - OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); - OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; - uint64_t width = width_ / 2; - uint64_t height = height_ / 2; - OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); - OH_Drawing_Canvas* newCanvas = OH_Drawing_CanvasCreate(); - OH_Drawing_CanvasBind(newCanvas, bitmap); - OH_Drawing_CanvasClear(newCanvas, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - // 创建image对象 - OH_Drawing_Image* image = OH_Drawing_ImageCreate(); - // 从bitmap构建image - OH_Drawing_ImageBuildFromBitmap(image, bitmap); - // 获取Image宽高 - SAMPLE_LOGI("Image-->width=%{public}d,height=%{public}d", OH_Drawing_ImageGetWidth(image), - OH_Drawing_ImageGetHeight(image)); - OH_Drawing_Rect* rect = OH_Drawing_RectCreate(0, 0, width / 2, height / 2); - OH_Drawing_SamplingOptions* options = OH_Drawing_SamplingOptionsCreate( - OH_Drawing_FilterMode::FILTER_MODE_LINEAR, OH_Drawing_MipmapMode::MIPMAP_MODE_LINEAR); - OH_Drawing_CanvasDrawImageRect(canvas, image, rect, options); - // 销毁对象 - OH_Drawing_CanvasDestroy(newCanvas); - OH_Drawing_BitmapDestroy(bitmap); - OH_Drawing_ImageDestroy(image); - OH_Drawing_RectDestroy(rect); - OH_Drawing_SamplingOptionsDestroy(options); -} +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" +#include "common/log_common.h" + +void SampleGraphics::DrawCustomPixelMap(OH_Drawing_Canvas *canvas) +{ + uint32_t width = 600; + uint32_t height = 400; + // 字节长度,RGBA_8888每个像素占4字节 + size_t bufferSize = width * height * 4; + uint8_t *pixels = new uint8_t[bufferSize]; + for (uint32_t i = 0; i < width * height; ++i) { + // 遍历并编辑每个像素,从而形成红绿蓝相间的条纹,间隔20 + uint32_t n = i / 20 % 3; + pixels[i * rgbaSize_] = rgbaMin_; + pixels[i * rgbaSize_ + indexOne_] = rgbaMin_; + pixels[i * rgbaSize_ + indexTwo_] = rgbaMin_; + pixels[i * rgbaSize_ + indexThree_] = rgbaMax_; + if (n == 0) { + pixels[i * rgbaSize_] = rgbaMax_; + } else if (n == 1) { + pixels[i * rgbaSize_ + indexOne_] = rgbaMax_; + } else { + pixels[i * rgbaSize_ + indexTwo_] = rgbaMax_; + } + } + // 设置位图格式(长、宽、颜色类型、透明度类型) + OH_Pixelmap_InitializationOptions *createOps = nullptr; + OH_PixelmapInitializationOptions_Create(&createOps); + OH_PixelmapInitializationOptions_SetWidth(createOps, width); + OH_PixelmapInitializationOptions_SetHeight(createOps, height); + OH_PixelmapInitializationOptions_SetPixelFormat(createOps, PIXEL_FORMAT_RGBA_8888); + OH_PixelmapInitializationOptions_SetAlphaType(createOps, PIXELMAP_ALPHA_TYPE_UNKNOWN); + // 创建OH_PixelmapNative对象 + OH_PixelmapNative *pixelMapNative = nullptr; + OH_PixelmapNative_CreatePixelmap(pixels, bufferSize, createOps, &pixelMapNative); + // 利用OH_PixelmapNative对象创建PixelMap对象 + OH_Drawing_PixelMap *pixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMapNative); + OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, width, height); + OH_Drawing_Rect *dst = OH_Drawing_RectCreate(value200_, value200_, value800_, value600_); + OH_Drawing_SamplingOptions* samplingOptions = OH_Drawing_SamplingOptionsCreate( + OH_Drawing_FilterMode::FILTER_MODE_LINEAR, OH_Drawing_MipmapMode::MIPMAP_MODE_LINEAR); + // 绘制PixelMap + OH_Drawing_CanvasDrawPixelMapRect(canvas, pixelMap, src, dst, samplingOptions); + OH_PixelmapNative_Release(pixelMapNative); + OH_Drawing_PixelMapDissolve(pixelMap); + OH_Drawing_RectDestroy(src); + OH_Drawing_RectDestroy(dst); + OH_Drawing_SamplingOptionsDestroy(samplingOptions); + delete[] pixels; +} + +void SampleGraphics::DrawPixelMapRect(OH_Drawing_Canvas *canvas) +{ + // 从NativePixelMap中获取PixelMap对象 + OH_Drawing_PixelMap *pixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(nativePixelMap_); + OH_Drawing_SamplingOptions *sampling = OH_Drawing_SamplingOptionsCreate(FILTER_MODE_LINEAR, MIPMAP_MODE_NONE); + float width = value400_; + float height = value400_; + OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, width, height); + OH_Drawing_Rect *dst = OH_Drawing_RectCreate(value100_, value100_, value700_, value700_); + // 绘制PixelMap + OH_Drawing_CanvasDrawPixelMapRect(canvas, pixelMap, src, dst, sampling); + // 解除NativePixelMap和PixelMap的关联 + OH_Drawing_PixelMapDissolve(pixelMap); + OH_Drawing_SamplingOptionsDestroy(sampling); + OH_Drawing_RectDestroy(src); + OH_Drawing_RectDestroy(dst); +} + +void SampleGraphics::DrawBitmap(OH_Drawing_Canvas *canvas) +{ + // 创建一个bitmap对象 + OH_Drawing_Bitmap* bitmap1 = OH_Drawing_BitmapCreate(); + OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; + uint64_t width = width_ / 2; + uint64_t height = height_ / 2; + // 构建bitmap对象 + OH_Drawing_BitmapBuild(bitmap1, width, height, &cFormat); + OH_Drawing_Canvas* newCanvas = OH_Drawing_CanvasCreate(); + OH_Drawing_CanvasBind(newCanvas, bitmap1); + OH_Drawing_CanvasClear(newCanvas, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + // 获取位图宽高 + SAMPLE_LOGI("Bitmap-->width=%{public}d,height=%{public}d", OH_Drawing_BitmapGetWidth(bitmap1), + OH_Drawing_BitmapGetHeight(bitmap1)); + // 获取像素 + void *pixels = OH_Drawing_BitmapGetPixels(bitmap1); + OH_Drawing_Image_Info imageInfo; + imageInfo.width = width; + imageInfo.height = height; + imageInfo.colorType = COLOR_FORMAT_RGBA_8888; + imageInfo.alphaType = ALPHA_FORMAT_OPAQUE; + // 通过像素创建一个bitmap对象 + OH_Drawing_Bitmap* bitmap2 = OH_Drawing_BitmapCreateFromPixels(&imageInfo, pixels, width * 4); + OH_Drawing_CanvasDrawBitmap(canvas, bitmap1, 0, 0); + OH_Drawing_CanvasDrawBitmap(canvas, bitmap2, width, height); + OH_Drawing_CanvasDestroy(newCanvas); + OH_Drawing_BitmapDestroy(bitmap1); + OH_Drawing_BitmapDestroy(bitmap2); +} + +void SampleGraphics::DrawImage(OH_Drawing_Canvas *canvas) +{ + // 创建一个bitmap对象 + OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); + OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; + uint64_t width = width_ / 2; + uint64_t height = height_ / 2; + OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); + OH_Drawing_Canvas* newCanvas = OH_Drawing_CanvasCreate(); + OH_Drawing_CanvasBind(newCanvas, bitmap); + OH_Drawing_CanvasClear(newCanvas, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + // 创建image对象 + OH_Drawing_Image* image = OH_Drawing_ImageCreate(); + // 从bitmap构建image + OH_Drawing_ImageBuildFromBitmap(image, bitmap); + // 获取Image宽高 + SAMPLE_LOGI("Image-->width=%{public}d,height=%{public}d", OH_Drawing_ImageGetWidth(image), + OH_Drawing_ImageGetHeight(image)); + OH_Drawing_Rect* rect = OH_Drawing_RectCreate(0, 0, width / 2, height / 2); + OH_Drawing_SamplingOptions* options = OH_Drawing_SamplingOptionsCreate( + OH_Drawing_FilterMode::FILTER_MODE_LINEAR, OH_Drawing_MipmapMode::MIPMAP_MODE_LINEAR); + OH_Drawing_CanvasDrawImageRect(canvas, image, rect, options); + // 销毁对象 + OH_Drawing_CanvasDestroy(newCanvas); + OH_Drawing_BitmapDestroy(bitmap); + OH_Drawing_ImageDestroy(image); + OH_Drawing_RectDestroy(rect); + OH_Drawing_SamplingOptionsDestroy(options); +} diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_rect.cpp b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_rect.cpp index 2547fe6aeae22dbd68f48227f883ceef83a31457..2897cea5142619d330934b8ad8f58b38671a4802 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_rect.cpp +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/cpp/samples/sample_rect.cpp @@ -1,126 +1,126 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sample_graphics.h" -#include "common/log_common.h" - -void SampleGraphics::DrawRectBasic(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_BrushSetAntiAlias(brush, true); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 创建矩形对象 - OH_Drawing_Rect* rect = OH_Drawing_RectCreate(value200_, value200_, value500_, value500_); - OH_Drawing_Rect* rect_copy = OH_Drawing_RectCreate(0, 0, 0, 0); - OH_Drawing_RectCopy(rect, rect_copy); - // 设置矩形left,right,top,bottom - OH_Drawing_RectSetLeft(rect, value300_); - OH_Drawing_RectSetTop(rect, value300_); - OH_Drawing_RectSetRight(rect, value600_); - OH_Drawing_RectSetBottom(rect, value600_); - // 获取矩形left,right,top,bottom,width,height - SAMPLE_LOGI( - "left:%{public}f, right:%{public}f, top:%{public}f, bottom:%{public}f, width:%{public}f, height: %{public}f", - OH_Drawing_RectGetLeft(rect), OH_Drawing_RectGetRight(rect), OH_Drawing_RectGetTop(rect), - OH_Drawing_RectGetBottom(rect), OH_Drawing_RectGetWidth(rect), OH_Drawing_RectGetHeight(rect)); - SAMPLE_LOGI( - "left:%{public}f, right:%{public}f, top:%{public}f, bottom:%{public}f, width:%{public}f, height: %{public}f", - OH_Drawing_RectGetLeft(rect_copy), OH_Drawing_RectGetRight(rect_copy), OH_Drawing_RectGetTop(rect_copy), - OH_Drawing_RectGetBottom(rect_copy), OH_Drawing_RectGetWidth(rect_copy), OH_Drawing_RectGetHeight(rect_copy)); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect); - OH_Drawing_CanvasDrawRect(canvas, rect_copy); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RectDestroy(rect); - OH_Drawing_RectDestroy(rect_copy); -} - -void SampleGraphics::DrawRectIntersect(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_BrushSetAntiAlias(brush, true); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 创建矩形对象 - OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(value200_, value200_, value500_, value500_); - OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); - // 取交集 - OH_Drawing_RectIntersect(rect1, rect2); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect1); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RectDestroy(rect1); - OH_Drawing_RectDestroy(rect2); -} - -void SampleGraphics::DrawRectJoin(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_BrushSetAntiAlias(brush, true); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 创建矩形对象 - OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(value200_, value200_, value500_, value500_); - OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); - // 取并集 - OH_Drawing_RectJoin(rect1, rect2); - // 绘制矩形 - OH_Drawing_CanvasDrawRect(canvas, rect1); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RectDestroy(rect1); - OH_Drawing_RectDestroy(rect2); -} - -void SampleGraphics::DrawRoundRect(OH_Drawing_Canvas *canvas) -{ - OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); - OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); - OH_Drawing_CanvasAttachBrush(canvas, brush); - // 创建矩形 - OH_Drawing_Rect* rect = OH_Drawing_RectCreate(value100_, value100_, value900_, value600_); - // 创建圆角矩形 - OH_Drawing_RoundRect* roundRect = OH_Drawing_RoundRectCreate(rect, value30_, value30_); - OH_Drawing_RoundRectSetCorner(roundRect, OH_Drawing_CornerPos::CORNER_POS_TOP_LEFT, {value50_, value50_}); - OH_Drawing_Corner_Radii p = OH_Drawing_RoundRectGetCorner(roundRect, OH_Drawing_CornerPos::CORNER_POS_TOP_LEFT); - SAMPLE_LOGI("top-left-corner:x=%{public}f, y:%{public}f", p.x, p.y); - // 绘制圆角矩形 - OH_Drawing_CanvasDrawRoundRect(canvas, roundRect); - OH_Drawing_CanvasDetachBrush(canvas); - OH_Drawing_BrushDestroy(brush); - OH_Drawing_RectDestroy(rect); - OH_Drawing_RoundRectDestroy(roundRect); -} +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "sample_graphics.h" +#include "common/log_common.h" + +void SampleGraphics::DrawRectBasic(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_BrushSetAntiAlias(brush, true); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 创建矩形对象 + OH_Drawing_Rect* rect = OH_Drawing_RectCreate(value200_, value200_, value500_, value500_); + OH_Drawing_Rect* rect_copy = OH_Drawing_RectCreate(0, 0, 0, 0); + OH_Drawing_RectCopy(rect, rect_copy); + // 设置矩形left,right,top,bottom + OH_Drawing_RectSetLeft(rect, value300_); + OH_Drawing_RectSetTop(rect, value300_); + OH_Drawing_RectSetRight(rect, value600_); + OH_Drawing_RectSetBottom(rect, value600_); + // 获取矩形left,right,top,bottom,width,height + SAMPLE_LOGI( + "left:%{public}f, right:%{public}f, top:%{public}f, bottom:%{public}f, width:%{public}f, height: %{public}f", + OH_Drawing_RectGetLeft(rect), OH_Drawing_RectGetRight(rect), OH_Drawing_RectGetTop(rect), + OH_Drawing_RectGetBottom(rect), OH_Drawing_RectGetWidth(rect), OH_Drawing_RectGetHeight(rect)); + SAMPLE_LOGI( + "left:%{public}f, right:%{public}f, top:%{public}f, bottom:%{public}f, width:%{public}f, height: %{public}f", + OH_Drawing_RectGetLeft(rect_copy), OH_Drawing_RectGetRight(rect_copy), OH_Drawing_RectGetTop(rect_copy), + OH_Drawing_RectGetBottom(rect_copy), OH_Drawing_RectGetWidth(rect_copy), OH_Drawing_RectGetHeight(rect_copy)); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect); + OH_Drawing_CanvasDrawRect(canvas, rect_copy); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RectDestroy(rect); + OH_Drawing_RectDestroy(rect_copy); +} + +void SampleGraphics::DrawRectIntersect(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_BrushSetAntiAlias(brush, true); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 创建矩形对象 + OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(value200_, value200_, value500_, value500_); + OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); + // 取交集 + OH_Drawing_RectIntersect(rect1, rect2); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect1); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RectDestroy(rect1); + OH_Drawing_RectDestroy(rect2); +} + +void SampleGraphics::DrawRectJoin(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush* brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_BrushSetAntiAlias(brush, true); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 创建矩形对象 + OH_Drawing_Rect* rect1 = OH_Drawing_RectCreate(value200_, value200_, value500_, value500_); + OH_Drawing_Rect* rect2 = OH_Drawing_RectCreate(value300_, value300_, value600_, value600_); + // 取并集 + OH_Drawing_RectJoin(rect1, rect2); + // 绘制矩形 + OH_Drawing_CanvasDrawRect(canvas, rect1); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RectDestroy(rect1); + OH_Drawing_RectDestroy(rect2); +} + +void SampleGraphics::DrawRoundRect(OH_Drawing_Canvas *canvas) +{ + OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); + OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(rgbaMax_, rgbaMax_, rgbaMin_, rgbaMin_)); + OH_Drawing_CanvasAttachBrush(canvas, brush); + // 创建矩形 + OH_Drawing_Rect* rect = OH_Drawing_RectCreate(value100_, value100_, value900_, value600_); + // 创建圆角矩形 + OH_Drawing_RoundRect* roundRect = OH_Drawing_RoundRectCreate(rect, value30_, value30_); + OH_Drawing_RoundRectSetCorner(roundRect, OH_Drawing_CornerPos::CORNER_POS_TOP_LEFT, {value50_, value50_}); + OH_Drawing_Corner_Radii p = OH_Drawing_RoundRectGetCorner(roundRect, OH_Drawing_CornerPos::CORNER_POS_TOP_LEFT); + SAMPLE_LOGI("top-left-corner:x=%{public}f, y:%{public}f", p.x, p.y); + // 绘制圆角矩形 + OH_Drawing_CanvasDrawRoundRect(canvas, roundRect); + OH_Drawing_CanvasDetachBrush(canvas); + OH_Drawing_BrushDestroy(brush); + OH_Drawing_RectDestroy(rect); + OH_Drawing_RoundRectDestroy(roundRect); +} diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BitmapDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BitmapDrawing.ets index 8ba47c25209536ada692e168ec2a570fd28deee6..a8bc93702fa264988363ab0337133aef520d0f65 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BitmapDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BitmapDrawing.ets @@ -1,35 +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. - */ - -import XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct BitmapDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - this.xComponentContext.draw('CanvasGet', 'DrawBitmap'); - }) - .backgroundColor(Color.White) - .width('100%') - .height('100%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct BitmapDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + this.xComponentContext.draw('CanvasGet', 'DrawBitmap'); + }) + .backgroundColor(Color.White) + .width('100%') + .height('100%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BrushDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BrushDrawing.ets index e0810fcd3c440ce9d11638a706ebc88f39fa30aa..bd90b0ab1ab86c78711e386bb36ecc0db1a87ccb 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BrushDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/BrushDrawing.ets @@ -1,78 +1,78 @@ -/* - * 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 XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct BrushDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingBrushBasic')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'BrushBasic'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingBlendMode')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'MixedMode'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingColorFilter')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'ColorFilter'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingShaderEffect')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'LinearGradient'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingMaskFilter')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'MaskFilterBrush'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct BrushDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingBrushBasic')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'BrushBasic'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingBlendMode')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'MixedMode'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingColorFilter')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'ColorFilter'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingShaderEffect')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'LinearGradient'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingMaskFilter')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'MaskFilterBrush'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/CanvasDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/CanvasDrawing.ets index 250044a192cfb796defca11a0f77a6f170cdb87a..b682fcfaa2ca7c531c4be47242025925c5707062 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/CanvasDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/CanvasDrawing.ets @@ -1,92 +1,92 @@ -/* - * 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 XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct CanvasDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingCreateCanvas')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGetByCPU', 'CanvasCreate'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingClip')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'ClipOperation'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingSave')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'SaveOperation'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingSaveLayer')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'SaveLayerOperation'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingConcatMatrix')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'ConcatMatrix'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingDrawPixelMap')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'CustomPixelMap'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingDrawRegion')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'DrawRegion'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct CanvasDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingCreateCanvas')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGetByCPU', 'CanvasCreate'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingClip')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'ClipOperation'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingSave')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'SaveOperation'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingSaveLayer')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'SaveLayerOperation'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingConcatMatrix')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'ConcatMatrix'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingDrawPixelMap')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'CustomPixelMap'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingDrawRegion')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'DrawRegion'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/ImageDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/ImageDrawing.ets index fb07ab8bb20e316f272c043e5f147afeefb466a0..728c80afbe7867d9f78dcbe529548eb6bbd1ae53 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/ImageDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/ImageDrawing.ets @@ -1,35 +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. - */ - -import XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct ImageDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - this.xComponentContext.draw('CanvasGet', 'DrawImage'); - }) - .backgroundColor(Color.White) - .width('100%') - .height('100%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct ImageDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + this.xComponentContext.draw('CanvasGet', 'DrawImage'); + }) + .backgroundColor(Color.White) + .width('100%') + .height('100%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/MatrixDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/MatrixDrawing.ets index 94db4b2170c911e4b20b5e42b4d43da476207750..86c50a4a88aeeda5a80febff24f8aa6c016c69af 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/MatrixDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/MatrixDrawing.ets @@ -1,120 +1,120 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct MatrixDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingMatrixBasic')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'MatrixBasic'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingTranslation')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'TranslationOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingPreTranslation')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PreTranslationOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingPostTranslation')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PostTranslationOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingRotation')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'RotationOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingPreRotation')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PreRotationOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingPostRotation')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PostRotationOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingScale')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'ScaleOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingPreScale')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PreScaleOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingPostScale')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PostScaleOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - Button($r('app.string.DrawingConcat')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'ConcatOperation'); - } - }) - .margin({ top: 5, bottom: 5, left: 5, right: 5 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct MatrixDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingMatrixBasic')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'MatrixBasic'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingTranslation')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'TranslationOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingPreTranslation')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PreTranslationOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingPostTranslation')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PostTranslationOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingRotation')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'RotationOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingPreRotation')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PreRotationOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingPostRotation')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PostRotationOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingScale')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'ScaleOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingPreScale')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PreScaleOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingPostScale')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PostScaleOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + Button($r('app.string.DrawingConcat')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'ConcatOperation'); + } + }) + .margin({ top: 5, bottom: 5, left: 5, right: 5 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PathDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PathDrawing.ets index f961f3244f783bb7cb757a0fd06882d02d104c76..9d9b23717910a2bcbf78cb792e5c05c2c549a61b 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PathDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PathDrawing.ets @@ -1,78 +1,78 @@ -/* - * 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 XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct PathDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingPathBasic')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PathBasic'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingPathAdd')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PathAdd'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingPathTo')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PathTo'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingPathStar')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PathStar'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingBuildFromSvgString')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'BuildFromSvgString'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct PathDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingPathBasic')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PathBasic'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingPathAdd')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PathAdd'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingPathTo')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PathTo'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingPathStar')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PathStar'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingBuildFromSvgString')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'BuildFromSvgString'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PenDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PenDrawing.ets index 0583bae219ee0176c695b9bf81024334af1fd8a9..22e53fd6e385d8aaacddb98192dec0ae4f9f8f5b 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PenDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PenDrawing.ets @@ -1,92 +1,92 @@ -/* - * 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 XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct PenDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingPenBasic')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PenBasic'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingCapJoin')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'Stroke'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingMiterLimit')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'MiterLimit'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingImageFilter')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'ImageFilter'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingPathEffect')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PathEffect'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingShaderEffect')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'PenLinearGradient'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingMaskFilter')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'MaskFilterPen'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct PenDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingPenBasic')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PenBasic'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingCapJoin')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'Stroke'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingMiterLimit')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'MiterLimit'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingImageFilter')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'ImageFilter'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingPathEffect')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PathEffect'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingShaderEffect')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'PenLinearGradient'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingMaskFilter')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'MaskFilterPen'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PixelMapDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PixelMapDrawing.ets index 9dd9691b5b1489d654304ce6a5b694c9579f9ffc..dfd6fdaf2edc6a64532957d6e15cf5f7df654b22 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PixelMapDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/PixelMapDrawing.ets @@ -1,77 +1,77 @@ -/* - * 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 XComponentContext from '../../interface/XComponentContext'; -import { image } from '@kit.ImageKit'; -import { resourceManager } from '@kit.LocalizationKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -@Entry -@Component -struct PixelMapDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - private pMap: image.PixelMap | undefined = undefined; - aboutToAppear() { - const context: Context = getContext(this); - const resourceMgr: resourceManager.ResourceManager = context.resourceManager; - resourceMgr.getRawFileContent('startIcon.png').then((fileData: Uint8Array) => { - console.log('Succeeded in getting RawFileContent'); - const buffer = fileData.buffer.slice(0); - const imageSource: image.ImageSource = image.createImageSource(buffer); - imageSource.createPixelMap().then((pMap: image.PixelMap) => { - this.pMap = pMap; - }).catch((err: BusinessError) => { - console.error('Failed to creating PixelMap'); - }); - }).catch((err: BusinessError) => { - console.error('Failed to get RawFileContent'); - }); - } - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingLocalPixelMap')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.drawImage('CanvasGet', 'LocalPixelMap', this.pMap); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingCustomPixelMap')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'CustomPixelMap'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; +import { image } from '@kit.ImageKit'; +import { resourceManager } from '@kit.LocalizationKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct PixelMapDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + private pMap: image.PixelMap | undefined = undefined; + aboutToAppear() { + const context: Context = getContext(this); + const resourceMgr: resourceManager.ResourceManager = context.resourceManager; + resourceMgr.getRawFileContent('startIcon.png').then((fileData: Uint8Array) => { + console.log('Succeeded in getting RawFileContent'); + const buffer = fileData.buffer.slice(0); + const imageSource: image.ImageSource = image.createImageSource(buffer); + imageSource.createPixelMap().then((pMap: image.PixelMap) => { + this.pMap = pMap; + }).catch((err: BusinessError) => { + console.error('Failed to creating PixelMap'); + }); + }).catch((err: BusinessError) => { + console.error('Failed to get RawFileContent'); + }); + } + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingLocalPixelMap')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.drawImage('CanvasGet', 'LocalPixelMap', this.pMap); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingCustomPixelMap')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'CustomPixelMap'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/RectDrawing.ets b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/RectDrawing.ets index bdebddb8c78872d517282847b41ef49bdbf3572f..74b58f3e2cea7c6ac0accbf87c996cdcb4044f35 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/RectDrawing.ets +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/ets/drawing/pages/RectDrawing.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import XComponentContext from '../../interface/XComponentContext'; - -@Entry -@Component -struct RectDrawing { - private xComponentContext: XComponentContext | undefined = undefined; - - build() { - Column() { - XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) - .onLoad((xComponentContext) => { - this.xComponentContext = xComponentContext as XComponentContext; - }) - .backgroundColor(Color.White) - .width('100%') - .height('70%') - Flex({ - direction: FlexDirection.Row, - wrap: FlexWrap.Wrap, - justifyContent: FlexAlign.Start, - alignItems: ItemAlign.Start - }) { - Button($r('app.string.DrawingRectBasic')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'RectBasic'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingIntersect')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'RectIntersect'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingJoin')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'RectJoin'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - Button($r('app.string.DrawingRoundRect')) - .onClick((): void => { - if (this.xComponentContext) { - this.xComponentContext.draw('CanvasGet', 'RoundRect'); - } - }) - .margin({ top: 10, bottom: 10, left: 10, right: 10 }) - } - .width('100%') - .height('30%') - } - } +/* + * 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 XComponentContext from '../../interface/XComponentContext'; + +@Entry +@Component +struct RectDrawing { + private xComponentContext: XComponentContext | undefined = undefined; + + build() { + Column() { + XComponent({ id: 'basicEffectXComponent', type: XComponentType.SURFACE, libraryname: 'entry' }) + .onLoad((xComponentContext) => { + this.xComponentContext = xComponentContext as XComponentContext; + }) + .backgroundColor(Color.White) + .width('100%') + .height('70%') + Flex({ + direction: FlexDirection.Row, + wrap: FlexWrap.Wrap, + justifyContent: FlexAlign.Start, + alignItems: ItemAlign.Start + }) { + Button($r('app.string.DrawingRectBasic')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'RectBasic'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingIntersect')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'RectIntersect'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingJoin')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'RectJoin'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + Button($r('app.string.DrawingRoundRect')) + .onClick((): void => { + if (this.xComponentContext) { + this.xComponentContext.draw('CanvasGet', 'RoundRect'); + } + }) + .margin({ top: 10, bottom: 10, left: 10, right: 10 }) + } + .width('100%') + .height('30%') + } + } } \ No newline at end of file diff --git a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/module.json5 b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/module.json5 index 81e36fa1cf0312bd206d3ceab0af57cd38f98e08..2cd3a6c601073f86f4789ab9db7529f84f705f3f 100644 --- a/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/module.json5 +++ b/code/DocsSample/Drawing/NDKAPIDrawing/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -{ - "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" - } - ] - } - ] - } +{ + "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/Notification/Notification/AppScope/app.json5 b/code/DocsSample/Notification/Notification/AppScope/app.json5 index 03e6d5d69415b3ed95b5243c2661866bc6325ba9..42c9a5408a5284dce20d0087708624859565a04d 100644 --- a/code/DocsSample/Notification/Notification/AppScope/app.json5 +++ b/code/DocsSample/Notification/Notification/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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.notification", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.notification", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Notification/Notification/AppScope/resources/base/element/string.json b/code/DocsSample/Notification/Notification/AppScope/resources/base/element/string.json index 6b5ba9e58589d610cdeadbd875a5d7282b050f51..2603caef266c9fb3dac66c7843ece4785f70311f 100644 --- a/code/DocsSample/Notification/Notification/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Notification/Notification/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "Notification" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "Notification" + } + ] +} diff --git a/code/DocsSample/Notification/Notification/README_zh.md b/code/DocsSample/Notification/Notification/README_zh.md index 83021009a928df77a9da86cb88908a8dc957c0a6..06d287717cb6a2368918c4a7d4085f8d8099b173 100644 --- a/code/DocsSample/Notification/Notification/README_zh.md +++ b/code/DocsSample/Notification/Notification/README_zh.md @@ -1,80 +1,80 @@ -# 通知 - -### 介绍 - -本示例使用 [@ohos.notificationManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-notification-kit/js-apis-notificationManager.md) 等接口, 展示了如何初始化不同类型通知的通知内容以及通知的发布、取消及桌面角标的设置,通知类型包括基本类型、长文本类型、多行文本类型、图片类型、带进度条的通知、点击可跳转到应用以及公共事件通知。 - -### 效果预览 - -| 主界面 | 图片通知 | 多行文本通知 | 进度条通知 | -|----------------------------------------------------------|:----------------------------------------------------:|:---------------------------------------------------------:|:---------------------------------------------------------:| -| | | | | - -使用说明 - -1.启动应用后,弹出是否允许发送通知的弹窗,点击允许后开始操作; - -2.点击主界面中设置角标列表项设置角标,回到仿桌面,可以看到角标数量,对应消息数量(使用前需安装并启动[仿桌面应用](../../../SystemFeature/ApplicationModels/Launcher)); - -3.点主击界面中对应的列表项发布不同类型的通知,下拉状态栏,在通知栏可以看到发布的通知; - -### 工程目录 - -``` -entry/src/main/ets/ -|---entryability -| |---EntryAbility.ets -|---pages -| |---Index.ets // 首页 -| |---Second.ets // 通知启动Ability时,被拉起的Ability页面 -|---publish -| |---PublishOperation.ets // 使能通知开关、设置通知角标、发布通知 -|---secondability -| |---SecondAbility.ets // 通知启动Ability时,被拉起的Ability -|---subscribe -| |---SubscribeOperation.ets // 订阅通知 -``` - -### 具体实现 - -- 允许发送通知、发送通知的功能接口封装在PublishOperation,源码参考:[PublishOperation.ets](entry/src/main/ets/publish/PublishOperation.ets) - * 允许发送通知: - 通过publishOperation.enableNotification()调用notificationManager.requestEnableNotification()接口向用户请求发送通知; - - * 设置角标: - - 通过publishOperation.setBadgeNumberForBasic()调用notificationManager.setBadgeNumber()接口设置角标; - - * 发送通知:通过notificationManager.publish发布通知的接口,通知类型包括基本类型、长文本类型、多行文本类型、图片类型、带进度条的通知、点击可跳转到应用以及公共事件通知; -- 订阅通知功能接口封装在SubscribeOperation,源码参考:[PublishOperation.ets](entry/src/main/ets/subscribe/SubscribeOperation.ets) - -### 相关权限 - -[ohos.permission.NOTIFICATION_CONTROLLER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionnotification_controller) - -### 依赖 - -应用的角标依赖于仿桌面应用进行显示:[仿桌面应用](../../../SystemFeature/ApplicationModels/Launcher)。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.3.1; - -3.本示例涉及使用系统接口:notificationManager.requestEnableNotification ,需要手动替换Full SDK才能编译通过; - -4.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; - -5.本示例涉及[ohos.permission.NOTIFICATION_CONTROLLER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionnotification_controller)权限为system_core级别,需要配置高权限签名; - -### 下载 - -```shell -git init -git config core.sparsecheckout true -echo code/DocsSample/Notification/Notification/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# 通知 + +### 介绍 + +本示例使用 [@ohos.notificationManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-notification-kit/js-apis-notificationManager.md) 等接口, 展示了如何初始化不同类型通知的通知内容以及通知的发布、取消及桌面角标的设置,通知类型包括基本类型、长文本类型、多行文本类型、图片类型、带进度条的通知、点击可跳转到应用以及公共事件通知。 + +### 效果预览 + +| 主界面 | 图片通知 | 多行文本通知 | 进度条通知 | +|----------------------------------------------------------|:----------------------------------------------------:|:---------------------------------------------------------:|:---------------------------------------------------------:| +| | | | | + +使用说明 + +1.启动应用后,弹出是否允许发送通知的弹窗,点击允许后开始操作; + +2.点击主界面中设置角标列表项设置角标,回到仿桌面,可以看到角标数量,对应消息数量(使用前需安装并启动[仿桌面应用](../../../SystemFeature/ApplicationModels/Launcher)); + +3.点主击界面中对应的列表项发布不同类型的通知,下拉状态栏,在通知栏可以看到发布的通知; + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets +|---pages +| |---Index.ets // 首页 +| |---Second.ets // 通知启动Ability时,被拉起的Ability页面 +|---publish +| |---PublishOperation.ets // 使能通知开关、设置通知角标、发布通知 +|---secondability +| |---SecondAbility.ets // 通知启动Ability时,被拉起的Ability +|---subscribe +| |---SubscribeOperation.ets // 订阅通知 +``` + +### 具体实现 + +- 允许发送通知、发送通知的功能接口封装在PublishOperation,源码参考:[PublishOperation.ets](entry/src/main/ets/publish/PublishOperation.ets) + * 允许发送通知: + 通过publishOperation.enableNotification()调用notificationManager.requestEnableNotification()接口向用户请求发送通知; + + * 设置角标: + + 通过publishOperation.setBadgeNumberForBasic()调用notificationManager.setBadgeNumber()接口设置角标; + + * 发送通知:通过notificationManager.publish发布通知的接口,通知类型包括基本类型、长文本类型、多行文本类型、图片类型、带进度条的通知、点击可跳转到应用以及公共事件通知; +- 订阅通知功能接口封装在SubscribeOperation,源码参考:[PublishOperation.ets](entry/src/main/ets/subscribe/SubscribeOperation.ets) + +### 相关权限 + +[ohos.permission.NOTIFICATION_CONTROLLER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionnotification_controller) + +### 依赖 + +应用的角标依赖于仿桌面应用进行显示:[仿桌面应用](../../../SystemFeature/ApplicationModels/Launcher)。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.3.1; + +3.本示例涉及使用系统接口:notificationManager.requestEnableNotification ,需要手动替换Full SDK才能编译通过; + +4.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; + +5.本示例涉及[ohos.permission.NOTIFICATION_CONTROLLER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionnotification_controller)权限为system_core级别,需要配置高权限签名; + +### 下载 + +```shell +git init +git config core.sparsecheckout true +echo code/DocsSample/Notification/Notification/ > .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/Notification/Notification/build-profile.json5 b/code/DocsSample/Notification/Notification/build-profile.json5 index e89f4e59bc2b66a8e511f9e9ac9c1ad763d349f3..50337ead0940e303a094aed3453c8bd7f1e6e289 100644 --- a/code/DocsSample/Notification/Notification/build-profile.json5 +++ b/code/DocsSample/Notification/Notification/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ], + "signingConfigs": [] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/build-profile.json5 b/code/DocsSample/Notification/Notification/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/DocsSample/Notification/Notification/entry/build-profile.json5 +++ b/code/DocsSample/Notification/Notification/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/oh-package.json5 b/code/DocsSample/Notification/Notification/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/DocsSample/Notification/Notification/entry/oh-package.json5 +++ b/code/DocsSample/Notification/Notification/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/Notification/Notification/entry/src/main/ets/entryAbility/EntryAbility.ets b/code/DocsSample/Notification/Notification/entry/src/main/ets/entryAbility/EntryAbility.ets index be806ebc5c38235edc30cd9f646f737bcc87ca46..b23b3e294202f50d89f2956097646a18e3c6ea4e 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/ets/entryAbility/EntryAbility.ets +++ b/code/DocsSample/Notification/Notification/entry/src/main/ets/entryAbility/EntryAbility.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import Base from '@ohos.base'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import hilog from '@ohos.hilog'; -import { subscribeOperations } from '../subscribe/SubscribeOperation'; - -const TAG: string = '[EntryAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onCreate'); - } - - onDestroy() { - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/Index', (err: Base.BusinessError) => { - if (err.code) { - hilog.info(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onForeground'); - subscribeOperations.createSubscriber(); - } - - onBackground() { - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import Base from '@ohos.base'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import hilog from '@ohos.hilog'; +import { subscribeOperations } from '../subscribe/SubscribeOperation'; + +const TAG: string = '[EntryAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onCreate'); + } + + onDestroy() { + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Index', (err: Base.BusinessError) => { + if (err.code) { + hilog.info(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onForeground'); + subscribeOperations.createSubscriber(); + } + + onBackground() { + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onBackground'); + } +} diff --git a/code/DocsSample/Notification/Notification/entry/src/main/ets/pages/Second.ets b/code/DocsSample/Notification/Notification/entry/src/main/ets/pages/Second.ets index 6d2e377eef58373846f76f6cd07693b1a52a1134..389f40e738ad411f0a1858b65da0d0d4a21d12d9 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/ets/pages/Second.ets +++ b/code/DocsSample/Notification/Notification/entry/src/main/ets/pages/Second.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct Second { - @State message: string = 'Second Page' - - build() { - Column() { - Row() { - Text($r('app.string.SecondPage')) { - } - .fontSize(24) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 24, right: 24 }) - .width('100%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { - Column() { - Image($r('app.media.pic_empty')).width('33%') - Text($r('app.string.empty')) - .fontSize(14) - .fontColor($r('app.color.text_color')) - } - }.width('100%') - .height('90%') - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - .padding({ top: 36, bottom: 106 }) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct Second { + @State message: string = 'Second Page' + + build() { + Column() { + Row() { + Text($r('app.string.SecondPage')) { + } + .fontSize(24) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 24, right: 24 }) + .width('100%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { + Column() { + Image($r('app.media.pic_empty')).width('33%') + Text($r('app.string.empty')) + .fontSize(14) + .fontColor($r('app.color.text_color')) + } + }.width('100%') + .height('90%') + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + .padding({ top: 36, bottom: 106 }) + } } \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/src/main/ets/publish/PublishOperation.ets b/code/DocsSample/Notification/Notification/entry/src/main/ets/publish/PublishOperation.ets index 0566b784501108b1a7ba886c85bc0301e42765ee..00a93a054ad4e0688b5e13b8da05523d03e61cfa 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/ets/publish/PublishOperation.ets +++ b/code/DocsSample/Notification/Notification/entry/src/main/ets/publish/PublishOperation.ets @@ -1,294 +1,294 @@ -/* - * Copyright (c) 2023 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 Base from '@ohos.base'; -import image from '@ohos.multimedia.image'; -import notificationManager from '@ohos.notificationManager'; -import wantAgent from '@ohos.app.ability.wantAgent'; -import { WantAgent } from '@ohos.app.ability.wantAgent' -import hilog from '@ohos.hilog'; -import resourceManager from '@ohos.resourceManager'; - -const TAG: string = '[PublishOperation]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class PublishOperation { - private context: Context; - - constructor(context: Context) { - this.context = context; - } - - enableNotification = async () => { - notificationManager.isNotificationEnabled().then((data: boolean) => { - hilog.info(DOMAIN_NUMBER, TAG, 'isNotificationEnabled success, data: ' + JSON.stringify(data)); - if(!data){ - notificationManager.requestEnableNotification().then(() => { - hilog.info(DOMAIN_NUMBER, TAG, `[ANS] requestEnableNotification success`); - }).catch((err:Base.BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, - `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); - }); - } - }).catch((err: Base.BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, `isNotificationEnabled fail: ${JSON.stringify(err)}`); - }); - } - publishBasic = async () => { - let notificationRequest: notificationManager.NotificationRequest = { - id: 1, - content: { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 普通文本类型通知 - normal: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText', - } - } - }; - - // 发布通知 - notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); - }); - } - publishLong = async () => { - let notificationRequest: notificationManager.NotificationRequest = { - id: 2, - content: { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // 长文本类型通知 - longText: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText', - longText: 'test_longText', - briefText: 'test_briefText', - expandedTitle: 'test_expandedTitle', - } - } - }; - - // 发布通知 - notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); - }); - } - publishMultiLine = async () => { - let notificationRequest: notificationManager.NotificationRequest = { - id: 3, - content: { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // 多行文本类型通知 - multiLine: { - title: 'test_title', - text: 'test_text', - briefText: 'test_briefText', - longTitle: 'test_longTitle', - lines: ['line_01', 'line_02', 'line_03', 'line_04'], - } - } - }; - - // 发布通知 - notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); - }); - } - - publishPicture = async () => { - const resourceMgr: resourceManager.ResourceManager = this.context.resourceManager; - let imageArray: Uint8Array = await resourceMgr.getMediaContent($r('app.media.pic').id); - const arraybuffer: ArrayBuffer = imageArray.buffer as ArrayBuffer; - let imageResource = image.createImageSource(arraybuffer); - let imagePixelMap = await imageResource.createPixelMap(); - - if (imagePixelMap !== undefined) { - let notificationRequest: notificationManager.NotificationRequest = { - id: 4, - content: { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE, - picture: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText', - briefText: 'test_briefText', - expandedTitle: 'test_expandedTitle', - picture: imagePixelMap - } - } - }; - - // 发布通知 - notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); - }); - } - } - publishProgressBar = async () => { - notificationManager.isSupportTemplate('downloadTemplate').then((data: boolean) => { - hilog.info(DOMAIN_NUMBER, TAG, `[ANS] isSupportTemplate success`); - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in supporting download template notification.'); - if (data == true) { // data的值为true表示支持支持downloadTemplate模板类通知,false表示不支持 - let notificationRequest: notificationManager.NotificationRequest = { - id: 5, - content: { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: 'test_title', - text: 'test_text', - additionalText: 'test_additionalText' - } - }, - // 构造进度条模板,name字段当前需要固定配置为downloadTemplate - template: { - name: 'downloadTemplate', - data: { - title: 'File Title', fileName: 'music.mp4', progressValue: 45 - } - } - } - // 发布通知 - notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); - }); - } - }).catch((err: Base.BusinessError) => { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to support download template notification. Code is ${err.code}, message is ${err.message}`); - }); - } - publishWantAgentStartAbility = async () => { - let wantAgentObj: WantAgent; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。 - // 通过WantAgentInfo的operationType设置动作类型 - let wantAgentInfo: wantAgent.WantAgentInfo = { - wants: [ - { - deviceId: '', - bundleName: 'com.samples.notification', - abilityName: 'SecondAbility', - action: '', - entities: [], - uri: '', - parameters: {} - } - ], - operationType: wantAgent.OperationType.START_ABILITY, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG] - }; - // 创建WantAgent - wantAgent.getWantAgent(wantAgentInfo, (err: Base.BusinessError, data: WantAgent) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in getting want agent.'); - wantAgentObj = data; - this.publishWantAgent(wantAgentObj); - }); - } - publishWantAgentCommonEvent = async () => { - let wantAgentObj: WantAgent; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。 - // 通过WantAgentInfo的operationType设置动作类型 - let wantAgentInfo: wantAgent.WantAgentInfo = { - wants: [ - { - action: 'event_name', // 设置事件名 - parameters: {}, - } - ], - operationType: wantAgent.OperationType.SEND_COMMON_EVENT, - requestCode: 0, - wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG], - }; - - // 创建WantAgent - wantAgent.getWantAgent(wantAgentInfo, (err: Base.BusinessError, data: WantAgent) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in getting want agent.'); - wantAgentObj = data; - this.publishWantAgent(wantAgentObj); - }); - } - publishWantAgent = async (wantAgentObj: WantAgent) => { - // 构造NotificationRequest对象 - let notificationRequest: notificationManager.NotificationRequest = { - content: { - notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, - normal: { - title: 'Test_Title', - text: 'Test_Text', - additionalText: 'Test_AdditionalText', - }, - }, - id: 6, - label: 'TEST', - wantAgent: wantAgentObj, - } - - notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); - }); - } - setBadgeNumberCallback = async (err: Base.BusinessError) => { - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, `Failed to set badge number. Code is ${err.code}, message is ${err.message}`); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in setting badge number.`); - } - setBadgeNumber = async () => { - let badgeNumber = 9; - notificationManager.setBadgeNumber(badgeNumber, this.setBadgeNumberCallback); - } - setBadgeNumberForBasic = async () => { - await notificationManager.removeAllSlots(); - await notificationManager.addSlot(notificationManager.SlotType.CONTENT_INFORMATION); - await this.publishBasic(); - await this.setBadgeNumber(); - } -} +/* + * Copyright (c) 2023 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 Base from '@ohos.base'; +import image from '@ohos.multimedia.image'; +import notificationManager from '@ohos.notificationManager'; +import wantAgent from '@ohos.app.ability.wantAgent'; +import { WantAgent } from '@ohos.app.ability.wantAgent' +import hilog from '@ohos.hilog'; +import resourceManager from '@ohos.resourceManager'; + +const TAG: string = '[PublishOperation]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class PublishOperation { + private context: Context; + + constructor(context: Context) { + this.context = context; + } + + enableNotification = async () => { + notificationManager.isNotificationEnabled().then((data: boolean) => { + hilog.info(DOMAIN_NUMBER, TAG, 'isNotificationEnabled success, data: ' + JSON.stringify(data)); + if(!data){ + notificationManager.requestEnableNotification().then(() => { + hilog.info(DOMAIN_NUMBER, TAG, `[ANS] requestEnableNotification success`); + }).catch((err:Base.BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, + `[ANS] requestEnableNotification failed, code is ${err.code}, message is ${err.message}`); + }); + } + }).catch((err: Base.BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, `isNotificationEnabled fail: ${JSON.stringify(err)}`); + }); + } + publishBasic = async () => { + let notificationRequest: notificationManager.NotificationRequest = { + id: 1, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, // 普通文本类型通知 + normal: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText', + } + } + }; + + // 发布通知 + notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); + }); + } + publishLong = async () => { + let notificationRequest: notificationManager.NotificationRequest = { + id: 2, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_LONG_TEXT, // 长文本类型通知 + longText: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText', + longText: 'test_longText', + briefText: 'test_briefText', + expandedTitle: 'test_expandedTitle', + } + } + }; + + // 发布通知 + notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); + }); + } + publishMultiLine = async () => { + let notificationRequest: notificationManager.NotificationRequest = { + id: 3, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_MULTILINE, // 多行文本类型通知 + multiLine: { + title: 'test_title', + text: 'test_text', + briefText: 'test_briefText', + longTitle: 'test_longTitle', + lines: ['line_01', 'line_02', 'line_03', 'line_04'], + } + } + }; + + // 发布通知 + notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); + }); + } + + publishPicture = async () => { + const resourceMgr: resourceManager.ResourceManager = this.context.resourceManager; + let imageArray: Uint8Array = await resourceMgr.getMediaContent($r('app.media.pic').id); + const arraybuffer: ArrayBuffer = imageArray.buffer as ArrayBuffer; + let imageResource = image.createImageSource(arraybuffer); + let imagePixelMap = await imageResource.createPixelMap(); + + if (imagePixelMap !== undefined) { + let notificationRequest: notificationManager.NotificationRequest = { + id: 4, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_PICTURE, + picture: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText', + briefText: 'test_briefText', + expandedTitle: 'test_expandedTitle', + picture: imagePixelMap + } + } + }; + + // 发布通知 + notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); + }); + } + } + publishProgressBar = async () => { + notificationManager.isSupportTemplate('downloadTemplate').then((data: boolean) => { + hilog.info(DOMAIN_NUMBER, TAG, `[ANS] isSupportTemplate success`); + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in supporting download template notification.'); + if (data == true) { // data的值为true表示支持支持downloadTemplate模板类通知,false表示不支持 + let notificationRequest: notificationManager.NotificationRequest = { + id: 5, + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: 'test_title', + text: 'test_text', + additionalText: 'test_additionalText' + } + }, + // 构造进度条模板,name字段当前需要固定配置为downloadTemplate + template: { + name: 'downloadTemplate', + data: { + title: 'File Title', fileName: 'music.mp4', progressValue: 45 + } + } + } + // 发布通知 + notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); + }); + } + }).catch((err: Base.BusinessError) => { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to support download template notification. Code is ${err.code}, message is ${err.message}`); + }); + } + publishWantAgentStartAbility = async () => { + let wantAgentObj: WantAgent; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。 + // 通过WantAgentInfo的operationType设置动作类型 + let wantAgentInfo: wantAgent.WantAgentInfo = { + wants: [ + { + deviceId: '', + bundleName: 'com.samples.notification', + abilityName: 'SecondAbility', + action: '', + entities: [], + uri: '', + parameters: {} + } + ], + operationType: wantAgent.OperationType.START_ABILITY, + requestCode: 0, + wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG] + }; + // 创建WantAgent + wantAgent.getWantAgent(wantAgentInfo, (err: Base.BusinessError, data: WantAgent) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in getting want agent.'); + wantAgentObj = data; + this.publishWantAgent(wantAgentObj); + }); + } + publishWantAgentCommonEvent = async () => { + let wantAgentObj: WantAgent; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。 + // 通过WantAgentInfo的operationType设置动作类型 + let wantAgentInfo: wantAgent.WantAgentInfo = { + wants: [ + { + action: 'event_name', // 设置事件名 + parameters: {}, + } + ], + operationType: wantAgent.OperationType.SEND_COMMON_EVENT, + requestCode: 0, + wantAgentFlags: [wantAgent.WantAgentFlags.CONSTANT_FLAG], + }; + + // 创建WantAgent + wantAgent.getWantAgent(wantAgentInfo, (err: Base.BusinessError, data: WantAgent) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in getting want agent.'); + wantAgentObj = data; + this.publishWantAgent(wantAgentObj); + }); + } + publishWantAgent = async (wantAgentObj: WantAgent) => { + // 构造NotificationRequest对象 + let notificationRequest: notificationManager.NotificationRequest = { + content: { + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, + normal: { + title: 'Test_Title', + text: 'Test_Text', + additionalText: 'Test_AdditionalText', + }, + }, + id: 6, + label: 'TEST', + wantAgent: wantAgentObj, + } + + notificationManager.publish(notificationRequest, (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to publish notification. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in publishing notification.'); + }); + } + setBadgeNumberCallback = async (err: Base.BusinessError) => { + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, `Failed to set badge number. Code is ${err.code}, message is ${err.message}`); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, `Succeeded in setting badge number.`); + } + setBadgeNumber = async () => { + let badgeNumber = 9; + notificationManager.setBadgeNumber(badgeNumber, this.setBadgeNumberCallback); + } + setBadgeNumberForBasic = async () => { + await notificationManager.removeAllSlots(); + await notificationManager.addSlot(notificationManager.SlotType.CONTENT_INFORMATION); + await this.publishBasic(); + await this.setBadgeNumber(); + } +} diff --git a/code/DocsSample/Notification/Notification/entry/src/main/ets/secondAbility/SecondAbility.ets b/code/DocsSample/Notification/Notification/entry/src/main/ets/secondAbility/SecondAbility.ets index be13d054f10ac74c2db168a08dbd6f78b5a36f8f..e17ba3c4df992d2efee0f8af8f8d84b9dd6e327f 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/ets/secondAbility/SecondAbility.ets +++ b/code/DocsSample/Notification/Notification/entry/src/main/ets/secondAbility/SecondAbility.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import Base from '@ohos.base'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import hilog from '@ohos.hilog'; - -const TAG: string = '[SecondAbility]'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class SecondAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onCreate'); - } - - onDestroy() { - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/Second', (err: Base.BusinessError) => { - if (err.code) { - hilog.info(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import Base from '@ohos.base'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import hilog from '@ohos.hilog'; + +const TAG: string = '[SecondAbility]'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class SecondAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onCreate'); + } + + onDestroy() { + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Second', (err: Base.BusinessError) => { + if (err.code) { + hilog.info(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, 'Ability onBackground'); + } +} diff --git a/code/DocsSample/Notification/Notification/entry/src/main/ets/subscribe/SubscribeOperation.ets b/code/DocsSample/Notification/Notification/entry/src/main/ets/subscribe/SubscribeOperation.ets index e7b3dc0dc79850518c4e1cc42d3c64667b50094f..4c53d5dbbbb57c7e09a650fec219d079504f37f4 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/ets/subscribe/SubscribeOperation.ets +++ b/code/DocsSample/Notification/Notification/entry/src/main/ets/subscribe/SubscribeOperation.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2023 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 Base from '@ohos.base'; -import notificationSubscribe from '@ohos.notificationSubscribe'; -import hilog from '@ohos.hilog'; -import notificationManager from '@ohos.notificationManager'; - -interface NotificationSortingMap { - readonly sortedHashCode: Array; -} - -const TAG: string = '[SubscribeOperations]'; -const DOMAIN_NUMBER: number = 0xFF00; - -class SubscribeOperations { - createSubscriber = async () => { - let subscriber: notificationSubscribe.NotificationSubscriber = { - onConsume: (data: notificationSubscribe.SubscribeCallbackData) => { - let req: notificationManager.NotificationRequest = data.request; - hilog.info(DOMAIN_NUMBER, TAG, `onConsume callback. req.id: ${req.id}`); - }, - onCancel: (data: notificationSubscribe.SubscribeCallbackData) => { - let req: notificationManager.NotificationRequest = data.request; - hilog.info(DOMAIN_NUMBER, TAG, `onCancel callback. req.id: ${req.id}`); - }, - onUpdate: (data: NotificationSortingMap) => { - hilog.info(DOMAIN_NUMBER, TAG, `onUpdate callback. req.id: ${data.sortedHashCode}`); - }, - onConnect: () => { - hilog.info(DOMAIN_NUMBER, TAG, `onConnect callback.`); - }, - onDisconnect: () => { - hilog.info(DOMAIN_NUMBER, TAG, `onDisconnect callback.`); - }, - onDestroy: () => { - hilog.info(DOMAIN_NUMBER, TAG, `onDestroy callback.`); - }, - }; - - notificationSubscribe.subscribe(subscriber, (err: Base.BusinessError) => { // callback形式调用异步接口 - if (err) { - hilog.error(DOMAIN_NUMBER, TAG, - `Failed to subscribe notification. Code is ${err.code}, message is ${err.message}`); - return; - } - }); - } -} - +/* + * Copyright (c) 2023 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 Base from '@ohos.base'; +import notificationSubscribe from '@ohos.notificationSubscribe'; +import hilog from '@ohos.hilog'; +import notificationManager from '@ohos.notificationManager'; + +interface NotificationSortingMap { + readonly sortedHashCode: Array; +} + +const TAG: string = '[SubscribeOperations]'; +const DOMAIN_NUMBER: number = 0xFF00; + +class SubscribeOperations { + createSubscriber = async () => { + let subscriber: notificationSubscribe.NotificationSubscriber = { + onConsume: (data: notificationSubscribe.SubscribeCallbackData) => { + let req: notificationManager.NotificationRequest = data.request; + hilog.info(DOMAIN_NUMBER, TAG, `onConsume callback. req.id: ${req.id}`); + }, + onCancel: (data: notificationSubscribe.SubscribeCallbackData) => { + let req: notificationManager.NotificationRequest = data.request; + hilog.info(DOMAIN_NUMBER, TAG, `onCancel callback. req.id: ${req.id}`); + }, + onUpdate: (data: NotificationSortingMap) => { + hilog.info(DOMAIN_NUMBER, TAG, `onUpdate callback. req.id: ${data.sortedHashCode}`); + }, + onConnect: () => { + hilog.info(DOMAIN_NUMBER, TAG, `onConnect callback.`); + }, + onDisconnect: () => { + hilog.info(DOMAIN_NUMBER, TAG, `onDisconnect callback.`); + }, + onDestroy: () => { + hilog.info(DOMAIN_NUMBER, TAG, `onDestroy callback.`); + }, + }; + + notificationSubscribe.subscribe(subscriber, (err: Base.BusinessError) => { // callback形式调用异步接口 + if (err) { + hilog.error(DOMAIN_NUMBER, TAG, + `Failed to subscribe notification. Code is ${err.code}, message is ${err.message}`); + return; + } + }); + } +} + export let subscribeOperations = new SubscribeOperations(); \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/src/main/ets/util/Logger.ets b/code/DocsSample/Notification/Notification/entry/src/main/ets/util/Logger.ets index 8161ed13ad4473c80824bf1f8328e9cd6782a071..37c4bc4c93fa24e43c77efd270e71c1ea177b605 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/ets/util/Logger.ets +++ b/code/DocsSample/Notification/Notification/entry/src/main/ets/util/Logger.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix - this.domain = 0xFF00 - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xFF00 + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export let logger = new Logger('[Sample_Notification]'); \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/src/main/module.json5 b/code/DocsSample/Notification/Notification/entry/src/main/module.json5 index 64e5dc0ebe08cc68de932956341cbc0487fc3cc8..f2f1d21694a813d96175354c311e89f175c3a821 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/module.json5 +++ b/code/DocsSample/Notification/Notification/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2023 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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "SecondAbility", - "srcEntry": "./ets/secondAbility/SecondAbility.ets", - "description": "$string:SecondAbility_desc", - "icon": "$media:icon", - "label": "$string:SecondAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - ], - "requestPermissions": [ - { - "name": "ohos.permission.NOTIFICATION_CONTROLLER", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - "when": "always" - } - } - ] - } +/* + * Copyright (c) 2023 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:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "SecondAbility", + "srcEntry": "./ets/secondAbility/SecondAbility.ets", + "description": "$string:SecondAbility_desc", + "icon": "$media:icon", + "label": "$string:SecondAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + ], + "requestPermissions": [ + { + "name": "ohos.permission.NOTIFICATION_CONTROLLER", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/src/main/resources/base/element/color.json b/code/DocsSample/Notification/Notification/entry/src/main/resources/base/element/color.json index e1691a2f316e327d18f698691d314d79bf98cc9b..59da6fd48a8fb1776cf4a71be42a94aaa6129e4c 100644 --- a/code/DocsSample/Notification/Notification/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Notification/Notification/entry/src/main/resources/base/element/color.json @@ -1,20 +1,20 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#f1f3f5" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#f1f3f5" + }, + { + "name": "backGrounding", + "value": "#f1f3f5" + }, + { + "name": "text_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/src/ohosTest/ets/util/Logger.ets b/code/DocsSample/Notification/Notification/entry/src/ohosTest/ets/util/Logger.ets index 314038b8c8afb04096f50f0107c5437e655c67d0..b7fe26163623b756cfecc2fe9159f25abad2749c 100644 --- a/code/DocsSample/Notification/Notification/entry/src/ohosTest/ets/util/Logger.ets +++ b/code/DocsSample/Notification/Notification/entry/src/ohosTest/ets/util/Logger.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix - this.domain = 0xF811 - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xF811 + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export let logger = new Logger('[Test_Notification]'); \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/entry/src/ohosTest/module.json5 b/code/DocsSample/Notification/Notification/entry/src/ohosTest/module.json5 index 7e44e83cf9b7428c7a916f5782b9a6d85bf6d7da..e6a499c49efe53f1a5bab25638ce6b00f612a7d8 100644 --- a/code/DocsSample/Notification/Notification/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Notification/Notification/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/DocsSample/Notification/Notification/hvigor/hvigor-config.json5 b/code/DocsSample/Notification/Notification/hvigor/hvigor-config.json5 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 100644 --- a/code/DocsSample/Notification/Notification/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Notification/Notification/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/DocsSample/Notification/Notification/oh-package.json5 b/code/DocsSample/Notification/Notification/oh-package.json5 index 50977617421d9ae1bf03876130eedfc9e73bb79f..1bad7f601d80d02a4d0e7760d92ca2fc64797096 100644 --- a/code/DocsSample/Notification/Notification/oh-package.json5 +++ b/code/DocsSample/Notification/Notification/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "notification", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "notification", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/DocsSample/Notification/Notification/ohosTest.md b/code/DocsSample/Notification/Notification/ohosTest.md index 44c41be7d0a75af62e6137413978d0f1bf412a20..31049a6bbc9b3ee22817999b5c60113b24a15825 100644 --- a/code/DocsSample/Notification/Notification/ohosTest.md +++ b/code/DocsSample/Notification/Notification/ohosTest.md @@ -1,16 +1,16 @@ -# Notification 测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------- | -------------- | ----------------------- | ------------------------------------------------------------ | :------- | -------- | -| 应用请求通知使能 | 设备正常运行 | 点击使能通知 | 底部弹出提示对话框,显示是否允许"Notification"发送通知.点击确认后开启通知权限 | 是 | Pass | -| 发布设置角标通知 | 已开启通知授权 | 点击设置角标 | 查看角标数量 | 否 | Pass | -| 发布普通文本通知 | 已开启通知授权 | 点击发布普通文本 | 通知栏显示通知图标,下拉后标题为'test_title',文本内容为'test_text',附加信息为'test_additionalText' | 是 | Pass | -| 发布长文本类型通知 | 已开启通知授权 | 点击长文本通知 | 通知栏显示通知图标,下拉后文本标题为 test_expandedTitle 文本内容为 test_longText | 是 | Pass | -| 发布多行文本通知 | 已开启通知授权 | 点击多行文本通知 | 通知栏显示通知图标,下拉后存在文本标题test_longTitle 文本内容为纵向的 'line_01', 'line_02', 'line_03', 'line_04' | 是 | Pass | -| 发布图片类型通知 | 已开启通知授权 | 点击图片通知 | 通知栏显示通知图标,下拉后文本标题为Test_Title 文本内容 为test_text, 弹窗右侧存在图片 | 是 | Pass | -| 发布进度条通知 | 已开启通知授权 | 点击发布进度条通知 | 通知栏显示通知图标,下拉后存在文件下载的进度条 | 否 | Pass | -| 发布公共事件通知 | 已开启通知授权 | 点击发布公共事件通知 | 通知栏显示通知图标,下拉后文本标题 Test_Title 文本内容 test_text | 是 | Pass | -| 发布启动Ability通知 | 已开启通知授权 | 点击发布启动Ability通知 | 通知栏显示通知图标,下拉后存在文本标题 Test_Title 文本内容 test_text,点击后打开 SecondAbility,并进入 | 是 | Pass | - +# Notification 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------- | -------------- | ----------------------- | ------------------------------------------------------------ | :------- | -------- | +| 应用请求通知使能 | 设备正常运行 | 点击使能通知 | 底部弹出提示对话框,显示是否允许"Notification"发送通知.点击确认后开启通知权限 | 是 | Pass | +| 发布设置角标通知 | 已开启通知授权 | 点击设置角标 | 查看角标数量 | 否 | Pass | +| 发布普通文本通知 | 已开启通知授权 | 点击发布普通文本 | 通知栏显示通知图标,下拉后标题为'test_title',文本内容为'test_text',附加信息为'test_additionalText' | 是 | Pass | +| 发布长文本类型通知 | 已开启通知授权 | 点击长文本通知 | 通知栏显示通知图标,下拉后文本标题为 test_expandedTitle 文本内容为 test_longText | 是 | Pass | +| 发布多行文本通知 | 已开启通知授权 | 点击多行文本通知 | 通知栏显示通知图标,下拉后存在文本标题test_longTitle 文本内容为纵向的 'line_01', 'line_02', 'line_03', 'line_04' | 是 | Pass | +| 发布图片类型通知 | 已开启通知授权 | 点击图片通知 | 通知栏显示通知图标,下拉后文本标题为Test_Title 文本内容 为test_text, 弹窗右侧存在图片 | 是 | Pass | +| 发布进度条通知 | 已开启通知授权 | 点击发布进度条通知 | 通知栏显示通知图标,下拉后存在文件下载的进度条 | 否 | Pass | +| 发布公共事件通知 | 已开启通知授权 | 点击发布公共事件通知 | 通知栏显示通知图标,下拉后文本标题 Test_Title 文本内容 test_text | 是 | Pass | +| 发布启动Ability通知 | 已开启通知授权 | 点击发布启动Ability通知 | 通知栏显示通知图标,下拉后存在文本标题 Test_Title 文本内容 test_text,点击后打开 SecondAbility,并进入 | 是 | Pass | + diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/.gitignore b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/app.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/app.json5 old mode 100755 new mode 100644 index 09cfe33a8c1dbebbd5125f484931821bbc106794..7ce69cd85af9af5f8d3a135e4089e5911ee58339 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/app.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/app.json5 @@ -1,25 +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.assetstoreproject", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.assetstoreproject", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 730252237fdd57a82fbb93951789998172be2063..f5ec105027da1aaaf7d29c0eb99bca11e436cf06 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AssetStoreProject" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AssetStoreProject" + } + ] +} diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/README.md b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/README.md old mode 100755 new mode 100644 index 3fb8bd7f7162fce7eb13e900b18695977ed4baa9..6e96cbfd4e68c8b68adda14ee9faf1a6e1244c7f --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/README.md +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/README.md @@ -1,73 +1,73 @@ -# Asset Store Kit开发指导(ArkTS) - -### 介绍 - -Asset Store Kit(关键资产存储开发套件)包含了关键资产存储服务(ASSET)开放的接口能力集合,提供了用户短敏感数据的安全存储及管理能力。其中,短敏感数据可以是密码类(账号/密码)、Token类(应用凭据)、关键明文(如银行卡号)等长度较短的用户敏感数据。 - -本示例主要展示了Asset Store Kit开发指导(ArkTS)中新增关键资产、删除关键资产、更新关键资产、查询关键资产和查询关键资产场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [新增关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-add.md) -- [删除关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-remove.md) -- [更新关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-update.md) -- [查询关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-query.md) -- [查询需要用户的关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-query-auth.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击文本为‘Add Critical Asset’和'Add Critical Asset Auth'的按钮可以新增资产,点击Remove Critical Asset'和'Remove Critical Asset Second'按钮可以对应删除新增资产点击'Update Critical Asset'、'QueryAll Critical Asset'、'QueryAttributes Critical Asset'、'QueryList Critical Asset'可以依次进行关键资产的更新查询,其中最后一个按钮需要具有用户关键资产点击后才可成功(可以通过设置运行设备锁屏密码后点击图中1,4按钮添加后执行成功弹出输入密码框) -3. 运行测试用例AssetStoreArkTS.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // Asset Store Kit开发指导(ArkTS)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── AssetStoreArkTS.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -ohos.permission.ACCESS_BIOMETRIC - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# Asset Store Kit开发指导(ArkTS) + +### 介绍 + +Asset Store Kit(关键资产存储开发套件)包含了关键资产存储服务(ASSET)开放的接口能力集合,提供了用户短敏感数据的安全存储及管理能力。其中,短敏感数据可以是密码类(账号/密码)、Token类(应用凭据)、关键明文(如银行卡号)等长度较短的用户敏感数据。 + +本示例主要展示了Asset Store Kit开发指导(ArkTS)中新增关键资产、删除关键资产、更新关键资产、查询关键资产和查询关键资产场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [新增关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-add.md) +- [删除关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-remove.md) +- [更新关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-update.md) +- [查询关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-query.md) +- [查询需要用户的关键资产(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-js-query-auth.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击文本为‘Add Critical Asset’和'Add Critical Asset Auth'的按钮可以新增资产,点击Remove Critical Asset'和'Remove Critical Asset Second'按钮可以对应删除新增资产点击'Update Critical Asset'、'QueryAll Critical Asset'、'QueryAttributes Critical Asset'、'QueryList Critical Asset'可以依次进行关键资产的更新查询,其中最后一个按钮需要具有用户关键资产点击后才可成功(可以通过设置运行设备锁屏密码后点击图中1,4按钮添加后执行成功弹出输入密码框) +3. 运行测试用例AssetStoreArkTS.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // Asset Store Kit开发指导(ArkTS)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── AssetStoreArkTS.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +ohos.permission.ACCESS_BIOMETRIC + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/build-profile.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/build-profile.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/code-linter.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/.gitignore b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/build-profile.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/build-profile.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/hvigorfile.ts b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/oh-package.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/oh-package.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/module.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/module.json5 old mode 100755 new mode 100644 index b2b3da6691ed861ba4d89b575d9fe2babb92ab21..e9819632b5c13bf1a171be3e9049eedb6425a5a5 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/module.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/module.json5 @@ -1,75 +1,75 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.ACCESS_BIOMETRIC", - "reason": "$string:reason", - "usedScene": { - "when": "always" - } - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_BIOMETRIC", + "reason": "$string:reason", + "usedScene": { + "when": "always" + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/AssetStoreArkTS.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/AssetStoreArkTS.test.ets old mode 100755 new mode 100644 index 7718fcb683135eb024b078ec0419c394426f4978..654b441b3dca6623c33e590eb8646538c56e0a80 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/AssetStoreArkTS.test.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/AssetStoreArkTS.test.ets @@ -1,111 +1,111 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function assetStoreArkTSTest() { - describe('assetStoreArkTSTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,添加关键资产 - */ - it('testAssetStoreArkTS001', 0, async () => { - console.info('uitest: testAssetStoreArkTS001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Add Critical Asset')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Add Critical Asset Success')); - console.info('uitest: testAssetStoreArkTS001 end'); - }) - - /** - * 点击按钮,添加关键资产 - */ - it('testAssetStoreArkTS002', 0, async () => { - console.info('uitest: testAssetStoreArkTS002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Add Critical Asset Auth')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Add Critical Asset Auth Success')); - console.info('uitest: testAssetStoreArkTS002 end'); - }) - - /** - * 点击按钮,更新查询关键资产 - */ - it('testAssetStoreArkTS003', 0, async () => { - console.info('uitest: testAssetStoreArkTS003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Update Critical Asset')); - const button2 = await driver.findComponent(ON.text('QueryAll Critical Asset')); - const button3 = await driver.findComponent(ON.text('QueryAttributes Critical Asset')); - const button4 = await driver.findComponent(ON.text('QueryList Critical Asset')); - await button1.click(); - await button2.click(); - await button3.click(); - await button4.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Update Critical Asset Success')); - await driver.assertComponentExist(ON.text('QueryAll Critical Asset Success')); - await driver.assertComponentExist(ON.text('QueryAttributes Critical Asset Success')); - await driver.assertComponentExist(ON.text('QueryList Critical Asset Success')); - console.info('uitest: testAssetStoreArkTS003 end'); - }) - - /** - * 点击按钮,删除关键资产 - */ - it('testAssetStoreArkTS004', 0, async () => { - console.info('uitest: testAssetStoreArkTS004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Remove Critical Asset')); - const button2 = await driver.findComponent(ON.text('Remove Critical Asset Second')); - await button1.click(); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Remove Critical Asset Success')); - await driver.assertComponentExist(ON.text('Remove Critical Asset Second Success')); - console.info('uitest: testAssetStoreArkTS004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function assetStoreArkTSTest() { + describe('assetStoreArkTSTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,添加关键资产 + */ + it('testAssetStoreArkTS001', 0, async () => { + console.info('uitest: testAssetStoreArkTS001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Add Critical Asset')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Add Critical Asset Success')); + console.info('uitest: testAssetStoreArkTS001 end'); + }) + + /** + * 点击按钮,添加关键资产 + */ + it('testAssetStoreArkTS002', 0, async () => { + console.info('uitest: testAssetStoreArkTS002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Add Critical Asset Auth')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Add Critical Asset Auth Success')); + console.info('uitest: testAssetStoreArkTS002 end'); + }) + + /** + * 点击按钮,更新查询关键资产 + */ + it('testAssetStoreArkTS003', 0, async () => { + console.info('uitest: testAssetStoreArkTS003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Update Critical Asset')); + const button2 = await driver.findComponent(ON.text('QueryAll Critical Asset')); + const button3 = await driver.findComponent(ON.text('QueryAttributes Critical Asset')); + const button4 = await driver.findComponent(ON.text('QueryList Critical Asset')); + await button1.click(); + await button2.click(); + await button3.click(); + await button4.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Update Critical Asset Success')); + await driver.assertComponentExist(ON.text('QueryAll Critical Asset Success')); + await driver.assertComponentExist(ON.text('QueryAttributes Critical Asset Success')); + await driver.assertComponentExist(ON.text('QueryList Critical Asset Success')); + console.info('uitest: testAssetStoreArkTS003 end'); + }) + + /** + * 点击按钮,删除关键资产 + */ + it('testAssetStoreArkTS004', 0, async () => { + console.info('uitest: testAssetStoreArkTS004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Remove Critical Asset')); + const button2 = await driver.findComponent(ON.text('Remove Critical Asset Second')); + await button1.click(); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Remove Critical Asset Success')); + await driver.assertComponentExist(ON.text('Remove Critical Asset Second Success')); + console.info('uitest: testAssetStoreArkTS004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/AssetStoreKit/AssetStoreArkTS/entry/src/test/List.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/AssetStoreKit/AssetStoreArkTS/hvigorfile.ts b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/oh-package.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/oh-package.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/AssetStoreKit/AssetStoreArkTS/ohosTest.md b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/ohosTest.md old mode 100755 new mode 100644 index 4843a896f86104c2662cddac55d7ca5964077f1c..f2c9d18d6f01ac1929a0e87c19391cfbdd6f3018 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/ohosTest.md +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/ohosTest.md @@ -1,11 +1,11 @@ -# Asset Store Kit(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮新增关键资产 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | -| 点击按钮新增关键资产 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | -| 点击按钮更新并查询关键资产 | 成功拉起应用 | | 成功更新查询并输出日志 | 是 | Pass | +# Asset Store Kit(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮新增关键资产 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +| 点击按钮新增关键资产 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +| 点击按钮更新并查询关键资产 | 成功拉起应用 | | 成功更新查询并输出日志 | 是 | Pass | | 点击按钮移除关键资产 | 成功拉起应用 | | 成功移除并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/screenshots/AssetStoreArkTS1.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/screenshots/AssetStoreArkTS1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/screenshots/AssetStoreArkTS2.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreArkTS/screenshots/AssetStoreArkTS2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/.gitignore b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/app.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/app.json5 old mode 100755 new mode 100644 index 9adf839d888004bfeb4a42acf31d655a503d40bc..bcf7c42f7ee30ea3c8b43d76f8a544fa0b778bb9 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/app.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/app.json5 @@ -1,25 +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.assetstorendk", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.assetstorendk", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/resources/base/element/string.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 14d02017ba134ccf6022d50e9f819fedb631cb49..7122455547eac86f79b9f6d3dbfd73d76356d412 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AssetStoreNdk" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AssetStoreNdk" + } + ] +} diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/README.md b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/README.md old mode 100755 new mode 100644 index 51ff1c070d120e1f6e370ba25e6510966f174cce..dd0502b079c8dc7c1f5e5bee64cf8a00dc82a5c5 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/README.md +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/README.md @@ -1,78 +1,78 @@ -# Asset Store Kit开发指导(C/C++) - -### 介绍 - -Asset Store Kit(关键资产存储开发套件)包含了关键资产存储服务(ASSET)开放的接口能力集合,提供了用户短敏感数据的安全存储及管理能力。其中,短敏感数据可以是密码类(账号/密码)、Token类(应用凭据)、关键明文(如银行卡号)等长度较短的用户敏感数据。 - -本示例主要展示了Asset Store Kit开发指导(C/C++)中新增关键资产、删除关键资产、更新关键资产、查询关键资产场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [新增关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-add.md) -- [删除关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-remove.md) -- [更新关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-update.md) -- [查询关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-query.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击文本为‘AddAsset’的按钮可以新增资产,点击'RemoveAsset'按钮可以删除新增资产,点击'UpdateAsset'、'QueryAsset'、'QueryAttributesAsset'、'BatchQuary'可以依次进行关键资产的更新查询,其中最后一个按钮需要先在添加后直接查询可成功,更新后会导致失败。 -3. 运行测试用例AssetStoreNdk.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ ├── libentry - │ │ | ├── index.d.ts - │ │ ├── CMakeLists.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // Asset Store Kit开发指导(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── AssetStoreNdk.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/AssetStoreKit/AssetStoreNdk > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# Asset Store Kit开发指导(C/C++) + +### 介绍 + +Asset Store Kit(关键资产存储开发套件)包含了关键资产存储服务(ASSET)开放的接口能力集合,提供了用户短敏感数据的安全存储及管理能力。其中,短敏感数据可以是密码类(账号/密码)、Token类(应用凭据)、关键明文(如银行卡号)等长度较短的用户敏感数据。 + +本示例主要展示了Asset Store Kit开发指导(C/C++)中新增关键资产、删除关键资产、更新关键资产、查询关键资产场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [新增关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-add.md) +- [删除关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-remove.md) +- [更新关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-update.md) +- [查询关键资产(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AssetStoreKit/asset-native-query.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击文本为‘AddAsset’的按钮可以新增资产,点击'RemoveAsset'按钮可以删除新增资产,点击'UpdateAsset'、'QueryAsset'、'QueryAttributesAsset'、'BatchQuary'可以依次进行关键资产的更新查询,其中最后一个按钮需要先在添加后直接查询可成功,更新后会导致失败。 +3. 运行测试用例AssetStoreNdk.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ ├── libentry + │ │ | ├── index.d.ts + │ │ ├── CMakeLists.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // Asset Store Kit开发指导(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── AssetStoreNdk.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/AssetStoreKit/AssetStoreNdk > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/build-profile.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/build-profile.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/code-linter.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/.gitignore b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/build-profile.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/build-profile.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/AssetStoreKit/AssetStoreNdk/entry/hvigorfile.ts b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/oh-package.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/oh-package.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 2b6d880a64abedda982c982e0a51219ecef92623..5995f4dc00f5ec592db1b5e7d68b5e94e85e76d3 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(AssetStoreNdk) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(AssetStoreNdk) + +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 libasset_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index f4dbb358715c1dccf92307862406b0f8f765cee1..57a51088ee311c6bacae176db1ae1c97d7882ee4 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/napi_init.cpp @@ -1,209 +1,209 @@ -/* - * 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 -#include "asset/asset_api.h" - -static constexpr int INT_ARG_7 = 7; // 入参索引 -static constexpr int INT_ARG_6 = 6; // 入参索引 - -static napi_value NAPI_Global_AddAsset(napi_env env, napi_callback_info info) -{ - static const char *secretContent = "demo_pwd"; - static const char *aliasContent = "demo_alias"; - static const char *labelContent = "demo_label"; - - Asset_Blob secret = {(uint32_t)(strlen(secretContent)), (uint8_t *)secretContent}; - Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; - Asset_Blob label = {(uint32_t)(strlen(labelContent)), (uint8_t *)labelContent}; - Asset_Attr attr[] = { - {.tag = ASSET_TAG_ACCESSIBILITY, .value.u32 = ASSET_ACCESSIBILITY_DEVICE_FIRST_UNLOCKED}, - {.tag = ASSET_TAG_SECRET, .value.blob = secret}, - {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, - {.tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = label}, - }; - - int32_t ret = OH_Asset_Add(attr, sizeof(attr) / sizeof(attr[0])); - napi_value result; - if (ret == ASSET_SUCCESS) { - // Asset added successfully. - napi_create_string_utf8(env, "success", INT_ARG_7, &result); - } else { - // Failed to add Asset. - napi_create_string_utf8(env, "failed", INT_ARG_6, &result); - } - return result; -} - -static napi_value RemoveAsset(napi_env env, napi_callback_info info) -{ - static const char *aliasContent = "demo_alias"; - Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; - - Asset_Attr attr[] = { - {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, // 此处指定别名删除,也可不指定别名删除多条数据 - }; - - int32_t ret = OH_Asset_Remove(attr, sizeof(attr) / sizeof(attr[0])); - napi_value result; - if (ret == ASSET_SUCCESS) { - // Asset added successfully. - napi_create_string_utf8(env, "success", INT_ARG_7, &result); - } else { - // Failed to add Asset. - napi_create_string_utf8(env, "failed", INT_ARG_6, &result); - } - return result; -} - -static napi_value NAPI_Global_UpdateAsset(napi_env env, napi_callback_info info) -{ - static const char *aliasContent = "demo_alias"; - static const char *secretContent = "demo_pwd_new"; - static const char *labelContent = "demo_label_new"; - - Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; - Asset_Blob new_secret = {(uint32_t)(strlen(secretContent)), (uint8_t *)secretContent}; - Asset_Blob new_label = {(uint32_t)(strlen(labelContent)), (uint8_t *)labelContent}; - Asset_Attr query[] = {{.tag = ASSET_TAG_ALIAS, .value.blob = alias}}; - Asset_Attr attributesToUpdate[] = { - {.tag = ASSET_TAG_SECRET, .value.blob = new_secret}, - {.tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = new_label}, - }; - - int32_t ret = OH_Asset_Update(query, sizeof(query) / sizeof(query[0]), attributesToUpdate, - sizeof(attributesToUpdate) / sizeof(attributesToUpdate[0])); - napi_value result; - if (ret == ASSET_SUCCESS) { - // Asset added successfully. - napi_create_string_utf8(env, "success", INT_ARG_7, &result); - } else { - // Failed to add Asset. - napi_create_string_utf8(env, "failed", INT_ARG_6, &result); - } - return result; -} - -static napi_value NAPI_Global_QueryAsset(napi_env env, napi_callback_info info) -{ - static const char *aliasContent = "demo_alias"; - Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; - Asset_Attr attr[] = { - {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, // 指定了关键资产别名,最多查询到一条满足条件的关键资产 - {.tag = ASSET_TAG_RETURN_TYPE, - .value.u32 = ASSET_RETURN_ALL}, // 此处表示需要返回关键资产的所有信息,即属性+明文 - }; - - Asset_ResultSet resultSet = {0}; - napi_value result; - int32_t ret = OH_Asset_Query(attr, sizeof(attr) / sizeof(attr[0]), &resultSet); - if (ret == ASSET_SUCCESS) { - // Parse the resultSet. - for (uint32_t i = 0; i < resultSet.count; i++) { - // Parse the secret: the data is secret->blob.data, the size is secret->blob.size. - Asset_Attr *secret = OH_Asset_ParseAttr(resultSet.results + i, ASSET_TAG_SECRET); - } - napi_create_string_utf8(env, "success", INT_ARG_7, &result); - } else { - napi_create_string_utf8(env, "failed", INT_ARG_6, &result); - } - OH_Asset_FreeResultSet(&resultSet); - return result; -} -static napi_value NAPI_Global_QueryAttributes(napi_env env, napi_callback_info info) -{ - static const char *aliasContent = "demo_alias"; - Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; - Asset_Attr attr[] = { - {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, // 指定了关键资产别名,最多查询到一条满足条件的关键资产 - {.tag = ASSET_TAG_RETURN_TYPE, - .value.u32 = ASSET_RETURN_ATTRIBUTES}, // 此处表示仅返回关键资产属性,不包含关键资产明文 - }; - - Asset_ResultSet resultSet = {0}; - int32_t ret = OH_Asset_Query(attr, sizeof(attr) / sizeof(attr[0]), &resultSet); - napi_value result; - if (ret == ASSET_SUCCESS) { - // Parse the result. - for (uint32_t i = 0; i < resultSet.count; i++) { - // Parse the data label: the data is label->blob.data, the size is label->blob.size. - Asset_Attr *label = OH_Asset_ParseAttr(resultSet.results + i, ASSET_TAG_DATA_LABEL_NORMAL_1); - } - napi_create_string_utf8(env, "success", INT_ARG_7, &result); - } else { - napi_create_string_utf8(env, "failed", INT_ARG_6, &result); - } - OH_Asset_FreeResultSet(&resultSet); - return result; -} - -static napi_value NAPI_Global_BatchQuery(napi_env env, napi_callback_info info) -{ - static const char *labelContent = "demo_label"; - Asset_Blob label = {(uint32_t)(strlen(labelContent)), (uint8_t *)labelContent}; - static const char *aliasContent = "demo_alias"; - Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; - - Asset_Attr attr[] = { - {.tag = ASSET_TAG_RETURN_TYPE, .value.u32 = ASSET_RETURN_ATTRIBUTES}, - {.tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = label}, - {.tag = ASSET_TAG_RETURN_OFFSET, .value.u32 = 0}, - {.tag = ASSET_TAG_RETURN_LIMIT, .value.u32 = 1}, - {.tag = ASSET_TAG_RETURN_ORDERED_BY, .value.u32 = ASSET_TAG_DATA_LABEL_NORMAL_1}, - }; - - Asset_ResultSet resultSet = {0}; - int32_t ret = OH_Asset_Query(attr, sizeof(attr) / sizeof(attr[0]), &resultSet); - napi_value result; - if (ret == ASSET_SUCCESS) { - // Parse the result. - for (uint32_t i = 0; i < resultSet.count; i++) { - // Parse the data alias: the data is alias->blob.data, the size is alias->blob.size.. - Asset_Attr *alias = OH_Asset_ParseAttr(resultSet.results + i, ASSET_TAG_ALIAS); - } - napi_create_string_utf8(env, "success", INT_ARG_7, &result); - } else { - napi_create_string_utf8(env, "failed", INT_ARG_6, &result); - } - OH_Asset_FreeResultSet(&resultSet); - return result; -} -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"AddAsset", nullptr, NAPI_Global_AddAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"RemoveAsset", nullptr, RemoveAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"UpdateAsset", nullptr, NAPI_Global_UpdateAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"QueryAsset", nullptr, NAPI_Global_QueryAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"QueryAttributes", nullptr, NAPI_Global_QueryAttributes, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"BatchQuery", nullptr, NAPI_Global_BatchQuery, 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); } +/* + * 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 +#include "asset/asset_api.h" + +static constexpr int INT_ARG_7 = 7; // 入参索引 +static constexpr int INT_ARG_6 = 6; // 入参索引 + +static napi_value NAPI_Global_AddAsset(napi_env env, napi_callback_info info) +{ + static const char *secretContent = "demo_pwd"; + static const char *aliasContent = "demo_alias"; + static const char *labelContent = "demo_label"; + + Asset_Blob secret = {(uint32_t)(strlen(secretContent)), (uint8_t *)secretContent}; + Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; + Asset_Blob label = {(uint32_t)(strlen(labelContent)), (uint8_t *)labelContent}; + Asset_Attr attr[] = { + {.tag = ASSET_TAG_ACCESSIBILITY, .value.u32 = ASSET_ACCESSIBILITY_DEVICE_FIRST_UNLOCKED}, + {.tag = ASSET_TAG_SECRET, .value.blob = secret}, + {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, + {.tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = label}, + }; + + int32_t ret = OH_Asset_Add(attr, sizeof(attr) / sizeof(attr[0])); + napi_value result; + if (ret == ASSET_SUCCESS) { + // Asset added successfully. + napi_create_string_utf8(env, "success", INT_ARG_7, &result); + } else { + // Failed to add Asset. + napi_create_string_utf8(env, "failed", INT_ARG_6, &result); + } + return result; +} + +static napi_value RemoveAsset(napi_env env, napi_callback_info info) +{ + static const char *aliasContent = "demo_alias"; + Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; + + Asset_Attr attr[] = { + {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, // 此处指定别名删除,也可不指定别名删除多条数据 + }; + + int32_t ret = OH_Asset_Remove(attr, sizeof(attr) / sizeof(attr[0])); + napi_value result; + if (ret == ASSET_SUCCESS) { + // Asset added successfully. + napi_create_string_utf8(env, "success", INT_ARG_7, &result); + } else { + // Failed to add Asset. + napi_create_string_utf8(env, "failed", INT_ARG_6, &result); + } + return result; +} + +static napi_value NAPI_Global_UpdateAsset(napi_env env, napi_callback_info info) +{ + static const char *aliasContent = "demo_alias"; + static const char *secretContent = "demo_pwd_new"; + static const char *labelContent = "demo_label_new"; + + Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; + Asset_Blob new_secret = {(uint32_t)(strlen(secretContent)), (uint8_t *)secretContent}; + Asset_Blob new_label = {(uint32_t)(strlen(labelContent)), (uint8_t *)labelContent}; + Asset_Attr query[] = {{.tag = ASSET_TAG_ALIAS, .value.blob = alias}}; + Asset_Attr attributesToUpdate[] = { + {.tag = ASSET_TAG_SECRET, .value.blob = new_secret}, + {.tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = new_label}, + }; + + int32_t ret = OH_Asset_Update(query, sizeof(query) / sizeof(query[0]), attributesToUpdate, + sizeof(attributesToUpdate) / sizeof(attributesToUpdate[0])); + napi_value result; + if (ret == ASSET_SUCCESS) { + // Asset added successfully. + napi_create_string_utf8(env, "success", INT_ARG_7, &result); + } else { + // Failed to add Asset. + napi_create_string_utf8(env, "failed", INT_ARG_6, &result); + } + return result; +} + +static napi_value NAPI_Global_QueryAsset(napi_env env, napi_callback_info info) +{ + static const char *aliasContent = "demo_alias"; + Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; + Asset_Attr attr[] = { + {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, // 指定了关键资产别名,最多查询到一条满足条件的关键资产 + {.tag = ASSET_TAG_RETURN_TYPE, + .value.u32 = ASSET_RETURN_ALL}, // 此处表示需要返回关键资产的所有信息,即属性+明文 + }; + + Asset_ResultSet resultSet = {0}; + napi_value result; + int32_t ret = OH_Asset_Query(attr, sizeof(attr) / sizeof(attr[0]), &resultSet); + if (ret == ASSET_SUCCESS) { + // Parse the resultSet. + for (uint32_t i = 0; i < resultSet.count; i++) { + // Parse the secret: the data is secret->blob.data, the size is secret->blob.size. + Asset_Attr *secret = OH_Asset_ParseAttr(resultSet.results + i, ASSET_TAG_SECRET); + } + napi_create_string_utf8(env, "success", INT_ARG_7, &result); + } else { + napi_create_string_utf8(env, "failed", INT_ARG_6, &result); + } + OH_Asset_FreeResultSet(&resultSet); + return result; +} +static napi_value NAPI_Global_QueryAttributes(napi_env env, napi_callback_info info) +{ + static const char *aliasContent = "demo_alias"; + Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; + Asset_Attr attr[] = { + {.tag = ASSET_TAG_ALIAS, .value.blob = alias}, // 指定了关键资产别名,最多查询到一条满足条件的关键资产 + {.tag = ASSET_TAG_RETURN_TYPE, + .value.u32 = ASSET_RETURN_ATTRIBUTES}, // 此处表示仅返回关键资产属性,不包含关键资产明文 + }; + + Asset_ResultSet resultSet = {0}; + int32_t ret = OH_Asset_Query(attr, sizeof(attr) / sizeof(attr[0]), &resultSet); + napi_value result; + if (ret == ASSET_SUCCESS) { + // Parse the result. + for (uint32_t i = 0; i < resultSet.count; i++) { + // Parse the data label: the data is label->blob.data, the size is label->blob.size. + Asset_Attr *label = OH_Asset_ParseAttr(resultSet.results + i, ASSET_TAG_DATA_LABEL_NORMAL_1); + } + napi_create_string_utf8(env, "success", INT_ARG_7, &result); + } else { + napi_create_string_utf8(env, "failed", INT_ARG_6, &result); + } + OH_Asset_FreeResultSet(&resultSet); + return result; +} + +static napi_value NAPI_Global_BatchQuery(napi_env env, napi_callback_info info) +{ + static const char *labelContent = "demo_label"; + Asset_Blob label = {(uint32_t)(strlen(labelContent)), (uint8_t *)labelContent}; + static const char *aliasContent = "demo_alias"; + Asset_Blob alias = {(uint32_t)(strlen(aliasContent)), (uint8_t *)aliasContent}; + + Asset_Attr attr[] = { + {.tag = ASSET_TAG_RETURN_TYPE, .value.u32 = ASSET_RETURN_ATTRIBUTES}, + {.tag = ASSET_TAG_DATA_LABEL_NORMAL_1, .value.blob = label}, + {.tag = ASSET_TAG_RETURN_OFFSET, .value.u32 = 0}, + {.tag = ASSET_TAG_RETURN_LIMIT, .value.u32 = 1}, + {.tag = ASSET_TAG_RETURN_ORDERED_BY, .value.u32 = ASSET_TAG_DATA_LABEL_NORMAL_1}, + }; + + Asset_ResultSet resultSet = {0}; + int32_t ret = OH_Asset_Query(attr, sizeof(attr) / sizeof(attr[0]), &resultSet); + napi_value result; + if (ret == ASSET_SUCCESS) { + // Parse the result. + for (uint32_t i = 0; i < resultSet.count; i++) { + // Parse the data alias: the data is alias->blob.data, the size is alias->blob.size.. + Asset_Attr *alias = OH_Asset_ParseAttr(resultSet.results + i, ASSET_TAG_ALIAS); + } + napi_create_string_utf8(env, "success", INT_ARG_7, &result); + } else { + napi_create_string_utf8(env, "failed", INT_ARG_6, &result); + } + OH_Asset_FreeResultSet(&resultSet); + return result; +} +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"AddAsset", nullptr, NAPI_Global_AddAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"RemoveAsset", nullptr, RemoveAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"UpdateAsset", nullptr, NAPI_Global_UpdateAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"QueryAsset", nullptr, NAPI_Global_QueryAsset, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"QueryAttributes", nullptr, NAPI_Global_QueryAttributes, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"BatchQuery", nullptr, NAPI_Global_BatchQuery, 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 620010e4c8cdd684f94af38c1243373067265063..67a55cce53700314c3b977c7ba96b623714fa56a --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,26 +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. - */ - -export const AddAsset: () => string; - -export const RemoveAsset: () => string; - -export const UpdateAsset: () => string; - -export const QueryAsset: () => string; - -export const QueryAttributes: () => string; - +/* + * 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 AddAsset: () => string; + +export const RemoveAsset: () => string; + +export const UpdateAsset: () => string; + +export const QueryAsset: () => string; + +export const QueryAttributes: () => string; + export const BatchQuery: () => string; \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 8ed0bcf328ac07487191153b9f805a3d5f545e45..bf6003c3e12ed1a11575039b9ebfe19e5ab34ce3 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/ets/pages/Index.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'AssetStoreNdk'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Center) - Button('AddAsset') - .width('70%') - .onClick(() => { - hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.AddAsset()) // 新增 - this.message = 'AddAsset success'; - }) - Button('RemoveAsset') - .width('70%') - .onClick(() => { - hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.RemoveAsset()) // 删除 - this.message = 'RemoveAsset success'; - }) - Button('UpdateAsset') - .width('70%') - .onClick(() => { - hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.UpdateAsset()) //更新 - this.message = 'UpdateAsset success'; - }) - Button('QueryAsset') - .width('70%') - .onClick(() => { - hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.QueryAsset()) - this.message = 'QueryAsset success'; - }) - Button('QueryAttributes') - .width('70%') - .onClick(() => { - hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.QueryAttributes()) - this.message = 'QueryAttributes success'; - }) - Button('BatchQuery') - .width('70%') - .onClick(() => { - hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.BatchQuery()) // 更新前进行查询成功 更新后会失败 - this.message = 'BatchQuery success'; - }) - } - .height('100%') - .width('100%') - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - } +/* + * 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'; + +@Entry +@Component +struct Index { + @State message: string = 'AssetStoreNdk'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + Button('AddAsset') + .width('70%') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.AddAsset()) // 新增 + this.message = 'AddAsset success'; + }) + Button('RemoveAsset') + .width('70%') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.RemoveAsset()) // 删除 + this.message = 'RemoveAsset success'; + }) + Button('UpdateAsset') + .width('70%') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.UpdateAsset()) //更新 + this.message = 'UpdateAsset success'; + }) + Button('QueryAsset') + .width('70%') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.QueryAsset()) + this.message = 'QueryAsset success'; + }) + Button('QueryAttributes') + .width('70%') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.QueryAttributes()) + this.message = 'QueryAttributes success'; + }) + Button('BatchQuery') + .width('70%') + .onClick(() => { + hilog.info(0x0000, 'testTag', 'GenerateKey %{public}s', testNapi.BatchQuery()) // 更新前进行查询成功 更新后会失败 + this.message = 'BatchQuery success'; + }) + } + .height('100%') + .width('100%') + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + } } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/module.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/module.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/AssetStoreNdk.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/AssetStoreNdk.test.ets old mode 100755 new mode 100644 index a018f3333c99c5689223ad526df18542210a87c2..50f1d72df28ce2f30779af7d26df367bd3acddd5 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/AssetStoreNdk.test.ets +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/AssetStoreNdk.test.ets @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function assetStoreNdkTest() { - describe('assetStoreNdkTest', () => { - - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - it('testAssetStoreNdk001', 0, async () => { - console.info('uitest: testAssetStoreNdk001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AddAsset')); - const button2 = await driver.findComponent(ON.text('RemoveAsset')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AddAsset success')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RemoveAsset success')); - await button1.click(); - console.info('uitest: testAssetStoreNdk001 end'); - }) - - it('testAssetStoreNdk002', 0, async () => { - console.info('uitest: testAssetStoreNdk002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('BatchQuery')); - const button2 = await driver.findComponent(ON.text('UpdateAsset')); - const button3 = await driver.findComponent(ON.text('QueryAsset')); - const button4 = await driver.findComponent(ON.text('QueryAttributes')); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('BatchQuery success')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('UpdateAsset success')); - await button3.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('QueryAsset success')); - await button4.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('QueryAttributes success')); - console.info('uitest: testAssetStoreNdk002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function assetStoreNdkTest() { + describe('assetStoreNdkTest', () => { + + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + it('testAssetStoreNdk001', 0, async () => { + console.info('uitest: testAssetStoreNdk001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AddAsset')); + const button2 = await driver.findComponent(ON.text('RemoveAsset')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AddAsset success')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RemoveAsset success')); + await button1.click(); + console.info('uitest: testAssetStoreNdk001 end'); + }) + + it('testAssetStoreNdk002', 0, async () => { + console.info('uitest: testAssetStoreNdk002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('BatchQuery')); + const button2 = await driver.findComponent(ON.text('UpdateAsset')); + const button3 = await driver.findComponent(ON.text('QueryAsset')); + const button4 = await driver.findComponent(ON.text('QueryAttributes')); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('BatchQuery success')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('UpdateAsset success')); + await button3.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('QueryAsset success')); + await button4.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('QueryAttributes success')); + console.info('uitest: testAssetStoreNdk002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/entry/src/test/List.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/hvigor/hvigor-config.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/hvigorfile.ts b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/oh-package.json5 b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/oh-package.json5 +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/AssetStoreKit/AssetStoreNdk/ohosTest.md b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/ohosTest.md old mode 100755 new mode 100644 index 8ac0e7544a1f5698a9c326e4f46febee9eca3a71..e0aec39739f784731cc756a47e3041b0356baad0 --- a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/ohosTest.md +++ b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/ohosTest.md @@ -1,10 +1,10 @@ -# Asset Store Kit(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮新增关键资产 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | -| 点击按钮移除关键资产 | 成功拉起应用 | | 成功移除并输出日志 | 是 | Pass | +# Asset Store Kit(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮新增关键资产 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +| 点击按钮移除关键资产 | 成功拉起应用 | | 成功移除并输出日志 | 是 | Pass | | 点击按钮更新并查询关键资产 | 成功拉起应用 | | 成功更新查询并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/screenshots/AssetStoreNdk1.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/screenshots/AssetStoreNdk1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/screenshots/AssetStoreNdk2.png b/code/DocsSample/Security/AssetStoreKit/AssetStoreNdk/screenshots/AssetStoreNdk2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/app.json5 old mode 100755 new mode 100644 index bc63d611f3d5822090d79d3a92109fcaec781073..d62c80428d5dd830d69ca50f5a965ba31d01f674 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidance3des", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidance3des", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 97555a321d110e8942a3137f448f27053f67f32d..c9880ec1f7c47f15803905dfb649999fa94a426f --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidance3DES" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidance3DES" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/README.md old mode 100755 new mode 100644 index d5002e4966a0f36bb74f854427729c741ec58253..d111c6f8f48ce7f40b4b8b1eba104995e00ab093 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/README.md @@ -1,81 +1,81 @@ -# 使用3DES对称密钥(ECB模式)加解密 - -### 介绍 - -本示例主要展示了使用3DES对称密钥(ECB模式)加解密(ArkTS)的同步异步方法和C/C++场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用3DES对称密钥(ECB模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-3des-sym-encrypt-decrypt-ecb.md) -- [使用3DES对称密钥(ECB模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-3des-sym-encrypt-decrypt-ecb-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidance3DES.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── 3des_ecb_encryption_decryption.cpp - │ │ | ├── file.h - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用3DES对称密钥(ECB模式)加解密示例代码 - │ │ ├── 3des_ecb_encryption_decryption.ets - │ │ ├── 3des_ecb_encryption_decryption_asynchronous.ets - │ │ ├── 3des_ecb_encryption_decryption_synchronous.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidance3DES.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用3DES对称密钥(ECB模式)加解密 + +### 介绍 + +本示例主要展示了使用3DES对称密钥(ECB模式)加解密(ArkTS)的同步异步方法和C/C++场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用3DES对称密钥(ECB模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-3des-sym-encrypt-decrypt-ecb.md) +- [使用3DES对称密钥(ECB模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-3des-sym-encrypt-decrypt-ecb-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidance3DES.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── 3des_ecb_encryption_decryption.cpp + │ │ | ├── file.h + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用3DES对称密钥(ECB模式)加解密示例代码 + │ │ ├── 3des_ecb_encryption_decryption.ets + │ │ ├── 3des_ecb_encryption_decryption_asynchronous.ets + │ │ ├── 3des_ecb_encryption_decryption_synchronous.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidance3DES.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index ebfec4c614065f840772e14e06041bbe82137b9d..05757dad0a38771d9bbab2b2d546ed22222c0bb0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(EncryptionDecryptionGuidance3DESArkTs) - -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 types/project/3des_ecb_encryption_decryption.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(EncryptionDecryptionGuidance3DESArkTs) + +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 types/project/3des_ecb_encryption_decryption.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index d998ee2fc275bb4a2bfea3ec4c8a811356518991..075d3ed0a5322f5fa644a22c88dbc56e51d1c2c4 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/napi_init.cpp @@ -1,46 +1,46 @@ -/* - * 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 "types/project/file.h" - -static napi_value NAPI_Global_doTest3DesEcb(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTest3DesEcb(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"doTest3DesEcb", nullptr, NAPI_Global_doTest3DesEcb, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTest3DesEcb(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTest3DesEcb(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"doTest3DesEcb", nullptr, NAPI_Global_doTest3DesEcb, 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index eca27a27b1899451ca2d383825f32888d91554f4..feacf528f99f276a68b23dae222d1e02e4dd0920 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 doTest3DesEcb: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp old mode 100755 new mode 100644 index 5fd01b3fc62be76efd146091f68376fe5d396b4f..3866acd6015e522aecbd03e5c1e3a84ce6e4b795 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/3des_ecb_encryption_decryption.cpp @@ -1,77 +1,77 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTest3DesEcb() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - char *plainText = const_cast("this is test!"); - Crypto_DataBlob input = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("3DES192", &genCtx); // 随机生成对称密钥 - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_Create(¶ms); // 创建参数 - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Create("3DES192|ECB|PKCS7", &encCtx); // 加密操作 - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, &input, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Create("3DES192|ECB|PKCS7", &decCtx); // 解密操作 - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTest3DesEcb() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + char *plainText = const_cast("this is test!"); + Crypto_DataBlob input = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("3DES192", &genCtx); // 随机生成对称密钥 + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_Create(¶ms); // 创建参数 + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Create("3DES192|ECB|PKCS7", &encCtx); // 加密操作 + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, &input, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Create("3DES192|ECB|PKCS7", &decCtx); // 解密操作 + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index ef588998c3a34066b1178f1374e88f1215a946ba..7e388d978e363aa72fa5ad00ae4ac452b562cd51 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/cpp/types/project/file.h @@ -1,23 +1,23 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" - -OH_Crypto_ErrCode doTest3DesEcb(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" + +OH_Crypto_ErrCode doTest3DesEcb(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption.ets old mode 100755 new mode 100644 index 28b1e6e0944e2f4d1d57732899ba01f459f7d053..9b26168d82175c649c701a588792bd4283041962 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption.ets @@ -1,36 +1,36 @@ -/* - * 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 { - @State message: string = 'Encryption Decryption Guidance 3DES'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_3des_ecb')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doTest3DesEcb(); - this.message = 'Call Success Result:' + ret.toString(); - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { + @State message: string = 'Encryption Decryption Guidance 3DES'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_3des_ecb')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doTest3DesEcb(); + this.message = 'Call Success Result:' + ret.toString(); + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index b1dc75ede5e4648634c9d5cbeff4678ea76f98bd..d7ebac457bda00fe918197f25ee345c654988b88 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_asynchronous.ets @@ -1,82 +1,82 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); - let encryptData = await cipher.doFinal(plainText); - return encryptData; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let symGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); - let symKey = await symGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function main() { - let keyData = - new Uint8Array([238, 249, 61, 55, 128, 220, 183, 224, 139, 253, 248, 239, 239, 41, 71, 25, 235, 206, 230, 162, 249, - 27, 234, 114]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance 3DES ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_3des_ecb_asynchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = '3DES_ECBSuccess'; - } catch { - this.message = '3DES_ECBFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); + let encryptData = await cipher.doFinal(plainText); + return encryptData; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let symGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); + let symKey = await symGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function main() { + let keyData = + new Uint8Array([238, 249, 61, 55, 128, 220, 183, 224, 139, 253, 248, 239, 239, 41, 71, 25, 235, 206, 230, 162, 249, + 27, 234, 114]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance 3DES ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_3des_ecb_asynchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = '3DES_ECBSuccess'; + } catch { + this.message = '3DES_ECBFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index c124ad89aedd445263347d5953b8cbd891f7c7fb..09734ef376056ed362f8ca2d5fc44989db14e990 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/3des_ecb_encryption_decryption_synchronous.ets @@ -1,82 +1,82 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); - let encryptData = cipher.doFinalSync(plainText); - return encryptData; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let symGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); - let symKey = symGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = - new Uint8Array([238, 249, 61, 55, 128, 220, 183, 224, 139, 253, 248, 239, 239, 41, 71, 25, 235, 206, 230, 162, 249, - 27, 234, 114]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance 3DES ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_3des_ecb_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = '3DES_ECBSuccess'; - } catch { - this.message = '3DES_ECBFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); + let encryptData = cipher.doFinalSync(plainText); + return encryptData; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('3DES192|ECB|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let symGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); + let symKey = symGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + let keyData = + new Uint8Array([238, 249, 61, 55, 128, 220, 183, 224, 139, 253, 248, 239, 239, 41, 71, 25, 235, 206, 230, 162, 249, + 27, 234, 114]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance 3DES ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_3des_ecb_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = '3DES_ECBSuccess'; + } catch { + this.message = '3DES_ECBFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/mock/mock-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DES.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DES.test.ets old mode 100755 new mode 100644 index 5147c7202c4a49daf1be2743978e522eca30bfb6..df2a2c7b595a53e80d8fbfdf609ee9b7b539cd44 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DES.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DES.test.ets @@ -1,98 +1,98 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidance3DESTest() { - describe('encryptionDecryptionGuidance3DESTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidance3DES001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DES001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('3des_ecb_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call 3DES_ECB Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('3DES_ECBSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DES001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidance3DES002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DES002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('3des_ecb_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call 3DES_ECB Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('3DES_ECBSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DES002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用3DES对称密钥(ECB模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidance3DES003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DES003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('3des_ecb_encryption_decryption')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call 3DES_ECB')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success Result:0')); - console.info('uitest: testEncryptionDecryptionGuidance3DES003 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidance3DESTest() { + describe('encryptionDecryptionGuidance3DESTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidance3DES001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DES001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('3des_ecb_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call 3DES_ECB Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('3DES_ECBSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DES001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidance3DES002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DES002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('3des_ecb_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call 3DES_ECB Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('3DES_ECBSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DES002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用3DES对称密钥(ECB模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidance3DES003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DES003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('3des_ecb_encryption_decryption')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call 3DES_ECB')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success Result:0')); + console.info('uitest: testEncryptionDecryptionGuidance3DES003 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/ohosTest.md old mode 100755 new mode 100644 index d03d8f9d22e40275fee4cde0eb5bd964d70558b6..c603d0ffe7f41d3cafe796f209fa330cbceb7da3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/ohosTest.md @@ -1,10 +1,10 @@ -# 使用3DES对称密钥(ECB模式)加解密测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用3DES对称密钥(ECB模式)加解密测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用3DES对称密钥(ECB模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用3DES对称密钥(ECB模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/screenshots/EncryptionDecryptionGuidance3DES1.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/screenshots/EncryptionDecryptionGuidance3DES1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/screenshots/EncryptionDecryptionGuidance3DES2.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidance3DES/screenshots/EncryptionDecryptionGuidance3DES2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/app.json5 old mode 100755 new mode 100644 index 2aa8298fa55120c946efd32f1261a952118235e6..153d7314e8a8ce2c07280135ee43e3fcad879b26 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidanceaes", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidanceaes", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 15f59c2fc0c8e44c6b041cb4f7bab0d1a4d88789..41dc2dbd559230d97f136fc54001bdedd375946b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidanceAes" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidanceAes" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/README.md old mode 100755 new mode 100644 index f31966a89e4eb7ddd1e398c52ed73c0401e82881..35cf64d81cdbc18443616bb24ac21e991c1d3945 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/README.md @@ -1,85 +1,85 @@ -# 使用AES对称密钥加解密(C/C++) - -### 介绍 - -本示例主要展示了使用AES对称密钥(C/C++)GCM模式、CCM模式、CBC模式、ECB模式以及GCM模式分段加解密场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用AES对称密钥(GCM模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm-ndk.md) -- [使用AES对称密钥(CCM模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ccm-ndk.md) -- [使用AES对称密钥(CBC模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-cbc-ndk.md) -- [使用AES对称密钥(ECB模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ecb-ndk.md) -- [使用AES对称密钥(GCM模式)分段加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm-by-segment-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidanceAes.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── aes_cbc_encryption_decryption.cpp - │ │ | ├── aes_ccm_encryption_decryption.cpp - │ │ | ├── aes_ecb_encryption_decryption.cpp - │ │ | ├── aes_gcm_encryption_decryption.cpp - │ │ | ├── aes_gcm_segment_encryption_decryption.cpp - │ │ | ├── file.h - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用AES对称密钥加解密(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidanceAes.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用AES对称密钥加解密(C/C++) + +### 介绍 + +本示例主要展示了使用AES对称密钥(C/C++)GCM模式、CCM模式、CBC模式、ECB模式以及GCM模式分段加解密场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用AES对称密钥(GCM模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm-ndk.md) +- [使用AES对称密钥(CCM模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ccm-ndk.md) +- [使用AES对称密钥(CBC模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-cbc-ndk.md) +- [使用AES对称密钥(ECB模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ecb-ndk.md) +- [使用AES对称密钥(GCM模式)分段加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm-by-segment-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidanceAes.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── aes_cbc_encryption_decryption.cpp + │ │ | ├── aes_ccm_encryption_decryption.cpp + │ │ | ├── aes_ecb_encryption_decryption.cpp + │ │ | ├── aes_gcm_encryption_decryption.cpp + │ │ | ├── aes_gcm_segment_encryption_decryption.cpp + │ │ | ├── file.h + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用AES对称密钥加解密(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidanceAes.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index a3c5ee621ee2ffc20cea5aeadbad16dcef71da24..6123b8267aa92ec425cfca36fe25ca0a83667c4b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(EncryptionDecryptionGuidanceAes) - -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 types/project/aes_gcm_encryption_decryption.cpp types/project/aes_ccm_encryption_decryption.cpp types/project/aes_cbc_encryption_decryption.cpp types/project/aes_ecb_encryption_decryption.cpp types/project/aes_gcm_segment_encryption_decryption.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(EncryptionDecryptionGuidanceAes) + +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 types/project/aes_gcm_encryption_decryption.cpp types/project/aes_ccm_encryption_decryption.cpp types/project/aes_cbc_encryption_decryption.cpp types/project/aes_ecb_encryption_decryption.cpp types/project/aes_gcm_segment_encryption_decryption.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index ed2270c009c72b5885fb192ff31b7255b5584b4d..835ac96773ff547d9ff1e3e40b4a8a64145b2c1e --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/napi_init.cpp @@ -1,78 +1,78 @@ -/* - * 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 "types/project/file.h" - -static napi_value NAPI_Global_doTestAesGcm(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestAesGcm(), &ret); - return ret; -} - -static napi_value NAPI_Global_doTestAesCcm(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestAesCcm(), &ret); - return ret; -} - -static napi_value NAPI_Global_doTestAesCbc(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestAesCbc(), &ret); - return ret; -} - -static napi_value NAPI_Global_doTestAesEcb(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestAesEcb(), &ret); - return ret; -} - -static napi_value NAPI_Global_testAesGcmSeg(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestAesGcmSeg(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"testAesGcm", nullptr, NAPI_Global_doTestAesGcm, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testAesCcm", nullptr, NAPI_Global_doTestAesCcm, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testAesCbc", nullptr, NAPI_Global_doTestAesCbc, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testAesEcb", nullptr, NAPI_Global_doTestAesEcb, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testAesGcmSeg", nullptr, NAPI_Global_testAesGcmSeg, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTestAesGcm(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestAesGcm(), &ret); + return ret; +} + +static napi_value NAPI_Global_doTestAesCcm(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestAesCcm(), &ret); + return ret; +} + +static napi_value NAPI_Global_doTestAesCbc(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestAesCbc(), &ret); + return ret; +} + +static napi_value NAPI_Global_doTestAesEcb(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestAesEcb(), &ret); + return ret; +} + +static napi_value NAPI_Global_testAesGcmSeg(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestAesGcmSeg(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"testAesGcm", nullptr, NAPI_Global_doTestAesGcm, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testAesCcm", nullptr, NAPI_Global_doTestAesCcm, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testAesCbc", nullptr, NAPI_Global_doTestAesCbc, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testAesEcb", nullptr, NAPI_Global_doTestAesEcb, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testAesGcmSeg", nullptr, NAPI_Global_testAesGcmSeg, 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index e50d1a04376564dc63bca5c8709da7d81aaf346e..12eaa9255666c3c51a65cdc9c597f886900da869 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,24 +1,24 @@ -/* - * 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 testAesGcm: () => number; - -export const testAesCcm: () => number; - -export const testAesCbc: () => number; - -export const testAesEcb: () => number; - -export const testAesGcmSeg: () => number; +/* + * 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 testAesGcm: () => number; + +export const testAesCcm: () => number; + +export const testAesCbc: () => number; + +export const testAesEcb: () => number; + +export const testAesGcmSeg: () => number; diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_cbc_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_cbc_encryption_decryption.cpp old mode 100755 new mode 100644 index b3a4b8f0b282575f273b4748e21c6abebb0e8ce9..40f2574d03d685656527f19d37f5aaa8bb02e440 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_cbc_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_cbc_encryption_decryption.cpp @@ -1,91 +1,91 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestAesCbc() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - char *plainText = const_cast("this is test!"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - uint8_t iv[16] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4, 3, 1, 0, 10}; // iv使用安全随机数生成 - Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; - // 生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("AES128|CBC|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - ret = OH_CryptoSymCipher_Create("AES128|CBC|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestAesCbc() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + char *plainText = const_cast("this is test!"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + uint8_t iv[16] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4, 3, 1, 0, 10}; // iv使用安全随机数生成 + Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; + // 生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("AES128|CBC|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + ret = OH_CryptoSymCipher_Create("AES128|CBC|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ccm_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ccm_encryption_decryption.cpp old mode 100755 new mode 100644 index 90770face32c51ae39b40d0de495399010d5015d..2aa3f2a32b29bf037b50b4af22e9a5c56a0efb6c --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ccm_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ccm_encryption_decryption.cpp @@ -1,116 +1,116 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestAesCcm() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - - uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint8_t tag[12] = {0}; - uint8_t iv[7] = {1, 2, 4, 12, 3, 4, 2}; // iv使用安全随机数生成 - Crypto_DataBlob ivData = {.data = iv, .len = sizeof(iv)}; - Crypto_DataBlob aadData = {.data = aad, .len = sizeof(aad)}; - Crypto_DataBlob tagData = {.data = tag, .len = sizeof(tag)}; - Crypto_DataBlob tagOutPut = {.data = nullptr, .len = 0}; - char *plainText = const_cast("this is test!"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - // 生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("AES128|CCM", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tagOutPut); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - ret = OH_CryptoSymCipher_Create("AES128|CCM", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagOutPut); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - OH_Crypto_FreeDataBlob(&tagOutPut); - return ret; -} - +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestAesCcm() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + + uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + uint8_t tag[12] = {0}; + uint8_t iv[7] = {1, 2, 4, 12, 3, 4, 2}; // iv使用安全随机数生成 + Crypto_DataBlob ivData = {.data = iv, .len = sizeof(iv)}; + Crypto_DataBlob aadData = {.data = aad, .len = sizeof(aad)}; + Crypto_DataBlob tagData = {.data = tag, .len = sizeof(tag)}; + Crypto_DataBlob tagOutPut = {.data = nullptr, .len = 0}; + char *plainText = const_cast("this is test!"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + // 生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("AES128|CCM", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tagOutPut); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + ret = OH_CryptoSymCipher_Create("AES128|CCM", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagOutPut); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + OH_Crypto_FreeDataBlob(&tagOutPut); + return ret; +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ecb_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ecb_encryption_decryption.cpp old mode 100755 new mode 100644 index a7bee2d05286a19c44bb98fb964848b217ff5d66..aa1ae55ab37ea2df30802dec9c0e610415b3ee46 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ecb_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_ecb_encryption_decryption.cpp @@ -1,85 +1,85 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestAesEcb() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - char *plainText = const_cast("this is test"); - Crypto_DataBlob input = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - - // 随机生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - // 创建参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密操作 - ret = OH_CryptoSymCipher_Create("AES128|ECB|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, &input, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密操作 - ret = OH_CryptoSymCipher_Create("AES128|ECB|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestAesEcb() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + char *plainText = const_cast("this is test"); + Crypto_DataBlob input = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + + // 随机生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + // 创建参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密操作 + ret = OH_CryptoSymCipher_Create("AES128|ECB|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, &input, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密操作 + ret = OH_CryptoSymCipher_Create("AES128|ECB|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_encryption_decryption.cpp old mode 100755 new mode 100644 index fde87a55c68ce4d8f7cc809935dd2a305bd9fbde..4b7b851ef773efd307ade5c3c81b27acd76ce6cd --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_encryption_decryption.cpp @@ -1,116 +1,116 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestAesGcm() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - - uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint8_t tag[16] = {0}; - uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 - Crypto_DataBlob ivData = {.data = iv, .len = sizeof(iv)}; - Crypto_DataBlob aadData = {.data = aad, .len = sizeof(aad)}; - Crypto_DataBlob tagData = {.data = tag, .len = sizeof(tag)}; - Crypto_DataBlob tagOutPut = {.data = nullptr, .len = 0}; - char *plainText = const_cast("this is test!"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - - // 生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tagOutPut); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagOutPut); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - OH_Crypto_FreeDataBlob(&tagOutPut); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestAesGcm() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + + uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + uint8_t tag[16] = {0}; + uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 + Crypto_DataBlob ivData = {.data = iv, .len = sizeof(iv)}; + Crypto_DataBlob aadData = {.data = aad, .len = sizeof(aad)}; + Crypto_DataBlob tagData = {.data = tag, .len = sizeof(tag)}; + Crypto_DataBlob tagOutPut = {.data = nullptr, .len = 0}; + char *plainText = const_cast("this is test!"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + + // 生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tagOutPut); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagOutPut); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + OH_Crypto_FreeDataBlob(&tagOutPut); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_segment_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_segment_encryption_decryption.cpp old mode 100755 new mode 100644 index 75dc5c6545122830085cd56565a56ef88c03b329..033fc7ba28e4fcdde3010d09faab2c8ddd9e5e4c --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_segment_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/aes_gcm_segment_encryption_decryption.cpp @@ -1,145 +1,145 @@ -/* - * 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 -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include "file.h" - -#define OH_CRYPTO_GCM_TAG_LEN 16 -#define OH_CRYPTO_MAX_TEST_DATA_LEN 128 -OH_Crypto_ErrCode doTestAesGcmSeg() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - - char *plainText = const_cast("aaaaa.....bbbbb.....ccccc.....ddddd.....eee"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - - uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint8_t tagArr[16] = {0}; - uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 - Crypto_DataBlob tag = {.data = nullptr, .len = 0}; - Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; - Crypto_DataBlob aadBlob = {.data = aad, .len = sizeof(aad)}; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob tagInit = {.data = tagArr, .len = sizeof(tagArr)}; - int32_t cipherLen = 0; - int blockSize = 20; - int32_t randomLen = strlen(plainText); - int cnt = randomLen / blockSize; - int rem = randomLen % blockSize; - uint8_t cipherText[OH_CRYPTO_MAX_TEST_DATA_LEN] = {0}; - Crypto_DataBlob cipherBlob; - - // 生成密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadBlob); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagInit); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - for (int i = 0; i < cnt; i++) { - msgBlob.len = blockSize; - ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - msgBlob.data += blockSize; - memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); - cipherLen += outUpdate.len; - } - if (rem > 0) { - msgBlob.len = rem; - ret = OH_CryptoSymCipher_Update(encCtx, (Crypto_DataBlob *)&msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); - cipherLen += outUpdate.len; - } - ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tag); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - cipherBlob = {.data = reinterpret_cast(cipherText), .len = (size_t)cipherLen}; - msgBlob.data -= strlen(plainText) - rem; - msgBlob.len = strlen(plainText); - ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tag); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &cipherBlob, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&tag); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; -} - +/* + * 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 +#include "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include "file.h" + +#define OH_CRYPTO_GCM_TAG_LEN 16 +#define OH_CRYPTO_MAX_TEST_DATA_LEN 128 +OH_Crypto_ErrCode doTestAesGcmSeg() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + + char *plainText = const_cast("aaaaa.....bbbbb.....ccccc.....ddddd.....eee"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + + uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + uint8_t tagArr[16] = {0}; + uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 + Crypto_DataBlob tag = {.data = nullptr, .len = 0}; + Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; + Crypto_DataBlob aadBlob = {.data = aad, .len = sizeof(aad)}; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob tagInit = {.data = tagArr, .len = sizeof(tagArr)}; + int32_t cipherLen = 0; + int blockSize = 20; + int32_t randomLen = strlen(plainText); + int cnt = randomLen / blockSize; + int rem = randomLen % blockSize; + uint8_t cipherText[OH_CRYPTO_MAX_TEST_DATA_LEN] = {0}; + Crypto_DataBlob cipherBlob; + + // 生成密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadBlob); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagInit); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + for (int i = 0; i < cnt; i++) { + msgBlob.len = blockSize; + ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + msgBlob.data += blockSize; + memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); + cipherLen += outUpdate.len; + } + if (rem > 0) { + msgBlob.len = rem; + ret = OH_CryptoSymCipher_Update(encCtx, (Crypto_DataBlob *)&msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); + cipherLen += outUpdate.len; + } + ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tag); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + cipherBlob = {.data = reinterpret_cast(cipherText), .len = (size_t)cipherLen}; + msgBlob.data -= strlen(plainText) - rem; + msgBlob.len = strlen(plainText); + ret = OH_CryptoSymCipher_Create("AES128|GCM|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tag); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &cipherBlob, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&tag); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index e2bfb60be69bf46a2c1e31bfa67f15854bec372c..0b8939ca3dc36757e475b979f6f4a41a4e2b5c93 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/cpp/types/project/file.h @@ -1,26 +1,26 @@ -#ifndef ENCRYPTIONDECRYPTIONGUIDANCEAES_FILE_H -#define ENCRYPTIONDECRYPTIONGUIDANCEAES_FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestAesGcm(); -OH_Crypto_ErrCode doTestAesCcm(); -OH_Crypto_ErrCode doTestAesCbc(); -OH_Crypto_ErrCode doTestAesEcb(); -OH_Crypto_ErrCode doTestAesGcmSeg(); - +#ifndef ENCRYPTIONDECRYPTIONGUIDANCEAES_FILE_H +#define ENCRYPTIONDECRYPTIONGUIDANCEAES_FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestAesGcm(); +OH_Crypto_ErrCode doTestAesCcm(); +OH_Crypto_ErrCode doTestAesCbc(); +OH_Crypto_ErrCode doTestAesEcb(); +OH_Crypto_ErrCode doTestAesGcmSeg(); + #endif //ENCRYPTIONDECRYPTIONGUIDANCEAES_FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index d096ce63dbd13192d717a44c3867d4d3be20cd0a..97b84c02d1377c86115b2852a4974f9b5392ca8e --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/ets/pages/Index.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'EncryptionDecryptionGuidanceAes'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(24) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_gcm')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testAesGcm(); - this.message = 'AES_GCMSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_aes_ccm')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testAesCcm(); - this.message = 'AES_CCMSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_aes_cbc')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testAesCbc(); - this.message = 'AES_CBCSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_aes_ecb')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testAesEcb(); - this.message = 'AES_ECBSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_aes_gcm_segment')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testAesEcb(); - this.message = 'AES_GCM_SegmentSuccess Result:' + ret.toString(); - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { + @State message: string = 'EncryptionDecryptionGuidanceAes'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(24) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_gcm')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testAesGcm(); + this.message = 'AES_GCMSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_aes_ccm')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testAesCcm(); + this.message = 'AES_CCMSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_aes_cbc')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testAesCbc(); + this.message = 'AES_CBCSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_aes_ecb')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testAesEcb(); + this.message = 'AES_ECBSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_aes_gcm_segment')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testAesEcb(); + this.message = 'AES_GCM_SegmentSuccess Result:' + ret.toString(); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAes.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAes.test.ets old mode 100755 new mode 100644 index 698d631a89bfd81e304557684f4a377af815b22d..5d9bff15da9e807bb4e3aec246dd8e3dbe15b49f --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAes.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAes.test.ets @@ -1,114 +1,114 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidanceAesTest() { - describe('EncryptionDecryptionGuidanceAesTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用AES对称密钥(GCM模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceAes001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call AES_GCM')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_GCMSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes001 end'); - }) - - /** - * 点击按钮,使用AES对称密钥(CCM模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceAes002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call AES_CCM')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_CCMSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes002 end'); - }) - - /** - * 点击按钮,使用AES对称密钥(CBC模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceAes003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call AES_CBC')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_CBCSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes003 end'); - }) - - /** - * 点击按钮,使用AES对称密钥(ECB模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceAes004', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call AES_ECB')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_ECBSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes004 end'); - }) - - /** - * 点击按钮,使用AES对称密钥(GCM模式)分段加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceAes005', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call AES_GCM_Segment')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_GCM_SegmentSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes005 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidanceAesTest() { + describe('EncryptionDecryptionGuidanceAesTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用AES对称密钥(GCM模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceAes001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call AES_GCM')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_GCMSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes001 end'); + }) + + /** + * 点击按钮,使用AES对称密钥(CCM模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceAes002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call AES_CCM')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_CCMSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes002 end'); + }) + + /** + * 点击按钮,使用AES对称密钥(CBC模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceAes003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call AES_CBC')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_CBCSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes003 end'); + }) + + /** + * 点击按钮,使用AES对称密钥(ECB模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceAes004', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call AES_ECB')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_ECBSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes004 end'); + }) + + /** + * 点击按钮,使用AES对称密钥(GCM模式)分段加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceAes005', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call AES_GCM_Segment')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_GCM_SegmentSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes005 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/ohosTest.md old mode 100755 new mode 100644 index 6149d9d589704459d788b6a57330fa4dd979921b..8415a3609c3dc791d0ef027b891cfe622f53ccd5 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/ohosTest.md @@ -1,12 +1,12 @@ -# 使用AES对称密钥加解密(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用AES对称密钥(GCM模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(CCM模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(CBC模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(ECB模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用AES对称密钥加解密(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用AES对称密钥(GCM模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(CCM模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(CBC模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(ECB模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用AES对称密钥(GCM模式)分段加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/screenshots/EncryptionDecryptionGuidanceAes1.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/screenshots/EncryptionDecryptionGuidanceAes1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/screenshots/EncryptionDecryptionGuidanceAes2.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAes/screenshots/EncryptionDecryptionGuidanceAes2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/app.json5 old mode 100755 new mode 100644 index c88fd0998443f96bf7134f813f17b672413f41de..f6ae8fe6054272263ccae98ee296eca6ca23341d --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidanceaesarkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidanceaesarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 90315fb34a796760bd172bd05a93c5dff0f04d28..96fc25d01b6383cbebb7640bd61eadbac364ea90 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidanceAesArkTs" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidanceAesArkTs" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/README.md old mode 100755 new mode 100644 index 636ba18456f3d1b34c2d7a70c051b8cdc2eed2bc..92ed5818cc63c5541913a752bec6d02ad71b2a83 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/README.md @@ -1,86 +1,86 @@ -# 使用AES对称密钥加解密(ArkTS) - -### 介绍 - -本示例主要展示了使用AES对称密钥不同模式加解密(ArkTS)的同步异步方法和C/C++场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用AES对称密钥(GCM模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm.md) -- [使用AES对称密钥(CCM模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ccm.md) -- [使用AES对称密钥(CBC模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-cbc.md) -- [使用AES对称密钥(ECB模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ecb.md) -- [使用AES对称密钥(GCM模式)分段加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm-by-segment.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidanceAesArkTs.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── aes_cbc_encryption_decryption - │ │ | ├── aes_cbc_encryption_decryption_asynchronous.ets - │ │ | ├── aes_cbc_encryption_decryption_synchronous.ets - │ │ ├── aes_ccm_encryption_decryption - │ │ | ├── aes_ccm_encryption_decryption_asynchronous.ets - │ │ | ├── aes_ccm_encryption_decryption_synchronous.ets - │ │ ├── aes_ecb_encryption_decryption - │ │ | ├── aes_ecb_encryption_decryption_asynchronous.ets - │ │ | ├── aes_ecb_encryption_decryption_synchronous.ets - │ │ ├── aes_gcm_encryption_decryption - │ │ | ├── aes_gcm_encryption_decryption_asynchronous.ets - │ │ | ├── aes_gcm_encryption_decryption_synchronous.ets - │ │ ├── aes_gcm_seg_encryption_decryption - │ │ | ├── aes_gcm_seg_encryption_decryption_asynchronous.ets - │ │ | ├── aes_gcm_seg_encryption_decryption_synchronous.ets - │ │ ├── Index.ets // 使用AES对称密钥加解密(ArkTS)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidanceAesArkTs.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用AES对称密钥加解密(ArkTS) + +### 介绍 + +本示例主要展示了使用AES对称密钥不同模式加解密(ArkTS)的同步异步方法和C/C++场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用AES对称密钥(GCM模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm.md) +- [使用AES对称密钥(CCM模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ccm.md) +- [使用AES对称密钥(CBC模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-cbc.md) +- [使用AES对称密钥(ECB模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-ecb.md) +- [使用AES对称密钥(GCM模式)分段加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-aes-sym-encrypt-decrypt-gcm-by-segment.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidanceAesArkTs.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── aes_cbc_encryption_decryption + │ │ | ├── aes_cbc_encryption_decryption_asynchronous.ets + │ │ | ├── aes_cbc_encryption_decryption_synchronous.ets + │ │ ├── aes_ccm_encryption_decryption + │ │ | ├── aes_ccm_encryption_decryption_asynchronous.ets + │ │ | ├── aes_ccm_encryption_decryption_synchronous.ets + │ │ ├── aes_ecb_encryption_decryption + │ │ | ├── aes_ecb_encryption_decryption_asynchronous.ets + │ │ | ├── aes_ecb_encryption_decryption_synchronous.ets + │ │ ├── aes_gcm_encryption_decryption + │ │ | ├── aes_gcm_encryption_decryption_asynchronous.ets + │ │ | ├── aes_gcm_encryption_decryption_synchronous.ets + │ │ ├── aes_gcm_seg_encryption_decryption + │ │ | ├── aes_gcm_seg_encryption_decryption_asynchronous.ets + │ │ | ├── aes_gcm_seg_encryption_decryption_synchronous.ets + │ │ ├── Index.ets // 使用AES对称密钥加解密(ArkTS)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidanceAesArkTs.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index ddffbf53eb8ccb2ed5be1aa69e76bc49d5aca0d9..e4b7c206d7003a3b7424aba4c39cd1ec7dae68f2 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_asynchronous.ets @@ -1,101 +1,101 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genIvParamsSpec() { - let ivBlob = generateRandom(16); - let ivParamsSpec: cryptoFramework.IvParamsSpec = { - algName: 'IvParamsSpec', - iv: ivBlob - }; - return ivParamsSpec; -} - -let iv = genIvParamsSpec(); - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|CBC|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); - let cipherData = await cipher.doFinal(plainText); - return cipherData; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|CBC|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function aesCBC() { - try { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } - } catch (error) { - console.error(`AES CBC “${error}“, error code: ${error.code}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_cbc_asynchronous')) - .width('70%') - .onClick(() => { - try { - aesCBC(); - this.message = 'AES_CBCAsynchronousSuccess'; - } catch { - this.message = 'AES_CBCAsynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genIvParamsSpec() { + let ivBlob = generateRandom(16); + let ivParamsSpec: cryptoFramework.IvParamsSpec = { + algName: 'IvParamsSpec', + iv: ivBlob + }; + return ivParamsSpec; +} + +let iv = genIvParamsSpec(); + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|CBC|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); + let cipherData = await cipher.doFinal(plainText); + return cipherData; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|CBC|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = await aesGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function aesCBC() { + try { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } + } catch (error) { + console.error(`AES CBC “${error}“, error code: ${error.code}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_cbc_asynchronous')) + .width('70%') + .onClick(() => { + try { + aesCBC(); + this.message = 'AES_CBCAsynchronousSuccess'; + } catch { + this.message = 'AES_CBCAsynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index 623ea3bc292157f99431f935db82ca6201c9c851..04dca23e8066ad9a6e3195c71a6d80fae42810bd --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_cbc_encryption_decryption/aes_cbc_encryption_decryption_synchronous.ets @@ -1,101 +1,101 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genIvParamsSpec() { - let ivBlob = generateRandom(16); - let ivParamsSpec: cryptoFramework.IvParamsSpec = { - algName: 'IvParamsSpec', - iv: ivBlob - }; - return ivParamsSpec; -} - -let iv = genIvParamsSpec(); - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|CBC|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); - let cipherData = cipher.doFinalSync(plainText); - return cipherData; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|CBC|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - try { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } - } catch (error) { - console.error(`AES CBC “${error}“, error code: ${error.code}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_cbc_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_CBCSynchronousSuccess'; - } catch { - this.message = 'AES_CBCSynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genIvParamsSpec() { + let ivBlob = generateRandom(16); + let ivParamsSpec: cryptoFramework.IvParamsSpec = { + algName: 'IvParamsSpec', + iv: ivBlob + }; + return ivParamsSpec; +} + +let iv = genIvParamsSpec(); + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|CBC|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); + let cipherData = cipher.doFinalSync(plainText); + return cipherData; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|CBC|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = aesGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + try { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } + } catch (error) { + console.error(`AES CBC “${error}“, error code: ${error.code}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_cbc_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'AES_CBCSynchronousSuccess'; + } catch { + this.message = 'AES_CBCSynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index 71b8a3be88bb1f312c54ed7bd645655ba3d17b6a..361344727882d55882c48c2f69b8233ba2518994 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_asynchronous.ets @@ -1,103 +1,103 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function genCcmParamsSpec() { - let rand: cryptoFramework.Random = cryptoFramework.createRandom(); - let ivBlob: cryptoFramework.DataBlob = rand.generateRandomSync(7); - let aadBlob: cryptoFramework.DataBlob = rand.generateRandomSync(8); - let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 12 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; - // CCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - let ccmParamsSpec: cryptoFramework.CcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'CcmParamsSpec' - }; - return ccmParamsSpec; -} - -let ccmParams = genCcmParamsSpec(); - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|CCM'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, ccmParams); - let encryptUpdate = await cipher.update(plainText); - // ccm模式加密doFinal时传入空,获得tag数据,并更新至ccmParams对象中。 - ccmParams.authTag = await cipher.doFinal(null); - return encryptUpdate; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|CCM'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, ccmParams); - let decryptUpdate = await decoder.doFinal(cipherText); - return decryptUpdate; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_ccm_asynchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_CCMAsynchronousSuccess'; - } catch { - this.message = 'AES_CCMAsynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function genCcmParamsSpec() { + let rand: cryptoFramework.Random = cryptoFramework.createRandom(); + let ivBlob: cryptoFramework.DataBlob = rand.generateRandomSync(7); + let aadBlob: cryptoFramework.DataBlob = rand.generateRandomSync(8); + let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 12 bytes + let dataTag = new Uint8Array(arr); + let tagBlob: cryptoFramework.DataBlob = { + data: dataTag + }; + // CCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + let ccmParamsSpec: cryptoFramework.CcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algName: 'CcmParamsSpec' + }; + return ccmParamsSpec; +} + +let ccmParams = genCcmParamsSpec(); + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|CCM'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, ccmParams); + let encryptUpdate = await cipher.update(plainText); + // ccm模式加密doFinal时传入空,获得tag数据,并更新至ccmParams对象中。 + ccmParams.authTag = await cipher.doFinal(null); + return encryptUpdate; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|CCM'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, ccmParams); + let decryptUpdate = await decoder.doFinal(cipherText); + return decryptUpdate; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = await aesGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function main() { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_ccm_asynchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'AES_CCMAsynchronousSuccess'; + } catch { + this.message = 'AES_CCMAsynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index 3f37aebd977f5bd3ce560966d1877d2f5c527f71..f52c1d682dcc38c7e4310289ba5daa83cc5d0b82 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ccm_encryption_decryption/aes_ccm_encryption_decryption_synchronous.ets @@ -1,103 +1,103 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function genCcmParamsSpec() { - let rand: cryptoFramework.Random = cryptoFramework.createRandom(); - let ivBlob: cryptoFramework.DataBlob = rand.generateRandomSync(7); - let aadBlob: cryptoFramework.DataBlob = rand.generateRandomSync(8); - let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 12 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; - // CCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - let ccmParamsSpec: cryptoFramework.CcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'CcmParamsSpec' - }; - return ccmParamsSpec; -} - -let ccmParams = genCcmParamsSpec(); - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|CCM'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, ccmParams); - let encryptUpdate = cipher.updateSync(plainText); - // ccm模式加密doFinal时传入空,获得tag数据,并更新至ccmParams对象中。 - ccmParams.authTag = cipher.doFinalSync(null); - return encryptUpdate; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|CCM'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, ccmParams); - let decryptUpdate = decoder.doFinalSync(cipherText); - return decryptUpdate; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_ccm_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_CCMSynchronousSuccess'; - } catch { - this.message = 'AES_CCMSynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function genCcmParamsSpec() { + let rand: cryptoFramework.Random = cryptoFramework.createRandom(); + let ivBlob: cryptoFramework.DataBlob = rand.generateRandomSync(7); + let aadBlob: cryptoFramework.DataBlob = rand.generateRandomSync(8); + let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 12 bytes + let dataTag = new Uint8Array(arr); + let tagBlob: cryptoFramework.DataBlob = { + data: dataTag + }; + // CCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + let ccmParamsSpec: cryptoFramework.CcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algName: 'CcmParamsSpec' + }; + return ccmParamsSpec; +} + +let ccmParams = genCcmParamsSpec(); + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|CCM'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, ccmParams); + let encryptUpdate = cipher.updateSync(plainText); + // ccm模式加密doFinal时传入空,获得tag数据,并更新至ccmParams对象中。 + ccmParams.authTag = cipher.doFinalSync(null); + return encryptUpdate; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|CCM'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, ccmParams); + let decryptUpdate = decoder.doFinalSync(cipherText); + return decryptUpdate; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = aesGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_ccm_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'AES_CCMSynchronousSuccess'; + } catch { + this.message = 'AES_CCMSynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index fe9efb21932cabe16e7209c01322e056724b5432..ac451c466e0f2a9f97c42986144c8193effa2b53 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_asynchronous.ets @@ -1,84 +1,84 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|ECB|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); - let cipherData = await cipher.doFinal(plainText); - return cipherData; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|ECB|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function aesECB() { - try { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } - } catch (error) { - console.error(`AES ECB “${error}“, error code: ${error.code}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_ecb_asynchronous')) - .width('70%') - .onClick(() => { - try { - aesECB(); - this.message = 'AES_ECBAsynchronousSuccess'; - } catch { - this.message = 'AES_ECBAsynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|ECB|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); + let cipherData = await cipher.doFinal(plainText); + return cipherData; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|ECB|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = await aesGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function aesECB() { + try { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } + } catch (error) { + console.error(`AES ECB “${error}“, error code: ${error.code}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_ecb_asynchronous')) + .width('70%') + .onClick(() => { + try { + aesECB(); + this.message = 'AES_ECBAsynchronousSuccess'; + } catch { + this.message = 'AES_ECBAsynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index 278430b769515c8ca1a0cb1c27414656cdcc74bc..1e987db84828a52e8d6f182305a90da99be79148 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_ecb_encryption_decryption/aes_ecb_encryption_decryption_synchronous.ets @@ -1,84 +1,84 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|ECB|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); - let cipherData = cipher.doFinalSync(plainText); - return cipherData; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|ECB|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - try { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } - } catch (error) { - console.error(`AES ECB “${error}“, error code: ${error.code}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_ecb_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_ECBSynchronousSuccess'; - } catch { - this.message = 'AES_ECBSynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|ECB|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); + let cipherData = cipher.doFinalSync(plainText); + return cipherData; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|ECB|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = aesGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + try { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } + } catch (error) { + console.error(`AES ECB “${error}“, error code: ${error.code}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_ecb_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'AES_ECBSynchronousSuccess'; + } catch { + this.message = 'AES_ECBSynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index 7e66c30b62ca2f25e253712c354041f4575a4778..d027ccfef270279c93ce549351b8ff647f7867a0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_asynchronous.ets @@ -1,115 +1,115 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; - // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let encryptUpdate = await cipher.update(plainText); - // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 - gcmParams.authTag = await cipher.doFinal(null); - return encryptUpdate; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let decryptUpdate = await decoder.update(cipherText); - // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 - let decryptData = await decoder.doFinal(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - return decryptUpdate; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_gcm_asynchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_GCMAsynchronousSuccess'; - } catch { - this.message = 'AES_GCMAsynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genGcmParamsSpec() { + let ivBlob = generateRandom(12); + let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes + let dataAad = new Uint8Array(arr); + let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; + arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes + let dataTag = new Uint8Array(arr); + let tagBlob: cryptoFramework.DataBlob = { + data: dataTag + }; + // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algName: 'GcmParamsSpec' + }; + return gcmParamsSpec; +} + +let gcmParams = genGcmParamsSpec(); + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|GCM|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); + let encryptUpdate = await cipher.update(plainText); + // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 + gcmParams.authTag = await cipher.doFinal(null); + return encryptUpdate; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|GCM|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); + let decryptUpdate = await decoder.update(cipherText); + // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 + let decryptData = await decoder.doFinal(null); + if (decryptData == null) { + console.info('GCM decrypt success, decryptData is null'); + } + return decryptUpdate; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = await aesGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function main() { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_gcm_asynchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'AES_GCMAsynchronousSuccess'; + } catch { + this.message = 'AES_GCMAsynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index d17cdd6a0bfd1b7b4805d3d1eadbb9491b137eae..e5d8fcf3ebb67b798565237dded28100ceb3474d --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_encryption_decryption/aes_gcm_encryption_decryption_synchronous.ets @@ -1,115 +1,115 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; - // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let encryptUpdate = cipher.updateSync(plainText); - // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 - gcmParams.authTag = cipher.doFinalSync(null); - return encryptUpdate; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let decryptUpdate = decoder.updateSync(cipherText); - // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 - let decryptData = decoder.doFinalSync(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - return decryptUpdate; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_gcm_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_GCMSynchronousSuccess'; - } catch { - this.message = 'AES_GCMSynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genGcmParamsSpec() { + let ivBlob = generateRandom(12); + let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes + let dataAad = new Uint8Array(arr); + let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; + arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes + let dataTag = new Uint8Array(arr); + let tagBlob: cryptoFramework.DataBlob = { + data: dataTag + }; + // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algName: 'GcmParamsSpec' + }; + return gcmParamsSpec; +} + +let gcmParams = genGcmParamsSpec(); + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('AES128|GCM|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); + let encryptUpdate = cipher.updateSync(plainText); + // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 + gcmParams.authTag = cipher.doFinalSync(null); + return encryptUpdate; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('AES128|GCM|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); + let decryptUpdate = decoder.updateSync(cipherText); + // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 + let decryptData = decoder.doFinalSync(null); + if (decryptData == null) { + console.info('GCM decrypt success, decryptData is null'); + } + return decryptUpdate; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); + let symKey = aesGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_gcm_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'AES_GCMSynchronousSuccess'; + } catch { + this.message = 'AES_GCMSynchronousFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_seg_encryption_decryption/aes_gcm_seg_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_seg_encryption_decryption/aes_gcm_seg_encryption_decryption_asynchronous.ets deleted file mode 100755 index 499685318d41af9bc4697709967f9363728fd865..0000000000000000000000000000000000000000 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_seg_encryption_decryption/aes_gcm_seg_encryption_decryption_asynchronous.ets +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; // The GCM authTag is obtained by doFinal() in encryption and passed in params of init() in decryption. - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 分段加密消息 -async function encryptMessageUpdateBySegment(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let cipherText = new Uint8Array(); - for (let i = 0; i < plainText.data.length; i += updateLength) { - let updateMessage = plainText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = await cipher.update(updateMessageBlob); - // 把update的结果拼接起来,得到密文(有些情况下还需拼接doFinal的结果,这取决于分组模式 - // 和填充模式,本例中GCM模式的doFinal结果只包含authTag而不含密文,所以不需要拼接) - let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); - mergeText.set(cipherText); - mergeText.set(updateOutput.data, cipherText.length); - cipherText = mergeText; - } - gcmParams.authTag = await cipher.doFinal(null); - let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; - return cipherBlob; -} - -// 分段解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let decryptText = new Uint8Array(); - for (let i = 0; i < cipherText.data.length; i += updateLength) { - let updateMessage = cipherText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = await decoder.update(updateMessageBlob); - // 把update的结果拼接起来,得到明文 - let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); - mergeText.set(decryptText); - mergeText.set(updateOutput.data, decryptText.length); - decryptText = mergeText; - } - let decryptData = await decoder.doFinal(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; - return decryptBlob; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function aes() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessageUpdateBySegment(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_gcm_segmentation_asynchronous')) - .width('70%') - .onClick(() => { - try { - aes(); - this.message = 'AES_GCMAsynchronousSuccess'; - } catch { - this.message = 'AES_GCMAsynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } -} \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_seg_encryption_decryption/aes_gcm_seg_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_seg_encryption_decryption/aes_gcm_seg_encryption_decryption_synchronous.ets deleted file mode 100755 index 3db9eedb75400f6d58200172c3243f8eb71f89d6..0000000000000000000000000000000000000000 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/ets/pages/aes_gcm_seg_encryption_decryption/aes_gcm_seg_encryption_decryption_synchronous.ets +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; // The GCM authTag is obtained by doFinal() in encryption and passed in params of init() in decryption. - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 分段加密消息 -function encryptMessageUpdateBySegment(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let cipherText = new Uint8Array(); - for (let i = 0; i < plainText.data.length; i += updateLength) { - let updateMessage = plainText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = cipher.updateSync(updateMessageBlob); - // 把update的结果拼接起来,得到密文(有些情况下还需拼接doFinal的结果,这取决于分组模式 - // 和填充模式,本例中GCM模式的doFinal结果只包含authTag而不含密文,所以不需要拼接) - let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); - mergeText.set(cipherText); - mergeText.set(updateOutput.data, cipherText.length); - cipherText = mergeText; - } - gcmParams.authTag = cipher.doFinalSync(null); - let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; - return cipherBlob; -} - -// 分段解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('AES128|GCM|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let decryptText = new Uint8Array(); - for (let i = 0; i < cipherText.data.length; i += updateLength) { - let updateMessage = cipherText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = decoder.updateSync(updateMessageBlob); - // 把update的结果拼接起来,得到明文 - let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); - mergeText.set(decryptText); - mergeText.set(updateOutput.data, decryptText.length); - decryptText = mergeText; - } - let decryptData = decoder.doFinalSync(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; - return decryptBlob; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('AES128'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessageUpdateBySegment(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance Aes ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_gcm_segmentation_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'AES_GCMSynchronousSuccess'; - } catch { - this.message = 'AES_GCMSynchronousFail'; - } - }) - } - .height('100%') - .width('100%') - } -} \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAesArkTs.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAesArkTs.test.ets old mode 100755 new mode 100644 index cf410b05a9c5c3fb78f45ff86e0098414b2803e5..f5217bc5f5f55976cdb0afb55f3e187c2311e70a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAesArkTs.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceAesArkTs.test.ets @@ -1,224 +1,224 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidanceAesArkTsTest() { - describe('encryptionDecryptionGuidanceAesArkTsTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_gcm_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_GCM Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_GCMAsynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_gcm_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_GCM Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_GCMSynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_ccm_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_CCM Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_CCMAsynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs004', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_ccm_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_CCM Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_CCMSynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs005', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_cbc_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_CBC Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_CBCAsynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs006', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_cbc_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_CBC Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_CBCSynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs006 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs007', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs007 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_ecb_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_ECB Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_ECBAsynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs007 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs008', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs008 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_ecb_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_ECB Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_ECBSynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs008 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs009', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs009 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_gcm_seg_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_GCM segmentation Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_GCMAsynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs009 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidanceAesArkTs010', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs010 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('aes_gcm_seg_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES_GCM segmentation Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES_GCMSynchronousSuccess')); - console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs010 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidanceAesArkTsTest() { + describe('encryptionDecryptionGuidanceAesArkTsTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_gcm_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_GCM Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_GCMAsynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_gcm_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_GCM Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_GCMSynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_ccm_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_CCM Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_CCMAsynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs004', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_ccm_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_CCM Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_CCMSynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs005', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_cbc_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_CBC Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_CBCAsynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs006', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_cbc_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_CBC Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_CBCSynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs006 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs007', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs007 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_ecb_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_ECB Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_ECBAsynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs007 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs008', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs008 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_ecb_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_ECB Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_ECBSynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs008 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs009', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs009 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_gcm_seg_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_GCM segmentation Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_GCMAsynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs009 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidanceAesArkTs010', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs010 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('aes_gcm_seg_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES_GCM segmentation Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES_GCMSynchronousSuccess')); + console.info('uitest: testEncryptionDecryptionGuidanceAesArkTs010 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/ohosTest.md old mode 100755 new mode 100644 index fb67bbedbd04ded61086884ac7af729d03cce931..ad51c77def0b7d3a42a25c291d5323cc43b0b12b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/ohosTest.md @@ -1,17 +1,17 @@ -# 使用AES对称密钥加解密(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用AES对称密钥加解密(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(GCM模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(CCM模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(CBC模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(ECB模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用AES对称密钥(GCM模式)分段加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/screenshots/EncryptionDecryptionGuidanceAesArkTs1.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/screenshots/EncryptionDecryptionGuidanceAesArkTs1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/screenshots/EncryptionDecryptionGuidanceAesArkTs2.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceAesArkTs/screenshots/EncryptionDecryptionGuidanceAesArkTs2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/app.json5 old mode 100755 new mode 100644 index f6aaebfdd97ddf71cd02cb85bb51782c1f5a34ae..c7be98756b482d8b1b6bbef6e75546b3a59e4cbc --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidancersa", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidancersa", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 501a0ecc0489d7590fa953ad414a65bd4ed3ec3c..a097cdb19d896f946557ad86446ef4d55f7e0448 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidanceRSA" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidanceRSA" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/README.md old mode 100755 new mode 100644 index 05fbc6431a090a018394a3a678c69dae339ae600..ff1301574a49787e99fc67602e0018a8ed56f018 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/README.md @@ -1,78 +1,78 @@ -# 使用RSA非对称密钥加解密 - -### 介绍 - -本示例主要展示了使用RSA非对称密钥(PKCS1模式)加解密、使用RSA非对称密钥分段加解密、使用RSA非对称密钥(PKCS1_OAEP模式)加解密场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用RSA非对称密钥(PKCS1模式)加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-asym-encrypt-decrypt-pkcs1.md) -- [使用RSA非对称密钥分段加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-asym-encrypt-decrypt-by-segment.md) -- [使用RSA非对称密钥(PKCS1_OAEP模式)加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-asym-encrypt-decrypt-pkcs1_oaep.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidanceRSA.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用RSA非对称密钥加解密示例代码 - │ │ ├── rsa_pkcs1 - │ │ | ├── RSAPKCS1Async.ets - │ │ | ├── RSAPKCS1Sync.ets - │ │ ├── rsa_pkcs1_oaep - │ │ | ├── RSAPKCS1OAEPAsync.ets - │ │ | ├── RSAPKCS1OAEPSync.ets - │ │ ├── rsa_segmentation - │ │ | ├── RSASegmentationAsync.ets - │ │ | ├── RSASegmentationSync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidanceRSA.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用RSA非对称密钥加解密 + +### 介绍 + +本示例主要展示了使用RSA非对称密钥(PKCS1模式)加解密、使用RSA非对称密钥分段加解密、使用RSA非对称密钥(PKCS1_OAEP模式)加解密场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用RSA非对称密钥(PKCS1模式)加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-asym-encrypt-decrypt-pkcs1.md) +- [使用RSA非对称密钥分段加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-asym-encrypt-decrypt-by-segment.md) +- [使用RSA非对称密钥(PKCS1_OAEP模式)加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-asym-encrypt-decrypt-pkcs1_oaep.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidanceRSA.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用RSA非对称密钥加解密示例代码 + │ │ ├── rsa_pkcs1 + │ │ | ├── RSAPKCS1Async.ets + │ │ | ├── RSAPKCS1Sync.ets + │ │ ├── rsa_pkcs1_oaep + │ │ | ├── RSAPKCS1OAEPAsync.ets + │ │ | ├── RSAPKCS1OAEPSync.ets + │ │ ├── rsa_segmentation + │ │ | ├── RSASegmentationAsync.ets + │ │ | ├── RSASegmentationSync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidanceRSA.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Async.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Async.ets old mode 100755 new mode 100644 index 0159e53a43fb083757358bcdf9d357ed2e40e0ae..33683cc72ee34889e00a88d21609ad602b6e78a2 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Async.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Async.ets @@ -1,123 +1,123 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -async function encryptMessagePromise(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); - let encryptData = await cipher.doFinal(plainText); - return encryptData; -} - -// 解密消息 -async function decryptMessagePromise(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -// 生成RSA密钥对 -async function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); - let keyPair = await rsaGenerator.convertKey(pubKeyBlob, priKeyBlob); - console.info('convertKey success'); - return keyPair; -} - -async function main() { - let pkData = - new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, - 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, 74, 42, 173, 40, 215, - 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, 210, 181, 12, 29, 70, - 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, 245, 46, 70, 45, 157, - 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, 118, 92, 147, 121, 220, - 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, 105, 208, 133, 140, 13, - 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1]); - let skData = - new Uint8Array([48, 130, 2, 119, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 97, 48, - 130, 2, 93, 2, 1, 0, 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, - 74, 42, 173, 40, 215, 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, - 210, 181, 12, 29, 70, 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, - 245, 46, 70, 45, 157, 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, - 118, 92, 147, 121, 220, 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, - 105, 208, 133, 140, 13, 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1, 2, 129, 128, 70, 75, 184, 139, 53, 1, 94, - 17, 240, 244, 218, 101, 193, 253, 215, 190, 164, 204, 197, 192, 200, 89, 107, 39, 171, 119, 65, 38, 204, 168, 105, - 180, 234, 217, 16, 161, 185, 132, 175, 103, 25, 154, 153, 153, 36, 36, 26, 178, 150, 66, 45, 8, 185, 19, 90, 228, - 210, 177, 30, 200, 177, 141, 78, 184, 248, 59, 113, 154, 145, 73, 160, 24, 73, 157, 86, 207, 186, 32, 95, 200, - 106, 252, 107, 69, 170, 193, 216, 196, 181, 142, 74, 203, 15, 18, 89, 228, 152, 19, 239, 21, 233, 98, 121, 214, - 57, 187, 111, 239, 223, 248, 199, 70, 223, 108, 108, 113, 234, 144, 155, 95, 246, 144, 244, 122, 39, 55, 127, 81, - 2, 65, 0, 246, 96, 188, 0, 0, 104, 221, 105, 139, 144, 63, 175, 209, 87, 179, 162, 88, 192, 99, 82, 125, 53, 54, - 48, 70, 245, 239, 37, 15, 242, 247, 84, 115, 187, 196, 95, 156, 40, 165, 60, 64, 102, 13, 229, 243, 2, 149, 0, - 232, 226, 221, 192, 95, 11, 12, 208, 5, 181, 98, 62, 210, 190, 141, 235, 2, 65, 0, 204, 244, 34, 10, 105, 80, 76, - 116, 163, 35, 231, 168, 187, 206, 189, 101, 215, 103, 80, 115, 86, 11, 34, 127, 203, 114, 84, 188, 121, 174, 169, - 31, 142, 2, 182, 27, 140, 225, 157, 227, 71, 98, 15, 203, 187, 213, 5, 190, 20, 121, 8, 30, 193, 100, 232, 101, - 141, 8, 124, 20, 29, 78, 6, 95, 2, 65, 0, 204, 43, 225, 224, 6, 118, 224, 117, 100, 200, 199, 94, 70, 23, 109, - 175, 173, 232, 208, 230, 61, 8, 105, 189, 156, 48, 150, 91, 154, 89, 248, 136, 173, 215, 254, 166, 84, 220, 130, - 1, 234, 68, 40, 100, 84, 251, 224, 202, 254, 51, 115, 28, 198, 38, 124, 25, 175, 129, 94, 199, 61, 17, 216, 189, - 2, 64, 72, 230, 129, 129, 48, 138, 134, 87, 106, 123, 231, 247, 165, 173, 216, 194, 115, 198, 228, 223, 209, 120, - 46, 114, 68, 92, 75, 117, 170, 214, 140, 131, 147, 208, 181, 19, 193, 157, 178, 186, 87, 246, 178, 101, 166, 79, - 20, 54, 211, 51, 101, 199, 2, 197, 48, 192, 134, 84, 193, 69, 170, 82, 201, 131, 2, 65, 0, 213, 165, 55, 166, 131, - 210, 195, 56, 250, 147, 195, 61, 205, 208, 189, 185, 40, 52, 50, 119, 137, 23, 246, 46, 220, 108, 52, 23, 152, - 154, 94, 32, 144, 195, 184, 249, 21, 168, 12, 57, 222, 18, 60, 117, 81, 157, 72, 30, 155, 190, 165, 242, 228, 139, - 240, 184, 145, 170, 103, 210, 160, 161, 135, 13]); - let keyPair = await genKeyPairByData(pkData, skData); - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - let message = 'This is a test'; - // 把字符串按utf-8解码为Uint8Array - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(pubKey, plainText); - let decryptText = await decryptMessagePromise(priKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - // 把Uint8Array按utf-8编码为字符串 - let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); - console.info('decrypted result string:' + messageDecrypted); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA PKCS1 Async'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_pkcs1_async')) - .onClick(async () => { - try { - await main(); - this.message = 'RSA PKCS1 Async Success'; - } catch (error) { - console.error(error); - this.message = 'RSA PKCS1 Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +async function encryptMessagePromise(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); + let encryptData = await cipher.doFinal(plainText); + return encryptData; +} + +// 解密消息 +async function decryptMessagePromise(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +// 生成RSA密钥对 +async function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); + let keyPair = await rsaGenerator.convertKey(pubKeyBlob, priKeyBlob); + console.info('convertKey success'); + return keyPair; +} + +async function main() { + let pkData = + new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, + 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, 74, 42, 173, 40, 215, + 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, 210, 181, 12, 29, 70, + 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, 245, 46, 70, 45, 157, + 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, 118, 92, 147, 121, 220, + 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, 105, 208, 133, 140, 13, + 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1]); + let skData = + new Uint8Array([48, 130, 2, 119, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 97, 48, + 130, 2, 93, 2, 1, 0, 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, + 74, 42, 173, 40, 215, 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, + 210, 181, 12, 29, 70, 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, + 245, 46, 70, 45, 157, 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, + 118, 92, 147, 121, 220, 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, + 105, 208, 133, 140, 13, 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1, 2, 129, 128, 70, 75, 184, 139, 53, 1, 94, + 17, 240, 244, 218, 101, 193, 253, 215, 190, 164, 204, 197, 192, 200, 89, 107, 39, 171, 119, 65, 38, 204, 168, 105, + 180, 234, 217, 16, 161, 185, 132, 175, 103, 25, 154, 153, 153, 36, 36, 26, 178, 150, 66, 45, 8, 185, 19, 90, 228, + 210, 177, 30, 200, 177, 141, 78, 184, 248, 59, 113, 154, 145, 73, 160, 24, 73, 157, 86, 207, 186, 32, 95, 200, + 106, 252, 107, 69, 170, 193, 216, 196, 181, 142, 74, 203, 15, 18, 89, 228, 152, 19, 239, 21, 233, 98, 121, 214, + 57, 187, 111, 239, 223, 248, 199, 70, 223, 108, 108, 113, 234, 144, 155, 95, 246, 144, 244, 122, 39, 55, 127, 81, + 2, 65, 0, 246, 96, 188, 0, 0, 104, 221, 105, 139, 144, 63, 175, 209, 87, 179, 162, 88, 192, 99, 82, 125, 53, 54, + 48, 70, 245, 239, 37, 15, 242, 247, 84, 115, 187, 196, 95, 156, 40, 165, 60, 64, 102, 13, 229, 243, 2, 149, 0, + 232, 226, 221, 192, 95, 11, 12, 208, 5, 181, 98, 62, 210, 190, 141, 235, 2, 65, 0, 204, 244, 34, 10, 105, 80, 76, + 116, 163, 35, 231, 168, 187, 206, 189, 101, 215, 103, 80, 115, 86, 11, 34, 127, 203, 114, 84, 188, 121, 174, 169, + 31, 142, 2, 182, 27, 140, 225, 157, 227, 71, 98, 15, 203, 187, 213, 5, 190, 20, 121, 8, 30, 193, 100, 232, 101, + 141, 8, 124, 20, 29, 78, 6, 95, 2, 65, 0, 204, 43, 225, 224, 6, 118, 224, 117, 100, 200, 199, 94, 70, 23, 109, + 175, 173, 232, 208, 230, 61, 8, 105, 189, 156, 48, 150, 91, 154, 89, 248, 136, 173, 215, 254, 166, 84, 220, 130, + 1, 234, 68, 40, 100, 84, 251, 224, 202, 254, 51, 115, 28, 198, 38, 124, 25, 175, 129, 94, 199, 61, 17, 216, 189, + 2, 64, 72, 230, 129, 129, 48, 138, 134, 87, 106, 123, 231, 247, 165, 173, 216, 194, 115, 198, 228, 223, 209, 120, + 46, 114, 68, 92, 75, 117, 170, 214, 140, 131, 147, 208, 181, 19, 193, 157, 178, 186, 87, 246, 178, 101, 166, 79, + 20, 54, 211, 51, 101, 199, 2, 197, 48, 192, 134, 84, 193, 69, 170, 82, 201, 131, 2, 65, 0, 213, 165, 55, 166, 131, + 210, 195, 56, 250, 147, 195, 61, 205, 208, 189, 185, 40, 52, 50, 119, 137, 23, 246, 46, 220, 108, 52, 23, 152, + 154, 94, 32, 144, 195, 184, 249, 21, 168, 12, 57, 222, 18, 60, 117, 81, 157, 72, 30, 155, 190, 165, 242, 228, 139, + 240, 184, 145, 170, 103, 210, 160, 161, 135, 13]); + let keyPair = await genKeyPairByData(pkData, skData); + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + let message = 'This is a test'; + // 把字符串按utf-8解码为Uint8Array + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(pubKey, plainText); + let decryptText = await decryptMessagePromise(priKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + // 把Uint8Array按utf-8编码为字符串 + let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); + console.info('decrypted result string:' + messageDecrypted); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA PKCS1 Async'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_pkcs1_async')) + .onClick(async () => { + try { + await main(); + this.message = 'RSA PKCS1 Async Success'; + } catch (error) { + console.error(error); + this.message = 'RSA PKCS1 Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Sync.ets old mode 100755 new mode 100644 index 6ce9553d8eb3804e480ee0acd0e8380afcae36f5..ed3d8769b0404fd77ee798b678f81b340c4934e1 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1/RSAPKCS1Sync.ets @@ -1,123 +1,123 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -function encryptMessage(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); - let encryptData = cipher.doFinalSync(plainText); - return encryptData; -} - -// 解密消息 -function decryptMessage(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -// 生成RSA密钥对 -function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); - let keyPair = rsaGenerator.convertKeySync(pubKeyBlob, priKeyBlob); - console.info('convertKeySync success'); - return keyPair; -} - -function main() { - let pkData = - new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, - 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, 74, 42, 173, 40, 215, - 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, 210, 181, 12, 29, 70, - 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, 245, 46, 70, 45, 157, - 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, 118, 92, 147, 121, 220, - 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, 105, 208, 133, 140, 13, - 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1]); - let skData = - new Uint8Array([48, 130, 2, 119, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 97, 48, - 130, 2, 93, 2, 1, 0, 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, - 74, 42, 173, 40, 215, 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, - 210, 181, 12, 29, 70, 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, - 245, 46, 70, 45, 157, 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, - 118, 92, 147, 121, 220, 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, - 105, 208, 133, 140, 13, 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1, 2, 129, 128, 70, 75, 184, 139, 53, 1, 94, - 17, 240, 244, 218, 101, 193, 253, 215, 190, 164, 204, 197, 192, 200, 89, 107, 39, 171, 119, 65, 38, 204, 168, 105, - 180, 234, 217, 16, 161, 185, 132, 175, 103, 25, 154, 153, 153, 36, 36, 26, 178, 150, 66, 45, 8, 185, 19, 90, 228, - 210, 177, 30, 200, 177, 141, 78, 184, 248, 59, 113, 154, 145, 73, 160, 24, 73, 157, 86, 207, 186, 32, 95, 200, - 106, 252, 107, 69, 170, 193, 216, 196, 181, 142, 74, 203, 15, 18, 89, 228, 152, 19, 239, 21, 233, 98, 121, 214, - 57, 187, 111, 239, 223, 248, 199, 70, 223, 108, 108, 113, 234, 144, 155, 95, 246, 144, 244, 122, 39, 55, 127, 81, - 2, 65, 0, 246, 96, 188, 0, 0, 104, 221, 105, 139, 144, 63, 175, 209, 87, 179, 162, 88, 192, 99, 82, 125, 53, 54, - 48, 70, 245, 239, 37, 15, 242, 247, 84, 115, 187, 196, 95, 156, 40, 165, 60, 64, 102, 13, 229, 243, 2, 149, 0, - 232, 226, 221, 192, 95, 11, 12, 208, 5, 181, 98, 62, 210, 190, 141, 235, 2, 65, 0, 204, 244, 34, 10, 105, 80, 76, - 116, 163, 35, 231, 168, 187, 206, 189, 101, 215, 103, 80, 115, 86, 11, 34, 127, 203, 114, 84, 188, 121, 174, 169, - 31, 142, 2, 182, 27, 140, 225, 157, 227, 71, 98, 15, 203, 187, 213, 5, 190, 20, 121, 8, 30, 193, 100, 232, 101, - 141, 8, 124, 20, 29, 78, 6, 95, 2, 65, 0, 204, 43, 225, 224, 6, 118, 224, 117, 100, 200, 199, 94, 70, 23, 109, - 175, 173, 232, 208, 230, 61, 8, 105, 189, 156, 48, 150, 91, 154, 89, 248, 136, 173, 215, 254, 166, 84, 220, 130, - 1, 234, 68, 40, 100, 84, 251, 224, 202, 254, 51, 115, 28, 198, 38, 124, 25, 175, 129, 94, 199, 61, 17, 216, 189, - 2, 64, 72, 230, 129, 129, 48, 138, 134, 87, 106, 123, 231, 247, 165, 173, 216, 194, 115, 198, 228, 223, 209, 120, - 46, 114, 68, 92, 75, 117, 170, 214, 140, 131, 147, 208, 181, 19, 193, 157, 178, 186, 87, 246, 178, 101, 166, 79, - 20, 54, 211, 51, 101, 199, 2, 197, 48, 192, 134, 84, 193, 69, 170, 82, 201, 131, 2, 65, 0, 213, 165, 55, 166, 131, - 210, 195, 56, 250, 147, 195, 61, 205, 208, 189, 185, 40, 52, 50, 119, 137, 23, 246, 46, 220, 108, 52, 23, 152, - 154, 94, 32, 144, 195, 184, 249, 21, 168, 12, 57, 222, 18, 60, 117, 81, 157, 72, 30, 155, 190, 165, 242, 228, 139, - 240, 184, 145, 170, 103, 210, 160, 161, 135, 13]); - let keyPair = genKeyPairByData(pkData, skData); - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - let message = 'This is a test'; - // 把字符串按utf-8解码为Uint8Array - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(pubKey, plainText); - let decryptText = decryptMessage(priKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - // 把Uint8Array按utf-8编码为字符串 - let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); - console.info('decrypted result string:' + messageDecrypted); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA PKCS1 Sync'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_pkcs1_sync')) - .onClick(() => { - try { - main(); - this.message = 'RSA PKCS1 Sync Success'; - } catch (error) { - console.error(error); - this.message = 'RSA PKCS1 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +function encryptMessage(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); + let encryptData = cipher.doFinalSync(plainText); + return encryptData; +} + +// 解密消息 +function decryptMessage(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +// 生成RSA密钥对 +function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); + let keyPair = rsaGenerator.convertKeySync(pubKeyBlob, priKeyBlob); + console.info('convertKeySync success'); + return keyPair; +} + +function main() { + let pkData = + new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, + 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, 74, 42, 173, 40, 215, + 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, 210, 181, 12, 29, 70, + 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, 245, 46, 70, 45, 157, + 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, 118, 92, 147, 121, 220, + 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, 105, 208, 133, 140, 13, + 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1]); + let skData = + new Uint8Array([48, 130, 2, 119, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130, 2, 97, 48, + 130, 2, 93, 2, 1, 0, 2, 129, 129, 0, 197, 64, 10, 198, 14, 110, 65, 92, 206, 35, 28, 123, 153, 24, 134, 255, 145, + 74, 42, 173, 40, 215, 146, 58, 143, 46, 10, 195, 154, 160, 69, 196, 220, 152, 179, 44, 111, 200, 84, 78, 215, 73, + 210, 181, 12, 29, 70, 68, 36, 135, 153, 89, 230, 202, 130, 212, 111, 243, 234, 92, 131, 62, 145, 50, 73, 48, 104, + 245, 46, 70, 45, 157, 147, 143, 140, 162, 156, 216, 220, 49, 121, 142, 194, 33, 223, 201, 0, 16, 163, 210, 240, + 118, 92, 147, 121, 220, 17, 114, 24, 52, 125, 135, 176, 88, 21, 83, 86, 17, 156, 88, 250, 48, 79, 86, 128, 248, + 105, 208, 133, 140, 13, 153, 164, 191, 136, 164, 44, 53, 2, 3, 1, 0, 1, 2, 129, 128, 70, 75, 184, 139, 53, 1, 94, + 17, 240, 244, 218, 101, 193, 253, 215, 190, 164, 204, 197, 192, 200, 89, 107, 39, 171, 119, 65, 38, 204, 168, 105, + 180, 234, 217, 16, 161, 185, 132, 175, 103, 25, 154, 153, 153, 36, 36, 26, 178, 150, 66, 45, 8, 185, 19, 90, 228, + 210, 177, 30, 200, 177, 141, 78, 184, 248, 59, 113, 154, 145, 73, 160, 24, 73, 157, 86, 207, 186, 32, 95, 200, + 106, 252, 107, 69, 170, 193, 216, 196, 181, 142, 74, 203, 15, 18, 89, 228, 152, 19, 239, 21, 233, 98, 121, 214, + 57, 187, 111, 239, 223, 248, 199, 70, 223, 108, 108, 113, 234, 144, 155, 95, 246, 144, 244, 122, 39, 55, 127, 81, + 2, 65, 0, 246, 96, 188, 0, 0, 104, 221, 105, 139, 144, 63, 175, 209, 87, 179, 162, 88, 192, 99, 82, 125, 53, 54, + 48, 70, 245, 239, 37, 15, 242, 247, 84, 115, 187, 196, 95, 156, 40, 165, 60, 64, 102, 13, 229, 243, 2, 149, 0, + 232, 226, 221, 192, 95, 11, 12, 208, 5, 181, 98, 62, 210, 190, 141, 235, 2, 65, 0, 204, 244, 34, 10, 105, 80, 76, + 116, 163, 35, 231, 168, 187, 206, 189, 101, 215, 103, 80, 115, 86, 11, 34, 127, 203, 114, 84, 188, 121, 174, 169, + 31, 142, 2, 182, 27, 140, 225, 157, 227, 71, 98, 15, 203, 187, 213, 5, 190, 20, 121, 8, 30, 193, 100, 232, 101, + 141, 8, 124, 20, 29, 78, 6, 95, 2, 65, 0, 204, 43, 225, 224, 6, 118, 224, 117, 100, 200, 199, 94, 70, 23, 109, + 175, 173, 232, 208, 230, 61, 8, 105, 189, 156, 48, 150, 91, 154, 89, 248, 136, 173, 215, 254, 166, 84, 220, 130, + 1, 234, 68, 40, 100, 84, 251, 224, 202, 254, 51, 115, 28, 198, 38, 124, 25, 175, 129, 94, 199, 61, 17, 216, 189, + 2, 64, 72, 230, 129, 129, 48, 138, 134, 87, 106, 123, 231, 247, 165, 173, 216, 194, 115, 198, 228, 223, 209, 120, + 46, 114, 68, 92, 75, 117, 170, 214, 140, 131, 147, 208, 181, 19, 193, 157, 178, 186, 87, 246, 178, 101, 166, 79, + 20, 54, 211, 51, 101, 199, 2, 197, 48, 192, 134, 84, 193, 69, 170, 82, 201, 131, 2, 65, 0, 213, 165, 55, 166, 131, + 210, 195, 56, 250, 147, 195, 61, 205, 208, 189, 185, 40, 52, 50, 119, 137, 23, 246, 46, 220, 108, 52, 23, 152, + 154, 94, 32, 144, 195, 184, 249, 21, 168, 12, 57, 222, 18, 60, 117, 81, 157, 72, 30, 155, 190, 165, 242, 228, 139, + 240, 184, 145, 170, 103, 210, 160, 161, 135, 13]); + let keyPair = genKeyPairByData(pkData, skData); + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + let message = 'This is a test'; + // 把字符串按utf-8解码为Uint8Array + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(pubKey, plainText); + let decryptText = decryptMessage(priKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + // 把Uint8Array按utf-8编码为字符串 + let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); + console.info('decrypted result string:' + messageDecrypted); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA PKCS1 Sync'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_pkcs1_sync')) + .onClick(() => { + try { + main(); + this.message = 'RSA PKCS1 Sync Success'; + } catch (error) { + console.error(error); + this.message = 'RSA PKCS1 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPAsync.ets old mode 100755 new mode 100644 index 6b2067740bf998d1462a410bd47adee0b67476cd..185087e6d6238d7448cec92e8ebdbb55107c447e --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPAsync.ets @@ -1,129 +1,129 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 根据密钥参数属性构造RSA非对称密钥对密钥参数 -function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { - let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { - n: nIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC - }; - let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { - params: rsaCommSpec, - sk: dIn, - pk: eIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC - }; - return rsaKeyPairSpec; -} - -// 生成RSA2048密钥对参数 -function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { - let nIn = - BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc4328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); - let eIn = BigInt('0x010001'); - let dIn = - BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); - return genRsaKeyPairSpec(nIn, eIn, dIn); -} - -async function rsaUseSpecDecryptOAEPPromise() { - let plan = 'This is a test'; - // 获得RSA密钥对密钥参数对象 - let rsaKeyPairSpec = genRsa2048KeyPairSpec(); - // 根据RSA密钥对参数生成RSA密钥对 - let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); - let cipher = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); - let decoder = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); - // RSA加解密PKCS1-OAEP模式填充字节流P - let pSource = new Uint8Array([1, 2, 3, 4]); - let input: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan, 'utf-8').buffer) }; - // 生成密钥对 - let keyPair = await rsaGeneratorSpec.generateKeyPair(); - // 进行加密操作初始化 - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, keyPair.pubKey, null); - // get和set操作可以放在Cipher对象init之后,此处对cipher进行set和get操作 - cipher.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); - let retP = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); - // 比较get出来的P字节流与set进去的P字节流是否一致 - if (retP.toString() != pSource.toString()) { - console.error('error init pSource' + retP); - } else { - console.info('pSource changed ==' + retP); - } - // 进行OAEP其他参数的get操作 - let md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); - console.info('md == ' + md); - let mgf = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); - console.info('mgf == ' + mgf); - let mgf1Md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); - console.info('mgf1Md == ' + mgf1Md); - let cipherDataBlob = await cipher.doFinal(input); - // get和set操作可以放在Cipher对象init之前,且与init之后等价,此处对decoder进行set和get操作 - decoder.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); - retP = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); - // 比较get出来的P字节流与set进去的P字节流是否一致 - if (retP.toString() != pSource.toString()) { - console.error('error init pSource' + retP); - } else { - console.info('pSource changed ==' + retP); - } - // 进行OAEP其他参数的get操作 - md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); - console.info('md == ' + md); - mgf = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); - console.info('mgf == ' + mgf); - mgf1Md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); - console.info('mgf1Md == ' + mgf1Md); - // 初始化解密操作 - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, keyPair.priKey, null); - let decodeData = await decoder.doFinal(cipherDataBlob); - // 解密成功 - if (decodeData.data.toString() === input.data.toString()) { - console.info('oaep decrypt success'); - } else { - console.error('oaep decrypt fail'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA PKCS1 OAEP Async'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_pkcs1_oaep_async')) - .onClick(async () => { - try { - await rsaUseSpecDecryptOAEPPromise(); - this.message = 'RSA PKCS1 OAEP Async Success'; - } catch (error) { - console.error(error); - this.message = 'RSA PKCS1 OAEP Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 根据密钥参数属性构造RSA非对称密钥对密钥参数 +function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: dIn, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC + }; + return rsaKeyPairSpec; +} + +// 生成RSA2048密钥对参数 +function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc4328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + let dIn = + BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); + return genRsaKeyPairSpec(nIn, eIn, dIn); +} + +async function rsaUseSpecDecryptOAEPPromise() { + let plan = 'This is a test'; + // 获得RSA密钥对密钥参数对象 + let rsaKeyPairSpec = genRsa2048KeyPairSpec(); + // 根据RSA密钥对参数生成RSA密钥对 + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + let cipher = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); + let decoder = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); + // RSA加解密PKCS1-OAEP模式填充字节流P + let pSource = new Uint8Array([1, 2, 3, 4]); + let input: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan, 'utf-8').buffer) }; + // 生成密钥对 + let keyPair = await rsaGeneratorSpec.generateKeyPair(); + // 进行加密操作初始化 + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, keyPair.pubKey, null); + // get和set操作可以放在Cipher对象init之后,此处对cipher进行set和get操作 + cipher.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); + let retP = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); + // 比较get出来的P字节流与set进去的P字节流是否一致 + if (retP.toString() != pSource.toString()) { + console.error('error init pSource' + retP); + } else { + console.info('pSource changed ==' + retP); + } + // 进行OAEP其他参数的get操作 + let md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); + console.info('md == ' + md); + let mgf = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); + console.info('mgf == ' + mgf); + let mgf1Md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + let cipherDataBlob = await cipher.doFinal(input); + // get和set操作可以放在Cipher对象init之前,且与init之后等价,此处对decoder进行set和get操作 + decoder.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); + retP = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); + // 比较get出来的P字节流与set进去的P字节流是否一致 + if (retP.toString() != pSource.toString()) { + console.error('error init pSource' + retP); + } else { + console.info('pSource changed ==' + retP); + } + // 进行OAEP其他参数的get操作 + md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); + console.info('md == ' + md); + mgf = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); + console.info('mgf == ' + mgf); + mgf1Md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + // 初始化解密操作 + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, keyPair.priKey, null); + let decodeData = await decoder.doFinal(cipherDataBlob); + // 解密成功 + if (decodeData.data.toString() === input.data.toString()) { + console.info('oaep decrypt success'); + } else { + console.error('oaep decrypt fail'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA PKCS1 OAEP Async'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_pkcs1_oaep_async')) + .onClick(async () => { + try { + await rsaUseSpecDecryptOAEPPromise(); + this.message = 'RSA PKCS1 OAEP Async Success'; + } catch (error) { + console.error(error); + this.message = 'RSA PKCS1 OAEP Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPSync.ets old mode 100755 new mode 100644 index 020ad64891b16031f376edbf02023e7545892d88..4416b29596d9f4b7f0e6a60a97b16f26179c4e6f --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_pkcs1_oaep/RSAPKCS1OAEPSync.ets @@ -1,124 +1,124 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; -// 根据密钥参数属性构造RSA非对称密钥对密钥参数 -function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { - let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { - n: nIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC - }; - let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { - params: rsaCommSpec, - sk: dIn, - pk: eIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC - }; - return rsaKeyPairSpec; -} -// 生成RSA2048密钥对参数 -function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { - let nIn = BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc4328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); - let eIn = BigInt('0x010001'); - let dIn = BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); - return genRsaKeyPairSpec(nIn, eIn, dIn); -} -function main() { - let plan = 'This is a test'; - // 获得RSA密钥对密钥参数对象 - let rsaKeyPairSpec = genRsa2048KeyPairSpec(); - // 根据RSA密钥对参数生成RSA密钥对 - let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); - let cipher = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); - let decoder = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); - // RSA加解密PKCS1-OAEP模式填充字节流P - let pSource = new Uint8Array([1, 2, 3, 4]); - let input: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan, 'utf-8').buffer) }; - // 生成密钥对 - let keyPair = rsaGeneratorSpec.generateKeyPairSync(); - // 进行加密操作初始化 - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, keyPair.pubKey, null); - // get和set操作可以放在Cipher对象init之后,此处对cipher进行set和get操作 - cipher.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); - let retP = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); - // 比较get出来的P字节流与set进去的P字节流是否一致 - if (retP.toString() != pSource.toString()) { - console.error('error init pSource' + retP); - } else { - console.info('pSource changed ==' + retP); - } - // 进行OAEP其他参数的get操作 - let md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); - console.info('md == ' + md); - let mgf = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); - console.info('mgf == ' + mgf); - let mgf1Md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); - console.info('mgf1Md == ' + mgf1Md); - let cipherDataBlob = cipher.doFinalSync(input); - // get和set操作可以放在Cipher对象init之前,且与init之后等价,此处对decoder进行set和get操作 - decoder.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); - retP = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); - // 比较get出来的P字节流与set进去的P字节流是否一致 - if (retP.toString() != pSource.toString()) { - console.error('error init pSource' + retP); - } else { - console.info('pSource changed ==' + retP); - } - // 进行OAEP其他参数的get操作 - md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); - console.info('md == ' + md); - mgf = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); - console.info('mgf == ' + mgf); - mgf1Md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); - console.info('mgf1Md == ' + mgf1Md); - // 初始化解密操作 - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, keyPair.priKey, null); - let decodeData = decoder.doFinalSync(cipherDataBlob); - // 解密成功 - if (decodeData.data.toString() === input.data.toString()) { - console.info('oaep decrypt success'); - } else { - console.error('oaep decrypt fail'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA PKCS1 OAEP Sync'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_pkcs1_oaep_sync')) - .onClick(() => { - try { - main(); - this.message = 'RSA PKCS1 OAEP Sync Success'; - } catch (error) { - console.error(error); - this.message = 'RSA PKCS1 OAEP Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; +// 根据密钥参数属性构造RSA非对称密钥对密钥参数 +function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: dIn, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC + }; + return rsaKeyPairSpec; +} +// 生成RSA2048密钥对参数 +function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { + let nIn = BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc4328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + let dIn = BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); + return genRsaKeyPairSpec(nIn, eIn, dIn); +} +function main() { + let plan = 'This is a test'; + // 获得RSA密钥对密钥参数对象 + let rsaKeyPairSpec = genRsa2048KeyPairSpec(); + // 根据RSA密钥对参数生成RSA密钥对 + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + let cipher = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); + let decoder = cryptoFramework.createCipher('RSA2048|PKCS1_OAEP|SHA256|MGF1_SHA1'); + // RSA加解密PKCS1-OAEP模式填充字节流P + let pSource = new Uint8Array([1, 2, 3, 4]); + let input: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan, 'utf-8').buffer) }; + // 生成密钥对 + let keyPair = rsaGeneratorSpec.generateKeyPairSync(); + // 进行加密操作初始化 + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, keyPair.pubKey, null); + // get和set操作可以放在Cipher对象init之后,此处对cipher进行set和get操作 + cipher.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); + let retP = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); + // 比较get出来的P字节流与set进去的P字节流是否一致 + if (retP.toString() != pSource.toString()) { + console.error('error init pSource' + retP); + } else { + console.info('pSource changed ==' + retP); + } + // 进行OAEP其他参数的get操作 + let md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); + console.info('md == ' + md); + let mgf = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); + console.info('mgf == ' + mgf); + let mgf1Md = cipher.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + let cipherDataBlob = cipher.doFinalSync(input); + // get和set操作可以放在Cipher对象init之前,且与init之后等价,此处对decoder进行set和get操作 + decoder.setCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR, pSource); + retP = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_PSRC_UINT8ARR); + // 比较get出来的P字节流与set进去的P字节流是否一致 + if (retP.toString() != pSource.toString()) { + console.error('error init pSource' + retP); + } else { + console.info('pSource changed ==' + retP); + } + // 进行OAEP其他参数的get操作 + md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MD_NAME_STR); + console.info('md == ' + md); + mgf = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF_NAME_STR); + console.info('mgf == ' + mgf); + mgf1Md = decoder.getCipherSpec(cryptoFramework.CipherSpecItem.OAEP_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + // 初始化解密操作 + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, keyPair.priKey, null); + let decodeData = decoder.doFinalSync(cipherDataBlob); + // 解密成功 + if (decodeData.data.toString() === input.data.toString()) { + console.info('oaep decrypt success'); + } else { + console.error('oaep decrypt fail'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA PKCS1 OAEP Sync'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_pkcs1_oaep_sync')) + .onClick(() => { + try { + main(); + this.message = 'RSA PKCS1 OAEP Sync Success'; + } catch (error) { + console.error(error); + this.message = 'RSA PKCS1 OAEP Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationAsync.ets old mode 100755 new mode 100644 index d69e8ada76a8846dfb834e772bddebdf678d5629..ddec066c4f399ba96e2dbf2f7f41c518fb5dc016 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationAsync.ets @@ -1,105 +1,105 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 分段加密消息 -async function rsaEncryptBySegment(pubKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, pubKey, null); - let plainTextSplitLen = 64; - let cipherText = new Uint8Array(); - for (let i = 0; i < plainText.data.length; i += plainTextSplitLen) { - let updateMessage = plainText.data.subarray(i, i + plainTextSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 将原文按64字符进行拆分,循环调用doFinal进行加密,使用1024bit密钥时,每次加密生成128字节长度的密文 - let updateOutput = await cipher.doFinal(updateMessageBlob); - let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); - mergeText.set(cipherText); - mergeText.set(updateOutput.data, cipherText.length); - cipherText = mergeText; - } - let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; - return cipherBlob; -} - -// 分段解密消息 -async function rsaDecryptBySegment(priKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, priKey, null); - let cipherTextSplitLen = 128; // RSA密钥每次加密生成的密文字节长度计算方式:密钥位数/8 - let decryptText = new Uint8Array(); - for (let i = 0; i < cipherText.data.length; i += cipherTextSplitLen) { - let updateMessage = cipherText.data.subarray(i, i + cipherTextSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 将密文按128字节进行拆分解密,得到原文后进行拼接 - let updateOutput = await decoder.doFinal(updateMessageBlob); - let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); - mergeText.set(decryptText); - mergeText.set(updateOutput.data, decryptText.length); - decryptText = mergeText; - } - let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; - return decryptBlob; -} - -async function rsaEncryptLongMessage() { - let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; - let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); // 创建非对称密钥生成器对象 - let keyPair = await asyKeyGenerator.generateKeyPair(); // 随机生成RSA密钥 - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await rsaEncryptBySegment(keyPair.pubKey, plainText); - let decryptText = await rsaDecryptBySegment(keyPair.priKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Segmentation Async'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_segmentation_async')) - .onClick(async () => { - try { - await rsaEncryptLongMessage(); - this.message = 'RSA Segmentation Async Success'; - } catch (error) { - console.error(error); - this.message = 'RSA Segmentation Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 分段加密消息 +async function rsaEncryptBySegment(pubKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, pubKey, null); + let plainTextSplitLen = 64; + let cipherText = new Uint8Array(); + for (let i = 0; i < plainText.data.length; i += plainTextSplitLen) { + let updateMessage = plainText.data.subarray(i, i + plainTextSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 将原文按64字符进行拆分,循环调用doFinal进行加密,使用1024bit密钥时,每次加密生成128字节长度的密文 + let updateOutput = await cipher.doFinal(updateMessageBlob); + let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); + mergeText.set(cipherText); + mergeText.set(updateOutput.data, cipherText.length); + cipherText = mergeText; + } + let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; + return cipherBlob; +} + +// 分段解密消息 +async function rsaDecryptBySegment(priKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, priKey, null); + let cipherTextSplitLen = 128; // RSA密钥每次加密生成的密文字节长度计算方式:密钥位数/8 + let decryptText = new Uint8Array(); + for (let i = 0; i < cipherText.data.length; i += cipherTextSplitLen) { + let updateMessage = cipherText.data.subarray(i, i + cipherTextSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 将密文按128字节进行拆分解密,得到原文后进行拼接 + let updateOutput = await decoder.doFinal(updateMessageBlob); + let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); + mergeText.set(decryptText); + mergeText.set(updateOutput.data, decryptText.length); + decryptText = mergeText; + } + let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; + return decryptBlob; +} + +async function rsaEncryptLongMessage() { + let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; + let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); // 创建非对称密钥生成器对象 + let keyPair = await asyKeyGenerator.generateKeyPair(); // 随机生成RSA密钥 + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await rsaEncryptBySegment(keyPair.pubKey, plainText); + let decryptText = await rsaDecryptBySegment(keyPair.priKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Segmentation Async'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_segmentation_async')) + .onClick(async () => { + try { + await rsaEncryptLongMessage(); + this.message = 'RSA Segmentation Async Success'; + } catch (error) { + console.error(error); + this.message = 'RSA Segmentation Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationSync.ets old mode 100755 new mode 100644 index 6ff5d7ecb021cab89e11d7b2d19769db3575e40d..e38c88681e459f8f726d89de79a24a780d8b60d3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/ets/pages/rsa_segmentation/RSASegmentationSync.ets @@ -1,105 +1,105 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 分段加密消息 -function rsaEncryptBySegment(pubKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, pubKey, null); - let plainTextSplitLen = 64; - let cipherText = new Uint8Array(); - for (let i = 0; i < plainText.data.length; i += plainTextSplitLen) { - let updateMessage = plainText.data.subarray(i, i + plainTextSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 将原文按64字符进行拆分,循环调用doFinal进行加密,使用1024bit密钥时,每次加密生成128字节长度的密文 - let updateOutput = cipher.doFinalSync(updateMessageBlob); - let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); - mergeText.set(cipherText); - mergeText.set(updateOutput.data, cipherText.length); - cipherText = mergeText; - } - let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; - return cipherBlob; -} - -// 分段解密消息 -function rsaDecryptBySegment(priKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, priKey, null); - let cipherTextSplitLen = 128; // RSA密钥每次加密生成的密文字节长度计算方式:密钥位数/8 - let decryptText = new Uint8Array(); - for (let i = 0; i < cipherText.data.length; i += cipherTextSplitLen) { - let updateMessage = cipherText.data.subarray(i, i + cipherTextSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 将密文按128字节进行拆分解密,得到原文后进行拼接 - let updateOutput = decoder.doFinalSync(updateMessageBlob); - let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); - mergeText.set(decryptText); - mergeText.set(updateOutput.data, decryptText.length); - decryptText = mergeText; - } - let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; - return decryptBlob; -} - -function main() { - let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; - let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); // 创建非对称密钥生成器对象 - let keyPair = asyKeyGenerator.generateKeyPairSync(); // 随机生成RSA密钥 - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = rsaEncryptBySegment(keyPair.pubKey, plainText); - let decryptText = rsaDecryptBySegment(keyPair.priKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Segmentation Sync'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_segmentation_sync')) - .onClick(() => { - try { - main(); - this.message = 'RSA Segmentation Sync Success'; - } catch (error) { - console.error(error); - this.message = 'RSA Segmentation Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 分段加密消息 +function rsaEncryptBySegment(pubKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('RSA1024|PKCS1'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, pubKey, null); + let plainTextSplitLen = 64; + let cipherText = new Uint8Array(); + for (let i = 0; i < plainText.data.length; i += plainTextSplitLen) { + let updateMessage = plainText.data.subarray(i, i + plainTextSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 将原文按64字符进行拆分,循环调用doFinal进行加密,使用1024bit密钥时,每次加密生成128字节长度的密文 + let updateOutput = cipher.doFinalSync(updateMessageBlob); + let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); + mergeText.set(cipherText); + mergeText.set(updateOutput.data, cipherText.length); + cipherText = mergeText; + } + let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; + return cipherBlob; +} + +// 分段解密消息 +function rsaDecryptBySegment(priKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('RSA1024|PKCS1'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, priKey, null); + let cipherTextSplitLen = 128; // RSA密钥每次加密生成的密文字节长度计算方式:密钥位数/8 + let decryptText = new Uint8Array(); + for (let i = 0; i < cipherText.data.length; i += cipherTextSplitLen) { + let updateMessage = cipherText.data.subarray(i, i + cipherTextSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 将密文按128字节进行拆分解密,得到原文后进行拼接 + let updateOutput = decoder.doFinalSync(updateMessageBlob); + let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); + mergeText.set(decryptText); + mergeText.set(updateOutput.data, decryptText.length); + decryptText = mergeText; + } + let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; + return decryptBlob; +} + +function main() { + let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; + let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); // 创建非对称密钥生成器对象 + let keyPair = asyKeyGenerator.generateKeyPairSync(); // 随机生成RSA密钥 + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = rsaEncryptBySegment(keyPair.pubKey, plainText); + let decryptText = rsaDecryptBySegment(keyPair.priKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Segmentation Sync'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_segmentation_sync')) + .onClick(() => { + try { + main(); + this.message = 'RSA Segmentation Sync Success'; + } catch (error) { + console.error(error); + this.message = 'RSA Segmentation Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceRSA.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceRSA.test.ets old mode 100755 new mode 100644 index 42831c4dee907416e21f348286b32151440d4d33..01251e87086fa33d64a485597bbf945c62724a71 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceRSA.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceRSA.test.ets @@ -1,152 +1,152 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidanceRSATest() { - describe('encryptionDecryptionGuidanceRSATest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,异步方法 - */ - it('testEncryptionDecryptionGuidanceRSA001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceRSA001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA PKCS1 Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA PKCS1 Async Success')); - console.info('uitest: testEncryptionDecryptionGuidanceRSA001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,同步方法 - */ - it('testEncryptionDecryptionGuidanceRSA002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceRSA002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA PKCS1 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA PKCS1 Sync Success')); - console.info('uitest: testEncryptionDecryptionGuidanceRSA002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA非对称密钥分段加解密,异步方法 - */ - it('testEncryptionDecryptionGuidanceRSA003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceRSA003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Segmentation Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Segmentation Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Segmentation Async Success')); - console.info('uitest: testEncryptionDecryptionGuidanceRSA003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA非对称密钥分段加解密,同步方法 - */ - it('testEncryptionDecryptionGuidanceRSA004', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceRSA004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Segmentation Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Segmentation Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Segmentation Sync Success')); - console.info('uitest: testEncryptionDecryptionGuidanceRSA004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,异步方法 - */ - it('testEncryptionDecryptionGuidanceRSA005', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceRSA005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA PKCS1 OAEP Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 OAEP Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA PKCS1 OAEP Async Success')); - console.info('uitest: testEncryptionDecryptionGuidanceRSA005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,同步方法 - */ - it('testEncryptionDecryptionGuidanceRSA006', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceRSA006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA PKCS1 OAEP Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 OAEP Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA PKCS1 OAEP Sync Success')); - console.info('uitest: testEncryptionDecryptionGuidanceRSA006 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidanceRSATest() { + describe('encryptionDecryptionGuidanceRSATest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,异步方法 + */ + it('testEncryptionDecryptionGuidanceRSA001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceRSA001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA PKCS1 Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA PKCS1 Async Success')); + console.info('uitest: testEncryptionDecryptionGuidanceRSA001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,同步方法 + */ + it('testEncryptionDecryptionGuidanceRSA002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceRSA002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA PKCS1 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA PKCS1 Sync Success')); + console.info('uitest: testEncryptionDecryptionGuidanceRSA002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA非对称密钥分段加解密,异步方法 + */ + it('testEncryptionDecryptionGuidanceRSA003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceRSA003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Segmentation Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Segmentation Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Segmentation Async Success')); + console.info('uitest: testEncryptionDecryptionGuidanceRSA003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA非对称密钥分段加解密,同步方法 + */ + it('testEncryptionDecryptionGuidanceRSA004', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceRSA004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Segmentation Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Segmentation Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Segmentation Sync Success')); + console.info('uitest: testEncryptionDecryptionGuidanceRSA004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,异步方法 + */ + it('testEncryptionDecryptionGuidanceRSA005', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceRSA005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA PKCS1 OAEP Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 OAEP Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA PKCS1 OAEP Async Success')); + console.info('uitest: testEncryptionDecryptionGuidanceRSA005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,同步方法 + */ + it('testEncryptionDecryptionGuidanceRSA006', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceRSA006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA PKCS1 OAEP Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA PKCS1 OAEP Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA PKCS1 OAEP Sync Success')); + console.info('uitest: testEncryptionDecryptionGuidanceRSA006 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/ohosTest.md old mode 100755 new mode 100644 index 19ecc369b918fe237fb51edf81c392b1c8e19125..3316dd685d3e854785928d322465f4204ca3d6dc --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/ohosTest.md @@ -1,13 +1,13 @@ -# 使用RSA非对称密钥加解密测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA非对称密钥分段加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA非对称密钥分段加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用RSA非对称密钥加解密测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA非对称密钥(PKCS1模式)加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA非对称密钥分段加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA非对称密钥分段加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用RSA非对称密钥(PKCS1_OAEP模式)加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/screenshots/EncryptionDecryptionGuidanceRSA1.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/screenshots/EncryptionDecryptionGuidanceRSA1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/screenshots/EncryptionDecryptionGuidanceRSA2.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceRSA/screenshots/EncryptionDecryptionGuidanceRSA2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/app.json5 old mode 100755 new mode 100644 index a3eeaf2416049777ceca66cd38b4447a45eeb9b3..d2e812a42e3891bec1dbc7fec55010a7da696c95 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidancesm2", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidancesm2", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 5f16b21330735bf25921b88ace780d4f39e146a7..d6c14f7e0d796be9b3b253366e2948661e841ac4 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidanceSM2" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidanceSM2" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/README.md old mode 100755 new mode 100644 index c62590747c26e62a3919451f8a79ace27bf7e89b..8f759e7ec1c117d1e16647af94a58e6f9c506236 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/README.md @@ -1,73 +1,73 @@ -# 使用SM2非对称密钥加解密及密文格式转换 - -### 介绍 - -本示例主要展示了使用SM2非对称密钥加解密及密文格式转换场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用SM2非对称密钥加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-asym-encrypt-decrypt.md) -- [使用SM2密文格式转换](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-ciphertext-conversion.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidanceSM2.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用SM2非对称密钥加解密及密文格式转换示例代码 - │ │ ├── sm2 - │ │ | ├── CreateASN.1Ciphertext.ets - │ │ | ├── ObtainCiphertext.ets - │ │ | ├── SM2EncryptionDecryptionAsync.ets - │ │ | ├── SM2EncryptionDecryptionSync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidanceSM2.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2 > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用SM2非对称密钥加解密及密文格式转换 + +### 介绍 + +本示例主要展示了使用SM2非对称密钥加解密及密文格式转换场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用SM2非对称密钥加解密](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-asym-encrypt-decrypt.md) +- [使用SM2密文格式转换](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-ciphertext-conversion.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidanceSM2.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用SM2非对称密钥加解密及密文格式转换示例代码 + │ │ ├── sm2 + │ │ | ├── CreateASN.1Ciphertext.ets + │ │ | ├── ObtainCiphertext.ets + │ │ | ├── SM2EncryptionDecryptionAsync.ets + │ │ | ├── SM2EncryptionDecryptionSync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidanceSM2.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2 > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/CreateASN.1Ciphertext.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/CreateASN.1Ciphertext.ets old mode 100755 new mode 100644 index f4a1f26269038a63160210a49e72edc2f3a997b3..fee1793d98a3161c815909c50161a9db042ec1d5 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/CreateASN.1Ciphertext.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/CreateASN.1Ciphertext.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function testGenCipherTextBySpec() { - let spec: cryptoFramework.SM2CipherTextSpec = { - xCoordinate: BigInt('20625015362595980457695435345498579729138244358573902431560627260141789922999'), - yCoordinate: BigInt('48563164792857017065725892921053777369510340820930241057309844352421738767712'), - cipherTextData: new Uint8Array([100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]), - hashData: new Uint8Array([87, 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, - 111, 143, 115, 169, 125, 128, 42, 157, 31, 114, 198, 109, 244]), - } - // 此处的data可直接使用cryptoFramework进行SM2解密 - let data = cryptoFramework.SM2CryptoUtil.genCipherTextBySpec(spec, 'C1C3C2'); - console.info('genCipherTextBySpec success'); -} - -@Entry -@Component -struct Index { - @State message: string = 'Create ASN.1'; - - build() { - Column({ space: 5 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_create_asn1')) - .width('70%') - .onClick(() => { - try { - testGenCipherTextBySpec(); - this.message = 'Create ASN.1 Success'; - } catch { - this.message = 'Create ASN.1 Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function testGenCipherTextBySpec() { + let spec: cryptoFramework.SM2CipherTextSpec = { + xCoordinate: BigInt('20625015362595980457695435345498579729138244358573902431560627260141789922999'), + yCoordinate: BigInt('48563164792857017065725892921053777369510340820930241057309844352421738767712'), + cipherTextData: new Uint8Array([100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]), + hashData: new Uint8Array([87, 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, + 111, 143, 115, 169, 125, 128, 42, 157, 31, 114, 198, 109, 244]), + } + // 此处的data可直接使用cryptoFramework进行SM2解密 + let data = cryptoFramework.SM2CryptoUtil.genCipherTextBySpec(spec, 'C1C3C2'); + console.info('genCipherTextBySpec success'); +} + +@Entry +@Component +struct Index { + @State message: string = 'Create ASN.1'; + + build() { + Column({ space: 5 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_create_asn1')) + .width('70%') + .onClick(() => { + try { + testGenCipherTextBySpec(); + this.message = 'Create ASN.1 Success'; + } catch { + this.message = 'Create ASN.1 Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/ObtainCiphertext.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/ObtainCiphertext.ets old mode 100755 new mode 100644 index 0470f3dafef1bf33c11835ebce5736e7ccab1df2..b8a3c20316412877ad8a5d002fee8ec4cb646195 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/ObtainCiphertext.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/ObtainCiphertext.ets @@ -1,52 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function testGetCipherTextSpec() { - let cipherTextArray = - new Uint8Array([48, 118, 2, 32, 45, 153, 88, 82, 104, 221, 226, 43, 174, 21, 122, 248, 5, 232, 105, 41, 92, 95, 102, - 224, 216, 149, 85, 236, 110, 6, 64, 188, 149, 70, 70, 183, 2, 32, 107, 93, 198, 247, 119, 18, 40, 110, 90, 156, - 193, 158, 205, 113, 170, 128, 146, 109, 75, 17, 181, 109, 110, 91, 149, 5, 110, 233, 209, 78, 229, 96, 4, 32, 87, - 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, 111, 143, 115, 169, 125, 128, - 42, 157, 31, 114, 198, 109, 244, 4, 14, 100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]); - let cipherText: cryptoFramework.DataBlob = { data: cipherTextArray }; - let spec: cryptoFramework.SM2CipherTextSpec = cryptoFramework.SM2CryptoUtil.getCipherTextSpec(cipherText, 'C1C3C2'); - console.info('getCipherTextSpec success'); -} - -@Entry -@Component -struct Index { - @State message: string = 'Obtain Ciphertext'; - - build() { - Column({ space: 5 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_obtain_ciphertext')) - .width('70%') - .onClick(() => { - try { - testGetCipherTextSpec(); - this.message = 'Obtain Ciphertext Success'; - } catch { - this.message = 'Obtain Ciphertext Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function testGetCipherTextSpec() { + let cipherTextArray = + new Uint8Array([48, 118, 2, 32, 45, 153, 88, 82, 104, 221, 226, 43, 174, 21, 122, 248, 5, 232, 105, 41, 92, 95, 102, + 224, 216, 149, 85, 236, 110, 6, 64, 188, 149, 70, 70, 183, 2, 32, 107, 93, 198, 247, 119, 18, 40, 110, 90, 156, + 193, 158, 205, 113, 170, 128, 146, 109, 75, 17, 181, 109, 110, 91, 149, 5, 110, 233, 209, 78, 229, 96, 4, 32, 87, + 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201, 111, 143, 115, 169, 125, 128, + 42, 157, 31, 114, 198, 109, 244, 4, 14, 100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]); + let cipherText: cryptoFramework.DataBlob = { data: cipherTextArray }; + let spec: cryptoFramework.SM2CipherTextSpec = cryptoFramework.SM2CryptoUtil.getCipherTextSpec(cipherText, 'C1C3C2'); + console.info('getCipherTextSpec success'); +} + +@Entry +@Component +struct Index { + @State message: string = 'Obtain Ciphertext'; + + build() { + Column({ space: 5 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_obtain_ciphertext')) + .width('70%') + .onClick(() => { + try { + testGetCipherTextSpec(); + this.message = 'Obtain Ciphertext Success'; + } catch { + this.message = 'Obtain Ciphertext Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionAsync.ets old mode 100755 new mode 100644 index 0c4d284ae63bafc0bc83e0e73b6ffb8a9f4d8a17..9f27af389240649027a9edbf4b32ad198d1a98a3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionAsync.ets @@ -1,95 +1,95 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -async function encryptMessagePromise(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM2_256|SM3'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); - let encryptData = await cipher.doFinal(plainText); - return encryptData; -} - -// 解密消息 -async function decryptMessagePromise(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM2_256|SM3'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -// 生成SM2密钥对 -async function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; - let sm2Generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); - let keyPair = await sm2Generator.convertKey(pubKeyBlob, priKeyBlob); - console.info('convertKey success'); - return keyPair; -} - -async function main() { - let pkData = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, - 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, - 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, - 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); - let skData = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, - 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, - 130, 45]); - let keyPair = await genKeyPairByData(pkData, skData); - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - let message = 'This is a test'; - // 把字符串按utf-8解码为Uint8Array - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(pubKey, plainText); - let decryptText = await decryptMessagePromise(priKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - // 把Uint8Array按utf-8编码为字符串 - let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); - console.info('decrypted result string:' + messageDecrypted); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Async'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_async')) - .width('70%') - .onClick(async () => { - try { - await main(); - this.message = 'SM2 Async Success'; - } catch { - this.message = 'SM2 Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +async function encryptMessagePromise(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM2_256|SM3'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); + let encryptData = await cipher.doFinal(plainText); + return encryptData; +} + +// 解密消息 +async function decryptMessagePromise(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM2_256|SM3'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +// 生成SM2密钥对 +async function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; + let sm2Generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); + let keyPair = await sm2Generator.convertKey(pubKeyBlob, priKeyBlob); + console.info('convertKey success'); + return keyPair; +} + +async function main() { + let pkData = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, + 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, + 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, + 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); + let skData = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, + 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, + 130, 45]); + let keyPair = await genKeyPairByData(pkData, skData); + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + let message = 'This is a test'; + // 把字符串按utf-8解码为Uint8Array + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(pubKey, plainText); + let decryptText = await decryptMessagePromise(priKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + // 把Uint8Array按utf-8编码为字符串 + let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); + console.info('decrypted result string:' + messageDecrypted); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Async'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_async')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'SM2 Async Success'; + } catch { + this.message = 'SM2 Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionSync.ets old mode 100755 new mode 100644 index 66fae4ff7c00a0cb22933e79c6c95109b49cbec1..48d1673144ab8bae6352bbf782ee530df3da364e --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/ets/pages/sm2/SM2EncryptionDecryptionSync.ets @@ -1,95 +1,95 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -function encryptMessage(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM2_256|SM3'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); - let encryptData = cipher.doFinalSync(plainText); - return encryptData; -} - -// 解密消息 -function decryptMessage(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM2_256|SM3'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -// 生成SM2密钥对 -function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; - let sm2Generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); - let keyPair = sm2Generator.convertKeySync(pubKeyBlob, priKeyBlob); - console.info('convertKeySync success'); - return keyPair; -} - -function main() { - let pkData = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, - 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, - 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, - 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); - let skData = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, - 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, - 130, 45]); - let keyPair = genKeyPairByData(pkData, skData); - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - let message = 'This is a test'; - // 把字符串按utf-8解码为Uint8Array - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(pubKey, plainText); - let decryptText = decryptMessage(priKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - // 把Uint8Array按utf-8编码为字符串 - let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); - console.info('decrypted result string:' + messageDecrypted); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_sync')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SM2 Sync Success'; - } catch { - this.message = 'SM2 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +function encryptMessage(publicKey: cryptoFramework.PubKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM2_256|SM3'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, publicKey, null); + let encryptData = cipher.doFinalSync(plainText); + return encryptData; +} + +// 解密消息 +function decryptMessage(privateKey: cryptoFramework.PriKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM2_256|SM3'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, privateKey, null); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +// 生成SM2密钥对 +function genKeyPairByData(pubKeyData: Uint8Array, priKeyData: Uint8Array) { + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyData }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyData }; + let sm2Generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); + let keyPair = sm2Generator.convertKeySync(pubKeyBlob, priKeyBlob); + console.info('convertKeySync success'); + return keyPair; +} + +function main() { + let pkData = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, + 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, + 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, + 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); + let skData = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, + 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, + 130, 45]); + let keyPair = genKeyPairByData(pkData, skData); + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + let message = 'This is a test'; + // 把字符串按utf-8解码为Uint8Array + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(pubKey, plainText); + let decryptText = decryptMessage(priKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + // 把Uint8Array按utf-8编码为字符串 + let messageDecrypted = buffer.from(decryptText.data).toString('utf-8'); + console.info('decrypted result string:' + messageDecrypted); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_sync')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SM2 Sync Success'; + } catch { + this.message = 'SM2 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM2.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM2.test.ets old mode 100755 new mode 100644 index fc847beaed5aa7e2fc77fd339cbcb269d795dca7..beab5f33d065030d2797dc57c92d1031c30a2eea --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM2.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM2.test.ets @@ -1,116 +1,116 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidanceSM2Test() { - describe('encryptionDecryptionGuidanceSM2Test', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用SM2非对称密钥加解密,异步方法 - */ - it('testEncryptionDecryptionGuidanceSM2001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM2001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Async Success')); - console.info('uitest: testEncryptionDecryptionGuidanceSM2001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM2非对称密钥加解密,同步方法 - */ - it('testEncryptionDecryptionGuidanceSM2002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM2002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Sync Success')); - console.info('uitest: testEncryptionDecryptionGuidanceSM2002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM2密文格式转换,指定密文参数,生成标准ASN.1密文 - */ - it('testEncryptionDecryptionGuidanceSM2003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM2003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Create ASN.1')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Create ASN.1')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Create ASN.1 Success')); - console.info('uitest: testEncryptionDecryptionGuidanceSM2003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM2密文格式转换,从标准ASN.1密文中,获取密文参数 - */ - it('testEncryptionDecryptionGuidanceSM2004', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM2004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Obtain Ciphertext')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Obtain Ciphertext')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Obtain Ciphertext Success')); - console.info('uitest: testEncryptionDecryptionGuidanceSM2004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidanceSM2Test() { + describe('encryptionDecryptionGuidanceSM2Test', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用SM2非对称密钥加解密,异步方法 + */ + it('testEncryptionDecryptionGuidanceSM2001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM2001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Async Success')); + console.info('uitest: testEncryptionDecryptionGuidanceSM2001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2非对称密钥加解密,同步方法 + */ + it('testEncryptionDecryptionGuidanceSM2002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM2002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Sync Success')); + console.info('uitest: testEncryptionDecryptionGuidanceSM2002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2密文格式转换,指定密文参数,生成标准ASN.1密文 + */ + it('testEncryptionDecryptionGuidanceSM2003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM2003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Create ASN.1')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Create ASN.1')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Create ASN.1 Success')); + console.info('uitest: testEncryptionDecryptionGuidanceSM2003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2密文格式转换,从标准ASN.1密文中,获取密文参数 + */ + it('testEncryptionDecryptionGuidanceSM2004', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM2004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Obtain Ciphertext')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Obtain Ciphertext')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Obtain Ciphertext Success')); + console.info('uitest: testEncryptionDecryptionGuidanceSM2004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/ohosTest.md old mode 100755 new mode 100644 index 86c99941160fca2db2cf60c4129606343628639f..517166af842a101b0c94c32c7fe1dfae9ebd830b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/ohosTest.md @@ -1,11 +1,11 @@ -# 使用SM2非对称密钥加解密及密文格式转换测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用SM2非对称密钥加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM2非对称密钥加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM2密文格式转换,指定密文参数,生成标准ASN.1密文 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用SM2非对称密钥加解密及密文格式转换测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用SM2非对称密钥加解密,异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM2非对称密钥加解密,同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM2密文格式转换,指定密文参数,生成标准ASN.1密文 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用SM2密文格式转换,从标准ASN.1密文中,获取密文参数 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/screenshots/EncryptionDecryptionGuidanceSM21.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/screenshots/EncryptionDecryptionGuidanceSM21.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/screenshots/EncryptionDecryptionGuidanceSM22.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM2/screenshots/EncryptionDecryptionGuidanceSM22.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/app.json5 old mode 100755 new mode 100644 index f705dfb2251a94c70e8a63b8f20da012c7b34832..63f431a6833fe90b98ddce43928a78a07c4709c0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidancesm4", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidancesm4", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 03f452cdce80fb6130a9e601863b93be983fd9ef..14ef92ce2be9c9c9125bbba64b06dcd9bb6f6893 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidanceSM4" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidanceSM4" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/README.md old mode 100755 new mode 100644 index 8984bdeee5ada7c9a79ea0479577339a8c1f0344..30672eed9d73f4d586f46d01f8d215ff2a06ce1d --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/README.md @@ -1,83 +1,83 @@ -# 使用SM4对称密钥加解密(C/C++) - -### 介绍 - -本示例主要展示了使用SM4对称密钥(ECB模式)加解密(C/C++)、使用SM4对称密钥(CBC模式)加解密(C/C++)、使用SM4对称密钥(GCM模式)加解密(C/C++)、使用SM4对称密钥(GCM模式)分段加解密(C/C++)场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用SM4对称密钥(ECB模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-ecb-ndk.md) -- [使用SM4对称密钥(CBC模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-cbc-ndk.md) -- [使用SM4对称密钥(GCM模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm-ndk.md) -- [使用SM4对称密钥(GCM模式)分段加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm-by-segment-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidanceSM4.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── sm4_cbc_encryption_decryption.cpp - │ │ | ├── sm4_ecb_encryption_decryption.cpp - │ │ | ├── sm4_gcm_encryption_decryption.cpp - │ │ | ├── sm4_gcm_seg_encryption_decryption.cpp - │ │ | ├── file.h - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用SM4对称密钥加解密(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidanceSM4.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4 > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用SM4对称密钥加解密(C/C++) + +### 介绍 + +本示例主要展示了使用SM4对称密钥(ECB模式)加解密(C/C++)、使用SM4对称密钥(CBC模式)加解密(C/C++)、使用SM4对称密钥(GCM模式)加解密(C/C++)、使用SM4对称密钥(GCM模式)分段加解密(C/C++)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用SM4对称密钥(ECB模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-ecb-ndk.md) +- [使用SM4对称密钥(CBC模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-cbc-ndk.md) +- [使用SM4对称密钥(GCM模式)加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm-ndk.md) +- [使用SM4对称密钥(GCM模式)分段加解密(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm-by-segment-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidanceSM4.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── sm4_cbc_encryption_decryption.cpp + │ │ | ├── sm4_ecb_encryption_decryption.cpp + │ │ | ├── sm4_gcm_encryption_decryption.cpp + │ │ | ├── sm4_gcm_seg_encryption_decryption.cpp + │ │ | ├── file.h + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用SM4对称密钥加解密(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidanceSM4.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4 > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 2452fd1879bbe58ca4a63378b1cfdad6e3cb6734..908bd14781eac02c94b3a8f090eb547db9225240 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(EncryptionDecryptionGuidanceSM4) - -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 types/project/sm4_ecb_encryption_decryption.cpp types/project/sm4_cbc_encryption_decryption.cpp types/project/sm4_gcm_encryption_decryption.cpp types/project/sm4_gcm_seg_encryption_decryption.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(EncryptionDecryptionGuidanceSM4) + +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 types/project/sm4_ecb_encryption_decryption.cpp types/project/sm4_cbc_encryption_decryption.cpp types/project/sm4_gcm_encryption_decryption.cpp types/project/sm4_gcm_seg_encryption_decryption.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index fa4c21e593bb88bdf9814463ce0455d910afa532..0baaf52375e2a0c148ab18e66124bdfd4650b80e --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/napi_init.cpp @@ -1,70 +1,70 @@ -/* - * 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 "types/project/file.h" - -static napi_value NAPI_Global_testSm4Ecb(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestSm4Ecb(), &ret); - return ret; -} - -static napi_value NAPI_Global_testSm4Cbc(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestSm4Cbc(), &ret); - return ret; -} - -static napi_value NAPI_Global_testSm4Gcm(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestSm4Gcm(), &ret); - return ret; -} - -static napi_value NAPI_Global_testSm4GcmSeg(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestSm4GcmSeg(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"testSm4Ecb", nullptr, NAPI_Global_testSm4Ecb, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testSm4Cbc", nullptr, NAPI_Global_testSm4Cbc, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testSm4Gcm", nullptr, NAPI_Global_testSm4Gcm, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"testSm4GcmSeg", nullptr, NAPI_Global_testSm4GcmSeg, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_testSm4Ecb(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestSm4Ecb(), &ret); + return ret; +} + +static napi_value NAPI_Global_testSm4Cbc(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestSm4Cbc(), &ret); + return ret; +} + +static napi_value NAPI_Global_testSm4Gcm(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestSm4Gcm(), &ret); + return ret; +} + +static napi_value NAPI_Global_testSm4GcmSeg(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestSm4GcmSeg(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"testSm4Ecb", nullptr, NAPI_Global_testSm4Ecb, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testSm4Cbc", nullptr, NAPI_Global_testSm4Cbc, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testSm4Gcm", nullptr, NAPI_Global_testSm4Gcm, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"testSm4GcmSeg", nullptr, NAPI_Global_testSm4GcmSeg, 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index eccd145f2af8850b48ce31929b581797912becb8..1286917646204ae04f6dd41ff47c51f525a30037 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,22 +1,22 @@ -/* - * 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 testSm4Ecb: () => number; - -export const testSm4Cbc: () => number; - -export const testSm4Gcm: () => number; - -export const testSm4GcmSeg: () => number; +/* + * 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 testSm4Ecb: () => number; + +export const testSm4Cbc: () => number; + +export const testSm4Gcm: () => number; + +export const testSm4GcmSeg: () => number; diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 076f122220385c109f6d39a2a132fc028d30d5b9..2e8def9185a35b9741ae36bda80469796a86fcbf --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/file.h @@ -1,21 +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. - */ - -#include "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestSm4Ecb(); -OH_Crypto_ErrCode doTestSm4Cbc(); -OH_Crypto_ErrCode doTestSm4Gcm(); +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestSm4Ecb(); +OH_Crypto_ErrCode doTestSm4Cbc(); +OH_Crypto_ErrCode doTestSm4Gcm(); OH_Crypto_ErrCode doTestSm4GcmSeg(); \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp old mode 100755 new mode 100644 index 9ee7c83de4404a64949d958cb4662e6f458cb57e..92d3aadd388f5e82a5ae8c9a74e9bef3357c4170 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_cbc_encryption_decryption.cpp @@ -1,93 +1,93 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestSm4Cbc() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - - char *plainText = const_cast("this is test!"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - uint8_t iv[16] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4, 3, 1, 0, 10}; // iv使用安全随机数生成 - Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; - // 生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("SM4_128|CBC|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - ret = OH_CryptoSymCipher_Create("SM4_128|CBC|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 资源释放 -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; -} +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestSm4Cbc() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + + char *plainText = const_cast("this is test!"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + uint8_t iv[16] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4, 3, 1, 0, 10}; // iv使用安全随机数生成 + Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; + // 生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("SM4_128|CBC|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + ret = OH_CryptoSymCipher_Create("SM4_128|CBC|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 资源释放 +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp old mode 100755 new mode 100644 index 3d0b4f1ea3502a13c565bdff87ac362c836a5018..e1533f0a790cac7e482e9250504e310f35f68073 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_ecb_encryption_decryption.cpp @@ -1,85 +1,85 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestSm4Ecb() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - char *plainText = const_cast("this is test!"); - Crypto_DataBlob input = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - - // 随机生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - // 创建参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密操作 - ret = OH_CryptoSymCipher_Create("SM4_128|ECB|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, &input, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密操作 - ret = OH_CryptoSymCipher_Create("SM4_128|ECB|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - // 释放资源 -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; -} +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestSm4Ecb() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + char *plainText = const_cast("this is test!"); + Crypto_DataBlob input = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + + // 随机生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + // 创建参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密操作 + ret = OH_CryptoSymCipher_Create("SM4_128|ECB|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, &input, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密操作 + ret = OH_CryptoSymCipher_Create("SM4_128|ECB|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + // 释放资源 +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp old mode 100755 new mode 100644 index b3925630118f9e621793a816ca97a8b21ddc2bc5..169746beaffe738dae80daa2dbf8ed7cfa0101bb --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_encryption_decryption.cpp @@ -1,116 +1,116 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestSm4Gcm() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - - uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint8_t tag[16] = {0}; - uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 - Crypto_DataBlob ivData = {.data = iv, .len = sizeof(iv)}; - Crypto_DataBlob aadData = {.data = aad, .len = sizeof(aad)}; - Crypto_DataBlob tagData = {.data = tag, .len = sizeof(tag)}; - Crypto_DataBlob tagOutPut = {.data = nullptr, .len = 0}; - char *plainText = const_cast("this is test!"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - // 生成对称密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagData); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tagOutPut); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagOutPut); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 释放资源 -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&decUpdate); - OH_Crypto_FreeDataBlob(&tagOutPut); - return ret; -} +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestSm4Gcm() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + + uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + uint8_t tag[16] = {0}; + uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 + Crypto_DataBlob ivData = {.data = iv, .len = sizeof(iv)}; + Crypto_DataBlob aadData = {.data = aad, .len = sizeof(aad)}; + Crypto_DataBlob tagData = {.data = tag, .len = sizeof(tag)}; + Crypto_DataBlob tagOutPut = {.data = nullptr, .len = 0}; + char *plainText = const_cast("this is test!"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + // 生成对称密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagData); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tagOutPut); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagOutPut); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &outUpdate, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 释放资源 +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&decUpdate); + OH_Crypto_FreeDataBlob(&tagOutPut); + return ret; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp old mode 100755 new mode 100644 index 882ae37606d2eec1be17caeab8dad06a3c8b5809..1aa0527d5c1406bda976d91e537d090f13b2e7c8 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/cpp/types/project/sm4_gcm_seg_encryption_decryption.cpp @@ -1,142 +1,142 @@ -/* - * 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 -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_cipher.h" - -#define OH_CRYPTO_GCM_TAG_LEN 16 -#define OH_CRYPTO_MAX_TEST_DATA_LEN 128 - -OH_Crypto_ErrCode doTestSm4GcmSeg() -{ - OH_CryptoSymKeyGenerator *genCtx = nullptr; - OH_CryptoSymCipher *encCtx = nullptr; - OH_CryptoSymCipher *decCtx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - OH_CryptoSymCipherParams *params = nullptr; - - char *plainText = const_cast("aaaaa.....bbbbb.....ccccc.....ddddd.....eee"); - Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; - uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - uint8_t tagArr[16] = {0}; - uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 - Crypto_DataBlob tag = {.data = nullptr, .len = 0}; - Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; - Crypto_DataBlob aadBlob = {.data = aad, .len = sizeof(aad)}; - Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; - Crypto_DataBlob tagInit = {.data = tagArr, .len = sizeof(tagArr)}; - int32_t cipherLen = 0; - int blockSize = 20; - int32_t randomLen = strlen(plainText); - int cnt = randomLen / blockSize; - int rem = randomLen % blockSize; - uint8_t cipherText[OH_CRYPTO_MAX_TEST_DATA_LEN] = {0}; - Crypto_DataBlob cipherBlob; - - // 生成密钥 - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 设置参数 - ret = OH_CryptoSymCipherParams_Create(¶ms); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadBlob); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagInit); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 加密 - ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &encCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - for (int i = 0; i < cnt; i++) { - msgBlob.len = blockSize; - ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - msgBlob.data += blockSize; - memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); - cipherLen += outUpdate.len; - } - if (rem > 0) { - msgBlob.len = rem; - ret = OH_CryptoSymCipher_Update(encCtx, (Crypto_DataBlob *)&msgBlob, &outUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); - cipherLen += outUpdate.len; - } - ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tag); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - - // 解密 - cipherBlob = {.data = reinterpret_cast(cipherText), .len = (size_t)cipherLen}; - msgBlob.data -= strlen(plainText) - rem; - msgBlob.len = strlen(plainText); - ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &decCtx); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tag); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); - if (ret != CRYPTO_SUCCESS) { - goto end; - } - ret = OH_CryptoSymCipher_Final(decCtx, &cipherBlob, &decUpdate); - if (ret != CRYPTO_SUCCESS) { - goto end; - } -end: - OH_CryptoSymCipherParams_Destroy(params); - OH_CryptoSymCipher_Destroy(encCtx); - OH_CryptoSymCipher_Destroy(decCtx); - OH_CryptoSymKeyGenerator_Destroy(genCtx); - OH_CryptoSymKey_Destroy(keyCtx); - OH_Crypto_FreeDataBlob(&outUpdate); - OH_Crypto_FreeDataBlob(&tag); - OH_Crypto_FreeDataBlob(&decUpdate); - return ret; -} +/* + * 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 +#include "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_cipher.h" + +#define OH_CRYPTO_GCM_TAG_LEN 16 +#define OH_CRYPTO_MAX_TEST_DATA_LEN 128 + +OH_Crypto_ErrCode doTestSm4GcmSeg() +{ + OH_CryptoSymKeyGenerator *genCtx = nullptr; + OH_CryptoSymCipher *encCtx = nullptr; + OH_CryptoSymCipher *decCtx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + OH_CryptoSymCipherParams *params = nullptr; + + char *plainText = const_cast("aaaaa.....bbbbb.....ccccc.....ddddd.....eee"); + Crypto_DataBlob msgBlob = {.data = (uint8_t *)(plainText), .len = strlen(plainText)}; + uint8_t aad[8] = {1, 2, 3, 4, 5, 6, 7, 8}; + uint8_t tagArr[16] = {0}; + uint8_t iv[12] = {1, 2, 4, 12, 3, 4, 2, 3, 3, 2, 0, 4}; // iv使用安全随机数生成 + Crypto_DataBlob tag = {.data = nullptr, .len = 0}; + Crypto_DataBlob ivBlob = {.data = iv, .len = sizeof(iv)}; + Crypto_DataBlob aadBlob = {.data = aad, .len = sizeof(aad)}; + Crypto_DataBlob outUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob decUpdate = {.data = nullptr, .len = 0}; + Crypto_DataBlob tagInit = {.data = tagArr, .len = sizeof(tagArr)}; + int32_t cipherLen = 0; + int blockSize = 20; + int32_t randomLen = strlen(plainText); + int cnt = randomLen / blockSize; + int rem = randomLen % blockSize; + uint8_t cipherText[OH_CRYPTO_MAX_TEST_DATA_LEN] = {0}; + Crypto_DataBlob cipherBlob; + + // 生成密钥 + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &genCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymKeyGenerator_Generate(genCtx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 设置参数 + ret = OH_CryptoSymCipherParams_Create(¶ms); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_IV_DATABLOB, &ivBlob); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_AAD_DATABLOB, &aadBlob); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tagInit); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 加密 + ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &encCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(encCtx, CRYPTO_ENCRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + for (int i = 0; i < cnt; i++) { + msgBlob.len = blockSize; + ret = OH_CryptoSymCipher_Update(encCtx, &msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + msgBlob.data += blockSize; + memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); + cipherLen += outUpdate.len; + } + if (rem > 0) { + msgBlob.len = rem; + ret = OH_CryptoSymCipher_Update(encCtx, (Crypto_DataBlob *)&msgBlob, &outUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + memcpy(&cipherText[cipherLen], outUpdate.data, outUpdate.len); + cipherLen += outUpdate.len; + } + ret = OH_CryptoSymCipher_Final(encCtx, nullptr, &tag); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + + // 解密 + cipherBlob = {.data = reinterpret_cast(cipherText), .len = (size_t)cipherLen}; + msgBlob.data -= strlen(plainText) - rem; + msgBlob.len = strlen(plainText); + ret = OH_CryptoSymCipher_Create("SM4_128|GCM|PKCS7", &decCtx); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipherParams_SetParam(params, CRYPTO_TAG_DATABLOB, &tag); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Init(decCtx, CRYPTO_DECRYPT_MODE, keyCtx, params); + if (ret != CRYPTO_SUCCESS) { + goto end; + } + ret = OH_CryptoSymCipher_Final(decCtx, &cipherBlob, &decUpdate); + if (ret != CRYPTO_SUCCESS) { + goto end; + } +end: + OH_CryptoSymCipherParams_Destroy(params); + OH_CryptoSymCipher_Destroy(encCtx); + OH_CryptoSymCipher_Destroy(decCtx); + OH_CryptoSymKeyGenerator_Destroy(genCtx); + OH_CryptoSymKey_Destroy(keyCtx); + OH_Crypto_FreeDataBlob(&outUpdate); + OH_Crypto_FreeDataBlob(&tag); + OH_Crypto_FreeDataBlob(&decUpdate); + return ret; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index b26a323c411d7af3ce8c2723f765cc80562c8d96..e138da64e6583f1819cf5dd317e3e58634c3fb0b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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', err.message ?? ''); - 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'); - } +/* + * 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', err.message ?? ''); + 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 2e6219c69b183a8fef732a167c0481d3c6cdcbdf..25fe92595bb59fc8066ec710ad6732b4adcf09b7 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/ets/pages/Index.ets @@ -1,56 +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 testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'EncryptionDecryptionGuidanceSM4'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(24) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_ecb')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testSm4Ecb(); - this.message = 'SM4_ECBSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_sm4_cbc')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testSm4Cbc(); - this.message = 'SM4_CBCSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_sm4_gcm')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testSm4Gcm(); - this.message = 'SM4_GCMSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_sm4_gcm_seg')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testSm4GcmSeg(); - this.message = 'SM4_GCM_SEGSuccess Result:' + ret.toString(); - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { + @State message: string = 'EncryptionDecryptionGuidanceSM4'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(24) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_ecb')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testSm4Ecb(); + this.message = 'SM4_ECBSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_sm4_cbc')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testSm4Cbc(); + this.message = 'SM4_CBCSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_sm4_gcm')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testSm4Gcm(); + this.message = 'SM4_GCMSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_sm4_gcm_seg')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testSm4GcmSeg(); + this.message = 'SM4_GCM_SEGSuccess Result:' + ret.toString(); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM4.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM4.test.ets old mode 100755 new mode 100644 index 820fdccd4e21495afa1e8e34f531fba3333f802b..9edb09d835998bd94c7e6ce1688512f48b4019ee --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM4.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidanceSM4.test.ets @@ -1,100 +1,100 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidanceSM4Test() { - describe('encryptionDecryptionGuidanceSM4Test', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用SM4对称密钥(ECB模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceSM4001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM4001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM4_ECB')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_ECBSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceSM4001 end'); - }) - - /** - * 点击按钮,使用SM4对称密钥(CBC模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceSM4002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM4002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM4_CBC')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_CBCSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceSM4002 end'); - }) - - /** - * 点击按钮,使用SM4对称密钥(GCM模式)加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceSM4003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM4003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM4_GCM')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_GCMSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceSM4003 end'); - }) - - /** - * 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(C/C++) - */ - it('testEncryptionDecryptionGuidanceSM4004', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceSM4004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM4_GCM_SEG')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_GCM_SEGSuccess Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceSM4004 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidanceSM4Test() { + describe('encryptionDecryptionGuidanceSM4Test', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用SM4对称密钥(ECB模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceSM4001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM4001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM4_ECB')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_ECBSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceSM4001 end'); + }) + + /** + * 点击按钮,使用SM4对称密钥(CBC模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceSM4002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM4002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM4_CBC')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_CBCSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceSM4002 end'); + }) + + /** + * 点击按钮,使用SM4对称密钥(GCM模式)加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceSM4003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM4003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM4_GCM')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_GCMSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceSM4003 end'); + }) + + /** + * 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(C/C++) + */ + it('testEncryptionDecryptionGuidanceSM4004', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceSM4004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM4_GCM_SEG')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_GCM_SEGSuccess Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceSM4004 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/ohosTest.md old mode 100755 new mode 100644 index 33d470b6d14a9d58cbc006d150fb501854a59aaf..8bb265dabdfbc2303a7ceafa217f1e5abee56c36 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/ohosTest.md @@ -1,11 +1,11 @@ -# 使用SM4对称密钥加解密(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(ECB模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(CBC模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(GCM模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用SM4对称密钥加解密(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(ECB模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(CBC模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(GCM模式)加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/screenshots/EncryptionDecryptionGuidanceSM41.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/screenshots/EncryptionDecryptionGuidanceSM41.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/screenshots/EncryptionDecryptionGuidanceSM42.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4/screenshots/EncryptionDecryptionGuidanceSM42.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/app.json5 old mode 100755 new mode 100644 index 0ad16de3977f45cafbd62b16a01119dfb5629545..294445e445be36d70125c75c4560ac1c85f43004 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/app.json5 @@ -1,25 +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.encryptiondecryptionguidancesm4arkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryptionguidancesm4arkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index deda2c228b97173b972523f7dab01baa337c6399..6f3ea08d13b0a3d9fe2cb3908fe869e52edbb441 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryptionGuidanceSM4ArkTs" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryptionGuidanceSM4ArkTs" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/README.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/README.md old mode 100755 new mode 100644 index c75536b69d593028127051f8ebc8f5b413b96299..158426a44f182a327284bc19939a176a7e0f597c --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/README.md @@ -1,82 +1,82 @@ -# 使用SM4对称密钥加解密(ArkTS) - -### 介绍 - -本示例主要展示了使用SM4对称密钥(ECB模式)加解密(ArkTS)、使用SM4对称密钥(CBC模式)加解密(ArkTS)、使用SM4对称密钥(GCM模式)加解密(ArkTS)、使用SM4对称密钥(GCM模式)分段加解密(ArkTS)场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用SM4对称密钥(ECB模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-ecb.md) -- [使用SM4对称密钥(CBC模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-cbc.md) -- [使用SM4对称密钥(GCM模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm.md) -- [使用SM4对称密钥(GCM模式)分段加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm-by-segment.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例EncryptionDecryptionGuidanceSM4ArkTs.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用SM4对称密钥加解密(ArkTS)示例代码 - │ │ ├── sm4_cbc_encryption_decryption - │ │ | ├── sm4_cbc_encryption_decryption_asynchronous.ets - │ │ | ├── sm4_cbc_encryption_decryption_synchronous.ets - │ │ ├── sm4_ecb_encryption_decryption - │ │ | ├── sm4_ecb_encryption_decryption_asynchronous.ets - │ │ | ├── sm4_ecb_encryption_decryption_synchronous.ets - │ │ ├── sm4_gcm_encryption_decryption - │ │ | ├── sm4_gcm_encryption_decryption_asynchronous.ets - │ │ | ├── sm4_gcm_encryption_decryption_synchronous.ets - │ │ ├── sm4_gcm_seg_encryption_decryption - │ │ | ├── sm4_gcm_seg_encryption_decryption_asynchronous.ets - │ │ | ├── sm4_gcm_seg_encryption_decryption_synchronous.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── EncryptionDecryptionGuidanceSM4ArkTs.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用SM4对称密钥加解密(ArkTS) + +### 介绍 + +本示例主要展示了使用SM4对称密钥(ECB模式)加解密(ArkTS)、使用SM4对称密钥(CBC模式)加解密(ArkTS)、使用SM4对称密钥(GCM模式)加解密(ArkTS)、使用SM4对称密钥(GCM模式)分段加解密(ArkTS)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用SM4对称密钥(ECB模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-ecb.md) +- [使用SM4对称密钥(CBC模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-cbc.md) +- [使用SM4对称密钥(GCM模式)加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm.md) +- [使用SM4对称密钥(GCM模式)分段加解密(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm4-sym-encrypt-decrypt-gcm-by-segment.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例EncryptionDecryptionGuidanceSM4ArkTs.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用SM4对称密钥加解密(ArkTS)示例代码 + │ │ ├── sm4_cbc_encryption_decryption + │ │ | ├── sm4_cbc_encryption_decryption_asynchronous.ets + │ │ | ├── sm4_cbc_encryption_decryption_synchronous.ets + │ │ ├── sm4_ecb_encryption_decryption + │ │ | ├── sm4_ecb_encryption_decryption_asynchronous.ets + │ │ | ├── sm4_ecb_encryption_decryption_synchronous.ets + │ │ ├── sm4_gcm_encryption_decryption + │ │ | ├── sm4_gcm_encryption_decryption_asynchronous.ets + │ │ | ├── sm4_gcm_encryption_decryption_synchronous.ets + │ │ ├── sm4_gcm_seg_encryption_decryption + │ │ | ├── sm4_gcm_seg_encryption_decryption_asynchronous.ets + │ │ | ├── sm4_gcm_seg_encryption_decryption_synchronous.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── EncryptionDecryptionGuidanceSM4ArkTs.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index aac7e1ebaeadc46467ac09702778f379924082a9..69f7cfda1a80780f6b5a001a21833803b638c5b5 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_asynchronous.ets @@ -1,101 +1,101 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genIvParamsSpec() { - let ivBlob = generateRandom(16); // 16 bytes - let ivParamsSpec: cryptoFramework.IvParamsSpec = { - algName: 'IvParamsSpec', - iv: ivBlob - }; - return ivParamsSpec; -} - -let iv = genIvParamsSpec(); - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); - let encryptData = await cipher.doFinal(plainText); - return encryptData; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = await symGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function main() { - try { - let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } - } catch (error) { - console.error(`SM4 “${error}“, error code: ${error.code}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_cbc_asynchronous')) - .width('70%') - .onClick(async () => { - try { - await main(); - this.message = 'SM4_CBCSuccess'; - } catch { - this.message = 'SM4_CBCFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genIvParamsSpec() { + let ivBlob = generateRandom(16); // 16 bytes + let ivParamsSpec: cryptoFramework.IvParamsSpec = { + algName: 'IvParamsSpec', + iv: ivBlob + }; + return ivParamsSpec; +} + +let iv = genIvParamsSpec(); + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); + let encryptData = await cipher.doFinal(plainText); + return encryptData; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); + let symKey = await symGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function main() { + try { + let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } + } catch (error) { + console.error(`SM4 “${error}“, error code: ${error.code}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_cbc_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'SM4_CBCSuccess'; + } catch { + this.message = 'SM4_CBCFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index fc8dc5499bdc3066c5f21a53862cf03d57469aae..545a0ceef9d27a6be85941e0ba6aa2cd814597f9 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_cbc_encryption_decryption/sm4_cbc_encryption_decryption_synchronous.ets @@ -1,101 +1,101 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genIvParamsSpec() { - let ivBlob = generateRandom(16); // 16 bytes - let ivParamsSpec: cryptoFramework.IvParamsSpec = { - algName: 'IvParamsSpec', - iv: ivBlob - }; - return ivParamsSpec; -} - -let iv = genIvParamsSpec(); - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); - let encryptData = cipher.doFinalSync(plainText); - return encryptData; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = symGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - try { - let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } - } catch (error) { - console.error(`SM4 “${error}“, error code: ${error.code}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_cbc_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SM4_CBCSuccess'; - } catch { - this.message = 'SM4_CBCFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genIvParamsSpec() { + let ivBlob = generateRandom(16); // 16 bytes + let ivParamsSpec: cryptoFramework.IvParamsSpec = { + algName: 'IvParamsSpec', + iv: ivBlob + }; + return ivParamsSpec; +} + +let iv = genIvParamsSpec(); + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, iv); + let encryptData = cipher.doFinalSync(plainText); + return encryptData; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM4_128|CBC|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, iv); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); + let symKey = symGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + try { + let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } + } catch (error) { + console.error(`SM4 “${error}“, error code: ${error.code}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_cbc_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SM4_CBCSuccess'; + } catch { + this.message = 'SM4_CBCFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index a18ba8bda22d76a51559fb0abb4f5e19fd435132..d54e5e53b44076fac710de54fda9be637f2d1717 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_asynchronous.ets @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); - let encryptData = await cipher.doFinal(plainText); - return encryptData; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); - let decryptData = await decoder.doFinal(cipherText); - return decryptData; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = await symGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function main() { - let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_ecb_asynchronous')) - .width('70%') - .onClick(async () => { - try { - await main(); - this.message = 'SM4_ECBSuccess'; - } catch { - this.message = 'SM4_ECBFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); + let encryptData = await cipher.doFinal(plainText); + return encryptData; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); + let decryptData = await decoder.doFinal(cipherText); + return decryptData; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); + let symKey = await symGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function main() { + let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_ecb_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'SM4_ECBSuccess'; + } catch { + this.message = 'SM4_ECBFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index 5bdb7b760773fc23954490ecf1120b6b1945140e..40e6060e8d0f3035c40e996d982329f52a063b88 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_ecb_encryption_decryption/sm4_ecb_encryption_decryption_synchronous.ets @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); - let encryptData = cipher.doFinalSync(plainText); - return encryptData; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); - let decryptData = decoder.doFinalSync(cipherText); - return decryptData; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = symGenerator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_ecb_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SM4_ECBSuccess'; - } catch { - this.message = 'SM4_ECBFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, null); + let encryptData = cipher.doFinalSync(plainText); + return encryptData; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM4_128|ECB|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, null); + let decryptData = decoder.doFinalSync(cipherText); + return decryptData; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let symGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); + let symKey = symGenerator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + let keyData = new Uint8Array([7, 154, 52, 176, 4, 236, 150, 43, 237, 9, 145, 166, 141, 174, 224, 131]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_ecb_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SM4_ECBSuccess'; + } catch { + this.message = 'SM4_ECBFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets old mode 100755 new mode 100644 index 3917f0a4e909f9d3fc5832e2abd21706e0fc4c98..f8f4b328b248c990f61a71f4ec2e11966f17b8b2 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_asynchronous.ets @@ -1,115 +1,115 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); // 12 bytes - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; - // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 加密消息 -async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let encryptUpdate = await cipher.update(plainText); - // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 - gcmParams.authTag = await cipher.doFinal(null); - return encryptUpdate; -} - -// 解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let decryptUpdate = await decoder.update(cipherText); - // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 - let decryptData = await decoder.doFinal(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - return decryptUpdate; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let sm4Generator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = await sm4Generator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessagePromise(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_gcm_asynchronous')) - .width('70%') - .onClick(async() => { - try { - await main(); - this.message = 'SM4_GCMSuccess'; - } catch { - this.message = 'SM4_GCMFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genGcmParamsSpec() { + let ivBlob = generateRandom(12); // 12 bytes + let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes + let dataAad = new Uint8Array(arr); + let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; + arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes + let dataTag = new Uint8Array(arr); + let tagBlob: cryptoFramework.DataBlob = { + data: dataTag + }; + // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algName: 'GcmParamsSpec' + }; + return gcmParamsSpec; +} + +let gcmParams = genGcmParamsSpec(); + +// 加密消息 +async function encryptMessagePromise(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); + await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); + let encryptUpdate = await cipher.update(plainText); + // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 + gcmParams.authTag = await cipher.doFinal(null); + return encryptUpdate; +} + +// 解密消息 +async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); + await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); + let decryptUpdate = await decoder.update(cipherText); + // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 + let decryptData = await decoder.doFinal(null); + if (decryptData == null) { + console.info('GCM decrypt success, decryptData is null'); + } + return decryptUpdate; +} + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let sm4Generator = cryptoFramework.createSymKeyGenerator('SM4_128'); + let symKey = await sm4Generator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function main() { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = await genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = await encryptMessagePromise(symKey, plainText); + let decryptText = await decryptMessagePromise(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_gcm_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await main(); + this.message = 'SM4_GCMSuccess'; + } catch { + this.message = 'SM4_GCMFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets old mode 100755 new mode 100644 index f4809e31f33fa824cc8231177a79af547688ba45..408afcf7f4b46c5e22f753e9770053f00f58ce26 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_encryption_decryption/sm4_gcm_encryption_decryption_synchronous.ets @@ -1,115 +1,115 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); // 12 bytes - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; - // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 加密消息 -function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let encryptUpdate = cipher.updateSync(plainText); - // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 - gcmParams.authTag = cipher.doFinalSync(null); - return encryptUpdate; -} - -// 解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let decryptUpdate = decoder.updateSync(cipherText); - // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 - let decryptData = decoder.doFinalSync(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - return decryptUpdate; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let sm4Generator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = sm4Generator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'This is a test'; - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessage(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_gcm_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SM4_GCMSuccess'; - } catch { - this.message = 'SM4_GCMFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function generateRandom(len: number) { + let rand = cryptoFramework.createRandom(); + let generateRandSync = rand.generateRandomSync(len); + return generateRandSync; +} + +function genGcmParamsSpec() { + let ivBlob = generateRandom(12); // 12 bytes + let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes + let dataAad = new Uint8Array(arr); + let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; + arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes + let dataTag = new Uint8Array(arr); + let tagBlob: cryptoFramework.DataBlob = { + data: dataTag + }; + // GCM的authTag在加密时从doFinal结果中获取,在解密时填入init函数的params参数中 + let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { + iv: ivBlob, + aad: aadBlob, + authTag: tagBlob, + algName: 'GcmParamsSpec' + }; + return gcmParamsSpec; +} + +let gcmParams = genGcmParamsSpec(); + +// 加密消息 +function encryptMessage(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { + let cipher = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); + cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); + let encryptUpdate = cipher.updateSync(plainText); + // gcm模式加密doFinal时传入空,获得tag数据,并更新至gcmParams对象中。 + gcmParams.authTag = cipher.doFinalSync(null); + return encryptUpdate; +} + +// 解密消息 +function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { + let decoder = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); + decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); + let decryptUpdate = decoder.updateSync(cipherText); + // gcm模式解密doFinal时传入空,验证init时传入的tag数据,如果验证失败会抛出异常。 + let decryptData = decoder.doFinalSync(null); + if (decryptData == null) { + console.info('GCM decrypt success, decryptData is null'); + } + return decryptUpdate; +} + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let sm4Generator = cryptoFramework.createSymKeyGenerator('SM4_128'); + let symKey = sm4Generator.convertKeySync(symKeyBlob); + console.info('convertKeySync success'); + return symKey; +} + +function main() { + let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); + let symKey = genSymKeyByData(keyData); + let message = 'This is a test'; + let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; + let encryptText = encryptMessage(symKey, plainText); + let decryptText = decryptMessage(symKey, encryptText); + if (plainText.data.toString() === decryptText.data.toString()) { + console.info('decrypt ok'); + console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); + } else { + console.error('decrypt failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_gcm_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SM4_GCMSuccess'; + } catch { + this.message = 'SM4_GCMFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets deleted file mode 100755 index 734538cfbd7c1dab5450cf717e9d1deefb1cda0a..0000000000000000000000000000000000000000 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_asynchronous.ets +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; // The GCM authTag is obtained by doFinal() in encryption and passed in params of init() in decryption. - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 分段加密消息 -async function encryptMessageUpdateBySegment(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - await cipher.init(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let cipherText = new Uint8Array(); - for (let i = 0; i < plainText.data.length; i += updateLength) { - let updateMessage = plainText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = await cipher.update(updateMessageBlob); - // 把update的结果拼接起来,得到密文(有些情况下还需拼接doFinal的结果,这取决于分组模式 - // 和填充模式,本例中GCM模式的doFinal结果只包含authTag而不含密文,所以不需要拼接) - let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); - mergeText.set(cipherText); - mergeText.set(updateOutput.data, cipherText.length); - cipherText = mergeText; - } - gcmParams.authTag = await cipher.doFinal(null); - let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; - return cipherBlob; -} - -// 分段解密消息 -async function decryptMessagePromise(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - await decoder.init(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let decryptText = new Uint8Array(); - for (let i = 0; i < cipherText.data.length; i += updateLength) { - let updateMessage = cipherText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = await decoder.update(updateMessageBlob); - // 把update的结果拼接起来,得到明文 - let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); - mergeText.set(decryptText); - mergeText.set(updateOutput.data, decryptText.length); - decryptText = mergeText; - } - let decryptData = await decoder.doFinal(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; - return decryptBlob; -} - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let sm4Generator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = await sm4Generator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function sm4() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = await genSymKeyByData(keyData); - let message = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = await encryptMessageUpdateBySegment(symKey, plainText); - let decryptText = await decryptMessagePromise(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_gcm_segmentation_asynchronous')) - .width('70%') - .onClick(async () => { - try { - await sm4(); - this.message = 'SM4_GCMSegmentationSuccess'; - } catch { - this.message = 'SM4_GCMSegmentationFail'; - } - }) - } - .height('100%') - .width('100%') - } -} \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets deleted file mode 100755 index edeb079d9f27acdb0dd1a4784aa19ab81daedd25..0000000000000000000000000000000000000000 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/ets/pages/sm4_gcm_seg_encryption_decryption/sm4_gcm_seg_encryption_decryption_synchronous.ets +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function generateRandom(len: number) { - let rand = cryptoFramework.createRandom(); - let generateRandSync = rand.generateRandomSync(len); - return generateRandSync; -} - -function genGcmParamsSpec() { - let ivBlob = generateRandom(12); // 12 bytes - let arr = [1, 2, 3, 4, 5, 6, 7, 8]; // 8 bytes - let dataAad = new Uint8Array(arr); - let aadBlob: cryptoFramework.DataBlob = { data: dataAad }; - arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // 16 bytes - let dataTag = new Uint8Array(arr); - let tagBlob: cryptoFramework.DataBlob = { - data: dataTag - }; // The GCM authTag is obtained by doFinal() in encryption and passed in params of init() in decryption. - let gcmParamsSpec: cryptoFramework.GcmParamsSpec = { - iv: ivBlob, - aad: aadBlob, - authTag: tagBlob, - algName: 'GcmParamsSpec' - }; - return gcmParamsSpec; -} - -let gcmParams = genGcmParamsSpec(); - -// 分段加密消息 -function encryptMessageUpdateBySegment(symKey: cryptoFramework.SymKey, plainText: cryptoFramework.DataBlob) { - let cipher = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - cipher.initSync(cryptoFramework.CryptoMode.ENCRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let cipherText = new Uint8Array(); - for (let i = 0; i < plainText.data.length; i += updateLength) { - let updateMessage = plainText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = cipher.updateSync(updateMessageBlob); - // 把update的结果拼接起来,得到密文(有些情况下还需拼接doFinal的结果,这取决于分组模式 - // 和填充模式,本例中GCM模式的doFinal结果只包含authTag而不含密文,所以不需要拼接) - let mergeText = new Uint8Array(cipherText.length + updateOutput.data.length); - mergeText.set(cipherText); - mergeText.set(updateOutput.data, cipherText.length); - cipherText = mergeText; - } - gcmParams.authTag = cipher.doFinalSync(null); - let cipherBlob: cryptoFramework.DataBlob = { data: cipherText }; - return cipherBlob; -} - -// 分段解密消息 -function decryptMessage(symKey: cryptoFramework.SymKey, cipherText: cryptoFramework.DataBlob) { - let decoder = cryptoFramework.createCipher('SM4_128|GCM|PKCS7'); - decoder.initSync(cryptoFramework.CryptoMode.DECRYPT_MODE, symKey, gcmParams); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - let decryptText = new Uint8Array(); - for (let i = 0; i < cipherText.data.length; i += updateLength) { - let updateMessage = cipherText.data.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - let updateOutput = decoder.updateSync(updateMessageBlob); - // 把update的结果拼接起来,得到明文 - let mergeText = new Uint8Array(decryptText.length + updateOutput.data.length); - mergeText.set(decryptText); - mergeText.set(updateOutput.data, decryptText.length); - decryptText = mergeText; - } - let decryptData = decoder.doFinalSync(null); - if (decryptData == null) { - console.info('GCM decrypt success, decryptData is null'); - } - let decryptBlob: cryptoFramework.DataBlob = { data: decryptText }; - return decryptBlob; -} - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let sm4Generator = cryptoFramework.createSymKeyGenerator('SM4_128'); - let symKey = sm4Generator.convertKeySync(symKeyBlob); - console.info('convertKeySync success'); - return symKey; -} - -function main() { - let keyData = new Uint8Array([83, 217, 231, 76, 28, 113, 23, 219, 250, 71, 209, 210, 205, 97, 32, 159]); - let symKey = genSymKeyByData(keyData); - let message = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let plainText: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }; - let encryptText = encryptMessageUpdateBySegment(symKey, plainText); - let decryptText = decryptMessage(symKey, encryptText); - if (plainText.data.toString() === decryptText.data.toString()) { - console.info('decrypt ok'); - console.info('decrypt plainText: ' + buffer.from(decryptText.data).toString('utf-8')); - } else { - console.error('decrypt failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Encryption Decryption Guidance SM4 ArkTs'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_gcm_segmentation_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SM4_GCMSegmentationSuccess'; - } catch { - this.message = 'SM4_GCMSegmentationFail'; - } - }) - } - .height('100%') - .width('100%') - } -} \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DESArkTs.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DESArkTs.test.ets old mode 100755 new mode 100644 index 8a1013fd00faaee5985888af68fd86eda7353cd5..822fd08aa614f2f2e5df3e44d00015784cce5a5a --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DESArkTs.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/EncryptionDecryptionGuidance3DESArkTs.test.ets @@ -1,188 +1,188 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidance3DESArkTsTest() { - describe('encryptionDecryptionGuidance3DESArkTsTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_cbc_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_CBC Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_CBCSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_cbc_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_CBC Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_CBCSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs003', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_ecb_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_ECB Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_ECBSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs004', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_ecb_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_ECB Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_ECBSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs005', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_gcm_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_GCM Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_GCMSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs006', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_gcm_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_GCM Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_GCMSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs006 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),异步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs007', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs007 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_gcm_seg_encryption_decryption_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_GCM Segmentation Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_GCMSegmentationSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs007 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),同步方法 - */ - it('testEncryptionDecryptionGuidance3DESArkTs008', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs008 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm4_gcm_seg_encryption_decryption_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4_GCM Segmentation Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4_GCMSegmentationSuccess')); - console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs008 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidance3DESArkTsTest() { + describe('encryptionDecryptionGuidance3DESArkTsTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_cbc_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_CBC Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_CBCSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_cbc_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_CBC Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_CBCSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs003', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_ecb_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_ECB Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_ECBSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs004', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_ecb_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_ECB Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_ECBSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs005', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_gcm_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_GCM Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_GCMSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs006', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_gcm_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_GCM Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_GCMSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs006 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),异步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs007', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs007 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_gcm_seg_encryption_decryption_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_GCM Segmentation Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_GCMSegmentationSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs007 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),同步方法 + */ + it('testEncryptionDecryptionGuidance3DESArkTs008', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs008 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm4_gcm_seg_encryption_decryption_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4_GCM Segmentation Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4_GCMSegmentationSuccess')); + console.info('uitest: testEncryptionDecryptionGuidance3DESArkTs008 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/ohosTest.md old mode 100755 new mode 100644 index fc78ff5f124806c356012703413e3d3986c5aa94..04e17dac5d8ccdd756696f06bb8abc365edc0c6d --- a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/ohosTest.md @@ -1,15 +1,15 @@ -# 使用SM4对称密钥加解密(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用SM4对称密钥加解密(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(ECB模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(CBC模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(GCM模式)加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),异步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用SM4对称密钥(GCM模式)分段加解密(ArkTS),同步方法 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/screenshots/EncryptionDecryptionGuidanceSM4ArkTs1.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/screenshots/EncryptionDecryptionGuidanceSM4ArkTs1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/screenshots/EncryptionDecryptionGuidanceSM4ArkTs2.png b/code/DocsSample/Security/CryptoArchitectureKit/EncryptionDecryption/EncryptionDecryptionGuidanceSM4ArkTs/screenshots/EncryptionDecryptionGuidanceSM4ArkTs2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 old mode 100755 new mode 100644 index 1cb30c06fa01484ff77be98a76503ac76d77b1c5..02057bf087c007e3f3d3529f8e1f21167352b4c6 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 @@ -1,25 +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.hkdfderivation", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.hkdfderivation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 76a0d27731e7c4ef25b9a4b961b89ae12bbda7de..83ed1e5d1f097d97a516fb2cfba1c3c23830d8ce --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "HKDFDerivation" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "HKDFDerivation" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md old mode 100755 new mode 100644 index 72d1d39386e585a025597aae85b80c21cb283831..45da0eccbe8695e925e7c1ef32180a0960b58c22 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md @@ -1,70 +1,70 @@ -# 使用HKDF进行密钥派生 - -### 介绍 - -本示例主要展示了使用HKDF进行密钥派生通过await、Promis、同步返回场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用HKDF进行密钥派生](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-derivation-using-hkdf.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例HKDFDerivation.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用HKDF进行密钥派生示例代码 - │ │ ├── Await.ets - │ │ ├── Promise.ets - │ │ ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── HKDFDerivation.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用HKDF进行密钥派生 + +### 介绍 + +本示例主要展示了使用HKDF进行密钥派生通过await、Promis、同步返回场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用HKDF进行密钥派生](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-derivation-using-hkdf.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例HKDFDerivation.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用HKDF进行密钥派生示例代码 + │ │ ├── Await.ets + │ │ ├── Promise.ets + │ │ ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── HKDFDerivation.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets old mode 100755 new mode 100644 index 827b06c68efe94ec79bb53d1713dd50a8375a5f3..1b634cc3f82bd9393397f008b90a5d993b9650e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets @@ -1,57 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function kdfAwait() { - let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); - let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); - let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); - let spec: cryptoFramework.HKDFSpec = { - algName: 'HKDF', - key: keyData, - salt: saltData, - info: infoData, - keySize: 32 - }; - let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); - let secret = await kdf.generateSecret(spec); - console.info('key derivation output is ' + secret.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'Await'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_await')) - .width('70%') - .onClick(async () => { - try { - await kdfAwait(); - this.message = 'Await Success'; - } catch { - this.message = 'Await Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function kdfAwait() { + let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); + let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); + let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); + let spec: cryptoFramework.HKDFSpec = { + algName: 'HKDF', + key: keyData, + salt: saltData, + info: infoData, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); + let secret = await kdf.generateSecret(spec); + console.info('key derivation output is ' + secret.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'Await'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_await')) + .width('70%') + .onClick(async () => { + try { + await kdfAwait(); + this.message = 'Await Success'; + } catch { + this.message = 'Await Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets old mode 100755 new mode 100644 index d4222fbff82e780cfebb6b97a0e61496c826f9d8..ad7f7c3f58ab9ced9b9be51c644a6a6489430119 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { buffer } from '@kit.ArkTS'; - -function kdfPromise() { - let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); - let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); - let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); - let spec: cryptoFramework.HKDFSpec = { - algName: 'HKDF', - key: keyData, - salt: saltData, - info: infoData, - keySize: 32 - }; - let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); - let kdfPromise = kdf.generateSecret(spec); - kdfPromise.then((secret) => { - console.info('key derivation output is ' + secret.data); - }).catch((error: BusinessError) => { - console.error('key derivation error.'); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_promise')) - .width('70%') - .onClick(() => { - try { - kdfPromise(); - this.message = 'Promise Success'; - } catch { - this.message = 'Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { buffer } from '@kit.ArkTS'; + +function kdfPromise() { + let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); + let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); + let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); + let spec: cryptoFramework.HKDFSpec = { + algName: 'HKDF', + key: keyData, + salt: saltData, + info: infoData, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); + let kdfPromise = kdf.generateSecret(spec); + kdfPromise.then((secret) => { + console.info('key derivation output is ' + secret.data); + }).catch((error: BusinessError) => { + console.error('key derivation error.'); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_promise')) + .width('70%') + .onClick(() => { + try { + kdfPromise(); + this.message = 'Promise Success'; + } catch { + this.message = 'Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets old mode 100755 new mode 100644 index 27285f67ce3491abf5762a314f6576081b403d70..93f9b7b37acbf822f2dd620d46ccd27b40800ca3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets @@ -1,57 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function kdfSync() { - let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); - let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); - let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); - let spec: cryptoFramework.HKDFSpec = { - algName: 'HKDF', - key: keyData, - salt: saltData, - info: infoData, - keySize: 32 - }; - let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); - let secret = kdf.generateSecretSync(spec); - console.info('[Sync]key derivation output is ' + secret.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sync')) - .width('70%') - .onClick(() => { - try { - kdfSync(); - this.message = 'Sync Success'; - } catch { - this.message = 'Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function kdfSync() { + let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); + let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); + let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); + let spec: cryptoFramework.HKDFSpec = { + algName: 'HKDF', + key: keyData, + salt: saltData, + info: infoData, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); + let secret = kdf.generateSecretSync(spec); + console.info('[Sync]key derivation output is ' + secret.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sync')) + .width('70%') + .onClick(() => { + try { + kdfSync(); + this.message = 'Sync Success'; + } catch { + this.message = 'Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets old mode 100755 new mode 100644 index 3a243a0a37c433c3330056e9036495de6f274938..8506514c41de52d50ad132a86c96a1a02848c765 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets @@ -1,98 +1,98 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function hKDFDerivationTest() { - describe('hKDFDerivationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用HKDF进行密钥派生,通过await返回结果 - */ - it('testHKDFDerivation001', 0, async () => { - console.info('uitest: testHKDFDerivation001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Await')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Await')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Await Success')); - console.info('uitest: testHKDFDerivation001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用HKDF进行密钥派生,通过Promise返回结果 - */ - it('testHKDFDerivation002', 0, async () => { - console.info('uitest: testHKDFDerivation002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Promise Success')); - console.info('uitest: testHKDFDerivation002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用HKDF进行密钥派生,通过同步方式返回结果 - */ - it('testHKDFDerivation003', 0, async () => { - console.info('uitest: testHKDFDerivation003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Sync Success')); - console.info('uitest: testHKDFDerivation003 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function hKDFDerivationTest() { + describe('hKDFDerivationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用HKDF进行密钥派生,通过await返回结果 + */ + it('testHKDFDerivation001', 0, async () => { + console.info('uitest: testHKDFDerivation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Await')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Await')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Await Success')); + console.info('uitest: testHKDFDerivation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用HKDF进行密钥派生,通过Promise返回结果 + */ + it('testHKDFDerivation002', 0, async () => { + console.info('uitest: testHKDFDerivation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Promise Success')); + console.info('uitest: testHKDFDerivation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用HKDF进行密钥派生,通过同步方式返回结果 + */ + it('testHKDFDerivation003', 0, async () => { + console.info('uitest: testHKDFDerivation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Sync Success')); + console.info('uitest: testHKDFDerivation003 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md old mode 100755 new mode 100644 index 709ea03893831d4b3c06b851f268d67ae2ae0d08..b60d8dee467228df4088a460dd51f4cf28d122ce --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md @@ -1,10 +1,10 @@ -# 使用HKDF进行密钥派生测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用HKDF进行密钥派生,通过await返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用HKDF进行密钥派生,通过Promise返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用HKDF进行密钥派生测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用HKDF进行密钥派生,通过await返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用HKDF进行密钥派生,通过Promise返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用HKDF进行密钥派生,通过同步方式返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 old mode 100755 new mode 100644 index c0f56cab0fc108fb56a7ad5151c8039b6b1c883f..43ce2547493eec2e4bf24f3a28d9cadf943f0961 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 @@ -1,25 +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.pbkdf2derivation", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.pbkdf2derivation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index f1111d634384ff79507f983183994d5ccd81c8a0..1c4fc7b6832f0bcf3ecf82109fe716399c3b9b69 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "PBKDF2Derivation" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "PBKDF2Derivation" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md old mode 100755 new mode 100644 index 2dd89e382f548f2d4803090893434642b50fbcf6..dc9f804a39b06a3b91aa079ed74595f7add5cbfa --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md @@ -1,70 +1,70 @@ -# 使用PBKDF2进行密钥派生 - -### 介绍 - -本示例主要展示了使用PBKDF2进行密钥派生(通过await、Promise、同步方式返回结果)的场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用PBKDF2进行密钥派生](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-derivation-using-pbkdf2.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例PBKDF2Derivation.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用PBKDF2进行密钥派生示例代码 - │ │ ├── Await.ets - │ │ ├── Promise.ets - │ │ ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── PBKDF2Derivation.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用PBKDF2进行密钥派生 + +### 介绍 + +本示例主要展示了使用PBKDF2进行密钥派生(通过await、Promise、同步方式返回结果)的场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用PBKDF2进行密钥派生](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-derivation-using-pbkdf2.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例PBKDF2Derivation.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用PBKDF2进行密钥派生示例代码 + │ │ ├── Await.ets + │ │ ├── Promise.ets + │ │ ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── PBKDF2Derivation.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets old mode 100755 new mode 100644 index 043464ce92dc7b1ce171df8d3dcd57c0579f4ed8..6b9f72de295c4b81b283a57e48a051fe71bbedff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function kdfAwait() { - let spec: cryptoFramework.PBKDF2Spec = { - algName: 'PBKDF2', - password: '123456', - salt: new Uint8Array(16), - iterations: 10000, - keySize: 32 - }; - let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); - let secret = await kdf.generateSecret(spec); - console.info('key derivation output is ' + secret.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'Await'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_await')) - .width('70%') - .onClick(async () => { - try { - await kdfAwait(); - this.message = 'Await Success'; - } catch { - this.message = 'Await Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function kdfAwait() { + let spec: cryptoFramework.PBKDF2Spec = { + algName: 'PBKDF2', + password: '123456', + salt: new Uint8Array(16), + iterations: 10000, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); + let secret = await kdf.generateSecret(spec); + console.info('key derivation output is ' + secret.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'Await'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_await')) + .width('70%') + .onClick(async () => { + try { + await kdfAwait(); + this.message = 'Await Success'; + } catch { + this.message = 'Await Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets old mode 100755 new mode 100644 index e41b03f51f82115b465aec7ff5a9b3d58c4aa40f..b17c9c1fd4440e69e718149cb18f1de524f83f64 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets @@ -1,58 +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. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -function kdfPromise() { - let spec: cryptoFramework.PBKDF2Spec = { - algName: 'PBKDF2', - password: '123456', - salt: new Uint8Array(16), - iterations: 10000, - keySize: 32 - }; - let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); - let kdfPromise = kdf.generateSecret(spec); - kdfPromise.then((secret) => { - console.info('key derivation output is ' + secret.data); - }).catch((error: BusinessError) => { - console.error('key derivation error.'); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_promise')) - .width('70%') - .onClick(() => { - try { - kdfPromise(); - this.message = 'Promise Success'; - } catch { - this.message = 'Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function kdfPromise() { + let spec: cryptoFramework.PBKDF2Spec = { + algName: 'PBKDF2', + password: '123456', + salt: new Uint8Array(16), + iterations: 10000, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); + let kdfPromise = kdf.generateSecret(spec); + kdfPromise.then((secret) => { + console.info('key derivation output is ' + secret.data); + }).catch((error: BusinessError) => { + console.error('key derivation error.'); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_promise')) + .width('70%') + .onClick(() => { + try { + kdfPromise(); + this.message = 'Promise Success'; + } catch { + this.message = 'Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets old mode 100755 new mode 100644 index eec7a22fb2565cad382fb9cdee63389e4c2eafe6..14add541d11cf5f2860876b6121b3075b2e0a96f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function kdfSync() { - let spec: cryptoFramework.PBKDF2Spec = { - algName: 'PBKDF2', - password: '123456', - salt: new Uint8Array(16), - iterations: 10000, - keySize: 32 - }; - let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); - let secret = kdf.generateSecretSync(spec); - console.info('[Sync]key derivation output is ' + secret.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sync')) - .width('70%') - .onClick(() => { - try { - kdfSync(); - this.message = 'Sync Success'; - } catch { - this.message = 'Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function kdfSync() { + let spec: cryptoFramework.PBKDF2Spec = { + algName: 'PBKDF2', + password: '123456', + salt: new Uint8Array(16), + iterations: 10000, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); + let secret = kdf.generateSecretSync(spec); + console.info('[Sync]key derivation output is ' + secret.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sync')) + .width('70%') + .onClick(() => { + try { + kdfSync(); + this.message = 'Sync Success'; + } catch { + this.message = 'Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets old mode 100755 new mode 100644 index 43d53397c987d57475ed841091588ef49fcd3181..e62d26ac0d5bb9b3dbfa75a9c4ce07ac07ddf0a8 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets @@ -1,98 +1,98 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function pBKDF2DerivationTest() { - describe('pBKDF2DerivationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用PBKDF2进行密钥派生,通过await返回 - */ - it('testPBKDF2Derivation001', 0, async () => { - console.info('uitest: testPBKDF2Derivation001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Await')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Await')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Await Success')); - console.info('uitest: testPBKDF2Derivation001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用PBKDF2进行密钥派生,通过Promise返回 - */ - it('testPBKDF2Derivation002', 0, async () => { - console.info('uitest: testPBKDF2Derivation002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Promise Success')); - console.info('uitest: testPBKDF2Derivation002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用PBKDF2进行密钥派生,通过同步方式 - */ - it('testPBKDF2Derivation003', 0, async () => { - console.info('uitest: testPBKDF2Derivation003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Sync Success')); - console.info('uitest: testPBKDF2Derivation003 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function pBKDF2DerivationTest() { + describe('pBKDF2DerivationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用PBKDF2进行密钥派生,通过await返回 + */ + it('testPBKDF2Derivation001', 0, async () => { + console.info('uitest: testPBKDF2Derivation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Await')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Await')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Await Success')); + console.info('uitest: testPBKDF2Derivation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用PBKDF2进行密钥派生,通过Promise返回 + */ + it('testPBKDF2Derivation002', 0, async () => { + console.info('uitest: testPBKDF2Derivation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Promise Success')); + console.info('uitest: testPBKDF2Derivation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用PBKDF2进行密钥派生,通过同步方式 + */ + it('testPBKDF2Derivation003', 0, async () => { + console.info('uitest: testPBKDF2Derivation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Sync Success')); + console.info('uitest: testPBKDF2Derivation003 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md old mode 100755 new mode 100644 index 9cbfdf11d4c65e1e4bedf5735dbfbb3f50c25cb8..96277ce9f2b207b505ca7af84ff10cd821585b85 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md @@ -1,10 +1,10 @@ -# 使用PBKDF2进行密钥派生测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用PBKDF2进行密钥派生,通过await返回 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用PBKDF2进行密钥派生,通过Promise返回 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用PBKDF2进行密钥派生测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用PBKDF2进行密钥派生,通过await返回 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用PBKDF2进行密钥派生,通过Promise返回 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用PBKDF2进行密钥派生,通过同步方式 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/app.json5 old mode 100755 new mode 100644 index 600c7611c1b62b088c781e70d82b12c9964d6a4a..b086c9bbef4e571f09e93d859f40ba4958df630d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/app.json5 @@ -1,25 +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.binarydataconvertasymmetrickeypair", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.binarydataconvertasymmetrickeypair", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 8464f1db0e9b7068f204387c6d090efd72260d85..5c28c864ec60d1f5baf8895c5047fe182264e7e9 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "BinaryDataConvertAsymmetricKeyPair" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "BinaryDataConvertAsymmetricKeyPair" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/README.md old mode 100755 new mode 100644 index d4a1a4c537ebb0009b9b3a3bb3a68c754eea12a9..9f2a47982921f0d5b4a7b3cc861ce542affe3f13 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/README.md @@ -1,81 +1,81 @@ -# 指定二进制数据转换非对称密钥对(C/C++) - -### 介绍 - -以RSA、ECC、SM2为例,根据指定的对称密钥二进制数据,生成非对称密钥对(OH_CryptoKeyPair),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 - -本示例主要展示了指定二进制数据转换RSA密钥对、 指定二进制数据转换ECC密钥对、 指定二进制数据转换SM2密钥对的场景。该工程中展示的代码详细描述可查如下链接。 - -- [指定二进制数据转换非对称密钥对(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-asym-key-pair-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例BinaryDataConvertAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── ecc.cpp - │ │ | ├── file.h - │ │ | ├── rsa.cpp - │ │ | ├── sm2.cpp - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 指定二进制数据转换非对称密钥对(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── BinaryDataConvertAsymmetricKeyPair.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 指定二进制数据转换非对称密钥对(C/C++) + +### 介绍 + +以RSA、ECC、SM2为例,根据指定的对称密钥二进制数据,生成非对称密钥对(OH_CryptoKeyPair),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 + +本示例主要展示了指定二进制数据转换RSA密钥对、 指定二进制数据转换ECC密钥对、 指定二进制数据转换SM2密钥对的场景。该工程中展示的代码详细描述可查如下链接。 + +- [指定二进制数据转换非对称密钥对(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-asym-key-pair-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例BinaryDataConvertAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── ecc.cpp + │ │ | ├── file.h + │ │ | ├── rsa.cpp + │ │ | ├── sm2.cpp + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 指定二进制数据转换非对称密钥对(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── BinaryDataConvertAsymmetricKeyPair.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 69dea61c9437246601263481526f1b9649b4119e..2f818a9fc1a0b2162b3b38a6f0500aa03f5d4d11 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(BinaryDataConvertAsymmetricKeyPair) - -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 types/project/ecc.cpp types/project/rsa.cpp types/project/sm2.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(BinaryDataConvertAsymmetricKeyPair) + +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 types/project/ecc.cpp types/project/rsa.cpp types/project/sm2.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 14fd46456a349b3a3e70e6cac6d6d979d645619b..83bb0807e78a175d21df6da6d4b816713416466a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "napi/native_api.h" -#include "types/project/file.h" - -static napi_value NAPI_Global_doTestDataCovertAsymKey(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestDataCovertAsymKey(), &ret); - return ret; -} - -static napi_value NAPI_Global_doAsymEccCovert(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doAsymEccCovert(), &ret); - return ret; -} - -static napi_value NAPI_Global_doAsymSm2Covert(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doAsymSm2Covert(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"doTestDataCovertAsymKey", nullptr, NAPI_Global_doTestDataCovertAsymKey, nullptr, nullptr, nullptr, - napi_default, nullptr}, - {"doAsymEccCovert", nullptr, NAPI_Global_doAsymEccCovert, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"doAsymSm2Covert", nullptr, NAPI_Global_doAsymSm2Covert, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTestDataCovertAsymKey(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestDataCovertAsymKey(), &ret); + return ret; +} + +static napi_value NAPI_Global_doAsymEccCovert(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doAsymEccCovert(), &ret); + return ret; +} + +static napi_value NAPI_Global_doAsymSm2Covert(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doAsymSm2Covert(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"doTestDataCovertAsymKey", nullptr, NAPI_Global_doTestDataCovertAsymKey, nullptr, nullptr, nullptr, + napi_default, nullptr}, + {"doAsymEccCovert", nullptr, NAPI_Global_doAsymEccCovert, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"doAsymSm2Covert", nullptr, NAPI_Global_doAsymSm2Covert, 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 06af395920b0760cfebcc0cb54a84999b5c85f2e..195f2920dee5e401c0f0eb2b81b862849dd6f49d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,20 +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. - */ - -export const doTestDataCovertAsymKey: () => number; - -export const doAsymEccCovert: () => number; - +/* + * 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 doTestDataCovertAsymKey: () => number; + +export const doAsymEccCovert: () => number; + export const doAsymSm2Covert: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/ecc.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/ecc.cpp old mode 100755 new mode 100644 index 4bcba79ee37920d382c1596ca010612df29933d8..1a05b95ba96b058f960b121f190149e8462ea908 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/ecc.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/ecc.cpp @@ -1,53 +1,53 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" -#include "file.h" - -OH_Crypto_ErrCode doAsymEccCovert() -{ - OH_CryptoAsymKeyGenerator *ctx = nullptr; - OH_Crypto_ErrCode ret; - - ret = OH_CryptoAsymKeyGenerator_Create("ECC256", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - - uint8_t ecc224PubKeyBlobData[] = {48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, - 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 157, 58, 248, 205, 95, - 171, 229, 33, 116, 44, 192, 12, 115, 119, 84, 156, 128, 56, 180, 246, 84, - 43, 33, 244, 224, 221, 181, 154, 155, 222, 157, 124, 131, 217, 214, 134, 199, - 155, 61, 196, 203, 107, 13, 227, 121, 57, 199, 109, 220, 103, 55, 78, 148, - 185, 226, 212, 162, 31, 66, 201, 50, 129, 1, 156}; - - uint8_t ecc224PriKeyBlobData[] = {48, 49, 2, 1, 1, 4, 32, 255, 121, 33, 196, 188, 159, 112, 149, 146, 107, - 243, 78, 152, 214, 12, 119, 87, 199, 207, 57, 116, 64, 150, 240, 121, 22, 88, - 138, 196, 71, 70, 222, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7}; - Crypto_DataBlob pubBlob = {.data = ecc224PubKeyBlobData, .len = sizeof(ecc224PubKeyBlobData)}; - Crypto_DataBlob priBlob = {.data = ecc224PriKeyBlobData, .len = sizeof(ecc224PriKeyBlobData)}; - - OH_CryptoKeyPair *dupKeyPair = nullptr; - ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &pubBlob, &priBlob, &dupKeyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - return ret; - } - - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" +#include "file.h" + +OH_Crypto_ErrCode doAsymEccCovert() +{ + OH_CryptoAsymKeyGenerator *ctx = nullptr; + OH_Crypto_ErrCode ret; + + ret = OH_CryptoAsymKeyGenerator_Create("ECC256", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + + uint8_t ecc224PubKeyBlobData[] = {48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, + 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 157, 58, 248, 205, 95, + 171, 229, 33, 116, 44, 192, 12, 115, 119, 84, 156, 128, 56, 180, 246, 84, + 43, 33, 244, 224, 221, 181, 154, 155, 222, 157, 124, 131, 217, 214, 134, 199, + 155, 61, 196, 203, 107, 13, 227, 121, 57, 199, 109, 220, 103, 55, 78, 148, + 185, 226, 212, 162, 31, 66, 201, 50, 129, 1, 156}; + + uint8_t ecc224PriKeyBlobData[] = {48, 49, 2, 1, 1, 4, 32, 255, 121, 33, 196, 188, 159, 112, 149, 146, 107, + 243, 78, 152, 214, 12, 119, 87, 199, 207, 57, 116, 64, 150, 240, 121, 22, 88, + 138, 196, 71, 70, 222, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7}; + Crypto_DataBlob pubBlob = {.data = ecc224PubKeyBlobData, .len = sizeof(ecc224PubKeyBlobData)}; + Crypto_DataBlob priBlob = {.data = ecc224PriKeyBlobData, .len = sizeof(ecc224PriKeyBlobData)}; + + OH_CryptoKeyPair *dupKeyPair = nullptr; + ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &pubBlob, &priBlob, &dupKeyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + return ret; + } + + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 7d25e738229bcf5f1e5cfe0bacb16278c48aebab..0ad709e29609ed4ceba9aa63b03dbbe0aceec100 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h @@ -1,24 +1,24 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestDataCovertAsymKey(); -OH_Crypto_ErrCode doAsymEccCovert(); -OH_Crypto_ErrCode doAsymSm2Covert(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestDataCovertAsymKey(); +OH_Crypto_ErrCode doAsymEccCovert(); +OH_Crypto_ErrCode doAsymSm2Covert(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp old mode 100755 new mode 100644 index e378aed8c7e84eba7cb9e5cc702b6e9efc36a9a3..dc3a8ca544727b3acd4c634b4532a9b00caf149d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp @@ -1,51 +1,51 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" -#include "file.h" - -OH_Crypto_ErrCode doTestDataCovertAsymKey() -{ - OH_CryptoAsymKeyGenerator *ctx = nullptr; - OH_Crypto_ErrCode ret; - - ret = OH_CryptoAsymKeyGenerator_Create("RSA1024|PRIMES_2", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - - uint8_t rsaDatablob[] = {48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, - 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 235, 184, 151, 247, 130, 216, 140, - 187, 64, 124, 219, 137, 140, 184, 53, 137, 216, 105, 156, 141, 137, 165, 30, 80, 232, - 55, 96, 46, 23, 237, 197, 123, 121, 27, 240, 190, 14, 111, 237, 172, 67, 42, 47, - 164, 226, 248, 211, 157, 213, 194, 131, 109, 181, 41, 173, 217, 127, 252, 121, 126, 26, - 130, 55, 4, 134, 104, 73, 5, 132, 91, 214, 146, 232, 64, 99, 87, 33, 222, 155, - 159, 9, 59, 212, 144, 46, 183, 83, 89, 220, 189, 148, 13, 176, 5, 139, 156, 230, - 143, 16, 152, 79, 36, 8, 112, 40, 174, 35, 83, 82, 57, 137, 87, 123, 215, 99, - 199, 66, 131, 150, 31, 143, 56, 252, 2, 73, 41, 70, 159, 2, 3, 1, 0, 1}; - Crypto_DataBlob retBlob = {.data = rsaDatablob, .len = sizeof(rsaDatablob)}; - - OH_CryptoKeyPair *dupKeyPair = nullptr; - ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &retBlob, nullptr, &dupKeyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - return ret; - } - - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; -} +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" +#include "file.h" + +OH_Crypto_ErrCode doTestDataCovertAsymKey() +{ + OH_CryptoAsymKeyGenerator *ctx = nullptr; + OH_Crypto_ErrCode ret; + + ret = OH_CryptoAsymKeyGenerator_Create("RSA1024|PRIMES_2", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + + uint8_t rsaDatablob[] = {48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, + 3, 129, 141, 0, 48, 129, 137, 2, 129, 129, 0, 235, 184, 151, 247, 130, 216, 140, + 187, 64, 124, 219, 137, 140, 184, 53, 137, 216, 105, 156, 141, 137, 165, 30, 80, 232, + 55, 96, 46, 23, 237, 197, 123, 121, 27, 240, 190, 14, 111, 237, 172, 67, 42, 47, + 164, 226, 248, 211, 157, 213, 194, 131, 109, 181, 41, 173, 217, 127, 252, 121, 126, 26, + 130, 55, 4, 134, 104, 73, 5, 132, 91, 214, 146, 232, 64, 99, 87, 33, 222, 155, + 159, 9, 59, 212, 144, 46, 183, 83, 89, 220, 189, 148, 13, 176, 5, 139, 156, 230, + 143, 16, 152, 79, 36, 8, 112, 40, 174, 35, 83, 82, 57, 137, 87, 123, 215, 99, + 199, 66, 131, 150, 31, 143, 56, 252, 2, 73, 41, 70, 159, 2, 3, 1, 0, 1}; + Crypto_DataBlob retBlob = {.data = rsaDatablob, .len = sizeof(rsaDatablob)}; + + OH_CryptoKeyPair *dupKeyPair = nullptr; + ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &retBlob, nullptr, &dupKeyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + return ret; + } + + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp old mode 100755 new mode 100644 index b6ad4f293a26385736c6ceabe7b42ef00b6f47d1..bb562a88a1eebb97ee85b3705415760a5063e5cf --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp @@ -1,52 +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. - */ - -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" -#include "file.h" - -OH_Crypto_ErrCode doAsymSm2Covert() -{ - OH_CryptoAsymKeyGenerator *ctx = nullptr; - OH_CryptoKeyPair *dupKeyPair = nullptr; - OH_Crypto_ErrCode ret; - - ret = OH_CryptoAsymKeyGenerator_Create("SM2_256", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - - uint8_t sm2PubKeyBlobData[] = {48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, - 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 157, 58, 248, 205, 95, - 171, 229, 33, 116, 44, 192, 12, 115, 119, 84, 156, 128, 56, 180, 246, 84, - 43, 33, 244, 224, 221, 181, 154, 155, 222, 157, 124, 131, 217, 214, 134, 199, - 155, 61, 196, 203, 107, 13, 227, 121, 57, 199, 109, 220, 103, 55, 78, 148, - 185, 226, 212, 162, 31, 66, 201, 50, 129, 1, 156}; - - uint8_t sm2PriKeyBlobData[] = {48, 49, 2, 1, 1, 4, 32, 255, 121, 33, 196, 188, 159, 112, 149, 146, 107, - 243, 78, 152, 214, 12, 119, 87, 199, 207, 57, 116, 64, 150, 240, 121, 22, 88, - 138, 196, 71, 70, 222, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7}; - Crypto_DataBlob pubBlob = {.data = sm2PubKeyBlobData, .len = sizeof(sm2PubKeyBlobData)}; - Crypto_DataBlob priBlob = {.data = sm2PriKeyBlobData, .len = sizeof(sm2PriKeyBlobData)}; - ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &pubBlob, &priBlob, &dupKeyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - return ret; - } - - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" +#include "file.h" + +OH_Crypto_ErrCode doAsymSm2Covert() +{ + OH_CryptoAsymKeyGenerator *ctx = nullptr; + OH_CryptoKeyPair *dupKeyPair = nullptr; + OH_Crypto_ErrCode ret; + + ret = OH_CryptoAsymKeyGenerator_Create("SM2_256", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + + uint8_t sm2PubKeyBlobData[] = {48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, + 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 157, 58, 248, 205, 95, + 171, 229, 33, 116, 44, 192, 12, 115, 119, 84, 156, 128, 56, 180, 246, 84, + 43, 33, 244, 224, 221, 181, 154, 155, 222, 157, 124, 131, 217, 214, 134, 199, + 155, 61, 196, 203, 107, 13, 227, 121, 57, 199, 109, 220, 103, 55, 78, 148, + 185, 226, 212, 162, 31, 66, 201, 50, 129, 1, 156}; + + uint8_t sm2PriKeyBlobData[] = {48, 49, 2, 1, 1, 4, 32, 255, 121, 33, 196, 188, 159, 112, 149, 146, 107, + 243, 78, 152, 214, 12, 119, 87, 199, 207, 57, 116, 64, 150, 240, 121, 22, 88, + 138, 196, 71, 70, 222, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7}; + Crypto_DataBlob pubBlob = {.data = sm2PubKeyBlobData, .len = sizeof(sm2PubKeyBlobData)}; + Crypto_DataBlob priBlob = {.data = sm2PriKeyBlobData, .len = sizeof(sm2PriKeyBlobData)}; + ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &pubBlob, &priBlob, &dupKeyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + return ret; + } + + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 4ed1e2a132237c985197aa4b044d04584ad996db..212c56b02dcdd5ac6600f8cc21c6a6126c37c1f9 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'BinaryDataConvertAsymmetricKeyPair'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doTestDataCovertAsymKey(); - this.message = 'Call RSA Success Result:' + ret.toString(); - }) - Button($r('app.string.call_ecc')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doAsymEccCovert(); - this.message = 'Call ECC Success Result:' + ret.toString(); - }) - Button($r('app.string.call_sm2')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doAsymSm2Covert(); - this.message = 'Call SM2 Success Result:' + ret.toString(); - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { + @State message: string = 'BinaryDataConvertAsymmetricKeyPair'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doTestDataCovertAsymKey(); + this.message = 'Call RSA Success Result:' + ret.toString(); + }) + Button($r('app.string.call_ecc')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doAsymEccCovert(); + this.message = 'Call ECC Success Result:' + ret.toString(); + }) + Button($r('app.string.call_sm2')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doAsymSm2Covert(); + this.message = 'Call SM2 Success Result:' + ret.toString(); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPair.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPair.test.ets old mode 100755 new mode 100644 index 9cc07e33f7f1b7a32684ccc37e670c68f3749a27..34b6b3ab20f6d70b2f579a1c59de26a12c973a79 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPair.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPair.test.ets @@ -1,86 +1,86 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function binaryDataConvertAsymmetricKeyPairTest() { - describe('binaryDataConvertAsymmetricKeyPairTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,指定二进制数据转换RSA密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPair001', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPair001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call RSA')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call RSA Success Result:0')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPair001 end'); - }) - - /** - * 点击按钮,指定二进制数据转换ECC密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPair002', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPair002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call ECC')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call ECC Success Result:0')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPair002 end'); - }) - - /** - * 点击按钮,指定二进制数据转换SM2密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPair003', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPair003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM2')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call SM2 Success Result:0')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPair003 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function binaryDataConvertAsymmetricKeyPairTest() { + describe('binaryDataConvertAsymmetricKeyPairTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,指定二进制数据转换RSA密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPair001', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPair001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call RSA')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call RSA Success Result:0')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPair001 end'); + }) + + /** + * 点击按钮,指定二进制数据转换ECC密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPair002', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPair002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call ECC')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call ECC Success Result:0')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPair002 end'); + }) + + /** + * 点击按钮,指定二进制数据转换SM2密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPair003', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPair003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM2')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call SM2 Success Result:0')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPair003 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/ohosTest.md old mode 100755 new mode 100644 index 9f5f6d82ffdc26058237843185bb7fb453a44577..aea3fe60ba7293aab2386a024dc2fb9be99cdf0f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/ohosTest.md @@ -1,10 +1,10 @@ -# 指定二进制数据转换非对称密钥对(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,指定二进制数据转换RSA密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换ECC密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 指定二进制数据转换非对称密钥对(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,指定二进制数据转换RSA密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换ECC密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,指定二进制数据转换SM2密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/screenshots/BinaryDataConvertAsymmetricKeyPair1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/screenshots/BinaryDataConvertAsymmetricKeyPair1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/screenshots/BinaryDataConvertAsymmetricKeyPair2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPair/screenshots/BinaryDataConvertAsymmetricKeyPair2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/app.json5 old mode 100755 new mode 100644 index 9920c5d64d5da1ae76da38d8e8684ae670f05fd4..fd806431dd99db813853f54da03a9e8b22d85370 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/app.json5 @@ -1,25 +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.binarydataconvertasymmetrickeypairarkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.binarydataconvertasymmetrickeypairarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index f74d73da1679686c9e33d50bb076ab238c567256..2062a7c594bfbd909b9f9054647b24d796732b51 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "BinaryDataConvertAsymmetricKeyPairArkTS" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "BinaryDataConvertAsymmetricKeyPairArkTS" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/README.md old mode 100755 new mode 100644 index 8bc1aa6db7e3592db7923621a2807be254567604..24239da1e99af991153a14095eba0dff81a432c9 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/README.md @@ -1,80 +1,80 @@ -# 指定二进制数据转换非对称密钥对(ArkTS) - -### 介绍 - -以RSA、ECC、SM2为例,根据指定的对称密钥二进制数据,生成非对称密钥对(KeyPair),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 - -本示例主要展示了指定二进制数据转换RSA密钥对、指定二进制数据转换ECC密钥对、 指定PKCS8二进制数据转换ECC私钥和指定二进制数据转换SM2密钥对场景。该工程中展示的代码详细描述可查如下链接。 - -- [ 指定二进制数据转换非对称密钥对(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-asym-key-pair.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例BinaryDataConvertAsymmetricKeyPairArkTS.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── ecc - │ │ | ├── Callback.ets - │ │ | ├── Sync.ets - │ │ ├── pkcs8ecc - │ │ | ├── PKCS8ECC.ets - │ │ ├── rsa - │ │ | ├── Callback.ets - │ │ | ├── Sync.ets - │ │ ├── sm2 - │ │ | ├── Callback.ets - │ │ | ├── Sync.ets - │ │ ├── Index.ets // 指定二进制数据转换非对称密钥对(ArkTS)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── BinaryDataConvertAsymmetricKeyPairArkTS.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 指定二进制数据转换非对称密钥对(ArkTS) + +### 介绍 + +以RSA、ECC、SM2为例,根据指定的对称密钥二进制数据,生成非对称密钥对(KeyPair),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 + +本示例主要展示了指定二进制数据转换RSA密钥对、指定二进制数据转换ECC密钥对、 指定PKCS8二进制数据转换ECC私钥和指定二进制数据转换SM2密钥对场景。该工程中展示的代码详细描述可查如下链接。 + +- [ 指定二进制数据转换非对称密钥对(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-asym-key-pair.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例BinaryDataConvertAsymmetricKeyPairArkTS.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── ecc + │ │ | ├── Callback.ets + │ │ | ├── Sync.ets + │ │ ├── pkcs8ecc + │ │ | ├── PKCS8ECC.ets + │ │ ├── rsa + │ │ | ├── Callback.ets + │ │ | ├── Sync.ets + │ │ ├── sm2 + │ │ | ├── Callback.ets + │ │ | ├── Sync.ets + │ │ ├── Index.ets // 指定二进制数据转换非对称密钥对(ArkTS)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── BinaryDataConvertAsymmetricKeyPairArkTS.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Callback.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Callback.ets old mode 100755 new mode 100644 index a11f0c543a1f6658f533891b6e5c4211909b1e2f..c9f72cbf7745de4fb3564e8c7c18d46ae21c2dc3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Callback.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Callback.ets @@ -1,61 +1,61 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function convertEccAsyKey() { - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, - 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, - 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, - 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, - 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; - let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); - generator.convertKey(pubKeyBlob, priKeyBlob, (error, data) => { - if (error) { - console.error(`convertKey failed, ${error.code}, ${error.message}`); - return; - } - console.info('convertKey success'); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'ECC Callback'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_ecc_callback')) - .width('70%') - .onClick(() => { - try { - convertEccAsyKey(); - this.message = 'ECC Callback Success'; - } catch { - this.message = 'ECC Callback Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function convertEccAsyKey() { + let pubKeyArray = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, + 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, + 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, + 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); + let priKeyArray = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, + 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; + let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); + generator.convertKey(pubKeyBlob, priKeyBlob, (error, data) => { + if (error) { + console.error(`convertKey failed, ${error.code}, ${error.message}`); + return; + } + console.info('convertKey success'); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'ECC Callback'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecc_callback')) + .width('70%') + .onClick(() => { + try { + convertEccAsyKey(); + this.message = 'ECC Callback Success'; + } catch { + this.message = 'ECC Callback Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Sync.ets old mode 100755 new mode 100644 index 3c614fc4fcec0d1fca91968561f662e1e873d617..7b6e6baf89e87701a40ead75f9b01daf274538b6 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/ecc/Sync.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function convertECCAsyKeySync() { - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, - 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, - 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, - 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, - 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; - let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); - try { - let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); - if (keyPair != null) { - console.info('convertKeySync success'); - } - } catch (e) { - console.error(`get key pair failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'ECC Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_ecc_sync')) - .width('70%') - .onClick(() => { - try { - convertECCAsyKeySync(); - this.message = 'ECC Sync Success'; - } catch { - this.message = 'ECC Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function convertECCAsyKeySync() { + let pubKeyArray = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, + 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, + 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, + 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); + let priKeyArray = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, + 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; + let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); + try { + let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); + if (keyPair != null) { + console.info('convertKeySync success'); + } + } catch (e) { + console.error(`get key pair failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'ECC Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecc_sync')) + .width('70%') + .onClick(() => { + try { + convertECCAsyKeySync(); + this.message = 'ECC Sync Success'; + } catch { + this.message = 'ECC Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/pkcs8ecc/PKCS8ECC.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/pkcs8ecc/PKCS8ECC.ets old mode 100755 new mode 100644 index 0eaec12f41b780e6eff0bcec0572b3cbc3cb1f95..a155f24b889e64d58d255a3ddc2120152c5ca985 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/pkcs8ecc/PKCS8ECC.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/pkcs8ecc/PKCS8ECC.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function main() { - // 创建一个AsyKeyGenerator实例 - let eccGenerator = cryptoFramework.createAsyKeyGenerator('ECC256'); - // 使用密钥生成器随机生成非对称密钥对 - let keyGenPromise = eccGenerator.generateKeyPair(); - keyGenPromise.then(keyPair => { - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - // 获取非对称密钥对ECC的二进制数据 - let pubBlob = pubKey.getEncoded(); - let skBlob = priKey.getEncodedDer('PKCS8'); - let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); - generator.convertKey(pubBlob, skBlob, (error, data) => { - if (error) { - console.error(`convertKey failed, ${error.code}, ${error.message}`); - return; - } - console.info('convertKey success'); - }); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'PKCS8 ECC Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_pkcs8_ecc_sync')) - .width('70%') - .onClick(async () => { - try { - await main(); - this.message = 'PKCS8 ECC Sync Success'; - } catch { - this.message = 'PKCS8 ECC Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function main() { + // 创建一个AsyKeyGenerator实例 + let eccGenerator = cryptoFramework.createAsyKeyGenerator('ECC256'); + // 使用密钥生成器随机生成非对称密钥对 + let keyGenPromise = eccGenerator.generateKeyPair(); + keyGenPromise.then(keyPair => { + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + // 获取非对称密钥对ECC的二进制数据 + let pubBlob = pubKey.getEncoded(); + let skBlob = priKey.getEncodedDer('PKCS8'); + let generator = cryptoFramework.createAsyKeyGenerator('ECC256'); + generator.convertKey(pubBlob, skBlob, (error, data) => { + if (error) { + console.error(`convertKey failed, ${error.code}, ${error.message}`); + return; + } + console.info('convertKey success'); + }); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'PKCS8 ECC Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_pkcs8_ecc_sync')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'PKCS8 ECC Sync Success'; + } catch { + this.message = 'PKCS8 ECC Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Callback.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Callback.ets old mode 100755 new mode 100644 index d032d59d519b2949f3677651a9f428bc9e4eff19..dd477599a700a8fc2fde933039306d9b1cf77e7c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Callback.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Callback.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function convertAsyKey() { - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); - let pkVal = - new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, - 2, 129, 129, 0, 174, 203, 113, 83, 113, 3, 143, 213, 194, 79, 91, 9, 51, 142, 87, 45, 97, 65, 136, 24, 166, 35, 5, - 179, 42, 47, 212, 79, 111, 74, 134, 120, 73, 67, 21, 19, 235, 80, 46, 152, 209, 133, 232, 87, 192, 140, 18, 206, - 27, 106, 106, 169, 106, 46, 135, 111, 118, 32, 129, 27, 89, 255, 183, 116, 247, 38, 12, 7, 238, 77, 151, 167, 6, - 102, 153, 126, 66, 28, 253, 253, 216, 64, 20, 138, 117, 72, 15, 216, 178, 37, 208, 179, 63, 204, 39, 94, 244, 170, - 48, 190, 21, 11, 73, 169, 156, 104, 193, 3, 17, 100, 28, 60, 50, 92, 235, 218, 57, 73, 119, 19, 101, 164, 192, - 161, 197, 106, 105, 73, 2, 3, 1, 0, 1]); - let pkBlob: cryptoFramework.DataBlob = { data: pkVal }; - rsaGenerator.convertKey(pkBlob, null, (err, keyPair) => { - if (err) { - console.error(`convertKey failed, ${err.code}, ${err.message}`); - return; - } - console.info('convertKey success'); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Callback'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_callback')) - .width('70%') - .onClick(() => { - try { - convertAsyKey(); - this.message = 'RSA Callback Success'; - } catch { - this.message = 'RSA Callback Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function convertAsyKey() { + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); + let pkVal = + new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, + 2, 129, 129, 0, 174, 203, 113, 83, 113, 3, 143, 213, 194, 79, 91, 9, 51, 142, 87, 45, 97, 65, 136, 24, 166, 35, 5, + 179, 42, 47, 212, 79, 111, 74, 134, 120, 73, 67, 21, 19, 235, 80, 46, 152, 209, 133, 232, 87, 192, 140, 18, 206, + 27, 106, 106, 169, 106, 46, 135, 111, 118, 32, 129, 27, 89, 255, 183, 116, 247, 38, 12, 7, 238, 77, 151, 167, 6, + 102, 153, 126, 66, 28, 253, 253, 216, 64, 20, 138, 117, 72, 15, 216, 178, 37, 208, 179, 63, 204, 39, 94, 244, 170, + 48, 190, 21, 11, 73, 169, 156, 104, 193, 3, 17, 100, 28, 60, 50, 92, 235, 218, 57, 73, 119, 19, 101, 164, 192, + 161, 197, 106, 105, 73, 2, 3, 1, 0, 1]); + let pkBlob: cryptoFramework.DataBlob = { data: pkVal }; + rsaGenerator.convertKey(pkBlob, null, (err, keyPair) => { + if (err) { + console.error(`convertKey failed, ${err.code}, ${err.message}`); + return; + } + console.info('convertKey success'); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Callback'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_callback')) + .width('70%') + .onClick(() => { + try { + convertAsyKey(); + this.message = 'RSA Callback Success'; + } catch { + this.message = 'RSA Callback Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets old mode 100755 new mode 100644 index 15359bdaa62fb1e9665b1c0cb2d693894d02a577..0674de039b015bffccb98434c06a6041a514102c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets @@ -1,61 +1,61 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function convertAsyKeySync() { - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); - let pkVal = - new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, - 2, 129, 129, 0, 174, 203, 113, 83, 113, 3, 143, 213, 194, 79, 91, 9, 51, 142, 87, 45, 97, 65, 136, 24, 166, 35, 5, - 179, 42, 47, 212, 79, 111, 74, 134, 120, 73, 67, 21, 19, 235, 80, 46, 152, 209, 133, 232, 87, 192, 140, 18, 206, - 27, 106, 106, 169, 106, 46, 135, 111, 118, 32, 129, 27, 89, 255, 183, 116, 247, 38, 12, 7, 238, 77, 151, 167, 6, - 102, 153, 126, 66, 28, 253, 253, 216, 64, 20, 138, 117, 72, 15, 216, 178, 37, 208, 179, 63, 204, 39, 94, 244, 170, - 48, 190, 21, 11, 73, 169, 156, 104, 193, 3, 17, 100, 28, 60, 50, 92, 235, 218, 57, 73, 119, 19, 101, 164, 192, - 161, 197, 106, 105, 73, 2, 3, 1, 0, 1]); - let pkBlob: cryptoFramework.DataBlob = { data: pkVal }; - try { - let keyPair = rsaGenerator.convertKeySync(pkBlob, null); - if (keyPair != null) { - console.info('convertKeySync success'); - } - } catch (e) { - console.error(`get key pair failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_sync')) - .width('70%') - .onClick(() => { - try { - convertAsyKeySync(); - this.message = 'RSA Sync Success'; - } catch { - this.message = 'RSA Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function convertAsyKeySync() { + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); + let pkVal = + new Uint8Array([48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, 0, 48, 129, 137, + 2, 129, 129, 0, 174, 203, 113, 83, 113, 3, 143, 213, 194, 79, 91, 9, 51, 142, 87, 45, 97, 65, 136, 24, 166, 35, 5, + 179, 42, 47, 212, 79, 111, 74, 134, 120, 73, 67, 21, 19, 235, 80, 46, 152, 209, 133, 232, 87, 192, 140, 18, 206, + 27, 106, 106, 169, 106, 46, 135, 111, 118, 32, 129, 27, 89, 255, 183, 116, 247, 38, 12, 7, 238, 77, 151, 167, 6, + 102, 153, 126, 66, 28, 253, 253, 216, 64, 20, 138, 117, 72, 15, 216, 178, 37, 208, 179, 63, 204, 39, 94, 244, 170, + 48, 190, 21, 11, 73, 169, 156, 104, 193, 3, 17, 100, 28, 60, 50, 92, 235, 218, 57, 73, 119, 19, 101, 164, 192, + 161, 197, 106, 105, 73, 2, 3, 1, 0, 1]); + let pkBlob: cryptoFramework.DataBlob = { data: pkVal }; + try { + let keyPair = rsaGenerator.convertKeySync(pkBlob, null); + if (keyPair != null) { + console.info('convertKeySync success'); + } + } catch (e) { + console.error(`get key pair failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_sync')) + .width('70%') + .onClick(() => { + try { + convertAsyKeySync(); + this.message = 'RSA Sync Success'; + } catch { + this.message = 'RSA Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Callback.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Callback.ets old mode 100755 new mode 100644 index 6cdb788f5c210422541cf9431db35d16a579d5b8..307d4c172ca5190f19d88946d6b10d6ca173a9a6 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Callback.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Callback.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function convertSM2AsyKey() { - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, - 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, - 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, - 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, - 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, - 130, 45]); - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; - let generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); - generator.convertKey(pubKeyBlob, priKeyBlob, (error, data) => { - if (error) { - console.error(`convertKey failed, ${error.code}, ${error.message}`); - return; - } - console.info('convertKey success'); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Callback'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_callback')) - .width('70%') - .onClick(() => { - try { - convertSM2AsyKey(); - this.message = 'SM2 Callback Success'; - } catch { - this.message = 'SM2 Callback Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function convertSM2AsyKey() { + let pubKeyArray = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, + 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, + 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, + 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); + let priKeyArray = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, + 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, + 130, 45]); + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; + let generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); + generator.convertKey(pubKeyBlob, priKeyBlob, (error, data) => { + if (error) { + console.error(`convertKey failed, ${error.code}, ${error.message}`); + return; + } + console.info('convertKey success'); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Callback'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_callback')) + .width('70%') + .onClick(() => { + try { + convertSM2AsyKey(); + this.message = 'SM2 Callback Success'; + } catch { + this.message = 'SM2 Callback Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets old mode 100755 new mode 100644 index c5bef128cc13cad6d16453ac3896a531a74a0780..6aff38858c3027d3564564079229b52f7ea53b41 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function convertSM2AsyKeySync() { - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, - 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, - 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, - 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, - 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, - 130, 45]); - let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; - let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; - let generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); - try { - let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); - if (keyPair != null) { - console.info('convertKeySync success'); - } - } catch (e) { - console.error(`get key pair failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_sync')) - .width('70%') - .onClick(() => { - try { - convertSM2AsyKeySync(); - this.message = 'SM2 Sync Success'; - } catch { - this.message = 'SM2 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function convertSM2AsyKeySync() { + let pubKeyArray = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 129, 28, 207, 85, 1, 130, 45, 3, 66, 0, + 4, 90, 3, 58, 157, 190, 248, 76, 7, 132, 200, 151, 208, 112, 230, 96, 140, 90, 238, 211, 155, 128, 109, 248, 40, + 83, 214, 78, 42, 104, 106, 55, 148, 249, 35, 61, 32, 221, 135, 143, 100, 45, 97, 194, 176, 52, 73, 136, 174, 40, + 70, 70, 34, 103, 103, 161, 99, 27, 187, 13, 187, 109, 244, 13, 7]); + let priKeyArray = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 54, 41, 239, 240, 63, 188, 134, 113, 31, 102, 149, 203, 245, 89, 15, 15, 47, + 202, 170, 60, 38, 154, 28, 169, 189, 100, 251, 76, 112, 223, 156, 159, 160, 10, 6, 8, 42, 129, 28, 207, 85, 1, + 130, 45]); + let pubKeyBlob: cryptoFramework.DataBlob = { data: pubKeyArray }; + let priKeyBlob: cryptoFramework.DataBlob = { data: priKeyArray }; + let generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); + try { + let keyPair = generator.convertKeySync(pubKeyBlob, priKeyBlob); + if (keyPair != null) { + console.info('convertKeySync success'); + } + } catch (e) { + console.error(`get key pair failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_sync')) + .width('70%') + .onClick(() => { + try { + convertSM2AsyKeySync(); + this.message = 'SM2 Sync Success'; + } catch { + this.message = 'SM2 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPairArkTS.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPairArkTS.test.ets old mode 100755 new mode 100644 index 570e9a0752973606f9f52a0223ed867ca87267ac..2dfb95cd2c8a53f7c49582791fc5040ddb2d86b2 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPairArkTS.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/BinaryDataConvertAsymmetricKeyPairArkTS.test.ets @@ -1,170 +1,170 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function binaryDataConvertAsymmetricKeyPairArkTSTest() { - describe('binaryDataConvertAsymmetricKeyPairArkTSTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,指定二进制数据转换ECC密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS001', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECC Callback')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call ECC Callback')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECC Callback Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换ECC密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS002', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECC Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call ECC Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECC Sync Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定PKCS8二进制数据转换ECC私钥 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS003', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('PKCS8 ECC')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call PKCS8 ECC Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('PKCS8 ECC Sync Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换RSA密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS004', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Callback')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Callback')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Callback Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换RSA密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS005', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Sync Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换SM2密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS006', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Callback')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Callback')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Callback Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS006 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换SM2密钥对 - */ - it('testBinaryDataConvertAsymmetricKeyPairArkTS007', 0, async () => { - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS007 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Sync Success')); - console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS007 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function binaryDataConvertAsymmetricKeyPairArkTSTest() { + describe('binaryDataConvertAsymmetricKeyPairArkTSTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,指定二进制数据转换ECC密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS001', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECC Callback')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECC Callback')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECC Callback Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换ECC密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS002', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECC Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECC Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECC Sync Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定PKCS8二进制数据转换ECC私钥 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS003', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('PKCS8 ECC')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call PKCS8 ECC Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PKCS8 ECC Sync Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换RSA密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS004', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Callback')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Callback')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Callback Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换RSA密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS005', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Sync Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换SM2密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS006', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Callback')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Callback')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Callback Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS006 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换SM2密钥对 + */ + it('testBinaryDataConvertAsymmetricKeyPairArkTS007', 0, async () => { + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS007 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Sync Success')); + console.info('uitest: testBinaryDataConvertAsymmetricKeyPairArkTS007 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/ohosTest.md old mode 100755 new mode 100644 index 8c37a2a8837c14e053f5d35358d5fc03a7edfa61..aca67a6fac0d5d432f3e4ed051cd3172e18656e1 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/ohosTest.md @@ -1,14 +1,14 @@ -# 指定二进制数据转换非对称密钥对(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,指定二进制数据转换ECC密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换ECC密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定PKCS8二进制数据转换ECC私钥 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换RSA密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换RSA密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换SM2密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 指定二进制数据转换非对称密钥对(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,指定二进制数据转换ECC密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换ECC密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定PKCS8二进制数据转换ECC私钥 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换RSA密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换RSA密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换SM2密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,指定二进制数据转换SM2密钥对 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/screenshots/BinaryDataConvertAsymmetricKeyPairArkTS1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/screenshots/BinaryDataConvertAsymmetricKeyPairArkTS1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/screenshots/BinaryDataConvertAsymmetricKeyPairArkTS2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/BinaryDataConvertAsymmetricKeyPairArkTS/screenshots/BinaryDataConvertAsymmetricKeyPairArkTS2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/app.json5 old mode 100755 new mode 100644 index 2d0fb8ce22949cab56c92e6f09ea50d433c5225f..a7ecbaae53a6841f8c8272e3c056ed70781676a6 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/app.json5 @@ -1,25 +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.convertspecifiedpemasymmetrickeypair", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.convertspecifiedpemasymmetrickeypair", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index a2e570241befa7d09cc0e64702f731f4179c9dd7..13b70d7f20f8eedd6db5bd52048d17e5961decd1 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ConvertSpecifiedPEMAsymmetricKeyPair" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ConvertSpecifiedPEMAsymmetricKeyPair" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/README.md old mode 100755 new mode 100644 index 2b086dc87be8a0821da4bc0a887b1490ef3e37eb..6f3cc74dd751923e4dd0aa01b158542ab148f946 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/README.md @@ -1,84 +1,84 @@ -# 指定PEM格式字符串数据转换非对称密钥对 - -### 介绍 - -以RSA为例,根据指定的非对称密钥字符串数据,生成非对称密钥对(KeyPair)。 - -以RSA为例,根据指定的非对称密钥字符串数据,生成非对称密钥对(OH_CryptoKeyPair)。 - -本示例主要展示了指定PEM格式字符串数据转换非对称密钥对(ArkTS、C/C++)场景。该工程中展示的代码详细描述可查如下链接。 - -- [指定PEM格式字符串数据转换非对称密钥对(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-string-data-to-asym-key-pair.md) -- [指定PEM格式字符串数据转换非对称密钥对(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-string-data-to-asym-key-pair-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例ConvertSpecifiedPEMAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── rsa.cpp - │ │ | ├── file.h - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 指定PEM格式字符串数据转换非对称密钥对示例代码 - │ │ ├── Promise.ets - │ │ ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── ConvertSpecifiedPEMAsymmetricKeyPair.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 指定PEM格式字符串数据转换非对称密钥对 + +### 介绍 + +以RSA为例,根据指定的非对称密钥字符串数据,生成非对称密钥对(KeyPair)。 + +以RSA为例,根据指定的非对称密钥字符串数据,生成非对称密钥对(OH_CryptoKeyPair)。 + +本示例主要展示了指定PEM格式字符串数据转换非对称密钥对(ArkTS、C/C++)场景。该工程中展示的代码详细描述可查如下链接。 + +- [指定PEM格式字符串数据转换非对称密钥对(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-string-data-to-asym-key-pair.md) +- [指定PEM格式字符串数据转换非对称密钥对(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-string-data-to-asym-key-pair-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例ConvertSpecifiedPEMAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── rsa.cpp + │ │ | ├── file.h + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 指定PEM格式字符串数据转换非对称密钥对示例代码 + │ │ ├── Promise.ets + │ │ ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── ConvertSpecifiedPEMAsymmetricKeyPair.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 3acbdf11b30d7ab093981507d45731ee369efc33..c368231d79270b3947c06bf4d7ad3f2b8040986d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(ConvertSpecifiedPEMAsymmetricKeyPair) - -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 types/project/rsa.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(ConvertSpecifiedPEMAsymmetricKeyPair) + +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 types/project/rsa.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index bcceea269b803cfb99593b3321c796a33fb4b37c..0289597a7623997bd7635449feffa52dc96237f3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp @@ -1,45 +1,45 @@ -/* - * 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 "types/project/file.h" - -static napi_value NAPI_Global_doTestPemDataCovertAsymKey(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestPemDataCovertAsymKey(), &ret); - return ret; -} -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"doTestPemDataCovertAsymKey", nullptr, NAPI_Global_doTestPemDataCovertAsymKey, - 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTestPemDataCovertAsymKey(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestPemDataCovertAsymKey(), &ret); + return ret; +} +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"doTestPemDataCovertAsymKey", nullptr, NAPI_Global_doTestPemDataCovertAsymKey, + 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index d6b778380d345b6f7e7627a96126ef2061a01c75..458a767fc8ad7a254b6b2b03bfde726a3441c835 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,16 +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. - */ - +/* + * 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 doTestPemDataCovertAsymKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 30d9dba93598d9f6a4107b2013997dfc0a890188..8b7f51e5dbcef1f89248ac29ad1b82f2fc44ab2b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h @@ -1,22 +1,22 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestPemDataCovertAsymKey(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestPemDataCovertAsymKey(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp old mode 100755 new mode 100644 index ba0aee7929d8468c290cd80ccd1aab41b8294e49..06179b2136cf3e2684677fbbf58bbe01c478917c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" -#include "file.h" - -OH_Crypto_ErrCode doTestPemDataCovertAsymKey() -{ - OH_CryptoAsymKeyGenerator *ctx = nullptr; - OH_Crypto_ErrCode ret; - - ret = OH_CryptoAsymKeyGenerator_Create("RSA1024", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - - uint8_t sm2PubKeyBlobData[] = { - 48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, - 0, 48, 129, 137, 2, 129, 129, 0, 235, 184, 151, 247, 130, 216, 140, 187, 64, 124, 219, 137, 140, - 184, 53, 137, 216, 105, 156, 141, 137, 165, 30, 80, 232, 55, 96, 46, 23, 237, 197, 123, 121, 27, - 240, 190, 14, 111, 237, 172, 67, 42, 47, 164, 226, 248, 211, 157, 213, 194, 131, 109, 181, 41, 173, - 217, 127, 252, 121, 126, 26, 130, 55, 4, 134, 104, 73, 5, 132, 91, 214, 146, 232, 64, 99, 87, - 33, 222, 155, 159, 9, 59, 212, 144, 46, 183, 83, 89, 220, 189, 148, 13, 176, 5, 139, 156, 230, - 143, 16, 152, 79, 36, 8, 112, 40, 174, 35, 83, 82, 57, 137, 87, 123, 215, 99, 199, 66, 131, - 150, 31, 143, 56, 252, 2, 73, 41, 70, 159, 2, 3, 1, 0, 1}; - - OH_CryptoKeyPair *dupKeyPair = nullptr; - Crypto_DataBlob pubBlob = {.data = sm2PubKeyBlobData, .len = sizeof(sm2PubKeyBlobData)}; - ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &pubBlob, nullptr, &dupKeyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - return ret; - } - - OH_CryptoPubKey *pubKey1 = OH_CryptoKeyPair_GetPubKey(dupKeyPair); - Crypto_DataBlob retBlob = {.data = nullptr, .len = 0}; - ret = OH_CryptoPubKey_Encode(pubKey1, CRYPTO_PEM, "PKCS1", &retBlob); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; - } - OH_Crypto_FreeDataBlob(&retBlob); - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" +#include "file.h" + +OH_Crypto_ErrCode doTestPemDataCovertAsymKey() +{ + OH_CryptoAsymKeyGenerator *ctx = nullptr; + OH_Crypto_ErrCode ret; + + ret = OH_CryptoAsymKeyGenerator_Create("RSA1024", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + + uint8_t sm2PubKeyBlobData[] = { + 48, 129, 159, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 3, 129, 141, + 0, 48, 129, 137, 2, 129, 129, 0, 235, 184, 151, 247, 130, 216, 140, 187, 64, 124, 219, 137, 140, + 184, 53, 137, 216, 105, 156, 141, 137, 165, 30, 80, 232, 55, 96, 46, 23, 237, 197, 123, 121, 27, + 240, 190, 14, 111, 237, 172, 67, 42, 47, 164, 226, 248, 211, 157, 213, 194, 131, 109, 181, 41, 173, + 217, 127, 252, 121, 126, 26, 130, 55, 4, 134, 104, 73, 5, 132, 91, 214, 146, 232, 64, 99, 87, + 33, 222, 155, 159, 9, 59, 212, 144, 46, 183, 83, 89, 220, 189, 148, 13, 176, 5, 139, 156, 230, + 143, 16, 152, 79, 36, 8, 112, 40, 174, 35, 83, 82, 57, 137, 87, 123, 215, 99, 199, 66, 131, + 150, 31, 143, 56, 252, 2, 73, 41, 70, 159, 2, 3, 1, 0, 1}; + + OH_CryptoKeyPair *dupKeyPair = nullptr; + Crypto_DataBlob pubBlob = {.data = sm2PubKeyBlobData, .len = sizeof(sm2PubKeyBlobData)}; + ret = OH_CryptoAsymKeyGenerator_Convert(ctx, CRYPTO_DER, &pubBlob, nullptr, &dupKeyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + return ret; + } + + OH_CryptoPubKey *pubKey1 = OH_CryptoKeyPair_GetPubKey(dupKeyPair); + Crypto_DataBlob retBlob = {.data = nullptr, .len = 0}; + ret = OH_CryptoPubKey_Encode(pubKey1, CRYPTO_PEM, "PKCS1", &retBlob); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; + } + OH_Crypto_FreeDataBlob(&retBlob); + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 49dcd5638923670a85d021ef16b6f2e179674db6..8f2a8e7e608ab64d7e6248e82733ff9c774a256f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets @@ -1,61 +1,61 @@ -/* - * 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 { router } from '@kit.ArkUI'; -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'ConvertSpecifiedPEMAsymmetricKeyPair'; - - goToSample(url: string): void { - router.pushUrl({ - url: url, - }, router.RouterMode.Single, (err) => { - if (err) { - console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info('pushUrl success'); - }) - } - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(20) - .fontWeight(FontWeight.Bold) - Button($r('app.string.pem_to_rsa')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doTestPemDataCovertAsymKey(); - this.message = 'doTestPemDataCovertAsymKey Success Result:' + ret.toString(); - }) - Button($r('app.string.promise')) - .width('70%') - .onClick(() => { - this.goToSample('pages/Promise') - }) - Button($r('app.string.sync')) - .width('70%') - .onClick(() => { - this.goToSample('pages/Sync') - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { router } from '@kit.ArkUI'; +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'ConvertSpecifiedPEMAsymmetricKeyPair'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Button($r('app.string.pem_to_rsa')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doTestPemDataCovertAsymKey(); + this.message = 'doTestPemDataCovertAsymKey Success Result:' + ret.toString(); + }) + Button($r('app.string.promise')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Promise') + }) + Button($r('app.string.sync')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Sync') + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Promise.ets old mode 100755 new mode 100644 index 27357725e0f5feefaba01b79f6a82881ceac548a..b45d61103bd9bdfe2ee7326bffb53772bc94655d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Promise.ets @@ -1,74 +1,74 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -let priKeyPkcs1Str1024: string = - '-----BEGIN RSA PRIVATE KEY-----\n' + - 'MIICXQIBAAKBgQCwIN3mr21+N96ToxnVnaS+xyK9cNRAHiHGgrbjHw6RAj3V+l+W\n' + - 'Y68IhIe3DudVlzE9oMjeOQwkMkq//HCxNlIlFR6O6pa0mrXSwPRE7YKG97CeKk2g\n' + - 'YOS8YEh8toAvm7xKbiLkXuuMlxrjP2j/mb5iI/UASFSPZiQ/IyxDr0AQaQIDAQAB\n' + - 'AoGAEvBFzBNa+7J4PXnRQlYEK/tvsd0bBZX33ceacMubHl6WVZbphltLq+fMTBPP\n' + - 'LjXmtpC+aJ7Lvmyl+wTi/TsxE9vxW5JnbuRT48rnZ/Xwq0eozDeEeIBRrpsr7Rvr\n' + - '7ctrgzr4m4yMHq9aDgpxj8IR7oHkfwnmWr0wM3FuiVlj650CQQDineeNZ1hUTkj4\n' + - 'D3O+iCi3mxEVEeJrpqrmSFolRMb+iozrIRKuJlgcOs+Gqi2fHfOTTL7LkpYe8SVg\n' + - 'e3JxUdVLAkEAxvcZXk+byMFoetrnlcMR13VHUpoVeoV9qkv6CAWLlbMdgf7uKmgp\n' + - 'a1Yp3QPDNQQqkPvrqtfR19JWZ4uy1qREmwJALTU3BjyBoH/liqb6fh4HkWk75Som\n' + - 'MzeSjFIOubSYxhq5tgZpBZjcpvUMhV7Zrw54kwASZ+YcUJvmyvKViAm9NQJBAKF7\n' + - 'DyXSKrem8Ws0m1ybM7HQx5As6l3EVhePDmDQT1eyRbKp+xaD74nkJpnwYdB3jyyY\n' + - 'qc7A1tj5J5NmeEFolR0CQQCn76Xp8HCjGgLHw9vg7YyIL28y/XyfFyaZAzzK+Yia\n' + - 'akNwQ6NeGtXSsuGCcyyfpacHp9xy8qXQNKSkw03/5vDO\n' + - '-----END RSA PRIVATE KEY-----\n'; -let publicPkcs1Str1024: string = - '-----BEGIN RSA PUBLIC KEY-----\n' + - 'MIGJAoGBALAg3eavbX433pOjGdWdpL7HIr1w1EAeIcaCtuMfDpECPdX6X5ZjrwiE\n' + - 'h7cO51WXMT2gyN45DCQySr/8cLE2UiUVHo7qlrSatdLA9ETtgob3sJ4qTaBg5Lxg\n' + - 'SHy2gC+bvEpuIuRe64yXGuM/aP+ZvmIj9QBIVI9mJD8jLEOvQBBpAgMBAAE=\n' + - '-----END RSA PUBLIC KEY-----\n'; - -async function testPkcs1ToPkcs8ByPromise() { - let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); - let keyPair = await asyKeyGenerator.convertPemKey(publicPkcs1Str1024, priKeyPkcs1Str1024); - let priPemKey = keyPair.priKey; - let pubPemKey = keyPair.pubKey; - let priString = priPemKey.getEncodedPem('PKCS8'); - let pubString = pubPemKey.getEncodedPem('X509'); - console.info('[promise]TestPkcs1ToPkcs8ByPromise priString output is ' + priString); - console.info('[promise]TestPkcs1ToPkcs8ByPromise pubString output is ' + pubString); -} - -@Entry -@Component -struct Index { - @State message: string = 'Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_promise')) - .width('70%') - .onClick(async () => { - try { - await testPkcs1ToPkcs8ByPromise(); - this.message = 'Promise Success'; - } catch { - this.message = 'Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +let priKeyPkcs1Str1024: string = + '-----BEGIN RSA PRIVATE KEY-----\n' + + 'MIICXQIBAAKBgQCwIN3mr21+N96ToxnVnaS+xyK9cNRAHiHGgrbjHw6RAj3V+l+W\n' + + 'Y68IhIe3DudVlzE9oMjeOQwkMkq//HCxNlIlFR6O6pa0mrXSwPRE7YKG97CeKk2g\n' + + 'YOS8YEh8toAvm7xKbiLkXuuMlxrjP2j/mb5iI/UASFSPZiQ/IyxDr0AQaQIDAQAB\n' + + 'AoGAEvBFzBNa+7J4PXnRQlYEK/tvsd0bBZX33ceacMubHl6WVZbphltLq+fMTBPP\n' + + 'LjXmtpC+aJ7Lvmyl+wTi/TsxE9vxW5JnbuRT48rnZ/Xwq0eozDeEeIBRrpsr7Rvr\n' + + '7ctrgzr4m4yMHq9aDgpxj8IR7oHkfwnmWr0wM3FuiVlj650CQQDineeNZ1hUTkj4\n' + + 'D3O+iCi3mxEVEeJrpqrmSFolRMb+iozrIRKuJlgcOs+Gqi2fHfOTTL7LkpYe8SVg\n' + + 'e3JxUdVLAkEAxvcZXk+byMFoetrnlcMR13VHUpoVeoV9qkv6CAWLlbMdgf7uKmgp\n' + + 'a1Yp3QPDNQQqkPvrqtfR19JWZ4uy1qREmwJALTU3BjyBoH/liqb6fh4HkWk75Som\n' + + 'MzeSjFIOubSYxhq5tgZpBZjcpvUMhV7Zrw54kwASZ+YcUJvmyvKViAm9NQJBAKF7\n' + + 'DyXSKrem8Ws0m1ybM7HQx5As6l3EVhePDmDQT1eyRbKp+xaD74nkJpnwYdB3jyyY\n' + + 'qc7A1tj5J5NmeEFolR0CQQCn76Xp8HCjGgLHw9vg7YyIL28y/XyfFyaZAzzK+Yia\n' + + 'akNwQ6NeGtXSsuGCcyyfpacHp9xy8qXQNKSkw03/5vDO\n' + + '-----END RSA PRIVATE KEY-----\n'; +let publicPkcs1Str1024: string = + '-----BEGIN RSA PUBLIC KEY-----\n' + + 'MIGJAoGBALAg3eavbX433pOjGdWdpL7HIr1w1EAeIcaCtuMfDpECPdX6X5ZjrwiE\n' + + 'h7cO51WXMT2gyN45DCQySr/8cLE2UiUVHo7qlrSatdLA9ETtgob3sJ4qTaBg5Lxg\n' + + 'SHy2gC+bvEpuIuRe64yXGuM/aP+ZvmIj9QBIVI9mJD8jLEOvQBBpAgMBAAE=\n' + + '-----END RSA PUBLIC KEY-----\n'; + +async function testPkcs1ToPkcs8ByPromise() { + let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); + let keyPair = await asyKeyGenerator.convertPemKey(publicPkcs1Str1024, priKeyPkcs1Str1024); + let priPemKey = keyPair.priKey; + let pubPemKey = keyPair.pubKey; + let priString = priPemKey.getEncodedPem('PKCS8'); + let pubString = pubPemKey.getEncodedPem('X509'); + console.info('[promise]TestPkcs1ToPkcs8ByPromise priString output is ' + priString); + console.info('[promise]TestPkcs1ToPkcs8ByPromise pubString output is ' + pubString); +} + +@Entry +@Component +struct Index { + @State message: string = 'Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_promise')) + .width('70%') + .onClick(async () => { + try { + await testPkcs1ToPkcs8ByPromise(); + this.message = 'Promise Success'; + } catch { + this.message = 'Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Sync.ets old mode 100755 new mode 100644 index 20819390259bf0cddd4df7cb9bf6ff6251dbc721..18d20eaf4c06499518a437073b9197615140f5e6 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/ets/pages/Sync.ets @@ -1,83 +1,83 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -let priKeyPkcs1Str1024: string = - '-----BEGIN RSA PRIVATE KEY-----\n' + - 'MIICXQIBAAKBgQCwIN3mr21+N96ToxnVnaS+xyK9cNRAHiHGgrbjHw6RAj3V+l+W\n' + - 'Y68IhIe3DudVlzE9oMjeOQwkMkq//HCxNlIlFR6O6pa0mrXSwPRE7YKG97CeKk2g\n' + - 'YOS8YEh8toAvm7xKbiLkXuuMlxrjP2j/mb5iI/UASFSPZiQ/IyxDr0AQaQIDAQAB\n' + - 'AoGAEvBFzBNa+7J4PXnRQlYEK/tvsd0bBZX33ceacMubHl6WVZbphltLq+fMTBPP\n' + - 'LjXmtpC+aJ7Lvmyl+wTi/TsxE9vxW5JnbuRT48rnZ/Xwq0eozDeEeIBRrpsr7Rvr\n' + - '7ctrgzr4m4yMHq9aDgpxj8IR7oHkfwnmWr0wM3FuiVlj650CQQDineeNZ1hUTkj4\n' + - 'D3O+iCi3mxEVEeJrpqrmSFolRMb+iozrIRKuJlgcOs+Gqi2fHfOTTL7LkpYe8SVg\n' + - 'e3JxUdVLAkEAxvcZXk+byMFoetrnlcMR13VHUpoVeoV9qkv6CAWLlbMdgf7uKmgp\n' + - 'a1Yp3QPDNQQqkPvrqtfR19JWZ4uy1qREmwJALTU3BjyBoH/liqb6fh4HkWk75Som\n' + - 'MzeSjFIOubSYxhq5tgZpBZjcpvUMhV7Zrw54kwASZ+YcUJvmyvKViAm9NQJBAKF7\n' + - 'DyXSKrem8Ws0m1ybM7HQx5As6l3EVhePDmDQT1eyRbKp+xaD74nkJpnwYdB3jyyY\n' + - 'qc7A1tj5J5NmeEFolR0CQQCn76Xp8HCjGgLHw9vg7YyIL28y/XyfFyaZAzzK+Yia\n' + - 'akNwQ6NeGtXSsuGCcyyfpacHp9xy8qXQNKSkw03/5vDO\n' + - '-----END RSA PRIVATE KEY-----\n'; -let publicPkcs1Str1024: string = - '-----BEGIN RSA PUBLIC KEY-----\n' + - 'MIGJAoGBALAg3eavbX433pOjGdWdpL7HIr1w1EAeIcaCtuMfDpECPdX6X5ZjrwiE\n' + - 'h7cO51WXMT2gyN45DCQySr/8cLE2UiUVHo7qlrSatdLA9ETtgob3sJ4qTaBg5Lxg\n' + - 'SHy2gC+bvEpuIuRe64yXGuM/aP+ZvmIj9QBIVI9mJD8jLEOvQBBpAgMBAAE=\n' + - '-----END RSA PUBLIC KEY-----\n'; - -function testPkcs1ToPkcs8BySync() { - let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); - try { - let keyPairData = asyKeyGenerator.convertPemKeySync(publicPkcs1Str1024, priKeyPkcs1Str1024); - if (keyPairData != null) { - console.info('[Sync]: convert pem key pair success'); - } else { - console.error('[Sync]: convert pem key pair result fail!'); - } - let priPemKey = keyPairData.priKey; - let pubPemKey = keyPairData.pubKey; - let priString = priPemKey.getEncodedPem('PKCS8'); - let pubString = pubPemKey.getEncodedPem('X509'); - console.info('[Sync]TestPkcs1ToPkcs8BySync priString output is ' + priString); - console.info('[Sync]TestPkcs1ToPkcs8BySync pubString output is ' + pubString); - } catch (e) { - console.error(`Sync error, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sync')) - .width('70%') - .onClick(() => { - try { - testPkcs1ToPkcs8BySync(); - this.message = 'Sync Success'; - } catch { - this.message = 'Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +let priKeyPkcs1Str1024: string = + '-----BEGIN RSA PRIVATE KEY-----\n' + + 'MIICXQIBAAKBgQCwIN3mr21+N96ToxnVnaS+xyK9cNRAHiHGgrbjHw6RAj3V+l+W\n' + + 'Y68IhIe3DudVlzE9oMjeOQwkMkq//HCxNlIlFR6O6pa0mrXSwPRE7YKG97CeKk2g\n' + + 'YOS8YEh8toAvm7xKbiLkXuuMlxrjP2j/mb5iI/UASFSPZiQ/IyxDr0AQaQIDAQAB\n' + + 'AoGAEvBFzBNa+7J4PXnRQlYEK/tvsd0bBZX33ceacMubHl6WVZbphltLq+fMTBPP\n' + + 'LjXmtpC+aJ7Lvmyl+wTi/TsxE9vxW5JnbuRT48rnZ/Xwq0eozDeEeIBRrpsr7Rvr\n' + + '7ctrgzr4m4yMHq9aDgpxj8IR7oHkfwnmWr0wM3FuiVlj650CQQDineeNZ1hUTkj4\n' + + 'D3O+iCi3mxEVEeJrpqrmSFolRMb+iozrIRKuJlgcOs+Gqi2fHfOTTL7LkpYe8SVg\n' + + 'e3JxUdVLAkEAxvcZXk+byMFoetrnlcMR13VHUpoVeoV9qkv6CAWLlbMdgf7uKmgp\n' + + 'a1Yp3QPDNQQqkPvrqtfR19JWZ4uy1qREmwJALTU3BjyBoH/liqb6fh4HkWk75Som\n' + + 'MzeSjFIOubSYxhq5tgZpBZjcpvUMhV7Zrw54kwASZ+YcUJvmyvKViAm9NQJBAKF7\n' + + 'DyXSKrem8Ws0m1ybM7HQx5As6l3EVhePDmDQT1eyRbKp+xaD74nkJpnwYdB3jyyY\n' + + 'qc7A1tj5J5NmeEFolR0CQQCn76Xp8HCjGgLHw9vg7YyIL28y/XyfFyaZAzzK+Yia\n' + + 'akNwQ6NeGtXSsuGCcyyfpacHp9xy8qXQNKSkw03/5vDO\n' + + '-----END RSA PRIVATE KEY-----\n'; +let publicPkcs1Str1024: string = + '-----BEGIN RSA PUBLIC KEY-----\n' + + 'MIGJAoGBALAg3eavbX433pOjGdWdpL7HIr1w1EAeIcaCtuMfDpECPdX6X5ZjrwiE\n' + + 'h7cO51WXMT2gyN45DCQySr/8cLE2UiUVHo7qlrSatdLA9ETtgob3sJ4qTaBg5Lxg\n' + + 'SHy2gC+bvEpuIuRe64yXGuM/aP+ZvmIj9QBIVI9mJD8jLEOvQBBpAgMBAAE=\n' + + '-----END RSA PUBLIC KEY-----\n'; + +function testPkcs1ToPkcs8BySync() { + let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024'); + try { + let keyPairData = asyKeyGenerator.convertPemKeySync(publicPkcs1Str1024, priKeyPkcs1Str1024); + if (keyPairData != null) { + console.info('[Sync]: convert pem key pair success'); + } else { + console.error('[Sync]: convert pem key pair result fail!'); + } + let priPemKey = keyPairData.priKey; + let pubPemKey = keyPairData.pubKey; + let priString = priPemKey.getEncodedPem('PKCS8'); + let pubString = pubPemKey.getEncodedPem('X509'); + console.info('[Sync]TestPkcs1ToPkcs8BySync priString output is ' + priString); + console.info('[Sync]TestPkcs1ToPkcs8BySync pubString output is ' + pubString); + } catch (e) { + console.error(`Sync error, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sync')) + .width('70%') + .onClick(() => { + try { + testPkcs1ToPkcs8BySync(); + this.message = 'Sync Success'; + } catch { + this.message = 'Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/ConvertSpecifiedPEMAsymmetricKeyPair.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/ConvertSpecifiedPEMAsymmetricKeyPair.test.ets old mode 100755 new mode 100644 index 8b68f88d7b1224e0a83a9a998145a5d9559da2eb..f95d1d3a759ffcb8cb9e3cd98e5bf77651e18916 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/ConvertSpecifiedPEMAsymmetricKeyPair.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/ConvertSpecifiedPEMAsymmetricKeyPair.test.ets @@ -1,94 +1,94 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function convertSpecifiedPEMAsymmetricKeyPairTest() { - describe('convertSpecifiedPEMAsymmetricKeyPairTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,指定PEM格式字符串数据转换非对称密钥对(C/C++) - */ - it('testConvertSpecifiedPEMAsymmetricKeyPair001', 0, async () => { - console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('PEM TO RSA')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('doTestPemDataCovertAsymKey Success Result:0')); - console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair001 end'); - }) - - /** - * 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),Promise方式 - */ - it('testConvertSpecifiedPEMAsymmetricKeyPair002', 0, async () => { - console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Promise Success')); - console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),同步方式 - */ - it('testConvertSpecifiedPEMAsymmetricKeyPair003', 0, async () => { - console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Sync Success')); - console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair003 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function convertSpecifiedPEMAsymmetricKeyPairTest() { + describe('convertSpecifiedPEMAsymmetricKeyPairTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,指定PEM格式字符串数据转换非对称密钥对(C/C++) + */ + it('testConvertSpecifiedPEMAsymmetricKeyPair001', 0, async () => { + console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('PEM TO RSA')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('doTestPemDataCovertAsymKey Success Result:0')); + console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair001 end'); + }) + + /** + * 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),Promise方式 + */ + it('testConvertSpecifiedPEMAsymmetricKeyPair002', 0, async () => { + console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Promise Success')); + console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),同步方式 + */ + it('testConvertSpecifiedPEMAsymmetricKeyPair003', 0, async () => { + console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Sync Success')); + console.info('uitest: testConvertSpecifiedPEMAsymmetricKeyPair003 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/oh-package.json5 old mode 100755 new mode 100644 index 610c3ebfcdf897a69c2f81cc71cb7a66d4cf2dfe..9b142d655b140175b33fe2a0c804ca498119f87f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/oh-package.json5 @@ -1,24 +1,24 @@ -/* - * 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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/ohosTest.md old mode 100755 new mode 100644 index 15c0012f6ac1ac7227cf6615d194b29ab1c0eaca..c634e4b865e6cf86c50919ff6112274d6df1cc75 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/ohosTest.md @@ -1,10 +1,10 @@ -# 指定PEM格式字符串数据转换非对称密钥对测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,指定PEM格式字符串数据转换非对称密钥对(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),Promise方式 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 指定PEM格式字符串数据转换非对称密钥对测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,指定PEM格式字符串数据转换非对称密钥对(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),Promise方式 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,指定PEM格式字符串数据转换非对称密钥对(ArkTS),同步方式 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/screenshots/ConvertSpecifiedPEMAsymmetricKeyPair1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/screenshots/ConvertSpecifiedPEMAsymmetricKeyPair1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/screenshots/ConvertSpecifiedPEMAsymmetricKeyPair2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSpecifiedPEMAsymmetricKeyPair/screenshots/ConvertSpecifiedPEMAsymmetricKeyPair2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/app.json5 old mode 100755 new mode 100644 index 5ddaae415a2b7d9f9912c6f73c67a99fad7ce7b0..f8882387c749110c76071f66274f2acf8b5b585a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/app.json5 @@ -1,25 +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.convertsymmetrickeybinaryformat", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.convertsymmetrickeybinaryformat", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 00781a53eaba9a74db28cc01663c23a6c5a44f08..7ee6e6868309277c5aca16ff1cd27e61545881c8 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ConvertSymmetricKeyBinaryFormat" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ConvertSymmetricKeyBinaryFormat" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/README.md old mode 100755 new mode 100644 index 3499be5efa7389b9cf4d65c2bd63e5887c5bcd23..49f2db0f9ca66367764bece978d7178839751080 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/README.md @@ -1,80 +1,80 @@ -# 指定二进制数据转换对称密钥(C/C++) - -### 介绍 - -以3DES和HMAC为例,根据指定的对称密钥二进制数据,生成密钥(OH_CryptoSymKey),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 - -本示例主要展示了指定二进制数据转换对称密钥(C/C++),指定二进制数据转换3DES密钥和指定二进制数据转换HMAC密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [指定二进制数据转换对称密钥(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-sym-key-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例ConvertSymmetricKeyBinaryFormat.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── 3des.cpp - │ │ | ├── file.h - │ │ | ├── hmac.cpp - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 指定二进制数据转换对称密钥(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── ConvertSymmetricKeyBinaryFormat.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 指定二进制数据转换对称密钥(C/C++) + +### 介绍 + +以3DES和HMAC为例,根据指定的对称密钥二进制数据,生成密钥(OH_CryptoSymKey),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 + +本示例主要展示了指定二进制数据转换对称密钥(C/C++),指定二进制数据转换3DES密钥和指定二进制数据转换HMAC密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [指定二进制数据转换对称密钥(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-sym-key-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例ConvertSymmetricKeyBinaryFormat.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── 3des.cpp + │ │ | ├── file.h + │ │ | ├── hmac.cpp + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 指定二进制数据转换对称密钥(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── ConvertSymmetricKeyBinaryFormat.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 4bca72ebb057f262c537e97ee6b9d5e228f70f67..01f0d79a10a04538f5452bf0d20553c44b24c3e9 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(ConvertSymmetricKeyBinaryFormat) - -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 types/project/3des.cpp types/project/hmac.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(ConvertSymmetricKeyBinaryFormat) + +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 types/project/3des.cpp types/project/hmac.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index b46e70b38c4936ae2d3af8ffe85edf8cd4ed3629..b919b8908ec7b082668d08e0b2c791cb42cea05b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/napi_init.cpp @@ -1,55 +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. - */ - -#include "napi/native_api.h" -#include "types/project/file.h" - -static napi_value NAPI_Global_doTestDataCovertSymKey(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestDataCovertSymKey(), &ret); - return ret; -} - -static napi_value NAPI_Global_testConvertHmacKey(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, testConvertHmacKey(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"doTestDataCovertSymKey", nullptr, NAPI_Global_doTestDataCovertSymKey, nullptr, - nullptr, nullptr, napi_default, nullptr}, - {"testConvertHmacKey", nullptr, NAPI_Global_testConvertHmacKey, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTestDataCovertSymKey(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestDataCovertSymKey(), &ret); + return ret; +} + +static napi_value NAPI_Global_testConvertHmacKey(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, testConvertHmacKey(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"doTestDataCovertSymKey", nullptr, NAPI_Global_doTestDataCovertSymKey, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"testConvertHmacKey", nullptr, NAPI_Global_testConvertHmacKey, 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 8e2a91aaa233631a7a060dbe934a4af4ffc9759e..b845170866b2350ffcd48af54966d0e2fdbb0729 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,18 +1,18 @@ -/* - * 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 doTestDataCovertSymKey: () => number; - +/* + * 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 doTestDataCovertSymKey: () => number; + export const testConvertHmacKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/3des.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/3des.cpp old mode 100755 new mode 100644 index 8636cc769213950fedd63106fdb87aac93d5a3ee..024c1f22e6627389fe907fbc6802e3e2e959edbe --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/3des.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/3des.cpp @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_key.h" -#include "file.h" - -OH_Crypto_ErrCode doTestDataCovertSymKey() -{ - const char *algName = "3DES192"; - OH_CryptoSymKeyGenerator *ctx = nullptr; - OH_CryptoSymKey *convertKeyCtx = nullptr; - Crypto_DataBlob out = {.data = nullptr, .len = 0}; - OH_Crypto_ErrCode ret; - uint8_t arr[] = {0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, 0xad, 0x47, 0xfc, 0x5a, - 0x46, 0x39, 0xee, 0x7c, 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72}; - Crypto_DataBlob convertBlob = {.data = arr, .len = sizeof(arr)}; - ret = OH_CryptoSymKeyGenerator_Create(algName, &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - ret = OH_CryptoSymKeyGenerator_Convert(ctx, &convertBlob, &convertKeyCtx); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoSymKeyGenerator_Destroy(ctx); - return ret; - } - ret = OH_CryptoSymKey_GetKeyData(convertKeyCtx, &out); - OH_CryptoSymKeyGenerator_Destroy(ctx); - OH_CryptoSymKey_Destroy(convertKeyCtx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - OH_Crypto_FreeDataBlob(&out); - return ret; -} - +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_key.h" +#include "file.h" + +OH_Crypto_ErrCode doTestDataCovertSymKey() +{ + const char *algName = "3DES192"; + OH_CryptoSymKeyGenerator *ctx = nullptr; + OH_CryptoSymKey *convertKeyCtx = nullptr; + Crypto_DataBlob out = {.data = nullptr, .len = 0}; + OH_Crypto_ErrCode ret; + uint8_t arr[] = {0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, 0xad, 0x47, 0xfc, 0x5a, + 0x46, 0x39, 0xee, 0x7c, 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72}; + Crypto_DataBlob convertBlob = {.data = arr, .len = sizeof(arr)}; + ret = OH_CryptoSymKeyGenerator_Create(algName, &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + ret = OH_CryptoSymKeyGenerator_Convert(ctx, &convertBlob, &convertKeyCtx); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoSymKeyGenerator_Destroy(ctx); + return ret; + } + ret = OH_CryptoSymKey_GetKeyData(convertKeyCtx, &out); + OH_CryptoSymKeyGenerator_Destroy(ctx); + OH_CryptoSymKey_Destroy(convertKeyCtx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + OH_Crypto_FreeDataBlob(&out); + return ret; +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 0014c8f10bed54274fc4a65940e0f1cfe3223e10..2169066f1a5759426fbbbc50af8f20a916b26507 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/file.h @@ -1,23 +1,23 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestDataCovertSymKey(); -OH_Crypto_ErrCode testConvertHmacKey(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestDataCovertSymKey(); +OH_Crypto_ErrCode testConvertHmacKey(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/hmac.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/hmac.cpp old mode 100755 new mode 100644 index 3443b09c9e7ad101ae4aea8bd5a17e337c5a2627..c53f5c6e3a123c312064e6ec8a31f03c9f752303 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/hmac.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/cpp/types/project/hmac.cpp @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_key.h" -#include -#include "file.h" - -OH_Crypto_ErrCode testConvertHmacKey() -{ - const char *algName = "HMAC"; - OH_CryptoSymKeyGenerator *ctx = nullptr; - OH_CryptoSymKey *convertKeyCtx = nullptr; - Crypto_DataBlob out = {.data = nullptr, .len = 0}; - OH_Crypto_ErrCode ret; - - char *arr = const_cast("12345678abcdefgh12345678abcdefgh12345678abcdefgh12345678abcdefgh"); - Crypto_DataBlob convertBlob = {.data = (uint8_t *)(arr), .len = strlen(arr)}; - ret = OH_CryptoSymKeyGenerator_Create(algName, &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - ret = OH_CryptoSymKeyGenerator_Convert(ctx, &convertBlob, &convertKeyCtx); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoSymKeyGenerator_Destroy(ctx); - return ret; - } - ret = OH_CryptoSymKey_GetKeyData(convertKeyCtx, &out); - OH_CryptoSymKeyGenerator_Destroy(ctx); - OH_CryptoSymKey_Destroy(convertKeyCtx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - OH_Crypto_FreeDataBlob(&out); - return ret; -} - +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_key.h" +#include +#include "file.h" + +OH_Crypto_ErrCode testConvertHmacKey() +{ + const char *algName = "HMAC"; + OH_CryptoSymKeyGenerator *ctx = nullptr; + OH_CryptoSymKey *convertKeyCtx = nullptr; + Crypto_DataBlob out = {.data = nullptr, .len = 0}; + OH_Crypto_ErrCode ret; + + char *arr = const_cast("12345678abcdefgh12345678abcdefgh12345678abcdefgh12345678abcdefgh"); + Crypto_DataBlob convertBlob = {.data = (uint8_t *)(arr), .len = strlen(arr)}; + ret = OH_CryptoSymKeyGenerator_Create(algName, &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + ret = OH_CryptoSymKeyGenerator_Convert(ctx, &convertBlob, &convertKeyCtx); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoSymKeyGenerator_Destroy(ctx); + return ret; + } + ret = OH_CryptoSymKey_GetKeyData(convertKeyCtx, &out); + OH_CryptoSymKeyGenerator_Destroy(ctx); + OH_CryptoSymKey_Destroy(convertKeyCtx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + OH_Crypto_FreeDataBlob(&out); + return ret; +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index a17ad623c796c0868ce25cc0405985a8926a9efb..bf0e19bee793e450ee86a037a5583266e5c08683 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/ets/pages/Index.ets @@ -1,44 +1,44 @@ -/* - * 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 { - @State message: string = 'ConvertSymmetricKeyBinaryFormat'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.3des')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doTestDataCovertSymKey(); - this.message = '3DES Success Result:' + ret.toString(); - }) - Button($r('app.string.hmac')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testConvertHmacKey(); - this.message = 'HMAC Success Result:' + ret.toString(); - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { + @State message: string = 'ConvertSymmetricKeyBinaryFormat'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.3des')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doTestDataCovertSymKey(); + this.message = '3DES Success Result:' + ret.toString(); + }) + Button($r('app.string.hmac')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testConvertHmacKey(); + this.message = 'HMAC Success Result:' + ret.toString(); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormat.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormat.test.ets old mode 100755 new mode 100644 index 20a5acac4054fe450cda51fbc44faaec04672036..fa05a8de551e52cc21edf31b4f5e0e09a04dcb8d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormat.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormat.test.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function convertSymmetricKeyBinaryFormatTest() { - describe('convertSymmetricKeyBinaryFormatTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,指定二进制数据转换对称密钥(3DES) - */ - it('testConvertSymmetricKeyBinaryFormat001', 0, async () => { - console.info('uitest: testConvertSymmetricKeyBinaryFormat001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('3DES')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('3DES Success Result:0')); - console.info('uitest: testConvertSymmetricKeyBinaryFormat001 end'); - }) - - /** - * 点击按钮,指定二进制数据转换对称密钥(HMAC) - */ - it('testConvertSymmetricKeyBinaryFormat002', 0, async () => { - console.info('uitest: testConvertSymmetricKeyBinaryFormat002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('HMAC')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('HMAC Success Result:0')); - console.info('uitest: testConvertSymmetricKeyBinaryFormat002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function convertSymmetricKeyBinaryFormatTest() { + describe('convertSymmetricKeyBinaryFormatTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,指定二进制数据转换对称密钥(3DES) + */ + it('testConvertSymmetricKeyBinaryFormat001', 0, async () => { + console.info('uitest: testConvertSymmetricKeyBinaryFormat001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('3DES')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('3DES Success Result:0')); + console.info('uitest: testConvertSymmetricKeyBinaryFormat001 end'); + }) + + /** + * 点击按钮,指定二进制数据转换对称密钥(HMAC) + */ + it('testConvertSymmetricKeyBinaryFormat002', 0, async () => { + console.info('uitest: testConvertSymmetricKeyBinaryFormat002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('HMAC')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('HMAC Success Result:0')); + console.info('uitest: testConvertSymmetricKeyBinaryFormat002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/ohosTest.md old mode 100755 new mode 100644 index b0efe41b95aad2680f29258c4e14594614354e9e..3d0857ee55eb0d338ef9bc6397df53cc71c71151 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/ohosTest.md @@ -1,9 +1,9 @@ -# 指定二进制数据转换对称密钥(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,指定二进制数据转换对称密钥(3DES) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 指定二进制数据转换对称密钥(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,指定二进制数据转换对称密钥(3DES) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,指定二进制数据转换对称密钥(HMAC) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/screenshots/ConvertSymmetricKeyBinaryFormat1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/screenshots/ConvertSymmetricKeyBinaryFormat1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/screenshots/ConvertSymmetricKeyBinaryFormat2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormat/screenshots/ConvertSymmetricKeyBinaryFormat2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/app.json5 old mode 100755 new mode 100644 index 98bb06c3591c103dd8625e9c1537fb0721f087af..13a98cdee53c155b382f3cfe3a61b46c1c70c64c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/app.json5 @@ -1,25 +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.convertsymmetrickeybinaryformatarkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.convertsymmetrickeybinaryformatarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index d0bbf57c68a10adb7a167d406336d14ca41ace8f..9e746ecc17a9cb8b29f2613e811ffe799f0ed772 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ConvertSymmetricKeyBinaryFormatArkTS" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ConvertSymmetricKeyBinaryFormatArkTS" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/README.md old mode 100755 new mode 100644 index 89c4fc9a4cb4cf80d8caca4d0349527f299acc27..e0e73fa912ec835c5a7ee0aea1e1eab7a7e0e4d9 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/README.md @@ -1,75 +1,75 @@ -# 指定二进制数据转换对称密钥(ArkTS) - -### 介绍 - -以3DES和HMAC为例,根据指定的对称密钥二进制数据,生成密钥(SymKey),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 - -本示例主要展示了指定二进制数据转换对称密钥(ArkTS),指定二进制数据转换3DES密钥和指定二进制数据转换HMAC密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [指定二进制数据转换对称密钥(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-sym-key.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例ConvertSymmetricKeyBinaryFormatArkTS.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 指定二进制数据转换对称密钥(ArkTS)示例代码 - │ │ ├── 3des - │ │ | ├── Callback.ets - │ │ | ├── Sync.ets - │ │ ├── hmac - │ │ | ├── Await.ets - │ │ | ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── ConvertSymmetricKeyBinaryFormatArkTS.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 指定二进制数据转换对称密钥(ArkTS) + +### 介绍 + +以3DES和HMAC为例,根据指定的对称密钥二进制数据,生成密钥(SymKey),即将外部或存储的二进制数据转换为算法库的密钥对象,该对象可用于后续的加解密等操作。 + +本示例主要展示了指定二进制数据转换对称密钥(ArkTS),指定二进制数据转换3DES密钥和指定二进制数据转换HMAC密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [指定二进制数据转换对称密钥(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-binary-data-to-sym-key.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例ConvertSymmetricKeyBinaryFormatArkTS.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 指定二进制数据转换对称密钥(ArkTS)示例代码 + │ │ ├── 3des + │ │ | ├── Callback.ets + │ │ | ├── Sync.ets + │ │ ├── hmac + │ │ | ├── Await.ets + │ │ | ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── ConvertSymmetricKeyBinaryFormatArkTS.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Callback.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Callback.ets old mode 100755 new mode 100644 index 5d5f65f4c4033d92cd21d4d46c17bb919a152d55..134d7666e94236e835fc44f442a2168d950c2409 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Callback.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Callback.ets @@ -1,73 +1,73 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -function genKeyMaterialBlob(): cryptoFramework.DataBlob { - let arr = [ - 0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, - 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c, - 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72]; // 密钥长度为192位,即24字节。 - let keyMaterial = new Uint8Array(arr); - return { data: keyMaterial }; -} - -function testConvertSymKey() { - // 创建SymKeyGenerator实例 - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); - // 根据指定的数据生成对称密钥 - let keyMaterialBlob = genKeyMaterialBlob(); - try { - symKeyGenerator.convertKey(keyMaterialBlob, (error, key) => { - if (error) { // 如果业务逻辑执行失败,则callback的第一个参数返回错误信息,即异步抛出异常 - let e: BusinessError = error as BusinessError; - console.error(`convertKey error, ${e.code}, ${e.message}`); - return; - } - console.info('key algName:' + key.algName); - console.info('key format:' + key.format); - let encodedKey = key.getEncoded(); // 获取对称密钥的二进制数据,并以字节数组形式输出。长度为24字节 - console.info('key getEncoded hex: ' + encodedKey.data); - }) - } catch (error) { // 参数检查发现错误立即抛出异常 - let e: BusinessError = error as BusinessError; - console.error(`convertKey failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Callback'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_3des_callback')) - .width('70%') - .onClick(() => { - try { - testConvertSymKey(); - this.message = '3DES Callback Success'; - } catch { - this.message = '3DES Callback Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function genKeyMaterialBlob(): cryptoFramework.DataBlob { + let arr = [ + 0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c, + 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72]; // 密钥长度为192位,即24字节。 + let keyMaterial = new Uint8Array(arr); + return { data: keyMaterial }; +} + +function testConvertSymKey() { + // 创建SymKeyGenerator实例 + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); + // 根据指定的数据生成对称密钥 + let keyMaterialBlob = genKeyMaterialBlob(); + try { + symKeyGenerator.convertKey(keyMaterialBlob, (error, key) => { + if (error) { // 如果业务逻辑执行失败,则callback的第一个参数返回错误信息,即异步抛出异常 + let e: BusinessError = error as BusinessError; + console.error(`convertKey error, ${e.code}, ${e.message}`); + return; + } + console.info('key algName:' + key.algName); + console.info('key format:' + key.format); + let encodedKey = key.getEncoded(); // 获取对称密钥的二进制数据,并以字节数组形式输出。长度为24字节 + console.info('key getEncoded hex: ' + encodedKey.data); + }) + } catch (error) { // 参数检查发现错误立即抛出异常 + let e: BusinessError = error as BusinessError; + console.error(`convertKey failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Callback'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_3des_callback')) + .width('70%') + .onClick(() => { + try { + testConvertSymKey(); + this.message = '3DES Callback Success'; + } catch { + this.message = '3DES Callback Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Sync.ets old mode 100755 new mode 100644 index c0fe17758c17d162bca20ddefaf0b240763fab0e..3781354af823a898ba94c374bc0cda749ef71ff8 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/3des/Sync.ets @@ -1,73 +1,73 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -function genKeyMaterialBlob(): cryptoFramework.DataBlob { - let arr = [ - 0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, - 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c, - 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72]; // 密钥长度为192位,即24字节。 - let keyMaterial = new Uint8Array(arr); - return { data: keyMaterial }; -} - -function testConvertSymKey() { - // 创建SymKeyGenerator实例 - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); - // 根据指定的数据生成对称密钥 - let keyMaterialBlob = genKeyMaterialBlob(); - try { - symKeyGenerator.convertKey(keyMaterialBlob, (error, key) => { - if (error) { // 如果业务逻辑执行失败,则callback的第一个参数返回错误信息,即异步抛出异常 - let e: BusinessError = error as BusinessError; - console.error(`convertKey error, ${e.code}, ${e.message}`); - return; - } - console.info('key algName:' + key.algName); - console.info('key format:' + key.format); - let encodedKey = key.getEncoded(); // 获取对称密钥的二进制数据,并以字节数组形式输出。长度为24字节 - console.info('key getEncoded hex: ' + encodedKey.data); - }) - } catch (error) { // 参数检查发现错误立即抛出异常 - let e: BusinessError = error as BusinessError; - console.error(`convertKey failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_3des_sync')) - .width('70%') - .onClick(() => { - try { - testConvertSymKey(); - this.message = '3DES Sync Success'; - } catch { - this.message = '3DES Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function genKeyMaterialBlob(): cryptoFramework.DataBlob { + let arr = [ + 0xba, 0x3d, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56, + 0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c, + 0xba, 0x3b, 0xc2, 0x71, 0xab, 0xa0, 0x30, 0x72]; // 密钥长度为192位,即24字节。 + let keyMaterial = new Uint8Array(arr); + return { data: keyMaterial }; +} + +function testConvertSymKey() { + // 创建SymKeyGenerator实例 + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('3DES192'); + // 根据指定的数据生成对称密钥 + let keyMaterialBlob = genKeyMaterialBlob(); + try { + symKeyGenerator.convertKey(keyMaterialBlob, (error, key) => { + if (error) { // 如果业务逻辑执行失败,则callback的第一个参数返回错误信息,即异步抛出异常 + let e: BusinessError = error as BusinessError; + console.error(`convertKey error, ${e.code}, ${e.message}`); + return; + } + console.info('key algName:' + key.algName); + console.info('key format:' + key.format); + let encodedKey = key.getEncoded(); // 获取对称密钥的二进制数据,并以字节数组形式输出。长度为24字节 + console.info('key getEncoded hex: ' + encodedKey.data); + }) + } catch (error) { // 参数检查发现错误立即抛出异常 + let e: BusinessError = error as BusinessError; + console.error(`convertKey failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_3des_sync')) + .width('70%') + .onClick(() => { + try { + testConvertSymKey(); + this.message = '3DES Sync Success'; + } catch { + this.message = '3DES Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Await.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Await.ets old mode 100755 new mode 100644 index 7c5d49092ba365fbb4a563e279a32f175e2cd03b..d46339e16be1445ba9e0f4d29ffcdaa33d051206 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Await.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Await.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function testConvertHmacKey() { - // 对称密钥长度为64字节,512比特 - let keyMessage = '12345678abcdefgh12345678abcdefgh12345678abcdefgh12345678abcdefgh'; - let keyBlob: cryptoFramework.DataBlob = { - data: new Uint8Array(buffer.from(keyMessage, 'utf-8').buffer) - } - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); - let key = await symKeyGenerator.convertKey(keyBlob); - let encodedKey = key.getEncoded(); - console.info('key encoded data:' + encodedKey.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'Await'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_hmac_await')) - .width('70%') - .onClick(async () => { - try { - await testConvertHmacKey(); - this.message = 'HMAC Await Success'; - } catch { - this.message = 'HMAC Await Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function testConvertHmacKey() { + // 对称密钥长度为64字节,512比特 + let keyMessage = '12345678abcdefgh12345678abcdefgh12345678abcdefgh12345678abcdefgh'; + let keyBlob: cryptoFramework.DataBlob = { + data: new Uint8Array(buffer.from(keyMessage, 'utf-8').buffer) + } + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); + let key = await symKeyGenerator.convertKey(keyBlob); + let encodedKey = key.getEncoded(); + console.info('key encoded data:' + encodedKey.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'Await'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_hmac_await')) + .width('70%') + .onClick(async () => { + try { + await testConvertHmacKey(); + this.message = 'HMAC Await Success'; + } catch { + this.message = 'HMAC Await Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Sync.ets old mode 100755 new mode 100644 index b4577e5ad00ac7c221cf830f38c9190db870857f..c838bb3c1200769cad6f28dfca5930c1ba54a28c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/ets/pages/hmac/Sync.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function testConvertKeySync() { - // 对称密钥长度为64字节,512比特 - let keyMessage = '12345678abcdefgh12345678abcdefgh12345678abcdefgh12345678abcdefgh'; - let keyBlob: cryptoFramework.DataBlob = { - data : new Uint8Array(buffer.from(keyMessage, 'utf-8').buffer) - } - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); - let key = symKeyGenerator.convertKeySync(keyBlob); - let encodedKey = key.getEncoded(); - console.info('key encoded data:' + encodedKey.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_hmac_sync')) - .width('70%') - .onClick(() => { - try { - testConvertKeySync(); - this.message = 'HMAC Sync Success'; - } catch { - this.message = 'HMAC Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function testConvertKeySync() { + // 对称密钥长度为64字节,512比特 + let keyMessage = '12345678abcdefgh12345678abcdefgh12345678abcdefgh12345678abcdefgh'; + let keyBlob: cryptoFramework.DataBlob = { + data : new Uint8Array(buffer.from(keyMessage, 'utf-8').buffer) + } + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); + let key = symKeyGenerator.convertKeySync(keyBlob); + let encodedKey = key.getEncoded(); + console.info('key encoded data:' + encodedKey.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_hmac_sync')) + .width('70%') + .onClick(() => { + try { + testConvertKeySync(); + this.message = 'HMAC Sync Success'; + } catch { + this.message = 'HMAC Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormatArkTS.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormatArkTS.test.ets old mode 100755 new mode 100644 index 2d9ad30904f8c3310f34cd155795ab3c7670aef8..acd0bdd3c5d6dafea6ec802bc01a8099c11eaf8c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormatArkTS.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/ConvertSymmetricKeyBinaryFormatArkTS.test.ets @@ -1,116 +1,116 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function convertSymmetricKeyBinaryFormatArkTSTest() { - describe('convertSymmetricKeyBinaryFormatArkTSTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,指定二进制数据转换对称密钥(3DES callback方式) - */ - it('testConvertSymmetricKeyBinaryFormatArkTS001', 0, async () => { - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('3DES Callback')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call 3DES Callback')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('3DES Callback Success')); - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换对称密钥(3DES 同步方式) - */ - it('testConvertSymmetricKeyBinaryFormatArkTS002', 0, async () => { - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('3DES Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call 3DES Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('3DES Sync Success')); - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换对称密钥(HMAC await方式) - */ - it('testConvertSymmetricKeyBinaryFormatArkTS003', 0, async () => { - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('HMAC Await')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call HMAC Await')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('HMAC Await Success')); - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定二进制数据转换对称密钥(HMAC 同步方式) - */ - it('testConvertSymmetricKeyBinaryFormatArkTS004', 0, async () => { - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('HMAC Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call HMAC Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('HMAC Sync Success')); - console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function convertSymmetricKeyBinaryFormatArkTSTest() { + describe('convertSymmetricKeyBinaryFormatArkTSTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,指定二进制数据转换对称密钥(3DES callback方式) + */ + it('testConvertSymmetricKeyBinaryFormatArkTS001', 0, async () => { + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('3DES Callback')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call 3DES Callback')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('3DES Callback Success')); + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换对称密钥(3DES 同步方式) + */ + it('testConvertSymmetricKeyBinaryFormatArkTS002', 0, async () => { + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('3DES Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call 3DES Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('3DES Sync Success')); + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换对称密钥(HMAC await方式) + */ + it('testConvertSymmetricKeyBinaryFormatArkTS003', 0, async () => { + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('HMAC Await')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call HMAC Await')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('HMAC Await Success')); + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定二进制数据转换对称密钥(HMAC 同步方式) + */ + it('testConvertSymmetricKeyBinaryFormatArkTS004', 0, async () => { + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('HMAC Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call HMAC Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('HMAC Sync Success')); + console.info('uitest: testConvertSymmetricKeyBinaryFormatArkTS004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/ohosTest.md old mode 100755 new mode 100644 index ef892568aaabc5cba600bad25c40dfbe5a022bac..2d2602064bfd5d6156a444a0242bf43f6c91af88 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/ohosTest.md @@ -1,11 +1,11 @@ -# 指定二进制数据转换对称密钥(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,指定二进制数据转换对称密钥(3DES callback方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换对称密钥(3DES 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定二进制数据转换对称密钥(HMAC await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 指定二进制数据转换对称密钥(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,指定二进制数据转换对称密钥(3DES callback方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换对称密钥(3DES 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定二进制数据转换对称密钥(HMAC await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,指定二进制数据转换对称密钥(HMAC 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/screenshots/ConvertSymmetricKeyBinaryFormatArkTS1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/screenshots/ConvertSymmetricKeyBinaryFormatArkTS1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/screenshots/ConvertSymmetricKeyBinaryFormatArkTS2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ConvertSymmetricKeyBinaryFormatArkTS/screenshots/ConvertSymmetricKeyBinaryFormatArkTS2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/app.json5 old mode 100755 new mode 100644 index f0e59de766eb9ca0c2be628cb3a5014cb6921c24..4bd0fd9f0054d82202c8f1317c650c4e5072e299 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/app.json5 @@ -1,25 +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.ecccompresspublickeyformatconversion", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.ecccompresspublickeyformatconversion", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 0b4c15377a612670199f6bfd457a09efe8a22ad7..e741108c2e828a8834f325bb1c966b57a2f604b4 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ECCCompressPublicKeyFormatConversion" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ECCCompressPublicKeyFormatConversion" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/README.md old mode 100755 new mode 100644 index 7de12b007cf6a04f639e01bfa5e0c6ddb73df5bf..08e4d78cab86db236a84e0a7a6b6010a186ddf9d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/README.md @@ -1,84 +1,84 @@ -# 使用ECC压缩/非压缩格式转换 - -### 介绍 - -可通过指定ECC公钥数据,生成公钥对象(PubKey);也可从公钥对象(PubKey)中,获取ECC公钥数据。当前仅支持ECC算法中,满足X509规范的压缩/非压缩格式的公钥数据。此处的公钥数据应当是完整的X509公钥,对于只使用点数据的情况. - -本示例主要展示了使用ECC压缩/非压缩公钥格式转换(ArkTS)、使用ECC压缩/非压缩公钥格式转换(C/C++)、使用ECC压缩/非压缩点格式转换场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [使用ECC压缩/非压缩公钥格式转换(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-compressed-or-uncompressed-ECC-pubkey.md) -- [使用ECC压缩/非压缩公钥格式转换(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-compressed-or-uncompressed-ECC-pubkey-ndk.md) -- [使用ECC压缩/非压缩点格式转换](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-compressed-or-uncompressed-ECC-point.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例ECCCompressPublicKeyFormatConversion.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── specifyUncompressedPublicKey.cpp - │ │ | ├── file.h - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 使用ECC压缩/非压缩格式转换示例代码 - │ │ ├── CompressedPointData.ets - │ │ ├── GetKeyObject.ets - │ │ ├── SpecifyUncompressedPublicKey.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── ECCCompressPublicKeyFormatConversion.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 使用ECC压缩/非压缩格式转换 + +### 介绍 + +可通过指定ECC公钥数据,生成公钥对象(PubKey);也可从公钥对象(PubKey)中,获取ECC公钥数据。当前仅支持ECC算法中,满足X509规范的压缩/非压缩格式的公钥数据。此处的公钥数据应当是完整的X509公钥,对于只使用点数据的情况. + +本示例主要展示了使用ECC压缩/非压缩公钥格式转换(ArkTS)、使用ECC压缩/非压缩公钥格式转换(C/C++)、使用ECC压缩/非压缩点格式转换场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [使用ECC压缩/非压缩公钥格式转换(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-compressed-or-uncompressed-ECC-pubkey.md) +- [使用ECC压缩/非压缩公钥格式转换(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-compressed-or-uncompressed-ECC-pubkey-ndk.md) +- [使用ECC压缩/非压缩点格式转换](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-convert-compressed-or-uncompressed-ECC-point.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例ECCCompressPublicKeyFormatConversion.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── specifyUncompressedPublicKey.cpp + │ │ | ├── file.h + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用ECC压缩/非压缩格式转换示例代码 + │ │ ├── CompressedPointData.ets + │ │ ├── GetKeyObject.ets + │ │ ├── SpecifyUncompressedPublicKey.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── ECCCompressPublicKeyFormatConversion.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 07e5f6b78a83b9dce843a6491f819a2c97524376..99340164a167ee01952f889e835389ce8811d34f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(ECCCompressPublicKeyFormatConversion) - -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 types/project/specifyUncompressedPublicKey.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(ECCCompressPublicKeyFormatConversion) + +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 types/project/specifyUncompressedPublicKey.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 7e5e45dba06a391744b811c69f3ace0f1eceae4e..fb044058090ea117bfff90c8229fd1d39150dbee --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/napi_init.cpp @@ -1,46 +1,46 @@ -/* - * 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 "types/project/file.h" - -static napi_value NAPI_Global_doTestEccDataCovert(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestEccDataCovert(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"doTestEccDataCovert", nullptr, NAPI_Global_doTestEccDataCovert, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTestEccDataCovert(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestEccDataCovert(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"doTestEccDataCovert", nullptr, NAPI_Global_doTestEccDataCovert, 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 351b95574f9625807820e93e93c00f8a76cddc8b..7ace52c4f4f5675d24c19ba1e486fdb0482e194d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,16 +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. - */ - +/* + * 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 doTestEccDataCovert: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 46646f6b1a9000dd6557d7008836d89e7729a520..028afbe0eb16ca668cb9977caf5212b9e3cf1d76 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/file.h @@ -1,22 +1,22 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestEccDataCovert(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestEccDataCovert(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/specifyUncompressedPublicKey.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/specifyUncompressedPublicKey.cpp old mode 100755 new mode 100644 index e5985817fea078c89ba570651f30618c692c9964..3b2c16151205707443b645f41822af2f31f390b8 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/specifyUncompressedPublicKey.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/cpp/types/project/specifyUncompressedPublicKey.cpp @@ -1,58 +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. - */ - -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" - -OH_Crypto_ErrCode doTestEccDataCovert() -{ - OH_CryptoAsymKeyGenerator *generator = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - Crypto_DataBlob returnBlob = { .data = nullptr, .len = 0 }; - OH_Crypto_ErrCode ret = CRYPTO_INVALID_PARAMS; - - ret = OH_CryptoAsymKeyGenerator_Create("ECC_BrainPoolP256r1", &generator); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - uint8_t pubKeyBlobData[] = { - 48, 90, 48, 20, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 9, 43, 36, 3, 3, 2, - 8, 1, 1, 7, 3, 66, 0, 4, 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, - 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, 157, 111, 40, 217, 215, - 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, - 228, 123, 242, 206, 200, 98, 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, - 46, 163, 156, 152 - }; - Crypto_DataBlob pubKeyUncompressedBlob = { - .data = pubKeyBlobData, - .len = sizeof(pubKeyBlobData), - }; - ret = OH_CryptoAsymKeyGenerator_Convert(generator, CRYPTO_DER, &pubKeyUncompressedBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(generator); - return ret; - } - - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - ret = OH_CryptoPubKey_Encode(pubKey, CRYPTO_DER, "X509|COMPRESSED", &returnBlob); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(generator); - OH_CryptoKeyPair_Destroy(keyPair); - return ret; - } - OH_CryptoAsymKeyGenerator_Destroy(generator); - OH_CryptoKeyPair_Destroy(keyPair); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" + +OH_Crypto_ErrCode doTestEccDataCovert() +{ + OH_CryptoAsymKeyGenerator *generator = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + Crypto_DataBlob returnBlob = { .data = nullptr, .len = 0 }; + OH_Crypto_ErrCode ret = CRYPTO_INVALID_PARAMS; + + ret = OH_CryptoAsymKeyGenerator_Create("ECC_BrainPoolP256r1", &generator); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + uint8_t pubKeyBlobData[] = { + 48, 90, 48, 20, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 9, 43, 36, 3, 3, 2, + 8, 1, 1, 7, 3, 66, 0, 4, 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, + 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, 157, 111, 40, 217, 215, + 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, + 228, 123, 242, 206, 200, 98, 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, + 46, 163, 156, 152 + }; + Crypto_DataBlob pubKeyUncompressedBlob = { + .data = pubKeyBlobData, + .len = sizeof(pubKeyBlobData), + }; + ret = OH_CryptoAsymKeyGenerator_Convert(generator, CRYPTO_DER, &pubKeyUncompressedBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(generator); + return ret; + } + + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + ret = OH_CryptoPubKey_Encode(pubKey, CRYPTO_DER, "X509|COMPRESSED", &returnBlob); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(generator); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; + } + OH_CryptoAsymKeyGenerator_Destroy(generator); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/CompressedPointData.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/CompressedPointData.ets old mode 100755 new mode 100644 index 088deb071d4ad2f3296095c941f47dc5541ad1a8..8f045db61e414bd6da50b4017159543deb54859c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/CompressedPointData.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/CompressedPointData.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function eccPointUncompressedToCompressed() { - let pkData = - new Uint8Array([4, 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, - 157, 111, 40, 217, 215, 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, 228, 123, 242, - 206, 200, 98, 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, 46, 163, 156, 152]); - let returnPoint = cryptoFramework.ECCKeyUtil.convertPoint('NID_brainpoolP256r1', pkData); - console.info('convertPoint success'); - let returnData = cryptoFramework.ECCKeyUtil.getEncodedPoint('NID_brainpoolP256r1', returnPoint, 'COMPRESSED'); - console.info('returnData: ' + - returnData); // (因为y为偶数,所以压缩点数据的前缀是02)returnData: 2,143,39,57,249,145,50,63,222,35,70,178,121,202,154,21, - // 146,129,75,76,63,8,195,157,111,40,217,215,148,120,224,205,82 -} - -@Entry -@Component -struct Index { - @State message: string = 'CompressedPointData'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_compressedPointData')) - .width('70%') - .onClick(() => { - try { - eccPointUncompressedToCompressed(); - this.message = 'CompressedPointData Success'; - } catch { - this.message = 'CompressedPointData Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function eccPointUncompressedToCompressed() { + let pkData = + new Uint8Array([4, 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, + 157, 111, 40, 217, 215, 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, 228, 123, 242, + 206, 200, 98, 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, 46, 163, 156, 152]); + let returnPoint = cryptoFramework.ECCKeyUtil.convertPoint('NID_brainpoolP256r1', pkData); + console.info('convertPoint success'); + let returnData = cryptoFramework.ECCKeyUtil.getEncodedPoint('NID_brainpoolP256r1', returnPoint, 'COMPRESSED'); + console.info('returnData: ' + + returnData); // (因为y为偶数,所以压缩点数据的前缀是02)returnData: 2,143,39,57,249,145,50,63,222,35,70,178,121,202,154,21, + // 146,129,75,76,63,8,195,157,111,40,217,215,148,120,224,205,82 +} + +@Entry +@Component +struct Index { + @State message: string = 'CompressedPointData'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_compressedPointData')) + .width('70%') + .onClick(() => { + try { + eccPointUncompressedToCompressed(); + this.message = 'CompressedPointData Success'; + } catch { + this.message = 'CompressedPointData Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/GetKeyObject.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/GetKeyObject.ets old mode 100755 new mode 100644 index 86a13a432228d6ee96e613d643a89b7d94d2e325..de77296888bee22989f7ea794085e59ea8ca0c93 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/GetKeyObject.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/GetKeyObject.ets @@ -1,67 +1,67 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function eccPointCompressedToPoint() { - let pkData = - new Uint8Array([2, 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, - 157, 111, 40, 217, 215, 148, 120, 224, 205, 82]); - let returnPoint = cryptoFramework.ECCKeyUtil.convertPoint('NID_brainpoolP256r1', pkData); - console.info('convertPoint success'); - let eccCommonParamsSpec = cryptoFramework.ECCKeyUtil.genECCCommonParamsSpec('NID_brainpoolP256r1'); - let eccPubKeySpec: cryptoFramework.ECCPubKeySpec = { - algName: 'ECC', - specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC, - params: eccCommonParamsSpec, - pk: returnPoint - }; - let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(eccPubKeySpec); - let pubKey = await generatorBySpec.generatePubKey(); - let returnData = cryptoFramework.ECCKeyUtil.getEncodedPoint('NID_brainpoolP256r1', returnPoint, 'UNCOMPRESSED'); - console.info('returnData: ' + - returnData); // 4,143,39,57,249,145,50,63,222,35,70,178,121,202,154,21,146,129,75,76,63,8,195,157,111, - // 40,217,215,148,120,224,205,82,83,92,185,21,211,184,5,19,114,33,86,85,228,123,242,206,200,98,178,184, - // 130,35,232,45,5,202,189,11,46,163,156,152 - let eccPkX = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_X_BN); - console.info('returnPoint x data: ' + - returnPoint.x); // 64750044510792891439269945828433327517677381559622384455951527515863444933970 - console.info('ECC_PK_X_BN:' + - eccPkX); // 64750044510792891439269945828433327517677381559622384455951527515863444933970 -} - -@Entry -@Component -struct Index { - @State message: string = 'GetKeyObject'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_getKeyObject')) - .width('70%') - .onClick(async () => { - try { - await eccPointCompressedToPoint(); - this.message = 'GetKeyObject Success'; - } catch { - this.message = 'GetKeyObject Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function eccPointCompressedToPoint() { + let pkData = + new Uint8Array([2, 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, + 157, 111, 40, 217, 215, 148, 120, 224, 205, 82]); + let returnPoint = cryptoFramework.ECCKeyUtil.convertPoint('NID_brainpoolP256r1', pkData); + console.info('convertPoint success'); + let eccCommonParamsSpec = cryptoFramework.ECCKeyUtil.genECCCommonParamsSpec('NID_brainpoolP256r1'); + let eccPubKeySpec: cryptoFramework.ECCPubKeySpec = { + algName: 'ECC', + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC, + params: eccCommonParamsSpec, + pk: returnPoint + }; + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(eccPubKeySpec); + let pubKey = await generatorBySpec.generatePubKey(); + let returnData = cryptoFramework.ECCKeyUtil.getEncodedPoint('NID_brainpoolP256r1', returnPoint, 'UNCOMPRESSED'); + console.info('returnData: ' + + returnData); // 4,143,39,57,249,145,50,63,222,35,70,178,121,202,154,21,146,129,75,76,63,8,195,157,111, + // 40,217,215,148,120,224,205,82,83,92,185,21,211,184,5,19,114,33,86,85,228,123,242,206,200,98,178,184, + // 130,35,232,45,5,202,189,11,46,163,156,152 + let eccPkX = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_X_BN); + console.info('returnPoint x data: ' + + returnPoint.x); // 64750044510792891439269945828433327517677381559622384455951527515863444933970 + console.info('ECC_PK_X_BN:' + + eccPkX); // 64750044510792891439269945828433327517677381559622384455951527515863444933970 +} + +@Entry +@Component +struct Index { + @State message: string = 'GetKeyObject'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_getKeyObject')) + .width('70%') + .onClick(async () => { + try { + await eccPointCompressedToPoint(); + this.message = 'GetKeyObject Success'; + } catch { + this.message = 'GetKeyObject Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 6036ad8755dc4cee7b4717bbeb76a2e0c9ab5c53..1d878bc7e041f3ea8325edfdb802f40dd980ae74 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/Index.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { router } from '@kit.ArkUI'; -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'ECCCompressPublicKeyFormatConversion'; - - goToSample(url: string): void { - router.pushUrl({ - url: url, - }, router.RouterMode.Single, (err) => { - if (err) { - console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info('pushUrl success'); - }) - } - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(20) - .fontWeight(FontWeight.Bold) - Button($r('app.string.SpecifyUncompressedPublicKey')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.doTestEccDataCovert(); - this.message = 'doTestEccDataCovert Success Result:' + ret.toString(); - }) - Button($r('app.string.SpecifyUncompressedPublicKeyArkTS')) - .width('70%') - .onClick(() => { - this.goToSample('pages/SpecifyUncompressedPublicKey') - }) - Button($r('app.string.CompressedPointData')) - .width('70%') - .onClick(() => { - this.goToSample('pages/CompressedPointData') - }) - Button($r('app.string.GetKeyObject')) - .width('70%') - .onClick(() => { - this.goToSample('pages/GetKeyObject') - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { router } from '@kit.ArkUI'; +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'ECCCompressPublicKeyFormatConversion'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + Button($r('app.string.SpecifyUncompressedPublicKey')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.doTestEccDataCovert(); + this.message = 'doTestEccDataCovert Success Result:' + ret.toString(); + }) + Button($r('app.string.SpecifyUncompressedPublicKeyArkTS')) + .width('70%') + .onClick(() => { + this.goToSample('pages/SpecifyUncompressedPublicKey') + }) + Button($r('app.string.CompressedPointData')) + .width('70%') + .onClick(() => { + this.goToSample('pages/CompressedPointData') + }) + Button($r('app.string.GetKeyObject')) + .width('70%') + .onClick(() => { + this.goToSample('pages/GetKeyObject') + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/SpecifyUncompressedPublicKey.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/SpecifyUncompressedPublicKey.ets old mode 100755 new mode 100644 index e2668612bd0b886e626547a6af956879a96ae0ed..62af5761ab00b410b5eae4e7546d829e4fe5ec86 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/SpecifyUncompressedPublicKey.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/ets/pages/SpecifyUncompressedPublicKey.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function eccPubUncompressedToCompressed() { - let pkData = - new Uint8Array([48, 90, 48, 20, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 9, 43, 36, 3, 3, 2, 8, 1, 1, 7, 3, 66, 0, 4, - 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, 157, 111, 40, - 217, 215, 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, 228, 123, 242, 206, 200, 98, - 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, 46, 163, 156, 152]); - let pubKeyBlob: cryptoFramework.DataBlob = { data: pkData }; - let generator = cryptoFramework.createAsyKeyGenerator('ECC_BrainPoolP256r1'); - let keyPair = await generator.convertKey(pubKeyBlob, null); - let returnBlob = keyPair.pubKey.getEncodedDer('X509|COMPRESSED'); - console.info('returnBlob data:' + returnBlob.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'SpecifyUncompressedPublicKey'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_specifyUncompressedPublicKey')) - .width('70%') - .onClick(async () => { - try { - await eccPubUncompressedToCompressed(); - this.message = 'SpecifyUncompressedPublicKey Success'; - } catch { - this.message = 'SpecifyUncompressedPublicKey Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function eccPubUncompressedToCompressed() { + let pkData = + new Uint8Array([48, 90, 48, 20, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 9, 43, 36, 3, 3, 2, 8, 1, 1, 7, 3, 66, 0, 4, + 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, 157, 111, 40, + 217, 215, 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, 228, 123, 242, 206, 200, 98, + 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, 46, 163, 156, 152]); + let pubKeyBlob: cryptoFramework.DataBlob = { data: pkData }; + let generator = cryptoFramework.createAsyKeyGenerator('ECC_BrainPoolP256r1'); + let keyPair = await generator.convertKey(pubKeyBlob, null); + let returnBlob = keyPair.pubKey.getEncodedDer('X509|COMPRESSED'); + console.info('returnBlob data:' + returnBlob.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'SpecifyUncompressedPublicKey'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_specifyUncompressedPublicKey')) + .width('70%') + .onClick(async () => { + try { + await eccPubUncompressedToCompressed(); + this.message = 'SpecifyUncompressedPublicKey Success'; + } catch { + this.message = 'SpecifyUncompressedPublicKey Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/ECCCompressPublicKeyFormatConversion.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/ECCCompressPublicKeyFormatConversion.test.ets old mode 100755 new mode 100644 index d26cb86c1b7ec4bc5bec566d9be20d8274cebc7d..b5bd589ba4e322e1e7a10dee248a937eb4cd94ee --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/ECCCompressPublicKeyFormatConversion.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/ECCCompressPublicKeyFormatConversion.test.ets @@ -1,112 +1,112 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function eccCompressPublicKeyFormatConversionTest() { - describe('eccCompressPublicKeyFormatConversionTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用ECC压缩/非压缩公钥格式转换(C/C++) - */ - it('testEccCompressPublicKeyFormatConversion001', 0, async () => { - console.info('uitest: testEccCompressPublicKeyFormatConversion001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SpecifyUncompressedPublicKey')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('doTestEccDataCovert Success Result:0')); - console.info('uitest: testEccCompressPublicKeyFormatConversion001 end'); - }) - - /** - * 点击按钮,使用ECC压缩/非压缩公钥格式转换(ArkTS) - */ - it('testEccCompressPublicKeyFormatConversion002', 0, async () => { - console.info('uitest: testEccCompressPublicKeyFormatConversion002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SpecifyUncompressedPublicKeyArkTS')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SpecifyUncompressedPublicKey')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SpecifyUncompressedPublicKey Success')); - console.info('uitest: testEccCompressPublicKeyFormatConversion002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用ECC压缩/非压缩点格式转换(指定非压缩点数据转换为压缩点数据) - */ - it('testEccCompressPublicKeyFormatConversion003', 0, async () => { - console.info('uitest: testEccCompressPublicKeyFormatConversion003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('CompressedPointData')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CompressedPointData')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('CompressedPointData Success')); - console.info('uitest: testEccCompressPublicKeyFormatConversion003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用ECC压缩/非压缩点格式转换(指定压缩点数据获取密钥对象) - */ - it('testEccCompressPublicKeyFormatConversion004', 0, async () => { - console.info('uitest: testEccCompressPublicKeyFormatConversion004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('GetKeyObject')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call GetKeyObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('GetKeyObject Success')); - console.info('uitest: testEccCompressPublicKeyFormatConversion004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function eccCompressPublicKeyFormatConversionTest() { + describe('eccCompressPublicKeyFormatConversionTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用ECC压缩/非压缩公钥格式转换(C/C++) + */ + it('testEccCompressPublicKeyFormatConversion001', 0, async () => { + console.info('uitest: testEccCompressPublicKeyFormatConversion001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SpecifyUncompressedPublicKey')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('doTestEccDataCovert Success Result:0')); + console.info('uitest: testEccCompressPublicKeyFormatConversion001 end'); + }) + + /** + * 点击按钮,使用ECC压缩/非压缩公钥格式转换(ArkTS) + */ + it('testEccCompressPublicKeyFormatConversion002', 0, async () => { + console.info('uitest: testEccCompressPublicKeyFormatConversion002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SpecifyUncompressedPublicKeyArkTS')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SpecifyUncompressedPublicKey')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SpecifyUncompressedPublicKey Success')); + console.info('uitest: testEccCompressPublicKeyFormatConversion002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECC压缩/非压缩点格式转换(指定非压缩点数据转换为压缩点数据) + */ + it('testEccCompressPublicKeyFormatConversion003', 0, async () => { + console.info('uitest: testEccCompressPublicKeyFormatConversion003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('CompressedPointData')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CompressedPointData')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('CompressedPointData Success')); + console.info('uitest: testEccCompressPublicKeyFormatConversion003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECC压缩/非压缩点格式转换(指定压缩点数据获取密钥对象) + */ + it('testEccCompressPublicKeyFormatConversion004', 0, async () => { + console.info('uitest: testEccCompressPublicKeyFormatConversion004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('GetKeyObject')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call GetKeyObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('GetKeyObject Success')); + console.info('uitest: testEccCompressPublicKeyFormatConversion004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/ohosTest.md old mode 100755 new mode 100644 index 9baaf295cfac526d9fcfd0455059a05e858210fe..13c6e7e5a29e35c161829daf6cd1c9a68989fcd7 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/ohosTest.md @@ -1,11 +1,11 @@ -# 使用ECC压缩/非压缩格式转换测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用ECC压缩/非压缩公钥格式转换(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用ECC压缩/非压缩公钥格式转换(ArkTS) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用ECC压缩/非压缩点格式转换(指定非压缩点数据转换为压缩点数据) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 使用ECC压缩/非压缩格式转换测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用ECC压缩/非压缩公钥格式转换(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECC压缩/非压缩公钥格式转换(ArkTS) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECC压缩/非压缩点格式转换(指定非压缩点数据转换为压缩点数据) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用ECC压缩/非压缩点格式转换(指定压缩点数据获取密钥对象) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/screenshots/ECCCompressPublicKeyFormatConversion1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/screenshots/ECCCompressPublicKeyFormatConversion1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/screenshots/ECCCompressPublicKeyFormatConversion2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/ECCCompressPublicKeyFormatConversion/screenshots/ECCCompressPublicKeyFormatConversion2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/app.json5 old mode 100755 new mode 100644 index 6e73874745f7d38384984fa7f6c68c1bb3f147a1..ec79f46166024fa07864cae9e6f73e09c022b9ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/app.json5 @@ -1,25 +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.randomlygenerateasymmetrickeypair", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.randomlygenerateasymmetrickeypair", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 0e2bfe3619948b85e4d9df16a71d45a1c8273bf0..8b2697f29766e6eaf67e43c2d4cf82a7418b10a1 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "RandomlyGenerateAsymmetricKeyPair" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "RandomlyGenerateAsymmetricKeyPair" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/README.md old mode 100755 new mode 100644 index 59cdecc50d19631c299650b7152759183e84656c..5f3d17a7469cc458094fd0751d6dc1cd0c63c7f2 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/README.md @@ -1,80 +1,80 @@ -# 随机生成非对称密钥对(C/C++) - -### 介绍 - -以RSA和SM2为例,随机生成非对称密钥对(OH_CryptoKeyPair),并获得二进制数据。非对称密钥对可用于后续加解密等操作,二进制数据可用于存储或运输。 - -本示例主要展示了随机生成非对称密钥对(C/C++),随机生成RSA、SM2密钥对场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [随机生成非对称密钥对(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-asym-key-pair-randomly-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例RandomlyGenerateAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── sm2.cpp - │ │ | ├── file.h - │ │ | ├── rsa.cpp - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 随机生成非对称密钥对(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── RandomlyGenerateAsymmetricKeyPair.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 随机生成非对称密钥对(C/C++) + +### 介绍 + +以RSA和SM2为例,随机生成非对称密钥对(OH_CryptoKeyPair),并获得二进制数据。非对称密钥对可用于后续加解密等操作,二进制数据可用于存储或运输。 + +本示例主要展示了随机生成非对称密钥对(C/C++),随机生成RSA、SM2密钥对场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [随机生成非对称密钥对(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-asym-key-pair-randomly-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例RandomlyGenerateAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── sm2.cpp + │ │ | ├── file.h + │ │ | ├── rsa.cpp + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 随机生成非对称密钥对(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── RandomlyGenerateAsymmetricKeyPair.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 6c5f6bf25347f1678c9eedde78bf9eada3ecb2f5..ace0c9826d12376fd07228a6ce4506c2e043633b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(RandomlyGenerateAsymmetricKeyPair) - -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 types/project/rsa.cpp types/project/sm2.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(RandomlyGenerateAsymmetricKeyPair) + +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 types/project/rsa.cpp types/project/sm2.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 51469dbaf84160544553b93d6cdfcd097f3ca6f7..a781d775947bc6a88834b51b42bfa037a1ee007e --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/napi_init.cpp @@ -1,53 +1,53 @@ -/* - * 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 "types/project/file.h" - -static napi_value NAPI_Global_randomGenerateAsymKey(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, randomGenerateAsymKey(), &ret); - return ret; -} -static napi_value NAPI_Global_randomGenerateRSA(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, randomGenerateRSA(), &ret); - return ret; -} -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"randomGenerateAsymKey", nullptr, NAPI_Global_randomGenerateAsymKey, nullptr, - nullptr, nullptr, napi_default, nullptr}, - {"randomGenerateRSA", nullptr, NAPI_Global_randomGenerateRSA, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_randomGenerateAsymKey(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, randomGenerateAsymKey(), &ret); + return ret; +} +static napi_value NAPI_Global_randomGenerateRSA(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, randomGenerateRSA(), &ret); + return ret; +} +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"randomGenerateAsymKey", nullptr, NAPI_Global_randomGenerateAsymKey, nullptr, + nullptr, nullptr, napi_default, nullptr}, + {"randomGenerateRSA", nullptr, NAPI_Global_randomGenerateRSA, 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 79549f1de180faa37965229a7af8950189f7deb8..6cc44ebc5538e023df40dd85e48436eac2c15479 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,18 +1,18 @@ -/* - * 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 randomGenerateAsymKey: () => number; - +/* + * 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 randomGenerateAsymKey: () => number; + export const randomGenerateRSA: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index e209fd8b3e936155481e442d992302dbbbea2a17..ef4b0f684319b22cca11c621c04f568e6bbc6040 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/file.h @@ -1,24 +1,24 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" - -OH_Crypto_ErrCode randomGenerateAsymKey(); -OH_Crypto_ErrCode randomGenerateRSA(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" + +OH_Crypto_ErrCode randomGenerateAsymKey(); +OH_Crypto_ErrCode randomGenerateRSA(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp old mode 100755 new mode 100644 index 2fd48802bd241f5f46d28b978e20d685a8dc38c6..e6b02ca1ed03a8262bfc09cddcb05ff633f997e7 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/rsa.cpp @@ -1,53 +1,53 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" -#include "file.h" - -OH_Crypto_ErrCode randomGenerateAsymKey() -{ - OH_CryptoAsymKeyGenerator *ctx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_Crypto_ErrCode ret; - - ret = OH_CryptoAsymKeyGenerator_Create("RSA1024|PRIMES_2", &ctx); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - return ret; - } - - ret = OH_CryptoAsymKeyGenerator_Generate(ctx, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(keyPair); - return ret; - } - - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - Crypto_DataBlob retBlob = {.data = nullptr, .len = 0}; - ret = OH_CryptoPubKey_Encode(pubKey, CRYPTO_PEM, "PKCS1", &retBlob); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(keyPair); - return ret; - } - - OH_Crypto_FreeDataBlob(&retBlob); - - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(keyPair); - return ret; -} +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" +#include "file.h" + +OH_Crypto_ErrCode randomGenerateAsymKey() +{ + OH_CryptoAsymKeyGenerator *ctx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_Crypto_ErrCode ret; + + ret = OH_CryptoAsymKeyGenerator_Create("RSA1024|PRIMES_2", &ctx); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + return ret; + } + + ret = OH_CryptoAsymKeyGenerator_Generate(ctx, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; + } + + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + Crypto_DataBlob retBlob = {.data = nullptr, .len = 0}; + ret = OH_CryptoPubKey_Encode(pubKey, CRYPTO_PEM, "PKCS1", &retBlob); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; + } + + OH_Crypto_FreeDataBlob(&retBlob); + + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp old mode 100755 new mode 100644 index 0149bf1b6237897628686d6acf58b12104a65013..96f9b8b385f3aee2b4f9654b9176e23c4d44812b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/cpp/types/project/sm2.cpp @@ -1,51 +1,51 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" -#include "file.h" - -OH_Crypto_ErrCode randomGenerateRSA() -{ - OH_CryptoAsymKeyGenerator *ctx = nullptr; - OH_CryptoKeyPair *dupKeyPair = nullptr; - OH_Crypto_ErrCode ret; - - ret = OH_CryptoAsymKeyGenerator_Create("SM2_256", &ctx); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - return ret; - } - - ret = OH_CryptoAsymKeyGenerator_Generate(ctx, &dupKeyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; - } - - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(dupKeyPair); - Crypto_DataBlob retBlob = { .data = nullptr, .len = 0 }; - ret = OH_CryptoPubKey_Encode(pubKey, CRYPTO_DER, nullptr, &retBlob); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; - } - - OH_CryptoAsymKeyGenerator_Destroy(ctx); - OH_CryptoKeyPair_Destroy(dupKeyPair); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" +#include "file.h" + +OH_Crypto_ErrCode randomGenerateRSA() +{ + OH_CryptoAsymKeyGenerator *ctx = nullptr; + OH_CryptoKeyPair *dupKeyPair = nullptr; + OH_Crypto_ErrCode ret; + + ret = OH_CryptoAsymKeyGenerator_Create("SM2_256", &ctx); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + return ret; + } + + ret = OH_CryptoAsymKeyGenerator_Generate(ctx, &dupKeyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; + } + + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(dupKeyPair); + Crypto_DataBlob retBlob = { .data = nullptr, .len = 0 }; + ret = OH_CryptoPubKey_Encode(pubKey, CRYPTO_DER, nullptr, &retBlob); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; + } + + OH_CryptoAsymKeyGenerator_Destroy(ctx); + OH_CryptoKeyPair_Destroy(dupKeyPair); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 7636c7b9f2a56de6cd7dfed433426458dd53dfbb..31df824f96ce1fd72310f11ec44cb4fc90cb1a9a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets @@ -1,44 +1,44 @@ -/* - * 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 { - @State message: string = 'RandomlyGenerateAsymmetricKeyPair'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.randomGenerateAsymKey(); - this.message = 'Call RSA Success Result:' + ret.toString(); - }) - Button($r('app.string.call_sm2')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.randomGenerateRSA(); - this.message = 'Call SM2 Success Result:' + ret.toString(); - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { + @State message: string = 'RandomlyGenerateAsymmetricKeyPair'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.randomGenerateAsymKey(); + this.message = 'Call RSA Success Result:' + ret.toString(); + }) + Button($r('app.string.call_sm2')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.randomGenerateRSA(); + this.message = 'Call SM2 Success Result:' + ret.toString(); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPair.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPair.test.ets old mode 100755 new mode 100644 index e0df163ee297dd5b811881e926e3ebeb8275f2aa..cc5008f1c4b25dc75d51517abf3f63f345c22776 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPair.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPair.test.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function randomlyGenerateAsymmetricKeyPairTest() { - describe('randomlyGenerateAsymmetricKeyPairTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,随机生成非对称密钥对(RSA) - */ - it('testRandomlyGenerateAsymmetricKeyPair001', 0, async () => { - console.info('uitest: testRandomlyGenerateAsymmetricKeyPair001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call RSA')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call RSA Success Result:0')); - console.info('uitest: testRandomlyGenerateAsymmetricKeyPair001 end'); - }) - - /** - * 点击按钮,随机生成非对称密钥对(SM2) - */ - it('testRandomlyGenerateAsymmetricKeyPair002', 0, async () => { - console.info('uitest: testRandomlyGenerateAsymmetricKeyPair002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM2')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call SM2 Success Result:0')); - console.info('uitest: testRandomlyGenerateAsymmetricKeyPair002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function randomlyGenerateAsymmetricKeyPairTest() { + describe('randomlyGenerateAsymmetricKeyPairTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,随机生成非对称密钥对(RSA) + */ + it('testRandomlyGenerateAsymmetricKeyPair001', 0, async () => { + console.info('uitest: testRandomlyGenerateAsymmetricKeyPair001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call RSA')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call RSA Success Result:0')); + console.info('uitest: testRandomlyGenerateAsymmetricKeyPair001 end'); + }) + + /** + * 点击按钮,随机生成非对称密钥对(SM2) + */ + it('testRandomlyGenerateAsymmetricKeyPair002', 0, async () => { + console.info('uitest: testRandomlyGenerateAsymmetricKeyPair002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM2')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call SM2 Success Result:0')); + console.info('uitest: testRandomlyGenerateAsymmetricKeyPair002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/ohosTest.md old mode 100755 new mode 100644 index 70148643fc4f8369a101c88e3a2ea6f6c951eb9a..6705d611b727f5435fc5e66a378574a82d47e871 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/ohosTest.md @@ -1,9 +1,9 @@ -# 随机生成非对称密钥对(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,随机生成非对称密钥对(RSA) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 随机生成非对称密钥对(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,随机生成非对称密钥对(RSA) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,随机生成非对称密钥对(SM2) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/screenshots/RandomlyGenerateAsymmetricKeyPair1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/screenshots/RandomlyGenerateAsymmetricKeyPair1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/screenshots/RandomlyGenerateAsymmetricKeyPair2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPair/screenshots/RandomlyGenerateAsymmetricKeyPair2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/app.json5 old mode 100755 new mode 100644 index 2bee01b4aff2ef5b785ccc640b39bc0372f09048..bf9e81bc4f9293c27da755556cf484fc84d445e5 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/app.json5 @@ -1,25 +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.randomlygenerateasymmetrickeypairarkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.randomlygenerateasymmetrickeypairarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 99aa3f9c60268e8a2121673f54f69c79863036a6..bd5ebcd46a4735e78818eb639a43add99827079d --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "RandomlyGenerateAsymmetricKeyPairArkTS" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "RandomlyGenerateAsymmetricKeyPairArkTS" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/README.md old mode 100755 new mode 100644 index db40d6e6d468cb065d3df716e2e376506544e6a5..1070ad5051c290fc0e97871e0a3335ced4757e3c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/README.md @@ -1,75 +1,75 @@ -# 随机生成非对称密钥对(ArkTS) - -### 介绍 - -以RSA和SM2为例,随机生成非对称密钥对(KeyPair),并获得二进制数据。非对称密钥对可用于后续加解密等操作,二进制数据可用于存储或运输。 - -本示例主要展示了随机生成非对称密钥对(ArkTS),随机生成RSA、SM2密钥对场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [随机生成非对称密钥对(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-asym-key-pair-randomly.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例RandomlyGenerateAsymmetricKeyPairArkTS.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 随机生成非对称密钥对(ArkTS)示例代码 - │ │ ├── rsa - │ │ | ├── Promise.ets - │ │ | ├── Sync.ets - │ │ ├── sm2 - │ │ | ├── Promise.ets - │ │ | ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── RandomlyGenerateAsymmetricKeyPairArkTS.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 随机生成非对称密钥对(ArkTS) + +### 介绍 + +以RSA和SM2为例,随机生成非对称密钥对(KeyPair),并获得二进制数据。非对称密钥对可用于后续加解密等操作,二进制数据可用于存储或运输。 + +本示例主要展示了随机生成非对称密钥对(ArkTS),随机生成RSA、SM2密钥对场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [随机生成非对称密钥对(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-asym-key-pair-randomly.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例RandomlyGenerateAsymmetricKeyPairArkTS.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 随机生成非对称密钥对(ArkTS)示例代码 + │ │ ├── rsa + │ │ | ├── Promise.ets + │ │ | ├── Sync.ets + │ │ ├── sm2 + │ │ | ├── Promise.ets + │ │ | ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── RandomlyGenerateAsymmetricKeyPairArkTS.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Promise.ets old mode 100755 new mode 100644 index 410b58f7cb7cc51d2d517df740cbda9fc8636139..4abc7fb8b85d82fac3ffd9bde0183d32da3dbb59 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Promise.ets @@ -1,56 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function generateAsyKey() { - // 创建一个AsyKeyGenerator实例 - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_2'); - // 使用密钥生成器随机生成非对称密钥对 - let keyGenPromise = rsaGenerator.generateKeyPair(); - keyGenPromise.then(keyPair => { - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - // 获取非对称密钥对的二进制数据 - let pkBlob = pubKey.getEncoded(); - let skBlob = priKey.getEncoded(); - console.info('pk bin data' + pkBlob.data); - console.info('sk bin data' + skBlob.data); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_promise')) - .width('70%') - .onClick(() => { - try { - generateAsyKey(); - this.message = 'RSA Promise Success'; - } catch { - this.message = 'RSA Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function generateAsyKey() { + // 创建一个AsyKeyGenerator实例 + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_2'); + // 使用密钥生成器随机生成非对称密钥对 + let keyGenPromise = rsaGenerator.generateKeyPair(); + keyGenPromise.then(keyPair => { + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + // 获取非对称密钥对的二进制数据 + let pkBlob = pubKey.getEncoded(); + let skBlob = priKey.getEncoded(); + console.info('pk bin data' + pkBlob.data); + console.info('sk bin data' + skBlob.data); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_promise')) + .width('70%') + .onClick(() => { + try { + generateAsyKey(); + this.message = 'RSA Promise Success'; + } catch { + this.message = 'RSA Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets old mode 100755 new mode 100644 index e02ef1080168ed91578bb3d211a7ed126e95a37f..fc7d6af58a3d117760032ea3b6ddcb9c514cdc35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/rsa/Sync.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function generateAsyKeySync() { - // 创建一个AsyKeyGenerator实例 - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_2'); - // 使用密钥生成器随机生成非对称密钥对 - try { - let keyPair = rsaGenerator.generateKeyPairSync(); - if (keyPair != null) { - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - // 获取非对称密钥对的二进制数据 - let pkBlob = pubKey.getEncoded(); - let skBlob = priKey.getEncoded(); - console.info('pk bin data' + pkBlob.data); - console.info('sk bin data' + skBlob.data); - } else { - console.error('[Sync]: get key pair result fail!'); - } - } catch (e) { - console.error(`get key pair failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_sync')) - .width('70%') - .onClick(() => { - try { - generateAsyKeySync(); - this.message = 'RSA Sync Success'; - } catch { - this.message = 'RSA Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function generateAsyKeySync() { + // 创建一个AsyKeyGenerator实例 + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_2'); + // 使用密钥生成器随机生成非对称密钥对 + try { + let keyPair = rsaGenerator.generateKeyPairSync(); + if (keyPair != null) { + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + // 获取非对称密钥对的二进制数据 + let pkBlob = pubKey.getEncoded(); + let skBlob = priKey.getEncoded(); + console.info('pk bin data' + pkBlob.data); + console.info('sk bin data' + skBlob.data); + } else { + console.error('[Sync]: get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_sync')) + .width('70%') + .onClick(() => { + try { + generateAsyKeySync(); + this.message = 'RSA Sync Success'; + } catch { + this.message = 'RSA Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Promise.ets old mode 100755 new mode 100644 index d7b51efaef432cafbfa1528e6c508b476678c3fd..367887bf89081903d2650baf69913ff6bf5fe7a3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Promise.ets @@ -1,56 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function generateSM2Key() { - // 创建一个AsyKeyGenerator实例 - let sm2Generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); - // 使用密钥生成器随机生成非对称密钥对 - let keyGenPromise = sm2Generator.generateKeyPair(); - keyGenPromise.then(keyPair => { - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - // 获取非对称密钥对的二进制数据 - let pkBlob = pubKey.getEncoded(); - let skBlob = priKey.getEncoded(); - console.info('pk bin data' + pkBlob.data); - console.info('sk bin data' + skBlob.data); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_promise')) - .width('70%') - .onClick(() => { - try { - generateSM2Key(); - this.message = 'SM2 Promise Success'; - } catch { - this.message = 'SM2 Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function generateSM2Key() { + // 创建一个AsyKeyGenerator实例 + let sm2Generator = cryptoFramework.createAsyKeyGenerator('SM2_256'); + // 使用密钥生成器随机生成非对称密钥对 + let keyGenPromise = sm2Generator.generateKeyPair(); + keyGenPromise.then(keyPair => { + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + // 获取非对称密钥对的二进制数据 + let pkBlob = pubKey.getEncoded(); + let skBlob = priKey.getEncoded(); + console.info('pk bin data' + pkBlob.data); + console.info('sk bin data' + skBlob.data); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_promise')) + .width('70%') + .onClick(() => { + try { + generateSM2Key(); + this.message = 'SM2 Promise Success'; + } catch { + this.message = 'SM2 Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets old mode 100755 new mode 100644 index 38bbc78858b5f0780a8b9394f2bf9353bd3b429a..e77a46f6c5262c65b91082eb4802bfcda7b8ce31 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/ets/pages/sm2/Sync.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function generateSM2KeySync() { - // 创建一个AsyKeyGenerator实例 - let rsaGenerator = cryptoFramework.createAsyKeyGenerator('SM2_256'); - // 使用密钥生成器随机生成非对称密钥对 - try { - let keyPair = rsaGenerator.generateKeyPairSync(); - if (keyPair != null) { - let pubKey = keyPair.pubKey; - let priKey = keyPair.priKey; - // 获取非对称密钥对的二进制数据 - let pkBlob = pubKey.getEncoded(); - let skBlob = priKey.getEncoded(); - console.info('pk bin data' + pkBlob.data); - console.info('sk bin data' + skBlob.data); - } else { - console.error('[Sync]: get key pair result fail!'); - } - } catch (e) { - console.error(`get key pair failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_sync')) - .width('70%') - .onClick(() => { - try { - generateSM2KeySync(); - this.message = 'SM2 Sync Success'; - } catch { - this.message = 'SM2 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function generateSM2KeySync() { + // 创建一个AsyKeyGenerator实例 + let rsaGenerator = cryptoFramework.createAsyKeyGenerator('SM2_256'); + // 使用密钥生成器随机生成非对称密钥对 + try { + let keyPair = rsaGenerator.generateKeyPairSync(); + if (keyPair != null) { + let pubKey = keyPair.pubKey; + let priKey = keyPair.priKey; + // 获取非对称密钥对的二进制数据 + let pkBlob = pubKey.getEncoded(); + let skBlob = priKey.getEncoded(); + console.info('pk bin data' + pkBlob.data); + console.info('sk bin data' + skBlob.data); + } else { + console.error('[Sync]: get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_sync')) + .width('70%') + .onClick(() => { + try { + generateSM2KeySync(); + this.message = 'SM2 Sync Success'; + } catch { + this.message = 'SM2 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPairArkTS.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPairArkTS.test.ets old mode 100755 new mode 100644 index 5c07cdc8974a8caff0905bceb3d40d817769aea0..5a8cdfe785b92e142bd8a0d97605a62b5ec323ab --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPairArkTS.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateAsymmetricKeyPairArkTS.test.ets @@ -1,116 +1,116 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function randomlyGenerateAsymmetricKeyPairArkTSTest() { - describe('randomlyGenerateAsymmetricKeyPairArkTSTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,随机生成非对称密钥对(RSA Promise方式) - */ - it('testRandomlyGenerateAsymmetricKeyPairArkTS001', 0, async () => { - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Promise Success')); - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,随机生成非对称密钥对(RSA 同步方式) - */ - it('testRandomlyGenerateAsymmetricKeyPairArkTS002', 0, async () => { - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Sync Success')); - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,随机生成非对称密钥对(SM2 Promise方式) - */ - it('testRandomlyGenerateAsymmetricKeyPairArkTS003', 0, async () => { - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Promise Success')); - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,随机生成非对称密钥对(SM2 同步方式) - */ - it('testRandomlyGenerateAsymmetricKeyPairArkTS004', 0, async () => { - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Sync Success')); - console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function randomlyGenerateAsymmetricKeyPairArkTSTest() { + describe('randomlyGenerateAsymmetricKeyPairArkTSTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,随机生成非对称密钥对(RSA Promise方式) + */ + it('testRandomlyGenerateAsymmetricKeyPairArkTS001', 0, async () => { + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Promise Success')); + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,随机生成非对称密钥对(RSA 同步方式) + */ + it('testRandomlyGenerateAsymmetricKeyPairArkTS002', 0, async () => { + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Sync Success')); + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,随机生成非对称密钥对(SM2 Promise方式) + */ + it('testRandomlyGenerateAsymmetricKeyPairArkTS003', 0, async () => { + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Promise Success')); + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,随机生成非对称密钥对(SM2 同步方式) + */ + it('testRandomlyGenerateAsymmetricKeyPairArkTS004', 0, async () => { + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Sync Success')); + console.info('uitest: testRandomlyGenerateAsymmetricKeyPairArkTS004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/ohosTest.md old mode 100755 new mode 100644 index 12243c6aeba86cfba25f99c4661094036c31c4ea..acf17e91e43304cebeb847b10ea04d335256df58 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/ohosTest.md @@ -1,11 +1,11 @@ -# 随机生成非对称密钥对(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,随机生成非对称密钥对(RSA Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,随机生成非对称密钥对(RSA 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,随机生成非对称密钥对(SM2 Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 随机生成非对称密钥对(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,随机生成非对称密钥对(RSA Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,随机生成非对称密钥对(RSA 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,随机生成非对称密钥对(SM2 Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,随机生成非对称密钥对(SM2 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/screenshots/RandomlyGenerateAsymmetricKeyPairArkTS1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/screenshots/RandomlyGenerateAsymmetricKeyPairArkTS1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/screenshots/RandomlyGenerateAsymmetricKeyPairArkTS2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateAsymmetricKeyPairArkTS/screenshots/RandomlyGenerateAsymmetricKeyPairArkTS2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/app.json5 old mode 100755 new mode 100644 index fe14bc8bea529b9d0a41b96a88f668dd08bd5c75..050d254981e17a60345c543098aa212f0a2cb33e --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/app.json5 @@ -1,25 +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.randomlygeneratesymmetrickey", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.randomlygeneratesymmetrickey", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 6ba815b2238596a95671c5b54331af4482e4f027..e400fe91aaa62b7676bb6e47c514968d4c0acf68 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "RandomlyGenerateSymmetricKey" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "RandomlyGenerateSymmetricKey" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/README.md old mode 100755 new mode 100644 index 1b0a4f0cf9393557ebeb1fc7f6e897e718b84317..ec6c451a8ffd6d09e63043e0f8652be54437df83 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/README.md @@ -1,80 +1,80 @@ -# 随机生成对称密钥(C/C++) - -### 介绍 - -以AES和SM4为例,随机生成对称密钥(OH_CryptoSymKey)。对称密钥对象可用于后续加解密操作,二进制数据可用于存储或运输。 - -本示例主要展示了随机生成对称密钥(C/C++),随机生成AES、SM4密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [随机生成对称密钥(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-sym-key-randomly-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例RandomlyGenerateSymmetricKey.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── aes.cpp - │ │ | ├── file.h - │ │ | ├── sm4.cpp - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 随机生成对称密钥(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── RandomlyGenerateSymmetricKey.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 随机生成对称密钥(C/C++) + +### 介绍 + +以AES和SM4为例,随机生成对称密钥(OH_CryptoSymKey)。对称密钥对象可用于后续加解密操作,二进制数据可用于存储或运输。 + +本示例主要展示了随机生成对称密钥(C/C++),随机生成AES、SM4密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [随机生成对称密钥(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-sym-key-randomly-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例RandomlyGenerateSymmetricKey.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── aes.cpp + │ │ | ├── file.h + │ │ | ├── sm4.cpp + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 随机生成对称密钥(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── RandomlyGenerateSymmetricKey.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 0ae7b82df5c60e6ceb0014b529a62fbedbe48bfc..8f216f9500faa1b5bc699e4fd826490e4973f11e --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(RandomlyGenerateSymmetricKey) - -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 types/project/aes.cpp types/project/sm4.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(RandomlyGenerateSymmetricKey) + +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 types/project/aes.cpp types/project/sm4.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 68d7644115c0cab5db114b87c3d8c9aebf1582fb..b718f5d2af5e7a6243426dabe3c0a47433332f3f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/napi_init.cpp @@ -1,57 +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. - */ - -#include "napi/native_api.h" -#include "types/project/file.h" - -static napi_value NAPI_Global_testGenerateSM4Key(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, testGenerateSymKey(), &ret); - return ret; -} - -static napi_value NAPI_Global_testGenerateSymKey(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, testGenerateSM4Key(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - - {"testGenerateSM4Key", nullptr, NAPI_Global_testGenerateSM4Key, nullptr, nullptr, nullptr, napi_default, - nullptr}, - {"testGenerateSymKey", nullptr, NAPI_Global_testGenerateSymKey, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_testGenerateSM4Key(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, testGenerateSymKey(), &ret); + return ret; +} + +static napi_value NAPI_Global_testGenerateSymKey(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, testGenerateSM4Key(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + + {"testGenerateSM4Key", nullptr, NAPI_Global_testGenerateSM4Key, nullptr, nullptr, nullptr, napi_default, + nullptr}, + {"testGenerateSymKey", nullptr, NAPI_Global_testGenerateSymKey, 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 8f0344e1716ce1c571f3513c7cfd811cfa7829f7..b90c1af84a2f0bf1e47c5f5f0a6d42256d4ddc18 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,18 +1,18 @@ -/* - * 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 testGenerateSymKey: () => number; - +/* + * 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 testGenerateSymKey: () => number; + export const testGenerateSM4Key: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/aes.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/aes.cpp old mode 100755 new mode 100644 index d147ec6e0d666bd9bd2aff7613003b2f304f56a5..e5ce931d9664e0064aa52006cf432983db56b1ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/aes.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/aes.cpp @@ -1,42 +1,42 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_key.h" -#include "file.h" - -OH_Crypto_ErrCode testGenerateSymKey() -{ - OH_CryptoSymKeyGenerator *ctx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - Crypto_DataBlob out = {.data = nullptr, .len = 0}; - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES256", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - ret = OH_CryptoSymKeyGenerator_Generate(ctx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoSymKeyGenerator_Destroy(ctx); - return ret; - } - ret = OH_CryptoSymKey_GetKeyData(keyCtx, &out); - OH_CryptoSymKeyGenerator_Destroy(ctx); - OH_CryptoSymKey_Destroy(keyCtx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - OH_Crypto_FreeDataBlob(&out); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_key.h" +#include "file.h" + +OH_Crypto_ErrCode testGenerateSymKey() +{ + OH_CryptoSymKeyGenerator *ctx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + Crypto_DataBlob out = {.data = nullptr, .len = 0}; + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("AES256", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + ret = OH_CryptoSymKeyGenerator_Generate(ctx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoSymKeyGenerator_Destroy(ctx); + return ret; + } + ret = OH_CryptoSymKey_GetKeyData(keyCtx, &out); + OH_CryptoSymKeyGenerator_Destroy(ctx); + OH_CryptoSymKey_Destroy(keyCtx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + OH_Crypto_FreeDataBlob(&out); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 619116bf40271175f5b33634c02456b69d511890..31e35bb0c3761e30771930c5df51b967ba77c215 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/file.h @@ -1,23 +1,23 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode testGenerateSymKey(); -OH_Crypto_ErrCode testGenerateSM4Key(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode testGenerateSymKey(); +OH_Crypto_ErrCode testGenerateSM4Key(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/sm4.cpp b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/sm4.cpp old mode 100755 new mode 100644 index 7a326b9a666aa912bdef56e0a1922998a8d79da9..42c5dfe5d1b04c38eb882352c8abbf957e8c8b1f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/sm4.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/cpp/types/project/sm4.cpp @@ -1,42 +1,42 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_sym_key.h" -#include "file.h" - -OH_Crypto_ErrCode testGenerateSM4Key() -{ - OH_CryptoSymKeyGenerator *ctx = nullptr; - OH_CryptoSymKey *keyCtx = nullptr; - Crypto_DataBlob out = {.data = nullptr, .len = 0}; - OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - ret = OH_CryptoSymKeyGenerator_Generate(ctx, &keyCtx); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoSymKeyGenerator_Destroy(ctx); - return ret; - } - ret = OH_CryptoSymKey_GetKeyData(keyCtx, &out); - OH_CryptoSymKeyGenerator_Destroy(ctx); - OH_CryptoSymKey_Destroy(keyCtx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - OH_Crypto_FreeDataBlob(&out); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_sym_key.h" +#include "file.h" + +OH_Crypto_ErrCode testGenerateSM4Key() +{ + OH_CryptoSymKeyGenerator *ctx = nullptr; + OH_CryptoSymKey *keyCtx = nullptr; + Crypto_DataBlob out = {.data = nullptr, .len = 0}; + OH_Crypto_ErrCode ret = OH_CryptoSymKeyGenerator_Create("SM4_128", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + ret = OH_CryptoSymKeyGenerator_Generate(ctx, &keyCtx); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoSymKeyGenerator_Destroy(ctx); + return ret; + } + ret = OH_CryptoSymKey_GetKeyData(keyCtx, &out); + OH_CryptoSymKeyGenerator_Destroy(ctx); + OH_CryptoSymKey_Destroy(keyCtx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + OH_Crypto_FreeDataBlob(&out); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 3cf9885f60ec0a7783ed393d72f0dd956a7ef62f..f290adcc5aa6c8a31719f9cf8b90c2ab30ba81eb --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/ets/pages/Index.ets @@ -1,44 +1,44 @@ -/* - * 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 { - @State message: string = 'RandomlyGenerateSymmetricKey'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testGenerateSymKey(); - this.message = 'Call AES Success Result:' + ret.toString(); - }) - Button($r('app.string.call_sm4')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.testGenerateSM4Key(); - this.message = 'Call SM4 Success Result:' + ret.toString(); - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { + @State message: string = 'RandomlyGenerateSymmetricKey'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testGenerateSymKey(); + this.message = 'Call AES Success Result:' + ret.toString(); + }) + Button($r('app.string.call_sm4')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.testGenerateSM4Key(); + this.message = 'Call SM4 Success Result:' + ret.toString(); + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKey.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKey.test.ets old mode 100755 new mode 100644 index a6892bf7a75d21ecd87ad1d836e7541855440755..a764585f4269066d507092100d5df6cb76ad1ee2 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKey.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKey.test.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionGuidanceAesTest() { - describe('encryptionDecryptionGuidanceAesTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,随机生成对称密钥(AES) - */ - it('testEncryptionDecryptionGuidanceAes001', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call AES')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call AES Success Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes001 end'); - }) - - /** - * 点击按钮,随机生成对称密钥(SM4) - */ - it('testEncryptionDecryptionGuidanceAes002', 0, async () => { - console.info('uitest: testEncryptionDecryptionGuidanceAes002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM4')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call SM4 Success Result:0')); - console.info('uitest: testEncryptionDecryptionGuidanceAes002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionGuidanceAesTest() { + describe('encryptionDecryptionGuidanceAesTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,随机生成对称密钥(AES) + */ + it('testEncryptionDecryptionGuidanceAes001', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call AES')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call AES Success Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes001 end'); + }) + + /** + * 点击按钮,随机生成对称密钥(SM4) + */ + it('testEncryptionDecryptionGuidanceAes002', 0, async () => { + console.info('uitest: testEncryptionDecryptionGuidanceAes002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM4')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call SM4 Success Result:0')); + console.info('uitest: testEncryptionDecryptionGuidanceAes002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/ohosTest.md old mode 100755 new mode 100644 index 02be69a3a15c12a1c01ca5df9346b38ad726676a..a2782d5bd9a3a18732a9c8c779979b13eadf0693 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/ohosTest.md @@ -1,9 +1,9 @@ -# 随机生成对称密钥(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,随机生成对称密钥(AES) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 随机生成对称密钥(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,随机生成对称密钥(AES) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,随机生成对称密钥(SM4) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/screenshots/RandomlyGenerateSymmetricKey1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/screenshots/RandomlyGenerateSymmetricKey1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/screenshots/RandomlyGenerateSymmetricKey2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKey/screenshots/RandomlyGenerateSymmetricKey2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/app.json5 old mode 100755 new mode 100644 index d22270a8e1b00a9b1340e67277c2f8a8286689e4..7375775fcb28d700f801dfedc0d9cb134e88cf85 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/app.json5 @@ -1,25 +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.randomlygeneratesymmetrickeyarkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.randomlygeneratesymmetrickeyarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 6a8e9bbcd3ae7330cb0d9fc05f002094f57caa8a..e5498d2667883d57b32049d4c582affa8785da59 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "RandomlyGenerateSymmetricKeyArkTS" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "RandomlyGenerateSymmetricKeyArkTS" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/README.md old mode 100755 new mode 100644 index 091b34bdc5de166cdf52918dc2fead1f7b2295ae..1c5af4d2007cc2b2be9c1824ce320835b412af84 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/README.md @@ -1,75 +1,75 @@ -# 随机生成对称密钥(ArkTS) - -### 介绍 - -以AES和SM4为例,随机生成对称密钥(SymKey),并获得二进制数据。对称密钥对象可用于后续加解密操作,二进制数据可用于存储或运输。 - -本示例主要展示了随机生成对称密钥(ArkTS),随机生成AES、SM4密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [随机生成对称密钥(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-sym-key-randomly.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例RandomlyGenerateSymmetricKeyArkTS.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 随机生成对称密钥(ArkTS)示例代码 - │ │ ├── aes - │ │ | ├── Promise.ets - │ │ | ├── Sync.ets - │ │ ├── sm4 - │ │ | ├── Promise.ets - │ │ | ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── RandomlyGenerateSymmetricKeyArkTS.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 随机生成对称密钥(ArkTS) + +### 介绍 + +以AES和SM4为例,随机生成对称密钥(SymKey),并获得二进制数据。对称密钥对象可用于后续加解密操作,二进制数据可用于存储或运输。 + +本示例主要展示了随机生成对称密钥(ArkTS),随机生成AES、SM4密钥场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [随机生成对称密钥(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-sym-key-randomly.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例RandomlyGenerateSymmetricKeyArkTS.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 随机生成对称密钥(ArkTS)示例代码 + │ │ ├── aes + │ │ | ├── Promise.ets + │ │ | ├── Sync.ets + │ │ ├── sm4 + │ │ | ├── Promise.ets + │ │ | ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── RandomlyGenerateSymmetricKeyArkTS.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Promise.ets old mode 100755 new mode 100644 index f4c834ba29eb8f6e0421876a7479e7d734d28d3a..ae868f82b57a548e10c7f7e52d82548d58998c5a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Promise.ets @@ -1,52 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function testGenerateAesKey() { - // 创建SymKeyGenerator实例 - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); - // 使用密钥生成器随机生成对称密钥 - let promiseSymKey = symKeyGenerator.generateSymKey(); - promiseSymKey.then(key => { - // 获取对称密钥的二进制数据,输出256位密钥。长度为32字节 - let encodedKey = key.getEncoded(); - console.info('key hex:' + encodedKey.data); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'AES Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_promise')) - .width('70%') - .onClick(() => { - try { - testGenerateAesKey(); - this.message = 'AES Promise Success'; - } catch { - this.message = 'AES Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function testGenerateAesKey() { + // 创建SymKeyGenerator实例 + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); + // 使用密钥生成器随机生成对称密钥 + let promiseSymKey = symKeyGenerator.generateSymKey(); + promiseSymKey.then(key => { + // 获取对称密钥的二进制数据,输出256位密钥。长度为32字节 + let encodedKey = key.getEncoded(); + console.info('key hex:' + encodedKey.data); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'AES Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_promise')) + .width('70%') + .onClick(() => { + try { + testGenerateAesKey(); + this.message = 'AES Promise Success'; + } catch { + this.message = 'AES Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Sync.ets old mode 100755 new mode 100644 index a143c89ab5fa7babf3b6aa9510f6b66a00c9b1ab..0e4481a65bfde5e837254cb47a704116831c200a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/aes/Sync.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function testSyncGenerateAesKey() { - // 创建SymKeyGenerator实例 - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); - // 使用密钥生成器随机生成对称密钥 - let promiseSymKey = symKeyGenerator.generateSymKeySync(); - // 获取对称密钥的二进制数据,输出256位密钥。长度为32字节 - let encodedKey = promiseSymKey.getEncoded(); - console.info('key hex:' + encodedKey.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'AES Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_aes_sync')) - .width('70%') - .onClick(() => { - try { - testSyncGenerateAesKey(); - this.message = 'AES Sync Success'; - } catch { - this.message = 'AES Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function testSyncGenerateAesKey() { + // 创建SymKeyGenerator实例 + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('AES256'); + // 使用密钥生成器随机生成对称密钥 + let promiseSymKey = symKeyGenerator.generateSymKeySync(); + // 获取对称密钥的二进制数据,输出256位密钥。长度为32字节 + let encodedKey = promiseSymKey.getEncoded(); + console.info('key hex:' + encodedKey.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'AES Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_aes_sync')) + .width('70%') + .onClick(() => { + try { + testSyncGenerateAesKey(); + this.message = 'AES Sync Success'; + } catch { + this.message = 'AES Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Promise.ets old mode 100755 new mode 100644 index 2a647d12e480e231f445de4c54aa4aaff5e72d52..4f95dfce22623a5dfb42cababe8f40f3a4ccdfd0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Promise.ets @@ -1,52 +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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function testGenerateSM4Key() { - // 创建SymKeyGenerator实例 - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); - // 使用密钥生成器随机生成对称密钥 - let promiseSymKey = symKeyGenerator.generateSymKey(); - promiseSymKey.then(key => { - // 获取对称密钥的二进制数据,输出128位字节流。长度为16字节 - let encodedKey = key.getEncoded(); - console.info('key hex:' + encodedKey.data); - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'SM4 Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_promise')) - .width('70%') - .onClick(() => { - try { - testGenerateSM4Key(); - this.message = 'SM4 Promise Success'; - } catch { - this.message = 'SM4 Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function testGenerateSM4Key() { + // 创建SymKeyGenerator实例 + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); + // 使用密钥生成器随机生成对称密钥 + let promiseSymKey = symKeyGenerator.generateSymKey(); + promiseSymKey.then(key => { + // 获取对称密钥的二进制数据,输出128位字节流。长度为16字节 + let encodedKey = key.getEncoded(); + console.info('key hex:' + encodedKey.data); + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'SM4 Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_promise')) + .width('70%') + .onClick(() => { + try { + testGenerateSM4Key(); + this.message = 'SM4 Promise Success'; + } catch { + this.message = 'SM4 Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Sync.ets old mode 100755 new mode 100644 index 9daf80aa81d693021481f7b82f1d0e3b16140048..0cad4d73f860e4ca5e11cbe4b43595877ded3c32 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/ets/pages/sm4/Sync.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function testSyncGenerateSm4Key() { - // 创建SymKeyGenerator实例 - let symKeyGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); - // 使用密钥生成器随机生成对称密钥 - let promiseSymKey = symKeyGenerator.generateSymKeySync(); - // 获取对称密钥的二进制数据,输出128位字节流。长度为16字节 - let encodedKey = promiseSymKey.getEncoded(); - console.info('key hex:' + encodedKey.data); -} - -@Entry -@Component -struct Index { - @State message: string = 'SM4 Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm4_sync')) - .width('70%') - .onClick(() => { - try { - testSyncGenerateSm4Key(); - this.message = 'SM4 Sync Success'; - } catch { - this.message = 'SM4 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function testSyncGenerateSm4Key() { + // 创建SymKeyGenerator实例 + let symKeyGenerator = cryptoFramework.createSymKeyGenerator('SM4_128'); + // 使用密钥生成器随机生成对称密钥 + let promiseSymKey = symKeyGenerator.generateSymKeySync(); + // 获取对称密钥的二进制数据,输出128位字节流。长度为16字节 + let encodedKey = promiseSymKey.getEncoded(); + console.info('key hex:' + encodedKey.data); +} + +@Entry +@Component +struct Index { + @State message: string = 'SM4 Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm4_sync')) + .width('70%') + .onClick(() => { + try { + testSyncGenerateSm4Key(); + this.message = 'SM4 Sync Success'; + } catch { + this.message = 'SM4 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKeyArkTS.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKeyArkTS.test.ets old mode 100755 new mode 100644 index 47d60062b36c631508c9f3c38a1652049e550914..22bd00d9acacf678dcc6fb6530b5ba519b53af09 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKeyArkTS.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/ets/test/RandomlyGenerateSymmetricKeyArkTS.test.ets @@ -1,116 +1,116 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function randomlyGenerateSymmetricKeyArkTSTest() { - describe('randomlyGenerateSymmetricKeyArkTSTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,随机生成对称密钥(AES Promise方式) - */ - it('testRandomlyGenerateSymmetricKeyArkTS001', 0, async () => { - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AES Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES Promise Success')); - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,随机生成对称密钥(AES 同步方式) - */ - it('testRandomlyGenerateSymmetricKeyArkTS002', 0, async () => { - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AES Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES Sync Success')); - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,随机生成对称密钥(SM4 Promise方式) - */ - it('testRandomlyGenerateSymmetricKeyArkTS003', 0, async () => { - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM4 Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4 Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4 Promise Success')); - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,随机生成对称密钥(SM4 同步方式) - */ - it('testRandomlyGenerateSymmetricKeyArkTS004', 0, async () => { - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM4 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM4 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM4 Sync Success')); - console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function randomlyGenerateSymmetricKeyArkTSTest() { + describe('randomlyGenerateSymmetricKeyArkTSTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,随机生成对称密钥(AES Promise方式) + */ + it('testRandomlyGenerateSymmetricKeyArkTS001', 0, async () => { + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AES Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES Promise Success')); + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,随机生成对称密钥(AES 同步方式) + */ + it('testRandomlyGenerateSymmetricKeyArkTS002', 0, async () => { + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AES Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES Sync Success')); + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,随机生成对称密钥(SM4 Promise方式) + */ + it('testRandomlyGenerateSymmetricKeyArkTS003', 0, async () => { + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM4 Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4 Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4 Promise Success')); + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,随机生成对称密钥(SM4 同步方式) + */ + it('testRandomlyGenerateSymmetricKeyArkTS004', 0, async () => { + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM4 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM4 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM4 Sync Success')); + console.info('uitest: testRandomlyGenerateSymmetricKeyArkTS004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/ohosTest.md old mode 100755 new mode 100644 index d446aed4da6061c5e5c08e4853e322b8095f2695..8f40868b3becab30d1d6dfcb3296e7d1f0ef124b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/ohosTest.md @@ -1,11 +1,11 @@ -# 随机生成对称密钥(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,随机生成对称密钥(AES Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,随机生成对称密钥(AES 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,随机生成对称密钥(SM4 Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 随机生成对称密钥(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,随机生成对称密钥(AES Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,随机生成对称密钥(AES 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,随机生成对称密钥(SM4 Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,随机生成对称密钥(SM4 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/screenshots/RandomlyGenerateSymmetricKeyArkTS1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/screenshots/RandomlyGenerateSymmetricKeyArkTS1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/screenshots/RandomlyGenerateSymmetricKeyArkTS2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/RandomlyGenerateSymmetricKeyArkTS/screenshots/RandomlyGenerateSymmetricKeyArkTS2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/app.json5 old mode 100755 new mode 100644 index 2faa5c820b6b7f3cd6a7f640aca20365582b37ac..00a1f3c0bb25968e2c2f195f0f5b57ba67520863 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/app.json5 @@ -1,25 +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.specifiedparametersgenerateasymmetrickeypair", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.specifiedparametersgenerateasymmetrickeypair", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 9cce03d52d3567f2d44c636195dc147187455390..564c4034207f86158ae7acd39af0387df476aa9c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SpecifiedParametersGenerateAsymmetricKeyPair" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SpecifiedParametersGenerateAsymmetricKeyPair" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/README.md old mode 100755 new mode 100644 index d82fe2cdbe7177b7df1dad16a1b1a66af7c6375d..d83f64eec01a10c33afd7aad069698d4e400efd8 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/README.md @@ -1,78 +1,78 @@ -# 指定密钥参数生成非对称密钥对 - -### 介绍 - -以RSA、ECC、SM2为例,根据指定的密钥参数,生成非对称密钥对(KeyPair),并获取密钥参数属性。该对象可用于后续的加解密等操作。获取的密钥参数属性可用于存储或运输。 - -本示例主要展示了指定密钥参数生成非对称密钥对,指定密钥参数生成RSA公钥、指定密钥参数生成ECC密钥对、根据椭圆曲线名生成SM2密钥对场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [指定密钥参数生成非对称密钥对](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-asym-key-pair-from-key-spec.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例SpecifiedParametersGenerateAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 指定密钥参数生成非对称密钥对示例代码 - │ │ ├── ecc - │ │ | ├── Promise.ets - │ │ | ├── Sync.ets - │ │ ├── rsa - │ │ | ├── Callback.ets - │ │ | ├── Sync.ets - │ │ ├── sm2 - │ │ | ├── Promise.ets - │ │ | ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── SpecifiedParametersGenerateAsymmetricKeyPair.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 指定密钥参数生成非对称密钥对 + +### 介绍 + +以RSA、ECC、SM2为例,根据指定的密钥参数,生成非对称密钥对(KeyPair),并获取密钥参数属性。该对象可用于后续的加解密等操作。获取的密钥参数属性可用于存储或运输。 + +本示例主要展示了指定密钥参数生成非对称密钥对,指定密钥参数生成RSA公钥、指定密钥参数生成ECC密钥对、根据椭圆曲线名生成SM2密钥对场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [指定密钥参数生成非对称密钥对](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-asym-key-pair-from-key-spec.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SpecifiedParametersGenerateAsymmetricKeyPair.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 指定密钥参数生成非对称密钥对示例代码 + │ │ ├── ecc + │ │ | ├── Promise.ets + │ │ | ├── Sync.ets + │ │ ├── rsa + │ │ | ├── Callback.ets + │ │ | ├── Sync.ets + │ │ ├── sm2 + │ │ | ├── Promise.ets + │ │ | ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SpecifiedParametersGenerateAsymmetricKeyPair.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Promise.ets old mode 100755 new mode 100644 index f9ee2ddfe0771419bb4fb5d84bc44f0dad5303e1..528eddb8b26f091fb9397fdd317517318a5dc920 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Promise.ets @@ -1,142 +1,142 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -// 打印bigint信息 -function showBigIntInfo(bnName: string, bnValue: bigint | string | number) { - if (typeof bnValue === 'string') { - console.error('type is string'); - return; - } - if (typeof bnValue === 'number') { - console.error('type is number'); - return; - } - console.info(bnName + ':'); - console.info('. Decimal: ' + bnValue.toString()); - console.info('. Hexadecimal: ' + bnValue.toString(16)); - console.info('. Length (bits): ' + bnValue.toString(2).length); -} - -// 根据关键规范构造EccCommonSpec结构体。EccCommonSpec结构体定义了ECC私钥和公钥的公共参数 -function genEccCommonSpec(): cryptoFramework.ECCCommonParamsSpec { - let fieldFp: cryptoFramework.ECFieldFp = { - fieldType: 'Fp', - p: BigInt('0xffffffffffffffffffffffffffffffff000000000000000000000001') - } - let G: cryptoFramework.Point = { - x: BigInt('0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21'), - y: BigInt('0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34') - } - let eccCommonSpec: cryptoFramework.ECCCommonParamsSpec = { - algName: 'ECC', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, - field: fieldFp, - a: BigInt('0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe'), - b: BigInt('0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4'), - g: G, - n: BigInt('0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d'), - h: 1 - } - return eccCommonSpec; -} - -// 打印ECC密钥规格 -function showEccSpecDetailInfo(key: cryptoFramework.PubKey | cryptoFramework.PriKey, keyType: string) { - console.info('show detail of ' + keyType + ':'); - try { - let p = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FP_P_BN); - showBigIntInfo('--- p', p); // length is 224, hex : ffffffffffffffffffffffffffffffff000000000000000000000001 - let a = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_A_BN); - showBigIntInfo('--- a', a); // length is 224, hex : fffffffffffffffffffffffffffffffefffffffffffffffffffffffe - let b = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_B_BN); - showBigIntInfo('--- b', b); // length is 224, hex : b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4 - let gX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_X_BN); - showBigIntInfo('--- gX', gX); // length is 224, hex : b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21 - let gY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_Y_BN); - showBigIntInfo('--- gY', gY); // length is 224, hex : bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34 - let n = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_N_BN); - showBigIntInfo('--- n', n); // length is 224, hex : ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d - let h = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_H_NUM); - console.warn('--- h: ' + h); // key h: 1 - let fieldType = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_TYPE_STR); - console.warn('--- field type: ' + fieldType); // key field type: Fp - let fieldSize = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_SIZE_NUM); - console.warn('--- field size: ' + fieldSize); // key field size: 224 - let curveName = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); - console.warn('--- curve name: ' + curveName); // key curve name: NID_secp224r1 - if (keyType == 'priKey') { - let sk = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_SK_BN); - showBigIntInfo('--- sk', sk); - } else if (keyType == 'pubKey') { - let pkX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_X_BN); - showBigIntInfo('--- pkX', pkX); - let pkY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_Y_BN); - showBigIntInfo('--- pkY', pkY); - } - } catch (error) { - console.error('getAsyKeySpec error'); - let e: BusinessError = error as BusinessError; - console.error(`getAsyKeySpec failed, ${e.code}, ${e.message}`); - } -} - -// 根据EccCommonSpec实例生成ECC密钥对,获取密钥规格 -function testEccUseCommKeySpecGet() { - try { - let commKeySpec = genEccCommonSpec(); // 使用参数属性,构造ECC公私钥公共密钥参数对象 - let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(commKeySpec); // 使用密钥参数对象创建生成器 - let keyPairPromise = generatorBySpec.generateKeyPair(); // Generate an ECC key pair. - keyPairPromise.then(keyPair => { // 使用生成器创建ECC密钥对 - showEccSpecDetailInfo(keyPair.priKey, 'priKey'); // 对私钥获取相关密钥参数属性 - showEccSpecDetailInfo(keyPair.pubKey, 'pubKey'); // 对公钥获取相关密钥参数属性 - }).catch((error: BusinessError) => { - // 逻辑错误等异步异常在此捕获 - console.error('generateComm error'); - console.error('error code: ' + error.code + ', message is: ' + error.message); - }) - } catch (error) { - // 参数错误等同步异常在此捕获 - console.error('testEccUseCommSpec error'); - let e: BusinessError = error as BusinessError; - console.error(`ecc comm spec failed, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'ECC Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_ecc_promise')) - .width('70%') - .onClick(() => { - try { - testEccUseCommKeySpecGet(); - this.message = 'ECC Promise Success'; - } catch { - this.message = 'ECC Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +// 打印bigint信息 +function showBigIntInfo(bnName: string, bnValue: bigint | string | number) { + if (typeof bnValue === 'string') { + console.error('type is string'); + return; + } + if (typeof bnValue === 'number') { + console.error('type is number'); + return; + } + console.info(bnName + ':'); + console.info('. Decimal: ' + bnValue.toString()); + console.info('. Hexadecimal: ' + bnValue.toString(16)); + console.info('. Length (bits): ' + bnValue.toString(2).length); +} + +// 根据关键规范构造EccCommonSpec结构体。EccCommonSpec结构体定义了ECC私钥和公钥的公共参数 +function genEccCommonSpec(): cryptoFramework.ECCCommonParamsSpec { + let fieldFp: cryptoFramework.ECFieldFp = { + fieldType: 'Fp', + p: BigInt('0xffffffffffffffffffffffffffffffff000000000000000000000001') + } + let G: cryptoFramework.Point = { + x: BigInt('0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21'), + y: BigInt('0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34') + } + let eccCommonSpec: cryptoFramework.ECCCommonParamsSpec = { + algName: 'ECC', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + field: fieldFp, + a: BigInt('0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe'), + b: BigInt('0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4'), + g: G, + n: BigInt('0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d'), + h: 1 + } + return eccCommonSpec; +} + +// 打印ECC密钥规格 +function showEccSpecDetailInfo(key: cryptoFramework.PubKey | cryptoFramework.PriKey, keyType: string) { + console.info('show detail of ' + keyType + ':'); + try { + let p = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FP_P_BN); + showBigIntInfo('--- p', p); // length is 224, hex : ffffffffffffffffffffffffffffffff000000000000000000000001 + let a = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_A_BN); + showBigIntInfo('--- a', a); // length is 224, hex : fffffffffffffffffffffffffffffffefffffffffffffffffffffffe + let b = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_B_BN); + showBigIntInfo('--- b', b); // length is 224, hex : b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4 + let gX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_X_BN); + showBigIntInfo('--- gX', gX); // length is 224, hex : b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21 + let gY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_Y_BN); + showBigIntInfo('--- gY', gY); // length is 224, hex : bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34 + let n = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_N_BN); + showBigIntInfo('--- n', n); // length is 224, hex : ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d + let h = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_H_NUM); + console.warn('--- h: ' + h); // key h: 1 + let fieldType = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_TYPE_STR); + console.warn('--- field type: ' + fieldType); // key field type: Fp + let fieldSize = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_SIZE_NUM); + console.warn('--- field size: ' + fieldSize); // key field size: 224 + let curveName = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); + console.warn('--- curve name: ' + curveName); // key curve name: NID_secp224r1 + if (keyType == 'priKey') { + let sk = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_SK_BN); + showBigIntInfo('--- sk', sk); + } else if (keyType == 'pubKey') { + let pkX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_X_BN); + showBigIntInfo('--- pkX', pkX); + let pkY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_Y_BN); + showBigIntInfo('--- pkY', pkY); + } + } catch (error) { + console.error('getAsyKeySpec error'); + let e: BusinessError = error as BusinessError; + console.error(`getAsyKeySpec failed, ${e.code}, ${e.message}`); + } +} + +// 根据EccCommonSpec实例生成ECC密钥对,获取密钥规格 +function testEccUseCommKeySpecGet() { + try { + let commKeySpec = genEccCommonSpec(); // 使用参数属性,构造ECC公私钥公共密钥参数对象 + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(commKeySpec); // 使用密钥参数对象创建生成器 + let keyPairPromise = generatorBySpec.generateKeyPair(); // Generate an ECC key pair. + keyPairPromise.then(keyPair => { // 使用生成器创建ECC密钥对 + showEccSpecDetailInfo(keyPair.priKey, 'priKey'); // 对私钥获取相关密钥参数属性 + showEccSpecDetailInfo(keyPair.pubKey, 'pubKey'); // 对公钥获取相关密钥参数属性 + }).catch((error: BusinessError) => { + // 逻辑错误等异步异常在此捕获 + console.error('generateComm error'); + console.error('error code: ' + error.code + ', message is: ' + error.message); + }) + } catch (error) { + // 参数错误等同步异常在此捕获 + console.error('testEccUseCommSpec error'); + let e: BusinessError = error as BusinessError; + console.error(`ecc comm spec failed, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'ECC Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecc_promise')) + .width('70%') + .onClick(() => { + try { + testEccUseCommKeySpecGet(); + this.message = 'ECC Promise Success'; + } catch { + this.message = 'ECC Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Sync.ets old mode 100755 new mode 100644 index 8e3d50600907edafea3dbbb90547bb2dc5d72f0f..553e579722ee30bee63dd24148acdc52c4782dfc --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/ecc/Sync.ets @@ -1,134 +1,134 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function showBigIntInfo(bnName: string, bnValue: bigint | string | number) { - if (typeof bnValue === 'string') { - console.error('type is string'); - return; - } - if (typeof bnValue === 'number') { - console.error('type is number'); - return; - } - console.info(bnName + ':'); - console.info('. Decimal: ' + bnValue.toString()); - console.info('. Hexadecimal: ' + bnValue.toString(16)); - console.info('. Length (bits): ' + bnValue.toString(2).length); -} - -// 根据关键规范构造EccCommonSpec结构体。EccCommonSpec结构体定义了ECC私钥和公钥的公共参数 -function genEccCommonSpec(): cryptoFramework.ECCCommonParamsSpec { - let fieldFp: cryptoFramework.ECFieldFp = { - fieldType: 'Fp', - p: BigInt('0xffffffffffffffffffffffffffffffff000000000000000000000001') - } - let G: cryptoFramework.Point = { - x: BigInt('0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21'), - y: BigInt('0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34') - } - let eccCommonSpec: cryptoFramework.ECCCommonParamsSpec = { - algName: 'ECC', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, - field: fieldFp, - a: BigInt('0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe'), - b: BigInt('0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4'), - g: G, - n: BigInt('0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d'), - h: 1 - } - return eccCommonSpec; -} - -// 打印ECC密钥规格 -function showEccSpecDetailInfo(key: cryptoFramework.PubKey | cryptoFramework.PriKey, keyType: string) { - console.info('show detail of ' + keyType + ':'); - try { - let p = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FP_P_BN); - showBigIntInfo('--- p', p); // length is 224, hex : ffffffffffffffffffffffffffffffff000000000000000000000001 - let a = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_A_BN); - showBigIntInfo('--- a', a); // length is 224, hex : fffffffffffffffffffffffffffffffefffffffffffffffffffffffe - let b = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_B_BN); - showBigIntInfo('--- b', b); // length is 224, hex : b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4 - let gX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_X_BN); - showBigIntInfo('--- gX', gX); // length is 224, hex : b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21 - let gY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_Y_BN); - showBigIntInfo('--- gY', gY); // length is 224, hex : bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34 - let n = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_N_BN); - showBigIntInfo('--- n', n); // length is 224, hex : ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d - let h = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_H_NUM); - console.warn('--- h: ' + h); // key h: 1 - let fieldType = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_TYPE_STR); - console.warn('--- field type: ' + fieldType); // key field type: Fp - let fieldSize = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_SIZE_NUM); - console.warn('--- field size: ' + fieldSize); // key field size: 224 - let curveName = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); - console.warn('--- curve name: ' + curveName); // key curve name: NID_secp224r1 - if (keyType == 'priKey') { - let sk = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_SK_BN); - showBigIntInfo('--- sk', sk); - } else if (keyType == 'pubKey') { - let pkX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_X_BN); - showBigIntInfo('--- pkX', pkX); - let pkY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_Y_BN); - showBigIntInfo('--- pkY', pkY); - } - } catch (e) { - console.error(`getAsyKeySpec failed, ${e.code}, ${e.message}`); - } -} - -// 根据EccCommonSpec实例生成ECC密钥对,获取密钥规格 -function testEccUseCommKeySpecGetSync() { - try { - let commKeySpec = genEccCommonSpec(); // 使用参数属性,构造ECC公私钥公共密钥参数对象 - let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(commKeySpec); // 使用密钥参数对象创建生成器 - let keyPair = generatorBySpec.generateKeyPairSync(); // Generate an ECC key pair. - if (keyPair != null) { - showEccSpecDetailInfo(keyPair.priKey, 'priKey'); // 对私钥获取相关密钥参数属性 - showEccSpecDetailInfo(keyPair.pubKey, 'pubKey'); // 对公钥获取相关密钥参数属性 - } else { - console.error('get key pair result fail!'); - } - } catch (e) { - // 逻辑错误等异常在此捕获 - console.error(`get key pair result fail, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'ECC Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_ecc_sync')) - .width('70%') - .onClick(() => { - try { - testEccUseCommKeySpecGetSync(); - this.message = 'ECC Sync Success'; - } catch { - this.message = 'ECC Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function showBigIntInfo(bnName: string, bnValue: bigint | string | number) { + if (typeof bnValue === 'string') { + console.error('type is string'); + return; + } + if (typeof bnValue === 'number') { + console.error('type is number'); + return; + } + console.info(bnName + ':'); + console.info('. Decimal: ' + bnValue.toString()); + console.info('. Hexadecimal: ' + bnValue.toString(16)); + console.info('. Length (bits): ' + bnValue.toString(2).length); +} + +// 根据关键规范构造EccCommonSpec结构体。EccCommonSpec结构体定义了ECC私钥和公钥的公共参数 +function genEccCommonSpec(): cryptoFramework.ECCCommonParamsSpec { + let fieldFp: cryptoFramework.ECFieldFp = { + fieldType: 'Fp', + p: BigInt('0xffffffffffffffffffffffffffffffff000000000000000000000001') + } + let G: cryptoFramework.Point = { + x: BigInt('0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21'), + y: BigInt('0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34') + } + let eccCommonSpec: cryptoFramework.ECCCommonParamsSpec = { + algName: 'ECC', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + field: fieldFp, + a: BigInt('0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe'), + b: BigInt('0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4'), + g: G, + n: BigInt('0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d'), + h: 1 + } + return eccCommonSpec; +} + +// 打印ECC密钥规格 +function showEccSpecDetailInfo(key: cryptoFramework.PubKey | cryptoFramework.PriKey, keyType: string) { + console.info('show detail of ' + keyType + ':'); + try { + let p = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FP_P_BN); + showBigIntInfo('--- p', p); // length is 224, hex : ffffffffffffffffffffffffffffffff000000000000000000000001 + let a = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_A_BN); + showBigIntInfo('--- a', a); // length is 224, hex : fffffffffffffffffffffffffffffffefffffffffffffffffffffffe + let b = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_B_BN); + showBigIntInfo('--- b', b); // length is 224, hex : b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4 + let gX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_X_BN); + showBigIntInfo('--- gX', gX); // length is 224, hex : b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21 + let gY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_G_Y_BN); + showBigIntInfo('--- gY', gY); // length is 224, hex : bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34 + let n = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_N_BN); + showBigIntInfo('--- n', n); // length is 224, hex : ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d + let h = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_H_NUM); + console.warn('--- h: ' + h); // key h: 1 + let fieldType = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_TYPE_STR); + console.warn('--- field type: ' + fieldType); // key field type: Fp + let fieldSize = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_FIELD_SIZE_NUM); + console.warn('--- field size: ' + fieldSize); // key field size: 224 + let curveName = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); + console.warn('--- curve name: ' + curveName); // key curve name: NID_secp224r1 + if (keyType == 'priKey') { + let sk = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_SK_BN); + showBigIntInfo('--- sk', sk); + } else if (keyType == 'pubKey') { + let pkX = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_X_BN); + showBigIntInfo('--- pkX', pkX); + let pkY = key.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_PK_Y_BN); + showBigIntInfo('--- pkY', pkY); + } + } catch (e) { + console.error(`getAsyKeySpec failed, ${e.code}, ${e.message}`); + } +} + +// 根据EccCommonSpec实例生成ECC密钥对,获取密钥规格 +function testEccUseCommKeySpecGetSync() { + try { + let commKeySpec = genEccCommonSpec(); // 使用参数属性,构造ECC公私钥公共密钥参数对象 + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(commKeySpec); // 使用密钥参数对象创建生成器 + let keyPair = generatorBySpec.generateKeyPairSync(); // Generate an ECC key pair. + if (keyPair != null) { + showEccSpecDetailInfo(keyPair.priKey, 'priKey'); // 对私钥获取相关密钥参数属性 + showEccSpecDetailInfo(keyPair.pubKey, 'pubKey'); // 对公钥获取相关密钥参数属性 + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + // 逻辑错误等异常在此捕获 + console.error(`get key pair result fail, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'ECC Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecc_sync')) + .width('70%') + .onClick(() => { + try { + testEccUseCommKeySpecGetSync(); + this.message = 'ECC Sync Success'; + } catch { + this.message = 'ECC Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Callback.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Callback.ets old mode 100755 new mode 100644 index bae460a5d828da7299530b4c1065b95f77bd282f..43c91c59983d75277917f617a926d52c22511f06 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Callback.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Callback.ets @@ -1,107 +1,107 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -// RSA公钥密钥参数生成函数 -function genRsaPubKeySpec(nIn: bigint, eIn: bigint): cryptoFramework.RSAPubKeySpec { - let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { - n: nIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC - }; - let rsaPubKeySpec: cryptoFramework.RSAPubKeySpec = { - params: rsaCommSpec, - pk: eIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC - }; - return rsaPubKeySpec; -} - -// 根据密钥参数构造RSA公钥规范对象 -function genRsa2048PubKeySpec() { - let nIn = - BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc4' + - '328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee' + - '34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7' + - 'afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c' + - '0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); - let eIn = BigInt('0x010001'); - return genRsaPubKeySpec(nIn, eIn); -} - -// 将RSA公钥规格与预期值进行比较 -function compareRsaPubKeyBySpec(rsaKeySpec: cryptoFramework.RSAPubKeySpec, n: bigint | string | number, - e: bigint | string | number) { - if (typeof n === 'string' || typeof e === 'string') { - console.error('type is string'); - return false; - } - if (typeof n === 'number' || typeof e === 'number') { - console.error('type is number'); - return false; - } - if (rsaKeySpec.params.n != n) { - return false; - } - if (rsaKeySpec.pk != e) { - return false; - } - return true; -} - -// 根据RSA公钥规格生成RSA公钥,获取密钥规格,并与预期值进行比较 -function rsaUsePubKeySpecGetCallback() { - let rsaPubKeySpec = genRsa2048PubKeySpec(); - let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaPubKeySpec); - rsaGeneratorSpec.generatePubKey((error, key) => { - if (error) { - console.error('generate pubKey error' + 'error code: ' + error.code + 'error message' + error.message); - } - let pubKey = key; - let nBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_N_BN); - let eBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_PK_BN); - if (compareRsaPubKeyBySpec(rsaPubKeySpec, nBN, eBN) != true) { - console.error('error pub key big number'); - } else { - console.info('n, e in the pubKey are same as the spec.'); - } - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Callback'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_callback')) - .width('70%') - .onClick(() => { - try { - rsaUsePubKeySpecGetCallback(); - this.message = 'RSA Callback Success'; - } catch { - this.message = 'RSA Callback Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +// RSA公钥密钥参数生成函数 +function genRsaPubKeySpec(nIn: bigint, eIn: bigint): cryptoFramework.RSAPubKeySpec { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaPubKeySpec: cryptoFramework.RSAPubKeySpec = { + params: rsaCommSpec, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC + }; + return rsaPubKeySpec; +} + +// 根据密钥参数构造RSA公钥规范对象 +function genRsa2048PubKeySpec() { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc4' + + '328daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee' + + '34e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7' + + 'afa7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c' + + '0589c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + return genRsaPubKeySpec(nIn, eIn); +} + +// 将RSA公钥规格与预期值进行比较 +function compareRsaPubKeyBySpec(rsaKeySpec: cryptoFramework.RSAPubKeySpec, n: bigint | string | number, + e: bigint | string | number) { + if (typeof n === 'string' || typeof e === 'string') { + console.error('type is string'); + return false; + } + if (typeof n === 'number' || typeof e === 'number') { + console.error('type is number'); + return false; + } + if (rsaKeySpec.params.n != n) { + return false; + } + if (rsaKeySpec.pk != e) { + return false; + } + return true; +} + +// 根据RSA公钥规格生成RSA公钥,获取密钥规格,并与预期值进行比较 +function rsaUsePubKeySpecGetCallback() { + let rsaPubKeySpec = genRsa2048PubKeySpec(); + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaPubKeySpec); + rsaGeneratorSpec.generatePubKey((error, key) => { + if (error) { + console.error('generate pubKey error' + 'error code: ' + error.code + 'error message' + error.message); + } + let pubKey = key; + let nBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_N_BN); + let eBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_PK_BN); + if (compareRsaPubKeyBySpec(rsaPubKeySpec, nBN, eBN) != true) { + console.error('error pub key big number'); + } else { + console.info('n, e in the pubKey are same as the spec.'); + } + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Callback'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_callback')) + .width('70%') + .onClick(() => { + try { + rsaUsePubKeySpecGetCallback(); + this.message = 'RSA Callback Success'; + } catch { + this.message = 'RSA Callback Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Sync.ets old mode 100755 new mode 100644 index 6af396c320a996dfcafb348f7f6db7a55702f4a1..2bca56d449a1ec8133dd86f79fff4b569e44fa48 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/rsa/Sync.ets @@ -1,110 +1,110 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -// RSA公钥密钥参数生成函数 -function genRsaPubKeySpec(nIn: bigint, eIn: bigint): cryptoFramework.RSAPubKeySpec { - let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { - n: nIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC - }; - let rsaPubKeySpec: cryptoFramework.RSAPubKeySpec = { - params: rsaCommSpec, - pk: eIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC - }; - return rsaPubKeySpec; -} - -// 根据密钥参数构造RSA公钥规范对象 -function genRsa2048PubKeySpec() { - let nIn = - BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc43' + - '28daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34' + - 'e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa' + - '7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589' + - 'c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); - let eIn = BigInt('0x010001'); - return genRsaPubKeySpec(nIn, eIn); -} - -// 将RSA公钥规格与预期值进行比较 -function compareRsaPubKeyBySpec(rsaKeySpec: cryptoFramework.RSAPubKeySpec, n: bigint | string | number, - e: bigint | string | number) { - if (typeof n === 'string' || typeof e === 'string') { - console.error('type is string'); - return false; - } - if (typeof n === 'number' || typeof e === 'number') { - console.error('type is number'); - return false; - } - if (rsaKeySpec.params.n != n) { - return false; - } - if (rsaKeySpec.pk != e) { - return false; - } - return true; -} - -// 根据RSA公钥规格生成RSA公钥,获取密钥规格,并与预期值进行比较 -function rsaUsePubKeySpecGetSync() { - let rsaPubKeySpec = genRsa2048PubKeySpec(); - let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaPubKeySpec); - try { - let pubKey = rsaGeneratorSpec.generatePubKeySync(); - if (pubKey != null) { - let nBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_N_BN); - let eBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_PK_BN); - if (compareRsaPubKeyBySpec(rsaPubKeySpec, nBN, eBN) != true) { - console.error('error pub key big number'); - } else { - console.info('n, e in the pubKey are same as the spec.'); - } - } else { - console.error('get pub key result fail!'); - } - } catch (e) { - console.error(`get pub key result fail, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_rsa_sync')) - .width('70%') - .onClick(() => { - try { - rsaUsePubKeySpecGetSync(); - this.message = 'RSA Sync Success'; - } catch { - this.message = 'RSA Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +// RSA公钥密钥参数生成函数 +function genRsaPubKeySpec(nIn: bigint, eIn: bigint): cryptoFramework.RSAPubKeySpec { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaPubKeySpec: cryptoFramework.RSAPubKeySpec = { + params: rsaCommSpec, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC + }; + return rsaPubKeySpec; +} + +// 根据密钥参数构造RSA公钥规范对象 +function genRsa2048PubKeySpec() { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc43' + + '28daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34' + + 'e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa' + + '7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589' + + 'c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + return genRsaPubKeySpec(nIn, eIn); +} + +// 将RSA公钥规格与预期值进行比较 +function compareRsaPubKeyBySpec(rsaKeySpec: cryptoFramework.RSAPubKeySpec, n: bigint | string | number, + e: bigint | string | number) { + if (typeof n === 'string' || typeof e === 'string') { + console.error('type is string'); + return false; + } + if (typeof n === 'number' || typeof e === 'number') { + console.error('type is number'); + return false; + } + if (rsaKeySpec.params.n != n) { + return false; + } + if (rsaKeySpec.pk != e) { + return false; + } + return true; +} + +// 根据RSA公钥规格生成RSA公钥,获取密钥规格,并与预期值进行比较 +function rsaUsePubKeySpecGetSync() { + let rsaPubKeySpec = genRsa2048PubKeySpec(); + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaPubKeySpec); + try { + let pubKey = rsaGeneratorSpec.generatePubKeySync(); + if (pubKey != null) { + let nBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_N_BN); + let eBN = pubKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.RSA_PK_BN); + if (compareRsaPubKeyBySpec(rsaPubKeySpec, nBN, eBN) != true) { + console.error('error pub key big number'); + } else { + console.info('n, e in the pubKey are same as the spec.'); + } + } else { + console.error('get pub key result fail!'); + } + } catch (e) { + console.error(`get pub key result fail, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_rsa_sync')) + .width('70%') + .onClick(() => { + try { + rsaUsePubKeySpecGetSync(); + this.message = 'RSA Sync Success'; + } catch { + this.message = 'RSA Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Promise.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Promise.ets old mode 100755 new mode 100644 index 5fe7027d2d9bf5d4c896ea34ef095659b64e417f..9068b04e1e036adea0dc693252f826351791e9ab --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Promise.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Promise.ets @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function genSM2KeyPairSpec() { - let sm2CommonParamsSpec = cryptoFramework.ECCKeyUtil.genECCCommonParamsSpec('NID_sm2'); - let sm2KeyPairSpec: cryptoFramework.ECCKeyPairSpec = { - algName: 'SM2', - specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, - params: sm2CommonParamsSpec, - sk: BigInt('0x6330B599ECD23ABDC74B9A5B7B5E00E553005F72743101C5FAB83AEB579B7074'), - pk: { - x: BigInt('0x67F3B850BDC0BA5D3A29D8A0883C4B17612AB84F87F18E28F77D824A115C02C4'), - y: BigInt('0xD48966CE754BBBEDD6501A1385E1B205C186E926ADED44287145E8897D4B2071') - }, - }; - return sm2KeyPairSpec; -} - -async function sm2Test() { - let sm2KeyPairSpec = genSM2KeyPairSpec(); - let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(sm2KeyPairSpec); - let keyPair = await generatorBySpec.generateKeyPair(); - let sm2CurveName = keyPair.priKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); - console.info('ECC_CURVE_NAME_STR: ' + sm2CurveName); // NID_sm2 -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Promise'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_promise')) - .width('70%') - .onClick(async () => { - try { - await sm2Test(); - this.message = 'SM2 Promise Success'; - } catch { - this.message = 'SM2 Promise Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function genSM2KeyPairSpec() { + let sm2CommonParamsSpec = cryptoFramework.ECCKeyUtil.genECCCommonParamsSpec('NID_sm2'); + let sm2KeyPairSpec: cryptoFramework.ECCKeyPairSpec = { + algName: 'SM2', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + params: sm2CommonParamsSpec, + sk: BigInt('0x6330B599ECD23ABDC74B9A5B7B5E00E553005F72743101C5FAB83AEB579B7074'), + pk: { + x: BigInt('0x67F3B850BDC0BA5D3A29D8A0883C4B17612AB84F87F18E28F77D824A115C02C4'), + y: BigInt('0xD48966CE754BBBEDD6501A1385E1B205C186E926ADED44287145E8897D4B2071') + }, + }; + return sm2KeyPairSpec; +} + +async function sm2Test() { + let sm2KeyPairSpec = genSM2KeyPairSpec(); + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(sm2KeyPairSpec); + let keyPair = await generatorBySpec.generateKeyPair(); + let sm2CurveName = keyPair.priKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); + console.info('ECC_CURVE_NAME_STR: ' + sm2CurveName); // NID_sm2 +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_promise')) + .width('70%') + .onClick(async () => { + try { + await sm2Test(); + this.message = 'SM2 Promise Success'; + } catch { + this.message = 'SM2 Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Sync.ets old mode 100755 new mode 100644 index 98a0d46daef214d44cdfc8ea2f0bb78a89372045..f8e64a12cf9045eff8110c0fa03a4456c0fdc5a2 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/ets/pages/sm2/Sync.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function genSM2KeyPairSpec() { - let sm2CommonParamsSpec = cryptoFramework.ECCKeyUtil.genECCCommonParamsSpec('NID_sm2'); - let sm2KeyPairSpec: cryptoFramework.ECCKeyPairSpec = { - algName: 'SM2', - specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, - params: sm2CommonParamsSpec, - sk: BigInt('0x6330B599ECD23ABDC74B9A5B7B5E00E553005F72743101C5FAB83AEB579B7074'), - pk: { - x: BigInt('0x67F3B850BDC0BA5D3A29D8A0883C4B17612AB84F87F18E28F77D824A115C02C4'), - y: BigInt('0xD48966CE754BBBEDD6501A1385E1B205C186E926ADED44287145E8897D4B2071') - }, - }; - return sm2KeyPairSpec; -} - -function sm2TestSync() { - let sm2KeyPairSpec = genSM2KeyPairSpec(); - let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(sm2KeyPairSpec); - try { - let keyPair = generatorBySpec.generateKeyPairSync(); - if (keyPair != null) { - let sm2CurveName = keyPair.priKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); - console.info('ECC_CURVE_NAME_STR: ' + sm2CurveName); // NID_sm2 - } else { - console.error('get key pair result fail!'); - } - } catch (e) { - console.error(`get key pair result fail, ${e.code}, ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2 Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_sync')) - .width('70%') - .onClick(() => { - try { - sm2TestSync(); - this.message = 'SM2 Sync Success'; - } catch { - this.message = 'SM2 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function genSM2KeyPairSpec() { + let sm2CommonParamsSpec = cryptoFramework.ECCKeyUtil.genECCCommonParamsSpec('NID_sm2'); + let sm2KeyPairSpec: cryptoFramework.ECCKeyPairSpec = { + algName: 'SM2', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + params: sm2CommonParamsSpec, + sk: BigInt('0x6330B599ECD23ABDC74B9A5B7B5E00E553005F72743101C5FAB83AEB579B7074'), + pk: { + x: BigInt('0x67F3B850BDC0BA5D3A29D8A0883C4B17612AB84F87F18E28F77D824A115C02C4'), + y: BigInt('0xD48966CE754BBBEDD6501A1385E1B205C186E926ADED44287145E8897D4B2071') + }, + }; + return sm2KeyPairSpec; +} + +function sm2TestSync() { + let sm2KeyPairSpec = genSM2KeyPairSpec(); + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(sm2KeyPairSpec); + try { + let keyPair = generatorBySpec.generateKeyPairSync(); + if (keyPair != null) { + let sm2CurveName = keyPair.priKey.getAsyKeySpec(cryptoFramework.AsyKeySpecItem.ECC_CURVE_NAME_STR); + console.info('ECC_CURVE_NAME_STR: ' + sm2CurveName); // NID_sm2 + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail, ${e.code}, ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2 Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_sync')) + .width('70%') + .onClick(() => { + try { + sm2TestSync(); + this.message = 'SM2 Sync Success'; + } catch { + this.message = 'SM2 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/SpecifiedParametersGenerateAsymmetricKeyPair.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/SpecifiedParametersGenerateAsymmetricKeyPair.test.ets old mode 100755 new mode 100644 index ff4381d2a56fa3569145c9dcc4f7b9bc0f51d5f9..970c0a23ed9e9885e9afc156ab079a8b602aa22c --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/SpecifiedParametersGenerateAsymmetricKeyPair.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/ets/test/SpecifiedParametersGenerateAsymmetricKeyPair.test.ets @@ -1,151 +1,151 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function specifiedParametersGenerateAsymmetricKeyPairTest() { - describe('specifiedParametersGenerateAsymmetricKeyPairTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,指定密钥参数生成RSA公钥(callback方式) - */ - it('testSpecifiedParametersGenerateAsymmetricKeyPair001', 0, async () => { - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECC Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call ECC Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECC Promise Success')); - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定密钥参数生成RSA公钥(同步方式) - */ - it('testSpecifiedParametersGenerateAsymmetricKeyPair002', 0, async () => { - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECC Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call ECC Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECC Sync Success')); - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定密钥参数生成ECC密钥对(Promise方式) - */ - it('testSpecifiedParametersGenerateAsymmetricKeyPair003', 0, async () => { - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Callback')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Callback')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Callback Success')); - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,指定密钥参数生成ECC密钥对(同步方式) - */ - it('testSpecifiedParametersGenerateAsymmetricKeyPair004', 0, async () => { - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA Sync Success')); - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,安根据椭圆曲线名生成SM2密钥对(Promise方式) - */ - it('testSpecifiedParametersGenerateAsymmetricKeyPair005', 0, async () => { - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Promise')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Promise')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Promise Success')); - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,根据椭圆曲线名生成SM2密钥对(同步方式) - */ - it('testSpecifiedParametersGenerateAsymmetricKeyPair006', 0, async () => { - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Sync Success')); - console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair006 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function specifiedParametersGenerateAsymmetricKeyPairTest() { + describe('specifiedParametersGenerateAsymmetricKeyPairTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,指定密钥参数生成RSA公钥(callback方式) + */ + it('testSpecifiedParametersGenerateAsymmetricKeyPair001', 0, async () => { + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECC Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECC Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECC Promise Success')); + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定密钥参数生成RSA公钥(同步方式) + */ + it('testSpecifiedParametersGenerateAsymmetricKeyPair002', 0, async () => { + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECC Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECC Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECC Sync Success')); + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定密钥参数生成ECC密钥对(Promise方式) + */ + it('testSpecifiedParametersGenerateAsymmetricKeyPair003', 0, async () => { + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Callback')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Callback')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Callback Success')); + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,指定密钥参数生成ECC密钥对(同步方式) + */ + it('testSpecifiedParametersGenerateAsymmetricKeyPair004', 0, async () => { + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA Sync Success')); + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,安根据椭圆曲线名生成SM2密钥对(Promise方式) + */ + it('testSpecifiedParametersGenerateAsymmetricKeyPair005', 0, async () => { + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Promise Success')); + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,根据椭圆曲线名生成SM2密钥对(同步方式) + */ + it('testSpecifiedParametersGenerateAsymmetricKeyPair006', 0, async () => { + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Sync Success')); + console.info('uitest: testSpecifiedParametersGenerateAsymmetricKeyPair006 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/ohosTest.md old mode 100755 new mode 100644 index 8de2bacdabf9ce609c0acf54de4ef3f81ba1d186..67e51c680657b8d36b7d63aac0a55dd39603fbff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/ohosTest.md @@ -1,13 +1,13 @@ -# 指定密钥参数生成非对称密钥对测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,指定密钥参数生成RSA公钥(callback方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定密钥参数生成RSA公钥(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定密钥参数生成ECC密钥对(Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,指定密钥参数生成ECC密钥对(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,安根据椭圆曲线名生成SM2密钥对(Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 指定密钥参数生成非对称密钥对测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,指定密钥参数生成RSA公钥(callback方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定密钥参数生成RSA公钥(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定密钥参数生成ECC密钥对(Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,指定密钥参数生成ECC密钥对(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,安根据椭圆曲线名生成SM2密钥对(Promise方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,根据椭圆曲线名生成SM2密钥对(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/screenshots/SpecifiedParametersGenerateAsymmetricKeyPair1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/screenshots/SpecifiedParametersGenerateAsymmetricKeyPair1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/screenshots/SpecifiedParametersGenerateAsymmetricKeyPair2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyGenerationConversion/SpecifiedParametersGenerateAsymmetricKeyPair/screenshots/SpecifiedParametersGenerateAsymmetricKeyPair2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/app.json5 old mode 100755 new mode 100644 index ad1234818ea2f4a3fde3a6f49b0f800a58fd9acf..09a0c5dcaecceb27446d187a5e75856d67277d12 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/app.json5 @@ -1,25 +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.keynegotiation", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.keynegotiation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 80d7691083ee2621c9940d55947c5da2236ccbbe..3c9c7b57678a813697ff4469d47366e745d4d44f --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "KeyNegotiation" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "KeyNegotiation" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/README.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/README.md old mode 100755 new mode 100644 index fadad79f8b388ba3642e23018c1203b7a8582850..0c122b08fcb315a98864e7734f742e4c0a735f0a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/README.md @@ -1,78 +1,78 @@ -# 密钥协商 - -### 介绍 - -本示例主要展示了使用ECDH进行密钥协商(await方式和同步方式)、使用X25519进行密钥协商(await方式和同步方式)、使用DH进行密钥协商(await方式和同步方式)场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用ECDH进行密钥协商](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-agreement-using-ecdh.md) -- [使用X25519进行密钥协商](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-agreement-using-x25519.md) -- [使用DH进行密钥协商](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-agreement-using-dh.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例KeyNegotiation.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 密钥协商示例代码 - │ │ ├── DH - │ │ | ├── DHAsync.ets - │ │ | ├── DHSync.ets - │ │ ├── ECDH - │ │ | ├── EDCHAsync.ets - │ │ | ├── EDCHSync.ets - │ │ ├── X25519 - │ │ | ├── X25519Async.ets - │ │ | ├── X25519Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── KeyNegotiation.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 密钥协商 + +### 介绍 + +本示例主要展示了使用ECDH进行密钥协商(await方式和同步方式)、使用X25519进行密钥协商(await方式和同步方式)、使用DH进行密钥协商(await方式和同步方式)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用ECDH进行密钥协商](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-agreement-using-ecdh.md) +- [使用X25519进行密钥协商](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-agreement-using-x25519.md) +- [使用DH进行密钥协商](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-agreement-using-dh.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例KeyNegotiation.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 密钥协商示例代码 + │ │ ├── DH + │ │ | ├── DHAsync.ets + │ │ | ├── DHSync.ets + │ │ ├── ECDH + │ │ | ├── EDCHAsync.ets + │ │ | ├── EDCHSync.ets + │ │ ├── X25519 + │ │ | ├── X25519Async.ets + │ │ | ├── X25519Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── KeyNegotiation.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHAsync.ets old mode 100755 new mode 100644 index ed556b1aaa51ac91215ab37d02970e5db63a26b9..9958a0529b3166af5a1ee780277145fc1ba5fac7 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHAsync.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function dhAwait() { - let keyGen = cryptoFramework.createAsyKeyGenerator('DH_modp1536'); - // 随机生成公私钥对A - let keyPairA = await keyGen.generateKeyPair(); - // 随机生成规格一致的公私钥对B - let keyPairB = await keyGen.generateKeyPair(); - let keyAgreement = cryptoFramework.createKeyAgreement('DH_modp1536'); - // 使用A的公钥和B的私钥进行密钥协商 - let secret1 = await keyAgreement.generateSecret(keyPairB.priKey, keyPairA.pubKey); - // 使用A的私钥和B的公钥进行密钥协商 - let secret2 = await keyAgreement.generateSecret(keyPairA.priKey, keyPairB.pubKey); - // 两种协商的结果应当一致 - if (secret1.data.toString() === secret2.data.toString()) { - console.info('DH success'); - console.info('DH output is ' + secret1.data); - } else { - console.error('DH result is not equal'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'DH Async'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_dh_async')) - .width('70%') - .onClick(async () => { - try { - await dhAwait(); - this.message = 'DH Async Success'; - } catch { - this.message = 'DH Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function dhAwait() { + let keyGen = cryptoFramework.createAsyKeyGenerator('DH_modp1536'); + // 随机生成公私钥对A + let keyPairA = await keyGen.generateKeyPair(); + // 随机生成规格一致的公私钥对B + let keyPairB = await keyGen.generateKeyPair(); + let keyAgreement = cryptoFramework.createKeyAgreement('DH_modp1536'); + // 使用A的公钥和B的私钥进行密钥协商 + let secret1 = await keyAgreement.generateSecret(keyPairB.priKey, keyPairA.pubKey); + // 使用A的私钥和B的公钥进行密钥协商 + let secret2 = await keyAgreement.generateSecret(keyPairA.priKey, keyPairB.pubKey); + // 两种协商的结果应当一致 + if (secret1.data.toString() === secret2.data.toString()) { + console.info('DH success'); + console.info('DH output is ' + secret1.data); + } else { + console.error('DH result is not equal'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'DH Async'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_dh_async')) + .width('70%') + .onClick(async () => { + try { + await dhAwait(); + this.message = 'DH Async Success'; + } catch { + this.message = 'DH Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHSync.ets old mode 100755 new mode 100644 index adec491b67f0a96428baacfd355997d5da6558d6..61a31884f7678f62df94a6556d895ad65850caba --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/DH/DHSync.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function dhAwait() { - let keyGen = cryptoFramework.createAsyKeyGenerator('DH_modp1536'); - // 随机生成公私钥对A - let keyPairA = keyGen.generateKeyPairSync(); - // 随机生成规格一致的公私钥对B - let keyPairB = keyGen.generateKeyPairSync(); - let keyAgreement = cryptoFramework.createKeyAgreement('DH_modp1536'); - // 使用A的公钥和B的私钥进行密钥协商 - let secret1 = keyAgreement.generateSecretSync(keyPairB.priKey, keyPairA.pubKey); - // 使用A的私钥和B的公钥进行密钥协商 - let secret2 = keyAgreement.generateSecretSync(keyPairA.priKey, keyPairB.pubKey); - // 两种协商的结果应当一致 - if (secret1.data.toString() === secret2.data.toString()) { - console.info('DH success'); - console.info('DH output is ' + secret1.data); - } else { - console.error('DH result is not equal'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'DH Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_dh_sync')) - .width('70%') - .onClick(() => { - try { - dhAwait(); - this.message = 'DH Sync Success'; - } catch { - this.message = 'DH Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function dhAwait() { + let keyGen = cryptoFramework.createAsyKeyGenerator('DH_modp1536'); + // 随机生成公私钥对A + let keyPairA = keyGen.generateKeyPairSync(); + // 随机生成规格一致的公私钥对B + let keyPairB = keyGen.generateKeyPairSync(); + let keyAgreement = cryptoFramework.createKeyAgreement('DH_modp1536'); + // 使用A的公钥和B的私钥进行密钥协商 + let secret1 = keyAgreement.generateSecretSync(keyPairB.priKey, keyPairA.pubKey); + // 使用A的私钥和B的公钥进行密钥协商 + let secret2 = keyAgreement.generateSecretSync(keyPairA.priKey, keyPairB.pubKey); + // 两种协商的结果应当一致 + if (secret1.data.toString() === secret2.data.toString()) { + console.info('DH success'); + console.info('DH output is ' + secret1.data); + } else { + console.error('DH result is not equal'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'DH Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_dh_sync')) + .width('70%') + .onClick(() => { + try { + dhAwait(); + this.message = 'DH Sync Success'; + } catch { + this.message = 'DH Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHAsync.ets old mode 100755 new mode 100644 index 8667db5eb4e28b90b6749b88f6e62c061a9a4b48..0991e638ef237cb84c5fbc1f7dc0cf0cd0d9c89e --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHAsync.ets @@ -1,69 +1,69 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function ecdhAwait() { - // 假设此公私钥对数据为外部传入 - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, - 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, - 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, - 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, - 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); - let eccGen = cryptoFramework.createAsyKeyGenerator('ECC256'); - // 外部传入的公私钥对A - let keyPairA = await eccGen.convertKey({ data: pubKeyArray }, { data: priKeyArray }); - // 内部生成的公私钥对B - let keyPairB = await eccGen.generateKeyPair(); - let eccKeyAgreement = cryptoFramework.createKeyAgreement('ECC256'); - // 使用A的公钥和B的私钥进行密钥协商 - let secret1 = await eccKeyAgreement.generateSecret(keyPairB.priKey, keyPairA.pubKey); - // 使用A的私钥和B的公钥进行密钥协商 - let secret2 = await eccKeyAgreement.generateSecret(keyPairA.priKey, keyPairB.pubKey); - // 两种协商的结果应当一致 - if (secret1.data.toString() === secret2.data.toString()) { - console.info('ecdh success'); - console.info('ecdh output is ' + secret1.data); - } else { - console.error('ecdh result is not equal'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'EDCH Async'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_edch_async')) - .width('70%') - .onClick(async () => { - try { - await ecdhAwait(); - this.message = 'EDCH Async Success'; - } catch { - this.message = 'EDCH Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function ecdhAwait() { + // 假设此公私钥对数据为外部传入 + let pubKeyArray = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, + 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, + 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, + 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); + let priKeyArray = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, + 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); + let eccGen = cryptoFramework.createAsyKeyGenerator('ECC256'); + // 外部传入的公私钥对A + let keyPairA = await eccGen.convertKey({ data: pubKeyArray }, { data: priKeyArray }); + // 内部生成的公私钥对B + let keyPairB = await eccGen.generateKeyPair(); + let eccKeyAgreement = cryptoFramework.createKeyAgreement('ECC256'); + // 使用A的公钥和B的私钥进行密钥协商 + let secret1 = await eccKeyAgreement.generateSecret(keyPairB.priKey, keyPairA.pubKey); + // 使用A的私钥和B的公钥进行密钥协商 + let secret2 = await eccKeyAgreement.generateSecret(keyPairA.priKey, keyPairB.pubKey); + // 两种协商的结果应当一致 + if (secret1.data.toString() === secret2.data.toString()) { + console.info('ecdh success'); + console.info('ecdh output is ' + secret1.data); + } else { + console.error('ecdh result is not equal'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'EDCH Async'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_edch_async')) + .width('70%') + .onClick(async () => { + try { + await ecdhAwait(); + this.message = 'EDCH Async Success'; + } catch { + this.message = 'EDCH Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHSync.ets old mode 100755 new mode 100644 index ee3f00e7e17b324dabb5cacabe14847859924694..d933b76f61ae2e127547052018ad96b8d34a91ec --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/ECDH/EDCHSync.ets @@ -1,69 +1,69 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function ecdhAwait() { - // 假设此公私钥对数据为外部传入 - let pubKeyArray = - new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, - 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, - 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, - 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); - let priKeyArray = - new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, - 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); - let eccGen = cryptoFramework.createAsyKeyGenerator('ECC256'); - // 外部传入的公私钥对A - let keyPairA = eccGen.convertKeySync({ data: pubKeyArray }, { data: priKeyArray }); - // 内部生成的公私钥对B - let keyPairB = eccGen.generateKeyPairSync(); - let eccKeyAgreement = cryptoFramework.createKeyAgreement('ECC256'); - // 使用A的公钥和B的私钥进行密钥协商 - let secret1 = eccKeyAgreement.generateSecretSync(keyPairB.priKey, keyPairA.pubKey); - // 使用A的私钥和B的公钥进行密钥协商 - let secret2 = eccKeyAgreement.generateSecretSync(keyPairA.priKey, keyPairB.pubKey); - // 两种协商的结果应当一致 - if (secret1.data.toString() === secret2.data.toString()) { - console.info('ecdh success'); - console.info('ecdh output is ' + secret1.data); - } else { - console.error('ecdh result is not equal'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'EDCH Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_edch_sync')) - .width('70%') - .onClick(() => { - try { - ecdhAwait(); - this.message = 'EDCH Sync Success'; - } catch { - this.message = 'EDCH Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function ecdhAwait() { + // 假设此公私钥对数据为外部传入 + let pubKeyArray = + new Uint8Array([48, 89, 48, 19, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, + 83, 96, 142, 9, 86, 214, 126, 106, 247, 233, 92, 125, 4, 128, 138, 105, 246, 162, 215, 71, 81, 58, 202, 121, 26, + 105, 211, 55, 130, 45, 236, 143, 55, 16, 248, 75, 167, 160, 167, 106, 2, 152, 243, 44, 68, 66, 0, 167, 99, 92, + 235, 215, 159, 239, 28, 106, 124, 171, 34, 145, 124, 174, 57, 92]); + let priKeyArray = + new Uint8Array([48, 49, 2, 1, 1, 4, 32, 115, 56, 137, 35, 207, 0, 60, 191, 90, 61, 136, 105, 210, 16, 27, 4, 171, + 57, 10, 61, 123, 40, 189, 28, 34, 207, 236, 22, 45, 223, 10, 189, 160, 10, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7]); + let eccGen = cryptoFramework.createAsyKeyGenerator('ECC256'); + // 外部传入的公私钥对A + let keyPairA = eccGen.convertKeySync({ data: pubKeyArray }, { data: priKeyArray }); + // 内部生成的公私钥对B + let keyPairB = eccGen.generateKeyPairSync(); + let eccKeyAgreement = cryptoFramework.createKeyAgreement('ECC256'); + // 使用A的公钥和B的私钥进行密钥协商 + let secret1 = eccKeyAgreement.generateSecretSync(keyPairB.priKey, keyPairA.pubKey); + // 使用A的私钥和B的公钥进行密钥协商 + let secret2 = eccKeyAgreement.generateSecretSync(keyPairA.priKey, keyPairB.pubKey); + // 两种协商的结果应当一致 + if (secret1.data.toString() === secret2.data.toString()) { + console.info('ecdh success'); + console.info('ecdh output is ' + secret1.data); + } else { + console.error('ecdh result is not equal'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'EDCH Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_edch_sync')) + .width('70%') + .onClick(() => { + try { + ecdhAwait(); + this.message = 'EDCH Sync Success'; + } catch { + this.message = 'EDCH Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Async.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Async.ets old mode 100755 new mode 100644 index 1be37d026c3936c0ef86851dedad4088baec9fa4..10a6ca724d23f75bb83193c75a9ade9f54d586e0 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Async.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Async.ets @@ -1,67 +1,67 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -async function x25519Await() { - // 假设此公私钥对数据为外部传入 - let pubKeyArray = - new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 36, 98, 216, 106, 74, 99, 179, 203, 81, 145, 147, 101, - 139, 57, 74, 225, 119, 196, 207, 0, 50, 232, 93, 147, 188, 21, 225, 228, 54, 251, 230, 52]); - let priKeyArray = - new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 112, 65, 156, 73, 65, 89, 183, 39, 119, - 229, 110, 12, 192, 237, 186, 153, 21, 122, 28, 176, 248, 108, 22, 242, 239, 179, 106, 175, 85, 65, 214, 90]); - let keyGen = cryptoFramework.createAsyKeyGenerator('X25519'); - // 外部传入的公私钥对A - let keyPairA = await keyGen.convertKey({ data: pubKeyArray }, { data: priKeyArray }); - // 内部生成的公私钥对B - let keyPairB = await keyGen.generateKeyPair(); - let keyAgreement = cryptoFramework.createKeyAgreement('X25519'); - // 使用A的公钥和B的私钥进行密钥协商 - let secret1 = await keyAgreement.generateSecret(keyPairB.priKey, keyPairA.pubKey); - // 使用A的私钥和B的公钥进行密钥协商 - let secret2 = await keyAgreement.generateSecret(keyPairA.priKey, keyPairB.pubKey); - // 两种协商的结果应当一致 - if (secret1.data.toString() === secret2.data.toString()) { - console.info('x25519 success'); - console.info('x25519 output is ' + secret1.data); - } else { - console.error('x25519 result is not equal'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'X25519 Async'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_x25519_async')) - .width('70%') - .onClick(async () => { - try { - await x25519Await(); - this.message = 'X25519 Async Success'; - } catch { - this.message = 'X25519 Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function x25519Await() { + // 假设此公私钥对数据为外部传入 + let pubKeyArray = + new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 36, 98, 216, 106, 74, 99, 179, 203, 81, 145, 147, 101, + 139, 57, 74, 225, 119, 196, 207, 0, 50, 232, 93, 147, 188, 21, 225, 228, 54, 251, 230, 52]); + let priKeyArray = + new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 112, 65, 156, 73, 65, 89, 183, 39, 119, + 229, 110, 12, 192, 237, 186, 153, 21, 122, 28, 176, 248, 108, 22, 242, 239, 179, 106, 175, 85, 65, 214, 90]); + let keyGen = cryptoFramework.createAsyKeyGenerator('X25519'); + // 外部传入的公私钥对A + let keyPairA = await keyGen.convertKey({ data: pubKeyArray }, { data: priKeyArray }); + // 内部生成的公私钥对B + let keyPairB = await keyGen.generateKeyPair(); + let keyAgreement = cryptoFramework.createKeyAgreement('X25519'); + // 使用A的公钥和B的私钥进行密钥协商 + let secret1 = await keyAgreement.generateSecret(keyPairB.priKey, keyPairA.pubKey); + // 使用A的私钥和B的公钥进行密钥协商 + let secret2 = await keyAgreement.generateSecret(keyPairA.priKey, keyPairB.pubKey); + // 两种协商的结果应当一致 + if (secret1.data.toString() === secret2.data.toString()) { + console.info('x25519 success'); + console.info('x25519 output is ' + secret1.data); + } else { + console.error('x25519 result is not equal'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'X25519 Async'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_x25519_async')) + .width('70%') + .onClick(async () => { + try { + await x25519Await(); + this.message = 'X25519 Async Success'; + } catch { + this.message = 'X25519 Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Sync.ets old mode 100755 new mode 100644 index 93b2d229b7084826e4178407b688e502f7ab4de0..eb8802f4766719a385e0709956c6c1df49fe9b96 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/ets/pages/X25519/X25519Sync.ets @@ -1,67 +1,67 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; - -function x25519Await() { - // 假设此公私钥对数据为外部传入 - let pubKeyArray = - new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 36, 98, 216, 106, 74, 99, 179, 203, 81, 145, 147, 101, - 139, 57, 74, 225, 119, 196, 207, 0, 50, 232, 93, 147, 188, 21, 225, 228, 54, 251, 230, 52]); - let priKeyArray = - new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 112, 65, 156, 73, 65, 89, 183, 39, 119, - 229, 110, 12, 192, 237, 186, 153, 21, 122, 28, 176, 248, 108, 22, 242, 239, 179, 106, 175, 85, 65, 214, 90]); - let keyGen = cryptoFramework.createAsyKeyGenerator('X25519'); - // 外部传入的公私钥对A - let keyPairA = keyGen.convertKeySync({ data: pubKeyArray }, { data: priKeyArray }); - // 内部生成的公私钥对B - let keyPairB = keyGen.generateKeyPairSync(); - let keyAgreement = cryptoFramework.createKeyAgreement('X25519'); - // 使用A的公钥和B的私钥进行密钥协商 - let secret1 = keyAgreement.generateSecretSync(keyPairB.priKey, keyPairA.pubKey); - // 使用A的私钥和B的公钥进行密钥协商 - let secret2 = keyAgreement.generateSecretSync(keyPairA.priKey, keyPairB.pubKey); - // 两种协商的结果应当一致 - if (secret1.data.toString() === secret2.data.toString()) { - console.info('x25519 success'); - console.info('x25519 output is ' + secret1.data); - } else { - console.error('x25519 result is not equal'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'X25519 Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_x25519_sync')) - .width('70%') - .onClick(() => { - try { - x25519Await(); - this.message = 'X25519 Sync Success'; - } catch { - this.message = 'X25519 Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function x25519Await() { + // 假设此公私钥对数据为外部传入 + let pubKeyArray = + new Uint8Array([48, 42, 48, 5, 6, 3, 43, 101, 110, 3, 33, 0, 36, 98, 216, 106, 74, 99, 179, 203, 81, 145, 147, 101, + 139, 57, 74, 225, 119, 196, 207, 0, 50, 232, 93, 147, 188, 21, 225, 228, 54, 251, 230, 52]); + let priKeyArray = + new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 110, 4, 34, 4, 32, 112, 65, 156, 73, 65, 89, 183, 39, 119, + 229, 110, 12, 192, 237, 186, 153, 21, 122, 28, 176, 248, 108, 22, 242, 239, 179, 106, 175, 85, 65, 214, 90]); + let keyGen = cryptoFramework.createAsyKeyGenerator('X25519'); + // 外部传入的公私钥对A + let keyPairA = keyGen.convertKeySync({ data: pubKeyArray }, { data: priKeyArray }); + // 内部生成的公私钥对B + let keyPairB = keyGen.generateKeyPairSync(); + let keyAgreement = cryptoFramework.createKeyAgreement('X25519'); + // 使用A的公钥和B的私钥进行密钥协商 + let secret1 = keyAgreement.generateSecretSync(keyPairB.priKey, keyPairA.pubKey); + // 使用A的私钥和B的公钥进行密钥协商 + let secret2 = keyAgreement.generateSecretSync(keyPairA.priKey, keyPairB.pubKey); + // 两种协商的结果应当一致 + if (secret1.data.toString() === secret2.data.toString()) { + console.info('x25519 success'); + console.info('x25519 output is ' + secret1.data); + } else { + console.error('x25519 result is not equal'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'X25519 Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_x25519_sync')) + .width('70%') + .onClick(() => { + try { + x25519Await(); + this.message = 'X25519 Sync Success'; + } catch { + this.message = 'X25519 Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/KeyNegotiation.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/KeyNegotiation.test.ets old mode 100755 new mode 100644 index dfa0e0b86f1cc86b79bc2acb168ad7ac2cb1d5a5..cece2ce32b52c65d1788244bf3dd75ab77f00fd2 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/KeyNegotiation.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/KeyNegotiation.test.ets @@ -1,152 +1,152 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function keyNegotiationTest() { - describe('keyNegotiationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用ECDH进行密钥协商(await方式) - */ - it('testKeyNegotiation001', 0, async () => { - console.info('uitest: testKeyNegotiation001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECDH Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call EDCH Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('EDCH Async Success')); - console.info('uitest: testKeyNegotiation001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用ECDH进行密钥协商(同步方式) - */ - it('testKeyNegotiation002', 0, async () => { - console.info('uitest: testKeyNegotiation002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECDH Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call EDCH Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('EDCH Sync Success')); - console.info('uitest: testKeyNegotiation002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用X25519进行密钥协商(await方式) - */ - it('testKeyNegotiation003', 0, async () => { - console.info('uitest: testKeyNegotiation003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('X25519 Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call X25519 Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('X25519 Async Success')); - console.info('uitest: testKeyNegotiation003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用X25519进行密钥协商(同步方式) - */ - it('testKeyNegotiation004', 0, async () => { - console.info('uitest: testKeyNegotiation004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('X25519 Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call X25519 Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('X25519 Sync Success')); - console.info('uitest: testKeyNegotiation004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用DH进行密钥协商(await方式) - */ - it('testKeyNegotiation005', 0, async () => { - console.info('uitest: testKeyNegotiation005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('DH Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call DH Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('DH Async Success')); - console.info('uitest: testKeyNegotiation005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用DH进行密钥协商(同步方式) - */ - it('testKeyNegotiation006', 0, async () => { - console.info('uitest: testKeyNegotiation006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('DH Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call DH Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('DH Sync Success')); - console.info('uitest: testKeyNegotiation006 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function keyNegotiationTest() { + describe('keyNegotiationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用ECDH进行密钥协商(await方式) + */ + it('testKeyNegotiation001', 0, async () => { + console.info('uitest: testKeyNegotiation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECDH Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call EDCH Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('EDCH Async Success')); + console.info('uitest: testKeyNegotiation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECDH进行密钥协商(同步方式) + */ + it('testKeyNegotiation002', 0, async () => { + console.info('uitest: testKeyNegotiation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECDH Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call EDCH Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('EDCH Sync Success')); + console.info('uitest: testKeyNegotiation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用X25519进行密钥协商(await方式) + */ + it('testKeyNegotiation003', 0, async () => { + console.info('uitest: testKeyNegotiation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('X25519 Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call X25519 Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('X25519 Async Success')); + console.info('uitest: testKeyNegotiation003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用X25519进行密钥协商(同步方式) + */ + it('testKeyNegotiation004', 0, async () => { + console.info('uitest: testKeyNegotiation004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('X25519 Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call X25519 Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('X25519 Sync Success')); + console.info('uitest: testKeyNegotiation004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用DH进行密钥协商(await方式) + */ + it('testKeyNegotiation005', 0, async () => { + console.info('uitest: testKeyNegotiation005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('DH Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call DH Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('DH Async Success')); + console.info('uitest: testKeyNegotiation005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用DH进行密钥协商(同步方式) + */ + it('testKeyNegotiation006', 0, async () => { + console.info('uitest: testKeyNegotiation006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('DH Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call DH Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('DH Sync Success')); + console.info('uitest: testKeyNegotiation006 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyNegotiation/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/KeyNegotiation/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/ohosTest.md old mode 100755 new mode 100644 index 0c4fd9e85be1323d7afb53a84c3f2eb5e2b0a01b..b082027408632e0de31dc3026ef368ed62c62c89 --- a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/ohosTest.md @@ -1,13 +1,13 @@ -# 密钥协商测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用ECDH进行密钥协商(await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用ECDH进行密钥协商(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用X25519进行密钥协商(await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用X25519进行密钥协商(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用DH进行密钥协商(await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 密钥协商测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用ECDH进行密钥协商(await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDH进行密钥协商(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用X25519进行密钥协商(await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用X25519进行密钥协商(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用DH进行密钥协商(await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用DH进行密钥协商(同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/screenshots/KeyNegotiation1.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/screenshots/KeyNegotiation1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/screenshots/KeyNegotiation2.png b/code/DocsSample/Security/CryptoArchitectureKit/KeyNegotiation/screenshots/KeyNegotiation2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/app.json5 old mode 100755 new mode 100644 index 506c34074686e1cb66e8c114c8aebafb49e12928..78f9ea61a085288da1707f7bec35a0a437567f6b --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/app.json5 @@ -1,25 +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.messageauthenticationcode", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.messageauthenticationcode", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 43fb13c24525ae2a4f3231e31374d881b6b77770..230944b974465b50915c796506ba59d301a9893a --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MessageAuthenticationCode" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MessageAuthenticationCode" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/README.md b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/README.md old mode 100755 new mode 100644 index b511849f5c1b9c7b0288630dbd2ff04592afc625..d277f6b7e28aed11dad512cb99d69ce9772e04a9 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/README.md @@ -1,73 +1,73 @@ -# 消息认证码计算 - -### 介绍 - -本示例主要展示了消息认证码计算(HMAC、分段HMAC)场景 。该工程中展示的代码详细描述可查如下链接。 - -- [消息认证码计算](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-compute-mac.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例MessageAuthenticationCode.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 消息认证码计算示例代码 - │ │ ├── HMACSegmentation - │ │ | ├── Async.ets - │ │ | ├── Sync.ets - │ │ ├── HMACSingleTime - │ │ | ├── Async.ets - │ │ | ├── Sync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── MessageAuthenticationCode.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 消息认证码计算 + +### 介绍 + +本示例主要展示了消息认证码计算(HMAC、分段HMAC)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [消息认证码计算](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-compute-mac.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例MessageAuthenticationCode.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 消息认证码计算示例代码 + │ │ ├── HMACSegmentation + │ │ | ├── Async.ets + │ │ | ├── Sync.ets + │ │ ├── HMACSingleTime + │ │ | ├── Async.ets + │ │ | ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── MessageAuthenticationCode.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Async.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Async.ets old mode 100755 new mode 100644 index 9b7ab53adb81e5666331e9c363be167fe20a0c9d..10c3109c8c6cec65184e3b575669546d4dd75dc0 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Async.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Async.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function doHmac() { - // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 - let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); - let key = await genSymKeyByData(keyData); - let macAlgName = 'SHA256'; // 摘要算法名 - let message = 'hmacTestMessgae'; // 待进行HMAC的数据 - let mac = cryptoFramework.createMac(macAlgName); - await mac.init(key); - // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 - await mac.update({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); - let macResult = await mac.doFinal(); - console.info('HMAC result:' + macResult.data); - let macLen = mac.getMacLength(); - console.info('HMAC len:' + macLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'Segmentation Async'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_segmentation_async')) - .width('70%') - .onClick(async () => { - try { - await doHmac(); - this.message = 'Segmentation Async Success'; - } catch { - this.message = 'Segmentation Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); + let symKey = await aesGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function doHmac() { + // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 + let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); + let key = await genSymKeyByData(keyData); + let macAlgName = 'SHA256'; // 摘要算法名 + let message = 'hmacTestMessgae'; // 待进行HMAC的数据 + let mac = cryptoFramework.createMac(macAlgName); + await mac.init(key); + // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 + await mac.update({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); + let macResult = await mac.doFinal(); + console.info('HMAC result:' + macResult.data); + let macLen = mac.getMacLength(); + console.info('HMAC len:' + macLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'Segmentation Async'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_segmentation_async')) + .width('70%') + .onClick(async () => { + try { + await doHmac(); + this.message = 'Segmentation Async Success'; + } catch { + this.message = 'Segmentation Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Sync.ets old mode 100755 new mode 100644 index ea497d8f18d8dc3138c72f3dfbaeeab29b8b25ff..c3b2bd7af5741bd9218110061c2458c8869d3492 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSegmentation/Sync.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('[Sync]convertKey success'); - return symKey; -} - -function doHmacBySync() { - // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 - let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); - let key = genSymKeyByData(keyData); - let macAlgName = 'SHA256'; // 摘要算法名 - let message = 'hmacTestMessgae'; // 待进行HMAC的数据 - let mac = cryptoFramework.createMac(macAlgName); - mac.initSync(key); - // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 - mac.updateSync({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); - let macResult = mac.doFinalSync(); - console.info('[Sync]HMAC result:' + macResult.data); - let macLen = mac.getMacLength(); - console.info('HMAC len:' + macLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'Segmentation Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_segmentation_sync')) - .width('70%') - .onClick(() => { - try { - doHmacBySync(); - this.message = 'Segmentation Sync Success'; - } catch { - this.message = 'Segmentation Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); + let symKey = aesGenerator.convertKeySync(symKeyBlob); + console.info('[Sync]convertKey success'); + return symKey; +} + +function doHmacBySync() { + // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 + let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); + let key = genSymKeyByData(keyData); + let macAlgName = 'SHA256'; // 摘要算法名 + let message = 'hmacTestMessgae'; // 待进行HMAC的数据 + let mac = cryptoFramework.createMac(macAlgName); + mac.initSync(key); + // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 + mac.updateSync({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); + let macResult = mac.doFinalSync(); + console.info('[Sync]HMAC result:' + macResult.data); + let macLen = mac.getMacLength(); + console.info('HMAC len:' + macLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'Segmentation Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_segmentation_sync')) + .width('70%') + .onClick(() => { + try { + doHmacBySync(); + this.message = 'Segmentation Sync Success'; + } catch { + this.message = 'Segmentation Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Async.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Async.ets old mode 100755 new mode 100644 index a9f73fa472fed6ddbc9907a645d3a35c51cdba72..166470cc9c618c476945e361a2f3400c7c488a4c --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Async.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Async.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); - let symKey = await aesGenerator.convertKey(symKeyBlob); - console.info('convertKey success'); - return symKey; -} - -async function doLoopHmac() { - // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 - let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); - let key = await genSymKeyByData(keyData); - let macAlgName = 'SHA256'; // 摘要算法名 - let mac = cryptoFramework.createMac(macAlgName); - // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; - let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - await mac.init(key); - for (let i = 0; i < messageData.length; i += updateLength) { - let updateMessage = messageData.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - await mac.update(updateMessageBlob); - } - let macOutput = await mac.doFinal(); - console.info('HMAC result: ' + macOutput.data); - let macLen = mac.getMacLength(); - console.info('HMAC len:' + macLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'SingleTime Async'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_single_time_async')) - .width('70%') - .onClick(async () => { - try { - await doLoopHmac(); - this.message = 'SingleTime Async Success'; - } catch { - this.message = 'SingleTime Async Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); + let symKey = await aesGenerator.convertKey(symKeyBlob); + console.info('convertKey success'); + return symKey; +} + +async function doLoopHmac() { + // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 + let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); + let key = await genSymKeyByData(keyData); + let macAlgName = 'SHA256'; // 摘要算法名 + let mac = cryptoFramework.createMac(macAlgName); + // 假设信息总共43字节,根据utf-8解码后,也是43字节 + let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; + let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); + let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 + await mac.init(key); + for (let i = 0; i < messageData.length; i += updateLength) { + let updateMessage = messageData.subarray(i, i + updateLength); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + await mac.update(updateMessageBlob); + } + let macOutput = await mac.doFinal(); + console.info('HMAC result: ' + macOutput.data); + let macLen = mac.getMacLength(); + console.info('HMAC len:' + macLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'SingleTime Async'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_single_time_async')) + .width('70%') + .onClick(async () => { + try { + await doLoopHmac(); + this.message = 'SingleTime Async Success'; + } catch { + this.message = 'SingleTime Async Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Sync.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Sync.ets old mode 100755 new mode 100644 index 52260466acbe0ceb73ed153c236a98bad41e4bc4..2a5e07504cb58b85c1a898612f89b6d44d961e8b --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Sync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/HMACSingleTime/Sync.ets @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function genSymKeyByData(symKeyData: Uint8Array) { - let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; - let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); - let symKey = aesGenerator.convertKeySync(symKeyBlob); - console.info('[Sync]convertKey success'); - return symKey; -} - -function doLoopHmacBySync() { - // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 - let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); - let key = genSymKeyByData(keyData); - let macAlgName = 'SHA256'; // 摘要算法名 - let mac = cryptoFramework.createMac(macAlgName); - // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; - let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - mac.initSync(key); - for (let i = 0; i < messageData.length; i += updateLength) { - let updateMessage = messageData.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - mac.updateSync(updateMessageBlob); - } - let macOutput = mac.doFinalSync(); - console.info('[Sync]HMAC result: ' + macOutput.data); - let macLen = mac.getMacLength(); - console.info('HMAC len:' + macLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'SingleTime Sync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_single_time_sync')) - .width('70%') - .onClick(() => { - try { - doLoopHmacBySync(); - this.message = 'SingleTime Sync Success'; - } catch { - this.message = 'SingleTime Sync Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function genSymKeyByData(symKeyData: Uint8Array) { + let symKeyBlob: cryptoFramework.DataBlob = { data: symKeyData }; + let aesGenerator = cryptoFramework.createSymKeyGenerator('HMAC'); + let symKey = aesGenerator.convertKeySync(symKeyBlob); + console.info('[Sync]convertKey success'); + return symKey; +} + +function doLoopHmacBySync() { + // 把字符串按utf-8解码为Uint8Array,使用固定的128位的密钥,即16字节 + let keyData = new Uint8Array(buffer.from('12345678abcdefgh', 'utf-8').buffer); + let key = genSymKeyByData(keyData); + let macAlgName = 'SHA256'; // 摘要算法名 + let mac = cryptoFramework.createMac(macAlgName); + // 假设信息总共43字节,根据utf-8解码后,也是43字节 + let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; + let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); + let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 + mac.initSync(key); + for (let i = 0; i < messageData.length; i += updateLength) { + let updateMessage = messageData.subarray(i, i + updateLength); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + mac.updateSync(updateMessageBlob); + } + let macOutput = mac.doFinalSync(); + console.info('[Sync]HMAC result: ' + macOutput.data); + let macLen = mac.getMacLength(); + console.info('HMAC len:' + macLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'SingleTime Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_single_time_sync')) + .width('70%') + .onClick(() => { + try { + doLoopHmacBySync(); + this.message = 'SingleTime Sync Success'; + } catch { + this.message = 'SingleTime Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/MessageAuthenticationCode.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/MessageAuthenticationCode.test.ets old mode 100755 new mode 100644 index c9a5c1341e925864493dedbd310bff70bc3bb54b..1c094db7b422bf1ad90f7fcc234f13d28fb15468 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/MessageAuthenticationCode.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/ets/test/MessageAuthenticationCode.test.ets @@ -1,116 +1,116 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function messageAuthenticationCodeTest() { - describe('messageAuthenticationCodeTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,消息认证码计算(HMAC await方式) - */ - it('testMessageAuthenticationCode001', 0, async () => { - console.info('uitest: testMessageAuthenticationCode001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Segmentation Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Segmentation Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Segmentation Async Success')); - console.info('uitest: testMessageAuthenticationCode001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息认证码计算(HMAC 同步方式) - */ - it('testMessageAuthenticationCode002', 0, async () => { - console.info('uitest: testMessageAuthenticationCode002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Segmentation Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call Segmentation Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Segmentation Sync Success')); - console.info('uitest: testMessageAuthenticationCode002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息认证码计算(分段HMAC await方式) - */ - it('testMessageAuthenticationCode003', 0, async () => { - console.info('uitest: testMessageAuthenticationCode003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SingleTime Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SingleTime Async')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SingleTime Async Success')); - console.info('uitest: testMessageAuthenticationCode003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息认证码计算(分段HMAC 同步方式) - */ - it('testMessageAuthenticationCode004', 0, async () => { - console.info('uitest: testMessageAuthenticationCode004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SingleTime Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SingleTime Sync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SingleTime Sync Success')); - console.info('uitest: testMessageAuthenticationCode004 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function messageAuthenticationCodeTest() { + describe('messageAuthenticationCodeTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,消息认证码计算(HMAC await方式) + */ + it('testMessageAuthenticationCode001', 0, async () => { + console.info('uitest: testMessageAuthenticationCode001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Segmentation Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Segmentation Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Segmentation Async Success')); + console.info('uitest: testMessageAuthenticationCode001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息认证码计算(HMAC 同步方式) + */ + it('testMessageAuthenticationCode002', 0, async () => { + console.info('uitest: testMessageAuthenticationCode002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Segmentation Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Segmentation Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Segmentation Sync Success')); + console.info('uitest: testMessageAuthenticationCode002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息认证码计算(分段HMAC await方式) + */ + it('testMessageAuthenticationCode003', 0, async () => { + console.info('uitest: testMessageAuthenticationCode003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SingleTime Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SingleTime Async')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SingleTime Async Success')); + console.info('uitest: testMessageAuthenticationCode003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息认证码计算(分段HMAC 同步方式) + */ + it('testMessageAuthenticationCode004', 0, async () => { + console.info('uitest: testMessageAuthenticationCode004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SingleTime Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SingleTime Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SingleTime Sync Success')); + console.info('uitest: testMessageAuthenticationCode004 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/MessageAuthenticationCode/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/MessageAuthenticationCode/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/ohosTest.md old mode 100755 new mode 100644 index 77ebece084ed115342fa802d75da29eb49c9371a..997924c6832a78fa7ff948d55fd5dd219d12605d --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/ohosTest.md @@ -1,11 +1,11 @@ -# 消息认证码计算测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,消息认证码计算(HMAC await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,消息认证码计算(HMAC 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,消息认证码计算(分段HMAC await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 消息认证码计算测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,消息认证码计算(HMAC await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,消息认证码计算(HMAC 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,消息认证码计算(分段HMAC await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,消息认证码计算(分段HMAC 同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/screenshots/MessageAuthenticationCode1.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/screenshots/MessageAuthenticationCode1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/screenshots/MessageAuthenticationCode2.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageAuthenticationCode/screenshots/MessageAuthenticationCode2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/app.json5 old mode 100755 new mode 100644 index 9910d9b555f291aae47f755ff7e25c6b2f772dbc..67ca91640924a02245b97f443f27d99761c11769 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/app.json5 @@ -1,25 +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.messagedigestcomputation", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.messagedigestcomputation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index a91c6054ec32a45c2d825c695a72045c08a9d3c5..8b289a1aceb74578de2d3518de476fe19489fa89 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MessageDigestComputation" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MessageDigestComputation" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/README.md b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/README.md old mode 100755 new mode 100644 index bcf20708c1d7b09a0b0b36f02dea4a50337827d4..cdcfecf7b3a6f86abef4678a40710f8eb77eaf64 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/README.md @@ -1,85 +1,85 @@ -# 消息摘要计算 - -### 介绍 - -本示例主要展示了消息摘要计算(ArkTS)、消息摘要计算(C/C++)场景 。该工程中展示的代码详细描述可查如下链接。 - -- [消息摘要计算(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-message-digest.md) -- [消息摘要计算(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-message-digest-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例MessageDigestComputation.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── segmentation.cpp - │ │ | ├── singleTime.cpp - │ │ | ├── file.h - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 消息摘要计算示例代码 - │ │ ├── segmentation - │ │ | ├── SegmentationAsync.ets - │ │ | ├── SegmentationSync.ets - │ │ ├── singleTime - │ │ | ├── SingleTimeAsync.ets - │ │ | ├── SingleTimeSync.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── MessageDigestComputation.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 消息摘要计算 + +### 介绍 + +本示例主要展示了消息摘要计算(ArkTS)、消息摘要计算(C/C++)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [消息摘要计算(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-message-digest.md) +- [消息摘要计算(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-message-digest-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例MessageDigestComputation.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── segmentation.cpp + │ │ | ├── singleTime.cpp + │ │ | ├── file.h + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 消息摘要计算示例代码 + │ │ ├── segmentation + │ │ | ├── SegmentationAsync.ets + │ │ | ├── SegmentationSync.ets + │ │ ├── singleTime + │ │ | ├── SingleTimeAsync.ets + │ │ | ├── SingleTimeSync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── MessageDigestComputation.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 2dfee85b6df19d950f553df3c01693724f22408e..e9e4d0405dc9cf2d466184b43eb662b8cee8b018 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(MessageDigestComputation) - -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 types/project/segmentation.cpp types/project/singleTime.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(MessageDigestComputation) + +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 types/project/segmentation.cpp types/project/singleTime.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 6c43b7ba23a25bce5857926893bc49bc9de07099..87ee66888a1b1e1735d66f93fd0c9574c4229573 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/napi_init.cpp @@ -1,52 +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. - */ - -#include "napi/native_api.h" -#include "types/project/file.h" - -static napi_value NAPI_Global_doTestMd(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doTestMd(), &ret); - return ret; -} -static napi_value NAPI_Global_doLoopMd(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, doLoopMd(), &ret); - return ret; -} -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"doTestMd", nullptr, NAPI_Global_doTestMd, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"doLoopMd", nullptr, NAPI_Global_doLoopMd, 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); } +/* + * 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 "types/project/file.h" + +static napi_value NAPI_Global_doTestMd(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doTestMd(), &ret); + return ret; +} +static napi_value NAPI_Global_doLoopMd(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, doLoopMd(), &ret); + return ret; +} +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"doTestMd", nullptr, NAPI_Global_doTestMd, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"doLoopMd", nullptr, NAPI_Global_doLoopMd, 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index 9e477cb765201587a97bbe863da599aa88344886..8d3539298b95d72f368d0d11392941493db862f2 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,18 +1,18 @@ -/* - * 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 doTestMd: () => number; - +/* + * 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 doTestMd: () => number; + export const doLoopMd: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/file.h b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/file.h old mode 100755 new mode 100644 index 9efce03ab0c534531276e1043af35c996db7cca4..4e6a15a13ede84884b3a90aca8f5eb0399e2ce4a --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/file.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/file.h @@ -1,23 +1,23 @@ -#ifndef FILE_H -#define FILE_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" - -OH_Crypto_ErrCode doTestMd(); -OH_Crypto_ErrCode doLoopMd(); - +#ifndef FILE_H +#define FILE_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" + +OH_Crypto_ErrCode doTestMd(); +OH_Crypto_ErrCode doLoopMd(); + #endif // FILE_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/segmentation.cpp b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/segmentation.cpp old mode 100755 new mode 100644 index 77528e2039ef292540bb433f5af407c37851619f..4651b088470819d2a0d4ebbeaffe25fe62865f6e --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/segmentation.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/segmentation.cpp @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_digest.h" -#include "file.h" -#define OH_CRYPTO_DIGEST_DATA_MAX (1024 * 1024 * 100) - -static constexpr int INT_640 = 640; - -OH_Crypto_ErrCode doLoopMd() -{ - OH_Crypto_ErrCode ret; - OH_CryptoDigest *ctx = nullptr; - uint8_t *testData = (uint8_t *)malloc(OH_CRYPTO_DIGEST_DATA_MAX); - if (testData == nullptr) { - return CRYPTO_MEMORY_ERROR; - } - Crypto_DataBlob out = {.data = nullptr, .len = 0}; - int mdLen = 0; - int isBlockSize = 20; - int offset = 0; - - ret = OH_CryptoDigest_Create("SHA256", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - do { - for (int i = 0; i < INT_640 / isBlockSize; i++) { - Crypto_DataBlob in = {.data = reinterpret_cast(testData + offset), - .len = static_cast(isBlockSize)}; - ret = OH_CryptoDigest_Update(ctx, &in); - if (ret != CRYPTO_SUCCESS) { - break; - } - offset += isBlockSize; - } - ret = OH_CryptoDigest_Final(ctx, &out); - if (ret != CRYPTO_SUCCESS) { - break; - } - mdLen = OH_CryptoDigest_GetLength(ctx); - } while (0); - OH_Crypto_FreeDataBlob(&out); - OH_DigestCrypto_Destroy(ctx); - return ret; +/* + * 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 +#include "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_digest.h" +#include "file.h" +#define OH_CRYPTO_DIGEST_DATA_MAX (1024 * 1024 * 100) + +static constexpr int INT_640 = 640; + +OH_Crypto_ErrCode doLoopMd() +{ + OH_Crypto_ErrCode ret; + OH_CryptoDigest *ctx = nullptr; + uint8_t *testData = (uint8_t *)malloc(OH_CRYPTO_DIGEST_DATA_MAX); + if (testData == nullptr) { + return CRYPTO_MEMORY_ERROR; + } + Crypto_DataBlob out = {.data = nullptr, .len = 0}; + int mdLen = 0; + int isBlockSize = 20; + int offset = 0; + + ret = OH_CryptoDigest_Create("SHA256", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + do { + for (int i = 0; i < INT_640 / isBlockSize; i++) { + Crypto_DataBlob in = {.data = reinterpret_cast(testData + offset), + .len = static_cast(isBlockSize)}; + ret = OH_CryptoDigest_Update(ctx, &in); + if (ret != CRYPTO_SUCCESS) { + break; + } + offset += isBlockSize; + } + ret = OH_CryptoDigest_Final(ctx, &out); + if (ret != CRYPTO_SUCCESS) { + break; + } + mdLen = OH_CryptoDigest_GetLength(ctx); + } while (0); + OH_Crypto_FreeDataBlob(&out); + OH_DigestCrypto_Destroy(ctx); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/singleTime.cpp b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/singleTime.cpp old mode 100755 new mode 100644 index 7e3e7d1af9ee2e3f441b7bdd0de195f25f17c4d1..4aabf9921707c50b3d4491120e272062529c6dc8 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/singleTime.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/cpp/types/project/singleTime.cpp @@ -1,47 +1,47 @@ -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_digest.h" -#include -#include "file.h" - -OH_Crypto_ErrCode doTestMd() -{ - OH_Crypto_ErrCode ret; - OH_CryptoDigest *ctx = nullptr; - char *testData = const_cast("0123456789"); - Crypto_DataBlob in = {.data = (uint8_t *)(testData), .len = strlen(testData)}; - Crypto_DataBlob out = {.data = nullptr, .len = 0}; - int mdLen = 0; - ret = OH_CryptoDigest_Create("SHA256", &ctx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - do { - ret = OH_CryptoDigest_Update(ctx, &in); - if (ret != CRYPTO_SUCCESS) { - break; - } - ret = OH_CryptoDigest_Final(ctx, &out); - if (ret != CRYPTO_SUCCESS) { - break; - } - mdLen = OH_CryptoDigest_GetLength(ctx); - } while (0); - OH_Crypto_FreeDataBlob(&out); - OH_DigestCrypto_Destroy(ctx); - return ret; +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_digest.h" +#include +#include "file.h" + +OH_Crypto_ErrCode doTestMd() +{ + OH_Crypto_ErrCode ret; + OH_CryptoDigest *ctx = nullptr; + char *testData = const_cast("0123456789"); + Crypto_DataBlob in = {.data = (uint8_t *)(testData), .len = strlen(testData)}; + Crypto_DataBlob out = {.data = nullptr, .len = 0}; + int mdLen = 0; + ret = OH_CryptoDigest_Create("SHA256", &ctx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + do { + ret = OH_CryptoDigest_Update(ctx, &in); + if (ret != CRYPTO_SUCCESS) { + break; + } + ret = OH_CryptoDigest_Final(ctx, &out); + if (ret != CRYPTO_SUCCESS) { + break; + } + mdLen = OH_CryptoDigest_GetLength(ctx); + } while (0); + OH_Crypto_FreeDataBlob(&out); + OH_DigestCrypto_Destroy(ctx); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationAsync.ets old mode 100755 new mode 100644 index d5d70502874245b556a02e2532585b2d4222e800..42c17e43d81b508924b266e87f17919850fdf768 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationAsync.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function doLoopMd() { - let mdAlgName = 'SHA256'; // 摘要算法名 - let md = cryptoFramework.createMd(mdAlgName); - // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; - let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - for (let i = 0; i < messageData.length; i += updateLength) { - let updateMessage = messageData.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - await md.update(updateMessageBlob); - } - let mdOutput = await md.digest(); - console.info('md result: ' + mdOutput.data); - let mdLen = md.getMdLength(); - console.info('md len: ' + mdLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'SegmentationAsync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_segmentation_async')) - .width('70%') - .onClick(async () => { - try { - await doLoopMd(); - this.message = 'SegmentationAsyncSuccess'; - } catch { - this.message = 'SegmentationAsyncFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function doLoopMd() { + let mdAlgName = 'SHA256'; // 摘要算法名 + let md = cryptoFramework.createMd(mdAlgName); + // 假设信息总共43字节,根据utf-8解码后,也是43字节 + let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; + let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); + let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 + for (let i = 0; i < messageData.length; i += updateLength) { + let updateMessage = messageData.subarray(i, i + updateLength); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + await md.update(updateMessageBlob); + } + let mdOutput = await md.digest(); + console.info('md result: ' + mdOutput.data); + let mdLen = md.getMdLength(); + console.info('md len: ' + mdLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'SegmentationAsync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_segmentation_async')) + .width('70%') + .onClick(async () => { + try { + await doLoopMd(); + this.message = 'SegmentationAsyncSuccess'; + } catch { + this.message = 'SegmentationAsyncFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationSync.ets old mode 100755 new mode 100644 index cbb9e89b2929af12a4f3933a3b1dc862d155b4b0..2f1d9d72b7b214cf5bd6296669ac3a034098e9a0 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/segmentation/SegmentationSync.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function doLoopMdBySync() { - let mdAlgName = 'SHA256'; // 摘要算法名 - let md = cryptoFramework.createMd(mdAlgName); - // 假设信息总共43字节,根据utf-8解码后,也是43字节 - let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; - let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); - let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 - for (let i = 0; i < messageData.length; i += updateLength) { - let updateMessage = messageData.subarray(i, i + updateLength); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - md.updateSync(updateMessageBlob); - } - let mdOutput = md.digestSync(); - console.info('[Sync]:md result: ' + mdOutput.data); - let mdLen = md.getMdLength(); - console.info('md len: ' + mdLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'SegmentationSync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_segmentation_sync')) - .width('70%') - .onClick(() => { - try { - doLoopMdBySync(); - this.message = 'SegmentationSyncSuccess'; - } catch { - this.message = 'SegmentationSyncFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function doLoopMdBySync() { + let mdAlgName = 'SHA256'; // 摘要算法名 + let md = cryptoFramework.createMd(mdAlgName); + // 假设信息总共43字节,根据utf-8解码后,也是43字节 + let messageText = 'aaaaa.....bbbbb.....ccccc.....ddddd.....eee'; + let messageData = new Uint8Array(buffer.from(messageText, 'utf-8').buffer); + let updateLength = 20; // 假设以20字节为单位进行分段update,实际并无要求 + for (let i = 0; i < messageData.length; i += updateLength) { + let updateMessage = messageData.subarray(i, i + updateLength); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + md.updateSync(updateMessageBlob); + } + let mdOutput = md.digestSync(); + console.info('[Sync]:md result: ' + mdOutput.data); + let mdLen = md.getMdLength(); + console.info('md len: ' + mdLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'SegmentationSync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_segmentation_sync')) + .width('70%') + .onClick(() => { + try { + doLoopMdBySync(); + this.message = 'SegmentationSyncSuccess'; + } catch { + this.message = 'SegmentationSyncFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeAsync.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeAsync.ets old mode 100755 new mode 100644 index 8c048faa380df661cc84de1fa44668ab7ce563fc..0dea0c35fe35aafa521b4f4c3dc328b5dd3237ac --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeAsync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeAsync.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function doMd() { - let mdAlgName = 'SHA256'; // 摘要算法名 - let message = 'mdTestMessgae'; // 待摘要的数据 - let md = cryptoFramework.createMd(mdAlgName); - // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 - await md.update({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); - let mdResult = await md.digest(); - console.info('Md result:' + mdResult.data); - let mdLen = md.getMdLength(); - console.info('md len: ' + mdLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'SingleTimeAsync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button($r('app.string.call_single_time_async')) - .width('70%') - .onClick(async () => { - try { - await doMd(); - this.message = 'SingleTimeAsyncSuccess'; - } catch { - this.message = 'SingleTimeAsyncFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function doMd() { + let mdAlgName = 'SHA256'; // 摘要算法名 + let message = 'mdTestMessgae'; // 待摘要的数据 + let md = cryptoFramework.createMd(mdAlgName); + // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 + await md.update({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); + let mdResult = await md.digest(); + console.info('Md result:' + mdResult.data); + let mdLen = md.getMdLength(); + console.info('md len: ' + mdLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'SingleTimeAsync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_single_time_async')) + .width('70%') + .onClick(async () => { + try { + await doMd(); + this.message = 'SingleTimeAsyncSuccess'; + } catch { + this.message = 'SingleTimeAsyncFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeSync.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeSync.ets old mode 100755 new mode 100644 index f1841e3ee2a38029295be83210b9518b8d3766ca..ec672b8b3810bc96380ccdea55c7130d36727ab9 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeSync.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/ets/pages/singleTime/SingleTimeSync.ets @@ -1,53 +1,53 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function doMdBySync() { - let mdAlgName = 'SHA256'; // 摘要算法名 - let message = 'mdTestMessgae'; // 待摘要的数据 - let md = cryptoFramework.createMd(mdAlgName); - // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 - md.updateSync({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); - let mdResult = md.digestSync(); - console.info('[Sync]:Md result:' + mdResult.data); - let mdLen = md.getMdLength(); - console.info('md len: ' + mdLen); -} - -@Entry -@Component -struct Index { - @State message: string = 'SingleTimeSync'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) - Button('Call SingleTimeSync') - .width('70%') - .onClick(() => { - try { - doMdBySync(); - this.message = 'SingleTimeSyncSuccess'; - } catch { - this.message = 'SingleTimeSyncFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function doMdBySync() { + let mdAlgName = 'SHA256'; // 摘要算法名 + let message = 'mdTestMessgae'; // 待摘要的数据 + let md = cryptoFramework.createMd(mdAlgName); + // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制 + md.updateSync({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) }); + let mdResult = md.digestSync(); + console.info('[Sync]:Md result:' + mdResult.data); + let mdLen = md.getMdLength(); + console.info('md len: ' + mdLen); +} + +@Entry +@Component +struct Index { + @State message: string = 'SingleTimeSync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button('Call SingleTimeSync') + .width('70%') + .onClick(() => { + try { + doMdBySync(); + this.message = 'SingleTimeSyncSuccess'; + } catch { + this.message = 'SingleTimeSyncFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/MessageDigestComputation.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/MessageDigestComputation.test.ets old mode 100755 new mode 100644 index 14bdf7f8400ce90d25ab60018d9db32a64674b8f..77a030e99cae340bcd914031bd589c79eb16b5d3 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/MessageDigestComputation.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/ets/test/MessageDigestComputation.test.ets @@ -1,144 +1,144 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function messageDigestComputationTest() { - describe('messageDigestComputationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,消息摘要计算(ArkTS 摘要算法await方式) - */ - it('testMessageDigestComputation001', 0, async () => { - console.info('uitest: testMessageDigestComputation001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SegmentationAsync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SegmentationAsync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SegmentationAsyncSuccess')); - console.info('uitest: testMessageDigestComputation001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息摘要计算(ArkTS 摘要算法同步方式) - */ - it('testMessageDigestComputation002', 0, async () => { - console.info('uitest: testMessageDigestComputation002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SegmentationSync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SegmentationSync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SegmentationSyncSuccess')); - console.info('uitest: testMessageDigestComputation002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息摘要计算(ArkTS 分段摘要算法await方式) - */ - it('testMessageDigestComputation003', 0, async () => { - console.info('uitest: testMessageDigestComputation003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SingleTimeAsync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SingleTimeAsync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SingleTimeAsyncSuccess')); - console.info('uitest: testMessageDigestComputation003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息摘要计算(ArkTS 分段摘要算法同步方式) - */ - it('testMessageDigestComputation004', 0, async () => { - console.info('uitest: testMessageDigestComputation004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SingleTimeSync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SingleTimeSync')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SingleTimeSyncSuccess')); - console.info('uitest: testMessageDigestComputation004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,消息摘要计算(C/C++ 摘要算法) - */ - it('testMessageDigestComputation005', 0, async () => { - console.info('uitest: testMessageDigestComputation005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SingleTime C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SingleTime C++ Success Result:0')); - console.info('uitest: testMessageDigestComputation005 end'); - }) - - /** - * 点击按钮,消息摘要计算(C/C++ 分段摘要算法) - */ - it('testMessageDigestComputation006', 0, async () => { - console.info('uitest: testMessageDigestComputation006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Segmentation C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Segmentation C++ Success Result:0')); - console.info('uitest: testMessageDigestComputation006 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function messageDigestComputationTest() { + describe('messageDigestComputationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,消息摘要计算(ArkTS 摘要算法await方式) + */ + it('testMessageDigestComputation001', 0, async () => { + console.info('uitest: testMessageDigestComputation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SegmentationAsync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SegmentationAsync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SegmentationAsyncSuccess')); + console.info('uitest: testMessageDigestComputation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息摘要计算(ArkTS 摘要算法同步方式) + */ + it('testMessageDigestComputation002', 0, async () => { + console.info('uitest: testMessageDigestComputation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SegmentationSync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SegmentationSync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SegmentationSyncSuccess')); + console.info('uitest: testMessageDigestComputation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息摘要计算(ArkTS 分段摘要算法await方式) + */ + it('testMessageDigestComputation003', 0, async () => { + console.info('uitest: testMessageDigestComputation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SingleTimeAsync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SingleTimeAsync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SingleTimeAsyncSuccess')); + console.info('uitest: testMessageDigestComputation003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息摘要计算(ArkTS 分段摘要算法同步方式) + */ + it('testMessageDigestComputation004', 0, async () => { + console.info('uitest: testMessageDigestComputation004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SingleTimeSync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SingleTimeSync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SingleTimeSyncSuccess')); + console.info('uitest: testMessageDigestComputation004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,消息摘要计算(C/C++ 摘要算法) + */ + it('testMessageDigestComputation005', 0, async () => { + console.info('uitest: testMessageDigestComputation005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SingleTime C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SingleTime C++ Success Result:0')); + console.info('uitest: testMessageDigestComputation005 end'); + }) + + /** + * 点击按钮,消息摘要计算(C/C++ 分段摘要算法) + */ + it('testMessageDigestComputation006', 0, async () => { + console.info('uitest: testMessageDigestComputation006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Segmentation C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Segmentation C++ Success Result:0')); + console.info('uitest: testMessageDigestComputation006 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/MessageDigestComputation/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/ohosTest.md old mode 100755 new mode 100644 index ccbd450e69f07aa9a83207fe4427c60162e39ec5..53df17f13a975ea08a43c3016c5808a08865cab8 --- a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/ohosTest.md @@ -1,13 +1,13 @@ -# 消息摘要计算测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,消息摘要计算(ArkTS 摘要算法await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,消息摘要计算(ArkTS 摘要算法同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,消息摘要计算(ArkTS 分段摘要算法await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,消息摘要计算(ArkTS 分段摘要算法同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,消息摘要计算(C/C++ 摘要算法) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 消息摘要计算测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,消息摘要计算(ArkTS 摘要算法await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,消息摘要计算(ArkTS 摘要算法同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,消息摘要计算(ArkTS 分段摘要算法await方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,消息摘要计算(ArkTS 分段摘要算法同步方式) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,消息摘要计算(C/C++ 摘要算法) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,消息摘要计算(C/C++ 分段摘要算法) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/screenshots/MessageDigestComputation1.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/screenshots/MessageDigestComputation1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/screenshots/MessageDigestComputation2.png b/code/DocsSample/Security/CryptoArchitectureKit/MessageDigestComputation/screenshots/MessageDigestComputation2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/app.json5 old mode 100755 new mode 100644 index 85c53f08856e0bfd9a32c2d4f6b217f332fc1091..5501621fff880e82a2661e43e9debc4bdb600aaa --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/app.json5 @@ -1,25 +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.securerandomnumbergeneration", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.securerandomnumbergeneration", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 8b07fd87d5faa9c9ea1e2abdb94832c493e454f0..3487457a46dffed3da9b3c3ab078e5a68353143e --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SecureRandomNumberGeneration" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SecureRandomNumberGeneration" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md old mode 100755 new mode 100644 index 0f0d3f0930b9739bf158cee03c2f2ea2f1ada47c..f5027645fa06cbd320188a6e86d99187e1f994f2 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md @@ -1,69 +1,69 @@ -# 安全随机数生成 - -### 介绍 - -随机数主要用于临时会话密钥生成和非对称加密算法密钥生成等场景。在加解密场景中,安全随机数生成器需要具备随机性,不可预测性,与不可重现性。当前系统生成的随机数满足密码学安全伪随机性要求 - -本示例主要展示了安全随机数生成(await、同步)场景 。该工程中展示的代码详细描述可查如下链接。 - -- [安全随机数生成](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-random-number.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例SecureRandomNumberGeneration.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 安全随机数生成示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── SecureRandomNumberGeneration.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 安全随机数生成 + +### 介绍 + +随机数主要用于临时会话密钥生成和非对称加密算法密钥生成等场景。在加解密场景中,安全随机数生成器需要具备随机性,不可预测性,与不可重现性。当前系统生成的随机数满足密码学安全伪随机性要求 + +本示例主要展示了安全随机数生成(await、同步)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [安全随机数生成](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-random-number.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SecureRandomNumberGeneration.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 安全随机数生成示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SecureRandomNumberGeneration.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets old mode 100755 new mode 100644 index a7521c6d1f12458256ee9a1bc6bb1c6e2b78da32..cc40b528c8b63a31c7097cb52cf98e216eeddc80 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function secureRandomNumberGenerationTest() { - describe('secureRandomNumberGenerationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,安全随机数生成,使用await返回结果 - */ - it('testSecureRandomNumberGeneration001', 0, async () => { - console.info('uitest: testSecureRandomNumberGeneration001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call Async')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AsyncSuccess')); - console.info('uitest: testSecureRandomNumberGeneration001 end'); - }) - - /** - * 点击按钮,安全随机数生成,同步返回结果 - */ - it('testSecureRandomNumberGeneration002', 0, async () => { - console.info('uitest: testSecureRandomNumberGeneration002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call Sync')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SyncSuccess')); - console.info('uitest: testSecureRandomNumberGeneration002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function secureRandomNumberGenerationTest() { + describe('secureRandomNumberGenerationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,安全随机数生成,使用await返回结果 + */ + it('testSecureRandomNumberGeneration001', 0, async () => { + console.info('uitest: testSecureRandomNumberGeneration001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AsyncSuccess')); + console.info('uitest: testSecureRandomNumberGeneration001 end'); + }) + + /** + * 点击按钮,安全随机数生成,同步返回结果 + */ + it('testSecureRandomNumberGeneration002', 0, async () => { + console.info('uitest: testSecureRandomNumberGeneration002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SyncSuccess')); + console.info('uitest: testSecureRandomNumberGeneration002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/ohosTest.md old mode 100755 new mode 100644 index 182fbe1d70093da15dbfebab0e27034028e8c06d..7437e0328f2411cb658056ee7508646ea3345292 --- a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/ohosTest.md @@ -1,9 +1,9 @@ -# 安全随机数生成测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,安全随机数生成,使用await返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 安全随机数生成测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,安全随机数生成,使用await返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,安全随机数生成,同步返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration1.png b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration2.png b/code/DocsSample/Security/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/app.json5 old mode 100755 new mode 100644 index ec1418b55f93e9d5512e7e431a7ff8303aea4a5f..56d39e636c9058c5a8f86e67597abe34a8695cce --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/app.json5 @@ -1,25 +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.signingsignatureverification", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.signingsignatureverification", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 4b213a8f306ce55aaef488a9f93b9a4017ae7bb4..7d9ab06441ad9ced1e145a29bc035572fbcd6ef4 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SigningSignatureVerification" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SigningSignatureVerification" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md old mode 100755 new mode 100644 index 3afb9e5c179f635ad95024a4775bf34fa86cefe3..15c458007261d85bbd5e70915beb511a63a3d1ef --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md @@ -1,89 +1,89 @@ -# 签名验签(C/C++) - -### 介绍 - -当需要判断接收的数据是否被篡改、数据是否为指定对象发送的数据时,可以使用签名验签操作。接下来将说明系统目前支持的算法及其对应的规格。 - -本示例主要展示了签名验签(C/C++)的多种场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用RSA密钥对(PKCS1模式)验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-ndk.md) -- [使用RSA密钥对(PKCS1模式)签名恢复(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-recover-pkcs1-ndk.md) -- [使用RSA密钥对分段验签(PKCS1模式)(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-by-segment-ndk.md) -- [使用RSA密钥对验签(PSS模式)(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pss-ndk.md) -- [使用ECDSA密钥对验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-ecdsa-sign-sig-verify-ndk.md) -- [使用SM2密钥对验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-sign-sig-verify-pkcs1-ndk.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例SigningSignatureVerification.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── cpp - │ │ ├── types - │ │ | ├── libentry - │ │ | ├── index.d.ts - │ │ | ├── oh-package.json5 - │ │ | ├── project - │ │ | ├── ecdsa_signature_verification.cpp - │ │ | ├── rsa_pkcs1_segment_signature.cpp - │ │ | ├── rsa_pkcs1_signature_restoration.cpp - │ │ | ├── rsa_pkcs1_signature_validator.cpp - │ │ | ├── rsa_pss_verification_tool.cpp - │ │ | ├── signing_signature_verification.h - │ │ | ├── sm2_signature_verification.cpp - │ │ ├── CMakeList.txt - │ │ ├── napi_init.cpp - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 签名验签(C/C++)示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── SigningSignatureVerification.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 签名验签(C/C++) + +### 介绍 + +当需要判断接收的数据是否被篡改、数据是否为指定对象发送的数据时,可以使用签名验签操作。接下来将说明系统目前支持的算法及其对应的规格。 + +本示例主要展示了签名验签(C/C++)的多种场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用RSA密钥对(PKCS1模式)验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-ndk.md) +- [使用RSA密钥对(PKCS1模式)签名恢复(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-recover-pkcs1-ndk.md) +- [使用RSA密钥对分段验签(PKCS1模式)(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-by-segment-ndk.md) +- [使用RSA密钥对验签(PSS模式)(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pss-ndk.md) +- [使用ECDSA密钥对验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-ecdsa-sign-sig-verify-ndk.md) +- [使用SM2密钥对验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-sign-sig-verify-pkcs1-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SigningSignatureVerification.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── ecdsa_signature_verification.cpp + │ │ | ├── rsa_pkcs1_segment_signature.cpp + │ │ | ├── rsa_pkcs1_signature_restoration.cpp + │ │ | ├── rsa_pkcs1_signature_validator.cpp + │ │ | ├── rsa_pss_verification_tool.cpp + │ │ | ├── signing_signature_verification.h + │ │ | ├── sm2_signature_verification.cpp + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 签名验签(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SigningSignatureVerification.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 old mode 100755 new mode 100644 index e736e6631f681b568494dedcb5fd036a96ec56fc..d4c9b145c65c003fbfe6dc9ca6ebee7ad7d14b28 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ], - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ], + } + }, + "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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 41f8f6ab752edfc14d896e3b3a3323665885f525..f3347fe669e9f04c7978387ee510f7e9c23733b9 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt @@ -1,16 +1,16 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(MyApplication) - -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 - ${NATIVERENDER_ROOT_PATH}/types/project) - -add_library(entry SHARED napi_init.cpp types/project/rsa_pkcs1_segment_signature.cpp types/project/rsa_pkcs1_signature_restoration.cpp types/project/rsa_pkcs1_signature_validator.cpp types/project/rsa_pss_verification_tool.cpp types/project/ecdsa_signature_verification.cpp types/project/sm2_signature_verification.cpp) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(MyApplication) + +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 + ${NATIVERENDER_ROOT_PATH}/types/project) + +add_library(entry SHARED napi_init.cpp types/project/rsa_pkcs1_segment_signature.cpp types/project/rsa_pkcs1_signature_restoration.cpp types/project/rsa_pkcs1_signature_validator.cpp types/project/rsa_pss_verification_tool.cpp types/project/ecdsa_signature_verification.cpp types/project/sm2_signature_verification.cpp) target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 5226e5c527744bf4386aacbb68753e9fb7a31253..b243c28c087a823ef07756a5bd4d971fc8bb61b8 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp @@ -1,88 +1,88 @@ -/* - * 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 "types/project/signing_signature_verification.h" -#include - -static napi_value TestRsaSignatureSeg(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_get_boolean(env, DoTestRsaSignatureSeg(), &ret); - return ret; -} - -static napi_value TestRsaSignature(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_get_boolean(env, DoTestRsaSignature(), &ret); - return ret; -} - -static napi_value TestRsaSignatureRecover(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_create_int32(env, DoTestRsaSignatureRecover(), &ret); - return ret; -} - -static napi_value TestRsaPssSignatureSeg(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_get_boolean(env, DoTestRsaPssSignatureSeg(), &ret); - return ret; -} - -static napi_value TestEcdsaSignature(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_get_boolean(env, DoTestEcdsaSignature(), &ret); - return ret; -} - -static napi_value TestSm2Signature(napi_env env, napi_callback_info info) -{ - napi_value ret; - napi_get_boolean(env, DoTestSm2Signature(), &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"signatureSeg", nullptr, TestRsaSignatureSeg, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"signature", nullptr, TestRsaSignature, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"signatureRecover", nullptr, TestRsaSignatureRecover, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"pssSignatureSeg", nullptr, TestRsaPssSignatureSeg, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"ecdsaSignature", nullptr, TestEcdsaSignature, nullptr, nullptr, nullptr, napi_default, nullptr}, - {"sm2Signature", nullptr, TestSm2Signature, 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); } +/* + * 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 "types/project/signing_signature_verification.h" +#include + +static napi_value TestRsaSignatureSeg(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestRsaSignatureSeg(), &ret); + return ret; +} + +static napi_value TestRsaSignature(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestRsaSignature(), &ret); + return ret; +} + +static napi_value TestRsaSignatureRecover(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, DoTestRsaSignatureRecover(), &ret); + return ret; +} + +static napi_value TestRsaPssSignatureSeg(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestRsaPssSignatureSeg(), &ret); + return ret; +} + +static napi_value TestEcdsaSignature(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestEcdsaSignature(), &ret); + return ret; +} + +static napi_value TestSm2Signature(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestSm2Signature(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"signatureSeg", nullptr, TestRsaSignatureSeg, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"signature", nullptr, TestRsaSignature, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"signatureRecover", nullptr, TestRsaSignatureRecover, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"pssSignatureSeg", nullptr, TestRsaPssSignatureSeg, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"ecdsaSignature", nullptr, TestEcdsaSignature, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"sm2Signature", nullptr, TestSm2Signature, 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index b2764719ca27d61cd0fa7725233179a26f5fa8ba..c14cf00cf4dfef8b005f46397d39ef630986d84e --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,26 +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. - */ - -export const signatureSeg: () => number; - -export const signature: () => number; - -export const signatureRecover: () => number; - -export const pssSignatureSeg: () => number; - -export const ecdsaSignature: () => number; - +/* + * 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 signatureSeg: () => number; + +export const signature: () => number; + +export const signatureRecover: () => number; + +export const pssSignatureSeg: () => number; + +export const ecdsaSignature: () => number; + export const sm2Signature: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp old mode 100755 new mode 100644 index 2eac147f35e13877318a4b3cc060772c50ddf075..d7c46740660e3fdd39233e62e547c2f12ba14595 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp @@ -1,79 +1,79 @@ -/* - * 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 "signing_signature_verification.h" - -bool DoTestEcdsaSignature() -{ - OH_CryptoAsymKeyGenerator *keyCtx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_CryptoVerify *verify = nullptr; - - uint8_t plainText[] = {0xe4, 0x2b, 0xcc, 0x08, 0x11, 0x79, 0x16, 0x1b, - 0x35, 0x7f, 0xb3, 0xaf, 0x40, 0x3b, 0x3f, 0x7c}; - Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; - - uint8_t pubKeyText[] = {0x30, 0x39, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, - 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x22, 0x00, 0x03, 0x4d, 0xe4, 0xbb, - 0x11, 0x10, 0x1a, 0xd2, 0x05, 0x74, 0xf1, 0x0b, 0xb4, 0x75, 0x57, 0xf4, 0x3e, 0x55, 0x14, - 0x17, 0x05, 0x4a, 0xb2, 0xfb, 0x8c, 0x84, 0x64, 0x38, 0x02, 0xa0, 0x2a, 0xa6, 0xf0}; - - Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; - - uint8_t signText[] = {0x30, 0x44, 0x02, 0x20, 0x21, 0x89, 0x99, 0xb1, 0x56, 0x4e, 0x3a, 0x2c, 0x16, 0x08, - 0xb5, 0x8a, 0x06, 0x6f, 0x67, 0x47, 0x1b, 0x04, 0x18, 0x7d, 0x53, 0x2d, 0xba, 0x00, - 0x38, 0xd9, 0xe3, 0xe7, 0x8c, 0xcf, 0x76, 0x83, 0x02, 0x20, 0x13, 0x54, 0x84, 0x9d, - 0x73, 0x40, 0xc3, 0x92, 0x66, 0xdc, 0x3e, 0xc9, 0xf1, 0x4c, 0x33, 0x84, 0x2a, 0x76, - 0xaf, 0xc6, 0x61, 0x84, 0x5c, 0xae, 0x4b, 0x0d, 0x3c, 0xb0, 0xc8, 0x04, 0x89, 0x71}; - - Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; - - OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; - // keypair - ret = OH_CryptoAsymKeyGenerator_Create((const char *)"ECC256", &keyCtx); - if (ret != CRYPTO_SUCCESS) { - return false; - } - ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_DER, &keyBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - // verify - ret = OH_CryptoVerify_Create((const char *)"ECC|SHA256", &verify); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - ret = OH_CryptoVerify_Init(verify, pubKey); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); - if (ret != true) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - OH_CryptoKeyPair_Destroy(keyPair); - return res; -} +/* + * 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 "signing_signature_verification.h" + +bool DoTestEcdsaSignature() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = {0xe4, 0x2b, 0xcc, 0x08, 0x11, 0x79, 0x16, 0x1b, + 0x35, 0x7f, 0xb3, 0xaf, 0x40, 0x3b, 0x3f, 0x7c}; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = {0x30, 0x39, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, + 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x22, 0x00, 0x03, 0x4d, 0xe4, 0xbb, + 0x11, 0x10, 0x1a, 0xd2, 0x05, 0x74, 0xf1, 0x0b, 0xb4, 0x75, 0x57, 0xf4, 0x3e, 0x55, 0x14, + 0x17, 0x05, 0x4a, 0xb2, 0xfb, 0x8c, 0x84, 0x64, 0x38, 0x02, 0xa0, 0x2a, 0xa6, 0xf0}; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = {0x30, 0x44, 0x02, 0x20, 0x21, 0x89, 0x99, 0xb1, 0x56, 0x4e, 0x3a, 0x2c, 0x16, 0x08, + 0xb5, 0x8a, 0x06, 0x6f, 0x67, 0x47, 0x1b, 0x04, 0x18, 0x7d, 0x53, 0x2d, 0xba, 0x00, + 0x38, 0xd9, 0xe3, 0xe7, 0x8c, 0xcf, 0x76, 0x83, 0x02, 0x20, 0x13, 0x54, 0x84, 0x9d, + 0x73, 0x40, 0xc3, 0x92, 0x66, 0xdc, 0x3e, 0xc9, 0xf1, 0x4c, 0x33, 0x84, 0x2a, 0x76, + 0xaf, 0xc6, 0x61, 0x84, 0x5c, 0xae, 0x4b, 0x0d, 0x3c, 0xb0, 0xc8, 0x04, 0x89, 0x71}; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + // keypair + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"ECC256", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_DER, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"ECC|SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (ret != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp old mode 100755 new mode 100644 index ac9e4b344209915b2a35209979e78a31583c68db..5f02098110bc5dd052286689fed9ebb75c29d6af --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp @@ -1,121 +1,121 @@ -/* - * 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 "signing_signature_verification.h" - -static constexpr int INT_64 = 64; -bool DoTestRsaSignatureSeg() -{ - OH_CryptoAsymKeyGenerator *keyCtx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_CryptoVerify *verify = nullptr; - - uint8_t plainText[] = { - 0x43, 0x31, 0x7d, 0xb5, 0x85, 0x2e, 0xd4, 0xef, 0x08, 0x7a, 0x17, 0x96, 0xbc, 0x7c, 0x8f, 0x80, - 0x8c, 0xa7, 0x63, 0x7f, 0x26, 0x89, 0x8f, 0xf0, 0xfa, 0xa7, 0x51, 0xbd, 0x9c, 0x69, 0x17, 0xf3, - 0xd1, 0xb5, 0xc7, 0x12, 0xbf, 0xcf, 0x91, 0x25, 0x82, 0x23, 0x6b, 0xd6, 0x64, 0x52, 0x77, 0x93, - 0x01, 0x9d, 0x70, 0xa3, 0xf4, 0x92, 0x16, 0xec, 0x3f, 0xa7, 0x3c, 0x83, 0x8d, 0x40, 0x41, 0xfc, - }; - Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; - - uint8_t pubKeyText[] = { - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, - 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, - 0x6f, 0x47, 0x42, 0x41, 0x4d, 0x78, 0x63, 0x44, 0x4d, 0x6f, 0x61, 0x59, 0x52, 0x58, 0x6f, 0x78, 0x65, 0x69, - 0x33, 0x49, 0x6d, 0x33, 0x33, 0x78, 0x4a, 0x76, 0x61, 0x73, 0x63, 0x43, 0x62, 0x77, 0x31, 0x6f, 0x73, 0x63, - 0x32, 0x56, 0x56, 0x69, 0x47, 0x6a, 0x56, 0x47, 0x47, 0x4a, 0x37, 0x6c, 0x75, 0x4e, 0x41, 0x58, 0x6b, 0x6a, - 0x73, 0x56, 0x46, 0x64, 0x35, 0x0a, 0x58, 0x37, 0x4c, 0x4d, 0x6c, 0x46, 0x34, 0x63, 0x35, 0x5a, 0x75, 0x59, - 0x2f, 0x61, 0x69, 0x57, 0x77, 0x70, 0x54, 0x69, 0x63, 0x62, 0x67, 0x49, 0x33, 0x43, 0x66, 0x50, 0x6f, 0x32, - 0x6a, 0x6c, 0x52, 0x74, 0x67, 0x41, 0x46, 0x6b, 0x44, 0x71, 0x7a, 0x4b, 0x53, 0x46, 0x62, 0x46, 0x47, 0x51, - 0x6b, 0x43, 0x6e, 0x64, 0x63, 0x2b, 0x54, 0x59, 0x6b, 0x5a, 0x42, 0x32, 0x70, 0x45, 0x6f, 0x72, 0x0a, 0x7a, - 0x73, 0x61, 0x56, 0x58, 0x77, 0x5a, 0x47, 0x45, 0x34, 0x41, 0x43, 0x70, 0x59, 0x35, 0x79, 0x65, 0x66, 0x49, - 0x44, 0x6c, 0x45, 0x57, 0x49, 0x51, 0x4f, 0x6a, 0x59, 0x4b, 0x2f, 0x6c, 0x58, 0x71, 0x7a, 0x48, 0x47, 0x69, - 0x4f, 0x69, 0x32, 0x75, 0x4a, 0x45, 0x75, 0x44, 0x43, 0x50, 0x6a, 0x51, 0x64, 0x6a, 0x54, 0x41, 0x67, 0x4d, - 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, - 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, - }; - - Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; - - uint8_t signText[] = { - 0x68, 0x2f, 0x3b, 0xe6, 0xa6, 0x5c, 0xb8, 0x60, 0xd4, 0xe1, 0x64, 0xa7, 0xd8, 0x0c, 0x9c, 0x89, - 0x39, 0xb4, 0xf0, 0xb7, 0xad, 0xb5, 0x8a, 0x71, 0x04, 0xf1, 0xa5, 0x63, 0xdd, 0x32, 0x6a, 0x44, - 0xeb, 0xff, 0xb7, 0xe6, 0x85, 0xe5, 0xa5, 0x55, 0x5d, 0x5b, 0x28, 0x53, 0x63, 0xe4, 0xb3, 0xb9, - 0xa8, 0x70, 0xc8, 0x8f, 0xcd, 0x21, 0x8d, 0xe6, 0x1f, 0xe5, 0x78, 0x34, 0xd3, 0x45, 0x0c, 0x9c, - 0x7a, 0x22, 0x1b, 0x63, 0x55, 0xca, 0x14, 0xa5, 0x0c, 0x7a, 0x40, 0x8e, 0xa1, 0x14, 0x78, 0xa1, - 0xf1, 0x36, 0x78, 0xbd, 0xba, 0x37, 0x3b, 0x5b, 0xb0, 0x8e, 0xb3, 0x4a, 0x9b, 0x1b, 0x0c, 0xfa, - 0xfa, 0xc7, 0x9f, 0xb1, 0x35, 0x48, 0x82, 0x73, 0xf8, 0x6b, 0xd4, 0x76, 0x33, 0x5c, 0xed, 0x9c, - 0xd8, 0x4b, 0xc9, 0x92, 0xa0, 0x3f, 0x6e, 0xba, 0x78, 0x2e, 0x80, 0x78, 0x1e, 0x74, 0xa0, 0x47, - }; - - Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; - - // keypair - OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; - ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); - if (ret != CRYPTO_SUCCESS) { - return false; - } - ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - // verify - ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256", &verify); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - int blockSize = 20; - int cntS = INT_64 / blockSize; - int remS = INT_64 % blockSize; - ret = OH_CryptoVerify_Init(verify, pubKey); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - for (int i = 0; i < cntS; i++) { - msgBlob.len = blockSize; - ret = OH_CryptoVerify_Update(verify, (Crypto_DataBlob *)&msgBlob); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - msgBlob.data += blockSize; - } - bool res = false; - if (remS > 0) { - msgBlob.len = remS; - res = OH_CryptoVerify_Final(verify, (Crypto_DataBlob *)&msgBlob, (Crypto_DataBlob *)&signBlob); - if (res != true) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - } - - msgBlob.data -= INT_64 - remS; - msgBlob.len = INT_64; - - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - OH_CryptoKeyPair_Destroy(keyPair); - return res; +/* + * 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 "signing_signature_verification.h" + +static constexpr int INT_64 = 64; +bool DoTestRsaSignatureSeg() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x43, 0x31, 0x7d, 0xb5, 0x85, 0x2e, 0xd4, 0xef, 0x08, 0x7a, 0x17, 0x96, 0xbc, 0x7c, 0x8f, 0x80, + 0x8c, 0xa7, 0x63, 0x7f, 0x26, 0x89, 0x8f, 0xf0, 0xfa, 0xa7, 0x51, 0xbd, 0x9c, 0x69, 0x17, 0xf3, + 0xd1, 0xb5, 0xc7, 0x12, 0xbf, 0xcf, 0x91, 0x25, 0x82, 0x23, 0x6b, 0xd6, 0x64, 0x52, 0x77, 0x93, + 0x01, 0x9d, 0x70, 0xa3, 0xf4, 0x92, 0x16, 0xec, 0x3f, 0xa7, 0x3c, 0x83, 0x8d, 0x40, 0x41, 0xfc, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, + 0x6f, 0x47, 0x42, 0x41, 0x4d, 0x78, 0x63, 0x44, 0x4d, 0x6f, 0x61, 0x59, 0x52, 0x58, 0x6f, 0x78, 0x65, 0x69, + 0x33, 0x49, 0x6d, 0x33, 0x33, 0x78, 0x4a, 0x76, 0x61, 0x73, 0x63, 0x43, 0x62, 0x77, 0x31, 0x6f, 0x73, 0x63, + 0x32, 0x56, 0x56, 0x69, 0x47, 0x6a, 0x56, 0x47, 0x47, 0x4a, 0x37, 0x6c, 0x75, 0x4e, 0x41, 0x58, 0x6b, 0x6a, + 0x73, 0x56, 0x46, 0x64, 0x35, 0x0a, 0x58, 0x37, 0x4c, 0x4d, 0x6c, 0x46, 0x34, 0x63, 0x35, 0x5a, 0x75, 0x59, + 0x2f, 0x61, 0x69, 0x57, 0x77, 0x70, 0x54, 0x69, 0x63, 0x62, 0x67, 0x49, 0x33, 0x43, 0x66, 0x50, 0x6f, 0x32, + 0x6a, 0x6c, 0x52, 0x74, 0x67, 0x41, 0x46, 0x6b, 0x44, 0x71, 0x7a, 0x4b, 0x53, 0x46, 0x62, 0x46, 0x47, 0x51, + 0x6b, 0x43, 0x6e, 0x64, 0x63, 0x2b, 0x54, 0x59, 0x6b, 0x5a, 0x42, 0x32, 0x70, 0x45, 0x6f, 0x72, 0x0a, 0x7a, + 0x73, 0x61, 0x56, 0x58, 0x77, 0x5a, 0x47, 0x45, 0x34, 0x41, 0x43, 0x70, 0x59, 0x35, 0x79, 0x65, 0x66, 0x49, + 0x44, 0x6c, 0x45, 0x57, 0x49, 0x51, 0x4f, 0x6a, 0x59, 0x4b, 0x2f, 0x6c, 0x58, 0x71, 0x7a, 0x48, 0x47, 0x69, + 0x4f, 0x69, 0x32, 0x75, 0x4a, 0x45, 0x75, 0x44, 0x43, 0x50, 0x6a, 0x51, 0x64, 0x6a, 0x54, 0x41, 0x67, 0x4d, + 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, + 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x68, 0x2f, 0x3b, 0xe6, 0xa6, 0x5c, 0xb8, 0x60, 0xd4, 0xe1, 0x64, 0xa7, 0xd8, 0x0c, 0x9c, 0x89, + 0x39, 0xb4, 0xf0, 0xb7, 0xad, 0xb5, 0x8a, 0x71, 0x04, 0xf1, 0xa5, 0x63, 0xdd, 0x32, 0x6a, 0x44, + 0xeb, 0xff, 0xb7, 0xe6, 0x85, 0xe5, 0xa5, 0x55, 0x5d, 0x5b, 0x28, 0x53, 0x63, 0xe4, 0xb3, 0xb9, + 0xa8, 0x70, 0xc8, 0x8f, 0xcd, 0x21, 0x8d, 0xe6, 0x1f, 0xe5, 0x78, 0x34, 0xd3, 0x45, 0x0c, 0x9c, + 0x7a, 0x22, 0x1b, 0x63, 0x55, 0xca, 0x14, 0xa5, 0x0c, 0x7a, 0x40, 0x8e, 0xa1, 0x14, 0x78, 0xa1, + 0xf1, 0x36, 0x78, 0xbd, 0xba, 0x37, 0x3b, 0x5b, 0xb0, 0x8e, 0xb3, 0x4a, 0x9b, 0x1b, 0x0c, 0xfa, + 0xfa, 0xc7, 0x9f, 0xb1, 0x35, 0x48, 0x82, 0x73, 0xf8, 0x6b, 0xd4, 0x76, 0x33, 0x5c, 0xed, 0x9c, + 0xd8, 0x4b, 0xc9, 0x92, 0xa0, 0x3f, 0x6e, 0xba, 0x78, 0x2e, 0x80, 0x78, 0x1e, 0x74, 0xa0, 0x47, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + int blockSize = 20; + int cntS = INT_64 / blockSize; + int remS = INT_64 % blockSize; + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + for (int i = 0; i < cntS; i++) { + msgBlob.len = blockSize; + ret = OH_CryptoVerify_Update(verify, (Crypto_DataBlob *)&msgBlob); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + msgBlob.data += blockSize; + } + bool res = false; + if (remS > 0) { + msgBlob.len = remS; + res = OH_CryptoVerify_Final(verify, (Crypto_DataBlob *)&msgBlob, (Crypto_DataBlob *)&signBlob); + if (res != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + } + + msgBlob.data -= INT_64 - remS; + msgBlob.len = INT_64; + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp old mode 100755 new mode 100644 index 441124e947129a987ce939cf9cbb2dccd369b27c..34fe316b9b252356b846c10cce9159ffe0a817d5 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp @@ -1,98 +1,98 @@ -/* - * 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 "signing_signature_verification.h" - -OH_Crypto_ErrCode DoTestRsaSignatureRecover() -{ - OH_CryptoAsymKeyGenerator *keyCtx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_CryptoVerify *verify = nullptr; - - uint8_t plainText[] = {0xc4, 0xa5, 0xe5, 0x45, 0xee, 0x71, 0x5e, 0x3b, 0x24, 0x1d, 0x7e, - 0x62, 0xd6, 0x6b, 0xab, 0x98, 0x88, 0x0f, 0xaf, 0x1e, 0x96, 0xa0, - 0x6c, 0xa5, 0x0d, 0x29, 0xfd, 0xcc, 0xef, 0xf6, 0x2b, 0x92}; - Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; - - uint8_t pubKeyText[] = { - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, - 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, - 0x6f, 0x47, 0x42, 0x41, 0x4b, 0x72, 0x55, 0x74, 0x74, 0x64, 0x76, 0x73, 0x2b, 0x62, 0x6e, 0x4d, 0x2f, 0x6f, - 0x4e, 0x75, 0x39, 0x45, 0x42, 0x78, 0x35, 0x64, 0x49, 0x6d, 0x61, 0x70, 0x52, 0x67, 0x4d, 0x6a, 0x4b, 0x41, - 0x38, 0x51, 0x48, 0x4b, 0x61, 0x75, 0x2f, 0x6c, 0x58, 0x50, 0x50, 0x68, 0x76, 0x38, 0x30, 0x69, 0x59, 0x4c, - 0x46, 0x2b, 0x79, 0x35, 0x35, 0x0a, 0x6d, 0x42, 0x2f, 0x38, 0x2b, 0x4b, 0x68, 0x34, 0x34, 0x43, 0x2b, 0x5a, - 0x76, 0x6f, 0x78, 0x5a, 0x66, 0x38, 0x78, 0x34, 0x6e, 0x78, 0x6f, 0x71, 0x76, 0x4f, 0x6f, 0x73, 0x32, 0x44, - 0x55, 0x69, 0x51, 0x44, 0x4f, 0x4a, 0x35, 0x63, 0x57, 0x68, 0x5a, 0x62, 0x4d, 0x71, 0x4d, 0x42, 0x71, 0x62, - 0x39, 0x30, 0x4e, 0x39, 0x63, 0x2f, 0x44, 0x51, 0x67, 0x39, 0x34, 0x63, 0x52, 0x7a, 0x35, 0x66, 0x0a, 0x68, - 0x55, 0x66, 0x6d, 0x66, 0x6d, 0x54, 0x41, 0x46, 0x6a, 0x5a, 0x53, 0x33, 0x78, 0x6c, 0x78, 0x77, 0x6e, 0x50, - 0x77, 0x66, 0x66, 0x39, 0x71, 0x44, 0x79, 0x4c, 0x63, 0x5a, 0x55, 0x6b, 0x6e, 0x64, 0x43, 0x30, 0x50, 0x77, - 0x72, 0x6c, 0x38, 0x72, 0x70, 0x4b, 0x7a, 0x50, 0x47, 0x63, 0x71, 0x4e, 0x67, 0x33, 0x5a, 0x41, 0x67, 0x4d, - 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, - 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, - }; - - Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; - - uint8_t signText[] = { - 0x1f, 0xe3, 0xcf, 0x8d, 0x94, 0xb4, 0xa0, 0x9e, 0xf1, 0x0c, 0x38, 0x59, 0xcb, 0x5b, 0x89, 0xc9, - 0x66, 0x8b, 0xfd, 0x8d, 0x1e, 0x37, 0xfa, 0x5e, 0x1b, 0xb1, 0x51, 0x07, 0xf1, 0xb0, 0x7d, 0x18, - 0x2d, 0x82, 0x2a, 0x04, 0xa4, 0x4e, 0x94, 0x7e, 0x76, 0xb8, 0xa4, 0x78, 0x90, 0x2f, 0x43, 0x1d, - 0x95, 0x80, 0xd7, 0xb3, 0x46, 0x4d, 0x58, 0x4b, 0xcd, 0x1f, 0x1d, 0xb3, 0x1f, 0x6b, 0x15, 0xd8, - 0x33, 0x51, 0x1d, 0x36, 0x12, 0x39, 0x92, 0xb4, 0x4d, 0xe2, 0x89, 0x26, 0x01, 0xe9, 0x1f, 0xc0, - 0x9c, 0x7c, 0xd8, 0xeb, 0x47, 0xff, 0xfb, 0x5d, 0x98, 0x9a, 0x02, 0x6a, 0x16, 0x37, 0xb1, 0xf5, - 0x08, 0x4d, 0xd7, 0xa0, 0xf2, 0x9e, 0xbe, 0x4b, 0x54, 0x77, 0x94, 0x95, 0x4b, 0x97, 0x10, 0x22, - 0x49, 0xa5, 0x2e, 0x05, 0x86, 0xfd, 0x6f, 0x9a, 0x40, 0xe6, 0x43, 0xab, 0xc5, 0xbc, 0xac, 0x21, - }; - - Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; - - // keypair - OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; - ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); - if (ret != CRYPTO_SUCCESS) { - return ret; - } - ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return ret; - } - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - // verify - ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256|Recover", &verify); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return ret; - } - ret = OH_CryptoVerify_Init(verify, pubKey); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return ret; - } - Crypto_DataBlob rawSignData = {.data = nullptr, .len = 0}; - ret = OH_CryptoVerify_Recover(verify, (Crypto_DataBlob *)&signBlob, &rawSignData); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return ret; - } - - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - OH_CryptoKeyPair_Destroy(keyPair); - return ret; +/* + * 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 "signing_signature_verification.h" + +OH_Crypto_ErrCode DoTestRsaSignatureRecover() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = {0xc4, 0xa5, 0xe5, 0x45, 0xee, 0x71, 0x5e, 0x3b, 0x24, 0x1d, 0x7e, + 0x62, 0xd6, 0x6b, 0xab, 0x98, 0x88, 0x0f, 0xaf, 0x1e, 0x96, 0xa0, + 0x6c, 0xa5, 0x0d, 0x29, 0xfd, 0xcc, 0xef, 0xf6, 0x2b, 0x92}; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, + 0x6f, 0x47, 0x42, 0x41, 0x4b, 0x72, 0x55, 0x74, 0x74, 0x64, 0x76, 0x73, 0x2b, 0x62, 0x6e, 0x4d, 0x2f, 0x6f, + 0x4e, 0x75, 0x39, 0x45, 0x42, 0x78, 0x35, 0x64, 0x49, 0x6d, 0x61, 0x70, 0x52, 0x67, 0x4d, 0x6a, 0x4b, 0x41, + 0x38, 0x51, 0x48, 0x4b, 0x61, 0x75, 0x2f, 0x6c, 0x58, 0x50, 0x50, 0x68, 0x76, 0x38, 0x30, 0x69, 0x59, 0x4c, + 0x46, 0x2b, 0x79, 0x35, 0x35, 0x0a, 0x6d, 0x42, 0x2f, 0x38, 0x2b, 0x4b, 0x68, 0x34, 0x34, 0x43, 0x2b, 0x5a, + 0x76, 0x6f, 0x78, 0x5a, 0x66, 0x38, 0x78, 0x34, 0x6e, 0x78, 0x6f, 0x71, 0x76, 0x4f, 0x6f, 0x73, 0x32, 0x44, + 0x55, 0x69, 0x51, 0x44, 0x4f, 0x4a, 0x35, 0x63, 0x57, 0x68, 0x5a, 0x62, 0x4d, 0x71, 0x4d, 0x42, 0x71, 0x62, + 0x39, 0x30, 0x4e, 0x39, 0x63, 0x2f, 0x44, 0x51, 0x67, 0x39, 0x34, 0x63, 0x52, 0x7a, 0x35, 0x66, 0x0a, 0x68, + 0x55, 0x66, 0x6d, 0x66, 0x6d, 0x54, 0x41, 0x46, 0x6a, 0x5a, 0x53, 0x33, 0x78, 0x6c, 0x78, 0x77, 0x6e, 0x50, + 0x77, 0x66, 0x66, 0x39, 0x71, 0x44, 0x79, 0x4c, 0x63, 0x5a, 0x55, 0x6b, 0x6e, 0x64, 0x43, 0x30, 0x50, 0x77, + 0x72, 0x6c, 0x38, 0x72, 0x70, 0x4b, 0x7a, 0x50, 0x47, 0x63, 0x71, 0x4e, 0x67, 0x33, 0x5a, 0x41, 0x67, 0x4d, + 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, + 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x1f, 0xe3, 0xcf, 0x8d, 0x94, 0xb4, 0xa0, 0x9e, 0xf1, 0x0c, 0x38, 0x59, 0xcb, 0x5b, 0x89, 0xc9, + 0x66, 0x8b, 0xfd, 0x8d, 0x1e, 0x37, 0xfa, 0x5e, 0x1b, 0xb1, 0x51, 0x07, 0xf1, 0xb0, 0x7d, 0x18, + 0x2d, 0x82, 0x2a, 0x04, 0xa4, 0x4e, 0x94, 0x7e, 0x76, 0xb8, 0xa4, 0x78, 0x90, 0x2f, 0x43, 0x1d, + 0x95, 0x80, 0xd7, 0xb3, 0x46, 0x4d, 0x58, 0x4b, 0xcd, 0x1f, 0x1d, 0xb3, 0x1f, 0x6b, 0x15, 0xd8, + 0x33, 0x51, 0x1d, 0x36, 0x12, 0x39, 0x92, 0xb4, 0x4d, 0xe2, 0x89, 0x26, 0x01, 0xe9, 0x1f, 0xc0, + 0x9c, 0x7c, 0xd8, 0xeb, 0x47, 0xff, 0xfb, 0x5d, 0x98, 0x9a, 0x02, 0x6a, 0x16, 0x37, 0xb1, 0xf5, + 0x08, 0x4d, 0xd7, 0xa0, 0xf2, 0x9e, 0xbe, 0x4b, 0x54, 0x77, 0x94, 0x95, 0x4b, 0x97, 0x10, 0x22, + 0x49, 0xa5, 0x2e, 0x05, 0x86, 0xfd, 0x6f, 0x9a, 0x40, 0xe6, 0x43, 0xab, 0xc5, 0xbc, 0xac, 0x21, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256|Recover", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + Crypto_DataBlob rawSignData = {.data = nullptr, .len = 0}; + ret = OH_CryptoVerify_Recover(verify, (Crypto_DataBlob *)&signBlob, &rawSignData); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp old mode 100755 new mode 100644 index cc6e38b761566f83be477017e34eb9f4c97f842c..ab6192f7e512f730abe7355b9f6d683cb1b465bb --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp @@ -1,100 +1,100 @@ -/* - * 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 "signing_signature_verification.h" - -bool DoTestRsaSignature() -{ - OH_CryptoAsymKeyGenerator *keyCtx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_CryptoVerify *verify = nullptr; - - uint8_t plainText[] = { - 0x43, 0x31, 0x7d, 0xb5, 0x85, 0x2e, 0xd4, 0xef, 0x08, 0x7a, 0x17, 0x96, 0xbc, 0x7c, 0x8f, 0x80, - 0x8c, 0xa7, 0x63, 0x7f, 0x26, 0x89, 0x8f, 0xf0, 0xfa, 0xa7, 0x51, 0xbd, 0x9c, 0x69, 0x17, 0xf3, - 0xd1, 0xb5, 0xc7, 0x12, 0xbf, 0xcf, 0x91, 0x25, 0x82, 0x23, 0x6b, 0xd6, 0x64, 0x52, 0x77, 0x93, - 0x01, 0x9d, 0x70, 0xa3, 0xf4, 0x92, 0x16, 0xec, 0x3f, 0xa7, 0x3c, 0x83, 0x8d, 0x40, 0x41, 0xfc, - }; - Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; - - uint8_t pubKeyText[] = { - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, - 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, - 0x6f, 0x47, 0x42, 0x41, 0x4d, 0x78, 0x63, 0x44, 0x4d, 0x6f, 0x61, 0x59, 0x52, 0x58, 0x6f, 0x78, 0x65, 0x69, - 0x33, 0x49, 0x6d, 0x33, 0x33, 0x78, 0x4a, 0x76, 0x61, 0x73, 0x63, 0x43, 0x62, 0x77, 0x31, 0x6f, 0x73, 0x63, - 0x32, 0x56, 0x56, 0x69, 0x47, 0x6a, 0x56, 0x47, 0x47, 0x4a, 0x37, 0x6c, 0x75, 0x4e, 0x41, 0x58, 0x6b, 0x6a, - 0x73, 0x56, 0x46, 0x64, 0x35, 0x0a, 0x58, 0x37, 0x4c, 0x4d, 0x6c, 0x46, 0x34, 0x63, 0x35, 0x5a, 0x75, 0x59, - 0x2f, 0x61, 0x69, 0x57, 0x77, 0x70, 0x54, 0x69, 0x63, 0x62, 0x67, 0x49, 0x33, 0x43, 0x66, 0x50, 0x6f, 0x32, - 0x6a, 0x6c, 0x52, 0x74, 0x67, 0x41, 0x46, 0x6b, 0x44, 0x71, 0x7a, 0x4b, 0x53, 0x46, 0x62, 0x46, 0x47, 0x51, - 0x6b, 0x43, 0x6e, 0x64, 0x63, 0x2b, 0x54, 0x59, 0x6b, 0x5a, 0x42, 0x32, 0x70, 0x45, 0x6f, 0x72, 0x0a, 0x7a, - 0x73, 0x61, 0x56, 0x58, 0x77, 0x5a, 0x47, 0x45, 0x34, 0x41, 0x43, 0x70, 0x59, 0x35, 0x79, 0x65, 0x66, 0x49, - 0x44, 0x6c, 0x45, 0x57, 0x49, 0x51, 0x4f, 0x6a, 0x59, 0x4b, 0x2f, 0x6c, 0x58, 0x71, 0x7a, 0x48, 0x47, 0x69, - 0x4f, 0x69, 0x32, 0x75, 0x4a, 0x45, 0x75, 0x44, 0x43, 0x50, 0x6a, 0x51, 0x64, 0x6a, 0x54, 0x41, 0x67, 0x4d, - 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, - 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, - }; - - Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; - - uint8_t signText[] = { - 0x68, 0x2f, 0x3b, 0xe6, 0xa6, 0x5c, 0xb8, 0x60, 0xd4, 0xe1, 0x64, 0xa7, 0xd8, 0x0c, 0x9c, 0x89, - 0x39, 0xb4, 0xf0, 0xb7, 0xad, 0xb5, 0x8a, 0x71, 0x04, 0xf1, 0xa5, 0x63, 0xdd, 0x32, 0x6a, 0x44, - 0xeb, 0xff, 0xb7, 0xe6, 0x85, 0xe5, 0xa5, 0x55, 0x5d, 0x5b, 0x28, 0x53, 0x63, 0xe4, 0xb3, 0xb9, - 0xa8, 0x70, 0xc8, 0x8f, 0xcd, 0x21, 0x8d, 0xe6, 0x1f, 0xe5, 0x78, 0x34, 0xd3, 0x45, 0x0c, 0x9c, - 0x7a, 0x22, 0x1b, 0x63, 0x55, 0xca, 0x14, 0xa5, 0x0c, 0x7a, 0x40, 0x8e, 0xa1, 0x14, 0x78, 0xa1, - 0xf1, 0x36, 0x78, 0xbd, 0xba, 0x37, 0x3b, 0x5b, 0xb0, 0x8e, 0xb3, 0x4a, 0x9b, 0x1b, 0x0c, 0xfa, - 0xfa, 0xc7, 0x9f, 0xb1, 0x35, 0x48, 0x82, 0x73, 0xf8, 0x6b, 0xd4, 0x76, 0x33, 0x5c, 0xed, 0x9c, - 0xd8, 0x4b, 0xc9, 0x92, 0xa0, 0x3f, 0x6e, 0xba, 0x78, 0x2e, 0x80, 0x78, 0x1e, 0x74, 0xa0, 0x47, - }; - - Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; - - // keypair - OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; - ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); - if (ret != CRYPTO_SUCCESS) { - return false; - } - ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - // verify - ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256", &verify); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - ret = OH_CryptoVerify_Init(verify, pubKey); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); - if (res != true) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - OH_CryptoKeyPair_Destroy(keyPair); - return res; +/* + * 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 "signing_signature_verification.h" + +bool DoTestRsaSignature() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x43, 0x31, 0x7d, 0xb5, 0x85, 0x2e, 0xd4, 0xef, 0x08, 0x7a, 0x17, 0x96, 0xbc, 0x7c, 0x8f, 0x80, + 0x8c, 0xa7, 0x63, 0x7f, 0x26, 0x89, 0x8f, 0xf0, 0xfa, 0xa7, 0x51, 0xbd, 0x9c, 0x69, 0x17, 0xf3, + 0xd1, 0xb5, 0xc7, 0x12, 0xbf, 0xcf, 0x91, 0x25, 0x82, 0x23, 0x6b, 0xd6, 0x64, 0x52, 0x77, 0x93, + 0x01, 0x9d, 0x70, 0xa3, 0xf4, 0x92, 0x16, 0xec, 0x3f, 0xa7, 0x3c, 0x83, 0x8d, 0x40, 0x41, 0xfc, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, + 0x6f, 0x47, 0x42, 0x41, 0x4d, 0x78, 0x63, 0x44, 0x4d, 0x6f, 0x61, 0x59, 0x52, 0x58, 0x6f, 0x78, 0x65, 0x69, + 0x33, 0x49, 0x6d, 0x33, 0x33, 0x78, 0x4a, 0x76, 0x61, 0x73, 0x63, 0x43, 0x62, 0x77, 0x31, 0x6f, 0x73, 0x63, + 0x32, 0x56, 0x56, 0x69, 0x47, 0x6a, 0x56, 0x47, 0x47, 0x4a, 0x37, 0x6c, 0x75, 0x4e, 0x41, 0x58, 0x6b, 0x6a, + 0x73, 0x56, 0x46, 0x64, 0x35, 0x0a, 0x58, 0x37, 0x4c, 0x4d, 0x6c, 0x46, 0x34, 0x63, 0x35, 0x5a, 0x75, 0x59, + 0x2f, 0x61, 0x69, 0x57, 0x77, 0x70, 0x54, 0x69, 0x63, 0x62, 0x67, 0x49, 0x33, 0x43, 0x66, 0x50, 0x6f, 0x32, + 0x6a, 0x6c, 0x52, 0x74, 0x67, 0x41, 0x46, 0x6b, 0x44, 0x71, 0x7a, 0x4b, 0x53, 0x46, 0x62, 0x46, 0x47, 0x51, + 0x6b, 0x43, 0x6e, 0x64, 0x63, 0x2b, 0x54, 0x59, 0x6b, 0x5a, 0x42, 0x32, 0x70, 0x45, 0x6f, 0x72, 0x0a, 0x7a, + 0x73, 0x61, 0x56, 0x58, 0x77, 0x5a, 0x47, 0x45, 0x34, 0x41, 0x43, 0x70, 0x59, 0x35, 0x79, 0x65, 0x66, 0x49, + 0x44, 0x6c, 0x45, 0x57, 0x49, 0x51, 0x4f, 0x6a, 0x59, 0x4b, 0x2f, 0x6c, 0x58, 0x71, 0x7a, 0x48, 0x47, 0x69, + 0x4f, 0x69, 0x32, 0x75, 0x4a, 0x45, 0x75, 0x44, 0x43, 0x50, 0x6a, 0x51, 0x64, 0x6a, 0x54, 0x41, 0x67, 0x4d, + 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, + 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x68, 0x2f, 0x3b, 0xe6, 0xa6, 0x5c, 0xb8, 0x60, 0xd4, 0xe1, 0x64, 0xa7, 0xd8, 0x0c, 0x9c, 0x89, + 0x39, 0xb4, 0xf0, 0xb7, 0xad, 0xb5, 0x8a, 0x71, 0x04, 0xf1, 0xa5, 0x63, 0xdd, 0x32, 0x6a, 0x44, + 0xeb, 0xff, 0xb7, 0xe6, 0x85, 0xe5, 0xa5, 0x55, 0x5d, 0x5b, 0x28, 0x53, 0x63, 0xe4, 0xb3, 0xb9, + 0xa8, 0x70, 0xc8, 0x8f, 0xcd, 0x21, 0x8d, 0xe6, 0x1f, 0xe5, 0x78, 0x34, 0xd3, 0x45, 0x0c, 0x9c, + 0x7a, 0x22, 0x1b, 0x63, 0x55, 0xca, 0x14, 0xa5, 0x0c, 0x7a, 0x40, 0x8e, 0xa1, 0x14, 0x78, 0xa1, + 0xf1, 0x36, 0x78, 0xbd, 0xba, 0x37, 0x3b, 0x5b, 0xb0, 0x8e, 0xb3, 0x4a, 0x9b, 0x1b, 0x0c, 0xfa, + 0xfa, 0xc7, 0x9f, 0xb1, 0x35, 0x48, 0x82, 0x73, 0xf8, 0x6b, 0xd4, 0x76, 0x33, 0x5c, 0xed, 0x9c, + 0xd8, 0x4b, 0xc9, 0x92, 0xa0, 0x3f, 0x6e, 0xba, 0x78, 0x2e, 0x80, 0x78, 0x1e, 0x74, 0xa0, 0x47, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (res != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp old mode 100755 new mode 100644 index a427ac7d10c4178700648f5ec51daf57140aa18a..e8205fc81ddf3fea1da07b5d31ff72e7c341f59f --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp @@ -1,114 +1,114 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "signing_signature_verification.h" - -bool DoTestRsaPssSignatureSeg() -{ - OH_CryptoAsymKeyGenerator *keyCtx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_CryptoVerify *verify = nullptr; - - uint8_t plainText[] = { - 0x13, 0xa7, 0x73, 0xe8, 0xb8, 0x22, 0x99, 0x72, 0x98, 0x29, 0xae, 0x74, 0xa8, 0x4a, 0xea, 0xa9, - }; - Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; - - uint8_t pubKeyText[] = { - 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, - 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x43, - 0x67, 0x4b, 0x43, 0x41, 0x51, 0x45, 0x41, 0x76, 0x6a, 0x6c, 0x59, 0x35, 0x53, 0x72, 0x54, 0x57, 0x32, 0x43, - 0x78, 0x74, 0x47, 0x32, 0x54, 0x67, 0x54, 0x54, 0x39, 0x39, 0x78, 0x71, 0x37, 0x62, 0x4e, 0x41, 0x6b, 0x54, - 0x2b, 0x65, 0x6a, 0x75, 0x65, 0x7a, 0x37, 0x39, 0x37, 0x2f, 0x65, 0x63, 0x56, 0x4b, 0x34, 0x78, 0x37, 0x58, - 0x41, 0x4d, 0x6d, 0x73, 0x4a, 0x0a, 0x4a, 0x63, 0x66, 0x49, 0x36, 0x73, 0x54, 0x4d, 0x4e, 0x68, 0x45, 0x6b, - 0x70, 0x79, 0x63, 0x31, 0x4b, 0x32, 0x46, 0x6e, 0x30, 0x74, 0x59, 0x47, 0x2f, 0x6d, 0x4d, 0x37, 0x72, 0x71, - 0x6d, 0x6a, 0x6c, 0x6b, 0x75, 0x72, 0x34, 0x72, 0x74, 0x6a, 0x4a, 0x4a, 0x75, 0x66, 0x34, 0x35, 0x45, 0x42, - 0x30, 0x79, 0x6c, 0x55, 0x65, 0x47, 0x61, 0x39, 0x6d, 0x44, 0x4a, 0x57, 0x76, 0x62, 0x2b, 0x73, 0x0a, 0x41, - 0x4a, 0x78, 0x33, 0x41, 0x44, 0x78, 0x70, 0x50, 0x31, 0x59, 0x36, 0x46, 0x61, 0x71, 0x54, 0x44, 0x6e, 0x64, - 0x47, 0x41, 0x6e, 0x6b, 0x65, 0x4d, 0x53, 0x2f, 0x56, 0x71, 0x53, 0x45, 0x65, 0x75, 0x43, 0x36, 0x4d, 0x42, - 0x38, 0x52, 0x53, 0x65, 0x6f, 0x31, 0x4f, 0x59, 0x4c, 0x53, 0x73, 0x7a, 0x36, 0x43, 0x76, 0x38, 0x34, 0x76, - 0x76, 0x53, 0x69, 0x32, 0x37, 0x32, 0x51, 0x44, 0x6e, 0x0a, 0x6f, 0x4b, 0x4f, 0x4d, 0x34, 0x43, 0x78, 0x6d, - 0x6e, 0x32, 0x31, 0x58, 0x5a, 0x43, 0x5a, 0x2f, 0x59, 0x50, 0x32, 0x35, 0x67, 0x5a, 0x6e, 0x57, 0x4f, 0x61, - 0x42, 0x4c, 0x50, 0x57, 0x79, 0x6f, 0x48, 0x46, 0x65, 0x49, 0x55, 0x42, 0x48, 0x4c, 0x50, 0x69, 0x4a, 0x2b, - 0x72, 0x58, 0x48, 0x4e, 0x65, 0x4f, 0x38, 0x2b, 0x70, 0x6c, 0x37, 0x49, 0x42, 0x74, 0x66, 0x35, 0x67, 0x70, - 0x4a, 0x76, 0x0a, 0x31, 0x6e, 0x78, 0x72, 0x45, 0x4b, 0x73, 0x75, 0x2b, 0x6e, 0x64, 0x48, 0x43, 0x6e, 0x46, - 0x64, 0x6f, 0x38, 0x2f, 0x49, 0x46, 0x46, 0x4a, 0x6a, 0x70, 0x36, 0x73, 0x6f, 0x55, 0x4a, 0x4f, 0x5a, 0x52, - 0x4b, 0x6e, 0x6f, 0x41, 0x4b, 0x34, 0x67, 0x6a, 0x34, 0x48, 0x30, 0x50, 0x76, 0x49, 0x79, 0x4d, 0x67, 0x4b, - 0x61, 0x43, 0x43, 0x41, 0x55, 0x57, 0x70, 0x4a, 0x65, 0x76, 0x35, 0x42, 0x52, 0x0a, 0x42, 0x4f, 0x56, 0x38, - 0x4f, 0x59, 0x34, 0x48, 0x48, 0x6f, 0x42, 0x6b, 0x47, 0x4d, 0x6e, 0x32, 0x71, 0x6a, 0x4d, 0x48, 0x78, 0x49, - 0x6c, 0x71, 0x48, 0x50, 0x67, 0x59, 0x70, 0x41, 0x53, 0x50, 0x51, 0x77, 0x49, 0x44, 0x41, 0x51, 0x41, 0x42, - 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, 0x4c, - 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, - }; - - Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; - - uint8_t signText[] = { - 0xac, 0x2b, 0x12, 0x56, 0x1c, 0xe1, 0x60, 0x49, 0xc2, 0xd9, 0x87, 0x89, 0xfb, 0xa3, 0xc5, 0x41, 0x64, 0x7f, - 0x6f, 0x80, 0xc8, 0xdb, 0xb3, 0xdf, 0x25, 0x76, 0x4b, 0x1e, 0x51, 0xaa, 0x0a, 0x6d, 0x83, 0x49, 0xae, 0x00, - 0x7a, 0x99, 0xf4, 0xc8, 0x98, 0x45, 0x71, 0xfc, 0x5e, 0xdb, 0xed, 0x31, 0xad, 0xf2, 0x35, 0x05, 0xe2, 0x3e, - 0xf1, 0xcb, 0x96, 0xb2, 0xb9, 0x59, 0xaf, 0x30, 0x25, 0xb0, 0xda, 0x83, 0x18, 0x2b, 0x11, 0xa4, 0x93, 0x2d, - 0x9e, 0x93, 0x99, 0x62, 0xdd, 0xea, 0x1b, 0xfa, 0x60, 0xb8, 0xea, 0x9c, 0xef, 0x4f, 0x2b, 0x9d, 0xd1, 0x3e, - 0xe1, 0x6b, 0x24, 0x98, 0x9d, 0x32, 0xa3, 0x1e, 0x9d, 0x45, 0xe7, 0x3d, 0x51, 0x7e, 0x3b, 0x0c, 0xee, 0x3f, - 0xca, 0x29, 0xd9, 0x02, 0xe5, 0xb8, 0xf5, 0x89, 0x06, 0xf4, 0xfe, 0x27, 0x44, 0xff, 0x38, 0xed, 0x5a, 0x0e, - 0x89, 0x16, 0x15, 0x26, 0xf0, 0xb2, 0x4c, 0x95, 0xee, 0x0a, 0xd3, 0x61, 0xc7, 0xb2, 0x4b, 0xfd, 0x20, 0xb9, - 0x83, 0x25, 0x43, 0x4d, 0xa0, 0x3d, 0xaa, 0x40, 0x7b, 0xac, 0x01, 0x48, 0x8e, 0x2a, 0x96, 0x11, 0xc0, 0x31, - 0x51, 0x5b, 0xaf, 0xeb, 0x8b, 0xaf, 0xb5, 0x88, 0xcb, 0xe0, 0x97, 0x45, 0x36, 0xe9, 0x6e, 0x6e, 0xe0, 0x55, - 0xea, 0xf4, 0xd2, 0x88, 0xbb, 0xc9, 0x85, 0x94, 0xd5, 0x65, 0xeb, 0xa3, 0x1c, 0xd1, 0xd6, 0xf5, 0x22, 0x29, - 0xf1, 0x16, 0xa5, 0x53, 0x1b, 0xd0, 0x6c, 0xf6, 0x0d, 0xa8, 0xd4, 0xe4, 0xb2, 0x0a, 0x92, 0x64, 0x7a, 0x6d, - 0xf2, 0x76, 0xf3, 0xb0, 0x08, 0x44, 0x31, 0x31, 0x90, 0x48, 0x9e, 0x2e, 0x03, 0xc7, 0xab, 0x5d, 0x7a, 0x07, - 0x1f, 0x1d, 0x10, 0x21, 0x54, 0x60, 0x0d, 0x26, 0xe4, 0x1c, 0xc7, 0x82, 0x03, 0x65, 0x64, 0x70, 0x41, 0x68, - 0x0f, 0xfa, 0x64, 0x3c, - }; - - Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; - - // keypair - OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; - ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); - if (ret != CRYPTO_SUCCESS) { - return false; - } - ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - // verify - ret = OH_CryptoVerify_Create((const char *)"RSA2048|PSS|SHA256|MGF1_SHA256", &verify); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - ret = OH_CryptoVerify_Init(verify, pubKey); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); - if (ret != true) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - OH_CryptoKeyPair_Destroy(keyPair); - return res; -} +/* + * 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 "signing_signature_verification.h" + +bool DoTestRsaPssSignatureSeg() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x13, 0xa7, 0x73, 0xe8, 0xb8, 0x22, 0x99, 0x72, 0x98, 0x29, 0xae, 0x74, 0xa8, 0x4a, 0xea, 0xa9, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x43, + 0x67, 0x4b, 0x43, 0x41, 0x51, 0x45, 0x41, 0x76, 0x6a, 0x6c, 0x59, 0x35, 0x53, 0x72, 0x54, 0x57, 0x32, 0x43, + 0x78, 0x74, 0x47, 0x32, 0x54, 0x67, 0x54, 0x54, 0x39, 0x39, 0x78, 0x71, 0x37, 0x62, 0x4e, 0x41, 0x6b, 0x54, + 0x2b, 0x65, 0x6a, 0x75, 0x65, 0x7a, 0x37, 0x39, 0x37, 0x2f, 0x65, 0x63, 0x56, 0x4b, 0x34, 0x78, 0x37, 0x58, + 0x41, 0x4d, 0x6d, 0x73, 0x4a, 0x0a, 0x4a, 0x63, 0x66, 0x49, 0x36, 0x73, 0x54, 0x4d, 0x4e, 0x68, 0x45, 0x6b, + 0x70, 0x79, 0x63, 0x31, 0x4b, 0x32, 0x46, 0x6e, 0x30, 0x74, 0x59, 0x47, 0x2f, 0x6d, 0x4d, 0x37, 0x72, 0x71, + 0x6d, 0x6a, 0x6c, 0x6b, 0x75, 0x72, 0x34, 0x72, 0x74, 0x6a, 0x4a, 0x4a, 0x75, 0x66, 0x34, 0x35, 0x45, 0x42, + 0x30, 0x79, 0x6c, 0x55, 0x65, 0x47, 0x61, 0x39, 0x6d, 0x44, 0x4a, 0x57, 0x76, 0x62, 0x2b, 0x73, 0x0a, 0x41, + 0x4a, 0x78, 0x33, 0x41, 0x44, 0x78, 0x70, 0x50, 0x31, 0x59, 0x36, 0x46, 0x61, 0x71, 0x54, 0x44, 0x6e, 0x64, + 0x47, 0x41, 0x6e, 0x6b, 0x65, 0x4d, 0x53, 0x2f, 0x56, 0x71, 0x53, 0x45, 0x65, 0x75, 0x43, 0x36, 0x4d, 0x42, + 0x38, 0x52, 0x53, 0x65, 0x6f, 0x31, 0x4f, 0x59, 0x4c, 0x53, 0x73, 0x7a, 0x36, 0x43, 0x76, 0x38, 0x34, 0x76, + 0x76, 0x53, 0x69, 0x32, 0x37, 0x32, 0x51, 0x44, 0x6e, 0x0a, 0x6f, 0x4b, 0x4f, 0x4d, 0x34, 0x43, 0x78, 0x6d, + 0x6e, 0x32, 0x31, 0x58, 0x5a, 0x43, 0x5a, 0x2f, 0x59, 0x50, 0x32, 0x35, 0x67, 0x5a, 0x6e, 0x57, 0x4f, 0x61, + 0x42, 0x4c, 0x50, 0x57, 0x79, 0x6f, 0x48, 0x46, 0x65, 0x49, 0x55, 0x42, 0x48, 0x4c, 0x50, 0x69, 0x4a, 0x2b, + 0x72, 0x58, 0x48, 0x4e, 0x65, 0x4f, 0x38, 0x2b, 0x70, 0x6c, 0x37, 0x49, 0x42, 0x74, 0x66, 0x35, 0x67, 0x70, + 0x4a, 0x76, 0x0a, 0x31, 0x6e, 0x78, 0x72, 0x45, 0x4b, 0x73, 0x75, 0x2b, 0x6e, 0x64, 0x48, 0x43, 0x6e, 0x46, + 0x64, 0x6f, 0x38, 0x2f, 0x49, 0x46, 0x46, 0x4a, 0x6a, 0x70, 0x36, 0x73, 0x6f, 0x55, 0x4a, 0x4f, 0x5a, 0x52, + 0x4b, 0x6e, 0x6f, 0x41, 0x4b, 0x34, 0x67, 0x6a, 0x34, 0x48, 0x30, 0x50, 0x76, 0x49, 0x79, 0x4d, 0x67, 0x4b, + 0x61, 0x43, 0x43, 0x41, 0x55, 0x57, 0x70, 0x4a, 0x65, 0x76, 0x35, 0x42, 0x52, 0x0a, 0x42, 0x4f, 0x56, 0x38, + 0x4f, 0x59, 0x34, 0x48, 0x48, 0x6f, 0x42, 0x6b, 0x47, 0x4d, 0x6e, 0x32, 0x71, 0x6a, 0x4d, 0x48, 0x78, 0x49, + 0x6c, 0x71, 0x48, 0x50, 0x67, 0x59, 0x70, 0x41, 0x53, 0x50, 0x51, 0x77, 0x49, 0x44, 0x41, 0x51, 0x41, 0x42, + 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, 0x4c, + 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0xac, 0x2b, 0x12, 0x56, 0x1c, 0xe1, 0x60, 0x49, 0xc2, 0xd9, 0x87, 0x89, 0xfb, 0xa3, 0xc5, 0x41, 0x64, 0x7f, + 0x6f, 0x80, 0xc8, 0xdb, 0xb3, 0xdf, 0x25, 0x76, 0x4b, 0x1e, 0x51, 0xaa, 0x0a, 0x6d, 0x83, 0x49, 0xae, 0x00, + 0x7a, 0x99, 0xf4, 0xc8, 0x98, 0x45, 0x71, 0xfc, 0x5e, 0xdb, 0xed, 0x31, 0xad, 0xf2, 0x35, 0x05, 0xe2, 0x3e, + 0xf1, 0xcb, 0x96, 0xb2, 0xb9, 0x59, 0xaf, 0x30, 0x25, 0xb0, 0xda, 0x83, 0x18, 0x2b, 0x11, 0xa4, 0x93, 0x2d, + 0x9e, 0x93, 0x99, 0x62, 0xdd, 0xea, 0x1b, 0xfa, 0x60, 0xb8, 0xea, 0x9c, 0xef, 0x4f, 0x2b, 0x9d, 0xd1, 0x3e, + 0xe1, 0x6b, 0x24, 0x98, 0x9d, 0x32, 0xa3, 0x1e, 0x9d, 0x45, 0xe7, 0x3d, 0x51, 0x7e, 0x3b, 0x0c, 0xee, 0x3f, + 0xca, 0x29, 0xd9, 0x02, 0xe5, 0xb8, 0xf5, 0x89, 0x06, 0xf4, 0xfe, 0x27, 0x44, 0xff, 0x38, 0xed, 0x5a, 0x0e, + 0x89, 0x16, 0x15, 0x26, 0xf0, 0xb2, 0x4c, 0x95, 0xee, 0x0a, 0xd3, 0x61, 0xc7, 0xb2, 0x4b, 0xfd, 0x20, 0xb9, + 0x83, 0x25, 0x43, 0x4d, 0xa0, 0x3d, 0xaa, 0x40, 0x7b, 0xac, 0x01, 0x48, 0x8e, 0x2a, 0x96, 0x11, 0xc0, 0x31, + 0x51, 0x5b, 0xaf, 0xeb, 0x8b, 0xaf, 0xb5, 0x88, 0xcb, 0xe0, 0x97, 0x45, 0x36, 0xe9, 0x6e, 0x6e, 0xe0, 0x55, + 0xea, 0xf4, 0xd2, 0x88, 0xbb, 0xc9, 0x85, 0x94, 0xd5, 0x65, 0xeb, 0xa3, 0x1c, 0xd1, 0xd6, 0xf5, 0x22, 0x29, + 0xf1, 0x16, 0xa5, 0x53, 0x1b, 0xd0, 0x6c, 0xf6, 0x0d, 0xa8, 0xd4, 0xe4, 0xb2, 0x0a, 0x92, 0x64, 0x7a, 0x6d, + 0xf2, 0x76, 0xf3, 0xb0, 0x08, 0x44, 0x31, 0x31, 0x90, 0x48, 0x9e, 0x2e, 0x03, 0xc7, 0xab, 0x5d, 0x7a, 0x07, + 0x1f, 0x1d, 0x10, 0x21, 0x54, 0x60, 0x0d, 0x26, 0xe4, 0x1c, 0xc7, 0x82, 0x03, 0x65, 0x64, 0x70, 0x41, 0x68, + 0x0f, 0xfa, 0x64, 0x3c, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA2048|PSS|SHA256|MGF1_SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (ret != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h old mode 100755 new mode 100644 index afde6e8c954c15caae0b75eaec04dee445978cfb..2aca2232efb18f0901cb7e392853b128f31bbadc --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h @@ -1,29 +1,29 @@ -#ifndef MYAPPLICATION_AA_H -#define MYAPPLICATION_AA_H -/* - * 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 "CryptoArchitectureKit/crypto_common.h" -#include "CryptoArchitectureKit/crypto_signature.h" -#include "CryptoArchitectureKit/crypto_asym_key.h" - -bool DoTestRsaSignature(); -bool DoTestRsaSignatureSeg(); -OH_Crypto_ErrCode DoTestRsaSignatureRecover(); -bool DoTestRsaPssSignatureSeg(); -bool DoTestEcdsaSignature(); -bool DoTestSm2Signature(); - +#ifndef MYAPPLICATION_AA_H +#define MYAPPLICATION_AA_H +/* + * 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 "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_signature.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" + +bool DoTestRsaSignature(); +bool DoTestRsaSignatureSeg(); +OH_Crypto_ErrCode DoTestRsaSignatureRecover(); +bool DoTestRsaPssSignatureSeg(); +bool DoTestEcdsaSignature(); +bool DoTestSm2Signature(); + #endif // MYAPPLICATION_AA_H \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp old mode 100755 new mode 100644 index 425b5eddd2413bc718c17a5d5ddd3e8048b78741..3b4b0316572258b358071a742accbb59fdd64eb7 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp @@ -1,86 +1,86 @@ -/* - * 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 "signing_signature_verification.h" - -bool DoTestSm2Signature() -{ - OH_CryptoAsymKeyGenerator *keyCtx = nullptr; - OH_CryptoKeyPair *keyPair = nullptr; - OH_CryptoVerify *verify = nullptr; - - uint8_t plainText[] = { - 0x96, 0x46, 0x2e, 0xde, 0x3f, 0x47, 0xbf, 0xd6, 0x87, 0x48, 0x36, 0x1d, 0x75, 0x35, 0xbd, 0xbc, - 0x6b, 0x06, 0xe8, 0xb3, 0x68, 0x91, 0x53, 0xce, 0x76, 0x5d, 0x24, 0xda, 0xdc, 0xc4, 0x9f, 0x94, - }; - Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; - - uint8_t pubKeyText[] = { - 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, - 0x81, 0x1c, 0xcf, 0x55, 0x01, 0x82, 0x2d, 0x03, 0x42, 0x00, 0x04, 0x80, 0x5b, 0x78, 0x04, 0xd7, - 0xcf, 0xc3, 0x99, 0x63, 0xae, 0x88, 0xcd, 0xfc, 0xd6, 0x18, 0xf4, 0x08, 0xe8, 0xe3, 0x68, 0x47, - 0x4f, 0x44, 0x0e, 0xb2, 0xba, 0x3a, 0xb3, 0x10, 0xf1, 0xc9, 0xd0, 0x84, 0xe2, 0xa4, 0x47, 0xbe, - 0x72, 0xae, 0xf8, 0x6a, 0xeb, 0x6e, 0x10, 0xab, 0x52, 0x6b, 0x6a, 0x58, 0xc6, 0xb5, 0x78, 0xaa, - 0x70, 0xe5, 0x58, 0x20, 0x4e, 0x34, 0x42, 0x77, 0x08, 0x27, 0x11, - }; - - Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; - - uint8_t signText[] = { - 0x30, 0x45, 0x02, 0x21, 0x00, 0xf4, 0xe7, 0x9d, 0x35, 0x33, 0xa6, 0x86, 0x2e, 0x2a, 0x97, 0x72, 0xc9, 0x46, - 0x79, 0x65, 0xca, 0x4a, 0x71, 0x34, 0xca, 0xf7, 0x58, 0xb3, 0x26, 0xa5, 0xdb, 0xfa, 0x8b, 0xbe, 0xbf, 0x5f, - 0x90, 0x02, 0x20, 0x53, 0xb4, 0x23, 0xb1, 0xe2, 0x8f, 0x2f, 0xe9, 0xc8, 0x22, 0xef, 0xab, 0x9b, 0x13, 0x08, - 0x75, 0x8e, 0xb1, 0x9c, 0x59, 0xe5, 0xd6, 0x64, 0x35, 0xf5, 0xd1, 0xde, 0xfa, 0xfe, 0x80, 0x37, 0x1a, - }; - - Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; - - // keypair - OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; - ret = OH_CryptoAsymKeyGenerator_Create((const char *)"SM2_256", &keyCtx); - if (ret != CRYPTO_SUCCESS) { - return false; - } - ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_DER, &keyBlob, nullptr, &keyPair); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); - // verify - ret = OH_CryptoVerify_Create((const char *)"SM2_256|SM3", &verify); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - ret = OH_CryptoVerify_Init(verify, pubKey); - if (ret != CRYPTO_SUCCESS) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); - if (ret != true) { - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - return false; - } - - OH_CryptoVerify_Destroy(verify); - OH_CryptoAsymKeyGenerator_Destroy(keyCtx); - OH_CryptoKeyPair_Destroy(keyPair); - return res; -} +/* + * 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 "signing_signature_verification.h" + +bool DoTestSm2Signature() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x96, 0x46, 0x2e, 0xde, 0x3f, 0x47, 0xbf, 0xd6, 0x87, 0x48, 0x36, 0x1d, 0x75, 0x35, 0xbd, 0xbc, + 0x6b, 0x06, 0xe8, 0xb3, 0x68, 0x91, 0x53, 0xce, 0x76, 0x5d, 0x24, 0xda, 0xdc, 0xc4, 0x9f, 0x94, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, + 0x81, 0x1c, 0xcf, 0x55, 0x01, 0x82, 0x2d, 0x03, 0x42, 0x00, 0x04, 0x80, 0x5b, 0x78, 0x04, 0xd7, + 0xcf, 0xc3, 0x99, 0x63, 0xae, 0x88, 0xcd, 0xfc, 0xd6, 0x18, 0xf4, 0x08, 0xe8, 0xe3, 0x68, 0x47, + 0x4f, 0x44, 0x0e, 0xb2, 0xba, 0x3a, 0xb3, 0x10, 0xf1, 0xc9, 0xd0, 0x84, 0xe2, 0xa4, 0x47, 0xbe, + 0x72, 0xae, 0xf8, 0x6a, 0xeb, 0x6e, 0x10, 0xab, 0x52, 0x6b, 0x6a, 0x58, 0xc6, 0xb5, 0x78, 0xaa, + 0x70, 0xe5, 0x58, 0x20, 0x4e, 0x34, 0x42, 0x77, 0x08, 0x27, 0x11, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x30, 0x45, 0x02, 0x21, 0x00, 0xf4, 0xe7, 0x9d, 0x35, 0x33, 0xa6, 0x86, 0x2e, 0x2a, 0x97, 0x72, 0xc9, 0x46, + 0x79, 0x65, 0xca, 0x4a, 0x71, 0x34, 0xca, 0xf7, 0x58, 0xb3, 0x26, 0xa5, 0xdb, 0xfa, 0x8b, 0xbe, 0xbf, 0x5f, + 0x90, 0x02, 0x20, 0x53, 0xb4, 0x23, 0xb1, 0xe2, 0x8f, 0x2f, 0xe9, 0xc8, 0x22, 0xef, 0xab, 0x9b, 0x13, 0x08, + 0x75, 0x8e, 0xb1, 0x9c, 0x59, 0xe5, 0xd6, 0x64, 0x35, 0xf5, 0xd1, 0xde, 0xfa, 0xfe, 0x80, 0x37, 0x1a, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"SM2_256", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_DER, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"SM2_256|SM3", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (ret != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 25fd42ff7d9651e217f444f2e3b8437738fec3cb..037c49dd582119f1322d373a61ffc3082b92e4aa --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets @@ -1,66 +1,66 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 5 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signature_seg')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.signatureSeg(); - this.message = 'SignatureSegSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_signature')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.signature(); - this.message = 'SignatureSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_signature_recover')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.signatureRecover(); - this.message = 'SignatureRecoverSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_psssignature_seg')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.pssSignatureSeg(); - this.message = 'PSSSignatureSegSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_ecdsasignature')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.ecdsaSignature(); - this.message = 'ECDSASignatureSuccess Result:' + ret.toString(); - }) - Button($r('app.string.call_sm2signature')) - .width('70%') - .onClick(() => { - let ret: number = testNapi.sm2Signature(); - this.message = 'SM2SignatureSuccess Result:' + ret.toString(); - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 5 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_seg')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.signatureSeg(); + this.message = 'SignatureSegSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_signature')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.signature(); + this.message = 'SignatureSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_signature_recover')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.signatureRecover(); + this.message = 'SignatureRecoverSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_psssignature_seg')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.pssSignatureSeg(); + this.message = 'PSSSignatureSegSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_ecdsasignature')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.ecdsaSignature(); + this.message = 'ECDSASignatureSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_sm2signature')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.sm2Signature(); + this.message = 'SM2SignatureSuccess Result:' + ret.toString(); + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets old mode 100755 new mode 100644 index fb2bef7c975d87b559706bbf4dba53b88fb7cb58..3d3612f119b2796631d0168a6737cf4dde83c410 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets @@ -1,128 +1,128 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function signingSignatureVerificationTest() { - describe('signingSignatureVerificationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用RSA密钥对(PKCS1模式)验签(C/C++) - */ - it('testSigningSignatureVerificationTest001', 0, async () => { - console.info('uitest: testSigningSignatureVerificationTest001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SignatureSeg')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureSegSuccess Result:true')); - console.info('uitest: testSigningSignatureVerificationTest001 end'); - }) - - /** - * 点击按钮,使用RSA密钥对(PKCS1模式)签名恢复(C/C++) - */ - it('testSigningSignatureVerificationTest002', 0, async () => { - console.info('uitest: testSigningSignatureVerificationTest002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call Signature')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureSuccess Result:true')); - console.info('uitest: testSigningSignatureVerificationTest002 end'); - }) - - /** - * 点击按钮,使用RSA密钥对分段验签(PKCS1模式)(C/C++) - */ - it('testSigningSignatureVerificationTest003', 0, async () => { - console.info('uitest: testSigningSignatureVerificationTest003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SignatureRecover')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureRecoverSuccess Result:0')); - console.info('uitest: testSigningSignatureVerificationTest003 end'); - }) - - /** - * 点击按钮,使用RSA密钥对验签(PSS模式)(C/C++) - */ - it('testSigningSignatureVerificationTest004', 0, async () => { - console.info('uitest: testSigningSignatureVerificationTest004 begin'); - const driver = Driver.create(); - const button = await driver.findComponent(ON.text('Call PSSSignatureSeg')); - await driver.delayMs(1000); - await button.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess Result:false')); - console.info('uitest: testSigningSignatureVerificationTest004 end'); - }) - - /** - * 点击按钮,使用ECDSA密钥对验签(C/C++) - */ - it('testSigningSignatureVerificationTest005', 0, async () => { - console.info('uitest: testSigningSignatureVerificationTest005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call ECDSASignature')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECDSASignatureSuccess Result:false')); - console.info('uitest: testSigningSignatureVerificationTest005 end'); - }) - - /** - * 点击按钮,使用SM2密钥对验签(C/C++) - */ - it('testSigningSignatureVerificationTest006', 0, async () => { - console.info('uitest: testSigningSignatureVerificationTest006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call SM2Signature')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2SignatureSuccess Result:false')); - console.info('uitest: testSigningSignatureVerificationTest006 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function signingSignatureVerificationTest() { + describe('signingSignatureVerificationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)验签(C/C++) + */ + it('testSigningSignatureVerificationTest001', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SignatureSeg')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSegSuccess Result:true')); + console.info('uitest: testSigningSignatureVerificationTest001 end'); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名恢复(C/C++) + */ + it('testSigningSignatureVerificationTest002', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call Signature')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSuccess Result:true')); + console.info('uitest: testSigningSignatureVerificationTest002 end'); + }) + + /** + * 点击按钮,使用RSA密钥对分段验签(PKCS1模式)(C/C++) + */ + it('testSigningSignatureVerificationTest003', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SignatureRecover')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureRecoverSuccess Result:0')); + console.info('uitest: testSigningSignatureVerificationTest003 end'); + }) + + /** + * 点击按钮,使用RSA密钥对验签(PSS模式)(C/C++) + */ + it('testSigningSignatureVerificationTest004', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest004 begin'); + const driver = Driver.create(); + const button = await driver.findComponent(ON.text('Call PSSSignatureSeg')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess Result:false')); + console.info('uitest: testSigningSignatureVerificationTest004 end'); + }) + + /** + * 点击按钮,使用ECDSA密钥对验签(C/C++) + */ + it('testSigningSignatureVerificationTest005', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call ECDSASignature')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECDSASignatureSuccess Result:false')); + console.info('uitest: testSigningSignatureVerificationTest005 end'); + }) + + /** + * 点击按钮,使用SM2密钥对验签(C/C++) + */ + it('testSigningSignatureVerificationTest006', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM2Signature')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2SignatureSuccess Result:false')); + console.info('uitest: testSigningSignatureVerificationTest006 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/ohosTest.md old mode 100755 new mode 100644 index cd57f20d95a884383fa6192e51df36631c5e4da3..3484ec8f4819a42287f78c19354fd6a5f175243e --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/ohosTest.md @@ -1,13 +1,13 @@ -# 签名验签(C/C++)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用RSA密钥对(PKCS1模式)验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对(PKCS1模式)签名恢复(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对分段验签(PKCS1模式)(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对验签(PSS模式)(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用ECDSA密钥对验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 签名验签(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名恢复(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对分段验签(PKCS1模式)(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对验签(PSS模式)(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDSA密钥对验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用SM2密钥对验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification1.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification2.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/app.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/app.json5 old mode 100755 new mode 100644 index b699ed2606af337b5b45f4939bf09dad48bbdc1e..839e94769a08a2a0352e9e4e1ef9d8c02ba591da --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/app.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/app.json5 @@ -1,25 +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.signingsignatureverificationarkts", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.signingsignatureverificationarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index cc63c915239a06694ec5049af7364c6cfe20742b..23956993e9766f265e2dc17d8fb70fcf9fdabd45 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SigningSignatureVerificationArkTs" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SigningSignatureVerificationArkTs" + } + ] +} diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md old mode 100755 new mode 100644 index cad3648ab0348af8f1b9425e742309aaf6898bb2..89991a1f58214f80bee7248fe8203af9d31eb991 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md @@ -1,80 +1,80 @@ -# 签名验签(ArkTS) - -### 介绍 - -当需要判断接收的数据是否被篡改、数据是否为指定对象发送的数据时,可以使用签名验签操作。接下来将说明系统目前支持的算法及其对应的规格。 - -本示例主要展示了签名验签(ArkTS)的多种场景 。该工程中展示的代码详细描述可查如下链接。 - -- [使用RSA密钥对(PKCS1模式)签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1.md) -- [使用RSA密钥对(PKCS1模式)签名及签名恢复(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-recover-pkcs1.md) -- [使用RSA密钥对分段签名验签(PKCS1模式)(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-by-segment.md) -- [使用RSA密钥对签名验签(PSS模式)(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pss.md) -- [使用ECDSA密钥对签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-ecdsa-sign-sig-verify.md) -- [使用SM2密钥对签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-sign-sig-verify-pkcs1.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例SigningSignatureVerificationArkTs.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 签名验签(ArkTS)示例代码 - │ │ ├── ecdsa_signature_verification - │ │ ├── rsa_pkcs1_segment_signature - │ │ ├── rsa_pkcs1_signature_restoration - │ │ ├── rsa_pkcs1_signature_validator - │ │ ├── rsa_pss_signature_verification - │ │ ├── sm2_signature_verification - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── SigningSignatureVerificationArkTs.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 签名验签(ArkTS) + +### 介绍 + +当需要判断接收的数据是否被篡改、数据是否为指定对象发送的数据时,可以使用签名验签操作。接下来将说明系统目前支持的算法及其对应的规格。 + +本示例主要展示了签名验签(ArkTS)的多种场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用RSA密钥对(PKCS1模式)签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1.md) +- [使用RSA密钥对(PKCS1模式)签名及签名恢复(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-recover-pkcs1.md) +- [使用RSA密钥对分段签名验签(PKCS1模式)(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-by-segment.md) +- [使用RSA密钥对签名验签(PSS模式)(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pss.md) +- [使用ECDSA密钥对签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-ecdsa-sign-sig-verify.md) +- [使用SM2密钥对签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-sign-sig-verify-pkcs1.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SigningSignatureVerificationArkTs.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 签名验签(ArkTS)示例代码 + │ │ ├── ecdsa_signature_verification + │ │ ├── rsa_pkcs1_segment_signature + │ │ ├── rsa_pkcs1_signature_restoration + │ │ ├── rsa_pkcs1_signature_validator + │ │ ├── rsa_pss_signature_verification + │ │ ├── sm2_signature_verification + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SigningSignatureVerificationArkTs.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/code-linter.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/.gitignore b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/build-profile.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/build-profile.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets old mode 100755 new mode 100644 index f31a122cd317a42f02c098f61116e14bbc73e9e5..e9429f5067b157ecff366f31e39a6e267ea8b812 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets @@ -1,77 +1,77 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; -let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; - -async function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'ECC256|SHA256'; - let signer = cryptoFramework.createSign(signAlg); - await signer.init(priKey); - await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 - let signData = await signer.sign(input2); - return signData; -} - -async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'ECC256|SHA256'; - let verifier = cryptoFramework.createVerify(verifyAlg); - await verifier.init(pubKey); - await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 - let res = await verifier.verify(input2, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -async function main() { - let keyGenAlg = 'ECC256'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = await generator.generateKeyPair(); - let signData = await signMessagePromise(keyPair.priKey); - let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_ecdsasignature_asynchronous')) - .width('70%') - .onClick(async () => { - try { - await main(); - this.message = 'ECDSASignatureSuccess'; - } catch { - this.message = 'ECDSASignatureFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'ECC256|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = await signer.sign(input2); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'ECC256|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = await verifier.verify(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function main() { + let keyGenAlg = 'ECC256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecdsasignature_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'ECDSASignatureSuccess'; + } catch { + this.message = 'ECDSASignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets old mode 100755 new mode 100644 index 8c011ab9229bc63b4782711c21cc08bd3f641c8f..2867f83f2457a1114057aa2dfe9f88f4cb25046b --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets @@ -1,77 +1,77 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; -let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; - -function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'ECC256|SHA256'; - let signer = cryptoFramework.createSign(signAlg); - signer.initSync(priKey); - signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 - let signData = signer.signSync(input2); - return signData; -} - -function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'ECC256|SHA256'; - let verifier = cryptoFramework.createVerify(verifyAlg); - verifier.initSync(pubKey); - verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 - let res = verifier.verifySync(input2, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -function main() { - let keyGenAlg = 'ECC256'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = generator.generateKeyPairSync(); - let signData = signMessagePromise(keyPair.priKey); - let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_ecdsasignature_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'ECDSASignatureSuccess'; - } catch { - this.message = 'ECDSASignatureFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'ECC256|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = signer.signSync(input2); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'ECC256|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = verifier.verifySync(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function main() { + let keyGenAlg = 'ECC256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecdsasignature_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'ECDSASignatureSuccess'; + } catch { + this.message = 'ECDSASignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets old mode 100755 new mode 100644 index 74d5686344610f704b1adf0958bc2e6fe3b0804d..7c6cdcea5d43d4c12815bf48983fafebbeba9345 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets @@ -1,97 +1,97 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -async function signMessageBySegment(priKey: cryptoFramework.PriKey, plainText: Uint8Array) { - let signAlg = 'RSA1024|PKCS1|SHA256'; - let signer = cryptoFramework.createSign(signAlg); - await signer.init(priKey); - let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 - for (let i = 0; i < plainText.length; i += textSplitLen) { - let updateMessage = plainText.subarray(i, i + textSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - await signer.update(updateMessageBlob); - } - // 已通过分段传入所有明文,故此处sign传入null - let signData = await signer.sign(null); - return signData; -} - -async function verifyMessagBySegment(pubKey: cryptoFramework.PubKey, plainText: Uint8Array, - signMessageBlob: cryptoFramework.DataBlob) { - let verifyAlg = 'RSA1024|PKCS1|SHA256'; - let verifier = cryptoFramework.createVerify(verifyAlg); - await verifier.init(pubKey); - let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 - for (let i = 0; i < plainText.length; i += textSplitLen) { - let updateMessage = plainText.subarray(i, i + textSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - await verifier.update(updateMessageBlob); - } - // 已通过分段传入所有明文,故此处verify第一个参数传入null - let res = await verifier.verify(null, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -async function rsaSignatureBySegment() { - let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; - let keyGenAlg = 'RSA1024'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = await generator.generateKeyPair(); - let messageData = new Uint8Array(buffer.from(message, 'utf-8').buffer); - let signData = await signMessageBySegment(keyPair.priKey, messageData); - let verifyResult = await verifyMessagBySegment(keyPair.pubKey, messageData, signData); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signatureseg_asynchronous')) - .width('70%') - .onClick(async () => { - try { - await rsaSignatureBySegment(); - this.message = 'SignatureSegSuccess'; - } catch { - this.message = 'SignatureSegFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function signMessageBySegment(priKey: cryptoFramework.PriKey, plainText: Uint8Array) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + await signer.update(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处sign传入null + let signData = await signer.sign(null); + return signData; +} + +async function verifyMessagBySegment(pubKey: cryptoFramework.PubKey, plainText: Uint8Array, + signMessageBlob: cryptoFramework.DataBlob) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + await verifier.update(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处verify第一个参数传入null + let res = await verifier.verify(null, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function rsaSignatureBySegment() { + let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let messageData = new Uint8Array(buffer.from(message, 'utf-8').buffer); + let signData = await signMessageBySegment(keyPair.priKey, messageData); + let verifyResult = await verifyMessagBySegment(keyPair.pubKey, messageData, signData); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signatureseg_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await rsaSignatureBySegment(); + this.message = 'SignatureSegSuccess'; + } catch { + this.message = 'SignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets old mode 100755 new mode 100644 index cdf7b2d530d6bcddabab69a9c13d669e9f7bfc93..98b11dc7086fca718508f9e187c8b2ff12b248f0 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets @@ -1,97 +1,97 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -function signMessageBySegment(priKey: cryptoFramework.PriKey, plainText: Uint8Array) { - let signAlg = 'RSA1024|PKCS1|SHA256'; - let signer = cryptoFramework.createSign(signAlg); - signer.initSync(priKey); - let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 - for (let i = 0; i < plainText.length; i += textSplitLen) { - let updateMessage = plainText.subarray(i, i + textSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - signer.updateSync(updateMessageBlob); - } - // 已通过分段传入所有明文,故此处sign传入null - let signData = signer.signSync(null); - return signData; -} - -function verifyMessagBySegment(pubKey: cryptoFramework.PubKey, plainText: Uint8Array, - signMessageBlob: cryptoFramework.DataBlob) { - let verifyAlg = 'RSA1024|PKCS1|SHA256'; - let verifier = cryptoFramework.createVerify(verifyAlg); - verifier.initSync(pubKey); - let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 - for (let i = 0; i < plainText.length; i += textSplitLen) { - let updateMessage = plainText.subarray(i, i + textSplitLen); - let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; - // 分段update - verifier.updateSync(updateMessageBlob); - } - // 已通过分段传入所有明文,故此处verify第一个参数传入null - let res = verifier.verifySync(null, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -function rsaSignatureBySegment() { - let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + - 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; - let keyGenAlg = 'RSA1024'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = generator.generateKeyPairSync(); - let messageData = new Uint8Array(buffer.from(message, 'utf-8').buffer); - let signData = signMessageBySegment(keyPair.priKey, messageData); - let verifyResult = verifyMessagBySegment(keyPair.pubKey, messageData, signData); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signatureseg_synchronous')) - .width('70%') - .onClick(() => { - try { - rsaSignatureBySegment(); - this.message = 'SignatureSegSuccess'; - } catch { - this.message = 'SignatureSegFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function signMessageBySegment(priKey: cryptoFramework.PriKey, plainText: Uint8Array) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + signer.updateSync(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处sign传入null + let signData = signer.signSync(null); + return signData; +} + +function verifyMessagBySegment(pubKey: cryptoFramework.PubKey, plainText: Uint8Array, + signMessageBlob: cryptoFramework.DataBlob) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + verifier.updateSync(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处verify第一个参数传入null + let res = verifier.verifySync(null, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function rsaSignatureBySegment() { + let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let messageData = new Uint8Array(buffer.from(message, 'utf-8').buffer); + let signData = signMessageBySegment(keyPair.priKey, messageData); + let verifyResult = verifyMessagBySegment(keyPair.pubKey, messageData, signData); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signatureseg_synchronous')) + .width('70%') + .onClick(() => { + try { + rsaSignatureBySegment(); + this.message = 'SignatureSegSuccess'; + } catch { + this.message = 'SignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets old mode 100755 new mode 100644 index 74beb12e6754840a80eb91571e54b6c13f4054d3..41d5d63618ceb7695d1d4369ac0e07d1029e386c --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets @@ -1,73 +1,73 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; - -async function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'RSA1024|PKCS1|NoHash|OnlySign'; - let signer = cryptoFramework.createSign(signAlg); - await signer.init(priKey); - let signData = await signer.sign(input1); - return signData; -} - -async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'RSA1024|PKCS1|NoHash|Recover'; - let verifier = cryptoFramework.createVerify(verifyAlg); - await verifier.init(pubKey); - let rawSignData = await verifier.recover(signMessageBlob); - return rawSignData; -} - -async function main() { - let keyGenAlg = 'RSA1024'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = await generator.generateKeyPair(); - let signData = await signMessagePromise(keyPair.priKey); - let rawSignData = await verifyMessagePromise(signData, keyPair.pubKey); - if (rawSignData != null) { - console.info('recover result: ' + rawSignData.data); - } else { - console.error('get verify recover result fail!'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signature_recover_asynchronous')) - .width('70%') - .onClick(async () => { - try { - await main(); - this.message = 'SignatureRecoverSuccess'; - } catch { - this.message = 'SignatureRecoverFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|NoHash|OnlySign'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + let signData = await signer.sign(input1); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|NoHash|Recover'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + let rawSignData = await verifier.recover(signMessageBlob); + return rawSignData; +} + +async function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let rawSignData = await verifyMessagePromise(signData, keyPair.pubKey); + if (rawSignData != null) { + console.info('recover result: ' + rawSignData.data); + } else { + console.error('get verify recover result fail!'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_recover_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'SignatureRecoverSuccess'; + } catch { + this.message = 'SignatureRecoverFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets old mode 100755 new mode 100644 index 10670f5c2135184a393fadf1afb9cdf675b09dfd..013c36664049c815d62134fec855c6f7f563e863 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets @@ -1,73 +1,73 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; - -function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'RSA1024|PKCS1|NoHash|OnlySign'; - let signer = cryptoFramework.createSign(signAlg); - signer.initSync(priKey); - let signData = signer.signSync(input1); - return signData; -} - -function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'RSA1024|PKCS1|NoHash|Recover'; - let verifier = cryptoFramework.createVerify(verifyAlg); - verifier.initSync(pubKey); - let rawSignData = verifier.recoverSync(signMessageBlob); - return rawSignData; -} - -function main() { - let keyGenAlg = 'RSA1024'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = generator.generateKeyPairSync(); - let signData = signMessagePromise(keyPair.priKey); - let rawSignData = verifyMessagePromise(signData, keyPair.pubKey); - if (rawSignData != null) { - console.info('recover result: ' + rawSignData.data); - } else { - console.error('get verify recover result fail!'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signature_recover_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SignatureRecoverSuccess'; - } catch { - this.message = 'SignatureRecoverFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|NoHash|OnlySign'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + let signData = signer.signSync(input1); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|NoHash|Recover'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + let rawSignData = verifier.recoverSync(signMessageBlob); + return rawSignData; +} + +function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let rawSignData = verifyMessagePromise(signData, keyPair.pubKey); + if (rawSignData != null) { + console.info('recover result: ' + rawSignData.data); + } else { + console.error('get verify recover result fail!'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_recover_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SignatureRecoverSuccess'; + } catch { + this.message = 'SignatureRecoverFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets old mode 100755 new mode 100644 index f3167dec5e8f2b0f2798716cbdd0d1c4cb47a98d..ef202246e3776708b0f0616c9b7f22ebde8ffb29 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets @@ -1,77 +1,77 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; -let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; - -async function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'RSA1024|PKCS1|SHA256'; - let signer = cryptoFramework.createSign(signAlg); - await signer.init(priKey); - await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 - let signData = await signer.sign(input2); - return signData; -} - -async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'RSA1024|PKCS1|SHA256'; - let verifier = cryptoFramework.createVerify(verifyAlg); - await verifier.init(pubKey); - await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 - let res = await verifier.verify(input2, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -async function main() { - let keyGenAlg = 'RSA1024'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = await generator.generateKeyPair(); - let signData = await signMessagePromise(keyPair.priKey); - let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signature_verify_asynchronous')) - .width('70%') - .onClick(async() => { - try { - await main(); - this.message = 'SignatureVerifySuccess'; - } catch { - this.message = 'SignatureVerifyFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = await signer.sign(input2); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = await verifier.verify(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_verify_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await main(); + this.message = 'SignatureVerifySuccess'; + } catch { + this.message = 'SignatureVerifyFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets old mode 100755 new mode 100644 index b31f42f839729acbc119b70c384f00a786570c36..af5f5f7a31d9f6d6e9801cb974692373638bdb05 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets @@ -1,77 +1,77 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; -let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; - -function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'RSA1024|PKCS1|SHA256'; - let signer = cryptoFramework.createSign(signAlg); - signer.initSync(priKey); - signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 - let signData = signer.signSync(input2); - return signData; -} - -function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'RSA1024|PKCS1|SHA256'; - let verifier = cryptoFramework.createVerify(verifyAlg); - verifier.initSync(pubKey); - verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 - let res = verifier.verifySync(input2, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -function main() { - let keyGenAlg = 'RSA1024'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = generator.generateKeyPairSync(); - let signData = signMessagePromise(keyPair.priKey); - let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_signature_verify_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SignatureVerifySuccess'; - } catch { - this.message = 'SignatureVerifyFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = signer.signSync(input2); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = verifier.verifySync(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_verify_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SignatureVerifySuccess'; + } catch { + this.message = 'SignatureVerifyFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets old mode 100755 new mode 100644 index 3a57c49f4f8ff678e5e99bcc86c228175998ce5f..5e67a8f9b82f0d0a0587b14cf6f76d2bca3a4b1e --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets @@ -1,127 +1,127 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 根据密钥参数属性构造RSA非对称密钥对密钥参数 -function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { - let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { - n: nIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC - }; - let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { - params: rsaCommSpec, - sk: dIn, - pk: eIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC - }; - return rsaKeyPairSpec; -} - -// 生成RSA2048密钥对参数 -function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { - let nIn = - BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc432' + - '8daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4' + - 'd933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac' + - '59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e2' + - '53f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); - let eIn = BigInt('0x010001'); - let dIn = - BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb3' + - '06aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8' + - 'bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b275' + - '06c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde721' + - '26b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); - return genRsaKeyPairSpec(nIn, eIn, dIn); -} - -async function verifyMessagePSS() { - // 完整的明文被拆分为input1和input2 - let plan1 = 'This is Sign test plan1'; - let plan2 = 'This is Sign test plan2'; - let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan1, 'utf-8').buffer) }; - let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan2, 'utf-8').buffer) }; - // 获得RSA密钥对密钥参数对象 - let rsaKeyPairSpec = genRsa2048KeyPairSpec(); - // 构造RSA密钥对生成器 - let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); - // sign和verfiy均支持RSA密钥带长度/不带长度的写法 - let signer = cryptoFramework.createSign('RSA|PSS|SHA256|MGF1_SHA256'); - let verifyer = cryptoFramework.createVerify('RSA2048|PSS|SHA256|MGF1_SHA256'); - let keyPair = await rsaGeneratorSpec.generateKeyPair(); - await signer.init(keyPair.priKey); - // 在签名初始化后,对PSS参数进行set和get操作 - let setN = 32; - signer.setSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); - let saltLen = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); - console.info('SaltLen == ' + saltLen); - let tf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); - console.info('trailer field == ' + tf); - let md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); - console.info('md == ' + md); - let mgf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); - console.info('mgf == ' + mgf); - let mgf1Md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); - console.info('mgf1Md == ' + mgf1Md); - await signer.update(input1); - let signMessageBlob = await signer.sign(input2); - // 在验签初始化前,对PSS参数进行set和get操作 - verifyer.setVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); - saltLen = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); - console.info('SaltLen == ' + saltLen); - tf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); - console.info('trailer field == ' + tf); - md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); - console.info('md == ' + md); - mgf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); - console.info('mgf == ' + mgf); - mgf1Md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); - await verifyer.init(keyPair.pubKey); - await verifyer.update(input1); - let verifyResult = await verifyer.verify(input2, signMessageBlob); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_psssignatureseg_asynchronous')) - .width('70%') - .onClick(async() => { - try { - await verifyMessagePSS(); - this.message = 'PSSSignatureSegSuccess'; - } catch { - this.message = 'PSSSignatureSegFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 根据密钥参数属性构造RSA非对称密钥对密钥参数 +function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: dIn, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC + }; + return rsaKeyPairSpec; +} + +// 生成RSA2048密钥对参数 +function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc432' + + '8daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4' + + 'd933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac' + + '59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e2' + + '53f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + let dIn = + BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb3' + + '06aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8' + + 'bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b275' + + '06c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde721' + + '26b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); + return genRsaKeyPairSpec(nIn, eIn, dIn); +} + +async function verifyMessagePSS() { + // 完整的明文被拆分为input1和input2 + let plan1 = 'This is Sign test plan1'; + let plan2 = 'This is Sign test plan2'; + let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan1, 'utf-8').buffer) }; + let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan2, 'utf-8').buffer) }; + // 获得RSA密钥对密钥参数对象 + let rsaKeyPairSpec = genRsa2048KeyPairSpec(); + // 构造RSA密钥对生成器 + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + // sign和verfiy均支持RSA密钥带长度/不带长度的写法 + let signer = cryptoFramework.createSign('RSA|PSS|SHA256|MGF1_SHA256'); + let verifyer = cryptoFramework.createVerify('RSA2048|PSS|SHA256|MGF1_SHA256'); + let keyPair = await rsaGeneratorSpec.generateKeyPair(); + await signer.init(keyPair.priKey); + // 在签名初始化后,对PSS参数进行set和get操作 + let setN = 32; + signer.setSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + let saltLen = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + let tf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + let md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + let mgf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + let mgf1Md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + await signer.update(input1); + let signMessageBlob = await signer.sign(input2); + // 在验签初始化前,对PSS参数进行set和get操作 + verifyer.setVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + saltLen = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + tf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + mgf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + mgf1Md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + await verifyer.init(keyPair.pubKey); + await verifyer.update(input1); + let verifyResult = await verifyer.verify(input2, signMessageBlob); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_psssignatureseg_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await verifyMessagePSS(); + this.message = 'PSSSignatureSegSuccess'; + } catch { + this.message = 'PSSSignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets old mode 100755 new mode 100644 index f6656e9c4ec10fe217f9557f117e9c971afab40b..fd4f9257b3fe3f7f2d99ab9638d622f3669df9ae --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets @@ -1,127 +1,127 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 根据密钥参数属性构造RSA非对称密钥对密钥参数 -function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { - let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { - n: nIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC - }; - let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { - params: rsaCommSpec, - sk: dIn, - pk: eIn, - algName: 'RSA', - specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC - }; - return rsaKeyPairSpec; -} - -// 生成RSA2048密钥对参数 -function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { - let nIn = - BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc43' + - '28daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34' + - 'e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa' + - '7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589' + - 'c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); - let eIn = BigInt('0x010001'); - let dIn = - BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb' + - '306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283a' + - 'd8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b' + - '27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdd' + - 'e72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); - return genRsaKeyPairSpec(nIn, eIn, dIn); -} - -function verifyMessagePSS() { - // 完整的明文被拆分为input1和input2 - let plan1 = 'This is Sign test plan1'; - let plan2 = 'This is Sign test plan2'; - let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan1, 'utf-8').buffer) }; - let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan2, 'utf-8').buffer) }; - // 获得RSA密钥对密钥参数对象 - let rsaKeyPairSpec = genRsa2048KeyPairSpec(); - // 构造RSA密钥对生成器 - let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); - // sign和verfiy均支持RSA密钥带长度/不带长度的写法 - let signer = cryptoFramework.createSign('RSA|PSS|SHA256|MGF1_SHA256'); - let verifyer = cryptoFramework.createVerify('RSA2048|PSS|SHA256|MGF1_SHA256'); - let keyPair = rsaGeneratorSpec.generateKeyPairSync(); - signer.initSync(keyPair.priKey); - // 在签名初始化后,对PSS参数进行set和get操作 - let setN = 32; - signer.setSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); - let saltLen = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); - console.info('SaltLen == ' + saltLen); - let tf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); - console.info('trailer field == ' + tf); - let md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); - console.info('md == ' + md); - let mgf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); - console.info('mgf == ' + mgf); - let mgf1Md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); - console.info('mgf1Md == ' + mgf1Md); - signer.updateSync(input1); - let signMessageBlob = signer.signSync(input2); - // 在验签初始化前,对PSS参数进行set和get操作 - verifyer.setVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); - saltLen = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); - console.info('SaltLen == ' + saltLen); - tf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); - console.info('trailer field == ' + tf); - md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); - console.info('md == ' + md); - mgf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); - console.info('mgf == ' + mgf); - mgf1Md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); - verifyer.initSync(keyPair.pubKey); - verifyer.updateSync(input1); - let verifyResult = verifyer.verifySync(input2, signMessageBlob); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_psssignatureseg_synchronous')) - .width('70%') - .onClick(() => { - try { - verifyMessagePSS(); - this.message = 'PSSSignatureSegSuccess'; - } catch { - this.message = 'PSSSignatureSegFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 根据密钥参数属性构造RSA非对称密钥对密钥参数 +function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: dIn, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC + }; + return rsaKeyPairSpec; +} + +// 生成RSA2048密钥对参数 +function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc43' + + '28daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34' + + 'e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa' + + '7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589' + + 'c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + let dIn = + BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb' + + '306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283a' + + 'd8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b' + + '27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdd' + + 'e72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); + return genRsaKeyPairSpec(nIn, eIn, dIn); +} + +function verifyMessagePSS() { + // 完整的明文被拆分为input1和input2 + let plan1 = 'This is Sign test plan1'; + let plan2 = 'This is Sign test plan2'; + let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan1, 'utf-8').buffer) }; + let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan2, 'utf-8').buffer) }; + // 获得RSA密钥对密钥参数对象 + let rsaKeyPairSpec = genRsa2048KeyPairSpec(); + // 构造RSA密钥对生成器 + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + // sign和verfiy均支持RSA密钥带长度/不带长度的写法 + let signer = cryptoFramework.createSign('RSA|PSS|SHA256|MGF1_SHA256'); + let verifyer = cryptoFramework.createVerify('RSA2048|PSS|SHA256|MGF1_SHA256'); + let keyPair = rsaGeneratorSpec.generateKeyPairSync(); + signer.initSync(keyPair.priKey); + // 在签名初始化后,对PSS参数进行set和get操作 + let setN = 32; + signer.setSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + let saltLen = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + let tf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + let md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + let mgf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + let mgf1Md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + signer.updateSync(input1); + let signMessageBlob = signer.signSync(input2); + // 在验签初始化前,对PSS参数进行set和get操作 + verifyer.setVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + saltLen = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + tf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + mgf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + mgf1Md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + verifyer.initSync(keyPair.pubKey); + verifyer.updateSync(input1); + let verifyResult = verifyer.verifySync(input2, signMessageBlob); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_psssignatureseg_synchronous')) + .width('70%') + .onClick(() => { + try { + verifyMessagePSS(); + this.message = 'PSSSignatureSegSuccess'; + } catch { + this.message = 'PSSSignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets old mode 100755 new mode 100644 index ba4b7a569dddc4d6a6b96f04592e61cf60f1a0bb..c8c9e2e727601486348b5ea5104bc8cd3b01c2e5 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets @@ -1,77 +1,77 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; -let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; - -async function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'SM2_256|SM3'; - let signer = cryptoFramework.createSign(signAlg); - await signer.init(priKey); - await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 - let signData = await signer.sign(input2); - return signData; -} - -async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'SM2_256|SM3'; - let verifier = cryptoFramework.createVerify(verifyAlg); - await verifier.init(pubKey); - await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 - let res = await verifier.verify(input2, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -async function main() { - let keyGenAlg = 'SM2_256'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = await generator.generateKeyPair(); - let signData = await signMessagePromise(keyPair.priKey); - let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_signature_asynchronous')) - .width('70%') - .onClick(async() => { - try { - await main(); - this.message = 'SM2SignatureSuccess'; - } catch { - this.message = 'SM2SignatureFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'SM2_256|SM3'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = await signer.sign(input2); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'SM2_256|SM3'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = await verifier.verify(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function main() { + let keyGenAlg = 'SM2_256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_signature_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await main(); + this.message = 'SM2SignatureSuccess'; + } catch { + this.message = 'SM2SignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets old mode 100755 new mode 100644 index 62e71435109d9b09f0c81612c229751c710e6c0b..9c5748f840a73314d16dacbea3714844fc31d3bb --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets @@ -1,77 +1,77 @@ -/* - * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { buffer } from '@kit.ArkTS'; - -// 完整的明文被拆分为input1和input2 -let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; -let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; - -function signMessagePromise(priKey: cryptoFramework.PriKey) { - let signAlg = 'SM2_256|SM3'; - let signer = cryptoFramework.createSign(signAlg); - signer.initSync(priKey); - signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 - let signData = signer.signSync(input2); - return signData; -} - -function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { - let verifyAlg = 'SM2_256|SM3'; - let verifier = cryptoFramework.createVerify(verifyAlg); - verifier.initSync(pubKey); - verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 - let res = verifier.verifySync(input2, signMessageBlob); - console.info('verify result is ' + res); - return res; -} - -function main() { - let keyGenAlg = 'SM2_256'; - let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); - let keyPair = generator.generateKeyPairSync(); - let signData = signMessagePromise(keyPair.priKey); - let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); - if (verifyResult === true) { - console.info('verify success'); - } else { - console.error('verify failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'Signing Signature Verification'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) - Button($r('app.string.call_sm2_signature_synchronous')) - .width('70%') - .onClick(() => { - try { - main(); - this.message = 'SM2SignatureSuccess'; - } catch { - this.message = 'SM2SignatureFail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'SM2_256|SM3'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = signer.signSync(input2); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'SM2_256|SM3'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = verifier.verifySync(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function main() { + let keyGenAlg = 'SM2_256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_signature_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SM2SignatureSuccess'; + } catch { + this.message = 'SM2SignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/mock/mock-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/mock/mock-config.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets old mode 100755 new mode 100644 index 62f8fd0ec5ab67ba0f1e87f47e99ad3c9cc801b9..13f32fba0ac84f371741e370e6a9a6b029b53d17 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets @@ -1,259 +1,259 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function signingSignatureVerificationArkTsTest() { - describe('signingSignatureVerificationArkTsTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(异步) - */ - it('signingSignatureVerificationArkTsTest001', 0, async () => { - console.info('uitest: signingSignatureVerificationArkTsTest001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_validator_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SignatureVerify Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureVerifySuccess')); - console.info('uitest: signingSignatureVerificationArkTsTest001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(同步) - */ - it('testSigningSignatureVerificationArkTsTest002', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_validator_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SignatureVerify Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureVerifySuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(异步) - */ - it('testSigningSignatureVerificationArkTsTest003', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_restoration_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SignatureRecover Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureRecoverSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(同步) - */ - it('testSigningSignatureVerificationArkTsTest004', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_restoration_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SignatureRecover Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureRecoverSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(异步) - */ - it('testSigningSignatureVerificationArkTsTest005', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pkcs1_segment_signature_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SignatureSeg Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureSegSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(同步) - */ - it('testSigningSignatureVerificationArkTsTest006', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest006 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pkcs1_segment_signature_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SignatureSeg Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SignatureSegSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest006 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对签名验签(PSS模式)(异步) - */ - it('testSigningSignatureVerificationArkTsTest007', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest007 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pss_signature_verification_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call PSSSignatureSeg Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest007 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用RSA密钥对签名验签(PSS模式)(同步) - */ - it('testSigningSignatureVerificationArkTsTest008', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest008 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('rsa_pss_signature_verification_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call PSSSignatureSeg Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest008 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用ECDSA密钥对签名验签(异步) - */ - it('testSigningSignatureVerificationArkTsTest009', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest009 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ecdsa_signature_verification_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call ECDSASignature Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECDSASignatureSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest009 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用ECDSA密钥对签名验签(同步) - */ - it('testSigningSignatureVerificationArkTsTest010', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest010 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ecdsa_signature_verification_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call ECDSASignature Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECDSASignatureSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest010 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM2密钥对签名验签(异步) - */ - it('testSigningSignatureVerificationArkTsTest011', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest011 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm2_signature_verification_asynchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2Signature Asynchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2SignatureSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest011 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,使用SM2密钥对签名验签(同步) - */ - it('testSigningSignatureVerificationArkTsTest012', 0, async () => { - console.info('uitest: testSigningSignatureVerificationArkTsTest012 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('sm2_signature_verification_synchronous')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2Signature Synchronous')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2SignatureSuccess')); - console.info('uitest: testSigningSignatureVerificationArkTsTest012 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function signingSignatureVerificationArkTsTest() { + describe('signingSignatureVerificationArkTsTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(异步) + */ + it('signingSignatureVerificationArkTsTest001', 0, async () => { + console.info('uitest: signingSignatureVerificationArkTsTest001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_validator_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureVerify Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureVerifySuccess')); + console.info('uitest: signingSignatureVerificationArkTsTest001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(同步) + */ + it('testSigningSignatureVerificationArkTsTest002', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_validator_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureVerify Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureVerifySuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(异步) + */ + it('testSigningSignatureVerificationArkTsTest003', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_restoration_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureRecover Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureRecoverSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(同步) + */ + it('testSigningSignatureVerificationArkTsTest004', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_restoration_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureRecover Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureRecoverSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(异步) + */ + it('testSigningSignatureVerificationArkTsTest005', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_segment_signature_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureSeg Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(同步) + */ + it('testSigningSignatureVerificationArkTsTest006', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_segment_signature_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureSeg Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest006 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对签名验签(PSS模式)(异步) + */ + it('testSigningSignatureVerificationArkTsTest007', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest007 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pss_signature_verification_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call PSSSignatureSeg Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest007 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对签名验签(PSS模式)(同步) + */ + it('testSigningSignatureVerificationArkTsTest008', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest008 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pss_signature_verification_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call PSSSignatureSeg Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest008 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECDSA密钥对签名验签(异步) + */ + it('testSigningSignatureVerificationArkTsTest009', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest009 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ecdsa_signature_verification_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECDSASignature Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECDSASignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest009 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECDSA密钥对签名验签(同步) + */ + it('testSigningSignatureVerificationArkTsTest010', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest010 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ecdsa_signature_verification_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECDSASignature Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECDSASignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest010 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2密钥对签名验签(异步) + */ + it('testSigningSignatureVerificationArkTsTest011', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest011 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm2_signature_verification_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2Signature Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2SignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest011 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2密钥对签名验签(同步) + */ + it('testSigningSignatureVerificationArkTsTest012', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest012 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm2_signature_verification_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2Signature Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2SignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest012 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/List.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigor/hvigor-config.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigorfile.ts b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/oh-package.json5 b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/oh-package.json5 +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md old mode 100755 new mode 100644 index 63f32b67e527974bb01277c3ee6edb7acdb771ee..6ae3b3fcca5ba900ed20e4fa74ba0c98b5707441 --- a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md +++ b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md @@ -1,19 +1,19 @@ -# 签名验签(ArkTS)测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对签名验签(PSS模式)(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用RSA密钥对签名验签(PSS模式)(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用ECDSA密钥对签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用ECDSA密钥对签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,使用SM2密钥对签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 签名验签(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对签名验签(PSS模式)(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对签名验签(PSS模式)(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDSA密钥对签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDSA密钥对签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM2密钥对签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,使用SM2密钥对签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs1.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs2.png b/code/DocsSample/Security/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/.gitignore b/code/DocsSample/Security/DataProtectionKit/DataProtection/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/app.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/app.json5 old mode 100755 new mode 100644 index eac5feed4ed86536dd351c1f1ff70091cec6236f..2b91e37f4239866b5e128dfbd3e40b888ba2fc76 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/app.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/app.json5 @@ -1,25 +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.dataprotection", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.dataprotection", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/resources/base/element/string.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index a374075e4794aaa59c91496e0788f0cedcb5a997..ab466414a7c4200a1a3718c612470eb7ebd8f125 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DataProtection" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "DataProtection" + } + ] +} diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/DataProtectionKit/DataProtection/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/README.md b/code/DocsSample/Security/DataProtectionKit/DataProtection/README.md old mode 100755 new mode 100644 index 054fb72487d471e9d602e4b54e3de332c34f9d04..604f191cb2e483681965276449a654aef70deab0 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/README.md +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/README.md @@ -1,73 +1,73 @@ -# 数据防泄漏服务开发指导 - -### 介绍 - -DLP是系统提供的系统级的数据防泄漏解决方案,提供一种称为DLP的文件格式。后缀格式为“原始文件名(包含原始文件后缀).dlp”,例如“test.docx.dlp”,文件由授权凭证和原始文件密文组成。 - -应用需要访问DLP文件时,系统会自动安装应用的DLP沙箱分身应用,相当于完全独立的应用,数据和配置会继承原应用,但相互之间并不共享。分身应用在运行时会处于DLP沙箱环境中,访问外部的权限会被限制,以防止数据的泄漏。每当打开一个新的DLP文件会生成一个应用沙箱分身,沙箱应用之间也是相互隔离的,当应用关闭后应用分身会自动卸载,沙箱期间产生的临时数据也会丢弃。 - -正常情况下,应用不会感知到沙箱的存在,访问的也是解密后的明文,和访问普通文件没有区别,但由于DLP沙箱会限制其访问外部的权限(例如网络、剪切板、截屏、录屏、蓝牙等)。为了更好的用户体验,需要应用进行适配,例如文件只读的情况下,不应显示“保存”按钮,不应主动联网等。 - -本示例主要展示了数据防泄漏服务开发指导,该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [数据防泄漏服务开发指导](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DataProtectionKit/dlp-guidelines.md) - -### 效果预览 - -| 首页效果图 | -| ------------------------------------------------------------ | -| | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,并且具有说明账号未登录,请登录账号后重试的弹窗。 -3. 运行测试用例DataProtection.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 数据防泄漏服务开发指导示例代码 - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── DataProtection.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API16版本SDK,版本号:5.0.4.150,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.4 Release (Build Version: 5.0.11.100, built on March 28, 2025)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/DataProtectionKit/DataProtection > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -```` +# 数据防泄漏服务开发指导 + +### 介绍 + +DLP是系统提供的系统级的数据防泄漏解决方案,提供一种称为DLP的文件格式。后缀格式为“原始文件名(包含原始文件后缀).dlp”,例如“test.docx.dlp”,文件由授权凭证和原始文件密文组成。 + +应用需要访问DLP文件时,系统会自动安装应用的DLP沙箱分身应用,相当于完全独立的应用,数据和配置会继承原应用,但相互之间并不共享。分身应用在运行时会处于DLP沙箱环境中,访问外部的权限会被限制,以防止数据的泄漏。每当打开一个新的DLP文件会生成一个应用沙箱分身,沙箱应用之间也是相互隔离的,当应用关闭后应用分身会自动卸载,沙箱期间产生的临时数据也会丢弃。 + +正常情况下,应用不会感知到沙箱的存在,访问的也是解密后的明文,和访问普通文件没有区别,但由于DLP沙箱会限制其访问外部的权限(例如网络、剪切板、截屏、录屏、蓝牙等)。为了更好的用户体验,需要应用进行适配,例如文件只读的情况下,不应显示“保存”按钮,不应主动联网等。 + +本示例主要展示了数据防泄漏服务开发指导,该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [数据防泄漏服务开发指导](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DataProtectionKit/dlp-guidelines.md) + +### 效果预览 + +| 首页效果图 | +| ------------------------------------------------------------ | +| | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,并且具有说明账号未登录,请登录账号后重试的弹窗。 +3. 运行测试用例DataProtection.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 数据防泄漏服务开发指导示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── DataProtection.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API16版本SDK,版本号:5.0.4.150,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.4 Release (Build Version: 5.0.11.100, built on March 28, 2025)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/DataProtectionKit/DataProtection > .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/Security/DataProtectionKit/DataProtection/build-profile.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/build-profile.json5 old mode 100755 new mode 100644 index 9296ac913680eb0cb437bd2d19bc409f41f81eb6..5df1ab5a7f386827c40adac81b35b82af8656284 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/build-profile.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/build-profile.json5 @@ -1,58 +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": 16, - "compatibleSdkVersion": 16, - "targetSdkVersion": 16, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 16, + "compatibleSdkVersion": 16, + "targetSdkVersion": 16, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/code-linter.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/.gitignore b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/build-profile.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/build-profile.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/hvigorfile.ts b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/oh-package.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/oh-package.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/DataProtectionKit/DataProtection/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/module.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/module.json5 old mode 100755 new mode 100644 index 0dd84338e857581871455ef0df1888abfab10c32..3d70d2156811270de7297723818cb0f55de499c4 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/module.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/module.json5 @@ -1,67 +1,67 @@ -/* - * 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", - "ohos.want.action.viewData" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EntryBackupAbility", - "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - } - ] - } +/* + * 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", + "ohos.want.action.viewData" + ] + } + ] + } + ], + "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/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/DataProtection.test.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/DataProtection.test.ets old mode 100755 new mode 100644 index 5c631dc9e2b0115dc04c48ddbe18b3b4f4ed84a2..b0b578bb9c3874158f1b959e1ef3a757fe952180 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/DataProtection.test.ets +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/DataProtection.test.ets @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -export default function dataProtectionTest() { - describe('dataProtectionTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮关闭弹窗 - */ - it('testDataProtection001', 0, async () => { - console.info('uitest: testDataProtection001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text(resourceToString($r('app.string.button_name')))); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('DataProtection')); - console.info('uitest: testDataProtection001 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +export default function dataProtectionTest() { + describe('dataProtectionTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮关闭弹窗 + */ + it('testDataProtection001', 0, async () => { + console.info('uitest: testDataProtection001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text(resourceToString($r('app.string.button_name')))); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('DataProtection')); + console.info('uitest: testDataProtection001 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/DataProtectionKit/DataProtection/entry/src/test/List.test.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/DataProtectionKit/DataProtection/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/hvigor/hvigor-config.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/DataProtectionKit/DataProtection/hvigorfile.ts b/code/DocsSample/Security/DataProtectionKit/DataProtection/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/oh-package.json5 b/code/DocsSample/Security/DataProtectionKit/DataProtection/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/oh-package.json5 +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/DataProtectionKit/DataProtection/ohosTest.md b/code/DocsSample/Security/DataProtectionKit/DataProtection/ohosTest.md old mode 100755 new mode 100644 index 214332ec2316b2fe1e2eb9e47fdb657e7f27ce2b..e34db9d8f9dbabc414d675532e668805288bf846 --- a/code/DocsSample/Security/DataProtectionKit/DataProtection/ohosTest.md +++ b/code/DocsSample/Security/DataProtectionKit/DataProtection/ohosTest.md @@ -1,8 +1,8 @@ -# 数据防泄漏服务开发指导测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------ | ------------ | ---- | ------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +# 数据防泄漏服务开发指导测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------ | ------------ | ---- | ------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | | 页面正确显示 | 成功拉起应用 | | 页面成功弹窗 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/DataProtectionKit/DataProtection/screenshots/DataProtection.png b/code/DocsSample/Security/DataProtectionKit/DataProtection/screenshots/DataProtection.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/.gitignore b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/app.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/app.json5 old mode 100755 new mode 100644 index 68bab6dbc2a2fe3c4d7c18430d034f28958877d3..801e86b73888d0950ee8e5cdb105e063820226a9 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/app.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/app.json5 @@ -1,25 +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.certificatealgorithmlibrary", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.certificatealgorithmlibrary", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 000f0d375b08a33696e64dd5c2226470d5116cf2..ad134223d3d57d15e5b21ae6072ab7faabd7981e --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "CertificateAlgorithmLibrary" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "CertificateAlgorithmLibrary" + } + ] +} diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md old mode 100755 new mode 100644 index 62e61b7e33edfd957a072e4a784a6de40e062977..c246f8945f6d39614934c4cbe829988a689e698c --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/README.md @@ -1,82 +1,82 @@ -# 证书算法库 - -### 介绍 - -证书算法库框架是一个屏蔽了第三方算法库实现差异的证书算法框架,向应用提供证书、证书扩展域段、证书吊销列表的创建、解析及校验能力,此外还提供了证书链的校验能力。 - -本示例主要展示了证书算法库中证书对象的创建、证书扩展信息对象的创建、证书吊销列表对象的创建、证书链校验时从p12文件构造TrustAnchor对象数组、证书链校验器对象的创建和校验、证书集合及证书吊销列表集合对象的创建和获取、证书链对象的创建和校验的场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 - -- [证书对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-cert-object.md) -- [证书扩展信息对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-certextension-object.md) -- [证书吊销列表对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-crl-object.md) -- [证书链校验时从p12文件构造TrustAnchor对象数组](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-trustanchor-from-p12.md) -- [证书链校验器对象的创建和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-verify-cerchainvalidator-object.md) -- [证书集合及证书吊销列表集合对象的创建和获取](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-get-cert-crl-object.md) -- [证书链对象的创建和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-verify-certchain-object.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例CertificateAlgorithmLibrary.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 证书算法库示例代码 - │ │ ├── CreateGetCertCrlObject.ets - │ │ ├── CreateParseVerifyCertextensionObject.ets - │ │ ├── CreateParseVerifyCertObject.ets - │ │ ├── CreateParseVerifyCrlObject.ets - │ │ ├── CreateTrustanchorFromP12.ets - │ │ ├── CreateVerifyCerchainvalidatorObject.ets - │ │ ├── CreateVerifyCertchainObject.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── CertificateAlgorithmLibrary.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 证书算法库 + +### 介绍 + +证书算法库框架是一个屏蔽了第三方算法库实现差异的证书算法框架,向应用提供证书、证书扩展域段、证书吊销列表的创建、解析及校验能力,此外还提供了证书链的校验能力。 + +本示例主要展示了证书算法库中证书对象的创建、证书扩展信息对象的创建、证书吊销列表对象的创建、证书链校验时从p12文件构造TrustAnchor对象数组、证书链校验器对象的创建和校验、证书集合及证书吊销列表集合对象的创建和获取、证书链对象的创建和校验的场景。该工程中展示的代码详细描述可查如下链接中业务扩展场景介绍部分。 + +- [证书对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-cert-object.md) +- [证书扩展信息对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-certextension-object.md) +- [证书吊销列表对象的创建、解析和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-parse-verify-crl-object.md) +- [证书链校验时从p12文件构造TrustAnchor对象数组](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-trustanchor-from-p12.md) +- [证书链校验器对象的创建和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-verify-cerchainvalidator-object.md) +- [证书集合及证书吊销列表集合对象的创建和获取](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-get-cert-crl-object.md) +- [证书链对象的创建和校验](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/create-verify-certchain-object.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例CertificateAlgorithmLibrary.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 证书算法库示例代码 + │ │ ├── CreateGetCertCrlObject.ets + │ │ ├── CreateParseVerifyCertextensionObject.ets + │ │ ├── CreateParseVerifyCertObject.ets + │ │ ├── CreateParseVerifyCrlObject.ets + │ │ ├── CreateTrustanchorFromP12.ets + │ │ ├── CreateVerifyCerchainvalidatorObject.ets + │ │ ├── CreateVerifyCertchainObject.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── CertificateAlgorithmLibrary.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/code-linter.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/.gitignore b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/hvigorfile.ts b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/oh-package.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/oh-package.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets old mode 100755 new mode 100644 index c560f710edbf70c5184e06a129a51e3364e519ed..1832bd955a74167864aff9ea4a19b7c09a2a7efd --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateGetCertCrlObject.ets @@ -1,130 +1,130 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { util } from '@kit.ArkTS'; - -async function createX509CRL(): Promise { - let crlData = '-----BEGIN X509 CRL-----\n' + - 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + - 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + - 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + - 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + - '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + - 'eavsH0Q3\n' + - '-----END X509 CRL-----\n'; - - // 证书吊销列表二进制数据,需业务自行赋值 - let textEncoder = new util.TextEncoder(); - let encodingBlob: cert.EncodingBlob = { - data: textEncoder.encodeInto(crlData), - // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - let x509CRL: cert.X509CRL = {} as cert.X509CRL; - try { - x509CRL = await cert.createX509CRL(encodingBlob); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`createX509CRL failed, errCode: ${e.code}, errMsg: ${e.message}`); - } - return x509CRL; -} - -async function createX509Cert(): Promise { - let certData = '-----BEGIN CERTIFICATE-----\n' + - 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + - 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + - 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + - 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + - 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + - 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + - 'Qw==\n' + - '-----END CERTIFICATE-----\n'; - - let textEncoder = new util.TextEncoder(); - let encodingBlob: cert.EncodingBlob = { - data: textEncoder.encodeInto(certData), - // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - - let x509Cert: cert.X509Cert = {} as cert.X509Cert; - try { - x509Cert = await cert.createX509Cert(encodingBlob); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`createX509Cert failed, errCode: ${e.code}, errMsg: ${e.message}`); - } - return x509Cert; -} - -async function sample() { - const x509Cert = await createX509Cert(); - const x509CRL = await createX509CRL(); - let collection: cert.CertCRLCollection = {} as cert.CertCRLCollection; - try { - collection = cert.createCertCRLCollection([x509Cert], [x509CRL]); - console.log('createCertCRLCollection success'); - } catch (err) { - console.error('createCertCRLCollection failed'); - } - - const certParam: cert.X509CertMatchParameters = { - validDate: '231128000000Z' - } - try { - let certs: cert.X509Cert[] = await collection.selectCerts(certParam); - } catch (err) { - console.error('selectCerts failed'); - } - - const crlParam: cert.X509CRLMatchParameters = { - x509Cert: x509Cert - } - try { - let crls: cert.X509CRL[] = await collection.selectCRLs(crlParam); - console.error('selectCRLs success'); - } catch (err) { - console.error('selectCRLs failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'CreateGetCertCrlObject'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateGetCertCrlObject') - .width('70%') - .onClick(() => { - try { - sample(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +async function createX509CRL(): Promise { + let crlData = '-----BEGIN X509 CRL-----\n' + + 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + + 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + + 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + + 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + + '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + + 'eavsH0Q3\n' + + '-----END X509 CRL-----\n'; + + // 证书吊销列表二进制数据,需业务自行赋值 + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(crlData), + // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + let x509CRL: cert.X509CRL = {} as cert.X509CRL; + try { + x509CRL = await cert.createX509CRL(encodingBlob); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`createX509CRL failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + return x509CRL; +} + +async function createX509Cert(): Promise { + let certData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + + 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + + 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + + 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + + 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + + 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + + 'Qw==\n' + + '-----END CERTIFICATE-----\n'; + + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(certData), + // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + let x509Cert: cert.X509Cert = {} as cert.X509Cert; + try { + x509Cert = await cert.createX509Cert(encodingBlob); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`createX509Cert failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + return x509Cert; +} + +async function sample() { + const x509Cert = await createX509Cert(); + const x509CRL = await createX509CRL(); + let collection: cert.CertCRLCollection = {} as cert.CertCRLCollection; + try { + collection = cert.createCertCRLCollection([x509Cert], [x509CRL]); + console.log('createCertCRLCollection success'); + } catch (err) { + console.error('createCertCRLCollection failed'); + } + + const certParam: cert.X509CertMatchParameters = { + validDate: '231128000000Z' + } + try { + let certs: cert.X509Cert[] = await collection.selectCerts(certParam); + } catch (err) { + console.error('selectCerts failed'); + } + + const crlParam: cert.X509CRLMatchParameters = { + x509Cert: x509Cert + } + try { + let crls: cert.X509CRL[] = await collection.selectCRLs(crlParam); + console.error('selectCRLs success'); + } catch (err) { + console.error('selectCRLs failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'CreateGetCertCrlObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateGetCertCrlObject') + .width('70%') + .onClick(() => { + try { + sample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets old mode 100755 new mode 100644 index b782420c88a2aeb4ee3eb263ec2d24f81ce03c78..8f36cba15f27c876dbf44d730eb275b745e78742 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertObject.ets @@ -1,111 +1,111 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { util } from '@kit.ArkTS'; - -// 此处仅为示例的证书二进制数据,需根据业务的不同对证书数据进行赋值 -let certData = '-----BEGIN CERTIFICATE-----\n' + - 'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' + - 'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' + - 'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' + - 'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' + - 'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' + - '0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' + - 'BetUokslUfjT6+s/X4ByaxycAA==\n' + - '-----END CERTIFICATE-----\n'; - -// 证书示例 -function certSample(): void { - let textEncoder = new util.TextEncoder(); - let encodingBlob: cert.EncodingBlob = { - // 将证书数据从string类型转换成Unit8Array - data: textEncoder.encodeInto(certData), - // 证书格式,仅支持PEM和DER。在此示例中,证书为PEM格式 - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - - // 创建X509Cert实例 - cert.createX509Cert(encodingBlob, (err, x509Cert) => { - if (err != null) { - // 创建X509Cert实例失败 - console.error(`createX509Cert failed, errCode:${err.code}, errMsg:${err.message}`); - return; - } - // X509Cert实例创建成功 - console.log('createX509Cert success'); - - // 获取证书版本 - let version = x509Cert.getVersion(); - let serial = x509Cert.getCertSerialNumber(); - console.log(`X509 version: ${version} , X509 serial:${serial}`); - - // 使用上级证书对象的getPublicKey()方法或本(自签名)证书对象获取公钥对象 - try { - let pubKey = x509Cert.getPublicKey(); - // 验证证书签名 - x509Cert.verify(pubKey, (err, data) => { - if (err == null) { - // 签名验证成功 - console.log('verify success'); - } else { - // 签名验证失败 - console.error(`verify failed, errCode: ${err.code} , errMsg:${err.message}`); - } - }); - } catch (error) { - let e: BusinessError = error as BusinessError; - console.error(`getPublicKey failed, errCode: ${e.code} , errMsg:${e.message}`); - } - - // 用一个字符串代表时间 - let date = '20230930000001Z'; - - // 验证证书的有效期 - try { - x509Cert.checkValidityWithDate(date); - } catch (error) { - let e: BusinessError = error as BusinessError; - console.error(`checkValidityWithDate failed, errCode: ${e.code}, errMsg:${e.message}`); - } - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'CreateParseVerifyCertObject'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateParseVerifyCertObject') - .width('70%') - .onClick(()=>{ - try { - certSample(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +// 此处仅为示例的证书二进制数据,需根据业务的不同对证书数据进行赋值 +let certData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' + + 'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' + + 'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' + + 'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' + + 'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' + + '0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' + + 'BetUokslUfjT6+s/X4ByaxycAA==\n' + + '-----END CERTIFICATE-----\n'; + +// 证书示例 +function certSample(): void { + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + // 将证书数据从string类型转换成Unit8Array + data: textEncoder.encodeInto(certData), + // 证书格式,仅支持PEM和DER。在此示例中,证书为PEM格式 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + // 创建X509Cert实例 + cert.createX509Cert(encodingBlob, (err, x509Cert) => { + if (err != null) { + // 创建X509Cert实例失败 + console.error(`createX509Cert failed, errCode:${err.code}, errMsg:${err.message}`); + return; + } + // X509Cert实例创建成功 + console.log('createX509Cert success'); + + // 获取证书版本 + let version = x509Cert.getVersion(); + let serial = x509Cert.getCertSerialNumber(); + console.log(`X509 version: ${version} , X509 serial:${serial}`); + + // 使用上级证书对象的getPublicKey()方法或本(自签名)证书对象获取公钥对象 + try { + let pubKey = x509Cert.getPublicKey(); + // 验证证书签名 + x509Cert.verify(pubKey, (err, data) => { + if (err == null) { + // 签名验证成功 + console.log('verify success'); + } else { + // 签名验证失败 + console.error(`verify failed, errCode: ${err.code} , errMsg:${err.message}`); + } + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`getPublicKey failed, errCode: ${e.code} , errMsg:${e.message}`); + } + + // 用一个字符串代表时间 + let date = '20230930000001Z'; + + // 验证证书的有效期 + try { + x509Cert.checkValidityWithDate(date); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`checkValidityWithDate failed, errCode: ${e.code}, errMsg:${e.message}`); + } + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'CreateParseVerifyCertObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateParseVerifyCertObject') + .width('70%') + .onClick(()=>{ + try { + certSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets old mode 100755 new mode 100644 index 395b7256232cae553fb0ac5f06e591d1fc5a05de..51c6822d9c283b79bed41b8c57842ce14c9b1de1 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCertextensionObject.ets @@ -1,96 +1,96 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { util } from '@kit.ArkTS'; - -// 证书扩展数据,以下只是一个示例。需要根据具体业务来赋值 -let extData = new Uint8Array([ - 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, - 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, - 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, - 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, - 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, - 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, - 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, - 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, - 0xD9, 0xE4 -]); - -// 证书扩展示例 -function certExtensionSample(): void { - let textEncoder = new util.TextEncoder(); - let encodingBlob: cert.EncodingBlob = { - data: extData, - // 证书扩展格式,目前仅支持DER格式 - encodingFormat: cert.EncodingFormat.FORMAT_DER - }; - - // 创建一个证书扩展实例 - cert.createCertExtension(encodingBlob, (err, certExtension) => { - if (err != null) { - // 证书扩展实例创建失败 - console.error(`createCertExtension failed, errCode:${err.code}, errMsg:${err.message} `); - return; - } - // 证书扩展实例创建成功 - console.log('createCertExtension success'); - - try { - // 根据OID获取证书扩展信息 - let oidData = '2.5.29.14'; - let oid: cert.DataBlob = { - data: textEncoder.encodeInto(oidData), - } - let entry = certExtension.getEntry(cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, oid); - - // 检查证书是否为CA证书 - let pathLen = certExtension.checkCA(); - console.log('test cert extension success'); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`operation failed, message:${e.message} ,code:${e.code} `); - } - }); -} - - - -@Entry -@Component -struct Index { - @State message: string = 'CreateParseVerifyCertextensionObject'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateParseVerifyCertextensionObject') - .width('70%') - .onClick(()=>{ - try { - certExtensionSample(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +// 证书扩展数据,以下只是一个示例。需要根据具体业务来赋值 +let extData = new Uint8Array([ + 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, + 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, + 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, + 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, + 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, + 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, + 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, + 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, + 0xD9, 0xE4 +]); + +// 证书扩展示例 +function certExtensionSample(): void { + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + data: extData, + // 证书扩展格式,目前仅支持DER格式 + encodingFormat: cert.EncodingFormat.FORMAT_DER + }; + + // 创建一个证书扩展实例 + cert.createCertExtension(encodingBlob, (err, certExtension) => { + if (err != null) { + // 证书扩展实例创建失败 + console.error(`createCertExtension failed, errCode:${err.code}, errMsg:${err.message} `); + return; + } + // 证书扩展实例创建成功 + console.log('createCertExtension success'); + + try { + // 根据OID获取证书扩展信息 + let oidData = '2.5.29.14'; + let oid: cert.DataBlob = { + data: textEncoder.encodeInto(oidData), + } + let entry = certExtension.getEntry(cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, oid); + + // 检查证书是否为CA证书 + let pathLen = certExtension.checkCA(); + console.log('test cert extension success'); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`operation failed, message:${e.message} ,code:${e.code} `); + } + }); +} + + + +@Entry +@Component +struct Index { + @State message: string = 'CreateParseVerifyCertextensionObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateParseVerifyCertextensionObject') + .width('70%') + .onClick(()=>{ + try { + certExtensionSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets old mode 100755 new mode 100644 index 51ec07c776883cba5911c7e00c9278d0d1bd239f..65add36150488401c8ec86f3dc987daf10c5330e --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateParseVerifyCrlObject.ets @@ -1,199 +1,199 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { cryptoFramework } from '@kit.CryptoArchitectureKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { util } from '@kit.ArkTS'; - -// CRL数据,以下只是一个示例,需要根据具体业务来赋值 -let crlData = '-----BEGIN X509 CRL-----\n' + - 'MIIByzCBtAIBATANBgkqhkiG9w0BAQsFADBXMQswCQYDVQQGEwJDTjEPMA0GA1UE\n' + - 'CAwG6ZmV6KW/MQ8wDQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMG\n' + - 'A1UEAwwM5Lit5paH5rWL6K+VFw0yNTAyMjAwNjEzMTZaFw0yNTAzMjIwNjEzMTZa\n' + - 'MBkwFwIGAXKnJjrAFw0yNTAyMjAwNjEzMDNaoA4wDDAKBgNVHRQEAwIBADANBgkq\n' + - 'hkiG9w0BAQsFAAOCAQEAt9AZ/B5FQiXnKKBGocKmM5QKeky/3etcI+cAVyD0zfjI\n' + - 'r1UrL1aF+49LdZps3zQRqm4RQmo9CwL+KsMZiIMSeWF5Q6LW7BQa08hx5PtdjoOu\n' + - '1IWVKAwR5IigpaOwMKRTq1xJ372EiUkDD83AsxEkQoQW0bBvFklGrzglSACeKST+\n' + - 'Pn6ywwFyYj34cfRuz3ueqwHRmN/mGzQdet7Ns8JBGWutDzfJsAiPC/TIaafTOocO\n' + - 'CHo81Q2rMcqAJj5uXyc1Gq8KfOEqsxo/oDwReghjwrUedJ+9l/cQBr0F8HPV4H8W\n' + - '49sYMpseywjp9lxjWt/2nrx1z2yMaivGrVhoFasZvQ==\n' + - '-----END X509 CRL-----\n' - -let certData = '-----BEGIN CERTIFICATE-----\n' + - 'MIIDgTCCAmmgAwIBAgIGAXKnJjrAMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + - 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + - '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDYwOTUyWhcN\n' + - 'MzUwMjE4MDYwOTUyWjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + - 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + - '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2DQpPYN7cJjQ\n' + - 'LWLlkP5dD8J/g1xx97t2bFciUOru14IBm9EeX6qkohDSl6kQHwfVSqTfcqdIn9We\n' + - '73FiitfDjHc9xxbvBKbCYicCzS/eNl0W9q14FiEB8M9vz4dpKK00KZBcGc1QK2m+\n' + - '/N6zw4Tw4wXZ97v6/M+bhY5X0b3qEJlgQNyz7dD0wF7SCuzLL9zbr403KktHMG5Y\n' + - 'MzyOBaGOaMuVQFlXMV/E5OWfqbM7n0Pu/cGj+AfkkziWxB+5WFCRP6Pw64LJGo+e\n' + - 'uZHgHp07kk6+a2YNnFMcdTsOIWBSpCvC3I612NjpBirn2bFRWqTD++YAuvJQagmM\n' + - '+VhIjXD48wIDAQABo1MwUTAdBgNVHQ4EFgQUIN7ulBn89L5HXh9m9JM7rpkvlXUw\n' + - 'HwYDVR0jBBgwFoAUIN7ulBn89L5HXh9m9JM7rpkvlXUwDwYDVR0TAQH/BAUwAwEB\n' + - '/zANBgkqhkiG9w0BAQsFAAOCAQEAxWNa3LSOR3QOJ+wE1Y/q5zzEPWmWR5OMrRJK\n' + - 'juBHhYbzsg3r74fBO3Hw8XggEpHr6SOI1rBpZhciA8D9E8RnM1aJLY53rpBDY5OV\n' + - 'wxTFzrjdwIknt13t6ILfGeLye5OAF0S8VPdfDqP9NddNNr/WFKpd3tKoBlG0ObMa\n' + - 'LaQvOqObz0MJrjKsyI680nJjFLjLZ6+lEDSg4rsGU+bxEkONerStAPNcN2x9z7O6\n' + - 'YJOvhiLjWvr8VRjlMZYVmT9gqCImoo+7JaHbu8jz9mjRxD6fo9I1OvCLNFyFw2sV\n' + - 'iYID9UEbT6IWv/kKBdr7Te9+SY6AWxUxO8Hd7HdPKDOCrGrU9A==\n' + - '-----END CERTIFICATE-----\n'; - -let pubKeyData = new Uint8Array([ - 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, - 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, - 0x00, 0xd8, 0x34, 0x29, 0x3d, 0x83, 0x7b, 0x70, 0x98, 0xd0, 0x2d, 0x62, 0xe5, 0x90, 0xfe, 0x5d, - 0x0f, 0xc2, 0x7f, 0x83, 0x5c, 0x71, 0xf7, 0xbb, 0x76, 0x6c, 0x57, 0x22, 0x50, 0xea, 0xee, 0xd7, - 0x82, 0x01, 0x9b, 0xd1, 0x1e, 0x5f, 0xaa, 0xa4, 0xa2, 0x10, 0xd2, 0x97, 0xa9, 0x10, 0x1f, 0x07, - 0xd5, 0x4a, 0xa4, 0xdf, 0x72, 0xa7, 0x48, 0x9f, 0xd5, 0x9e, 0xef, 0x71, 0x62, 0x8a, 0xd7, 0xc3, - 0x8c, 0x77, 0x3d, 0xc7, 0x16, 0xef, 0x04, 0xa6, 0xc2, 0x62, 0x27, 0x02, 0xcd, 0x2f, 0xde, 0x36, - 0x5d, 0x16, 0xf6, 0xad, 0x78, 0x16, 0x21, 0x01, 0xf0, 0xcf, 0x6f, 0xcf, 0x87, 0x69, 0x28, 0xad, - 0x34, 0x29, 0x90, 0x5c, 0x19, 0xcd, 0x50, 0x2b, 0x69, 0xbe, 0xfc, 0xde, 0xb3, 0xc3, 0x84, 0xf0, - 0xe3, 0x05, 0xd9, 0xf7, 0xbb, 0xfa, 0xfc, 0xcf, 0x9b, 0x85, 0x8e, 0x57, 0xd1, 0xbd, 0xea, 0x10, - 0x99, 0x60, 0x40, 0xdc, 0xb3, 0xed, 0xd0, 0xf4, 0xc0, 0x5e, 0xd2, 0x0a, 0xec, 0xcb, 0x2f, 0xdc, - 0xdb, 0xaf, 0x8d, 0x37, 0x2a, 0x4b, 0x47, 0x30, 0x6e, 0x58, 0x33, 0x3c, 0x8e, 0x05, 0xa1, 0x8e, - 0x68, 0xcb, 0x95, 0x40, 0x59, 0x57, 0x31, 0x5f, 0xc4, 0xe4, 0xe5, 0x9f, 0xa9, 0xb3, 0x3b, 0x9f, - 0x43, 0xee, 0xfd, 0xc1, 0xa3, 0xf8, 0x07, 0xe4, 0x93, 0x38, 0x96, 0xc4, 0x1f, 0xb9, 0x58, 0x50, - 0x91, 0x3f, 0xa3, 0xf0, 0xeb, 0x82, 0xc9, 0x1a, 0x8f, 0x9e, 0xb9, 0x91, 0xe0, 0x1e, 0x9d, 0x3b, - 0x92, 0x4e, 0xbe, 0x6b, 0x66, 0x0d, 0x9c, 0x53, 0x1c, 0x75, 0x3b, 0x0e, 0x21, 0x60, 0x52, 0xa4, - 0x2b, 0xc2, 0xdc, 0x8e, 0xb5, 0xd8, 0xd8, 0xe9, 0x06, 0x2a, 0xe7, 0xd9, 0xb1, 0x51, 0x5a, 0xa4, - 0xc3, 0xfb, 0xe6, 0x00, 0xba, 0xf2, 0x50, 0x6a, 0x09, 0x8c, 0xf9, 0x58, 0x48, 0x8d, 0x70, 0xf8, - 0xf3, 0x02, 0x03, 0x01, 0x00, 0x01 -]); - -// CRL示例 -function crlSample(): void { - let textEncoder = new util.TextEncoder(); - let encodingBlob: cert.EncodingBlob = { - // 将CRL数据从string转为Unit8Array - data: textEncoder.encodeInto(crlData), - // CRL格式,仅支持PEM和DER格式。在这个例子中,CRL用的是PEM格式 - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - - // 创建X509CRL实例 - cert.createX509CRL(encodingBlob, (err, x509Crl) => { - if (err != null) { - // 创建X509CRL实例失败 - console.error(`createX509Crl failed, errCode: ${err.code}, errMsg:${err.message} `); - return; - } - // 创建X509CRL实例成功 - console.log('createX509CRL success'); - - // 获取CRL的版本 - let version = x509Crl.getVersion(); - let revokedType = x509Crl.getType(); - console.log(`X509 CRL version: ${version}, type :${revokedType}`); - - // 公钥的二进制数据需要传入@ohos.security.cryptoFramework的convertKey()方法去获取公钥对象 - try { - let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); - console.log('createAsyKeyGenerator success'); - let pubEncodingBlob: cryptoFramework.DataBlob = { - data: pubKeyData, - }; - keyGenerator.convertKey(pubEncodingBlob, null, (e, keyPair) => { - if (e == null) { - console.log('convert key success'); - x509Crl.verify(keyPair.pubKey, (err, data) => { - if (err == null) { - // 签名验证成功 - console.log('verify success'); - } else { - // 签名验证失败 - console.error(`verify failed, errCode: ${err.code}, errMsg: ${err.message}`); - } - }); - } else { - console.error(`convert key failed, message: ${e.message}, code: ${e.code} `); - } - }) - } catch (error) { - let e: BusinessError = error as BusinessError; - console.error(`get pubKey failed, errCode: ${e.code}, errMsg: ${e.message}`); - } - - // 使用certFramework的createX509Cert()方法创建一个X509Cert实例 - let certBlob: cert.EncodingBlob = { - data: textEncoder.encodeInto(certData), - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - let revokedFlag = true; - let serial: bigint = BigInt('0'); - cert.createX509Cert(certBlob, (err, cert) => { - serial = cert.getCertSerialNumber(); - if (err == null) { - try { - // 检查证书是否被吊销 - revokedFlag = x509Crl.isRevoked(cert); - console.log(`revokedFlag is: ${revokedFlag}`); - if (!revokedFlag) { - console.log('the given cert is not revoked.'); - return; - } - // 根据序列号来获取被吊销的证书 - try { - let crlEntry = x509Crl.getRevokedCert(serial); - console.log('get getRevokedCert success'); - let serialNumber = crlEntry.getSerialNumber(); - console.log(`crlEntry serialNumber is: ${serialNumber}`); - - // 获取被吊销证书的吊销日期 - let date = crlEntry.getRevocationDate(); - console.log(`revocation date is: ${date}`); - } catch (error) { - let e: BusinessError = error as BusinessError; - console.error(`getRevokedCert failed, errCode: ${e.code}, errMsg: ${e.message}`); - } - } catch (error) { - let e: BusinessError = error as BusinessError; - console.error(`isRevoked failed, errCode: ${e.code}, errMsg:${e.message}`); - } - } else { - console.error(`create x509 cert failed, errCode: ${err.code}, errMsg: ${err.message}`); - } - }) - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'CreateParseVerifyCrlObject'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateParseVerifyCrlObject') - .width('70%') - .onClick(() => { - try { - crlSample(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +// CRL数据,以下只是一个示例,需要根据具体业务来赋值 +let crlData = '-----BEGIN X509 CRL-----\n' + + 'MIIByzCBtAIBATANBgkqhkiG9w0BAQsFADBXMQswCQYDVQQGEwJDTjEPMA0GA1UE\n' + + 'CAwG6ZmV6KW/MQ8wDQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMG\n' + + 'A1UEAwwM5Lit5paH5rWL6K+VFw0yNTAyMjAwNjEzMTZaFw0yNTAzMjIwNjEzMTZa\n' + + 'MBkwFwIGAXKnJjrAFw0yNTAyMjAwNjEzMDNaoA4wDDAKBgNVHRQEAwIBADANBgkq\n' + + 'hkiG9w0BAQsFAAOCAQEAt9AZ/B5FQiXnKKBGocKmM5QKeky/3etcI+cAVyD0zfjI\n' + + 'r1UrL1aF+49LdZps3zQRqm4RQmo9CwL+KsMZiIMSeWF5Q6LW7BQa08hx5PtdjoOu\n' + + '1IWVKAwR5IigpaOwMKRTq1xJ372EiUkDD83AsxEkQoQW0bBvFklGrzglSACeKST+\n' + + 'Pn6ywwFyYj34cfRuz3ueqwHRmN/mGzQdet7Ns8JBGWutDzfJsAiPC/TIaafTOocO\n' + + 'CHo81Q2rMcqAJj5uXyc1Gq8KfOEqsxo/oDwReghjwrUedJ+9l/cQBr0F8HPV4H8W\n' + + '49sYMpseywjp9lxjWt/2nrx1z2yMaivGrVhoFasZvQ==\n' + + '-----END X509 CRL-----\n' + +let certData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIDgTCCAmmgAwIBAgIGAXKnJjrAMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + + 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + + '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDYwOTUyWhcN\n' + + 'MzUwMjE4MDYwOTUyWjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + + 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + + '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2DQpPYN7cJjQ\n' + + 'LWLlkP5dD8J/g1xx97t2bFciUOru14IBm9EeX6qkohDSl6kQHwfVSqTfcqdIn9We\n' + + '73FiitfDjHc9xxbvBKbCYicCzS/eNl0W9q14FiEB8M9vz4dpKK00KZBcGc1QK2m+\n' + + '/N6zw4Tw4wXZ97v6/M+bhY5X0b3qEJlgQNyz7dD0wF7SCuzLL9zbr403KktHMG5Y\n' + + 'MzyOBaGOaMuVQFlXMV/E5OWfqbM7n0Pu/cGj+AfkkziWxB+5WFCRP6Pw64LJGo+e\n' + + 'uZHgHp07kk6+a2YNnFMcdTsOIWBSpCvC3I612NjpBirn2bFRWqTD++YAuvJQagmM\n' + + '+VhIjXD48wIDAQABo1MwUTAdBgNVHQ4EFgQUIN7ulBn89L5HXh9m9JM7rpkvlXUw\n' + + 'HwYDVR0jBBgwFoAUIN7ulBn89L5HXh9m9JM7rpkvlXUwDwYDVR0TAQH/BAUwAwEB\n' + + '/zANBgkqhkiG9w0BAQsFAAOCAQEAxWNa3LSOR3QOJ+wE1Y/q5zzEPWmWR5OMrRJK\n' + + 'juBHhYbzsg3r74fBO3Hw8XggEpHr6SOI1rBpZhciA8D9E8RnM1aJLY53rpBDY5OV\n' + + 'wxTFzrjdwIknt13t6ILfGeLye5OAF0S8VPdfDqP9NddNNr/WFKpd3tKoBlG0ObMa\n' + + 'LaQvOqObz0MJrjKsyI680nJjFLjLZ6+lEDSg4rsGU+bxEkONerStAPNcN2x9z7O6\n' + + 'YJOvhiLjWvr8VRjlMZYVmT9gqCImoo+7JaHbu8jz9mjRxD6fo9I1OvCLNFyFw2sV\n' + + 'iYID9UEbT6IWv/kKBdr7Te9+SY6AWxUxO8Hd7HdPKDOCrGrU9A==\n' + + '-----END CERTIFICATE-----\n'; + +let pubKeyData = new Uint8Array([ + 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, + 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, + 0x00, 0xd8, 0x34, 0x29, 0x3d, 0x83, 0x7b, 0x70, 0x98, 0xd0, 0x2d, 0x62, 0xe5, 0x90, 0xfe, 0x5d, + 0x0f, 0xc2, 0x7f, 0x83, 0x5c, 0x71, 0xf7, 0xbb, 0x76, 0x6c, 0x57, 0x22, 0x50, 0xea, 0xee, 0xd7, + 0x82, 0x01, 0x9b, 0xd1, 0x1e, 0x5f, 0xaa, 0xa4, 0xa2, 0x10, 0xd2, 0x97, 0xa9, 0x10, 0x1f, 0x07, + 0xd5, 0x4a, 0xa4, 0xdf, 0x72, 0xa7, 0x48, 0x9f, 0xd5, 0x9e, 0xef, 0x71, 0x62, 0x8a, 0xd7, 0xc3, + 0x8c, 0x77, 0x3d, 0xc7, 0x16, 0xef, 0x04, 0xa6, 0xc2, 0x62, 0x27, 0x02, 0xcd, 0x2f, 0xde, 0x36, + 0x5d, 0x16, 0xf6, 0xad, 0x78, 0x16, 0x21, 0x01, 0xf0, 0xcf, 0x6f, 0xcf, 0x87, 0x69, 0x28, 0xad, + 0x34, 0x29, 0x90, 0x5c, 0x19, 0xcd, 0x50, 0x2b, 0x69, 0xbe, 0xfc, 0xde, 0xb3, 0xc3, 0x84, 0xf0, + 0xe3, 0x05, 0xd9, 0xf7, 0xbb, 0xfa, 0xfc, 0xcf, 0x9b, 0x85, 0x8e, 0x57, 0xd1, 0xbd, 0xea, 0x10, + 0x99, 0x60, 0x40, 0xdc, 0xb3, 0xed, 0xd0, 0xf4, 0xc0, 0x5e, 0xd2, 0x0a, 0xec, 0xcb, 0x2f, 0xdc, + 0xdb, 0xaf, 0x8d, 0x37, 0x2a, 0x4b, 0x47, 0x30, 0x6e, 0x58, 0x33, 0x3c, 0x8e, 0x05, 0xa1, 0x8e, + 0x68, 0xcb, 0x95, 0x40, 0x59, 0x57, 0x31, 0x5f, 0xc4, 0xe4, 0xe5, 0x9f, 0xa9, 0xb3, 0x3b, 0x9f, + 0x43, 0xee, 0xfd, 0xc1, 0xa3, 0xf8, 0x07, 0xe4, 0x93, 0x38, 0x96, 0xc4, 0x1f, 0xb9, 0x58, 0x50, + 0x91, 0x3f, 0xa3, 0xf0, 0xeb, 0x82, 0xc9, 0x1a, 0x8f, 0x9e, 0xb9, 0x91, 0xe0, 0x1e, 0x9d, 0x3b, + 0x92, 0x4e, 0xbe, 0x6b, 0x66, 0x0d, 0x9c, 0x53, 0x1c, 0x75, 0x3b, 0x0e, 0x21, 0x60, 0x52, 0xa4, + 0x2b, 0xc2, 0xdc, 0x8e, 0xb5, 0xd8, 0xd8, 0xe9, 0x06, 0x2a, 0xe7, 0xd9, 0xb1, 0x51, 0x5a, 0xa4, + 0xc3, 0xfb, 0xe6, 0x00, 0xba, 0xf2, 0x50, 0x6a, 0x09, 0x8c, 0xf9, 0x58, 0x48, 0x8d, 0x70, 0xf8, + 0xf3, 0x02, 0x03, 0x01, 0x00, 0x01 +]); + +// CRL示例 +function crlSample(): void { + let textEncoder = new util.TextEncoder(); + let encodingBlob: cert.EncodingBlob = { + // 将CRL数据从string转为Unit8Array + data: textEncoder.encodeInto(crlData), + // CRL格式,仅支持PEM和DER格式。在这个例子中,CRL用的是PEM格式 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + // 创建X509CRL实例 + cert.createX509CRL(encodingBlob, (err, x509Crl) => { + if (err != null) { + // 创建X509CRL实例失败 + console.error(`createX509Crl failed, errCode: ${err.code}, errMsg:${err.message} `); + return; + } + // 创建X509CRL实例成功 + console.log('createX509CRL success'); + + // 获取CRL的版本 + let version = x509Crl.getVersion(); + let revokedType = x509Crl.getType(); + console.log(`X509 CRL version: ${version}, type :${revokedType}`); + + // 公钥的二进制数据需要传入@ohos.security.cryptoFramework的convertKey()方法去获取公钥对象 + try { + let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); + console.log('createAsyKeyGenerator success'); + let pubEncodingBlob: cryptoFramework.DataBlob = { + data: pubKeyData, + }; + keyGenerator.convertKey(pubEncodingBlob, null, (e, keyPair) => { + if (e == null) { + console.log('convert key success'); + x509Crl.verify(keyPair.pubKey, (err, data) => { + if (err == null) { + // 签名验证成功 + console.log('verify success'); + } else { + // 签名验证失败 + console.error(`verify failed, errCode: ${err.code}, errMsg: ${err.message}`); + } + }); + } else { + console.error(`convert key failed, message: ${e.message}, code: ${e.code} `); + } + }) + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`get pubKey failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + + // 使用certFramework的createX509Cert()方法创建一个X509Cert实例 + let certBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(certData), + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + let revokedFlag = true; + let serial: bigint = BigInt('0'); + cert.createX509Cert(certBlob, (err, cert) => { + serial = cert.getCertSerialNumber(); + if (err == null) { + try { + // 检查证书是否被吊销 + revokedFlag = x509Crl.isRevoked(cert); + console.log(`revokedFlag is: ${revokedFlag}`); + if (!revokedFlag) { + console.log('the given cert is not revoked.'); + return; + } + // 根据序列号来获取被吊销的证书 + try { + let crlEntry = x509Crl.getRevokedCert(serial); + console.log('get getRevokedCert success'); + let serialNumber = crlEntry.getSerialNumber(); + console.log(`crlEntry serialNumber is: ${serialNumber}`); + + // 获取被吊销证书的吊销日期 + let date = crlEntry.getRevocationDate(); + console.log(`revocation date is: ${date}`); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`getRevokedCert failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`isRevoked failed, errCode: ${e.code}, errMsg:${e.message}`); + } + } else { + console.error(`create x509 cert failed, errCode: ${err.code}, errMsg: ${err.message}`); + } + }) + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'CreateParseVerifyCrlObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateParseVerifyCrlObject') + .width('70%') + .onClick(() => { + try { + crlSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets old mode 100755 new mode 100644 index 4cded231313c55578f03189d332cad10e16a2a1c..8efb0f9d3c6598fa528e7b7faf5c7fdec560e4f5 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateTrustanchorFromP12.ets @@ -1,157 +1,157 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -function test() { - let p12Data = - new Uint8Array([0x30, 0x82, 0x07, 0x5C, 0x02, 0x01, 0x03, 0x30, 0x82, 0x07, 0x12, 0x06, 0x09, 0x2A, 0x86, 0x48, - 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x07, 0x03, 0x04, 0x82, 0x06, 0xFF, 0x30, 0x82, 0x06, 0xFB, 0x30, - 0x82, 0x05, 0xB2, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06, 0xA0, 0x82, 0x05, 0xA3, 0x30, - 0x82, 0x05, 0x9F, 0x02, 0x01, 0x00, 0x30, 0x82, 0x05, 0x98, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, - 0x07, 0x01, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, - 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, 0x30, 0x1C, 0x04, 0x08, 0xA9, 0x1C, 0x1B, 0x19, - 0x36, 0xDE, 0xD4, 0x20, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, - 0x09, 0x05, 0x00, 0x30, 0x1D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x01, 0x2A, 0x04, 0x10, 0x7D, - 0xE5, 0x23, 0x96, 0x18, 0x8B, 0xF4, 0xBC, 0x9F, 0x4E, 0xE8, 0xE9, 0xAA, 0x52, 0x18, 0x39, 0x80, 0x82, 0x05, 0x30, - 0x02, 0x2D, 0x59, 0xA9, 0x96, 0x5A, 0xFE, 0x20, 0x18, 0xB2, 0x25, 0xEA, 0xFC, 0x86, 0x0F, 0xA8, 0x3C, 0x2B, 0x26, - 0x2F, 0x44, 0x6E, 0xF3, 0x15, 0xB7, 0x94, 0xE4, 0x43, 0xEE, 0xE6, 0xC3, 0xBB, 0x3C, 0x9E, 0x60, 0x08, 0xF8, 0x15, - 0x61, 0x44, 0xD0, 0xEA, 0xD5, 0x6D, 0x1A, 0x3B, 0x9F, 0x4E, 0x2A, 0x1E, 0xBB, 0xB9, 0x4E, 0x15, 0x43, 0xB8, 0x68, - 0xDB, 0x1A, 0x4E, 0x41, 0xBA, 0x29, 0x8E, 0x75, 0xEB, 0x12, 0xC1, 0xF0, 0x4B, 0x0D, 0x13, 0xB2, 0xC2, 0x48, 0x6F, - 0xC4, 0xC4, 0x82, 0xF2, 0x26, 0xD4, 0x3D, 0x1F, 0x42, 0x7D, 0x67, 0xB0, 0x37, 0x55, 0x9E, 0xD9, 0x46, 0x99, 0x98, - 0xB4, 0xE7, 0x4B, 0x07, 0x08, 0x3F, 0xD3, 0x96, 0x9A, 0xC5, 0xDA, 0x37, 0x74, 0x08, 0x5D, 0x3B, 0x06, 0x8A, 0x16, - 0x6D, 0x81, 0x63, 0x01, 0x83, 0x94, 0xDA, 0x1B, 0x0E, 0x04, 0xCE, 0x18, 0xF0, 0x51, 0x22, 0xD8, 0x2D, 0xF1, 0x69, - 0x0C, 0xCB, 0xC9, 0x51, 0x17, 0x07, 0x1F, 0x2B, 0xCF, 0x74, 0x26, 0xD7, 0x73, 0xB3, 0x2D, 0xF2, 0x82, 0xF0, 0x38, - 0x5B, 0x8A, 0x8F, 0xCD, 0x84, 0x69, 0x40, 0x59, 0xCE, 0xB3, 0x39, 0xFE, 0xF6, 0xB7, 0x24, 0x89, 0x34, 0xFF, 0xF4, - 0x40, 0x50, 0x06, 0x4D, 0xC6, 0x13, 0x82, 0xAF, 0x7F, 0x84, 0xB1, 0x67, 0x3C, 0x89, 0xBB, 0x5D, 0x32, 0xC3, 0xA6, - 0xF1, 0x7D, 0xF5, 0x72, 0x68, 0x75, 0xCE, 0x69, 0xAB, 0x6C, 0x32, 0xDA, 0x16, 0x3B, 0xC4, 0xCA, 0x47, 0x45, 0xE9, - 0x59, 0x1E, 0xB1, 0x70, 0xDA, 0x8A, 0x00, 0x69, 0x80, 0x40, 0xCA, 0x60, 0xE6, 0x07, 0x16, 0xF0, 0xA2, 0xF9, 0x12, - 0x7D, 0x09, 0x43, 0x66, 0x46, 0x78, 0x35, 0xA6, 0x94, 0x35, 0x60, 0x82, 0xFC, 0xB8, 0x5E, 0x39, 0xE7, 0xA1, 0x22, - 0xAD, 0xCC, 0x6F, 0x5E, 0xCE, 0x01, 0x6B, 0xA1, 0xDD, 0xE5, 0xDD, 0x79, 0x9B, 0xA1, 0x28, 0xC4, 0x03, 0x84, 0x8D, - 0x6C, 0x07, 0xD4, 0xFE, 0x57, 0xFB, 0x89, 0x3F, 0x43, 0x44, 0x69, 0xF1, 0x9E, 0x53, 0x6C, 0x11, 0x11, 0x96, 0x79, - 0xE4, 0xB8, 0x3B, 0x49, 0x2E, 0xF6, 0x3B, 0xC5, 0x6C, 0x76, 0x21, 0x22, 0x15, 0x85, 0x77, 0x8A, 0xDD, 0xD2, 0x43, - 0x85, 0x73, 0x39, 0x77, 0x9F, 0xFA, 0x8F, 0xCF, 0xCB, 0xEA, 0x62, 0xBD, 0x5C, 0x66, 0x45, 0xCD, 0xB0, 0xCA, 0x42, - 0xCC, 0xB9, 0xCF, 0xE3, 0x84, 0x63, 0x9F, 0x63, 0xCE, 0x49, 0xE9, 0x74, 0x26, 0xCC, 0x26, 0x78, 0xCE, 0x9F, 0x4E, - 0x38, 0xA2, 0x9C, 0xEB, 0x75, 0xC5, 0x33, 0x6B, 0x00, 0x83, 0x85, 0xA3, 0x0F, 0xE7, 0xE1, 0x11, 0xA6, 0x48, 0xDC, - 0xEF, 0x0C, 0x05, 0xB3, 0xDE, 0x94, 0xB9, 0x69, 0xCB, 0x27, 0x09, 0xAB, 0x27, 0xD8, 0x06, 0xED, 0x25, 0xBC, 0xA6, - 0x2E, 0xB7, 0xF9, 0x2E, 0xAD, 0x84, 0x1D, 0xDD, 0x73, 0xD8, 0xC0, 0x46, 0x8A, 0xFE, 0x9A, 0xDF, 0x07, 0xE1, 0x33, - 0xE2, 0x1C, 0x37, 0x6A, 0x8E, 0xA2, 0x91, 0x0B, 0xD7, 0x76, 0xEF, 0x3C, 0x87, 0x4A, 0x53, 0x84, 0xFA, 0xFA, 0xC5, - 0x71, 0x76, 0xC0, 0x75, 0x70, 0x67, 0x67, 0x71, 0x9D, 0x8B, 0x81, 0x6F, 0x68, 0xC5, 0xB1, 0xFC, 0xA3, 0x59, 0xB5, - 0xD0, 0x03, 0x56, 0xE7, 0x89, 0x03, 0xD7, 0x99, 0xDE, 0x66, 0x33, 0xFA, 0x53, 0x50, 0x5F, 0xB4, 0x9D, 0xB3, 0x90, - 0x8F, 0x57, 0x20, 0xF0, 0x8B, 0xDB, 0x73, 0xCA, 0xA4, 0x71, 0x61, 0x67, 0x6A, 0x6D, 0xA5, 0xCA, 0x88, 0xD4, 0xCC, - 0x82, 0x34, 0xC9, 0x3E, 0x10, 0x10, 0x57, 0xD1, 0x08, 0x96, 0x80, 0x09, 0xA8, 0xBB, 0x6F, 0x53, 0x8F, 0xFD, 0x87, - 0xCF, 0x73, 0xFC, 0xE1, 0x3A, 0x92, 0x2E, 0x78, 0x66, 0xFB, 0x86, 0x5D, 0x62, 0xE0, 0xC4, 0x58, 0x55, 0x3F, 0xA4, - 0xEA, 0xA1, 0xBE, 0x5B, 0x5E, 0x8E, 0x46, 0x50, 0x5E, 0x7C, 0x01, 0xD6, 0x63, 0xAA, 0x6F, 0xD5, 0xFD, 0xAF, 0xC5, - 0x1D, 0xB3, 0x90, 0x9C, 0xD8, 0x5F, 0x8D, 0xF2, 0x81, 0xEB, 0xBF, 0xA1, 0xDE, 0xB7, 0x9D, 0xCD, 0x24, 0x82, 0x06, - 0x0B, 0x63, 0xE6, 0xBF, 0x57, 0x51, 0xF0, 0xB6, 0xE9, 0x7F, 0xAA, 0x7B, 0x10, 0xBD, 0xCD, 0x85, 0x41, 0xE0, 0xD7, - 0xF1, 0x53, 0xB7, 0xF8, 0x46, 0x91, 0x9E, 0x8D, 0x4B, 0xCB, 0x28, 0x35, 0x40, 0x37, 0x1E, 0x83, 0x64, 0x6A, 0x70, - 0x01, 0x9D, 0xBF, 0xF1, 0x0E, 0xB6, 0x2E, 0x7A, 0xB7, 0x8F, 0x0F, 0x8C, 0x69, 0xD6, 0xF2, 0xD1, 0xF6, 0x1E, 0xCD, - 0x08, 0xA8, 0xD4, 0x1B, 0xCB, 0x38, 0xEA, 0x26, 0x37, 0x5C, 0x60, 0x3A, 0x38, 0x5B, 0x12, 0x1D, 0x00, 0x7B, 0xEC, - 0xCE, 0xFB, 0x89, 0x23, 0x8A, 0x11, 0xE1, 0x1B, 0xDE, 0x54, 0x91, 0x6A, 0x26, 0x22, 0xD0, 0x1C, 0x2E, 0xBA, 0xD0, - 0x92, 0x87, 0xDA, 0xF0, 0x93, 0xBB, 0x3A, 0x2C, 0x52, 0xFB, 0xB2, 0xA9, 0xA8, 0x92, 0x19, 0xE3, 0x19, 0xDC, 0xB0, - 0x0E, 0xC5, 0xE7, 0x9D, 0xFB, 0xF9, 0xA3, 0x23, 0x32, 0xD0, 0x4E, 0x2C, 0x05, 0x2D, 0x76, 0xDB, 0x93, 0x53, 0x5B, - 0x0E, 0x2A, 0xA3, 0xDD, 0x5F, 0xD3, 0x1A, 0x3B, 0x1E, 0x1F, 0x26, 0x88, 0x43, 0xAD, 0x10, 0x1F, 0xA9, 0xC4, 0xF9, - 0x1F, 0xCD, 0xA5, 0xD2, 0xDC, 0x24, 0x95, 0x1D, 0xE7, 0x57, 0xE1, 0x02, 0x0A, 0x20, 0xEA, 0x6A, 0x78, 0x4E, 0x96, - 0xE2, 0xE5, 0x6D, 0x6F, 0xFD, 0x81, 0x7B, 0x61, 0x85, 0xA3, 0x3D, 0xC5, 0x7B, 0xEF, 0xAE, 0x58, 0xA2, 0xDB, 0x91, - 0x73, 0xDB, 0x47, 0x8E, 0xD1, 0x7D, 0xD7, 0x8F, 0x56, 0x06, 0x28, 0x8C, 0x78, 0x73, 0x02, 0x65, 0xB0, 0x16, 0x4B, - 0xE6, 0xA3, 0xD7, 0x06, 0x7C, 0xEA, 0x7D, 0xE2, 0xAE, 0xBB, 0xE5, 0xD2, 0xEB, 0xF0, 0x91, 0x71, 0x7C, 0xBC, 0xA6, - 0x1A, 0xE8, 0x9F, 0xD3, 0xA9, 0x3C, 0x5D, 0x60, 0xCF, 0x59, 0x26, 0x46, 0x45, 0xF2, 0x7F, 0x85, 0x6B, 0xE7, 0xC2, - 0x58, 0x52, 0x90, 0x12, 0x07, 0xBA, 0xE6, 0xB8, 0xE5, 0xD7, 0x24, 0x93, 0xD5, 0x6E, 0xB1, 0x74, 0x6C, 0xAA, 0xA0, - 0x60, 0xBF, 0xF3, 0x32, 0x41, 0x0B, 0xA2, 0x01, 0x84, 0x0D, 0x83, 0xE4, 0x43, 0xD1, 0xBA, 0xC1, 0x92, 0x84, 0x26, - 0xF8, 0xF2, 0x77, 0x20, 0x1B, 0xF2, 0x8F, 0x00, 0x69, 0x18, 0x2F, 0x6C, 0xA8, 0x58, 0xB5, 0x5D, 0xFA, 0x27, 0xD2, - 0x38, 0xD2, 0x49, 0x6E, 0xDF, 0x55, 0x79, 0xAF, 0x1C, 0x44, 0xDA, 0x5A, 0xD7, 0x44, 0x53, 0x50, 0x8B, 0x77, 0x70, - 0x4D, 0x91, 0xEC, 0x07, 0xA5, 0x64, 0x21, 0x3C, 0x31, 0x09, 0x68, 0x65, 0xB4, 0xFA, 0xBE, 0x23, 0xF9, 0xDF, 0x77, - 0x46, 0xA2, 0x9A, 0x5D, 0xE3, 0xBE, 0x1E, 0xE3, 0x84, 0xEF, 0xAE, 0x7D, 0xF8, 0x1C, 0x54, 0xE8, 0x4E, 0xAE, 0xB5, - 0xBB, 0xD6, 0xC3, 0x8D, 0x56, 0x79, 0xE8, 0x7C, 0x43, 0xDC, 0xF3, 0xB3, 0x7A, 0x30, 0x22, 0x09, 0xBC, 0x10, 0xD6, - 0x84, 0xC4, 0x0F, 0x4C, 0x0B, 0xA2, 0xD1, 0xCB, 0xCD, 0x1F, 0x50, 0x3D, 0xF7, 0x23, 0x45, 0x55, 0x18, 0x21, 0x3D, - 0x64, 0x05, 0x2E, 0x52, 0x3A, 0x73, 0xFD, 0xF2, 0xA9, 0xCA, 0x3F, 0xF6, 0x7F, 0x87, 0xE8, 0x56, 0x9B, 0x68, 0x6B, - 0x20, 0xB0, 0x1D, 0x83, 0x04, 0x2F, 0x59, 0xFD, 0x84, 0x57, 0x7D, 0x82, 0x97, 0x96, 0xE8, 0xFB, 0xDF, 0x71, 0x8C, - 0x26, 0x47, 0x85, 0xA5, 0xBE, 0xFB, 0xF5, 0x05, 0x4C, 0xD3, 0x3D, 0x73, 0xF4, 0xA5, 0xF1, 0xA3, 0x99, 0x98, 0x1B, - 0x84, 0x8B, 0xB3, 0x53, 0xCE, 0x4D, 0xEA, 0x5A, 0x48, 0xD2, 0xB9, 0x7E, 0xB6, 0xEB, 0x9B, 0x94, 0x6F, 0xDD, 0x44, - 0x80, 0x89, 0xD2, 0x78, 0x6D, 0xB9, 0xDA, 0x8B, 0x83, 0x49, 0xE0, 0x4D, 0x49, 0xDF, 0x6B, 0xFF, 0xF7, 0x04, 0x00, - 0x32, 0xAA, 0x1D, 0x4F, 0x8D, 0x4B, 0xDE, 0xB8, 0x0D, 0xC6, 0x54, 0x1C, 0xB2, 0xCD, 0x60, 0x29, 0x72, 0x0A, 0x7E, - 0xE7, 0xEB, 0x7A, 0xF6, 0x5B, 0x04, 0x3F, 0x5B, 0x93, 0x12, 0x0D, 0xD5, 0xFF, 0x7A, 0x41, 0x44, 0x0B, 0x37, 0x12, - 0x82, 0x3D, 0xDD, 0x1E, 0x59, 0xB9, 0xBE, 0x0F, 0x9E, 0xD6, 0xD0, 0x68, 0x69, 0x74, 0xF9, 0xB1, 0x21, 0xA3, 0x70, - 0x4F, 0xDA, 0xF8, 0x9F, 0xB9, 0x49, 0x3F, 0xC6, 0xB2, 0x69, 0xC8, 0xD8, 0x60, 0xF1, 0x6A, 0x52, 0x07, 0xFA, 0x42, - 0xFD, 0xA9, 0x06, 0xCF, 0x97, 0x4A, 0x0E, 0xC5, 0xFC, 0x63, 0x27, 0x54, 0xC8, 0xBE, 0x8B, 0x4F, 0xB6, 0x42, 0xBC, - 0xA2, 0xCC, 0x70, 0x4A, 0x6B, 0x24, 0x5B, 0x68, 0x28, 0x47, 0xFA, 0x6B, 0x89, 0x28, 0x07, 0x5D, 0xE0, 0x2C, 0x4A, - 0xD9, 0x22, 0xE3, 0xB3, 0x2F, 0xAA, 0xC2, 0xA0, 0x7C, 0x0F, 0x92, 0xC5, 0xDD, 0xB6, 0x23, 0x8F, 0x73, 0x73, 0x0F, - 0xD7, 0x73, 0x71, 0x2F, 0x0A, 0x78, 0xE8, 0x5B, 0xDB, 0xC2, 0xE0, 0xDB, 0xC9, 0x3E, 0xC3, 0x72, 0x9C, 0x14, 0xD7, - 0xD1, 0x28, 0xFD, 0xF4, 0xEE, 0xBC, 0x0E, 0x13, 0x37, 0xCA, 0x85, 0x9F, 0xB9, 0xA2, 0x0E, 0xF6, 0xE7, 0x49, 0xD1, - 0xD0, 0x11, 0x76, 0x53, 0xA3, 0x73, 0x95, 0x2A, 0x23, 0xC8, 0x0E, 0x97, 0x83, 0x07, 0x64, 0xB2, 0x51, 0xB7, 0xC8, - 0x51, 0x9F, 0xA4, 0x3E, 0x7B, 0xA4, 0x18, 0x6D, 0x99, 0xF0, 0x6E, 0xC3, 0x97, 0xAE, 0xF4, 0xB7, 0x66, 0x37, 0xFA, - 0x65, 0xFC, 0x5E, 0xE2, 0x57, 0xFA, 0x8B, 0x4C, 0x86, 0x10, 0xB4, 0x5C, 0xA4, 0xD2, 0x60, 0x83, 0x69, 0x1E, 0xFF, - 0x36, 0x9B, 0xF9, 0x84, 0xFB, 0xB8, 0x83, 0x64, 0xF1, 0x41, 0xA5, 0x25, 0x56, 0x21, 0xBA, 0x13, 0x98, 0x0C, 0x3B, - 0x04, 0xAA, 0x6C, 0x9A, 0xD4, 0xE3, 0x13, 0x15, 0x54, 0x05, 0x4C, 0x5C, 0xE1, 0x7A, 0x31, 0x5E, 0x90, 0xCF, 0x48, - 0x4E, 0x83, 0xD7, 0x7F, 0xED, 0x93, 0x22, 0xAB, 0x67, 0xE7, 0x76, 0x32, 0x64, 0xBA, 0x5A, 0x21, 0x3E, 0x30, 0x82, - 0x01, 0x41, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x01, 0x32, 0x04, 0x82, - 0x01, 0x2E, 0x30, 0x82, 0x01, 0x2A, 0x30, 0x82, 0x01, 0x26, 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, - 0x0C, 0x0A, 0x01, 0x02, 0xA0, 0x81, 0xEF, 0x30, 0x81, 0xEC, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, - 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, - 0x30, 0x1C, 0x04, 0x08, 0xED, 0x3E, 0xED, 0x07, 0x5C, 0x1F, 0x71, 0xAD, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, - 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x09, 0x05, 0x00, 0x30, 0x1D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, - 0x65, 0x03, 0x04, 0x01, 0x2A, 0x04, 0x10, 0xA7, 0x49, 0xA4, 0x6E, 0x00, 0x19, 0x75, 0x59, 0x75, 0x59, 0xBA, 0x4B, - 0xC7, 0x24, 0x88, 0x34, 0x04, 0x81, 0x90, 0xCA, 0x23, 0x82, 0xAA, 0x16, 0x57, 0x99, 0xFA, 0x94, 0x9F, 0xAE, 0x32, - 0x5C, 0x5B, 0xE7, 0x01, 0xD0, 0xED, 0xA7, 0x58, 0x57, 0x52, 0xBF, 0x57, 0x13, 0xD4, 0x15, 0xB0, 0x06, 0xF5, 0x38, - 0xCC, 0x64, 0x23, 0x09, 0xD5, 0x8C, 0x0D, 0x64, 0x31, 0xFA, 0x74, 0xAA, 0x96, 0x7E, 0x9B, 0x16, 0xCA, 0x21, 0xFD, - 0xC0, 0x54, 0x91, 0x40, 0x7F, 0xB3, 0xF2, 0xA3, 0xEC, 0xA1, 0x4A, 0x07, 0xF0, 0x87, 0x22, 0xDB, 0x8A, 0x49, 0x89, - 0xF7, 0xF2, 0x6A, 0xFC, 0x8D, 0x03, 0x6E, 0x32, 0x4F, 0xD0, 0xD8, 0x93, 0x92, 0xA5, 0xF1, 0x41, 0xBD, 0xEA, 0xE1, - 0x38, 0xA9, 0xD8, 0x9D, 0xAB, 0xB4, 0x8E, 0x4A, 0x40, 0x0E, 0xC7, 0xE3, 0xE9, 0xBF, 0x0E, 0xBA, 0x8D, 0xAA, 0x3E, - 0x93, 0x53, 0x88, 0xEE, 0x0A, 0x2C, 0x71, 0xF1, 0x61, 0x44, 0xA5, 0xAD, 0xED, 0x3E, 0xAB, 0x32, 0x9A, 0x32, 0x85, - 0x08, 0xF5, 0x8B, 0xCC, 0x15, 0x35, 0xEE, 0xFA, 0x17, 0x27, 0x97, 0x8D, 0xD9, 0x1C, 0x5E, 0x74, 0x9D, 0x7B, 0x31, - 0x25, 0x30, 0x23, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x15, 0x31, 0x16, 0x04, 0x14, 0x5F, - 0x8E, 0xAB, 0x9C, 0x5F, 0xE2, 0x3B, 0xB1, 0x5C, 0x1A, 0x36, 0x1D, 0x7D, 0xCB, 0x90, 0x45, 0x20, 0x3C, 0x3B, 0xAC, - 0x30, 0x41, 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, - 0x04, 0x20, 0x93, 0x25, 0xC4, 0x3E, 0x2A, 0x6D, 0x4C, 0x30, 0x87, 0x0F, 0xE3, 0x5A, 0x95, 0xB0, 0xF2, 0x6C, 0xBA, - 0x07, 0x89, 0x7D, 0xFB, 0xCF, 0xCF, 0x1D, 0x54, 0xA3, 0x36, 0x24, 0x7B, 0x30, 0x97, 0xB5, 0x04, 0x08, 0xE7, 0x96, - 0x59, 0xCC, 0x42, 0x9F, 0xEF, 0xFC, 0x02, 0x02, 0x08, 0x00]); - - try { - cert.createTrustAnchorsWithKeyStore(p12Data, '123456').then((data) => { - console.log('createTrustAnchorsWithKeyStore sucess, the num of result is :' + JSON.stringify(data.length)); - }).catch((err: BusinessError) => { - console.error('createTrustAnchorsWithKeyStore failed, error :' + JSON.stringify(err)); - }) - } catch (error) { - console.error('createTrustAnchorsWithKeyStore failed, error :' + JSON.stringify(error)); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'CreateTrustanchorFromP12'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateTrustanchorFromP12') - .width('70%') - .onClick(() => { - try { - test(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function test() { + let p12Data = + new Uint8Array([0x30, 0x82, 0x07, 0x5C, 0x02, 0x01, 0x03, 0x30, 0x82, 0x07, 0x12, 0x06, 0x09, 0x2A, 0x86, 0x48, + 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x07, 0x03, 0x04, 0x82, 0x06, 0xFF, 0x30, 0x82, 0x06, 0xFB, 0x30, + 0x82, 0x05, 0xB2, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06, 0xA0, 0x82, 0x05, 0xA3, 0x30, + 0x82, 0x05, 0x9F, 0x02, 0x01, 0x00, 0x30, 0x82, 0x05, 0x98, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + 0x07, 0x01, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, + 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, 0x30, 0x1C, 0x04, 0x08, 0xA9, 0x1C, 0x1B, 0x19, + 0x36, 0xDE, 0xD4, 0x20, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, + 0x09, 0x05, 0x00, 0x30, 0x1D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x01, 0x2A, 0x04, 0x10, 0x7D, + 0xE5, 0x23, 0x96, 0x18, 0x8B, 0xF4, 0xBC, 0x9F, 0x4E, 0xE8, 0xE9, 0xAA, 0x52, 0x18, 0x39, 0x80, 0x82, 0x05, 0x30, + 0x02, 0x2D, 0x59, 0xA9, 0x96, 0x5A, 0xFE, 0x20, 0x18, 0xB2, 0x25, 0xEA, 0xFC, 0x86, 0x0F, 0xA8, 0x3C, 0x2B, 0x26, + 0x2F, 0x44, 0x6E, 0xF3, 0x15, 0xB7, 0x94, 0xE4, 0x43, 0xEE, 0xE6, 0xC3, 0xBB, 0x3C, 0x9E, 0x60, 0x08, 0xF8, 0x15, + 0x61, 0x44, 0xD0, 0xEA, 0xD5, 0x6D, 0x1A, 0x3B, 0x9F, 0x4E, 0x2A, 0x1E, 0xBB, 0xB9, 0x4E, 0x15, 0x43, 0xB8, 0x68, + 0xDB, 0x1A, 0x4E, 0x41, 0xBA, 0x29, 0x8E, 0x75, 0xEB, 0x12, 0xC1, 0xF0, 0x4B, 0x0D, 0x13, 0xB2, 0xC2, 0x48, 0x6F, + 0xC4, 0xC4, 0x82, 0xF2, 0x26, 0xD4, 0x3D, 0x1F, 0x42, 0x7D, 0x67, 0xB0, 0x37, 0x55, 0x9E, 0xD9, 0x46, 0x99, 0x98, + 0xB4, 0xE7, 0x4B, 0x07, 0x08, 0x3F, 0xD3, 0x96, 0x9A, 0xC5, 0xDA, 0x37, 0x74, 0x08, 0x5D, 0x3B, 0x06, 0x8A, 0x16, + 0x6D, 0x81, 0x63, 0x01, 0x83, 0x94, 0xDA, 0x1B, 0x0E, 0x04, 0xCE, 0x18, 0xF0, 0x51, 0x22, 0xD8, 0x2D, 0xF1, 0x69, + 0x0C, 0xCB, 0xC9, 0x51, 0x17, 0x07, 0x1F, 0x2B, 0xCF, 0x74, 0x26, 0xD7, 0x73, 0xB3, 0x2D, 0xF2, 0x82, 0xF0, 0x38, + 0x5B, 0x8A, 0x8F, 0xCD, 0x84, 0x69, 0x40, 0x59, 0xCE, 0xB3, 0x39, 0xFE, 0xF6, 0xB7, 0x24, 0x89, 0x34, 0xFF, 0xF4, + 0x40, 0x50, 0x06, 0x4D, 0xC6, 0x13, 0x82, 0xAF, 0x7F, 0x84, 0xB1, 0x67, 0x3C, 0x89, 0xBB, 0x5D, 0x32, 0xC3, 0xA6, + 0xF1, 0x7D, 0xF5, 0x72, 0x68, 0x75, 0xCE, 0x69, 0xAB, 0x6C, 0x32, 0xDA, 0x16, 0x3B, 0xC4, 0xCA, 0x47, 0x45, 0xE9, + 0x59, 0x1E, 0xB1, 0x70, 0xDA, 0x8A, 0x00, 0x69, 0x80, 0x40, 0xCA, 0x60, 0xE6, 0x07, 0x16, 0xF0, 0xA2, 0xF9, 0x12, + 0x7D, 0x09, 0x43, 0x66, 0x46, 0x78, 0x35, 0xA6, 0x94, 0x35, 0x60, 0x82, 0xFC, 0xB8, 0x5E, 0x39, 0xE7, 0xA1, 0x22, + 0xAD, 0xCC, 0x6F, 0x5E, 0xCE, 0x01, 0x6B, 0xA1, 0xDD, 0xE5, 0xDD, 0x79, 0x9B, 0xA1, 0x28, 0xC4, 0x03, 0x84, 0x8D, + 0x6C, 0x07, 0xD4, 0xFE, 0x57, 0xFB, 0x89, 0x3F, 0x43, 0x44, 0x69, 0xF1, 0x9E, 0x53, 0x6C, 0x11, 0x11, 0x96, 0x79, + 0xE4, 0xB8, 0x3B, 0x49, 0x2E, 0xF6, 0x3B, 0xC5, 0x6C, 0x76, 0x21, 0x22, 0x15, 0x85, 0x77, 0x8A, 0xDD, 0xD2, 0x43, + 0x85, 0x73, 0x39, 0x77, 0x9F, 0xFA, 0x8F, 0xCF, 0xCB, 0xEA, 0x62, 0xBD, 0x5C, 0x66, 0x45, 0xCD, 0xB0, 0xCA, 0x42, + 0xCC, 0xB9, 0xCF, 0xE3, 0x84, 0x63, 0x9F, 0x63, 0xCE, 0x49, 0xE9, 0x74, 0x26, 0xCC, 0x26, 0x78, 0xCE, 0x9F, 0x4E, + 0x38, 0xA2, 0x9C, 0xEB, 0x75, 0xC5, 0x33, 0x6B, 0x00, 0x83, 0x85, 0xA3, 0x0F, 0xE7, 0xE1, 0x11, 0xA6, 0x48, 0xDC, + 0xEF, 0x0C, 0x05, 0xB3, 0xDE, 0x94, 0xB9, 0x69, 0xCB, 0x27, 0x09, 0xAB, 0x27, 0xD8, 0x06, 0xED, 0x25, 0xBC, 0xA6, + 0x2E, 0xB7, 0xF9, 0x2E, 0xAD, 0x84, 0x1D, 0xDD, 0x73, 0xD8, 0xC0, 0x46, 0x8A, 0xFE, 0x9A, 0xDF, 0x07, 0xE1, 0x33, + 0xE2, 0x1C, 0x37, 0x6A, 0x8E, 0xA2, 0x91, 0x0B, 0xD7, 0x76, 0xEF, 0x3C, 0x87, 0x4A, 0x53, 0x84, 0xFA, 0xFA, 0xC5, + 0x71, 0x76, 0xC0, 0x75, 0x70, 0x67, 0x67, 0x71, 0x9D, 0x8B, 0x81, 0x6F, 0x68, 0xC5, 0xB1, 0xFC, 0xA3, 0x59, 0xB5, + 0xD0, 0x03, 0x56, 0xE7, 0x89, 0x03, 0xD7, 0x99, 0xDE, 0x66, 0x33, 0xFA, 0x53, 0x50, 0x5F, 0xB4, 0x9D, 0xB3, 0x90, + 0x8F, 0x57, 0x20, 0xF0, 0x8B, 0xDB, 0x73, 0xCA, 0xA4, 0x71, 0x61, 0x67, 0x6A, 0x6D, 0xA5, 0xCA, 0x88, 0xD4, 0xCC, + 0x82, 0x34, 0xC9, 0x3E, 0x10, 0x10, 0x57, 0xD1, 0x08, 0x96, 0x80, 0x09, 0xA8, 0xBB, 0x6F, 0x53, 0x8F, 0xFD, 0x87, + 0xCF, 0x73, 0xFC, 0xE1, 0x3A, 0x92, 0x2E, 0x78, 0x66, 0xFB, 0x86, 0x5D, 0x62, 0xE0, 0xC4, 0x58, 0x55, 0x3F, 0xA4, + 0xEA, 0xA1, 0xBE, 0x5B, 0x5E, 0x8E, 0x46, 0x50, 0x5E, 0x7C, 0x01, 0xD6, 0x63, 0xAA, 0x6F, 0xD5, 0xFD, 0xAF, 0xC5, + 0x1D, 0xB3, 0x90, 0x9C, 0xD8, 0x5F, 0x8D, 0xF2, 0x81, 0xEB, 0xBF, 0xA1, 0xDE, 0xB7, 0x9D, 0xCD, 0x24, 0x82, 0x06, + 0x0B, 0x63, 0xE6, 0xBF, 0x57, 0x51, 0xF0, 0xB6, 0xE9, 0x7F, 0xAA, 0x7B, 0x10, 0xBD, 0xCD, 0x85, 0x41, 0xE0, 0xD7, + 0xF1, 0x53, 0xB7, 0xF8, 0x46, 0x91, 0x9E, 0x8D, 0x4B, 0xCB, 0x28, 0x35, 0x40, 0x37, 0x1E, 0x83, 0x64, 0x6A, 0x70, + 0x01, 0x9D, 0xBF, 0xF1, 0x0E, 0xB6, 0x2E, 0x7A, 0xB7, 0x8F, 0x0F, 0x8C, 0x69, 0xD6, 0xF2, 0xD1, 0xF6, 0x1E, 0xCD, + 0x08, 0xA8, 0xD4, 0x1B, 0xCB, 0x38, 0xEA, 0x26, 0x37, 0x5C, 0x60, 0x3A, 0x38, 0x5B, 0x12, 0x1D, 0x00, 0x7B, 0xEC, + 0xCE, 0xFB, 0x89, 0x23, 0x8A, 0x11, 0xE1, 0x1B, 0xDE, 0x54, 0x91, 0x6A, 0x26, 0x22, 0xD0, 0x1C, 0x2E, 0xBA, 0xD0, + 0x92, 0x87, 0xDA, 0xF0, 0x93, 0xBB, 0x3A, 0x2C, 0x52, 0xFB, 0xB2, 0xA9, 0xA8, 0x92, 0x19, 0xE3, 0x19, 0xDC, 0xB0, + 0x0E, 0xC5, 0xE7, 0x9D, 0xFB, 0xF9, 0xA3, 0x23, 0x32, 0xD0, 0x4E, 0x2C, 0x05, 0x2D, 0x76, 0xDB, 0x93, 0x53, 0x5B, + 0x0E, 0x2A, 0xA3, 0xDD, 0x5F, 0xD3, 0x1A, 0x3B, 0x1E, 0x1F, 0x26, 0x88, 0x43, 0xAD, 0x10, 0x1F, 0xA9, 0xC4, 0xF9, + 0x1F, 0xCD, 0xA5, 0xD2, 0xDC, 0x24, 0x95, 0x1D, 0xE7, 0x57, 0xE1, 0x02, 0x0A, 0x20, 0xEA, 0x6A, 0x78, 0x4E, 0x96, + 0xE2, 0xE5, 0x6D, 0x6F, 0xFD, 0x81, 0x7B, 0x61, 0x85, 0xA3, 0x3D, 0xC5, 0x7B, 0xEF, 0xAE, 0x58, 0xA2, 0xDB, 0x91, + 0x73, 0xDB, 0x47, 0x8E, 0xD1, 0x7D, 0xD7, 0x8F, 0x56, 0x06, 0x28, 0x8C, 0x78, 0x73, 0x02, 0x65, 0xB0, 0x16, 0x4B, + 0xE6, 0xA3, 0xD7, 0x06, 0x7C, 0xEA, 0x7D, 0xE2, 0xAE, 0xBB, 0xE5, 0xD2, 0xEB, 0xF0, 0x91, 0x71, 0x7C, 0xBC, 0xA6, + 0x1A, 0xE8, 0x9F, 0xD3, 0xA9, 0x3C, 0x5D, 0x60, 0xCF, 0x59, 0x26, 0x46, 0x45, 0xF2, 0x7F, 0x85, 0x6B, 0xE7, 0xC2, + 0x58, 0x52, 0x90, 0x12, 0x07, 0xBA, 0xE6, 0xB8, 0xE5, 0xD7, 0x24, 0x93, 0xD5, 0x6E, 0xB1, 0x74, 0x6C, 0xAA, 0xA0, + 0x60, 0xBF, 0xF3, 0x32, 0x41, 0x0B, 0xA2, 0x01, 0x84, 0x0D, 0x83, 0xE4, 0x43, 0xD1, 0xBA, 0xC1, 0x92, 0x84, 0x26, + 0xF8, 0xF2, 0x77, 0x20, 0x1B, 0xF2, 0x8F, 0x00, 0x69, 0x18, 0x2F, 0x6C, 0xA8, 0x58, 0xB5, 0x5D, 0xFA, 0x27, 0xD2, + 0x38, 0xD2, 0x49, 0x6E, 0xDF, 0x55, 0x79, 0xAF, 0x1C, 0x44, 0xDA, 0x5A, 0xD7, 0x44, 0x53, 0x50, 0x8B, 0x77, 0x70, + 0x4D, 0x91, 0xEC, 0x07, 0xA5, 0x64, 0x21, 0x3C, 0x31, 0x09, 0x68, 0x65, 0xB4, 0xFA, 0xBE, 0x23, 0xF9, 0xDF, 0x77, + 0x46, 0xA2, 0x9A, 0x5D, 0xE3, 0xBE, 0x1E, 0xE3, 0x84, 0xEF, 0xAE, 0x7D, 0xF8, 0x1C, 0x54, 0xE8, 0x4E, 0xAE, 0xB5, + 0xBB, 0xD6, 0xC3, 0x8D, 0x56, 0x79, 0xE8, 0x7C, 0x43, 0xDC, 0xF3, 0xB3, 0x7A, 0x30, 0x22, 0x09, 0xBC, 0x10, 0xD6, + 0x84, 0xC4, 0x0F, 0x4C, 0x0B, 0xA2, 0xD1, 0xCB, 0xCD, 0x1F, 0x50, 0x3D, 0xF7, 0x23, 0x45, 0x55, 0x18, 0x21, 0x3D, + 0x64, 0x05, 0x2E, 0x52, 0x3A, 0x73, 0xFD, 0xF2, 0xA9, 0xCA, 0x3F, 0xF6, 0x7F, 0x87, 0xE8, 0x56, 0x9B, 0x68, 0x6B, + 0x20, 0xB0, 0x1D, 0x83, 0x04, 0x2F, 0x59, 0xFD, 0x84, 0x57, 0x7D, 0x82, 0x97, 0x96, 0xE8, 0xFB, 0xDF, 0x71, 0x8C, + 0x26, 0x47, 0x85, 0xA5, 0xBE, 0xFB, 0xF5, 0x05, 0x4C, 0xD3, 0x3D, 0x73, 0xF4, 0xA5, 0xF1, 0xA3, 0x99, 0x98, 0x1B, + 0x84, 0x8B, 0xB3, 0x53, 0xCE, 0x4D, 0xEA, 0x5A, 0x48, 0xD2, 0xB9, 0x7E, 0xB6, 0xEB, 0x9B, 0x94, 0x6F, 0xDD, 0x44, + 0x80, 0x89, 0xD2, 0x78, 0x6D, 0xB9, 0xDA, 0x8B, 0x83, 0x49, 0xE0, 0x4D, 0x49, 0xDF, 0x6B, 0xFF, 0xF7, 0x04, 0x00, + 0x32, 0xAA, 0x1D, 0x4F, 0x8D, 0x4B, 0xDE, 0xB8, 0x0D, 0xC6, 0x54, 0x1C, 0xB2, 0xCD, 0x60, 0x29, 0x72, 0x0A, 0x7E, + 0xE7, 0xEB, 0x7A, 0xF6, 0x5B, 0x04, 0x3F, 0x5B, 0x93, 0x12, 0x0D, 0xD5, 0xFF, 0x7A, 0x41, 0x44, 0x0B, 0x37, 0x12, + 0x82, 0x3D, 0xDD, 0x1E, 0x59, 0xB9, 0xBE, 0x0F, 0x9E, 0xD6, 0xD0, 0x68, 0x69, 0x74, 0xF9, 0xB1, 0x21, 0xA3, 0x70, + 0x4F, 0xDA, 0xF8, 0x9F, 0xB9, 0x49, 0x3F, 0xC6, 0xB2, 0x69, 0xC8, 0xD8, 0x60, 0xF1, 0x6A, 0x52, 0x07, 0xFA, 0x42, + 0xFD, 0xA9, 0x06, 0xCF, 0x97, 0x4A, 0x0E, 0xC5, 0xFC, 0x63, 0x27, 0x54, 0xC8, 0xBE, 0x8B, 0x4F, 0xB6, 0x42, 0xBC, + 0xA2, 0xCC, 0x70, 0x4A, 0x6B, 0x24, 0x5B, 0x68, 0x28, 0x47, 0xFA, 0x6B, 0x89, 0x28, 0x07, 0x5D, 0xE0, 0x2C, 0x4A, + 0xD9, 0x22, 0xE3, 0xB3, 0x2F, 0xAA, 0xC2, 0xA0, 0x7C, 0x0F, 0x92, 0xC5, 0xDD, 0xB6, 0x23, 0x8F, 0x73, 0x73, 0x0F, + 0xD7, 0x73, 0x71, 0x2F, 0x0A, 0x78, 0xE8, 0x5B, 0xDB, 0xC2, 0xE0, 0xDB, 0xC9, 0x3E, 0xC3, 0x72, 0x9C, 0x14, 0xD7, + 0xD1, 0x28, 0xFD, 0xF4, 0xEE, 0xBC, 0x0E, 0x13, 0x37, 0xCA, 0x85, 0x9F, 0xB9, 0xA2, 0x0E, 0xF6, 0xE7, 0x49, 0xD1, + 0xD0, 0x11, 0x76, 0x53, 0xA3, 0x73, 0x95, 0x2A, 0x23, 0xC8, 0x0E, 0x97, 0x83, 0x07, 0x64, 0xB2, 0x51, 0xB7, 0xC8, + 0x51, 0x9F, 0xA4, 0x3E, 0x7B, 0xA4, 0x18, 0x6D, 0x99, 0xF0, 0x6E, 0xC3, 0x97, 0xAE, 0xF4, 0xB7, 0x66, 0x37, 0xFA, + 0x65, 0xFC, 0x5E, 0xE2, 0x57, 0xFA, 0x8B, 0x4C, 0x86, 0x10, 0xB4, 0x5C, 0xA4, 0xD2, 0x60, 0x83, 0x69, 0x1E, 0xFF, + 0x36, 0x9B, 0xF9, 0x84, 0xFB, 0xB8, 0x83, 0x64, 0xF1, 0x41, 0xA5, 0x25, 0x56, 0x21, 0xBA, 0x13, 0x98, 0x0C, 0x3B, + 0x04, 0xAA, 0x6C, 0x9A, 0xD4, 0xE3, 0x13, 0x15, 0x54, 0x05, 0x4C, 0x5C, 0xE1, 0x7A, 0x31, 0x5E, 0x90, 0xCF, 0x48, + 0x4E, 0x83, 0xD7, 0x7F, 0xED, 0x93, 0x22, 0xAB, 0x67, 0xE7, 0x76, 0x32, 0x64, 0xBA, 0x5A, 0x21, 0x3E, 0x30, 0x82, + 0x01, 0x41, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x01, 0x32, 0x04, 0x82, + 0x01, 0x2E, 0x30, 0x82, 0x01, 0x2A, 0x30, 0x82, 0x01, 0x26, 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + 0x0C, 0x0A, 0x01, 0x02, 0xA0, 0x81, 0xEF, 0x30, 0x81, 0xEC, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, + 0x30, 0x1C, 0x04, 0x08, 0xED, 0x3E, 0xED, 0x07, 0x5C, 0x1F, 0x71, 0xAD, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, + 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x09, 0x05, 0x00, 0x30, 0x1D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x01, 0x2A, 0x04, 0x10, 0xA7, 0x49, 0xA4, 0x6E, 0x00, 0x19, 0x75, 0x59, 0x75, 0x59, 0xBA, 0x4B, + 0xC7, 0x24, 0x88, 0x34, 0x04, 0x81, 0x90, 0xCA, 0x23, 0x82, 0xAA, 0x16, 0x57, 0x99, 0xFA, 0x94, 0x9F, 0xAE, 0x32, + 0x5C, 0x5B, 0xE7, 0x01, 0xD0, 0xED, 0xA7, 0x58, 0x57, 0x52, 0xBF, 0x57, 0x13, 0xD4, 0x15, 0xB0, 0x06, 0xF5, 0x38, + 0xCC, 0x64, 0x23, 0x09, 0xD5, 0x8C, 0x0D, 0x64, 0x31, 0xFA, 0x74, 0xAA, 0x96, 0x7E, 0x9B, 0x16, 0xCA, 0x21, 0xFD, + 0xC0, 0x54, 0x91, 0x40, 0x7F, 0xB3, 0xF2, 0xA3, 0xEC, 0xA1, 0x4A, 0x07, 0xF0, 0x87, 0x22, 0xDB, 0x8A, 0x49, 0x89, + 0xF7, 0xF2, 0x6A, 0xFC, 0x8D, 0x03, 0x6E, 0x32, 0x4F, 0xD0, 0xD8, 0x93, 0x92, 0xA5, 0xF1, 0x41, 0xBD, 0xEA, 0xE1, + 0x38, 0xA9, 0xD8, 0x9D, 0xAB, 0xB4, 0x8E, 0x4A, 0x40, 0x0E, 0xC7, 0xE3, 0xE9, 0xBF, 0x0E, 0xBA, 0x8D, 0xAA, 0x3E, + 0x93, 0x53, 0x88, 0xEE, 0x0A, 0x2C, 0x71, 0xF1, 0x61, 0x44, 0xA5, 0xAD, 0xED, 0x3E, 0xAB, 0x32, 0x9A, 0x32, 0x85, + 0x08, 0xF5, 0x8B, 0xCC, 0x15, 0x35, 0xEE, 0xFA, 0x17, 0x27, 0x97, 0x8D, 0xD9, 0x1C, 0x5E, 0x74, 0x9D, 0x7B, 0x31, + 0x25, 0x30, 0x23, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x15, 0x31, 0x16, 0x04, 0x14, 0x5F, + 0x8E, 0xAB, 0x9C, 0x5F, 0xE2, 0x3B, 0xB1, 0x5C, 0x1A, 0x36, 0x1D, 0x7D, 0xCB, 0x90, 0x45, 0x20, 0x3C, 0x3B, 0xAC, + 0x30, 0x41, 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, + 0x04, 0x20, 0x93, 0x25, 0xC4, 0x3E, 0x2A, 0x6D, 0x4C, 0x30, 0x87, 0x0F, 0xE3, 0x5A, 0x95, 0xB0, 0xF2, 0x6C, 0xBA, + 0x07, 0x89, 0x7D, 0xFB, 0xCF, 0xCF, 0x1D, 0x54, 0xA3, 0x36, 0x24, 0x7B, 0x30, 0x97, 0xB5, 0x04, 0x08, 0xE7, 0x96, + 0x59, 0xCC, 0x42, 0x9F, 0xEF, 0xFC, 0x02, 0x02, 0x08, 0x00]); + + try { + cert.createTrustAnchorsWithKeyStore(p12Data, '123456').then((data) => { + console.log('createTrustAnchorsWithKeyStore sucess, the num of result is :' + JSON.stringify(data.length)); + }).catch((err: BusinessError) => { + console.error('createTrustAnchorsWithKeyStore failed, error :' + JSON.stringify(err)); + }) + } catch (error) { + console.error('createTrustAnchorsWithKeyStore failed, error :' + JSON.stringify(error)); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'CreateTrustanchorFromP12'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateTrustanchorFromP12') + .width('70%') + .onClick(() => { + try { + test(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets old mode 100755 new mode 100644 index 6513b3b8c5b66bd80ba73d51bdc15212fa490fbc..491a668636ea7ac43a8d97a5c46dbb91b527ccbe --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCerchainvalidatorObject.ets @@ -1,149 +1,149 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { util } from '@kit.ArkTS'; - -// CA数据,这只是一个示例,需要根据具体业务来赋值 -let caCertData = '-----BEGIN CERTIFICATE-----\n' + - 'MIIDgTCCAmmgAwIBAgIGAXKnJjrAMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + - 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + - '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDI1NjMxWhcN\n' + - 'MzUwMjE4MDI1NjMxWjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + - 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + - '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyY30ubE33Zmc\n' + - 'BBM4OIpD1UuDVKynC4xNBK4v79vnlc4ElmRZD4RjkS612DtpaUzt/yHMZXmJTdqg\n' + - '2jq7UG4sQc0G3uNGIXdUpRZpnUYGVftuZMxHaNOb+IgDkZzaO3Dk33piOpH/X/Ke\n' + - 'OosCbm7eBL+y+wRhUsLSCEasEsIvW3edHuYLrfz3MzwY/9AmnwqDGdRJ5rPayODD\n' + - 'HH0yw9JuRkdMacN8omVX8jBfJeI8KafcQW8MJz+Y0qyQyiZ6A81AQSVfT+6Sk2U3\n' + - 'UqeSTmtdIL1u29HfYLwYGHey+1Ro2wxqnMsFKIdKu2dDMDQZx61pER/dFtPYFlS7\n' + - '/uh3mi9HUQIDAQABo1MwUTAdBgNVHQ4EFgQUGDykmR825RPNFIEQaFzUqkr+CIow\n' + - 'HwYDVR0jBBgwFoAUGDykmR825RPNFIEQaFzUqkr+CIowDwYDVR0TAQH/BAUwAwEB\n' + - '/zANBgkqhkiG9w0BAQsFAAOCAQEAXjlmYKjBz1ajWywZNlN+LVRXNx7bS4TYtOc2\n' + - 'ME4N1ls6yjWSLtBe4DdkBqZ2HwrVW4dg5xZdAS/T0v/rRiGbX6iUFRV9WCTdtLZB\n' + - 'HKNh7vU39F7mgTaaWXQK/+6NeLKMzwJENRRaESI/sXeKE6irfJgYuq3NH8GGFd+w\n' + - 'HnvVBHRb6WSlY2s5Li7t6lj40UbwOljnqzRQvBeX57rOnzJgVKND3oY9pex/05Oe\n' + - '96x+qc2iqZbu54A6NYCTj/65EEKoj5rYxPXMV4FegV42ouaLJJoS+cEEY7w+ixcl\n' + - '04TjtjEdhTZiJCmI0RK50H2SWC0t9qkFewM3CCWTHY5ygPtMGA==\n' + - '-----END CERTIFICATE-----\n'; - -// 二级CA证书数据,这只是一个示例,需要根据具体业务来赋值 -let secondCaCertData = '-----BEGIN CERTIFICATE-----\n' + - 'MIIDgTCCAmmgAwIBAgIGAXKnJjrBMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + - 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + - '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDI1NjU3WhcN\n' + - 'MzUwMjE4MDI1NjU3WjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + - 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + - '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxSL5L7fwMaRF\n' + - 'RiT1l7kpzaAqZe33/3lgexoMfGiIFarIhYyYJsmOJKes2uLSnPeqEtscrXmFQiIG\n' + - '0srmwrriGgo3oxDp4/5i1FhCf3FqZUwD/RJhtVmkHT0HoYl4cpt/dJSF/e5vxt/J\n' + - '2Z1eRIQOj9DzyqET6+ONQmfVOyzEH6xlpXHZLvykSZ7ytPp25LxULPWjTmpDOPRq\n' + - 'vkSMaH4H3mPw/Z9r0MVKP7DgAZMl2yVudHp785AMTVD0L9zWGHf3sek25ek5nv2r\n' + - 'SlB21MTBpvd8GC/iGns4V3Bvf75WAMgpGghAkRRyADeqt5Hw+x9BIb9FcfE+h6n+\n' + - '6EF6FPa8GQIDAQABo1MwUTAdBgNVHQ4EFgQUjt2Crk/j6W8WCdHWyz4H+Q2/3PYw\n' + - 'HwYDVR0jBBgwFoAUGDykmR825RPNFIEQaFzUqkr+CIowDwYDVR0TAQH/BAUwAwEB\n' + - '/zANBgkqhkiG9w0BAQsFAAOCAQEAksPHMuVF9e2GMVlaSe1Ao9D1KrJvKNaFZPCI\n' + - 'lQe2CDsX+Qu7sQj4SML5vvWFLtcAp6ZovqUyEM0PtZWVSjPCRTMJ3ofBPwnXvQ2N\n' + - '7J7NCDA227MQabXeN3jMhkcAzlpdO5poTnobPF4xRqb39jM7otnNJsujvzdDab2l\n' + - 'LiP4eU5TrEaF2lwidBWJX0VoLrRpqzQhiWXGMpCBBugP5U+bFs20wezJBG19WYyc\n' + - '2xKKfvyIcxrpmvjLZl8HddS7Ot1CKXyc8U9QZBGAlPwOXu8juppcEtjJyl36EnvF\n' + - 'YAcwrXOAtCiNpX3UnLUbG8GtpOOWQWCt+x1gKmA6V0jbqQmqcw==\n' + - '-----END CERTIFICATE-----\n'; - -// 证书链校验器示例。在这个示例中,验证了一个二级证书链 -function certChainValidatorSample(): void { - let textEncoder = new util.TextEncoder(); - // 证书链校验器算法。目前仅支持PKIX - let algorithm = 'PKIX'; - - // 创建一个证书链校验器实例 - let validator = cert.createCertChainValidator(algorithm); - - // CA证书数据 - let uint8ArrayOfCaCertData = textEncoder.encodeInto(caCertData); - - // CA证书数据的长度 - let uint8ArrayOfCaCertDataLen = new Uint8Array(new Uint16Array([uint8ArrayOfCaCertData.byteLength]).buffer); - - // 二级CA证书数据 - let uint8ArrayOf2ndCaCertData = textEncoder.encodeInto(secondCaCertData); - - // 二级CA证书数据的长度 - let uint8ArrayOf2ndCaCertDataLen = new Uint8Array(new Uint16Array([uint8ArrayOf2ndCaCertData.byteLength]).buffer); - - // 证书链二进制数据:二级CA证书数据长度+二级CA证书数据+CA证书数据长度+CA证书数据(L-V格式) - let encodingData = new Uint8Array(uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + - uint8ArrayOfCaCertDataLen.length + uint8ArrayOfCaCertData.length); - for (let i = 0; i < uint8ArrayOf2ndCaCertDataLen.length; i++) { - encodingData[i] = uint8ArrayOf2ndCaCertDataLen[i]; - } - for (let i = 0; i < uint8ArrayOf2ndCaCertData.length; i++) { - encodingData[uint8ArrayOf2ndCaCertDataLen.length + i] = uint8ArrayOf2ndCaCertData[i]; - } - for (let i = 0; i < uint8ArrayOfCaCertDataLen.length; i++) { - encodingData[uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + i] = - uint8ArrayOfCaCertDataLen[i]; - } - for (let i = 0; i < uint8ArrayOfCaCertData.length; i++) { - encodingData[uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + - uint8ArrayOfCaCertDataLen.length + i] = uint8ArrayOfCaCertData[i]; - } - - let certChainData: cert.CertChainData = { - // Uint8Array类型:L-V格式(证书数据长度-证书数据) - data: encodingData, - // 证书的数量。本例中为2 - count: 2, - // 证书格式。仅支持 PEM 和 DER。在此示例中,证书为 PEM 格式 - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - - // 验证证书链 - validator.validate(certChainData, (err, data) => { - if (err != null) { - // 校验失败 - console.error(`validate failed, errCode: ${err.code}, errMsg: ${err.message}`); - } else { - // 校验成功 - console.log('validate success'); - } - }); -} - -@Entry -@Component -struct Index { - @State message: string = 'CreateVerifyCerchainvalidatorObject'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateVerifyCerchainvalidatorObject') - .width('70%') - .onClick(() => { - try { - certChainValidatorSample(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { util } from '@kit.ArkTS'; + +// CA数据,这只是一个示例,需要根据具体业务来赋值 +let caCertData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIDgTCCAmmgAwIBAgIGAXKnJjrAMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + + 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + + '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDI1NjMxWhcN\n' + + 'MzUwMjE4MDI1NjMxWjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + + 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + + '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyY30ubE33Zmc\n' + + 'BBM4OIpD1UuDVKynC4xNBK4v79vnlc4ElmRZD4RjkS612DtpaUzt/yHMZXmJTdqg\n' + + '2jq7UG4sQc0G3uNGIXdUpRZpnUYGVftuZMxHaNOb+IgDkZzaO3Dk33piOpH/X/Ke\n' + + 'OosCbm7eBL+y+wRhUsLSCEasEsIvW3edHuYLrfz3MzwY/9AmnwqDGdRJ5rPayODD\n' + + 'HH0yw9JuRkdMacN8omVX8jBfJeI8KafcQW8MJz+Y0qyQyiZ6A81AQSVfT+6Sk2U3\n' + + 'UqeSTmtdIL1u29HfYLwYGHey+1Ro2wxqnMsFKIdKu2dDMDQZx61pER/dFtPYFlS7\n' + + '/uh3mi9HUQIDAQABo1MwUTAdBgNVHQ4EFgQUGDykmR825RPNFIEQaFzUqkr+CIow\n' + + 'HwYDVR0jBBgwFoAUGDykmR825RPNFIEQaFzUqkr+CIowDwYDVR0TAQH/BAUwAwEB\n' + + '/zANBgkqhkiG9w0BAQsFAAOCAQEAXjlmYKjBz1ajWywZNlN+LVRXNx7bS4TYtOc2\n' + + 'ME4N1ls6yjWSLtBe4DdkBqZ2HwrVW4dg5xZdAS/T0v/rRiGbX6iUFRV9WCTdtLZB\n' + + 'HKNh7vU39F7mgTaaWXQK/+6NeLKMzwJENRRaESI/sXeKE6irfJgYuq3NH8GGFd+w\n' + + 'HnvVBHRb6WSlY2s5Li7t6lj40UbwOljnqzRQvBeX57rOnzJgVKND3oY9pex/05Oe\n' + + '96x+qc2iqZbu54A6NYCTj/65EEKoj5rYxPXMV4FegV42ouaLJJoS+cEEY7w+ixcl\n' + + '04TjtjEdhTZiJCmI0RK50H2SWC0t9qkFewM3CCWTHY5ygPtMGA==\n' + + '-----END CERTIFICATE-----\n'; + +// 二级CA证书数据,这只是一个示例,需要根据具体业务来赋值 +let secondCaCertData = '-----BEGIN CERTIFICATE-----\n' + + 'MIIDgTCCAmmgAwIBAgIGAXKnJjrBMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYT\n' + + 'AkNOMQ8wDQYDVQQIDAbpmZXopb8xDzANBgNVBAcMBuilv+WuiTEPMA0GA1UECgwG\n' + + '5rWL6K+VMRUwEwYDVQQDDAzkuK3mlofmtYvor5UwHhcNMjUwMjIwMDI1NjU3WhcN\n' + + 'MzUwMjE4MDI1NjU3WjBXMQswCQYDVQQGEwJDTjEPMA0GA1UECAwG6ZmV6KW/MQ8w\n' + + 'DQYDVQQHDAbopb/lrokxDzANBgNVBAoMBua1i+ivlTEVMBMGA1UEAwwM5Lit5paH\n' + + '5rWL6K+VMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxSL5L7fwMaRF\n' + + 'RiT1l7kpzaAqZe33/3lgexoMfGiIFarIhYyYJsmOJKes2uLSnPeqEtscrXmFQiIG\n' + + '0srmwrriGgo3oxDp4/5i1FhCf3FqZUwD/RJhtVmkHT0HoYl4cpt/dJSF/e5vxt/J\n' + + '2Z1eRIQOj9DzyqET6+ONQmfVOyzEH6xlpXHZLvykSZ7ytPp25LxULPWjTmpDOPRq\n' + + 'vkSMaH4H3mPw/Z9r0MVKP7DgAZMl2yVudHp785AMTVD0L9zWGHf3sek25ek5nv2r\n' + + 'SlB21MTBpvd8GC/iGns4V3Bvf75WAMgpGghAkRRyADeqt5Hw+x9BIb9FcfE+h6n+\n' + + '6EF6FPa8GQIDAQABo1MwUTAdBgNVHQ4EFgQUjt2Crk/j6W8WCdHWyz4H+Q2/3PYw\n' + + 'HwYDVR0jBBgwFoAUGDykmR825RPNFIEQaFzUqkr+CIowDwYDVR0TAQH/BAUwAwEB\n' + + '/zANBgkqhkiG9w0BAQsFAAOCAQEAksPHMuVF9e2GMVlaSe1Ao9D1KrJvKNaFZPCI\n' + + 'lQe2CDsX+Qu7sQj4SML5vvWFLtcAp6ZovqUyEM0PtZWVSjPCRTMJ3ofBPwnXvQ2N\n' + + '7J7NCDA227MQabXeN3jMhkcAzlpdO5poTnobPF4xRqb39jM7otnNJsujvzdDab2l\n' + + 'LiP4eU5TrEaF2lwidBWJX0VoLrRpqzQhiWXGMpCBBugP5U+bFs20wezJBG19WYyc\n' + + '2xKKfvyIcxrpmvjLZl8HddS7Ot1CKXyc8U9QZBGAlPwOXu8juppcEtjJyl36EnvF\n' + + 'YAcwrXOAtCiNpX3UnLUbG8GtpOOWQWCt+x1gKmA6V0jbqQmqcw==\n' + + '-----END CERTIFICATE-----\n'; + +// 证书链校验器示例。在这个示例中,验证了一个二级证书链 +function certChainValidatorSample(): void { + let textEncoder = new util.TextEncoder(); + // 证书链校验器算法。目前仅支持PKIX + let algorithm = 'PKIX'; + + // 创建一个证书链校验器实例 + let validator = cert.createCertChainValidator(algorithm); + + // CA证书数据 + let uint8ArrayOfCaCertData = textEncoder.encodeInto(caCertData); + + // CA证书数据的长度 + let uint8ArrayOfCaCertDataLen = new Uint8Array(new Uint16Array([uint8ArrayOfCaCertData.byteLength]).buffer); + + // 二级CA证书数据 + let uint8ArrayOf2ndCaCertData = textEncoder.encodeInto(secondCaCertData); + + // 二级CA证书数据的长度 + let uint8ArrayOf2ndCaCertDataLen = new Uint8Array(new Uint16Array([uint8ArrayOf2ndCaCertData.byteLength]).buffer); + + // 证书链二进制数据:二级CA证书数据长度+二级CA证书数据+CA证书数据长度+CA证书数据(L-V格式) + let encodingData = new Uint8Array(uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + + uint8ArrayOfCaCertDataLen.length + uint8ArrayOfCaCertData.length); + for (let i = 0; i < uint8ArrayOf2ndCaCertDataLen.length; i++) { + encodingData[i] = uint8ArrayOf2ndCaCertDataLen[i]; + } + for (let i = 0; i < uint8ArrayOf2ndCaCertData.length; i++) { + encodingData[uint8ArrayOf2ndCaCertDataLen.length + i] = uint8ArrayOf2ndCaCertData[i]; + } + for (let i = 0; i < uint8ArrayOfCaCertDataLen.length; i++) { + encodingData[uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + i] = + uint8ArrayOfCaCertDataLen[i]; + } + for (let i = 0; i < uint8ArrayOfCaCertData.length; i++) { + encodingData[uint8ArrayOf2ndCaCertDataLen.length + uint8ArrayOf2ndCaCertData.length + + uint8ArrayOfCaCertDataLen.length + i] = uint8ArrayOfCaCertData[i]; + } + + let certChainData: cert.CertChainData = { + // Uint8Array类型:L-V格式(证书数据长度-证书数据) + data: encodingData, + // 证书的数量。本例中为2 + count: 2, + // 证书格式。仅支持 PEM 和 DER。在此示例中,证书为 PEM 格式 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + + // 验证证书链 + validator.validate(certChainData, (err, data) => { + if (err != null) { + // 校验失败 + console.error(`validate failed, errCode: ${err.code}, errMsg: ${err.message}`); + } else { + // 校验成功 + console.log('validate success'); + } + }); +} + +@Entry +@Component +struct Index { + @State message: string = 'CreateVerifyCerchainvalidatorObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateVerifyCerchainvalidatorObject') + .width('70%') + .onClick(() => { + try { + certChainValidatorSample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets old mode 100755 new mode 100644 index 75ab34393e3358d58a7820f61d6bbd6835ad635e..bde5d6058dc2d2494c343a126738802c27916c16 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/CreateVerifyCertchainObject.ets @@ -1,145 +1,145 @@ -/* - * 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 { cert } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { util } from '@kit.ArkTS'; - -let certChainData = '-----BEGIN CERTIFICATE-----\n' + - 'MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n' + - 'BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n' + - 'ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n' + - 'MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n' + - 'Z3N1MRAwDgYDVQQHEwdOYW5qaW5nMQwwCgYDVQQKEwN0czMxDDAKBgNVBAsTA3Rz\n' + - 'MzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n' + - 'CgKCAQEAtt+2QxUevbolYLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLR\n' + - 'p26LFV/F8ebwPyo8YEBKSwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmc\n' + - 'rVvLBNMeVnxY86xHpo0MTNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0j\n' + - 'zT9GjeUP6JLdLFUZJKUPSTK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/U\n' + - 'T+p5ThAMH593zszlz330nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI3\n' + - '8MFQFJKvRHfgTAvVsvAvpBUM2DuBKwIDAQABo4GsMIGpMAkGA1UdEwQCMAAwHQYD\n' + - 'VR0OBBYEFDfsHTMZwoA6eaDFlBUyDpka+sYtMAsGA1UdDwQEAwID+DAnBgNVHSUE\n' + - 'IDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEy\n' + - 'Ny4wLjAuMTARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBj\n' + - 'ZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEAp5vTvXrt8ZpgRJVtzv9ss0lJ\n' + - 'izp1fJf+ft5cDXrs7TSD5oHrSW2vk/ZieIMhexU4LFwhs4OE7jK6pgI48Dseqxx7\n' + - 'B/KktxhVMJUmVXd9Ayjp6f+BtZlIk0cArPuoXToXjsV8caTGBXHRdzxpAk/w9syc\n' + - 'GYrbH9TrdNMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n' + - 'DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n' + - 'iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n' + - '-----END CERTIFICATE-----\n' + - '-----BEGIN CERTIFICATE-----\n' + - 'MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n' + - 'DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n' + - 'MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n' + - 'OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n' + - 'A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n' + - 'AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n' + - 'YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n' + - 'SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n' + - 'TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n' + - 'STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n' + - 'nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n' + - 'pBUM2DuBKwIDAQABo28wbTAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBQ37B0zGcKA\n' + - 'OnmgxZQVMg6ZGvrGLTALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEBBAQDAgAHMB4G\n' + - 'CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n' + - 'b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n' + - 'uKPWR9dKBA==\n' + - '-----END CERTIFICATE-----\n' + - '-----BEGIN CERTIFICATE-----\n' + - 'MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n' + - 'DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n' + - 'MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n' + - 'MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n' + - 'A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n' + - 'AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n' + - 'klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n' + - 'St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n' + - 'AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n' + - 'KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n' + - 'xjoE\n' + - '-----END CERTIFICATE-----\n'; - -async function sample() { - let textEncoder = new util.TextEncoder(); - // 证书链二进制数据,需业务自行赋值 - const encodingBlob: cert.EncodingBlob = { - data: textEncoder.encodeInto(certChainData), - // 根据encodingData的格式进行赋值,支持FORMAT_PEM、FORMAT_DER和FORMAT_PKCS7 - encodingFormat: cert.EncodingFormat.FORMAT_PEM - }; - let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; - try { - x509CertChain = await cert.createX509CertChain(encodingBlob); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`createX509CertChain failed, errCode: ${e.code}, errMsg: ${e.message}`); - } - - try { - let certList = x509CertChain.getCertList(); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`X509CertChain getCertList failed, errCode: ${e.code}, errMsg: ${e.message}`); - } - - // 证书链校验数据,需业务自行赋值 - const param: cert.CertChainValidationParameters = { - date: '20231212080000Z', - trustAnchors: [{ - CAPubKey: new Uint8Array([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, 0xbb, 0x16, - 0x9d, 0x8f, 0x5c, 0x30, 0xd0, 0xba, 0x8f, 0x37, 0x6e, 0x33, 0xaf, 0x6f, 0x23, 0x71, 0x23, 0xa5, 0x49, 0x60, - 0x1e, 0xd1, 0x07, 0x4b, 0xc9, 0x11, 0x7e, 0x66, 0x01, 0xba, 0x92, 0x52]), - CASubject: new Uint8Array([0x30, 0x5a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x45, - 0x4e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x45, 0x6e, 0x67, 0x6c, 0x61, 0x6e, - 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x06, 0x4c, 0x6f, 0x6e, 0x64, 0x6f, 0x6e, - 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, - 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, - 0x03, 0x13, 0x03, 0x74, 0x73, 0x31]), - }] - }; - try { - const validationRes = await x509CertChain.validate(param); - console.log('X509CertChain validate success'); - } catch (err) { - console.error('X509CertChain validate failed'); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'CreateVerifyCertchainObject'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button('Call CreateVerifyCertchainObject') - .width('70%') - .onClick(()=>{ - try { - sample(); - this.message = 'Call Success'; - } catch { - this.message = 'Call Fail'; - } - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { cert } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { util } from '@kit.ArkTS'; + +let certChainData = '-----BEGIN CERTIFICATE-----\n' + + 'MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n' + + 'BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n' + + 'ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n' + + 'MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n' + + 'Z3N1MRAwDgYDVQQHEwdOYW5qaW5nMQwwCgYDVQQKEwN0czMxDDAKBgNVBAsTA3Rz\n' + + 'MzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n' + + 'CgKCAQEAtt+2QxUevbolYLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLR\n' + + 'p26LFV/F8ebwPyo8YEBKSwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmc\n' + + 'rVvLBNMeVnxY86xHpo0MTNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0j\n' + + 'zT9GjeUP6JLdLFUZJKUPSTK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/U\n' + + 'T+p5ThAMH593zszlz330nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI3\n' + + '8MFQFJKvRHfgTAvVsvAvpBUM2DuBKwIDAQABo4GsMIGpMAkGA1UdEwQCMAAwHQYD\n' + + 'VR0OBBYEFDfsHTMZwoA6eaDFlBUyDpka+sYtMAsGA1UdDwQEAwID+DAnBgNVHSUE\n' + + 'IDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEy\n' + + 'Ny4wLjAuMTARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBj\n' + + 'ZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEAp5vTvXrt8ZpgRJVtzv9ss0lJ\n' + + 'izp1fJf+ft5cDXrs7TSD5oHrSW2vk/ZieIMhexU4LFwhs4OE7jK6pgI48Dseqxx7\n' + + 'B/KktxhVMJUmVXd9Ayjp6f+BtZlIk0cArPuoXToXjsV8caTGBXHRdzxpAk/w9syc\n' + + 'GYrbH9TrdNMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n' + + 'DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n' + + 'iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n' + + '-----END CERTIFICATE-----\n' + + '-----BEGIN CERTIFICATE-----\n' + + 'MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n' + + 'DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n' + + 'MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n' + + 'OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n' + + 'A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n' + + 'AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n' + + 'YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n' + + 'SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n' + + 'TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n' + + 'STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n' + + 'nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n' + + 'pBUM2DuBKwIDAQABo28wbTAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBQ37B0zGcKA\n' + + 'OnmgxZQVMg6ZGvrGLTALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEBBAQDAgAHMB4G\n' + + 'CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n' + + 'b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n' + + 'uKPWR9dKBA==\n' + + '-----END CERTIFICATE-----\n' + + '-----BEGIN CERTIFICATE-----\n' + + 'MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n' + + 'DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n' + + 'MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n' + + 'MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n' + + 'A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n' + + 'AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n' + + 'klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n' + + 'St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n' + + 'AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n' + + 'KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n' + + 'xjoE\n' + + '-----END CERTIFICATE-----\n'; + +async function sample() { + let textEncoder = new util.TextEncoder(); + // 证书链二进制数据,需业务自行赋值 + const encodingBlob: cert.EncodingBlob = { + data: textEncoder.encodeInto(certChainData), + // 根据encodingData的格式进行赋值,支持FORMAT_PEM、FORMAT_DER和FORMAT_PKCS7 + encodingFormat: cert.EncodingFormat.FORMAT_PEM + }; + let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; + try { + x509CertChain = await cert.createX509CertChain(encodingBlob); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`createX509CertChain failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + + try { + let certList = x509CertChain.getCertList(); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`X509CertChain getCertList failed, errCode: ${e.code}, errMsg: ${e.message}`); + } + + // 证书链校验数据,需业务自行赋值 + const param: cert.CertChainValidationParameters = { + date: '20231212080000Z', + trustAnchors: [{ + CAPubKey: new Uint8Array([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, 0xbb, 0x16, + 0x9d, 0x8f, 0x5c, 0x30, 0xd0, 0xba, 0x8f, 0x37, 0x6e, 0x33, 0xaf, 0x6f, 0x23, 0x71, 0x23, 0xa5, 0x49, 0x60, + 0x1e, 0xd1, 0x07, 0x4b, 0xc9, 0x11, 0x7e, 0x66, 0x01, 0xba, 0x92, 0x52]), + CASubject: new Uint8Array([0x30, 0x5a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x45, + 0x4e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x45, 0x6e, 0x67, 0x6c, 0x61, 0x6e, + 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x06, 0x4c, 0x6f, 0x6e, 0x64, 0x6f, 0x6e, + 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, + 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, + 0x03, 0x13, 0x03, 0x74, 0x73, 0x31]), + }] + }; + try { + const validationRes = await x509CertChain.validate(param); + console.log('X509CertChain validate success'); + } catch (err) { + console.error('X509CertChain validate failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'CreateVerifyCertchainObject'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button('Call CreateVerifyCertchainObject') + .width('70%') + .onClick(()=>{ + try { + sample(); + this.message = 'Call Success'; + } catch { + this.message = 'Call Fail'; + } + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 old mode 100755 new mode 100644 index ee5b41c51094121dbfbc99f591367ec5bf680d2a..4bdc71c1d64e827bf919ab4a9fde28908d33746e --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/module.json5 @@ -1,78 +1,78 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.ACCESS_CERT_MANAGER", - "reason": "$string:reason", - "usedScene": { - "abilities": [ - "FormAbility" - ], - "when": "always" - } - }, - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_CERT_MANAGER", + "reason": "$string:reason", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + }, + ] + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets old mode 100755 new mode 100644 index 66e63896639aaf2cc52ee862fb85b881947c1d86..a99ab838b79a8fa43323c78b4fd4afd4854955b7 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/CertificateAlgorithmLibrary.test.ets @@ -1,176 +1,176 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function certificateAlgorithmLibraryTest() { - describe('certificateAlgorithmLibraryTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,创建、解析校验证书对象 - */ - it('testCertificateAlgorithmLibrary001', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateParseVerifyCertObject')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCertObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary001 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,创建、解析和校验证书扩展信息对象 - */ - it('testCertificateAlgorithmLibrary002', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateParseVerifyCertextensionObject')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCertextensionObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary002 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,创建、解析和校验证书吊销列表对象 - */ - it('testCertificateAlgorithmLibrary003', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary003 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateParseVerifyCrlObject')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCrlObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary003 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,构造TrustAnchor对象数组 - */ - it('testCertificateAlgorithmLibrary004', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary004 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateTrustanchorFromP12')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateTrustanchorFromP12')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary004 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,创建和校验证书链校验器对象 - */ - it('testCertificateAlgorithmLibrary005', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary005 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateVerifyCerchainvalidatorObject')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateVerifyCerchainvalidatorObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary005 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,创建和获取证书集合及证书吊销列表集合对象 - */ - it('testCertificateAlgorithmLibrary006', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateGetCertCrlObject')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateGetCertCrlObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary006 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,创建和校验证书链对象 - */ - it('testCertificateAlgorithmLibrary007', 0, async (done: Function) => { - console.info('uitest: testCertificateAlgorithmLibrary007 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CreateVerifyCertchainObject')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CreateVerifyCertchainObject')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call Success')); - console.info('uitest: testCertificateAlgorithmLibrary007 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function certificateAlgorithmLibraryTest() { + describe('certificateAlgorithmLibraryTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,创建、解析校验证书对象 + */ + it('testCertificateAlgorithmLibrary001', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateParseVerifyCertObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCertObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary001 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建、解析和校验证书扩展信息对象 + */ + it('testCertificateAlgorithmLibrary002', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateParseVerifyCertextensionObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCertextensionObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary002 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建、解析和校验证书吊销列表对象 + */ + it('testCertificateAlgorithmLibrary003', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary003 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateParseVerifyCrlObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateParseVerifyCrlObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary003 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,构造TrustAnchor对象数组 + */ + it('testCertificateAlgorithmLibrary004', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary004 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateTrustanchorFromP12')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateTrustanchorFromP12')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary004 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建和校验证书链校验器对象 + */ + it('testCertificateAlgorithmLibrary005', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary005 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateVerifyCerchainvalidatorObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateVerifyCerchainvalidatorObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary005 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建和获取证书集合及证书吊销列表集合对象 + */ + it('testCertificateAlgorithmLibrary006', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateGetCertCrlObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateGetCertCrlObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary006 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,创建和校验证书链对象 + */ + it('testCertificateAlgorithmLibrary007', 0, async (done: Function) => { + console.info('uitest: testCertificateAlgorithmLibrary007 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CreateVerifyCertchainObject')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CreateVerifyCertchainObject')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call Success')); + console.info('uitest: testCertificateAlgorithmLibrary007 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/List.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigor/hvigor-config.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigorfile.ts b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/oh-package.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/oh-package.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md old mode 100755 new mode 100644 index 810f0307b3e8526d329ea7276084fd8a8f144ec1..282567f26044325a9eec99dc10a98adbf4a7e459 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/ohosTest.md @@ -1,14 +1,14 @@ -# 证书算法库测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,创建、解析校验证书对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,创建、解析和校验证书扩展信息对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,创建、解析和校验证书吊销列表对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,构造TrustAnchor对象数组 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,创建和校验证书链校验器对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | -| 点击按钮,创建和获取证书集合及证书吊销列表集合对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# 证书算法库测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,创建、解析校验证书对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建、解析和校验证书扩展信息对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建、解析和校验证书吊销列表对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,构造TrustAnchor对象数组 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建和校验证书链校验器对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,创建和获取证书集合及证书吊销列表集合对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮,创建和校验证书链对象 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary1.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary2.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateAlgorithmLibrary/screenshots/CertificateAlgorithmLibrary2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/.gitignore b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/app.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/app.json5 old mode 100755 new mode 100644 index 5963407ce75af2af37e39011956aaf2ec925989d..f6dcb15f5a47f36774ee0587223fffd5f5c464d9 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/app.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/app.json5 @@ -1,25 +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.certificatemanagement", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.certificatemanagement", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 4763eada6a8c5012861a0afda6e8283d95866896..939dfafaa7e20bd1f187de1f7f7097929946b194 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "CertificateManagement" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "CertificateManagement" + } + ] +} diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/README.md b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/README.md old mode 100755 new mode 100644 index 26c19d65e92e7220cba0640e799faeff5e307e4d..33eb0cc35131b2fd355e79f69e45514d631625a2 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/README.md +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/README.md @@ -1,72 +1,72 @@ -# 证书管理 - -### 介绍 - -证书管理主要提供系统级的证书管理能力,实现证书全生命周期(安装、存储、使用和销毁)的管理和安全使用。 - -本示例主要展示了证书管理中证书管理与证书管理对话框的使用场景。该工程中展示的代码详细描述可查如下链接中介绍。 - -- [证书管理开发指导](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/certManager-guidelines.md) -- [证书管理对话框开发指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/DeviceCertificateKit/certManagerDialog-guidelines.md) - -### 效果预览 - -| 首页效果图 | 执行结果图 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| | | - -### 使用说明 - -1. 运行Index主界面。 -2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 -3. 运行测试用例CertificateManagement.test.ets文件对页面代码进行测试可以全部通过。 - -### 工程目录 - -``` -entry/src/ - ├── main - │ ├── ets - │ │ ├── entryability - │ │ ├── entrybackupability - │ │ ├── pages - │ │ ├── Index.ets // 证书管理示例代码 - │ │ ├── CertManagerGuidelines.ets - │ │ ├── CertManagerDialogGuidelines.ets - │ ├── module.json5 - │ └── resources - ├── ohosTest - │ ├── ets - │ │ └── test - │ │ ├── Ability.test.ets - │ │ ├── CertificateManagement.test.ets // 自动化测试代码 - │ │ └── List.test.ets -``` - -### 相关权限 - -[ohos.permission.ACCESS_CERT_MANAGER](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccesscertmanager) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行, 支持设备:RK3568。 - -2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 - -3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -```` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/DeviceCertificateKit/CertificateManagement > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 证书管理 + +### 介绍 + +证书管理主要提供系统级的证书管理能力,实现证书全生命周期(安装、存储、使用和销毁)的管理和安全使用。 + +本示例主要展示了证书管理中证书管理与证书管理对话框的使用场景。该工程中展示的代码详细描述可查如下链接中介绍。 + +- [证书管理开发指导](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/DeviceCertificateKit/certManager-guidelines.md) +- [证书管理对话框开发指导](https://gitee.com/openharmony/docs/blob/OpenHarmony-5.0.1-Release/zh-cn/application-dev/security/DeviceCertificateKit/certManagerDialog-guidelines.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例CertificateManagement.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 证书管理示例代码 + │ │ ├── CertManagerGuidelines.ets + │ │ ├── CertManagerDialogGuidelines.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── CertificateManagement.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +[ohos.permission.ACCESS_CERT_MANAGER](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccesscertmanager) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/DeviceCertificateKit/CertificateManagement > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ```` \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/build-profile.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/build-profile.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/code-linter.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/.gitignore b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/hvigorfile.ts b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/oh-package.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/oh-package.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets old mode 100755 new mode 100644 index dddba1b3a4bb66b415939a12bfbe09f872b2d8ea..7f7affd17e39117ff8bd5c17c2b21319695fa3b3 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerDialogGuidelines.ets @@ -1,57 +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 { certificateManagerDialog } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { common } from '@kit.AbilityKit'; - -async function certificateManagerDialogSample() { - /* context为应用的上下文信息,由调用方自行获取,此处仅为示例 */ - let context: common.Context = getContext(); - /* pageType为页面类型,此处赋值PAGE_MAIN,即拉起证书管理主界面 */ - let pageType: certificateManagerDialog.CertificateDialogPageType = - certificateManagerDialog.CertificateDialogPageType.PAGE_MAIN; - try { - certificateManagerDialog.openCertificateManagerDialog(context, pageType).then(() => { - console.info('Succeeded in opening certificate manager dialog.'); - }).catch((err: BusinessError) => { - console.error(`Failed to open certificate manager dialog. Code: ${err.code}, message: ${err.message}`); - }) - } catch (error) { - console.error(`Failed to open certificate manager dialog. Code: ${error.code}, message: ${error.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'CertManagerDialogGuidelines'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Bold) - .fontSize(25) - Button($r('app.string.call_certManagerDialogGuidelines')) - .width('70%') - .onClick(() => { - certificateManagerDialogSample(); - this.message = 'CertManagerDialogGuidelines Success'; - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { certificateManagerDialog } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; + +async function certificateManagerDialogSample() { + /* context为应用的上下文信息,由调用方自行获取,此处仅为示例 */ + let context: common.Context = getContext(); + /* pageType为页面类型,此处赋值PAGE_MAIN,即拉起证书管理主界面 */ + let pageType: certificateManagerDialog.CertificateDialogPageType = + certificateManagerDialog.CertificateDialogPageType.PAGE_MAIN; + try { + certificateManagerDialog.openCertificateManagerDialog(context, pageType).then(() => { + console.info('Succeeded in opening certificate manager dialog.'); + }).catch((err: BusinessError) => { + console.error(`Failed to open certificate manager dialog. Code: ${err.code}, message: ${err.message}`); + }) + } catch (error) { + console.error(`Failed to open certificate manager dialog. Code: ${error.code}, message: ${error.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'CertManagerDialogGuidelines'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Bold) + .fontSize(25) + Button($r('app.string.call_certManagerDialogGuidelines')) + .width('70%') + .onClick(() => { + certificateManagerDialogSample(); + this.message = 'CertManagerDialogGuidelines Success'; + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets old mode 100755 new mode 100644 index 09baa8cb5610f4e7a4abc0922de889e1a104e562..c7be60323dc46534e58e8995517a7a50cfb63227 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/CertManagerGuidelines.ets @@ -1,295 +1,295 @@ -/* - * 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 { certificateManager } from '@kit.DeviceCertificateKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -async function certificateManagerSample() { - /* 安装的凭据数据需要业务赋值,本例数据非凭据数据 */ - let keystore: Uint8Array = new Uint8Array([ - 0x30,0x82,0x0c,0x26,0x02,0x01,0x03,0x30,0x82,0x0b,0xe0,0x06,0x09,0x2a,0x86,0x48, - 0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x82,0x0b,0xd1,0x04,0x82,0x0b,0xcd,0x30,0x82, - 0x0b,0xc9,0x30,0x82,0x05,0x6e,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07, - 0x01,0xa0,0x82,0x05,0x5f,0x04,0x82,0x05,0x5b,0x30,0x82,0x05,0x57,0x30,0x82,0x05, - 0x53,0x06,0x0b,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x0a,0x01,0x02,0xa0,0x82, - 0x04,0xfa,0x30,0x82,0x04,0xf6,0x30,0x28,0x06,0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d, - 0x01,0x0c,0x01,0x03,0x30,0x1a,0x04,0x14,0xb6,0x80,0x7d,0xb9,0xc3,0x44,0x84,0x1f, - 0x44,0xe6,0x95,0x6a,0x98,0xa1,0xcb,0x97,0xfb,0x2b,0xcc,0x5a,0x02,0x02,0x04,0x00, - 0x04,0x82,0x04,0xc8,0x78,0xa7,0x16,0x45,0x40,0xf0,0xec,0xac,0x3e,0x34,0x17,0xd7, - 0x8b,0x5c,0xca,0x85,0x29,0x0b,0x08,0xef,0xa2,0xf0,0x6d,0x55,0xd7,0xde,0x96,0xa5, - 0x49,0x6d,0x9d,0xa6,0xe6,0x00,0xd7,0x2c,0x65,0xf6,0xc2,0xd1,0xe8,0x70,0xfb,0xb5, - 0xd9,0xc6,0x7d,0xd4,0x28,0x45,0x17,0x4f,0x4f,0xd9,0x9b,0xab,0xe2,0xdc,0xe7,0x22, - 0x6c,0x1e,0xbc,0xd6,0xf0,0x38,0x0b,0xd7,0xd9,0xfc,0xa7,0xb4,0x87,0x95,0x96,0xc3, - 0x93,0xc0,0xb5,0x37,0xf4,0x64,0xfe,0xe5,0x07,0xac,0x41,0x2d,0xf5,0xeb,0xe3,0x8b, - 0xc2,0x74,0x73,0x13,0x3b,0x5f,0x17,0x54,0x2d,0x31,0x20,0x69,0x1c,0xab,0x66,0xba, - 0x06,0x43,0x03,0xa3,0x69,0x54,0x72,0x70,0x5f,0x78,0xd2,0xec,0xdd,0x50,0xb8,0x25, - 0x03,0xd4,0xec,0x2d,0x92,0x96,0x9f,0xcc,0xa6,0x4a,0x50,0x34,0x1c,0xfc,0xe3,0xc2, - 0x6b,0x65,0xec,0xb3,0x1c,0xc8,0xf2,0xd0,0x79,0xf0,0x28,0x61,0x9a,0xfe,0xea,0x7f, - 0x16,0x38,0xe1,0xf4,0x7f,0x86,0xfe,0x73,0x67,0xc9,0x60,0x73,0xd8,0xef,0x2c,0x6b, - 0xde,0x88,0x37,0xc5,0xd7,0x18,0x60,0x74,0x97,0x07,0x85,0x70,0x74,0x30,0x66,0x8f, - 0x11,0x4a,0xb9,0x18,0xed,0xfc,0xc7,0xdb,0x63,0x58,0x7b,0x57,0x0d,0xfa,0x43,0x81, - 0xbd,0x34,0xfc,0x17,0xd3,0x2a,0xa9,0x74,0xa0,0x2c,0x1b,0xe2,0xaa,0x3d,0xd2,0x84, - 0x18,0xaa,0x2a,0x0e,0xa8,0xcc,0x2a,0xc4,0x39,0x60,0x29,0xb5,0x03,0xaf,0xea,0x96, - 0xcf,0xa5,0x67,0x4c,0xa7,0x59,0x76,0xea,0x8a,0x60,0xd6,0xd8,0xc3,0x9e,0x0e,0xad, - 0xd6,0xa0,0x5a,0x00,0x7c,0xa6,0xe8,0x62,0xa4,0x0a,0x53,0xcc,0x48,0xf0,0x4d,0x6d, - 0xda,0xb3,0xa9,0x82,0x37,0x75,0xff,0x20,0xa9,0xe8,0x6e,0xc8,0x4a,0x8a,0x81,0x84, - 0x7a,0x1d,0x02,0x40,0xd9,0x76,0xee,0x89,0x62,0xd5,0x57,0x19,0xc8,0x9a,0x6a,0x22, - 0x8d,0x01,0x8f,0xc9,0x14,0x72,0xf9,0x90,0xa3,0x0f,0x5f,0x23,0x32,0xc4,0xd5,0x79, - 0x53,0x1f,0xbc,0x3a,0xf4,0x19,0x7f,0x93,0xb7,0x8b,0x0b,0xb9,0xeb,0x1f,0xa2,0x5c, - 0x93,0x0e,0x5f,0x29,0x87,0xea,0x67,0x4d,0x5d,0x2b,0x5e,0x29,0x81,0xbd,0x3d,0xfc, - 0xdf,0x92,0x50,0x19,0xc2,0x50,0x4d,0x07,0x76,0x08,0xfc,0xbe,0xd1,0x73,0x64,0xb7, - 0x22,0x6f,0xb7,0x89,0x93,0xc1,0xb1,0x44,0x42,0x27,0xf5,0x61,0x06,0x32,0xd1,0xc0, - 0xdb,0x92,0x51,0x1b,0xd3,0x5c,0x95,0x85,0x0e,0x66,0xc5,0xe9,0xf5,0x7f,0x44,0x52, - 0x49,0xfb,0x0a,0x83,0x02,0x6e,0x69,0x6c,0xf1,0x6f,0xe5,0xa1,0xa0,0x5d,0x8a,0xd3, - 0x4f,0x9d,0x0a,0x08,0x1b,0x32,0x70,0xe3,0xf3,0xf0,0x63,0xda,0x37,0x90,0x96,0x3f, - 0xac,0xf7,0x3d,0xd5,0xeb,0x08,0xc1,0x51,0x91,0x75,0x2c,0x0f,0xf1,0x5b,0x39,0xce, - 0x05,0x06,0x65,0x1c,0xe8,0x36,0xb0,0x86,0x6e,0xbe,0xb9,0x25,0xd6,0xdf,0x5c,0x50, - 0x56,0x99,0x69,0x8e,0x92,0xbe,0xa1,0x03,0x18,0xd6,0x34,0xa6,0x98,0x53,0x3a,0xb7, - 0x96,0xcb,0xa8,0x1d,0xc9,0x9e,0x92,0x15,0xf4,0x99,0x7e,0x58,0x81,0x99,0x84,0xa0, - 0x67,0xa5,0x77,0x1e,0xa9,0xac,0xc2,0xcf,0xd8,0x7a,0x68,0xef,0x35,0x9e,0xb6,0xb7, - 0x78,0x6b,0x43,0x12,0x53,0x93,0x7b,0x50,0x94,0x37,0x48,0x75,0x98,0x27,0x0f,0x73, - 0x1a,0xb7,0x2f,0x19,0x7e,0x42,0x08,0x02,0x05,0x42,0x71,0xd6,0x26,0x64,0x04,0x25, - 0x87,0xd9,0x02,0x05,0x1f,0x79,0x6b,0x9b,0x0e,0xfa,0x10,0x7b,0xf3,0x96,0x3f,0x53, - 0x02,0x9d,0x80,0x13,0xd7,0x30,0x03,0x24,0x96,0x21,0x05,0xdb,0x2d,0xe9,0xc8,0x51, - 0x30,0x42,0x6d,0xa9,0xe8,0x39,0xb0,0xa9,0x59,0xb9,0x21,0x22,0x98,0x41,0x0e,0x33, - 0x0d,0x7f,0x7a,0x69,0x45,0x0b,0xf1,0xac,0xfd,0xaa,0xaa,0x45,0x7f,0x78,0x24,0xf8, - 0x56,0x85,0x3b,0x4b,0x95,0x78,0x40,0xc7,0x2f,0xfc,0xb6,0xb7,0x5f,0xa2,0xf9,0xe9, - 0x80,0x4c,0x4a,0xbf,0x4f,0xcb,0xb9,0x51,0x7c,0x18,0xb7,0xb7,0x70,0xf1,0x4c,0x96, - 0xd2,0x4a,0x44,0xb9,0xa6,0x22,0xc9,0x95,0xf5,0x99,0xbd,0x8c,0xf2,0x45,0x88,0xfb, - 0x2f,0xe0,0x38,0x42,0xc8,0xe5,0x0d,0x55,0x05,0x0f,0xb9,0x91,0x7d,0xaf,0x27,0x91, - 0xb3,0xc4,0x83,0x46,0x49,0x1a,0xce,0x3a,0xff,0x1b,0x58,0xc9,0xa4,0x22,0x82,0x57, - 0x7f,0xda,0x5f,0xae,0xea,0xae,0x96,0x91,0xef,0xde,0x4e,0x25,0x66,0xbb,0xe9,0xb3, - 0xa7,0xbc,0x12,0xc4,0x5f,0xee,0xc6,0x13,0x9c,0xd9,0xbc,0x14,0xef,0x3d,0x7b,0xa4, - 0x91,0x4a,0x77,0xfd,0x18,0x9c,0xc7,0x38,0xaf,0x24,0x3f,0x6c,0x8f,0x8f,0x6e,0x2c, - 0x38,0x7c,0xa4,0xba,0xc7,0x70,0x90,0x6d,0x5e,0x51,0x3c,0xe0,0x3d,0xc5,0xa8,0x44, - 0xb0,0xf4,0x0b,0xba,0xe0,0x0e,0x8b,0x65,0xeb,0x04,0xfd,0x1a,0x8b,0x94,0xbf,0xfe, - 0xf0,0x64,0xa4,0xfa,0xb4,0xe1,0x11,0xd4,0x95,0x13,0xee,0xce,0xf6,0x14,0xf7,0x1c, - 0xbc,0xf5,0x64,0x90,0x88,0x69,0xb2,0xfd,0x26,0x26,0x83,0xa7,0x4c,0x3d,0x27,0xae, - 0x3c,0x68,0xb5,0xcc,0x9f,0x46,0xc2,0x9a,0x95,0x9a,0xa7,0x8b,0x4a,0x14,0xf7,0x80, - 0x9f,0x04,0xf9,0x39,0x3b,0x55,0x9e,0xb5,0x1c,0x79,0x7d,0x2d,0x9b,0x29,0xb9,0x7c, - 0x61,0x01,0xf5,0x26,0x1e,0xa0,0xcb,0x18,0xaf,0xc6,0x6d,0x2f,0x42,0xb7,0xa5,0x94, - 0x91,0xa5,0xc0,0x15,0xd9,0x18,0x4e,0xb6,0xc3,0x77,0x9e,0x59,0x6e,0x61,0x48,0x32, - 0xcf,0x5e,0x09,0x3a,0x17,0x48,0x59,0x68,0x9a,0x6c,0x7f,0xd3,0x71,0xd8,0x2c,0xce, - 0x58,0x68,0x33,0x79,0xe6,0xb6,0xf0,0xb5,0xac,0xb0,0xa4,0xc0,0x10,0x0f,0xad,0x02, - 0x19,0x58,0x53,0x5a,0x9a,0x5d,0x84,0xa6,0x8e,0x3c,0xc8,0xa9,0x22,0xb5,0x2a,0x39, - 0x3f,0xf8,0x76,0x53,0xea,0x7b,0x23,0x81,0x2b,0xe1,0x1d,0x63,0xb3,0x83,0x76,0xc8, - 0xd3,0x5e,0xba,0x97,0x79,0x9b,0xfb,0xf3,0x1e,0x10,0xac,0xd8,0x2e,0xa0,0x64,0xba, - 0x02,0x21,0x18,0x05,0xd1,0x30,0xdd,0x33,0x32,0x98,0x3d,0x0d,0x22,0xb4,0xda,0x8d, - 0xa0,0x9a,0x3a,0x97,0x0f,0xa5,0xe1,0xf1,0x56,0x17,0xd8,0xbd,0x15,0xd3,0xd6,0xe0, - 0x20,0x95,0x7b,0x6a,0x63,0x59,0x80,0xee,0xcd,0x60,0xb1,0xb0,0xba,0x8d,0x6a,0x4c, - 0x3d,0x5c,0xac,0x1a,0x87,0x1d,0x07,0xfe,0x69,0x81,0x8f,0x5d,0xba,0x64,0x3f,0xea, - 0xdf,0x36,0xb3,0x07,0x6c,0xbc,0x5b,0xe8,0xc0,0x5c,0x9a,0xd1,0x16,0xe3,0x2e,0xa5, - 0x92,0x5b,0xba,0x89,0x55,0x65,0x5d,0x14,0xd2,0x36,0x9e,0xfd,0x6d,0xcf,0x9d,0x68, - 0x10,0x7f,0xb6,0xdf,0x6b,0x9a,0x9b,0xd4,0x6b,0x37,0xfd,0x77,0xde,0x39,0x59,0xed, - 0xe3,0xdb,0x65,0xe8,0xa4,0x15,0x4a,0x6d,0xb4,0xad,0xb8,0x36,0xe1,0x3a,0xf8,0x6a, - 0xfe,0x6e,0x1f,0x02,0x15,0x09,0x36,0x44,0xb7,0x52,0x5b,0x79,0x3c,0x8e,0xfb,0x20, - 0x62,0xdb,0x7b,0xb6,0xb1,0x43,0xea,0x29,0xff,0x10,0xef,0x24,0x9c,0x4d,0xc2,0xa8, - 0x98,0xaa,0x29,0x59,0x85,0x06,0xc3,0xdb,0xcf,0xc2,0x71,0xfa,0xad,0x7b,0xd5,0xf7, - 0x50,0x53,0xc5,0x75,0x97,0x15,0x42,0x90,0x8f,0xf1,0xed,0x6a,0x98,0x83,0x59,0x15, - 0x23,0xa7,0xea,0xe9,0xed,0x22,0xec,0x0a,0x41,0x4c,0xc2,0x35,0x54,0xd9,0xec,0x4b, - 0xb8,0x3f,0xd0,0x68,0xed,0xa7,0x83,0x4e,0x42,0x29,0x5c,0x4d,0xa3,0x79,0x3e,0x59, - 0x86,0x04,0x62,0x24,0x9d,0x7b,0xb3,0x69,0xe9,0x82,0x57,0xdb,0xbf,0xeb,0x98,0x4f, - 0x59,0x7e,0x8d,0x8f,0x69,0x56,0xdc,0x3f,0xeb,0x01,0xcf,0x82,0x05,0x1e,0xe7,0x6d, - 0xff,0xb2,0x67,0xd8,0x34,0x68,0xf7,0xd0,0xee,0x6d,0xc6,0x22,0x4c,0x4d,0x36,0xd1, - 0xf5,0x5a,0xab,0xbb,0x41,0x43,0x4d,0xef,0x2c,0x62,0x64,0x28,0x31,0x46,0x30,0x1f, - 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x14,0x31,0x12,0x1e,0x10,0x00, - 0x6c,0x00,0x64,0x00,0x71,0x00,0x20,0x00,0x74,0x00,0x65,0x00,0x73,0x00,0x74,0x30, - 0x23,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x15,0x31,0x16,0x04,0x14, - 0x44,0x37,0x75,0x8f,0xcd,0x94,0x90,0x07,0x3e,0x38,0x20,0xb7,0x1b,0x3f,0x0d,0x3d, - 0x40,0x85,0x32,0x6a,0x30,0x82,0x06,0x53,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d, - 0x01,0x07,0x06,0xa0,0x82,0x06,0x44,0x30,0x82,0x06,0x40,0x02,0x01,0x00,0x30,0x82, - 0x06,0x39,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0x30,0x28,0x06, - 0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x01,0x06,0x30,0x1a,0x04,0x14,0xc8, - 0xe2,0x48,0x69,0x85,0x06,0xb3,0x34,0x55,0xf1,0xfe,0x9c,0x95,0x92,0xbd,0x73,0xcd, - 0x50,0xf4,0x88,0x02,0x02,0x04,0x00,0x80,0x82,0x06,0x00,0xb6,0x66,0x06,0x1a,0x84, - 0xb1,0xb7,0xf8,0xca,0x74,0xe1,0x7c,0x23,0x94,0x5f,0xb3,0x73,0xda,0x81,0x51,0x0e, - 0x4d,0x07,0xcd,0x8a,0x68,0xd5,0x15,0x98,0x57,0xc1,0xb9,0x94,0x30,0xc7,0x97,0x40, - 0x3b,0xa4,0xc0,0xd5,0xfe,0xd3,0x9f,0x92,0xe9,0x6a,0xeb,0x52,0x1c,0xd8,0x89,0x26, - 0xf4,0x1b,0x49,0xe9,0xef,0x45,0x0b,0x33,0x36,0x73,0x1b,0x91,0x2b,0x75,0xff,0x9b, - 0x12,0x41,0xc7,0x80,0xb1,0x4a,0x12,0xaf,0x02,0x8d,0x4b,0xea,0xcd,0x0e,0xc6,0x03, - 0x14,0x4c,0x79,0xef,0xa6,0xc2,0xf6,0x86,0xd3,0x19,0xfd,0xe6,0x85,0xfa,0x3b,0x0d, - 0x3b,0xb2,0x98,0xd2,0xff,0xa0,0xfe,0x65,0x63,0xc9,0xc2,0xa7,0xf4,0x0d,0x98,0x57, - 0xab,0xd5,0x7b,0x58,0x87,0x62,0x58,0x74,0x40,0x75,0x06,0x8f,0x4a,0x93,0xff,0x76, - 0xbb,0xd3,0x19,0x4d,0xf8,0x04,0x89,0xa4,0xc5,0xe3,0xbe,0xde,0x60,0x04,0x7f,0x52, - 0x58,0x11,0x51,0x6f,0xa9,0xf9,0x06,0x6d,0x03,0x83,0xcd,0xa7,0x01,0xf8,0x2d,0xa0, - 0xe6,0x45,0x63,0x85,0x46,0x7c,0x9b,0x55,0x86,0xfd,0xe9,0xc3,0xd4,0xeb,0xeb,0x3e, - 0x2b,0x0e,0x33,0x8a,0x9f,0x40,0xe3,0x9d,0x52,0xe3,0xf8,0x6f,0x1a,0x4d,0x5f,0xaf, - 0x78,0x12,0x56,0x56,0xab,0x3d,0xbd,0x36,0x8e,0xd9,0xa9,0xc4,0xfc,0xd3,0x21,0x6b, - 0xa7,0xa0,0xa3,0xc6,0x50,0x41,0x43,0xdb,0xd0,0xf7,0x16,0x08,0x06,0x0d,0xed,0x15, - 0x90,0xdc,0x31,0xeb,0x0d,0x4b,0x7b,0x1c,0xa6,0x32,0xca,0x52,0xaa,0x3a,0x71,0xc2, - 0xb7,0xce,0x42,0xd4,0x90,0xbe,0x65,0x0b,0x55,0x54,0x79,0x6b,0xbf,0xbc,0xf7,0x1d, - 0x5f,0x14,0x4a,0x02,0x4c,0x63,0x16,0x6d,0x85,0xad,0xb3,0x1f,0x11,0x43,0x3f,0xd3, - 0x4d,0x3b,0xfc,0x96,0x79,0xca,0xa5,0x9e,0xc1,0xdf,0xbc,0x94,0x2d,0x46,0xe2,0xe7, - 0x1a,0x93,0xfc,0xc5,0x09,0x16,0x8d,0x91,0x41,0xc0,0x59,0x4f,0x9c,0x76,0x94,0x86, - 0xf2,0x59,0x5d,0xca,0xa9,0x20,0x93,0x10,0xd6,0x45,0x3b,0x30,0x55,0xdf,0x96,0x9f, - 0x60,0x06,0x7c,0x9a,0xb9,0x24,0x1e,0xe0,0xae,0x65,0xd5,0x4b,0x4a,0xe2,0x55,0xc7, - 0x09,0xb5,0x51,0x40,0x07,0x7e,0xe1,0xef,0x34,0x63,0x7b,0x3a,0xa9,0x98,0x2f,0x09, - 0xe1,0xfd,0x7a,0xb3,0x29,0x79,0xfc,0xf5,0xbd,0x3c,0x3c,0x05,0x02,0xd5,0xc5,0x86, - 0xaf,0x9a,0xd3,0x10,0x7e,0xc3,0x1b,0xf7,0x73,0x64,0xd6,0x27,0x04,0x08,0xee,0x7b, - 0x49,0x2d,0x21,0x2e,0xd8,0xbc,0x29,0x3a,0x80,0x82,0x2d,0xed,0xf2,0xaf,0x08,0x55, - 0xce,0x80,0x9c,0xf2,0xeb,0x60,0x38,0x12,0x27,0x31,0xa0,0x2f,0x64,0xbf,0x21,0x8c, - 0x63,0x88,0x90,0xee,0x9e,0xc0,0x5f,0xb8,0xea,0xa5,0xf3,0x26,0x01,0x65,0xe3,0x97, - 0xb6,0x17,0x6f,0x6a,0x48,0x77,0xc0,0x26,0x00,0x65,0x19,0xc8,0xe8,0xc6,0x94,0x5d, - 0x03,0xcb,0xc5,0xa9,0x5d,0xc5,0x4b,0x8f,0xcf,0x33,0xeb,0x2a,0x9a,0x5a,0x75,0xe4, - 0xec,0x7d,0x59,0xab,0xd1,0x9a,0xb7,0x73,0x54,0x2a,0xe3,0x3d,0x63,0x62,0xcf,0xa0, - 0x5f,0xb5,0xf4,0x12,0x61,0xa6,0xbb,0xd9,0xf6,0x3f,0xc9,0x0c,0x96,0x9f,0xf8,0xa2, - 0x38,0x2c,0xb5,0xdf,0x26,0x07,0x0d,0xc5,0x43,0x33,0xe3,0x69,0x31,0x56,0x7a,0x4c, - 0x3c,0xc7,0x44,0xa4,0x9f,0x62,0xa4,0x5f,0x9b,0xdd,0xe4,0x24,0x28,0x1b,0xe6,0x72, - 0xc8,0x8d,0xe7,0x40,0x4e,0x81,0xe6,0x8e,0x3c,0xb5,0x53,0xe3,0x0b,0x43,0x69,0xaf, - 0x7d,0xb8,0xfc,0xf2,0xb5,0x2a,0xad,0x95,0xe1,0xb7,0xbd,0xdf,0x3b,0x16,0xac,0x7b, - 0x9f,0xad,0x8f,0x66,0x7d,0x72,0x3e,0xf4,0xdb,0xf5,0xdd,0x91,0x09,0x7a,0x2b,0xf8, - 0x3d,0xa6,0x26,0xec,0x22,0x00,0xcc,0xe6,0xab,0x03,0xe6,0xbe,0x7b,0x70,0x09,0x07, - 0x72,0xfc,0x32,0xf1,0x46,0xda,0x7e,0x0a,0x97,0xcf,0x42,0xaf,0x2d,0x70,0x56,0x34, - 0xce,0xc9,0x7b,0xca,0xb6,0xd5,0xc8,0xd4,0xe3,0x96,0x62,0x02,0x54,0x66,0x65,0x88, - 0xf7,0xe5,0xb6,0x68,0x0d,0x61,0x8d,0x71,0xa4,0x39,0xd0,0xe5,0xf7,0x38,0x27,0x00, - 0x65,0x53,0xd4,0x1b,0x0a,0x94,0x63,0xa8,0x19,0xc3,0x2a,0x5b,0x2a,0x6a,0xb9,0x19, - 0xfa,0x04,0x3e,0xc5,0x0a,0xc6,0x5c,0xc0,0x3f,0xbb,0x3f,0x18,0x9b,0x27,0xdc,0xd5, - 0xf7,0x2b,0x54,0x30,0x68,0x47,0x45,0xae,0x12,0xe4,0xdc,0x71,0xa5,0xbd,0x4b,0x6e, - 0xd6,0xba,0x6e,0x96,0xa6,0x73,0x77,0xc5,0x2b,0x48,0x6d,0x7e,0xbb,0x44,0x6f,0xd5, - 0x5d,0x17,0xcb,0xd6,0x96,0xb8,0xd1,0x06,0xe1,0xea,0x2f,0xa6,0x86,0x1b,0x81,0x97, - 0xbe,0xa0,0xfb,0x9a,0x20,0x6d,0xf5,0x33,0xeb,0x64,0xd3,0x89,0x68,0x8c,0x8b,0xa9, - 0x4f,0x19,0x51,0xb5,0x8d,0x89,0x74,0x51,0x2c,0x90,0x38,0x0e,0x0d,0x18,0x53,0x87, - 0x31,0x62,0x3d,0x54,0x1e,0x74,0xc0,0x9a,0xc3,0x37,0xdd,0x36,0x00,0x5c,0xc9,0xb4, - 0x1d,0x57,0x0b,0xb2,0x43,0x25,0x2b,0xb6,0xee,0x83,0xda,0xfd,0xad,0x41,0x9d,0xf4, - 0xdf,0x60,0xfe,0xa1,0xd0,0x1c,0x78,0x3e,0x36,0x17,0x38,0x4a,0xb2,0x42,0x15,0xac, - 0xa6,0x5e,0x88,0xe3,0x11,0x76,0x48,0xc9,0xcd,0x86,0xbb,0x2b,0x7a,0xab,0xa9,0xfe, - 0x76,0x0f,0xb5,0xb4,0x6e,0x1a,0xfd,0x5f,0xa4,0x20,0x32,0xb2,0xb5,0x4d,0x25,0xa4, - 0x34,0xd3,0x06,0xf4,0xc6,0x6e,0x83,0xcb,0x5e,0x87,0xe0,0x25,0xee,0x17,0x58,0x2e, - 0xaa,0x3c,0x54,0xf1,0xb5,0x33,0xcd,0xa7,0x37,0x78,0x10,0x25,0x23,0x90,0x8a,0x80, - 0x3f,0xbb,0x4b,0xdf,0x89,0xc2,0xee,0x5c,0x78,0x33,0x1a,0x76,0x3e,0xf9,0x46,0x49, - 0x50,0x0c,0x39,0x38,0x33,0x6b,0xbe,0xae,0xec,0xec,0xf9,0xf5,0x1c,0x40,0xa1,0xa7, - 0x29,0x0e,0x02,0x7a,0xd7,0xb9,0x0b,0x2e,0x6f,0x9f,0x33,0x97,0x63,0x87,0xe0,0xb7, - 0xf6,0x9e,0xa0,0x43,0xa6,0xbe,0x04,0x3f,0x3f,0x8a,0xcc,0x8d,0xd3,0xbc,0x15,0x0e, - 0x9b,0xb7,0x99,0xc1,0x3f,0xfa,0xaf,0x8a,0xc4,0x67,0x0d,0x36,0xda,0xab,0xf5,0xe9, - 0x77,0xa9,0x84,0x0b,0xf9,0x22,0x49,0x15,0x9d,0x72,0x62,0x73,0x21,0x90,0x14,0x6e, - 0x4b,0x2d,0x50,0x80,0x02,0x5e,0x79,0x66,0x7d,0x8c,0x5b,0xf8,0x2a,0x0c,0x2e,0x62, - 0x15,0x85,0x78,0xce,0xa7,0xb6,0x33,0x8f,0xba,0xe4,0xb1,0xa5,0x9e,0xea,0x66,0x9e, - 0x9c,0x98,0x7d,0x90,0x75,0x6f,0xd4,0xc0,0xd5,0x42,0x5d,0x5e,0xd4,0xab,0xed,0x1e, - 0xe0,0x77,0x48,0xaf,0x13,0xac,0x89,0x8c,0x2a,0x2a,0x6b,0xb1,0x45,0xca,0xae,0x86, - 0xfc,0xd8,0x15,0x4e,0xae,0xce,0x00,0x63,0x71,0xa6,0xef,0x43,0xdd,0x1c,0x77,0x21, - 0x85,0xa8,0xd2,0x46,0x61,0xf0,0xfd,0xcb,0x43,0x31,0x41,0x35,0xda,0x2f,0xa9,0xc8, - 0xb0,0x5f,0xd6,0xc9,0x7b,0x43,0x97,0x28,0xfa,0x2e,0xe7,0x07,0x8e,0x32,0xd5,0xf5, - 0x30,0x2f,0x76,0x51,0x4b,0x21,0xcf,0xbd,0xc2,0x3a,0x5e,0x85,0x60,0x2b,0x42,0xc5, - 0x56,0x70,0xf1,0xfb,0xce,0xd5,0xee,0x4f,0x30,0x33,0x08,0xea,0x3b,0xa7,0x31,0x54, - 0x67,0xc2,0x07,0x2d,0x7c,0x2f,0x43,0xbe,0x34,0x34,0xd4,0x11,0x5c,0x8f,0x94,0x6a, - 0x77,0xcb,0x03,0x77,0x48,0x33,0xac,0x77,0x78,0x42,0x6c,0x6f,0x08,0x93,0x23,0x5c, - 0xb8,0x6e,0xae,0xac,0xd0,0x33,0x85,0x1a,0x55,0xd5,0x85,0xa7,0x00,0xf0,0xf9,0x01, - 0x58,0xac,0x39,0x10,0x05,0x45,0x3e,0xb0,0xa9,0x86,0x12,0x78,0xe7,0xad,0xb0,0xee, - 0x4f,0xc7,0x34,0xf4,0x09,0x9c,0x70,0x77,0xa7,0x41,0xb3,0x54,0xc3,0xc4,0xa0,0xf2, - 0x72,0x50,0x74,0x9c,0xed,0x16,0x45,0x92,0x15,0xa8,0x42,0x86,0x93,0x4e,0x28,0x79, - 0x1e,0x80,0x7a,0x13,0xae,0x4d,0x37,0x55,0xeb,0xbd,0x83,0x35,0xec,0x20,0xa1,0x83, - 0x19,0x50,0x30,0x02,0x6c,0x48,0x78,0x3b,0xa9,0x6f,0x18,0x57,0x69,0x3a,0x5b,0xdb, - 0xd6,0x77,0x7f,0x5c,0x0d,0xe3,0xd1,0xd0,0x27,0x1f,0x3f,0xd2,0xfb,0x6b,0xab,0x36, - 0x44,0x58,0x6f,0xf4,0xa2,0x45,0x32,0xc9,0x05,0x67,0xd9,0x1a,0x9c,0x9b,0x63,0x31, - 0x7a,0x54,0xbd,0xa0,0x63,0x7a,0x01,0x73,0xbc,0xcc,0xd2,0xe2,0x44,0x17,0xd2,0xd7, - 0xb8,0x76,0x7e,0xb7,0x5a,0x04,0xfc,0xb9,0xd9,0xed,0xd2,0x76,0x38,0x21,0x71,0xfc, - 0x83,0x55,0x89,0x30,0x6e,0xf8,0x0d,0xc0,0xe7,0xb6,0x8e,0x1a,0x44,0xf6,0x8d,0xdb, - 0x2a,0x01,0xf6,0x55,0x6f,0x43,0xbe,0x66,0x39,0xd7,0xeb,0x7c,0x5a,0xb8,0xb2,0xae, - 0x9c,0xf0,0x7b,0xb8,0xbd,0x4e,0x3b,0xf0,0x67,0x15,0x47,0xc7,0x62,0x6c,0xe5,0xe9, - 0x96,0xb8,0x97,0x10,0x3a,0x1d,0xf2,0x22,0xf4,0x10,0x92,0x46,0xb0,0x09,0xda,0x98, - 0xff,0xef,0xa9,0x1f,0xe8,0x23,0x52,0xfa,0x30,0x9b,0x4b,0xf1,0xe1,0xb6,0x13,0xd4, - 0xd7,0x2c,0x37,0x1d,0x71,0x91,0x0f,0x0a,0x22,0x9d,0x31,0x2a,0x5e,0x70,0xa1,0xe2, - 0x7d,0xeb,0x3d,0x06,0xc6,0xfb,0xe7,0x96,0x96,0x43,0xcc,0xdc,0x29,0xa1,0xfa,0xbb, - 0x45,0x16,0x4c,0xbe,0xa1,0xad,0xce,0x0e,0x8b,0x95,0x50,0xac,0x7e,0x8d,0x68,0x08, - 0xd4,0xe2,0xa6,0x63,0x70,0xb4,0x1e,0x1a,0x80,0xcb,0x6d,0xa6,0xf5,0xf5,0xcc,0xe8, - 0xeb,0xc2,0x49,0x08,0x72,0xf3,0xad,0x4a,0xb9,0x0a,0xec,0xf7,0x35,0x97,0x6f,0x72, - 0x0c,0x48,0xc6,0xa8,0x54,0xc7,0x93,0xd4,0xf7,0x70,0x5a,0xe9,0x16,0x08,0xb5,0xfc, - 0xf9,0xb2,0xb6,0xe4,0xc2,0xd4,0xfd,0x31,0xe9,0xe6,0x3c,0x3a,0x67,0xcc,0x35,0xf5, - 0xfd,0x81,0xb6,0x14,0xff,0xb8,0xfb,0x4f,0x0f,0xc2,0x2d,0xd0,0x57,0xdf,0xa4,0x5f, - 0x1e,0x4d,0x01,0x41,0x4f,0xfe,0x76,0x50,0x66,0x83,0x75,0x90,0x06,0xbf,0x2d,0xf1, - 0x27,0x46,0x7e,0x32,0xc4,0xc5,0x2f,0xf4,0x26,0x7f,0x46,0x30,0x3d,0x30,0x21,0x30, - 0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14,0x33,0x7b,0x5c,0xd1, - 0x1b,0xad,0x79,0x93,0x10,0xa3,0x79,0x2e,0xae,0x8b,0x10,0x87,0xba,0x28,0xf7,0xa6, - 0x04,0x14,0x84,0x78,0x82,0x85,0xc4,0x9e,0xa2,0x14,0x4f,0xad,0x59,0x15,0x3d,0x23, - 0xe6,0x62,0xbf,0x6d,0x8c,0x06,0x02,0x02,0x04,0x00 - ]); - - /* 安装凭据对应的密码,业务赋值 */ - let keystorePwd: string = 'huawei'; - let appKeyUri: string = ''; - try { - /* 安装私有凭据 */ - const res: certificateManager.CMResult = await certificateManager.installPrivateCertificate(keystore, keystorePwd, 'testPriCredential'); - appKeyUri = (res.uri != undefined) ? res.uri : ''; - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`Failed to install private certificate. Code: ${e.code}, message: ${e.message}`); - } - - try { - /* srcData为待签名、验签的数据,业务自行赋值 */ - let srcData: Uint8Array = new Uint8Array([ - 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, - ]); - - /* 构造签名的属性参数 */ - const signSpec: certificateManager.CMSignatureSpec = { - purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_SIGN, - padding: certificateManager.CmKeyPadding.CM_PADDING_PSS, - digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256 - }; - - /* 签名 */ - const signHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, signSpec); - await certificateManager.update(signHandle.handle, srcData); - const signResult: certificateManager.CMResult = await certificateManager.finish(signHandle.handle); - - /* 构造验签的的属性参数 */ - const verifySpec: certificateManager.CMSignatureSpec = { - purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_VERIFY, - padding: certificateManager.CmKeyPadding.CM_PADDING_PSS, - digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256 - }; - - /* 验签 */ - const verifyHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, verifySpec); - await certificateManager.update(verifyHandle.handle, srcData); - const verifyResult = await certificateManager.finish(verifyHandle.handle, signResult.outData); - console.info('Succeeded in signing and verifying.'); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`Failed to sign or verify. Code: ${e.code}, message: ${e.message}`); - } - - try { - /* 卸载私有凭据 */ - await certificateManager.uninstallPrivateCertificate(appKeyUri); - } catch (err) { - let e: BusinessError = err as BusinessError; - console.error(`Failed to uninstall private certificate. Code: ${e.code}, message: ${e.message}`); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'CertManagerGuidelines'; - - build() { - Column({space: 5}) { - Text(this.message) - .fontSize(25) - .fontWeight(FontWeight.Bold) - Button($r('app.string.call_certManagerGuidelines')) - .width('70%') - .onClick(()=>{ - certificateManagerSample(); - this.message = 'CertManagerGuidelines Success'; - }) - } - .height('100%') - .width('100%') - } +/* + * 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 { certificateManager } from '@kit.DeviceCertificateKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +async function certificateManagerSample() { + /* 安装的凭据数据需要业务赋值,本例数据非凭据数据 */ + let keystore: Uint8Array = new Uint8Array([ + 0x30,0x82,0x0c,0x26,0x02,0x01,0x03,0x30,0x82,0x0b,0xe0,0x06,0x09,0x2a,0x86,0x48, + 0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x82,0x0b,0xd1,0x04,0x82,0x0b,0xcd,0x30,0x82, + 0x0b,0xc9,0x30,0x82,0x05,0x6e,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07, + 0x01,0xa0,0x82,0x05,0x5f,0x04,0x82,0x05,0x5b,0x30,0x82,0x05,0x57,0x30,0x82,0x05, + 0x53,0x06,0x0b,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x0a,0x01,0x02,0xa0,0x82, + 0x04,0xfa,0x30,0x82,0x04,0xf6,0x30,0x28,0x06,0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d, + 0x01,0x0c,0x01,0x03,0x30,0x1a,0x04,0x14,0xb6,0x80,0x7d,0xb9,0xc3,0x44,0x84,0x1f, + 0x44,0xe6,0x95,0x6a,0x98,0xa1,0xcb,0x97,0xfb,0x2b,0xcc,0x5a,0x02,0x02,0x04,0x00, + 0x04,0x82,0x04,0xc8,0x78,0xa7,0x16,0x45,0x40,0xf0,0xec,0xac,0x3e,0x34,0x17,0xd7, + 0x8b,0x5c,0xca,0x85,0x29,0x0b,0x08,0xef,0xa2,0xf0,0x6d,0x55,0xd7,0xde,0x96,0xa5, + 0x49,0x6d,0x9d,0xa6,0xe6,0x00,0xd7,0x2c,0x65,0xf6,0xc2,0xd1,0xe8,0x70,0xfb,0xb5, + 0xd9,0xc6,0x7d,0xd4,0x28,0x45,0x17,0x4f,0x4f,0xd9,0x9b,0xab,0xe2,0xdc,0xe7,0x22, + 0x6c,0x1e,0xbc,0xd6,0xf0,0x38,0x0b,0xd7,0xd9,0xfc,0xa7,0xb4,0x87,0x95,0x96,0xc3, + 0x93,0xc0,0xb5,0x37,0xf4,0x64,0xfe,0xe5,0x07,0xac,0x41,0x2d,0xf5,0xeb,0xe3,0x8b, + 0xc2,0x74,0x73,0x13,0x3b,0x5f,0x17,0x54,0x2d,0x31,0x20,0x69,0x1c,0xab,0x66,0xba, + 0x06,0x43,0x03,0xa3,0x69,0x54,0x72,0x70,0x5f,0x78,0xd2,0xec,0xdd,0x50,0xb8,0x25, + 0x03,0xd4,0xec,0x2d,0x92,0x96,0x9f,0xcc,0xa6,0x4a,0x50,0x34,0x1c,0xfc,0xe3,0xc2, + 0x6b,0x65,0xec,0xb3,0x1c,0xc8,0xf2,0xd0,0x79,0xf0,0x28,0x61,0x9a,0xfe,0xea,0x7f, + 0x16,0x38,0xe1,0xf4,0x7f,0x86,0xfe,0x73,0x67,0xc9,0x60,0x73,0xd8,0xef,0x2c,0x6b, + 0xde,0x88,0x37,0xc5,0xd7,0x18,0x60,0x74,0x97,0x07,0x85,0x70,0x74,0x30,0x66,0x8f, + 0x11,0x4a,0xb9,0x18,0xed,0xfc,0xc7,0xdb,0x63,0x58,0x7b,0x57,0x0d,0xfa,0x43,0x81, + 0xbd,0x34,0xfc,0x17,0xd3,0x2a,0xa9,0x74,0xa0,0x2c,0x1b,0xe2,0xaa,0x3d,0xd2,0x84, + 0x18,0xaa,0x2a,0x0e,0xa8,0xcc,0x2a,0xc4,0x39,0x60,0x29,0xb5,0x03,0xaf,0xea,0x96, + 0xcf,0xa5,0x67,0x4c,0xa7,0x59,0x76,0xea,0x8a,0x60,0xd6,0xd8,0xc3,0x9e,0x0e,0xad, + 0xd6,0xa0,0x5a,0x00,0x7c,0xa6,0xe8,0x62,0xa4,0x0a,0x53,0xcc,0x48,0xf0,0x4d,0x6d, + 0xda,0xb3,0xa9,0x82,0x37,0x75,0xff,0x20,0xa9,0xe8,0x6e,0xc8,0x4a,0x8a,0x81,0x84, + 0x7a,0x1d,0x02,0x40,0xd9,0x76,0xee,0x89,0x62,0xd5,0x57,0x19,0xc8,0x9a,0x6a,0x22, + 0x8d,0x01,0x8f,0xc9,0x14,0x72,0xf9,0x90,0xa3,0x0f,0x5f,0x23,0x32,0xc4,0xd5,0x79, + 0x53,0x1f,0xbc,0x3a,0xf4,0x19,0x7f,0x93,0xb7,0x8b,0x0b,0xb9,0xeb,0x1f,0xa2,0x5c, + 0x93,0x0e,0x5f,0x29,0x87,0xea,0x67,0x4d,0x5d,0x2b,0x5e,0x29,0x81,0xbd,0x3d,0xfc, + 0xdf,0x92,0x50,0x19,0xc2,0x50,0x4d,0x07,0x76,0x08,0xfc,0xbe,0xd1,0x73,0x64,0xb7, + 0x22,0x6f,0xb7,0x89,0x93,0xc1,0xb1,0x44,0x42,0x27,0xf5,0x61,0x06,0x32,0xd1,0xc0, + 0xdb,0x92,0x51,0x1b,0xd3,0x5c,0x95,0x85,0x0e,0x66,0xc5,0xe9,0xf5,0x7f,0x44,0x52, + 0x49,0xfb,0x0a,0x83,0x02,0x6e,0x69,0x6c,0xf1,0x6f,0xe5,0xa1,0xa0,0x5d,0x8a,0xd3, + 0x4f,0x9d,0x0a,0x08,0x1b,0x32,0x70,0xe3,0xf3,0xf0,0x63,0xda,0x37,0x90,0x96,0x3f, + 0xac,0xf7,0x3d,0xd5,0xeb,0x08,0xc1,0x51,0x91,0x75,0x2c,0x0f,0xf1,0x5b,0x39,0xce, + 0x05,0x06,0x65,0x1c,0xe8,0x36,0xb0,0x86,0x6e,0xbe,0xb9,0x25,0xd6,0xdf,0x5c,0x50, + 0x56,0x99,0x69,0x8e,0x92,0xbe,0xa1,0x03,0x18,0xd6,0x34,0xa6,0x98,0x53,0x3a,0xb7, + 0x96,0xcb,0xa8,0x1d,0xc9,0x9e,0x92,0x15,0xf4,0x99,0x7e,0x58,0x81,0x99,0x84,0xa0, + 0x67,0xa5,0x77,0x1e,0xa9,0xac,0xc2,0xcf,0xd8,0x7a,0x68,0xef,0x35,0x9e,0xb6,0xb7, + 0x78,0x6b,0x43,0x12,0x53,0x93,0x7b,0x50,0x94,0x37,0x48,0x75,0x98,0x27,0x0f,0x73, + 0x1a,0xb7,0x2f,0x19,0x7e,0x42,0x08,0x02,0x05,0x42,0x71,0xd6,0x26,0x64,0x04,0x25, + 0x87,0xd9,0x02,0x05,0x1f,0x79,0x6b,0x9b,0x0e,0xfa,0x10,0x7b,0xf3,0x96,0x3f,0x53, + 0x02,0x9d,0x80,0x13,0xd7,0x30,0x03,0x24,0x96,0x21,0x05,0xdb,0x2d,0xe9,0xc8,0x51, + 0x30,0x42,0x6d,0xa9,0xe8,0x39,0xb0,0xa9,0x59,0xb9,0x21,0x22,0x98,0x41,0x0e,0x33, + 0x0d,0x7f,0x7a,0x69,0x45,0x0b,0xf1,0xac,0xfd,0xaa,0xaa,0x45,0x7f,0x78,0x24,0xf8, + 0x56,0x85,0x3b,0x4b,0x95,0x78,0x40,0xc7,0x2f,0xfc,0xb6,0xb7,0x5f,0xa2,0xf9,0xe9, + 0x80,0x4c,0x4a,0xbf,0x4f,0xcb,0xb9,0x51,0x7c,0x18,0xb7,0xb7,0x70,0xf1,0x4c,0x96, + 0xd2,0x4a,0x44,0xb9,0xa6,0x22,0xc9,0x95,0xf5,0x99,0xbd,0x8c,0xf2,0x45,0x88,0xfb, + 0x2f,0xe0,0x38,0x42,0xc8,0xe5,0x0d,0x55,0x05,0x0f,0xb9,0x91,0x7d,0xaf,0x27,0x91, + 0xb3,0xc4,0x83,0x46,0x49,0x1a,0xce,0x3a,0xff,0x1b,0x58,0xc9,0xa4,0x22,0x82,0x57, + 0x7f,0xda,0x5f,0xae,0xea,0xae,0x96,0x91,0xef,0xde,0x4e,0x25,0x66,0xbb,0xe9,0xb3, + 0xa7,0xbc,0x12,0xc4,0x5f,0xee,0xc6,0x13,0x9c,0xd9,0xbc,0x14,0xef,0x3d,0x7b,0xa4, + 0x91,0x4a,0x77,0xfd,0x18,0x9c,0xc7,0x38,0xaf,0x24,0x3f,0x6c,0x8f,0x8f,0x6e,0x2c, + 0x38,0x7c,0xa4,0xba,0xc7,0x70,0x90,0x6d,0x5e,0x51,0x3c,0xe0,0x3d,0xc5,0xa8,0x44, + 0xb0,0xf4,0x0b,0xba,0xe0,0x0e,0x8b,0x65,0xeb,0x04,0xfd,0x1a,0x8b,0x94,0xbf,0xfe, + 0xf0,0x64,0xa4,0xfa,0xb4,0xe1,0x11,0xd4,0x95,0x13,0xee,0xce,0xf6,0x14,0xf7,0x1c, + 0xbc,0xf5,0x64,0x90,0x88,0x69,0xb2,0xfd,0x26,0x26,0x83,0xa7,0x4c,0x3d,0x27,0xae, + 0x3c,0x68,0xb5,0xcc,0x9f,0x46,0xc2,0x9a,0x95,0x9a,0xa7,0x8b,0x4a,0x14,0xf7,0x80, + 0x9f,0x04,0xf9,0x39,0x3b,0x55,0x9e,0xb5,0x1c,0x79,0x7d,0x2d,0x9b,0x29,0xb9,0x7c, + 0x61,0x01,0xf5,0x26,0x1e,0xa0,0xcb,0x18,0xaf,0xc6,0x6d,0x2f,0x42,0xb7,0xa5,0x94, + 0x91,0xa5,0xc0,0x15,0xd9,0x18,0x4e,0xb6,0xc3,0x77,0x9e,0x59,0x6e,0x61,0x48,0x32, + 0xcf,0x5e,0x09,0x3a,0x17,0x48,0x59,0x68,0x9a,0x6c,0x7f,0xd3,0x71,0xd8,0x2c,0xce, + 0x58,0x68,0x33,0x79,0xe6,0xb6,0xf0,0xb5,0xac,0xb0,0xa4,0xc0,0x10,0x0f,0xad,0x02, + 0x19,0x58,0x53,0x5a,0x9a,0x5d,0x84,0xa6,0x8e,0x3c,0xc8,0xa9,0x22,0xb5,0x2a,0x39, + 0x3f,0xf8,0x76,0x53,0xea,0x7b,0x23,0x81,0x2b,0xe1,0x1d,0x63,0xb3,0x83,0x76,0xc8, + 0xd3,0x5e,0xba,0x97,0x79,0x9b,0xfb,0xf3,0x1e,0x10,0xac,0xd8,0x2e,0xa0,0x64,0xba, + 0x02,0x21,0x18,0x05,0xd1,0x30,0xdd,0x33,0x32,0x98,0x3d,0x0d,0x22,0xb4,0xda,0x8d, + 0xa0,0x9a,0x3a,0x97,0x0f,0xa5,0xe1,0xf1,0x56,0x17,0xd8,0xbd,0x15,0xd3,0xd6,0xe0, + 0x20,0x95,0x7b,0x6a,0x63,0x59,0x80,0xee,0xcd,0x60,0xb1,0xb0,0xba,0x8d,0x6a,0x4c, + 0x3d,0x5c,0xac,0x1a,0x87,0x1d,0x07,0xfe,0x69,0x81,0x8f,0x5d,0xba,0x64,0x3f,0xea, + 0xdf,0x36,0xb3,0x07,0x6c,0xbc,0x5b,0xe8,0xc0,0x5c,0x9a,0xd1,0x16,0xe3,0x2e,0xa5, + 0x92,0x5b,0xba,0x89,0x55,0x65,0x5d,0x14,0xd2,0x36,0x9e,0xfd,0x6d,0xcf,0x9d,0x68, + 0x10,0x7f,0xb6,0xdf,0x6b,0x9a,0x9b,0xd4,0x6b,0x37,0xfd,0x77,0xde,0x39,0x59,0xed, + 0xe3,0xdb,0x65,0xe8,0xa4,0x15,0x4a,0x6d,0xb4,0xad,0xb8,0x36,0xe1,0x3a,0xf8,0x6a, + 0xfe,0x6e,0x1f,0x02,0x15,0x09,0x36,0x44,0xb7,0x52,0x5b,0x79,0x3c,0x8e,0xfb,0x20, + 0x62,0xdb,0x7b,0xb6,0xb1,0x43,0xea,0x29,0xff,0x10,0xef,0x24,0x9c,0x4d,0xc2,0xa8, + 0x98,0xaa,0x29,0x59,0x85,0x06,0xc3,0xdb,0xcf,0xc2,0x71,0xfa,0xad,0x7b,0xd5,0xf7, + 0x50,0x53,0xc5,0x75,0x97,0x15,0x42,0x90,0x8f,0xf1,0xed,0x6a,0x98,0x83,0x59,0x15, + 0x23,0xa7,0xea,0xe9,0xed,0x22,0xec,0x0a,0x41,0x4c,0xc2,0x35,0x54,0xd9,0xec,0x4b, + 0xb8,0x3f,0xd0,0x68,0xed,0xa7,0x83,0x4e,0x42,0x29,0x5c,0x4d,0xa3,0x79,0x3e,0x59, + 0x86,0x04,0x62,0x24,0x9d,0x7b,0xb3,0x69,0xe9,0x82,0x57,0xdb,0xbf,0xeb,0x98,0x4f, + 0x59,0x7e,0x8d,0x8f,0x69,0x56,0xdc,0x3f,0xeb,0x01,0xcf,0x82,0x05,0x1e,0xe7,0x6d, + 0xff,0xb2,0x67,0xd8,0x34,0x68,0xf7,0xd0,0xee,0x6d,0xc6,0x22,0x4c,0x4d,0x36,0xd1, + 0xf5,0x5a,0xab,0xbb,0x41,0x43,0x4d,0xef,0x2c,0x62,0x64,0x28,0x31,0x46,0x30,0x1f, + 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x14,0x31,0x12,0x1e,0x10,0x00, + 0x6c,0x00,0x64,0x00,0x71,0x00,0x20,0x00,0x74,0x00,0x65,0x00,0x73,0x00,0x74,0x30, + 0x23,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x15,0x31,0x16,0x04,0x14, + 0x44,0x37,0x75,0x8f,0xcd,0x94,0x90,0x07,0x3e,0x38,0x20,0xb7,0x1b,0x3f,0x0d,0x3d, + 0x40,0x85,0x32,0x6a,0x30,0x82,0x06,0x53,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d, + 0x01,0x07,0x06,0xa0,0x82,0x06,0x44,0x30,0x82,0x06,0x40,0x02,0x01,0x00,0x30,0x82, + 0x06,0x39,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0x30,0x28,0x06, + 0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x01,0x06,0x30,0x1a,0x04,0x14,0xc8, + 0xe2,0x48,0x69,0x85,0x06,0xb3,0x34,0x55,0xf1,0xfe,0x9c,0x95,0x92,0xbd,0x73,0xcd, + 0x50,0xf4,0x88,0x02,0x02,0x04,0x00,0x80,0x82,0x06,0x00,0xb6,0x66,0x06,0x1a,0x84, + 0xb1,0xb7,0xf8,0xca,0x74,0xe1,0x7c,0x23,0x94,0x5f,0xb3,0x73,0xda,0x81,0x51,0x0e, + 0x4d,0x07,0xcd,0x8a,0x68,0xd5,0x15,0x98,0x57,0xc1,0xb9,0x94,0x30,0xc7,0x97,0x40, + 0x3b,0xa4,0xc0,0xd5,0xfe,0xd3,0x9f,0x92,0xe9,0x6a,0xeb,0x52,0x1c,0xd8,0x89,0x26, + 0xf4,0x1b,0x49,0xe9,0xef,0x45,0x0b,0x33,0x36,0x73,0x1b,0x91,0x2b,0x75,0xff,0x9b, + 0x12,0x41,0xc7,0x80,0xb1,0x4a,0x12,0xaf,0x02,0x8d,0x4b,0xea,0xcd,0x0e,0xc6,0x03, + 0x14,0x4c,0x79,0xef,0xa6,0xc2,0xf6,0x86,0xd3,0x19,0xfd,0xe6,0x85,0xfa,0x3b,0x0d, + 0x3b,0xb2,0x98,0xd2,0xff,0xa0,0xfe,0x65,0x63,0xc9,0xc2,0xa7,0xf4,0x0d,0x98,0x57, + 0xab,0xd5,0x7b,0x58,0x87,0x62,0x58,0x74,0x40,0x75,0x06,0x8f,0x4a,0x93,0xff,0x76, + 0xbb,0xd3,0x19,0x4d,0xf8,0x04,0x89,0xa4,0xc5,0xe3,0xbe,0xde,0x60,0x04,0x7f,0x52, + 0x58,0x11,0x51,0x6f,0xa9,0xf9,0x06,0x6d,0x03,0x83,0xcd,0xa7,0x01,0xf8,0x2d,0xa0, + 0xe6,0x45,0x63,0x85,0x46,0x7c,0x9b,0x55,0x86,0xfd,0xe9,0xc3,0xd4,0xeb,0xeb,0x3e, + 0x2b,0x0e,0x33,0x8a,0x9f,0x40,0xe3,0x9d,0x52,0xe3,0xf8,0x6f,0x1a,0x4d,0x5f,0xaf, + 0x78,0x12,0x56,0x56,0xab,0x3d,0xbd,0x36,0x8e,0xd9,0xa9,0xc4,0xfc,0xd3,0x21,0x6b, + 0xa7,0xa0,0xa3,0xc6,0x50,0x41,0x43,0xdb,0xd0,0xf7,0x16,0x08,0x06,0x0d,0xed,0x15, + 0x90,0xdc,0x31,0xeb,0x0d,0x4b,0x7b,0x1c,0xa6,0x32,0xca,0x52,0xaa,0x3a,0x71,0xc2, + 0xb7,0xce,0x42,0xd4,0x90,0xbe,0x65,0x0b,0x55,0x54,0x79,0x6b,0xbf,0xbc,0xf7,0x1d, + 0x5f,0x14,0x4a,0x02,0x4c,0x63,0x16,0x6d,0x85,0xad,0xb3,0x1f,0x11,0x43,0x3f,0xd3, + 0x4d,0x3b,0xfc,0x96,0x79,0xca,0xa5,0x9e,0xc1,0xdf,0xbc,0x94,0x2d,0x46,0xe2,0xe7, + 0x1a,0x93,0xfc,0xc5,0x09,0x16,0x8d,0x91,0x41,0xc0,0x59,0x4f,0x9c,0x76,0x94,0x86, + 0xf2,0x59,0x5d,0xca,0xa9,0x20,0x93,0x10,0xd6,0x45,0x3b,0x30,0x55,0xdf,0x96,0x9f, + 0x60,0x06,0x7c,0x9a,0xb9,0x24,0x1e,0xe0,0xae,0x65,0xd5,0x4b,0x4a,0xe2,0x55,0xc7, + 0x09,0xb5,0x51,0x40,0x07,0x7e,0xe1,0xef,0x34,0x63,0x7b,0x3a,0xa9,0x98,0x2f,0x09, + 0xe1,0xfd,0x7a,0xb3,0x29,0x79,0xfc,0xf5,0xbd,0x3c,0x3c,0x05,0x02,0xd5,0xc5,0x86, + 0xaf,0x9a,0xd3,0x10,0x7e,0xc3,0x1b,0xf7,0x73,0x64,0xd6,0x27,0x04,0x08,0xee,0x7b, + 0x49,0x2d,0x21,0x2e,0xd8,0xbc,0x29,0x3a,0x80,0x82,0x2d,0xed,0xf2,0xaf,0x08,0x55, + 0xce,0x80,0x9c,0xf2,0xeb,0x60,0x38,0x12,0x27,0x31,0xa0,0x2f,0x64,0xbf,0x21,0x8c, + 0x63,0x88,0x90,0xee,0x9e,0xc0,0x5f,0xb8,0xea,0xa5,0xf3,0x26,0x01,0x65,0xe3,0x97, + 0xb6,0x17,0x6f,0x6a,0x48,0x77,0xc0,0x26,0x00,0x65,0x19,0xc8,0xe8,0xc6,0x94,0x5d, + 0x03,0xcb,0xc5,0xa9,0x5d,0xc5,0x4b,0x8f,0xcf,0x33,0xeb,0x2a,0x9a,0x5a,0x75,0xe4, + 0xec,0x7d,0x59,0xab,0xd1,0x9a,0xb7,0x73,0x54,0x2a,0xe3,0x3d,0x63,0x62,0xcf,0xa0, + 0x5f,0xb5,0xf4,0x12,0x61,0xa6,0xbb,0xd9,0xf6,0x3f,0xc9,0x0c,0x96,0x9f,0xf8,0xa2, + 0x38,0x2c,0xb5,0xdf,0x26,0x07,0x0d,0xc5,0x43,0x33,0xe3,0x69,0x31,0x56,0x7a,0x4c, + 0x3c,0xc7,0x44,0xa4,0x9f,0x62,0xa4,0x5f,0x9b,0xdd,0xe4,0x24,0x28,0x1b,0xe6,0x72, + 0xc8,0x8d,0xe7,0x40,0x4e,0x81,0xe6,0x8e,0x3c,0xb5,0x53,0xe3,0x0b,0x43,0x69,0xaf, + 0x7d,0xb8,0xfc,0xf2,0xb5,0x2a,0xad,0x95,0xe1,0xb7,0xbd,0xdf,0x3b,0x16,0xac,0x7b, + 0x9f,0xad,0x8f,0x66,0x7d,0x72,0x3e,0xf4,0xdb,0xf5,0xdd,0x91,0x09,0x7a,0x2b,0xf8, + 0x3d,0xa6,0x26,0xec,0x22,0x00,0xcc,0xe6,0xab,0x03,0xe6,0xbe,0x7b,0x70,0x09,0x07, + 0x72,0xfc,0x32,0xf1,0x46,0xda,0x7e,0x0a,0x97,0xcf,0x42,0xaf,0x2d,0x70,0x56,0x34, + 0xce,0xc9,0x7b,0xca,0xb6,0xd5,0xc8,0xd4,0xe3,0x96,0x62,0x02,0x54,0x66,0x65,0x88, + 0xf7,0xe5,0xb6,0x68,0x0d,0x61,0x8d,0x71,0xa4,0x39,0xd0,0xe5,0xf7,0x38,0x27,0x00, + 0x65,0x53,0xd4,0x1b,0x0a,0x94,0x63,0xa8,0x19,0xc3,0x2a,0x5b,0x2a,0x6a,0xb9,0x19, + 0xfa,0x04,0x3e,0xc5,0x0a,0xc6,0x5c,0xc0,0x3f,0xbb,0x3f,0x18,0x9b,0x27,0xdc,0xd5, + 0xf7,0x2b,0x54,0x30,0x68,0x47,0x45,0xae,0x12,0xe4,0xdc,0x71,0xa5,0xbd,0x4b,0x6e, + 0xd6,0xba,0x6e,0x96,0xa6,0x73,0x77,0xc5,0x2b,0x48,0x6d,0x7e,0xbb,0x44,0x6f,0xd5, + 0x5d,0x17,0xcb,0xd6,0x96,0xb8,0xd1,0x06,0xe1,0xea,0x2f,0xa6,0x86,0x1b,0x81,0x97, + 0xbe,0xa0,0xfb,0x9a,0x20,0x6d,0xf5,0x33,0xeb,0x64,0xd3,0x89,0x68,0x8c,0x8b,0xa9, + 0x4f,0x19,0x51,0xb5,0x8d,0x89,0x74,0x51,0x2c,0x90,0x38,0x0e,0x0d,0x18,0x53,0x87, + 0x31,0x62,0x3d,0x54,0x1e,0x74,0xc0,0x9a,0xc3,0x37,0xdd,0x36,0x00,0x5c,0xc9,0xb4, + 0x1d,0x57,0x0b,0xb2,0x43,0x25,0x2b,0xb6,0xee,0x83,0xda,0xfd,0xad,0x41,0x9d,0xf4, + 0xdf,0x60,0xfe,0xa1,0xd0,0x1c,0x78,0x3e,0x36,0x17,0x38,0x4a,0xb2,0x42,0x15,0xac, + 0xa6,0x5e,0x88,0xe3,0x11,0x76,0x48,0xc9,0xcd,0x86,0xbb,0x2b,0x7a,0xab,0xa9,0xfe, + 0x76,0x0f,0xb5,0xb4,0x6e,0x1a,0xfd,0x5f,0xa4,0x20,0x32,0xb2,0xb5,0x4d,0x25,0xa4, + 0x34,0xd3,0x06,0xf4,0xc6,0x6e,0x83,0xcb,0x5e,0x87,0xe0,0x25,0xee,0x17,0x58,0x2e, + 0xaa,0x3c,0x54,0xf1,0xb5,0x33,0xcd,0xa7,0x37,0x78,0x10,0x25,0x23,0x90,0x8a,0x80, + 0x3f,0xbb,0x4b,0xdf,0x89,0xc2,0xee,0x5c,0x78,0x33,0x1a,0x76,0x3e,0xf9,0x46,0x49, + 0x50,0x0c,0x39,0x38,0x33,0x6b,0xbe,0xae,0xec,0xec,0xf9,0xf5,0x1c,0x40,0xa1,0xa7, + 0x29,0x0e,0x02,0x7a,0xd7,0xb9,0x0b,0x2e,0x6f,0x9f,0x33,0x97,0x63,0x87,0xe0,0xb7, + 0xf6,0x9e,0xa0,0x43,0xa6,0xbe,0x04,0x3f,0x3f,0x8a,0xcc,0x8d,0xd3,0xbc,0x15,0x0e, + 0x9b,0xb7,0x99,0xc1,0x3f,0xfa,0xaf,0x8a,0xc4,0x67,0x0d,0x36,0xda,0xab,0xf5,0xe9, + 0x77,0xa9,0x84,0x0b,0xf9,0x22,0x49,0x15,0x9d,0x72,0x62,0x73,0x21,0x90,0x14,0x6e, + 0x4b,0x2d,0x50,0x80,0x02,0x5e,0x79,0x66,0x7d,0x8c,0x5b,0xf8,0x2a,0x0c,0x2e,0x62, + 0x15,0x85,0x78,0xce,0xa7,0xb6,0x33,0x8f,0xba,0xe4,0xb1,0xa5,0x9e,0xea,0x66,0x9e, + 0x9c,0x98,0x7d,0x90,0x75,0x6f,0xd4,0xc0,0xd5,0x42,0x5d,0x5e,0xd4,0xab,0xed,0x1e, + 0xe0,0x77,0x48,0xaf,0x13,0xac,0x89,0x8c,0x2a,0x2a,0x6b,0xb1,0x45,0xca,0xae,0x86, + 0xfc,0xd8,0x15,0x4e,0xae,0xce,0x00,0x63,0x71,0xa6,0xef,0x43,0xdd,0x1c,0x77,0x21, + 0x85,0xa8,0xd2,0x46,0x61,0xf0,0xfd,0xcb,0x43,0x31,0x41,0x35,0xda,0x2f,0xa9,0xc8, + 0xb0,0x5f,0xd6,0xc9,0x7b,0x43,0x97,0x28,0xfa,0x2e,0xe7,0x07,0x8e,0x32,0xd5,0xf5, + 0x30,0x2f,0x76,0x51,0x4b,0x21,0xcf,0xbd,0xc2,0x3a,0x5e,0x85,0x60,0x2b,0x42,0xc5, + 0x56,0x70,0xf1,0xfb,0xce,0xd5,0xee,0x4f,0x30,0x33,0x08,0xea,0x3b,0xa7,0x31,0x54, + 0x67,0xc2,0x07,0x2d,0x7c,0x2f,0x43,0xbe,0x34,0x34,0xd4,0x11,0x5c,0x8f,0x94,0x6a, + 0x77,0xcb,0x03,0x77,0x48,0x33,0xac,0x77,0x78,0x42,0x6c,0x6f,0x08,0x93,0x23,0x5c, + 0xb8,0x6e,0xae,0xac,0xd0,0x33,0x85,0x1a,0x55,0xd5,0x85,0xa7,0x00,0xf0,0xf9,0x01, + 0x58,0xac,0x39,0x10,0x05,0x45,0x3e,0xb0,0xa9,0x86,0x12,0x78,0xe7,0xad,0xb0,0xee, + 0x4f,0xc7,0x34,0xf4,0x09,0x9c,0x70,0x77,0xa7,0x41,0xb3,0x54,0xc3,0xc4,0xa0,0xf2, + 0x72,0x50,0x74,0x9c,0xed,0x16,0x45,0x92,0x15,0xa8,0x42,0x86,0x93,0x4e,0x28,0x79, + 0x1e,0x80,0x7a,0x13,0xae,0x4d,0x37,0x55,0xeb,0xbd,0x83,0x35,0xec,0x20,0xa1,0x83, + 0x19,0x50,0x30,0x02,0x6c,0x48,0x78,0x3b,0xa9,0x6f,0x18,0x57,0x69,0x3a,0x5b,0xdb, + 0xd6,0x77,0x7f,0x5c,0x0d,0xe3,0xd1,0xd0,0x27,0x1f,0x3f,0xd2,0xfb,0x6b,0xab,0x36, + 0x44,0x58,0x6f,0xf4,0xa2,0x45,0x32,0xc9,0x05,0x67,0xd9,0x1a,0x9c,0x9b,0x63,0x31, + 0x7a,0x54,0xbd,0xa0,0x63,0x7a,0x01,0x73,0xbc,0xcc,0xd2,0xe2,0x44,0x17,0xd2,0xd7, + 0xb8,0x76,0x7e,0xb7,0x5a,0x04,0xfc,0xb9,0xd9,0xed,0xd2,0x76,0x38,0x21,0x71,0xfc, + 0x83,0x55,0x89,0x30,0x6e,0xf8,0x0d,0xc0,0xe7,0xb6,0x8e,0x1a,0x44,0xf6,0x8d,0xdb, + 0x2a,0x01,0xf6,0x55,0x6f,0x43,0xbe,0x66,0x39,0xd7,0xeb,0x7c,0x5a,0xb8,0xb2,0xae, + 0x9c,0xf0,0x7b,0xb8,0xbd,0x4e,0x3b,0xf0,0x67,0x15,0x47,0xc7,0x62,0x6c,0xe5,0xe9, + 0x96,0xb8,0x97,0x10,0x3a,0x1d,0xf2,0x22,0xf4,0x10,0x92,0x46,0xb0,0x09,0xda,0x98, + 0xff,0xef,0xa9,0x1f,0xe8,0x23,0x52,0xfa,0x30,0x9b,0x4b,0xf1,0xe1,0xb6,0x13,0xd4, + 0xd7,0x2c,0x37,0x1d,0x71,0x91,0x0f,0x0a,0x22,0x9d,0x31,0x2a,0x5e,0x70,0xa1,0xe2, + 0x7d,0xeb,0x3d,0x06,0xc6,0xfb,0xe7,0x96,0x96,0x43,0xcc,0xdc,0x29,0xa1,0xfa,0xbb, + 0x45,0x16,0x4c,0xbe,0xa1,0xad,0xce,0x0e,0x8b,0x95,0x50,0xac,0x7e,0x8d,0x68,0x08, + 0xd4,0xe2,0xa6,0x63,0x70,0xb4,0x1e,0x1a,0x80,0xcb,0x6d,0xa6,0xf5,0xf5,0xcc,0xe8, + 0xeb,0xc2,0x49,0x08,0x72,0xf3,0xad,0x4a,0xb9,0x0a,0xec,0xf7,0x35,0x97,0x6f,0x72, + 0x0c,0x48,0xc6,0xa8,0x54,0xc7,0x93,0xd4,0xf7,0x70,0x5a,0xe9,0x16,0x08,0xb5,0xfc, + 0xf9,0xb2,0xb6,0xe4,0xc2,0xd4,0xfd,0x31,0xe9,0xe6,0x3c,0x3a,0x67,0xcc,0x35,0xf5, + 0xfd,0x81,0xb6,0x14,0xff,0xb8,0xfb,0x4f,0x0f,0xc2,0x2d,0xd0,0x57,0xdf,0xa4,0x5f, + 0x1e,0x4d,0x01,0x41,0x4f,0xfe,0x76,0x50,0x66,0x83,0x75,0x90,0x06,0xbf,0x2d,0xf1, + 0x27,0x46,0x7e,0x32,0xc4,0xc5,0x2f,0xf4,0x26,0x7f,0x46,0x30,0x3d,0x30,0x21,0x30, + 0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14,0x33,0x7b,0x5c,0xd1, + 0x1b,0xad,0x79,0x93,0x10,0xa3,0x79,0x2e,0xae,0x8b,0x10,0x87,0xba,0x28,0xf7,0xa6, + 0x04,0x14,0x84,0x78,0x82,0x85,0xc4,0x9e,0xa2,0x14,0x4f,0xad,0x59,0x15,0x3d,0x23, + 0xe6,0x62,0xbf,0x6d,0x8c,0x06,0x02,0x02,0x04,0x00 + ]); + + /* 安装凭据对应的密码,业务赋值 */ + let keystorePwd: string = 'huawei'; + let appKeyUri: string = ''; + try { + /* 安装私有凭据 */ + const res: certificateManager.CMResult = await certificateManager.installPrivateCertificate(keystore, keystorePwd, 'testPriCredential'); + appKeyUri = (res.uri != undefined) ? res.uri : ''; + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`Failed to install private certificate. Code: ${e.code}, message: ${e.message}`); + } + + try { + /* srcData为待签名、验签的数据,业务自行赋值 */ + let srcData: Uint8Array = new Uint8Array([ + 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, + ]); + + /* 构造签名的属性参数 */ + const signSpec: certificateManager.CMSignatureSpec = { + purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_SIGN, + padding: certificateManager.CmKeyPadding.CM_PADDING_PSS, + digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256 + }; + + /* 签名 */ + const signHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, signSpec); + await certificateManager.update(signHandle.handle, srcData); + const signResult: certificateManager.CMResult = await certificateManager.finish(signHandle.handle); + + /* 构造验签的的属性参数 */ + const verifySpec: certificateManager.CMSignatureSpec = { + purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_VERIFY, + padding: certificateManager.CmKeyPadding.CM_PADDING_PSS, + digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256 + }; + + /* 验签 */ + const verifyHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, verifySpec); + await certificateManager.update(verifyHandle.handle, srcData); + const verifyResult = await certificateManager.finish(verifyHandle.handle, signResult.outData); + console.info('Succeeded in signing and verifying.'); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`Failed to sign or verify. Code: ${e.code}, message: ${e.message}`); + } + + try { + /* 卸载私有凭据 */ + await certificateManager.uninstallPrivateCertificate(appKeyUri); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`Failed to uninstall private certificate. Code: ${e.code}, message: ${e.message}`); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'CertManagerGuidelines'; + + build() { + Column({space: 5}) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_certManagerGuidelines')) + .width('70%') + .onClick(()=>{ + certificateManagerSample(); + this.message = 'CertManagerGuidelines Success'; + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 old mode 100755 new mode 100644 index a42c7d6374297f294133a6e17983e04af4151976..6ec5c351a433017454fe6df8e3be97f56e279472 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/module.json5 @@ -1,78 +1,78 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.ACCESS_CERT_MANAGER", - "reason": "$string:reason", - "usedScene": { - "abilities": [ - "FormAbility" - ], - "when": "always" - } - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_CERT_MANAGER", + "reason": "$string:reason", + "usedScene": { + "abilities": [ + "FormAbility" + ], + "when": "always" + } + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets old mode 100755 new mode 100644 index c4ad7137ad316101421c40a7641af4c2218b3ccd..f5d4e5875911ce81256d315ebf7570417ab90726 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/CertificateManagement.test.ets @@ -1,85 +1,85 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -function resourceToString(resource: Resource) { - return getContext().resourceManager.getStringSync(resource); -} - -export default function certificateManagementTest() { - describe('certificateManagementTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,安装、获取、使用、卸载证书 - */ - it('testCertificateManagement001', 0, async (done: Function) => { - console.info('uitest: testCertificateManagement001 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CertManagerGuidelines')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CertManagerGuidelines')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('CertManagerGuidelines Success')); - console.info('uitest: testCertificateManagement001 end'); - await driver.pressBack(); - done(); - }) - - /** - * 点击按钮,拉起证书管理界面 - */ - it('testCertificateManagement002', 0, async (done: Function) => { - console.info('uitest: testCertificateManagement002 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button1 = await driver.findComponent(ON.text('CertManagerDialogGuidelines')); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CertManagerDialogGuidelines')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text(resourceToString($r('app.string.dialog')))); - console.info('uitest: testCertificateManagement002 end'); - done(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +function resourceToString(resource: Resource) { + return getContext().resourceManager.getStringSync(resource); +} + +export default function certificateManagementTest() { + describe('certificateManagementTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,安装、获取、使用、卸载证书 + */ + it('testCertificateManagement001', 0, async (done: Function) => { + console.info('uitest: testCertificateManagement001 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CertManagerGuidelines')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CertManagerGuidelines')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('CertManagerGuidelines Success')); + console.info('uitest: testCertificateManagement001 end'); + await driver.pressBack(); + done(); + }) + + /** + * 点击按钮,拉起证书管理界面 + */ + it('testCertificateManagement002', 0, async (done: Function) => { + console.info('uitest: testCertificateManagement002 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button1 = await driver.findComponent(ON.text('CertManagerDialogGuidelines')); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CertManagerDialogGuidelines')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text(resourceToString($r('app.string.dialog')))); + console.info('uitest: testCertificateManagement002 end'); + done(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/DeviceCertificateKit/CertificateManagement/entry/src/test/List.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/hvigor/hvigor-config.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/DeviceCertificateKit/CertificateManagement/hvigorfile.ts b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/oh-package.json5 b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/oh-package.json5 +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/DeviceCertificateKit/CertificateManagement/ohosTest.md b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/ohosTest.md old mode 100755 new mode 100644 index dd7dfc6a9d387d1f24a6b3576fbe5df24c0c8006..6301852ad71ebe1413bf61d336122af484a2e4c0 --- a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/ohosTest.md +++ b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/ohosTest.md @@ -1,9 +1,9 @@ -# **证书管理**测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮安装,获取,应用私有凭据进行签名、验签,删除 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +# **证书管理**测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------- | ------------ | ---- | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮安装,获取,应用私有凭据进行签名、验签,删除 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | | 点击按钮拉起证书管理界面 | 成功拉起应用 | | 成功拉起弹窗并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement1.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement2.png b/code/DocsSample/Security/DeviceCertificateKit/CertificateManagement/screenshots/CertificateManagement2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/app.json5 old mode 100755 new mode 100644 index cd3e2cc1f737fd6b314ffa1d0dccaed6e258d54a..dddc4dae3eabe2acc674968b64d9175df3693160 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/app.json5 @@ -1,25 +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.keydeletion", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.keydeletion", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 90445a8bb9517cc0b01bb48a99e908099f352e29..6871b23fb433023d1988284b0685d810565e66ee --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "KeyDeletion" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "KeyDeletion" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyDeletion/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index baaca7e6a47852f297b592e89e6e175776a2137d..7395e4fc05762f8c66ed070d71c1abddaddc4c37 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(KeyDeletion) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(KeyDeletion) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 6c177236330e9bf0b399e94f0b7887b25a8a8423..f6801d1634b6d30d3bad7493f14e7a7a7dcf780e --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/napi_init.cpp @@ -1,115 +1,115 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -/* 以下以生成ECC密钥为例 */ -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; - -static OH_Huks_Result GenerateKeyHelper(const char *alias) -{ - struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; - struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; - struct OH_Huks_Result ohResult; - do { - /* 1.初始化密钥属性集 */ - ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, - sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2.生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); - } while (0); - OH_Huks_FreeParamSet(&testGenerateKeyParamSet); - return ohResult; -} - -static napi_value DeleteKey(napi_env env, napi_callback_info info) -{ - /* 1.获取密钥别名 */ - const char *alias = "test_key"; - struct OH_Huks_Blob keyAlias = { - (uint32_t)strlen("test_key"), - (uint8_t *)"test_key" - }; - - /* 生成密钥 */ - OH_Huks_Result genResult = GenerateKeyHelper(alias); - if (genResult.errorCode != OH_HUKS_SUCCESS) { - napi_value ret; - napi_create_int32(env, genResult.errorCode, &ret); - return ret; - } - - /* 2.调用OH_Huks_DeleteKeyItem删除密钥 */ - struct OH_Huks_Result ohResult = OH_Huks_DeleteKeyItem(&keyAlias, nullptr); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "deleteKey", nullptr, DeleteKey, 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); -} +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +/* 以下以生成ECC密钥为例 */ +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static OH_Huks_Result GenerateKeyHelper(const char *alias) +{ + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + /* 1.初始化密钥属性集 */ + ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, + sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2.生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); + } while (0); + OH_Huks_FreeParamSet(&testGenerateKeyParamSet); + return ohResult; +} + +static napi_value DeleteKey(napi_env env, napi_callback_info info) +{ + /* 1.获取密钥别名 */ + const char *alias = "test_key"; + struct OH_Huks_Blob keyAlias = { + (uint32_t)strlen("test_key"), + (uint8_t *)"test_key" + }; + + /* 生成密钥 */ + OH_Huks_Result genResult = GenerateKeyHelper(alias); + if (genResult.errorCode != OH_HUKS_SUCCESS) { + napi_value ret; + napi_create_int32(env, genResult.errorCode, &ret); + return ret; + } + + /* 2.调用OH_Huks_DeleteKeyItem删除密钥 */ + struct OH_Huks_Result ohResult = OH_Huks_DeleteKeyItem(&keyAlias, nullptr); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "deleteKey", nullptr, DeleteKey, 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index 4ebb6e3b65fa192ee0876143238870440d2e4d7f..70baf682c5d9bb1e866d36a2ed3c1d008143a0c9 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 deleteKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/pages/KeyDeletion.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/pages/KeyDeletion.ets old mode 100755 new mode 100644 index 27e5addb80f01f353c93291fb926952ce6cff37c..51c563e2e00a9a09a11fc7b0b2a1c05568de5e70 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/pages/KeyDeletion.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/ets/pages/KeyDeletion.ets @@ -1,170 +1,170 @@ -/* - * 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. - */ - -/* - * 以下以HKDF256密钥的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -/* 1.确定密钥别名 */ -let keyAlias = 'test_Key'; - -/* 2.初始化密钥属性集 */ -let generateProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_DH - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 - } -]; - -let generateHuksOptions: huks.HuksOptions = { - properties: generateProperties, - inData: new Uint8Array([]) -} - -/* 3.生成密钥 */ -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise generateKeyItem`); - try { - await generateKeyItem(keyAlias, huksOptions) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - }); - return 'Success'; - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -async function testGenKey(): Promise { - let ret = await publicGenKeyFunc(keyAlias, generateHuksOptions); - return ret; -} - - -/* 4.构造空对象 */ -let deleteHuksOptions: huks.HuksOptions = { - properties: [] -} - -class ThrowObject { - public isThrow = false; -} - -function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 3.删除密钥*/ -async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise deleteKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - console.log('start genKey...') - await testGenKey(); - console.log('end genKey...') - await deleteKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); - } - }); - return 'Success'; - } catch (error) { - console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -async function testDerive(): Promise { - let ret = await publicDeleteKeyFunc(keyAlias, deleteHuksOptions); - return ret; -} - -@Entry -@Component -struct Index { - @State message: string = 'KeyDeletion'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_key_deletion')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - let ret = await testDerive(); - this.message = 'KeyDeletion Result: ' + ret; - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以HKDF256密钥的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +/* 1.确定密钥别名 */ +let keyAlias = 'test_Key'; + +/* 2.初始化密钥属性集 */ +let generateProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 + } +]; + +let generateHuksOptions: huks.HuksOptions = { + properties: generateProperties, + inData: new Uint8Array([]) +} + +/* 3.生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise generateKeyItem`); + try { + await generateKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + }); + return 'Success'; + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +async function testGenKey(): Promise { + let ret = await publicGenKeyFunc(keyAlias, generateHuksOptions); + return ret; +} + + +/* 4.构造空对象 */ +let deleteHuksOptions: huks.HuksOptions = { + properties: [] +} + +class ThrowObject { + public isThrow = false; +} + +function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 3.删除密钥*/ +async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise deleteKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + console.log('start genKey...') + await testGenKey(); + console.log('end genKey...') + await deleteKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); + } + }); + return 'Success'; + } catch (error) { + console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +async function testDerive(): Promise { + let ret = await publicDeleteKeyFunc(keyAlias, deleteHuksOptions); + return ret; +} + +@Entry +@Component +struct Index { + @State message: string = 'KeyDeletion'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_key_deletion')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + let ret = await testDerive(); + this.message = 'KeyDeletion Result: ' + ret; + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/KeyDeletion.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/KeyDeletion.test.ets old mode 100755 new mode 100644 index 725a61f88535c0e4320ee80e25f378b8d7286ee0..23df4b73762c536f91139e12073a1ab091d4ccda --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/KeyDeletion.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/KeyDeletion.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function keyDeletionTest() { - describe('keyDeletionTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,密钥删除(ArkTS) - */ - it('testKeyDeletion001', 0, async () => { - console.info('uitest: testKeyDeletion001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('KeyDeletion').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call KeyDeletion')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('KeyDeletion Result: Success')); - console.info('uitest: testKeyDeletion001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,密钥删除(C/C++) - */ - it('testKeyDeletion002', 0, async () => { - console.info('uitest: testKeyDeletion002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testKeyDeletion002 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function keyDeletionTest() { + describe('keyDeletionTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,密钥删除(ArkTS) + */ + it('testKeyDeletion001', 0, async () => { + console.info('uitest: testKeyDeletion001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('KeyDeletion').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call KeyDeletion')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('KeyDeletion Result: Success')); + console.info('uitest: testKeyDeletion001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,密钥删除(C/C++) + */ + it('testKeyDeletion002', 0, async () => { + console.info('uitest: testKeyDeletion002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testKeyDeletion002 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyDeletion/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/ohosTest.md old mode 100755 new mode 100644 index 3f92d43bf35706b0921ce23c8f159c091822dde5..f123e6d1846e212b4feefa096a316dc17daec380 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/ohosTest.md @@ -1,9 +1,9 @@ -# 密钥删除测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,密钥删除(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +# 密钥删除测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,密钥删除(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | | 点击按钮,密钥删除(C/C++) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletionCpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletionCpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletionCpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletionCpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletion_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletion_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletion_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyDeletion/screenshots/KeyDeletion_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 old mode 100755 new mode 100644 index 9b61f8dafabb98c7e492afe800d47e5044b1c6e5..013014463590069c923be75705b96c9b11176793 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/app.json5 @@ -1,25 +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.generatekey", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.generatekey", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index db98e9ec5c89dc27f022a2cab91c60611af68fa8..99baa78e80bf9d2a9f479bcf02577c5419b11b7c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "GenerateKey" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "GenerateKey" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index a6ed6d775f5a9dc638a522b9433f0010b81c140f..0a6fa49673dd77e7b109b82e84f31911ec5b5e9f --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(GenerateKey) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(GenerateKey) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index fd8f89141bdd2bef7e30921d66a9e32c6fb16761..91576a8058bfa19d1431aa29fcb8598940a85e66 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/napi_init.cpp @@ -1,90 +1,90 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* 以下以生成ECC密钥为例 */ -#include "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; - -static napi_value GenerateKey(napi_env env, napi_callback_info info) -{ - /* 1.确定密钥别名 */ - const char *alias = "test_generate"; - struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; - struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; - struct OH_Huks_Result ohResult; - do { - /* 2.初始化密钥属性集 */ - ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, - sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 3.生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); - } while (0); - OH_Huks_FreeParamSet(&testGenerateKeyParamSet); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"generateKey", nullptr, GenerateKey, 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); } +/* + * 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. + */ + +/* 以下以生成ECC密钥为例 */ +#include "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static napi_value GenerateKey(napi_env env, napi_callback_info info) +{ + /* 1.确定密钥别名 */ + const char *alias = "test_generate"; + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + /* 2.初始化密钥属性集 */ + ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, + sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 3.生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); + } while (0); + OH_Huks_FreeParamSet(&testGenerateKeyParamSet); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"generateKey", nullptr, GenerateKey, 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts old mode 100755 new mode 100644 index 9f09a140e54fb4cf4f112355ad0cb466494234f7..589dd8a4f8f75e5b3684e5fb6275cf43a829840d --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/Index.d.ts @@ -1,16 +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. - */ - +/* + * 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 generateKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index 846e4c7e13ead48abe6019bd40f3a13bf8f9c083..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index a36ca588fe1aa322e8fca13744debe6f29d41d44..965554bb3a331e2418180b86da1993baf5e8d536 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 2ce4dd0d3e7388189b86785f8ac7769bd42c44ae..a3577e17f185b2539774c8bbb520d954e86eb032 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/ets/pages/Index.ets @@ -1,120 +1,120 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { huks } from '@kit.UniversalKeystoreKit'; -import testNapi from 'libentry.so'; - -/* 1.确定密钥别名 */ -let keyAlias = 'dh_key'; -/* 2.初始化密钥属性集 */ -let properties1: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_DH - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 - } -]; - -let huksOptions: huks.HuksOptions = { - properties: properties1, - inData: new Uint8Array([]) -} - -/* 3.生成密钥 */ -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise generateKeyItem`); - try { - await generateKeyItem(keyAlias, huksOptions) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - }); - return 'Success'; - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); - return 'Failed'; - } -} - -async function testGenKey(): Promise { - let ret = await publicGenKeyFunc(keyAlias, huksOptions); - return ret; -} - -@Entry -@Component -struct Index { - @State message: string = 'GenerateKey'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_cpp')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - let ret: number = testNapi.generateKey(); - this.message = 'C/C++ Call Result: ' + ret.toString(); - }) - Button($r('app.string.call_arkts')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - let ret = await testGenKey(); - this.message = 'ArkTS Call Result: ' + ret; - }) - } - .width('100%') - .height('100%') - } -} +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; +import testNapi from 'libentry.so'; + +/* 1.确定密钥别名 */ +let keyAlias = 'dh_key'; +/* 2.初始化密钥属性集 */ +let properties1: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 + } +]; + +let huksOptions: huks.HuksOptions = { + properties: properties1, + inData: new Uint8Array([]) +} + +/* 3.生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise generateKeyItem`); + try { + await generateKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + }); + return 'Success'; + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); + return 'Failed'; + } +} + +async function testGenKey(): Promise { + let ret = await publicGenKeyFunc(keyAlias, huksOptions); + return ret; +} + +@Entry +@Component +struct Index { + @State message: string = 'GenerateKey'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_cpp')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + let ret: number = testNapi.generateKey(); + this.message = 'C/C++ Call Result: ' + ret.toString(); + }) + Button($r('app.string.call_arkts')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + let ret = await testGenKey(); + this.message = 'ArkTS Call Result: ' + ret; + }) + } + .width('100%') + .height('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets old mode 100755 new mode 100644 index 19c39f7844060631782b93e709dd0bcc89191f7b..3eb32fe70b6b57efde0ac2504a2dcd3ec4d9c60d --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/GenerateKey.test.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function generateKeyTest() { - describe('generateKeyTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,生成密钥(C/C++) - */ - it('testGenerateKey001', 0, async () => { - console.info('uitest: testGenerateKey001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('C/C++ Call Result: 0')); - console.info('uitest: testGenerateKey001 end'); - }) - - /** - * 点击按钮,生成密钥(ArkTS) - */ - it('testGenerateKey002', 0, async () => { - console.info('uitest: testGenerateKey002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call ArkTS')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ArkTS Call Result: Success')); - console.info('uitest: testGenerateKey002 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function generateKeyTest() { + describe('generateKeyTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,生成密钥(C/C++) + */ + it('testGenerateKey001', 0, async () => { + console.info('uitest: testGenerateKey001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('C/C++ Call Result: 0')); + console.info('uitest: testGenerateKey001 end'); + }) + + /** + * 点击按钮,生成密钥(ArkTS) + */ + it('testGenerateKey002', 0, async () => { + console.info('uitest: testGenerateKey002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call ArkTS')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ArkTS Call Result: Success')); + console.info('uitest: testGenerateKey002 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md old mode 100755 new mode 100644 index 3f92d43bf35706b0921ce23c8f159c091822dde5..f123e6d1846e212b4feefa096a316dc17daec380 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/ohosTest.md @@ -1,9 +1,9 @@ -# 密钥删除测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,密钥删除(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +# 密钥删除测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,密钥删除(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | | 点击按钮,密钥删除(C/C++) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/ArkTS_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyGeneration/DevelopmentGuidelines/GenerateKey/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/app.json5 old mode 100755 new mode 100644 index 0a9cd32b1464a66636ca890333f68337f553aba0..e676f61bef5991fe2810e330b189c67e77e48e25 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/app.json5 @@ -1,25 +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.importencryptedkey", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.importencryptedkey", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 3e08dc57737670a75985f1edd14bb91324e58407..53ff5b073bf1236f68127b5a191ecb270d2dbb82 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ImportEncryptedKey" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ImportEncryptedKey" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/build-profile.json5 old mode 100755 new mode 100644 index 6f6fa15160d15c9135b1f4452581f7562e0c151a..d8e84a5fde184fee9f780b0175cc69065d86c718 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/build-profile.json5 @@ -1,58 +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": 15, - "compatibleSdkVersion": 15, - "targetSdkVersion": 15, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/* + * 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": 15, + "compatibleSdkVersion": 15, + "targetSdkVersion": 15, + "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/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/code-linter.json5 old mode 100755 new mode 100644 index 9deb9807637aa27ebde62e61e2362a417aacdc04..28586467ee7a761c737d8654a73aed6fddbc3c71 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/code-linter.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/code-linter.json5 @@ -1,35 +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": { - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/build-profile.json5 index 4774ad7bc7e7c15b5a640240be76edc3d067977e..6e7c38b54f815556a5f3e744e6a7135abf148797 100644 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/build-profile.json5 @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "armeabi-v7a", - "arm64-v8a", - "x86_64" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * 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": [ + "armeabi-v7a", + "arm64-v8a", + "x86_64" + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/hvigorfile.ts old mode 100755 new mode 100644 index 46872af92274609fb7926a0eb6451cebbb18afef..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/hvigorfile.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/hvigorfile.ts @@ -1,21 +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. */ -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/oh-package.json5 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 100644 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 628b68bebe3c14adcebe7a0b91dde2e63e251452..8bfc96301103ed13381219de2ae6287d77a7ea17 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(ImportEncryptedKey) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(ImportEncryptedKey) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 8535a23a75c9494a13be53614bd50992d3c1d065..7a74e50c70a1a157f29a0b42f3f7303584438cb4 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/napi_init.cpp @@ -1,602 +1,602 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -#define MAX_MALLOC_SIZE 0x800000 - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} -struct HksImportWrappedKeyTestParams { - // server key, for real. - struct OH_Huks_Blob *wrappingKeyAlias; - struct OH_Huks_ParamSet *genWrappingKeyParamSet; - uint32_t publicKeySize; - struct OH_Huks_Blob *callerKeyAlias; - struct OH_Huks_ParamSet *genCallerKeyParamSet; - struct OH_Huks_Blob *callerKekAlias; - struct OH_Huks_Blob *callerKek; - struct OH_Huks_ParamSet *importCallerKekParamSet; - struct OH_Huks_Blob *callerAgreeKeyAlias; - struct OH_Huks_ParamSet *agreeParamSet; - struct OH_Huks_ParamSet *importWrappedKeyParamSet; - struct OH_Huks_Blob *importedKeyAlias; - struct OH_Huks_Blob *importedPlainKey; - uint32_t keyMaterialLen; -}; -static const uint32_t IV_SIZE = 16; -static uint8_t IV[IV_SIZE] = "bababababababab"; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static const uint32_t WRAPPED_KEY_IV_SIZE = 16; -static uint8_t WRAPPED_KEY_IV[IV_SIZE] = "bababababababab"; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static const uint32_t AAD_SIZE = 16; -static uint8_t AAD[AAD_SIZE] = "abababababababa"; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static const uint32_t NONCE_SIZE = 12; -static uint8_t NONCE[NONCE_SIZE] = "hahahahahah"; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static const uint32_t AEAD_TAG_SIZE = 16; -static const uint32_t X25519_256_SIZE = 256; -static struct OH_Huks_Blob g_wrappingKeyAliasAes256 = {.size = (uint32_t)strlen("test_wrappingKey_x25519_aes256"), - .data = (uint8_t *)"test_wrappingKey_x25519_aes256"}; -static struct OH_Huks_Blob g_callerKeyAliasAes256 = {.size = (uint32_t)strlen("test_caller_key_x25519_aes256"), - .data = (uint8_t *)"test_caller_key_x25519_aes256"}; -static struct OH_Huks_Blob g_callerKekAliasAes256 = {.size = (uint32_t)strlen("test_caller_kek_x25519_aes256"), - .data = (uint8_t *)"test_caller_kek_x25519_aes256"}; -static struct OH_Huks_Blob g_callerAes256Kek = {.size = (uint32_t)strlen("This is kek to encrypt plain key"), - .data = (uint8_t *)"This is kek to encrypt plain key"}; -static struct OH_Huks_Blob g_callerAgreeKeyAliasAes256 = {.size = - (uint32_t)strlen("test_caller_agree_key_x25519_aes256"), - .data = (uint8_t *)"test_caller_agree_key_x25519_aes256"}; -static struct OH_Huks_Blob g_importedKeyAliasAes256 = {.size = (uint32_t)strlen("test_import_key_x25519_aes256"), - .data = (uint8_t *)"test_import_key_x25519_aes256"}; -static struct OH_Huks_Blob g_importedAes256PlainKey = {.size = (uint32_t)strlen("This is plain key to be imported"), - .data = (uint8_t *)"This is plain key to be imported"}; -static struct OH_Huks_Param g_importWrappedAes256Params[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, - {.tag = OH_HUKS_TAG_UNWRAP_ALGORITHM_SUITE, .uint32Param = OH_HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING}, - {.tag = OH_HUKS_TAG_ASSOCIATED_DATA, - .blob = {.size = AAD_SIZE, .data = (uint8_t *)AAD}}, // 此处仅为测试数据,实际使用时该值应与调用者信息相关。 - {.tag = OH_HUKS_TAG_NONCE, - .blob = {.size = NONCE_SIZE, .data = (uint8_t *)NONCE}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static const uint32_t g_x25519PubKeySize = 32; -static struct OH_Huks_Param g_genWrappingKeyParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_X25519}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_UNWRAP}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256}}; -static struct OH_Huks_Param g_genCallerX25519Params[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_X25519}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256}}; -static struct OH_Huks_Param g_importParamsCallerKek[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, - {.tag = OH_HUKS_TAG_IV, - .blob = {.size = WRAPPED_KEY_IV_SIZE, - .data = (uint8_t *)WRAPPED_KEY_IV}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static struct OH_Huks_Param g_callerAgreeParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_X25519}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256}}; -static struct OH_Huks_Param g_aesKekEncryptParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, - {.tag = OH_HUKS_TAG_ASSOCIATED_DATA, - .blob = {.size = AAD_SIZE, .data = (uint8_t *)AAD}}, // 此处仅为测试数据,实际使用时该值应与调用者信息相关。 - {.tag = OH_HUKS_TAG_NONCE, - .blob = {.size = NONCE_SIZE, .data = (uint8_t *)NONCE}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 -static struct OH_Huks_Param g_importAgreeKeyParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, - {.tag = OH_HUKS_TAG_IV, - .blob = {.size = IV_SIZE, .data = (uint8_t *)IV}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 -OH_Huks_Result HuksAgreeKey(const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_Blob *peerPublicKey, struct OH_Huks_Blob *agreedKey) -{ - uint8_t temp[10] = {0}; - struct OH_Huks_Blob inData = {sizeof(temp), temp}; - uint8_t handleU[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handle = {sizeof(uint64_t), handleU}; - OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, paramSet, &handle, nullptr); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - uint8_t outDataU[1024] = {0}; - struct OH_Huks_Blob outDataUpdate = {1024, outDataU}; - ret = OH_Huks_UpdateSession(&handle, paramSet, peerPublicKey, &outDataUpdate); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_FinishSession(&handle, paramSet, &inData, agreedKey); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - return ret; -} -OH_Huks_Result MallocAndCheckBlobData(struct OH_Huks_Blob *blob, const uint32_t blobSize) -{ - struct OH_Huks_Result ret; - ret.errorCode = OH_HUKS_SUCCESS; - if (blobSize == 0 || blobSize > MAX_MALLOC_SIZE) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - } - blob->data = (uint8_t *)malloc(blobSize); - if (blob->data == NULL) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - } - return ret; -} -static const uint32_t TIMES = 4; -static const uint32_t MAX_UPDATE_SIZE = 64; -static const uint32_t MAX_OUTDATA_SIZE = MAX_UPDATE_SIZE * TIMES; -#define HUKS_FREE_BLOB(blob) \ - do { \ - if ((blob).data != nullptr) { \ - free((blob).data); \ - (blob).data = nullptr; \ - } \ - (blob).size = 0; \ - } while (0) -#define OH_HUKS_KEY_BYTES(keySize) (((keySize) + 7) / 8) -static OH_Huks_Result HksEncryptLoopUpdate(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet, - const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData) -{ - struct OH_Huks_Result ret; - ret.errorCode = OH_HUKS_SUCCESS; - struct OH_Huks_Blob inDataSeg = *inData; - uint8_t *lastPtr = inData->data + inData->size - 1; - struct OH_Huks_Blob outDataSeg = {MAX_OUTDATA_SIZE, NULL}; - uint8_t *cur = outData->data; - outData->size = 0; - inDataSeg.size = MAX_UPDATE_SIZE; - bool isFinished = false; - while (inDataSeg.data <= lastPtr) { - if (inDataSeg.data + MAX_UPDATE_SIZE <= lastPtr) { - outDataSeg.size = MAX_OUTDATA_SIZE; - } else { - isFinished = true; - inDataSeg.size = lastPtr - inDataSeg.data + 1; - break; - } - if (MallocAndCheckBlobData(&outDataSeg, outDataSeg.size).errorCode != (int32_t)OH_HUKS_SUCCESS) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - return ret; - } - ret = OH_Huks_UpdateSession(handle, paramSet, &inDataSeg, &outDataSeg); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - free(outDataSeg.data); - return ret; - } - std::copy(outDataSeg.data, outDataSeg.data + outDataSeg.size, cur); - cur += outDataSeg.size; - outData->size += outDataSeg.size; - free(outDataSeg.data); - if ((isFinished == false) && (inDataSeg.data + MAX_UPDATE_SIZE > lastPtr)) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - return ret; - } - inDataSeg.data += MAX_UPDATE_SIZE; - } - struct OH_Huks_Blob outDataFinish = {inDataSeg.size * TIMES, NULL}; - if (MallocAndCheckBlobData(&outDataFinish, outDataFinish.size).errorCode != (int32_t)OH_HUKS_SUCCESS) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - return ret; - } - ret = OH_Huks_FinishSession(handle, paramSet, &inDataSeg, &outDataFinish); - if (ret.errorCode != OH_HUKS_SUCCESS) { - free(outDataFinish.data); - return ret; - } - std::copy(outDataFinish.data, outDataFinish.data + outDataFinish.size, cur); - outData->size += outDataFinish.size; - free(outDataFinish.data); - return ret; -} -OH_Huks_Result HuksEncrypt(const struct OH_Huks_Blob *key, const struct OH_Huks_ParamSet *paramSet, - const struct OH_Huks_Blob *plainText, struct OH_Huks_Blob *cipherText) -{ - uint8_t handle[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handleBlob = {sizeof(uint64_t), handle}; - OH_Huks_Result ret = OH_Huks_InitSession(key, paramSet, &handleBlob, nullptr); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = HksEncryptLoopUpdate(&handleBlob, paramSet, plainText, cipherText); - return ret; -} -static OH_Huks_Result BuildWrappedKeyData(struct OH_Huks_Blob **blobArray, uint32_t size, - struct OH_Huks_Blob *outData) -{ - uint32_t totalLength = size * sizeof(uint32_t); - struct OH_Huks_Result ret; - ret.errorCode = OH_HUKS_SUCCESS; - /* 计算大小 */ - for (uint32_t i = 0; i < size; ++i) { - totalLength += blobArray[i]->size; - } - struct OH_Huks_Blob outBlob = {0, nullptr}; - outBlob.size = totalLength; - ret = MallocAndCheckBlobData(&outBlob, outBlob.size); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - uint32_t offset = 0; - /* 拷贝数据 */ - for (uint32_t i = 0; i < size; ++i) { - if (totalLength - offset >= sizeof(blobArray[i]->size)) { - std::copy(reinterpret_cast(&blobArray[i]->size), - reinterpret_cast(&blobArray[i]->size) + sizeof(blobArray[i]->size), - outBlob.data + offset); - } else { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - return ret; - } - offset += sizeof(blobArray[i]->size); - if (totalLength - offset >= blobArray[i]->size) { - std::copy(blobArray[i]->data, blobArray[i]->data + blobArray[i]->size, outBlob.data + offset); - } else { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - return ret; - } - offset += blobArray[i]->size; - } - outData->size = outBlob.size; - outData->data = outBlob.data; - return ret; -} -static OH_Huks_Result CheckParamsValid(const struct HksImportWrappedKeyTestParams *params) -{ - struct OH_Huks_Result ret; - ret.errorCode = OH_HUKS_SUCCESS; - if (params == nullptr) { - ret.errorCode = OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; - return ret; - } - if (params->wrappingKeyAlias == nullptr || params->genWrappingKeyParamSet == nullptr || - params->callerKeyAlias == nullptr || params->genCallerKeyParamSet == nullptr || - params->callerKekAlias == nullptr || params->callerKek == nullptr || - params->importCallerKekParamSet == nullptr || params->callerAgreeKeyAlias == nullptr || - params->agreeParamSet == nullptr || params->importWrappedKeyParamSet == nullptr || - params->importedKeyAlias == nullptr || params->importedPlainKey == nullptr) { - ret.errorCode = OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; - return ret; - } - return ret; -} -static OH_Huks_Result GenerateAndExportHuksPublicKey(const struct HksImportWrappedKeyTestParams *params, - struct OH_Huks_Blob *huksPublicKey) -{ - OH_Huks_Result ret = OH_Huks_GenerateKeyItem(params->wrappingKeyAlias, params->genWrappingKeyParamSet, nullptr); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - huksPublicKey->size = params->publicKeySize; - ret = MallocAndCheckBlobData(huksPublicKey, huksPublicKey->size); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_ExportPublicKeyItem(params->wrappingKeyAlias, nullptr, huksPublicKey); - return ret; -} -static OH_Huks_Result GenerateAndExportCallerPublicKey(const struct HksImportWrappedKeyTestParams *params, - struct OH_Huks_Blob *callerSelfPublicKey) -{ - OH_Huks_Result ret = OH_Huks_GenerateKeyItem(params->callerKeyAlias, params->genCallerKeyParamSet, nullptr); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - callerSelfPublicKey->size = params->publicKeySize; - ret = MallocAndCheckBlobData(callerSelfPublicKey, callerSelfPublicKey->size); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_ExportPublicKeyItem(params->callerKeyAlias, params->genWrappingKeyParamSet, callerSelfPublicKey); - return ret; -} -static OH_Huks_Result ImportKekAndAgreeSharedSecret(const struct HksImportWrappedKeyTestParams *params, - const struct OH_Huks_Blob *huksPublicKey, - struct OH_Huks_Blob *outSharedKey) -{ - OH_Huks_Result ret = - OH_Huks_ImportKeyItem(params->callerKekAlias, params->importCallerKekParamSet, params->callerKek); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = MallocAndCheckBlobData(outSharedKey, outSharedKey->size); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = HuksAgreeKey(params->agreeParamSet, params->callerKeyAlias, huksPublicKey, outSharedKey); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - struct OH_Huks_ParamSet *importAgreeKeyParams = nullptr; - ret = InitParamSet(&importAgreeKeyParams, g_importAgreeKeyParams, - sizeof(g_importAgreeKeyParams) / sizeof(OH_Huks_Param)); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_ImportKeyItem(params->callerAgreeKeyAlias, importAgreeKeyParams, outSharedKey); - OH_Huks_FreeParamSet(&importAgreeKeyParams); - return ret; -} -static OH_Huks_Result EncryptImportedPlainKeyAndKek(const struct HksImportWrappedKeyTestParams *params, - struct OH_Huks_Blob *plainCipherText, - struct OH_Huks_Blob *kekCipherText) -{ - struct OH_Huks_ParamSet *encryptParamSet = nullptr; - OH_Huks_Result ret = - InitParamSet(&encryptParamSet, g_aesKekEncryptParams, sizeof(g_aesKekEncryptParams) / sizeof(OH_Huks_Param)); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = HuksEncrypt(params->callerKekAlias, encryptParamSet, params->importedPlainKey, plainCipherText); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = HuksEncrypt(params->callerAgreeKeyAlias, encryptParamSet, params->callerKek, kekCipherText); - OH_Huks_FreeParamSet(&encryptParamSet); - return ret; -} -static OH_Huks_Result ImportWrappedKey(const struct HksImportWrappedKeyTestParams *params, - struct OH_Huks_Blob *plainCipher, struct OH_Huks_Blob *kekCipherText, - struct OH_Huks_Blob *peerPublicKey, struct OH_Huks_Blob *wrappedKeyData) -{ - struct OH_Huks_Blob commonAad = {.size = AAD_SIZE, .data = reinterpret_cast(AAD)}; - struct OH_Huks_Blob commonNonce = {.size = NONCE_SIZE, .data = reinterpret_cast(NONCE)}; - struct OH_Huks_Blob keyMaterialLen = {.size = sizeof(uint32_t), .data = (uint8_t *)¶ms->keyMaterialLen}; - /* 从密文中拷贝AEAD的tag并缩小其大小 */ - const uint32_t tagSize = AEAD_TAG_SIZE; - uint8_t kekTagBuf[tagSize] = {0}; - struct OH_Huks_Blob kekTag = {.size = tagSize, .data = kekTagBuf}; - std::copy(plainCipher->data + (plainCipher->size - tagSize), - plainCipher->data + (plainCipher->size - tagSize) + tagSize, kekTag.data); - plainCipher->size -= tagSize; - /* 从密钥加密密钥的密文中拷贝AEAD的tag并缩小其大小 */ - uint8_t agreeKeyTagBuf[tagSize] = {0}; - struct OH_Huks_Blob agreeKeyTag = {.size = tagSize, .data = agreeKeyTagBuf}; - std::copy(kekCipherText->data + (kekCipherText->size - tagSize), - kekCipherText->data + (kekCipherText->size - tagSize) + tagSize, agreeKeyTagBuf); - kekCipherText->size -= tagSize; - struct OH_Huks_Blob *blobArray[] = {peerPublicKey, &commonAad, &commonNonce, &agreeKeyTag, kekCipherText, - &commonAad, &commonNonce, &kekTag, &keyMaterialLen, plainCipher}; - OH_Huks_Result ret = BuildWrappedKeyData(blobArray, OH_HUKS_IMPORT_WRAPPED_KEY_TOTAL_BLOBS, wrappedKeyData); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - struct OH_Huks_Param *purpose = nullptr; - ret = OH_Huks_GetParam(params->importWrappedKeyParamSet, OH_HUKS_TAG_PURPOSE, &purpose); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_ImportWrappedKeyItem(params->importedKeyAlias, params->wrappingKeyAlias, - params->importWrappedKeyParamSet, wrappedKeyData); - return ret; -} -OH_Huks_Result HksImportWrappedKeyTestCommonCase(const struct HksImportWrappedKeyTestParams *params) -{ - OH_Huks_Result ret = CheckParamsValid(params); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return ret; - } - struct OH_Huks_Blob huksPublicKey = {0, nullptr}; - struct OH_Huks_Blob callerSelfPublicKey = {0, nullptr}; - struct OH_Huks_Blob outSharedKey = {.size = OH_HUKS_KEY_BYTES(OH_HUKS_AES_KEY_SIZE_256), .data = nullptr}; - struct OH_Huks_Blob wrappedKeyData = {0, nullptr}; - uint8_t plainKeyCipherBuffer[OH_HUKS_MAX_KEY_SIZE] = {0}; - struct OH_Huks_Blob plainCipherText = {OH_HUKS_MAX_KEY_SIZE, plainKeyCipherBuffer}; - uint8_t kekCipherTextBuffer[OH_HUKS_MAX_KEY_SIZE] = {0}; - struct OH_Huks_Blob kekCipherText = {OH_HUKS_MAX_KEY_SIZE, kekCipherTextBuffer}; - /* 模拟加密导入密钥场景,设备A为远端设备(导入设备),设备B为本端设备(被导入设备) */ - do { - /** - * 1.设备A将待导入密钥转换成HUKS密钥材料格式To_Import_Key(仅针对非对称密钥,若待导入密钥是对称密钥则可省略此步骤), - * 本示例使用g_importedAes256PlainKey(对称密钥)作为模拟 - */ - /* 2.设备B生成一个加密导入用途的、用于协商的非对称密钥对Wrapping_Key(公钥Wrapping_Pk,私钥Wrapping_Sk), - * 其密钥用途设置为unwrap,导出Wrapping_Key公钥Wrapping_Pk存放在变量huksPublicKey中 - */ - ret = GenerateAndExportHuksPublicKey(params, &huksPublicKey); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - break; - } - /* 3.设备A使用和设备B同样的算法,生成一个加密导入用途的、用于协商的非对称密钥对Caller_Key(公钥Caller_Pk,私钥Caller_Sk), - * 导出Caller_Key公钥Caller_Pk存放在变量callerSelfPublicKey中 - */ - ret = GenerateAndExportCallerPublicKey(params, &callerSelfPublicKey); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - break; - } - /** - * 4. 设备A生成一个对称密钥Caller_Kek,该密钥后续将用于加密To_Import_Key - * 5. 设备A基于Caller_Key的私钥Caller_Sk和设备B Wrapping_Key的公钥Wrapping_Pk,协商出Shared_Key - */ - ret = ImportKekAndAgreeSharedSecret(params, &huksPublicKey, &outSharedKey); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - break; - } - /** - * 6. 设备A使用Caller_Kek加密To_Import_Key,生成To_Import_Key_Enc - * 7. 设备A使用Shared_Key加密Caller_Kek,生成Caller_Kek_Enc - */ - ret = EncryptImportedPlainKeyAndKek(params, &plainCipherText, &kekCipherText); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - break; - } - /* 8. 设备A封装Caller_Pk、To_Import_Key_Enc、Caller_Kek_Enc等加密导入的材料并发送给设备B。 - * 本示例作为变量存放在callerSelfPublicKey,plainCipherText,kekCipherText - * 9. 设备B导入封装的加密密钥材料 - */ - ret = ImportWrappedKey(params, &plainCipherText, &kekCipherText, &callerSelfPublicKey, &wrappedKeyData); - } while (0); - /* 10. 设备A、B删除用于加密导入的密钥 */ - HUKS_FREE_BLOB(huksPublicKey); - HUKS_FREE_BLOB(callerSelfPublicKey); - HUKS_FREE_BLOB(outSharedKey); - HUKS_FREE_BLOB(wrappedKeyData); - return ret; -} -void HksClearKeysForWrappedKeyTest(const struct HksImportWrappedKeyTestParams *params) -{ - OH_Huks_Result ret = CheckParamsValid(params); - if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { - return; - } - (void)OH_Huks_DeleteKeyItem(params->wrappingKeyAlias, nullptr); - (void)OH_Huks_DeleteKeyItem(params->callerKeyAlias, nullptr); - (void)OH_Huks_DeleteKeyItem(params->callerKekAlias, nullptr); - (void)OH_Huks_DeleteKeyItem(params->callerAgreeKeyAlias, nullptr); - (void)OH_Huks_DeleteKeyItem(params->importedKeyAlias, nullptr); -} -static OH_Huks_Result InitCommonTestParamsAndDoImport(struct HksImportWrappedKeyTestParams *importWrappedKeyTestParams, - const struct OH_Huks_Param *importedKeyParamSetArray, - uint32_t arraySize) -{ - struct OH_Huks_ParamSet *genX25519KeyParamSet = nullptr; - struct OH_Huks_ParamSet *genCallerKeyParamSet = nullptr; - struct OH_Huks_ParamSet *callerImportParamsKek = nullptr; - struct OH_Huks_ParamSet *agreeParamSet = nullptr; - struct OH_Huks_ParamSet *importPlainKeyParams = nullptr; - OH_Huks_Result ret; - do { - ret = InitParamSet(&genX25519KeyParamSet, g_genWrappingKeyParams, - sizeof(g_genWrappingKeyParams) / sizeof(OH_Huks_Param)); - if (ret.errorCode != OH_HUKS_SUCCESS) { - break; - } - importWrappedKeyTestParams->genWrappingKeyParamSet = genX25519KeyParamSet; - importWrappedKeyTestParams->publicKeySize = g_x25519PubKeySize; - ret = InitParamSet(&genCallerKeyParamSet, g_genCallerX25519Params, - sizeof(g_genCallerX25519Params) / sizeof(OH_Huks_Param)); - if (ret.errorCode != OH_HUKS_SUCCESS) { - break; - } - importWrappedKeyTestParams->genCallerKeyParamSet = genCallerKeyParamSet; - ret = InitParamSet(&callerImportParamsKek, g_importParamsCallerKek, - sizeof(g_importParamsCallerKek) / sizeof(OH_Huks_Param)); - if (ret.errorCode != OH_HUKS_SUCCESS) { - break; - } - importWrappedKeyTestParams->importCallerKekParamSet = callerImportParamsKek; - ret = InitParamSet(&agreeParamSet, g_callerAgreeParams, sizeof(g_callerAgreeParams) / sizeof(OH_Huks_Param)); - if (ret.errorCode != OH_HUKS_SUCCESS) { - break; - } - importWrappedKeyTestParams->agreeParamSet = agreeParamSet; - ret = InitParamSet(&importPlainKeyParams, importedKeyParamSetArray, arraySize); - if (ret.errorCode != OH_HUKS_SUCCESS) { - break; - } - importWrappedKeyTestParams->importWrappedKeyParamSet = importPlainKeyParams; - ret = HksImportWrappedKeyTestCommonCase(importWrappedKeyTestParams); - } while (0); - OH_Huks_FreeParamSet(&genX25519KeyParamSet); - OH_Huks_FreeParamSet(&genCallerKeyParamSet); - OH_Huks_FreeParamSet(&callerImportParamsKek); - OH_Huks_FreeParamSet(&agreeParamSet); - OH_Huks_FreeParamSet(&importPlainKeyParams); - return ret; -} -static napi_value NAPI_Global_importWrappedKey(napi_env env, napi_callback_info info) -{ - struct HksImportWrappedKeyTestParams importWrappedKeyTestParams001 = {0}; - importWrappedKeyTestParams001.wrappingKeyAlias = &g_wrappingKeyAliasAes256; - importWrappedKeyTestParams001.keyMaterialLen = g_importedAes256PlainKey.size; - importWrappedKeyTestParams001.callerKeyAlias = &g_callerKeyAliasAes256; - importWrappedKeyTestParams001.callerKekAlias = &g_callerKekAliasAes256; - importWrappedKeyTestParams001.callerKek = &g_callerAes256Kek; - importWrappedKeyTestParams001.callerAgreeKeyAlias = &g_callerAgreeKeyAliasAes256; - importWrappedKeyTestParams001.importedKeyAlias = &g_importedKeyAliasAes256; - importWrappedKeyTestParams001.importedPlainKey = &g_importedAes256PlainKey; - OH_Huks_Result ohResult = - InitCommonTestParamsAndDoImport(&importWrappedKeyTestParams001, g_importWrappedAes256Params, - sizeof(g_importWrappedAes256Params) / sizeof(struct OH_Huks_Param)); - HksClearKeysForWrappedKeyTest(&importWrappedKeyTestParams001); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -static napi_value IsKeyExist(napi_env env, napi_callback_info info) -{ - /* 1.指定密钥别名 */ - struct OH_Huks_Blob keyAlias = { - (uint32_t)strlen("test_key"), - (uint8_t *)"test_key" - }; - - /* 2.调用OH_Huks_IsKeyItemExist判断密钥是否存在 */ - struct OH_Huks_Result ohResult = OH_Huks_IsKeyItemExist(&keyAlias, NULL); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"isKeyExist", nullptr, IsKeyExist, nullptr, nullptr, nullptr, napi_default, nullptr }, - {"importWrappedKey", nullptr, NAPI_Global_importWrappedKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +#define MAX_MALLOC_SIZE 0x800000 + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} +struct HksImportWrappedKeyTestParams { + // server key, for real. + struct OH_Huks_Blob *wrappingKeyAlias; + struct OH_Huks_ParamSet *genWrappingKeyParamSet; + uint32_t publicKeySize; + struct OH_Huks_Blob *callerKeyAlias; + struct OH_Huks_ParamSet *genCallerKeyParamSet; + struct OH_Huks_Blob *callerKekAlias; + struct OH_Huks_Blob *callerKek; + struct OH_Huks_ParamSet *importCallerKekParamSet; + struct OH_Huks_Blob *callerAgreeKeyAlias; + struct OH_Huks_ParamSet *agreeParamSet; + struct OH_Huks_ParamSet *importWrappedKeyParamSet; + struct OH_Huks_Blob *importedKeyAlias; + struct OH_Huks_Blob *importedPlainKey; + uint32_t keyMaterialLen; +}; +static const uint32_t IV_SIZE = 16; +static uint8_t IV[IV_SIZE] = "bababababababab"; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static const uint32_t WRAPPED_KEY_IV_SIZE = 16; +static uint8_t WRAPPED_KEY_IV[IV_SIZE] = "bababababababab"; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static const uint32_t AAD_SIZE = 16; +static uint8_t AAD[AAD_SIZE] = "abababababababa"; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static const uint32_t NONCE_SIZE = 12; +static uint8_t NONCE[NONCE_SIZE] = "hahahahahah"; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static const uint32_t AEAD_TAG_SIZE = 16; +static const uint32_t X25519_256_SIZE = 256; +static struct OH_Huks_Blob g_wrappingKeyAliasAes256 = {.size = (uint32_t)strlen("test_wrappingKey_x25519_aes256"), + .data = (uint8_t *)"test_wrappingKey_x25519_aes256"}; +static struct OH_Huks_Blob g_callerKeyAliasAes256 = {.size = (uint32_t)strlen("test_caller_key_x25519_aes256"), + .data = (uint8_t *)"test_caller_key_x25519_aes256"}; +static struct OH_Huks_Blob g_callerKekAliasAes256 = {.size = (uint32_t)strlen("test_caller_kek_x25519_aes256"), + .data = (uint8_t *)"test_caller_kek_x25519_aes256"}; +static struct OH_Huks_Blob g_callerAes256Kek = {.size = (uint32_t)strlen("This is kek to encrypt plain key"), + .data = (uint8_t *)"This is kek to encrypt plain key"}; +static struct OH_Huks_Blob g_callerAgreeKeyAliasAes256 = {.size = + (uint32_t)strlen("test_caller_agree_key_x25519_aes256"), + .data = (uint8_t *)"test_caller_agree_key_x25519_aes256"}; +static struct OH_Huks_Blob g_importedKeyAliasAes256 = {.size = (uint32_t)strlen("test_import_key_x25519_aes256"), + .data = (uint8_t *)"test_import_key_x25519_aes256"}; +static struct OH_Huks_Blob g_importedAes256PlainKey = {.size = (uint32_t)strlen("This is plain key to be imported"), + .data = (uint8_t *)"This is plain key to be imported"}; +static struct OH_Huks_Param g_importWrappedAes256Params[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, + {.tag = OH_HUKS_TAG_UNWRAP_ALGORITHM_SUITE, .uint32Param = OH_HUKS_UNWRAP_SUITE_X25519_AES_256_GCM_NOPADDING}, + {.tag = OH_HUKS_TAG_ASSOCIATED_DATA, + .blob = {.size = AAD_SIZE, .data = (uint8_t *)AAD}}, // 此处仅为测试数据,实际使用时该值应与调用者信息相关。 + {.tag = OH_HUKS_TAG_NONCE, + .blob = {.size = NONCE_SIZE, .data = (uint8_t *)NONCE}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static const uint32_t g_x25519PubKeySize = 32; +static struct OH_Huks_Param g_genWrappingKeyParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_X25519}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_UNWRAP}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256}}; +static struct OH_Huks_Param g_genCallerX25519Params[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_X25519}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256}}; +static struct OH_Huks_Param g_importParamsCallerKek[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, + {.tag = OH_HUKS_TAG_IV, + .blob = {.size = WRAPPED_KEY_IV_SIZE, + .data = (uint8_t *)WRAPPED_KEY_IV}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static struct OH_Huks_Param g_callerAgreeParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_X25519}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_CURVE25519_KEY_SIZE_256}}; +static struct OH_Huks_Param g_aesKekEncryptParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, + {.tag = OH_HUKS_TAG_ASSOCIATED_DATA, + .blob = {.size = AAD_SIZE, .data = (uint8_t *)AAD}}, // 此处仅为测试数据,实际使用时该值应与调用者信息相关。 + {.tag = OH_HUKS_TAG_NONCE, + .blob = {.size = NONCE_SIZE, .data = (uint8_t *)NONCE}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 +static struct OH_Huks_Param g_importAgreeKeyParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_GCM}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}, + {.tag = OH_HUKS_TAG_IV, + .blob = {.size = IV_SIZE, .data = (uint8_t *)IV}}}; // 此处仅为测试数据,实际使用时该值每次应该不同。 +OH_Huks_Result HuksAgreeKey(const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_Blob *peerPublicKey, struct OH_Huks_Blob *agreedKey) +{ + uint8_t temp[10] = {0}; + struct OH_Huks_Blob inData = {sizeof(temp), temp}; + uint8_t handleU[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handle = {sizeof(uint64_t), handleU}; + OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, paramSet, &handle, nullptr); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + uint8_t outDataU[1024] = {0}; + struct OH_Huks_Blob outDataUpdate = {1024, outDataU}; + ret = OH_Huks_UpdateSession(&handle, paramSet, peerPublicKey, &outDataUpdate); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_FinishSession(&handle, paramSet, &inData, agreedKey); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + return ret; +} +OH_Huks_Result MallocAndCheckBlobData(struct OH_Huks_Blob *blob, const uint32_t blobSize) +{ + struct OH_Huks_Result ret; + ret.errorCode = OH_HUKS_SUCCESS; + if (blobSize == 0 || blobSize > MAX_MALLOC_SIZE) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + } + blob->data = (uint8_t *)malloc(blobSize); + if (blob->data == NULL) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + } + return ret; +} +static const uint32_t TIMES = 4; +static const uint32_t MAX_UPDATE_SIZE = 64; +static const uint32_t MAX_OUTDATA_SIZE = MAX_UPDATE_SIZE * TIMES; +#define HUKS_FREE_BLOB(blob) \ + do { \ + if ((blob).data != nullptr) { \ + free((blob).data); \ + (blob).data = nullptr; \ + } \ + (blob).size = 0; \ + } while (0) +#define OH_HUKS_KEY_BYTES(keySize) (((keySize) + 7) / 8) +static OH_Huks_Result HksEncryptLoopUpdate(const struct OH_Huks_Blob *handle, const struct OH_Huks_ParamSet *paramSet, + const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData) +{ + struct OH_Huks_Result ret; + ret.errorCode = OH_HUKS_SUCCESS; + struct OH_Huks_Blob inDataSeg = *inData; + uint8_t *lastPtr = inData->data + inData->size - 1; + struct OH_Huks_Blob outDataSeg = {MAX_OUTDATA_SIZE, NULL}; + uint8_t *cur = outData->data; + outData->size = 0; + inDataSeg.size = MAX_UPDATE_SIZE; + bool isFinished = false; + while (inDataSeg.data <= lastPtr) { + if (inDataSeg.data + MAX_UPDATE_SIZE <= lastPtr) { + outDataSeg.size = MAX_OUTDATA_SIZE; + } else { + isFinished = true; + inDataSeg.size = lastPtr - inDataSeg.data + 1; + break; + } + if (MallocAndCheckBlobData(&outDataSeg, outDataSeg.size).errorCode != (int32_t)OH_HUKS_SUCCESS) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + return ret; + } + ret = OH_Huks_UpdateSession(handle, paramSet, &inDataSeg, &outDataSeg); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + free(outDataSeg.data); + return ret; + } + std::copy(outDataSeg.data, outDataSeg.data + outDataSeg.size, cur); + cur += outDataSeg.size; + outData->size += outDataSeg.size; + free(outDataSeg.data); + if ((isFinished == false) && (inDataSeg.data + MAX_UPDATE_SIZE > lastPtr)) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + return ret; + } + inDataSeg.data += MAX_UPDATE_SIZE; + } + struct OH_Huks_Blob outDataFinish = {inDataSeg.size * TIMES, NULL}; + if (MallocAndCheckBlobData(&outDataFinish, outDataFinish.size).errorCode != (int32_t)OH_HUKS_SUCCESS) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + return ret; + } + ret = OH_Huks_FinishSession(handle, paramSet, &inDataSeg, &outDataFinish); + if (ret.errorCode != OH_HUKS_SUCCESS) { + free(outDataFinish.data); + return ret; + } + std::copy(outDataFinish.data, outDataFinish.data + outDataFinish.size, cur); + outData->size += outDataFinish.size; + free(outDataFinish.data); + return ret; +} +OH_Huks_Result HuksEncrypt(const struct OH_Huks_Blob *key, const struct OH_Huks_ParamSet *paramSet, + const struct OH_Huks_Blob *plainText, struct OH_Huks_Blob *cipherText) +{ + uint8_t handle[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handleBlob = {sizeof(uint64_t), handle}; + OH_Huks_Result ret = OH_Huks_InitSession(key, paramSet, &handleBlob, nullptr); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = HksEncryptLoopUpdate(&handleBlob, paramSet, plainText, cipherText); + return ret; +} +static OH_Huks_Result BuildWrappedKeyData(struct OH_Huks_Blob **blobArray, uint32_t size, + struct OH_Huks_Blob *outData) +{ + uint32_t totalLength = size * sizeof(uint32_t); + struct OH_Huks_Result ret; + ret.errorCode = OH_HUKS_SUCCESS; + /* 计算大小 */ + for (uint32_t i = 0; i < size; ++i) { + totalLength += blobArray[i]->size; + } + struct OH_Huks_Blob outBlob = {0, nullptr}; + outBlob.size = totalLength; + ret = MallocAndCheckBlobData(&outBlob, outBlob.size); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + uint32_t offset = 0; + /* 拷贝数据 */ + for (uint32_t i = 0; i < size; ++i) { + if (totalLength - offset >= sizeof(blobArray[i]->size)) { + std::copy(reinterpret_cast(&blobArray[i]->size), + reinterpret_cast(&blobArray[i]->size) + sizeof(blobArray[i]->size), + outBlob.data + offset); + } else { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + return ret; + } + offset += sizeof(blobArray[i]->size); + if (totalLength - offset >= blobArray[i]->size) { + std::copy(blobArray[i]->data, blobArray[i]->data + blobArray[i]->size, outBlob.data + offset); + } else { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + return ret; + } + offset += blobArray[i]->size; + } + outData->size = outBlob.size; + outData->data = outBlob.data; + return ret; +} +static OH_Huks_Result CheckParamsValid(const struct HksImportWrappedKeyTestParams *params) +{ + struct OH_Huks_Result ret; + ret.errorCode = OH_HUKS_SUCCESS; + if (params == nullptr) { + ret.errorCode = OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; + return ret; + } + if (params->wrappingKeyAlias == nullptr || params->genWrappingKeyParamSet == nullptr || + params->callerKeyAlias == nullptr || params->genCallerKeyParamSet == nullptr || + params->callerKekAlias == nullptr || params->callerKek == nullptr || + params->importCallerKekParamSet == nullptr || params->callerAgreeKeyAlias == nullptr || + params->agreeParamSet == nullptr || params->importWrappedKeyParamSet == nullptr || + params->importedKeyAlias == nullptr || params->importedPlainKey == nullptr) { + ret.errorCode = OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; + return ret; + } + return ret; +} +static OH_Huks_Result GenerateAndExportHuksPublicKey(const struct HksImportWrappedKeyTestParams *params, + struct OH_Huks_Blob *huksPublicKey) +{ + OH_Huks_Result ret = OH_Huks_GenerateKeyItem(params->wrappingKeyAlias, params->genWrappingKeyParamSet, nullptr); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + huksPublicKey->size = params->publicKeySize; + ret = MallocAndCheckBlobData(huksPublicKey, huksPublicKey->size); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_ExportPublicKeyItem(params->wrappingKeyAlias, nullptr, huksPublicKey); + return ret; +} +static OH_Huks_Result GenerateAndExportCallerPublicKey(const struct HksImportWrappedKeyTestParams *params, + struct OH_Huks_Blob *callerSelfPublicKey) +{ + OH_Huks_Result ret = OH_Huks_GenerateKeyItem(params->callerKeyAlias, params->genCallerKeyParamSet, nullptr); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + callerSelfPublicKey->size = params->publicKeySize; + ret = MallocAndCheckBlobData(callerSelfPublicKey, callerSelfPublicKey->size); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_ExportPublicKeyItem(params->callerKeyAlias, params->genWrappingKeyParamSet, callerSelfPublicKey); + return ret; +} +static OH_Huks_Result ImportKekAndAgreeSharedSecret(const struct HksImportWrappedKeyTestParams *params, + const struct OH_Huks_Blob *huksPublicKey, + struct OH_Huks_Blob *outSharedKey) +{ + OH_Huks_Result ret = + OH_Huks_ImportKeyItem(params->callerKekAlias, params->importCallerKekParamSet, params->callerKek); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = MallocAndCheckBlobData(outSharedKey, outSharedKey->size); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = HuksAgreeKey(params->agreeParamSet, params->callerKeyAlias, huksPublicKey, outSharedKey); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + struct OH_Huks_ParamSet *importAgreeKeyParams = nullptr; + ret = InitParamSet(&importAgreeKeyParams, g_importAgreeKeyParams, + sizeof(g_importAgreeKeyParams) / sizeof(OH_Huks_Param)); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_ImportKeyItem(params->callerAgreeKeyAlias, importAgreeKeyParams, outSharedKey); + OH_Huks_FreeParamSet(&importAgreeKeyParams); + return ret; +} +static OH_Huks_Result EncryptImportedPlainKeyAndKek(const struct HksImportWrappedKeyTestParams *params, + struct OH_Huks_Blob *plainCipherText, + struct OH_Huks_Blob *kekCipherText) +{ + struct OH_Huks_ParamSet *encryptParamSet = nullptr; + OH_Huks_Result ret = + InitParamSet(&encryptParamSet, g_aesKekEncryptParams, sizeof(g_aesKekEncryptParams) / sizeof(OH_Huks_Param)); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = HuksEncrypt(params->callerKekAlias, encryptParamSet, params->importedPlainKey, plainCipherText); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = HuksEncrypt(params->callerAgreeKeyAlias, encryptParamSet, params->callerKek, kekCipherText); + OH_Huks_FreeParamSet(&encryptParamSet); + return ret; +} +static OH_Huks_Result ImportWrappedKey(const struct HksImportWrappedKeyTestParams *params, + struct OH_Huks_Blob *plainCipher, struct OH_Huks_Blob *kekCipherText, + struct OH_Huks_Blob *peerPublicKey, struct OH_Huks_Blob *wrappedKeyData) +{ + struct OH_Huks_Blob commonAad = {.size = AAD_SIZE, .data = reinterpret_cast(AAD)}; + struct OH_Huks_Blob commonNonce = {.size = NONCE_SIZE, .data = reinterpret_cast(NONCE)}; + struct OH_Huks_Blob keyMaterialLen = {.size = sizeof(uint32_t), .data = (uint8_t *)¶ms->keyMaterialLen}; + /* 从密文中拷贝AEAD的tag并缩小其大小 */ + const uint32_t tagSize = AEAD_TAG_SIZE; + uint8_t kekTagBuf[tagSize] = {0}; + struct OH_Huks_Blob kekTag = {.size = tagSize, .data = kekTagBuf}; + std::copy(plainCipher->data + (plainCipher->size - tagSize), + plainCipher->data + (plainCipher->size - tagSize) + tagSize, kekTag.data); + plainCipher->size -= tagSize; + /* 从密钥加密密钥的密文中拷贝AEAD的tag并缩小其大小 */ + uint8_t agreeKeyTagBuf[tagSize] = {0}; + struct OH_Huks_Blob agreeKeyTag = {.size = tagSize, .data = agreeKeyTagBuf}; + std::copy(kekCipherText->data + (kekCipherText->size - tagSize), + kekCipherText->data + (kekCipherText->size - tagSize) + tagSize, agreeKeyTagBuf); + kekCipherText->size -= tagSize; + struct OH_Huks_Blob *blobArray[] = {peerPublicKey, &commonAad, &commonNonce, &agreeKeyTag, kekCipherText, + &commonAad, &commonNonce, &kekTag, &keyMaterialLen, plainCipher}; + OH_Huks_Result ret = BuildWrappedKeyData(blobArray, OH_HUKS_IMPORT_WRAPPED_KEY_TOTAL_BLOBS, wrappedKeyData); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + struct OH_Huks_Param *purpose = nullptr; + ret = OH_Huks_GetParam(params->importWrappedKeyParamSet, OH_HUKS_TAG_PURPOSE, &purpose); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_ImportWrappedKeyItem(params->importedKeyAlias, params->wrappingKeyAlias, + params->importWrappedKeyParamSet, wrappedKeyData); + return ret; +} +OH_Huks_Result HksImportWrappedKeyTestCommonCase(const struct HksImportWrappedKeyTestParams *params) +{ + OH_Huks_Result ret = CheckParamsValid(params); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return ret; + } + struct OH_Huks_Blob huksPublicKey = {0, nullptr}; + struct OH_Huks_Blob callerSelfPublicKey = {0, nullptr}; + struct OH_Huks_Blob outSharedKey = {.size = OH_HUKS_KEY_BYTES(OH_HUKS_AES_KEY_SIZE_256), .data = nullptr}; + struct OH_Huks_Blob wrappedKeyData = {0, nullptr}; + uint8_t plainKeyCipherBuffer[OH_HUKS_MAX_KEY_SIZE] = {0}; + struct OH_Huks_Blob plainCipherText = {OH_HUKS_MAX_KEY_SIZE, plainKeyCipherBuffer}; + uint8_t kekCipherTextBuffer[OH_HUKS_MAX_KEY_SIZE] = {0}; + struct OH_Huks_Blob kekCipherText = {OH_HUKS_MAX_KEY_SIZE, kekCipherTextBuffer}; + /* 模拟加密导入密钥场景,设备A为远端设备(导入设备),设备B为本端设备(被导入设备) */ + do { + /** + * 1.设备A将待导入密钥转换成HUKS密钥材料格式To_Import_Key(仅针对非对称密钥,若待导入密钥是对称密钥则可省略此步骤), + * 本示例使用g_importedAes256PlainKey(对称密钥)作为模拟 + */ + /* 2.设备B生成一个加密导入用途的、用于协商的非对称密钥对Wrapping_Key(公钥Wrapping_Pk,私钥Wrapping_Sk), + * 其密钥用途设置为unwrap,导出Wrapping_Key公钥Wrapping_Pk存放在变量huksPublicKey中 + */ + ret = GenerateAndExportHuksPublicKey(params, &huksPublicKey); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + break; + } + /* 3.设备A使用和设备B同样的算法,生成一个加密导入用途的、用于协商的非对称密钥对Caller_Key(公钥Caller_Pk,私钥Caller_Sk), + * 导出Caller_Key公钥Caller_Pk存放在变量callerSelfPublicKey中 + */ + ret = GenerateAndExportCallerPublicKey(params, &callerSelfPublicKey); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + break; + } + /** + * 4. 设备A生成一个对称密钥Caller_Kek,该密钥后续将用于加密To_Import_Key + * 5. 设备A基于Caller_Key的私钥Caller_Sk和设备B Wrapping_Key的公钥Wrapping_Pk,协商出Shared_Key + */ + ret = ImportKekAndAgreeSharedSecret(params, &huksPublicKey, &outSharedKey); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + break; + } + /** + * 6. 设备A使用Caller_Kek加密To_Import_Key,生成To_Import_Key_Enc + * 7. 设备A使用Shared_Key加密Caller_Kek,生成Caller_Kek_Enc + */ + ret = EncryptImportedPlainKeyAndKek(params, &plainCipherText, &kekCipherText); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + break; + } + /* 8. 设备A封装Caller_Pk、To_Import_Key_Enc、Caller_Kek_Enc等加密导入的材料并发送给设备B。 + * 本示例作为变量存放在callerSelfPublicKey,plainCipherText,kekCipherText + * 9. 设备B导入封装的加密密钥材料 + */ + ret = ImportWrappedKey(params, &plainCipherText, &kekCipherText, &callerSelfPublicKey, &wrappedKeyData); + } while (0); + /* 10. 设备A、B删除用于加密导入的密钥 */ + HUKS_FREE_BLOB(huksPublicKey); + HUKS_FREE_BLOB(callerSelfPublicKey); + HUKS_FREE_BLOB(outSharedKey); + HUKS_FREE_BLOB(wrappedKeyData); + return ret; +} +void HksClearKeysForWrappedKeyTest(const struct HksImportWrappedKeyTestParams *params) +{ + OH_Huks_Result ret = CheckParamsValid(params); + if (ret.errorCode != (int32_t)OH_HUKS_SUCCESS) { + return; + } + (void)OH_Huks_DeleteKeyItem(params->wrappingKeyAlias, nullptr); + (void)OH_Huks_DeleteKeyItem(params->callerKeyAlias, nullptr); + (void)OH_Huks_DeleteKeyItem(params->callerKekAlias, nullptr); + (void)OH_Huks_DeleteKeyItem(params->callerAgreeKeyAlias, nullptr); + (void)OH_Huks_DeleteKeyItem(params->importedKeyAlias, nullptr); +} +static OH_Huks_Result InitCommonTestParamsAndDoImport(struct HksImportWrappedKeyTestParams *importWrappedKeyTestParams, + const struct OH_Huks_Param *importedKeyParamSetArray, + uint32_t arraySize) +{ + struct OH_Huks_ParamSet *genX25519KeyParamSet = nullptr; + struct OH_Huks_ParamSet *genCallerKeyParamSet = nullptr; + struct OH_Huks_ParamSet *callerImportParamsKek = nullptr; + struct OH_Huks_ParamSet *agreeParamSet = nullptr; + struct OH_Huks_ParamSet *importPlainKeyParams = nullptr; + OH_Huks_Result ret; + do { + ret = InitParamSet(&genX25519KeyParamSet, g_genWrappingKeyParams, + sizeof(g_genWrappingKeyParams) / sizeof(OH_Huks_Param)); + if (ret.errorCode != OH_HUKS_SUCCESS) { + break; + } + importWrappedKeyTestParams->genWrappingKeyParamSet = genX25519KeyParamSet; + importWrappedKeyTestParams->publicKeySize = g_x25519PubKeySize; + ret = InitParamSet(&genCallerKeyParamSet, g_genCallerX25519Params, + sizeof(g_genCallerX25519Params) / sizeof(OH_Huks_Param)); + if (ret.errorCode != OH_HUKS_SUCCESS) { + break; + } + importWrappedKeyTestParams->genCallerKeyParamSet = genCallerKeyParamSet; + ret = InitParamSet(&callerImportParamsKek, g_importParamsCallerKek, + sizeof(g_importParamsCallerKek) / sizeof(OH_Huks_Param)); + if (ret.errorCode != OH_HUKS_SUCCESS) { + break; + } + importWrappedKeyTestParams->importCallerKekParamSet = callerImportParamsKek; + ret = InitParamSet(&agreeParamSet, g_callerAgreeParams, sizeof(g_callerAgreeParams) / sizeof(OH_Huks_Param)); + if (ret.errorCode != OH_HUKS_SUCCESS) { + break; + } + importWrappedKeyTestParams->agreeParamSet = agreeParamSet; + ret = InitParamSet(&importPlainKeyParams, importedKeyParamSetArray, arraySize); + if (ret.errorCode != OH_HUKS_SUCCESS) { + break; + } + importWrappedKeyTestParams->importWrappedKeyParamSet = importPlainKeyParams; + ret = HksImportWrappedKeyTestCommonCase(importWrappedKeyTestParams); + } while (0); + OH_Huks_FreeParamSet(&genX25519KeyParamSet); + OH_Huks_FreeParamSet(&genCallerKeyParamSet); + OH_Huks_FreeParamSet(&callerImportParamsKek); + OH_Huks_FreeParamSet(&agreeParamSet); + OH_Huks_FreeParamSet(&importPlainKeyParams); + return ret; +} +static napi_value NAPI_Global_importWrappedKey(napi_env env, napi_callback_info info) +{ + struct HksImportWrappedKeyTestParams importWrappedKeyTestParams001 = {0}; + importWrappedKeyTestParams001.wrappingKeyAlias = &g_wrappingKeyAliasAes256; + importWrappedKeyTestParams001.keyMaterialLen = g_importedAes256PlainKey.size; + importWrappedKeyTestParams001.callerKeyAlias = &g_callerKeyAliasAes256; + importWrappedKeyTestParams001.callerKekAlias = &g_callerKekAliasAes256; + importWrappedKeyTestParams001.callerKek = &g_callerAes256Kek; + importWrappedKeyTestParams001.callerAgreeKeyAlias = &g_callerAgreeKeyAliasAes256; + importWrappedKeyTestParams001.importedKeyAlias = &g_importedKeyAliasAes256; + importWrappedKeyTestParams001.importedPlainKey = &g_importedAes256PlainKey; + OH_Huks_Result ohResult = + InitCommonTestParamsAndDoImport(&importWrappedKeyTestParams001, g_importWrappedAes256Params, + sizeof(g_importWrappedAes256Params) / sizeof(struct OH_Huks_Param)); + HksClearKeysForWrappedKeyTest(&importWrappedKeyTestParams001); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +static napi_value IsKeyExist(napi_env env, napi_callback_info info) +{ + /* 1.指定密钥别名 */ + struct OH_Huks_Blob keyAlias = { + (uint32_t)strlen("test_key"), + (uint8_t *)"test_key" + }; + + /* 2.调用OH_Huks_IsKeyItemExist判断密钥是否存在 */ + struct OH_Huks_Result ohResult = OH_Huks_IsKeyItemExist(&keyAlias, NULL); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"isKeyExist", nullptr, IsKeyExist, nullptr, nullptr, nullptr, napi_default, nullptr }, + {"importWrappedKey", nullptr, NAPI_Global_importWrappedKey, 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index c753ec3dc01d860c3380ffce9175f3831a7e4a24..e8fa214af4c18f95f777db9dc895130efeef7322 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export const importWrappedKey: () => number; +/* + * 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 importWrappedKey: () => number; export const isKeyExist: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/oh-package.json5 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c 100644 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/ImportEncryptedKey.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/ImportEncryptedKey.ets old mode 100755 new mode 100644 index 4a550cec4c2a0953f65d4286cc92444a37691eba..0eb6e3fc8d6be9d3217b131c219a04be694f4259 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/ImportEncryptedKey.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/ImportEncryptedKey.ets @@ -1,655 +1,655 @@ -/* - * 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 { huks } from '@kit.UniversalKeystoreKit'; - -let IV = '0000000000000000'; -let AAD = 'abababababababab'; -let NONCE = 'hahahahahaha'; -let TAG_SIZE = 16; -let FILED_LENGTH = 4; -let importedAes192PlainKey = 'The aes192 key to import'; -let callerAes256Kek = 'The is kek to encrypt aes192 key'; -let callerKeyAlias = 'test_caller_key_ecdh_aes192'; -let callerKekAliasAes256 = 'test_caller_kek_ecdh_aes256'; -let callerAgreeKeyAliasAes256 = 'test_caller_agree_key_ecdh_aes256'; -let importedKeyAliasAes192 = 'test_import_key_ecdh_aes192'; -let huksPubKey: Uint8Array; -let callerSelfPublicKey: Uint8Array; -let outSharedKey: Uint8Array; -let outPlainKeyEncData: Uint8Array; -let outKekEncData: Uint8Array; -let outKekEncTag: Uint8Array; -let outAgreeKeyEncTag: Uint8Array; -let mask = [0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000]; - -function subUint8ArrayOf(arrayBuf: Uint8Array, start: number, end: number) { - let arr: number[] = []; - for (let i = start; i < end && i < arrayBuf.length; ++i) { - arr.push(arrayBuf[i]); - } - return new Uint8Array(arr); -} - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function assignLength(length: number, arrayBuf: Uint8Array, startIndex: number) { - let index = startIndex; - for (let i = 0; i < 4; i++) { - arrayBuf[index++] = (length & mask[i]) >> (i * 8); - } - return 4; -} - -function assignData(data: Uint8Array, arrayBuf: Uint8Array, startIndex: number) { - let index = startIndex; - for (let i = 0; i < data.length; i++) { - arrayBuf[index++] = data[i]; - } - return data.length; -} - -let genWrappingKeyParams: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_ECC - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_UNWRAP - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - } - ] -} - -let genCallerEcdhParams: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_ECC - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 - } - ] -} - -let importParamsCallerKek: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_GCM - }, - { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV) - } - ], - inData: stringToUint8Array(callerAes256Kek) -} - -let importParamsAgreeKey: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_GCM - }, - { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV) - } - ], -} - -let callerAgreeParams: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_ECDH - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 - } - ] -} - -let encryptKeyCommonParams: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_GCM - }, - { - tag: huks.HuksTag.HUKS_TAG_NONCE, - value: stringToUint8Array(NONCE) - }, - { - tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, - value: stringToUint8Array(AAD) - } - ], -} - -let importWrappedAes192Params: huks.HuksOptions = { - properties: [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_192 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC - }, - { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE - }, - { - tag: huks.HuksTag.HUKS_TAG_UNWRAP_ALGORITHM_SUITE, - value: huks.HuksUnwrapSuite.HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING - }, - { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV) - } - ] -} - -async function publicGenerateItemFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - try { - await huks.generateKeyItem(keyAlias, huksOptions) - .then(data => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((err: Error) => { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(err)}`); - throw (err as Error); - }) - } catch (err) { - console.error(`promise: generateKeyItem invalid, ${JSON.stringify(err)}`); - throw (err as Error); - } -} - -async function publicImportKeyItemFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise importKeyItem`); - try { - await huks.importKeyItem(keyAlias, huksOptions) - .then(data => { - console.info(`promise: importKeyItem success, data = ${JSON.stringify(data)}`); - }).catch((err: Error) => { - console.error(`promise: importKeyItem failed, ${JSON.stringify(err)}`); - throw (err as Error); - }) - } catch (err) { - console.error(`promise: importKeyItem input arg invalid, ${JSON.stringify(err)}`); - throw (err as Error); - } -} - -async function publicDeleteKeyItemFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise deleteKeyItem`); - try { - await huks.deleteKeyItem(keyAlias, huksOptions) - .then(data => { - console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); - }) - .catch((err: Error) => { - console.error(`promise: deleteKeyItem failed, ${JSON.stringify(err)}`); - throw (err as Error); - }) - } catch (err) { - console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(err)}`); - throw (err as Error); - } -} - -function importWrappedKeyItem(keyAlias: string, wrappingKeyAlias: string, huksOptions: huks.HuksOptions) { - return new Promise((resolve, reject) => { - try { - huks.importWrappedKeyItem(keyAlias, wrappingKeyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throw (error as Error); - } - }); -} - -async function publicImportWrappedKeyFunc(keyAlias: string, wrappingKeyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise importWrappedKeyItem`); - for (let i = 0; i < huksOptions.inData!.length; i++) { - console.error(`${i}: ${huksOptions.inData![i]}`); - } - try { - await importWrappedKeyItem(keyAlias, wrappingKeyAlias, huksOptions) - .then((data) => { - console.info(`promise: importWrappedKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: importWrappedKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: importWrappedKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -async function publicImportWrappedKeyPromise(keyAlias: string, wrappingKeyAlias: string, - huksOptions: huks.HuksOptions) { - console.info(`enter promise importWrappedKeyItem`); - try { - await huks.importWrappedKeyItem(keyAlias, wrappingKeyAlias, huksOptions) - .then((data) => { - console.info(`promise: importWrappedKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: importWrappedKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: importWrappedKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -async function publicInitFunc(srcKeyAlias: string, huksOptions: huks.HuksOptions) { - let handle: number = 0; - console.info(`enter promise doInit`); - try { - await huks.initSession(srcKeyAlias, huksOptions) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - handle = data.handle; - }) - .catch((error: Error) => { - console.error(`promise: doInit key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } - return handle; -} - -async function publicUpdateSessionFunction(handle: number, huksOptions: huks.HuksOptions) { - const maxUpdateSize = 64; - const inData = huksOptions.inData!; - const lastInDataPosition = inData.length - 1; - let inDataSegSize = maxUpdateSize; - let inDataSegPosition = 0; - let isFinished = false; - let outData: number[] = []; - - while (inDataSegPosition <= lastInDataPosition) { - if (inDataSegPosition + maxUpdateSize > lastInDataPosition) { - isFinished = true; - inDataSegSize = lastInDataPosition - inDataSegPosition + 1; - console.info(`enter promise doUpdate`); - break; - } - huksOptions.inData = new Uint8Array( - Array.from(inData).slice(inDataSegPosition, inDataSegPosition + inDataSegSize) - ); - console.info(`enter promise doUpdate`); - try { - await huks.updateSession(handle, huksOptions) - .then((data) => { - console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - outData = outData.concat(Array.from(data.outData!)); - }) - .catch((error: Error) => { - console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } - if ((!isFinished) && (inDataSegPosition + maxUpdateSize > lastInDataPosition)) { - console.error(`update size invalid isFinished = ${isFinished}`); - console.error(`inDataSegPosition = ${inDataSegPosition}`); - console.error(`lastInDataPosition = ${lastInDataPosition}`); - return; - } - inDataSegPosition += maxUpdateSize; - } - return outData; -} - -async function publicFinishSession(handle: number, huksOptions: huks.HuksOptions, inData: number[]) { - let outData: number[] = []; - console.info(`enter promise doFinish`); - try { - await huks.finishSession(handle, huksOptions) - .then((data) => { - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - outData = inData.concat(Array.from(data.outData!)); - }) - .catch((error: Error) => { - console.error(`promise: doFinish key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } - return new Uint8Array(outData); -} - -async function cipherFunction(keyAlias: string, huksOptions: huks.HuksOptions) { - let handle = await publicInitFunc(keyAlias, huksOptions); - let tmpData = await publicUpdateSessionFunction(handle, huksOptions); - let outData = await publicFinishSession(handle, huksOptions, tmpData!); - return outData; -} - -async function agreeFunction(keyAlias: string, huksOptions: huks.HuksOptions, huksPublicKey: Uint8Array) { - let handle = await publicInitFunc(keyAlias, huksOptions); - let outSharedKey: Uint8Array = new Uint8Array; - huksOptions.inData = huksPublicKey; - console.info(`enter promise doUpdate`); - try { - await huks.updateSession(handle, huksOptions) - .then((data) => { - console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } - console.info(`enter promise doInit`); - try { - await huks.finishSession(handle, huksOptions) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - outSharedKey = data.outData as Uint8Array; - }) - .catch((error: Error) => { - console.error(`promise: doInit key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } - return outSharedKey; -} - -async function importKekAndAgreeSharedSecret(callerKekAlias: string, importKekParams: huks.HuksOptions, - callerKeyAlias: string, huksPublicKey: Uint8Array, agreeParams: huks.HuksOptions) { - await publicImportKeyItemFunc(callerKekAlias, importKekParams); - outSharedKey = await agreeFunction(callerKeyAlias, agreeParams, huksPublicKey); - importParamsAgreeKey.inData = outSharedKey; - await publicImportKeyItemFunc(callerAgreeKeyAliasAes256, importParamsAgreeKey); -} - -async function generateAndExportPublicKey(keyAlias: string, huksOptions: huks.HuksOptions, caller: Boolean) { - await publicGenerateItemFunc(keyAlias, huksOptions); - try { - await huks.exportKeyItem(keyAlias, huksOptions) - .then((data) => { - console.info(`promise: exportKeyItem success, data = ${JSON.stringify(data)}`); - if (caller) { - callerSelfPublicKey = data.outData as Uint8Array; - } else { - huksPubKey = data.outData as Uint8Array; - } - }) - .catch((error: Error) => { - console.error(`promise: exportKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - }); - } catch (error) { - console.error(`promise: generate pubKey failed, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -async function encryptImportedPlainKeyAndKek(keyAlias: string) { - encryptKeyCommonParams.inData = stringToUint8Array(keyAlias) - let plainKeyEncData = await cipherFunction(callerKekAliasAes256, encryptKeyCommonParams); - outKekEncTag = subUint8ArrayOf(plainKeyEncData, plainKeyEncData.length - TAG_SIZE, plainKeyEncData.length) - outPlainKeyEncData = subUint8ArrayOf(plainKeyEncData, 0, plainKeyEncData.length - TAG_SIZE) - encryptKeyCommonParams.inData = stringToUint8Array(callerAes256Kek) - let kekEncData = await cipherFunction(callerAgreeKeyAliasAes256, encryptKeyCommonParams) - outAgreeKeyEncTag = subUint8ArrayOf(kekEncData, kekEncData.length - TAG_SIZE, kekEncData.length) - outKekEncData = subUint8ArrayOf(kekEncData, 0, kekEncData.length - TAG_SIZE) -} - -async function buildWrappedDataAndImportWrappedKey(plainKey: string) { - let plainKeySizeBuff = new Uint8Array(4); - assignLength(plainKey.length, plainKeySizeBuff, 0); - let wrappedData = new Uint8Array( - FILED_LENGTH + huksPubKey.length + - FILED_LENGTH + AAD.length + - FILED_LENGTH + NONCE.length + - FILED_LENGTH + TAG_SIZE + - FILED_LENGTH + outKekEncData.length + - FILED_LENGTH + AAD.length + - FILED_LENGTH + NONCE.length + - FILED_LENGTH + TAG_SIZE + - FILED_LENGTH + plainKeySizeBuff.length + - FILED_LENGTH + outPlainKeyEncData.length - ); - let index = 0; - let aadUint8Array = stringToUint8Array(AAD); - let nonceArray = stringToUint8Array(NONCE); - index += assignLength(callerSelfPublicKey.length, wrappedData, index); // 4 - index += assignData(callerSelfPublicKey, wrappedData, index); // 91 - index += assignLength(aadUint8Array.length, wrappedData, index); // 4 - index += assignData(aadUint8Array, wrappedData, index); // 16 - index += assignLength(nonceArray.length, wrappedData, index); // 4 - index += assignData(nonceArray, wrappedData, index); // 12 - index += assignLength(outAgreeKeyEncTag.length, wrappedData, index); // 4 - index += assignData(outAgreeKeyEncTag, wrappedData, index); // 16 - index += assignLength(outKekEncData.length, wrappedData, index); // 4 - index += assignData(outKekEncData, wrappedData, index); // 32 - index += assignLength(aadUint8Array.length, wrappedData, index); // 4 - index += assignData(aadUint8Array, wrappedData, index); // 16 - index += assignLength(nonceArray.length, wrappedData, index); // 4 - index += assignData(nonceArray, wrappedData, index); // 12 - index += assignLength(outKekEncTag.length, wrappedData, index); // 4 - index += assignData(outKekEncTag, wrappedData, index); // 16 - index += assignLength(plainKeySizeBuff.length, wrappedData, index); // 4 - index += assignData(plainKeySizeBuff, wrappedData, index); // 4 - index += assignLength(outPlainKeyEncData.length, wrappedData, index); // 4 - index += assignData(outPlainKeyEncData, wrappedData, index); // 24 - return wrappedData; -} - -/* 模拟加密导入密钥场景,设备A为远端设备(导入设备),设备B为本端设备(被导入设备) */ -async function ImportWrappedKey() { - /** - * 1.设备A将待导入密钥转换成HUKS密钥材料格式To_Import_Key(仅针对非对称密钥,若待导入密钥是对称密钥则可省略此步骤), - * 本示例使用importedAes256PlainKey(对称密钥)作为模拟 - */ - - /* 2.设备B生成一个加密导入用途的、用于协商的非对称密钥对Wrapping_Key(公钥Wrapping_Pk,私钥Wrapping_Sk), - * 其密钥用途设置为unwrap,导出Wrapping_Key公钥Wrapping_Pk存放在变量huksPubKey中 - */ - const srcKeyAliasWrap = 'HUKS_Basic_Capability_Import_0200'; - await generateAndExportPublicKey(srcKeyAliasWrap, genWrappingKeyParams, false); - - /* 3.设备A使用和设备B同样的算法,生成一个加密导入用途的、用于协商的非对称密钥对Caller_Key(公钥Caller_Pk,私钥Caller_Sk), - * 导出Caller_Key公钥Caller_Pk存放在变量callerSelfPublicKey中 - */ - await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true); - - /** - * 4.设备A生成一个对称密钥Caller_Kek,该密钥后续将用于加密To_Import_Key - * 5.设备A基于Caller_Key的私钥Caller_Sk和Wrapping_Key的公钥Wrapping_Pk,协商出Shared_Key - */ - await importKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, - callerAgreeParams); - - /** - * 6.设备A使用Caller_Kek加密To_Import_Key,生成To_Import_Key_Enc - * 7.设备A使用Shared_Key加密Caller_Kek,生成Caller_Kek_Enc - */ - await encryptImportedPlainKeyAndKek(importedAes192PlainKey); - - /* 8.设备A封装Caller_Pk、To_Import_Key_Enc、Caller_Kek_Enc等加密导入的材料并发送给设备B。 - 本示例作为变量存放在callerSelfPublicKey,PlainKeyEncData,KekEncData */ - let wrappedData = await buildWrappedDataAndImportWrappedKey(importedAes192PlainKey); - importWrappedAes192Params.inData = wrappedData; - - /* 9.设备B导入封装的加密密钥材料 */ - await publicImportWrappedKeyFunc(importedKeyAliasAes192, srcKeyAliasWrap, importWrappedAes192Params); - - /* 10.设备A、B删除用于加密导入的密钥 */ - await publicDeleteKeyItemFunc(srcKeyAliasWrap, genWrappingKeyParams); - await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams); - await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192Params); - await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams); -} - -/* - * 确定密钥别名和封装密钥属性参数集 - */ -let keyAlias = 'test_import_key_ecdh_aes192'; -let isKeyExist: Boolean; -let keyProperties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES, -}]; -let huksOptions: huks.HuksOptions = { - properties: keyProperties, // 非空填充 - inData: new Uint8Array([]) // 非空填充 -} - -function Check() { - try { - huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { - if (error) { - console.error(`callback: isKeyItemExist failed, ${JSON.stringify(error)}`); - } else { - if (data !== null && data.valueOf() !== null) { - isKeyExist = data.valueOf(); - console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); - } - } - }); - } catch (error) { - console.error(`callback: isKeyItemExist input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -export { ImportWrappedKey, Check }; +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; + +let IV = '0000000000000000'; +let AAD = 'abababababababab'; +let NONCE = 'hahahahahaha'; +let TAG_SIZE = 16; +let FILED_LENGTH = 4; +let importedAes192PlainKey = 'The aes192 key to import'; +let callerAes256Kek = 'The is kek to encrypt aes192 key'; +let callerKeyAlias = 'test_caller_key_ecdh_aes192'; +let callerKekAliasAes256 = 'test_caller_kek_ecdh_aes256'; +let callerAgreeKeyAliasAes256 = 'test_caller_agree_key_ecdh_aes256'; +let importedKeyAliasAes192 = 'test_import_key_ecdh_aes192'; +let huksPubKey: Uint8Array; +let callerSelfPublicKey: Uint8Array; +let outSharedKey: Uint8Array; +let outPlainKeyEncData: Uint8Array; +let outKekEncData: Uint8Array; +let outKekEncTag: Uint8Array; +let outAgreeKeyEncTag: Uint8Array; +let mask = [0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000]; + +function subUint8ArrayOf(arrayBuf: Uint8Array, start: number, end: number) { + let arr: number[] = []; + for (let i = start; i < end && i < arrayBuf.length; ++i) { + arr.push(arrayBuf[i]); + } + return new Uint8Array(arr); +} + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function assignLength(length: number, arrayBuf: Uint8Array, startIndex: number) { + let index = startIndex; + for (let i = 0; i < 4; i++) { + arrayBuf[index++] = (length & mask[i]) >> (i * 8); + } + return 4; +} + +function assignData(data: Uint8Array, arrayBuf: Uint8Array, startIndex: number) { + let index = startIndex; + for (let i = 0; i < data.length; i++) { + arrayBuf[index++] = data[i]; + } + return data.length; +} + +let genWrappingKeyParams: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_ECC + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_UNWRAP + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + } + ] +} + +let genCallerEcdhParams: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_ECC + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 + } + ] +} + +let importParamsCallerKek: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_GCM + }, + { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ], + inData: stringToUint8Array(callerAes256Kek) +} + +let importParamsAgreeKey: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_GCM + }, + { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ], +} + +let callerAgreeParams: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_ECDH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 + } + ] +} + +let encryptKeyCommonParams: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_GCM + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + } + ], +} + +let importWrappedAes192Params: huks.HuksOptions = { + properties: [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_192 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC + }, + { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE + }, + { + tag: huks.HuksTag.HUKS_TAG_UNWRAP_ALGORITHM_SUITE, + value: huks.HuksUnwrapSuite.HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING + }, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ] +} + +async function publicGenerateItemFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + try { + await huks.generateKeyItem(keyAlias, huksOptions) + .then(data => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((err: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(err)}`); + throw (err as Error); + }) + } catch (err) { + console.error(`promise: generateKeyItem invalid, ${JSON.stringify(err)}`); + throw (err as Error); + } +} + +async function publicImportKeyItemFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise importKeyItem`); + try { + await huks.importKeyItem(keyAlias, huksOptions) + .then(data => { + console.info(`promise: importKeyItem success, data = ${JSON.stringify(data)}`); + }).catch((err: Error) => { + console.error(`promise: importKeyItem failed, ${JSON.stringify(err)}`); + throw (err as Error); + }) + } catch (err) { + console.error(`promise: importKeyItem input arg invalid, ${JSON.stringify(err)}`); + throw (err as Error); + } +} + +async function publicDeleteKeyItemFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise deleteKeyItem`); + try { + await huks.deleteKeyItem(keyAlias, huksOptions) + .then(data => { + console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + }) + .catch((err: Error) => { + console.error(`promise: deleteKeyItem failed, ${JSON.stringify(err)}`); + throw (err as Error); + }) + } catch (err) { + console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(err)}`); + throw (err as Error); + } +} + +function importWrappedKeyItem(keyAlias: string, wrappingKeyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.importWrappedKeyItem(keyAlias, wrappingKeyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicImportWrappedKeyFunc(keyAlias: string, wrappingKeyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise importWrappedKeyItem`); + for (let i = 0; i < huksOptions.inData!.length; i++) { + console.error(`${i}: ${huksOptions.inData![i]}`); + } + try { + await importWrappedKeyItem(keyAlias, wrappingKeyAlias, huksOptions) + .then((data) => { + console.info(`promise: importWrappedKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: importWrappedKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: importWrappedKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +async function publicImportWrappedKeyPromise(keyAlias: string, wrappingKeyAlias: string, + huksOptions: huks.HuksOptions) { + console.info(`enter promise importWrappedKeyItem`); + try { + await huks.importWrappedKeyItem(keyAlias, wrappingKeyAlias, huksOptions) + .then((data) => { + console.info(`promise: importWrappedKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: importWrappedKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: importWrappedKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +async function publicInitFunc(srcKeyAlias: string, huksOptions: huks.HuksOptions) { + let handle: number = 0; + console.info(`enter promise doInit`); + try { + await huks.initSession(srcKeyAlias, huksOptions) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + }) + .catch((error: Error) => { + console.error(`promise: doInit key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } + return handle; +} + +async function publicUpdateSessionFunction(handle: number, huksOptions: huks.HuksOptions) { + const maxUpdateSize = 64; + const inData = huksOptions.inData!; + const lastInDataPosition = inData.length - 1; + let inDataSegSize = maxUpdateSize; + let inDataSegPosition = 0; + let isFinished = false; + let outData: number[] = []; + + while (inDataSegPosition <= lastInDataPosition) { + if (inDataSegPosition + maxUpdateSize > lastInDataPosition) { + isFinished = true; + inDataSegSize = lastInDataPosition - inDataSegPosition + 1; + console.info(`enter promise doUpdate`); + break; + } + huksOptions.inData = new Uint8Array( + Array.from(inData).slice(inDataSegPosition, inDataSegPosition + inDataSegSize) + ); + console.info(`enter promise doUpdate`); + try { + await huks.updateSession(handle, huksOptions) + .then((data) => { + console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + outData = outData.concat(Array.from(data.outData!)); + }) + .catch((error: Error) => { + console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } + if ((!isFinished) && (inDataSegPosition + maxUpdateSize > lastInDataPosition)) { + console.error(`update size invalid isFinished = ${isFinished}`); + console.error(`inDataSegPosition = ${inDataSegPosition}`); + console.error(`lastInDataPosition = ${lastInDataPosition}`); + return; + } + inDataSegPosition += maxUpdateSize; + } + return outData; +} + +async function publicFinishSession(handle: number, huksOptions: huks.HuksOptions, inData: number[]) { + let outData: number[] = []; + console.info(`enter promise doFinish`); + try { + await huks.finishSession(handle, huksOptions) + .then((data) => { + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + outData = inData.concat(Array.from(data.outData!)); + }) + .catch((error: Error) => { + console.error(`promise: doFinish key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } + return new Uint8Array(outData); +} + +async function cipherFunction(keyAlias: string, huksOptions: huks.HuksOptions) { + let handle = await publicInitFunc(keyAlias, huksOptions); + let tmpData = await publicUpdateSessionFunction(handle, huksOptions); + let outData = await publicFinishSession(handle, huksOptions, tmpData!); + return outData; +} + +async function agreeFunction(keyAlias: string, huksOptions: huks.HuksOptions, huksPublicKey: Uint8Array) { + let handle = await publicInitFunc(keyAlias, huksOptions); + let outSharedKey: Uint8Array = new Uint8Array; + huksOptions.inData = huksPublicKey; + console.info(`enter promise doUpdate`); + try { + await huks.updateSession(handle, huksOptions) + .then((data) => { + console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } + console.info(`enter promise doInit`); + try { + await huks.finishSession(handle, huksOptions) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + outSharedKey = data.outData as Uint8Array; + }) + .catch((error: Error) => { + console.error(`promise: doInit key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } + return outSharedKey; +} + +async function importKekAndAgreeSharedSecret(callerKekAlias: string, importKekParams: huks.HuksOptions, + callerKeyAlias: string, huksPublicKey: Uint8Array, agreeParams: huks.HuksOptions) { + await publicImportKeyItemFunc(callerKekAlias, importKekParams); + outSharedKey = await agreeFunction(callerKeyAlias, agreeParams, huksPublicKey); + importParamsAgreeKey.inData = outSharedKey; + await publicImportKeyItemFunc(callerAgreeKeyAliasAes256, importParamsAgreeKey); +} + +async function generateAndExportPublicKey(keyAlias: string, huksOptions: huks.HuksOptions, caller: Boolean) { + await publicGenerateItemFunc(keyAlias, huksOptions); + try { + await huks.exportKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: exportKeyItem success, data = ${JSON.stringify(data)}`); + if (caller) { + callerSelfPublicKey = data.outData as Uint8Array; + } else { + huksPubKey = data.outData as Uint8Array; + } + }) + .catch((error: Error) => { + console.error(`promise: exportKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + }); + } catch (error) { + console.error(`promise: generate pubKey failed, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +async function encryptImportedPlainKeyAndKek(keyAlias: string) { + encryptKeyCommonParams.inData = stringToUint8Array(keyAlias) + let plainKeyEncData = await cipherFunction(callerKekAliasAes256, encryptKeyCommonParams); + outKekEncTag = subUint8ArrayOf(plainKeyEncData, plainKeyEncData.length - TAG_SIZE, plainKeyEncData.length) + outPlainKeyEncData = subUint8ArrayOf(plainKeyEncData, 0, plainKeyEncData.length - TAG_SIZE) + encryptKeyCommonParams.inData = stringToUint8Array(callerAes256Kek) + let kekEncData = await cipherFunction(callerAgreeKeyAliasAes256, encryptKeyCommonParams) + outAgreeKeyEncTag = subUint8ArrayOf(kekEncData, kekEncData.length - TAG_SIZE, kekEncData.length) + outKekEncData = subUint8ArrayOf(kekEncData, 0, kekEncData.length - TAG_SIZE) +} + +async function buildWrappedDataAndImportWrappedKey(plainKey: string) { + let plainKeySizeBuff = new Uint8Array(4); + assignLength(plainKey.length, plainKeySizeBuff, 0); + let wrappedData = new Uint8Array( + FILED_LENGTH + huksPubKey.length + + FILED_LENGTH + AAD.length + + FILED_LENGTH + NONCE.length + + FILED_LENGTH + TAG_SIZE + + FILED_LENGTH + outKekEncData.length + + FILED_LENGTH + AAD.length + + FILED_LENGTH + NONCE.length + + FILED_LENGTH + TAG_SIZE + + FILED_LENGTH + plainKeySizeBuff.length + + FILED_LENGTH + outPlainKeyEncData.length + ); + let index = 0; + let aadUint8Array = stringToUint8Array(AAD); + let nonceArray = stringToUint8Array(NONCE); + index += assignLength(callerSelfPublicKey.length, wrappedData, index); // 4 + index += assignData(callerSelfPublicKey, wrappedData, index); // 91 + index += assignLength(aadUint8Array.length, wrappedData, index); // 4 + index += assignData(aadUint8Array, wrappedData, index); // 16 + index += assignLength(nonceArray.length, wrappedData, index); // 4 + index += assignData(nonceArray, wrappedData, index); // 12 + index += assignLength(outAgreeKeyEncTag.length, wrappedData, index); // 4 + index += assignData(outAgreeKeyEncTag, wrappedData, index); // 16 + index += assignLength(outKekEncData.length, wrappedData, index); // 4 + index += assignData(outKekEncData, wrappedData, index); // 32 + index += assignLength(aadUint8Array.length, wrappedData, index); // 4 + index += assignData(aadUint8Array, wrappedData, index); // 16 + index += assignLength(nonceArray.length, wrappedData, index); // 4 + index += assignData(nonceArray, wrappedData, index); // 12 + index += assignLength(outKekEncTag.length, wrappedData, index); // 4 + index += assignData(outKekEncTag, wrappedData, index); // 16 + index += assignLength(plainKeySizeBuff.length, wrappedData, index); // 4 + index += assignData(plainKeySizeBuff, wrappedData, index); // 4 + index += assignLength(outPlainKeyEncData.length, wrappedData, index); // 4 + index += assignData(outPlainKeyEncData, wrappedData, index); // 24 + return wrappedData; +} + +/* 模拟加密导入密钥场景,设备A为远端设备(导入设备),设备B为本端设备(被导入设备) */ +async function ImportWrappedKey() { + /** + * 1.设备A将待导入密钥转换成HUKS密钥材料格式To_Import_Key(仅针对非对称密钥,若待导入密钥是对称密钥则可省略此步骤), + * 本示例使用importedAes256PlainKey(对称密钥)作为模拟 + */ + + /* 2.设备B生成一个加密导入用途的、用于协商的非对称密钥对Wrapping_Key(公钥Wrapping_Pk,私钥Wrapping_Sk), + * 其密钥用途设置为unwrap,导出Wrapping_Key公钥Wrapping_Pk存放在变量huksPubKey中 + */ + const srcKeyAliasWrap = 'HUKS_Basic_Capability_Import_0200'; + await generateAndExportPublicKey(srcKeyAliasWrap, genWrappingKeyParams, false); + + /* 3.设备A使用和设备B同样的算法,生成一个加密导入用途的、用于协商的非对称密钥对Caller_Key(公钥Caller_Pk,私钥Caller_Sk), + * 导出Caller_Key公钥Caller_Pk存放在变量callerSelfPublicKey中 + */ + await generateAndExportPublicKey(callerKeyAlias, genCallerEcdhParams, true); + + /** + * 4.设备A生成一个对称密钥Caller_Kek,该密钥后续将用于加密To_Import_Key + * 5.设备A基于Caller_Key的私钥Caller_Sk和Wrapping_Key的公钥Wrapping_Pk,协商出Shared_Key + */ + await importKekAndAgreeSharedSecret(callerKekAliasAes256, importParamsCallerKek, callerKeyAlias, huksPubKey, + callerAgreeParams); + + /** + * 6.设备A使用Caller_Kek加密To_Import_Key,生成To_Import_Key_Enc + * 7.设备A使用Shared_Key加密Caller_Kek,生成Caller_Kek_Enc + */ + await encryptImportedPlainKeyAndKek(importedAes192PlainKey); + + /* 8.设备A封装Caller_Pk、To_Import_Key_Enc、Caller_Kek_Enc等加密导入的材料并发送给设备B。 + 本示例作为变量存放在callerSelfPublicKey,PlainKeyEncData,KekEncData */ + let wrappedData = await buildWrappedDataAndImportWrappedKey(importedAes192PlainKey); + importWrappedAes192Params.inData = wrappedData; + + /* 9.设备B导入封装的加密密钥材料 */ + await publicImportWrappedKeyFunc(importedKeyAliasAes192, srcKeyAliasWrap, importWrappedAes192Params); + + /* 10.设备A、B删除用于加密导入的密钥 */ + await publicDeleteKeyItemFunc(srcKeyAliasWrap, genWrappingKeyParams); + await publicDeleteKeyItemFunc(callerKeyAlias, genCallerEcdhParams); + await publicDeleteKeyItemFunc(importedKeyAliasAes192, importWrappedAes192Params); + await publicDeleteKeyItemFunc(callerKekAliasAes256, callerAgreeParams); +} + +/* + * 确定密钥别名和封装密钥属性参数集 + */ +let keyAlias = 'test_import_key_ecdh_aes192'; +let isKeyExist: Boolean; +let keyProperties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES, +}]; +let huksOptions: huks.HuksOptions = { + properties: keyProperties, // 非空填充 + inData: new Uint8Array([]) // 非空填充 +} + +function Check() { + try { + huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { + if (error) { + console.error(`callback: isKeyItemExist failed, ${JSON.stringify(error)}`); + } else { + if (data !== null && data.valueOf() !== null) { + isKeyExist = data.valueOf(); + console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); + } + } + }); + } catch (error) { + console.error(`callback: isKeyItemExist input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +export { ImportWrappedKey, Check }; diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index d6143ff61353fd4d0098111b7aae0ff2194cdd8f..5f77599495377ba5976cf2f3bf06188464abf5a4 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/ets/pages/Index.ets @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Check, ImportWrappedKey } from './ImportEncryptedKey'; -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'ImportEncryptedKey'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_arkts')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await ImportWrappedKey(); - Check(); - this.message = 'Call ArkTS Result: Success'; - } catch (error) { - this.message = 'Call ArkTS Result: Failed'; - } - }) - Button($r('app.string.call_cpp')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - let ret: number = testNapi.importWrappedKey(); - this.message = 'Call C/C++ Result: ' + ret.toString(); - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { Check, ImportWrappedKey } from './ImportEncryptedKey'; +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'ImportEncryptedKey'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_arkts')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await ImportWrappedKey(); + Check(); + this.message = 'Call ArkTS Result: Success'; + } catch (error) { + this.message = 'Call ArkTS Result: Failed'; + } + }) + Button($r('app.string.call_cpp')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + let ret: number = testNapi.importWrappedKey(); + this.message = 'Call C/C++ Result: ' + ret.toString(); + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 index 9d4f8a434d863461a900661b39dc7ac9808997e2..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/ImportEncryptedKey.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/ImportEncryptedKey.test.ets old mode 100755 new mode 100644 index 5ea2be8b7b913396820f8cb1c30457048cc162a8..3d6850fe65b37cdbd6ec2ca961800b8acb35060e --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/ImportEncryptedKey.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/ImportEncryptedKey.test.ets @@ -1,74 +1,74 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function hMACTest() { - describe('importEncryptedKeyTest', () => { - - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,ImportEncryptedKey(ArkTS) - */ - it('testImportEncryptedKey001', 0, async () => { - console.info('uitest: testImportEncryptedKey001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call ArkTS')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call ArkTS Result: Success')); - console.info('uitest: testImportEncryptedKey001 end'); - }) - - /** - * 点击按钮,ImportEncryptedKey(C/C++) - */ - it('testImportEncryptedKey002', 0, async () => { - console.info('uitest: testImportEncryptedKey002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testImportEncryptedKey002 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function hMACTest() { + describe('importEncryptedKeyTest', () => { + + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,ImportEncryptedKey(ArkTS) + */ + it('testImportEncryptedKey001', 0, async () => { + console.info('uitest: testImportEncryptedKey001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call ArkTS')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call ArkTS Result: Success')); + console.info('uitest: testImportEncryptedKey001 end'); + }) + + /** + * 点击按钮,ImportEncryptedKey(C/C++) + */ + it('testImportEncryptedKey002', 0, async () => { + console.info('uitest: testImportEncryptedKey002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testImportEncryptedKey002 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 index ddb5fc75520bdfceaeb8c4cf112bfe546f481065..894688fbdfa33cad33c3da1c1254b5aace0d7640 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +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 importEncryptedKeyTest from './ImportEncryptedKey.test'; - -export default function testsuite() { - importEncryptedKeyTest(); -} +/* + * 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 importEncryptedKeyTest from './ImportEncryptedKey.test'; + +export default function testsuite() { + importEncryptedKeyTest(); +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigorfile.ts old mode 100755 new mode 100644 index 2db60fa91881f6961e5def61af680301d22a1341..2a5e543f190732c159beb574dfc9fa37bc94e156 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigorfile.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/hvigorfile.ts @@ -1,21 +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. */ -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/ohosTest.md old mode 100755 new mode 100644 index 20cc8ebe07d2df58f464acdab19f493a200f5d4c..6fafce2eb98df20c79c45d496ae985f52e48ddf4 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportEncryptedKey/ohosTest.md @@ -1,9 +1,9 @@ -# 密钥删除测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,加密导入密钥(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +# 密钥删除测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,加密导入密钥(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | | 点击按钮,加密导入密钥(C/C++) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/app.json5 old mode 100755 new mode 100644 index 2bdcd5e61962222241056ee2e796a58040542684..1ce720e3541a7c24313527278b4736e7476da920 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/app.json5 @@ -1,25 +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.importkeyplaintext", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.importkeyplaintext", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 4eb76575a5c896024eade2bb9305ed731a9507bd..2b7782e7d841d5e794f13c5396c487d0ed2663bc --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ImportKeyPlainText" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ImportKeyPlainText" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 14b058b32cbb69360cbd00a665d801152f125f4f..2b331e5591b4f371f30cc01157777be18bbfa531 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(ImportKeyPlainText) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(ImportKeyPlainText) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index a1c3e6ff08a41ac6dacc920d770308c782741061..18e90f1b4a3b414e4abcd980504ef6c2f114a7b4 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/napi_init.cpp @@ -1,99 +1,99 @@ -/* - * 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. - */ - -/* 以下以明文导入AES密钥为例 */ -#include "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -#define OH_HUKS_AES_KEY_SIZE_32 32 - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} -struct OH_Huks_Param g_testImportKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; - -static napi_value ImportKey(napi_env env, napi_callback_info info) -{ - const char *alias = "test_import"; - struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; - /* DER格式的公钥,用于后续导入密钥 */ - uint8_t pubKey[OH_HUKS_AES_KEY_SIZE_32] = {0xfb, 0x8b, 0x9f, 0x12, 0xa0, 0x83, 0x19, 0xbe, 0x6a, 0x6f, 0x63, - 0x2a, 0x7c, 0x86, 0xba, 0xca, 0x64, 0x0b, 0x88, 0x96, 0xe2, 0xfa, - 0x77, 0xbc, 0x71, 0xe3, 0x0f, 0x0f, 0x9e, 0x3c, 0xe5, 0xf9}; - struct OH_Huks_Blob publicKey = {OH_HUKS_AES_KEY_SIZE_32, pubKey}; - struct OH_Huks_ParamSet *testImportKeyParamSet = nullptr; - struct OH_Huks_Result ohResult; - do { - ohResult = InitParamSet(&testImportKeyParamSet, g_testImportKeyParam, - sizeof(g_testImportKeyParam) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 4. Import Key */ - char newKey[] = "test_import"; - struct OH_Huks_Blob newKeyAlias = {.size = (uint32_t)strlen(newKey), .data = (uint8_t *)newKey}; - ohResult = OH_Huks_ImportKeyItem(&newKeyAlias, testImportKeyParamSet, &publicKey); - } while (0); - OH_Huks_FreeParamSet(&testImportKeyParamSet); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"importKey", nullptr, ImportKey, 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); } +/* + * 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. + */ + +/* 以下以明文导入AES密钥为例 */ +#include "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +#define OH_HUKS_AES_KEY_SIZE_32 32 + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} +struct OH_Huks_Param g_testImportKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static napi_value ImportKey(napi_env env, napi_callback_info info) +{ + const char *alias = "test_import"; + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + /* DER格式的公钥,用于后续导入密钥 */ + uint8_t pubKey[OH_HUKS_AES_KEY_SIZE_32] = {0xfb, 0x8b, 0x9f, 0x12, 0xa0, 0x83, 0x19, 0xbe, 0x6a, 0x6f, 0x63, + 0x2a, 0x7c, 0x86, 0xba, 0xca, 0x64, 0x0b, 0x88, 0x96, 0xe2, 0xfa, + 0x77, 0xbc, 0x71, 0xe3, 0x0f, 0x0f, 0x9e, 0x3c, 0xe5, 0xf9}; + struct OH_Huks_Blob publicKey = {OH_HUKS_AES_KEY_SIZE_32, pubKey}; + struct OH_Huks_ParamSet *testImportKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + ohResult = InitParamSet(&testImportKeyParamSet, g_testImportKeyParam, + sizeof(g_testImportKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 4. Import Key */ + char newKey[] = "test_import"; + struct OH_Huks_Blob newKeyAlias = {.size = (uint32_t)strlen(newKey), .data = (uint8_t *)newKey}; + ohResult = OH_Huks_ImportKeyItem(&newKeyAlias, testImportKeyParamSet, &publicKey); + } while (0); + OH_Huks_FreeParamSet(&testImportKeyParamSet); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"importKey", nullptr, ImportKey, 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index fbdae5048af456ed992b885df1d9f98f3baaf9c5..d04ac97cd20baad9316c66bc199301636c526174 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 importKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/AES256.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/AES256.ets old mode 100755 new mode 100644 index 20718d09e102ec3da9621a7bd2d6ae9d96768d69..d840ba2fe76f9c68d05a4df0c088ad1c3bf9be1d --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/AES256.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/AES256.ets @@ -1,137 +1,137 @@ -/* - * 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. - */ - -/* 以下以导入AES256密钥的Callback操作使用为例 */ -import { huks } from '@kit.UniversalKeystoreKit' - -/* 密钥材料 */ -let plainTextSize32 = new Uint8Array([ - 0xfb, 0x8b, 0x9f, 0x12, 0xa0, 0x83, 0x19, 0xbe, 0x6a, 0x6f, 0x63, 0x2a, 0x7c, 0x86, 0xba, 0xca, - 0x64, 0x0b, 0x88, 0x96, 0xe2, 0xfa, 0x77, 0xbc, 0x71, 0xe3, 0x0f, 0x0f, 0x9e, 0x3c, 0xe5, 0xf9 -]); -/* 1.确定密钥别名 */ -let keyAlias = 'AES256Alias_sample'; - -/* 2.封装密钥属性集和密钥材料 */ -let properties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, -]; - -let options: huks.HuksOptions = { - properties: properties, - inData: plainTextSize32 -}; - -/* 3.明文导入密钥 */ -function importAES256() { - try { - huks.importKeyItem(keyAlias, options, (error, data) => { - if (error) { - console.error(`callback: importKeyItem failed` + JSON.stringify(error)); - } else { - console.info(`callback: importKeyItem success`); - } - }); - } catch (error) { - console.error(`callback: importKeyItem input arg invalid` + JSON.stringify(error)); - throw (error as Error); - } -} - -let isKeyExist = false; - -let keyProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, -]; - -let huksOptions: huks.HuksOptions = { - properties: keyProperties, // 非空填充 - inData: new Uint8Array([]) // 非空填充 -} - -function check() { - try { - huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { - if (error) { - console.error(`callback: isKeyItemExist failed, ` + JSON.stringify(error)); - } else { - if (data !== null && data.valueOf() !== null) { - isKeyExist = data.valueOf(); - console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); - } - } - }); - } catch (error) { - console.error(`callback: isKeyItemExist input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'AES256'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_aes_256')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - try { - importAES256(); - check(); - this.message = 'AES256 Result: Success'; - }catch{ - this.message = 'AES256 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* 以下以导入AES256密钥的Callback操作使用为例 */ +import { huks } from '@kit.UniversalKeystoreKit' + +/* 密钥材料 */ +let plainTextSize32 = new Uint8Array([ + 0xfb, 0x8b, 0x9f, 0x12, 0xa0, 0x83, 0x19, 0xbe, 0x6a, 0x6f, 0x63, 0x2a, 0x7c, 0x86, 0xba, 0xca, + 0x64, 0x0b, 0x88, 0x96, 0xe2, 0xfa, 0x77, 0xbc, 0x71, 0xe3, 0x0f, 0x0f, 0x9e, 0x3c, 0xe5, 0xf9 +]); +/* 1.确定密钥别名 */ +let keyAlias = 'AES256Alias_sample'; + +/* 2.封装密钥属性集和密钥材料 */ +let properties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, +]; + +let options: huks.HuksOptions = { + properties: properties, + inData: plainTextSize32 +}; + +/* 3.明文导入密钥 */ +function importAES256() { + try { + huks.importKeyItem(keyAlias, options, (error, data) => { + if (error) { + console.error(`callback: importKeyItem failed` + JSON.stringify(error)); + } else { + console.info(`callback: importKeyItem success`); + } + }); + } catch (error) { + console.error(`callback: importKeyItem input arg invalid` + JSON.stringify(error)); + throw (error as Error); + } +} + +let isKeyExist = false; + +let keyProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, +]; + +let huksOptions: huks.HuksOptions = { + properties: keyProperties, // 非空填充 + inData: new Uint8Array([]) // 非空填充 +} + +function check() { + try { + huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { + if (error) { + console.error(`callback: isKeyItemExist failed, ` + JSON.stringify(error)); + } else { + if (data !== null && data.valueOf() !== null) { + isKeyExist = data.valueOf(); + console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); + } + } + }); + } catch (error) { + console.error(`callback: isKeyItemExist input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'AES256'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_aes_256')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + try { + importAES256(); + check(); + this.message = 'AES256 Result: Success'; + }catch{ + this.message = 'AES256 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/RSA2048.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/RSA2048.ets old mode 100755 new mode 100644 index e522e1cc29df3c0288995213fa4260f3e6458b49..6f7bc66fa17b67990d599eb18bd708b3c422ae1f --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/RSA2048.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/RSA2048.ets @@ -1,186 +1,186 @@ -/* - * 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. - */ - -/* 以下以导入RSA2048密钥的Callback操作使用为例 */ -import { huks } from '@kit.UniversalKeystoreKit' - -let rsa2048KeyPairMaterial = new Uint8Array([ - 0x01, 0x00, 0x00, 0x00, // 密钥算法(小端表示)huks.HuksKeyAlg.HUKS_ALG_RSA = 1 - 0x00, 0x08, 0x00, 0x00, // 密钥大小(比特):2048 - 0x00, 0x01, 0x00, 0x00, // 模数n长度(字节):256 - 0x03, 0x00, 0x00, 0x00, // 公钥指数e长度(字节):3 - 0x00, 0x01, 0x00, 0x00, // 私钥指数d长度(字节):256 - // 模数n - 0xc5, 0x35, 0x62, 0x48, 0xc4, 0x92, 0x87, 0x73, 0x0d, 0x42, 0x96, 0xfc, 0x7b, 0x11, 0x05, 0x06, - 0x0f, 0x8d, 0x66, 0xc1, 0x0e, 0xad, 0x37, 0x44, 0x92, 0x95, 0x2f, 0x6a, 0x55, 0xba, 0xec, 0x1d, - 0x54, 0x62, 0x0a, 0x4b, 0xd3, 0xc7, 0x05, 0xe4, 0x07, 0x40, 0xd9, 0xb7, 0xc2, 0x12, 0xcb, 0x9a, - 0x90, 0xad, 0xe3, 0x24, 0xe8, 0x5e, 0xa6, 0xf8, 0xd0, 0x6e, 0xbc, 0xd1, 0x69, 0x7f, 0x6b, 0xe4, - 0x2b, 0x4e, 0x1a, 0x65, 0xbb, 0x73, 0x88, 0x6b, 0x7c, 0xaf, 0x7e, 0xd0, 0x47, 0x26, 0xeb, 0xa5, - 0xbe, 0xd6, 0xe8, 0xee, 0x9c, 0xa5, 0x66, 0xa5, 0xc9, 0xd3, 0x25, 0x13, 0xc4, 0x0e, 0x6c, 0xab, - 0x50, 0xb6, 0x50, 0xc9, 0xce, 0x8f, 0x0a, 0x0b, 0xc6, 0x28, 0x69, 0xe9, 0x83, 0x69, 0xde, 0x42, - 0x56, 0x79, 0x7f, 0xde, 0x86, 0x24, 0xca, 0xfc, 0xaa, 0xc0, 0xf3, 0xf3, 0x7f, 0x92, 0x8e, 0x8a, - 0x12, 0x52, 0xfe, 0x50, 0xb1, 0x5e, 0x8c, 0x01, 0xce, 0xfc, 0x7e, 0xf2, 0x4f, 0x5f, 0x03, 0xfe, - 0xa7, 0xcd, 0xa1, 0xfc, 0x94, 0x52, 0x00, 0x8b, 0x9b, 0x7f, 0x09, 0xab, 0xa8, 0xa4, 0xf5, 0xb4, - 0xa5, 0xaa, 0xfc, 0x72, 0xeb, 0x17, 0x40, 0xa9, 0xee, 0xbe, 0x8f, 0xc2, 0xd1, 0x80, 0xc2, 0x0d, - 0x44, 0xa9, 0x59, 0x44, 0x59, 0x81, 0x3b, 0x5d, 0x4a, 0xde, 0xfb, 0xae, 0x24, 0xfc, 0xa3, 0xd9, - 0xbc, 0x57, 0x55, 0xc2, 0x26, 0xbc, 0x19, 0xa7, 0x9a, 0xc5, 0x59, 0xa3, 0xee, 0x5a, 0xef, 0x41, - 0x80, 0x7d, 0xf8, 0x5e, 0xc1, 0x1d, 0x32, 0x38, 0x41, 0x5b, 0xb6, 0x92, 0xb8, 0xb7, 0x03, 0x0d, - 0x3e, 0x59, 0x0f, 0x1c, 0xb3, 0xe1, 0x2a, 0x95, 0x1a, 0x3b, 0x50, 0x4f, 0xc4, 0x1d, 0xcf, 0x73, - 0x7c, 0x14, 0xca, 0xe3, 0x0b, 0xa7, 0xc7, 0x1a, 0x41, 0x4a, 0xee, 0xbe, 0x1f, 0x43, 0xdd, 0xf9, - // 公钥指数e - 0x01, 0x00, 0x01, - // 私钥指数d - 0x88, 0x4b, 0x82, 0xe7, 0xe3, 0xe3, 0x99, 0x75, 0x6c, 0x9e, 0xaf, 0x17, 0x44, 0x3e, 0xd9, 0x07, - 0xfd, 0x4b, 0xae, 0xce, 0x92, 0xc4, 0x28, 0x44, 0x5e, 0x42, 0x79, 0x08, 0xb6, 0xc3, 0x7f, 0x58, - 0x2d, 0xef, 0xac, 0x4a, 0x07, 0xcd, 0xaf, 0x46, 0x8f, 0xb4, 0xc4, 0x43, 0xf9, 0xff, 0x5f, 0x74, - 0x2d, 0xb5, 0xe0, 0x1c, 0xab, 0xf4, 0x6e, 0xd5, 0xdb, 0xc8, 0x0c, 0xfb, 0x76, 0x3c, 0x38, 0x66, - 0xf3, 0x7f, 0x01, 0x43, 0x7a, 0x30, 0x39, 0x02, 0x80, 0xa4, 0x11, 0xb3, 0x04, 0xd9, 0xe3, 0x57, - 0x23, 0xf4, 0x07, 0xfc, 0x91, 0x8a, 0xc6, 0xcc, 0xa2, 0x16, 0x29, 0xb3, 0xe5, 0x76, 0x4a, 0xa8, - 0x84, 0x19, 0xdc, 0xef, 0xfc, 0xb0, 0x63, 0x33, 0x0b, 0xfa, 0xf6, 0x68, 0x0b, 0x08, 0xea, 0x31, - 0x52, 0xee, 0x99, 0xef, 0x43, 0x2a, 0xbe, 0x97, 0xad, 0xb3, 0xb9, 0x66, 0x7a, 0xae, 0xe1, 0x8f, - 0x57, 0x86, 0xe5, 0xfe, 0x14, 0x3c, 0x81, 0xd0, 0x64, 0xf8, 0x86, 0x1a, 0x0b, 0x40, 0x58, 0xc9, - 0x33, 0x49, 0xb8, 0x99, 0xc6, 0x2e, 0x94, 0x70, 0xee, 0x09, 0x88, 0xe1, 0x5c, 0x4e, 0x6c, 0x22, - 0x72, 0xa7, 0x2a, 0x21, 0xdd, 0xd7, 0x1d, 0xfc, 0x63, 0x15, 0x0b, 0xde, 0x06, 0x9c, 0xf3, 0x28, - 0xf3, 0xac, 0x4a, 0xa8, 0xb5, 0x50, 0xca, 0x9b, 0xcc, 0x0a, 0x04, 0xfe, 0x3f, 0x98, 0x68, 0x81, - 0xac, 0x24, 0x53, 0xea, 0x1f, 0x1c, 0x6e, 0x5e, 0xca, 0xe8, 0x31, 0x0d, 0x08, 0x12, 0xf3, 0x26, - 0xf8, 0x5e, 0xeb, 0x10, 0x27, 0xae, 0xaa, 0xc3, 0xad, 0x6c, 0xc1, 0x89, 0xdb, 0x7d, 0x5a, 0x12, - 0x55, 0xad, 0x11, 0x19, 0xa1, 0xa9, 0x8f, 0x0b, 0x6d, 0x78, 0x8d, 0x1c, 0xdf, 0xe5, 0x63, 0x82, - 0x0b, 0x7d, 0x23, 0x04, 0xb4, 0x75, 0x8c, 0xed, 0x77, 0xfc, 0x1a, 0x85, 0x29, 0x11, 0xe0, 0x61, -]); - -/* 1.确定密钥别名 */ -let keyAlias = 'RSA_sample'; -/* 2.封装密钥属性集和密钥材料 */ -let properties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, - { - // 此 tag表示密钥导入后的用途,导入后将不可更改 - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, - { - // 此 tag表示需导入的密钥类型 - tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, - // 此 value表示导入密钥对,若改为HUKS_KEY_TYPE_PUBLIC_KEY时表示仅导入公钥 - value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR - }, -]; - -let options: huks.HuksOptions = { - properties: properties, - inData: rsa2048KeyPairMaterial -}; - -/* 3.明文导入密钥 */ -function importRSA2048() { - try { - huks.importKeyItem(keyAlias, options, (error, data) => { - if (error) { - console.error(`callback: importKeyItem failed` + error); - } else { - console.info(`callback: importKeyItem success`); - } - }); - } catch (error) { - console.error(`callback: importKeyItem input arg invalid` + error); - throw (error as Error); - } -} - -let isKeyExist = false; - -let keyProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, - { - tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, - value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR - }, -]; - -let huksOptions: huks.HuksOptions = { - properties: keyProperties, // 非空填充 - inData: new Uint8Array([]) // 非空填充 -} - -function check() { - try { - huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { - if (error) { - console.error(`callback: isKeyItemExist failed, ` + JSON.stringify(error)); - } else { - if (data !== null && data.valueOf() !== null) { - isKeyExist = data.valueOf(); - console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); - } - } - }); - } catch (error) { - console.error(`callback: isKeyItemExist input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA2048'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_rsa_2048')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - try { - importRSA2048(); - check(); - this.message = 'RSA2048 Result: Success'; - }catch{ - this.message = 'RSA2048 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* 以下以导入RSA2048密钥的Callback操作使用为例 */ +import { huks } from '@kit.UniversalKeystoreKit' + +let rsa2048KeyPairMaterial = new Uint8Array([ + 0x01, 0x00, 0x00, 0x00, // 密钥算法(小端表示)huks.HuksKeyAlg.HUKS_ALG_RSA = 1 + 0x00, 0x08, 0x00, 0x00, // 密钥大小(比特):2048 + 0x00, 0x01, 0x00, 0x00, // 模数n长度(字节):256 + 0x03, 0x00, 0x00, 0x00, // 公钥指数e长度(字节):3 + 0x00, 0x01, 0x00, 0x00, // 私钥指数d长度(字节):256 + // 模数n + 0xc5, 0x35, 0x62, 0x48, 0xc4, 0x92, 0x87, 0x73, 0x0d, 0x42, 0x96, 0xfc, 0x7b, 0x11, 0x05, 0x06, + 0x0f, 0x8d, 0x66, 0xc1, 0x0e, 0xad, 0x37, 0x44, 0x92, 0x95, 0x2f, 0x6a, 0x55, 0xba, 0xec, 0x1d, + 0x54, 0x62, 0x0a, 0x4b, 0xd3, 0xc7, 0x05, 0xe4, 0x07, 0x40, 0xd9, 0xb7, 0xc2, 0x12, 0xcb, 0x9a, + 0x90, 0xad, 0xe3, 0x24, 0xe8, 0x5e, 0xa6, 0xf8, 0xd0, 0x6e, 0xbc, 0xd1, 0x69, 0x7f, 0x6b, 0xe4, + 0x2b, 0x4e, 0x1a, 0x65, 0xbb, 0x73, 0x88, 0x6b, 0x7c, 0xaf, 0x7e, 0xd0, 0x47, 0x26, 0xeb, 0xa5, + 0xbe, 0xd6, 0xe8, 0xee, 0x9c, 0xa5, 0x66, 0xa5, 0xc9, 0xd3, 0x25, 0x13, 0xc4, 0x0e, 0x6c, 0xab, + 0x50, 0xb6, 0x50, 0xc9, 0xce, 0x8f, 0x0a, 0x0b, 0xc6, 0x28, 0x69, 0xe9, 0x83, 0x69, 0xde, 0x42, + 0x56, 0x79, 0x7f, 0xde, 0x86, 0x24, 0xca, 0xfc, 0xaa, 0xc0, 0xf3, 0xf3, 0x7f, 0x92, 0x8e, 0x8a, + 0x12, 0x52, 0xfe, 0x50, 0xb1, 0x5e, 0x8c, 0x01, 0xce, 0xfc, 0x7e, 0xf2, 0x4f, 0x5f, 0x03, 0xfe, + 0xa7, 0xcd, 0xa1, 0xfc, 0x94, 0x52, 0x00, 0x8b, 0x9b, 0x7f, 0x09, 0xab, 0xa8, 0xa4, 0xf5, 0xb4, + 0xa5, 0xaa, 0xfc, 0x72, 0xeb, 0x17, 0x40, 0xa9, 0xee, 0xbe, 0x8f, 0xc2, 0xd1, 0x80, 0xc2, 0x0d, + 0x44, 0xa9, 0x59, 0x44, 0x59, 0x81, 0x3b, 0x5d, 0x4a, 0xde, 0xfb, 0xae, 0x24, 0xfc, 0xa3, 0xd9, + 0xbc, 0x57, 0x55, 0xc2, 0x26, 0xbc, 0x19, 0xa7, 0x9a, 0xc5, 0x59, 0xa3, 0xee, 0x5a, 0xef, 0x41, + 0x80, 0x7d, 0xf8, 0x5e, 0xc1, 0x1d, 0x32, 0x38, 0x41, 0x5b, 0xb6, 0x92, 0xb8, 0xb7, 0x03, 0x0d, + 0x3e, 0x59, 0x0f, 0x1c, 0xb3, 0xe1, 0x2a, 0x95, 0x1a, 0x3b, 0x50, 0x4f, 0xc4, 0x1d, 0xcf, 0x73, + 0x7c, 0x14, 0xca, 0xe3, 0x0b, 0xa7, 0xc7, 0x1a, 0x41, 0x4a, 0xee, 0xbe, 0x1f, 0x43, 0xdd, 0xf9, + // 公钥指数e + 0x01, 0x00, 0x01, + // 私钥指数d + 0x88, 0x4b, 0x82, 0xe7, 0xe3, 0xe3, 0x99, 0x75, 0x6c, 0x9e, 0xaf, 0x17, 0x44, 0x3e, 0xd9, 0x07, + 0xfd, 0x4b, 0xae, 0xce, 0x92, 0xc4, 0x28, 0x44, 0x5e, 0x42, 0x79, 0x08, 0xb6, 0xc3, 0x7f, 0x58, + 0x2d, 0xef, 0xac, 0x4a, 0x07, 0xcd, 0xaf, 0x46, 0x8f, 0xb4, 0xc4, 0x43, 0xf9, 0xff, 0x5f, 0x74, + 0x2d, 0xb5, 0xe0, 0x1c, 0xab, 0xf4, 0x6e, 0xd5, 0xdb, 0xc8, 0x0c, 0xfb, 0x76, 0x3c, 0x38, 0x66, + 0xf3, 0x7f, 0x01, 0x43, 0x7a, 0x30, 0x39, 0x02, 0x80, 0xa4, 0x11, 0xb3, 0x04, 0xd9, 0xe3, 0x57, + 0x23, 0xf4, 0x07, 0xfc, 0x91, 0x8a, 0xc6, 0xcc, 0xa2, 0x16, 0x29, 0xb3, 0xe5, 0x76, 0x4a, 0xa8, + 0x84, 0x19, 0xdc, 0xef, 0xfc, 0xb0, 0x63, 0x33, 0x0b, 0xfa, 0xf6, 0x68, 0x0b, 0x08, 0xea, 0x31, + 0x52, 0xee, 0x99, 0xef, 0x43, 0x2a, 0xbe, 0x97, 0xad, 0xb3, 0xb9, 0x66, 0x7a, 0xae, 0xe1, 0x8f, + 0x57, 0x86, 0xe5, 0xfe, 0x14, 0x3c, 0x81, 0xd0, 0x64, 0xf8, 0x86, 0x1a, 0x0b, 0x40, 0x58, 0xc9, + 0x33, 0x49, 0xb8, 0x99, 0xc6, 0x2e, 0x94, 0x70, 0xee, 0x09, 0x88, 0xe1, 0x5c, 0x4e, 0x6c, 0x22, + 0x72, 0xa7, 0x2a, 0x21, 0xdd, 0xd7, 0x1d, 0xfc, 0x63, 0x15, 0x0b, 0xde, 0x06, 0x9c, 0xf3, 0x28, + 0xf3, 0xac, 0x4a, 0xa8, 0xb5, 0x50, 0xca, 0x9b, 0xcc, 0x0a, 0x04, 0xfe, 0x3f, 0x98, 0x68, 0x81, + 0xac, 0x24, 0x53, 0xea, 0x1f, 0x1c, 0x6e, 0x5e, 0xca, 0xe8, 0x31, 0x0d, 0x08, 0x12, 0xf3, 0x26, + 0xf8, 0x5e, 0xeb, 0x10, 0x27, 0xae, 0xaa, 0xc3, 0xad, 0x6c, 0xc1, 0x89, 0xdb, 0x7d, 0x5a, 0x12, + 0x55, 0xad, 0x11, 0x19, 0xa1, 0xa9, 0x8f, 0x0b, 0x6d, 0x78, 0x8d, 0x1c, 0xdf, 0xe5, 0x63, 0x82, + 0x0b, 0x7d, 0x23, 0x04, 0xb4, 0x75, 0x8c, 0xed, 0x77, 0xfc, 0x1a, 0x85, 0x29, 0x11, 0xe0, 0x61, +]); + +/* 1.确定密钥别名 */ +let keyAlias = 'RSA_sample'; +/* 2.封装密钥属性集和密钥材料 */ +let properties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, + { + // 此 tag表示密钥导入后的用途,导入后将不可更改 + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, + { + // 此 tag表示需导入的密钥类型 + tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, + // 此 value表示导入密钥对,若改为HUKS_KEY_TYPE_PUBLIC_KEY时表示仅导入公钥 + value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR + }, +]; + +let options: huks.HuksOptions = { + properties: properties, + inData: rsa2048KeyPairMaterial +}; + +/* 3.明文导入密钥 */ +function importRSA2048() { + try { + huks.importKeyItem(keyAlias, options, (error, data) => { + if (error) { + console.error(`callback: importKeyItem failed` + error); + } else { + console.info(`callback: importKeyItem success`); + } + }); + } catch (error) { + console.error(`callback: importKeyItem input arg invalid` + error); + throw (error as Error); + } +} + +let isKeyExist = false; + +let keyProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, + { + tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, + value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR + }, +]; + +let huksOptions: huks.HuksOptions = { + properties: keyProperties, // 非空填充 + inData: new Uint8Array([]) // 非空填充 +} + +function check() { + try { + huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { + if (error) { + console.error(`callback: isKeyItemExist failed, ` + JSON.stringify(error)); + } else { + if (data !== null && data.valueOf() !== null) { + isKeyExist = data.valueOf(); + console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); + } + } + }); + } catch (error) { + console.error(`callback: isKeyItemExist input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA2048'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_rsa_2048')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + try { + importRSA2048(); + check(); + this.message = 'RSA2048 Result: Success'; + }catch{ + this.message = 'RSA2048 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/X25519.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/X25519.ets old mode 100755 new mode 100644 index 29794fbe2c6a40f92498c89eb4decf481628ec98..2a0774f247b99a33c29b602a7c986de3202773aa --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/X25519.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/ets/pages/X25519.ets @@ -1,148 +1,148 @@ -/* - * 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. - */ - -/* 以下以导入X25519密钥的Callback操作使用为例 */ -import { huks } from '@kit.UniversalKeystoreKit' - -// X25519的公钥数据。X25519 密钥对中的私钥和公钥都是 32 字节(256 位),关于算法原理请自行参考相关密钥学资料。 -let x25519KeyPubMaterial = new Uint8Array([ - 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00, 0xD2, 0x36, 0x9E, 0xCF, - 0xF0, 0x61, 0x5B, 0x73, 0xCE, 0x4F, 0xF0, 0x40, 0x2B, 0x89, 0x18, 0x3E, 0x06, 0x33, 0x60, 0xC6 -]); - -/* 1.确定密钥别名 */ -let keyAlias = 'X25519_Pub_import_sample'; -/* 2.封装密钥属性集和密钥材料 */ -let properties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_X25519 - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 - }, - { - // 此 tag表示密钥导入后的用途,导入后将不可更改 - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, - { - // 此 tag表示需导入的密钥类型 - tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, - // 此 value表示导入密钥的公钥,若改为HUKS_KEY_TYPE_KEY_PAIR时表示导入密钥对 - value: huks.HuksImportKeyType.HUKS_KEY_TYPE_PUBLIC_KEY - }, -]; - -let options: huks.HuksOptions = { - properties: properties, - inData: x25519KeyPubMaterial -}; - -/* 3.明文导入密钥 */ -function importX25519() { - try { - huks.importKeyItem(keyAlias, options, (error, data) => { - if (error) { - console.error(`callback: importKeyItem failed` + error); - } else { - console.info(`callback: importKeyItem success`); - } - }); - } catch (error) { - console.error(`callback: importKeyItem input arg invalid` + error); - throw (error as Error); - } -} - -let isKeyExist = false; - -let keyProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_X25519 - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, - { - tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, - value: huks.HuksImportKeyType.HUKS_KEY_TYPE_PUBLIC_KEY - }, -] - -let huksOptions: huks.HuksOptions = { - properties: keyProperties, // 非空填充 - inData: new Uint8Array([]) // 非空填充 -} - -function check() { - try { - huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { - if (error) { - console.error(`callback: isKeyItemExist failed, ` + JSON.stringify(error)); - } else { - if (data !== null && data.valueOf() !== null) { - isKeyExist = data.valueOf(); - console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); - } - } - }); - } catch (error) { - console.error(`callback: isKeyItemExist input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -@Entry -@Component -struct Index { - @State message: string = 'X25519'; - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_x25519')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - try { - importX25519(); - check(); - this.message = 'X25519 Result: Success'; - }catch{ - this.message = 'X25519 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* 以下以导入X25519密钥的Callback操作使用为例 */ +import { huks } from '@kit.UniversalKeystoreKit' + +// X25519的公钥数据。X25519 密钥对中的私钥和公钥都是 32 字节(256 位),关于算法原理请自行参考相关密钥学资料。 +let x25519KeyPubMaterial = new Uint8Array([ + 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00, 0xD2, 0x36, 0x9E, 0xCF, + 0xF0, 0x61, 0x5B, 0x73, 0xCE, 0x4F, 0xF0, 0x40, 0x2B, 0x89, 0x18, 0x3E, 0x06, 0x33, 0x60, 0xC6 +]); + +/* 1.确定密钥别名 */ +let keyAlias = 'X25519_Pub_import_sample'; +/* 2.封装密钥属性集和密钥材料 */ +let properties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_X25519 + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 + }, + { + // 此 tag表示密钥导入后的用途,导入后将不可更改 + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, + { + // 此 tag表示需导入的密钥类型 + tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, + // 此 value表示导入密钥的公钥,若改为HUKS_KEY_TYPE_KEY_PAIR时表示导入密钥对 + value: huks.HuksImportKeyType.HUKS_KEY_TYPE_PUBLIC_KEY + }, +]; + +let options: huks.HuksOptions = { + properties: properties, + inData: x25519KeyPubMaterial +}; + +/* 3.明文导入密钥 */ +function importX25519() { + try { + huks.importKeyItem(keyAlias, options, (error, data) => { + if (error) { + console.error(`callback: importKeyItem failed` + error); + } else { + console.info(`callback: importKeyItem success`); + } + }); + } catch (error) { + console.error(`callback: importKeyItem input arg invalid` + error); + throw (error as Error); + } +} + +let isKeyExist = false; + +let keyProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_X25519 + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, + { + tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, + value: huks.HuksImportKeyType.HUKS_KEY_TYPE_PUBLIC_KEY + }, +] + +let huksOptions: huks.HuksOptions = { + properties: keyProperties, // 非空填充 + inData: new Uint8Array([]) // 非空填充 +} + +function check() { + try { + huks.isKeyItemExist(keyAlias, huksOptions, (error, data) => { + if (error) { + console.error(`callback: isKeyItemExist failed, ` + JSON.stringify(error)); + } else { + if (data !== null && data.valueOf() !== null) { + isKeyExist = data.valueOf(); + console.info(`callback: isKeyItemExist success, isKeyExist = ${isKeyExist}`); + } + } + }); + } catch (error) { + console.error(`callback: isKeyItemExist input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'X25519'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_x25519')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + try { + importX25519(); + check(); + this.message = 'X25519 Result: Success'; + }catch{ + this.message = 'X25519 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/ImportKeyPlainText.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/ImportKeyPlainText.test.ets old mode 100755 new mode 100644 index 37549a3ecc7fe1b391e174fcc02ea5255038658e..cf0e6f603a5b021444fa1cf362c4dc136c998709 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/ImportKeyPlainText.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/ImportKeyPlainText.test.ets @@ -1,98 +1,98 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function importKeyPlainTextTest() { - describe('importKeyPlainTextTest', () => { - - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - it('testImportKeyPlainText001', 0, async () => { - console.info('uitest: testImportKeyPlainText001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AES256')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES256')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES256 Result: Success')); - console.info('uitest: testImportKeyPlainText001 end'); - await driver.pressBack(); - }) - - it('testImportKeyPlainText002', 0, async () => { - console.info('uitest: testImportKeyPlainText002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA2048')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA2048')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('RSA2048 Result: Success')); - console.info('uitest: testImportKeyPlainText002 end'); - await driver.pressBack(); - }) - - it('testImportKeyPlainText003', 0, async () => { - console.info('uitest: testImportKeyPlainText003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('X25519')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call X25519')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('X25519 Result: Success')); - console.info('uitest: testImportKeyPlainText003 end'); - await driver.pressBack(); - }) - - it('testImportKeyPlainText004', 0, async () => { - console.info('uitest: testImportKeyPlainText004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testImportKeyPlainText004 end'); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function importKeyPlainTextTest() { + describe('importKeyPlainTextTest', () => { + + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + it('testImportKeyPlainText001', 0, async () => { + console.info('uitest: testImportKeyPlainText001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AES256')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES256')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES256 Result: Success')); + console.info('uitest: testImportKeyPlainText001 end'); + await driver.pressBack(); + }) + + it('testImportKeyPlainText002', 0, async () => { + console.info('uitest: testImportKeyPlainText002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA2048')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA2048')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('RSA2048 Result: Success')); + console.info('uitest: testImportKeyPlainText002 end'); + await driver.pressBack(); + }) + + it('testImportKeyPlainText003', 0, async () => { + console.info('uitest: testImportKeyPlainText003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('X25519')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call X25519')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('X25519 Result: Success')); + console.info('uitest: testImportKeyPlainText003 end'); + await driver.pressBack(); + }) + + it('testImportKeyPlainText004', 0, async () => { + console.info('uitest: testImportKeyPlainText004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testImportKeyPlainText004 end'); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyGenerationImport/KeyImport/DevelopmentGuidelines/ImportKeyPlainText/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/app.json5 old mode 100755 new mode 100644 index 163d71aa93df1dd8ac4eb4118a74fed72fa7dc8e..f2c7feff9328013dd929155aa1c207d15e058341 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/app.json5 @@ -1,25 +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.anonymouskeyproof", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.anonymouskeyproof", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 5cf961e6bf5c25e7613401011d98b63ca860eca7..d2ae0e044db93ba46958817a61b732b194a78a48 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AnonymousKeyProof" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AnonymousKeyProof" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index de73f737d213fd6e9f699e911ed2fd67a017a008..2120cc1b577198fc8da5aca0191d1fe768c9963c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(AnonymousKeyProof) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(AnonymousKeyProof) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 3be42f279901310396a96153a7a58ae9abafe89f..07e145b58516046be213f95aec08e7a3d268db30 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/napi_init.cpp @@ -1,157 +1,157 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -static uint32_t g_size = 4096; -static uint32_t CERT_COUNT = 4; -void FreeCertChain(struct OH_Huks_CertChain *certChain, const uint32_t pos) -{ - if (certChain == nullptr || certChain->certs == nullptr) { - return; - } - for (uint32_t j = 0; j < pos; j++) { - if (certChain->certs[j].data != nullptr) { - free(certChain->certs[j].data); - certChain->certs[j].data = nullptr; - } - } - if (certChain->certs != nullptr) { - free(certChain->certs); - certChain->certs = nullptr; - } -} - -int32_t ConstructDataToCertChain(struct OH_Huks_CertChain *certChain) -{ - if (certChain == nullptr) { - return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; - } - certChain->certsCount = CERT_COUNT; - - certChain->certs = (struct OH_Huks_Blob *)malloc(sizeof(struct OH_Huks_Blob) * (certChain->certsCount)); - if (certChain->certs == nullptr) { - return OH_HUKS_ERR_CODE_INTERNAL_ERROR; - } - for (uint32_t i = 0; i < certChain->certsCount; i++) { - certChain->certs[i].size = g_size; - certChain->certs[i].data = (uint8_t *)malloc(certChain->certs[i].size); - if (certChain->certs[i].data == nullptr) { - FreeCertChain(certChain, i); - return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; - } - } - return 0; -} - -static struct OH_Huks_Param g_genAnonAttestParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_ECB}, -}; - -#define CHALLENGE_DATA "hi_challenge_data" -static struct OH_Huks_Blob g_challenge = {sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA}; -static napi_value AnonAttestKey(napi_env env, napi_callback_info info) -{ - /* 1.确定密钥别名 */ - struct OH_Huks_Blob genAlias = {(uint32_t)strlen("test_anon_attest"), (uint8_t *)"test_anon_attest"}; - static struct OH_Huks_Param g_anonAttestParams[] = { - {.tag = OH_HUKS_TAG_ATTESTATION_CHALLENGE, .blob = g_challenge}, - {.tag = OH_HUKS_TAG_ATTESTATION_ID_ALIAS, .blob = genAlias}, - }; - struct OH_Huks_ParamSet *genParamSet = nullptr; - struct OH_Huks_ParamSet *anonAttestParamSet = nullptr; - OH_Huks_Result ohResult; - OH_Huks_Blob certs = {0}; - OH_Huks_CertChain certChain = {&certs, 0}; - do { - /* 2.初始化密钥参数集 */ - ohResult = - InitParamSet(&genParamSet, g_genAnonAttestParams, sizeof(g_genAnonAttestParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = - InitParamSet(&anonAttestParamSet, g_anonAttestParams, sizeof(g_anonAttestParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = OH_Huks_GenerateKeyItem(&genAlias, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - - (void)ConstructDataToCertChain(&certChain); - /* 3.证明密钥 */ - ohResult = OH_Huks_AnonAttestKeyItem(&genAlias, anonAttestParamSet, &certChain); - } while (0); - FreeCertChain(&certChain, CERT_COUNT); - OH_Huks_FreeParamSet(&genParamSet); - OH_Huks_FreeParamSet(&anonAttestParamSet); - (void)OH_Huks_DeleteKeyItem(&genAlias, NULL); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"anonAttestKey", nullptr, AnonAttestKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +static uint32_t g_size = 4096; +static uint32_t CERT_COUNT = 4; +void FreeCertChain(struct OH_Huks_CertChain *certChain, const uint32_t pos) +{ + if (certChain == nullptr || certChain->certs == nullptr) { + return; + } + for (uint32_t j = 0; j < pos; j++) { + if (certChain->certs[j].data != nullptr) { + free(certChain->certs[j].data); + certChain->certs[j].data = nullptr; + } + } + if (certChain->certs != nullptr) { + free(certChain->certs); + certChain->certs = nullptr; + } +} + +int32_t ConstructDataToCertChain(struct OH_Huks_CertChain *certChain) +{ + if (certChain == nullptr) { + return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; + } + certChain->certsCount = CERT_COUNT; + + certChain->certs = (struct OH_Huks_Blob *)malloc(sizeof(struct OH_Huks_Blob) * (certChain->certsCount)); + if (certChain->certs == nullptr) { + return OH_HUKS_ERR_CODE_INTERNAL_ERROR; + } + for (uint32_t i = 0; i < certChain->certsCount; i++) { + certChain->certs[i].size = g_size; + certChain->certs[i].data = (uint8_t *)malloc(certChain->certs[i].size); + if (certChain->certs[i].data == nullptr) { + FreeCertChain(certChain, i); + return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; + } + } + return 0; +} + +static struct OH_Huks_Param g_genAnonAttestParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_ECB}, +}; + +#define CHALLENGE_DATA "hi_challenge_data" +static struct OH_Huks_Blob g_challenge = {sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA}; +static napi_value AnonAttestKey(napi_env env, napi_callback_info info) +{ + /* 1.确定密钥别名 */ + struct OH_Huks_Blob genAlias = {(uint32_t)strlen("test_anon_attest"), (uint8_t *)"test_anon_attest"}; + static struct OH_Huks_Param g_anonAttestParams[] = { + {.tag = OH_HUKS_TAG_ATTESTATION_CHALLENGE, .blob = g_challenge}, + {.tag = OH_HUKS_TAG_ATTESTATION_ID_ALIAS, .blob = genAlias}, + }; + struct OH_Huks_ParamSet *genParamSet = nullptr; + struct OH_Huks_ParamSet *anonAttestParamSet = nullptr; + OH_Huks_Result ohResult; + OH_Huks_Blob certs = {0}; + OH_Huks_CertChain certChain = {&certs, 0}; + do { + /* 2.初始化密钥参数集 */ + ohResult = + InitParamSet(&genParamSet, g_genAnonAttestParams, sizeof(g_genAnonAttestParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = + InitParamSet(&anonAttestParamSet, g_anonAttestParams, sizeof(g_anonAttestParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = OH_Huks_GenerateKeyItem(&genAlias, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + + (void)ConstructDataToCertChain(&certChain); + /* 3.证明密钥 */ + ohResult = OH_Huks_AnonAttestKeyItem(&genAlias, anonAttestParamSet, &certChain); + } while (0); + FreeCertChain(&certChain, CERT_COUNT); + OH_Huks_FreeParamSet(&genParamSet); + OH_Huks_FreeParamSet(&anonAttestParamSet); + (void)OH_Huks_DeleteKeyItem(&genAlias, NULL); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"anonAttestKey", nullptr, AnonAttestKey, 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index ea4292d9205e559adce85fc88a6a5f8041b707f2..b9a785abe30b1a88a915c6f5b28e1ca6fd8adb3f --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 anonAttestKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/pages/AnonymousKeyProof.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/pages/AnonymousKeyProof.ets old mode 100755 new mode 100644 index 18a32ed19679a54a4e02317268a41eb2ab3a9581..d0f5b040e0e00e1476d19453b563f93d3f0710f5 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/pages/AnonymousKeyProof.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/pages/AnonymousKeyProof.ets @@ -1,216 +1,216 @@ -/* - * 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. - */ - -/* - * 以下以anonAttestKey的Promise接口操作验证为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -/* 1.确定密钥别名 */ -let keyAliasString = 'key anon attest'; -let aliasString = keyAliasString; -let aliasUint8 = stringToUint8Array(keyAliasString); -let securityLevel = stringToUint8Array('sec_level'); -let challenge = stringToUint8Array('challenge_data'); -let versionInfo = stringToUint8Array('version_info'); -let anonAttestCertChain: string[]; - -class ThrowObject { - public isThrow: boolean = false; -} - -/* 封装生成时的密钥参数集 */ -let genKeyProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, - { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PSS - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE, - value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB - } -] -let genOptions: huks.HuksOptions = { - properties: genKeyProperties -}; - -/* 2.封装证明密钥的参数集 */ -let anonAttestKeyProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO, - value: securityLevel - }, - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE, - value: challenge - }, - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO, - value: versionInfo - }, - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS, - value: aliasUint8 - } -] -let huksOptions: huks.HuksOptions = { - properties: anonAttestKeyProperties -}; - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 3.生成密钥 */ -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - } -} - -/* 4.证明密钥 */ -function anonAttestKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.anonAttestKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicAnonAttestKey(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise anonAttestKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await anonAttestKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: anonAttestKeyItem success, data = ${JSON.stringify(data)}`); - if (data !== null && data.certChains !== null) { - anonAttestCertChain = data.certChains as string[]; - } - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: anonAttestKeyItem failed, ${JSON.stringify(error)}`); - } - }); - return 'Success'; - } catch (error) { - console.error(`promise: anonAttestKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -async function anonAttestKeyTest(): Promise { - await publicGenKeyFunc(aliasString, genOptions); - let ret = await publicAnonAttestKey(aliasString, huksOptions); - console.info('anon attest certChain data: ' + anonAttestCertChain) - return ret; -} - -@Entry -@Component -struct Index { - @State message: string = 'AnonymousKeyProof'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_anonymous_key_proof')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - let ret = await anonAttestKeyTest(); - this.message = 'AnonymousKeyProof Result: ' + ret; - }) - } - .height('100%') - .width('100%') - } +/* + * 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. + */ + +/* + * 以下以anonAttestKey的Promise接口操作验证为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +/* 1.确定密钥别名 */ +let keyAliasString = 'key anon attest'; +let aliasString = keyAliasString; +let aliasUint8 = stringToUint8Array(keyAliasString); +let securityLevel = stringToUint8Array('sec_level'); +let challenge = stringToUint8Array('challenge_data'); +let versionInfo = stringToUint8Array('version_info'); +let anonAttestCertChain: string[]; + +class ThrowObject { + public isThrow: boolean = false; +} + +/* 封装生成时的密钥参数集 */ +let genKeyProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, + { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PSS + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE, + value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB + } +] +let genOptions: huks.HuksOptions = { + properties: genKeyProperties +}; + +/* 2.封装证明密钥的参数集 */ +let anonAttestKeyProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO, + value: securityLevel + }, + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE, + value: challenge + }, + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO, + value: versionInfo + }, + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS, + value: aliasUint8 + } +] +let huksOptions: huks.HuksOptions = { + properties: anonAttestKeyProperties +}; + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 3.生成密钥 */ +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + } +} + +/* 4.证明密钥 */ +function anonAttestKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.anonAttestKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicAnonAttestKey(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise anonAttestKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await anonAttestKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: anonAttestKeyItem success, data = ${JSON.stringify(data)}`); + if (data !== null && data.certChains !== null) { + anonAttestCertChain = data.certChains as string[]; + } + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: anonAttestKeyItem failed, ${JSON.stringify(error)}`); + } + }); + return 'Success'; + } catch (error) { + console.error(`promise: anonAttestKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +async function anonAttestKeyTest(): Promise { + await publicGenKeyFunc(aliasString, genOptions); + let ret = await publicAnonAttestKey(aliasString, huksOptions); + console.info('anon attest certChain data: ' + anonAttestCertChain) + return ret; +} + +@Entry +@Component +struct Index { + @State message: string = 'AnonymousKeyProof'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_anonymous_key_proof')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + let ret = await anonAttestKeyTest(); + this.message = 'AnonymousKeyProof Result: ' + ret; + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/AnonymousKeyProof.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/AnonymousKeyProof.test.ets old mode 100755 new mode 100644 index 91bbbef8155932fcd35d84e90fdfe3607589cd75..80afe5c5aa80205fd19b0224002e2fd523037d9c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/AnonymousKeyProof.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/AnonymousKeyProof.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function anonymousKeyProofTest() { - describe('anonymousKeyProofTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,匿名密钥证明(ArkTS) - */ - it('testAnonymousKeyProof001', 0, async () => { - console.info('uitest: testAnonymousKeyProof001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AnonymousKeyProof').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AnonymousKeyProof')); - await button2.click(); - await driver.delayMs(5000); - await driver.assertComponentExist(ON.text('AnonymousKeyProof Result: Success')); - console.info('uitest: testAnonymousKeyProof001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,匿名密钥证明(C/C++) - */ - it('testAnonymousKeyProof002', 0, async () => { - console.info('uitest: testAnonymousKeyProof002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(3000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testAnonymousKeyProof002 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function anonymousKeyProofTest() { + describe('anonymousKeyProofTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,匿名密钥证明(ArkTS) + */ + it('testAnonymousKeyProof001', 0, async () => { + console.info('uitest: testAnonymousKeyProof001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AnonymousKeyProof').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AnonymousKeyProof')); + await button2.click(); + await driver.delayMs(5000); + await driver.assertComponentExist(ON.text('AnonymousKeyProof Result: Success')); + console.info('uitest: testAnonymousKeyProof001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,匿名密钥证明(C/C++) + */ + it('testAnonymousKeyProof002', 0, async () => { + console.info('uitest: testAnonymousKeyProof002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(3000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testAnonymousKeyProof002 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/ohosTest.md old mode 100755 new mode 100644 index 23e0088d4cbb665570059c1fc0f535b59633f5e6..cd3b5f37c2616a6a9eb4b46fa71e534b73b18a3b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/ohosTest.md @@ -1,9 +1,9 @@ -# 匿名密钥证明测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------- | ------------ | ---- | ---------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,匿名密钥证明(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +# 匿名密钥证明测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,匿名密钥证明(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | | 点击按钮,匿名密钥证明(C/C++) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/AnonymousKeyProof_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/AnonymousKeyProof_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/AnonymousKeyProof_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/AnonymousKeyProof_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/AnonymousKeyProof/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/app.json5 old mode 100755 new mode 100644 index 90addccb5b5229b39d0355a21376bd46e46ebdf8..4b8d9e4aee7c41e5e4904b20fa819f8f02e1e2fd --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/app.json5 @@ -1,25 +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.nonanonymouskeyproof", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.nonanonymouskeyproof", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index bed89842c859aef361348d48db22d630e9593d65..b9bd49669a451e15a0b153ce1f53d0e7e0bff326 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NonAnonymousKeyProof" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NonAnonymousKeyProof" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index f4f82803697d9be5dbb78e0b726602d73c8faa7a..5c714d56e55dfdbc4ba958c69f77c6b525f7cf80 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(NonanonymousKeyProof) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(NonanonymousKeyProof) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index ed25c4cf2fbf985a2db596c4774403931ee06496..0260e4475b90caca54dda625a59bdd73d27b9580 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/napi_init.cpp @@ -1,156 +1,156 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -static uint32_t g_size = 4096; -static uint32_t CERT_COUNT = 4; - -void FreeCertChain(struct OH_Huks_CertChain *certChain, const uint32_t pos) -{ - if (certChain == nullptr || certChain->certs == nullptr) { - return; - } - for (uint32_t j = 0; j < pos; j++) { - if (certChain->certs[j].data != nullptr) { - free(certChain->certs[j].data); - certChain->certs[j].data = nullptr; - } - } - if (certChain->certs != nullptr) { - free(certChain->certs); - certChain->certs = nullptr; - } -} - -int32_t ConstructDataToCertChain(struct OH_Huks_CertChain *certChain) -{ - if (certChain == nullptr) { - return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; - } - certChain->certsCount = CERT_COUNT; - - certChain->certs = (struct OH_Huks_Blob *)malloc(sizeof(struct OH_Huks_Blob) * (certChain->certsCount)); - if (certChain->certs == nullptr) { - return OH_HUKS_ERR_CODE_INTERNAL_ERROR; - } - for (uint32_t i = 0; i < certChain->certsCount; i++) { - certChain->certs[i].size = g_size; - certChain->certs[i].data = (uint8_t *)malloc(certChain->certs[i].size); - if (certChain->certs[i].data == nullptr) { - FreeCertChain(certChain, i); - return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; - } - } - return 0; -} - -static struct OH_Huks_Param g_genAttestParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_ECB}, -}; - -#define CHALLENGE_DATA "hi_challenge_data" -static struct OH_Huks_Blob g_challenge = {sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA}; -static napi_value AttestKey(napi_env env, napi_callback_info info) -{ - /* 1.确定密钥别名 */ - struct OH_Huks_Blob genAlias = {(uint32_t)strlen("test_attest"), (uint8_t *)"test_attest"}; - static struct OH_Huks_Param g_attestParams[] = { - {.tag = OH_HUKS_TAG_ATTESTATION_CHALLENGE, .blob = g_challenge}, - {.tag = OH_HUKS_TAG_ATTESTATION_ID_ALIAS, .blob = genAlias}, - }; - struct OH_Huks_ParamSet *genParamSet = nullptr; - struct OH_Huks_ParamSet *attestParamSet = nullptr; - OH_Huks_Result ohResult; - OH_Huks_Blob certs = {0}; - OH_Huks_CertChain certChain = {&certs, 0}; - do { - /* 2.初始化密钥参数集 */ - ohResult = InitParamSet(&genParamSet, g_genAttestParams, sizeof(g_genAttestParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = InitParamSet(&attestParamSet, g_attestParams, sizeof(g_attestParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = OH_Huks_GenerateKeyItem(&genAlias, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - - (void)ConstructDataToCertChain(&certChain); - /* 3.证明密钥 */ - ohResult = OH_Huks_AttestKeyItem(&genAlias, attestParamSet, &certChain); - } while (0); - FreeCertChain(&certChain, CERT_COUNT); - OH_Huks_FreeParamSet(&genParamSet); - OH_Huks_FreeParamSet(&attestParamSet); - (void)OH_Huks_DeleteKeyItem(&genAlias, NULL); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"attestKey", nullptr, AttestKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +static uint32_t g_size = 4096; +static uint32_t CERT_COUNT = 4; + +void FreeCertChain(struct OH_Huks_CertChain *certChain, const uint32_t pos) +{ + if (certChain == nullptr || certChain->certs == nullptr) { + return; + } + for (uint32_t j = 0; j < pos; j++) { + if (certChain->certs[j].data != nullptr) { + free(certChain->certs[j].data); + certChain->certs[j].data = nullptr; + } + } + if (certChain->certs != nullptr) { + free(certChain->certs); + certChain->certs = nullptr; + } +} + +int32_t ConstructDataToCertChain(struct OH_Huks_CertChain *certChain) +{ + if (certChain == nullptr) { + return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; + } + certChain->certsCount = CERT_COUNT; + + certChain->certs = (struct OH_Huks_Blob *)malloc(sizeof(struct OH_Huks_Blob) * (certChain->certsCount)); + if (certChain->certs == nullptr) { + return OH_HUKS_ERR_CODE_INTERNAL_ERROR; + } + for (uint32_t i = 0; i < certChain->certsCount; i++) { + certChain->certs[i].size = g_size; + certChain->certs[i].data = (uint8_t *)malloc(certChain->certs[i].size); + if (certChain->certs[i].data == nullptr) { + FreeCertChain(certChain, i); + return OH_HUKS_ERR_CODE_ILLEGAL_ARGUMENT; + } + } + return 0; +} + +static struct OH_Huks_Param g_genAttestParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_ECB}, +}; + +#define CHALLENGE_DATA "hi_challenge_data" +static struct OH_Huks_Blob g_challenge = {sizeof(CHALLENGE_DATA), (uint8_t *)CHALLENGE_DATA}; +static napi_value AttestKey(napi_env env, napi_callback_info info) +{ + /* 1.确定密钥别名 */ + struct OH_Huks_Blob genAlias = {(uint32_t)strlen("test_attest"), (uint8_t *)"test_attest"}; + static struct OH_Huks_Param g_attestParams[] = { + {.tag = OH_HUKS_TAG_ATTESTATION_CHALLENGE, .blob = g_challenge}, + {.tag = OH_HUKS_TAG_ATTESTATION_ID_ALIAS, .blob = genAlias}, + }; + struct OH_Huks_ParamSet *genParamSet = nullptr; + struct OH_Huks_ParamSet *attestParamSet = nullptr; + OH_Huks_Result ohResult; + OH_Huks_Blob certs = {0}; + OH_Huks_CertChain certChain = {&certs, 0}; + do { + /* 2.初始化密钥参数集 */ + ohResult = InitParamSet(&genParamSet, g_genAttestParams, sizeof(g_genAttestParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = InitParamSet(&attestParamSet, g_attestParams, sizeof(g_attestParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = OH_Huks_GenerateKeyItem(&genAlias, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + + (void)ConstructDataToCertChain(&certChain); + /* 3.证明密钥 */ + ohResult = OH_Huks_AttestKeyItem(&genAlias, attestParamSet, &certChain); + } while (0); + FreeCertChain(&certChain, CERT_COUNT); + OH_Huks_FreeParamSet(&genParamSet); + OH_Huks_FreeParamSet(&attestParamSet); + (void)OH_Huks_DeleteKeyItem(&genAlias, NULL); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"attestKey", nullptr, AttestKey, 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index fc5993bf009c3c4a510d0a602dd54ef4105ba11d..2d7892ea30fd0966e7126764f50a77bc4145ac05 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 attestKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/pages/NonAnonymousKeyProof.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/pages/NonAnonymousKeyProof.ets old mode 100755 new mode 100644 index ab44d65cc1c05fed9bc83da39478e39f7987397f..3a823bb2640278b1734b7ca765cdefccf0fd1bd0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/pages/NonAnonymousKeyProof.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/ets/pages/NonAnonymousKeyProof.ets @@ -1,216 +1,216 @@ -/* - * 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. - */ - -/* - * 以下以attestKey的Promise接口操作验证为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -/* 1.确定密钥别名 */ -let keyAliasString = 'key attest'; -let aliasString = keyAliasString; -let aliasUint8 = stringToUint8Array(keyAliasString); -let securityLevel = stringToUint8Array('sec_level'); -let challenge = stringToUint8Array('challenge_data'); -let versionInfo = stringToUint8Array('version_info'); -let attestCertChain: string[]; - -class ThrowObject { - public isThrow: boolean = false; -} - -/* 封装生成时的密钥参数集 */ -let genKeyProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, - { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PSS - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE, - value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB - } -] -let genOptions: huks.HuksOptions = { - properties: genKeyProperties -}; - -/* 2.封装证明密钥的参数集 */ -let attestKeyproperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO, - value: securityLevel - }, - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE, - value: challenge - }, - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO, - value: versionInfo - }, - { - tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS, - value: aliasUint8 - } -] -let huksOptions: huks.HuksOptions = { - properties: attestKeyproperties -}; - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 3.生成密钥 */ -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - } -} - -/* 4.证明密钥 */ -function attestKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.attestKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicAttestKey(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise attestKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await attestKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: attestKeyItem success, data = ${JSON.stringify(data)}`); - if (data !== null && data.certChains !== null) { - attestCertChain = data.certChains as string[]; - } - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: attestKeyItem failed, ${JSON.stringify(error)}`); - } - }); - return 'Success'; - } catch (error) { - console.error(`promise: attestKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -async function attestKeyTest(): Promise { - await publicGenKeyFunc(aliasString, genOptions); - let ret = await publicAttestKey(aliasString, huksOptions); - console.info('attest certChain data: ' + attestCertChain) - return ret; -} - -@Entry -@Component -struct Index { - @State message: string = 'NonAnonymousKeyProof'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_non_anonymous_key_proof')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - let ret = await attestKeyTest(); - this.message = 'NonAnonymousKeyProof Result: ' + ret; - }) - } - .height('100%') - .width('100%') - } +/* + * 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. + */ + +/* + * 以下以attestKey的Promise接口操作验证为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +/* 1.确定密钥别名 */ +let keyAliasString = 'key attest'; +let aliasString = keyAliasString; +let aliasUint8 = stringToUint8Array(keyAliasString); +let securityLevel = stringToUint8Array('sec_level'); +let challenge = stringToUint8Array('challenge_data'); +let versionInfo = stringToUint8Array('version_info'); +let attestCertChain: string[]; + +class ThrowObject { + public isThrow: boolean = false; +} + +/* 封装生成时的密钥参数集 */ +let genKeyProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, + { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PSS + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_GENERATE_TYPE, + value: huks.HuksKeyGenerateType.HUKS_KEY_GENERATE_TYPE_DEFAULT + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB + } +] +let genOptions: huks.HuksOptions = { + properties: genKeyProperties +}; + +/* 2.封装证明密钥的参数集 */ +let attestKeyproperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_SEC_LEVEL_INFO, + value: securityLevel + }, + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_CHALLENGE, + value: challenge + }, + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_VERSION_INFO, + value: versionInfo + }, + { + tag: huks.HuksTag.HUKS_TAG_ATTESTATION_ID_ALIAS, + value: aliasUint8 + } +] +let huksOptions: huks.HuksOptions = { + properties: attestKeyproperties +}; + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 3.生成密钥 */ +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + } +} + +/* 4.证明密钥 */ +function attestKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.attestKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicAttestKey(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise attestKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await attestKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: attestKeyItem success, data = ${JSON.stringify(data)}`); + if (data !== null && data.certChains !== null) { + attestCertChain = data.certChains as string[]; + } + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: attestKeyItem failed, ${JSON.stringify(error)}`); + } + }); + return 'Success'; + } catch (error) { + console.error(`promise: attestKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +async function attestKeyTest(): Promise { + await publicGenKeyFunc(aliasString, genOptions); + let ret = await publicAttestKey(aliasString, huksOptions); + console.info('attest certChain data: ' + attestCertChain) + return ret; +} + +@Entry +@Component +struct Index { + @State message: string = 'NonAnonymousKeyProof'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_non_anonymous_key_proof')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + let ret = await attestKeyTest(); + this.message = 'NonAnonymousKeyProof Result: ' + ret; + }) + } + .height('100%') + .width('100%') + } } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/module.json5 old mode 100755 new mode 100644 index 0e0b2cf33de268b28b7d974952fb7c9630fc3f01..f0261f2ef4abd37a29780940adb2b5641a24aec6 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/module.json5 @@ -1,78 +1,78 @@ -/* - * 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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.ATTEST_KEY", - "reason": "$string:permissionsReason", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - "when": "inuse" - } - } - ] - } -} +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ATTEST_KEY", + "reason": "$string:permissionsReason", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + } + } + ] + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/NonAnonymousKeyProof.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/NonAnonymousKeyProof.test.ets old mode 100755 new mode 100644 index 8905d23585bbe357e4981d3e903dbd6bdaa4495b..56e3d849aa1dbe3412d497e0238b5ae717cccdd6 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/NonAnonymousKeyProof.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/ets/test/NonAnonymousKeyProof.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function nonAnonymousKeyProofTest() { - describe('nonAnonymousKeyProofTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,非匿名密钥证明(ArkTS) - */ - it('testNonAnonymousKeyProof001', 0, async () => { - console.info('uitest: testNonAnonymousKeyProof001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('NonAnonymousKeyProof').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call NonAnonymousKeyProof')); - await button2.click(); - await driver.delayMs(3000); - await driver.assertComponentExist(ON.text('NonAnonymousKeyProof Result: Success')); - console.info('uitest: testNonAnonymousKeyProof001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,非匿名密钥证明(C/C++) - */ - it('testNonAnonymousKeyProof002', 0, async () => { - console.info('uitest: testNonAnonymousKeyProof002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testNonAnonymousKeyProof002 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function nonAnonymousKeyProofTest() { + describe('nonAnonymousKeyProofTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,非匿名密钥证明(ArkTS) + */ + it('testNonAnonymousKeyProof001', 0, async () => { + console.info('uitest: testNonAnonymousKeyProof001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('NonAnonymousKeyProof').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call NonAnonymousKeyProof')); + await button2.click(); + await driver.delayMs(3000); + await driver.assertComponentExist(ON.text('NonAnonymousKeyProof Result: Success')); + console.info('uitest: testNonAnonymousKeyProof001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,非匿名密钥证明(C/C++) + */ + it('testNonAnonymousKeyProof002', 0, async () => { + console.info('uitest: testNonAnonymousKeyProof002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testNonAnonymousKeyProof002 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/ohosTest.md old mode 100755 new mode 100644 index ccfba062f1c80d494fe3aacb5efbc0b98537f0e7..d83f44fc10950ef624d4dae1d291dfd279d05bf4 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/ohosTest.md @@ -1,9 +1,9 @@ -# 非匿名密钥证明测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------- | ------------ | ---- | ---------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,非匿名密钥证明(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +# 非匿名密钥证明测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,非匿名密钥证明(ArkTS) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | | 点击按钮,非匿名密钥证明(C/C++) | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/NonAnonymousKeyProof_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/NonAnonymousKeyProof_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/NonAnonymousKeyProof_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyProving/DevelopmentGuidelines/NonanonymousKeyProof/screenshots/NonAnonymousKeyProof_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/.gitignore old mode 100755 new mode 100644 index 0b9dda19af05cf615a8be3bc063b228131da6b7c..d2ff20141ceed86d87c0ea5d99481973005bab2b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/.gitignore +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/.gitignore @@ -1,12 +1,12 @@ -/node_modules -/oh_modules -/local.properties -/.idea -**/build -/.hvigor -.cxx -/.clangd -/.clang-format -/.clang-tidy -**/.test +/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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/app.json5 old mode 100755 new mode 100644 index 0040509f4e038aa3a35705a4b88c7e4a0f7c72cc..92d4575e4516617e3ca51f5cfe22cfeecfbd5b4a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/app.json5 @@ -1,25 +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.accesscontrol", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.accesscontrol", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index c7b5f61e40edbb616058a20f9eb946fe7b0cd205..daebd0deb4b5593c38ed846cc19a01d68750c875 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AccessControl" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AccessControl" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/README.md old mode 100755 new mode 100644 index ba626d036077cbf52c8c67347d63faebe12d158d..5c30219adf89e62755c551afa18ce522a7c6b97c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/README.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/README.md @@ -1,88 +1,88 @@ -## 用户身份认证访问控制开发指导 - -### 介绍 - -1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/UniversalKeystoreKit/huks-user-identity-authentication.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 - -#### UserIdentityAuthentication - -##### 介绍 - -1. 本示例主要介绍实现用户身份认证访问控制,确保只有经过PIN认证的用户才能对加密数据进行操作。 - -##### 效果预览 - -| 主页 | 删除 | -| ------------------------------------------------------------------------- | ------------------------------------------------------------------------- | -| | | - -使用说明 - -1. 点击Call按钮依据预先设定的参数(如 SM4 算法、PIN认证等)生成密钥。 - -## 细粒度用户身份认证访问控制开发指导 - -### 介绍 - -1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/UniversalKeystoreKit/huks-refined-user-identity-authentication.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 - -#### FineGrainedUserIdentityAuthentication - -##### 介绍 - -1. 本示例主要介绍细粒度用户身份认证访问控制,允许设置密钥在加密、解密、签名、验签、密钥协商、密钥派生的单个或多个场景时是否需要进行身份验证。 - -##### 效果预览 - -| 主页 | 跳转页 | -| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | -| | | - -使用说明 - -1. 点击Call 按钮生成一个基于 SM4 算法、支持PIN认证且在解密时需身份验证的密钥。 - -## 工程目录 - -``` -entry/src/main/ -|---ets -|---|---entryability -|---|---|---EntryAbility.ets -|---|---pages -|---|---|---Index.ets // 首页 -|---|---|---FineGrainedUserIdentityAuthentication.ets -|---|---|---UserIdentityAuthentication.ets -|---cpp -|---resources // 静态资源 -|---ohosTest -|---|---ets -|---|---|---tests -|---|---|---|---AccessControl.test.ets // 自动化测试用例 -``` - -## 相关权限 - -[ohos.permission.ACCESS_BIOMETRIC](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccessbiometric) - -## 依赖 - -不涉及。 - -## 约束与限制 - -1. 本示例仅支持标准系统上运行,支持设备:RK3568。 -2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 -3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 - -## 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` +## 用户身份认证访问控制开发指导 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/UniversalKeystoreKit/huks-user-identity-authentication.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### UserIdentityAuthentication + +##### 介绍 + +1. 本示例主要介绍实现用户身份认证访问控制,确保只有经过PIN认证的用户才能对加密数据进行操作。 + +##### 效果预览 + +| 主页 | 删除 | +| ------------------------------------------------------------------------- | ------------------------------------------------------------------------- | +| | | + +使用说明 + +1. 点击Call按钮依据预先设定的参数(如 SM4 算法、PIN认证等)生成密钥。 + +## 细粒度用户身份认证访问控制开发指导 + +### 介绍 + +1. 本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/UniversalKeystoreKit/huks-refined-user-identity-authentication.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 + +#### FineGrainedUserIdentityAuthentication + +##### 介绍 + +1. 本示例主要介绍细粒度用户身份认证访问控制,允许设置密钥在加密、解密、签名、验签、密钥协商、密钥派生的单个或多个场景时是否需要进行身份验证。 + +##### 效果预览 + +| 主页 | 跳转页 | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | +| | | + +使用说明 + +1. 点击Call 按钮生成一个基于 SM4 算法、支持PIN认证且在解密时需身份验证的密钥。 + +## 工程目录 + +``` +entry/src/main/ +|---ets +|---|---entryability +|---|---|---EntryAbility.ets +|---|---pages +|---|---|---Index.ets // 首页 +|---|---|---FineGrainedUserIdentityAuthentication.ets +|---|---|---UserIdentityAuthentication.ets +|---cpp +|---resources // 静态资源 +|---ohosTest +|---|---ets +|---|---|---tests +|---|---|---|---AccessControl.test.ets // 自动化测试用例 +``` + +## 相关权限 + +[ohos.permission.ACCESS_BIOMETRIC](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionaccessbiometric) + +## 依赖 + +不涉及。 + +## 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:RK3568。 +2. 本示例支持API14版本SDK,SDK版本号(API Version 14 Release)。 +3. 本示例需要使用DevEco Studio 版本号(5.0.1Release)才可编译运行。 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl > .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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/build-profile.json5 old mode 100755 new mode 100644 index d903787c46ed450cc00125d16a590de4577538f5..7acbde12b146c7793fc992e5af8ed99d6ed67f31 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "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/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/code-linter.json5 old mode 100755 new mode 100644 index 9deb9807637aa27ebde62e61e2362a417aacdc04..28586467ee7a761c737d8654a73aed6fddbc3c71 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/code-linter.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/code-linter.json5 @@ -1,35 +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": { - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/.gitignore old mode 100755 new mode 100644 index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..e2713a2779c5a3e0eb879efe6115455592caeea5 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/.gitignore +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/.gitignore @@ -1,6 +1,6 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx +/node_modules +/oh_modules +/.preview +/build +/.cxx /.test \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/build-profile.json5 old mode 100755 new mode 100644 index b4d65d490ef6cbe22d933b9231555210f1555786..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/hvigorfile.ts old mode 100755 new mode 100644 index 46872af92274609fb7926a0eb6451cebbb18afef..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/hvigorfile.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/hvigorfile.ts @@ -1,21 +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. */ -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/oh-package.json5 old mode 100755 new mode 100644 index 4bf3e2a9b1ae7381cf9363dff1cbcc1861a41e7b..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/FineGrainedUserIdentityAuthentication.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/FineGrainedUserIdentityAuthentication.ets old mode 100755 new mode 100644 index 0bc3920045029cfd4217e441dd2d9ce893c41533..e0614e86bc356c8bcee9f7b5b5ad816efbea1b75 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/FineGrainedUserIdentityAuthentication.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/FineGrainedUserIdentityAuthentication.ets @@ -1,442 +1,442 @@ -/* - * 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 { huks } from '@kit.UniversalKeystoreKit'; -import { userAuth } from '@kit.UserAuthenticationKit'; -import { BusinessError } from '@kit.BasicServicesKit'; - -let keyAlias = 'test_sm4_key_alias'; -let cipherInData = 'Hks_SM4_Cipher_Test_101010101010101010110_string'; // 明文数据。 -let IV = '1234567890123456'; -let handle = 0; -let cipherText: Uint8Array; // 密文数据。 -let finishOutData: Uint8Array; // 解密后的明文数据。 -let authToken: Uint8Array; -let challenge: Uint8Array; -let authType = userAuth.UserAuthType.PIN; -let authTrustLevel = userAuth.AuthTrustLevel.ATL1; - -class ThrowObject { - public isThrow: boolean = false; -} - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -/* - * 确定封装密钥属性参数集 - */ -let generateProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM4, - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, - }, - { - tag: huks.HuksTag.HUKS_TAG_USER_AUTH_TYPE, - value: huks.HuksUserAuthType.HUKS_USER_AUTH_TYPE_PIN - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_AUTH_ACCESS_TYPE, - value: huks.HuksAuthAccessType.HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD - }, - { - tag: huks.HuksTag.HUKS_TAG_CHALLENGE_TYPE, - value: huks.HuksChallengeType.HUKS_CHALLENGE_TYPE_NORMAL - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_AUTH_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - } -]; - -let generateHuksOptions: huks.HuksOptions = { - properties: generateProperties, - inData: new Uint8Array([]) -} - -/* - * 生成密钥 - */ -async function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: true }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: generateKeyItem failed` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid` + JSON.stringify(error)); - throw (error as Error); - } -} - -async function testGenKeyForFingerprintAccessControl() { - await publicGenKeyFunc(keyAlias, generateHuksOptions); -} - -class HuksProperties { - public tag: huks.HuksTag = huks.HuksTag.HUKS_TAG_ALGORITHM; - public value: huks.HuksKeyAlg | huks.HuksKeySize | huks.HuksKeyPurpose | huks.HuksKeyPadding | huks.HuksCipherMode - | Uint8Array = huks.HuksKeyAlg.HUKS_ALG_ECC; -} - -/* - * 确定封装密钥属性参数集 - */ - -/* 集成生成密钥参数集 & 加密参数集 */ -let propertiesEncrypt: HuksProperties[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM4, - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, - }, - { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV), - } -]; -let encryptOptions: huks.HuksOptions = { - properties: propertiesEncrypt, - inData: new Uint8Array([]) -} - -function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.initSession(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise doInit`); - let throwObject: ThrowObject = { isThrow: true }; - try { - await initSession(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - handle = data.handle as number; - challenge = data.challenge as Uint8Array; - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doInit failed` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: doInit input arg invalid` + JSON.stringify(error)); - throw (error as Error); - } -} - -function finishEncryptSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.finishSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicEncryptFinishFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doFinish`); - let throwObject: ThrowObject = { isThrow: true }; - try { - await finishEncryptSession(handle, huksOptions, throwObject) - .then((data) => { - cipherText = data.outData as Uint8Array; - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doFinish failed` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid` + JSON.stringify(error)); - throw (error as Error); - } -} - -async function testSm4Cipher() { - /* 初始化密钥会话获取挑战值 */ - await publicInitFunc(keyAlias, encryptOptions); - /* 加密 */ - encryptOptions.inData = stringToUint8Array(cipherInData); - await publicEncryptFinishFunc(handle, encryptOptions); -} - -/* 集成生成密钥参数集 & 加密参数集 */ -class PropertyDecryptType { - public tag: huks.HuksTag = huks.HuksTag.HUKS_TAG_ALGORITHM - public value: huks.HuksKeyAlg | huks.HuksKeyPurpose | huks.HuksKeySize | huks.HuksKeyPadding | huks.HuksCipherMode - | Uint8Array = huks.HuksKeyAlg.HUKS_ALG_SM4 -} - -let propertiesDecrypt: PropertyDecryptType[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM4, - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, - }, - { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV), - } -] -let decryptOptions: huks.HuksOptions = { - properties: propertiesDecrypt, - inData: new Uint8Array([]) -} - -function userIAMAuthFinger(huksChallenge: Uint8Array) { - // 获取认证对象。 - let authTypeList: userAuth.UserAuthType[] = [authType]; - const authParam: userAuth.AuthParam = { - challenge: huksChallenge, - authType: authTypeList, - authTrustLevel: authTrustLevel - }; - const widgetParam: userAuth.WidgetParam = { - title: 'PIN', - }; - let auth: userAuth.UserAuthInstance; - try { - auth = userAuth.getUserAuthInstance(authParam, widgetParam); - console.info('get auth instance success'); - } catch (error) { - console.error('get auth instance failed' + JSON.stringify(error)); - throw (error as Error); - } - // 订阅认证结果。 - try { - auth.on('result', { - onResult(result) { - console.info('[HUKS] -> [IAM] userAuthInstance callback result = ' + JSON.stringify(result)); - authToken = result.token; - testSm4CipherFinish(); - } - }); - console.info('subscribe authentication event success'); - } catch (error) { - console.error('subscribe authentication event failed ' + JSON.stringify(error)); - throw (error as Error); - } - // 开始认证。 - try { - auth.start(); - console.info('authV9 start auth success'); - } catch (error) { - console.error('authV9 start auth failed, error = ' + JSON.stringify(error)); - throw (error as Error); - } -} - -function finishDecryptSession(handle: number, huksOptions: huks.HuksOptions, token: Uint8Array, - throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.finishSession(handle, huksOptions, token, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicDecryptFinishFunc(handle: number, token: Uint8Array, huksOptions: huks.HuksOptions) { - console.info(`enter promise doFinish`); - let throwObject: ThrowObject = { isThrow: true }; - try { - await finishDecryptSession(handle, huksOptions, token, throwObject) - .then((data) => { - finishOutData = data.outData as Uint8Array; - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - }) - .catch((error: BusinessError) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doFinish failed` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid` + JSON.stringify(error)); - throw (error as Error); - } -} - -async function testSm4CipherInit() { - /* 初始化密钥会话获取挑战值 */ - await publicInitFunc(keyAlias, decryptOptions); - /* 调用userIAM进行身份认证 */ - console.log('challenge value: ' + challenge.toString()); - userIAMAuthFinger(challenge); -} - -async function testSm4CipherFinish() { - /* 认证成功后进行解密, 需要传入Auth获取到的authToken值 */ - decryptOptions.inData = cipherText; - await publicDecryptFinishFunc(handle, authToken, decryptOptions); - if (finishOutData === stringToUint8Array(cipherInData)) { - console.error('test finish decrypt error'); - } else { - console.info('test finish decrypt success'); - } -} - -async function main() { - await testGenKeyForFingerprintAccessControl(); - await testSm4Cipher(); - await testSm4CipherInit(); -} - -@Entry -@Component -struct Index { - @State message: string = 'FineGrainedUserIdentityAuthentication'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.fine_grained_user_identity_authentication_call')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await main(); - this.message = 'Call Result: Success'; - } catch (error) { - this.message = 'Call Result: Failed' + error.message; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; +import { userAuth } from '@kit.UserAuthenticationKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let keyAlias = 'test_sm4_key_alias'; +let cipherInData = 'Hks_SM4_Cipher_Test_101010101010101010110_string'; // 明文数据。 +let IV = '1234567890123456'; +let handle = 0; +let cipherText: Uint8Array; // 密文数据。 +let finishOutData: Uint8Array; // 解密后的明文数据。 +let authToken: Uint8Array; +let challenge: Uint8Array; +let authType = userAuth.UserAuthType.PIN; +let authTrustLevel = userAuth.AuthTrustLevel.ATL1; + +class ThrowObject { + public isThrow: boolean = false; +} + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +/* + * 确定封装密钥属性参数集 + */ +let generateProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM4, + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, + }, + { + tag: huks.HuksTag.HUKS_TAG_USER_AUTH_TYPE, + value: huks.HuksUserAuthType.HUKS_USER_AUTH_TYPE_PIN + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_AUTH_ACCESS_TYPE, + value: huks.HuksAuthAccessType.HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD + }, + { + tag: huks.HuksTag.HUKS_TAG_CHALLENGE_TYPE, + value: huks.HuksChallengeType.HUKS_CHALLENGE_TYPE_NORMAL + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_AUTH_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + } +]; + +let generateHuksOptions: huks.HuksOptions = { + properties: generateProperties, + inData: new Uint8Array([]) +} + +/* + * 生成密钥 + */ +async function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: true }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: generateKeyItem failed` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid` + JSON.stringify(error)); + throw (error as Error); + } +} + +async function testGenKeyForFingerprintAccessControl() { + await publicGenKeyFunc(keyAlias, generateHuksOptions); +} + +class HuksProperties { + public tag: huks.HuksTag = huks.HuksTag.HUKS_TAG_ALGORITHM; + public value: huks.HuksKeyAlg | huks.HuksKeySize | huks.HuksKeyPurpose | huks.HuksKeyPadding | huks.HuksCipherMode + | Uint8Array = huks.HuksKeyAlg.HUKS_ALG_ECC; +} + +/* + * 确定封装密钥属性参数集 + */ + +/* 集成生成密钥参数集 & 加密参数集 */ +let propertiesEncrypt: HuksProperties[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM4, + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, + }, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV), + } +]; +let encryptOptions: huks.HuksOptions = { + properties: propertiesEncrypt, + inData: new Uint8Array([]) +} + +function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.initSession(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise doInit`); + let throwObject: ThrowObject = { isThrow: true }; + try { + await initSession(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle as number; + challenge = data.challenge as Uint8Array; + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doInit failed` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: doInit input arg invalid` + JSON.stringify(error)); + throw (error as Error); + } +} + +function finishEncryptSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.finishSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicEncryptFinishFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doFinish`); + let throwObject: ThrowObject = { isThrow: true }; + try { + await finishEncryptSession(handle, huksOptions, throwObject) + .then((data) => { + cipherText = data.outData as Uint8Array; + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doFinish failed` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid` + JSON.stringify(error)); + throw (error as Error); + } +} + +async function testSm4Cipher() { + /* 初始化密钥会话获取挑战值 */ + await publicInitFunc(keyAlias, encryptOptions); + /* 加密 */ + encryptOptions.inData = stringToUint8Array(cipherInData); + await publicEncryptFinishFunc(handle, encryptOptions); +} + +/* 集成生成密钥参数集 & 加密参数集 */ +class PropertyDecryptType { + public tag: huks.HuksTag = huks.HuksTag.HUKS_TAG_ALGORITHM + public value: huks.HuksKeyAlg | huks.HuksKeyPurpose | huks.HuksKeySize | huks.HuksKeyPadding | huks.HuksCipherMode + | Uint8Array = huks.HuksKeyAlg.HUKS_ALG_SM4 +} + +let propertiesDecrypt: PropertyDecryptType[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM4, + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, + }, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV), + } +] +let decryptOptions: huks.HuksOptions = { + properties: propertiesDecrypt, + inData: new Uint8Array([]) +} + +function userIAMAuthFinger(huksChallenge: Uint8Array) { + // 获取认证对象。 + let authTypeList: userAuth.UserAuthType[] = [authType]; + const authParam: userAuth.AuthParam = { + challenge: huksChallenge, + authType: authTypeList, + authTrustLevel: authTrustLevel + }; + const widgetParam: userAuth.WidgetParam = { + title: 'PIN', + }; + let auth: userAuth.UserAuthInstance; + try { + auth = userAuth.getUserAuthInstance(authParam, widgetParam); + console.info('get auth instance success'); + } catch (error) { + console.error('get auth instance failed' + JSON.stringify(error)); + throw (error as Error); + } + // 订阅认证结果。 + try { + auth.on('result', { + onResult(result) { + console.info('[HUKS] -> [IAM] userAuthInstance callback result = ' + JSON.stringify(result)); + authToken = result.token; + testSm4CipherFinish(); + } + }); + console.info('subscribe authentication event success'); + } catch (error) { + console.error('subscribe authentication event failed ' + JSON.stringify(error)); + throw (error as Error); + } + // 开始认证。 + try { + auth.start(); + console.info('authV9 start auth success'); + } catch (error) { + console.error('authV9 start auth failed, error = ' + JSON.stringify(error)); + throw (error as Error); + } +} + +function finishDecryptSession(handle: number, huksOptions: huks.HuksOptions, token: Uint8Array, + throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.finishSession(handle, huksOptions, token, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicDecryptFinishFunc(handle: number, token: Uint8Array, huksOptions: huks.HuksOptions) { + console.info(`enter promise doFinish`); + let throwObject: ThrowObject = { isThrow: true }; + try { + await finishDecryptSession(handle, huksOptions, token, throwObject) + .then((data) => { + finishOutData = data.outData as Uint8Array; + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + }) + .catch((error: BusinessError) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doFinish failed` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid` + JSON.stringify(error)); + throw (error as Error); + } +} + +async function testSm4CipherInit() { + /* 初始化密钥会话获取挑战值 */ + await publicInitFunc(keyAlias, decryptOptions); + /* 调用userIAM进行身份认证 */ + console.log('challenge value: ' + challenge.toString()); + userIAMAuthFinger(challenge); +} + +async function testSm4CipherFinish() { + /* 认证成功后进行解密, 需要传入Auth获取到的authToken值 */ + decryptOptions.inData = cipherText; + await publicDecryptFinishFunc(handle, authToken, decryptOptions); + if (finishOutData === stringToUint8Array(cipherInData)) { + console.error('test finish decrypt error'); + } else { + console.info('test finish decrypt success'); + } +} + +async function main() { + await testGenKeyForFingerprintAccessControl(); + await testSm4Cipher(); + await testSm4CipherInit(); +} + +@Entry +@Component +struct Index { + @State message: string = 'FineGrainedUserIdentityAuthentication'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.fine_grained_user_identity_authentication_call')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await main(); + this.message = 'Call Result: Success'; + } catch (error) { + this.message = 'Call Result: Failed' + error.message; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index c09773e820268ac5571a58147803f772e9e769d3..e012e25431385cb41b6a4e5eb139561e43d60375 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/Index.ets @@ -1,67 +1,67 @@ -/* - * 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 { router } from '@kit.ArkUI'; - -@Entry -@Component -struct Index { - @State message: string = 'AccessControl'; - - goToSample(url: string): void { - router.pushUrl({ - url: url, - }, router.RouterMode.Single, (err) => { - if (err) { - console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info('pushUrl success'); - }) - } - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button('UserIdentityAuthentication') - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - this.goToSample('pages/UserIdentityAuthentication'); - }) - Button('FineGrainedUserIdentityAuthentication') - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - this.goToSample('pages/FineGrainedUserIdentityAuthentication'); - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'AccessControl'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button('UserIdentityAuthentication') + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + this.goToSample('pages/UserIdentityAuthentication'); + }) + Button('FineGrainedUserIdentityAuthentication') + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + this.goToSample('pages/FineGrainedUserIdentityAuthentication'); + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/UserIdentityAuthentication.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/UserIdentityAuthentication.ets old mode 100755 new mode 100644 index a89e9303affd1137c13e9cd42919879dd349dbe8..2fa41d7e77dd32a16251ad1655c0e50a84c23c73 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/UserIdentityAuthentication.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/ets/pages/UserIdentityAuthentication.ets @@ -1,415 +1,415 @@ -/* - * 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 { huks } from '@kit.UniversalKeystoreKit'; -import { userAuth } from '@kit.UserAuthenticationKit'; - -/* -* 确定密钥别名和封装密钥属性参数集 -*/ -let keyAlias = 'test_sm4_key_alias'; -let IV = '1234567890123456'; -let handle: number; -let challenge: Uint8Array; -let fingerAuthToken: Uint8Array; -let authType = userAuth.UserAuthType.PIN; -let authTrustLevel = userAuth.AuthTrustLevel.ATL1; -let cipherInData = 'Hks_SM4_Cipher_Test_101010101010101010110_string'; -let finishOutData: Uint8Array; - -class ThrowObject { - public isThrow: boolean = false; -} - -let generateProperties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM4 -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, -}, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, -}, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, -}, - // 指定密钥身份认证的类型:PIN。 - { - tag: huks.HuksTag.HUKS_TAG_USER_AUTH_TYPE, - value: huks.HuksUserAuthType.HUKS_USER_AUTH_TYPE_PIN - }, - // 指定密钥安全授权的类型(失效类型):新录入生物特征(PIN)后无效。 - { - tag: huks.HuksTag.HUKS_TAG_KEY_AUTH_ACCESS_TYPE, - value: huks.HuksAuthAccessType.HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD - }, - // 指定挑战值的类型:默认类型。 - { - tag: huks.HuksTag.HUKS_TAG_CHALLENGE_TYPE, - value: huks.HuksChallengeType.HUKS_CHALLENGE_TYPE_NORMAL - }]; - -let generateHuksOptions: huks.HuksOptions = { - properties: generateProperties, - inData: new Uint8Array([]) -} - -/* - * 生成密钥 - */ - -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: true }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - console.error(`promise: generateKeyItem failed, ` + JSON.stringify(error)); - throw (error as Error); - } else { - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -async function testGenKeyForFingerprintAccessControl() { - await publicGenKeyFunc(keyAlias, generateHuksOptions); -} - -/* 集成生成密钥参数集 & 加密参数集 */ -let initProperties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM4, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, -}, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, -}, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV), -}]; - -let initHuksOptions: huks.HuksOptions = { - properties: initProperties, - inData: new Uint8Array([]) -} - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.initSession(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 初始化HUKS中的会话,获取挑战值 */ -async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise doInit`); - let throwObject: ThrowObject = { isThrow: true }; - try { - await initSession(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - handle = data.handle; - challenge = data.challenge as Uint8Array; - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doInit failed, ` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: doInit input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -/* 调用UserIAM拉起认证,触发HUKS的访问控制流程 */ -function userIAMAuthFinger(huksChallenge: Uint8Array) { - // 获取认证对象。 - let authTypeList: userAuth.UserAuthType[] = [authType]; - const authParam: userAuth.AuthParam = { - challenge: huksChallenge, - authType: authTypeList, - authTrustLevel: authTrustLevel - }; - const widgetParam: userAuth.WidgetParam = { - title: 'PIN', - }; - let auth: userAuth.UserAuthInstance; - try { - auth = userAuth.getUserAuthInstance(authParam, widgetParam); - console.info('get auth instance success'); - } catch (error) { - console.error('get auth instance failed' + JSON.stringify(error)); - throw (error as Error); - } - // 订阅认证结果。 - try { - auth.on('result', { - onResult(result) { - console.info('[HUKS] -> [IAM] userAuthInstance callback result = ' + JSON.stringify(result)); - fingerAuthToken = result.token; - testSm4Cipher(); - } - }); - console.log('subscribe authentication event success'); - } catch (error) { - console.error('subscribe authentication event failed, ' + JSON.stringify(error)); - throw (error as Error); - } - // 开始认证。 - try { - auth.start(); - console.info('authV9 start auth success'); - } catch (error) { - console.error('authV9 start auth failed, error = ' + JSON.stringify(error)); - throw (error as Error); - } -} - -async function testInitAndAuthFinger() { - /* 初始化密钥会话获取挑战值 */ - await publicInitFunc(keyAlias, initHuksOptions); - /* 调用userIAM进行身份认证 */ - console.log('challenge value: ' + challenge.toString()); - userIAMAuthFinger(challenge); -} - -/* 集成生成密钥参数集 & 加密参数集 */ -class PropertyEncryptType { - public tag: huks.HuksTag = huks.HuksTag.HUKS_TAG_ALGORITHM; - public value: huks.HuksKeyAlg | huks.HuksKeyPurpose | huks.HuksKeySize | huks.HuksKeyPadding | huks.HuksCipherMode - | Uint8Array = huks.HuksKeyAlg.HUKS_ALG_SM4; -} - -let propertiesEncrypt: PropertyEncryptType[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM4, - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, - }, - { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, - }, - { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, - }, - { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV), - } -] -let encryptOptions: huks.HuksOptions = { - properties: propertiesEncrypt, - inData: new Uint8Array([]) -} - -function updateSession(handle: number, huksOptions: huks.HuksOptions, token: Uint8Array, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.updateSession(handle, huksOptions, token, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicUpdateFunc(handle: number, token: Uint8Array, huksOptions: huks.HuksOptions) { - console.info(`enter promise doUpdate`); - let throwObject: ThrowObject = { isThrow: true }; - console.log('token value[publicUpdateFunc]:' + token) - try { - await updateSession(handle, huksOptions, token, throwObject) - .then((data) => { - console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doUpdate failed, ` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: doUpdate input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -function finishSession(handle: number, huksOptions: huks.HuksOptions, token: Uint8Array, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.finishSession(handle, huksOptions, token, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicFinishFunc(handle: number, token: Uint8Array, huksOptions: huks.HuksOptions) { - console.info(`enter promise doFinish`); - let throwObject: ThrowObject = { isThrow: false }; - console.log('token value[publicFinishFunc]:' + token) - try { - await finishSession(handle, huksOptions, token, throwObject) - .then((data) => { - finishOutData = data.outData as Uint8Array; - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doFinish failed, ` + JSON.stringify(error)); - } - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid, ` + JSON.stringify(error)); - throw (error as Error); - } -} - -async function testSm4Cipher() { - encryptOptions.inData = stringToUint8Array(cipherInData); - /* 传入认证令牌 */ - await publicUpdateFunc(handle, fingerAuthToken, encryptOptions); - /* 传入认证令牌 */ - console.log('continue publicFinishFunc'); - await publicFinishFunc(handle, fingerAuthToken, encryptOptions); - console.log('end publicFinishFunc'); - if (finishOutData === stringToUint8Array(cipherInData)) { - console.error('test finish encrypt error'); - } else { - console.info('test finish encrypt success'); - } -} - -async function main() { - await testGenKeyForFingerprintAccessControl(); - await testInitAndAuthFinger(); -} - -@Entry -@Component -struct Index { - @State message: string = 'UserIdentityAuthentication'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.user_identity_authentication')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await main(); - this.message = 'Call Result: Success'; - } catch (error) { - this.message = 'Call Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; +import { userAuth } from '@kit.UserAuthenticationKit'; + +/* +* 确定密钥别名和封装密钥属性参数集 +*/ +let keyAlias = 'test_sm4_key_alias'; +let IV = '1234567890123456'; +let handle: number; +let challenge: Uint8Array; +let fingerAuthToken: Uint8Array; +let authType = userAuth.UserAuthType.PIN; +let authTrustLevel = userAuth.AuthTrustLevel.ATL1; +let cipherInData = 'Hks_SM4_Cipher_Test_101010101010101010110_string'; +let finishOutData: Uint8Array; + +class ThrowObject { + public isThrow: boolean = false; +} + +let generateProperties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM4 +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, +}, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, +}, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, +}, + // 指定密钥身份认证的类型:PIN。 + { + tag: huks.HuksTag.HUKS_TAG_USER_AUTH_TYPE, + value: huks.HuksUserAuthType.HUKS_USER_AUTH_TYPE_PIN + }, + // 指定密钥安全授权的类型(失效类型):新录入生物特征(PIN)后无效。 + { + tag: huks.HuksTag.HUKS_TAG_KEY_AUTH_ACCESS_TYPE, + value: huks.HuksAuthAccessType.HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD + }, + // 指定挑战值的类型:默认类型。 + { + tag: huks.HuksTag.HUKS_TAG_CHALLENGE_TYPE, + value: huks.HuksChallengeType.HUKS_CHALLENGE_TYPE_NORMAL + }]; + +let generateHuksOptions: huks.HuksOptions = { + properties: generateProperties, + inData: new Uint8Array([]) +} + +/* + * 生成密钥 + */ + +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: true }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + console.error(`promise: generateKeyItem failed, ` + JSON.stringify(error)); + throw (error as Error); + } else { + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +async function testGenKeyForFingerprintAccessControl() { + await publicGenKeyFunc(keyAlias, generateHuksOptions); +} + +/* 集成生成密钥参数集 & 加密参数集 */ +let initProperties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM4, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, +}, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, +}, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV), +}]; + +let initHuksOptions: huks.HuksOptions = { + properties: initProperties, + inData: new Uint8Array([]) +} + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.initSession(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 初始化HUKS中的会话,获取挑战值 */ +async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise doInit`); + let throwObject: ThrowObject = { isThrow: true }; + try { + await initSession(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + challenge = data.challenge as Uint8Array; + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doInit failed, ` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +/* 调用UserIAM拉起认证,触发HUKS的访问控制流程 */ +function userIAMAuthFinger(huksChallenge: Uint8Array) { + // 获取认证对象。 + let authTypeList: userAuth.UserAuthType[] = [authType]; + const authParam: userAuth.AuthParam = { + challenge: huksChallenge, + authType: authTypeList, + authTrustLevel: authTrustLevel + }; + const widgetParam: userAuth.WidgetParam = { + title: 'PIN', + }; + let auth: userAuth.UserAuthInstance; + try { + auth = userAuth.getUserAuthInstance(authParam, widgetParam); + console.info('get auth instance success'); + } catch (error) { + console.error('get auth instance failed' + JSON.stringify(error)); + throw (error as Error); + } + // 订阅认证结果。 + try { + auth.on('result', { + onResult(result) { + console.info('[HUKS] -> [IAM] userAuthInstance callback result = ' + JSON.stringify(result)); + fingerAuthToken = result.token; + testSm4Cipher(); + } + }); + console.log('subscribe authentication event success'); + } catch (error) { + console.error('subscribe authentication event failed, ' + JSON.stringify(error)); + throw (error as Error); + } + // 开始认证。 + try { + auth.start(); + console.info('authV9 start auth success'); + } catch (error) { + console.error('authV9 start auth failed, error = ' + JSON.stringify(error)); + throw (error as Error); + } +} + +async function testInitAndAuthFinger() { + /* 初始化密钥会话获取挑战值 */ + await publicInitFunc(keyAlias, initHuksOptions); + /* 调用userIAM进行身份认证 */ + console.log('challenge value: ' + challenge.toString()); + userIAMAuthFinger(challenge); +} + +/* 集成生成密钥参数集 & 加密参数集 */ +class PropertyEncryptType { + public tag: huks.HuksTag = huks.HuksTag.HUKS_TAG_ALGORITHM; + public value: huks.HuksKeyAlg | huks.HuksKeyPurpose | huks.HuksKeySize | huks.HuksKeyPadding | huks.HuksCipherMode + | Uint8Array = huks.HuksKeyAlg.HUKS_ALG_SM4; +} + +let propertiesEncrypt: PropertyEncryptType[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM4, + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT, + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM4_KEY_SIZE_128, + }, + { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, + }, + { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, + }, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV), + } +] +let encryptOptions: huks.HuksOptions = { + properties: propertiesEncrypt, + inData: new Uint8Array([]) +} + +function updateSession(handle: number, huksOptions: huks.HuksOptions, token: Uint8Array, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.updateSession(handle, huksOptions, token, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicUpdateFunc(handle: number, token: Uint8Array, huksOptions: huks.HuksOptions) { + console.info(`enter promise doUpdate`); + let throwObject: ThrowObject = { isThrow: true }; + console.log('token value[publicUpdateFunc]:' + token) + try { + await updateSession(handle, huksOptions, token, throwObject) + .then((data) => { + console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doUpdate failed, ` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +function finishSession(handle: number, huksOptions: huks.HuksOptions, token: Uint8Array, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.finishSession(handle, huksOptions, token, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicFinishFunc(handle: number, token: Uint8Array, huksOptions: huks.HuksOptions) { + console.info(`enter promise doFinish`); + let throwObject: ThrowObject = { isThrow: false }; + console.log('token value[publicFinishFunc]:' + token) + try { + await finishSession(handle, huksOptions, token, throwObject) + .then((data) => { + finishOutData = data.outData as Uint8Array; + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doFinish failed, ` + JSON.stringify(error)); + } + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid, ` + JSON.stringify(error)); + throw (error as Error); + } +} + +async function testSm4Cipher() { + encryptOptions.inData = stringToUint8Array(cipherInData); + /* 传入认证令牌 */ + await publicUpdateFunc(handle, fingerAuthToken, encryptOptions); + /* 传入认证令牌 */ + console.log('continue publicFinishFunc'); + await publicFinishFunc(handle, fingerAuthToken, encryptOptions); + console.log('end publicFinishFunc'); + if (finishOutData === stringToUint8Array(cipherInData)) { + console.error('test finish encrypt error'); + } else { + console.info('test finish encrypt success'); + } +} + +async function main() { + await testGenKeyForFingerprintAccessControl(); + await testInitAndAuthFinger(); +} + +@Entry +@Component +struct Index { + @State message: string = 'UserIdentityAuthentication'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.user_identity_authentication')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await main(); + this.message = 'Call Result: Success'; + } catch (error) { + this.message = 'Call Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/module.json5 old mode 100755 new mode 100644 index c16511ef424489ffd26122b867084ed73759a165..9a475d7e2c0f3d598e37b05c4de61e5c61efd9df --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/module.json5 @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "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" - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.ACCESS_BIOMETRIC" - } - ] - } +/* + * 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" + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_BIOMETRIC" + } + ] + } } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/float.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/float.json old mode 100755 new mode 100644 index 5f0600c7083c3ac3776dcc13ce3e3f03c378fc6d..a0a93dd91fd48f08f3a9532c76e9b26e68d4c034 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/float.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/float.json @@ -1,8 +1,8 @@ -{ - "float": [ - { - "name": "page_text_font_size", - "value": "50fp" - } - ] +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 index 24b1814c51712c19b5976b2e06330acdb7e8e7b8..dd4d93181a69ec9a45ffbef5c4d09aae705eb103 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/element/string.json @@ -1,24 +1,24 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "AccessControl" - }, - { - "name": "fine_grained_user_identity_authentication_call", - "value": "Call" - }, - { - "name": "user_identity_authentication", - "value": "Call" - } - ] -} +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "AccessControl" + }, + { + "name": "fine_grained_user_identity_authentication_call", + "value": "Call" + }, + { + "name": "user_identity_authentication", + "value": "Call" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 index 16cf3219a2997a071cd6f0cd4816d3e173b18d15..fb49920440fb4d246c82f9ada275e26123a2136a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/layered_image.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/layered_image.json @@ -1,7 +1,7 @@ -{ - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" - } +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 index 107bdba988af2050a2236f2d4c1cdcc97c5e6b6a..49a1be3eb9f9a717fe1c9c59a70414595a21cb96 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/main_pages.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/base/profile/main_pages.json @@ -1,7 +1,7 @@ -{ - "src": [ - "pages/Index", - "pages/FineGrainedUserIdentityAuthentication", - "pages/UserIdentityAuthentication" - ] +{ + "src": [ + "pages/Index", + "pages/FineGrainedUserIdentityAuthentication", + "pages/UserIdentityAuthentication" + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 index 9d4f8a434d863461a900661b39dc7ac9808997e2..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/AccessControl.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/AccessControl.test.ets old mode 100755 new mode 100644 index fd70984c805aa0a8cfa80ebb0d8327e60b52cf92..55cf08dbcd934777a0c72520116ea5f29f987b56 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/AccessControl.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/AccessControl.test.ets @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { describe, it, expect, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function accessControlTest() { - describe('accessControlTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,用户身份认证访问控制 - */ - it('testAccessControl001', 0, async () => { - console.info('uitest: testAccessControl001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('UserIdentityAuthentication')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(5000); - const button2 = await driver.findComponent(ON.text('Call')); - await button2.click(); - await driver.delayMs(10000); - await driver.assertComponentExist(ON.text('Call Result: Success')); - console.info('uitest: testAccessControl001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,细粒度用户身份认证访问控制 - */ - it('testAccessControl002', 0, async () => { - console.info('uitest: testAccessControl002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('FineGrainedUserIdentityAuthentication')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call')); - await button2.click(); - await driver.delayMs(10000); - await driver.assertComponentExist(ON.text('Call Result: Success')); - console.info('uitest: testAccessControl002 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function accessControlTest() { + describe('accessControlTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,用户身份认证访问控制 + */ + it('testAccessControl001', 0, async () => { + console.info('uitest: testAccessControl001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('UserIdentityAuthentication')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(5000); + const button2 = await driver.findComponent(ON.text('Call')); + await button2.click(); + await driver.delayMs(10000); + await driver.assertComponentExist(ON.text('Call Result: Success')); + console.info('uitest: testAccessControl001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,细粒度用户身份认证访问控制 + */ + it('testAccessControl002', 0, async () => { + console.info('uitest: testAccessControl002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('FineGrainedUserIdentityAuthentication')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call')); + await button2.click(); + await driver.delayMs(10000); + await driver.assertComponentExist(ON.text('Call Result: Success')); + console.info('uitest: testAccessControl002 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 index 628014e135de912429c73f28f5529b48d5abc498..d923f98577a9bdd74c848705553d310aef1d143b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +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 accessControlTest from './AccessControl.test'; - -export default function testsuite() { - accessControlTest(); -} +/* + * 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 accessControlTest from './AccessControl.test'; + +export default function testsuite() { + accessControlTest(); +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigorfile.ts old mode 100755 new mode 100644 index 2db60fa91881f6961e5def61af680301d22a1341..2a5e543f190732c159beb574dfc9fa37bc94e156 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigorfile.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/hvigorfile.ts @@ -1,21 +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. */ -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/AccessControl/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/ohosTest.md old mode 100755 new mode 100644 index 0333efcb58a81523e8ef1c927501e713ff21558f..c32f4adb8f3c485df8d4df0f1a21038a45521ef9 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/ohosTest.md @@ -1,9 +1,9 @@ -# 访问控制测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------- | ------------ | ---- | ---------------- | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮, 用户身份认证访问控制 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | +# 访问控制测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------- | ------------ | ---- | ---------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮, 用户身份认证访问控制 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | | 点击按钮, 细粒度用户身份认证访问控制 | 成功拉起应用 | | 成功新增输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/FineGrainedUserIdentityAuthentication_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/FineGrainedUserIdentityAuthentication_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/FineGrainedUserIdentityAuthentication_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/FineGrainedUserIdentityAuthentication_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/UserIdentityAuthentication_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/UserIdentityAuthentication_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/UserIdentityAuthentication_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/AccessControl/screenshots/UserIdentityAuthentication_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/app.json5 old mode 100755 new mode 100644 index 50a8887628c839f7bed08d4e95f2737cedefa379..ad9bc7f08ab6ca06bac9378776be927ff6c9f375 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/app.json5 @@ -1,25 +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.encryptiondecryption", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.encryptiondecryption", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index ba04620cde177e5f93811ca9007b506019f8324a..3e3fade23715f562a60093d1ac694b18eae2f045 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EncryptionDecryption" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EncryptionDecryption" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index ab0e49ba07d2ad6087ae39215500b5390532c441..870045a54ae1426a9af5261da9ccf3f702039589 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(EncryptionDecryption) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(EncryptionDecryption) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 8153f0a5121c38bf73092beacbcd653828cde7ca..bf59a3a21fed6ceb6ea45b763003e6c6534b58ee --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/napi_init.cpp @@ -1,225 +1,225 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -static const uint32_t IV_SIZE = 16; -static uint8_t IV[IV_SIZE] = {0}; // this is a test value, for real use the iv should be different every time -static struct OH_Huks_Param g_genEncDecParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}}; - -static struct OH_Huks_Param g_encryptParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}, - {.tag = OH_HUKS_TAG_IV, - .blob = { - .size = IV_SIZE, - .data = (uint8_t *)IV // this is a test value, for real use the iv should be different every time - }}}; - -static struct OH_Huks_Param g_decryptParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DECRYPT}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}, - {.tag = OH_HUKS_TAG_IV, - .blob = { - .size = IV_SIZE, - .data = (uint8_t *)IV // this is a test value, for real use the iv should be different every time - }}}; - -static const uint32_t AES_COMMON_SIZE = 1024; -OH_Huks_Result HksAesCipherTestEncrypt(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *encryptParamSet, - const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText) -{ - uint8_t handleE[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handleEncrypt = {sizeof(uint64_t), handleE}; - OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, encryptParamSet, &handleEncrypt, nullptr); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_FinishSession(&handleEncrypt, encryptParamSet, inData, cipherText); - return ret; -} - -OH_Huks_Result HksAesCipherTestDecrypt(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *decryptParamSet, - const struct OH_Huks_Blob *cipherText, struct OH_Huks_Blob *plainText, - const struct OH_Huks_Blob *inData) -{ - uint8_t handleD[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handleDecrypt = {sizeof(uint64_t), handleD}; - OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, decryptParamSet, &handleDecrypt, nullptr); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_FinishSession(&handleDecrypt, decryptParamSet, cipherText, plainText); - return ret; -} - -static napi_value EncDecKey(napi_env env, napi_callback_info info) -{ - char tmpKeyAlias[] = "test_enc_dec"; - struct OH_Huks_Blob keyAlias = {(uint32_t)strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias}; - struct OH_Huks_ParamSet *genParamSet = nullptr; - struct OH_Huks_ParamSet *encryptParamSet = nullptr; - struct OH_Huks_ParamSet *decryptParamSet = nullptr; - OH_Huks_Result ohResult; - do { - /* 1. Generate Key */ - /* - * 模拟生成密钥场景 - * 1.1. 确定密钥别名 - */ - /* - * 1.2. 获取生成密钥算法参数配置 - */ - ohResult = InitParamSet(&genParamSet, g_genEncDecParams, sizeof(g_genEncDecParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* - * 1.3. 调用generateKeyItem - */ - ohResult = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2. Encrypt */ - /* - * 模拟加密场景 - * 2.1. 获取密钥别名 - */ - /* - * 2.2. 获取待加密的数据 - */ - /* - * 2.3. 获取加密算法参数配置 - */ - ohResult = InitParamSet(&encryptParamSet, g_encryptParams, sizeof(g_encryptParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - char tmpInData[] = "AES_ECB_INDATA_1"; - struct OH_Huks_Blob inData = {(uint32_t)strlen(tmpInData), (uint8_t *)tmpInData}; - uint8_t cipher[AES_COMMON_SIZE] = {0}; - struct OH_Huks_Blob cipherText = {AES_COMMON_SIZE, cipher}; - /* - * 2.4. 调用initSession获取handle - */ - /* - * 2.5. 调用finishSession获取加密后的密文 - */ - ohResult = HksAesCipherTestEncrypt(&keyAlias, encryptParamSet, &inData, &cipherText); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 3. Decrypt */ - /* - * 模拟解密场景 - * 3.1. 获取密钥别名 - */ - /* - * 3.2. 获取待解密的密文 - */ - /* - * 3.3. 获取解密算法参数配置 - */ - ohResult = InitParamSet(&decryptParamSet, g_decryptParams, sizeof(g_decryptParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - uint8_t plain[AES_COMMON_SIZE] = {0}; - struct OH_Huks_Blob plainText = {AES_COMMON_SIZE, plain}; - /* - * 3.4. 调用initSession获取handle - */ - /* - * 3.5. 调用finishSession获取解密后的数据 - */ - ohResult = HksAesCipherTestDecrypt(&keyAlias, decryptParamSet, &cipherText, &plainText, &inData); - } while (0); - /* 4. Delete Key */ - /* - * 模拟删除密钥场景 - * 4.1. 获取密钥别名 - */ - /* - * 4.2. 调用deleteKeyItem删除密钥 - */ - (void)OH_Huks_DeleteKeyItem(&keyAlias, genParamSet); - - OH_Huks_FreeParamSet(&genParamSet); - OH_Huks_FreeParamSet(&encryptParamSet); - OH_Huks_FreeParamSet(&decryptParamSet); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"encDecKey", nullptr, EncDecKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +static const uint32_t IV_SIZE = 16; +static uint8_t IV[IV_SIZE] = {0}; // this is a test value, for real use the iv should be different every time +static struct OH_Huks_Param g_genEncDecParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT | OH_HUKS_KEY_PURPOSE_DECRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}}; + +static struct OH_Huks_Param g_encryptParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_ENCRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}, + {.tag = OH_HUKS_TAG_IV, + .blob = { + .size = IV_SIZE, + .data = (uint8_t *)IV // this is a test value, for real use the iv should be different every time + }}}; + +static struct OH_Huks_Param g_decryptParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DECRYPT}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}, + {.tag = OH_HUKS_TAG_IV, + .blob = { + .size = IV_SIZE, + .data = (uint8_t *)IV // this is a test value, for real use the iv should be different every time + }}}; + +static const uint32_t AES_COMMON_SIZE = 1024; +OH_Huks_Result HksAesCipherTestEncrypt(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *encryptParamSet, + const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *cipherText) +{ + uint8_t handleE[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handleEncrypt = {sizeof(uint64_t), handleE}; + OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, encryptParamSet, &handleEncrypt, nullptr); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_FinishSession(&handleEncrypt, encryptParamSet, inData, cipherText); + return ret; +} + +OH_Huks_Result HksAesCipherTestDecrypt(const struct OH_Huks_Blob *keyAlias, + const struct OH_Huks_ParamSet *decryptParamSet, + const struct OH_Huks_Blob *cipherText, struct OH_Huks_Blob *plainText, + const struct OH_Huks_Blob *inData) +{ + uint8_t handleD[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handleDecrypt = {sizeof(uint64_t), handleD}; + OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, decryptParamSet, &handleDecrypt, nullptr); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_FinishSession(&handleDecrypt, decryptParamSet, cipherText, plainText); + return ret; +} + +static napi_value EncDecKey(napi_env env, napi_callback_info info) +{ + char tmpKeyAlias[] = "test_enc_dec"; + struct OH_Huks_Blob keyAlias = {(uint32_t)strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias}; + struct OH_Huks_ParamSet *genParamSet = nullptr; + struct OH_Huks_ParamSet *encryptParamSet = nullptr; + struct OH_Huks_ParamSet *decryptParamSet = nullptr; + OH_Huks_Result ohResult; + do { + /* 1. Generate Key */ + /* + * 模拟生成密钥场景 + * 1.1. 确定密钥别名 + */ + /* + * 1.2. 获取生成密钥算法参数配置 + */ + ohResult = InitParamSet(&genParamSet, g_genEncDecParams, sizeof(g_genEncDecParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* + * 1.3. 调用generateKeyItem + */ + ohResult = OH_Huks_GenerateKeyItem(&keyAlias, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2. Encrypt */ + /* + * 模拟加密场景 + * 2.1. 获取密钥别名 + */ + /* + * 2.2. 获取待加密的数据 + */ + /* + * 2.3. 获取加密算法参数配置 + */ + ohResult = InitParamSet(&encryptParamSet, g_encryptParams, sizeof(g_encryptParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + char tmpInData[] = "AES_ECB_INDATA_1"; + struct OH_Huks_Blob inData = {(uint32_t)strlen(tmpInData), (uint8_t *)tmpInData}; + uint8_t cipher[AES_COMMON_SIZE] = {0}; + struct OH_Huks_Blob cipherText = {AES_COMMON_SIZE, cipher}; + /* + * 2.4. 调用initSession获取handle + */ + /* + * 2.5. 调用finishSession获取加密后的密文 + */ + ohResult = HksAesCipherTestEncrypt(&keyAlias, encryptParamSet, &inData, &cipherText); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 3. Decrypt */ + /* + * 模拟解密场景 + * 3.1. 获取密钥别名 + */ + /* + * 3.2. 获取待解密的密文 + */ + /* + * 3.3. 获取解密算法参数配置 + */ + ohResult = InitParamSet(&decryptParamSet, g_decryptParams, sizeof(g_decryptParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + uint8_t plain[AES_COMMON_SIZE] = {0}; + struct OH_Huks_Blob plainText = {AES_COMMON_SIZE, plain}; + /* + * 3.4. 调用initSession获取handle + */ + /* + * 3.5. 调用finishSession获取解密后的数据 + */ + ohResult = HksAesCipherTestDecrypt(&keyAlias, decryptParamSet, &cipherText, &plainText, &inData); + } while (0); + /* 4. Delete Key */ + /* + * 模拟删除密钥场景 + * 4.1. 获取密钥别名 + */ + /* + * 4.2. 调用deleteKeyItem删除密钥 + */ + (void)OH_Huks_DeleteKeyItem(&keyAlias, genParamSet); + + OH_Huks_FreeParamSet(&genParamSet); + OH_Huks_FreeParamSet(&encryptParamSet); + OH_Huks_FreeParamSet(&decryptParamSet); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"encDecKey", nullptr, EncDecKey, 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index a042918612dd70ff3c33dceb4db54131fe0ad55e..49fa4d09e13c12fe0e241bdd320d5a832ded6ea6 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 encDecKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESCBCPKCS7.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESCBCPKCS7.ets old mode 100755 new mode 100644 index 73542193e2e83ce050b4245d8d8fd25417e012c1..11add3df22aad99f6a355622b5d88da31f7735d2 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESCBCPKCS7.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESCBCPKCS7.ets @@ -1,260 +1,260 @@ -/* - * 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. - */ - -/* - * 以下以AES/CBC/PKCS7的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let aesKeyAlias = 'test_aesKeyAlias'; -let handle: number; -let plainText = '123456'; -let IV = '001122334455'; -let cipherData: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getAesGenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }]; - return properties; -} - -function getAesEncryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7 - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC - }, { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV) - }]; - return properties; -} - -function getAesDecryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7 - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC - }, { - tag: huks.HuksTag.HUKS_TAG_IV, - value: stringToUint8Array(IV) - }]; - return properties; -} - -async function generateAesKey() { - /* - * 模拟生成密钥场景 - * 1. 确定密钥别名 - */ - /* - * 2. 获取生成密钥算法参数配置 - */ - let genProperties = getAesGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - /* - * 3. 调用generateKeyItem - */ - await huks.generateKeyItem(aesKeyAlias, options) - .then((data) => { - console.info(`promise: generate AES Key success, data = ${JSON.stringify(data)}`); - }).catch((error: Error) => { - console.error(`promise: generate AES Key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function encryptData() { - /* - * 模拟加密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待加密的数据 - */ - /* - * 3. 获取加密算法参数配置 - */ - let encryptProperties = getAesEncryptProperties(); - let options: huks.HuksOptions = { - properties: encryptProperties, - inData: stringToUint8Array(plainText) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(aesKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init EncryptData failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取加密后的密文 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - cipherData = data.outData as Uint8Array; - }).catch((error: Error) => { - console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function decryptData() { - /* - * 模拟解密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待解密的密文 - */ - /* - * 3. 获取解密算法参数配置 - */ - let decryptOptions = getAesDecryptProperties() - let options: huks.HuksOptions = { - properties: decryptOptions, - inData: cipherData - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(aesKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init DecryptData failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取解密后的数据 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((error: Error) => { - console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function deleteKey() { - /* - * 模拟删除密钥场景 - * 1. 获取密钥别名 - */ - let emptyOptions: huks.HuksOptions = { - properties: [] - } - /* - * 2. 调用deleteKeyItem删除密钥 - */ - await huks.deleteKeyItem(aesKeyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((error: Error) => { - console.error(`promise: delete data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'AES/CBC/PKCS7'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.aes_cbc_pkcs7')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await generateAesKey(); - await encryptData(); - await decryptData(); - await deleteKey(); - this.message = 'AES/CBC/PKCS7 Result: Success'; - } catch { - this.message = 'AES/CBC/PKCS7 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以AES/CBC/PKCS7的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let aesKeyAlias = 'test_aesKeyAlias'; +let handle: number; +let plainText = '123456'; +let IV = '001122334455'; +let cipherData: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getAesGenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }]; + return properties; +} + +function getAesEncryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7 + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC + }, { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + }]; + return properties; +} + +function getAesDecryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PKCS7 + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC + }, { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + }]; + return properties; +} + +async function generateAesKey() { + /* + * 模拟生成密钥场景 + * 1. 确定密钥别名 + */ + /* + * 2. 获取生成密钥算法参数配置 + */ + let genProperties = getAesGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + /* + * 3. 调用generateKeyItem + */ + await huks.generateKeyItem(aesKeyAlias, options) + .then((data) => { + console.info(`promise: generate AES Key success, data = ${JSON.stringify(data)}`); + }).catch((error: Error) => { + console.error(`promise: generate AES Key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function encryptData() { + /* + * 模拟加密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待加密的数据 + */ + /* + * 3. 获取加密算法参数配置 + */ + let encryptProperties = getAesEncryptProperties(); + let options: huks.HuksOptions = { + properties: encryptProperties, + inData: stringToUint8Array(plainText) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(aesKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init EncryptData failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取加密后的密文 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + cipherData = data.outData as Uint8Array; + }).catch((error: Error) => { + console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function decryptData() { + /* + * 模拟解密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待解密的密文 + */ + /* + * 3. 获取解密算法参数配置 + */ + let decryptOptions = getAesDecryptProperties() + let options: huks.HuksOptions = { + properties: decryptOptions, + inData: cipherData + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(aesKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init DecryptData failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取解密后的数据 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((error: Error) => { + console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function deleteKey() { + /* + * 模拟删除密钥场景 + * 1. 获取密钥别名 + */ + let emptyOptions: huks.HuksOptions = { + properties: [] + } + /* + * 2. 调用deleteKeyItem删除密钥 + */ + await huks.deleteKeyItem(aesKeyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((error: Error) => { + console.error(`promise: delete data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'AES/CBC/PKCS7'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.aes_cbc_pkcs7')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await generateAesKey(); + await encryptData(); + await decryptData(); + await deleteKey(); + this.message = 'AES/CBC/PKCS7 Result: Success'; + } catch { + this.message = 'AES/CBC/PKCS7 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESGCMNoPadding.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESGCMNoPadding.ets old mode 100755 new mode 100644 index 733fea8a418d44f00d9bba79ff859ab0742d2f6c..cd7c194c3efcf918eda54ec2422eec634b38c760 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESGCMNoPadding.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/AESGCMNoPadding.ets @@ -1,271 +1,271 @@ -/* - * 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. - */ - -/* - * 以下以AES/GCM/NoPadding的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let aesKeyAlias = 'test_aesKeyAlias'; -let handle: number; -let plainText = '123456'; -let cipherData: Uint8Array; -let AAD = '1234567890123456'; -let NONCE = '001122334455'; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getAesGenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }]; - return properties; -} - -function getAesGcmEncryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_GCM - }, { - tag: huks.HuksTag.HUKS_TAG_NONCE, - value: stringToUint8Array(NONCE) - }, { - tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, - value: stringToUint8Array(AAD) - }]; - return properties; -} - -function getAesGcmDecryptProperties(cipherData: Uint8Array) { - let properties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_GCM - }, { - tag: huks.HuksTag.HUKS_TAG_NONCE, - value: stringToUint8Array(NONCE) - }, { - tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, - value: stringToUint8Array(AAD) - }, { - tag: huks.HuksTag.HUKS_TAG_AE_TAG, - value: cipherData.slice(cipherData.length - 16) - }]; - return properties; -} - -async function generateAesKey() { - /* - * 模拟生成密钥场景 - * 1. 确定密钥别名 - */ - /* - * 2. 获取生成密钥算法参数配置 - */ - let genProperties = getAesGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - /* - * 3. 调用generateKeyItem - */ - await huks.generateKeyItem(aesKeyAlias, options) - .then((data) => { - console.info(`promise: generate AES Key success, data = ${JSON.stringify(data)}`); - }).catch((error: Error) => { - console.error(`promise: generate AES Key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function encryptData() { - /* - * 模拟加密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待加密的数据 - */ - /* - * 3. 获取加密算法参数配置 - */ - let encryptProperties = getAesGcmEncryptProperties(); - let options: huks.HuksOptions = { - properties: encryptProperties, - inData: stringToUint8Array(plainText) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(aesKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init EncryptDataGcm failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取加密后的密文 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - cipherData = data.outData as Uint8Array; - }).catch((error: Error) => { - console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function decryptData() { - /* - * 模拟解密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待解密的密文 - */ - /* - * 3. 获取解密算法参数配置 - */ - let decryptOptions = getAesGcmDecryptProperties(cipherData) - let options: huks.HuksOptions = { - properties: decryptOptions, - inData: cipherData.slice(0, cipherData.length - 16) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(aesKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init DecryptDataGcm failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取解密后的数据 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((error: Error) => { - console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function deleteKey() { - /* - * 模拟删除密钥场景 - * 1. 获取密钥别名 - */ - let emptyOptions: huks.HuksOptions = { - properties: [] - } - /* - * 2. 调用deleteKeyItem删除密钥 - */ - await huks.deleteKeyItem(aesKeyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((error: Error) => { - console.error(`promise: delete data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'AES/GCM/NoPadding'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.aes_gcm_nopadding')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await generateAesKey(); - await encryptData(); - await decryptData(); - await deleteKey(); - this.message = 'AES/GCM/NoPadding Result: Success'; - } catch { - this.message = 'AES/GCM/NoPadding Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以AES/GCM/NoPadding的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let aesKeyAlias = 'test_aesKeyAlias'; +let handle: number; +let plainText = '123456'; +let cipherData: Uint8Array; +let AAD = '1234567890123456'; +let NONCE = '001122334455'; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getAesGenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }]; + return properties; +} + +function getAesGcmEncryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_GCM + }, { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }]; + return properties; +} + +function getAesGcmDecryptProperties(cipherData: Uint8Array) { + let properties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_GCM + }, { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: cipherData.slice(cipherData.length - 16) + }]; + return properties; +} + +async function generateAesKey() { + /* + * 模拟生成密钥场景 + * 1. 确定密钥别名 + */ + /* + * 2. 获取生成密钥算法参数配置 + */ + let genProperties = getAesGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + /* + * 3. 调用generateKeyItem + */ + await huks.generateKeyItem(aesKeyAlias, options) + .then((data) => { + console.info(`promise: generate AES Key success, data = ${JSON.stringify(data)}`); + }).catch((error: Error) => { + console.error(`promise: generate AES Key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function encryptData() { + /* + * 模拟加密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待加密的数据 + */ + /* + * 3. 获取加密算法参数配置 + */ + let encryptProperties = getAesGcmEncryptProperties(); + let options: huks.HuksOptions = { + properties: encryptProperties, + inData: stringToUint8Array(plainText) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(aesKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init EncryptDataGcm failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取加密后的密文 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + cipherData = data.outData as Uint8Array; + }).catch((error: Error) => { + console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function decryptData() { + /* + * 模拟解密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待解密的密文 + */ + /* + * 3. 获取解密算法参数配置 + */ + let decryptOptions = getAesGcmDecryptProperties(cipherData) + let options: huks.HuksOptions = { + properties: decryptOptions, + inData: cipherData.slice(0, cipherData.length - 16) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(aesKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init DecryptDataGcm failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取解密后的数据 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((error: Error) => { + console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function deleteKey() { + /* + * 模拟删除密钥场景 + * 1. 获取密钥别名 + */ + let emptyOptions: huks.HuksOptions = { + properties: [] + } + /* + * 2. 调用deleteKeyItem删除密钥 + */ + await huks.deleteKeyItem(aesKeyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((error: Error) => { + console.error(`promise: delete data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'AES/GCM/NoPadding'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.aes_gcm_nopadding')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await generateAesKey(); + await encryptData(); + await decryptData(); + await deleteKey(); + this.message = 'AES/GCM/NoPadding Result: Success'; + } catch { + this.message = 'AES/GCM/NoPadding Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBOAEPSHA256.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBOAEPSHA256.ets old mode 100755 new mode 100644 index d3b82510655d34a957affcdf329c745f7008553d..c56934eece42b110b23778a5bd0444f5bfa46e78 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBOAEPSHA256.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBOAEPSHA256.ets @@ -1,259 +1,259 @@ -/* - * 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. - */ - -/* - * 以下以RSA/ECB/OAEP/SHA256模式的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let rsaKeyAlias = 'test_rsaKeyAlias'; -let handle: number; -let plainText = '123456'; -let cipherData: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getRsaGenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }]; - return properties; -} - -function getRsaEncryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_OAEP - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -function getRsaDecryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_OAEP - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -async function generateRsaKey() { - /* - * 模拟生成密钥场景 - * 1. 确定密钥别名 - */ - /* - * 2. 获取生成密钥算法参数配置 - */ - let genProperties = getRsaGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - /* - * 3. 调用generateKeyItem - */ - await huks.generateKeyItem(rsaKeyAlias, options) - .then((data) => { - console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); - }).catch((error: Error) => { - console.error(`promise: generate RSA Key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function encryptData() { - /* - * 模拟加密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待加密的数据 - */ - /* - * 3. 获取加密算法参数配置 - */ - let encryptProperties = getRsaEncryptProperties(); - let options: huks.HuksOptions = { - properties: encryptProperties, - inData: stringToUint8Array(plainText) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(rsaKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init EncryptDataRsa failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取加密后的密文 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - cipherData = data.outData as Uint8Array; - }).catch((error: Error) => { - console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function decryptData() { - /* - * 模拟解密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待解密的密文 - */ - /* - * 3. 获取解密算法参数配置 - */ - let decryptOptions = getRsaDecryptProperties() - let options: huks.HuksOptions = { - properties: decryptOptions, - inData: cipherData - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(rsaKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init DecryptDataRsa failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取解密后的数据 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((error: Error) => { - console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function deleteKey() { - /* - * 模拟删除密钥场景 - * 1. 获取密钥别名 - */ - let emptyOptions: huks.HuksOptions = { - properties: [] - } - /* - * 2. 调用deleteKeyItem删除密钥 - */ - await huks.deleteKeyItem(rsaKeyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((error: Error) => { - console.error(`promise: delete data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA/ECB/OAEP/SHA256'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.rsa_ecb_oaep_sha256')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await generateRsaKey(); - await encryptData(); - await decryptData(); - await deleteKey(); - this.message = 'RSA/ECB/OAEP/SHA256 Result: Success'; - } catch { - this.message = 'RSA/ECB/OAEP/SHA256 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以RSA/ECB/OAEP/SHA256模式的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let rsaKeyAlias = 'test_rsaKeyAlias'; +let handle: number; +let plainText = '123456'; +let cipherData: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getRsaGenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }]; + return properties; +} + +function getRsaEncryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_OAEP + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +function getRsaDecryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_OAEP + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +async function generateRsaKey() { + /* + * 模拟生成密钥场景 + * 1. 确定密钥别名 + */ + /* + * 2. 获取生成密钥算法参数配置 + */ + let genProperties = getRsaGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + /* + * 3. 调用generateKeyItem + */ + await huks.generateKeyItem(rsaKeyAlias, options) + .then((data) => { + console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); + }).catch((error: Error) => { + console.error(`promise: generate RSA Key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function encryptData() { + /* + * 模拟加密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待加密的数据 + */ + /* + * 3. 获取加密算法参数配置 + */ + let encryptProperties = getRsaEncryptProperties(); + let options: huks.HuksOptions = { + properties: encryptProperties, + inData: stringToUint8Array(plainText) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(rsaKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init EncryptDataRsa failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取加密后的密文 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + cipherData = data.outData as Uint8Array; + }).catch((error: Error) => { + console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function decryptData() { + /* + * 模拟解密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待解密的密文 + */ + /* + * 3. 获取解密算法参数配置 + */ + let decryptOptions = getRsaDecryptProperties() + let options: huks.HuksOptions = { + properties: decryptOptions, + inData: cipherData + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(rsaKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init DecryptDataRsa failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取解密后的数据 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((error: Error) => { + console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function deleteKey() { + /* + * 模拟删除密钥场景 + * 1. 获取密钥别名 + */ + let emptyOptions: huks.HuksOptions = { + properties: [] + } + /* + * 2. 调用deleteKeyItem删除密钥 + */ + await huks.deleteKeyItem(rsaKeyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((error: Error) => { + console.error(`promise: delete data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA/ECB/OAEP/SHA256'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.rsa_ecb_oaep_sha256')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await generateRsaKey(); + await encryptData(); + await decryptData(); + await deleteKey(); + this.message = 'RSA/ECB/OAEP/SHA256 Result: Success'; + } catch { + this.message = 'RSA/ECB/OAEP/SHA256 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBPKCS1_V1_5.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBPKCS1_V1_5.ets old mode 100755 new mode 100644 index 7f44648fceb793272e0d009b23f583b816e56d51..4ffbf7dffb313c49c72507f6d4f2715df0e8d174 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBPKCS1_V1_5.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/RSAECBPKCS1_V1_5.ets @@ -1,259 +1,259 @@ -/* - * 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. - */ - -/* - * 以下以RSA/ECB/PKCS1_V1_5模式的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let rsaKeyAlias = 'test_rsaKeyAlias'; -let handle: number; -let plainText = '123456'; -let cipherData: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getRsaGenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }]; - return properties; -} - -function getRsaEncryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE - }]; - return properties; -} - -function getRsaDecryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 - }, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE - }]; - return properties; -} - -async function generateRsaKey() { - /* - * 模拟生成密钥场景 - * 1. 确定密钥别名 - */ - /* - * 2. 获取生成密钥算法参数配置 - */ - let genProperties = getRsaGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - /* - * 3. 调用generateKeyItem - */ - await huks.generateKeyItem(rsaKeyAlias, options) - .then((data) => { - console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); - }).catch((error: Error) => { - console.error(`promise: generate RSA Key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function encryptData() { - /* - * 模拟加密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待加密的数据 - */ - /* - * 3. 获取加密算法参数配置 - */ - let encryptProperties = getRsaEncryptProperties(); - let options: huks.HuksOptions = { - properties: encryptProperties, - inData: stringToUint8Array(plainText) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(rsaKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init EncryptDataRsa failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取加密后的密文 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - cipherData = data.outData as Uint8Array; - }).catch((error: Error) => { - console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function decryptData() { - /* - * 模拟解密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待解密的密文 - */ - /* - * 3. 获取解密算法参数配置 - */ - let decryptOptions = getRsaDecryptProperties() - let options: huks.HuksOptions = { - properties: decryptOptions, - inData: cipherData - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(rsaKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init DecryptDataRsa failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取解密后的数据 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((error: Error) => { - console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function deleteKey() { - /* - * 模拟删除密钥场景 - * 1. 获取密钥别名 - */ - let emptyOptions: huks.HuksOptions = { - properties: [] - } - /* - * 2. 调用deleteKeyItem删除密钥 - */ - await huks.deleteKeyItem(rsaKeyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((error: Error) => { - console.error(`promise: delete data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA/ECB/PKCS1_V1_5'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.rsa_ecb_pkcs1_v1_5')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await generateRsaKey(); - await encryptData(); - await decryptData(); - let ret = await deleteKey(); - this.message = 'RSA/ECB/PKCS1_V1_5 Result: Success'; - } catch { - this.message = 'RSA/ECB/PKCS1_V1_5 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以RSA/ECB/PKCS1_V1_5模式的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let rsaKeyAlias = 'test_rsaKeyAlias'; +let handle: number; +let plainText = '123456'; +let cipherData: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getRsaGenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }]; + return properties; +} + +function getRsaEncryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE + }]; + return properties; +} + +function getRsaDecryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 + }, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE + }]; + return properties; +} + +async function generateRsaKey() { + /* + * 模拟生成密钥场景 + * 1. 确定密钥别名 + */ + /* + * 2. 获取生成密钥算法参数配置 + */ + let genProperties = getRsaGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + /* + * 3. 调用generateKeyItem + */ + await huks.generateKeyItem(rsaKeyAlias, options) + .then((data) => { + console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); + }).catch((error: Error) => { + console.error(`promise: generate RSA Key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function encryptData() { + /* + * 模拟加密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待加密的数据 + */ + /* + * 3. 获取加密算法参数配置 + */ + let encryptProperties = getRsaEncryptProperties(); + let options: huks.HuksOptions = { + properties: encryptProperties, + inData: stringToUint8Array(plainText) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(rsaKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init EncryptDataRsa failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取加密后的密文 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + cipherData = data.outData as Uint8Array; + }).catch((error: Error) => { + console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function decryptData() { + /* + * 模拟解密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待解密的密文 + */ + /* + * 3. 获取解密算法参数配置 + */ + let decryptOptions = getRsaDecryptProperties() + let options: huks.HuksOptions = { + properties: decryptOptions, + inData: cipherData + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(rsaKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init DecryptDataRsa failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取解密后的数据 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((error: Error) => { + console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function deleteKey() { + /* + * 模拟删除密钥场景 + * 1. 获取密钥别名 + */ + let emptyOptions: huks.HuksOptions = { + properties: [] + } + /* + * 2. 调用deleteKeyItem删除密钥 + */ + await huks.deleteKeyItem(rsaKeyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((error: Error) => { + console.error(`promise: delete data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA/ECB/PKCS1_V1_5'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.rsa_ecb_pkcs1_v1_5')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await generateRsaKey(); + await encryptData(); + await decryptData(); + let ret = await deleteKey(); + this.message = 'RSA/ECB/PKCS1_V1_5 Result: Success'; + } catch { + this.message = 'RSA/ECB/PKCS1_V1_5 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/SM2.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/SM2.ets old mode 100755 new mode 100644 index 98a624ef39a0d82bbf05396d8dd7e7bfbc72e209..e0f314a2d1a0aff1726a45e91c47ec7fa6cf628b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/SM2.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/ets/pages/SM2.ets @@ -1,247 +1,247 @@ -/* - * 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. - */ - -/* - * 以下以SM2模式的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let sm2KeyAlias = 'test_sm2KeyAlias'; -let handle: number; -let plainText = '123456'; -let cipherData: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getSm2GenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM2 - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM2_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }]; - return properties; -} - -function getSm2EncryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM2 - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM2_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 - }]; - return properties; -} - -function getSm2DecryptProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM2 - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_SM2_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 - }]; - return properties; -} - -async function generateSm2Key() { - /* - * 模拟生成密钥场景 - * 1. 确定密钥别名 - */ - /* - * 2. 获取生成密钥算法参数配置 - */ - let genProperties = getSm2GenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - /* - * 3. 调用generateKeyItem - */ - await huks.generateKeyItem(sm2KeyAlias, options) - .then((data) => { - console.info(`promise: generate SM2 Key success, data = ${JSON.stringify(data)}`); - }).catch((error: Error) => { - console.error(`promise: generate SM2 Key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function encryptDataSm2() { - /* - * 模拟加密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待加密的数据 - */ - /* - * 3. 获取加密算法参数配置 - */ - let encryptProperties = getSm2EncryptProperties(); - let options: huks.HuksOptions = { - properties: encryptProperties, - inData: stringToUint8Array(plainText) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(sm2KeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init EncryptDataSm2 failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取加密后的密文 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - cipherData = data.outData as Uint8Array; - }).catch((error: Error) => { - console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function decryptDataSm2() { - /* - * 模拟解密场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待解密的密文 - */ - /* - * 3. 获取解密算法参数配置 - */ - let decryptOptions = getSm2DecryptProperties() - let options: huks.HuksOptions = { - properties: decryptOptions, - inData: cipherData - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(sm2KeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init DecryptDataSm2 failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取解密后的数据 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((error: Error) => { - console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function deleteKey() { - /* - * 模拟删除密钥场景 - * 1. 获取密钥别名 - */ - let emptyOptions: huks.HuksOptions = { - properties: [] - } - /* - * 2. 调用deleteKeyItem删除密钥 - */ - await huks.deleteKeyItem(sm2KeyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((error: Error) => { - console.error(`promise: delete data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.sm2')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await generateSm2Key(); - await encryptDataSm2(); - await decryptDataSm2(); - await deleteKey(); - this.message = 'SM2 Result: Success'; - } catch { - this.message = 'SM2 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以SM2模式的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let sm2KeyAlias = 'test_sm2KeyAlias'; +let handle: number; +let plainText = '123456'; +let cipherData: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getSm2GenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM2 + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM2_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }]; + return properties; +} + +function getSm2EncryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM2 + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM2_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 + }]; + return properties; +} + +function getSm2DecryptProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM2 + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_SM2_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 + }]; + return properties; +} + +async function generateSm2Key() { + /* + * 模拟生成密钥场景 + * 1. 确定密钥别名 + */ + /* + * 2. 获取生成密钥算法参数配置 + */ + let genProperties = getSm2GenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + /* + * 3. 调用generateKeyItem + */ + await huks.generateKeyItem(sm2KeyAlias, options) + .then((data) => { + console.info(`promise: generate SM2 Key success, data = ${JSON.stringify(data)}`); + }).catch((error: Error) => { + console.error(`promise: generate SM2 Key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function encryptDataSm2() { + /* + * 模拟加密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待加密的数据 + */ + /* + * 3. 获取加密算法参数配置 + */ + let encryptProperties = getSm2EncryptProperties(); + let options: huks.HuksOptions = { + properties: encryptProperties, + inData: stringToUint8Array(plainText) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(sm2KeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init EncryptDataSm2 failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取加密后的密文 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: encrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + cipherData = data.outData as Uint8Array; + }).catch((error: Error) => { + console.error(`promise: encrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function decryptDataSm2() { + /* + * 模拟解密场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待解密的密文 + */ + /* + * 3. 获取解密算法参数配置 + */ + let decryptOptions = getSm2DecryptProperties() + let options: huks.HuksOptions = { + properties: decryptOptions, + inData: cipherData + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(sm2KeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init DecryptDataSm2 failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取解密后的数据 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: decrypt data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((error: Error) => { + console.error(`promise: decrypt data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function deleteKey() { + /* + * 模拟删除密钥场景 + * 1. 获取密钥别名 + */ + let emptyOptions: huks.HuksOptions = { + properties: [] + } + /* + * 2. 调用deleteKeyItem删除密钥 + */ + await huks.deleteKeyItem(sm2KeyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((error: Error) => { + console.error(`promise: delete data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.sm2')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await generateSm2Key(); + await encryptDataSm2(); + await decryptDataSm2(); + await deleteKey(); + this.message = 'SM2 Result: Success'; + } catch { + this.message = 'SM2 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/EncryptionDecryption.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/EncryptionDecryption.test.ets old mode 100755 new mode 100644 index d908a11e703dfd6d364af2c722bb2c5e0e1cec3d..75208b5792f5b1388d2a0a64a59705f364dacf84 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/EncryptionDecryption.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/EncryptionDecryption.test.ets @@ -1,149 +1,149 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function encryptionDecryptionTest() { - describe('encryptionDecryptionTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,加解密AES/CBC/PKCS7 - */ - it('testEncryptionDecryption001', 0, async () => { - console.info('uitest: testEncryptionDecryption001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AES/CBC/PKCS7')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES/CBC/PKCS7')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES/CBC/PKCS7 Result: Success')); - console.info('uitest: testEncryptionDecryption001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,加解密AES/GCM/NoPadding - */ - it('testEncryptionDecryption002', 0, async () => { - console.info('uitest: testEncryptionDecryption002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('AES/GCM/NoPadding')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call AES/GCM/NoPadding')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('AES/GCM/NoPadding Result: Success')); - console.info('uitest: testEncryptionDecryption002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,加解密RSA/ECB/PKCS1_V1_5 - */ - it('testEncryptionDecryption003', 0, async () => { - console.info('uitest: testEncryptionDecryption003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA/ECB/PKCS1_V1_5')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA/ECB/PKCS1_V1_5')); - await button2.click(); - await driver.delayMs(3500); - await driver.assertComponentExist(ON.text('RSA/ECB/PKCS1_V1_5 Result: Success')); - console.info('uitest: testEncryptionDecryption003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,加解密RSA/ECB/OAEP/SHA256 - */ - it('testEncryptionDecryption004', 0, async () => { - console.info('uitest: testEncryptionDecryption004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA/ECB/OAEP/SHA256')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call RSA/ECB/OAEP/SHA256')); - await button2.click(); - await driver.delayMs(3500); - await driver.assertComponentExist(ON.text('RSA/ECB/OAEP/SHA256 Result: Success')); - console.info('uitest: testEncryptionDecryption004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,加解密SM2 - */ - it('testEncryptionDecryption005', 0, async () => { - console.info('uitest: testEncryptionDecryption005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call SM2')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2 Result: Success')); - console.info('uitest: testEncryptionDecryption005 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,加解密C/C++ - */ - it('testEncryptionDecryption006', 0, async () => { - console.info('uitest: testEncryptionDecryption006 begin'); - const driver = Driver.create(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call C/C++')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testEncryptionDecryption006 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function encryptionDecryptionTest() { + describe('encryptionDecryptionTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,加解密AES/CBC/PKCS7 + */ + it('testEncryptionDecryption001', 0, async () => { + console.info('uitest: testEncryptionDecryption001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AES/CBC/PKCS7')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES/CBC/PKCS7')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES/CBC/PKCS7 Result: Success')); + console.info('uitest: testEncryptionDecryption001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,加解密AES/GCM/NoPadding + */ + it('testEncryptionDecryption002', 0, async () => { + console.info('uitest: testEncryptionDecryption002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('AES/GCM/NoPadding')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call AES/GCM/NoPadding')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AES/GCM/NoPadding Result: Success')); + console.info('uitest: testEncryptionDecryption002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,加解密RSA/ECB/PKCS1_V1_5 + */ + it('testEncryptionDecryption003', 0, async () => { + console.info('uitest: testEncryptionDecryption003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA/ECB/PKCS1_V1_5')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA/ECB/PKCS1_V1_5')); + await button2.click(); + await driver.delayMs(3500); + await driver.assertComponentExist(ON.text('RSA/ECB/PKCS1_V1_5 Result: Success')); + console.info('uitest: testEncryptionDecryption003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,加解密RSA/ECB/OAEP/SHA256 + */ + it('testEncryptionDecryption004', 0, async () => { + console.info('uitest: testEncryptionDecryption004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA/ECB/OAEP/SHA256')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call RSA/ECB/OAEP/SHA256')); + await button2.click(); + await driver.delayMs(3500); + await driver.assertComponentExist(ON.text('RSA/ECB/OAEP/SHA256 Result: Success')); + console.info('uitest: testEncryptionDecryption004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,加解密SM2 + */ + it('testEncryptionDecryption005', 0, async () => { + console.info('uitest: testEncryptionDecryption005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2 Result: Success')); + console.info('uitest: testEncryptionDecryption005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,加解密C/C++ + */ + it('testEncryptionDecryption006', 0, async () => { + console.info('uitest: testEncryptionDecryption006 begin'); + const driver = Driver.create(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call C/C++')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testEncryptionDecryption006 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/ohosTest.md old mode 100755 new mode 100644 index 40c6b9c6de5d2a000f2db2e496d9cbdf178e46c0..f638f4014234ff0551ec918ff0a0d12e27899d1a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/ohosTest.md @@ -1,13 +1,13 @@ -# 密钥加解密测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,加解密AES/CBC/PKCS7 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,加解密AES/GCM/NoPadding | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,加解密RSA/ECB/PKCS1_V1_5 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,加解密RSA/ECB/OAEP/SHA256 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,加解密SM2 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 密钥加解密测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,加解密AES/CBC/PKCS7 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,加解密AES/GCM/NoPadding | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,加解密RSA/ECB/PKCS1_V1_5 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,加解密RSA/ECB/OAEP/SHA256 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,加解密SM2 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,加解密C/C++ | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESCBCPKCS7_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESCBCPKCS7_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESCBCPKCS7_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESCBCPKCS7_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESGCMNoPadding_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESGCMNoPadding_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESGCMNoPadding_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/AESGCMNoPadding_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBOAEPSHA256_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBOAEPSHA256_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBOAEPSHA256_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBOAEPSHA256_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBPKCS1_V1_5_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBPKCS1_V1_5_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBPKCS1_V1_5_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/RSAECBPKCS1_V1_5_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/SM2_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/SM2_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/SM2_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/EncryptionDecryption/screenshots/SM2_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/app.json5 old mode 100755 new mode 100644 index f52eb071f7aba2afe807a54064877bd22e6ca0c1..007435cf8c28359cb1e59eff3c6b247549df35ca --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/app.json5 @@ -1,25 +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.hmac", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.hmac", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index afd32d11bf083def97cdeae762081c84dd95cf52..029ee36507cfbae7faf39e9d91238ab70189bf55 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "HMAC" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "HMAC" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/build-profile.json5 old mode 100755 new mode 100644 index d903787c46ed450cc00125d16a590de4577538f5..7acbde12b146c7793fc992e5af8ed99d6ed67f31 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "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/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/code-linter.json5 old mode 100755 new mode 100644 index 9deb9807637aa27ebde62e61e2362a417aacdc04..28586467ee7a761c737d8654a73aed6fddbc3c71 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/code-linter.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/code-linter.json5 @@ -1,35 +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": { - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/hvigorfile.ts old mode 100755 new mode 100644 index 46872af92274609fb7926a0eb6451cebbb18afef..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/hvigorfile.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/hvigorfile.ts @@ -1,21 +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. */ -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 0539f21e8b474803c41e0d3dc31401a5e80d949e..4b42dae94126fb56900e47244f760770ba8ec0c0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(HMAC) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(HMAC) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 781dc912304279fca5fa6c8ff4af2c1e99271da6..6d1a94a55fce7b1c72573002e5572ed846ebbad6 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/napi_init.cpp @@ -1,134 +1,134 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -static struct OH_Huks_Param g_genHmacParams[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_HMAC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_MAC}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}}; - -static const uint32_t HMAC_COMMON_SIZE = 1024; -OH_Huks_Result HksHmacTest(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *hmacParamSet, - const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *hashText) -{ - uint8_t handleE[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handle = {sizeof(uint64_t), handleE}; - OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, hmacParamSet, &handle, nullptr); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_FinishSession(&handle, hmacParamSet, inData, hashText); - return ret; -} - -static napi_value HmacKey(napi_env env, napi_callback_info info) -{ - /* 1. Generate Key */ - /* - * 模拟生成密钥场景 - * 1.1. 确定密钥别名 - */ - char tmpKeyAlias[] = "test_hmac"; - struct OH_Huks_Blob keyAlias = {(uint32_t)strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias}; - struct OH_Huks_ParamSet *hmacParamSet = nullptr; - OH_Huks_Result ohResult; - do { - /* - * 1.2. 获取生成密钥算法参数配置 - */ - ohResult = InitParamSet(&hmacParamSet, g_genHmacParams, sizeof(g_genHmacParams) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* - * 1.3. 调用generateKeyItem - */ - ohResult = OH_Huks_GenerateKeyItem(&keyAlias, hmacParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2. Hmac */ - /* - * 模拟哈希场景 - * 2.1. 获取密钥别名 - */ - /* - * 2.2. 获取待哈希的数据 - */ - char tmpInData[] = "HMAC_MAC_INDATA_1"; - struct OH_Huks_Blob inData = {(uint32_t)strlen(tmpInData), (uint8_t *)tmpInData}; - uint8_t cipher[HMAC_COMMON_SIZE] = {0}; - struct OH_Huks_Blob hashText = {HMAC_COMMON_SIZE, cipher}; - /* - * 2.3. 调用initSession获取handle - */ - /* - * 2.4. 调用finishSession获取哈希后的内容 - */ - ohResult = HksHmacTest(&keyAlias, hmacParamSet, &inData, &hashText); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - } while (0); - OH_Huks_FreeParamSet(&hmacParamSet); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = {{"hmacKey", nullptr, HmacKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +static struct OH_Huks_Param g_genHmacParams[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_HMAC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_MAC}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}}; + +static const uint32_t HMAC_COMMON_SIZE = 1024; +OH_Huks_Result HksHmacTest(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *hmacParamSet, + const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *hashText) +{ + uint8_t handleE[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handle = {sizeof(uint64_t), handleE}; + OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, hmacParamSet, &handle, nullptr); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_FinishSession(&handle, hmacParamSet, inData, hashText); + return ret; +} + +static napi_value HmacKey(napi_env env, napi_callback_info info) +{ + /* 1. Generate Key */ + /* + * 模拟生成密钥场景 + * 1.1. 确定密钥别名 + */ + char tmpKeyAlias[] = "test_hmac"; + struct OH_Huks_Blob keyAlias = {(uint32_t)strlen(tmpKeyAlias), (uint8_t *)tmpKeyAlias}; + struct OH_Huks_ParamSet *hmacParamSet = nullptr; + OH_Huks_Result ohResult; + do { + /* + * 1.2. 获取生成密钥算法参数配置 + */ + ohResult = InitParamSet(&hmacParamSet, g_genHmacParams, sizeof(g_genHmacParams) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* + * 1.3. 调用generateKeyItem + */ + ohResult = OH_Huks_GenerateKeyItem(&keyAlias, hmacParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2. Hmac */ + /* + * 模拟哈希场景 + * 2.1. 获取密钥别名 + */ + /* + * 2.2. 获取待哈希的数据 + */ + char tmpInData[] = "HMAC_MAC_INDATA_1"; + struct OH_Huks_Blob inData = {(uint32_t)strlen(tmpInData), (uint8_t *)tmpInData}; + uint8_t cipher[HMAC_COMMON_SIZE] = {0}; + struct OH_Huks_Blob hashText = {HMAC_COMMON_SIZE, cipher}; + /* + * 2.3. 调用initSession获取handle + */ + /* + * 2.4. 调用finishSession获取哈希后的内容 + */ + ohResult = HksHmacTest(&keyAlias, hmacParamSet, &inData, &hashText); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + } while (0); + OH_Huks_FreeParamSet(&hmacParamSet); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = {{"hmacKey", nullptr, HmacKey, 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index 127a71cc2a3541d69ca5b85eca8d6d9285306f05..97f8716a9af8a08f358e360f048a42982f04eac2 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 hmacKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/HMAC.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/HMAC.ets old mode 100755 new mode 100644 index 2382757540c0a7028dc581a0f7dbc15a81eafe09..786fe86b3fb882aeb385256f7682075c3667d0aa --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/HMAC.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/HMAC.ets @@ -1,155 +1,155 @@ -/* - * 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. - */ - -/* - * 以下以HMAC密钥的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let hmacKeyAlias = 'test_HMAC'; -let handle: number; -let plainText = '123456'; -let hashData: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getHMACProperties() { - const properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_HMAC - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_MAC - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA384, - }]; - return properties; -} - -async function generateHMACKey() { - /* - * 模拟生成密钥场景 - * 1. 确定密钥别名 - */ - /* - * 2. 获取生成密钥算法参数配置 - */ - let genProperties = getHMACProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - /* - * 3. 调用generateKeyItem - */ - await huks.generateKeyItem(hmacKeyAlias, options) - .then((data) => { - console.info(`promise: generate HMAC Key success`); - }).catch((error: Error) => { - console.error(`promise: generate HMAC Key failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -async function hMACData() { - /* - * 模拟HMAC场景 - * 1. 获取密钥别名 - */ - /* - * 2. 获取待哈希的数据 - */ - /* - * 3. 获取HMAC算法参数配置 - */ - let hmacProperties = getHMACProperties(); - let options: huks.HuksOptions = { - properties: hmacProperties, - inData: stringToUint8Array(plainText) - } - /* - * 4. 调用initSession获取handle - */ - await huks.initSession(hmacKeyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((error: Error) => { - console.error(`promise: init EncryptData failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) - /* - * 5. 调用finishSession获取HMAC的结果 - */ - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: HMAC data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - hashData = data.outData as Uint8Array; - }).catch((error: Error) => { - console.error(`promise: HMAC data failed, ${JSON.stringify(error)}`); - throw (error as Error); - }) -} - -@Entry -@Component -struct Index { - @State message: string = 'HMAC'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_hmac')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await generateHMACKey(); - await hMACData(); - this.message = 'HMAC Result: Success'; - } catch (error) { - this.message = 'HMAC Result: ' + error.message; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以HMAC密钥的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let hmacKeyAlias = 'test_HMAC'; +let handle: number; +let plainText = '123456'; +let hashData: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getHMACProperties() { + const properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_HMAC + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_MAC + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA384, + }]; + return properties; +} + +async function generateHMACKey() { + /* + * 模拟生成密钥场景 + * 1. 确定密钥别名 + */ + /* + * 2. 获取生成密钥算法参数配置 + */ + let genProperties = getHMACProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + /* + * 3. 调用generateKeyItem + */ + await huks.generateKeyItem(hmacKeyAlias, options) + .then((data) => { + console.info(`promise: generate HMAC Key success`); + }).catch((error: Error) => { + console.error(`promise: generate HMAC Key failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +async function hMACData() { + /* + * 模拟HMAC场景 + * 1. 获取密钥别名 + */ + /* + * 2. 获取待哈希的数据 + */ + /* + * 3. 获取HMAC算法参数配置 + */ + let hmacProperties = getHMACProperties(); + let options: huks.HuksOptions = { + properties: hmacProperties, + inData: stringToUint8Array(plainText) + } + /* + * 4. 调用initSession获取handle + */ + await huks.initSession(hmacKeyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((error: Error) => { + console.error(`promise: init EncryptData failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) + /* + * 5. 调用finishSession获取HMAC的结果 + */ + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: HMAC data success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + hashData = data.outData as Uint8Array; + }).catch((error: Error) => { + console.error(`promise: HMAC data failed, ${JSON.stringify(error)}`); + throw (error as Error); + }) +} + +@Entry +@Component +struct Index { + @State message: string = 'HMAC'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_hmac')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await generateHMACKey(); + await hMACData(); + this.message = 'HMAC Result: Success'; + } catch (error) { + this.message = 'HMAC Result: ' + error.message; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index 4ca75fc98a2d498dcdd03797dabaa98eeb91a16e..4cddde7d4baba7a00c26fccfa97bd30c562d4524 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/Index.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/ets/pages/Index.ets @@ -1,69 +1,69 @@ -/* - * 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 { router } from '@kit.ArkUI'; -import testNapi from 'libentry.so'; - -@Entry -@Component -struct Index { - @State message: string = 'HMAC'; - - goToSample(url: string): void { - router.pushUrl({ - url: url, - }, router.RouterMode.Single, (err) => { - if (err) { - console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); - return; - } - console.info('pushUrl success'); - }) - } - - build() { - Column({ space: 5 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.hmac')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - this.goToSample('pages/HMAC') - }) - Button($r('app.string.call_cpp_hmac_key')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - let ret: number = testNapi.hmacKey(); - this.message = 'Call C/C++ Result: ' + ret.toString(); - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { router } from '@kit.ArkUI'; +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'HMAC'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.hmac')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + this.goToSample('pages/HMAC') + }) + Button($r('app.string.call_cpp_hmac_key')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + let ret: number = testNapi.hmacKey(); + this.message = 'Call C/C++ Result: ' + ret.toString(); + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 index 9d4f8a434d863461a900661b39dc7ac9808997e2..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(() => { - // Presets an action, which is performed only once before all test cases of the test suite start. - // This API supports only one parameter: preset action function. - }) - beforeEach(() => { - // Presets an action, which is performed before each unit test case starts. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: preset action function. - }) - afterEach(() => { - // Presets a clear action, which is performed after each unit test case ends. - // The number of execution times is the same as the number of test cases defined by **it**. - // This API supports only one parameter: clear action function. - }) - afterAll(() => { - // Presets a clear action, which is performed after all test cases of the test suite end. - // This API supports only one parameter: clear action function. - }) - it('assertContain', 0, () => { - // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. - hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); - let a = 'abc'; - let b = 'b'; - // Defines a variety of assertion methods, which are used to declare expected boolean conditions. - expect(a).assertContain(b); - expect(a).assertEqual(a); - }) - }) +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/HMAC.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/HMAC.test.ets old mode 100755 new mode 100644 index 805e76c00bd7f81b91ad7e04e6d34b2c9314c76b..9555cd908701b39a6e15eaeb1edf669e8ac1dbc6 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/HMAC.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/HMAC.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function hMACTest() { - describe('hMACTest', () => { - - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,HMAC(ArkTS) - */ - it('testHMAC001', 0, async () => { - console.info('uitest: testHMAC001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('HMAC').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call HMAC')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('HMAC Result: Success')); - console.info('uitest: testHMAC001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,HMAC(C/C++) - */ - it('testHMAC002', 0, async () => { - console.info('uitest: testHMAC002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(2000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testHMAC002 end'); - }) - }) -} +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function hMACTest() { + describe('hMACTest', () => { + + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,HMAC(ArkTS) + */ + it('testHMAC001', 0, async () => { + console.info('uitest: testHMAC001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('HMAC').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call HMAC')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('HMAC Result: Success')); + console.info('uitest: testHMAC001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,HMAC(C/C++) + */ + it('testHMAC002', 0, async () => { + console.info('uitest: testHMAC002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(2000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testHMAC002 end'); + }) + }) +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 index 6993a5dd1e6385024df3d6a67bb1c6c494fb7f51..c054467fd688e71bf4b2a13ee0bef72b1bb4758c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +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 hMACTest from './HMAC.test'; - -export default function testsuite() { - hMACTest(); +/* + * 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 hMACTest from './HMAC.test'; + +export default function testsuite() { + hMACTest(); } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigorfile.ts old mode 100755 new mode 100644 index 2db60fa91881f6961e5def61af680301d22a1341..2a5e543f190732c159beb574dfc9fa37bc94e156 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigorfile.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/hvigorfile.ts @@ -1,21 +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. */ -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/HMAC/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/ohosTest.md old mode 100755 new mode 100644 index 52479113a43a1e3686e780c7804b93fec95b7d43..4568f24cfecf4149b1315b844928427be60b10d9 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/ohosTest.md @@ -1,9 +1,9 @@ -# 密钥HMAC测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,HMAC(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 密钥HMAC测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,HMAC(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,HMAC(C/C++) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/HMAC_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/HMAC_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/HMAC_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/HMAC_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/HMAC/screenshots/cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/app.json5 old mode 100755 new mode 100644 index 132bda4cf68f4a288418da86e33e870896fd3242..6defc46afc5484f3455686d18b743db44c6ffc47 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/app.json5 @@ -1,25 +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.keyderivation", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.keyderivation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index e03fb76012d254271f33bacd030113a06864be17..96cf25cee263ecee3a2e7f67bfd7c32600f65090 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "KeyDerivation" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "KeyDerivation" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 7a2e4e36633e6ae08ef23c36212052f2987cab98..183f2308d472e51823c051c79ee98f55f159f479 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(KeyDerivation) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(KeyDerivation) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 0cfae37cb4c3cee38334695bc6efd9eb19b64f05..18ee86ef3fb0e2965a413528243cb87817ed1086 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/napi_init.cpp @@ -1,148 +1,148 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} -static const uint32_t DERIVE_KEY_SIZE_32 = 32; -static const uint32_t DERIVE_KEY_SIZE_256 = 256; -static struct OH_Huks_Blob g_deriveKeyAlias = {(uint32_t)strlen("test_derive"), (uint8_t *)"test_derive"}; -static struct OH_Huks_Param g_genDeriveParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}}; -static struct OH_Huks_Param g_hkdfParams[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_HKDF}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, - {.tag = OH_HUKS_TAG_DERIVE_KEY_SIZE, .uint32Param = DERIVE_KEY_SIZE_32}}; -static struct OH_Huks_Param g_hkdfFinishParams[] = { - {.tag = OH_HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_ONLY_USED_IN_HUKS}, - {.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_deriveKeyAlias}, - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = DERIVE_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}}; -static const uint32_t COMMON_SIZE = 2048; -static const char *G_DERIVE_IN_DATA = "Hks_HKDF_Derive_Test_00000000000000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; -static napi_value DeriveKey(napi_env env, napi_callback_info info) -{ - struct OH_Huks_Blob genAlias = {(uint32_t)strlen("test_signVerify"), (uint8_t *)"test_signVerify"}; - struct OH_Huks_Blob inData = {(uint32_t)strlen(G_DERIVE_IN_DATA), (uint8_t *)G_DERIVE_IN_DATA}; - struct OH_Huks_ParamSet *genParamSet = nullptr; - struct OH_Huks_ParamSet *hkdfParamSet = nullptr; - struct OH_Huks_ParamSet *hkdfFinishParamSet = nullptr; - OH_Huks_Result ohResult; - do { - ohResult = InitParamSet(&genParamSet, g_genDeriveParams, sizeof(g_genDeriveParams) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - - ohResult = InitParamSet(&hkdfParamSet, g_hkdfParams, sizeof(g_hkdfParams) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - - // finish paramset - ohResult = - InitParamSet(&hkdfFinishParamSet, g_hkdfFinishParams, sizeof(g_hkdfFinishParams) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - - /* 1. Generate Key */ - ohResult = OH_Huks_GenerateKeyItem(&genAlias, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2. Derive */ - // Init - uint8_t handleD[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handleDerive = {sizeof(uint64_t), handleD}; - ohResult = OH_Huks_InitSession(&genAlias, hkdfParamSet, &handleDerive, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - // Update - uint8_t tmpOut[COMMON_SIZE] = {0}; - struct OH_Huks_Blob outData = {COMMON_SIZE, tmpOut}; - ohResult = OH_Huks_UpdateSession(&handleDerive, hkdfParamSet, &inData, &outData); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - // Finish - uint8_t outDataD[COMMON_SIZE] = {0}; - struct OH_Huks_Blob outDataDerive = {COMMON_SIZE, outDataD}; - ohResult = OH_Huks_FinishSession(&handleDerive, hkdfFinishParamSet, &inData, &outDataDerive); - } while (0); - (void)OH_Huks_DeleteKeyItem(&genAlias, nullptr); - (void)OH_Huks_DeleteKeyItem(&g_deriveKeyAlias, nullptr); - OH_Huks_FreeParamSet(&genParamSet); - OH_Huks_FreeParamSet(&hkdfParamSet); - OH_Huks_FreeParamSet(&hkdfFinishParamSet); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"deriveKey", nullptr, DeriveKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} +static const uint32_t DERIVE_KEY_SIZE_32 = 32; +static const uint32_t DERIVE_KEY_SIZE_256 = 256; +static struct OH_Huks_Blob g_deriveKeyAlias = {(uint32_t)strlen("test_derive"), (uint8_t *)"test_derive"}; +static struct OH_Huks_Param g_genDeriveParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}}; +static struct OH_Huks_Param g_hkdfParams[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_HKDF}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}, + {.tag = OH_HUKS_TAG_DERIVE_KEY_SIZE, .uint32Param = DERIVE_KEY_SIZE_32}}; +static struct OH_Huks_Param g_hkdfFinishParams[] = { + {.tag = OH_HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_ONLY_USED_IN_HUKS}, + {.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_deriveKeyAlias}, + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = DERIVE_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_DERIVE}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA256}}; +static const uint32_t COMMON_SIZE = 2048; +static const char *G_DERIVE_IN_DATA = "Hks_HKDF_Derive_Test_00000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; +static napi_value DeriveKey(napi_env env, napi_callback_info info) +{ + struct OH_Huks_Blob genAlias = {(uint32_t)strlen("test_signVerify"), (uint8_t *)"test_signVerify"}; + struct OH_Huks_Blob inData = {(uint32_t)strlen(G_DERIVE_IN_DATA), (uint8_t *)G_DERIVE_IN_DATA}; + struct OH_Huks_ParamSet *genParamSet = nullptr; + struct OH_Huks_ParamSet *hkdfParamSet = nullptr; + struct OH_Huks_ParamSet *hkdfFinishParamSet = nullptr; + OH_Huks_Result ohResult; + do { + ohResult = InitParamSet(&genParamSet, g_genDeriveParams, sizeof(g_genDeriveParams) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + + ohResult = InitParamSet(&hkdfParamSet, g_hkdfParams, sizeof(g_hkdfParams) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + + // finish paramset + ohResult = + InitParamSet(&hkdfFinishParamSet, g_hkdfFinishParams, sizeof(g_hkdfFinishParams) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + + /* 1. Generate Key */ + ohResult = OH_Huks_GenerateKeyItem(&genAlias, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2. Derive */ + // Init + uint8_t handleD[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handleDerive = {sizeof(uint64_t), handleD}; + ohResult = OH_Huks_InitSession(&genAlias, hkdfParamSet, &handleDerive, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + // Update + uint8_t tmpOut[COMMON_SIZE] = {0}; + struct OH_Huks_Blob outData = {COMMON_SIZE, tmpOut}; + ohResult = OH_Huks_UpdateSession(&handleDerive, hkdfParamSet, &inData, &outData); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + // Finish + uint8_t outDataD[COMMON_SIZE] = {0}; + struct OH_Huks_Blob outDataDerive = {COMMON_SIZE, outDataD}; + ohResult = OH_Huks_FinishSession(&handleDerive, hkdfFinishParamSet, &inData, &outDataDerive); + } while (0); + (void)OH_Huks_DeleteKeyItem(&genAlias, nullptr); + (void)OH_Huks_DeleteKeyItem(&g_deriveKeyAlias, nullptr); + OH_Huks_FreeParamSet(&genParamSet); + OH_Huks_FreeParamSet(&hkdfParamSet); + OH_Huks_FreeParamSet(&hkdfFinishParamSet); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"deriveKey", nullptr, DeriveKey, 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index 0079094e8c12127b12f0b04ea7c1953870a5f9f1..a15baf5bd241f5b2657003a4e76d66de97097c3d --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 deriveKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/HKDF.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/HKDF.ets old mode 100755 new mode 100644 index 5c8b2881e4d7253d31b2e7b700906ae93f6f8f4b..a38738c8b9e92c070931d1605e1b3bca33f8fe85 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/HKDF.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/HKDF.ets @@ -1,360 +1,360 @@ -/* - * 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. - */ - -/* - * 以下以HKDF密钥的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -/* - * 确定密钥别名和封装密钥属性参数集 - */ -let srcKeyAlias = 'hkdf_Key'; -let deriveHkdfInData = 'deriveHkdfTestIndata'; -let handle: number; -let finishOutData: Uint8Array; -let huksKeyDeriveKeySize = 32; -/* 集成生成密钥参数集 */ -let properties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES, - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128, -}, { - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, -}]; - -let huksOptions: huks.HuksOptions = { - properties: properties, - inData: new Uint8Array([]) -} -/* 集成init时密钥参数集 */ -let initProperties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_HKDF, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, -}, { - tag: huks.HuksTag.HUKS_TAG_DERIVE_KEY_SIZE, - value: huksKeyDeriveKeySize, -}]; - -let initOptions: huks.HuksOptions = { - properties: initProperties, - inData: new Uint8Array([]) -} -/* 集成finish时密钥参数集 */ -let finishProperties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, -}, { - tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, - value: true, -}, { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, - value: stringToUint8Array(srcKeyAlias), -}, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB, -}]; -let finishOptions: huks.HuksOptions = { - properties: finishProperties, - inData: new Uint8Array([]) -} - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -class ThrowObject { - public isThrow = false; -} - -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.initSession(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise doInit`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await initSession(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - handle = data.handle; - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doInit failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function updateSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.updateSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicUpdateFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doUpdate`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await updateSession(handle, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function finishSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.finishSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicFinishFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doFinish`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await finishSession(handle, huksOptions, throwObject) - .then((data) => { - finishOutData = data.outData as Uint8Array; - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doFinish failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise deleteKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await deleteKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -async function testDerive() { - /* 生成密钥 */ - await publicGenKeyFunc(srcKeyAlias, huksOptions); - /* 进行派生操作 */ - await publicInitFunc(srcKeyAlias, initOptions); - initOptions.inData = stringToUint8Array(deriveHkdfInData); - await publicUpdateFunc(handle, initOptions); - await publicFinishFunc(handle, finishOptions); - await publicDeleteKeyFunc(srcKeyAlias, huksOptions); -} - -@Entry -@Component -struct Index { - @State message: string = 'HKDF'; - - build() { - Column({ space: 12 }) { - Text(this.message).fontSize(20) - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_hkdf')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - let ret = await testDerive(); - this.message = 'HKDF Result: Success'; - } catch { - this.message = 'HKDF Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以HKDF密钥的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +/* + * 确定密钥别名和封装密钥属性参数集 + */ +let srcKeyAlias = 'hkdf_Key'; +let deriveHkdfInData = 'deriveHkdfTestIndata'; +let handle: number; +let finishOutData: Uint8Array; +let huksKeyDeriveKeySize = 32; +/* 集成生成密钥参数集 */ +let properties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES, + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128, +}, { + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, +}]; + +let huksOptions: huks.HuksOptions = { + properties: properties, + inData: new Uint8Array([]) +} +/* 集成init时密钥参数集 */ +let initProperties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_HKDF, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, +}, { + tag: huks.HuksTag.HUKS_TAG_DERIVE_KEY_SIZE, + value: huksKeyDeriveKeySize, +}]; + +let initOptions: huks.HuksOptions = { + properties: initProperties, + inData: new Uint8Array([]) +} +/* 集成finish时密钥参数集 */ +let finishProperties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, +}, { + tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, + value: true, +}, { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlias), +}, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB, +}]; +let finishOptions: huks.HuksOptions = { + properties: finishProperties, + inData: new Uint8Array([]) +} + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +class ThrowObject { + public isThrow = false; +} + +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.initSession(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise doInit`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await initSession(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doInit failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function updateSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.updateSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicUpdateFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doUpdate`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await updateSession(handle, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function finishSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.finishSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicFinishFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doFinish`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await finishSession(handle, huksOptions, throwObject) + .then((data) => { + finishOutData = data.outData as Uint8Array; + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doFinish failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise deleteKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await deleteKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +async function testDerive() { + /* 生成密钥 */ + await publicGenKeyFunc(srcKeyAlias, huksOptions); + /* 进行派生操作 */ + await publicInitFunc(srcKeyAlias, initOptions); + initOptions.inData = stringToUint8Array(deriveHkdfInData); + await publicUpdateFunc(handle, initOptions); + await publicFinishFunc(handle, finishOptions); + await publicDeleteKeyFunc(srcKeyAlias, huksOptions); +} + +@Entry +@Component +struct Index { + @State message: string = 'HKDF'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20) + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_hkdf')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + let ret = await testDerive(); + this.message = 'HKDF Result: Success'; + } catch { + this.message = 'HKDF Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/PBKDF2.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/PBKDF2.ets old mode 100755 new mode 100644 index e3e0ad78ff5c42f13d38a0432b597e06cce111e4..c8680fe5abf689536650b09d374532a436761fe0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/PBKDF2.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/ets/pages/PBKDF2.ets @@ -1,373 +1,373 @@ -/* - * 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. - */ - -/* - * 以下以PBKDF2密钥的Promise操作使用为例 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -/* - * 确定密钥别名和封装密钥属性参数集 - */ -let srcKeyAlias = 'pbkdf2_Key'; -let salt = 'mySalt'; -let iterationCount = 10000; -let derivedKeySize = 32; -let handle: number; -let finishOutData: Uint8Array; - -/* 集成生成密钥参数集 */ -let properties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES, - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128, -}, { - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, -} -]; - -let huksOptions: huks.HuksOptions = { - properties: properties, - inData: new Uint8Array([]) -} - -/* 集成init时密钥参数集 */ -let initProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_PBKDF2, - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, -}, { - tag: huks.HuksTag.HUKS_TAG_DERIVE_KEY_SIZE, - value: derivedKeySize, -}, { - tag: huks.HuksTag.HUKS_TAG_ITERATION, - value: iterationCount, -}, { - tag: huks.HuksTag.HUKS_TAG_SALT, - value: stringToUint8Array(salt), -} -]; - -let initOptions: huks.HuksOptions = { - properties: initProperties, - inData: new Uint8Array([]) -} - -/* 集成finish时密钥参数集 */ -let finishProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, - }, { - tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, - value: true, -}, { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, - value: stringToUint8Array(srcKeyAlias), -}, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB, -} -]; - -let finishOptions: huks.HuksOptions = { - properties: finishProperties, - inData: new Uint8Array([]) -} - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -class ThrowObject { - public isThrow = false; -} - -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.initSession(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise doInit`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await initSession(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - handle = data.handle; - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doInit failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function updateSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.updateSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicUpdateFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doUpdate`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await updateSession(handle, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function finishSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.finishSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicFinishFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doFinish`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await finishSession(handle, huksOptions, throwObject) - .then((data) => { - finishOutData = data.outData as Uint8Array; - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doFinish failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise deleteKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await deleteKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -async function testDerive() { - /* 生成密钥 */ - await publicGenKeyFunc(srcKeyAlias, huksOptions); - /* 进行派生操作 */ - await publicInitFunc(srcKeyAlias, initOptions); - await publicUpdateFunc(handle, initOptions); - await publicFinishFunc(handle, finishOptions); - await publicDeleteKeyFunc(srcKeyAlias, huksOptions); -} - -@Entry -@Component -struct Index { - @State message: string = 'PBKDF2'; - - build() { - Column({ space: 12 }) { - Text(this.message) - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_pbkdf2')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - let ret = await testDerive(); - this.message = 'PBKDF2 Result: Success'; - } catch { - this.message = 'PBKDF2 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 以下以PBKDF2密钥的Promise操作使用为例 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +/* + * 确定密钥别名和封装密钥属性参数集 + */ +let srcKeyAlias = 'pbkdf2_Key'; +let salt = 'mySalt'; +let iterationCount = 10000; +let derivedKeySize = 32; +let handle: number; +let finishOutData: Uint8Array; + +/* 集成生成密钥参数集 */ +let properties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES, + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128, +}, { + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, +} +]; + +let huksOptions: huks.HuksOptions = { + properties: properties, + inData: new Uint8Array([]) +} + +/* 集成init时密钥参数集 */ +let initProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_PBKDF2, + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DERIVE, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256, +}, { + tag: huks.HuksTag.HUKS_TAG_DERIVE_KEY_SIZE, + value: derivedKeySize, +}, { + tag: huks.HuksTag.HUKS_TAG_ITERATION, + value: iterationCount, +}, { + tag: huks.HuksTag.HUKS_TAG_SALT, + value: stringToUint8Array(salt), +} +]; + +let initOptions: huks.HuksOptions = { + properties: initProperties, + inData: new Uint8Array([]) +} + +/* 集成finish时密钥参数集 */ +let finishProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, + }, { + tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, + value: true, +}, { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlias), +}, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB, +} +]; + +let finishOptions: huks.HuksOptions = { + properties: finishProperties, + inData: new Uint8Array([]) +} + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +class ThrowObject { + public isThrow = false; +} + +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.initSession(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise doInit`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await initSession(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doInit failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function updateSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.updateSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicUpdateFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doUpdate`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await updateSession(handle, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function finishSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.finishSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicFinishFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doFinish`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await finishSession(handle, huksOptions, throwObject) + .then((data) => { + finishOutData = data.outData as Uint8Array; + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doFinish failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise deleteKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await deleteKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +async function testDerive() { + /* 生成密钥 */ + await publicGenKeyFunc(srcKeyAlias, huksOptions); + /* 进行派生操作 */ + await publicInitFunc(srcKeyAlias, initOptions); + await publicUpdateFunc(handle, initOptions); + await publicFinishFunc(handle, finishOptions); + await publicDeleteKeyFunc(srcKeyAlias, huksOptions); +} + +@Entry +@Component +struct Index { + @State message: string = 'PBKDF2'; + + build() { + Column({ space: 12 }) { + Text(this.message) + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_pbkdf2')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + let ret = await testDerive(); + this.message = 'PBKDF2 Result: Success'; + } catch { + this.message = 'PBKDF2 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/KeyDerivation.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/KeyDerivation.test.ets old mode 100755 new mode 100644 index 5538f567358d66de4d1d5abb83b7d849d9fa680b..b7b4b3de0aa97d0fb8b8a623258407370a4b5bd9 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/KeyDerivation.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/KeyDerivation.test.ets @@ -1,95 +1,95 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function keyDerivationTest() { - describe('keyDerivationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,密钥派生HKDF - */ - it('testKeyDerivation001', 0, async () => { - console.info('uitest: testKeyDerivation001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('HKDF')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call HKDF')); - await button2.click(); - await driver.delayMs(2000); - await driver.assertComponentExist(ON.text('HKDF Result: Success')); - console.info('uitest: testKeyDerivation001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,密钥派生PBKDF2 - */ - it('testKeyDerivation002', 0, async () => { - console.info('uitest: testKeyDerivation002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('PBKDF2')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call PBKDF2')); - await button2.click(); - await driver.delayMs(2000); - await driver.assertComponentExist(ON.text('PBKDF2 Result: Success')); - console.info('uitest: testKeyDerivation002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,密钥派生HKDF256(C/C++) - */ - it('testKeyDerivation003', 0, async () => { - console.info('uitest: testKeyDerivation003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testKeyDerivation003 end'); - await driver.pressBack(); - }) - }) -} +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function keyDerivationTest() { + describe('keyDerivationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,密钥派生HKDF + */ + it('testKeyDerivation001', 0, async () => { + console.info('uitest: testKeyDerivation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('HKDF')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call HKDF')); + await button2.click(); + await driver.delayMs(2000); + await driver.assertComponentExist(ON.text('HKDF Result: Success')); + console.info('uitest: testKeyDerivation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,密钥派生PBKDF2 + */ + it('testKeyDerivation002', 0, async () => { + console.info('uitest: testKeyDerivation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('PBKDF2')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call PBKDF2')); + await button2.click(); + await driver.delayMs(2000); + await driver.assertComponentExist(ON.text('PBKDF2 Result: Success')); + console.info('uitest: testKeyDerivation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,密钥派生HKDF256(C/C++) + */ + it('testKeyDerivation003', 0, async () => { + console.info('uitest: testKeyDerivation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testKeyDerivation003 end'); + await driver.pressBack(); + }) + }) +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/ohosTest.md old mode 100755 new mode 100644 index da4b8c8a2c8a01e1a84c8682ebdc2c0a5d738f2b..ba4443dd88394f07c4face6c7d36b4efef66d21d --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/ohosTest.md @@ -1,10 +1,10 @@ -# 密钥派生测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,密钥派生HKDF | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,密钥派生PBKDF2 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 密钥派生测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,密钥派生HKDF | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,密钥派生PBKDF2 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,密钥派生(C/C++) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/HKDF_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/HKDF_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/HKDF_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/HKDF_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/PBKDF2_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/PBKDF2_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/PBKDF2_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyDerivation/screenshots/PBKDF2_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/app.json5 old mode 100755 new mode 100644 index 6aa00b44a49e1ef6446e6b4424b853a59b59b351..287ffdacf9ec7c9a1fc48456bcdcdef60ebeb12a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/app.json5 @@ -1,25 +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.keyexchange", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.keyexchange", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index dfe9e4e2e92f5c8dda15e81a18e0af36c00a11e7..dc8e956b1ffc434990edb1694e538f161db709e8 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "KeyExchange" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "KeyExchange" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index b847c2d1cb55a9ddca8872ccbb4234635d321ca9..9e0677bac15dc15913479dd0df1397426d9617a2 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(KeyExchange) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(KeyExchange) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 46554caae9513313f59ee579584015d78bc37ce6..6575bbcda8564a292476c7947a93ed0fe1be6934 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/napi_init.cpp @@ -1,264 +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. - */ - -#include "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -/* 初始化参数 */ -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} -static const uint32_t IV_SIZE = 16; -static uint8_t IV[IV_SIZE] = {0}; // this is a test value, for real use the iv should be different every time -static struct OH_Huks_Blob g_keyAliasFinal1001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_1_final"), - (uint8_t *)"HksECDHAgreeKeyAliasTest001_1_final"}; -/* 集成密钥参数集 */ -static struct OH_Huks_Param g_genAgreeParams[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; -static struct OH_Huks_Param g_agreeParamsInit01[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECDH}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}}; -static struct OH_Huks_Param g_agreeParamsFinish01[] = { - {.tag = OH_HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_ONLY_USED_IN_HUKS}, - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_keyAliasFinal1001}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}}; -static struct OH_Huks_Blob g_keyAliasFinal2001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_2_final"), - (uint8_t *)"HksECDHAgreeKeyAliasTest001_2_final"}; -static struct OH_Huks_Param g_agreeParamsInit02[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECDH}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}}; -static struct OH_Huks_Param g_agreeParamsFinish02[] = { - {.tag = OH_HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_ONLY_USED_IN_HUKS}, - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_keyAliasFinal2001}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, - {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}}; -static const uint32_t ECDH_COMMON_SIZE = 1024; -static struct OH_Huks_Blob g_keyAlias01001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_1"), - (uint8_t *)"HksECDHAgreeKeyAliasTest001_1"}; -static struct OH_Huks_Blob g_keyAlias02001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_2"), - (uint8_t *)"HksECDHAgreeKeyAliasTest001_2"}; - -OH_Huks_Result MallocAndCheckBlobData(struct OH_Huks_Blob *blob, const uint32_t blobSize) -{ - struct OH_Huks_Result ret; - ret.errorCode = OH_HUKS_SUCCESS; - if (blobSize == 0 || blobSize > ECDH_COMMON_SIZE) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - return ret; - } - blob->data = (uint8_t *)malloc(blobSize); - if (blob->data == NULL) { - ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; - } - return ret; -} -/* 导出密钥 */ -OH_Huks_Result HksEcdhAgreeExport(const struct OH_Huks_Blob *keyAlias1, const struct OH_Huks_Blob *keyAlias2, - struct OH_Huks_Blob *publicKey1, struct OH_Huks_Blob *publicKey2, - const struct OH_Huks_ParamSet *genParamSet) -{ - OH_Huks_Result ret = OH_Huks_ExportPublicKeyItem(keyAlias1, genParamSet, publicKey1); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_ExportPublicKeyItem(keyAlias2, genParamSet, publicKey2); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - return ret; -} -static const char *IN_DATA = "Hks_ECDH_Agree_Test_000000000000000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; -/* 协商密钥操作 */ -OH_Huks_Result HksEcdhAgreeFinish(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey, - const struct OH_Huks_ParamSet *initParamSet, - const struct OH_Huks_ParamSet *finishParamSet, struct OH_Huks_Blob *outData) -{ - struct OH_Huks_Blob inData = {(uint32_t)strlen(IN_DATA), (uint8_t *)IN_DATA}; - uint8_t handleU[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handle = {sizeof(uint64_t), handleU}; - OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - uint8_t outDataU[ECDH_COMMON_SIZE] = {0}; - struct OH_Huks_Blob outDataUpdate = {ECDH_COMMON_SIZE, outDataU}; - ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_FinishSession(&handle, finishParamSet, &inData, outData); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - return ret; -} - -/* 协商密钥整体流程 */ -static napi_value AgreeKey(napi_env env, napi_callback_info info) -{ - struct OH_Huks_ParamSet *genParamSet = nullptr; - struct OH_Huks_ParamSet *initParamSet01 = nullptr; - struct OH_Huks_ParamSet *finishParamSet01 = nullptr; - struct OH_Huks_ParamSet *initParamSet02 = nullptr; - struct OH_Huks_ParamSet *finishParamSet02 = nullptr; - struct OH_Huks_Blob publicKey01 = {.size = OH_HUKS_ECC_KEY_SIZE_256, .data = nullptr}; - struct OH_Huks_Blob publicKey02 = {.size = OH_HUKS_ECC_KEY_SIZE_256, .data = nullptr}; - struct OH_Huks_Blob outData01 = {.size = ECDH_COMMON_SIZE, .data = nullptr}; - struct OH_Huks_Blob outData02 = {.size = ECDH_COMMON_SIZE, .data = nullptr}; - OH_Huks_Result ohResult; - do { - /* 1.确定密钥别名集成密钥参数集 */ - ohResult = InitParamSet(&genParamSet, g_genAgreeParams, sizeof(g_genAgreeParams) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = - InitParamSet(&initParamSet01, g_agreeParamsInit01, sizeof(g_agreeParamsInit01) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = InitParamSet(&finishParamSet01, g_agreeParamsFinish01, - sizeof(g_agreeParamsFinish01) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = - InitParamSet(&initParamSet02, g_agreeParamsInit02, sizeof(g_agreeParamsInit02) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = InitParamSet(&finishParamSet02, g_agreeParamsFinish02, - sizeof(g_agreeParamsFinish02) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2.设备A生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&g_keyAlias01001, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 3.设备B生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&g_keyAlias02001, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = MallocAndCheckBlobData(&publicKey01, publicKey01.size); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = MallocAndCheckBlobData(&publicKey02, publicKey02.size); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 4.设备A、B导出公钥 */ - ohResult = HksEcdhAgreeExport(&g_keyAlias01001, &g_keyAlias02001, &publicKey01, - &publicKey02, genParamSet); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = MallocAndCheckBlobData(&outData01, outData01.size); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = MallocAndCheckBlobData(&outData02, outData02.size); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 5.设备A协商密钥 */ - ohResult = HksEcdhAgreeFinish(&g_keyAlias01001, &publicKey02, initParamSet01, - finishParamSet01, &outData01); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 5.设备B协商密钥 */ - ohResult = HksEcdhAgreeFinish(&g_keyAlias02001, &publicKey01, initParamSet02, - finishParamSet02, &outData02); - } while (0); - free(publicKey01.data); - free(publicKey02.data); - free(outData01.data); - free(outData02.data); - /* 6.设备A、B删除密钥 */ - OH_Huks_DeleteKeyItem(&g_keyAlias01001, genParamSet); - OH_Huks_DeleteKeyItem(&g_keyAlias02001, genParamSet); - OH_Huks_DeleteKeyItem(&g_keyAliasFinal1001, NULL); - OH_Huks_DeleteKeyItem(&g_keyAliasFinal2001, NULL); - OH_Huks_FreeParamSet(&genParamSet); - OH_Huks_FreeParamSet(&initParamSet01); - OH_Huks_FreeParamSet(&finishParamSet01); - OH_Huks_FreeParamSet(&initParamSet02); - OH_Huks_FreeParamSet(&finishParamSet02); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"agreeKey", nullptr, AgreeKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +/* 初始化参数 */ +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} +static const uint32_t IV_SIZE = 16; +static uint8_t IV[IV_SIZE] = {0}; // this is a test value, for real use the iv should be different every time +static struct OH_Huks_Blob g_keyAliasFinal1001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_1_final"), + (uint8_t *)"HksECDHAgreeKeyAliasTest001_1_final"}; +/* 集成密钥参数集 */ +static struct OH_Huks_Param g_genAgreeParams[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; +static struct OH_Huks_Param g_agreeParamsInit01[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECDH}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}}; +static struct OH_Huks_Param g_agreeParamsFinish01[] = { + {.tag = OH_HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_ONLY_USED_IN_HUKS}, + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_keyAliasFinal1001}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}}; +static struct OH_Huks_Blob g_keyAliasFinal2001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_2_final"), + (uint8_t *)"HksECDHAgreeKeyAliasTest001_2_final"}; +static struct OH_Huks_Param g_agreeParamsInit02[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECDH}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}}; +static struct OH_Huks_Param g_agreeParamsFinish02[] = { + {.tag = OH_HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, .uint32Param = OH_HUKS_STORAGE_ONLY_USED_IN_HUKS}, + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_AES}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_AES_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_ALIAS, .blob = g_keyAliasFinal2001}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_NONE}, + {.tag = OH_HUKS_TAG_BLOCK_MODE, .uint32Param = OH_HUKS_MODE_CBC}}; +static const uint32_t ECDH_COMMON_SIZE = 1024; +static struct OH_Huks_Blob g_keyAlias01001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_1"), + (uint8_t *)"HksECDHAgreeKeyAliasTest001_1"}; +static struct OH_Huks_Blob g_keyAlias02001 = {(uint32_t)strlen("HksECDHAgreeKeyAliasTest001_2"), + (uint8_t *)"HksECDHAgreeKeyAliasTest001_2"}; + +OH_Huks_Result MallocAndCheckBlobData(struct OH_Huks_Blob *blob, const uint32_t blobSize) +{ + struct OH_Huks_Result ret; + ret.errorCode = OH_HUKS_SUCCESS; + if (blobSize == 0 || blobSize > ECDH_COMMON_SIZE) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + return ret; + } + blob->data = (uint8_t *)malloc(blobSize); + if (blob->data == NULL) { + ret.errorCode = OH_HUKS_ERR_CODE_INTERNAL_ERROR; + } + return ret; +} +/* 导出密钥 */ +OH_Huks_Result HksEcdhAgreeExport(const struct OH_Huks_Blob *keyAlias1, const struct OH_Huks_Blob *keyAlias2, + struct OH_Huks_Blob *publicKey1, struct OH_Huks_Blob *publicKey2, + const struct OH_Huks_ParamSet *genParamSet) +{ + OH_Huks_Result ret = OH_Huks_ExportPublicKeyItem(keyAlias1, genParamSet, publicKey1); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_ExportPublicKeyItem(keyAlias2, genParamSet, publicKey2); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + return ret; +} +static const char *IN_DATA = "Hks_ECDH_Agree_Test_000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; +/* 协商密钥操作 */ +OH_Huks_Result HksEcdhAgreeFinish(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_Blob *publicKey, + const struct OH_Huks_ParamSet *initParamSet, + const struct OH_Huks_ParamSet *finishParamSet, struct OH_Huks_Blob *outData) +{ + struct OH_Huks_Blob inData = {(uint32_t)strlen(IN_DATA), (uint8_t *)IN_DATA}; + uint8_t handleU[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handle = {sizeof(uint64_t), handleU}; + OH_Huks_Result ret = OH_Huks_InitSession(keyAlias, initParamSet, &handle, nullptr); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + uint8_t outDataU[ECDH_COMMON_SIZE] = {0}; + struct OH_Huks_Blob outDataUpdate = {ECDH_COMMON_SIZE, outDataU}; + ret = OH_Huks_UpdateSession(&handle, initParamSet, publicKey, &outDataUpdate); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_FinishSession(&handle, finishParamSet, &inData, outData); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + return ret; +} + +/* 协商密钥整体流程 */ +static napi_value AgreeKey(napi_env env, napi_callback_info info) +{ + struct OH_Huks_ParamSet *genParamSet = nullptr; + struct OH_Huks_ParamSet *initParamSet01 = nullptr; + struct OH_Huks_ParamSet *finishParamSet01 = nullptr; + struct OH_Huks_ParamSet *initParamSet02 = nullptr; + struct OH_Huks_ParamSet *finishParamSet02 = nullptr; + struct OH_Huks_Blob publicKey01 = {.size = OH_HUKS_ECC_KEY_SIZE_256, .data = nullptr}; + struct OH_Huks_Blob publicKey02 = {.size = OH_HUKS_ECC_KEY_SIZE_256, .data = nullptr}; + struct OH_Huks_Blob outData01 = {.size = ECDH_COMMON_SIZE, .data = nullptr}; + struct OH_Huks_Blob outData02 = {.size = ECDH_COMMON_SIZE, .data = nullptr}; + OH_Huks_Result ohResult; + do { + /* 1.确定密钥别名集成密钥参数集 */ + ohResult = InitParamSet(&genParamSet, g_genAgreeParams, sizeof(g_genAgreeParams) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = + InitParamSet(&initParamSet01, g_agreeParamsInit01, sizeof(g_agreeParamsInit01) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = InitParamSet(&finishParamSet01, g_agreeParamsFinish01, + sizeof(g_agreeParamsFinish01) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = + InitParamSet(&initParamSet02, g_agreeParamsInit02, sizeof(g_agreeParamsInit02) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = InitParamSet(&finishParamSet02, g_agreeParamsFinish02, + sizeof(g_agreeParamsFinish02) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2.设备A生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&g_keyAlias01001, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 3.设备B生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&g_keyAlias02001, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = MallocAndCheckBlobData(&publicKey01, publicKey01.size); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = MallocAndCheckBlobData(&publicKey02, publicKey02.size); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 4.设备A、B导出公钥 */ + ohResult = HksEcdhAgreeExport(&g_keyAlias01001, &g_keyAlias02001, &publicKey01, + &publicKey02, genParamSet); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = MallocAndCheckBlobData(&outData01, outData01.size); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = MallocAndCheckBlobData(&outData02, outData02.size); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 5.设备A协商密钥 */ + ohResult = HksEcdhAgreeFinish(&g_keyAlias01001, &publicKey02, initParamSet01, + finishParamSet01, &outData01); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 5.设备B协商密钥 */ + ohResult = HksEcdhAgreeFinish(&g_keyAlias02001, &publicKey01, initParamSet02, + finishParamSet02, &outData02); + } while (0); + free(publicKey01.data); + free(publicKey02.data); + free(outData01.data); + free(outData02.data); + /* 6.设备A、B删除密钥 */ + OH_Huks_DeleteKeyItem(&g_keyAlias01001, genParamSet); + OH_Huks_DeleteKeyItem(&g_keyAlias02001, genParamSet); + OH_Huks_DeleteKeyItem(&g_keyAliasFinal1001, NULL); + OH_Huks_DeleteKeyItem(&g_keyAliasFinal2001, NULL); + OH_Huks_FreeParamSet(&genParamSet); + OH_Huks_FreeParamSet(&initParamSet01); + OH_Huks_FreeParamSet(&finishParamSet01); + OH_Huks_FreeParamSet(&initParamSet02); + OH_Huks_FreeParamSet(&finishParamSet02); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"agreeKey", nullptr, AgreeKey, 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index 2199a476a72915be02c610b4b88293c316cc799b..14e3b41480dbecb0511d4b9fe692b1e651fd14aa --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 agreeKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/DH.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/DH.ets old mode 100755 new mode 100644 index 0732f58f99458e2a7ed8e7b86ca724ba7f8cb9b0..10747c3c94848a4e4a938057b2a69b79389492b4 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/DH.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/DH.ets @@ -1,201 +1,201 @@ -/* - * 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. - */ - -/* -*以下以 DH密钥的Promise操作使用为例 -*/ -import { huks } from '@kit.UniversalKeystoreKit'; - -function stringToUint8Array(str: string) { - let arr: number[] = [] - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToBigInt(arr: Uint8Array): bigint { - let i = 0 - const byteMax: bigint = BigInt('0x100') - let result: bigint = BigInt('0') - while (i < arr.length) { - result = result * byteMax - result = result + BigInt(arr[i]) - i += 1 - } - return result; -} - -const dhAgree: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_DH, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE, -}] -const dh2048Agree: huks.HuksParam[] = [ - ...dhAgree, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048, -}] -const dhGenOptions: huks.HuksOptions = { - properties: dh2048Agree, - inData: new Uint8Array([]) -} -const emptyOptions: huks.HuksOptions = { - properties: [], - inData: new Uint8Array([]) -} - -async function huksDhAgreeExportKey(keyAlias: string, - peerPubKey: huks.HuksReturnResult): Promise { - const initHandle = await huks.initSession(keyAlias, dhGenOptions) - const dhAgreeUpdateBobPubKey: huks.HuksOptions = { - properties: [ - ...dh2048Agree, { - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_KEY_EXPORT_ALLOWED, - }], - inData: peerPubKey.outData - } - await huks.updateSession(initHandle.handle, dhAgreeUpdateBobPubKey) - return await huks.finishSession(initHandle.handle, emptyOptions) -} - -async function huksDhAgreeExportTest( - aliasA: string, aliasB: string, - pubKeyA: huks.HuksReturnResult, pubKeyB: huks.HuksReturnResult) { - - const agreedKeyFromAlice = await huksDhAgreeExportKey(aliasA, pubKeyB); - console.info(`ok! agreedKeyFromAlice export is 0x${uint8ArrayToBigInt(agreedKeyFromAlice.outData).toString(16)}`); - - const agreedKeyFromBob = await huksDhAgreeExportKey(aliasB, pubKeyA); - console.info(`ok! agreedKeyFromBob export is 0x${uint8ArrayToBigInt(agreedKeyFromBob.outData).toString(16)}`); -} - -async function huksDhAgreeInHuks(keyAlias: string, peerPubKey: huks.HuksReturnResult, - aliasAgreedKey: string): Promise { - const onlyUsedInHuks: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, - }, { - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, - }] - const dhAgreeInit: huks.HuksOptions = { - properties: [ - ...dhAgree, - { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, }, - ...onlyUsedInHuks], - inData: new Uint8Array([]) - } - const dhAgreeFinishParams: huks.HuksParam[] = [ - ...onlyUsedInHuks, - { tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, value: true }, - { tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES }, - { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT - }] - - const handle = await huks.initSession(keyAlias, dhAgreeInit) - const dhAgreeUpdatePubKey: huks.HuksOptions = { - properties: [...dhAgree, ...onlyUsedInHuks], - inData: peerPubKey.outData - } - await huks.updateSession(handle.handle, dhAgreeUpdatePubKey) - const dhAgreeAliceFinnish: huks.HuksOptions = { - properties: [...dhAgreeFinishParams, { - tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, value: stringToUint8Array(aliasAgreedKey) - }], inData: new Uint8Array([]) - } - return await huks.finishSession(handle.handle, dhAgreeAliceFinnish); -} - -async function huksDhAgreeInHuksTest( - aliasA: string, aliasB: string, - pubKeyA: huks.HuksReturnResult, pubKeyB: huks.HuksReturnResult, - aliasAgreedKeyFromA: string, aliasAgreedKeyFromB: string) { - - const finishAliceResult = await huksDhAgreeInHuks(aliasA, pubKeyB, aliasAgreedKeyFromA); - console.info(`ok! finishAliceResult in huks is 0x${uint8ArrayToBigInt(finishAliceResult.outData).toString(16)}`); - const aliceAgreedExist = await huks.isKeyItemExist(aliasAgreedKeyFromA, emptyOptions); - console.info(`ok! aliceAgreedExist in huks is ${aliceAgreedExist}`); - - const finishBobResult = await huksDhAgreeInHuks(aliasB, pubKeyA, aliasAgreedKeyFromB); - console.info(`ok! finishBobResult in huks is 0x${uint8ArrayToBigInt(finishBobResult.outData).toString(16)}`); - const bobAgreedExist = await huks.isKeyItemExist(aliasAgreedKeyFromB, emptyOptions); - console.info(`ok! bobAgreedExist in huks is ${bobAgreedExist}`); - - await huks.deleteKeyItem(aliasAgreedKeyFromA, emptyOptions); - await huks.deleteKeyItem(aliasAgreedKeyFromB, emptyOptions); -} - -export default async function huksDhAgreeTest() { - const aliasAlice = 'alice'; - const aliasBob = 'bob'; - - /* 调用generateKeyItem生成别名为alice与bob的两个密钥 */ - await huks.generateKeyItem(aliasAlice, dhGenOptions); - await huks.generateKeyItem(aliasBob, dhGenOptions); - - /* 导出非对称密钥alice与bob的的公钥 */ - const pubKeyAlice = await huks.exportKeyItem(aliasAlice, emptyOptions); - const pubKeyBob = await huks.exportKeyItem(aliasBob, emptyOptions); - - /* 开始协商,协商生成的密钥返回给业务管理 */ - await huksDhAgreeExportTest(aliasAlice, aliasBob, pubKeyAlice, pubKeyBob); - - /* 开始协商,协商生成的密钥由HUKS管理 */ - await huksDhAgreeInHuksTest(aliasAlice, aliasBob, pubKeyAlice, pubKeyBob, 'agreedKeyFromAlice', 'agreedKeyFromBob'); - - await huks.deleteKeyItem(aliasAlice, emptyOptions); - await huks.deleteKeyItem(aliasBob, emptyOptions); -} - -@Entry -@Component -struct Index { - @State message: string = 'DH'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.dh')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await huksDhAgreeTest(); - this.message = 'DH Result: Success'; - } catch { - this.message = 'DH Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* +*以下以 DH密钥的Promise操作使用为例 +*/ +import { huks } from '@kit.UniversalKeystoreKit'; + +function stringToUint8Array(str: string) { + let arr: number[] = [] + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToBigInt(arr: Uint8Array): bigint { + let i = 0 + const byteMax: bigint = BigInt('0x100') + let result: bigint = BigInt('0') + while (i < arr.length) { + result = result * byteMax + result = result + BigInt(arr[i]) + i += 1 + } + return result; +} + +const dhAgree: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE, +}] +const dh2048Agree: huks.HuksParam[] = [ + ...dhAgree, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048, +}] +const dhGenOptions: huks.HuksOptions = { + properties: dh2048Agree, + inData: new Uint8Array([]) +} +const emptyOptions: huks.HuksOptions = { + properties: [], + inData: new Uint8Array([]) +} + +async function huksDhAgreeExportKey(keyAlias: string, + peerPubKey: huks.HuksReturnResult): Promise { + const initHandle = await huks.initSession(keyAlias, dhGenOptions) + const dhAgreeUpdateBobPubKey: huks.HuksOptions = { + properties: [ + ...dh2048Agree, { + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_KEY_EXPORT_ALLOWED, + }], + inData: peerPubKey.outData + } + await huks.updateSession(initHandle.handle, dhAgreeUpdateBobPubKey) + return await huks.finishSession(initHandle.handle, emptyOptions) +} + +async function huksDhAgreeExportTest( + aliasA: string, aliasB: string, + pubKeyA: huks.HuksReturnResult, pubKeyB: huks.HuksReturnResult) { + + const agreedKeyFromAlice = await huksDhAgreeExportKey(aliasA, pubKeyB); + console.info(`ok! agreedKeyFromAlice export is 0x${uint8ArrayToBigInt(agreedKeyFromAlice.outData).toString(16)}`); + + const agreedKeyFromBob = await huksDhAgreeExportKey(aliasB, pubKeyA); + console.info(`ok! agreedKeyFromBob export is 0x${uint8ArrayToBigInt(agreedKeyFromBob.outData).toString(16)}`); +} + +async function huksDhAgreeInHuks(keyAlias: string, peerPubKey: huks.HuksReturnResult, + aliasAgreedKey: string): Promise { + const onlyUsedInHuks: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, + }, { + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, + }] + const dhAgreeInit: huks.HuksOptions = { + properties: [ + ...dhAgree, + { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, }, + ...onlyUsedInHuks], + inData: new Uint8Array([]) + } + const dhAgreeFinishParams: huks.HuksParam[] = [ + ...onlyUsedInHuks, + { tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, value: true }, + { tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES }, + { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT + }] + + const handle = await huks.initSession(keyAlias, dhAgreeInit) + const dhAgreeUpdatePubKey: huks.HuksOptions = { + properties: [...dhAgree, ...onlyUsedInHuks], + inData: peerPubKey.outData + } + await huks.updateSession(handle.handle, dhAgreeUpdatePubKey) + const dhAgreeAliceFinnish: huks.HuksOptions = { + properties: [...dhAgreeFinishParams, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, value: stringToUint8Array(aliasAgreedKey) + }], inData: new Uint8Array([]) + } + return await huks.finishSession(handle.handle, dhAgreeAliceFinnish); +} + +async function huksDhAgreeInHuksTest( + aliasA: string, aliasB: string, + pubKeyA: huks.HuksReturnResult, pubKeyB: huks.HuksReturnResult, + aliasAgreedKeyFromA: string, aliasAgreedKeyFromB: string) { + + const finishAliceResult = await huksDhAgreeInHuks(aliasA, pubKeyB, aliasAgreedKeyFromA); + console.info(`ok! finishAliceResult in huks is 0x${uint8ArrayToBigInt(finishAliceResult.outData).toString(16)}`); + const aliceAgreedExist = await huks.isKeyItemExist(aliasAgreedKeyFromA, emptyOptions); + console.info(`ok! aliceAgreedExist in huks is ${aliceAgreedExist}`); + + const finishBobResult = await huksDhAgreeInHuks(aliasB, pubKeyA, aliasAgreedKeyFromB); + console.info(`ok! finishBobResult in huks is 0x${uint8ArrayToBigInt(finishBobResult.outData).toString(16)}`); + const bobAgreedExist = await huks.isKeyItemExist(aliasAgreedKeyFromB, emptyOptions); + console.info(`ok! bobAgreedExist in huks is ${bobAgreedExist}`); + + await huks.deleteKeyItem(aliasAgreedKeyFromA, emptyOptions); + await huks.deleteKeyItem(aliasAgreedKeyFromB, emptyOptions); +} + +export default async function huksDhAgreeTest() { + const aliasAlice = 'alice'; + const aliasBob = 'bob'; + + /* 调用generateKeyItem生成别名为alice与bob的两个密钥 */ + await huks.generateKeyItem(aliasAlice, dhGenOptions); + await huks.generateKeyItem(aliasBob, dhGenOptions); + + /* 导出非对称密钥alice与bob的的公钥 */ + const pubKeyAlice = await huks.exportKeyItem(aliasAlice, emptyOptions); + const pubKeyBob = await huks.exportKeyItem(aliasBob, emptyOptions); + + /* 开始协商,协商生成的密钥返回给业务管理 */ + await huksDhAgreeExportTest(aliasAlice, aliasBob, pubKeyAlice, pubKeyBob); + + /* 开始协商,协商生成的密钥由HUKS管理 */ + await huksDhAgreeInHuksTest(aliasAlice, aliasBob, pubKeyAlice, pubKeyBob, 'agreedKeyFromAlice', 'agreedKeyFromBob'); + + await huks.deleteKeyItem(aliasAlice, emptyOptions); + await huks.deleteKeyItem(aliasBob, emptyOptions); +} + +@Entry +@Component +struct Index { + @State message: string = 'DH'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.dh')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await huksDhAgreeTest(); + this.message = 'DH Result: Success'; + } catch { + this.message = 'DH Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/X25519.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/X25519.ets old mode 100755 new mode 100644 index c02c8185551ba7f6928058a9b431448d6e6a3673..4552e6756765f7e4ec11e0a9dc80b677521302ad --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/X25519.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/ets/pages/X25519.ets @@ -1,424 +1,424 @@ -/* - * 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. - */ - -/* -*以下以X25519密钥的Promise操作使用为例 -*/ -import { huks } from '@kit.UniversalKeystoreKit'; - -/* -* 确定密钥别名和封装密钥属性参数集 -*/ -let srcKeyAliasFirst = 'AgreeX25519KeyFirstAlias'; -let srcKeyAliasSecond = 'AgreeX25519KeySecondAlias'; -let agreeX25519InData = 'AgreeX25519TestIndata'; -let finishOutData: Uint8Array; -let handle: number; -let exportKey: Uint8Array; -let exportKeyFirst: Uint8Array; -let exportKeySecond: Uint8Array; -/* 集成生成密钥参数集 */ -let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_X25519, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_CBC, -}, { - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, -}]; -let huksOptions: huks.HuksOptions = { - properties: properties, - inData: new Uint8Array([]) -} -/* 集成第一个协商参数集 */ -const finishProperties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, - value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, -}, { - tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, - value: true -}, { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_AES, -}, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, -}, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, -}, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_NONE, -}, { - tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, - value: huks.HuksCipherMode.HUKS_MODE_ECB, -}]; -let finishOptionsFirst: huks.HuksOptions = { - properties: [ - ...finishProperties, { - tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, - value: stringToUint8Array(srcKeyAliasFirst + 'final'), - }], - inData: stringToUint8Array(agreeX25519InData) -} -/* 集成第二个协商参数集 */ -let finishOptionsSecond: huks.HuksOptions = { - properties: [ - ...finishProperties, { - tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, - value: stringToUint8Array(srcKeyAliasSecond + 'final'), - }], - inData: stringToUint8Array(agreeX25519InData) -} - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -class ThrowObject { - public isThrow: boolean = false -} - -/* 生成密钥 */ -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 调用generateKeyItem生成密钥 */ -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise generateKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await generateKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -/*初始化密钥会话接口,并获取一个句柄(必选)和挑战值(可选)*/ -function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.initSession(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/*调用initSession获取handle*/ -async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise doInit`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await initSession(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); - handle = data.handle; - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doInit failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -/* 分段添加密钥操作的数据并进行相应的密钥操作,输出处理数据 */ -function updateSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.updateSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 调用updateSession进行协商操作 */ -async function publicUpdateFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doUpdate`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await updateSession(handle, huksOptions, throwObject) - .then((data) => { - console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -/* 结束密钥会话并进行相应的密钥操作,输出处理数据 */ -function finishSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.finishSession(handle, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 调用finishSession结束操作 */ -async function publicFinishFunc(handle: number, huksOptions: huks.HuksOptions) { - console.info(`enter promise doFinish`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await finishSession(handle, huksOptions, throwObject) - .then((data) => { - finishOutData = data.outData as Uint8Array; - console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: doFinish failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -/* 导出密钥 */ -function exportKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.exportKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 调用exportKeyItem导出公钥操作 */ -async function publicExportKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise export`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await exportKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: exportKeyItem success, data = ${JSON.stringify(data)}`); - exportKey = data.outData as Uint8Array; - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: exportKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: exportKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -/* 删除密钥操作 */ -function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { - return new Promise((resolve, reject) => { - try { - huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throwObject.isThrow = true; - throw (error as Error); - } - }); -} - -/* 调用deleteKeyItem删除密钥操作 */ -async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { - console.info(`enter promise deleteKeyItem`); - let throwObject: ThrowObject = { isThrow: false }; - try { - await deleteKeyItem(keyAlias, huksOptions, throwObject) - .then((data) => { - console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - if (throwObject.isThrow) { - throw (error as Error); - } else { - console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); - throw (error as Error); - } - }); - } catch (error) { - console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); - throw (error as Error); - } -} - -async function testAgree() { - /* 1.确定密钥别名并集成并集成要参数集 A设备:srcKeyAliasFirst B设备:srcKeyAliasSecond*/ - /* 2.设备A生成密钥 */ - await publicGenKeyFunc(srcKeyAliasFirst, huksOptions); - /* 3.设备B生成密钥 */ - await publicGenKeyFunc(srcKeyAliasSecond, huksOptions); - /* 4.设备A、B导出非对称密钥的公钥 */ - await publicExportKeyFunc(srcKeyAliasFirst, huksOptions); - exportKeyFirst = exportKey; - await publicExportKeyFunc(srcKeyAliasSecond, huksOptions); - exportKeySecond = exportKey; - /* 5.对第一个密钥进行协商(三段式)*/ - await publicInitFunc(srcKeyAliasFirst, huksOptions); - huksOptions.inData = exportKeySecond; - await publicUpdateFunc(handle, huksOptions); - await publicFinishFunc(handle, finishOptionsFirst); - /* 5.对第二个密钥进行协商(三段式) */ - await publicInitFunc(srcKeyAliasSecond, huksOptions); - huksOptions.inData = exportKeyFirst; - await publicUpdateFunc(handle, huksOptions); - await publicFinishFunc(handle, finishOptionsSecond); - /* 6.设备A、B删除密钥 */ - await publicDeleteKeyFunc(srcKeyAliasFirst, huksOptions); - await publicDeleteKeyFunc(srcKeyAliasSecond, huksOptions); -} - -@Entry -@Component -struct Index { - @State message: string = 'X25519'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.x25519')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await testAgree(); - this.message = 'X25519 Result: Success'; - } catch { - this.message = 'X25519 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* +*以下以X25519密钥的Promise操作使用为例 +*/ +import { huks } from '@kit.UniversalKeystoreKit'; + +/* +* 确定密钥别名和封装密钥属性参数集 +*/ +let srcKeyAliasFirst = 'AgreeX25519KeyFirstAlias'; +let srcKeyAliasSecond = 'AgreeX25519KeySecondAlias'; +let agreeX25519InData = 'AgreeX25519TestIndata'; +let finishOutData: Uint8Array; +let handle: number; +let exportKey: Uint8Array; +let exportKeyFirst: Uint8Array; +let exportKeySecond: Uint8Array; +/* 集成生成密钥参数集 */ +let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_X25519, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_CURVE25519_KEY_SIZE_256, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_CBC, +}, { + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, +}]; +let huksOptions: huks.HuksOptions = { + properties: properties, + inData: new Uint8Array([]) +} +/* 集成第一个协商参数集 */ +const finishProperties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_DERIVED_AGREED_KEY_STORAGE_FLAG, + value: huks.HuksKeyStorageType.HUKS_STORAGE_ONLY_USED_IN_HUKS, +}, { + tag: huks.HuksTag.HUKS_TAG_IS_KEY_ALIAS, + value: true +}, { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_AES, +}, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256, +}, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT, +}, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_NONE, +}, { + tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, + value: huks.HuksCipherMode.HUKS_MODE_ECB, +}]; +let finishOptionsFirst: huks.HuksOptions = { + properties: [ + ...finishProperties, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAliasFirst + 'final'), + }], + inData: stringToUint8Array(agreeX25519InData) +} +/* 集成第二个协商参数集 */ +let finishOptionsSecond: huks.HuksOptions = { + properties: [ + ...finishProperties, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAliasSecond + 'final'), + }], + inData: stringToUint8Array(agreeX25519InData) +} + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +class ThrowObject { + public isThrow: boolean = false +} + +/* 生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 调用generateKeyItem生成密钥 */ +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise generateKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await generateKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +/*初始化密钥会话接口,并获取一个句柄(必选)和挑战值(可选)*/ +function initSession(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.initSession(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/*调用initSession获取handle*/ +async function publicInitFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise doInit`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await initSession(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doInit failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +/* 分段添加密钥操作的数据并进行相应的密钥操作,输出处理数据 */ +function updateSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.updateSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 调用updateSession进行协商操作 */ +async function publicUpdateFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doUpdate`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await updateSession(handle, huksOptions, throwObject) + .then((data) => { + console.info(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doUpdate failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +/* 结束密钥会话并进行相应的密钥操作,输出处理数据 */ +function finishSession(handle: number, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.finishSession(handle, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 调用finishSession结束操作 */ +async function publicFinishFunc(handle: number, huksOptions: huks.HuksOptions) { + console.info(`enter promise doFinish`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await finishSession(handle, huksOptions, throwObject) + .then((data) => { + finishOutData = data.outData as Uint8Array; + console.info(`promise: doFinish success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: doFinish failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +/* 导出密钥 */ +function exportKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.exportKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 调用exportKeyItem导出公钥操作 */ +async function publicExportKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise export`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await exportKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: exportKeyItem success, data = ${JSON.stringify(data)}`); + exportKey = data.outData as Uint8Array; + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: exportKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: exportKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +/* 删除密钥操作 */ +function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: ThrowObject) { + return new Promise((resolve, reject) => { + try { + huks.deleteKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throwObject.isThrow = true; + throw (error as Error); + } + }); +} + +/* 调用deleteKeyItem删除密钥操作 */ +async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) { + console.info(`enter promise deleteKeyItem`); + let throwObject: ThrowObject = { isThrow: false }; + try { + await deleteKeyItem(keyAlias, huksOptions, throwObject) + .then((data) => { + console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + if (throwObject.isThrow) { + throw (error as Error); + } else { + console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`); + throw (error as Error); + } + }); + } catch (error) { + console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`); + throw (error as Error); + } +} + +async function testAgree() { + /* 1.确定密钥别名并集成并集成要参数集 A设备:srcKeyAliasFirst B设备:srcKeyAliasSecond*/ + /* 2.设备A生成密钥 */ + await publicGenKeyFunc(srcKeyAliasFirst, huksOptions); + /* 3.设备B生成密钥 */ + await publicGenKeyFunc(srcKeyAliasSecond, huksOptions); + /* 4.设备A、B导出非对称密钥的公钥 */ + await publicExportKeyFunc(srcKeyAliasFirst, huksOptions); + exportKeyFirst = exportKey; + await publicExportKeyFunc(srcKeyAliasSecond, huksOptions); + exportKeySecond = exportKey; + /* 5.对第一个密钥进行协商(三段式)*/ + await publicInitFunc(srcKeyAliasFirst, huksOptions); + huksOptions.inData = exportKeySecond; + await publicUpdateFunc(handle, huksOptions); + await publicFinishFunc(handle, finishOptionsFirst); + /* 5.对第二个密钥进行协商(三段式) */ + await publicInitFunc(srcKeyAliasSecond, huksOptions); + huksOptions.inData = exportKeyFirst; + await publicUpdateFunc(handle, huksOptions); + await publicFinishFunc(handle, finishOptionsSecond); + /* 6.设备A、B删除密钥 */ + await publicDeleteKeyFunc(srcKeyAliasFirst, huksOptions); + await publicDeleteKeyFunc(srcKeyAliasSecond, huksOptions); +} + +@Entry +@Component +struct Index { + @State message: string = 'X25519'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.x25519')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await testAgree(); + this.message = 'X25519 Result: Success'; + } catch { + this.message = 'X25519 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/KeyExchange.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/KeyExchange.test.ets old mode 100755 new mode 100644 index 0391b7f8583707ce6d246d87f2ef5a8e95830273..7219b914f0330a8d4943cc7828c27d34b39bf2b2 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/KeyExchange.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/KeyExchange.test.ets @@ -1,95 +1,95 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function keyExchangeTest() { - describe('keyExchangeTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,X25519非对称密钥协商 - */ - it('testKeyExchange001', 0, async () => { - console.info('uitest: testKeyExchange001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('X25519')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('X25519').type('Button')); - await button2.click(); - await driver.delayMs(3500); - await driver.assertComponentExist(ON.text('X25519 Result: Success')); - console.info('uitest: testKeyExchange001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,DH密钥协商 - */ - it('testKeyExchange002', 0, async () => { - console.info('uitest: testKeyExchange002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('DH')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('DH').type('Button')); - await button2.click(); - await driver.delayMs(3500); - await driver.assertComponentExist(ON.text('DH Result: Success')); - console.info('uitest: testKeyExchange002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,密钥协商(C/C++) - */ - it('testKeyExchange003', 0, async () => { - console.info('uitest: testKeyExchange003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testKeyExchange003 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function keyExchangeTest() { + describe('keyExchangeTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,X25519非对称密钥协商 + */ + it('testKeyExchange001', 0, async () => { + console.info('uitest: testKeyExchange001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('X25519')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('X25519').type('Button')); + await button2.click(); + await driver.delayMs(3500); + await driver.assertComponentExist(ON.text('X25519 Result: Success')); + console.info('uitest: testKeyExchange001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,DH密钥协商 + */ + it('testKeyExchange002', 0, async () => { + console.info('uitest: testKeyExchange002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('DH')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('DH').type('Button')); + await button2.click(); + await driver.delayMs(3500); + await driver.assertComponentExist(ON.text('DH Result: Success')); + console.info('uitest: testKeyExchange002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,密钥协商(C/C++) + */ + it('testKeyExchange003', 0, async () => { + console.info('uitest: testKeyExchange003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testKeyExchange003 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/ohosTest.md old mode 100755 new mode 100644 index 59477d16241552e7ff0e08dcc9625abcadff569d..d4941cce1b22c08d507fda5ceb805dfe1876e2ae --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/ohosTest.md @@ -1,10 +1,10 @@ -# 密钥协商测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------ | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,X25519非对称密钥协商 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,DH密钥协商 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 密钥协商测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------ | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,X25519非对称密钥协商 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,DH密钥协商 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,密钥协商(C/C++) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/DH_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/DH_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/DH_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/DH_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/X25519_1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/X25519_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/X25519_2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/KeyExchange/screenshots/X25519_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/app.json5 old mode 100755 new mode 100644 index 834bf80281b630d919b88b5920109e79e3ef9c0c..681c2bb041f6e055cb91dae41f51930505aec79e --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/app.json5 @@ -1,25 +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.signingverification", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.signingverification", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index a814cae425f4d4d3572455ca751e24c0d099f7d1..5244c89a0e918b99d3caa2c1dbce5004bac05cb5 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "SigningVerification" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "SigningVerification" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/README.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index ac96cbc6e7a1232edd31c7ba936e2170eb7d3203..376c5456c7f6e87e7a020b2db8a14dc8d9a14912 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(SigningVerification) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(SigningVerification) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 59a744a829c667481037b88374f2af43f19c12af..2145f11cb2626d751fdc2897e4d6f5071b89cc3e --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/napi_init.cpp @@ -1,165 +1,165 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -static struct OH_Huks_Param g_genSignVerifyParamsTest[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}, -}; - -static struct OH_Huks_Param g_signParamsTest[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_SIGN}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}}; - -static struct OH_Huks_Param g_verifyParamsTest[] = { - {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, - {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}}; - -static const uint32_t RSA_COMMON_SIZE = 1024; -static const char *DATA_TO_SIGN = "Hks_RSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000" - "00000000000000000000000000000000000000000000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; - -static napi_value SignVerifyKey(napi_env env, napi_callback_info info) -{ - struct OH_Huks_Blob g_keyAlias = {(uint32_t)strlen("test_signVerify"), (uint8_t *)"test_signVerify"}; - struct OH_Huks_Blob inData = {(uint32_t)strlen(DATA_TO_SIGN), (uint8_t *)DATA_TO_SIGN}; - struct OH_Huks_ParamSet *genParamSet = nullptr; - struct OH_Huks_ParamSet *signParamSet = nullptr; - struct OH_Huks_ParamSet *verifyParamSet = nullptr; - OH_Huks_Result ohResult; - do { - ohResult = InitParamSet(&genParamSet, g_genSignVerifyParamsTest, - sizeof(g_genSignVerifyParamsTest) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = InitParamSet(&signParamSet, g_signParamsTest, sizeof(g_signParamsTest) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - ohResult = - InitParamSet(&verifyParamSet, g_verifyParamsTest, sizeof(g_verifyParamsTest) / - sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 1. Generate Key */ - ohResult = OH_Huks_GenerateKeyItem(&g_keyAlias, genParamSet, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2. Sign */ - // Init - uint8_t handleS[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handleSign = {(uint32_t)sizeof(uint64_t), handleS}; - ohResult = OH_Huks_InitSession(&g_keyAlias, signParamSet, &handleSign, nullptr); - // Update - uint8_t outDataS[RSA_COMMON_SIZE] = {0}; - struct OH_Huks_Blob outDataSign = {RSA_COMMON_SIZE, outDataS}; - ohResult = OH_Huks_UpdateSession(&handleSign, signParamSet, &inData, &outDataSign); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - // Finish - struct OH_Huks_Blob finishInData = {0, NULL}; - ohResult = OH_Huks_FinishSession(&handleSign, signParamSet, &finishInData, &outDataSign); - - /* 3. Verify */ - // Init - uint8_t handleV[sizeof(uint64_t)] = {0}; - struct OH_Huks_Blob handleVerify = {(uint32_t)sizeof(uint64_t), handleV}; - ohResult = OH_Huks_InitSession(&g_keyAlias, verifyParamSet, &handleVerify, nullptr); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - // Update loop - uint8_t temp[] = "out"; - struct OH_Huks_Blob verifyOut = {(uint32_t)sizeof(temp), temp}; - ohResult = OH_Huks_UpdateSession(&handleVerify, verifyParamSet, &inData, &verifyOut); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - // Finish - ohResult = OH_Huks_FinishSession(&handleVerify, verifyParamSet, &outDataSign, &verifyOut); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - } while (0); - (void)OH_Huks_DeleteKeyItem(&g_keyAlias, genParamSet); - OH_Huks_FreeParamSet(&genParamSet); - OH_Huks_FreeParamSet(&signParamSet); - OH_Huks_FreeParamSet(&verifyParamSet); - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - {"signVerifyKey", nullptr, SignVerifyKey, 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); } +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +static struct OH_Huks_Param g_genSignVerifyParamsTest[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_SIGN | OH_HUKS_KEY_PURPOSE_VERIFY}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}, +}; + +static struct OH_Huks_Param g_signParamsTest[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_SIGN}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}}; + +static struct OH_Huks_Param g_verifyParamsTest[] = { + {.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_RSA}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_VERIFY}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_RSA_KEY_SIZE_2048}, + {.tag = OH_HUKS_TAG_PADDING, .uint32Param = OH_HUKS_PADDING_PSS}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_SHA384}}; + +static const uint32_t RSA_COMMON_SIZE = 1024; +static const char *DATA_TO_SIGN = "Hks_RSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; + +static napi_value SignVerifyKey(napi_env env, napi_callback_info info) +{ + struct OH_Huks_Blob g_keyAlias = {(uint32_t)strlen("test_signVerify"), (uint8_t *)"test_signVerify"}; + struct OH_Huks_Blob inData = {(uint32_t)strlen(DATA_TO_SIGN), (uint8_t *)DATA_TO_SIGN}; + struct OH_Huks_ParamSet *genParamSet = nullptr; + struct OH_Huks_ParamSet *signParamSet = nullptr; + struct OH_Huks_ParamSet *verifyParamSet = nullptr; + OH_Huks_Result ohResult; + do { + ohResult = InitParamSet(&genParamSet, g_genSignVerifyParamsTest, + sizeof(g_genSignVerifyParamsTest) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = InitParamSet(&signParamSet, g_signParamsTest, sizeof(g_signParamsTest) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + ohResult = + InitParamSet(&verifyParamSet, g_verifyParamsTest, sizeof(g_verifyParamsTest) / + sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 1. Generate Key */ + ohResult = OH_Huks_GenerateKeyItem(&g_keyAlias, genParamSet, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2. Sign */ + // Init + uint8_t handleS[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handleSign = {(uint32_t)sizeof(uint64_t), handleS}; + ohResult = OH_Huks_InitSession(&g_keyAlias, signParamSet, &handleSign, nullptr); + // Update + uint8_t outDataS[RSA_COMMON_SIZE] = {0}; + struct OH_Huks_Blob outDataSign = {RSA_COMMON_SIZE, outDataS}; + ohResult = OH_Huks_UpdateSession(&handleSign, signParamSet, &inData, &outDataSign); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + // Finish + struct OH_Huks_Blob finishInData = {0, NULL}; + ohResult = OH_Huks_FinishSession(&handleSign, signParamSet, &finishInData, &outDataSign); + + /* 3. Verify */ + // Init + uint8_t handleV[sizeof(uint64_t)] = {0}; + struct OH_Huks_Blob handleVerify = {(uint32_t)sizeof(uint64_t), handleV}; + ohResult = OH_Huks_InitSession(&g_keyAlias, verifyParamSet, &handleVerify, nullptr); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + // Update loop + uint8_t temp[] = "out"; + struct OH_Huks_Blob verifyOut = {(uint32_t)sizeof(temp), temp}; + ohResult = OH_Huks_UpdateSession(&handleVerify, verifyParamSet, &inData, &verifyOut); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + // Finish + ohResult = OH_Huks_FinishSession(&handleVerify, verifyParamSet, &outDataSign, &verifyOut); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + } while (0); + (void)OH_Huks_DeleteKeyItem(&g_keyAlias, genParamSet); + OH_Huks_FreeParamSet(&genParamSet); + OH_Huks_FreeParamSet(&signParamSet); + OH_Huks_FreeParamSet(&verifyParamSet); + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"signVerifyKey", nullptr, SignVerifyKey, 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index d451b1ef8898b3d8aec9737da4eb7a332eb4123a..d5ab38249969b5a1fb1ba8f2fbc77c0348101bad --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 signVerifyKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/ECC256SHA256.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/ECC256SHA256.ets old mode 100755 new mode 100644 index dcc3acc992c346680bf2e50ea3370af7c4236aa3..5d6d9db93182f99391d8ff7eadd760c651d43452 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/ECC256SHA256.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/ECC256SHA256.ets @@ -1,213 +1,213 @@ -/* - * 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. - */ - -/* - * 密钥算法为ECC256、摘要算法为SHA256 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let keyAlias = 'test_eccKeyAlias'; -let handle: number; -let plaintext = '123456'; -let signature: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getEccGenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_ECC - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -function getEccSignProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_ECC - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -function getEccVerifyProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_ECC - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -async function generateEccKey(keyAlias: string) { - let genProperties = getEccGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - await huks.generateKeyItem(keyAlias, options) - .then((data) => { - console.info(`promise: generate ECC Key success, data = ${JSON.stringify(data)}`); - }).catch((err: Error) => { - console.error(`promise: generate ECC Key failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function sign(keyAlias: string, plaintext: string) { - let signProperties = getEccSignProperties(); - let options: huks.HuksOptions = { - properties: signProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - signature = data.outData as Uint8Array; - }).catch((err: Error) => { - console.error(`promise: sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { - let verifyProperties = getEccVerifyProperties() - let options: huks.HuksOptions = { - properties: verifyProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - await huks.updateSession(handle, options) - .then((data) => { - console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - options.inData = signature; - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function deleteEccKey(keyAlias: string) { - let emptyOptions: huks.HuksOptions = { - properties: [] - } - await huks.deleteKeyItem(keyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((err: Error) => { - console.error(`promise: delete data failed`); - throw (err as Error); - }) -} - -async function testSignVerify() { - await generateEccKey(keyAlias); - await sign(keyAlias, plaintext); - await verify(keyAlias, plaintext, signature); - await deleteEccKey(keyAlias); -} - -@Entry -@Component -struct Index { - @State message: string = 'ECC256/SHA256'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.ecc256_sha256')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await testSignVerify(); - this.message = 'ECC256/SHA256 Result: Success'; - } catch (error) { - this.message = 'ECC256/SHA256 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 密钥算法为ECC256、摘要算法为SHA256 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let keyAlias = 'test_eccKeyAlias'; +let handle: number; +let plaintext = '123456'; +let signature: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getEccGenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_ECC + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +function getEccSignProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_ECC + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +function getEccVerifyProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_ECC + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +async function generateEccKey(keyAlias: string) { + let genProperties = getEccGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + await huks.generateKeyItem(keyAlias, options) + .then((data) => { + console.info(`promise: generate ECC Key success, data = ${JSON.stringify(data)}`); + }).catch((err: Error) => { + console.error(`promise: generate ECC Key failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function sign(keyAlias: string, plaintext: string) { + let signProperties = getEccSignProperties(); + let options: huks.HuksOptions = { + properties: signProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + signature = data.outData as Uint8Array; + }).catch((err: Error) => { + console.error(`promise: sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { + let verifyProperties = getEccVerifyProperties() + let options: huks.HuksOptions = { + properties: verifyProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + await huks.updateSession(handle, options) + .then((data) => { + console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + options.inData = signature; + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function deleteEccKey(keyAlias: string) { + let emptyOptions: huks.HuksOptions = { + properties: [] + } + await huks.deleteKeyItem(keyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((err: Error) => { + console.error(`promise: delete data failed`); + throw (err as Error); + }) +} + +async function testSignVerify() { + await generateEccKey(keyAlias); + await sign(keyAlias, plaintext); + await verify(keyAlias, plaintext, signature); + await deleteEccKey(keyAlias); +} + +@Entry +@Component +struct Index { + @State message: string = 'ECC256/SHA256'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.ecc256_sha256')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await testSignVerify(); + this.message = 'ECC256/SHA256 Result: Success'; + } catch (error) { + this.message = 'ECC256/SHA256 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PKCS1_V1_5.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PKCS1_V1_5.ets old mode 100755 new mode 100644 index f0de12b0e575000da5e1e7cac5ec60af7f69bf07..9217e18295f653be2fde13612c977d2479922cd5 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PKCS1_V1_5.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PKCS1_V1_5.ets @@ -1,215 +1,215 @@ -/* - * 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. - */ - -/* - * 密钥算法为RSA,摘要算法为SHA256,填充模式为PKCS1_V1_5 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let keyAlias = 'test_rsaKeyAlias'; -let handle: number; -let plaintext = '123456'; -let signature: Uint8Array; - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getRsaGenerateProperties() { - let properties: huks.HuksParam[] = [ - { tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_RSA }, - { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, - { tag: huks.HuksTag.HUKS_TAG_PADDING, value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 }, - { tag: huks.HuksTag.HUKS_TAG_DIGEST, value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 } - ]; - return properties; -} - -function getRsaSignProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -function getRsaVerifyProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -async function generateRsaKey(keyAlias: string) { - let genProperties = getRsaGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - await huks.generateKeyItem(keyAlias, options) - .then((data) => { - console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); - }).catch((err: Error) => { - console.error(`promise: generate RSA Key failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function sign(keyAlias: string, plaintext: string) { - let signProperties = getRsaSignProperties(); - let options: huks.HuksOptions = { - properties: signProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - signature = data.outData as Uint8Array; - }).catch((err: Error) => { - console.error(`promise: sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { - let verifyProperties = getRsaVerifyProperties() - let options: huks.HuksOptions = { - properties: verifyProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - await huks.updateSession(handle, options) - .then((data) => { - console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - options.inData = signature; - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function deleteRsaKey(keyAlias: string) { - let emptyOptions: huks.HuksOptions = { - properties: [] - } - await huks.deleteKeyItem(keyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((err: Error) => { - console.error(`promise: delete data failed`); - throw (err as Error); - }) -} - -export async function testSignVerify() { - await generateRsaKey(keyAlias); - await sign(keyAlias, plaintext); - await verify(keyAlias, plaintext, signature); - await deleteRsaKey(keyAlias); -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA/SHA256/PKCS1_V1_5'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.rsa_sha256_pkcs1_v1_5')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await testSignVerify(); - this.message = 'RSA/SHA256/PKCS1_V1_5 Result: Success'; - } catch (error) { - this.message = 'RSA/SHA256/PKCS1_V1_5 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 密钥算法为RSA,摘要算法为SHA256,填充模式为PKCS1_V1_5 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let keyAlias = 'test_rsaKeyAlias'; +let handle: number; +let plaintext = '123456'; +let signature: Uint8Array; + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getRsaGenerateProperties() { + let properties: huks.HuksParam[] = [ + { tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_RSA }, + { tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, + { tag: huks.HuksTag.HUKS_TAG_PADDING, value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 }, + { tag: huks.HuksTag.HUKS_TAG_DIGEST, value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 } + ]; + return properties; +} + +function getRsaSignProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +function getRsaVerifyProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5 + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +async function generateRsaKey(keyAlias: string) { + let genProperties = getRsaGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + await huks.generateKeyItem(keyAlias, options) + .then((data) => { + console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); + }).catch((err: Error) => { + console.error(`promise: generate RSA Key failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function sign(keyAlias: string, plaintext: string) { + let signProperties = getRsaSignProperties(); + let options: huks.HuksOptions = { + properties: signProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + signature = data.outData as Uint8Array; + }).catch((err: Error) => { + console.error(`promise: sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { + let verifyProperties = getRsaVerifyProperties() + let options: huks.HuksOptions = { + properties: verifyProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + await huks.updateSession(handle, options) + .then((data) => { + console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + options.inData = signature; + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function deleteRsaKey(keyAlias: string) { + let emptyOptions: huks.HuksOptions = { + properties: [] + } + await huks.deleteKeyItem(keyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((err: Error) => { + console.error(`promise: delete data failed`); + throw (err as Error); + }) +} + +export async function testSignVerify() { + await generateRsaKey(keyAlias); + await sign(keyAlias, plaintext); + await verify(keyAlias, plaintext, signature); + await deleteRsaKey(keyAlias); +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA/SHA256/PKCS1_V1_5'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.rsa_sha256_pkcs1_v1_5')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await testSignVerify(); + this.message = 'RSA/SHA256/PKCS1_V1_5 Result: Success'; + } catch (error) { + this.message = 'RSA/SHA256/PKCS1_V1_5 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PSS.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PSS.ets old mode 100755 new mode 100644 index 9aa3789686259015d97c754aaa16fbca5e404313..2058afcc2ed081a7c9e1444653fc6e589a507721 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PSS.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/RSASHA256PSS.ets @@ -1,223 +1,223 @@ -/* - * 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. - */ - -/* - * 密钥算法为RSA,摘要算法为SHA256,填充模式为PSS - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let keyAlias = 'test_rsaKeyAlias'; -let handle: number; -let plaintext = '123456'; -let signature: Uint8Array; - -function stringToUint8Array(str: string) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - -function getRsaGenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PSS - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }]; - return properties; -} - -function getRsaSignProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PSS - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN - }]; - return properties; -} - -function getRsaVerifyProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_RSA - }, { - tag: huks.HuksTag.HUKS_TAG_PADDING, - value: huks.HuksKeyPadding.HUKS_PADDING_PSS - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }]; - return properties; -} - -async function generateRsaKey(keyAlias: string) { - let genProperties = getRsaGenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - }; - await huks.generateKeyItem(keyAlias, options) - .then((data) => { - console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); - }).catch((err: Error) => { - console.error(`promise: generate RSA Key failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }); -} - -async function sign(keyAlias: string, plaintext: string) { - let signProperties = getRsaSignProperties(); - let options: huks.HuksOptions = { - properties: signProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); - return; - }); - - if (handle !== undefined) { - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - signature = data.outData as Uint8Array; - }).catch((err: Error) => { - console.error(`promise: sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }); - } -} - -async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { - let verifyProperties = getRsaVerifyProperties(); - let options: huks.HuksOptions = { - properties: verifyProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); - return; - }); - - if (handle !== undefined) { - await huks.updateSession(handle, options) - .then((data) => { - console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }); - - options.inData = signature; - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }); - } -} - -async function deleteRsaKey(keyAlias: string) { - let emptyOptions: huks.HuksOptions = { - properties: [] - } - await huks.deleteKeyItem(keyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((err: Error) => { - console.error(`promise: delete data failed`); - throw (err as Error); - }); -} - -export async function testSignVerify() { - await generateRsaKey(keyAlias); - await sign(keyAlias, plaintext); - await verify(keyAlias, plaintext, signature); - await deleteRsaKey(keyAlias); -} - -@Entry -@Component -struct Index { - @State message: string = 'RSA/SHA256/PSS'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.rsa_sha256_pss')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - await testSignVerify(); - this.message = 'RSA/SHA256/PSS Result: Success'; - }catch { - this.message = 'RSA/SHA256/PSS Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 密钥算法为RSA,摘要算法为SHA256,填充模式为PSS + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let keyAlias = 'test_rsaKeyAlias'; +let handle: number; +let plaintext = '123456'; +let signature: Uint8Array; + +function stringToUint8Array(str: string) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + +function getRsaGenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_RSA_KEY_SIZE_2048 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PSS + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }]; + return properties; +} + +function getRsaSignProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PSS + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN + }]; + return properties; +} + +function getRsaVerifyProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_RSA + }, { + tag: huks.HuksTag.HUKS_TAG_PADDING, + value: huks.HuksKeyPadding.HUKS_PADDING_PSS + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }]; + return properties; +} + +async function generateRsaKey(keyAlias: string) { + let genProperties = getRsaGenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + }; + await huks.generateKeyItem(keyAlias, options) + .then((data) => { + console.info(`promise: generate RSA Key success, data = ${JSON.stringify(data)}`); + }).catch((err: Error) => { + console.error(`promise: generate RSA Key failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }); +} + +async function sign(keyAlias: string, plaintext: string) { + let signProperties = getRsaSignProperties(); + let options: huks.HuksOptions = { + properties: signProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); + return; + }); + + if (handle !== undefined) { + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + signature = data.outData as Uint8Array; + }).catch((err: Error) => { + console.error(`promise: sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }); + } +} + +async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { + let verifyProperties = getRsaVerifyProperties(); + let options: huks.HuksOptions = { + properties: verifyProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); + return; + }); + + if (handle !== undefined) { + await huks.updateSession(handle, options) + .then((data) => { + console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }); + + options.inData = signature; + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }); + } +} + +async function deleteRsaKey(keyAlias: string) { + let emptyOptions: huks.HuksOptions = { + properties: [] + } + await huks.deleteKeyItem(keyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((err: Error) => { + console.error(`promise: delete data failed`); + throw (err as Error); + }); +} + +export async function testSignVerify() { + await generateRsaKey(keyAlias); + await sign(keyAlias, plaintext); + await verify(keyAlias, plaintext, signature); + await deleteRsaKey(keyAlias); +} + +@Entry +@Component +struct Index { + @State message: string = 'RSA/SHA256/PSS'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.rsa_sha256_pss')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + await testSignVerify(); + this.message = 'RSA/SHA256/PSS Result: Success'; + }catch { + this.message = 'RSA/SHA256/PSS Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/SM2SM3.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/SM2SM3.ets old mode 100755 new mode 100644 index d8d926059142894deaff188cc096a3d51ed7d92a..801a695e76ac84248f0ec4591bb5db3085c9d8d9 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/SM2SM3.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/ets/pages/SM2SM3.ets @@ -1,216 +1,216 @@ -/* - * 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. - */ - -/* - * 密钥算法为SM2、摘要算法为SM3 - */ -import { huks } from '@kit.UniversalKeystoreKit'; - -let keyAlias = 'test_sm2KeyAlias'; -let handle: number; -let plaintext = '123456'; -let signature: Uint8Array; - - -function stringToUint8Array(str: String) { - let arr: number[] = []; - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); -} - - -function uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; -} - - -function getSm2GenerateProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM2 - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | - huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 - }]; - return properties; -} - -function getSm2SignProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM2 - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 - }]; - return properties; -} - -function getSm2VerifyProperties() { - let properties: huks.HuksParam[] = [{ - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_SM2 - }, { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 - }, { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY - }, { - tag: huks.HuksTag.HUKS_TAG_DIGEST, - value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 - }]; - return properties; -} - -async function generateSm2Key(keyAlias: string) { - let genProperties = getSm2GenerateProperties(); - let options: huks.HuksOptions = { - properties: genProperties - } - await huks.generateKeyItem(keyAlias, options) - .then((data) => { - console.info(`promise: generate Sm2 Key success, data = ${JSON.stringify(data)}`); - }).catch((err: Error) => { - console.error(`promise: generate Sm2 Key failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function sign(keyAlias: string, plaintext: string) { - let signProperties = getSm2SignProperties(); - let options: huks.HuksOptions = { - properties: signProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - signature = data.outData as Uint8Array; - }).catch((err: Error) => { - console.error(`promise: sign failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { - let verifyProperties = getSm2VerifyProperties() - let options: huks.HuksOptions = { - properties: verifyProperties, - inData: stringToUint8Array(plaintext) - } - await huks.initSession(keyAlias, options) - .then((data) => { - handle = data.handle; - }).catch((err: Error) => { - console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - await huks.updateSession(handle, options) - .then((data) => { - console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) - options.inData = signature; - await huks.finishSession(handle, options) - .then((data) => { - console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); - }).catch((err: Error) => { - console.error(`promise: verify failed, error: ` + JSON.stringify(err)); - throw (err as Error); - }) -} - -async function deleteSm2Key(keyAlias: string) { - let emptyOptions: huks.HuksOptions = { - properties: [] - } - await huks.deleteKeyItem(keyAlias, emptyOptions) - .then((data) => { - console.info(`promise: delete data success`); - }).catch((err: Error) => { - console.error(`promise: delete data failed`); - throw (err as Error); - }) -} - -export async function testSignVerify() { - await generateSm2Key(keyAlias); - await sign(keyAlias, plaintext); - await verify(keyAlias, plaintext, signature); - await deleteSm2Key(keyAlias); -} - -@Entry -@Component -struct Index { - @State message: string = 'SM2/SM3'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.sm2_sm3')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(async () => { - try { - let ret = await testSignVerify(); - this.message = 'SM2/SM3 Result: Success'; - } catch { - this.message = 'SM2/SM3 Result: Failed'; - } - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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. + */ + +/* + * 密钥算法为SM2、摘要算法为SM3 + */ +import { huks } from '@kit.UniversalKeystoreKit'; + +let keyAlias = 'test_sm2KeyAlias'; +let handle: number; +let plaintext = '123456'; +let signature: Uint8Array; + + +function stringToUint8Array(str: String) { + let arr: number[] = []; + for (let i = 0, j = str.length; i < j; ++i) { + arr.push(str.charCodeAt(i)); + } + return new Uint8Array(arr); +} + + +function uint8ArrayToString(fileData: Uint8Array) { + let dataString = ''; + for (let i = 0; i < fileData.length; i++) { + dataString += String.fromCharCode(fileData[i]); + } + return dataString; +} + + +function getSm2GenerateProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM2 + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN | + huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 + }]; + return properties; +} + +function getSm2SignProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM2 + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_SIGN + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 + }]; + return properties; +} + +function getSm2VerifyProperties() { + let properties: huks.HuksParam[] = [{ + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_SM2 + }, { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256 + }, { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_VERIFY + }, { + tag: huks.HuksTag.HUKS_TAG_DIGEST, + value: huks.HuksKeyDigest.HUKS_DIGEST_SM3 + }]; + return properties; +} + +async function generateSm2Key(keyAlias: string) { + let genProperties = getSm2GenerateProperties(); + let options: huks.HuksOptions = { + properties: genProperties + } + await huks.generateKeyItem(keyAlias, options) + .then((data) => { + console.info(`promise: generate Sm2 Key success, data = ${JSON.stringify(data)}`); + }).catch((err: Error) => { + console.error(`promise: generate Sm2 Key failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function sign(keyAlias: string, plaintext: string) { + let signProperties = getSm2SignProperties(); + let options: huks.HuksOptions = { + properties: signProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: sign success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + signature = data.outData as Uint8Array; + }).catch((err: Error) => { + console.error(`promise: sign failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function verify(keyAlias: string, plaintext: string, signature: Uint8Array) { + let verifyProperties = getSm2VerifyProperties() + let options: huks.HuksOptions = { + properties: verifyProperties, + inData: stringToUint8Array(plaintext) + } + await huks.initSession(keyAlias, options) + .then((data) => { + handle = data.handle; + }).catch((err: Error) => { + console.error(`promise: init verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + await huks.updateSession(handle, options) + .then((data) => { + console.info(`promise: update verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: update verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) + options.inData = signature; + await huks.finishSession(handle, options) + .then((data) => { + console.info(`promise: verify success, data is ` + uint8ArrayToString(data.outData as Uint8Array)); + }).catch((err: Error) => { + console.error(`promise: verify failed, error: ` + JSON.stringify(err)); + throw (err as Error); + }) +} + +async function deleteSm2Key(keyAlias: string) { + let emptyOptions: huks.HuksOptions = { + properties: [] + } + await huks.deleteKeyItem(keyAlias, emptyOptions) + .then((data) => { + console.info(`promise: delete data success`); + }).catch((err: Error) => { + console.error(`promise: delete data failed`); + throw (err as Error); + }) +} + +export async function testSignVerify() { + await generateSm2Key(keyAlias); + await sign(keyAlias, plaintext); + await verify(keyAlias, plaintext, signature); + await deleteSm2Key(keyAlias); +} + +@Entry +@Component +struct Index { + @State message: string = 'SM2/SM3'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.sm2_sm3')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(async () => { + try { + let ret = await testSignVerify(); + this.message = 'SM2/SM3 Result: Success'; + } catch { + this.message = 'SM2/SM3 Result: Failed'; + } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/SigningVerification.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/SigningVerification.test.ets old mode 100755 new mode 100644 index 7006b7be9ca078180baaa81f420789bb57116588..d609d5490616eaeb5a30d07d6858f3ddb379a239 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/SigningVerification.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/ets/test/SigningVerification.test.ets @@ -1,131 +1,131 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function signingVerificationTest() { - describe('signingVerificationTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,签名/验签ECC256/SHA256 - */ - it('testSigningVerification001', 0, async () => { - console.info('uitest: testSigningVerification001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('ECC256/SHA256')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('ECC256/SHA256').type('Button')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('ECC256/SHA256 Result: Success')); - console.info('uitest: testSigningVerification001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,签名/验签SM2/SM3 - */ - it('testSigningVerification002', 0, async () => { - console.info('uitest: testSigningVerification002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('SM2/SM3')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('SM2/SM3').type('Button')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('SM2/SM3 Result: Success')); - console.info('uitest: testSigningVerification002 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,签名/验签RSA/SHA256/PSS - */ - it('testSigningVerification003', 0, async () => { - console.info('uitest: testSigningVerification003 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA/SHA256/PSS')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('RSA/SHA256/PSS').type('Button')); - await button2.click(); - await driver.delayMs(4000); - await driver.assertComponentExist(ON.text('RSA/SHA256/PSS Result: Success')); - console.info('uitest: testSigningVerification003 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,签名/验签RSA/SHA256/PKCS1_V1_5 - */ - it('testSigningVerification004', 0, async () => { - console.info('uitest: testSigningVerification004 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('RSA/SHA256/PKCS1_V1_5')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('RSA/SHA256/PKCS1_V1_5').type('Button')); - await button2.click(); - await driver.delayMs(4000); - await driver.assertComponentExist(ON.text('RSA/SHA256/PKCS1_V1_5 Result: Success')); - console.info('uitest: testSigningVerification004 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,签名/验签C/C++ - */ - it('testSigningVerification005', 0, async () => { - console.info('uitest: testSigningVerification005 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testSigningVerification005 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function signingVerificationTest() { + describe('signingVerificationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,签名/验签ECC256/SHA256 + */ + it('testSigningVerification001', 0, async () => { + console.info('uitest: testSigningVerification001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ECC256/SHA256')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('ECC256/SHA256').type('Button')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECC256/SHA256 Result: Success')); + console.info('uitest: testSigningVerification001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,签名/验签SM2/SM3 + */ + it('testSigningVerification002', 0, async () => { + console.info('uitest: testSigningVerification002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('SM2/SM3')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('SM2/SM3').type('Button')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2/SM3 Result: Success')); + console.info('uitest: testSigningVerification002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,签名/验签RSA/SHA256/PSS + */ + it('testSigningVerification003', 0, async () => { + console.info('uitest: testSigningVerification003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA/SHA256/PSS')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('RSA/SHA256/PSS').type('Button')); + await button2.click(); + await driver.delayMs(4000); + await driver.assertComponentExist(ON.text('RSA/SHA256/PSS Result: Success')); + console.info('uitest: testSigningVerification003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,签名/验签RSA/SHA256/PKCS1_V1_5 + */ + it('testSigningVerification004', 0, async () => { + console.info('uitest: testSigningVerification004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('RSA/SHA256/PKCS1_V1_5')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('RSA/SHA256/PKCS1_V1_5').type('Button')); + await button2.click(); + await driver.delayMs(4000); + await driver.assertComponentExist(ON.text('RSA/SHA256/PKCS1_V1_5 Result: Success')); + console.info('uitest: testSigningVerification004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,签名/验签C/C++ + */ + it('testSigningVerification005', 0, async () => { + console.info('uitest: testSigningVerification005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testSigningVerification005 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/ohosTest.md old mode 100755 new mode 100644 index c53c86e8016d5fa57e5f52daf35ca7e031b72e5c..8bd7bdea561b7fad69db096765bf34eb8c8111be --- a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/ohosTest.md @@ -1,12 +1,12 @@ -# 签名/验签测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ---------------------------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,签名/验签ECC256/SHA256 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,签名/验签SM2/SM3 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,签名/验签RSA/SHA256/PSS | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | -| 点击按钮,签名/验签RSA/SHA256/PKCS1_V1_5 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 签名/验签测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,签名/验签ECC256/SHA256 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,签名/验签SM2/SM3 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,签名/验签RSA/SHA256/PSS | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +| 点击按钮,签名/验签RSA/SHA256/PKCS1_V1_5 | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,签名/验签C/C++ | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/ECC2561.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/ECC2561.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/ECC2562.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/ECC2562.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/RSA1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/RSA1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/RSA2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/RSA2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SHA2561.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SHA2561.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SHA2562.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SHA2562.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SM21.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SM21.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SM22.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/SM22.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/cpp1.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/cpp1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/cpp2.png b/code/DocsSample/Security/UniversalKeystoreKit/KeyUsage/SigningVerification/screenshots/cpp2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/app.json5 old mode 100755 new mode 100644 index 03eb12b21817988b8947030e5cc5934e29400334..70552995056a2f9c64bbe4113945a75b0c3eeed6 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/app.json5 @@ -1,25 +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.checkkeyexists", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.checkkeyexists", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index d5af2732332b3179fde0115e8219b6ea0c1c7ddd..b52da87a06229d9c75fba2ecef8ac99052d55017 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "CheckKeyExists" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "CheckKeyExists" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/README.md b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index c15a8e8f36fb04d81b74b6d9e43c2f18498438cf..1fa27ba437437c563ec5cf148d4d1c9e61f74437 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(CheckKeyExists) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(CheckKeyExists) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 81b1ce5a0fd6cb37ac6566ba52e6d52330bb560d..2746990617fa8df4473c2c5a5e6c0908e9fde9fa --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/napi_init.cpp @@ -1,116 +1,116 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -/* 以下以生成ECC密钥为例 */ -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; - -static OH_Huks_Result GenerateKeyHelper(const char *alias) -{ - struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; - struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; - struct OH_Huks_Result ohResult; - do { - /* 1.初始化密钥属性集 */ - ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, - sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2.生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); - } while (0); - OH_Huks_FreeParamSet(&testGenerateKeyParamSet); - return ohResult; -} - -static napi_value IsKeyExist(napi_env env, napi_callback_info info) -{ - /* 1.获取密钥别名 */ - const char *alias = "test_key"; - struct OH_Huks_Blob keyAlias = { - (uint32_t)strlen(alias), - (uint8_t *)alias - }; - - /* 生成密钥 */ - OH_Huks_Result genResult = GenerateKeyHelper(alias); - if (genResult.errorCode != OH_HUKS_SUCCESS) { - napi_value ret; - napi_create_int32(env, genResult.errorCode, &ret); - return ret; - } - - /* 2.调用OH_Huks_IsKeyItemExist判断密钥是否存在 */ - struct OH_Huks_Result ohResult = OH_Huks_IsKeyItemExist(&keyAlias, nullptr); - // OH_HUKS_SUCCESS表示存在, OH_HUKS_ERR_CODE_ITEM_NOT_EXIST表示不存在 - - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "isKeyExist", nullptr, IsKeyExist, 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); -} +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +/* 以下以生成ECC密钥为例 */ +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static OH_Huks_Result GenerateKeyHelper(const char *alias) +{ + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + /* 1.初始化密钥属性集 */ + ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, + sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2.生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); + } while (0); + OH_Huks_FreeParamSet(&testGenerateKeyParamSet); + return ohResult; +} + +static napi_value IsKeyExist(napi_env env, napi_callback_info info) +{ + /* 1.获取密钥别名 */ + const char *alias = "test_key"; + struct OH_Huks_Blob keyAlias = { + (uint32_t)strlen(alias), + (uint8_t *)alias + }; + + /* 生成密钥 */ + OH_Huks_Result genResult = GenerateKeyHelper(alias); + if (genResult.errorCode != OH_HUKS_SUCCESS) { + napi_value ret; + napi_create_int32(env, genResult.errorCode, &ret); + return ret; + } + + /* 2.调用OH_Huks_IsKeyItemExist判断密钥是否存在 */ + struct OH_Huks_Result ohResult = OH_Huks_IsKeyItemExist(&keyAlias, nullptr); + // OH_HUKS_SUCCESS表示存在, OH_HUKS_ERR_CODE_ITEM_NOT_EXIST表示不存在 + + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "isKeyExist", nullptr, IsKeyExist, 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index c8feb77db6dceb96c69363d46be30362d8990dd8..d13f949ed36ef22f9d5593606a56f77e2f773183 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 isKeyExist: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/pages/CheckKeyExists.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/pages/CheckKeyExists.ets old mode 100755 new mode 100644 index b3dcfc0d85bedbe95d4bebe9302ab9a32fddac6f..d42753c3dc8b2b28e22ef5f1a2dff99fbd2502f8 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/pages/CheckKeyExists.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/pages/CheckKeyExists.ets @@ -1,136 +1,136 @@ -/* - * 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 { huks } from '@kit.UniversalKeystoreKit'; - -/* 1.确定密钥别名 */ -let keyAlias = 'test_key'; -let isKeyExist: Boolean; -/* 2.构造空对象 */ -let huksOptions: huks.HuksOptions = { - properties: [] -} - -/* 3.初始化密钥属性集 */ -let generateProperties: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_DH - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 - } -]; - -let generateHuksOptions: huks.HuksOptions = { - properties: generateProperties, - inData: new Uint8Array([]) -} - -/* 3.生成密钥 */ -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise generateKeyItem`); - try { - await generateKeyItem(keyAlias, huksOptions) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - }); - return 'Success'; - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); - return 'Failed'; - } -} - -async function testGenKey(): Promise { - let ret = await publicGenKeyFunc(keyAlias, generateHuksOptions); - return ret; -} - -function check(): string { - try { - /* 1.生成密钥 */ - testGenKey(); - /* 2.判断密钥是否存在 */ - huks.hasKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - console.error(`callback: hasKeyItem failed, ` + JSON.stringify(error)); - } else { - if (data !== null && data.valueOf() !== null) { - isKeyExist = data.valueOf(); - console.info(`callback: hasKeyItem success, isKeyExist = ${isKeyExist}`); - } - } - }); - return 'Success'; - } catch (error) { - console.error(`callback: hasKeyItem input arg invalid, ` + JSON.stringify(error)); - return 'Failed'; - } -} - -@Entry -@Component -struct Index { - @State message: string = 'CheckKeyExists'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_check_key_exists')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - let ret: string = check(); - this.message = 'CheckKeyExists Result: ' + ret; - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; + +/* 1.确定密钥别名 */ +let keyAlias = 'test_key'; +let isKeyExist: Boolean; +/* 2.构造空对象 */ +let huksOptions: huks.HuksOptions = { + properties: [] +} + +/* 3.初始化密钥属性集 */ +let generateProperties: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 + } +]; + +let generateHuksOptions: huks.HuksOptions = { + properties: generateProperties, + inData: new Uint8Array([]) +} + +/* 3.生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise generateKeyItem`); + try { + await generateKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + }); + return 'Success'; + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ` + JSON.stringify(error)); + return 'Failed'; + } +} + +async function testGenKey(): Promise { + let ret = await publicGenKeyFunc(keyAlias, generateHuksOptions); + return ret; +} + +function check(): string { + try { + /* 1.生成密钥 */ + testGenKey(); + /* 2.判断密钥是否存在 */ + huks.hasKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + console.error(`callback: hasKeyItem failed, ` + JSON.stringify(error)); + } else { + if (data !== null && data.valueOf() !== null) { + isKeyExist = data.valueOf(); + console.info(`callback: hasKeyItem success, isKeyExist = ${isKeyExist}`); + } + } + }); + return 'Success'; + } catch (error) { + console.error(`callback: hasKeyItem input arg invalid, ` + JSON.stringify(error)); + return 'Failed'; + } +} + +@Entry +@Component +struct Index { + @State message: string = 'CheckKeyExists'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_check_key_exists')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + let ret: string = check(); + this.message = 'CheckKeyExists Result: ' + ret; + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/CheckKeyExists.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/CheckKeyExists.test.ets old mode 100755 new mode 100644 index 8647c8c7e322f3736b08463f24e25c089b659643..a41b084cd3264659743e16fe4d5084effa8e7870 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/CheckKeyExists.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/CheckKeyExists.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function checkKeyExistsTest() { - describe('checkKeyExistsTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,查询密钥是否存在(ArkTS) - */ - it('testCheckKeyExists001', 0, async () => { - console.info('uitest: testCheckKeyExists001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('CheckKeyExists').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call CheckKeyExists')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('CheckKeyExists Result: Success')); - console.info('uitest: testCheckKeyExists001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,查询密钥是否存在(C/C++) - */ - it('testCheckKeyExists002', 0, async () => { - console.info('uitest: testCheckKeyExists002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testCheckKeyExists002 end'); - await driver.pressBack(); - }) - }) -} +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function checkKeyExistsTest() { + describe('checkKeyExistsTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,查询密钥是否存在(ArkTS) + */ + it('testCheckKeyExists001', 0, async () => { + console.info('uitest: testCheckKeyExists001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('CheckKeyExists').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call CheckKeyExists')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('CheckKeyExists Result: Success')); + console.info('uitest: testCheckKeyExists001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,查询密钥是否存在(C/C++) + */ + it('testCheckKeyExists002', 0, async () => { + console.info('uitest: testCheckKeyExists002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testCheckKeyExists002 end'); + await driver.pressBack(); + }) + }) +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/ohosTest.md old mode 100755 new mode 100644 index b9a0aadfd5c7e6e99bcf7d069ab5a940e4dffe39..e672dd2ab8813a2e1fbafc70a03aaefb7c7df2e4 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/ohosTest.md @@ -1,9 +1,9 @@ -## 查询密钥是否存在测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| --------------------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,查询密钥是否存在(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +## 查询密钥是否存在测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,查询密钥是否存在(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,查询密钥是否存在(C/C++) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/CheckKeyExists_1.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/CheckKeyExists_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/CheckKeyExists_2.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/CheckKeyExists_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/CheckKeyExists/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/app.json5 old mode 100755 new mode 100644 index 79d423e06565c1bb79086ab6ee3e047da739e6f1..6827bed80198b0b7fe24863d996bafa9b4b45d61 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/app.json5 @@ -1,25 +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.getkeyattributes", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.getkeyattributes", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 079011dd5dabbcdc5e2b03dec7b97631f2f629bd..c5f9a78ef244f536d43207ccfca07f51ba5df965 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "GetKeyAttributes" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "GetKeyAttributes" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/README.md b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index c12d3b9c8cf9b99cb821a33359f2c0aa2c41983d..a411957596688e3191fffdc435b89ccefd5ea388 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(GetKeyAttributes) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(GetKeyAttributes) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index f12c2e5c701eab8484c5656c93f283c9b87102ab..52b71e1ff3f962f4bf1cf8f1c0fb5cd879982436 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/napi_init.cpp @@ -1,130 +1,130 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; - -static OH_Huks_Result GenerateKeyHelper(const char *alias) -{ - struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; - struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; - struct OH_Huks_Result ohResult; - do { - /* 1.初始化密钥属性集 */ - ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, - sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 1.生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); - } while (0); - OH_Huks_FreeParamSet(&testGenerateKeyParamSet); - return ohResult; -} - -static napi_value GetKeyParamSet(napi_env env, napi_callback_info info) -{ - /* 1. 参数构造:确定密钥别名 */ - const char *alias = "test_key"; - struct OH_Huks_Blob aliasBlob = { .size = (uint32_t)strlen(alias), .data = (uint8_t *)alias }; - /* 生成密钥 */ - OH_Huks_Result genResult = GenerateKeyHelper(alias); - if (genResult.errorCode != OH_HUKS_SUCCESS) { - napi_value ret; - napi_create_int32(env, genResult.errorCode, &ret); - return ret; - } - const size_t paramSetSize = 512; - /* 构造参数:为参数集申请内存 - * 请业务按实际情况评估大小进行申请 - */ - struct OH_Huks_ParamSet *outParamSet = static_cast(malloc(paramSetSize)); - if (outParamSet == nullptr) { - return nullptr; - } - outParamSet->paramSetSize = paramSetSize; - struct OH_Huks_Result ohResult; - do { - /* 2. 获取密钥属性集 */ - ohResult = OH_Huks_GetKeyItemParamSet(&aliasBlob, nullptr, outParamSet); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 3. 从参数集中读取参数,以OH_HUKS_TAG_PURPOSE为例 */ - OH_Huks_Param *purposeParam = nullptr; // 无需申请内存,获取后指针指向该参数在参数集中所处内存地址 - ohResult = OH_Huks_GetParam(outParamSet, OH_HUKS_TAG_PURPOSE, &purposeParam); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - } while (0); - OH_Huks_FreeParamSet(&outParamSet); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "getKeyParamSet", nullptr, GetKeyParamSet, 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); -} +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static OH_Huks_Result GenerateKeyHelper(const char *alias) +{ + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + /* 1.初始化密钥属性集 */ + ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, + sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 1.生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); + } while (0); + OH_Huks_FreeParamSet(&testGenerateKeyParamSet); + return ohResult; +} + +static napi_value GetKeyParamSet(napi_env env, napi_callback_info info) +{ + /* 1. 参数构造:确定密钥别名 */ + const char *alias = "test_key"; + struct OH_Huks_Blob aliasBlob = { .size = (uint32_t)strlen(alias), .data = (uint8_t *)alias }; + /* 生成密钥 */ + OH_Huks_Result genResult = GenerateKeyHelper(alias); + if (genResult.errorCode != OH_HUKS_SUCCESS) { + napi_value ret; + napi_create_int32(env, genResult.errorCode, &ret); + return ret; + } + const size_t paramSetSize = 512; + /* 构造参数:为参数集申请内存 + * 请业务按实际情况评估大小进行申请 + */ + struct OH_Huks_ParamSet *outParamSet = static_cast(malloc(paramSetSize)); + if (outParamSet == nullptr) { + return nullptr; + } + outParamSet->paramSetSize = paramSetSize; + struct OH_Huks_Result ohResult; + do { + /* 2. 获取密钥属性集 */ + ohResult = OH_Huks_GetKeyItemParamSet(&aliasBlob, nullptr, outParamSet); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 3. 从参数集中读取参数,以OH_HUKS_TAG_PURPOSE为例 */ + OH_Huks_Param *purposeParam = nullptr; // 无需申请内存,获取后指针指向该参数在参数集中所处内存地址 + ohResult = OH_Huks_GetParam(outParamSet, OH_HUKS_TAG_PURPOSE, &purposeParam); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + } while (0); + OH_Huks_FreeParamSet(&outParamSet); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "getKeyParamSet", nullptr, GetKeyParamSet, 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index bb850cef0e8d015d5915306b6b7715b3cb5535c6..daea8fc76737836657d12c5451c00838339620a8 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 getKeyParamSet: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/pages/GetKeyAttributes.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/pages/GetKeyAttributes.ets old mode 100755 new mode 100644 index 1ef4abdbbc87c62218f7793ab04a84e7199e72dd..0301267cfc073cfb8eda534db6b8e1596cd42471 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/pages/GetKeyAttributes.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/pages/GetKeyAttributes.ets @@ -1,131 +1,131 @@ -/* - * 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 { huks } from '@kit.UniversalKeystoreKit'; - -/* 1. 设置密钥别名 */ -let keyAlias = 'keyAlias'; -/* option对象传空 */ -let emptyOptions: huks.HuksOptions = { - properties: [] -}; - -let properties1: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_DH - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 - } -]; - -let huksOptions: huks.HuksOptions = { - properties: properties1, - inData: new Uint8Array([]) -} - -/* 3.生成密钥 */ -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise generateKeyItem`); - try { - await generateKeyItem(keyAlias, huksOptions) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - }); - return 'Success'; - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -async function testGenKey(): Promise { - let ret = await publicGenKeyFunc(keyAlias, huksOptions); - return ret; -} - -function check(): string { - try { - /* 1. 生成密钥 */ - testGenKey(); - /* 2. 获取密钥属性 */ - huks.getKeyItemProperties(keyAlias, emptyOptions, (error, data) => { - if (error) { - console.error(`callback: getKeyItemProperties failed, ${JSON.stringify(error)}`); - } else { - console.info(`callback: getKeyItemProperties success, data = ${JSON.stringify(data)}`); - } - }); - return 'Success'; - } catch (error) { - console.error(`callback: getKeyItemProperties input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -@Entry -@Component -struct Index { - @State message: string = 'GetKeyAttributes'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_get_key_attributes')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - let ret: string = check(); - this.message = 'GetKeyAttributes Result: ' + ret; - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; + +/* 1. 设置密钥别名 */ +let keyAlias = 'keyAlias'; +/* option对象传空 */ +let emptyOptions: huks.HuksOptions = { + properties: [] +}; + +let properties1: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 + } +]; + +let huksOptions: huks.HuksOptions = { + properties: properties1, + inData: new Uint8Array([]) +} + +/* 3.生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise generateKeyItem`); + try { + await generateKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + }); + return 'Success'; + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +async function testGenKey(): Promise { + let ret = await publicGenKeyFunc(keyAlias, huksOptions); + return ret; +} + +function check(): string { + try { + /* 1. 生成密钥 */ + testGenKey(); + /* 2. 获取密钥属性 */ + huks.getKeyItemProperties(keyAlias, emptyOptions, (error, data) => { + if (error) { + console.error(`callback: getKeyItemProperties failed, ${JSON.stringify(error)}`); + } else { + console.info(`callback: getKeyItemProperties success, data = ${JSON.stringify(data)}`); + } + }); + return 'Success'; + } catch (error) { + console.error(`callback: getKeyItemProperties input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +@Entry +@Component +struct Index { + @State message: string = 'GetKeyAttributes'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_get_key_attributes')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + let ret: string = check(); + this.message = 'GetKeyAttributes Result: ' + ret; + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/GetKeyAttributes.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/GetKeyAttributes.test.ets old mode 100755 new mode 100644 index b389e340051ee1646a24e649e91a9d430b573732..0b3b396fee0a3adfbb73224f5f5f9524dc1b4051 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/GetKeyAttributes.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/GetKeyAttributes.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function getKeyAttributesTest() { - describe('getKeyAttributesTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,获取密钥属性(ArkTS) - */ - it('testGetKeyAttributes001', 0, async () => { - console.info('uitest: testGetKeyAttributes001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('GetKeyAttributes').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call GetKeyAttributes')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('GetKeyAttributes Result: Success')); - console.info('uitest: testGetKeyAttributes001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,获取密钥属性(C/C++) - */ - it('testGetKeyAttributes002', 0, async () => { - console.info('uitest: testGetKeyAttributes002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testGetKeyAttributes002 end'); - await driver.pressBack(); - }) - }) -} +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function getKeyAttributesTest() { + describe('getKeyAttributesTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,获取密钥属性(ArkTS) + */ + it('testGetKeyAttributes001', 0, async () => { + console.info('uitest: testGetKeyAttributes001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('GetKeyAttributes').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call GetKeyAttributes')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('GetKeyAttributes Result: Success')); + console.info('uitest: testGetKeyAttributes001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,获取密钥属性(C/C++) + */ + it('testGetKeyAttributes002', 0, async () => { + console.info('uitest: testGetKeyAttributes002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testGetKeyAttributes002 end'); + await driver.pressBack(); + }) + }) +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/ohosTest.md old mode 100755 new mode 100644 index f94cbca75087f2a1a1c7effe084b6f43c2fc409e..9ff789ae85df086bb1526ca9cfd26c07f9dd8cf8 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/ohosTest.md @@ -1,9 +1,9 @@ -# 获取密钥属性测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ----------------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 获取密钥属性(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 获取密钥属性测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ----------------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 获取密钥属性(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,获取密钥属性(C/C++) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/GetKeyAttributes_1.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/GetKeyAttributes_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/GetKeyAttributes_2.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/GetKeyAttributes/screenshots/GetKeyAttributes_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/app.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/app.json5 old mode 100755 new mode 100644 index 6af55fd49d7ec489d3165ea6a80e42cb2f5b31d5..4ee18eb53cdc1e92a3feaf8aa0372f4e473cc77d --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/app.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/app.json5 @@ -1,25 +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.keyexport", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * 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.keyexport", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 6b14bfbaf86178383bb299c464fdf00b2eef2c6e..31f53443c81a19a32b55c841faa917f046e58704 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/resources/base/element/string.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "KeyExport" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "KeyExport" + } + ] +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/resources/base/media/app_icon.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/README.md b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/README.md old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/build-profile.json5 old mode 100755 new mode 100644 index df8b8004f9207069a86cc1b12716cdcdb73f9072..9a067264a40737cf79d1d8ae7c574b8d2cc87ce0 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/build-profile.json5 @@ -1,58 +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": 14, - "compatibleSdkVersion": 14, - "targetSdkVersion": 14, - "runtimeOS": "OpenHarmony", - "buildOption": { - "strictMode": { - "caseSensitiveCheck": true, - "useNormalizedOHMUrl": true - } - } - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * 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": 14, + "compatibleSdkVersion": 14, + "targetSdkVersion": 14, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/code-linter.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/code-linter.json5 old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/.gitignore b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/.gitignore old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/build-profile.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/build-profile.json5 old mode 100755 new mode 100644 index 5612a9a1db33c953c5d474210a9a9576d1afd4d4..31862257476bc8403e59fa42b4c924974d7dbe03 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/build-profile.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/build-profile.json5 @@ -1,59 +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. - */ - -{ - "apiType": "stageMode", - "buildOption": { - "externalNativeOptions": { - "path": "./src/main/cpp/CMakeLists.txt", - "arguments": "", - "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64", - "armeabi-v7a" - ] - } - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": false, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - }, - "nativeLib": { - "debugSymbol": { - "strip": true, - "exclude": [] - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * 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", + "armeabi-v7a" + ] + } + }, + "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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/oh-package.json5 old mode 100755 new mode 100644 index 5d993e5251fd56950970aa593aefef1b8d71e976..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/oh-package.json5 @@ -1,26 +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" - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/CMakeLists.txt old mode 100755 new mode 100644 index 482cdaa452e5b8a51cd008ed046196a420d69f4d..5b291e7135972a0c84baf4d606e22fe2c45f9353 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/CMakeLists.txt +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/CMakeLists.txt @@ -1,15 +1,15 @@ -# the minimum version of CMake. -cmake_minimum_required(VERSION 3.5.0) -project(KeyExport) - -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) +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(KeyExport) + +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 libhuks_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/napi_init.cpp old mode 100755 new mode 100644 index 33abf36c07a3e2a4553f7e3771027c69162f76a7..7646616778c8159aaa31d1e6bed46256459620c7 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/napi_init.cpp +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/napi_init.cpp @@ -1,121 +1,121 @@ -/* - * 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 "huks/native_huks_api.h" -#include "huks/native_huks_param.h" -#include "napi/native_api.h" -#include - -/* 以下以生成ECC密钥为例 */ -OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, - uint32_t paramCount) -{ - OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - return ret; - } - ret = OH_Huks_AddParams(*paramSet, params, paramCount); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - ret = OH_Huks_BuildParamSet(paramSet); - if (ret.errorCode != OH_HUKS_SUCCESS) { - OH_Huks_FreeParamSet(paramSet); - return ret; - } - return ret; -} - -struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, - {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, - {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, - {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; - -static OH_Huks_Result GenerateKeyHelper(const char *alias) -{ - struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; - struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; - struct OH_Huks_Result ohResult; - do { - /* 1.初始化密钥属性集 */ - ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, - sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - /* 2.生成密钥 */ - ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); - } while (0); - OH_Huks_FreeParamSet(&testGenerateKeyParamSet); - return ohResult; -} - -static napi_value ExportKey(napi_env env, napi_callback_info info) -{ - /* 1. 参数构造:确定密钥别名 */ - const char *alias = "test_key"; - struct OH_Huks_Blob aliasBlob = { .size = (uint32_t)strlen(alias), .data = (uint8_t *)alias }; - /* 生成密钥 */ - OH_Huks_Result genResult = GenerateKeyHelper(alias); - if (genResult.errorCode != OH_HUKS_SUCCESS) { - napi_value ret; - napi_create_int32(env, genResult.errorCode, &ret); - return ret; - } - /* 构造参数:为待导出公钥申请内存 */ - uint8_t *pubKey = (uint8_t *)malloc(512); // 请业务按实际密钥大小评估申请 - if (pubKey == nullptr) { - return nullptr; - } - struct OH_Huks_Blob keyBlob = { 256, pubKey }; - struct OH_Huks_Result ohResult; - do { - ohResult = OH_Huks_ExportPublicKeyItem(&aliasBlob, nullptr, &keyBlob); - if (ohResult.errorCode != OH_HUKS_SUCCESS) { - break; - } - } while (0); - free(pubKey); - napi_value ret; - napi_create_int32(env, ohResult.errorCode, &ret); - return ret; -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "exportKey", nullptr, ExportKey, 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); -} +/* + * 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 "huks/native_huks_api.h" +#include "huks/native_huks_param.h" +#include "napi/native_api.h" +#include + +/* 以下以生成ECC密钥为例 */ +OH_Huks_Result InitParamSet(struct OH_Huks_ParamSet **paramSet, const struct OH_Huks_Param *params, + uint32_t paramCount) +{ + OH_Huks_Result ret = OH_Huks_InitParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + return ret; + } + ret = OH_Huks_AddParams(*paramSet, params, paramCount); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + ret = OH_Huks_BuildParamSet(paramSet); + if (ret.errorCode != OH_HUKS_SUCCESS) { + OH_Huks_FreeParamSet(paramSet); + return ret; + } + return ret; +} + +struct OH_Huks_Param g_testGenerateKeyParam[] = {{.tag = OH_HUKS_TAG_ALGORITHM, .uint32Param = OH_HUKS_ALG_ECC}, + {.tag = OH_HUKS_TAG_PURPOSE, .uint32Param = OH_HUKS_KEY_PURPOSE_AGREE}, + {.tag = OH_HUKS_TAG_KEY_SIZE, .uint32Param = OH_HUKS_ECC_KEY_SIZE_256}, + {.tag = OH_HUKS_TAG_DIGEST, .uint32Param = OH_HUKS_DIGEST_NONE}}; + +static OH_Huks_Result GenerateKeyHelper(const char *alias) +{ + struct OH_Huks_Blob aliasBlob = {.size = (uint32_t)strlen(alias), .data = (uint8_t *)alias}; + struct OH_Huks_ParamSet *testGenerateKeyParamSet = nullptr; + struct OH_Huks_Result ohResult; + do { + /* 1.初始化密钥属性集 */ + ohResult = InitParamSet(&testGenerateKeyParamSet, g_testGenerateKeyParam, + sizeof(g_testGenerateKeyParam) / sizeof(OH_Huks_Param)); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + /* 2.生成密钥 */ + ohResult = OH_Huks_GenerateKeyItem(&aliasBlob, testGenerateKeyParamSet, nullptr); + } while (0); + OH_Huks_FreeParamSet(&testGenerateKeyParamSet); + return ohResult; +} + +static napi_value ExportKey(napi_env env, napi_callback_info info) +{ + /* 1. 参数构造:确定密钥别名 */ + const char *alias = "test_key"; + struct OH_Huks_Blob aliasBlob = { .size = (uint32_t)strlen(alias), .data = (uint8_t *)alias }; + /* 生成密钥 */ + OH_Huks_Result genResult = GenerateKeyHelper(alias); + if (genResult.errorCode != OH_HUKS_SUCCESS) { + napi_value ret; + napi_create_int32(env, genResult.errorCode, &ret); + return ret; + } + /* 构造参数:为待导出公钥申请内存 */ + uint8_t *pubKey = (uint8_t *)malloc(512); // 请业务按实际密钥大小评估申请 + if (pubKey == nullptr) { + return nullptr; + } + struct OH_Huks_Blob keyBlob = { 256, pubKey }; + struct OH_Huks_Result ohResult; + do { + ohResult = OH_Huks_ExportPublicKeyItem(&aliasBlob, nullptr, &keyBlob); + if (ohResult.errorCode != OH_HUKS_SUCCESS) { + break; + } + } while (0); + free(pubKey); + napi_value ret; + napi_create_int32(env, ohResult.errorCode, &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "exportKey", nullptr, ExportKey, 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/index.d.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/index.d.ts old mode 100755 new mode 100644 index 406132e484e49351c4d87c51a8ec0195ce8eca55..a9a8bde79fb4162899309919dfa2331cb823290e --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/index.d.ts +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/index.d.ts @@ -1,16 +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. - */ - +/* + * 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 exportKey: () => number; \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/oh-package.json5 old mode 100755 new mode 100644 index e8f69f3d7619ec71489946af3b6f83522b32de76..2826cc7d6bd199c1008bb51d898dffa922201e6c --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -1,21 +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." +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entryability/EntryAbility.ets old mode 100755 new mode 100644 index 3e77e4b9f7946d80aa77e6b2dcfe40b23ccf6178..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +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'); - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets old mode 100755 new mode 100644 index 1504a74f09dfdcfae408be979f99369a2c5affab..b1e212947256c5533c7b06285a597c94f840a6e3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +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)); - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/pages/KeyExport.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/pages/KeyExport.ets old mode 100755 new mode 100644 index 8d01c74c1e9978e65e0d9fa9efd736f70d111074..c340b719732e8f2f0481e7ba6a62b7ae922e9211 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/pages/KeyExport.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/ets/pages/KeyExport.ets @@ -1,131 +1,131 @@ -/* - * 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 { huks } from '@kit.UniversalKeystoreKit'; - -/* 1. 设置密钥别名 */ -let keyAlias = 'keyAlias'; -/* option对象传空 */ -let emptyOptions: huks.HuksOptions = { - properties: [] -}; - -let properties1: huks.HuksParam[] = [ - { - tag: huks.HuksTag.HUKS_TAG_ALGORITHM, - value: huks.HuksKeyAlg.HUKS_ALG_DH - }, - { - tag: huks.HuksTag.HUKS_TAG_PURPOSE, - value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE - }, - { - tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, - value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 - } -]; - -let huksOptions: huks.HuksOptions = { - properties: properties1, - inData: new Uint8Array([]) -} - -/* 3.生成密钥 */ -function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { - return new Promise((resolve, reject) => { - try { - huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { - if (error) { - reject(error); - } else { - resolve(data); - } - }); - } catch (error) { - throw (error as Error); - } - }); -} - -async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { - console.info(`enter promise generateKeyItem`); - try { - await generateKeyItem(keyAlias, huksOptions) - .then((data) => { - console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); - }) - .catch((error: Error) => { - console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); - }); - return 'Success'; - } catch (error) { - console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -async function testGenKey(): Promise { - let ret = await publicGenKeyFunc(keyAlias, huksOptions); - return ret; -} - -function check(): string { - try { - /* 1. 生成密钥 */ - testGenKey() - /* 2. 导出密钥 */ - huks.exportKeyItem(keyAlias, emptyOptions, (error, data) => { - if (error) { - console.error(`callback: exportKeyItem failed, ` + error); - } else { - console.info(`callback: exportKeyItem success, data = ${JSON.stringify(data)}`); - } - }); - return 'Success'; - } catch (error) { - console.error(`callback: exportKeyItem input arg invalid, ${JSON.stringify(error)}`); - return 'Failed'; - } -} - -@Entry -@Component -struct Index { - @State message: string = 'KeyExport'; - - build() { - Column({ space: 12 }) { - Text(this.message) - .fontWeight(FontWeight.Regular) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .maxLines(Infinity) - .textAlign(TextAlign.Start) - Button($r('app.string.call_keyExport')) - .padding('12vp') - .height('40vp') - .borderRadius($r('sys.float.ohos_id_corner_radius_button')) - .backgroundColor($r('sys.color.ohos_id_color_emphasize')) - .fontSize('14sp') - .fontColor('#ffffff') - .onClick(() => { - let ret: string = check(); - this.message = 'KeyExport Result: ' + ret; - }) - } - .height('100%') - .width('100%') - } -} +/* + * 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 { huks } from '@kit.UniversalKeystoreKit'; + +/* 1. 设置密钥别名 */ +let keyAlias = 'keyAlias'; +/* option对象传空 */ +let emptyOptions: huks.HuksOptions = { + properties: [] +}; + +let properties1: huks.HuksParam[] = [ + { + tag: huks.HuksTag.HUKS_TAG_ALGORITHM, + value: huks.HuksKeyAlg.HUKS_ALG_DH + }, + { + tag: huks.HuksTag.HUKS_TAG_PURPOSE, + value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_AGREE + }, + { + tag: huks.HuksTag.HUKS_TAG_KEY_SIZE, + value: huks.HuksKeySize.HUKS_DH_KEY_SIZE_2048 + } +]; + +let huksOptions: huks.HuksOptions = { + properties: properties1, + inData: new Uint8Array([]) +} + +/* 3.生成密钥 */ +function generateKeyItem(keyAlias: string, huksOptions: huks.HuksOptions) { + return new Promise((resolve, reject) => { + try { + huks.generateKeyItem(keyAlias, huksOptions, (error, data) => { + if (error) { + reject(error); + } else { + resolve(data); + } + }); + } catch (error) { + throw (error as Error); + } + }); +} + +async function publicGenKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions): Promise { + console.info(`enter promise generateKeyItem`); + try { + await generateKeyItem(keyAlias, huksOptions) + .then((data) => { + console.info(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch((error: Error) => { + console.error(`promise: generateKeyItem failed, ${JSON.stringify(error)}`); + }); + return 'Success'; + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +async function testGenKey(): Promise { + let ret = await publicGenKeyFunc(keyAlias, huksOptions); + return ret; +} + +function check(): string { + try { + /* 1. 生成密钥 */ + testGenKey() + /* 2. 导出密钥 */ + huks.exportKeyItem(keyAlias, emptyOptions, (error, data) => { + if (error) { + console.error(`callback: exportKeyItem failed, ` + error); + } else { + console.info(`callback: exportKeyItem success, data = ${JSON.stringify(data)}`); + } + }); + return 'Success'; + } catch (error) { + console.error(`callback: exportKeyItem input arg invalid, ${JSON.stringify(error)}`); + return 'Failed'; + } +} + +@Entry +@Component +struct Index { + @State message: string = 'KeyExport'; + + build() { + Column({ space: 12 }) { + Text(this.message) + .fontWeight(FontWeight.Regular) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .maxLines(Infinity) + .textAlign(TextAlign.Start) + Button($r('app.string.call_keyExport')) + .padding('12vp') + .height('40vp') + .borderRadius($r('sys.float.ohos_id_corner_radius_button')) + .backgroundColor($r('sys.color.ohos_id_color_emphasize')) + .fontSize('14sp') + .fontColor('#ffffff') + .onClick(() => { + let ret: string = check(); + this.message = 'KeyExport Result: ' + ret; + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/module.json5 old mode 100755 new mode 100644 index 776ce01475229d674487a2830790c4c87b777379..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/module.json5 @@ -1,66 +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" - } - ] - } - ] - } +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/element/string.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/background.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/background.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/foreground.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/layered_image.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/media/startIcon.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/profile/backup_config.json old mode 100755 new mode 100644 index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/profile/backup_config.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/dark/element/color.json old mode 100755 new mode 100644 index 438d5bc43bb23c59c210d586b96635a72da5b64a..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/dark/element/color.json +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/main/resources/dark/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/KeyExport.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/KeyExport.test.ets old mode 100755 new mode 100644 index f233530c8d70c16f81d6b7d15d2f7b5c6f6d11ce..dd36f06100eac3e606a31c56121f931a59d9442d --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/KeyExport.test.ets +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/KeyExport.test.ets @@ -1,77 +1,77 @@ -/* - * 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, beforeAll } from '@ohos/hypium'; -// 导入测试依赖kit -import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; -import { UIAbility, Want } from '@kit.AbilityKit'; - -const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); -const bundleName = abilityDelegatorRegistry.getArguments().bundleName; -let want: Want; - -export default function keyExportTest() { - describe('keyExportTest', () => { - /** - * 打开应用 - */ - beforeAll(async () => { - want = { - bundleName: bundleName, - abilityName: 'EntryAbility' - }; - await delegator.startAbility(want); - const driver = Driver.create(); - await driver.delayMs(1000); - const ability: UIAbility = await delegator.getCurrentTopAbility(); - console.info('get top ability'); - await driver.delayMs(1000); - expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); - }) - - /** - * 点击按钮,密钥导出(ArkTS) - */ - it('testKeyExport001', 0, async () => { - console.info('uitest: testKeyExport001 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('KeyExport').type('Button')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - const button2 = await driver.findComponent(ON.text('Call KeyExport')); - await button2.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('KeyExport Result: Success')); - console.info('uitest: testKeyExport001 end'); - await driver.pressBack(); - }) - - /** - * 点击按钮,密钥导出(C/C++) - */ - it('testKeyExport002', 0, async () => { - console.info('uitest: testKeyExport002 begin'); - const driver = Driver.create(); - const button1 = await driver.findComponent(ON.text('Call C/C++')); - await driver.delayMs(1000); - await button1.click(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); - console.info('uitest: testKeyExport002 end'); - await driver.pressBack(); - }) - }) +/* + * 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, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function keyExportTest() { + describe('keyExportTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,密钥导出(ArkTS) + */ + it('testKeyExport001', 0, async () => { + console.info('uitest: testKeyExport001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('KeyExport').type('Button')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call KeyExport')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('KeyExport Result: Success')); + console.info('uitest: testKeyExport001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,密钥导出(C/C++) + */ + it('testKeyExport002', 0, async () => { + console.info('uitest: testKeyExport002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call C/C++')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Call C/C++ Result: 0')); + console.info('uitest: testKeyExport002 end'); + await driver.pressBack(); + }) + }) } \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/module.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 9983b2ba4e55e31a172f0328c82c9a75bfa00ded..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/module.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/ohosTest/module.json5 @@ -1,27 +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 - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/test/List.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/entry/src/test/LocalUnit.test.ets old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/hvigor/hvigor-config.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index cef74543b1f97c82275e4bf3434b162395bff2eb..d584c19c247db9a7caee4b606bb931aa9279c637 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/hvigor/hvigor-config.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/hvigor/hvigor-config.json5 @@ -1,37 +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*/ - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/hvigorfile.ts b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/oh-package.json5 b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/oh-package.json5 old mode 100755 new mode 100644 index eaef52736f22c14e04fca386ba01611ab32a7e4a..e41bae026aab3b50d0abb42fece08ba43b4a772b --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/oh-package.json5 +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/oh-package.json5 @@ -1,25 +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" - } -} +/* + * 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/Security/UniversalKeystoreKit/OtherOperations/KeyExport/ohosTest.md b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/ohosTest.md old mode 100755 new mode 100644 index 695e9b34ac4a800119752adaff6701939f5ed23c..2f97b8c42f110059a18893aa733f1d6aae4f18f3 --- a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/ohosTest.md +++ b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/ohosTest.md @@ -1,9 +1,9 @@ -# 密钥导出测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------- | ------------ | ---- | ------------------ | -------- | -------- | -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | -| 点击按钮,密钥导出(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | +# 密钥导出测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------- | ------------ | ---- | ------------------ | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,密钥导出(ArkTS) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | | 点击按钮,密钥导出(C/C++) | 成功拉起应用 | | 成功执行,输出日志 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/Cpp_1.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/Cpp_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/Cpp_2.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/Cpp_2.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/KeyExport_1.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/KeyExport_1.png old mode 100755 new mode 100644 diff --git a/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/KeyExport_2.png b/code/DocsSample/Security/UniversalKeystoreKit/OtherOperations/KeyExport/screenshots/KeyExport_2.png old mode 100755 new mode 100644 diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/app.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/app.json5 index dd320f51bca402384b154865275d0e418d1bec87..5a35ef2b308d10bbbcf9098abdb27a128fdd3cc0 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/app.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.concurrentmodule", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.concurrentmodule", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/resources/base/element/string.json b/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/resources/base/element/string.json index bc6e0a7a403c2a92add277ff53937decb9b4cdb8..33d5dba8d042bb35eb2f204d772df8ca550489f2 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/resources/base/element/string.json +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "ConcurrentModule" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "ConcurrentModule" + } + ] +} diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/build-profile.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/build-profile.json5 index 611c4b002d256b0fdda47ae9ece5ad0dfa9e6bb8..6755644553d13a6cb28e3537529701e3952c61e6 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/build-profile.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony", - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/build-profile.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/build-profile.json5 index cc72131cc3db1118a2204916114100244c74a1eb..0d0cc70644830558add6a79f59c8d47815428d92 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/build-profile.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/build-profile.json5 @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2024 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": { - "sourceOption": { - "workers": [ - './src/main/ets/workers/Worker.ts', - "./src/main/ets/workers/WorkerCopy.ts", - ] - } - }, - "targets": [ - { - "name": "default", - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 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": { + "sourceOption": { + "workers": [ + './src/main/ets/workers/Worker.ts', + "./src/main/ets/workers/WorkerCopy.ts", + ] + } + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/oh-package.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/oh-package.json5 index 4be95c59ce0dede7a66d6fcb2e3018c8011f838a..3fbe67bbf8193c883bab1ccea7be318bc3a65bdb 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/oh-package.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/TaskPoolTab.ets b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/TaskPoolTab.ets index 74c4f818f2cad063cc3b1afebf37fdc8891368de..3c31ad51e26d94f433349a92ddc87bbaae5cb0fd 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/TaskPoolTab.ets +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/TaskPoolTab.ets @@ -1,430 +1,430 @@ -/* - * Copyright (c) 2024 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 taskpool from '@ohos.taskpool'; -import utils from '@arkts.utils'; -import stack from '@ohos.util.Stack'; -import { BusinessError } from '@ohos.base'; -import { SendableClass, a } from './SendableTest'; -import { TestA, TestB } from './test' - -@Component -export struct TaskPoolTab { - @State taskPoolOutPutStr: string = ''; - @State taskPoolInPutStr: string = ''; - taskPoolInPutArr: string[] = []; - isTaskGroup : boolean = false; - gStack: stack = new stack(); - taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup(); - - - build() { - Column() { - Text($r('app.string.Text_desc')) - .width("100%") - .height("48vp") - .position({ x: "7%", y: "0" }) - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#182431") - .lineHeight(22) - .fontWeight(500) - - Button() { - Row() { - Image($r('app.media.public_add')) - .width(20) - .height(20) - .margin({ left: 4 }) - Text($r('app.string.Add_task')) - .width("75%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("14fp") - .fontColor("#182431") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - } - .id("addButton") - .height("10vp") - .borderRadius("10vp") - .backgroundColor("#00000000") - .position({ x: "67%", y: "1.5%" }) - .width(135) - .height(35) - .onClick(() => { - this.taskAdd(); - }) - - Button() { - Row() { - Image($r('app.media.empties')) - .width(20) - .height(20) - .margin({ left: 4 }) - Text($r('app.string.Clear_desc')) - .width("35%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("14fp") - .fontColor("#182431") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - } - .id("taskPoolClearButton") - .height("10vp") - .borderRadius("10vp") - .backgroundColor("#00000000") - .position({ x: "71%", y: "31.5%" }) - .width(135) - .height(35) - .onClick(() => { - this.Clear(); - }) - - TextArea({placeholder:$r('app.string.Default_desc'), text:this.taskPoolInPutStr}) - .id("taskPoolInPutTextArea") - .width("93.3%") - .height("139vp") - .position({ x: "3.3%", y: "48vp" }) - .textAlign(TextAlign.Start) - .borderRadius("24vp") - .backgroundColor("#ffffff") - .fontFamily("HarmonyHeiTi") - .fontSize("16fp") - .fontColor("#182431") - .fontWeight(400) - .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) - .onChange((value: string) => { - this.taskPoolInPutStr = value; - this.taskPoolInPutArr = this.taskPoolInPutStr.trim().split(','); - this.taskPoolOutPutStr = ''; - }) - - Text($r('app.string.Result_desc')) - .width("50%") - .height("48") - .position({ x: "7%", y: "187vp" }) - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#182431") - .lineHeight(22) - .fontWeight(500) - - Scroll() { - Text(this.taskPoolOutPutStr) - .id("taskPoolOutPutText") - .fontFamily("HarmonyHeiTi") - .fontSize("16fp") - .fontColor("#182431") - .fontWeight(400) - .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) - } - .id("taskPoolOutPutScroll") - .width("93.3%") - .height("139vp") - .position({ x: "3.3%", y: "235vp" }) - .borderRadius("24vp") - .backgroundColor("#ffffff") - .align(Alignment.TopStart) - - GridRow({columns: 4, - gutter: { x: 12, y: 12 }, - breakpoints: { value: ["360vp", "480vp"]}, - direction: GridRowDirection.Row}) { - GridCol ({ span: 2, offset: 0 }) { - Button() { - Text($r('app.string.Execute_After_3s_desc')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#007DFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("exeDelayButton") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("rgba(24,36,49,0.05)") - .onClick(()=>{ - this.executeDelay(); - }) - } - - GridCol ({ span: 2, offset: 0 }) { - Button() { - Text($r('app.string.Execute_Immediately_desc')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#FFFFFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("exeImmButton") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("#007DFF") - .onClick(()=>{ - if(this.isTaskGroup == true) { - this.TaskGroupExec(); - } else { - this.executeImmediately(); - } - }) - } - - GridCol ({ span: 2, offset: 0 }) { - Button() { - Text($r('app.string.Function_Task_desc')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#007DFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("exeFunctionButton") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("rgba(24,36,49,0.05)") - .onClick(()=>{ - this.executeFunc(); - }) - } - - GridCol ({ span: 2, offset: 0 }) { - Button() { - Text($r('app.string.Cancel_Task_desc')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#FFFFFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("exeCancelButton") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("#007DFF") - .onClick(()=>{ - this.cancelTask(); - }) - } - - GridCol ({ span: 4, offset: 0 }) { - Button() { - Text($r('app.string.transferSendableClass')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#007DFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("sendableButton") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("rgba(24,36,49,0.05)") - .onClick(()=>{ - this.sendableTask(); - }) - } - } - .width("100%") - .height("168vp") - .position({ x: "0", y: "73%" }) - .padding({ left: "25vp", right: "25vp" }) - } - .width("100%") - .height("100%") - .justifyContent(FlexAlign.Center) - } - - async executeImmediately(): Promise { - if (!this.taskPoolInPutStr.length) { - this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; - return; - } - let task = new taskpool.Task(strSort,this.taskPoolInPutArr); - this.gStack.push(task); - try { - let result: taskpool.Task = await taskpool.execute(task) as taskpool.Task; - this.taskPoolOutPutStr += "Task executed successfully: "+ result.toString()+ "\n"; - } catch(e) { - this.taskPoolOutPutStr += "Task executed failed: "+ (e as BusinessError).toString()+ "\n"; - } - this.gStack.pop(); - } - - async executeDelay(): Promise { - if (!this.taskPoolInPutStr.length) { - this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; - return; - } - let task = new taskpool.Task(strSortDelay,this.taskPoolInPutArr); - this.gStack.push(task); - try { - let result: string[] = await taskpool.execute(task) as string[]; - this.taskPoolOutPutStr += "Task executed successfully: "+ result.toString()+ "\n"; - } catch(e) { - this.taskPoolOutPutStr += "Task executed failed: "+ (e as BusinessError).toString() + "\n"; - } - this.gStack.pop(); - } - - async executeFunc(): Promise { - if (!this.taskPoolInPutStr.length) { - this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; - return; - } - try { - let result: string[] = await taskpool.execute(strSort,this.taskPoolInPutArr) as string[]; - this.taskPoolOutPutStr += "Task executed successfully: "+ result.toString()+ "\n"; - } catch(e) { - this.taskPoolOutPutStr += "Task executed failed: "+ (e as BusinessError).toString()+ "\n"; - } - } - - async taskAdd(): Promise { - if (!this.taskPoolInPutStr.length) { - this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; - return; - } - try { - let task: taskpool.Task = new taskpool.Task(strSort, this.taskPoolInPutArr); - this.taskGroup.addTask(task); - this.isTaskGroup = true; - this.taskPoolOutPutStr += "TaskGroup addTask successfully.\n"; - } catch (e) { - this.taskPoolOutPutStr += "TaskGroup addTask failed: "+ (e as BusinessError).toString()+ "\n"; - } - } - - Clear(): void { - this.taskPoolInPutStr = ''; - this.taskPoolInPutArr = this.taskPoolInPutStr.trim().split(','); - this.taskPoolOutPutStr = ''; - } - - async TaskGroupExec(): Promise { - try { - let res: string[] = await taskpool.execute(this.taskGroup) as string[]; - this.taskPoolOutPutStr += "TaskGroup executed successfully: "+ res.toString()+ "\n"; - } catch(e) { - this.taskPoolOutPutStr += "TaskGroup executed failed: "+ (e as BusinessError).toString()+ "\n"; - } - this.isTaskGroup = false; - } - - async cancelTask(): Promise { - if (this.gStack.isEmpty()) { - this.taskPoolOutPutStr += "The current task queue has no cancellable tasks."+ "\n"; - } else { - let task: taskpool.Task = this.gStack.peek() as taskpool.Task; - try { - taskpool.cancel(task); - this.taskPoolOutPutStr += "Task canceled successfully."+ "\n"; - this.gStack.pop(); - } catch(e) { - this.taskPoolOutPutStr += "Task canceled failed: "+ (e as BusinessError).toString()+ "\n"; - } - } - } - - async sendableTask(): Promise { - // 定义主线程异步锁sendableTask_lock - let lock: utils.locks.AsyncLock = utils.locks.AsyncLock.request("sendableTask_lock"); - let count: number = 0; - lock.lockAsync(async () => { - // 主线程调用实例a.data1的方法setCount、getCount - a.data1.setCount(111); - count = await a.data1.getCount(); - console.info("this data1 count is: " + await a.data1.getCount()); - }) - let task: taskpool.Task = new taskpool.Task(createSendableData, a); - try { - await taskpool.execute(task); - this.taskPoolOutPutStr += "sendableTask execute successfully."+ "\n"; - // 访问子线程返回的实例a中的各个属性 - this.taskPoolOutPutStr += "Sendable data TestA v1 is: " + a.data1.v1 + "\n"; - this.taskPoolOutPutStr += "Sendable data TestA v2 is: " + a.data1.v2 + "\n"; - this.taskPoolOutPutStr += "Sendable data TestA v3 is: " + a.data1.v3 + "\n"; - this.taskPoolOutPutStr += "Sendable data TestA count is: " + count + "\n"; - this.taskPoolOutPutStr += "Sendable data TestB v1 length is: " + a.data2.v1.length + "\n"; - this.taskPoolOutPutStr += "Sendable data TestB v2 has key: " + a.data2.v2.has(100) + "\n"; - this.taskPoolOutPutStr += "Sendable data TestB v3 size is: " + a.data2.v3.size + "\n"; - } catch(e) { - this.taskPoolOutPutStr += "Task execute failed: "+ (e as BusinessError).toString()+ "\n"; - } - } -} - -@Concurrent -function strSort(inPutArr: string[]) : string[] { - let newArr: string[] = inPutArr.sort(); - return newArr; -} - -@Concurrent -function strSortDelay(inPutArr: string[]) : string[] { - let start: number= new Date().getTime(); - while (new Date().getTime() - start < 3000) { - continue; - } - let newArr: string[] = inPutArr.sort(); - return newArr; -} - -@Concurrent -async function createSendableData(data: SendableClass): Promise { - // 定义taskpool子线程异步锁sendableTask_lock - let lock: utils.locks.AsyncLock = utils.locks.AsyncLock.request("sendableTask_lock"); - - // 构造TestA、TestB实例,组装SendableClass实例 - let d1: TestA = new TestA(); - d1.v1 = 1010; - d1.v2 = "aaa"; - d1.v3 = true; - let d2: TestB = new TestB(); - d2.v2.set(100, "aaa"); - for(let i = 0;i < 1000;i++) { - d2.v1.push(i); - } - d2.v3.add("hello"); - - lock.lockAsync(async () => { - // 子线程调用实例方法setCount、getCount - await d1.setCount(10); - console.info("taskpool: this data1 count is: " + await d1.getCount()); - }) - - data.data1 = d1; - data.data2 = d2; +/* + * Copyright (c) 2024 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 taskpool from '@ohos.taskpool'; +import utils from '@arkts.utils'; +import stack from '@ohos.util.Stack'; +import { BusinessError } from '@ohos.base'; +import { SendableClass, a } from './SendableTest'; +import { TestA, TestB } from './test' + +@Component +export struct TaskPoolTab { + @State taskPoolOutPutStr: string = ''; + @State taskPoolInPutStr: string = ''; + taskPoolInPutArr: string[] = []; + isTaskGroup : boolean = false; + gStack: stack = new stack(); + taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup(); + + + build() { + Column() { + Text($r('app.string.Text_desc')) + .width("100%") + .height("48vp") + .position({ x: "7%", y: "0" }) + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#182431") + .lineHeight(22) + .fontWeight(500) + + Button() { + Row() { + Image($r('app.media.public_add')) + .width(20) + .height(20) + .margin({ left: 4 }) + Text($r('app.string.Add_task')) + .width("75%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("14fp") + .fontColor("#182431") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + } + .id("addButton") + .height("10vp") + .borderRadius("10vp") + .backgroundColor("#00000000") + .position({ x: "67%", y: "1.5%" }) + .width(135) + .height(35) + .onClick(() => { + this.taskAdd(); + }) + + Button() { + Row() { + Image($r('app.media.empties')) + .width(20) + .height(20) + .margin({ left: 4 }) + Text($r('app.string.Clear_desc')) + .width("35%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("14fp") + .fontColor("#182431") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + } + .id("taskPoolClearButton") + .height("10vp") + .borderRadius("10vp") + .backgroundColor("#00000000") + .position({ x: "71%", y: "31.5%" }) + .width(135) + .height(35) + .onClick(() => { + this.Clear(); + }) + + TextArea({placeholder:$r('app.string.Default_desc'), text:this.taskPoolInPutStr}) + .id("taskPoolInPutTextArea") + .width("93.3%") + .height("139vp") + .position({ x: "3.3%", y: "48vp" }) + .textAlign(TextAlign.Start) + .borderRadius("24vp") + .backgroundColor("#ffffff") + .fontFamily("HarmonyHeiTi") + .fontSize("16fp") + .fontColor("#182431") + .fontWeight(400) + .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) + .onChange((value: string) => { + this.taskPoolInPutStr = value; + this.taskPoolInPutArr = this.taskPoolInPutStr.trim().split(','); + this.taskPoolOutPutStr = ''; + }) + + Text($r('app.string.Result_desc')) + .width("50%") + .height("48") + .position({ x: "7%", y: "187vp" }) + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#182431") + .lineHeight(22) + .fontWeight(500) + + Scroll() { + Text(this.taskPoolOutPutStr) + .id("taskPoolOutPutText") + .fontFamily("HarmonyHeiTi") + .fontSize("16fp") + .fontColor("#182431") + .fontWeight(400) + .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) + } + .id("taskPoolOutPutScroll") + .width("93.3%") + .height("139vp") + .position({ x: "3.3%", y: "235vp" }) + .borderRadius("24vp") + .backgroundColor("#ffffff") + .align(Alignment.TopStart) + + GridRow({columns: 4, + gutter: { x: 12, y: 12 }, + breakpoints: { value: ["360vp", "480vp"]}, + direction: GridRowDirection.Row}) { + GridCol ({ span: 2, offset: 0 }) { + Button() { + Text($r('app.string.Execute_After_3s_desc')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#007DFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("exeDelayButton") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("rgba(24,36,49,0.05)") + .onClick(()=>{ + this.executeDelay(); + }) + } + + GridCol ({ span: 2, offset: 0 }) { + Button() { + Text($r('app.string.Execute_Immediately_desc')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#FFFFFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("exeImmButton") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("#007DFF") + .onClick(()=>{ + if(this.isTaskGroup == true) { + this.TaskGroupExec(); + } else { + this.executeImmediately(); + } + }) + } + + GridCol ({ span: 2, offset: 0 }) { + Button() { + Text($r('app.string.Function_Task_desc')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#007DFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("exeFunctionButton") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("rgba(24,36,49,0.05)") + .onClick(()=>{ + this.executeFunc(); + }) + } + + GridCol ({ span: 2, offset: 0 }) { + Button() { + Text($r('app.string.Cancel_Task_desc')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#FFFFFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("exeCancelButton") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("#007DFF") + .onClick(()=>{ + this.cancelTask(); + }) + } + + GridCol ({ span: 4, offset: 0 }) { + Button() { + Text($r('app.string.transferSendableClass')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#007DFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("sendableButton") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("rgba(24,36,49,0.05)") + .onClick(()=>{ + this.sendableTask(); + }) + } + } + .width("100%") + .height("168vp") + .position({ x: "0", y: "73%" }) + .padding({ left: "25vp", right: "25vp" }) + } + .width("100%") + .height("100%") + .justifyContent(FlexAlign.Center) + } + + async executeImmediately(): Promise { + if (!this.taskPoolInPutStr.length) { + this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; + return; + } + let task = new taskpool.Task(strSort,this.taskPoolInPutArr); + this.gStack.push(task); + try { + let result: taskpool.Task = await taskpool.execute(task) as taskpool.Task; + this.taskPoolOutPutStr += "Task executed successfully: "+ result.toString()+ "\n"; + } catch(e) { + this.taskPoolOutPutStr += "Task executed failed: "+ (e as BusinessError).toString()+ "\n"; + } + this.gStack.pop(); + } + + async executeDelay(): Promise { + if (!this.taskPoolInPutStr.length) { + this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; + return; + } + let task = new taskpool.Task(strSortDelay,this.taskPoolInPutArr); + this.gStack.push(task); + try { + let result: string[] = await taskpool.execute(task) as string[]; + this.taskPoolOutPutStr += "Task executed successfully: "+ result.toString()+ "\n"; + } catch(e) { + this.taskPoolOutPutStr += "Task executed failed: "+ (e as BusinessError).toString() + "\n"; + } + this.gStack.pop(); + } + + async executeFunc(): Promise { + if (!this.taskPoolInPutStr.length) { + this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; + return; + } + try { + let result: string[] = await taskpool.execute(strSort,this.taskPoolInPutArr) as string[]; + this.taskPoolOutPutStr += "Task executed successfully: "+ result.toString()+ "\n"; + } catch(e) { + this.taskPoolOutPutStr += "Task executed failed: "+ (e as BusinessError).toString()+ "\n"; + } + } + + async taskAdd(): Promise { + if (!this.taskPoolInPutStr.length) { + this.taskPoolOutPutStr = "No input for the string to be sorted.\n"; + return; + } + try { + let task: taskpool.Task = new taskpool.Task(strSort, this.taskPoolInPutArr); + this.taskGroup.addTask(task); + this.isTaskGroup = true; + this.taskPoolOutPutStr += "TaskGroup addTask successfully.\n"; + } catch (e) { + this.taskPoolOutPutStr += "TaskGroup addTask failed: "+ (e as BusinessError).toString()+ "\n"; + } + } + + Clear(): void { + this.taskPoolInPutStr = ''; + this.taskPoolInPutArr = this.taskPoolInPutStr.trim().split(','); + this.taskPoolOutPutStr = ''; + } + + async TaskGroupExec(): Promise { + try { + let res: string[] = await taskpool.execute(this.taskGroup) as string[]; + this.taskPoolOutPutStr += "TaskGroup executed successfully: "+ res.toString()+ "\n"; + } catch(e) { + this.taskPoolOutPutStr += "TaskGroup executed failed: "+ (e as BusinessError).toString()+ "\n"; + } + this.isTaskGroup = false; + } + + async cancelTask(): Promise { + if (this.gStack.isEmpty()) { + this.taskPoolOutPutStr += "The current task queue has no cancellable tasks."+ "\n"; + } else { + let task: taskpool.Task = this.gStack.peek() as taskpool.Task; + try { + taskpool.cancel(task); + this.taskPoolOutPutStr += "Task canceled successfully."+ "\n"; + this.gStack.pop(); + } catch(e) { + this.taskPoolOutPutStr += "Task canceled failed: "+ (e as BusinessError).toString()+ "\n"; + } + } + } + + async sendableTask(): Promise { + // 定义主线程异步锁sendableTask_lock + let lock: utils.locks.AsyncLock = utils.locks.AsyncLock.request("sendableTask_lock"); + let count: number = 0; + lock.lockAsync(async () => { + // 主线程调用实例a.data1的方法setCount、getCount + a.data1.setCount(111); + count = await a.data1.getCount(); + console.info("this data1 count is: " + await a.data1.getCount()); + }) + let task: taskpool.Task = new taskpool.Task(createSendableData, a); + try { + await taskpool.execute(task); + this.taskPoolOutPutStr += "sendableTask execute successfully."+ "\n"; + // 访问子线程返回的实例a中的各个属性 + this.taskPoolOutPutStr += "Sendable data TestA v1 is: " + a.data1.v1 + "\n"; + this.taskPoolOutPutStr += "Sendable data TestA v2 is: " + a.data1.v2 + "\n"; + this.taskPoolOutPutStr += "Sendable data TestA v3 is: " + a.data1.v3 + "\n"; + this.taskPoolOutPutStr += "Sendable data TestA count is: " + count + "\n"; + this.taskPoolOutPutStr += "Sendable data TestB v1 length is: " + a.data2.v1.length + "\n"; + this.taskPoolOutPutStr += "Sendable data TestB v2 has key: " + a.data2.v2.has(100) + "\n"; + this.taskPoolOutPutStr += "Sendable data TestB v3 size is: " + a.data2.v3.size + "\n"; + } catch(e) { + this.taskPoolOutPutStr += "Task execute failed: "+ (e as BusinessError).toString()+ "\n"; + } + } +} + +@Concurrent +function strSort(inPutArr: string[]) : string[] { + let newArr: string[] = inPutArr.sort(); + return newArr; +} + +@Concurrent +function strSortDelay(inPutArr: string[]) : string[] { + let start: number= new Date().getTime(); + while (new Date().getTime() - start < 3000) { + continue; + } + let newArr: string[] = inPutArr.sort(); + return newArr; +} + +@Concurrent +async function createSendableData(data: SendableClass): Promise { + // 定义taskpool子线程异步锁sendableTask_lock + let lock: utils.locks.AsyncLock = utils.locks.AsyncLock.request("sendableTask_lock"); + + // 构造TestA、TestB实例,组装SendableClass实例 + let d1: TestA = new TestA(); + d1.v1 = 1010; + d1.v2 = "aaa"; + d1.v3 = true; + let d2: TestB = new TestB(); + d2.v2.set(100, "aaa"); + for(let i = 0;i < 1000;i++) { + d2.v1.push(i); + } + d2.v3.add("hello"); + + lock.lockAsync(async () => { + // 子线程调用实例方法setCount、getCount + await d1.setCount(10); + console.info("taskpool: this data1 count is: " + await d1.getCount()); + }) + + data.data1 = d1; + data.data2 = d2; } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/WorkerTab.ets b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/WorkerTab.ets index 410038a827d6f7cc4c40ab980888612102531828..1f8c1885a6e492ab63779bce308f6bb76b21f9b6 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/WorkerTab.ets +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/ets/component/WorkerTab.ets @@ -1,168 +1,168 @@ -/* - * Copyright (c) 2023 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 worker from '@ohos.worker'; - -@Component -export struct WorkerTab { - @State jsWorkerOutPutStr: string = ''; - @State jsWorkerInPutStr: string = ''; - jsWorkerInPutArr: string[] = []; - isDone: boolean = false; - myWorker: worker.ThreadWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ts"); - - build() { - Column() { - Text($r('app.string.Text_desc')) - .width("100%") - .height("48vp") - .position({ x: "7%", y: "0vp" }) - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#182431") - .lineHeight(22) - .fontWeight(500) - - TextArea({text:this.jsWorkerInPutStr}) - .id("jsWorkerInPutTextArea") - .width("93.3%") - .height("139vp") - .position({ x: "3.3%", y: "48vp" }) - .textAlign(TextAlign.Start) - .fontFamily("HarmonyHeiTi") - .fontSize("16fp") - .fontColor("#182431") - .fontWeight(400) - .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) - .borderRadius("24vp") - .backgroundColor("#ffffff") - .onChange((value: string) => { - this.jsWorkerInPutStr = value; - this.jsWorkerInPutArr = value.trim().split(','); - this.jsWorkerOutPutStr = ''; - }) - - Text($r('app.string.Result_desc')) - .width("100%") - .height("48") - .position({ x: "7%", y: "187vp" }) - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#182431") - .lineHeight(22) - .fontWeight(500) - - Scroll() { - Text(this.jsWorkerOutPutStr) - .id("jsWorkerOutPutText") - .fontFamily("HarmonyHeiTi") - .fontSize("16fp") - .fontColor("#182431") - .fontWeight(400) - .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) - } - .id("jsWorkerOutPutScroll") - .width("93.3%") - .height("139vp") - .position({ x: "3.3%", y: "235vp" }) - .borderRadius("24vp") - .backgroundColor("#ffffff") - .align(Alignment.TopStart) - - GridRow({columns: 4, - gutter: { x: 12, y: 12 }, - breakpoints: { value: ["360vp", "480vp"]}, - direction: GridRowDirection.Row}) { - GridCol ({ span: 2, offset: 0 }) { - Button() { - Text($r('app.string.Clear_desc')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#007DFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("workerClearButton") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("rgba(24,36,49,0.05)") - .onClick(()=>{ - this.jsWorkerInPutStr = ''; - this.jsWorkerOutPutStr = ''; - }) - } - - GridCol ({ span: 2, offset: 0 }) { - Button() { - Text($r('app.string.SortString_desc')) - .width("100%") - .height("22") - .fontFamily("HarmonyHeiTi-Medium") - .fontSize("16fp") - .fontColor("#FFFFFF") - .textAlign(TextAlign.Center) - .lineHeight(22) - .fontWeight(500) - } - .id("workerStrSort") - .height("40vp") - .borderRadius("20vp") - .backgroundColor("#007DFF") - .onClick(()=>{ - this.executeWorkerFunc(this.jsWorkerInPutArr); - }) - } - } - .width("100%") - .height("40vp") - .position({ x: "0", y: "555vp" }) - .padding({ left: "24vp", right: "24vp" }) - } - .width("100%") - .height("100%") - .justifyContent(FlexAlign.Center) - } - - async executeWorkerFunc(inPutArr: string[]): Promise { - if (!this.jsWorkerInPutStr.length) { - this.jsWorkerOutPutStr = "No input for the string to be sorted.\n"; - return; - } - this.myWorker.postMessage(inPutArr); - let strFlag = false; - let outPutStr = ''; - this.myWorker.onmessage = (e) => { - outPutStr = e.data.toString(); - strFlag = true; - } - while(!strFlag) { - await promiseCase(); - } - this.jsWorkerOutPutStr = outPutStr; - } -} - -function promiseCase() : Promise { - let p: Promise = new Promise((resolve: Function, reject: Function) => { - setTimeout(() => { - resolve(1) - }, 100) - }).then(undefined, () => { - }) - return p; +/* + * Copyright (c) 2023 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 worker from '@ohos.worker'; + +@Component +export struct WorkerTab { + @State jsWorkerOutPutStr: string = ''; + @State jsWorkerInPutStr: string = ''; + jsWorkerInPutArr: string[] = []; + isDone: boolean = false; + myWorker: worker.ThreadWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ts"); + + build() { + Column() { + Text($r('app.string.Text_desc')) + .width("100%") + .height("48vp") + .position({ x: "7%", y: "0vp" }) + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#182431") + .lineHeight(22) + .fontWeight(500) + + TextArea({text:this.jsWorkerInPutStr}) + .id("jsWorkerInPutTextArea") + .width("93.3%") + .height("139vp") + .position({ x: "3.3%", y: "48vp" }) + .textAlign(TextAlign.Start) + .fontFamily("HarmonyHeiTi") + .fontSize("16fp") + .fontColor("#182431") + .fontWeight(400) + .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) + .borderRadius("24vp") + .backgroundColor("#ffffff") + .onChange((value: string) => { + this.jsWorkerInPutStr = value; + this.jsWorkerInPutArr = value.trim().split(','); + this.jsWorkerOutPutStr = ''; + }) + + Text($r('app.string.Result_desc')) + .width("100%") + .height("48") + .position({ x: "7%", y: "187vp" }) + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#182431") + .lineHeight(22) + .fontWeight(500) + + Scroll() { + Text(this.jsWorkerOutPutStr) + .id("jsWorkerOutPutText") + .fontFamily("HarmonyHeiTi") + .fontSize("16fp") + .fontColor("#182431") + .fontWeight(400) + .padding({ top: "8vp" , left: "16vp", right: "16vp", bottom: "21vp" }) + } + .id("jsWorkerOutPutScroll") + .width("93.3%") + .height("139vp") + .position({ x: "3.3%", y: "235vp" }) + .borderRadius("24vp") + .backgroundColor("#ffffff") + .align(Alignment.TopStart) + + GridRow({columns: 4, + gutter: { x: 12, y: 12 }, + breakpoints: { value: ["360vp", "480vp"]}, + direction: GridRowDirection.Row}) { + GridCol ({ span: 2, offset: 0 }) { + Button() { + Text($r('app.string.Clear_desc')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#007DFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("workerClearButton") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("rgba(24,36,49,0.05)") + .onClick(()=>{ + this.jsWorkerInPutStr = ''; + this.jsWorkerOutPutStr = ''; + }) + } + + GridCol ({ span: 2, offset: 0 }) { + Button() { + Text($r('app.string.SortString_desc')) + .width("100%") + .height("22") + .fontFamily("HarmonyHeiTi-Medium") + .fontSize("16fp") + .fontColor("#FFFFFF") + .textAlign(TextAlign.Center) + .lineHeight(22) + .fontWeight(500) + } + .id("workerStrSort") + .height("40vp") + .borderRadius("20vp") + .backgroundColor("#007DFF") + .onClick(()=>{ + this.executeWorkerFunc(this.jsWorkerInPutArr); + }) + } + } + .width("100%") + .height("40vp") + .position({ x: "0", y: "555vp" }) + .padding({ left: "24vp", right: "24vp" }) + } + .width("100%") + .height("100%") + .justifyContent(FlexAlign.Center) + } + + async executeWorkerFunc(inPutArr: string[]): Promise { + if (!this.jsWorkerInPutStr.length) { + this.jsWorkerOutPutStr = "No input for the string to be sorted.\n"; + return; + } + this.myWorker.postMessage(inPutArr); + let strFlag = false; + let outPutStr = ''; + this.myWorker.onmessage = (e) => { + outPutStr = e.data.toString(); + strFlag = true; + } + while(!strFlag) { + await promiseCase(); + } + this.jsWorkerOutPutStr = outPutStr; + } +} + +function promiseCase() : Promise { + let p: Promise = new Promise((resolve: Function, reject: Function) => { + setTimeout(() => { + resolve(1) + }, 100) + }).then(undefined, () => { + }) + return p; } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/module.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/module.json5 index c4c3c62e25cdb37fe6ef344e49f845297440a6f3..e42c2962094ce21b5300a2e19e780aa0b1b84002 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/module.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/resources/base/element/color.json b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/resources/base/element/color.json +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/ohosTest/module.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/ohosTest/module.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/hvigor/hvigor-config.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/hvigor/hvigor-config.json5 index 97147e6cf70998c11d749a4146796115c5ae9c7c..909bc9a52c9871b7a12b665460a7cb3cea6d50c5 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/hvigor/hvigor-config.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "hvigorVersion": "4.0.4", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.4" - } +/* + * Copyright (c) 2023 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. + */ + +{ + "hvigorVersion": "4.0.4", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.4" + } } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ConcurrentModule/oh-package.json5 b/code/LaunguageBaseClassLibrary/ConcurrentModule/oh-package.json5 index 84f6ca3ba8fd8a59bfa8db14c123316c1d886621..ac21a550a2b71be3fcb99c6577a806b43240c96e 100644 --- a/code/LaunguageBaseClassLibrary/ConcurrentModule/oh-package.json5 +++ b/code/LaunguageBaseClassLibrary/ConcurrentModule/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "concurrentmodule", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "concurrentmodule", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/common/DeleteDialog.ets b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/common/DeleteDialog.ets index 2b199c183eafc27140eb552f3c5d82ad40764bc9..0e16604204feaf206574b4900ed672dfa45be60f 100644 --- a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/common/DeleteDialog.ets +++ b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/common/DeleteDialog.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2024 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'; - -const DOMAIN = 0xF811; -const BUNDLE = 'ZipLib_'; -const TAG: string = '[DeleteDialog]'; - -@CustomDialog -export struct DeleteDialog { - private fileNames: string[] = []; - private isInserted: boolean = false; - private deleteFiles: (isInserted: boolean, fileNames: Array) => void = - (isInserted: boolean, fileNames: Array) => { - }; - private controller: CustomDialogController; - @State buttonColor: Resource = $r('app.color.button_light_color'); - - build() { - Column() { - Text($r('app.string.delete_file')) - .fontSize(16) - .width('100%') - .height('40%') - .margin({ top: '3%' }) - .textAlign(TextAlign.Center) - - Row() { - Text($r('app.string.button_cancel')) - .fontColor($r('app.color.button_color')) - .fontSize(16) - .height('18.5%') - .width('44%') - .margin({ left: '23%', top: '3%' }) - .onClick(() => { - this.controller.close(); - }) - - Text($r('app.string.button_confirm')) - .fontColor($r('app.color.button_color')) - .fontSize(16) - .height('18.5%') - .width('44%') - .margin({ right: '23%', top: '3%' }) - .onClick(() => { - this.isInserted = true; - hilog.info(DOMAIN, TAG, BUNDLE + `fileName = ${this.fileNames}`); - this.deleteFiles(this.isInserted, this.fileNames); - hilog.info(DOMAIN, TAG, BUNDLE + `isInserted = ${this.isInserted}`); - this.controller.close(); - }) - } - .width('100%') - } - .width('100%') - .height('18%') - .backgroundColor($r('app.color.start_window_background')) - } +/* + * Copyright (c) 2024 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'; + +const DOMAIN = 0xF811; +const BUNDLE = 'ZipLib_'; +const TAG: string = '[DeleteDialog]'; + +@CustomDialog +export struct DeleteDialog { + private fileNames: string[] = []; + private isInserted: boolean = false; + private deleteFiles: (isInserted: boolean, fileNames: Array) => void = + (isInserted: boolean, fileNames: Array) => { + }; + private controller: CustomDialogController; + @State buttonColor: Resource = $r('app.color.button_light_color'); + + build() { + Column() { + Text($r('app.string.delete_file')) + .fontSize(16) + .width('100%') + .height('40%') + .margin({ top: '3%' }) + .textAlign(TextAlign.Center) + + Row() { + Text($r('app.string.button_cancel')) + .fontColor($r('app.color.button_color')) + .fontSize(16) + .height('18.5%') + .width('44%') + .margin({ left: '23%', top: '3%' }) + .onClick(() => { + this.controller.close(); + }) + + Text($r('app.string.button_confirm')) + .fontColor($r('app.color.button_color')) + .fontSize(16) + .height('18.5%') + .width('44%') + .margin({ right: '23%', top: '3%' }) + .onClick(() => { + this.isInserted = true; + hilog.info(DOMAIN, TAG, BUNDLE + `fileName = ${this.fileNames}`); + this.deleteFiles(this.isInserted, this.fileNames); + hilog.info(DOMAIN, TAG, BUNDLE + `isInserted = ${this.isInserted}`); + this.controller.close(); + }) + } + .width('100%') + } + .width('100%') + .height('18%') + .backgroundColor($r('app.color.start_window_background')) + } } \ No newline at end of file diff --git a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets index d17ad9bc38840bae61f8dba797e0ee75873d001b..46a56f4771a7103c8f2ef014964e1d0f7baff156 100644 --- a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets +++ b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets @@ -1,246 +1,246 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { common } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { preferences } from '@kit.ArkData'; -import { promptAction, router } from '@kit.ArkUI'; -import { zlib } from '@kit.BasicServicesKit'; -import fileio from '@ohos.fileio'; -import { AddDialog } from '../common/AddDialog'; -import { ZipLibSource } from '../model/DataSource'; - -const DOMAIN = 0xF811; -const BUNDLE = 'ZipLib_'; -const TAG: string = '[CompressFilesPage]'; -let fileList: preferences.Preferences; - -@Entry -@Component -struct CompressFilesPage { - @State isInserted: boolean = false; - @State files: ZipLibSource = new ZipLibSource([]); - @State fileName: string = ''; - @State slectFileName: string[] = []; - @State zipFileNames: string[] = []; - @State fileContent: string = ''; - @State isSelect: boolean = false; - private path: string = ''; - private title: Resource = $r('app.string.CompressFiles'); - private dialogController: CustomDialogController = new CustomDialogController({ - builder: AddDialog({ - fileName: this.fileName, - fileContent: this.fileContent, - isInserted: this.isInserted, - createFile: async (isInserted: boolean, fileName: string, fileContent: string) => { - hilog.info(DOMAIN, TAG, BUNDLE + `enter the createFile`); - this.fileName = `${fileName}.txt`; - let isDuplication = this.files.fileData.includes(this.fileName); - hilog.info(DOMAIN, TAG, BUNDLE + `isInserted = ${isInserted} isDuplication = ${isDuplication}`); - if (!isInserted || isDuplication) { - return; - } - let fd = fileio.openSync(`${this.path}/${this.fileName}`, 0o100 | 0o2, 0o666); - let number = fileio.writeSync(fd, fileContent); - hilog.info(DOMAIN, TAG, BUNDLE + `fd = ${fd} number = ${number}`); - this.files.pushData(this.fileName); - hilog.info(DOMAIN, TAG, BUNDLE + `this.files = ${JSON.stringify(this.files.fileData)}`); - await fileList.put('fileNames', JSON.stringify(this.files.fileData)); - await fileList.flush(); - } - }), - autoCancel: true, - }) - - async aboutToAppear() { - fileList = await preferences.getPreferences(getContext(this), 'fileList'); - let ctx = getContext(this) as common.Context; - this.path = ctx.filesDir; - let value = await fileList.get('fileNames', ''); - this.files.fileData = JSON.parse(`${value}`); - this.files.notifyDataReload(); - this.zipFileNames.length = 0; - this.zipFileNames = this.files.fileData.filter(item => item.endsWith('.zip')); - } - - async zipcompressFiles(path: string, zipfileNames: Array): Promise { - let files: string[] = []; - for (let index = 0; index < zipfileNames.length; index++) { - files[index] = `${path}/${zipfileNames[index]}`; - } - let zipFiles = Array.from(files); - hilog.debug(DOMAIN, TAG, BUNDLE + `zipFile = ${zipFiles}`); - let newName = `test_` + this.zipFileNames.length + `.zip`; - let zipOutFile = `${this.path}/${newName}`; - hilog.debug(DOMAIN, TAG, BUNDLE + `zipOutFile = ${zipOutFile}`); - - if (this.files.fileData.includes(newName)) { - promptAction.showToast({ - message: $r('app.string.warning_failed'), - bottom: '11%' - }); - return; - } - try { - await zlib.compressFiles(zipFiles, zipOutFile, {}).then(data => { - zlib.getOriginalSize(zipOutFile).then((num) => { - promptAction.showToast({ - message: $r('app.string.CompressFiles_success_size', num), - bottom: '11%' - }); - }) - this.files.pushData(`${newName}`); - this.zipFileNames.push(newName); - }) - } catch { - promptAction.showToast({ - message: $r('app.string.CompressFiles_failure'), - bottom: '11%' - }); - } - await fileList.put('fileNames', JSON.stringify(this.files.fileData)); - await fileList.flush(); - } - - build() { - Column() { - Column() { - Row() { - Row() { - Image($r('app.media.icon_back')) - .size({ height: '71%' }) - .objectFit(ImageFit.Contain) - .onClick(() => { - router.pushUrl({ - url: 'zlib/ZLibInterfaceListPage' - }); - }) - Text(this.title) - .fontSize(20) - .margin({ left: 8 }) - .fontWeight(FontWeight.Bold) - } - - Row() { - Image($r('app.media.add')) - .size({ height: '71%' }) - .id('addFile') - .margin({ left: '3%' }) - .objectFit(ImageFit.Contain) - .onClick(() => { - this.dialogController.open(); - }) - } - } - .justifyContent(FlexAlign.SpaceBetween) - .width('91%') - .height('9.75%') - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - LazyForEach(this.files, (item: string, index: number) => { - ListItem() { - Row() { - Row() { - Image(item.includes('.zip') ? $r('app.media.zip') : $r('app.media.file')) - .size({ height: '66.7%' }) - .objectFit(ImageFit.Contain) - Column() { - Text(item) - .width('50%') - .fontSize(16) - .margin({ left: 16 }) - } - } - - Checkbox() - .visibility(item.includes('.zip') ? Visibility.Hidden : Visibility.Visible) - .width('6%') - .select(this.slectFileName.indexOf(item) != -1 ? true : false) - .id('file_' + index) - .selectedColor($r('app.color.checkbox_color')) - .shape(CheckBoxShape.CIRCLE) - .onChange((value: boolean) => { - if (value) { - this.isSelect = true; - this.slectFileName.push(item); - } else { - this.isSelect = false; - let index = this.slectFileName.indexOf(item); - if (index !== -1) { - this.slectFileName.splice(index, 1); - } - } - }) - } - .justifyContent(FlexAlign.SpaceBetween) - .padding({ right: 12, left: 12 }) - .width('100%') - .height('14.2%') - .borderRadius(16) - .backgroundColor($r('app.color.start_window_background')) - } - .margin({ bottom: 12 }) - }, (item: string) => item) - } - .margin({ top: 8 }) - .height('85.875%') - .width('91%') - .backgroundColor($r('app.color.index_bg')) - } - .height('80%') - .width('100%') - - - Column() { - Text($r('app.string.tip_CompressFiles')) - .textAlign(TextAlign.Start) - .fontSize(12) - .fontColor($r('app.color.tip_Gzip_backeGround')) - .width('86.4%') - .height('22.3%') - .margin({ bottom: 24 }) - - Row() { - Button($r('app.string.zip')) - .id('compress') - .height('100%') - .width('100%') - .fontSize(16) - .fontFamily('HarmonyHeiTi') - .type(ButtonType.Capsule) - .backgroundColor($r('app.color.button_color')) - .fontColor($r('app.color.text_white_color')) - .borderRadius(20) - .onClick(() => { - if (this.isSelect) { - this.zipcompressFiles(this.path, this.slectFileName); - } - }) - } - .margin({ bottom: 16 }) - .height('28%') - .width('91%') - } - .justifyContent(FlexAlign.End) - .alignItems(HorizontalAlign.Center) - .height('20%') - .width('100%') - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.index_bg')) - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { preferences } from '@kit.ArkData'; +import { promptAction, router } from '@kit.ArkUI'; +import { zlib } from '@kit.BasicServicesKit'; +import fileio from '@ohos.fileio'; +import { AddDialog } from '../common/AddDialog'; +import { ZipLibSource } from '../model/DataSource'; + +const DOMAIN = 0xF811; +const BUNDLE = 'ZipLib_'; +const TAG: string = '[CompressFilesPage]'; +let fileList: preferences.Preferences; + +@Entry +@Component +struct CompressFilesPage { + @State isInserted: boolean = false; + @State files: ZipLibSource = new ZipLibSource([]); + @State fileName: string = ''; + @State slectFileName: string[] = []; + @State zipFileNames: string[] = []; + @State fileContent: string = ''; + @State isSelect: boolean = false; + private path: string = ''; + private title: Resource = $r('app.string.CompressFiles'); + private dialogController: CustomDialogController = new CustomDialogController({ + builder: AddDialog({ + fileName: this.fileName, + fileContent: this.fileContent, + isInserted: this.isInserted, + createFile: async (isInserted: boolean, fileName: string, fileContent: string) => { + hilog.info(DOMAIN, TAG, BUNDLE + `enter the createFile`); + this.fileName = `${fileName}.txt`; + let isDuplication = this.files.fileData.includes(this.fileName); + hilog.info(DOMAIN, TAG, BUNDLE + `isInserted = ${isInserted} isDuplication = ${isDuplication}`); + if (!isInserted || isDuplication) { + return; + } + let fd = fileio.openSync(`${this.path}/${this.fileName}`, 0o100 | 0o2, 0o666); + let number = fileio.writeSync(fd, fileContent); + hilog.info(DOMAIN, TAG, BUNDLE + `fd = ${fd} number = ${number}`); + this.files.pushData(this.fileName); + hilog.info(DOMAIN, TAG, BUNDLE + `this.files = ${JSON.stringify(this.files.fileData)}`); + await fileList.put('fileNames', JSON.stringify(this.files.fileData)); + await fileList.flush(); + } + }), + autoCancel: true, + }) + + async aboutToAppear() { + fileList = await preferences.getPreferences(getContext(this), 'fileList'); + let ctx = getContext(this) as common.Context; + this.path = ctx.filesDir; + let value = await fileList.get('fileNames', ''); + this.files.fileData = JSON.parse(`${value}`); + this.files.notifyDataReload(); + this.zipFileNames.length = 0; + this.zipFileNames = this.files.fileData.filter(item => item.endsWith('.zip')); + } + + async zipcompressFiles(path: string, zipfileNames: Array): Promise { + let files: string[] = []; + for (let index = 0; index < zipfileNames.length; index++) { + files[index] = `${path}/${zipfileNames[index]}`; + } + let zipFiles = Array.from(files); + hilog.debug(DOMAIN, TAG, BUNDLE + `zipFile = ${zipFiles}`); + let newName = `test_` + this.zipFileNames.length + `.zip`; + let zipOutFile = `${this.path}/${newName}`; + hilog.debug(DOMAIN, TAG, BUNDLE + `zipOutFile = ${zipOutFile}`); + + if (this.files.fileData.includes(newName)) { + promptAction.showToast({ + message: $r('app.string.warning_failed'), + bottom: '11%' + }); + return; + } + try { + await zlib.compressFiles(zipFiles, zipOutFile, {}).then(data => { + zlib.getOriginalSize(zipOutFile).then((num) => { + promptAction.showToast({ + message: $r('app.string.CompressFiles_success_size', num), + bottom: '11%' + }); + }) + this.files.pushData(`${newName}`); + this.zipFileNames.push(newName); + }) + } catch { + promptAction.showToast({ + message: $r('app.string.CompressFiles_failure'), + bottom: '11%' + }); + } + await fileList.put('fileNames', JSON.stringify(this.files.fileData)); + await fileList.flush(); + } + + build() { + Column() { + Column() { + Row() { + Row() { + Image($r('app.media.icon_back')) + .size({ height: '71%' }) + .objectFit(ImageFit.Contain) + .onClick(() => { + router.pushUrl({ + url: 'zlib/ZLibInterfaceListPage' + }); + }) + Text(this.title) + .fontSize(20) + .margin({ left: 8 }) + .fontWeight(FontWeight.Bold) + } + + Row() { + Image($r('app.media.add')) + .size({ height: '71%' }) + .id('addFile') + .margin({ left: '3%' }) + .objectFit(ImageFit.Contain) + .onClick(() => { + this.dialogController.open(); + }) + } + } + .justifyContent(FlexAlign.SpaceBetween) + .width('91%') + .height('9.75%') + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + LazyForEach(this.files, (item: string, index: number) => { + ListItem() { + Row() { + Row() { + Image(item.includes('.zip') ? $r('app.media.zip') : $r('app.media.file')) + .size({ height: '66.7%' }) + .objectFit(ImageFit.Contain) + Column() { + Text(item) + .width('50%') + .fontSize(16) + .margin({ left: 16 }) + } + } + + Checkbox() + .visibility(item.includes('.zip') ? Visibility.Hidden : Visibility.Visible) + .width('6%') + .select(this.slectFileName.indexOf(item) != -1 ? true : false) + .id('file_' + index) + .selectedColor($r('app.color.checkbox_color')) + .shape(CheckBoxShape.CIRCLE) + .onChange((value: boolean) => { + if (value) { + this.isSelect = true; + this.slectFileName.push(item); + } else { + this.isSelect = false; + let index = this.slectFileName.indexOf(item); + if (index !== -1) { + this.slectFileName.splice(index, 1); + } + } + }) + } + .justifyContent(FlexAlign.SpaceBetween) + .padding({ right: 12, left: 12 }) + .width('100%') + .height('14.2%') + .borderRadius(16) + .backgroundColor($r('app.color.start_window_background')) + } + .margin({ bottom: 12 }) + }, (item: string) => item) + } + .margin({ top: 8 }) + .height('85.875%') + .width('91%') + .backgroundColor($r('app.color.index_bg')) + } + .height('80%') + .width('100%') + + + Column() { + Text($r('app.string.tip_CompressFiles')) + .textAlign(TextAlign.Start) + .fontSize(12) + .fontColor($r('app.color.tip_Gzip_backeGround')) + .width('86.4%') + .height('22.3%') + .margin({ bottom: 24 }) + + Row() { + Button($r('app.string.zip')) + .id('compress') + .height('100%') + .width('100%') + .fontSize(16) + .fontFamily('HarmonyHeiTi') + .type(ButtonType.Capsule) + .backgroundColor($r('app.color.button_color')) + .fontColor($r('app.color.text_white_color')) + .borderRadius(20) + .onClick(() => { + if (this.isSelect) { + this.zipcompressFiles(this.path, this.slectFileName); + } + }) + } + .margin({ bottom: 16 }) + .height('28%') + .width('91%') + } + .justifyContent(FlexAlign.End) + .alignItems(HorizontalAlign.Center) + .height('20%') + .width('100%') + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.index_bg')) + } +} diff --git a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets index fc7a9ff2480ca292a785b03d3540e027f39cb369..1339c29568c6741f8c3b30daf0faf7a7c3cd2612 100644 --- a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets +++ b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets @@ -1,292 +1,292 @@ -/* - * Copyright (c) 2024 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 { fileIo } from '@kit.CoreFileKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction, router } from '@kit.ArkUI'; -import { zlib } from '@kit.BasicServicesKit'; - -const DOMAIN = 0xF811; -const BUNDLE = 'ZipLib_'; -const TAG: string = '[ZLibInterfaceListPage]'; -const SLEEP_TIME = 3000; -const BUFFER_SIZE = 13; -const OFFSET = 0; -const STRING_DATA = 'hello, hello!'; - -function sleep(time: number) { - return new Promise((resolve) => setTimeout(resolve, time)); -}; - -@Entry -@Component -struct ZLibInterfaceListPage { - async zlibDecompression(): Promise { - hilog.info(DOMAIN, TAG, BUNDLE + `zlibDecompression begin`); - let context = AppStorage.get('context') as Context; - let pathDir = context.cacheDir; - let zlibFile = fileIo.openSync(pathDir + '/zlibFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - fileIo.writeSync(zlibFile.fd, STRING_DATA); - let arrayBufferIn = new ArrayBuffer(BUFFER_SIZE); - fileIo.readSync(zlibFile.fd, arrayBufferIn, { offset: OFFSET }); - fileIo.closeSync(zlibFile); - - let arrayBufferOut = new ArrayBuffer(BUFFER_SIZE); - // 创建zip对象 - let zip = zlib.createZipSync(); - // 压缩初始化 - await zip.deflateInit({}, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED); - // 校验数据 - let checksum = zlib.createChecksumSync(); - checksum.crc32(0, arrayBufferIn); - try { - // 压缩数据 - await zip.deflate({ - nextIn: arrayBufferIn, - availableIn: BUFFER_SIZE, - nextOut: arrayBufferOut, - availableOut: BUFFER_SIZE - }, zlib.CompressFlushMode.FINISH).then((data) => { - // 将压缩后的buffer写入zlibDeflateFile.txt文件中 - let zlibDeflateFile = - fileIo.openSync(pathDir + '/zlibDeflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - fileIo.writeSync(zlibDeflateFile.fd, arrayBufferOut); - fileIo.closeSync(zlibDeflateFile); - promptAction.showToast({ - message: $r('app.string.zlib_compress_success', STRING_DATA), - bottom: '11%' - }); - }) - } catch (errData) { - promptAction.showToast({ - message: $r('app.string.zlib_compress_failure'), - bottom: '11%' - }); - } - // 释放动态分配的数据结构 - await zip.deflateEnd({ nextOut: arrayBufferOut }); - await sleep(SLEEP_TIME); - // 解压初始化 - await zip.inflateInit({}); - let inflateArrayBufferOut = new ArrayBuffer(BUFFER_SIZE); - // 校验数据 - checksum.crc32(0, arrayBufferOut); - try { - // 解压数据 - await zip.inflate({ - nextIn: arrayBufferOut, - availableIn: BUFFER_SIZE, - nextOut: inflateArrayBufferOut, - availableOut: BUFFER_SIZE - }, zlib.CompressFlushMode.NO_FLUSH).then((data) => { - let array = new Uint8Array(inflateArrayBufferOut); - let dataString = ''; - for (let i = 0; i < array.length; i++) { - dataString += String.fromCharCode(array[i]); - } - // 将解压后的数据写入zlibInflateFile.txt文件中 - let zlibInflateFile = - fileIo.openSync(pathDir + '/zlibInflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - fileIo.writeSync(zlibInflateFile.fd, dataString); - fileIo.closeSync(zlibInflateFile); - // 验证压缩与解压的数据是否一致 - if (STRING_DATA == dataString) { - promptAction.showToast({ - message: $r('app.string.zlib_uncompress_success', dataString), - bottom: '11%' - }); - } - }) - } catch (errData) { - promptAction.showToast({ - message: $r('app.string.zlib_uncompress_failure'), - bottom: '11%' - }); - } - // 释放动态分配的数据结构 - await zip.inflateEnd({ nextOut: arrayBufferOut }); - hilog.info(DOMAIN, TAG, BUNDLE + `zlibDecompression end`); - } - - async gzipDecompression(): Promise { - hilog.info(DOMAIN, TAG, BUNDLE + `gzipDecompression begin`); - let context = AppStorage.get('context') as Context; - let pathDir = context.cacheDir; - let file = fileIo.openSync(pathDir + '/gzipTest.gz', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - let path = pathDir + '/gzipTest.gz'; - fileIo.closeSync(file); - - // 创建gzip对象 - let gzip = zlib.createGZipSync(); - // 打开.gz文件,对文件进行写操作 - await gzip.gzopen(path, 'wb'); - let str = STRING_DATA; - let arrayBufferIn = new ArrayBuffer(BUFFER_SIZE); - let byteArray = new Uint8Array(arrayBufferIn); - for (let i = 0, j = str.length; i < j; i++) { - byteArray[i] = str.charCodeAt(i); - } - try { - // 将bufferWithData压缩并写入文件 - await gzip.gzfwrite(arrayBufferIn, 8, 2).then((data) => { - promptAction.showToast({ - message: $r('app.string.gzip_compress_success', str), - bottom: '11%' - }); - }) - } catch (errData) { - promptAction.showToast({ - message: $r('app.string.gzip_compress_failure'), - bottom: '11%' - }); - } - await gzip.gzflush(0); - await gzip.gzclose(); - - await sleep(SLEEP_TIME); - // 打开.gz文件,对文件进行读操作 - await gzip.gzopen(path, 'rb'); - try { - let bufferWithDataOut = new ArrayBuffer(BUFFER_SIZE); - // 从.gz文件中读取和解压数据 - await gzip.gzfread(bufferWithDataOut, 8, 2).then((data) => { - let array = new Uint8Array(bufferWithDataOut); - let dataString = ''; - for (let i = 0; i < array.length; i++) { - dataString += String.fromCharCode(array[i]); - } - if (dataString == str) { - promptAction.showToast({ - message: $r('app.string.gzip_uncompress_success', dataString), - bottom: '11%' - }); - let gzipFile = - fileIo.openSync(pathDir + '/gzipTest.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - fileIo.writeSync(gzipFile.fd, dataString); - fileIo.closeSync(gzipFile); - } - }) - } catch (errData) { - promptAction.showToast({ - message: $r('app.string.gzip_uncompress_failure'), - bottom: '11%' - }); - } - await gzip.gzclose(); - hilog.info(DOMAIN, TAG, BUNDLE + `gzipDecompression end`); - } - - build() { - Column() { - Column() { - Row() { - Image($r('app.media.icon_back')) - .size({ height: '71%' }) - .objectFit(ImageFit.Contain) - .onClick(() => { - router.pushUrl({ - url: 'pages/Index' - }); - }) - Text($r('app.string.zlibInterface')) - .fontSize(20) - .margin({ left: 8 }) - .width('100%') - .height('100%') - .fontWeight(FontWeight.Bold) - } - .height('15.64%') - .width('91%') - - Row() { - Text($r('app.string.CompressFiles')) - .textAlign(TextAlign.Start) - .fontSize(16) - .fontColor($r('app.color.text_color')) - Image($r('app.media.icon_next')) - .size({ height: '42.8%' }) - .objectFit(ImageFit.Contain) - } - .id('compressFiles') - .onClick(() => { - router.pushUrl({ - url: 'zlib/CompressFilesPage' - }); - }) - .justifyContent(FlexAlign.SpaceBetween) - .padding({ right: 12, left: 12 }) - .height('15.64%') - .width('91%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(15) - .margin({ top: 8 }) - } - .alignItems(HorizontalAlign.Center) - .width('100%') - .height('50%') - - Column() { - Text($r('app.string.tip_Gzip')) - .textAlign(TextAlign.Start) - .fontSize(12) - .fontColor($r('app.color.tip_Gzip_backeGround')) - .width('86.4%') - .height('9%') - .margin({ bottom: 24 }) - - Button($r('app.string.gzip_interface')) - .id('gzipinterface') - .width('100%') - .height('100%') - .fontSize(16) - .fontFamily('HarmonyHeiTi') - .type(ButtonType.Capsule) - .backgroundColor($r('app.color.button_backeGround')) - .fontColor($r('app.color.button_color')) - .borderRadius(20) - .onClick(() => { - this.gzipDecompression(); - }) - .margin({ bottom: 12 }) - .width('91%') - .height('11.2%') - - Button($r('app.string.zlib_interface')) - .id('zlibinterface') - .width('100%') - .height('100%') - .fontSize(16) - .fontFamily('HarmonyHeiTi') - .type(ButtonType.Capsule) - .backgroundColor($r('app.color.button_backeGround')) - .fontColor($r('app.color.button_color')) - .borderRadius(20) - .onClick(() => { - this.zlibDecompression(); - }) - .margin({ bottom: 16 }) - .width('91%') - .height('11.2%') - } - .justifyContent(FlexAlign.End) - .alignItems(HorizontalAlign.Center) - .width('100%') - .height('50%') - } - .backgroundColor($r('app.color.backGrounding')) - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2024 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 { fileIo } from '@kit.CoreFileKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction, router } from '@kit.ArkUI'; +import { zlib } from '@kit.BasicServicesKit'; + +const DOMAIN = 0xF811; +const BUNDLE = 'ZipLib_'; +const TAG: string = '[ZLibInterfaceListPage]'; +const SLEEP_TIME = 3000; +const BUFFER_SIZE = 13; +const OFFSET = 0; +const STRING_DATA = 'hello, hello!'; + +function sleep(time: number) { + return new Promise((resolve) => setTimeout(resolve, time)); +}; + +@Entry +@Component +struct ZLibInterfaceListPage { + async zlibDecompression(): Promise { + hilog.info(DOMAIN, TAG, BUNDLE + `zlibDecompression begin`); + let context = AppStorage.get('context') as Context; + let pathDir = context.cacheDir; + let zlibFile = fileIo.openSync(pathDir + '/zlibFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + fileIo.writeSync(zlibFile.fd, STRING_DATA); + let arrayBufferIn = new ArrayBuffer(BUFFER_SIZE); + fileIo.readSync(zlibFile.fd, arrayBufferIn, { offset: OFFSET }); + fileIo.closeSync(zlibFile); + + let arrayBufferOut = new ArrayBuffer(BUFFER_SIZE); + // 创建zip对象 + let zip = zlib.createZipSync(); + // 压缩初始化 + await zip.deflateInit({}, zlib.CompressLevel.COMPRESS_LEVEL_BEST_SPEED); + // 校验数据 + let checksum = zlib.createChecksumSync(); + checksum.crc32(0, arrayBufferIn); + try { + // 压缩数据 + await zip.deflate({ + nextIn: arrayBufferIn, + availableIn: BUFFER_SIZE, + nextOut: arrayBufferOut, + availableOut: BUFFER_SIZE + }, zlib.CompressFlushMode.FINISH).then((data) => { + // 将压缩后的buffer写入zlibDeflateFile.txt文件中 + let zlibDeflateFile = + fileIo.openSync(pathDir + '/zlibDeflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + fileIo.writeSync(zlibDeflateFile.fd, arrayBufferOut); + fileIo.closeSync(zlibDeflateFile); + promptAction.showToast({ + message: $r('app.string.zlib_compress_success', STRING_DATA), + bottom: '11%' + }); + }) + } catch (errData) { + promptAction.showToast({ + message: $r('app.string.zlib_compress_failure'), + bottom: '11%' + }); + } + // 释放动态分配的数据结构 + await zip.deflateEnd({ nextOut: arrayBufferOut }); + await sleep(SLEEP_TIME); + // 解压初始化 + await zip.inflateInit({}); + let inflateArrayBufferOut = new ArrayBuffer(BUFFER_SIZE); + // 校验数据 + checksum.crc32(0, arrayBufferOut); + try { + // 解压数据 + await zip.inflate({ + nextIn: arrayBufferOut, + availableIn: BUFFER_SIZE, + nextOut: inflateArrayBufferOut, + availableOut: BUFFER_SIZE + }, zlib.CompressFlushMode.NO_FLUSH).then((data) => { + let array = new Uint8Array(inflateArrayBufferOut); + let dataString = ''; + for (let i = 0; i < array.length; i++) { + dataString += String.fromCharCode(array[i]); + } + // 将解压后的数据写入zlibInflateFile.txt文件中 + let zlibInflateFile = + fileIo.openSync(pathDir + '/zlibInflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + fileIo.writeSync(zlibInflateFile.fd, dataString); + fileIo.closeSync(zlibInflateFile); + // 验证压缩与解压的数据是否一致 + if (STRING_DATA == dataString) { + promptAction.showToast({ + message: $r('app.string.zlib_uncompress_success', dataString), + bottom: '11%' + }); + } + }) + } catch (errData) { + promptAction.showToast({ + message: $r('app.string.zlib_uncompress_failure'), + bottom: '11%' + }); + } + // 释放动态分配的数据结构 + await zip.inflateEnd({ nextOut: arrayBufferOut }); + hilog.info(DOMAIN, TAG, BUNDLE + `zlibDecompression end`); + } + + async gzipDecompression(): Promise { + hilog.info(DOMAIN, TAG, BUNDLE + `gzipDecompression begin`); + let context = AppStorage.get('context') as Context; + let pathDir = context.cacheDir; + let file = fileIo.openSync(pathDir + '/gzipTest.gz', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + let path = pathDir + '/gzipTest.gz'; + fileIo.closeSync(file); + + // 创建gzip对象 + let gzip = zlib.createGZipSync(); + // 打开.gz文件,对文件进行写操作 + await gzip.gzopen(path, 'wb'); + let str = STRING_DATA; + let arrayBufferIn = new ArrayBuffer(BUFFER_SIZE); + let byteArray = new Uint8Array(arrayBufferIn); + for (let i = 0, j = str.length; i < j; i++) { + byteArray[i] = str.charCodeAt(i); + } + try { + // 将bufferWithData压缩并写入文件 + await gzip.gzfwrite(arrayBufferIn, 8, 2).then((data) => { + promptAction.showToast({ + message: $r('app.string.gzip_compress_success', str), + bottom: '11%' + }); + }) + } catch (errData) { + promptAction.showToast({ + message: $r('app.string.gzip_compress_failure'), + bottom: '11%' + }); + } + await gzip.gzflush(0); + await gzip.gzclose(); + + await sleep(SLEEP_TIME); + // 打开.gz文件,对文件进行读操作 + await gzip.gzopen(path, 'rb'); + try { + let bufferWithDataOut = new ArrayBuffer(BUFFER_SIZE); + // 从.gz文件中读取和解压数据 + await gzip.gzfread(bufferWithDataOut, 8, 2).then((data) => { + let array = new Uint8Array(bufferWithDataOut); + let dataString = ''; + for (let i = 0; i < array.length; i++) { + dataString += String.fromCharCode(array[i]); + } + if (dataString == str) { + promptAction.showToast({ + message: $r('app.string.gzip_uncompress_success', dataString), + bottom: '11%' + }); + let gzipFile = + fileIo.openSync(pathDir + '/gzipTest.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + fileIo.writeSync(gzipFile.fd, dataString); + fileIo.closeSync(gzipFile); + } + }) + } catch (errData) { + promptAction.showToast({ + message: $r('app.string.gzip_uncompress_failure'), + bottom: '11%' + }); + } + await gzip.gzclose(); + hilog.info(DOMAIN, TAG, BUNDLE + `gzipDecompression end`); + } + + build() { + Column() { + Column() { + Row() { + Image($r('app.media.icon_back')) + .size({ height: '71%' }) + .objectFit(ImageFit.Contain) + .onClick(() => { + router.pushUrl({ + url: 'pages/Index' + }); + }) + Text($r('app.string.zlibInterface')) + .fontSize(20) + .margin({ left: 8 }) + .width('100%') + .height('100%') + .fontWeight(FontWeight.Bold) + } + .height('15.64%') + .width('91%') + + Row() { + Text($r('app.string.CompressFiles')) + .textAlign(TextAlign.Start) + .fontSize(16) + .fontColor($r('app.color.text_color')) + Image($r('app.media.icon_next')) + .size({ height: '42.8%' }) + .objectFit(ImageFit.Contain) + } + .id('compressFiles') + .onClick(() => { + router.pushUrl({ + url: 'zlib/CompressFilesPage' + }); + }) + .justifyContent(FlexAlign.SpaceBetween) + .padding({ right: 12, left: 12 }) + .height('15.64%') + .width('91%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(15) + .margin({ top: 8 }) + } + .alignItems(HorizontalAlign.Center) + .width('100%') + .height('50%') + + Column() { + Text($r('app.string.tip_Gzip')) + .textAlign(TextAlign.Start) + .fontSize(12) + .fontColor($r('app.color.tip_Gzip_backeGround')) + .width('86.4%') + .height('9%') + .margin({ bottom: 24 }) + + Button($r('app.string.gzip_interface')) + .id('gzipinterface') + .width('100%') + .height('100%') + .fontSize(16) + .fontFamily('HarmonyHeiTi') + .type(ButtonType.Capsule) + .backgroundColor($r('app.color.button_backeGround')) + .fontColor($r('app.color.button_color')) + .borderRadius(20) + .onClick(() => { + this.gzipDecompression(); + }) + .margin({ bottom: 12 }) + .width('91%') + .height('11.2%') + + Button($r('app.string.zlib_interface')) + .id('zlibinterface') + .width('100%') + .height('100%') + .fontSize(16) + .fontFamily('HarmonyHeiTi') + .type(ButtonType.Capsule) + .backgroundColor($r('app.color.button_backeGround')) + .fontColor($r('app.color.button_color')) + .borderRadius(20) + .onClick(() => { + this.zlibDecompression(); + }) + .margin({ bottom: 16 }) + .width('91%') + .height('11.2%') + } + .justifyContent(FlexAlign.End) + .alignItems(HorizontalAlign.Center) + .width('100%') + .height('50%') + } + .backgroundColor($r('app.color.backGrounding')) + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/code/Performance/ArkRuntime/NBody/AppScope/app.json5 b/code/Performance/ArkRuntime/NBody/AppScope/app.json5 index e76916bdcc9739c4bdb77201c09e15558dbd1b71..9e14e0fcb4861fde08345e5bb041d209e12e11de 100644 --- a/code/Performance/ArkRuntime/NBody/AppScope/app.json5 +++ b/code/Performance/ArkRuntime/NBody/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "app": { - "bundleName": "com.example.nbody", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.example.nbody", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/Performance/ArkRuntime/NBody/AppScope/resources/base/element/string.json b/code/Performance/ArkRuntime/NBody/AppScope/resources/base/element/string.json index 6c70e2d8155547924acd16e1577006ac1e5c25ee..69746c0922a1b3f551c1cd3437bb51c61f263d11 100644 --- a/code/Performance/ArkRuntime/NBody/AppScope/resources/base/element/string.json +++ b/code/Performance/ArkRuntime/NBody/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "NBody" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "NBody" + } + ] +} diff --git a/code/Performance/ArkRuntime/NBody/build-profile.json5 b/code/Performance/ArkRuntime/NBody/build-profile.json5 index a387b394ae39fc0a406699dee781b93be34c6af8..faa08452aadba3f469a4988a71246a8781af8da4 100644 --- a/code/Performance/ArkRuntime/NBody/build-profile.json5 +++ b/code/Performance/ArkRuntime/NBody/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2022-2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2022-2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "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/Performance/ArkRuntime/NBody/entry/build-profile.json5 b/code/Performance/ArkRuntime/NBody/entry/build-profile.json5 index 94d88d01e5ee0b5d550bd7821ea440365d7b8259..a1fb0f59651544e945a332d658e44fdcba839c85 100644 --- a/code/Performance/ArkRuntime/NBody/entry/build-profile.json5 +++ b/code/Performance/ArkRuntime/NBody/entry/build-profile.json5 @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2023 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": { - "sourceOption": { - "workers": [ - "./src/main/ets/workers/CalculateWorker.ts" - ] - } - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/CalculateWorker.ts" + ] + } + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/Performance/ArkRuntime/NBody/entry/oh-package.json5 b/code/Performance/ArkRuntime/NBody/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/Performance/ArkRuntime/NBody/entry/oh-package.json5 +++ b/code/Performance/ArkRuntime/NBody/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/Performance/ArkRuntime/NBody/entry/src/main/ets/entryability/EntryAbility.ets b/code/Performance/ArkRuntime/NBody/entry/src/main/ets/entryability/EntryAbility.ets index f583515e6d6ed218c9925bf98ec08f5aa73a5a36..a50eabebd1157b99154da7d846828068d16898fa 100644 --- a/code/Performance/ArkRuntime/NBody/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/Performance/ArkRuntime/NBody/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import Logger from '../utils/Logger'; - -const TAG: string = 'EntryAbility' - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - Logger.info(TAG, 'Ability onCreate'); - } - - onDestroy(): void | Promise { - Logger.info(TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - Logger.info(TAG, 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - Logger.info(TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - Logger.info(TAG, 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - Logger.info(TAG, 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - Logger.info(TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import Logger from '../utils/Logger'; + +const TAG: string = 'EntryAbility' + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + Logger.info(TAG, 'Ability onCreate'); + } + + onDestroy(): void | Promise { + Logger.info(TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + Logger.info(TAG, 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + Logger.info(TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + Logger.info(TAG, 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + Logger.info(TAG, 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + Logger.info(TAG, 'Ability onBackground'); + } +} diff --git a/code/Performance/ArkRuntime/NBody/entry/src/main/ets/model/CalculateUtil.ets b/code/Performance/ArkRuntime/NBody/entry/src/main/ets/model/CalculateUtil.ets index 2c88b54ba65559e0759928f391e02a75b83dfea5..c3ae6714dc9c6658f1bd1222729ea681cbe947fe 100644 --- a/code/Performance/ArkRuntime/NBody/entry/src/main/ets/model/CalculateUtil.ets +++ b/code/Performance/ArkRuntime/NBody/entry/src/main/ets/model/CalculateUtil.ets @@ -1,99 +1,99 @@ -/* - * Copyright (c) 2023 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 taskpool from '@ohos.taskpool'; -import { BusinessError } from '@ohos.base'; -import worker, { MessageEvents } from '@ohos.worker'; -import util from '@ohos.util'; -import { offsetMomentum, energy, advance } from './NBody_ETS_6'; -import Logger from '../utils/Logger'; - -const TAG: string = 'CalculateUtil'; -let calculateResult: string = "Total time costed = %s ms." - -class WorkerMessage { - timeSteps: number; - - constructor(timeSteps: number) { - this.timeSteps = timeSteps; - } -} - -/** - * 运行天体轨道计算程序 - * @param totalTimeSteps 时间推移量 - * @returns 计算时间 - */ -@Concurrent -export function computeTask(totalTimeSteps: number): number { - const tagInTask: string = 'computeTask'; - const timeStep: number = 0.01; // 单位:hour - const fractionDigits: number = 9; // 机械能数值小数位 - let start: number = new Date().getTime(); - - // 建立孤立系统的动量守恒 - offsetMomentum(); - Logger.info(tagInTask, energy().toFixed(fractionDigits)); - - // 更新天体在按指定的时间变化后的位置信息 - for (let i: number = 0; i < totalTimeSteps; i++) { - advance(timeStep); - } - - // 判断系统计算前后机械能守恒 - Logger.info(tagInTask, energy().toFixed(fractionDigits)); - let end: number = new Date().getTime(); - return end - start; -} - -/** - * 使用TaskPool开启子线程,执行轨道计算任务 - * @param totalTimeSteps 时间推移量 - */ -export function computeNBodyByTaskPool(totalTimeSteps: number): void { - Logger.info(TAG, "computeNBodyByTaskPool: start executing"); - let task: taskpool.Task = new taskpool.Task(computeTask, totalTimeSteps); - try { - Logger.info(TAG, 'computeNBodyByTaskPool: start calculating...'); - - // 向taskpool线程池派发子线程任务 - taskpool.execute(task, taskpool.Priority.HIGH).then((res: number) => { - Logger.info(TAG, 'computeNBodyByTaskPool: executed successfully, total time costed = ' + res + ' ms.'); - AppStorage.set('timeCost', util.format(calculateResult, res.toString())) - }) - } catch (err) { - Logger.error(TAG, "computeNBodyByTaskPool: execute failed, " + (err as BusinessError).toString()); - } - Logger.info(TAG, "computeNBodyByTaskPool: finish executing"); -} - -/** - * 使用Worker开启子线程,执行轨道计算任务 - * @param totalTimeSteps 时间推移量 - */ -export function computeNBodyByWorker(totalTimeSteps: number): void { - Logger.info(TAG, "computeNBodyByWorker: start executing"); - let workerInstance = new worker.ThreadWorker("entry/ets/workers/CalculateWorker.ts"); - - // 设置如何处理,来自worker线程的消息 - workerInstance.onmessage = (e: MessageEvents): void => { - let data: Record = e.data; - Logger.info(TAG, 'computeNBodyByWorker: executed successfully, total time costed = ' + data.result + ' ms.'); - AppStorage.set('timeCost', util.format(calculateResult, data.result)); - } - - // 设置由主线程向worker线程发送什么消息 - workerInstance.postMessage(new WorkerMessage(totalTimeSteps)); +/* + * Copyright (c) 2023 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 taskpool from '@ohos.taskpool'; +import { BusinessError } from '@ohos.base'; +import worker, { MessageEvents } from '@ohos.worker'; +import util from '@ohos.util'; +import { offsetMomentum, energy, advance } from './NBody_ETS_6'; +import Logger from '../utils/Logger'; + +const TAG: string = 'CalculateUtil'; +let calculateResult: string = "Total time costed = %s ms." + +class WorkerMessage { + timeSteps: number; + + constructor(timeSteps: number) { + this.timeSteps = timeSteps; + } +} + +/** + * 运行天体轨道计算程序 + * @param totalTimeSteps 时间推移量 + * @returns 计算时间 + */ +@Concurrent +export function computeTask(totalTimeSteps: number): number { + const tagInTask: string = 'computeTask'; + const timeStep: number = 0.01; // 单位:hour + const fractionDigits: number = 9; // 机械能数值小数位 + let start: number = new Date().getTime(); + + // 建立孤立系统的动量守恒 + offsetMomentum(); + Logger.info(tagInTask, energy().toFixed(fractionDigits)); + + // 更新天体在按指定的时间变化后的位置信息 + for (let i: number = 0; i < totalTimeSteps; i++) { + advance(timeStep); + } + + // 判断系统计算前后机械能守恒 + Logger.info(tagInTask, energy().toFixed(fractionDigits)); + let end: number = new Date().getTime(); + return end - start; +} + +/** + * 使用TaskPool开启子线程,执行轨道计算任务 + * @param totalTimeSteps 时间推移量 + */ +export function computeNBodyByTaskPool(totalTimeSteps: number): void { + Logger.info(TAG, "computeNBodyByTaskPool: start executing"); + let task: taskpool.Task = new taskpool.Task(computeTask, totalTimeSteps); + try { + Logger.info(TAG, 'computeNBodyByTaskPool: start calculating...'); + + // 向taskpool线程池派发子线程任务 + taskpool.execute(task, taskpool.Priority.HIGH).then((res: number) => { + Logger.info(TAG, 'computeNBodyByTaskPool: executed successfully, total time costed = ' + res + ' ms.'); + AppStorage.set('timeCost', util.format(calculateResult, res.toString())) + }) + } catch (err) { + Logger.error(TAG, "computeNBodyByTaskPool: execute failed, " + (err as BusinessError).toString()); + } + Logger.info(TAG, "computeNBodyByTaskPool: finish executing"); +} + +/** + * 使用Worker开启子线程,执行轨道计算任务 + * @param totalTimeSteps 时间推移量 + */ +export function computeNBodyByWorker(totalTimeSteps: number): void { + Logger.info(TAG, "computeNBodyByWorker: start executing"); + let workerInstance = new worker.ThreadWorker("entry/ets/workers/CalculateWorker.ts"); + + // 设置如何处理,来自worker线程的消息 + workerInstance.onmessage = (e: MessageEvents): void => { + let data: Record = e.data; + Logger.info(TAG, 'computeNBodyByWorker: executed successfully, total time costed = ' + data.result + ' ms.'); + AppStorage.set('timeCost', util.format(calculateResult, data.result)); + } + + // 设置由主线程向worker线程发送什么消息 + workerInstance.postMessage(new WorkerMessage(totalTimeSteps)); } \ No newline at end of file diff --git a/code/Performance/ArkRuntime/NBody/entry/src/main/module.json5 b/code/Performance/ArkRuntime/NBody/entry/src/main/module.json5 index d0ae81f7824a8dd306da3ec891818ce8c0f13138..7dadb239554a46de79a68f02701da35bee06492c 100644 --- a/code/Performance/ArkRuntime/NBody/entry/src/main/module.json5 +++ b/code/Performance/ArkRuntime/NBody/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/color.json b/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/color.json index 2436817ebe6201319761967020599f7b378a1abd..35992ef1212aa0e712df4749fd8023b36a71dbd1 100644 --- a/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/color.json +++ b/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/color.json @@ -1,12 +1,12 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "top_bar_background_color", - "value": "#3399ff" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "top_bar_background_color", + "value": "#3399ff" + } + ] } \ No newline at end of file diff --git a/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/integer.json b/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/integer.json index 4a37c784134a6d64cb8dfad538de6b5e7ec38546..a5f29aed5591aca51ec09650454d3fbb4a0064de 100644 --- a/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/integer.json +++ b/code/Performance/ArkRuntime/NBody/entry/src/main/resources/base/element/integer.json @@ -1,37 +1,37 @@ -{ - "integer": [ - { - "name": "top_bar_font_size", - "value": 30 - }, - { - "name": "top_bar_text_height", - "value": 50 - }, - { - "name": "top_bar_height", - "value": 50 - }, - { - "name": "top_image_border_radius", - "value": 5 - }, - { - "name": "center_message_font_size", - "value": 30 - }, - { - "name": "button_task_pool_margin_top", - "value": 30 - }, - { - "name": "button_worker_margin_top", - "value": 30 - } - , - { - "name": "AlertDialog_offset", - "value": -20 - } - ] +{ + "integer": [ + { + "name": "top_bar_font_size", + "value": 30 + }, + { + "name": "top_bar_text_height", + "value": 50 + }, + { + "name": "top_bar_height", + "value": 50 + }, + { + "name": "top_image_border_radius", + "value": 5 + }, + { + "name": "center_message_font_size", + "value": 30 + }, + { + "name": "button_task_pool_margin_top", + "value": 30 + }, + { + "name": "button_worker_margin_top", + "value": 30 + } + , + { + "name": "AlertDialog_offset", + "value": -20 + } + ] } \ No newline at end of file diff --git a/code/Performance/ArkRuntime/NBody/entry/src/ohosTest/module.json5 b/code/Performance/ArkRuntime/NBody/entry/src/ohosTest/module.json5 index 404ccf0b4cdd9785cdc8c50d709e5c98cfc84fe5..fb9aa4387110756938771e76566e75c94122c08c 100644 --- a/code/Performance/ArkRuntime/NBody/entry/src/ohosTest/module.json5 +++ b/code/Performance/ArkRuntime/NBody/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/Performance/ArkRuntime/NBody/hvigor/hvigor-config.json5 b/code/Performance/ArkRuntime/NBody/hvigor/hvigor-config.json5 index 3a4f957eef9278a763645f6cf23ac2e94d0d61b1..277e9a1fd2d734352e53676bf912347fee241ed0 100644 --- a/code/Performance/ArkRuntime/NBody/hvigor/hvigor-config.json5 +++ b/code/Performance/ArkRuntime/NBody/hvigor/hvigor-config.json5 @@ -1,18 +1,18 @@ -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } -} +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } +} diff --git a/code/Performance/ArkRuntime/NBody/oh-package.json5 b/code/Performance/ArkRuntime/NBody/oh-package.json5 index cefc7c1df3408ae2b83c4232345e8ecc13290c82..ec0ac2d207ea0f8806c09c10474c8ab68741bf90 100644 --- a/code/Performance/ArkRuntime/NBody/oh-package.json5 +++ b/code/Performance/ArkRuntime/NBody/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "nbody", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "nbody", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/Performance/renderGroup/AppScope/app.json5 b/code/Performance/renderGroup/AppScope/app.json5 index eda9bfffdeddb359f00e584d0d6a808325960f77..ed455315712a22658b176818a10df8979399e369 100644 --- a/code/Performance/renderGroup/AppScope/app.json5 +++ b/code/Performance/renderGroup/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "bundleName": "com.example.performance", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.example.performance", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/Performance/renderGroup/AppScope/resources/base/element/string.json b/code/Performance/renderGroup/AppScope/resources/base/element/string.json index 07e19712244b546cfe7dced84f8a7ab25c14e4e1..e330d1e5e15f290e8cbb94ea3f36684b2adc7a2b 100644 --- a/code/Performance/renderGroup/AppScope/resources/base/element/string.json +++ b/code/Performance/renderGroup/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "Performance" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "Performance" + } + ] +} diff --git a/code/Performance/renderGroup/README.md b/code/Performance/renderGroup/README.md index b2bd66ccd801dc9471ac3879264ec48288d91ca5..37bdd8d1f6aadfeda12f586ba922b027cfe0544b 100644 --- a/code/Performance/renderGroup/README.md +++ b/code/Performance/renderGroup/README.md @@ -1,87 +1,87 @@ -# 性能示例 - -### 介绍 - -本示例使用renderGroup接口实现了在单一页面上存在大量应用动效的组件时,使用renderGroup方法来解决卡顿问题,从而提升绘制能力。 - -renderGroup原理说明:首次绘制组件时,若组件被标记为启用renderGroup状态,将对组件和其子组件进行离屏绘制,将绘制结果进行缓存。以后当需要重新绘制组件时,就会优先使用缓存而不必重新绘制了。从而降低绘制负载,优化渲染性能。 - -### 效果预览 -| 性能示例主页 | 场景主页 | 正例场景页 | 反例场景页 | -| ------------------------------------- |--------------------------------------------------| -------------------------------------- | ----------------------------------- | -| ![](screenshots/device/PerformanceHomePage.jpeg) | ![](screenshots/device/RenderGroupHomePage.jpeg) | ![](screenshots/device/ProfitScenePage.jpeg) | ![](screenshots/device/NonProfitScenePage.jpeg) | - -使用说明 - -1.点击性能示例主页面的**RenderGroup**按钮,在场景界面中点击**正例场景示例**,进入正例场景页,可以点击renderGroup开关按钮,可以通过Profiler分析性能数据。 - -2.点击性能示例主页面的**RenderGroup**按钮,在场景界面中点击**反例场景示例**,进入反例场景页,可以点击renderGroup开关按钮,可以通过Profiler分析性能数据。 - -### 工程目录 - -``` -features/renderGroup/src/main/ets // 列表类功能HAR共享包 -|---/pages -| |---NonProfitScene.ets // 反例场景页面 -| |---ProfitScene.ets // 正例场景页面 -|---/utils -| |---Logger.ets // 封装整个日志 -|---/view -| |---IconView.ets // 正例场景模块 -| |---NonIconView.ets // 反例场景模块 -products/phone/entry/src/main/ets -|---/entryability -| |---EntryAbility.ts // 封装整个模块启用,监听Ability对应的窗口等逻辑 -|---/model -| |---/DataType // 数据类型 -| |---/MockData // 本地数据 -|---pages -| |---/renderGroup -| | |---NonProfitScenePage.ets // 反例场景页面 -| | |---ProfitScenePage.ets // 正例场景页面 -| | |---RenderGroupHomePage.ets // 场景主页面 -| |---/Index // 性能示例首页 -|---/utils -| |---Logger.ets // 封装整个日志 - -``` - -### 具体实现 - -* 本示例分成正例场景与反例场景两个模块 - - * 正例场景 - - * 在ProfitScene的IconItem上添加动画,在IconView上使用到renderGroup接口(renderGroup(value: boolean): T)得到收益。 - * 源码链接:[ProfitScene.ets](feature/renderGroup/src/main/ets/pages/ProfitScene.ets),[IconView.ts](feature/renderGroup/src/main/ets/view/IconView.ets) - - * 反例场景 - - * 在IconView的Image上添加动画,在NonIconView上使用到renderGroup接口(renderGroup(value: boolean): T)得到负收益。 - * 源码链接:[NonProfitScene.ets](feature/renderGroup/src/main/ets/pages/NonProfitScene.ets),[NonIconView.ts](feature/renderGroup/src/main/ets/view/NonIconView.ets) - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例已适配API version 10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0Release)。 - -2.本示例需要使用DevEco Studio 版本号(4.0Release)及以上版本才可编译运行。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/Performance/renderGroup/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# 性能示例 + +### 介绍 + +本示例使用renderGroup接口实现了在单一页面上存在大量应用动效的组件时,使用renderGroup方法来解决卡顿问题,从而提升绘制能力。 + +renderGroup原理说明:首次绘制组件时,若组件被标记为启用renderGroup状态,将对组件和其子组件进行离屏绘制,将绘制结果进行缓存。以后当需要重新绘制组件时,就会优先使用缓存而不必重新绘制了。从而降低绘制负载,优化渲染性能。 + +### 效果预览 +| 性能示例主页 | 场景主页 | 正例场景页 | 反例场景页 | +| ------------------------------------- |--------------------------------------------------| -------------------------------------- | ----------------------------------- | +| ![](screenshots/device/PerformanceHomePage.jpeg) | ![](screenshots/device/RenderGroupHomePage.jpeg) | ![](screenshots/device/ProfitScenePage.jpeg) | ![](screenshots/device/NonProfitScenePage.jpeg) | + +使用说明 + +1.点击性能示例主页面的**RenderGroup**按钮,在场景界面中点击**正例场景示例**,进入正例场景页,可以点击renderGroup开关按钮,可以通过Profiler分析性能数据。 + +2.点击性能示例主页面的**RenderGroup**按钮,在场景界面中点击**反例场景示例**,进入反例场景页,可以点击renderGroup开关按钮,可以通过Profiler分析性能数据。 + +### 工程目录 + +``` +features/renderGroup/src/main/ets // 列表类功能HAR共享包 +|---/pages +| |---NonProfitScene.ets // 反例场景页面 +| |---ProfitScene.ets // 正例场景页面 +|---/utils +| |---Logger.ets // 封装整个日志 +|---/view +| |---IconView.ets // 正例场景模块 +| |---NonIconView.ets // 反例场景模块 +products/phone/entry/src/main/ets +|---/entryability +| |---EntryAbility.ts // 封装整个模块启用,监听Ability对应的窗口等逻辑 +|---/model +| |---/DataType // 数据类型 +| |---/MockData // 本地数据 +|---pages +| |---/renderGroup +| | |---NonProfitScenePage.ets // 反例场景页面 +| | |---ProfitScenePage.ets // 正例场景页面 +| | |---RenderGroupHomePage.ets // 场景主页面 +| |---/Index // 性能示例首页 +|---/utils +| |---Logger.ets // 封装整个日志 + +``` + +### 具体实现 + +* 本示例分成正例场景与反例场景两个模块 + + * 正例场景 + + * 在ProfitScene的IconItem上添加动画,在IconView上使用到renderGroup接口(renderGroup(value: boolean): T)得到收益。 + * 源码链接:[ProfitScene.ets](feature/renderGroup/src/main/ets/pages/ProfitScene.ets),[IconView.ts](feature/renderGroup/src/main/ets/view/IconView.ets) + + * 反例场景 + + * 在IconView的Image上添加动画,在NonIconView上使用到renderGroup接口(renderGroup(value: boolean): T)得到负收益。 + * 源码链接:[NonProfitScene.ets](feature/renderGroup/src/main/ets/pages/NonProfitScene.ets),[NonIconView.ts](feature/renderGroup/src/main/ets/view/NonIconView.ets) + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例已适配API version 10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0Release)。 + +2.本示例需要使用DevEco Studio 版本号(4.0Release)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/Performance/renderGroup/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/Performance/renderGroup/build-profile.json5 b/code/Performance/renderGroup/build-profile.json5 index 5fc0f34eb670b4c6dba490e5013e9d9c41558c0a..f84138f1907593432513ca976869791f5d7f474f 100644 --- a/code/Performance/renderGroup/build-profile.json5 +++ b/code/Performance/renderGroup/build-profile.json5 @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./product/phone/entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "renderGroup", - "srcPath": "./feature/renderGroup" - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./product/phone/entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "renderGroup", + "srcPath": "./feature/renderGroup" + } + ] } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/Index.ets b/code/Performance/renderGroup/feature/renderGroup/Index.ets index 240e61d114411b35e3e3cb43d87819b9e933b27a..a205148552155d4ed1c13fed951b595b4e89a6af 100644 --- a/code/Performance/renderGroup/feature/renderGroup/Index.ets +++ b/code/Performance/renderGroup/feature/renderGroup/Index.ets @@ -1,18 +1,18 @@ -/* - * Copyright (c) 2023 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 { ProfitScene } from './src/main/ets/pages/ProfitScene'; - +/* + * Copyright (c) 2023 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 { ProfitScene } from './src/main/ets/pages/ProfitScene'; + export { NonProfitScene } from './src/main/ets/pages/NonProfitScene'; \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/build-profile.json5 b/code/Performance/renderGroup/feature/renderGroup/build-profile.json5 index 2f44828ebc512812bde78968aaf9d5297b298ea3..805afd07d89bc1e98a42c4f44c068417d4cacdc9 100644 --- a/code/Performance/renderGroup/feature/renderGroup/build-profile.json5 +++ b/code/Performance/renderGroup/feature/renderGroup/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - }, - "consumerFiles": [ - "./consumer-rules.txt" - ] - } - } - }, - ], - "targets": [ - { - "name": "default" - } - ] -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + } + }, + ], + "targets": [ + { + "name": "default" + } + ] +} diff --git a/code/Performance/renderGroup/feature/renderGroup/oh-package.json5 b/code/Performance/renderGroup/feature/renderGroup/oh-package.json5 index dfa8449e0b39a21560f35a18543905330a6ac140..a3eb37e069e410ea0846d0c9fe1116d3bb983800 100644 --- a/code/Performance/renderGroup/feature/renderGroup/oh-package.json5 +++ b/code/Performance/renderGroup/feature/renderGroup/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "Apache-2.0", - "devDependencies": {}, - "author": "", - "name": "rendergroup", - "description": "Please describe the basic information.", - "main": "Index.ets", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "Apache-2.0", + "devDependencies": {}, + "author": "", + "name": "rendergroup", + "description": "Please describe the basic information.", + "main": "Index.ets", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/NonProfitScene.ets b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/NonProfitScene.ets index c796b8ad2b6471099a426902d86168d35aeedd5d..10e50519a4005dd472905f9a3da6512b912d7ff8 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/NonProfitScene.ets +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/NonProfitScene.ets @@ -1,127 +1,127 @@ -/* - * Copyright (c) 2023 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 { NonIconItem } from '../view/NonIconView'; -import router from '@ohos.router' - -// GridRow列数 -const COLUMNS: number = 6; -// GridRow横向间隙 -const GUTTER_X: number = 0; -// GridRow纵向间隙 -const GUTTER_Y: number = 0; - -// IconItem相关数据 -class IconItemSource { - image: string | Resource = '' - text: string | Resource = '' - - constructor(image: string | Resource = '', text: string | Resource = '') { - this.image = image; - this.text = text; - } -} - -@Component -export struct NonProfitScene { - // renderGroup接口是否开启 - @State renderGroupFlag: boolean = false; - private iconItemSourceList: IconItemSource[] = []; - - aboutToAppear() { - // 遍历添加60个IconItem的数据 - for (let index = 0; index < 20; index++) { - const numStart: number = index * 3; - // 此处循环使用三张图片资源 - this.iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); - this.iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); - this.iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); - } - } - - build() { - Column() { - // 顶部导航栏 - Row() { - Row() { - Image($r("app.media.back")) - .id('returnBtn') - .height($r('app.integer.RenderGroup_scene_back_image_size')) - .width($r('app.integer.RenderGroup_scene_back_image_size')) - .onClick(() => { - router.back(); - }) - - Text($r('app.string.RenderGroup_nonProfit_scene_title')) - .fontSize($r('app.integer.RenderGroup_scene_title_font')) - .lineHeight($r('app.integer.RenderGroup_scene_title_lineHeight')) - .fontColor(Color.Black) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Start) - .margin({ - left: $r('app.integer.RenderGroup_scene_title_margin_left') - }) - } - .margin({ - left: $r('app.integer.RenderGroup_scene_row_margin_left') - }) - - Stack({ alignContent: Alignment.End }) { - Button(this.renderGroupFlag ? $r('app.string.RenderGroup_button_on') : $r('app.string.RenderGroup_button_off'), { - type: ButtonType.Normal, - stateEffect: true - }) - .id("renderGroupSwitch") - .fontSize($r('app.integer.RenderGroup_scene_button_fontSize')) - .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) - .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) - .width($r('app.integer.RenderGroup_scene_title_button_width')) - .height($r('app.integer.RenderGroup_scene_title_button_height')) - .margin({ - right: $r('app.integer.RenderGroup_scene_button_margin_right') - }) - .onClick(() => { - this.renderGroupFlag = !this.renderGroupFlag; - }) - } - } - .height($r('app.integer.RenderGroup_scene_title_row_height')) - .width($r('app.string.layout_100_percent')) - .backgroundColor(Color.White) - .justifyContent(FlexAlign.SpaceBetween) - - // IconItem放置在grid内 - GridRow({ - columns: COLUMNS, - gutter: { x: GUTTER_X, y: GUTTER_Y }, - breakpoints: { value: ["400vp", "600vp", "800vp"], reference: BreakpointsReference.WindowSize }, - direction: GridRowDirection.Row - }) { - ForEach(this.iconItemSourceList, (item: IconItemSource) => { - GridCol() { - NonIconItem({ image: item.image, text: item.text, renderGroupFlag: this.renderGroupFlag }) - } - .height($r('app.integer.RenderGroup_scene_GridCol_height')) - .width($r('app.string.layout_17_percent')) - }) - } - .width($r('app.string.layout_100_percent')) - .height($r('app.string.layout_100_percent')) - } - .width($r('app.string.layout_100_percent')) - .height($r('app.string.layout_100_percent')) - .alignItems(HorizontalAlign.Center) - } +/* + * Copyright (c) 2023 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 { NonIconItem } from '../view/NonIconView'; +import router from '@ohos.router' + +// GridRow列数 +const COLUMNS: number = 6; +// GridRow横向间隙 +const GUTTER_X: number = 0; +// GridRow纵向间隙 +const GUTTER_Y: number = 0; + +// IconItem相关数据 +class IconItemSource { + image: string | Resource = '' + text: string | Resource = '' + + constructor(image: string | Resource = '', text: string | Resource = '') { + this.image = image; + this.text = text; + } +} + +@Component +export struct NonProfitScene { + // renderGroup接口是否开启 + @State renderGroupFlag: boolean = false; + private iconItemSourceList: IconItemSource[] = []; + + aboutToAppear() { + // 遍历添加60个IconItem的数据 + for (let index = 0; index < 20; index++) { + const numStart: number = index * 3; + // 此处循环使用三张图片资源 + this.iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`)); + } + } + + build() { + Column() { + // 顶部导航栏 + Row() { + Row() { + Image($r("app.media.back")) + .id('returnBtn') + .height($r('app.integer.RenderGroup_scene_back_image_size')) + .width($r('app.integer.RenderGroup_scene_back_image_size')) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.RenderGroup_nonProfit_scene_title')) + .fontSize($r('app.integer.RenderGroup_scene_title_font')) + .lineHeight($r('app.integer.RenderGroup_scene_title_lineHeight')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: $r('app.integer.RenderGroup_scene_title_margin_left') + }) + } + .margin({ + left: $r('app.integer.RenderGroup_scene_row_margin_left') + }) + + Stack({ alignContent: Alignment.End }) { + Button(this.renderGroupFlag ? $r('app.string.RenderGroup_button_on') : $r('app.string.RenderGroup_button_off'), { + type: ButtonType.Normal, + stateEffect: true + }) + .id("renderGroupSwitch") + .fontSize($r('app.integer.RenderGroup_scene_button_fontSize')) + .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) + .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) + .width($r('app.integer.RenderGroup_scene_title_button_width')) + .height($r('app.integer.RenderGroup_scene_title_button_height')) + .margin({ + right: $r('app.integer.RenderGroup_scene_button_margin_right') + }) + .onClick(() => { + this.renderGroupFlag = !this.renderGroupFlag; + }) + } + } + .height($r('app.integer.RenderGroup_scene_title_row_height')) + .width($r('app.string.layout_100_percent')) + .backgroundColor(Color.White) + .justifyContent(FlexAlign.SpaceBetween) + + // IconItem放置在grid内 + GridRow({ + columns: COLUMNS, + gutter: { x: GUTTER_X, y: GUTTER_Y }, + breakpoints: { value: ["400vp", "600vp", "800vp"], reference: BreakpointsReference.WindowSize }, + direction: GridRowDirection.Row + }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + GridCol() { + NonIconItem({ image: item.image, text: item.text, renderGroupFlag: this.renderGroupFlag }) + } + .height($r('app.integer.RenderGroup_scene_GridCol_height')) + .width($r('app.string.layout_17_percent')) + }) + } + .width($r('app.string.layout_100_percent')) + .height($r('app.string.layout_100_percent')) + } + .width($r('app.string.layout_100_percent')) + .height($r('app.string.layout_100_percent')) + .alignItems(HorizontalAlign.Center) + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/ProfitScene.ets b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/ProfitScene.ets index 1340c8fcf78214fc47c9f5c2d3fcd3e29e914722..f9dea3782aa39ac866c0fc103f291f2c198acb9c 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/ProfitScene.ets +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/pages/ProfitScene.ets @@ -1,144 +1,144 @@ -/* - * Copyright (c) 2023 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 { IconItem } from '../view/IconView'; -import router from '@ohos.router' - -// GridRow列数 -const COLUMNS: number = 6; -// GridRow横向间隙 -const GUTTER_X: number = 0; -// GridRow纵向间隙 -const GUTTER_Y: number = 0; -// X轴方向缩放比例 -const SCALE_X: number = 0.5; -// Y轴方向缩放比例 -const SCALE_Y: number = 0.5; -// 绕z轴旋转 -const ROTATE_Z: number = 1; -// 旋转角度 -const ROTATE_ANGLE: number = 360; -// 动画时长 -const DURATION: number = 3000; -// 重复次数 -const ITERATIONS: number = -1; - - -// IconItem相关数据 -class IconItemSource { - image: string | Resource = '' - text: string | Resource = '' - - constructor(image: string | Resource = '', text: string | Resource = '') { - this.image = image; - this.text = text; - } -} - -@Component -export struct ProfitScene { - // renderGroup接口是否开启 - @State renderGroupFlag: boolean = false; - private iconItemSourceList: IconItemSource[] = []; - - aboutToAppear() { - // 遍历添加60个IconItem的数据 - for (let index = 0; index < 20; index++) { - const numStart: number = index * 3; - // 此处循环使用三张图片资源 - this.iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 1}`)); - this.iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 2}`)); - this.iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 3}`)); - } - } - - build() { - Column() { - // 顶部导航栏 - Row() { - Row() { - Image($r("app.media.back")) - .id('returnBtn') - .height($r('app.integer.RenderGroup_scene_back_image_size')) - .width($r('app.integer.RenderGroup_scene_back_image_size')) - .onClick(() => { - router.back(); - }) - - Text($r('app.string.RenderGroup_profit_scene_title')) - .fontSize($r('app.integer.RenderGroup_scene_title_font')) - .lineHeight($r('app.integer.RenderGroup_scene_title_lineHeight')) - .fontColor(Color.Black) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Start) - .margin({ - left: $r('app.integer.RenderGroup_scene_title_margin_left') - }) - } - .margin({ - left: $r('app.integer.RenderGroup_scene_row_margin_left') - }) - - Stack({ alignContent: Alignment.End }) { - Button(this.renderGroupFlag ? $r('app.string.RenderGroup_button_on') : $r('app.string.RenderGroup_button_off'), { - type: ButtonType.Normal, - stateEffect: true - }) - .id("renderGroupSwitch") - .fontSize($r('app.integer.RenderGroup_scene_button_fontSize')) - .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) - .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) - .width($r('app.integer.RenderGroup_scene_title_button_width')) - .height($r('app.integer.RenderGroup_scene_title_button_height')) - .margin({ - right: $r('app.integer.RenderGroup_scene_button_margin_right') - }) - .onClick(() => { - this.renderGroupFlag = !this.renderGroupFlag; - }) - } - } - .height($r('app.integer.RenderGroup_scene_title_row_height')) - .width($r('app.string.layout_100_percent')) - .backgroundColor(Color.White) - .justifyContent(FlexAlign.SpaceBetween) - - // IconItem放置在grid内 - GridRow({ - columns: COLUMNS, - gutter: { x: GUTTER_X, y: GUTTER_Y }, - breakpoints: { value: ["400vp", "600vp", "800vp"], reference: BreakpointsReference.WindowSize }, - direction: GridRowDirection.Row - }) { - ForEach(this.iconItemSourceList, (item: IconItemSource) => { - GridCol() { - IconItem({ image: item.image, text: item.text, renderGroupFlag: this.renderGroupFlag }) - .transition(TransitionEffect.scale({ x: SCALE_X, y: SCALE_Y }) - .animation({ duration: DURATION, curve: Curve.FastOutSlowIn, iterations: ITERATIONS }) - .combine(TransitionEffect.rotate({ z: ROTATE_Z, angle: ROTATE_ANGLE }) - .animation({ duration: DURATION, curve: Curve.Linear, iterations: ITERATIONS }))) - } - .height($r('app.integer.RenderGroup_scene_GridCol_height')) - .width($r('app.string.layout_17_percent')) - }) - } - .width($r('app.string.layout_100_percent')) - .height($r('app.string.layout_100_percent')) - } - .width($r('app.string.layout_100_percent')) - .height($r('app.string.layout_100_percent')) - .alignItems(HorizontalAlign.Center) - } +/* + * Copyright (c) 2023 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 { IconItem } from '../view/IconView'; +import router from '@ohos.router' + +// GridRow列数 +const COLUMNS: number = 6; +// GridRow横向间隙 +const GUTTER_X: number = 0; +// GridRow纵向间隙 +const GUTTER_Y: number = 0; +// X轴方向缩放比例 +const SCALE_X: number = 0.5; +// Y轴方向缩放比例 +const SCALE_Y: number = 0.5; +// 绕z轴旋转 +const ROTATE_Z: number = 1; +// 旋转角度 +const ROTATE_ANGLE: number = 360; +// 动画时长 +const DURATION: number = 3000; +// 重复次数 +const ITERATIONS: number = -1; + + +// IconItem相关数据 +class IconItemSource { + image: string | Resource = '' + text: string | Resource = '' + + constructor(image: string | Resource = '', text: string | Resource = '') { + this.image = image; + this.text = text; + } +} + +@Component +export struct ProfitScene { + // renderGroup接口是否开启 + @State renderGroupFlag: boolean = false; + private iconItemSourceList: IconItemSource[] = []; + + aboutToAppear() { + // 遍历添加60个IconItem的数据 + for (let index = 0; index < 20; index++) { + const numStart: number = index * 3; + // 此处循环使用三张图片资源 + this.iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 1}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 2}`)); + this.iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 3}`)); + } + } + + build() { + Column() { + // 顶部导航栏 + Row() { + Row() { + Image($r("app.media.back")) + .id('returnBtn') + .height($r('app.integer.RenderGroup_scene_back_image_size')) + .width($r('app.integer.RenderGroup_scene_back_image_size')) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.RenderGroup_profit_scene_title')) + .fontSize($r('app.integer.RenderGroup_scene_title_font')) + .lineHeight($r('app.integer.RenderGroup_scene_title_lineHeight')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Start) + .margin({ + left: $r('app.integer.RenderGroup_scene_title_margin_left') + }) + } + .margin({ + left: $r('app.integer.RenderGroup_scene_row_margin_left') + }) + + Stack({ alignContent: Alignment.End }) { + Button(this.renderGroupFlag ? $r('app.string.RenderGroup_button_on') : $r('app.string.RenderGroup_button_off'), { + type: ButtonType.Normal, + stateEffect: true + }) + .id("renderGroupSwitch") + .fontSize($r('app.integer.RenderGroup_scene_button_fontSize')) + .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) + .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) + .width($r('app.integer.RenderGroup_scene_title_button_width')) + .height($r('app.integer.RenderGroup_scene_title_button_height')) + .margin({ + right: $r('app.integer.RenderGroup_scene_button_margin_right') + }) + .onClick(() => { + this.renderGroupFlag = !this.renderGroupFlag; + }) + } + } + .height($r('app.integer.RenderGroup_scene_title_row_height')) + .width($r('app.string.layout_100_percent')) + .backgroundColor(Color.White) + .justifyContent(FlexAlign.SpaceBetween) + + // IconItem放置在grid内 + GridRow({ + columns: COLUMNS, + gutter: { x: GUTTER_X, y: GUTTER_Y }, + breakpoints: { value: ["400vp", "600vp", "800vp"], reference: BreakpointsReference.WindowSize }, + direction: GridRowDirection.Row + }) { + ForEach(this.iconItemSourceList, (item: IconItemSource) => { + GridCol() { + IconItem({ image: item.image, text: item.text, renderGroupFlag: this.renderGroupFlag }) + .transition(TransitionEffect.scale({ x: SCALE_X, y: SCALE_Y }) + .animation({ duration: DURATION, curve: Curve.FastOutSlowIn, iterations: ITERATIONS }) + .combine(TransitionEffect.rotate({ z: ROTATE_Z, angle: ROTATE_ANGLE }) + .animation({ duration: DURATION, curve: Curve.Linear, iterations: ITERATIONS }))) + } + .height($r('app.integer.RenderGroup_scene_GridCol_height')) + .width($r('app.string.layout_17_percent')) + }) + } + .width($r('app.string.layout_100_percent')) + .height($r('app.string.layout_100_percent')) + } + .width($r('app.string.layout_100_percent')) + .height($r('app.string.layout_100_percent')) + .alignItems(HorizontalAlign.Center) + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/utils/Logger.ets b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/utils/Logger.ets index 169a17ae538e02319d717b839b612bac1859eb9a..3a51cfce32bc95a545e5233520e009db6e277f0a 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/utils/Logger.ets +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/utils/Logger.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - // 日志对应的领域标识 - private domain: number = 0xF811; - // tag日志标识 - private prefix: string = '[Samples_RenderGroup]'; - // 格式字符串,用于日志的格式化输出 - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + // 日志对应的领域标识 + private domain: number = 0xF811; + // tag日志标识 + private prefix: string = '[Samples_RenderGroup]'; + // 格式字符串,用于日志的格式化输出 + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Samples_RenderGroup]'); \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/IconView.ets b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/IconView.ets index 0cd6da69dede2c38c6d8a5651925aa78432b406e..4e204a0753d047615dcf6aa9e5683c73019fd6a2 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/IconView.ets +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/IconView.ets @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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. - */ - -// 字体透明度 -const TEXT_OPACITY: number = 0.8; - -@Component -export struct IconItem { - @Link renderGroupFlag: boolean; - image: string | Resource = ''; - text: string | Resource = ''; - - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) { - Image(this.image) - .height($r('app.integer.RenderGroup_item_image_height')) - .width($r('app.integer.RenderGroup_item_image_width')) - .objectFit(ImageFit.Contain) - .margin({ - left: $r('app.integer.RenderGroup_item_image_margin') - }) - - Text(this.text) - .fontSize($r('app.integer.RenderGroup_item_text_font')) - .fontColor($r('app.color.RenderGroup_item_text_fontColor')) - .margin({ - top: $r('app.integer.RenderGroup_item_text_margin_top') - }) - .width($r('app.integer.RenderGroup_item_text_width')) - .opacity(TEXT_OPACITY) - .textAlign(TextAlign.Center) - } - .backgroundColor($r('app.color.RenderGroup_item_backgroundColor')) - .width($r('app.integer.RenderGroup_item_width')) - .height($r('app.integer.RenderGroup_item_height')) - .borderRadius($r('app.integer.RenderGroup_item_borderRadius')) - // 在IconItem内调用renderGroup,true为开启,false为关闭 - .renderGroup(this.renderGroupFlag) - } +/* + * Copyright (c) 2023 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. + */ + +// 字体透明度 +const TEXT_OPACITY: number = 0.8; + +@Component +export struct IconItem { + @Link renderGroupFlag: boolean; + image: string | Resource = ''; + text: string | Resource = ''; + + build() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) { + Image(this.image) + .height($r('app.integer.RenderGroup_item_image_height')) + .width($r('app.integer.RenderGroup_item_image_width')) + .objectFit(ImageFit.Contain) + .margin({ + left: $r('app.integer.RenderGroup_item_image_margin') + }) + + Text(this.text) + .fontSize($r('app.integer.RenderGroup_item_text_font')) + .fontColor($r('app.color.RenderGroup_item_text_fontColor')) + .margin({ + top: $r('app.integer.RenderGroup_item_text_margin_top') + }) + .width($r('app.integer.RenderGroup_item_text_width')) + .opacity(TEXT_OPACITY) + .textAlign(TextAlign.Center) + } + .backgroundColor($r('app.color.RenderGroup_item_backgroundColor')) + .width($r('app.integer.RenderGroup_item_width')) + .height($r('app.integer.RenderGroup_item_height')) + .borderRadius($r('app.integer.RenderGroup_item_borderRadius')) + // 在IconItem内调用renderGroup,true为开启,false为关闭 + .renderGroup(this.renderGroupFlag) + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/NonIconView.ets b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/NonIconView.ets index 56253953847786d83e9d056d7691666a838407f4..ef4bdd782e520a0cc2b49c524f370809124fe695 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/NonIconView.ets +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/ets/view/NonIconView.ets @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2023 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. - */ - -// 绕z轴旋转 -const ROTATE_Z: number = 1; -// 旋转角度 -const ROTATE_ANGLE: number = 360; -// 旋转时长 -const ROTATE_DURATION: number = 3000; -// 重复次数 -const ROTATE_ITERATIONS: number = -1; -// 字体透明度 -const TEXT_OPACITY: number = 0.8; - -@Component -export struct NonIconItem { - @Link renderGroupFlag: boolean; - image: string | Resource = ''; - text: string | Resource = ''; - - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) { - Image(this.image) - .height($r('app.integer.RenderGroup_item_image_height')) - .width($r('app.integer.RenderGroup_item_image_width')) - .objectFit(ImageFit.Contain) - .margin({ - left: $r('app.integer.RenderGroup_item_image_margin') - }) - .transition(TransitionEffect.rotate({ z: ROTATE_Z, angle: ROTATE_ANGLE }) - .animation({ duration: ROTATE_DURATION, curve: Curve.Linear, iterations: ROTATE_ITERATIONS })) - - Text(this.text) - .fontSize($r('app.integer.RenderGroup_item_text_font')) - .fontColor($r('app.color.RenderGroup_item_text_fontColor')) - .margin({ - top: $r('app.integer.RenderGroup_item_text_margin_top') - }) - .width($r('app.integer.RenderGroup_item_text_width')) - .opacity(TEXT_OPACITY) - .textAlign(TextAlign.Center) - } - .backgroundColor($r('app.color.RenderGroup_item_backgroundColor')) - .width($r('app.integer.RenderGroup_item_width')) - .height($r('app.integer.RenderGroup_item_height')) - .borderRadius($r('app.integer.RenderGroup_item_borderRadius')) - // 在IconItem内调用renderGroup,true为开启,false为关闭 - .renderGroup(this.renderGroupFlag) - } +/* + * Copyright (c) 2023 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. + */ + +// 绕z轴旋转 +const ROTATE_Z: number = 1; +// 旋转角度 +const ROTATE_ANGLE: number = 360; +// 旋转时长 +const ROTATE_DURATION: number = 3000; +// 重复次数 +const ROTATE_ITERATIONS: number = -1; +// 字体透明度 +const TEXT_OPACITY: number = 0.8; + +@Component +export struct NonIconItem { + @Link renderGroupFlag: boolean; + image: string | Resource = ''; + text: string | Resource = ''; + + build() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) { + Image(this.image) + .height($r('app.integer.RenderGroup_item_image_height')) + .width($r('app.integer.RenderGroup_item_image_width')) + .objectFit(ImageFit.Contain) + .margin({ + left: $r('app.integer.RenderGroup_item_image_margin') + }) + .transition(TransitionEffect.rotate({ z: ROTATE_Z, angle: ROTATE_ANGLE }) + .animation({ duration: ROTATE_DURATION, curve: Curve.Linear, iterations: ROTATE_ITERATIONS })) + + Text(this.text) + .fontSize($r('app.integer.RenderGroup_item_text_font')) + .fontColor($r('app.color.RenderGroup_item_text_fontColor')) + .margin({ + top: $r('app.integer.RenderGroup_item_text_margin_top') + }) + .width($r('app.integer.RenderGroup_item_text_width')) + .opacity(TEXT_OPACITY) + .textAlign(TextAlign.Center) + } + .backgroundColor($r('app.color.RenderGroup_item_backgroundColor')) + .width($r('app.integer.RenderGroup_item_width')) + .height($r('app.integer.RenderGroup_item_height')) + .borderRadius($r('app.integer.RenderGroup_item_borderRadius')) + // 在IconItem内调用renderGroup,true为开启,false为关闭 + .renderGroup(this.renderGroupFlag) + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/module.json5 b/code/Performance/renderGroup/feature/renderGroup/src/main/module.json5 index d60f69c3378f5e6949ab3fe6e0da4e35bba78203..4171e20ff984801771d0bf1c0746e7a4ef7f4f8a 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/module.json5 +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/module.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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": "renderGroup", - "type": "har", - "deviceTypes": [ - "default", - "tablet" - ] - } -} +/* + * Copyright (c) 2023 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": "renderGroup", + "type": "har", + "deviceTypes": [ + "default", + "tablet" + ] + } +} diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/color.json b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/color.json index b2859ea57a660e26137585ca3b46d036358b1e33..a3bace6407871d4bbcec9e84c5f82a8ea6143f60 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/color.json +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "RenderGroup_item_text_fontColor", - "value": "#182431" - }, - { - "name": "RenderGroup_item_backgroundColor", - "value": "#e3e3e3" - }, - { - "name": "RenderGroup_scene_button_backgroundColor", - "value": "#317aff" - } - ] +{ + "color": [ + { + "name": "RenderGroup_item_text_fontColor", + "value": "#182431" + }, + { + "name": "RenderGroup_item_backgroundColor", + "value": "#e3e3e3" + }, + { + "name": "RenderGroup_scene_button_backgroundColor", + "value": "#317aff" + } + ] } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/integer.json b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/integer.json index 6d5f212dceb9d241ebc664f530c9b5f6e6b8729f..67dbd84053053d5d0f0c17ff0b027a29f75bbf67 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/integer.json +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/element/integer.json @@ -1,88 +1,88 @@ -{ - "integer": [ - { - "name": "RenderGroup_item_image_height", - "value": 20 - }, - { - "name": "RenderGroup_item_image_width", - "value": 20 - }, - { - "name": "RenderGroup_item_image_margin", - "value": 15 - }, - { - "name": "RenderGroup_item_text_font", - "value": 10 - }, - { - "name": "RenderGroup_item_text_margin_top", - "value": 5 - }, - { - "name": "RenderGroup_item_text_width", - "value": 50 - }, - { - "name": "RenderGroup_item_width", - "value": 50 - }, - { - "name": "RenderGroup_item_height", - "value": 50 - }, - { - "name": "RenderGroup_item_borderRadius", - "value": 25 - }, - { - "name": "RenderGroup_scene_back_image_size", - "value": 24 - }, - { - "name": "RenderGroup_scene_title_font", - "value": 24 - }, - { - "name": "RenderGroup_scene_title_lineHeight", - "value": 30 - }, - { - "name": "RenderGroup_scene_title_margin_left", - "value": 16 - }, - { - "name": "RenderGroup_scene_row_margin_left", - "value": 24 - }, - { - "name": "RenderGroup_scene_button_fontSize", - "value": 13 - }, - { - "name": "RenderGroup_scene_button_borderRadius", - "value": 8 - }, - { - "name": "RenderGroup_scene_title_button_width", - "value": 160 - }, - { - "name": "RenderGroup_scene_title_button_height", - "value": 30 - }, - { - "name": "RenderGroup_scene_button_margin_right", - "value": 24 - }, - { - "name": "RenderGroup_scene_title_row_height", - "value": 56 - }, - { - "name": "RenderGroup_scene_GridCol_height", - "value": 70 - } - ] +{ + "integer": [ + { + "name": "RenderGroup_item_image_height", + "value": 20 + }, + { + "name": "RenderGroup_item_image_width", + "value": 20 + }, + { + "name": "RenderGroup_item_image_margin", + "value": 15 + }, + { + "name": "RenderGroup_item_text_font", + "value": 10 + }, + { + "name": "RenderGroup_item_text_margin_top", + "value": 5 + }, + { + "name": "RenderGroup_item_text_width", + "value": 50 + }, + { + "name": "RenderGroup_item_width", + "value": 50 + }, + { + "name": "RenderGroup_item_height", + "value": 50 + }, + { + "name": "RenderGroup_item_borderRadius", + "value": 25 + }, + { + "name": "RenderGroup_scene_back_image_size", + "value": 24 + }, + { + "name": "RenderGroup_scene_title_font", + "value": 24 + }, + { + "name": "RenderGroup_scene_title_lineHeight", + "value": 30 + }, + { + "name": "RenderGroup_scene_title_margin_left", + "value": 16 + }, + { + "name": "RenderGroup_scene_row_margin_left", + "value": 24 + }, + { + "name": "RenderGroup_scene_button_fontSize", + "value": 13 + }, + { + "name": "RenderGroup_scene_button_borderRadius", + "value": 8 + }, + { + "name": "RenderGroup_scene_title_button_width", + "value": 160 + }, + { + "name": "RenderGroup_scene_title_button_height", + "value": 30 + }, + { + "name": "RenderGroup_scene_button_margin_right", + "value": 24 + }, + { + "name": "RenderGroup_scene_title_row_height", + "value": 56 + }, + { + "name": "RenderGroup_scene_GridCol_height", + "value": 70 + } + ] } \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/album.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/album.svg index c891dd3e23722756f3045ef0c6559cb57f9678c1..7b14dc626367f61d422793bc55735c47ef358fc3 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/album.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/album.svg @@ -1,30 +1,30 @@ - - - ic_album - - - - - - - - - - - - - - - - - - - - - - - - - - + + + ic_album + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/applet.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/applet.svg index 81842a97864605384ffb3309cd5ee004cfaff5a2..ebe013f917650222b5a5688f1c572f72f1f39fe1 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/applet.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/applet.svg @@ -1,16 +1,16 @@ - - - ic_applet - - - - - - - - - - - - + + + ic_applet + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/back.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/back.svg index e84df74e269086052f3eba12d7ecefc93e5de0a6..57acebd1220b7c06e7014d00499771bd412b68ab 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/back.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/back.svg @@ -1,23 +1,23 @@ - - - public/ic_back - - - - - - - - - - - - - - - - - - - + + + public/ic_back + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/cards.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/cards.svg index 15541705038cf0bf12ed86e9b64a9f81ce8a4145..aeb80463ad9b5bd5f6fbb4f57c4a5a13bd5fcb56 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/cards.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/cards.svg @@ -1,28 +1,28 @@ - - - ic_cards - - - - - - - - - - - - - - - - - - - - - - - - + + + ic_cards + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/nearby.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/nearby.svg index 8031837dde6dbc04bfabb24d592ca7e5c6868975..56852c4b5123551656bcd4ba97416bff8aad5b7a 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/nearby.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/nearby.svg @@ -1,31 +1,31 @@ - - - ic_near - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + ic_near + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/scan.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/scan.svg index 1dd38531fc7a215842b71b04823d04235e74b46a..dae3d51e2cce6c4c7ca4b3cef730e10317226748 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/scan.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/scan.svg @@ -1,29 +1,29 @@ - - - ic_scan - - - - - - - - - - - - - - - - - - - - - - - - - + + + ic_scan + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/shop.svg b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/shop.svg index ee8e19061e077f1258d5bf6d1737b3cc6f0e859f..672daaa49e3727f04efd512ec33edc2a2919e1ed 100644 --- a/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/shop.svg +++ b/code/Performance/renderGroup/feature/renderGroup/src/main/resources/base/media/shop.svg @@ -1,31 +1,31 @@ - - - ic_shop - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + ic_shop + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Performance/renderGroup/hvigor/hvigor-config.json5 b/code/Performance/renderGroup/hvigor/hvigor-config.json5 index 213d992653403a9be1fa24d0e27327214befd7cb..a7edd62de456a09645989d596aa94da499ab1e96 100644 --- a/code/Performance/renderGroup/hvigor/hvigor-config.json5 +++ b/code/Performance/renderGroup/hvigor/hvigor-config.json5 @@ -1,18 +1,18 @@ -{ - "hvigorVersion": "3.0.9", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.9" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +{ + "hvigorVersion": "3.0.9", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.9" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/oh-package.json5 b/code/Performance/renderGroup/oh-package.json5 index 45f119bb6bde1473e7b18bc51424ecf50cd95052..a7ab602e43bda681db1392c25f637bad9f08354e 100644 --- a/code/Performance/renderGroup/oh-package.json5 +++ b/code/Performance/renderGroup/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "performance", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "performance", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/Performance/renderGroup/product/phone/entry/build-profile.json5 b/code/Performance/renderGroup/product/phone/entry/build-profile.json5 index d3845997002b81690e5d7bfdacc654bbadabd890..3360e1a75480a94cb89ec209ffb6240be1e50465 100644 --- a/code/Performance/renderGroup/product/phone/entry/build-profile.json5 +++ b/code/Performance/renderGroup/product/phone/entry/build-profile.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/oh-package.json5 b/code/Performance/renderGroup/product/phone/entry/oh-package.json5 index e289f8ab59b5db7f4db2a71c92c5b28bfafd9239..999f7eb3a55a48013884c6f4bedbc40f9c5040ed 100644 --- a/code/Performance/renderGroup/product/phone/entry/oh-package.json5 +++ b/code/Performance/renderGroup/product/phone/entry/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "@ohos/rendergroup": "file:../../../feature/renderGroup" - } -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "@ohos/rendergroup": "file:../../../feature/renderGroup" + } +} diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/entryability/EntryAbility.ts b/code/Performance/renderGroup/product/phone/entry/src/main/ets/entryability/EntryAbility.ts index 1f498190c39687eca3002961cf5b482855d32373..078a52eb8bb31b173c165c608ea399eaa4455d72 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/DataType.ets b/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/DataType.ets index e7985a4b361b85c97e3694be0ec827c1bd476d54..ea76bfdcffddf0014ac43a65062741e1c87e042e 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/DataType.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/DataType.ets @@ -1,19 +1,19 @@ -/* - * Copyright (c) 2023 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 interface PerformanceMsg { - name: string - uri: string -} +/* + * Copyright (c) 2023 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 interface PerformanceMsg { + name: string + uri: string +} diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/MockData.ets b/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/MockData.ets index b015cb872a893e426036b8acb398f92ac1c407fd..a0773f96dce18c8657a1db52e38ccdc714e78a2e 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/MockData.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/model/MockData.ets @@ -1,23 +1,23 @@ -/* - * Copyright (c) 2023 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 { PerformanceMsg } from './DataType'; - -export let performanceTypeArray: Array = [ - { - name: 'RenderGroup', - uri: 'pages/renderGroup/RenderGroupHomePage' - } +/* + * Copyright (c) 2023 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 { PerformanceMsg } from './DataType'; + +export let performanceTypeArray: Array = [ + { + name: 'RenderGroup', + uri: 'pages/renderGroup/RenderGroupHomePage' + } ] \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/NonProfitScenePage.ets b/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/NonProfitScenePage.ets index 89725222947f2fcba47dbdaaf0c74fadc99aef96..5f21f2770d3f4fdc958ad91c753057f4ae7c24d3 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/NonProfitScenePage.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/NonProfitScenePage.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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 { NonProfitScene } from '@ohos/rendergroup'; - -@Entry -@Component -struct NonProfitScenePage { - build() { - Column() { - NonProfitScene() - } - } +/* + * Copyright (c) 2023 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 { NonProfitScene } from '@ohos/rendergroup'; + +@Entry +@Component +struct NonProfitScenePage { + build() { + Column() { + NonProfitScene() + } + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/ProfitScenePage.ets b/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/ProfitScenePage.ets index 9f9f0850f170896c4a2cb494a4523f90e4532b0b..4c48c5d2df18a4c64d2e775c70ce04feafd9c1a6 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/ProfitScenePage.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/ProfitScenePage.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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 { ProfitScene } from '@ohos/rendergroup'; - -@Entry -@Component -struct ProfitScenePage { - build() { - Column() { - ProfitScene() - } - } +/* + * Copyright (c) 2023 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 { ProfitScene } from '@ohos/rendergroup'; + +@Entry +@Component +struct ProfitScenePage { + build() { + Column() { + ProfitScene() + } + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/RenderGroupHomePage.ets b/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/RenderGroupHomePage.ets index cc4e8883e56512274e7e6ce266b1ad6f1a8f4722..6860c60a6f6c30d35ed5def09ed87b3a17e134d5 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/RenderGroupHomePage.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/pages/renderGroup/RenderGroupHomePage.ets @@ -1,84 +1,84 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router' - -@Entry -@Component -struct Index { - build() { - Column() { - Row() { - Row(){ - Image($r("app.media.back")) - .id('returnBtn') - .height($r('app.integer.RenderGroup_scene_back_image_size')) - .width($r('app.integer.RenderGroup_scene_back_image_size')) - .onClick(() => { - router.back(); - }) - - Text($r('app.string.RenderGroupHomePage_title')) - .fontSize($r('app.integer.RenderGroupHomePage_title_font')) - .lineHeight($r('app.integer.RenderGroupHomePage_title_lineHeight')) - .fontColor(Color.Black) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Center) - .width($r('app.string.layout_100_percent')) - .height($r('app.integer.RenderGroupHomePage_title_height')) - } - .height($r('app.integer.RenderGroupHomePage_row_height')) - .backgroundColor(Color.White) - } - .margin({ - left: $r('app.integer.RenderGroup_scene_row_margin_left') - }) - - Button($r('app.string.RenderGroup_profit_scene_button_title'), { type: ButtonType.Normal, stateEffect: true }) - .id('ProfitScenePage') - .fontSize($r('app.integer.RenderGroup_scene_button_font')) - .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) - .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) - .width($r('app.integer.RenderGroup_scene_button_width')) - .height($r('app.integer.RenderGroup_scene_button_height')) - .margin({ - top: $r('app.integer.RenderGroup_scene_button_margin_top') - }) - .onClick(() => { - router.pushUrl({ - url: 'pages/renderGroup/ProfitScenePage' - }) - }) - - Button($r('app.string.RenderGroup_nonProfit_scene_button_title'), { type: ButtonType.Normal, stateEffect: true }) - .id('NonProfitScenePage') - .fontSize($r('app.integer.RenderGroup_scene_button_font')) - .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) - .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) - .width($r('app.integer.RenderGroup_scene_button_width')) - .height($r('app.integer.RenderGroup_scene_button_height')) - .margin({ - top: $r('app.integer.RenderGroup_scene_button_margin_top') - }) - .onClick(() => { - router.pushUrl({ - url: 'pages/renderGroup/NonProfitScenePage' - }) - }) - } - .height($r('app.integer.RenderGroup_scene_row_height')) - .width($r('app.string.layout_100_percent')) - } +/* + * Copyright (c) 2023 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 router from '@ohos.router' + +@Entry +@Component +struct Index { + build() { + Column() { + Row() { + Row(){ + Image($r("app.media.back")) + .id('returnBtn') + .height($r('app.integer.RenderGroup_scene_back_image_size')) + .width($r('app.integer.RenderGroup_scene_back_image_size')) + .onClick(() => { + router.back(); + }) + + Text($r('app.string.RenderGroupHomePage_title')) + .fontSize($r('app.integer.RenderGroupHomePage_title_font')) + .lineHeight($r('app.integer.RenderGroupHomePage_title_lineHeight')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + .width($r('app.string.layout_100_percent')) + .height($r('app.integer.RenderGroupHomePage_title_height')) + } + .height($r('app.integer.RenderGroupHomePage_row_height')) + .backgroundColor(Color.White) + } + .margin({ + left: $r('app.integer.RenderGroup_scene_row_margin_left') + }) + + Button($r('app.string.RenderGroup_profit_scene_button_title'), { type: ButtonType.Normal, stateEffect: true }) + .id('ProfitScenePage') + .fontSize($r('app.integer.RenderGroup_scene_button_font')) + .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) + .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) + .width($r('app.integer.RenderGroup_scene_button_width')) + .height($r('app.integer.RenderGroup_scene_button_height')) + .margin({ + top: $r('app.integer.RenderGroup_scene_button_margin_top') + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/renderGroup/ProfitScenePage' + }) + }) + + Button($r('app.string.RenderGroup_nonProfit_scene_button_title'), { type: ButtonType.Normal, stateEffect: true }) + .id('NonProfitScenePage') + .fontSize($r('app.integer.RenderGroup_scene_button_font')) + .borderRadius($r('app.integer.RenderGroup_scene_button_borderRadius')) + .backgroundColor($r('app.color.RenderGroup_scene_button_backgroundColor')) + .width($r('app.integer.RenderGroup_scene_button_width')) + .height($r('app.integer.RenderGroup_scene_button_height')) + .margin({ + top: $r('app.integer.RenderGroup_scene_button_margin_top') + }) + .onClick(() => { + router.pushUrl({ + url: 'pages/renderGroup/NonProfitScenePage' + }) + }) + } + .height($r('app.integer.RenderGroup_scene_row_height')) + .width($r('app.string.layout_100_percent')) + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/ets/utils/Logger.ets b/code/Performance/renderGroup/product/phone/entry/src/main/ets/utils/Logger.ets index 989751202937d9a0caab8d59c6456ec04e491da5..87fdc629e4398ba9f8af8683fe14079ab931d8ec 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/ets/utils/Logger.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/main/ets/utils/Logger.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - // 日志对应的领域标识 - private domain: number = 0xF811; - // tag日志标识 - private prefix: string = '[Samples_Performance]'; - // 格式字符串,用于日志的格式化输出 - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + // 日志对应的领域标识 + private domain: number = 0xF811; + // tag日志标识 + private prefix: string = '[Samples_Performance]'; + // 格式字符串,用于日志的格式化输出 + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Samples_Performance]'); \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/module.json5 b/code/Performance/renderGroup/product/phone/entry/src/main/module.json5 index c32260d08bfb818fe7ade578f954dc391b2f0804..6f2734bc4f37c89617ecf39dff2829571bf384c5 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/module.json5 +++ b/code/Performance/renderGroup/product/phone/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/color.json b/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/color.json index 4d12768ffb1e05bcbadae094f61ab2965fcc328e..e53ed61eef81ec1b160c3c57f49a903ad2806af8 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/color.json +++ b/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "performance_message_item_backgroundColor", - "value": "#0091FF" - }, - { - "name": "RenderGroup_scene_button_backgroundColor", - "value": "#317aff" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "performance_message_item_backgroundColor", + "value": "#0091FF" + }, + { + "name": "RenderGroup_scene_button_backgroundColor", + "value": "#317aff" + } + ] } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/integer.json b/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/integer.json index d79963dad5ea7c225adf9318c79188a52e3777df..8d30f20c00708496aedd6783f2ecb2b22f5b9bd1 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/integer.json +++ b/code/Performance/renderGroup/product/phone/entry/src/main/resources/base/element/integer.json @@ -1,56 +1,56 @@ -{ - "integer": [ - { - "name": "performance_message_font", - "value": 20 - }, - { - "name": "performance_message_margin", - "value": 20 - }, - { - "name": "performance_message_padding", - "value": 16 - }, - { - "name": "RenderGroupHomePage_title_font", - "value": 24 - }, - { - "name": "RenderGroupHomePage_title_lineHeight", - "value": 30 - }, - { - "name": "RenderGroupHomePage_title_height", - "value": 30 - }, - { - "name": "RenderGroupHomePage_row_height", - "value": 56 - }, - { - "name": "RenderGroup_scene_button_font", - "value": 18 - }, - { - "name": "RenderGroup_scene_button_borderRadius", - "value": 8 - }, - { - "name": "RenderGroup_scene_button_width", - "value": 250 - }, - { - "name": "RenderGroup_scene_button_height", - "value": 60 - }, - { - "name": "RenderGroup_scene_button_margin_top", - "value": 30 - }, - { - "name": "RenderGroup_scene_row_height", - "value": 200 - } - ] +{ + "integer": [ + { + "name": "performance_message_font", + "value": 20 + }, + { + "name": "performance_message_margin", + "value": 20 + }, + { + "name": "performance_message_padding", + "value": 16 + }, + { + "name": "RenderGroupHomePage_title_font", + "value": 24 + }, + { + "name": "RenderGroupHomePage_title_lineHeight", + "value": 30 + }, + { + "name": "RenderGroupHomePage_title_height", + "value": 30 + }, + { + "name": "RenderGroupHomePage_row_height", + "value": 56 + }, + { + "name": "RenderGroup_scene_button_font", + "value": 18 + }, + { + "name": "RenderGroup_scene_button_borderRadius", + "value": 8 + }, + { + "name": "RenderGroup_scene_button_width", + "value": 250 + }, + { + "name": "RenderGroup_scene_button_height", + "value": 60 + }, + { + "name": "RenderGroup_scene_button_margin_top", + "value": 30 + }, + { + "name": "RenderGroup_scene_row_height", + "value": 200 + } + ] } \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/ohosTest/ets/util/Logger.ets b/code/Performance/renderGroup/product/phone/entry/src/ohosTest/ets/util/Logger.ets index f84e782775c539602dc20c9ffeec7898ef08e4d6..a173e472305b737e4eeffa44a850eb28bcac85ee 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/ohosTest/ets/util/Logger.ets +++ b/code/Performance/renderGroup/product/phone/entry/src/ohosTest/ets/util/Logger.ets @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License") - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number = 0xF811 - private prefix: string = '[Sample_Performance_Uitest]' - private format: string = '%{public}s, %{public}s' - - constructor(prefix: string) { - this.prefix = prefix - this.domain = 0xF811 - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args) - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args) - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args) - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args) - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number = 0xF811 + private prefix: string = '[Sample_Performance_Uitest]' + private format: string = '%{public}s, %{public}s' + + constructor(prefix: string) { + this.prefix = prefix + this.domain = 0xF811 + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args) + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args) + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args) + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args) + } +} + export default new Logger('[Samples_Performance]') \ No newline at end of file diff --git a/code/Performance/renderGroup/product/phone/entry/src/ohosTest/module.json5 b/code/Performance/renderGroup/product/phone/entry/src/ohosTest/module.json5 index 7e44e83cf9b7428c7a916f5782b9a6d85bf6d7da..e6a499c49efe53f1a5bab25638ce6b00f612a7d8 100644 --- a/code/Performance/renderGroup/product/phone/entry/src/ohosTest/module.json5 +++ b/code/Performance/renderGroup/product/phone/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/Pragram01/code01.zip b/code/Pragram01/code01.zip new file mode 100644 index 0000000000000000000000000000000000000000..cf468861cc19270fe77d70b14ac74b0315d07588 --- /dev/null +++ b/code/Pragram01/code01.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:580e7f19c34a681539197ebf7bb56cefd484447fa201fb6b91bec1b5e2360159 +size 513046508 diff --git a/code/Project/Test/uitest/entry/src/main/ets/pages/Web.ets b/code/Project/Test/uitest/entry/src/main/ets/pages/Web.ets index 6158df0f5c9c7eb9f8a64cc187939c2dab2fb986..ab2f4ec8ab2f20624472d3fd78efb676465e9e63 100644 --- a/code/Project/Test/uitest/entry/src/main/ets/pages/Web.ets +++ b/code/Project/Test/uitest/entry/src/main/ets/pages/Web.ets @@ -1,44 +1,44 @@ -/* -* Copyright (c) 2023-2024 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 web_webview from '@ohos.web.webview'; - -@Entry -@Component -struct Index { - controller: web_webview.WebviewController = new web_webview.WebviewController(); - // 将 WebviewController 存储到应用全局状态,TestAbility 中可获取并使用该对象 - @StorageLink('controller') storageLink: web_webview.WebviewController = this.controller; - - build() { - Row() { - Column() { - Web({ src: $rawfile('index.html'), controller: this.controller }) - .javaScriptAccess(true) - .onPageEnd(e => { - console.info(`webview onPageEnd`); - }) - .id('webComponent') - .width('80%') - .height('80%') - .align(Alignment.Center) - .borderColor(Color.Black) - .borderWidth(5) - } - .width('100%') - } - .height('100%') - } +/* +* Copyright (c) 2023-2024 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 web_webview from '@ohos.web.webview'; + +@Entry +@Component +struct Index { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + // 将 WebviewController 存储到应用全局状态,TestAbility 中可获取并使用该对象 + @StorageLink('controller') storageLink: web_webview.WebviewController = this.controller; + + build() { + Row() { + Column() { + Web({ src: $rawfile('index.html'), controller: this.controller }) + .javaScriptAccess(true) + .onPageEnd(e => { + console.info(`webview onPageEnd`); + }) + .id('webComponent') + .width('80%') + .height('80%') + .align(Alignment.Center) + .borderColor(Color.Black) + .borderWidth(5) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/Project/Test/uitest/entry/src/main/ets/webability/WebAbility.ts b/code/Project/Test/uitest/entry/src/main/ets/webability/WebAbility.ts index 4dda5742a48e43c9ea32be6de79f951219823f03..af1335dfbe173ff607dc870c76a52ace7593561a 100644 --- a/code/Project/Test/uitest/entry/src/main/ets/webability/WebAbility.ts +++ b/code/Project/Test/uitest/entry/src/main/ets/webability/WebAbility.ts @@ -1,62 +1,62 @@ -/* -* Copyright (c) 2023-2024 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import common from '@ohos.app.ability.common'; -import { BusinessError } from '@ohos.base'; - -export default class WebAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - AppStorage.SetOrCreate('EntryAbilityContext', this.context); - } - - 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/Web', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - AppStorage.SetOrCreate('windowStage', windowStage); - } - - 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'); - } -} +/* +* Copyright (c) 2023-2024 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import common from '@ohos.app.ability.common'; +import { BusinessError } from '@ohos.base'; + +export default class WebAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + AppStorage.SetOrCreate('EntryAbilityContext', this.context); + } + + 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/Web', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + AppStorage.SetOrCreate('windowStage', windowStage); + } + + 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/Project/Test/uitest/entry/src/main/resources/rawfile/index.html b/code/Project/Test/uitest/entry/src/main/resources/rawfile/index.html index b0f9c14471444b631bbd5446f2c67ea2ab9ba9ec..c5a69914cef34dd1ce5ffdb847aeb6a192d7b50a 100644 --- a/code/Project/Test/uitest/entry/src/main/resources/rawfile/index.html +++ b/code/Project/Test/uitest/entry/src/main/resources/rawfile/index.html @@ -1,36 +1,36 @@ - - - -

H5页面

- - - - + + + +

H5页面

+ + + + \ No newline at end of file diff --git a/code/Solutions/InputMethod/KikaInput/build-profile.json5 b/code/Solutions/InputMethod/KikaInput/build-profile.json5 deleted file mode 100644 index ef1a3fa1da1b02dead3c0e4d2a1198247e0a68af..0000000000000000000000000000000000000000 --- a/code/Solutions/InputMethod/KikaInput/build-profile.json5 +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "products": [ - { - "name": "default", - "signingConfig": "default", - "compileSdkVersion": 14, - "compatibleSdkVersion": 14, - "runtimeOS": "OpenHarmony" - } - ], - "signingConfigs": [] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/.gitignore b/code/Solutions/Social/GrapeSquare/.gitignore index 8514e821bac8db62bf0dfa9eca7f7eb5fa659116..fbabf771011fe78f9919db0b1195ab6cadffc2b0 100644 --- a/code/Solutions/Social/GrapeSquare/.gitignore +++ b/code/Solutions/Social/GrapeSquare/.gitignore @@ -1,11 +1,11 @@ -/node_modules -/oh_modules -/local.properties -/.idea -**/build -/.hvigor -.cxx -/.clangd -/.clang-format -/.clang-tidy +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy **/.test \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/AppScope/app.json5 b/code/Solutions/Social/GrapeSquare/AppScope/app.json5 index 30a561cf7e7fc79670b1038a016e6a7bccd3fb85..f93374f4650b2dc1825eb49d2f933acbb42429e1 100644 --- a/code/Solutions/Social/GrapeSquare/AppScope/app.json5 +++ b/code/Solutions/Social/GrapeSquare/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.grapesquare", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.grapesquare", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/Solutions/Social/GrapeSquare/AppScope/resources/base/element/string.json b/code/Solutions/Social/GrapeSquare/AppScope/resources/base/element/string.json index cee7e9d78d7a1d784129462ea0ed7bc91340e0a8..80a5232ed9673427f1902fc3dfb10b841fbe6831 100644 --- a/code/Solutions/Social/GrapeSquare/AppScope/resources/base/element/string.json +++ b/code/Solutions/Social/GrapeSquare/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "葡萄广场" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "葡萄广场" + } + ] +} diff --git a/code/Solutions/Social/GrapeSquare/build-profile.json5 b/code/Solutions/Social/GrapeSquare/build-profile.json5 index bb0a0274248d034caedc74f82afdaab74d040175..d02ed820a45cf0429403951068f9cf3d52e5b435 100644 --- a/code/Solutions/Social/GrapeSquare/build-profile.json5 +++ b/code/Solutions/Social/GrapeSquare/build-profile.json5 @@ -1,55 +1,55 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./product/phone/entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "authorizedControl", - "srcPath": "./feature/authorizedControl" - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./product/phone/entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "authorizedControl", + "srcPath": "./feature/authorizedControl" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/hvigor/hvigor-config.json5 b/code/Solutions/Social/GrapeSquare/hvigor/hvigor-config.json5 index 213d992653403a9be1fa24d0e27327214befd7cb..a7edd62de456a09645989d596aa94da499ab1e96 100644 --- a/code/Solutions/Social/GrapeSquare/hvigor/hvigor-config.json5 +++ b/code/Solutions/Social/GrapeSquare/hvigor/hvigor-config.json5 @@ -1,18 +1,18 @@ -{ - "hvigorVersion": "3.0.9", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.9" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +{ + "hvigorVersion": "3.0.9", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.9" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/hvigorfile.ts b/code/Solutions/Social/GrapeSquare/hvigorfile.ts index 160030fb5b18c871456bd0e979ff4f21f465a65b..2a4a8343e9944f8f8148d7c1be20d593f26e9ff3 100644 --- a/code/Solutions/Social/GrapeSquare/hvigorfile.ts +++ b/code/Solutions/Social/GrapeSquare/hvigorfile.ts @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. */ -} +/* + * Copyright (c) 2023 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/Solutions/Social/GrapeSquare/hvigorw.bat b/code/Solutions/Social/GrapeSquare/hvigorw.bat index b11662229904d8932c75ac963554ccf3ee0b8859..93a1e34ae80b1e02e79f1724a1655d04e2482262 100644 --- a/code/Solutions/Social/GrapeSquare/hvigorw.bat +++ b/code/Solutions/Social/GrapeSquare/hvigorw.bat @@ -1,79 +1,79 @@ -:: Copyright (c) 2023 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. - -@echo off - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Hvigor startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js -set NODE_EXE=node.exe - -goto start - -:start -@rem Find node.exe -if defined NODE_HOME goto findNodeFromNodeHome - -%NODE_EXE% --version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:findNodeFromNodeHome -set NODE_HOME=%NODE_HOME:"=% -set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% - -if exist "%NODE_EXE_PATH%" goto execute -echo. -echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. -echo. -echo Please set the NODE_HOME variable in your environment to match the -echo location of your NodeJs installation. - -goto fail - -:execute -@rem Execute hvigor -"%NODE_EXE%" "%WRAPPER_MODULE_PATH%" %* - -if "%ERRORLEVEL%" == "0" goto hvigorwEnd - -:fail -exit /b 1 - -:hvigorwEnd -if "%OS%" == "Windows_NT" endlocal - -:end +:: Copyright (c) 2023 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. + +@echo off + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Hvigor startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js +set NODE_EXE=node.exe + +goto start + +:start +@rem Find node.exe +if defined NODE_HOME goto findNodeFromNodeHome + +%NODE_EXE% --version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. +echo. +echo Please set the NODE_HOME variable in your environment to match the +echo location of your NodeJs installation. + +goto fail + +:findNodeFromNodeHome +set NODE_HOME=%NODE_HOME:"=% +set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% + +if exist "%NODE_EXE_PATH%" goto execute +echo. +echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. +echo. +echo Please set the NODE_HOME variable in your environment to match the +echo location of your NodeJs installation. + +goto fail + +:execute +@rem Execute hvigor +"%NODE_EXE%" "%WRAPPER_MODULE_PATH%" %* + +if "%ERRORLEVEL%" == "0" goto hvigorwEnd + +:fail +exit /b 1 + +:hvigorwEnd +if "%OS%" == "Windows_NT" endlocal + +:end diff --git a/code/Solutions/Social/GrapeSquare/oh-package.json5 b/code/Solutions/Social/GrapeSquare/oh-package.json5 index 25ff7452b8aa1d76cbbd15435cb67784fc0b774e..9a3d1890b0ad07025251fb445123afff3d120b2e 100644 --- a/code/Solutions/Social/GrapeSquare/oh-package.json5 +++ b/code/Solutions/Social/GrapeSquare/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "authorizedcontrol", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "authorizedcontrol", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/.gitignore b/code/Solutions/Social/GrapeSquare/product/phone/entry/.gitignore index 32abf8fd5e44623ebe60bf2adeee4a366372cc85..e2713a2779c5a3e0eb879efe6115455592caeea5 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/.gitignore +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/.gitignore @@ -1,6 +1,6 @@ -/node_modules -/oh_modules -/.preview -/build -/.cxx +/node_modules +/oh_modules +/.preview +/build +/.cxx /.test \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/build-profile.json5 b/code/Solutions/Social/GrapeSquare/product/phone/entry/build-profile.json5 index d3845997002b81690e5d7bfdacc654bbadabd890..3360e1a75480a94cb89ec209ffb6240be1e50465 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/build-profile.json5 +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/build-profile.json5 @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/hvigorfile.ts b/code/Solutions/Social/GrapeSquare/product/phone/entry/hvigorfile.ts index eed1897d60a86ef437e11be4b2836082bb8fcca8..b25e77c7c848c86f7b3904a0a772cc1b6adb53a2 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/hvigorfile.ts +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/hvigorfile.ts @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. */ -} +/* + * Copyright (c) 2023 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/Solutions/Social/GrapeSquare/product/phone/entry/oh-package.json5 b/code/Solutions/Social/GrapeSquare/product/phone/entry/oh-package.json5 index 49efa14bac12390cc7f6dfd625939f67a1b9dcd9..9b72814cb25522c768f22eb8515103065e403cfe 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/oh-package.json5 +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/oh-package.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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. - */ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": { - "@ohos/authorizedcontrol": "file:../../../feature/authorizedControl" - } -} +/* + * Copyright (c) 2023 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. + */ +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": { + "@ohos/authorizedcontrol": "file:../../../feature/authorizedControl" + } +} diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/entryability/EntryAbility.ts b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/entryability/EntryAbility.ts index 3206000243c69d6b6a9f82ad1ada6d5ae78529dd..4b036407fc32b379eac8195b38cd8e7033f10a25 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,108 +1,108 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import display from '@ohos.display'; -import Logger from '../utils/Logger'; - -const TAG = ' EntryAbility'; -const DPI: number = 160; -const SMALL_SCREEN_WIDTH: number = 480; -const MIDDLE_SCREEN_WIDTH: number = 520; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - Logger.info('Ability onCreate'); - } - - onDestroy() { - Logger.info('Ability onDestroy'); - } - - updateBreakpoint(windowWidth: number): void { - let windowWidthVp: number = windowWidth / (display.getDefaultDisplaySync().densityDPI / DPI); - let currentBreakpoint: string; - Logger.info(`breakpoint windowWidthVp:${windowWidthVp}`); - // 520以及840分别为小屏和中屏的最大宽度 - if (windowWidthVp < SMALL_SCREEN_WIDTH) { - currentBreakpoint = 'sm'; - } else if (windowWidthVp < MIDDLE_SCREEN_WIDTH) { - currentBreakpoint = 'md'; - } else { - currentBreakpoint = 'lg'; - } - Logger.info(TAG, `breakpoint: ${currentBreakpoint}`); - AppStorage.setOrCreate('currentBreakpoint', currentBreakpoint); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info('Ability onWindowStageCreate'); - - windowStage.loadContent('pages/AdvertisingPage', (err, data) => { - if (err.code) { - Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); - return; - } - Logger.info(`Succeeded in loading the content. Data:JSON.stringify(data)`); - }); - windowStage.getMainWindow((err, windowClass) => { - if (err.code) { - Logger.error(`Failed to obtain the main window.Cause: ${JSON.stringify(err)}`); - return; - } - let windowWidth: number = windowClass.getWindowProperties().windowRect.width; - this.updateBreakpoint(windowWidth); - // 设置监听键盘变化,用来设置inputView避让输入法 - try { - windowClass.on('windowSizeChange', (currentWindowSize) => { - let currentWindowWidth: number = currentWindowSize.width; - this.updateBreakpoint(currentWindowWidth); - - if (windowClass.getWindowProperties().isFullScreen) { - Logger.info(TAG, 'isFullScreen'); - } - if (windowClass.getWindowProperties().isLayoutFullScreen) { - Logger.info(TAG, 'isLayoutFullScreen'); - } - }); - windowClass.on('keyboardHeightChange', (data) => { - Logger.info(`keyboardHeightChange.Data: ${JSON.stringify(data)}`); - AppStorage.setOrCreate('keyboardHeight', data); - }) - } catch (exception) { - Logger.error(`Failed to enable the listener for keyboard height changes.Cause: ${JSON.stringify(exception)}`); - } - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info('Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info('Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info('Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import display from '@ohos.display'; +import Logger from '../utils/Logger'; + +const TAG = ' EntryAbility'; +const DPI: number = 160; +const SMALL_SCREEN_WIDTH: number = 480; +const MIDDLE_SCREEN_WIDTH: number = 520; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + Logger.info('Ability onCreate'); + } + + onDestroy() { + Logger.info('Ability onDestroy'); + } + + updateBreakpoint(windowWidth: number): void { + let windowWidthVp: number = windowWidth / (display.getDefaultDisplaySync().densityDPI / DPI); + let currentBreakpoint: string; + Logger.info(`breakpoint windowWidthVp:${windowWidthVp}`); + // 520以及840分别为小屏和中屏的最大宽度 + if (windowWidthVp < SMALL_SCREEN_WIDTH) { + currentBreakpoint = 'sm'; + } else if (windowWidthVp < MIDDLE_SCREEN_WIDTH) { + currentBreakpoint = 'md'; + } else { + currentBreakpoint = 'lg'; + } + Logger.info(TAG, `breakpoint: ${currentBreakpoint}`); + AppStorage.setOrCreate('currentBreakpoint', currentBreakpoint); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info('Ability onWindowStageCreate'); + + windowStage.loadContent('pages/AdvertisingPage', (err, data) => { + if (err.code) { + Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + Logger.info(`Succeeded in loading the content. Data:JSON.stringify(data)`); + }); + windowStage.getMainWindow((err, windowClass) => { + if (err.code) { + Logger.error(`Failed to obtain the main window.Cause: ${JSON.stringify(err)}`); + return; + } + let windowWidth: number = windowClass.getWindowProperties().windowRect.width; + this.updateBreakpoint(windowWidth); + // 设置监听键盘变化,用来设置inputView避让输入法 + try { + windowClass.on('windowSizeChange', (currentWindowSize) => { + let currentWindowWidth: number = currentWindowSize.width; + this.updateBreakpoint(currentWindowWidth); + + if (windowClass.getWindowProperties().isFullScreen) { + Logger.info(TAG, 'isFullScreen'); + } + if (windowClass.getWindowProperties().isLayoutFullScreen) { + Logger.info(TAG, 'isLayoutFullScreen'); + } + }); + windowClass.on('keyboardHeightChange', (data) => { + Logger.info(`keyboardHeightChange.Data: ${JSON.stringify(data)}`); + AppStorage.setOrCreate('keyboardHeight', data); + }) + } catch (exception) { + Logger.error(`Failed to enable the listener for keyboard height changes.Cause: ${JSON.stringify(exception)}`); + } + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info('Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info('Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info('Ability onBackground'); + } +} diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/AdvertisingPage.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/AdvertisingPage.ets index ecb6093a203f5a6fd2d74838850e7d872c161fd2..f76a15d2390d5481873ab3f2e462975becd71ec7 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/AdvertisingPage.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/AdvertisingPage.ets @@ -1,72 +1,72 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; -import common from '@ohos.app.ability.common'; -import { getResourceString } from '../utils/ResourceUtils'; -import Constants from '../utils/Constants'; - -let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - -@Entry -@Component -struct AdvertisingPage { - // 初始化广告时间 - @State advertisingTime: number = 3; - // 定时器timer - @State timer: number = -1; - - aboutToAppear() { - this.timer = setInterval(() => { - this.advertisingTime--; - // 广告时间为0s时跳转到首页 - if (this.advertisingTime === 0) { - router.replaceUrl({ url: 'pages/HomePage' }); - clearInterval(this.timer); - } - }, Constants.SETINTERVAL_TIME) - } - - build() { - Stack() { - Image($r('app.media.advertisment')) - .width('100%') - .height('100%') - .objectFit(ImageFit.Contain) - Row() { - Text(`${getResourceString(context, $r('app.string.skip'))} ${this.advertisingTime}s`) - .id('skip') - .padding({ - left: $r('app.integer.layout_size_30'), - right: $r('app.integer.layout_size_30'), - top: $r('app.integer.layout_size_6'), - bottom: $r('app.integer.layout_size_6') - }) - .backgroundColor('rgba(0,0,0,0.20)') - .fontColor(Color.White) - .borderRadius($r('app.integer.layout_size_15')) - .onClick(() => { - clearInterval(this.timer); - router.replaceUrl({ url: 'pages/HomePage' }); - }) - }.width($r('app.string.layout_100')) - .justifyContent(FlexAlign.End) - .padding($r('app.integer.layout_size_10')) - } - .alignContent(Alignment.TopEnd) - .width($r('app.string.layout_100')) - .height($r('app.string.layout_100')) - } +/* + * Copyright (c) 2023 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 router from '@ohos.router'; +import common from '@ohos.app.ability.common'; +import { getResourceString } from '../utils/ResourceUtils'; +import Constants from '../utils/Constants'; + +let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + +@Entry +@Component +struct AdvertisingPage { + // 初始化广告时间 + @State advertisingTime: number = 3; + // 定时器timer + @State timer: number = -1; + + aboutToAppear() { + this.timer = setInterval(() => { + this.advertisingTime--; + // 广告时间为0s时跳转到首页 + if (this.advertisingTime === 0) { + router.replaceUrl({ url: 'pages/HomePage' }); + clearInterval(this.timer); + } + }, Constants.SETINTERVAL_TIME) + } + + build() { + Stack() { + Image($r('app.media.advertisment')) + .width('100%') + .height('100%') + .objectFit(ImageFit.Contain) + Row() { + Text(`${getResourceString(context, $r('app.string.skip'))} ${this.advertisingTime}s`) + .id('skip') + .padding({ + left: $r('app.integer.layout_size_30'), + right: $r('app.integer.layout_size_30'), + top: $r('app.integer.layout_size_6'), + bottom: $r('app.integer.layout_size_6') + }) + .backgroundColor('rgba(0,0,0,0.20)') + .fontColor(Color.White) + .borderRadius($r('app.integer.layout_size_15')) + .onClick(() => { + clearInterval(this.timer); + router.replaceUrl({ url: 'pages/HomePage' }); + }) + }.width($r('app.string.layout_100')) + .justifyContent(FlexAlign.End) + .padding($r('app.integer.layout_size_10')) + } + .alignContent(Alignment.TopEnd) + .width($r('app.string.layout_100')) + .height($r('app.string.layout_100')) + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/CommentDetailPage.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/CommentDetailPage.ets index 181c977fd92968dc911e85a5f116e76163087fbb..f145b258c50e762cc845ab5aa39131e672b7d972 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/CommentDetailPage.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/CommentDetailPage.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 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 { CommentDetailView } from '@ohos/authorizedcontrol'; - -@Entry -@Component -export struct CommentDetailPage { - build() { - Column() { - CommentDetailView() - } - } +/* + * Copyright (c) 2023 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 { CommentDetailView } from '@ohos/authorizedcontrol'; + +@Entry +@Component +export struct CommentDetailPage { + build() { + Column() { + CommentDetailView() + } + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/HomePage.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/HomePage.ets index 3427fc074cdfc930350ab1d5771069b627066770..9cd515bd20fb9a7af1b6e3c72936a189943c3eaa 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/HomePage.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/HomePage.ets @@ -1,101 +1,101 @@ -/* - * Copyright (c) 2023 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 { MainView, SquareView, MineView } from '@ohos/authorizedcontrol'; - -AppStorage.setOrCreate('location', '北京市') -const TAB_INDEX_0: number = 0; -const TAB_INDEX_1: number = 1; -const TAB_INDEX_2: number = 2; -// divider组件的strokWidth为1 -const DIVIDER_LINE_STROKWIDTH: number = 1; -const TABBAR_SEPARATE_LINE = 0.05; - -@Entry -@Component -struct HomePage { - // 默认显示第一个tab - @State currentTabIndex: number = 0; - @State message: Resource = $r('app.string.home'); - private controller: TabsController = new TabsController(); - - // 设置tabBar样式的位置、未选中图片、选中图片及文字显示的参数 - @Builder - TabBuilder(index: number, imageNormal: Resource, imageSelected: Resource, text: Resource) { - Column() { - Divider() - .vertical(false) - .strokeWidth(DIVIDER_LINE_STROKWIDTH) - .color($r('app.color.tab_bar_separator_line_color')) - .opacity(TABBAR_SEPARATE_LINE) - Image(this.currentTabIndex === index ? imageSelected : imageNormal) - .syncLoad(true) - .width($r('app.integer.tabbar_image_width')) - .height($r('app.integer.tabbar_image_height')) - .margin($r('app.integer.tabbar_image_margin')) - .objectFit(ImageFit.Contain) - Text(text) - .fontSize($r('app.integer.tabbar_item_font_size')) - } - .backgroundColor($r('app.color.tabbar_background')) - .height($r('app.string.layout_100')) - .width($r('app.string.layout_100')) - } - - build() { - Tabs({ barPosition: BarPosition.End, controller: this.controller, index: this.currentTabIndex }) { - TabContent() { - // 首页 - MainView() - } - .tabBar(this.TabBuilder(TAB_INDEX_0, - $r('app.media.ic_public_home'), - $r('app.media.ic_public_home_filled'), - $r('app.string.home'))); - - TabContent() { - // 广场页 - SquareView() - } - .tabBar(this.TabBuilder(TAB_INDEX_1, - $r('app.media.ic_gallery_discover'), - $r('app.media.ic_gallery_discover_filled'), - $r('app.string.square'))); - - TabContent() { - // 我的 - MineView() - } - .tabBar(this.TabBuilder(TAB_INDEX_2, - $r('app.media.ic_public_contacts'), - $r('app.media.ic_public_contacts_filled'), - $r('app.string.mine'))); - } - .onChange((index: number) => { - this.currentTabIndex = index; - if (this.currentTabIndex === TAB_INDEX_0) { - this.message = $r('app.string.home'); - } else if (this.currentTabIndex === TAB_INDEX_1) { - this.message = $r('app.string.square'); - } else if (this.currentTabIndex === TAB_INDEX_2) { - this.message = $r('app.string.mine'); - } - }) - - .barWidth($r('app.string.layout_100')) - .barHeight($r('app.integer.tabbar_height')) - .backgroundColor(Color.White) - } +/* + * Copyright (c) 2023 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 { MainView, SquareView, MineView } from '@ohos/authorizedcontrol'; + +AppStorage.setOrCreate('location', '北京市') +const TAB_INDEX_0: number = 0; +const TAB_INDEX_1: number = 1; +const TAB_INDEX_2: number = 2; +// divider组件的strokWidth为1 +const DIVIDER_LINE_STROKWIDTH: number = 1; +const TABBAR_SEPARATE_LINE = 0.05; + +@Entry +@Component +struct HomePage { + // 默认显示第一个tab + @State currentTabIndex: number = 0; + @State message: Resource = $r('app.string.home'); + private controller: TabsController = new TabsController(); + + // 设置tabBar样式的位置、未选中图片、选中图片及文字显示的参数 + @Builder + TabBuilder(index: number, imageNormal: Resource, imageSelected: Resource, text: Resource) { + Column() { + Divider() + .vertical(false) + .strokeWidth(DIVIDER_LINE_STROKWIDTH) + .color($r('app.color.tab_bar_separator_line_color')) + .opacity(TABBAR_SEPARATE_LINE) + Image(this.currentTabIndex === index ? imageSelected : imageNormal) + .syncLoad(true) + .width($r('app.integer.tabbar_image_width')) + .height($r('app.integer.tabbar_image_height')) + .margin($r('app.integer.tabbar_image_margin')) + .objectFit(ImageFit.Contain) + Text(text) + .fontSize($r('app.integer.tabbar_item_font_size')) + } + .backgroundColor($r('app.color.tabbar_background')) + .height($r('app.string.layout_100')) + .width($r('app.string.layout_100')) + } + + build() { + Tabs({ barPosition: BarPosition.End, controller: this.controller, index: this.currentTabIndex }) { + TabContent() { + // 首页 + MainView() + } + .tabBar(this.TabBuilder(TAB_INDEX_0, + $r('app.media.ic_public_home'), + $r('app.media.ic_public_home_filled'), + $r('app.string.home'))); + + TabContent() { + // 广场页 + SquareView() + } + .tabBar(this.TabBuilder(TAB_INDEX_1, + $r('app.media.ic_gallery_discover'), + $r('app.media.ic_gallery_discover_filled'), + $r('app.string.square'))); + + TabContent() { + // 我的 + MineView() + } + .tabBar(this.TabBuilder(TAB_INDEX_2, + $r('app.media.ic_public_contacts'), + $r('app.media.ic_public_contacts_filled'), + $r('app.string.mine'))); + } + .onChange((index: number) => { + this.currentTabIndex = index; + if (this.currentTabIndex === TAB_INDEX_0) { + this.message = $r('app.string.home'); + } else if (this.currentTabIndex === TAB_INDEX_1) { + this.message = $r('app.string.square'); + } else if (this.currentTabIndex === TAB_INDEX_2) { + this.message = $r('app.string.mine'); + } + }) + + .barWidth($r('app.string.layout_100')) + .barHeight($r('app.integer.tabbar_height')) + .backgroundColor(Color.White) + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/SameCityListPage.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/SameCityListPage.ets index 4d6dc5a8ed7f62bcf27d5efa445fca33d9f2dbcb..a6c4ca7917aeb6b4e8373328e37c89d0f72e6e4e 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/SameCityListPage.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/pages/SameCityListPage.ets @@ -1,28 +1,28 @@ -/* - * Copyright (c) 2023 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 { SameCityListView } from '@ohos/authorizedcontrol'; -import url from '@ohos.url'; -@Entry -@Component -export struct SameCityListPage { - private controller:TabsController=new TabsController(); - build() { - Column(){ - SameCityListView() - } - - } +/* + * Copyright (c) 2023 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 { SameCityListView } from '@ohos/authorizedcontrol'; +import url from '@ohos.url'; +@Entry +@Component +export struct SameCityListPage { + private controller:TabsController=new TabsController(); + build() { + Column(){ + SameCityListView() + } + + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Constants.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Constants.ets index eacaa807e73f38d733245663d29c6ed1b6cd965b..3eb7d8c662aeca581b19640a043afdcd4ec49a15 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Constants.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Constants.ets @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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 default class Constants { - // Tab下标为0 - public static readonly TAB_INDEX_0: number = 0; - // Tab下标为1 - public static readonly TAB_INDEX_1: number = 1; - // Tab下标为2 - public static readonly TAB_INDEX_2: number = 2; - // 计时器,每隔1s执行一次 - public static readonly SETINTERVAL_TIME: number = 1000; - // borderWidth - public static readonly BORDERWIDTH: number = 1; -} +/* + * Copyright (c) 2023 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 default class Constants { + // Tab下标为0 + public static readonly TAB_INDEX_0: number = 0; + // Tab下标为1 + public static readonly TAB_INDEX_1: number = 1; + // Tab下标为2 + public static readonly TAB_INDEX_2: number = 2; + // 计时器,每隔1s执行一次 + public static readonly SETINTERVAL_TIME: number = 1000; + // borderWidth + public static readonly BORDERWIDTH: number = 1; +} diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Logger.ts b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Logger.ts index 5e16f6a640c20e448f28024f34399a16e777d42d..94213adc9f65c5405cd0c3635c3e05240f630c87 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Logger.ts +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/Logger.ts @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - // 日志对应的领域标识 - private domain: number = 0xF811; - // tag日志标识 - private prefix: string = '[Samples_AuthorizedControl]'; - // 格式字符串,用于日志的格式化输出 - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + // 日志对应的领域标识 + private domain: number = 0xF811; + // tag日志标识 + private prefix: string = '[Samples_AuthorizedControl]'; + // 格式字符串,用于日志的格式化输出 + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Samples_AuthorizedControl]'); \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/ResourceUtils.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/ResourceUtils.ets index 3085317211d7e92a6435061ff51f984826366dc6..95ea48f5c32d5603b8bb61787045d3bb4d7fac5b 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/ResourceUtils.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/ets/utils/ResourceUtils.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; - -/** - * getResourceString将Resource类型的数据转换成string类型的数据 - * @param context - * @param ResourceData - */ -export function getResourceString(context: common.UIAbilityContext, resourceData: Resource): string { - let stringData: string = context.resourceManager.getStringSync(resourceData.id); - return stringData; +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; + +/** + * getResourceString将Resource类型的数据转换成string类型的数据 + * @param context + * @param ResourceData + */ +export function getResourceString(context: common.UIAbilityContext, resourceData: Resource): string { + let stringData: string = context.resourceManager.getStringSync(resourceData.id); + return stringData; } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/module.json5 b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/module.json5 index 44457b3f9dd53a73ec692af14729289f4d76bd4d..f249b1e8e93b789b01b6352cf54bd315514b48bd 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/module.json5 +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:grape_app_icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:grape_app_icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/color.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/color.json index db5766943d917590c054d4fd9c91dc707a964eab..0652575934381c8a8309d6cf4a88c284baa4a98a 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/color.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "tabbar_background", - "value": "#F1F3F5" - }, - { - "name": "tab_bar_separator_line_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "tabbar_background", + "value": "#F1F3F5" + }, + { + "name": "tab_bar_separator_line_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/integer.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/integer.json index 6fa7a5122ab5b29ce81abbc59a9508e82c41b817..d7f7ab06b42692e8db1d328309002b2ebbb57730 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/integer.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/integer.json @@ -1,40 +1,40 @@ -{ - "integer": [ - { - "name": "tabbar_image_width", - "value": 28 - }, - { - "name": "tabbar_image_height", - "value": 28 - }, - { - "name": "tabbar_image_margin", - "value": 6 - }, - { - "name": "tabbar_height", - "value": 56 - }, - { - "name": "tabbar_item_font_size", - "value": 12 - }, - { - "name": "layout_size_30", - "value": 30 - }, - { - "name": "layout_size_10", - "value": 10 - }, - { - "name": "layout_size_15", - "value": 15 - }, - { - "name": "layout_size_6", - "value": 6 - } - ] +{ + "integer": [ + { + "name": "tabbar_image_width", + "value": 28 + }, + { + "name": "tabbar_image_height", + "value": 28 + }, + { + "name": "tabbar_image_margin", + "value": 6 + }, + { + "name": "tabbar_height", + "value": 56 + }, + { + "name": "tabbar_item_font_size", + "value": 12 + }, + { + "name": "layout_size_30", + "value": 30 + }, + { + "name": "layout_size_10", + "value": 10 + }, + { + "name": "layout_size_15", + "value": 15 + }, + { + "name": "layout_size_6", + "value": 6 + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/string.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/string.json index 396f21e17777848224246453c7b81652420b325b..9f170f79ed14f169cf69cd1c2f0582fe49d564f4 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/string.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/element/string.json @@ -1,36 +1,36 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "home", - "value": "home" - }, - { - "name": "square", - "value": "square" - }, - { - "name": "mine", - "value": "mine" - }, - { - "name": "layout_100", - "value": "100%" - }, - { - "name": "skip", - "value": "skip" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "home", + "value": "home" + }, + { + "name": "square", + "value": "square" + }, + { + "name": "mine", + "value": "mine" + }, + { + "name": "layout_100", + "value": "100%" + }, + { + "name": "skip", + "value": "skip" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover.svg b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover.svg index 34f07f5b62ca9bef9027403e99a480ea78bd3037..7fcf8d8b68ed4f5494c4241d9dabbd49c8033c64 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover.svg +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover.svg @@ -1,16 +1,16 @@ - - - ic_gallery_discover - - - - - - - - - - - - + + + ic_gallery_discover + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover_filled.svg b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover_filled.svg index 96c605da57fbc90d1d6b3aeb07087b4742a6e6e8..7c2c4505c9c2e4b4c3bf57a5ed9cdc64d9b69f60 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover_filled.svg +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_gallery_discover_filled.svg @@ -1,19 +1,19 @@ - - - ic_gallery_discover_filled - - - - - - - - - - - - - - - + + + ic_gallery_discover_filled + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts.svg b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts.svg index f2bc46df0846e67b21fd68fc0f5cea6376cf4192..d186d58a4e1b21bbbd5582bd882ba59db8538a62 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts.svg +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts.svg @@ -1,26 +1,26 @@ - - - ic_public_contacts - - - - - - - - - - - - - - - - - - - - - - + + + ic_public_contacts + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts_filled.svg b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts_filled.svg index eb188f2d313b0adf33dce32771c48ac4f5a605a2..20c983954728fe4a2205b829b7cf344ffe261380 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts_filled.svg +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_contacts_filled.svg @@ -1,18 +1,18 @@ - - - Public/ic_public_contacts_filled - - - - - - - - - - - - - - + + + Public/ic_public_contacts_filled + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home.svg b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home.svg index 23de6d3033c24ebf9bbd75ee78127a371b2a94be..f17f26aa77dc6f1fc26d23e3e3ded5489d1e7a56 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home.svg +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home.svg @@ -1,16 +1,16 @@ - - - ic_public_home - - - - - - - - - - - - + + + ic_public_home + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home_filled.svg b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home_filled.svg index a68babffe2af6cdf7a204d122c2aec9df766f968..88e5832a27c8f5c0c9b87b3ed06c9ac504faaf7a 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home_filled.svg +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/media/ic_public_home_filled.svg @@ -1,16 +1,16 @@ - - - ic_public_home_filled - - - - - - - - - - - - + + + ic_public_home_filled + + + + + + + + + + + + \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/profile/main_pages.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/profile/main_pages.json index 8df505dffdca9679e6cc4719c849c301383b4af6..aa8b34d03deff7e23b7e627649af79e8a31accfb 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/profile/main_pages.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/base/profile/main_pages.json @@ -1,8 +1,8 @@ -{ - "src": [ - "pages/HomePage", - "pages/AdvertisingPage", - "pages/CommentDetailPage", - "pages/SameCityListPage" - ] -} +{ + "src": [ + "pages/HomePage", + "pages/AdvertisingPage", + "pages/CommentDetailPage", + "pages/SameCityListPage" + ] +} diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/en_US/element/string.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/en_US/element/string.json index 396f21e17777848224246453c7b81652420b325b..9f170f79ed14f169cf69cd1c2f0582fe49d564f4 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/en_US/element/string.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/en_US/element/string.json @@ -1,36 +1,36 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "home", - "value": "home" - }, - { - "name": "square", - "value": "square" - }, - { - "name": "mine", - "value": "mine" - }, - { - "name": "layout_100", - "value": "100%" - }, - { - "name": "skip", - "value": "skip" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "home", + "value": "home" + }, + { + "name": "square", + "value": "square" + }, + { + "name": "mine", + "value": "mine" + }, + { + "name": "layout_100", + "value": "100%" + }, + { + "name": "skip", + "value": "skip" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/zh_CN/element/string.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/zh_CN/element/string.json index 9a856ef9f965a0f87d53c06c43f531ea6983a748..5049daadeeb88634e1740fdf61a2905e73bef194 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/zh_CN/element/string.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/main/resources/zh_CN/element/string.json @@ -1,36 +1,36 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "葡萄广场" - }, - { - "name": "home", - "value": "主页" - }, - { - "name": "square", - "value": "发现" - }, - { - "name": "mine", - "value": "我的" - }, - { - "name": "layout_100", - "value": "100%" - }, - { - "name": "skip", - "value": "跳过" - } - ] +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "葡萄广场" + }, + { + "name": "home", + "value": "主页" + }, + { + "name": "square", + "value": "发现" + }, + { + "name": "mine", + "value": "我的" + }, + { + "name": "layout_100", + "value": "100%" + }, + { + "name": "skip", + "value": "跳过" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets index 2656267da69e86ffd85229ef83873c5ef27d39c8..79764c5bb4f8cb960099f404ba8ad1abeae9aa7f 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,163 +1,163 @@ -/* - * Copyright (c) 2023 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, beforeAll } from '@ohos/hypium'; -import Logger from './Logger' -import { Driver, ON } from '@ohos.UiTest' -import Want from '@ohos.app.ability.Want'; -import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - -const BUNDLE = 'Weibo'; -const TAG = '[Sample_Weibo_Test]'; -const delegator = abilityDelegatorRegistry.getAbilityDelegator(); -const DELAY_TIME = 1000; - -async function getResourceString(resource: T): Promise { - let manage = delegator.getAppContext().resourceManager - let text = await manage.getStringValue(resource) - return text -} - -export default function abilityTest() { - let driver = Driver.create(); - describe('ActsAbilityTest', () => { - beforeAll(async ()=>{ - let want: Want = { - bundleName : 'com.samples.grapesquare', - abilityName : "EntryAbility" - } - await delegator.startAbility(want); - }) - - it("pass_advertisment", 0,async ()=> { - await driver.delayMs(DELAY_TIME); - Logger.info(TAG,BUNDLE + 'pass_advertisment begin'); - await driver.assertComponentExist(ON.id('skip')); - let passButton = await driver.findComponent(ON.id('skip')); - await passButton.click(); - Logger.info(TAG,BUNDLE + 'pass_advertisment end'); - }) - - //保存图片到媒体库 - it("Save_001", 0, async (done: Function) => { - Logger.info(TAG, BUNDLE + 'Save_001 begin'); - //点击进入微博展示页 - await driver.assertComponentExist(ON.id('textDetail')) - let viewList = await driver.findComponent(ON.id('textDetail')) - await driver.delayMs(500); - await viewList.click() - Logger.info(TAG, BUNDLE + 'Save_001 displayDetails') - //长按图片保存 - await driver.delayMs(DELAY_TIME) - await driver.assertComponentExist(ON.type('Image').isAfter(ON.id('textDetail'))) - let imageButton = await driver.findComponent(ON.type('Image').isAfter(ON.id('textDetail'))) - await driver.delayMs(500); - await imageButton.longClick() - //点击保存按钮 - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.save')))); - let saveButton = await driver.findComponent(ON.text(await getResourceString($r('app.string.save')))); - await driver.delayMs(500); - await saveButton.click() - Logger.info(TAG, BUNDLE + 'Save_001 imageSaveSuccess') - await driver.delayMs(DELAY_TIME) - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.known')))); - let know = await driver.findComponent(ON.text(await getResourceString($r('app.string.known')))); - await know.click(); - //返回 - let backBtn = await driver.findComponent(ON.id('backBtn')); - await backBtn.click(); - Logger.info( TAG, BUNDLE + 'Save_001 end'); - await driver.delayMs(DELAY_TIME) - done() - }) - - - //获取剪贴板内容 - it("GetPasteContent_001", 0, async (done: Function) => { - await driver.delayMs(500); - Logger.info(TAG, BUNDLE + 'GetPasteContent_001 begin') - //点击进入微博展示页 - await driver.assertComponentExist(ON.id('textDetail')) - let viewList = await driver.findComponent(ON.id('textDetail')) - await viewList.click() - Logger.info(TAG, BUNDLE + 'GetPasteContent_001 displayDetails') - //点击评论按钮 - let paste = await driver.findComponent(ON.id('commentButton').text(await getResourceString($r('app.string.comment')))); - await driver.delayMs(500); - await paste.click(); - Logger.info(TAG, BUNDLE + 'SendMessageFunction_001 addComment') - //点击输入框,调起输入法 - let textInput = await driver.findComponent(ON.id('comment_add')) - await textInput.click() - Logger.info(TAG, BUNDLE + 'SendMessageFunction_001 inputText') - //在输入框输入example - await textInput.inputText('example') - let inputValue = await textInput.getText() - Logger.info(TAG, BUNDLE + 'InputMessageFunction_001 inputValue=' + inputValue) - //长按输入框调起复制 - await textInput.click() - await textInput.longClick() - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.copy')))); - let copyButton = await driver.findComponent(ON.text(await getResourceString($r('app.string.copy')))); - await copyButton.click() - Logger.info(TAG, BUNDLE + 'SendMessageFunction_001 copySuccess') - //长按输入框调起粘贴 - await textInput.longClick() - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.paste')))); - let pasteButton = await driver.findComponent(ON.text(await getResourceString($r('app.string.paste')))); - await pasteButton.click() - await driver.delayMs(DELAY_TIME) - let pasteValue = await textInput.getText() - Logger.info(TAG, BUNDLE + 'pasteMessageFunction_001 inputValue=' + pasteValue) - Logger.info(TAG, BUNDLE + 'PasteMessageFunction_001 pasteSuccess') - //返回 - let backBtn = await driver.findComponent(ON.id('backBtn')); - await backBtn.click(); - Logger.info( TAG, BUNDLE + 'Save_001 end'); - done() - }) - - //获取定位信息 - it("GetLocation_001", 0, async (done: Function) => { - await driver.delayMs(DELAY_TIME) - Logger.info(TAG, BUNDLE + 'GetLocation_001 begin') - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.discover')))); - let square = await driver.findComponent(ON.text(await getResourceString($r('app.string.discover')))); - await square.click() - Logger.info(TAG,BUNDLE + 'GetLocation_001 squareView') - //点击"同城"获取定位信息 - await driver.assertComponentExist(ON.type('LocationButton')) - Logger.info(TAG, BUNDLE + 'GetLocation_001 begin') - let location = await driver.findComponent(ON.type('LocationButton')) - await location.click() - Logger.info(TAG,BUNDLE + 'GetLocation_001 clickLocationButton') - // 点击确定 - await driver.delayMs(DELAY_TIME) - await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.known')))); - let Button = await driver.findComponent(ON.text(await getResourceString($r('app.string.known')))); - await Button.click(); - //获取定位城市信息 - await driver.assertComponentExist(ON.id('locationDisplay')) - let locationValue = await driver.findComponent(ON.id('locationDisplay')) - let locationCity =await locationValue.getText() - await driver.delayMs(500); - Logger.info(TAG, BUNDLE + 'GetLocation_001 inputValue=' + locationCity) - // 返回 - let backBtn = await driver.findComponent(ON.id('locationbackBtn')) - await backBtn.click() - done() - }) - }) +/* + * Copyright (c) 2023 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, beforeAll } from '@ohos/hypium'; +import Logger from './Logger' +import { Driver, ON } from '@ohos.UiTest' +import Want from '@ohos.app.ability.Want'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +const BUNDLE = 'Weibo'; +const TAG = '[Sample_Weibo_Test]'; +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const DELAY_TIME = 1000; + +async function getResourceString(resource: T): Promise { + let manage = delegator.getAppContext().resourceManager + let text = await manage.getStringValue(resource) + return text +} + +export default function abilityTest() { + let driver = Driver.create(); + describe('ActsAbilityTest', () => { + beforeAll(async ()=>{ + let want: Want = { + bundleName : 'com.samples.grapesquare', + abilityName : "EntryAbility" + } + await delegator.startAbility(want); + }) + + it("pass_advertisment", 0,async ()=> { + await driver.delayMs(DELAY_TIME); + Logger.info(TAG,BUNDLE + 'pass_advertisment begin'); + await driver.assertComponentExist(ON.id('skip')); + let passButton = await driver.findComponent(ON.id('skip')); + await passButton.click(); + Logger.info(TAG,BUNDLE + 'pass_advertisment end'); + }) + + //保存图片到媒体库 + it("Save_001", 0, async (done: Function) => { + Logger.info(TAG, BUNDLE + 'Save_001 begin'); + //点击进入微博展示页 + await driver.assertComponentExist(ON.id('textDetail')) + let viewList = await driver.findComponent(ON.id('textDetail')) + await driver.delayMs(500); + await viewList.click() + Logger.info(TAG, BUNDLE + 'Save_001 displayDetails') + //长按图片保存 + await driver.delayMs(DELAY_TIME) + await driver.assertComponentExist(ON.type('Image').isAfter(ON.id('textDetail'))) + let imageButton = await driver.findComponent(ON.type('Image').isAfter(ON.id('textDetail'))) + await driver.delayMs(500); + await imageButton.longClick() + //点击保存按钮 + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.save')))); + let saveButton = await driver.findComponent(ON.text(await getResourceString($r('app.string.save')))); + await driver.delayMs(500); + await saveButton.click() + Logger.info(TAG, BUNDLE + 'Save_001 imageSaveSuccess') + await driver.delayMs(DELAY_TIME) + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.known')))); + let know = await driver.findComponent(ON.text(await getResourceString($r('app.string.known')))); + await know.click(); + //返回 + let backBtn = await driver.findComponent(ON.id('backBtn')); + await backBtn.click(); + Logger.info( TAG, BUNDLE + 'Save_001 end'); + await driver.delayMs(DELAY_TIME) + done() + }) + + + //获取剪贴板内容 + it("GetPasteContent_001", 0, async (done: Function) => { + await driver.delayMs(500); + Logger.info(TAG, BUNDLE + 'GetPasteContent_001 begin') + //点击进入微博展示页 + await driver.assertComponentExist(ON.id('textDetail')) + let viewList = await driver.findComponent(ON.id('textDetail')) + await viewList.click() + Logger.info(TAG, BUNDLE + 'GetPasteContent_001 displayDetails') + //点击评论按钮 + let paste = await driver.findComponent(ON.id('commentButton').text(await getResourceString($r('app.string.comment')))); + await driver.delayMs(500); + await paste.click(); + Logger.info(TAG, BUNDLE + 'SendMessageFunction_001 addComment') + //点击输入框,调起输入法 + let textInput = await driver.findComponent(ON.id('comment_add')) + await textInput.click() + Logger.info(TAG, BUNDLE + 'SendMessageFunction_001 inputText') + //在输入框输入example + await textInput.inputText('example') + let inputValue = await textInput.getText() + Logger.info(TAG, BUNDLE + 'InputMessageFunction_001 inputValue=' + inputValue) + //长按输入框调起复制 + await textInput.click() + await textInput.longClick() + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.copy')))); + let copyButton = await driver.findComponent(ON.text(await getResourceString($r('app.string.copy')))); + await copyButton.click() + Logger.info(TAG, BUNDLE + 'SendMessageFunction_001 copySuccess') + //长按输入框调起粘贴 + await textInput.longClick() + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.paste')))); + let pasteButton = await driver.findComponent(ON.text(await getResourceString($r('app.string.paste')))); + await pasteButton.click() + await driver.delayMs(DELAY_TIME) + let pasteValue = await textInput.getText() + Logger.info(TAG, BUNDLE + 'pasteMessageFunction_001 inputValue=' + pasteValue) + Logger.info(TAG, BUNDLE + 'PasteMessageFunction_001 pasteSuccess') + //返回 + let backBtn = await driver.findComponent(ON.id('backBtn')); + await backBtn.click(); + Logger.info( TAG, BUNDLE + 'Save_001 end'); + done() + }) + + //获取定位信息 + it("GetLocation_001", 0, async (done: Function) => { + await driver.delayMs(DELAY_TIME) + Logger.info(TAG, BUNDLE + 'GetLocation_001 begin') + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.discover')))); + let square = await driver.findComponent(ON.text(await getResourceString($r('app.string.discover')))); + await square.click() + Logger.info(TAG,BUNDLE + 'GetLocation_001 squareView') + //点击"同城"获取定位信息 + await driver.assertComponentExist(ON.type('LocationButton')) + Logger.info(TAG, BUNDLE + 'GetLocation_001 begin') + let location = await driver.findComponent(ON.type('LocationButton')) + await location.click() + Logger.info(TAG,BUNDLE + 'GetLocation_001 clickLocationButton') + // 点击确定 + await driver.delayMs(DELAY_TIME) + await driver.assertComponentExist(ON.text(await getResourceString($r('app.string.known')))); + let Button = await driver.findComponent(ON.text(await getResourceString($r('app.string.known')))); + await Button.click(); + //获取定位城市信息 + await driver.assertComponentExist(ON.id('locationDisplay')) + let locationValue = await driver.findComponent(ON.id('locationDisplay')) + let locationCity =await locationValue.getText() + await driver.delayMs(500); + Logger.info(TAG, BUNDLE + 'GetLocation_001 inputValue=' + locationCity) + // 返回 + let backBtn = await driver.findComponent(ON.id('locationbackBtn')) + await backBtn.click() + done() + }) + }) } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/List.test.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/List.test.ets index 2a22ae6dc9bdd833b75571bef8c29a0e39dde777..27c07a1a174f6862ea84c4bb5f45bc1789234441 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2023 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() +/* + * Copyright (c) 2023 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/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Logger.ts b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Logger.ts index 5e16f6a640c20e448f28024f34399a16e777d42d..94213adc9f65c5405cd0c3635c3e05240f630c87 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Logger.ts +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/test/Logger.ts @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - // 日志对应的领域标识 - private domain: number = 0xF811; - // tag日志标识 - private prefix: string = '[Samples_AuthorizedControl]'; - // 格式字符串,用于日志的格式化输出 - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + // 日志对应的领域标识 + private domain: number = 0xF811; + // tag日志标识 + private prefix: string = '[Samples_AuthorizedControl]'; + // 格式字符串,用于日志的格式化输出 + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Samples_AuthorizedControl]'); \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/TestAbility.ets index 0d120161d51ef340700a478c6bfdb69ddecef1de..0a150abd0d008e2a2ba059ae09564cb6da384b04 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import hilog from '@ohos.hilog'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; - -export default class TestAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); - hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); - hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); - let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator - abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() - let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs - abilityDelegatorArguments = abilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); - windowStage.loadContent('testability/pages/Index', (err, data) => { - 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. Data: %{public}s', - JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); - } - - onForeground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); - } - - onBackground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); - } +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator + abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs + abilityDelegatorArguments = abilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + 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. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/pages/Index.ets index 44948793a774f7d965db9b4f02c6cc5925948f51..40f0a77aebde46e8c079bd9975134e37d373c1f7 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -@Entry -@Component -struct Index { - aboutToAppear() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); - } - @State message: string = 'Hello World' - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(()=>{ - }) - } - .width('100%') - } - .height('100%') - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts index 1d7dc001bc91196773f66c879afdf4897de8c8f2..e3414df5c17843651f8ef9040727ea0f7e0c604b 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import TestRunner from '@ohos.application.testRunner'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -async function onAbilityCreateCallback() { - hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); -} - -async function addAbilityMonitorCallback(err: any) { - hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); - } - - async onRun() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - const bundleName = abilityDelegatorArguments.bundleName; - const testAbilityName = 'TestAbility'; - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName; - let debug = abilityDelegatorArguments.parameters['-D']; - if (debug == 'true') { - cmd += ' -D'; - } - hilog.info(0x0000,'testTag', 'cmd : %{public}s', cmd); - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - hilog.info(0x0000,'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); - hilog.info(0x0000,'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); - hilog.info(0x0000,'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); - }) -/* const want = { - bundleName: bundleName, - abilityName: testAbilityName - }; - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - abilityDelegator.startAbility(want, (err : any, data : any) => { - hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? ''); - hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s',JSON.stringify(data) ?? ''); - }) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');*/ - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + const bundleName = abilityDelegatorArguments.bundleName; + const testAbilityName = 'TestAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + let debug = abilityDelegatorArguments.parameters['-D']; + if (debug == 'true') { + cmd += ' -D'; + } + hilog.info(0x0000,'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000,'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000,'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000,'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) +/* const want = { + bundleName: bundleName, + abilityName: testAbilityName + }; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + abilityDelegator.startAbility(want, (err : any, data : any) => { + hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s',JSON.stringify(data) ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');*/ + } } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/module.json5 b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/module.json5 index 7e44e83cf9b7428c7a916f5782b9a6d85bf6d7da..e6a499c49efe53f1a5bab25638ce6b00f612a7d8 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/module.json5 +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/color.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/color.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/string.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/string.json index 3436ca036653c9e9ae2d1ff1d770f06b7b4e57cf..cecafbf573b1fcc9da03f6d708ae0c1a6e35172e 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/string.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/element/string.json @@ -1,40 +1,40 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - }, - { - "name": "save", - "value": "保存" - }, - { - "name": "known", - "value": "知道了" - }, - { - "name": "comment", - "value": "评论" - }, - { - "name": "copy", - "value": "复制" - }, - { - "name": "paste", - "value": "粘贴" - }, - { - "name": "discover", - "value": "发现" - } - ] +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "save", + "value": "保存" + }, + { + "name": "known", + "value": "知道了" + }, + { + "name": "comment", + "value": "评论" + }, + { + "name": "copy", + "value": "复制" + }, + { + "name": "paste", + "value": "粘贴" + }, + { + "name": "discover", + "value": "发现" + } + ] } \ No newline at end of file diff --git a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/profile/test_pages.json index c3d813c41aa8ac1b64ccf124bb705adefb381787..b7e7343cacb32ce982a45e76daad86e435e054fe 100644 --- a/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/profile/test_pages.json +++ b/code/Solutions/Social/GrapeSquare/product/phone/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -1,5 +1,5 @@ -{ - "src": [ - "testability/pages/Index" - ] -} +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/code/SuperFeature/DistributedAppDev/ArkTSDistributedMusicPlayer/entry/src/main/ets/serviceability/ServiceAbility.ts b/code/SuperFeature/DistributedAppDev/ArkTSDistributedMusicPlayer/entry/src/main/ets/serviceability/ServiceAbility.ts index 6de986e256518850d27bf3f2b90acb358caf2c1e..535bf6f349d7313a7a99db841ad456e7381560af 100644 --- a/code/SuperFeature/DistributedAppDev/ArkTSDistributedMusicPlayer/entry/src/main/ets/serviceability/ServiceAbility.ts +++ b/code/SuperFeature/DistributedAppDev/ArkTSDistributedMusicPlayer/entry/src/main/ets/serviceability/ServiceAbility.ts @@ -1,229 +1,229 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import rpc from '@ohos.rpc'; -import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; -import Logger from '../model/Logger'; -import { - APPLICATION_BUNDLE_NAME, - APPLICATION_ABILITY_NAME, - APPLICATION_SERVICE_NAME, - MusicSharedEventCode, - MusicConnectEvent -} from '../common/MusicSharedDefinition'; - -const TAG: string = 'ServiceAbility' -const CONNECT_REMOTE_TIMEOUT = 10000 - -let remoteProxy: rpc.RemoteProxy = null; - -class DistributedMusicServiceExtension extends rpc.RemoteObject { - private context - - constructor(des, context) { - super(des) - this.context = context - } - - startServiceAbility(want): void { - try { - let connectOptions = { - onConnect(elementName, remote): void { - Logger.info(TAG, `Start remote service has been succeeded, elementName= ${JSON.stringify(elementName)}, remote= ${JSON.stringify(remote)}`) - if (remote === null) { - Logger.info(TAG, 'Remote is null') - } - remoteProxy = remote as rpc.RemoteProxy; - clearTimeout(timeoutId) - let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); - if (remoteServiceExtensionConnectEvent === undefined) { - Logger.info(TAG, `Connect remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); - return; - } - AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); - }, - onDisconnect(elementName): void { - Logger.info(TAG, `ServiceExtension has onDisconnected,elementName= ${JSON.stringify(elementName)}`) - clearTimeout(timeoutId) - remoteProxy = null; - let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); - if (remoteServiceExtensionConnectEvent === undefined) { - Logger.info(TAG, `Disconnect remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); - return; - } - AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); - }, - onFailed(code): void { - Logger.info(TAG, `ServiceExtension has onFailed, code= ${JSON.stringify(code)}`) - clearTimeout(timeoutId) - remoteProxy = null; - let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); - if (remoteServiceExtensionConnectEvent === undefined) { - Logger.info(TAG, `Failed remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); - return; - } - AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); - } - } - - this.context.connectServiceExtensionAbility(want, connectOptions) - let timeoutId = setTimeout(() => { - Logger.info(TAG, 'Connect remote service extension timeout') - let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); - if (remoteServiceExtensionConnectEvent === undefined) { - Logger.info(TAG, `Timeout remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); - return; - } - AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); - }, CONNECT_REMOTE_TIMEOUT) - } catch (err) { - Logger.info(TAG, `ConnectServiceExtensionAbility has failed, want= ${JSON.stringify(want)}, err= ${JSON.stringify(err)}`) - } - } - - stopServiceAbility(want): void { - this.context.stopServiceExtensionAbility(want).then(() => { - Logger.info(TAG, `Stop service has been succeeded, want= ${JSON.stringify(want)}`) - }).catch((err) => { - Logger.info(TAG, `Stop service has been failed, want= ${JSON.stringify(want)}, err= ${JSON.stringify(err)}`) - }) - } - - onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, options: rpc.MessageOption): boolean { - if (code === MusicSharedEventCode.START_DISTRIBUTED_MUSIC_SERVICE) { - let deviceId = data.readString() - let stringJson: string = data.readString() - try { - let jsonData = JSON.parse(stringJson); - Logger.info(TAG, `onRemoteRequest jsonData: ${JSON.stringify(jsonData)}`); - let params = { - uri: jsonData.uri, - seekTo: jsonData.seekTo, - isPlaying: jsonData.isPlaying, - flag: 'START_REMOTE_DISTRIBUTED_MUSIC_SERVICE' - } - let want = { - deviceId: deviceId, - bundleName: APPLICATION_BUNDLE_NAME, - abilityName: APPLICATION_SERVICE_NAME, - parameters: params - } - this.startServiceAbility(want); - } catch (error) { - Logger.error(TAG, `JSON text error`); - } - } else if (code === MusicSharedEventCode.STOP_DISTRIBUTED_MUSIC_SERVICE) { - let deviceId = data.readString() - let want = { - deviceId: deviceId, - bundleName: APPLICATION_BUNDLE_NAME, - abilityName: APPLICATION_SERVICE_NAME - } - this.stopServiceAbility(want) - } else if (code === MusicSharedEventCode.PLAY_MUSIC_SERVICE) { - if (remoteProxy === null) { - Logger.info(TAG, 'Play local is null') - return false - } - let option = new rpc.MessageOption() - let data = new rpc.MessageParcel() - let reply = new rpc.MessageParcel() - remoteProxy.sendRequest(MusicSharedEventCode.PLAY_MUSIC_SERVICE_REMOTE, data, reply, option); - } else if (code === MusicSharedEventCode.PAUSE_MUSIC_SERVICE) { - if (remoteProxy === null) { - Logger.info(TAG, 'Pause local is null') - return false - } - let option = new rpc.MessageOption() - let data = new rpc.MessageParcel() - let reply = new rpc.MessageParcel() - remoteProxy.sendRequest(MusicSharedEventCode.PAUSE_MUSIC_SERVICE_REMOTE, data, reply, option); - } else if (code === MusicSharedEventCode.PLAY_MUSIC_SERVICE_REMOTE) { - let musicPlay = AppStorage.get('musicPlay'); - if (musicPlay === undefined) { - Logger.error(TAG, 'get play callback form app storage falied'); - return false; - } - AppStorage.setOrCreate('musicPlay', !musicPlay); - } else if (code === MusicSharedEventCode.PAUSE_MUSIC_SERVICE_REMOTE) { - let musicPause = AppStorage.get('musicPause'); - if (musicPause === undefined) { - Logger.error(TAG, 'get pause callback form app storage falied'); - return false; - } - AppStorage.setOrCreate('musicPause', !musicPause); - } else if (code === MusicSharedEventCode.STOP_LOCAL_SERIVCE) { - this.context.terminateSelf().then(() => { - Logger.info(TAG, 'TerminateSelf service extension has been succeeded') - }).catch((err) => { - Logger.info(TAG, `TerminateSelf service extension has been failed err= ${JSON.stringify(err)}`) - }) - } else { - Logger.info(TAG, 'Invalid instruction') - return false - } - return true - } -} - -export default class ServiceAbility extends ServiceExtensionAbility { - onCreate(want): void { - if (want.parameters.flag === 'START_REMOTE_DISTRIBUTED_MUSIC_SERVICE') { - let localwant = { - bundleName: APPLICATION_BUNDLE_NAME, - abilityName: APPLICATION_ABILITY_NAME, - parameters: want.parameters - } - this.context.startAbility(localwant).then(() => { - Logger.info(TAG, 'StartUIAbility has been succeeded') - }).catch((err) => { - Logger.info(TAG, `StartUIAbility has been failed, err= ${JSON.stringify(err)}`) - }) - } - } - - onDestroy(): void { - Logger.info(TAG, 'ServiceAbility onDestroy') - } - - onRequest(want, startId): void { - Logger.info(TAG, 'ServiceAbility onRequest') - } - - onConnect(want): rpc.RemoteObject { - Logger.info(TAG, 'ServiceAbility onConnect') - if (this.context === null && this.context === undefined) { - Logger.error(TAG, 'ServiceAbility context does not exist or is empty') - return - } - return new DistributedMusicServiceExtension('ohos.samples.distributedMusicServiceExtension', this.context) - } - - onDisconnect(want): void { - Logger.info(TAG, 'ServiceAbility onDisconnect') - } - - onReconnect(want): void { - Logger.info(TAG, 'ServiceAbility onReconnect') - } - - onConfigurationUpdate(newConfig): void { - Logger.info(TAG, 'ServiceAbility onConfigurationUpdate') - } - - onDump(params: Array): Array { - Logger.info(TAG, 'ServiceAbility onDump') - return params - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import rpc from '@ohos.rpc'; +import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; +import Logger from '../model/Logger'; +import { + APPLICATION_BUNDLE_NAME, + APPLICATION_ABILITY_NAME, + APPLICATION_SERVICE_NAME, + MusicSharedEventCode, + MusicConnectEvent +} from '../common/MusicSharedDefinition'; + +const TAG: string = 'ServiceAbility' +const CONNECT_REMOTE_TIMEOUT = 10000 + +let remoteProxy: rpc.RemoteProxy = null; + +class DistributedMusicServiceExtension extends rpc.RemoteObject { + private context + + constructor(des, context) { + super(des) + this.context = context + } + + startServiceAbility(want): void { + try { + let connectOptions = { + onConnect(elementName, remote): void { + Logger.info(TAG, `Start remote service has been succeeded, elementName= ${JSON.stringify(elementName)}, remote= ${JSON.stringify(remote)}`) + if (remote === null) { + Logger.info(TAG, 'Remote is null') + } + remoteProxy = remote as rpc.RemoteProxy; + clearTimeout(timeoutId) + let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); + if (remoteServiceExtensionConnectEvent === undefined) { + Logger.info(TAG, `Connect remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); + return; + } + AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); + }, + onDisconnect(elementName): void { + Logger.info(TAG, `ServiceExtension has onDisconnected,elementName= ${JSON.stringify(elementName)}`) + clearTimeout(timeoutId) + remoteProxy = null; + let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); + if (remoteServiceExtensionConnectEvent === undefined) { + Logger.info(TAG, `Disconnect remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); + return; + } + AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); + }, + onFailed(code): void { + Logger.info(TAG, `ServiceExtension has onFailed, code= ${JSON.stringify(code)}`) + clearTimeout(timeoutId) + remoteProxy = null; + let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); + if (remoteServiceExtensionConnectEvent === undefined) { + Logger.info(TAG, `Failed remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); + return; + } + AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); + } + } + + this.context.connectServiceExtensionAbility(want, connectOptions) + let timeoutId = setTimeout(() => { + Logger.info(TAG, 'Connect remote service extension timeout') + let remoteServiceExtensionConnectEvent = AppStorage.get('remoteServiceExtensionConnectEvent'); + if (remoteServiceExtensionConnectEvent === undefined) { + Logger.info(TAG, `Timeout remote service callback is ${JSON.stringify(remoteServiceExtensionConnectEvent)}`); + return; + } + AppStorage.setOrCreate('remoteServiceExtensionConnectEvent', !remoteServiceExtensionConnectEvent); + }, CONNECT_REMOTE_TIMEOUT) + } catch (err) { + Logger.info(TAG, `ConnectServiceExtensionAbility has failed, want= ${JSON.stringify(want)}, err= ${JSON.stringify(err)}`) + } + } + + stopServiceAbility(want): void { + this.context.stopServiceExtensionAbility(want).then(() => { + Logger.info(TAG, `Stop service has been succeeded, want= ${JSON.stringify(want)}`) + }).catch((err) => { + Logger.info(TAG, `Stop service has been failed, want= ${JSON.stringify(want)}, err= ${JSON.stringify(err)}`) + }) + } + + onRemoteRequest(code: number, data: rpc.MessageParcel, reply: rpc.MessageParcel, options: rpc.MessageOption): boolean { + if (code === MusicSharedEventCode.START_DISTRIBUTED_MUSIC_SERVICE) { + let deviceId = data.readString() + let stringJson: string = data.readString() + try { + let jsonData = JSON.parse(stringJson); + Logger.info(TAG, `onRemoteRequest jsonData: ${JSON.stringify(jsonData)}`); + let params = { + uri: jsonData.uri, + seekTo: jsonData.seekTo, + isPlaying: jsonData.isPlaying, + flag: 'START_REMOTE_DISTRIBUTED_MUSIC_SERVICE' + } + let want = { + deviceId: deviceId, + bundleName: APPLICATION_BUNDLE_NAME, + abilityName: APPLICATION_SERVICE_NAME, + parameters: params + } + this.startServiceAbility(want); + } catch (error) { + Logger.error(TAG, `JSON text error`); + } + } else if (code === MusicSharedEventCode.STOP_DISTRIBUTED_MUSIC_SERVICE) { + let deviceId = data.readString() + let want = { + deviceId: deviceId, + bundleName: APPLICATION_BUNDLE_NAME, + abilityName: APPLICATION_SERVICE_NAME + } + this.stopServiceAbility(want) + } else if (code === MusicSharedEventCode.PLAY_MUSIC_SERVICE) { + if (remoteProxy === null) { + Logger.info(TAG, 'Play local is null') + return false + } + let option = new rpc.MessageOption() + let data = new rpc.MessageParcel() + let reply = new rpc.MessageParcel() + remoteProxy.sendRequest(MusicSharedEventCode.PLAY_MUSIC_SERVICE_REMOTE, data, reply, option); + } else if (code === MusicSharedEventCode.PAUSE_MUSIC_SERVICE) { + if (remoteProxy === null) { + Logger.info(TAG, 'Pause local is null') + return false + } + let option = new rpc.MessageOption() + let data = new rpc.MessageParcel() + let reply = new rpc.MessageParcel() + remoteProxy.sendRequest(MusicSharedEventCode.PAUSE_MUSIC_SERVICE_REMOTE, data, reply, option); + } else if (code === MusicSharedEventCode.PLAY_MUSIC_SERVICE_REMOTE) { + let musicPlay = AppStorage.get('musicPlay'); + if (musicPlay === undefined) { + Logger.error(TAG, 'get play callback form app storage falied'); + return false; + } + AppStorage.setOrCreate('musicPlay', !musicPlay); + } else if (code === MusicSharedEventCode.PAUSE_MUSIC_SERVICE_REMOTE) { + let musicPause = AppStorage.get('musicPause'); + if (musicPause === undefined) { + Logger.error(TAG, 'get pause callback form app storage falied'); + return false; + } + AppStorage.setOrCreate('musicPause', !musicPause); + } else if (code === MusicSharedEventCode.STOP_LOCAL_SERIVCE) { + this.context.terminateSelf().then(() => { + Logger.info(TAG, 'TerminateSelf service extension has been succeeded') + }).catch((err) => { + Logger.info(TAG, `TerminateSelf service extension has been failed err= ${JSON.stringify(err)}`) + }) + } else { + Logger.info(TAG, 'Invalid instruction') + return false + } + return true + } +} + +export default class ServiceAbility extends ServiceExtensionAbility { + onCreate(want): void { + if (want.parameters.flag === 'START_REMOTE_DISTRIBUTED_MUSIC_SERVICE') { + let localwant = { + bundleName: APPLICATION_BUNDLE_NAME, + abilityName: APPLICATION_ABILITY_NAME, + parameters: want.parameters + } + this.context.startAbility(localwant).then(() => { + Logger.info(TAG, 'StartUIAbility has been succeeded') + }).catch((err) => { + Logger.info(TAG, `StartUIAbility has been failed, err= ${JSON.stringify(err)}`) + }) + } + } + + onDestroy(): void { + Logger.info(TAG, 'ServiceAbility onDestroy') + } + + onRequest(want, startId): void { + Logger.info(TAG, 'ServiceAbility onRequest') + } + + onConnect(want): rpc.RemoteObject { + Logger.info(TAG, 'ServiceAbility onConnect') + if (this.context === null && this.context === undefined) { + Logger.error(TAG, 'ServiceAbility context does not exist or is empty') + return + } + return new DistributedMusicServiceExtension('ohos.samples.distributedMusicServiceExtension', this.context) + } + + onDisconnect(want): void { + Logger.info(TAG, 'ServiceAbility onDisconnect') + } + + onReconnect(want): void { + Logger.info(TAG, 'ServiceAbility onReconnect') + } + + onConfigurationUpdate(newConfig): void { + Logger.info(TAG, 'ServiceAbility onConfigurationUpdate') + } + + onDump(params: Array): Array { + Logger.info(TAG, 'ServiceAbility onDump') + return params + } } \ No newline at end of file diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/app.json5 b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/app.json5 index 058c41157e77ba3babe16009bb147016f23ab4bd..756ccf115f59dbb32e4c558afceb1b78e630d68a 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/app.json5 +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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.distributedfilemanager", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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.distributedfilemanager", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/resources/base/element/string.json b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/resources/base/element/string.json index 1d8ff02351f6a9e0af0174e4a3c0e774b91097d5..1a825da4ec3d82173c4216e9ac9c8aa072f7a122 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/resources/base/element/string.json +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "分布式文件管理" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "分布式文件管理" + } + ] +} diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/build-profile.json5 b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/build-profile.json5 index 66f05ac2067275754252159bc31b877ea541bb08..66a6f8f36dde704fdeb6be14566a8b8371a77747 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/build-profile.json5 +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/build-profile.json5 @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - }, - { - "name": "Library", - "srcPath": "./Library" - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "Library", + "srcPath": "./Library" + } + ] } \ No newline at end of file diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/entryability/EntryAbility.ets b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/entryability/EntryAbility.ets index 21b1c8420ef1d096515fdd7c69e5a4037937aa77..10fda1fe60ebd59ad894ded6912a82208a48327d 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,80 +1,80 @@ -/* - * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; -import DataObject from '../model/DataObject'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import { Logger } from '@ohos/feature-file-manager'; - -let sessionId : string; - -export default class EntryAbility extends UIAbility { - async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onCreate'); - //user grant - let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); - try { - let requestPermissionsResult = await atManager.requestPermissionsFromUser(this.context, - ['ohos.permission.DISTRIBUTED_DATASYNC']); - Logger.info(`requestPermissionsResult: ${JSON.stringify(requestPermissionsResult)}`); - } catch (err) { - Logger.error(`catch err: ${JSON.stringify(err)}`); - } - - // 判断是否被拉起 - if (want.parameters && want.parameters.distributedSessionId) { - sessionId = want.parameters.distributedSessionId as string; - DataObject.createDataObject(this.context, sessionId); - } else { - DataObject.callRemote(this.context); - DataObject.createDataObject(this.context); - } - } - - onDestroy() { - Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error('0x0000', 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - Logger.info('0x0000', 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import DataObject from '../model/DataObject'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import { Logger } from '@ohos/feature-file-manager'; + +let sessionId : string; + +export default class EntryAbility extends UIAbility { + async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onCreate'); + //user grant + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + try { + let requestPermissionsResult = await atManager.requestPermissionsFromUser(this.context, + ['ohos.permission.DISTRIBUTED_DATASYNC']); + Logger.info(`requestPermissionsResult: ${JSON.stringify(requestPermissionsResult)}`); + } catch (err) { + Logger.error(`catch err: ${JSON.stringify(err)}`); + } + + // 判断是否被拉起 + if (want.parameters && want.parameters.distributedSessionId) { + sessionId = want.parameters.distributedSessionId as string; + DataObject.createDataObject(this.context, sessionId); + } else { + DataObject.callRemote(this.context); + DataObject.createDataObject(this.context); + } + } + + onDestroy() { + Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error('0x0000', 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + Logger.info('0x0000', 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info('0x0000', 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/DataObject.ets b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/DataObject.ets index 4d838f95f0f4d0ad9453cba8bfa7afc12263a9b6..c005e636a0942086761bf633d0c892bdfb97bb49 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/DataObject.ets +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/DataObject.ets @@ -1,150 +1,150 @@ -/* - * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import distributedDataObject from '@ohos.data.distributedDataObject'; -import distributedDeviceManager from '@ohos.distributedDeviceManager'; -import fs from '@ohos.file.fs'; -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; -import { Caller } from '@ohos.app.ability.UIAbility'; -import { Logger } from '@ohos/feature-file-manager'; - -const TAG: string = 'DataObjectModel'; -let caller: Caller; - -class DataObject { - public distributedObject: distributedDataObject.DataObject | undefined = undefined; - private sessionId: string = ''; - - createDataObject(context: common.UIAbilityContext, sessionId?: string) { - if (this.distributedObject) { - Logger.error(TAG, 'create dataObject already'); - return; - } - - // 创建分布式数据对象实例 - this.distributedObject = distributedDataObject.create(context, { - from: '', - localFileUriList: [], - disFileUriList: [], - disFileList: [] - }); - - // 设置数据变更监听 - this.distributedObject.on('change', (sessionId: string, fields: Array) => { - Logger.info(TAG, `change, sessionId: ${sessionId}, fields: ${JSON.stringify(fields)}`); - fields.forEach((field) => { - Logger.info(TAG, `${field}: ${this.distributedObject![field]}`); - }); - }); - // 设置同步sessionId加入组网 - if (sessionId) { - this.sessionId = sessionId; - } - this.distributedObject.setSessionId(this.sessionId); - } - - // 调用端调用startAbilityByCall接口拉起对端Ability - callRemote(context: common.UIAbilityContext) { - if (caller) { - Logger.error(TAG, 'call remote already'); - return; - } - - // 调用genSessionId接口创建一个sessionId、获取对端设备networkId - if (!this.sessionId) { - this.sessionId = distributedDataObject.genSessionId(); - } - Logger.info(TAG, `gen sessionId: ${this.sessionId}`); - let deviceId = getRemoteDeviceId(); - if (deviceId == '') { - Logger.error(TAG, 'no remote device'); - return; - } - Logger.info(TAG, `get remote deviceId: ${deviceId}`); - - let want: Want = { - bundleName: 'com.samples.distributedfilemanager', - abilityName: 'EntryAbility', - deviceId: deviceId, - parameters: { - 'ohos.aafwk.param.callAbilityToForeground': true, - 'distributedSessionId': this.sessionId - } - } - try { - context.startAbilityByCall(want).then((res) => { - if (!res) { - Logger.error(TAG, 'startAbilityByCall failed'); - } - Logger.info(TAG, 'startAbilityByCall success'); - caller = res; - }) - } catch (e) { - let err = e as BusinessError; - Logger.error(TAG, `get remote deviceId error, error code: ${err.code}, error message: ${err.message}`); - } - } - - update(from: string, localFileUriList: string[], disFileUriList: string[], disFileList: string[]) { - Logger.info(TAG, `doUpdate,${from},${localFileUriList},${disFileUriList},${disFileList}`) - this.distributedObject!['from'] = from; - this.distributedObject!['localFileUriList'] = localFileUriList; - this.distributedObject!['disFileUriList'] = disFileUriList; - this.distributedObject!['disFileList'] = disFileList; - } - - clear() { - try{ - let disFileArray: Array = this.distributedObject!["disFileList"]; - disFileArray.forEach( item => { - //判断uri前缀是否有“file+”,如果有则为文件 - if(item.includes("file+")){ - item = item.substring(5, item.length); - fs.unlinkSync(item); - } else { - fs.rmdirSync(item); - } - }) - } catch (err) { - Logger.error(TAG, `delete failed, code is ${err.code}, message is ${err.message}`); - } - this.distributedObject!['from'] = ''; - this.distributedObject!['localFileUriList'] = []; - this.distributedObject!['disFileUriList'] = []; - this.distributedObject!['disFileList'] = []; - } -} - -// 获取可信组网中的设备 -function getRemoteDeviceId() { - let deviceId = ''; - try { - let deviceManager = distributedDeviceManager.createDeviceManager('com.samples.distributedfilemanager'); - let devices = deviceManager.getAvailableDeviceListSync(); - for (let device of devices) { - if (device.networkId) { - deviceId = device.networkId; - } - } - } catch (e) { - let err = e as BusinessError; - Logger.error(TAG, `get remote deviceId error, error code: ${err.code}, error message: ${err.message}`); - } - return deviceId; -} - -export default new DataObject(); +/* + * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import distributedDataObject from '@ohos.data.distributedDataObject'; +import distributedDeviceManager from '@ohos.distributedDeviceManager'; +import fs from '@ohos.file.fs'; +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; +import { Caller } from '@ohos.app.ability.UIAbility'; +import { Logger } from '@ohos/feature-file-manager'; + +const TAG: string = 'DataObjectModel'; +let caller: Caller; + +class DataObject { + public distributedObject: distributedDataObject.DataObject | undefined = undefined; + private sessionId: string = ''; + + createDataObject(context: common.UIAbilityContext, sessionId?: string) { + if (this.distributedObject) { + Logger.error(TAG, 'create dataObject already'); + return; + } + + // 创建分布式数据对象实例 + this.distributedObject = distributedDataObject.create(context, { + from: '', + localFileUriList: [], + disFileUriList: [], + disFileList: [] + }); + + // 设置数据变更监听 + this.distributedObject.on('change', (sessionId: string, fields: Array) => { + Logger.info(TAG, `change, sessionId: ${sessionId}, fields: ${JSON.stringify(fields)}`); + fields.forEach((field) => { + Logger.info(TAG, `${field}: ${this.distributedObject![field]}`); + }); + }); + // 设置同步sessionId加入组网 + if (sessionId) { + this.sessionId = sessionId; + } + this.distributedObject.setSessionId(this.sessionId); + } + + // 调用端调用startAbilityByCall接口拉起对端Ability + callRemote(context: common.UIAbilityContext) { + if (caller) { + Logger.error(TAG, 'call remote already'); + return; + } + + // 调用genSessionId接口创建一个sessionId、获取对端设备networkId + if (!this.sessionId) { + this.sessionId = distributedDataObject.genSessionId(); + } + Logger.info(TAG, `gen sessionId: ${this.sessionId}`); + let deviceId = getRemoteDeviceId(); + if (deviceId == '') { + Logger.error(TAG, 'no remote device'); + return; + } + Logger.info(TAG, `get remote deviceId: ${deviceId}`); + + let want: Want = { + bundleName: 'com.samples.distributedfilemanager', + abilityName: 'EntryAbility', + deviceId: deviceId, + parameters: { + 'ohos.aafwk.param.callAbilityToForeground': true, + 'distributedSessionId': this.sessionId + } + } + try { + context.startAbilityByCall(want).then((res) => { + if (!res) { + Logger.error(TAG, 'startAbilityByCall failed'); + } + Logger.info(TAG, 'startAbilityByCall success'); + caller = res; + }) + } catch (e) { + let err = e as BusinessError; + Logger.error(TAG, `get remote deviceId error, error code: ${err.code}, error message: ${err.message}`); + } + } + + update(from: string, localFileUriList: string[], disFileUriList: string[], disFileList: string[]) { + Logger.info(TAG, `doUpdate,${from},${localFileUriList},${disFileUriList},${disFileList}`) + this.distributedObject!['from'] = from; + this.distributedObject!['localFileUriList'] = localFileUriList; + this.distributedObject!['disFileUriList'] = disFileUriList; + this.distributedObject!['disFileList'] = disFileList; + } + + clear() { + try{ + let disFileArray: Array = this.distributedObject!["disFileList"]; + disFileArray.forEach( item => { + //判断uri前缀是否有“file+”,如果有则为文件 + if(item.includes("file+")){ + item = item.substring(5, item.length); + fs.unlinkSync(item); + } else { + fs.rmdirSync(item); + } + }) + } catch (err) { + Logger.error(TAG, `delete failed, code is ${err.code}, message is ${err.message}`); + } + this.distributedObject!['from'] = ''; + this.distributedObject!['localFileUriList'] = []; + this.distributedObject!['disFileUriList'] = []; + this.distributedObject!['disFileList'] = []; + } +} + +// 获取可信组网中的设备 +function getRemoteDeviceId() { + let deviceId = ''; + try { + let deviceManager = distributedDeviceManager.createDeviceManager('com.samples.distributedfilemanager'); + let devices = deviceManager.getAvailableDeviceListSync(); + for (let device of devices) { + if (device.networkId) { + deviceId = device.networkId; + } + } + } catch (e) { + let err = e as BusinessError; + Logger.error(TAG, `get remote deviceId error, error code: ${err.code}, error message: ${err.message}`); + } + return deviceId; +} + +export default new DataObject(); diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/FsManager.ets b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/FsManager.ets index fcfe40826bebbeffbb09c4b75d36544924a33625..58f5ab50a8051e74845a922cce3ae2192207510c 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/FsManager.ets +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/ets/model/FsManager.ets @@ -1,316 +1,316 @@ -/* - * Copyright (c) 2023-2025 Shenzhen Kaihong Digital Industry Development Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import fs from '@ohos.file.fs'; -import fileuri from '@ohos.file.fileuri'; -import Logger from '../../../../../Library/src/main/ets/utils/Logger'; -import prompt from '@ohos.promptAction'; -import DataObject from './DataObject'; -import { BusinessError } from '@ohos.base'; -import { FileStructure, FileType } from '@ohos/feature-file-manager/src/main/ets/mock/local/FileData'; - -const TAG: string = 'FsManager'; -const BASE_PATH = "/data/storage/el2/base/haps/entry/files"; -let filesDir1 = BASE_PATH + '/test1'; -let filesDir2 = BASE_PATH + '/test2'; -let precastFiles: string[] = [ - "file1.txt", - "file2.txt", - "file3.txt", -]; - -let isCopying: boolean = false; -const fileCopy: string = '-副本'; - -class FsManager { - initFiles(): void { - try { - let res = fs.accessSync(filesDir1); - if (res) { - Logger.info(TAG, `file path: ${filesDir1} exists`); - } else { - Logger.info(TAG, `file path: ${filesDir1} not exists`); - fs.mkdirSync(filesDir1); - } - } catch (error) { - let err: BusinessError = error as BusinessError; - Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); - } - try { - let res = fs.accessSync(filesDir2); - if (res) { - Logger.info(TAG, `file path: ${filesDir2} exists`); - } else { - Logger.info(TAG, `file path: ${filesDir2} not exists`); - fs.mkdirSync(filesDir2); - } - } catch (error) { - let err: BusinessError = error as BusinessError; - Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); - } - - for (let i = 0; i < precastFiles.length; i++) { - let fileName = filesDir1 + "/" + precastFiles[i]; - Logger.info(TAG, `The file name: ${fileName}`); - try { - let res = fs.accessSync(fileName); - if (res) { - Logger.info(TAG, `file: ${fileName} exists!.`); - } else { - Logger.info(TAG, `file: ${fileName} not exists, will create it!.`); - let file = fs.openSync(fileName, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - fs.writeSync(file.fd, 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1' + - 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + - 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + - 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + - 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + - 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test'); - fs.closeSync(file); - } - } catch (error) { - let err: BusinessError = error as BusinessError; - Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); - } - } - - let fileName = filesDir2 + "/" + "file4.txt"; - try { - let res = fs.accessSync(fileName); - if (res) { - Logger.info(TAG, `file: ${fileName} exists!.`); - } else { - Logger.info(TAG, `file: ${fileName} not exists, will create it!.`); - let file = fs.openSync(fileName, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - fs.writeSync(file.fd, 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + - 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + - 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + - 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + - 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + - 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4'); - fs.closeSync(file); - } - } catch (error) { - let err: BusinessError = error as BusinessError; - Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); - } - } - - listFiles(dir: string): Array { - let files: string[] = []; - let context = getContext(this) as common.UIAbilityContext; - let fileDir = (dir == 'files' ? context.filesDir : (dir == 'temp' ? context.tempDir : context.cacheDir)); - Logger.info(TAG, `listFiles fileDir =${fileDir}`); - try { - files = fs.listFileSync(fileDir); - Logger.info(TAG, `listFiles listFileSync =${JSON.stringify(files)}`); - } catch (err) { - Logger.info(TAG, `listFiles err =${JSON.stringify(err)}`); - } - return files; - } - - copyFilesToDistributedDir(deviceId: string, needMoveFiles: Array, disPathInSandbox: string) { - let distributedUri0 = fileuri.getUriFromPath(disPathInSandbox); - let localFileUriList: Array = []; - let disFileUriList: Array = []; - let disFileList: Array = []; - let distributedUri = ''; - needMoveFiles.forEach((file: FileType) => { - Logger.info(TAG, `in copyToDistributedDir--file type : ${file.type}`); - //用于粘贴完后的clear动作中 - let disFilePath = disPathInSandbox + "/" + file.fileName; - //type: 1 directory,type 2 file - let localSrcUri = fileuri.getUriFromPath(file.filePath); - //如果是文件夹 - if (file.type === 1) { - distributedUri = distributedUri0 + "/" + file.fileName; - this.innerCopyFilesToDistributedDir(localSrcUri, distributedUri0); - } else if (file.type === 2) { //处理Uri,如果是文件类型,需另外处理,前缀增加"file+",用分布式对象进行传输 - const fileName = localSrcUri.split('/').pop(); - distributedUri = distributedUri0 + "/" + fileName; - this.innerCopyFilesToDistributedDir(localSrcUri, distributedUri); - localSrcUri = "file+" + localSrcUri; - distributedUri = "file+" + distributedUri; - } else { - Logger.error(TAG, `this is not file or directory`); - } - // to update DataObject - localFileUriList.push(localSrcUri); - disFileUriList.push(localSrcUri); - disFileList.push(disFilePath); - }) - DataObject.update(deviceId, localFileUriList, disFileUriList, disFileList); - } - - //复制到剪切板,不弹进度条 - innerCopyFilesToDistributedDir(from: string, to: string) { - Logger.info(TAG, `copyToDistributedDir--from: ${from}`); - Logger.info(TAG, `copyToDistributedDir--to: ${to}`); - try { - // copy - let progressListener: fs.ProgressListener = (progress: fs.Progress) => { - Logger.info(TAG, "progressSize: " + progress.processedSize + ", totalSize: " + progress.totalSize); - }; - let options: fs.CopyOptions = { - "progressListener": progressListener - }; - // 进行拷贝 - fs.copy(from, to, options).then(() => { - Logger.info("Succeeded in copying. "); - }).catch((err: BusinessError) => { - Logger.info(`Failed to copy. Code: ${err.code}, message: ${err.message}`); - return prompt.showToast({ message: $r('app.string.label_copy2disfailed') }); - }) - } catch (error) { - let err: BusinessError = error as BusinessError; - Logger.error(TAG, `Failed to set paste data. Code: ${err.code}, message: ${err.message}`); - } - } - - pasteFromDistributedDir(deviceId: string, directoryPath: string, fileData: Array) { - let localDstUri = fileuri.getUriFromPath(directoryPath); - - if (DataObject.distributedObject!["disFileUriList"].length === 0) { - return prompt.showToast({ message: $r('app.string.label_nodata') }); - } - //本地拷贝:文件需进行重命名操作 - if (deviceId == DataObject.distributedObject!["from"]) { - let localFileArray: Array = DataObject.distributedObject!["localFileUriList"]; - let newFileName: string = ''; - localFileArray.forEach(item => { - //判断uri前缀是否有“file+”,如果是文件类型,去掉“file+”前缀,在localDstUri后面加上文件名称 - if (item.includes("file+")) { - item = item.substring(5, item.length); - let fileName: string | undefined = item.split('/').pop(); - if (fileName) { - newFileName = decodeURIComponent(fileName); - } else { - return; - } - //判断本地是否有同名文件,有则重命名 - fileData.forEach(file => { - //有同名文件 - if (decodeURIComponent(file.name).includes(newFileName)) { - //extension 文件后缀 - let extension: string = newFileName.slice((newFileName.lastIndexOf(".") - 1 >>> 0) + 2); - if (extension) { - let fileParts = newFileName.split('.'); - newFileName = fileParts[0] + fileCopy + '.' + fileParts[1]; - } else { - newFileName = newFileName + fileCopy; - } - } - }) - } - this.innerPasteFromDistributedDir(item, localDstUri + newFileName); - }) - } else { //跨设备拷贝 - let disFileUriArray: Array = DataObject.distributedObject!["disFileUriList"]; - disFileUriArray.forEach(item => { - if (item.includes("file+")) { - item = item.substring(5, item.length); - let fileName: string | undefined = item.split('/').pop(); - let newFileName: string = ''; - if (fileName) { - newFileName = decodeURIComponent(fileName); - //判断是否有同名文件,有则重命名 - fileData.forEach(file => { - //有同名文件 - if (decodeURIComponent(file.name).includes(newFileName)) { - //extension 文件后缀 - let extension: string = newFileName.slice((newFileName.lastIndexOf(".") - 1 >>> 0) + 2); - if (extension) { - let fileParts = newFileName.split('.'); - newFileName = fileParts[0] + fileCopy + '.' + fileParts[1]; - } else { - newFileName = newFileName + fileCopy; - } - } - }) - } else { - return; - } - this.innerPasteFromDistributedDir(item, localDstUri + newFileName); - } else { - this.innerPasteFromDistributedDir(item, localDstUri); - } - }) - } - } - - //粘贴,弹进度条 - innerPasteFromDistributedDir(from: string, to: string) { - Logger.info(TAG, `innerPasteFromDistributedDir--from: ${from}`); - Logger.info(TAG, `innerPasteFromDistributedDir--to: ${to}`); - try { - // 定义拷贝回调 - let totalProgress: number = 0; - let totalCopySize: number = 0; - let copiedSize: number = 0; - let lastCopiedSize: number = 0; - let firstCopy = true; - let progressListener: fs.ProgressListener = (progress: fs.Progress) => { - Logger.info(TAG, "progressSize: " + progress.processedSize + ", totalSize: " + progress.totalSize); - //第一次进入回调 - if (firstCopy === true) { - Logger.info(TAG, "firstCopy"); - totalCopySize += progress.totalSize; - copiedSize += progress.processedSize; - lastCopiedSize = progress.processedSize; - firstCopy = false; - } else { - copiedSize -= lastCopiedSize; - copiedSize += progress.processedSize; - lastCopiedSize = progress.processedSize; - } - - totalProgress = Number(((copiedSize / totalCopySize) * 100).toFixed(0)); - AppStorage.setOrCreate('progress', totalProgress); - Logger.info(TAG, "totalCopySize: " + totalCopySize + ", copiedSize: " + copiedSize); - if (totalCopySize != copiedSize) { - isCopying = true; - AppStorage.setOrCreate('isCopying', true); - } else { - Logger.info(TAG, "totalCopySize == copiedSize,Successfully coppied"); - isCopying = false; - AppStorage.setOrCreate('isCopying', false); - AppStorage.setOrCreate('flashPage',!AppStorage.get('flashPage')); - DataObject.clear(); - return prompt.showToast({ message: $r('app.string.label_dirupdate') }); - } - }; - let options: fs.CopyOptions = { - "progressListener": progressListener - }; - // 进行拷贝 - fs.copy(from, to, options).then(() => { - isCopying = false; - AppStorage.setOrCreate('isCopying', false); - Logger.info(TAG, "Succeeded in copying. "); - }).catch((err: BusinessError) => { - isCopying = false; - AppStorage.setOrCreate('isCopying', false); - Logger.info(TAG, `Failed to copy. Code: ${err.code}, message: ${err.message}`); - DataObject.clear(); - return prompt.showToast({ message: $r('app.string.label_copyfailed') }); - }) - } catch (err) { - Logger.error(TAG, `Failed to getData. Code: ${err.code}, message: ${err.message}`); - } - } -} - -export default new FsManager(); +/* + * Copyright (c) 2023-2025 Shenzhen Kaihong Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import fs from '@ohos.file.fs'; +import fileuri from '@ohos.file.fileuri'; +import Logger from '../../../../../Library/src/main/ets/utils/Logger'; +import prompt from '@ohos.promptAction'; +import DataObject from './DataObject'; +import { BusinessError } from '@ohos.base'; +import { FileStructure, FileType } from '@ohos/feature-file-manager/src/main/ets/mock/local/FileData'; + +const TAG: string = 'FsManager'; +const BASE_PATH = "/data/storage/el2/base/haps/entry/files"; +let filesDir1 = BASE_PATH + '/test1'; +let filesDir2 = BASE_PATH + '/test2'; +let precastFiles: string[] = [ + "file1.txt", + "file2.txt", + "file3.txt", +]; + +let isCopying: boolean = false; +const fileCopy: string = '-副本'; + +class FsManager { + initFiles(): void { + try { + let res = fs.accessSync(filesDir1); + if (res) { + Logger.info(TAG, `file path: ${filesDir1} exists`); + } else { + Logger.info(TAG, `file path: ${filesDir1} not exists`); + fs.mkdirSync(filesDir1); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); + } + try { + let res = fs.accessSync(filesDir2); + if (res) { + Logger.info(TAG, `file path: ${filesDir2} exists`); + } else { + Logger.info(TAG, `file path: ${filesDir2} not exists`); + fs.mkdirSync(filesDir2); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); + } + + for (let i = 0; i < precastFiles.length; i++) { + let fileName = filesDir1 + "/" + precastFiles[i]; + Logger.info(TAG, `The file name: ${fileName}`); + try { + let res = fs.accessSync(fileName); + if (res) { + Logger.info(TAG, `file: ${fileName} exists!.`); + } else { + Logger.info(TAG, `file: ${fileName} not exists, will create it!.`); + let file = fs.openSync(fileName, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1' + + 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + + 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + + 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + + 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test' + + 'test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1test'); + fs.closeSync(file); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); + } + } + + let fileName = filesDir2 + "/" + "file4.txt"; + try { + let res = fs.accessSync(fileName); + if (res) { + Logger.info(TAG, `file: ${fileName} exists!.`); + } else { + Logger.info(TAG, `file: ${fileName} not exists, will create it!.`); + let file = fs.openSync(fileName, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + fs.writeSync(file.fd, 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + + 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + + 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + + 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + + 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4' + + 'test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4test4'); + fs.closeSync(file); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + Logger.error(TAG, "accessSync failed with error message: " + err.message + ", error code: " + err.code); + } + } + + listFiles(dir: string): Array { + let files: string[] = []; + let context = getContext(this) as common.UIAbilityContext; + let fileDir = (dir == 'files' ? context.filesDir : (dir == 'temp' ? context.tempDir : context.cacheDir)); + Logger.info(TAG, `listFiles fileDir =${fileDir}`); + try { + files = fs.listFileSync(fileDir); + Logger.info(TAG, `listFiles listFileSync =${JSON.stringify(files)}`); + } catch (err) { + Logger.info(TAG, `listFiles err =${JSON.stringify(err)}`); + } + return files; + } + + copyFilesToDistributedDir(deviceId: string, needMoveFiles: Array, disPathInSandbox: string) { + let distributedUri0 = fileuri.getUriFromPath(disPathInSandbox); + let localFileUriList: Array = []; + let disFileUriList: Array = []; + let disFileList: Array = []; + let distributedUri = ''; + needMoveFiles.forEach((file: FileType) => { + Logger.info(TAG, `in copyToDistributedDir--file type : ${file.type}`); + //用于粘贴完后的clear动作中 + let disFilePath = disPathInSandbox + "/" + file.fileName; + //type: 1 directory,type 2 file + let localSrcUri = fileuri.getUriFromPath(file.filePath); + //如果是文件夹 + if (file.type === 1) { + distributedUri = distributedUri0 + "/" + file.fileName; + this.innerCopyFilesToDistributedDir(localSrcUri, distributedUri0); + } else if (file.type === 2) { //处理Uri,如果是文件类型,需另外处理,前缀增加"file+",用分布式对象进行传输 + const fileName = localSrcUri.split('/').pop(); + distributedUri = distributedUri0 + "/" + fileName; + this.innerCopyFilesToDistributedDir(localSrcUri, distributedUri); + localSrcUri = "file+" + localSrcUri; + distributedUri = "file+" + distributedUri; + } else { + Logger.error(TAG, `this is not file or directory`); + } + // to update DataObject + localFileUriList.push(localSrcUri); + disFileUriList.push(localSrcUri); + disFileList.push(disFilePath); + }) + DataObject.update(deviceId, localFileUriList, disFileUriList, disFileList); + } + + //复制到剪切板,不弹进度条 + innerCopyFilesToDistributedDir(from: string, to: string) { + Logger.info(TAG, `copyToDistributedDir--from: ${from}`); + Logger.info(TAG, `copyToDistributedDir--to: ${to}`); + try { + // copy + let progressListener: fs.ProgressListener = (progress: fs.Progress) => { + Logger.info(TAG, "progressSize: " + progress.processedSize + ", totalSize: " + progress.totalSize); + }; + let options: fs.CopyOptions = { + "progressListener": progressListener + }; + // 进行拷贝 + fs.copy(from, to, options).then(() => { + Logger.info("Succeeded in copying. "); + }).catch((err: BusinessError) => { + Logger.info(`Failed to copy. Code: ${err.code}, message: ${err.message}`); + return prompt.showToast({ message: $r('app.string.label_copy2disfailed') }); + }) + } catch (error) { + let err: BusinessError = error as BusinessError; + Logger.error(TAG, `Failed to set paste data. Code: ${err.code}, message: ${err.message}`); + } + } + + pasteFromDistributedDir(deviceId: string, directoryPath: string, fileData: Array) { + let localDstUri = fileuri.getUriFromPath(directoryPath); + + if (DataObject.distributedObject!["disFileUriList"].length === 0) { + return prompt.showToast({ message: $r('app.string.label_nodata') }); + } + //本地拷贝:文件需进行重命名操作 + if (deviceId == DataObject.distributedObject!["from"]) { + let localFileArray: Array = DataObject.distributedObject!["localFileUriList"]; + let newFileName: string = ''; + localFileArray.forEach(item => { + //判断uri前缀是否有“file+”,如果是文件类型,去掉“file+”前缀,在localDstUri后面加上文件名称 + if (item.includes("file+")) { + item = item.substring(5, item.length); + let fileName: string | undefined = item.split('/').pop(); + if (fileName) { + newFileName = decodeURIComponent(fileName); + } else { + return; + } + //判断本地是否有同名文件,有则重命名 + fileData.forEach(file => { + //有同名文件 + if (decodeURIComponent(file.name).includes(newFileName)) { + //extension 文件后缀 + let extension: string = newFileName.slice((newFileName.lastIndexOf(".") - 1 >>> 0) + 2); + if (extension) { + let fileParts = newFileName.split('.'); + newFileName = fileParts[0] + fileCopy + '.' + fileParts[1]; + } else { + newFileName = newFileName + fileCopy; + } + } + }) + } + this.innerPasteFromDistributedDir(item, localDstUri + newFileName); + }) + } else { //跨设备拷贝 + let disFileUriArray: Array = DataObject.distributedObject!["disFileUriList"]; + disFileUriArray.forEach(item => { + if (item.includes("file+")) { + item = item.substring(5, item.length); + let fileName: string | undefined = item.split('/').pop(); + let newFileName: string = ''; + if (fileName) { + newFileName = decodeURIComponent(fileName); + //判断是否有同名文件,有则重命名 + fileData.forEach(file => { + //有同名文件 + if (decodeURIComponent(file.name).includes(newFileName)) { + //extension 文件后缀 + let extension: string = newFileName.slice((newFileName.lastIndexOf(".") - 1 >>> 0) + 2); + if (extension) { + let fileParts = newFileName.split('.'); + newFileName = fileParts[0] + fileCopy + '.' + fileParts[1]; + } else { + newFileName = newFileName + fileCopy; + } + } + }) + } else { + return; + } + this.innerPasteFromDistributedDir(item, localDstUri + newFileName); + } else { + this.innerPasteFromDistributedDir(item, localDstUri); + } + }) + } + } + + //粘贴,弹进度条 + innerPasteFromDistributedDir(from: string, to: string) { + Logger.info(TAG, `innerPasteFromDistributedDir--from: ${from}`); + Logger.info(TAG, `innerPasteFromDistributedDir--to: ${to}`); + try { + // 定义拷贝回调 + let totalProgress: number = 0; + let totalCopySize: number = 0; + let copiedSize: number = 0; + let lastCopiedSize: number = 0; + let firstCopy = true; + let progressListener: fs.ProgressListener = (progress: fs.Progress) => { + Logger.info(TAG, "progressSize: " + progress.processedSize + ", totalSize: " + progress.totalSize); + //第一次进入回调 + if (firstCopy === true) { + Logger.info(TAG, "firstCopy"); + totalCopySize += progress.totalSize; + copiedSize += progress.processedSize; + lastCopiedSize = progress.processedSize; + firstCopy = false; + } else { + copiedSize -= lastCopiedSize; + copiedSize += progress.processedSize; + lastCopiedSize = progress.processedSize; + } + + totalProgress = Number(((copiedSize / totalCopySize) * 100).toFixed(0)); + AppStorage.setOrCreate('progress', totalProgress); + Logger.info(TAG, "totalCopySize: " + totalCopySize + ", copiedSize: " + copiedSize); + if (totalCopySize != copiedSize) { + isCopying = true; + AppStorage.setOrCreate('isCopying', true); + } else { + Logger.info(TAG, "totalCopySize == copiedSize,Successfully coppied"); + isCopying = false; + AppStorage.setOrCreate('isCopying', false); + AppStorage.setOrCreate('flashPage',!AppStorage.get('flashPage')); + DataObject.clear(); + return prompt.showToast({ message: $r('app.string.label_dirupdate') }); + } + }; + let options: fs.CopyOptions = { + "progressListener": progressListener + }; + // 进行拷贝 + fs.copy(from, to, options).then(() => { + isCopying = false; + AppStorage.setOrCreate('isCopying', false); + Logger.info(TAG, "Succeeded in copying. "); + }).catch((err: BusinessError) => { + isCopying = false; + AppStorage.setOrCreate('isCopying', false); + Logger.info(TAG, `Failed to copy. Code: ${err.code}, message: ${err.message}`); + DataObject.clear(); + return prompt.showToast({ message: $r('app.string.label_copyfailed') }); + }) + } catch (err) { + Logger.error(TAG, `Failed to getData. Code: ${err.code}, message: ${err.message}`); + } + } +} + +export default new FsManager(); diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/resources/rawfile/arkdata/utd/utd-adt.json b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/resources/rawfile/arkdata/utd/utd-adt.json index b4486d5c868c2bb77668f65ef5320c7310ae10f3..1e7e1fda4db725e8fac8a9bc63f61e5bd4ef35a8 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/resources/rawfile/arkdata/utd/utd-adt.json +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/entry/src/main/resources/rawfile/arkdata/utd/utd-adt.json @@ -1,27 +1,27 @@ -{ - "UniformDataTypeDeclarations": [{ - "TypeId": "com.example.UTDType.image", - "BelongingToTypes": ["general.image"], - "FilenameExtensions": [".myImage", ".khImage"], - "MIMETypes": ["application/my-document", "application/my-doc"], - "Description": "My Image.", - "ReferenceURL": "" - }, - { - "TypeId": "com.example.UTDType.audio", - "BelongingToTypes": ["general.audio"], - "FilenameExtensions": [".myAudio", ".khAudio"], - "MIMETypes": ["application/my-document", "application/my-doc"], - "Description": "My audio.", - "ReferenceURL": "" - }, - { - "TypeId": "com.example.UTDType.video", - "BelongingToTypes": ["general.video"], - "FilenameExtensions": [".myVideo", ".khVideo"], - "MIMETypes": ["application/my-document", "application/my-doc"], - "Description": "My video.", - "ReferenceURL": "" - } - ] +{ + "UniformDataTypeDeclarations": [{ + "TypeId": "com.example.UTDType.image", + "BelongingToTypes": ["general.image"], + "FilenameExtensions": [".myImage", ".khImage"], + "MIMETypes": ["application/my-document", "application/my-doc"], + "Description": "My Image.", + "ReferenceURL": "" + }, + { + "TypeId": "com.example.UTDType.audio", + "BelongingToTypes": ["general.audio"], + "FilenameExtensions": [".myAudio", ".khAudio"], + "MIMETypes": ["application/my-document", "application/my-doc"], + "Description": "My audio.", + "ReferenceURL": "" + }, + { + "TypeId": "com.example.UTDType.video", + "BelongingToTypes": ["general.video"], + "FilenameExtensions": [".myVideo", ".khVideo"], + "MIMETypes": ["application/my-document", "application/my-doc"], + "Description": "My video.", + "ReferenceURL": "" + } + ] } \ No newline at end of file diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/hvigor/hvigor-config.json5 b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/hvigor/hvigor-config.json5 index 2e97c542886b3a400b21582dc62d628ad25243f1..a2eb20c67c35c8b1b6d7f34b63dfd44d5d09505e 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/hvigor/hvigor-config.json5 +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.1.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.1.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.1.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.1.2" + } } \ No newline at end of file diff --git a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/oh-package.json5 b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/oh-package.json5 index 3762fe6b2a97a0e2cfe64c08744a2c2eb59bd5a2..368c840c89b3a0550d4bcb58ce0a86ad228b487c 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedFilemanager/oh-package.json5 +++ b/code/SuperFeature/DistributedAppDev/DistributedFilemanager/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myfile", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "myfile", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SuperFeature/DistributedAppDev/DistributedRdb/entry/src/main/ets/model/GlobalContext.ts b/code/SuperFeature/DistributedAppDev/DistributedRdb/entry/src/main/ets/model/GlobalContext.ts index 91a43d675a4ab4c963415e55bc26f05e3346a4b1..7f505311b3501cb734e7c00df6eb3dfcd03bd5bc 100644 --- a/code/SuperFeature/DistributedAppDev/DistributedRdb/entry/src/main/ets/model/GlobalContext.ts +++ b/code/SuperFeature/DistributedAppDev/DistributedRdb/entry/src/main/ets/model/GlobalContext.ts @@ -1,36 +1,36 @@ -// 构造单例对象 -/* - * Copyright (c) 2023 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 class GlobalContext { - private constructor() {} - private static instance: GlobalContext; - private _objects = new Map(); - - public static getContext(): GlobalContext { - if (!GlobalContext.instance) { - GlobalContext.instance = new GlobalContext(); - } - return GlobalContext.instance; - } - - getObject(value: string): Object | undefined { - return this._objects.get(value); - } - - setObject(key: string, objectClass: Object): void { - this._objects.set(key, objectClass); - } -} +// 构造单例对象 +/* + * Copyright (c) 2023 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 class GlobalContext { + private constructor() {} + private static instance: GlobalContext; + private _objects = new Map(); + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getObject(value: string): Object | undefined { + return this._objects.get(value); + } + + setObject(key: string, objectClass: Object): void { + this._objects.set(key, objectClass); + } +} diff --git a/code/SuperFeature/MultiDeviceAppDev/AdaptiveCapabilities/entry/src/main/ets/pages/typicalScene/multiScene/data/applications/Applications.ets b/code/SuperFeature/MultiDeviceAppDev/AdaptiveCapabilities/entry/src/main/ets/pages/typicalScene/multiScene/data/applications/Applications.ets index 20b11b8c036add8c620009d4dd77d52bcf0e3bfc..1739c4e980744f64b41e9678edcc86a969deb067 100644 --- a/code/SuperFeature/MultiDeviceAppDev/AdaptiveCapabilities/entry/src/main/ets/pages/typicalScene/multiScene/data/applications/Applications.ets +++ b/code/SuperFeature/MultiDeviceAppDev/AdaptiveCapabilities/entry/src/main/ets/pages/typicalScene/multiScene/data/applications/Applications.ets @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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 ApplicationsData: Resource [] = [ - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application'), - $r('app.string.multiScene_application') +/* + * Copyright (c) 2023 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 ApplicationsData: Resource [] = [ + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application'), + $r('app.string.multiScene_application') ] \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/app.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/app.json5 index c295ae892aa53262dcd7335dac923b5b815e0ea4..39d910e4c564c3be83dd4b3fc4d58eba773e5ff6 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/app.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.abilityFeatureSystem", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.abilityFeatureSystem", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/resources/base/element/string.json b/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/resources/base/element/string.json index 329e7ac73e2e2e59a5a9db9c66328e71d1392f4b..84d99212a1b145d139266bb4d40a82739d2fc8df 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AbilityFeatureSystem" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AbilityFeatureSystem" + } + ] +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/README_zh.md b/code/SystemFeature/Ability/AbilityFeatureSystem/README_zh.md index c2c342e7d16e042f294120d08c820e298ce8c4fb..c5f6b671cfe5e77201d155b6503e9a90ca133584 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/README_zh.md +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/README_zh.md @@ -1,113 +1,113 @@ -# 基础能力增强 - -### 介绍 - -本示例使用 [ohos.app.ability.appManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-appManager-sys.md), [UIAbilityContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext-sys.md) , [UIExtensionContentSession](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-uiExtensionContentSession-sys.md) 等接口实现了以下功能: - -1. 提供查询单个应用是否正在运行接口; - -2. 新增系统接口请求创建模系统或模应用的UIExtension; - -3. UIExtension支持同步返回数据的能力; - -4. UIExtension提供StartAsCaller接口。 - -### 效果预览 - -| 主页面 | 弹出状态Toast | 同步数据页面 | UIExtension启动页 | -|:------------------------------------------------:|:-----------------------------------------------------:|:----------------------------------------------------:|:------------------------------------------------------:| -| | | | | - -使用说明 - -1.应用查询单个应用是否正在运行的能力 - -点击'查询应用状态'的ListItem,弹出Toast提示'当前应用运行中' - -2.UIExtension创建模系统或模应用 - -点击'创建模系统'的ListItem,弹出UIExtension的页面弹窗 - -3.UIExtension支持同步返回数据的能力 - -点击'同步发送数据'的ListItem,进入到新页面再次点击'同步发送数据'的ListItem,UIAbility部分弹出Toast提示'HomeAbility -onReceive data from UIExtensionAbility',UIExtensionAbility 部分弹出Toast提示'UIExtensionAbility onReceive data from -HomeAbility' - -4.UIExtension提供启动AbilityAsCaller的能力 - -点击'启动AbilityAsCaller'的ListItem,应用启动NewAbility - -5.UIExtension提供startAbilityAsCaller的能力 - -点击启动'启动UIExtensionAbility'的ListItem,进入到新页面,在新页面点击'启动AbilityAsCaller'的ListItem,应用启动NewAbility - -### 工程目录 - -``` -entry/src/main/ets/ -|---entryability -| |---EntryAbility.ets // 首页的Ability -|---pages -| |---Index.ets // 首页 -| |---Ext.ets // UIExtensionAbility的展示页 -| |---NewExt.ets // 被启动的UIExtensionAbility的页面 -| |---New.ets // 被启动UIAbility的展示页 -| |---Transit.ets // UIExtensionComponent加载NewUIExtAbility的页面 -| |---SendSync.ets // UIExtensionComponent加载SendSyncExtAbility的页面 -| |---SendSyncExt.ets // 同步数据UIExtensionAbility的展示页 -|---uiextability -| |---UIExtAbility.ets // UIExtensionAbility(用于验证新接口使用) -|---sendsyncextability -| |---SendSyncExtAbility.ets // UIExtensionAbility(用于验证新接口使用) -|---newuiextability -| |---NewUIExtAbility.ets // UIExtensionAbility(用于验证新接口使用) -|---newability -| |---NewAbility.ets // 被启动的UIAbility(验证新接口启动使用) -|---utils // 工具 -| |---Logger.ets // 日志工具 -``` - -### 具体实现 - -- 应用查询单个应用是否正在运行的能力,通过appManager调用isApplicationRunning(bundleName: string, callback: - AsyncCallback): void方法查询应用状态, 源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) -- UIExtension创建模系统或模应用,通过UIAbilityContext调用requestModalUIExtension(pickerWant: Want, callback: - AsyncCallback): void方法拉起UIExtensionAbility, 源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) -- UIExtension支持同步返回数据的能力,通过UIExtensionProxy调用sendSync(data: { [key: string]: Object }): { [key: string]: - Object }接口实现,源码参考:[SendSync.ets](entry/src/main/ets/pages/SendSync.ets) -- UIExtension提供startAbilityAsCaller的能力,通过UIExtensionContentSession调用startAbilityAsCaller(want: Want, callback: - AsyncCallback): void接口实现,源码参考:[Ext.ets](entry/src/main/ets/pages/Ext.ets) - -### 相关权限 - -[ohos.permission.GET_RUNNING_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_running_info) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568。 - -2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.5.1; - -3.本示例涉及使用系统接口:appManager.isApplicationRunning ,UIAbilityContext.requestModalUIExtension, -UIAbilityContext.startAbilityAsCaller,UIExtensionContentSession.startAbilityAsCaller,UIExtensionProxy.sendSync -需要手动替换Full SDK才能编译通过; - -4.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; - -5.本示例涉及[ohos.permission.GET_RUNNING_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_running_info)权限为 system_basic级别,需要配置高权限签名; - -### 下载 - -```shell -git init -git config core.sparsecheckout true -echo code/SystemFeature/Ability/AbilityFeatureSystem/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# 基础能力增强 + +### 介绍 + +本示例使用 [ohos.app.ability.appManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-appManager-sys.md), [UIAbilityContext](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiAbilityContext-sys.md) , [UIExtensionContentSession](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-uiExtensionContentSession-sys.md) 等接口实现了以下功能: + +1. 提供查询单个应用是否正在运行接口; + +2. 新增系统接口请求创建模系统或模应用的UIExtension; + +3. UIExtension支持同步返回数据的能力; + +4. UIExtension提供StartAsCaller接口。 + +### 效果预览 + +| 主页面 | 弹出状态Toast | 同步数据页面 | UIExtension启动页 | +|:------------------------------------------------:|:-----------------------------------------------------:|:----------------------------------------------------:|:------------------------------------------------------:| +| | | | | + +使用说明 + +1.应用查询单个应用是否正在运行的能力 + +点击'查询应用状态'的ListItem,弹出Toast提示'当前应用运行中' + +2.UIExtension创建模系统或模应用 + +点击'创建模系统'的ListItem,弹出UIExtension的页面弹窗 + +3.UIExtension支持同步返回数据的能力 + +点击'同步发送数据'的ListItem,进入到新页面再次点击'同步发送数据'的ListItem,UIAbility部分弹出Toast提示'HomeAbility +onReceive data from UIExtensionAbility',UIExtensionAbility 部分弹出Toast提示'UIExtensionAbility onReceive data from +HomeAbility' + +4.UIExtension提供启动AbilityAsCaller的能力 + +点击'启动AbilityAsCaller'的ListItem,应用启动NewAbility + +5.UIExtension提供startAbilityAsCaller的能力 + +点击启动'启动UIExtensionAbility'的ListItem,进入到新页面,在新页面点击'启动AbilityAsCaller'的ListItem,应用启动NewAbility + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets // 首页的Ability +|---pages +| |---Index.ets // 首页 +| |---Ext.ets // UIExtensionAbility的展示页 +| |---NewExt.ets // 被启动的UIExtensionAbility的页面 +| |---New.ets // 被启动UIAbility的展示页 +| |---Transit.ets // UIExtensionComponent加载NewUIExtAbility的页面 +| |---SendSync.ets // UIExtensionComponent加载SendSyncExtAbility的页面 +| |---SendSyncExt.ets // 同步数据UIExtensionAbility的展示页 +|---uiextability +| |---UIExtAbility.ets // UIExtensionAbility(用于验证新接口使用) +|---sendsyncextability +| |---SendSyncExtAbility.ets // UIExtensionAbility(用于验证新接口使用) +|---newuiextability +| |---NewUIExtAbility.ets // UIExtensionAbility(用于验证新接口使用) +|---newability +| |---NewAbility.ets // 被启动的UIAbility(验证新接口启动使用) +|---utils // 工具 +| |---Logger.ets // 日志工具 +``` + +### 具体实现 + +- 应用查询单个应用是否正在运行的能力,通过appManager调用isApplicationRunning(bundleName: string, callback: + AsyncCallback): void方法查询应用状态, 源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) +- UIExtension创建模系统或模应用,通过UIAbilityContext调用requestModalUIExtension(pickerWant: Want, callback: + AsyncCallback): void方法拉起UIExtensionAbility, 源码参考:[Index.ets](entry/src/main/ets/pages/Index.ets) +- UIExtension支持同步返回数据的能力,通过UIExtensionProxy调用sendSync(data: { [key: string]: Object }): { [key: string]: + Object }接口实现,源码参考:[SendSync.ets](entry/src/main/ets/pages/SendSync.ets) +- UIExtension提供startAbilityAsCaller的能力,通过UIExtensionContentSession调用startAbilityAsCaller(want: Want, callback: + AsyncCallback): void接口实现,源码参考:[Ext.ets](entry/src/main/ets/pages/Ext.ets) + +### 相关权限 + +[ohos.permission.GET_RUNNING_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_running_info) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568。 + +2.本示例为Stage模型,支持API11版本SDK,版本号:4.1.5.1; + +3.本示例涉及使用系统接口:appManager.isApplicationRunning ,UIAbilityContext.requestModalUIExtension, +UIAbilityContext.startAbilityAsCaller,UIExtensionContentSession.startAbilityAsCaller,UIExtensionProxy.sendSync +需要手动替换Full SDK才能编译通过; + +4.本示例需要使用DevEco Studio 3.1.1 Release (Build Version: 3.1.0.501, built on June 20, 2023)才可编译运行; + +5.本示例涉及[ohos.permission.GET_RUNNING_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_running_info)权限为 system_basic级别,需要配置高权限签名; + +### 下载 + +```shell +git init +git config core.sparsecheckout true +echo code/SystemFeature/Ability/AbilityFeatureSystem/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` + diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/build-profile.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/build-profile.json5 index 6e4824ee32c74ed2c8150843557de85a879e7c39..51d43b29fefc5fa4622edbb868c588525238f272 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/build-profile.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/build-profile.json5 @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2023 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": 11, - "compatibleSdkVersion": 11, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 11, + "compatibleSdkVersion": 11, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/build-profile.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/build-profile.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/oh-package.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/oh-package.json5 index 4be95c59ce0dede7a66d6fcb2e3018c8011f838a..3fbe67bbf8193c883bab1ccea7be318bc3a65bdb 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/oh-package.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/entryability/EntryAbility.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/entryability/EntryAbility.ets index f640336e76d40da47dc2cfe81cb8bf326a3e8efc..d759f4f0a6333fc2ba066566399d9decaf3cef4e 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; -import { logger } from '../util/Logger'; - -export default class EntryAbility extends UIAbility { - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - windowStage.loadContent('pages/Index', (err: BusinessError) => { - }); - windowStage.getMainWindow((err, windowClass) => { - if (err.code) { - return; - } - windowClass.setWindowLayoutFullScreen(true); - }) - logger.info(`EntryAbility onWindowStageCreate`); - } - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - AppStorage.setOrCreate('want', want); - AppStorage.setOrCreate('launchParam', launchParam); - logger.info(`EntryAbility onCreate ${want.bundleName},${launchParam.launchReason}`); - } - - onDestroy() { - logger.info(`EntryAbility onDestroy`); - } - - onWindowStageDestroy() { - logger.info(`EntryAbility onWindowStageDestroy`); - // Main window is destroyed, release UI related resources - } - - onForeground() { - logger.info(`EntryAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`EntryAbility onBackground`); - // Ability has back to background - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; +import { logger } from '../util/Logger'; + +export default class EntryAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + windowStage.loadContent('pages/Index', (err: BusinessError) => { + }); + windowStage.getMainWindow((err, windowClass) => { + if (err.code) { + return; + } + windowClass.setWindowLayoutFullScreen(true); + }) + logger.info(`EntryAbility onWindowStageCreate`); + } + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + AppStorage.setOrCreate('want', want); + AppStorage.setOrCreate('launchParam', launchParam); + logger.info(`EntryAbility onCreate ${want.bundleName},${launchParam.launchReason}`); + } + + onDestroy() { + logger.info(`EntryAbility onDestroy`); + } + + onWindowStageDestroy() { + logger.info(`EntryAbility onWindowStageDestroy`); + // Main window is destroyed, release UI related resources + } + + onForeground() { + logger.info(`EntryAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`EntryAbility onBackground`); + // Ability has back to background + } +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newability/NewAbility.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newability/NewAbility.ets index b9acfd827cba61cc2599d55a6276c0a9c86f2146..f74c81a86dd1897ce35bdcdbb86ecfdabed384ef 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newability/NewAbility.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newability/NewAbility.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import { logger } from '../util/Logger'; - -export default class NewAbility extends UIAbility { - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - windowStage.loadContent('pages/New', () => { - }); - windowStage.getMainWindow((err, windowClass) => { - if (err.code) { - return; - } - windowClass.setWindowLayoutFullScreen(true); - }) - } - - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - AppStorage.setOrCreate('want', want); - AppStorage.setOrCreate('launchParam', launchParam); - logger.info(`NewAbility onCreate ${want.bundleName},${launchParam.launchReason}`); - } - - onDestroy() { - logger.info(`NewAbility onDestroy`); - } - - onWindowStageDestroy() { - logger.info(`NewAbility onWindowStageDestroy`); - // Main window is destroyed, release UI related resources - } - - onForeground() { - logger.info(`NewAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`NewAbility onBackground`); - // Ability has back to background - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../util/Logger'; + +export default class NewAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + windowStage.loadContent('pages/New', () => { + }); + windowStage.getMainWindow((err, windowClass) => { + if (err.code) { + return; + } + windowClass.setWindowLayoutFullScreen(true); + }) + } + + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + AppStorage.setOrCreate('want', want); + AppStorage.setOrCreate('launchParam', launchParam); + logger.info(`NewAbility onCreate ${want.bundleName},${launchParam.launchReason}`); + } + + onDestroy() { + logger.info(`NewAbility onDestroy`); + } + + onWindowStageDestroy() { + logger.info(`NewAbility onWindowStageDestroy`); + // Main window is destroyed, release UI related resources + } + + onForeground() { + logger.info(`NewAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`NewAbility onBackground`); + // Ability has back to background + } +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newuiextability/NewUIExtAbility.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newuiextability/NewUIExtAbility.ets index eff814ee1b63545baecfcbffa2096ca1e0e9280e..2277e8a911df9b5541b545a24c3080b6a74eb3d1 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newuiextability/NewUIExtAbility.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/newuiextability/NewUIExtAbility.ets @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; -import Want from '@ohos.app.ability.Want'; -import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import { logger } from '../util/Logger'; - -export default class NewUIExtAbility extends UIExtensionAbility { - onCreate() { - logger.info(`NewUIExtAbility onCreate`); - } - - onDestroy() { - logger.info(`NewUIExtAbility onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - let param: Record = { - 'session': session, - 'want': want - }; - - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('pages/NewExt', storage); - } - - onForeground() { - logger.info(`NewUIExtAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`NewUIExtAbility onBackground`); - // Ability has back to background - } -} - - +/* + * Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import Want from '@ohos.app.ability.Want'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import { logger } from '../util/Logger'; + +export default class NewUIExtAbility extends UIExtensionAbility { + onCreate() { + logger.info(`NewUIExtAbility onCreate`); + } + + onDestroy() { + logger.info(`NewUIExtAbility onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + let param: Record = { + 'session': session, + 'want': want + }; + + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/NewExt', storage); + } + + onForeground() { + logger.info(`NewUIExtAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`NewUIExtAbility onBackground`); + // Ability has back to background + } +} + + diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Ext.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Ext.ets index f7383138a5d4f0125c491ba8c7e1e885f0d01904..829ddc493ffb6ffac95ac0ebaa57c040c7b1f9a0 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Ext.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Ext.ets @@ -1,117 +1,117 @@ -/* - * Copyright (c) 2023 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Want from '@ohos.app.ability.Want'; -import { logger } from '../util/Logger'; - -export interface ListItemModel { - text: Resource, - callback?: () => void -} - -const TAG: string = 'UIExtensionAbility'; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry(storage) -@Component -struct Ext { - private session: (UIExtensionContentSession | undefined) = storage.get('session'); - private want: (Want | undefined) = storage.get('want'); - @State list: ListItemModel[] = [ - { - text: $r('app.string.extStartAbilityAsCaller'), - callback: () => { - if (this.session === undefined) { - logger.error(`${TAG} session undefined`); - return; - } - if (this.want === undefined) { - logger.error(`${TAG} want undefined`); - return; - } - let localWant: Want = this.want; - localWant.bundleName = 'com.samples.abilityFeatureSystem'; - localWant.moduleName = 'entry'; - localWant.abilityName = 'NewAbility'; - // 使用启动方的Caller身份信息启动新Ability - this.session.startAbilityAsCaller(localWant, (err, data) => { - logger.info(`${TAG} startAbilityAsCaller error:${JSON.stringify(err)} data:${JSON.stringify(data)}`); - }) - }, - } - ]; - - build() { - Column() { - Column() { - Row() { - Image($r('app.media.ic_back')) - .size({ width: 20, height: 18 }) - .margin({ right: 18 }) - .onClick(() => { - if (this.session === undefined) { - return; - } - this.session.sendData({ back: true }); - }) - Text($r('app.string.UIExtAbility_label')) - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 24, right: 24 }) - .width('100%') - } - - Column() { - List({ space: 0, initialIndex: 0 }) { - ForEach(this.list, (item: ListItemModel, index: number) => { - ListItemGroup() { - ListItem() { - Column() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { - Text(item.text) { - }.fontSize(16) - .fontColor($r('sys.color.ohos_id_color_toolbar_sub_bg_dark')) - .height(48) - }.width('100%') - } - } - .align(Alignment.Start) - .onClick(item.callback) - .width('100%') - .padding({ left: 12, right: 12 }) - } - .padding({ top: 4, bottom: 4 }) - .borderRadius(24) - .width('100%') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .margin({ top: 10, bottom: 10 }) - }) - } - .scrollBar(BarState.Off) - .listDirection(Axis.Vertical) // 排列方向 - .friction(0.6) - .width('100%') - .height('100%') - .padding({ left: 12, right: 12 }) - .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring - }.width('100%') - }.width('100%') - .height('100%') - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - .padding({ top: 36, bottom: 106 }) - } +/* + * Copyright (c) 2023 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../util/Logger'; + +export interface ListItemModel { + text: Resource, + callback?: () => void +} + +const TAG: string = 'UIExtensionAbility'; +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry(storage) +@Component +struct Ext { + private session: (UIExtensionContentSession | undefined) = storage.get('session'); + private want: (Want | undefined) = storage.get('want'); + @State list: ListItemModel[] = [ + { + text: $r('app.string.extStartAbilityAsCaller'), + callback: () => { + if (this.session === undefined) { + logger.error(`${TAG} session undefined`); + return; + } + if (this.want === undefined) { + logger.error(`${TAG} want undefined`); + return; + } + let localWant: Want = this.want; + localWant.bundleName = 'com.samples.abilityFeatureSystem'; + localWant.moduleName = 'entry'; + localWant.abilityName = 'NewAbility'; + // 使用启动方的Caller身份信息启动新Ability + this.session.startAbilityAsCaller(localWant, (err, data) => { + logger.info(`${TAG} startAbilityAsCaller error:${JSON.stringify(err)} data:${JSON.stringify(data)}`); + }) + }, + } + ]; + + build() { + Column() { + Column() { + Row() { + Image($r('app.media.ic_back')) + .size({ width: 20, height: 18 }) + .margin({ right: 18 }) + .onClick(() => { + if (this.session === undefined) { + return; + } + this.session.sendData({ back: true }); + }) + Text($r('app.string.UIExtAbility_label')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 24, right: 24 }) + .width('100%') + } + + Column() { + List({ space: 0, initialIndex: 0 }) { + ForEach(this.list, (item: ListItemModel, index: number) => { + ListItemGroup() { + ListItem() { + Column() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { + Text(item.text) { + }.fontSize(16) + .fontColor($r('sys.color.ohos_id_color_toolbar_sub_bg_dark')) + .height(48) + }.width('100%') + } + } + .align(Alignment.Start) + .onClick(item.callback) + .width('100%') + .padding({ left: 12, right: 12 }) + } + .padding({ top: 4, bottom: 4 }) + .borderRadius(24) + .width('100%') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .margin({ top: 10, bottom: 10 }) + }) + } + .scrollBar(BarState.Off) + .listDirection(Axis.Vertical) // 排列方向 + .friction(0.6) + .width('100%') + .height('100%') + .padding({ left: 12, right: 12 }) + .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring + }.width('100%') + }.width('100%') + .height('100%') + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + .padding({ top: 36, bottom: 106 }) + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/New.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/New.ets index c9ca586a7d6ee6c429790e67df4f8101c7400b88..9b6418792bc029bedf448a56739986bef7c8ff0e 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/New.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/New.ets @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import { logger } from '../util/Logger'; - -const TAG: string = '[NewAbility]'; - -@Entry -@Component -struct New { - private context = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Image($r('app.media.ic_back')) - .size({ width: 20, height: 18 }) - .margin({ right: 18 }) - .onClick(() => { - this.context.terminateSelf((err, data) => { - logger.info(`${TAG} terminateSelf err:${JSON.stringify(err)},data:${JSON.stringify(data)}`); - }) - }) - Text($r('app.string.NewAbility_label')) - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 26, right: 26 }) - .width('100%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { - Column() { - Image($r('app.media.pic_empty')).width('33%') - Text($r('app.string.empty')) - .fontSize(14) - } - }.width('100%') - .height('90%') - } - .width('100%') - .height('100%') - .padding({ top: 36, bottom: 106 }) - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import { logger } from '../util/Logger'; + +const TAG: string = '[NewAbility]'; + +@Entry +@Component +struct New { + private context = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Image($r('app.media.ic_back')) + .size({ width: 20, height: 18 }) + .margin({ right: 18 }) + .onClick(() => { + this.context.terminateSelf((err, data) => { + logger.info(`${TAG} terminateSelf err:${JSON.stringify(err)},data:${JSON.stringify(data)}`); + }) + }) + Text($r('app.string.NewAbility_label')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 26, right: 26 }) + .width('100%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { + Column() { + Image($r('app.media.pic_empty')).width('33%') + Text($r('app.string.empty')) + .fontSize(14) + } + }.width('100%') + .height('90%') + } + .width('100%') + .height('100%') + .padding({ top: 36, bottom: 106 }) + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/NewExt.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/NewExt.ets index c72b74610787dcb86af753d12669acb98ad3a596..3d199e898f63fcfd8850b8dd9257a81c581d363b 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/NewExt.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/NewExt.ets @@ -1,64 +1,64 @@ -/* - * Copyright (c) 2023 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Want from '@ohos.app.ability.Want'; -import { logger } from '../util/Logger'; - -const TAG: string = 'UIExtensionAbility'; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry(storage) -@Component -struct NewExt { - private session: (UIExtensionContentSession | undefined) = storage.get('session'); - private want: (Want | undefined) = storage.get('want'); - - build() { - Column() { - Row() { - Image($r('app.media.ic_back')) - .size({ width: 20, height: 18 }) - .margin({ right: 18 }) - .onClick(() => { - if (this.session === undefined) { - return; - } - this.session.terminateSelf((err, data) => { - logger.info(`${TAG} terminateSelf err:${JSON.stringify(err)},data:${JSON.stringify(data)}`); - }) - }) - Text($r('app.string.NewUIExtAbility_label')) - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 24, right: 24 }) - .width('100%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { - Column() { - Image($r('app.media.pic_empty')).width('33%') - Text($r('app.string.empty')) - .fontSize(14) - } - }.width('100%') - .height('90%') - } - .width('100%') - .height('100%') - .padding({ top: 36, bottom: 106 }) - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - } +/* + * Copyright (c) 2023 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../util/Logger'; + +const TAG: string = 'UIExtensionAbility'; +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry(storage) +@Component +struct NewExt { + private session: (UIExtensionContentSession | undefined) = storage.get('session'); + private want: (Want | undefined) = storage.get('want'); + + build() { + Column() { + Row() { + Image($r('app.media.ic_back')) + .size({ width: 20, height: 18 }) + .margin({ right: 18 }) + .onClick(() => { + if (this.session === undefined) { + return; + } + this.session.terminateSelf((err, data) => { + logger.info(`${TAG} terminateSelf err:${JSON.stringify(err)},data:${JSON.stringify(data)}`); + }) + }) + Text($r('app.string.NewUIExtAbility_label')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 24, right: 24 }) + .width('100%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, alignContent: FlexAlign.Center }) { + Column() { + Image($r('app.media.pic_empty')).width('33%') + Text($r('app.string.empty')) + .fontSize(14) + } + }.width('100%') + .height('90%') + } + .width('100%') + .height('100%') + .padding({ top: 36, bottom: 106 }) + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSync.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSync.ets index f16fe2a3da1ac21aac5423bb2f7451bf115fee11..d00a09aecfaf0dd40d9454ec8aea7f80e9e2957c 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSync.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSync.ets @@ -1,138 +1,138 @@ -/* - * Copyright (c) 2023 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 prompt from '@ohos.promptAction'; -import router from '@ohos.router'; -import { logger } from '../util/Logger'; - -interface GroupModel { - title?: string; - list: ListItemModel[]; -} - -export interface ListItemModel { - text: Resource, - rType?: string, - callback?: () => void, -} - -const TAG: string = 'HomeAbility'; - -@Entry -@Component -struct SendSync { - private myProxy: (UIExtensionProxy | null) = null; - @State list: GroupModel[] = [ - { - title: '1', - list: [ - { - text: $r('app.string.sendSyncData'), - rType: '', - callback: () => { - if (this.myProxy === null) { - logger.error(`${TAG} myProxy null`); - return; - } - let params: Record = { 'key': `data from ${TAG}` }; - let result = this.myProxy.sendSync(params); - prompt.showToast({ message: (`${TAG} onReceive ${result['key']}`), duration: 3000, bottom: 150 }); - } - } - ] - }, - ] - - build() { - Column() { - Column() { - Row() { - Image($r('app.media.ic_back')) - .size({ width: 20, height: 18 }) - .margin({ right: 18 }) - .onClick(() => { - router.back({ - url: 'pages/Index' - }); - }) - Text($r('app.string.SendSyncUIExtAbility_label')) - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.height(56) - .padding({ left: 24, right: 24 }) - .width('100%') - } - - Column() { - List({ space: 0, initialIndex: 0 }) { - ForEach(this.list, (groupItem: GroupModel, groupIndex: number) => { - ListItemGroup() { - ForEach(groupItem.list, (item: ListItemModel, index: number) => { - ListItem() { - Column() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { - Text(item.text) - .fontSize(16) - .height(48) - .fontColor($r('sys.color.ohos_id_color_toolbar_sub_bg_dark')) - }.width('100%') - }.width('100%') - } - .id('sendSync') - .align(Alignment.Start) - .onClick(item.callback) - .width('100%') - .padding({ left: 12, right: 12 }) - }) - } - .padding({ top: 4, bottom: 4 }) - .borderRadius(24) - .width('100%') - .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) - .margin({ top: 10, bottom: 10 }) - }) - ListItemGroup() { - ListItem() { - UIExtensionComponent({ - bundleName: 'com.samples.abilityFeatureSystem', - abilityName: 'SendSyncUIExtAbility', - parameters: { - 'ability.want.params.uiExtensionType': 'sys/commonUI', - } - }).size({ width: '100%', height: '90%' }) - .onRemoteReady((pro: UIExtensionProxy) => { - logger.info(`${TAG} onRemoteReady:`); - this.myProxy = pro; - }) - } - } - .borderRadius(24) - .width('100%') - .margin({ top: 10, bottom: 10 }) - } - .scrollBar(BarState.Off) - .listDirection(Axis.Vertical) - .friction(0.6) - .edgeEffect(EdgeEffect.Spring) - .padding({ left: 12, right: 12 }) - .width('100%') - .height('100%') - }.width('100%') - }.width('100%') - .height('100%') - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - .padding({ top: 36, bottom: 106 }) - } +/* + * Copyright (c) 2023 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 prompt from '@ohos.promptAction'; +import router from '@ohos.router'; +import { logger } from '../util/Logger'; + +interface GroupModel { + title?: string; + list: ListItemModel[]; +} + +export interface ListItemModel { + text: Resource, + rType?: string, + callback?: () => void, +} + +const TAG: string = 'HomeAbility'; + +@Entry +@Component +struct SendSync { + private myProxy: (UIExtensionProxy | null) = null; + @State list: GroupModel[] = [ + { + title: '1', + list: [ + { + text: $r('app.string.sendSyncData'), + rType: '', + callback: () => { + if (this.myProxy === null) { + logger.error(`${TAG} myProxy null`); + return; + } + let params: Record = { 'key': `data from ${TAG}` }; + let result = this.myProxy.sendSync(params); + prompt.showToast({ message: (`${TAG} onReceive ${result['key']}`), duration: 3000, bottom: 150 }); + } + } + ] + }, + ] + + build() { + Column() { + Column() { + Row() { + Image($r('app.media.ic_back')) + .size({ width: 20, height: 18 }) + .margin({ right: 18 }) + .onClick(() => { + router.back({ + url: 'pages/Index' + }); + }) + Text($r('app.string.SendSyncUIExtAbility_label')) + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.height(56) + .padding({ left: 24, right: 24 }) + .width('100%') + } + + Column() { + List({ space: 0, initialIndex: 0 }) { + ForEach(this.list, (groupItem: GroupModel, groupIndex: number) => { + ListItemGroup() { + ForEach(groupItem.list, (item: ListItemModel, index: number) => { + ListItem() { + Column() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { + Text(item.text) + .fontSize(16) + .height(48) + .fontColor($r('sys.color.ohos_id_color_toolbar_sub_bg_dark')) + }.width('100%') + }.width('100%') + } + .id('sendSync') + .align(Alignment.Start) + .onClick(item.callback) + .width('100%') + .padding({ left: 12, right: 12 }) + }) + } + .padding({ top: 4, bottom: 4 }) + .borderRadius(24) + .width('100%') + .backgroundColor($r('sys.color.ohos_id_color_foreground_contrary')) + .margin({ top: 10, bottom: 10 }) + }) + ListItemGroup() { + ListItem() { + UIExtensionComponent({ + bundleName: 'com.samples.abilityFeatureSystem', + abilityName: 'SendSyncUIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'sys/commonUI', + } + }).size({ width: '100%', height: '90%' }) + .onRemoteReady((pro: UIExtensionProxy) => { + logger.info(`${TAG} onRemoteReady:`); + this.myProxy = pro; + }) + } + } + .borderRadius(24) + .width('100%') + .margin({ top: 10, bottom: 10 }) + } + .scrollBar(BarState.Off) + .listDirection(Axis.Vertical) + .friction(0.6) + .edgeEffect(EdgeEffect.Spring) + .padding({ left: 12, right: 12 }) + .width('100%') + .height('100%') + }.width('100%') + }.width('100%') + .height('100%') + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + .padding({ top: 36, bottom: 106 }) + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSyncExt.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSyncExt.ets index 22c0de815c1b01cf9305bab93bad23d093f0e2ae..b606992be71c21af5c3aea99562b85d633e4e1f8 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSyncExt.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/SendSyncExt.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2023 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 prompt from '@ohos.promptAction'; -import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Want from '@ohos.app.ability.Want'; - -const TAG: string = 'UIExtensionAbility'; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry(storage) -@Component -struct SendSyncExt { - private session: (UIExtensionContentSession | undefined) = storage.get('session'); - private want: (Want | undefined) = storage.get('want'); - - onPageShow() { - if (this.session != undefined) { - this.session.setReceiveDataForResultCallback((data: Record) => { - prompt.showToast({ message: `${TAG} onReceive ${data['key']}`, duration: 3000, bottom: 20 }); - let a: Record = { 'key': `data from ${TAG}` }; - return a; - }) - } - } - - build() { - Column() { - - } - .width('100%') - .height('100%') - .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) - } +/* + * Copyright (c) 2023 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 prompt from '@ohos.promptAction'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; + +const TAG: string = 'UIExtensionAbility'; +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry(storage) +@Component +struct SendSyncExt { + private session: (UIExtensionContentSession | undefined) = storage.get('session'); + private want: (Want | undefined) = storage.get('want'); + + onPageShow() { + if (this.session != undefined) { + this.session.setReceiveDataForResultCallback((data: Record) => { + prompt.showToast({ message: `${TAG} onReceive ${data['key']}`, duration: 3000, bottom: 20 }); + let a: Record = { 'key': `data from ${TAG}` }; + return a; + }) + } + } + + build() { + Column() { + + } + .width('100%') + .height('100%') + .backgroundColor($r('sys.color.ohos_id_color_text_field_sub_bg')) + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Transit.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Transit.ets index e8a4516a6c16c18b09eb8c39fa2364da08ef45ab..35216f0fa3150d76c7ceb2ebcb0720c98c19f5e1 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Transit.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/pages/Transit.ets @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; -import { logger } from '../util/Logger'; - -@Entry -@Component -struct Transit { - build() { - Column() { - UIExtensionComponent({ - bundleName: 'com.samples.abilityFeatureSystem', - abilityName: 'UIExtAbility', - parameters: { - 'ability.want.params.uiExtensionType': 'sys/commonUI', - } - }).size({ width: '100%', height: '100%' }) - .onReceive((data) => { - logger.info(`onReceive data:${JSON.stringify(data)}`); - if (data.back) { - router.back({ - url: 'pages/Index' - }); - } - }) - }.width('100%') - .height('100%') - } +/* + * Copyright (c) 2023 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 router from '@ohos.router'; +import { logger } from '../util/Logger'; + +@Entry +@Component +struct Transit { + build() { + Column() { + UIExtensionComponent({ + bundleName: 'com.samples.abilityFeatureSystem', + abilityName: 'UIExtAbility', + parameters: { + 'ability.want.params.uiExtensionType': 'sys/commonUI', + } + }).size({ width: '100%', height: '100%' }) + .onReceive((data) => { + logger.info(`onReceive data:${JSON.stringify(data)}`); + if (data.back) { + router.back({ + url: 'pages/Index' + }); + } + }) + }.width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/sendsyncuiextability/SendSyncUIExtAbility.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/sendsyncuiextability/SendSyncUIExtAbility.ets index 8808430f08c87f3ce38b62e467114a187686cfa7..08e7ebb533d907c21d35734c72bc75953094d197 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/sendsyncuiextability/SendSyncUIExtAbility.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/sendsyncuiextability/SendSyncUIExtAbility.ets @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; -import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Want from '@ohos.app.ability.Want'; -import { logger } from '../util/Logger'; - -export default class NewUIExtAbility extends UIExtensionAbility { - onCreate() { - logger.info(`NewUIExtAbility onCreate`); - } - - onDestroy() { - logger.info(`NewUIExtAbility onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - let param: Record = { - 'session': session, - 'want': want - }; - - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('pages/SendSyncExt', storage); - } - - onForeground() { - logger.info(`NewUIExtAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`NewUIExtAbility onBackground`); - // Ability has back to background - } -} - - +/* + * Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../util/Logger'; + +export default class NewUIExtAbility extends UIExtensionAbility { + onCreate() { + logger.info(`NewUIExtAbility onCreate`); + } + + onDestroy() { + logger.info(`NewUIExtAbility onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + let param: Record = { + 'session': session, + 'want': want + }; + + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/SendSyncExt', storage); + } + + onForeground() { + logger.info(`NewUIExtAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`NewUIExtAbility onBackground`); + // Ability has back to background + } +} + + diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/uiextability/UIExtAbility.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/uiextability/UIExtAbility.ets index d7c8f3b105db243c1c21e23c51a5a75110e69b5c..8bf0bcfb1dac1c242f5089d45727f446dbcb2747 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/uiextability/UIExtAbility.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/uiextability/UIExtAbility.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; -import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Want from '@ohos.app.ability.Want'; -import { logger } from '../util/Logger'; - -export default class UIExtAbility extends UIExtensionAbility { - onCreate() { - logger.info(`UIExtAbility onCreate`); - } - - onDestroy() { - logger.info(`UIExtAbility onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - let param: Record = { - 'session': session, - 'want': want - }; - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('pages/Ext', storage); - } - - onForeground() { - logger.info(`UIExtAbility onForeground`); - // Ability has brought to foreground - } - - onBackground() { - logger.info(`UIExtAbility onBackground`); - // Ability has back to background - } -} - - +/* + * Copyright (c) 2023 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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; +import { logger } from '../util/Logger'; + +export default class UIExtAbility extends UIExtensionAbility { + onCreate() { + logger.info(`UIExtAbility onCreate`); + } + + onDestroy() { + logger.info(`UIExtAbility onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + let param: Record = { + 'session': session, + 'want': want + }; + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/Ext', storage); + } + + onForeground() { + logger.info(`UIExtAbility onForeground`); + // Ability has brought to foreground + } + + onBackground() { + logger.info(`UIExtAbility onBackground`); + // Ability has back to background + } +} + + diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/util/Logger.ets b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/util/Logger.ets index a2aa23f156a0de629723420590916860148a8f14..68370d9993189f4b7790be8c0ca99adb0afab00e 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/util/Logger.ets +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/ets/util/Logger.ets @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export let logger = new Logger('[Basic capabilities are enhanced use system api]'); \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/module.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/module.json5 index e967eb0aa577edbbb4e1717708ec5aaf1827affc..1e32da5c2f94bcf37b606230a2704da135f80d08 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/module.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/module.json5 @@ -1,91 +1,91 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "NewAbility", - "srcEntry": "./ets/newability/NewAbility.ets", - "description": "$string:NewAbility_desc", - "icon": "$media:icon", - "label": "$string:NewAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background" - }, - ], - "extensionAbilities": [ - { - "name": "UIExtAbility", - "srcEntry": "./ets/uiextability/UIExtAbility.ets", - "description": "$string:UIExtAbility_desc", - "icon": "$media:icon", - "visible": true, - "type": "sys/commonUI", - }, - { - "name": "NewUIExtAbility", - "icon": "$media:icon", - "description": "$string:UIExtAbility_desc", - "visible": true, - "type": "sysPicker/share", - "srcEntrance": "./ets/newuiextability/NewUIExtAbility.ets", - }, - { - "name": "SendSyncUIExtAbility", - "icon": "$media:icon", - "description": "$string:UIExtAbility_desc", - "visible": true, - "type": "sys/commonUI", - "srcEntrance": "./ets/sendsyncuiextability/SendSyncUIExtAbility.ets", - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.GET_RUNNING_INFO" - }, - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "NewAbility", + "srcEntry": "./ets/newability/NewAbility.ets", + "description": "$string:NewAbility_desc", + "icon": "$media:icon", + "label": "$string:NewAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background" + }, + ], + "extensionAbilities": [ + { + "name": "UIExtAbility", + "srcEntry": "./ets/uiextability/UIExtAbility.ets", + "description": "$string:UIExtAbility_desc", + "icon": "$media:icon", + "visible": true, + "type": "sys/commonUI", + }, + { + "name": "NewUIExtAbility", + "icon": "$media:icon", + "description": "$string:UIExtAbility_desc", + "visible": true, + "type": "sysPicker/share", + "srcEntrance": "./ets/newuiextability/NewUIExtAbility.ets", + }, + { + "name": "SendSyncUIExtAbility", + "icon": "$media:icon", + "description": "$string:UIExtAbility_desc", + "visible": true, + "type": "sys/commonUI", + "srcEntrance": "./ets/sendsyncuiextability/SendSyncUIExtAbility.ets", + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.GET_RUNNING_INFO" + }, + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/color.json b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/color.json index a55608bdfd4b80e04025510c67c65dd138310caf..01dee5176177a542d94efac26fae560c5c19a30a 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/color.json @@ -1,24 +1,24 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "background", - "value": "#FAFAFA" - }, - { - "name": "line_color", - "value": "#182431" - }, - { - "name": "text_color", - "value": "#182431" - }, - { - "name": "button_color", - "value": "#182431" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "background", + "value": "#FAFAFA" + }, + { + "name": "line_color", + "value": "#182431" + }, + { + "name": "text_color", + "value": "#182431" + }, + { + "name": "button_color", + "value": "#182431" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/float.json b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/float.json index 51aeb0059ce9ff1532c80bc800f52ad416ef23eb..c8d10991d67b86589cd2d8fc78970850f27999ab 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/float.json +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/main/resources/base/element/float.json @@ -1,8 +1,8 @@ -{ - "float": [ - { - "name": "font_size", - "value": "16fp" - } - ] +{ + "float": [ + { + "name": "font_size", + "value": "16fp" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/ets/util/Logger.ts b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/ets/util/Logger.ts index a2aa23f156a0de629723420590916860148a8f14..68370d9993189f4b7790be8c0ca99adb0afab00e 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/ets/util/Logger.ts +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/ets/util/Logger.ts @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); - hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.INFO); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.DEBUG); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.WARN); + hilog.isLoggable(this.domain, prefix, hilog.LogLevel.ERROR); + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export let logger = new Logger('[Basic capabilities are enhanced use system api]'); \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/module.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/module.json5 index 0511adbc861eba4c62107d508b88a550567331aa..c6ad62fbbd46259bb51381022bcdce57349e123c 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/hvigor/hvigor-config.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/hvigor/hvigor-config.json5 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/oh-package.json5 b/code/SystemFeature/Ability/AbilityFeatureSystem/oh-package.json5 index ef9d148a5bc411bc5dce4b8905057e5b7bc4d098..f668114f8d55a9a0db801571c31321d0093bbc68 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/oh-package.json5 +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "AbilityFeatureSystem", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "AbilityFeatureSystem", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/Ability/AbilityFeatureSystem/ohosTest.md b/code/SystemFeature/Ability/AbilityFeatureSystem/ohosTest.md index f73d748db9b38e5186ca715c4d0a87050bce17a3..4b7d5e3f3c478fff0ee8fafadd5773d924a05cdd 100644 --- a/code/SystemFeature/Ability/AbilityFeatureSystem/ohosTest.md +++ b/code/SystemFeature/Ability/AbilityFeatureSystem/ohosTest.md @@ -1,14 +1,14 @@ -# 基础能力增强测试用例 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -|---------------------------------------------|--------|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|------| -| 应用查询单个应用是否正在运行的能力 | 设备正常运行 | 应用启动成功,点击''查询应用状态'的ListItem | 弹出Toast提示'当前应用运行中' | Yes | Pass | -| UIExtension创建模系统或模应用 | 设备正常运行 | 应用启动成功,点击'创建模系统'的ListItem | 弹出UIExtension的页面弹窗 | Yes | Pass | -| UIExtension支持同步返回数据的能力 | 设备正常运行 | 1.应用启动成功,点击'同步发送数据'的ListItem
2.再次点击'同步发送数据'的ListItem
| 1.进入到同步发送数据页面页面
2.UIAbility部分弹出Toast提示'HomeAbility onReceive data from UIExtensionAbility',UIExtensionAbility 部分弹出Toast提示'UIExtensionAbility onReceive data from HomeAbility', | Yes | Pass | -| UIAbilityContext提供startAbilityAsCaller的能力 | 设备正常运行 | 应用启动成功,点击'启动AbilityAsCaller'的ListItem | 应用启动NewAbility | Yes | Pass | -| UIAbilityContext提供隐式启动startAbilityByType的能力 | 设备正常运行 | 应用启动成功,点击'启动AbilityByType'的ListItem | 应用启动NewUIExtensionAbility | Yes | Pass | -| UIExtension提供startAbilityAsCaller的能力 | 设备正常运行 | 1.应用启动成功,点击'启动UIExtensionAbility'的ListItem
2.点击'启动AbilityAsCaller'的ListItem | 1.进入到UIExtensionAbility页面
2.应用启动NewAbility | Yes | Pass | -| UIExtension提供隐式启动startAbilityByType的能力 | 设备正常运行 | 1.应用启动成功,点击'启动UIExtensionAbility'的ListItem
2.点击'启动AbilityByType'的ListItem | 1.进入到UIExtensionAbility页面
2.应用启动NewUIExtensionAbility | Yes | Pass | - +# 基础能力增强测试用例 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|---------------------------------------------|--------|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|------| +| 应用查询单个应用是否正在运行的能力 | 设备正常运行 | 应用启动成功,点击''查询应用状态'的ListItem | 弹出Toast提示'当前应用运行中' | Yes | Pass | +| UIExtension创建模系统或模应用 | 设备正常运行 | 应用启动成功,点击'创建模系统'的ListItem | 弹出UIExtension的页面弹窗 | Yes | Pass | +| UIExtension支持同步返回数据的能力 | 设备正常运行 | 1.应用启动成功,点击'同步发送数据'的ListItem
2.再次点击'同步发送数据'的ListItem
| 1.进入到同步发送数据页面页面
2.UIAbility部分弹出Toast提示'HomeAbility onReceive data from UIExtensionAbility',UIExtensionAbility 部分弹出Toast提示'UIExtensionAbility onReceive data from HomeAbility', | Yes | Pass | +| UIAbilityContext提供startAbilityAsCaller的能力 | 设备正常运行 | 应用启动成功,点击'启动AbilityAsCaller'的ListItem | 应用启动NewAbility | Yes | Pass | +| UIAbilityContext提供隐式启动startAbilityByType的能力 | 设备正常运行 | 应用启动成功,点击'启动AbilityByType'的ListItem | 应用启动NewUIExtensionAbility | Yes | Pass | +| UIExtension提供startAbilityAsCaller的能力 | 设备正常运行 | 1.应用启动成功,点击'启动UIExtensionAbility'的ListItem
2.点击'启动AbilityAsCaller'的ListItem | 1.进入到UIExtensionAbility页面
2.应用启动NewAbility | Yes | Pass | +| UIExtension提供隐式启动startAbilityByType的能力 | 设备正常运行 | 1.应用启动成功,点击'启动UIExtensionAbility'的ListItem
2.点击'启动AbilityByType'的ListItem | 1.进入到UIExtensionAbility页面
2.应用启动NewUIExtensionAbility | Yes | Pass | + diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/app.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/app.json5 index c9a4a91b6a4baecc17da1f6f66f324070aec7fe2..b70890c3b0b194ad48d5b34e31b5cb08ade0ddf1 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/app.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.embeddeduiextensionability", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.embeddeduiextensionability", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json index 571d3b555bc6861d63dd165a19b4d5ddf1cc14ff..6e273b77f75875a9b361f0bb06adc938d17b4842 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "EmbeddedUIExtensionAbility" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "EmbeddedUIExtensionAbility" + } + ] +} diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/build-profile.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/build-profile.json5 index ea6d3ca20839c0b83e4605102164820c289d5d70..6ae38bd2fb623625b0ec1588ce196c16bbc33f53 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ], + "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/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/build-profile.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/build-profile.json5 index ff39b71edaed81e4e57aa7cd56f3eb341f2dc9a4..caf14acb2d41dc9ee298e93cc2557fe635574c5a 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/oh-package.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/oh-package.json5 index 51b730caf14ff3788716a3b37a7b71ebbd96f9c6..2d009f6f7388b15508928e7fd2fe954893dee683 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2024 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.ts b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.ts index a2ac5ffe4c8b78a5fe599e56792f66556ee35343..af0028ffe38037bd4fed3a55e096136535606e8d 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.ts +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/embeddeduiextability/EmbeddedUIExtAbility.ts @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 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 EmbeddedUIExtensionAbility from '@ohos.app.ability.EmbeddedUIExtensionAbility'; -import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Want from '@ohos.app.ability.Want'; -import Logger from '../model/Logger'; - -const TAG: string = 'ExampleEmbeddedAbility' -export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility { - onCreate() { - Logger.info(TAG, `onCreate`); - } - - onForeground() { - Logger.info(TAG, `onForeground`); - } - - onBackground() { - Logger.info(TAG, `onBackground`); - } - - onDestroy() { - Logger.info(TAG, `onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - Logger.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}}`); - let param: Record = { - 'session': session - }; - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('pages/extension', storage); - } - - onSessionDestroy(session: UIExtensionContentSession) { - Logger.info(TAG, `onSessionDestroy`); - } +/* + * Copyright (c) 2024 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 EmbeddedUIExtensionAbility from '@ohos.app.ability.EmbeddedUIExtensionAbility'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Want from '@ohos.app.ability.Want'; +import Logger from '../model/Logger'; + +const TAG: string = 'ExampleEmbeddedAbility' +export default class ExampleEmbeddedAbility extends EmbeddedUIExtensionAbility { + onCreate() { + Logger.info(TAG, `onCreate`); + } + + onForeground() { + Logger.info(TAG, `onForeground`); + } + + onBackground() { + Logger.info(TAG, `onBackground`); + } + + onDestroy() { + Logger.info(TAG, `onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + Logger.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}}`); + let param: Record = { + 'session': session + }; + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('pages/extension', storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + Logger.info(TAG, `onSessionDestroy`); + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts index d30cea1c9d32325874d2732215ccdba0289957a1..72df1d36a58370c171b9f8816d814574930bb65a 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; -import Logger from '../model/Logger'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -const TAG: string = 'EntryAbility '; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - Logger.info(TAG, 'Ability onCreate'); - } - - onDestroy() { - Logger.info(TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info(TAG, 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(TAG, 'Failed to load the content.' + JSON.stringify(err)); - return; - } - Logger.info(TAG, 'Succeeded in loading the content.' + JSON.stringify(data)); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info(TAG, 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info(TAG, 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info(TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; +import Logger from '../model/Logger'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +const TAG: string = 'EntryAbility '; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + Logger.info(TAG, 'Ability onCreate'); + } + + onDestroy() { + Logger.info(TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info(TAG, 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(TAG, 'Failed to load the content.' + JSON.stringify(err)); + return; + } + Logger.info(TAG, 'Succeeded in loading the content.' + JSON.stringify(data)); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info(TAG, 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info(TAG, 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info(TAG, 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/model/Logger.ts b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/model/Logger.ts index 140eef6342e380cfd61058ccdf265b99aa5c6feb..2a0e73e7cdda35b94649a64e3d6ae35e857b7544 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/model/Logger.ts +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/model/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_EmbeddedUIExtensionAbility]'); \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/extension.ets b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/extension.ets index 00bac17ada0c1111c51836f98373d4303b838f0f..5c30e0357f89389da90c9b2e369f3b45e69f73dc 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/extension.ets +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/ets/pages/extension.ets @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2024 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import commonEvent from '@ohos.commonEventManager'; - -let storage = LocalStorage.getShared() - -@Entry(storage) -@Component - -struct Extension { - @State message: string = 'EmbeddedUIExtensionAbility provider'; - private session: UIExtensionContentSession | undefined = storage.get('session'); - - aboutToAppear(){ - console.info(`show`) - commonEvent.publish('page_show', (err) => { - console.log('Extension page show'); - }) - } - - build() { - Column() { - Text(this.message) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Center) - } - .alignItems(HorizontalAlign.Center) - .width('100%') - .height('100%') - .justifyContent(FlexAlign.Center) - } +/* + * Copyright (c) 2024 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import commonEvent from '@ohos.commonEventManager'; + +let storage = LocalStorage.getShared() + +@Entry(storage) +@Component + +struct Extension { + @State message: string = 'EmbeddedUIExtensionAbility provider'; + private session: UIExtensionContentSession | undefined = storage.get('session'); + + aboutToAppear(){ + console.info(`show`) + commonEvent.publish('page_show', (err) => { + console.log('Extension page show'); + }) + } + + build() { + Column() { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + } + .alignItems(HorizontalAlign.Center) + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/module.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/module.json5 index 75e355c9530cb98b6523f76bd6989d3d10c5293c..176ac6d9fbd3bc8a74a9e3d620906ba1bdf77d92 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/module.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/module.json5 @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EmbeddedUIExtAbility", - "icon": "$media:icon", - "description": "EmbeddedUIExtAbility", - "type": "embeddedUI", - "srcEntry": "./ets/embeddeduiextability/EmbeddedUIExtAbility.ts", - "exported": true, - } - ] - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EmbeddedUIExtAbility", + "icon": "$media:icon", + "description": "EmbeddedUIExtAbility", + "type": "embeddedUI", + "srcEntry": "./ets/embeddeduiextability/EmbeddedUIExtAbility.ts", + "exported": true, + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/color.json b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 index 3613514e70e0916ece5f7bc2b650d8a3991e457d..7690747eb4c20a802f3a53ad2b493201d03d0659 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/hvigor/hvigor-config.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/hvigor/hvigor-config.json5 index 3a4f957eef9278a763645f6cf23ac2e94d0d61b1..277e9a1fd2d734352e53676bf912347fee241ed0 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/hvigor/hvigor-config.json5 @@ -1,18 +1,18 @@ -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } -} +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } +} diff --git a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/oh-package.json5 b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/oh-package.json5 index 216cd0bb413d1473a882da2f6150e8ef1a384990..ce6cb16a57dcd8f6a12cf359e644d62b073a20f6 100644 --- a/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/EmbeddedUIExtensionAbility/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "embeddeduiextensionability", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "embeddeduiextensionability", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/Launcher/entry/src/ohosTest/ets/test/Launcher.test.ets b/code/SystemFeature/ApplicationModels/Launcher/entry/src/ohosTest/ets/test/Launcher.test.ets index 249853739f1bda7049b352a6ed535beead0fbaff..84c06b4ef133fd4085037b64cc090422796e5e9f 100644 --- a/code/SystemFeature/ApplicationModels/Launcher/entry/src/ohosTest/ets/test/Launcher.test.ets +++ b/code/SystemFeature/ApplicationModels/Launcher/entry/src/ohosTest/ets/test/Launcher.test.ets @@ -1,272 +1,272 @@ -/* - * Copyright (c) 2023 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, beforeAll, expect, beforeEach, afterEach } from '@ohos/hypium' -import { Driver, ON } from '@ohos.UiTest' -import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry' -import hilog from '@ohos.hilog' - -const TAG = '[Sample_Launcher_Test]' -const DOMAIN = 0xF811 -const BUNDLE = 'LauncherTest_' -let appStartRecent = 'startRecent' -let timeStampId = 'time' -let startRecentButtonId = 'startSingletonAbility' -let singletonAbilityText = 'SingletonAbility' -let appCrossChain = 'crossChain' -let crossChainButtonId = 'startSecondAbility' -let entryAbilityText = 'EntryAbility' -let secondAbilityText = 'SecondAbility' -// Return desktop coordinates based on rk3568 -let pressHome_x = 360 -let pressHome_y = 1270 -// Open the recent task list coordinates based on rk3568 -let pressRecent_x = 576 -let pressRecent_y = 1270 - -export default function launcherTest() { - describe('ActsLauncherTest', () => { - /** - * Scene:Start the most recent component instance. - * Input:Click to open the application, return to the desktop, and then click the icon again. - * Expected output:Pull the most recent ability to the foreground, no new ability instance be created. - */ - it(BUNDLE + 'StartRecentAbility_001', 0, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 begin') - let driver = Driver.create() - await driver.delayMs(1000) - // Open the recent task list - await driver.click(pressRecent_x, pressRecent_y) - await driver.delayMs(300) - // Find the number of ability instances that have been opened - let appCount = 1 - await driver.findComponents(ON.text(appStartRecent)).then(result =>{ - if (result != null) { - appCount = result.length - } - }) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 checkComponent, appCount: ' + appCount) - await driver.pressBack() - await driver.delayMs(300) - // Find and open the test application - let app = await driver.findComponent(ON.text(appStartRecent)) - await app.click() - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 openApplication') - await driver.delayMs(500) - // Read the timestamp on the current UIAbility - let firstTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) - let firstTimeStamp = JSON.stringify(await firstTimeStampComponent.getText()) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 getFirstTimeStamp, firstTimeStamp: ' + firstTimeStamp) - // Click the home button to return to the desktop - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - // open the test application again - await app.click() - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 openApplicationAgain') - await driver.delayMs(500) - // Read the timestamp - // verify that clicking the application icon again opened the most recent instance, not a new one - let secondTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) - let secondTimeStamp = JSON.stringify(await secondTimeStampComponent.getText()) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 compareTimeStampEqual, secondTimeStamp: ' + secondTimeStamp) - expect(firstTimeStamp).assertEqual(secondTimeStamp) - // Open the recent task list - await driver.click(pressRecent_x, pressRecent_y) - await driver.delayMs(300) - // Verify that no new instance has been created - let secondAppList = await driver.findComponents(ON.text(appStartRecent)) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 confirmAbilityNotAdd, secondAppList: ' + secondAppList.length) - expect(secondAppList.length).assertEqual(appCount) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(500) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 end') - done() - }) - - /** - * Scene:Start the most recent component instance. - * Input:Long click on the application icon, select 'Open' from the pop-up menu. - * Return to the desktop and open the application by long clicking again. - * Expected output:Pull the most recent ability to the foreground, no new ability instance will be created. - */ - it(BUNDLE + 'StartRecentAbility_002', 1, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 begin') - let driver = Driver.create() - await driver.delayMs(1000) - // Open the recent task list - await driver.click(pressRecent_x, pressRecent_y) - await driver.delayMs(500) - // Find the number of ability instances that have been opened - let appCount = 1 - await driver.findComponents(ON.text(appStartRecent)).then(result =>{ - if (result != null) { - appCount = result.length - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 checkComponent, appCount: ' + appCount) - } - }) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 appCount: ' + appCount) - await driver.pressBack() - await driver.delayMs(300) - let resourceManager = abilityDelegatorRegistry.getAbilityDelegator().getAppContext().resourceManager - // Open the test application with a long click - let app = await driver.findComponent(ON.text(appStartRecent)) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 openApplicationByLongClick') - await app.longClick() - await driver.delayMs(100) - let open = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.app_menu_open')))) - await open.click() - await driver.delayMs(500) - // Read the timestamp on the current UIAbility - let firstTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) - let firstTimeStamp = JSON.stringify(await firstTimeStampComponent.getText()) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 getFirstTimeStamp, firstTimeStamp: ' + firstTimeStamp) - // Click the home button to return to the desktop - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - // open the test application with a long click again - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 openApplicationByLongClickAgain') - await app.longClick() - await driver.delayMs(100) - await open.click() - await driver.delayMs(500) - // Read the timestamp - // verify that clicking the application icon again opened the most recent instance, not a new one - let secondTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) - let secondTimeStamp = JSON.stringify(await secondTimeStampComponent.getText()) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 compareTimeStampEqual, secondTimeStamp: ' + secondTimeStamp) - expect(firstTimeStamp).assertEqual(secondTimeStamp) - // Open the recent task list - await driver.click(pressRecent_x, pressRecent_y) - await driver.delayMs(300) - // Verify that no new instance has been created - let secondAppList = await driver.findComponents(ON.text(appStartRecent)) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 confirmAbilityNotAdd, secondAppList: ' + secondAppList.length) - expect(secondAppList.length).assertEqual(appCount) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(500) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 end') - done() - }) - - /** - * Scene:Start the most recent component instance. - * Input:Click to open the application, click button to open SecondAbility, return to the desktop. - * Click the icon to open the application again. - * Expected output:Pull EntryAbility to the foreground, no new ability instance will be created. - */ - it(BUNDLE + 'StartRecentAbility_003', 2, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 begin') - let driver = Driver.create() - await driver.delayMs(1000) - // Open the recent task list - await driver.click(pressRecent_x, pressRecent_y) - await driver.delayMs(500) - // Find the number of ability instances that have been opened - let appList = await driver.findComponents(ON.text(appStartRecent)) - let appCount = 2 - if (appList != null) { - appCount = appList.length + 1 - } - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 checkComponent, appCount: ' + appCount) - await driver.pressBack() - await driver.delayMs(300) - // Find and open the test application - let app = await driver.findComponent(ON.text(appStartRecent)) - await app.click() - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 openApplication') - await driver.delayMs(500) - // Read the timestamp on the current UIAbility - let firstTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) - let firstTimeStamp = JSON.stringify(await firstTimeStampComponent.getText()) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 getFirstTimeStamp, firstTimeStamp: ' + firstTimeStamp) - // Find the button and click,open singletonAbility - let startRecentButton = await driver.findComponent(ON.id(startRecentButtonId)) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 clickStartRecentButton') - await startRecentButton.click() - await driver.delayMs(300) - // Verify singletonAbility is opened. - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 confirmIsSingletonAbility, singletonAbilityText: ' + singletonAbilityText) - await driver.assertComponentExist(ON.text(singletonAbilityText)) - // Click the home key - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - // Find and open the test application again - await app.click() - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 openApplicationAgain') - await driver.delayMs(300) - // Read the timestamp - // Verify open current EntryAbility instead of to the desktop - let secondTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) - let secondTimeStamp = JSON.stringify(await secondTimeStampComponent.getText()) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 compareTimeStampEqual, secondTimeStamp: ' + secondTimeStamp) - expect(secondTimeStamp).assertEqual(firstTimeStamp) - // Open the recent task list - await driver.click(pressRecent_x, pressRecent_y) - await driver.delayMs(300) - // Verify that no new instance has been created - let secondAppList = await driver.findComponents(ON.text(appStartRecent)) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 confirmAbilityNotAdd, secondAppList: ' + secondAppList.length) - expect(secondAppList.length).assertEqual(appCount) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(500) - hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 end') - done() - }) - - /** - * Scene:Return across task chain. - * Input:Click to open the application, click the button in EntryAbility. - * Click the back button after opening SecondAbility. - * Expected output:Return to EntryAbility instead of to the desktop. - */ - it(BUNDLE + 'TaskChainBack_001', 3, async (done: Function) => { - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 begin') - let driver = Driver.create() - await driver.delayMs(1000) - // Find and open the test application - let app = await driver.findComponent(ON.text(appCrossChain)) - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 openApplication') - await app.click() - await driver.delayMs(500) - // Verify EntryAbility is opened - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 confirmIsEntryAbility, entryAbilityText: ' + entryAbilityText) - await driver.assertComponentExist(ON.text(entryAbilityText)) - // Find the button and click - let crossChainButton = await driver.findComponent(ON.id(crossChainButtonId)) - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 clickCrossChainButton') - await crossChainButton.click() - await driver.delayMs(300) - // Verify SecondAbility is opened by pulling up ServiceExtensionAbility after clicking the button - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 confirmIsSecondAbility, secondAbilityText: ' + secondAbilityText) - await driver.assertComponentExist(ON.text(secondAbilityText)) - // Click the back key - await driver.pressBack() - await driver.delayMs(300) - // Verify back to EntryAbility instead of to the desktop - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 assertIsEntryAbility, entryAbilityText: ' + entryAbilityText) - await driver.assertComponentExist(ON.text(entryAbilityText)) - await driver.click(pressHome_x, pressHome_y) - await driver.delayMs(300) - hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 end') - done() - }) - }) +/* + * Copyright (c) 2023 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, beforeAll, expect, beforeEach, afterEach } from '@ohos/hypium' +import { Driver, ON } from '@ohos.UiTest' +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry' +import hilog from '@ohos.hilog' + +const TAG = '[Sample_Launcher_Test]' +const DOMAIN = 0xF811 +const BUNDLE = 'LauncherTest_' +let appStartRecent = 'startRecent' +let timeStampId = 'time' +let startRecentButtonId = 'startSingletonAbility' +let singletonAbilityText = 'SingletonAbility' +let appCrossChain = 'crossChain' +let crossChainButtonId = 'startSecondAbility' +let entryAbilityText = 'EntryAbility' +let secondAbilityText = 'SecondAbility' +// Return desktop coordinates based on rk3568 +let pressHome_x = 360 +let pressHome_y = 1270 +// Open the recent task list coordinates based on rk3568 +let pressRecent_x = 576 +let pressRecent_y = 1270 + +export default function launcherTest() { + describe('ActsLauncherTest', () => { + /** + * Scene:Start the most recent component instance. + * Input:Click to open the application, return to the desktop, and then click the icon again. + * Expected output:Pull the most recent ability to the foreground, no new ability instance be created. + */ + it(BUNDLE + 'StartRecentAbility_001', 0, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 begin') + let driver = Driver.create() + await driver.delayMs(1000) + // Open the recent task list + await driver.click(pressRecent_x, pressRecent_y) + await driver.delayMs(300) + // Find the number of ability instances that have been opened + let appCount = 1 + await driver.findComponents(ON.text(appStartRecent)).then(result =>{ + if (result != null) { + appCount = result.length + } + }) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 checkComponent, appCount: ' + appCount) + await driver.pressBack() + await driver.delayMs(300) + // Find and open the test application + let app = await driver.findComponent(ON.text(appStartRecent)) + await app.click() + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 openApplication') + await driver.delayMs(500) + // Read the timestamp on the current UIAbility + let firstTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) + let firstTimeStamp = JSON.stringify(await firstTimeStampComponent.getText()) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 getFirstTimeStamp, firstTimeStamp: ' + firstTimeStamp) + // Click the home button to return to the desktop + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + // open the test application again + await app.click() + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 openApplicationAgain') + await driver.delayMs(500) + // Read the timestamp + // verify that clicking the application icon again opened the most recent instance, not a new one + let secondTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) + let secondTimeStamp = JSON.stringify(await secondTimeStampComponent.getText()) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 compareTimeStampEqual, secondTimeStamp: ' + secondTimeStamp) + expect(firstTimeStamp).assertEqual(secondTimeStamp) + // Open the recent task list + await driver.click(pressRecent_x, pressRecent_y) + await driver.delayMs(300) + // Verify that no new instance has been created + let secondAppList = await driver.findComponents(ON.text(appStartRecent)) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 confirmAbilityNotAdd, secondAppList: ' + secondAppList.length) + expect(secondAppList.length).assertEqual(appCount) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(500) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_001 end') + done() + }) + + /** + * Scene:Start the most recent component instance. + * Input:Long click on the application icon, select 'Open' from the pop-up menu. + * Return to the desktop and open the application by long clicking again. + * Expected output:Pull the most recent ability to the foreground, no new ability instance will be created. + */ + it(BUNDLE + 'StartRecentAbility_002', 1, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 begin') + let driver = Driver.create() + await driver.delayMs(1000) + // Open the recent task list + await driver.click(pressRecent_x, pressRecent_y) + await driver.delayMs(500) + // Find the number of ability instances that have been opened + let appCount = 1 + await driver.findComponents(ON.text(appStartRecent)).then(result =>{ + if (result != null) { + appCount = result.length + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 checkComponent, appCount: ' + appCount) + } + }) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 appCount: ' + appCount) + await driver.pressBack() + await driver.delayMs(300) + let resourceManager = abilityDelegatorRegistry.getAbilityDelegator().getAppContext().resourceManager + // Open the test application with a long click + let app = await driver.findComponent(ON.text(appStartRecent)) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 openApplicationByLongClick') + await app.longClick() + await driver.delayMs(100) + let open = await driver.findComponent(ON.text(await resourceManager.getStringValue($r('app.string.app_menu_open')))) + await open.click() + await driver.delayMs(500) + // Read the timestamp on the current UIAbility + let firstTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) + let firstTimeStamp = JSON.stringify(await firstTimeStampComponent.getText()) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 getFirstTimeStamp, firstTimeStamp: ' + firstTimeStamp) + // Click the home button to return to the desktop + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + // open the test application with a long click again + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 openApplicationByLongClickAgain') + await app.longClick() + await driver.delayMs(100) + await open.click() + await driver.delayMs(500) + // Read the timestamp + // verify that clicking the application icon again opened the most recent instance, not a new one + let secondTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) + let secondTimeStamp = JSON.stringify(await secondTimeStampComponent.getText()) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 compareTimeStampEqual, secondTimeStamp: ' + secondTimeStamp) + expect(firstTimeStamp).assertEqual(secondTimeStamp) + // Open the recent task list + await driver.click(pressRecent_x, pressRecent_y) + await driver.delayMs(300) + // Verify that no new instance has been created + let secondAppList = await driver.findComponents(ON.text(appStartRecent)) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 confirmAbilityNotAdd, secondAppList: ' + secondAppList.length) + expect(secondAppList.length).assertEqual(appCount) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(500) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_002 end') + done() + }) + + /** + * Scene:Start the most recent component instance. + * Input:Click to open the application, click button to open SecondAbility, return to the desktop. + * Click the icon to open the application again. + * Expected output:Pull EntryAbility to the foreground, no new ability instance will be created. + */ + it(BUNDLE + 'StartRecentAbility_003', 2, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 begin') + let driver = Driver.create() + await driver.delayMs(1000) + // Open the recent task list + await driver.click(pressRecent_x, pressRecent_y) + await driver.delayMs(500) + // Find the number of ability instances that have been opened + let appList = await driver.findComponents(ON.text(appStartRecent)) + let appCount = 2 + if (appList != null) { + appCount = appList.length + 1 + } + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 checkComponent, appCount: ' + appCount) + await driver.pressBack() + await driver.delayMs(300) + // Find and open the test application + let app = await driver.findComponent(ON.text(appStartRecent)) + await app.click() + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 openApplication') + await driver.delayMs(500) + // Read the timestamp on the current UIAbility + let firstTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) + let firstTimeStamp = JSON.stringify(await firstTimeStampComponent.getText()) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 getFirstTimeStamp, firstTimeStamp: ' + firstTimeStamp) + // Find the button and click,open singletonAbility + let startRecentButton = await driver.findComponent(ON.id(startRecentButtonId)) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 clickStartRecentButton') + await startRecentButton.click() + await driver.delayMs(300) + // Verify singletonAbility is opened. + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 confirmIsSingletonAbility, singletonAbilityText: ' + singletonAbilityText) + await driver.assertComponentExist(ON.text(singletonAbilityText)) + // Click the home key + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + // Find and open the test application again + await app.click() + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 openApplicationAgain') + await driver.delayMs(300) + // Read the timestamp + // Verify open current EntryAbility instead of to the desktop + let secondTimeStampComponent = await driver.findComponent(ON.id(timeStampId)) + let secondTimeStamp = JSON.stringify(await secondTimeStampComponent.getText()) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 compareTimeStampEqual, secondTimeStamp: ' + secondTimeStamp) + expect(secondTimeStamp).assertEqual(firstTimeStamp) + // Open the recent task list + await driver.click(pressRecent_x, pressRecent_y) + await driver.delayMs(300) + // Verify that no new instance has been created + let secondAppList = await driver.findComponents(ON.text(appStartRecent)) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 confirmAbilityNotAdd, secondAppList: ' + secondAppList.length) + expect(secondAppList.length).assertEqual(appCount) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(500) + hilog.info(DOMAIN, TAG, BUNDLE + 'StartRecentAbility_003 end') + done() + }) + + /** + * Scene:Return across task chain. + * Input:Click to open the application, click the button in EntryAbility. + * Click the back button after opening SecondAbility. + * Expected output:Return to EntryAbility instead of to the desktop. + */ + it(BUNDLE + 'TaskChainBack_001', 3, async (done: Function) => { + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 begin') + let driver = Driver.create() + await driver.delayMs(1000) + // Find and open the test application + let app = await driver.findComponent(ON.text(appCrossChain)) + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 openApplication') + await app.click() + await driver.delayMs(500) + // Verify EntryAbility is opened + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 confirmIsEntryAbility, entryAbilityText: ' + entryAbilityText) + await driver.assertComponentExist(ON.text(entryAbilityText)) + // Find the button and click + let crossChainButton = await driver.findComponent(ON.id(crossChainButtonId)) + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 clickCrossChainButton') + await crossChainButton.click() + await driver.delayMs(300) + // Verify SecondAbility is opened by pulling up ServiceExtensionAbility after clicking the button + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 confirmIsSecondAbility, secondAbilityText: ' + secondAbilityText) + await driver.assertComponentExist(ON.text(secondAbilityText)) + // Click the back key + await driver.pressBack() + await driver.delayMs(300) + // Verify back to EntryAbility instead of to the desktop + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 assertIsEntryAbility, entryAbilityText: ' + entryAbilityText) + await driver.assertComponentExist(ON.text(entryAbilityText)) + await driver.click(pressHome_x, pressHome_y) + await driver.delayMs(300) + hilog.info(DOMAIN, TAG, BUNDLE + 'TaskChainBack_001 end') + done() + }) + }) } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/StaticSubscriber/entry/hvigorfile.ts b/code/SystemFeature/ApplicationModels/StaticSubscriber/entry/hvigorfile.ts index c57c77181d0d36beb49c897ff3fc1ad92f7eaa7c..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 100644 --- a/code/SystemFeature/ApplicationModels/StaticSubscriber/entry/hvigorfile.ts +++ b/code/SystemFeature/ApplicationModels/StaticSubscriber/entry/hvigorfile.ts @@ -1,2 +1,2 @@ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { hapTasks } from '@ohos/hvigor-ohos-plugin'; +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/code/SystemFeature/ApplicationModels/StaticSubscriber/hvigorfile.ts b/code/SystemFeature/ApplicationModels/StaticSubscriber/hvigorfile.ts index 1a4d9969c6ab9c5b03543519686d9d713e729402..6478186902c0c1ad7c966a929c7d6b7d8ae7a9f3 100644 --- a/code/SystemFeature/ApplicationModels/StaticSubscriber/hvigorfile.ts +++ b/code/SystemFeature/ApplicationModels/StaticSubscriber/hvigorfile.ts @@ -1,2 +1,2 @@ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. export { appTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/StaticSubscriber/publish/hvigorfile.ts b/code/SystemFeature/ApplicationModels/StaticSubscriber/publish/hvigorfile.ts index c57c77181d0d36beb49c897ff3fc1ad92f7eaa7c..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 100644 --- a/code/SystemFeature/ApplicationModels/StaticSubscriber/publish/hvigorfile.ts +++ b/code/SystemFeature/ApplicationModels/StaticSubscriber/publish/hvigorfile.ts @@ -1,2 +1,2 @@ -// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -export { hapTasks } from '@ohos/hvigor-ohos-plugin'; +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/app.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/app.json5 index 3f78b42a42744711a17c2505bd19d976ef546a3d..3ce317c6e3d6f0cfcbe3626caffe2c68bdbec1a6 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/app.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.acts.abilityabacktoabilityb", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.acts.abilityabacktoabilityb", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/resources/base/element/string.json b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/resources/base/element/string.json index d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4..1080233f01384411ec684b58955cb8808746fdd3 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MyApplication" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/build-profile.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/build-profile.json5 index 235336001bdc2ec11c1b951317a00a86f3c0bca1..66170112ecc41d476f770f8de1d2b4d74ce42132 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 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": [], - "compileSdkVersion": 9, - "compatibleSdkVersion": 9, - "products": [ - { - "name": "default", - "signingConfig": "default", - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": [], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/build-profile.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/build-profile.json5 index d2711a6c649936843c4a2b8deac9037c9f7674a6..fcaca9146e02c0cfb9fde98f2dc05ff9fd0fad1d 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/oh-package.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/oh-package.json5 index 4be95c59ce0dede7a66d6fcb2e3018c8011f838a..3fbe67bbf8193c883bab1ccea7be318bc3a65bdb 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/entryability/EntryAbility.ts index ba63ef824c90c947d42fe489082f658f8cf4e755..c2c39ef45f81d540bf5bba83f7f45b13c822396e 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,56 +1,56 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/logger/Logger.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/logger/Logger.ts index 57c377b5114e3ccced47335e5f860344d46bb8ad..8e41f73118000665976bc39e25e15b21f13963f5 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/logger/Logger.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/logger/Logger.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - /** - * debug - * @param args - */ - debug(...args: any[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - /** - * info - * @param args - */ - info(...args: any[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - /** - * warn - * @param args - */ - warn(...args: any[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - /** - * error - * @param args - */ - error(...args: any[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + /** + * debug + * @param args + */ + debug(...args: any[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + /** + * info + * @param args + */ + info(...args: any[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + /** + * warn + * @param args + */ + warn(...args: any[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + /** + * error + * @param args + */ + error(...args: any[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_CrossChainBack]'); \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/secondability/SecondAbility.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/secondability/SecondAbility.ts index 9187897370c0b2ed766f13baf0ee79ea66399dd8..cc130d425947d51d6eb45ae18b92af2911950d2c 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/secondability/SecondAbility.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/secondability/SecondAbility.ts @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; -import Logger from '../logger/Logger'; - -export default class SecondAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - Logger.debug('SecondAbility onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/IndexSecond', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; +import Logger from '../logger/Logger'; + +export default class SecondAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + Logger.debug('SecondAbility onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/IndexSecond', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/serviceability/ServiceAbility.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/serviceability/ServiceAbility.ts index ca5200c02e503dad0afa6aad76945929c763ef53..002431002ce5d81d02bcf4bc0d4089f71db603b4 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/serviceability/ServiceAbility.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/ets/serviceability/ServiceAbility.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; -import wantConstant from '@ohos.app.ability.wantConstant'; -import rpc from '@ohos.rpc'; -import Logger from '../logger/Logger'; - -class StubTest extends rpc.RemoteObject { - constructor(des) { - super(des); - } - - onRemoteRequest(code, data, reply, option): boolean { - return true; - } -} - -export default class ServiceAbility extends ServiceExtensionAbility { - onCreate(want) { - Logger.debug('ServiceExtensionAbility has been onCreate'); - } - - onDestroy() { - Logger.debug('ServiceExtensionAbility has been onDestroy'); - } - - onRequest(want, startId) { - Logger.debug('ServiceExtensionAbility has been onRequest'); - } - - onConnect(want) { - console.info('ServiceAbility onConnect'); - let secUIAbilityWant = { - bundleName: 'com.acts.abilityabacktoabilityb', - abilityName: 'SecondAbility', - parameters: { - [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true - } - }; - globalThis.context = this.context; - this.context.startAbility(secUIAbilityWant).then(() => { - Logger.debug('startAbility successful.'); - }).catch((err) => { - Logger.debug('startAbility failed.'); - }); - return new StubTest('test'); - } -} +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import ServiceExtensionAbility from '@ohos.app.ability.ServiceExtensionAbility'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import rpc from '@ohos.rpc'; +import Logger from '../logger/Logger'; + +class StubTest extends rpc.RemoteObject { + constructor(des) { + super(des); + } + + onRemoteRequest(code, data, reply, option): boolean { + return true; + } +} + +export default class ServiceAbility extends ServiceExtensionAbility { + onCreate(want) { + Logger.debug('ServiceExtensionAbility has been onCreate'); + } + + onDestroy() { + Logger.debug('ServiceExtensionAbility has been onDestroy'); + } + + onRequest(want, startId) { + Logger.debug('ServiceExtensionAbility has been onRequest'); + } + + onConnect(want) { + console.info('ServiceAbility onConnect'); + let secUIAbilityWant = { + bundleName: 'com.acts.abilityabacktoabilityb', + abilityName: 'SecondAbility', + parameters: { + [wantConstant.Params.ABILITY_BACK_TO_OTHER_MISSION_STACK]: true + } + }; + globalThis.context = this.context; + this.context.startAbility(secUIAbilityWant).then(() => { + Logger.debug('startAbility successful.'); + }).catch((err) => { + Logger.debug('startAbility failed.'); + }); + return new StubTest('test'); + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/module.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/module.json5 index 2887681ad90bd44e9c3f6d0bdbbd73204c316339..4d3bbdc72d997d1706824d9ed8a01287de3e0d76 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/module.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/module.json5 @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "launchType": "standard", - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "SecondAbility", - "srcEntrance": "./ets/secondability/SecondAbility.ts", - "description": "$string:SecondAbility_desc", - "icon": "$media:icon", - "label": "$string:SecondAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true - } - ], - "extensionAbilities": [ - { - "name": "ServiceAbility", - "srcEntrance": "./ets/serviceability/ServiceAbility.ts", - "label": "$string:ServiceAbility_label", - "description": "$string:ServiceAbility_desc", - "type": "service" - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "launchType": "standard", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "SecondAbility", + "srcEntrance": "./ets/secondability/SecondAbility.ts", + "description": "$string:SecondAbility_desc", + "icon": "$media:icon", + "label": "$string:SecondAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true + } + ], + "extensionAbilities": [ + { + "name": "ServiceAbility", + "srcEntrance": "./ets/serviceability/ServiceAbility.ts", + "label": "$string:ServiceAbility_label", + "description": "$string:ServiceAbility_desc", + "type": "service" + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND" + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/resources/base/element/color.json b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/hvigor/hvigor-config.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/hvigor/hvigor-config.json5 index e5abb715c8f7e6289dd9c71f2804eee8d6480f91..835122515a93cc9181bd1fe13e447674a53526cb 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "hvigorVersion": "2.0.0", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "hvigorVersion": "2.0.0", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "2.0.0" + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/oh-package.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/oh-package.json5 index 80dcaf146d22664551e742d530f9c673cb43e487..ab9d172f9624c609eb075bd64361a1448c6fa893 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/CrossChainBack/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myapplication", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "myapplication", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/app.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/app.json5 index cafc68858cfc1f51b337db8a268633ccfd3e6108..e6f13d24b2ba17b7287513de6213c60a3c06092a 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/app.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.acts.startrecentability", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.acts.startrecentability", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/resources/base/element/string.json b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/resources/base/element/string.json index d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4..1080233f01384411ec684b58955cb8808746fdd3 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MyApplication" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/build-profile.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/build-profile.json5 index 235336001bdc2ec11c1b951317a00a86f3c0bca1..66170112ecc41d476f770f8de1d2b4d74ce42132 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 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": [], - "compileSdkVersion": 9, - "compatibleSdkVersion": 9, - "products": [ - { - "name": "default", - "signingConfig": "default", - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": [], + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/build-profile.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/build-profile.json5 index d2711a6c649936843c4a2b8deac9037c9f7674a6..fcaca9146e02c0cfb9fde98f2dc05ff9fd0fad1d 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/oh-package.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/oh-package.json5 index 4be95c59ce0dede7a66d6fcb2e3018c8011f838a..3fbe67bbf8193c883bab1ccea7be318bc3a65bdb 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/entryability/EntryAbility.ts index c6b55c98e637a50202f7bb3329f8954c397c55df..d24d63eb7906574a450f4cec7e443606569aaa87 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; -import systemDateTime from '@ohos.systemDateTime'; -import Logger from '../logger/Logger'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - systemDateTime.getDate().then((date) => { - Logger.debug('getDate successful'); - }); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; +import systemDateTime from '@ohos.systemDateTime'; +import Logger from '../logger/Logger'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + systemDateTime.getDate().then((date) => { + Logger.debug('getDate successful'); + }); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/logger/Logger.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/logger/Logger.ts index a770417524b5a7b59c4e142fe847a25cc11b4e78..d8268862afdbfbceb911ff84519d53496b063bf3 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/logger/Logger.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/logger/Logger.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - /** - * debug - * @param args - */ - debug(...args: any[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - /** - * info - * @param args - */ - info(...args: any[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - /** - * warn - * @param args - */ - warn(...args: any[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - /** - * error - * @param args - */ - error(...args: any[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - -export default new Logger('[Sample_StartRecentAbility]'); +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + /** + * debug + * @param args + */ + debug(...args: any[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + /** + * info + * @param args + */ + info(...args: any[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + /** + * warn + * @param args + */ + warn(...args: any[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + /** + * error + * @param args + */ + error(...args: any[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('[Sample_StartRecentAbility]'); diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/secondability/SecondAbility.ts b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/secondability/SecondAbility.ts index 690958f990e86d00bc435ea27a576b433b099ccd..b0271aaf8d32b44558d21efd216794cd03d44648 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/secondability/SecondAbility.ts +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/ets/secondability/SecondAbility.ts @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import hilog from '@ohos.hilog'; -import window from '@ohos.window'; -import wantConstant from '@ohos.ability.wantConstant'; - -export default class SecondAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/IndexSecond', (err, data) => { - 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. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; +import wantConstant from '@ohos.ability.wantConstant'; + +export default class SecondAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/IndexSecond', (err, data) => { + 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. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/module.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/module.json5 index 275c4826c0e428ab229071ab8d5b449335a49b9d..cc0bec953612a3104f18dac04ca122200381fc95 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/module.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/module.json5 @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "default" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "launchType": "standard", - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - }, - { - "name": "SecondAbility", - "srcEntrance": "./ets/secondability/SecondAbility.ts", - "description": "$string:SecondAbility_desc", - "icon": "$media:icon", - "label": "$string:SecondAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true - } - ] - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "launchType": "standard", + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + }, + { + "name": "SecondAbility", + "srcEntrance": "./ets/secondability/SecondAbility.ts", + "description": "$string:SecondAbility_desc", + "icon": "$media:icon", + "label": "$string:SecondAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/resources/base/element/color.json b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/hvigor/hvigor-config.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/hvigor/hvigor-config.json5 index e5abb715c8f7e6289dd9c71f2804eee8d6480f91..835122515a93cc9181bd1fe13e447674a53526cb 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "hvigorVersion": "2.0.0", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" - } -} +/* + * Copyright (c) 2023 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. + */ + +{ + "hvigorVersion": "2.0.0", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "2.0.0" + } +} diff --git a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/oh-package.json5 b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/oh-package.json5 index 80dcaf146d22664551e742d530f9c673cb43e487..ab9d172f9624c609eb075bd64361a1448c6fa893 100644 --- a/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/TestRely/LauncherTest/StartRecentAbility/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "myapplication", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "myapplication", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/app.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/app.json5 index 2f14d2e59df4515921e423feea00df97932e938b..e520f83e467b680de408e61792607d07f8b11c33 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/app.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.uiextensionability", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.uiextensionability", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/resources/base/element/string.json b/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/resources/base/element/string.json index d9951e760be4f977667cd341f03dfcb8f92155cc..5071f4a359cd7def3c152fc7a63c760cf71c75a1 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "uiextensionability" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "uiextensionability" + } + ] +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/build-profile.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/build-profile.json5 index ea6d3ca20839c0b83e4605102164820c289d5d70..6ae38bd2fb623625b0ec1588ce196c16bbc33f53 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ], + "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/SystemFeature/ApplicationModels/UIExtensionAbility/entry/build-profile.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/build-profile.json5 index ff39b71edaed81e4e57aa7cd56f3eb341f2dc9a4..caf14acb2d41dc9ee298e93cc2557fe635574c5a 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/build-profile.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/oh-package.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts index 053964af92d400721937e4c78065f52496308374..0c2f4a450e5305ada19dbc0638f9984d592a5f11 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; -import Logger from '../model/Logger'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; - -const TAG: string = 'EntryAbility '; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - Logger.info(TAG, 'Ability onCreate'); - } - - onDestroy() { - Logger.info(TAG, 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info(TAG, 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(TAG, 'Failed to load the content.' + JSON.stringify(err)); - return; - } - Logger.info(TAG, 'Succeeded in loading the content.' + JSON.stringify(data)); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info(TAG, 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info(TAG, 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info(TAG, 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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 from '@ohos.app.ability.AbilityConstant'; +import Logger from '../model/Logger'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; + +const TAG: string = 'EntryAbility '; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + Logger.info(TAG, 'Ability onCreate'); + } + + onDestroy() { + Logger.info(TAG, 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info(TAG, 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(TAG, 'Failed to load the content.' + JSON.stringify(err)); + return; + } + Logger.info(TAG, 'Succeeded in loading the content.' + JSON.stringify(data)); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info(TAG, 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info(TAG, 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info(TAG, 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/model/Logger.ts b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/model/Logger.ts index 140eef6342e380cfd61058ccdf265b99aa5c6feb..2a0e73e7cdda35b94649a64e3d6ae35e857b7544 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/model/Logger.ts +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/model/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_EmbeddedUIExtensionAbility]'); \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/pages/Extension.ets b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/pages/Extension.ets index 1b1072ca81ae6fd170b496f6e402ea9f8423b988..d9d7b7705dbb3f2fd51f8ae212c0c0832f3fe7e3 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/pages/Extension.ets +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/pages/Extension.ets @@ -1,46 +1,46 @@ -/* - * Copyright (c) 2024 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import commonEvent from '@ohos.commonEventManager' -let storage = LocalStorage.GetShared(); -const TAG: string = `[testTag] ExtensionPage` - -@Entry(storage) -@Component -struct Extension { - @State message: string = `UIExtension provider`; - private session: UIExtensionContentSession | undefined = storage.get('session'); - - onPageShow() { - console.info(TAG, 'show'); - commonEvent.publish('page_show', (err) => { - console.log('Extension page show'); - }) - } - - build() { - Column() { - Text(this.message) - .fontSize(20) - .fontWeight(FontWeight.Bold) - .textAlign(TextAlign.Center) - } - .alignItems(HorizontalAlign.Center) - .width('100%') - .height('100%') - .justifyContent(FlexAlign.Center) - } +/* + * Copyright (c) 2024 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import commonEvent from '@ohos.commonEventManager' +let storage = LocalStorage.GetShared(); +const TAG: string = `[testTag] ExtensionPage` + +@Entry(storage) +@Component +struct Extension { + @State message: string = `UIExtension provider`; + private session: UIExtensionContentSession | undefined = storage.get('session'); + + onPageShow() { + console.info(TAG, 'show'); + commonEvent.publish('page_show', (err) => { + console.log('Extension page show'); + }) + } + + build() { + Column() { + Text(this.message) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .textAlign(TextAlign.Center) + } + .alignItems(HorizontalAlign.Center) + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets index fc3c4201bc73da6948fa2734afd333bf8a4a7007..f448fbf3a012ae559aecec8962332ef6ae794e5f 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2024 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 Want from '@ohos.app.ability.Want'; -import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; -import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; -import Logger from '../model/Logger'; - -const TAG: string = 'UIExtensionAbility '; - -export default class UIExtAbility extends UIExtensionAbility { - onCreate() { - Logger.info(TAG, `onCreate`); - } - - onForeground() { - Logger.info(TAG, `onForeground`); - } - - onBackground() { - Logger.info(TAG, `onBackground`); - } - - onDestroy() { - Logger.info(TAG, `onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - Logger.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}}`); - let storage: LocalStorage = new LocalStorage(); - storage.setOrCreate('session', session); - session.loadContent('pages/Extension',storage); - } - - onSessionDestroy(session: UIExtensionContentSession) { - Logger.info(TAG, `onSessionDestroy`); - } -} +/* + * Copyright (c) 2024 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 Want from '@ohos.app.ability.Want'; +import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; +import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; +import Logger from '../model/Logger'; + +const TAG: string = 'UIExtensionAbility '; + +export default class UIExtAbility extends UIExtensionAbility { + onCreate() { + Logger.info(TAG, `onCreate`); + } + + onForeground() { + Logger.info(TAG, `onForeground`); + } + + onBackground() { + Logger.info(TAG, `onBackground`); + } + + onDestroy() { + Logger.info(TAG, `onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + Logger.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}}`); + let storage: LocalStorage = new LocalStorage(); + storage.setOrCreate('session', session); + session.loadContent('pages/Extension',storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + Logger.info(TAG, `onSessionDestroy`); + } +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/module.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/module.json5 index 070c5f159972f0e042f224b1f57c84aa19332e5c..ae399e0057b1ff965c2cfae4f14bbb43cead5e17 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/module.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/module.json5 @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "UIExtensionProvider", - "srcEntry": "./ets/uiextensionability/UIExtensionAbility.ets", - "description": "UIExtensionAbility", - "type": "sys/commonUI", - "exported": true - } - ] - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "UIExtensionProvider", + "srcEntry": "./ets/uiextensionability/UIExtensionAbility.ets", + "description": "UIExtensionAbility", + "type": "sys/commonUI", + "exported": true + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/resources/base/element/color.json b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/ohosTest/module.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/ohosTest/module.json5 index 3613514e70e0916ece5f7bc2b650d8a3991e457d..7690747eb4c20a802f3a53ad2b493201d03d0659 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/hvigor/hvigor-config.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/hvigor/hvigor-config.json5 index 497c2eb211f0b525133f58232d0786b425a414ef..44a5bdf2367aeef8357a73f00a050ba13a6dd2bf 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/hvigor/hvigor-config.json5 @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } -} +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } +} diff --git a/code/SystemFeature/ApplicationModels/UIExtensionAbility/oh-package.json5 b/code/SystemFeature/ApplicationModels/UIExtensionAbility/oh-package.json5 index 5a254d117a8ac1918f4ced30dd81bf73b9eb46a9..336dbf0048d01f1cff610f5c76cd48b6c9040403 100644 --- a/code/SystemFeature/ApplicationModels/UIExtensionAbility/oh-package.json5 +++ b/code/SystemFeature/ApplicationModels/UIExtensionAbility/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "uiextensionability", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2024 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "uiextensionability", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/AutoFill/AutoFill/AppScope/app.json5 b/code/SystemFeature/AutoFill/AutoFill/AppScope/app.json5 index f60b21ffed4b991b152778291ee5e8e63fded2db..96904f1a104cc852f6eabe47fec9f899487c2d7f 100644 --- a/code/SystemFeature/AutoFill/AutoFill/AppScope/app.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2023 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.ohos.passwordbox", - "vendor": "ohos", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.ohos.passwordbox", + "vendor": "ohos", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/AutoFill/AutoFill/AppScope/resources/base/element/string.json b/code/SystemFeature/AutoFill/AutoFill/AppScope/resources/base/element/string.json index 56e6f761cc0c4232d4f154cbad37f921bcf82edf..610e3e845e28851cdee93231a291b9191a97e411 100644 --- a/code/SystemFeature/AutoFill/AutoFill/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/AutoFill/AutoFill/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "PasswordBox" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "PasswordBox" + } + ] +} diff --git a/code/SystemFeature/AutoFill/AutoFill/build-profile.json5 b/code/SystemFeature/AutoFill/AutoFill/build-profile.json5 index 81843dac936883b1af0eee45ecc0eb202549e9de..7e17a4b32929406dffa5d71bcc322e2b4ccc5b0a 100644 --- a/code/SystemFeature/AutoFill/AutoFill/build-profile.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2023-2024 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": 14, - "compatibleSdkVersion": 14, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023-2024 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": 14, + "compatibleSdkVersion": 14, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/build-profile.json5 b/code/SystemFeature/AutoFill/AutoFill/entry/build-profile.json5 index 0c8525dfdde040a6d029cd2dc7bbddc5a5ee5353..910cc991f5e6483bbaebf92e26274ddd43db6f82 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/build-profile.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/oh-package.json5 b/code/SystemFeature/AutoFill/AutoFill/entry/oh-package.json5 index 60744fdbc79d1e21f9e40bd00955aa195ba84e22..225946cb11a2c405c8dc81eea89c22f923556638 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/oh-package.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillability/AutoFillAbility.ts b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillability/AutoFillAbility.ts index 68fab8e0da44d5e8c0baf777cf8cdbc531e6e891..a3cdc0da50d1d408e25742881558d6a19419f020 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillability/AutoFillAbility.ts +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillability/AutoFillAbility.ts @@ -1,98 +1,98 @@ -/* - * Copyright (c) 2023-2024 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 type { FillRequest, SaveRequest, FillRequestCallback, SaveRequestCallback } from 'application/AutoFillRequest'; -import { AutoFillExtensionAbility, autoFillManager, UIExtensionContentSession } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const AUTOFILLTYPE: number = 3; -const TAG: string = 'autoFillAbility'; -const DOMAIN_NUMBER: number = 0xFF00; -const BOTTOM_LEFT: number = 6; - -export default class AutoFillAbility extends AutoFillExtensionAbility { - onCreate(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onDestroy'); - } - - onSessionDestroy(session: UIExtensionContentSession): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSessionDestroy'); - hilog.info(DOMAIN_NUMBER, TAG, 'session content: %{public}s', JSON.stringify(session)); - } - - onForeground(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onForeground'); - } - - onBackground(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onBackground'); - } - - onFillRequest(session: UIExtensionContentSession, request: FillRequest, callback: FillRequestCallback): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onFillRequest'); - hilog.info(DOMAIN_NUMBER, TAG, 'fill requestCallback: %{public}s', JSON.stringify(callback)); - hilog.info(DOMAIN_NUMBER, TAG, 'get request viewData: ', JSON.stringify(request.viewData)); - try { - let storageFill = new LocalStorage( - { - 'session': session, - 'message': 'AutoFill Page', - 'fillCallback': callback, - 'viewData': request.viewData, - 'pageNodeInfos': request.viewData.pageNodeInfos, - 'autoFillExtensionContext': this.context, - 'customData': request.customData - }); - - let size: autoFillManager.PopupSize = { - width: 620, - height: 220 - }; - callback.setAutoFillPopupConfig({ - popupSize: size, - placement: BOTTOM_LEFT - }); - - request.viewData.pageNodeInfos.forEach((item) => { - if (item.autoFillType === AUTOFILLTYPE) { - session.loadContent('autofillpages/AutoFillNewPassWord', storageFill); - } else if (request.customData != undefined) { - session.loadContent('autofillpages/BiometricAuthentication', storageFill); - } else { - session.loadContent('autofillpages/AutoFillControl', storageFill); - } - }); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill failed to load content'); - } - } - - onSaveRequest(session: UIExtensionContentSession, request: SaveRequest, callback: SaveRequestCallback): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSaveRequest'); - - let storageSave = new LocalStorage( - { - 'session': session, - 'message': 'AutoFill Page', - 'saveCallback': callback, - 'viewData': request.viewData - }); - session.loadContent('autofillpages/SavePage', storageSave); - } -} +/* + * Copyright (c) 2023-2024 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 type { FillRequest, SaveRequest, FillRequestCallback, SaveRequestCallback } from 'application/AutoFillRequest'; +import { AutoFillExtensionAbility, autoFillManager, UIExtensionContentSession } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const AUTOFILLTYPE: number = 3; +const TAG: string = 'autoFillAbility'; +const DOMAIN_NUMBER: number = 0xFF00; +const BOTTOM_LEFT: number = 6; + +export default class AutoFillAbility extends AutoFillExtensionAbility { + onCreate(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onDestroy'); + } + + onSessionDestroy(session: UIExtensionContentSession): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSessionDestroy'); + hilog.info(DOMAIN_NUMBER, TAG, 'session content: %{public}s', JSON.stringify(session)); + } + + onForeground(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onForeground'); + } + + onBackground(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onBackground'); + } + + onFillRequest(session: UIExtensionContentSession, request: FillRequest, callback: FillRequestCallback): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onFillRequest'); + hilog.info(DOMAIN_NUMBER, TAG, 'fill requestCallback: %{public}s', JSON.stringify(callback)); + hilog.info(DOMAIN_NUMBER, TAG, 'get request viewData: ', JSON.stringify(request.viewData)); + try { + let storageFill = new LocalStorage( + { + 'session': session, + 'message': 'AutoFill Page', + 'fillCallback': callback, + 'viewData': request.viewData, + 'pageNodeInfos': request.viewData.pageNodeInfos, + 'autoFillExtensionContext': this.context, + 'customData': request.customData + }); + + let size: autoFillManager.PopupSize = { + width: 620, + height: 220 + }; + callback.setAutoFillPopupConfig({ + popupSize: size, + placement: BOTTOM_LEFT + }); + + request.viewData.pageNodeInfos.forEach((item) => { + if (item.autoFillType === AUTOFILLTYPE) { + session.loadContent('autofillpages/AutoFillNewPassWord', storageFill); + } else if (request.customData != undefined) { + session.loadContent('autofillpages/BiometricAuthentication', storageFill); + } else { + session.loadContent('autofillpages/AutoFillControl', storageFill); + } + }); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill failed to load content'); + } + } + + onSaveRequest(session: UIExtensionContentSession, request: SaveRequest, callback: SaveRequestCallback): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSaveRequest'); + + let storageSave = new LocalStorage( + { + 'session': session, + 'message': 'AutoFill Page', + 'saveCallback': callback, + 'viewData': request.viewData + }); + session.loadContent('autofillpages/SavePage', storageSave); + } +} diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillControl.ets b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillControl.ets index 886243a25147ba87316eaa522b07984a32b3dcb7..c9cf555d15718485ce87dad93e925947d14a5f92 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillControl.ets +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillControl.ets @@ -1,114 +1,114 @@ -/* - * Copyright (c) 2023-2024 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 { BusinessError } from '@ohos.base'; -import { autoFillManager, common } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const storage = LocalStorage.getShared(); -let viewData: autoFillManager.ViewData | undefined = storage.get('viewData'); -let context: common.AutoFillExtensionContext | undefined = storage.get('autoFillExtensionContext'); -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct AutoFillControl { - build() { - Row() { - Column() { - List({ space: 10, initialIndex: 0 }) { - ListItem() { - Text($r('app.string.user1')) - .width('100%') - .height(40) - .fontSize(16) - .textAlign(TextAlign.Center) - .borderRadius(5) - } - .onClick(() => { - if (context != undefined) { - let want: Record = {}; - context.reloadInModal({ data: { text: 'User1', want } }).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal successfully User1.'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal failed User1.'); - }) - } - }) - - ListItem() { - Text($r('app.string.user2')) - .width('100%') - .height(40) - .fontSize(16) - .textAlign(TextAlign.Center) - .borderRadius(5) - } - .onClick(() => { - if (viewData != undefined) { - if (context != undefined) { - let want: Record = {}; - context.reloadInModal({ data: { text: 'User2', want } }).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal successfully User2.'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal failed User2.'); - }) - } - } - }) - - ListItem() { - Text($r('app.string.user3')) - .width('100%') - .height(40) - .fontSize(16) - .textAlign(TextAlign.Center) - .borderRadius(5) - } - .onClick(() => { - if (viewData != undefined) { - if (context != undefined) { - let want: Record = {}; - context.reloadInModal({ data: { text: 'User3', want } }).then(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal successfully User3.'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal failed User3.'); - }) - } - } - }) - } - .listDirection(Axis.Vertical) - .scrollBar(BarState.Off) - .friction(0.6) - .divider({ strokeWidth: 1, color: $r('app.color.placeholderColor'), startMargin: 20, endMargin: 20 }) - .edgeEffect(EdgeEffect.Spring) - .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { - console.info('first' + firstIndex); - console.info('last' + lastIndex); - console.info('center' + centerIndex); - }) - .onScroll((scrollOffset: number, scrollState: ScrollState) => { - console.info(`onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset); - }) - } - .width('100%') - .shadow(ShadowStyle.OUTER_FLOATING_SM) - } - .height('100%') - .shadow(ShadowStyle.OUTER_FLOATING_SM) - } +/* + * Copyright (c) 2023-2024 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 { BusinessError } from '@ohos.base'; +import { autoFillManager, common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const storage = LocalStorage.getShared(); +let viewData: autoFillManager.ViewData | undefined = storage.get('viewData'); +let context: common.AutoFillExtensionContext | undefined = storage.get('autoFillExtensionContext'); +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct AutoFillControl { + build() { + Row() { + Column() { + List({ space: 10, initialIndex: 0 }) { + ListItem() { + Text($r('app.string.user1')) + .width('100%') + .height(40) + .fontSize(16) + .textAlign(TextAlign.Center) + .borderRadius(5) + } + .onClick(() => { + if (context != undefined) { + let want: Record = {}; + context.reloadInModal({ data: { text: 'User1', want } }).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal successfully User1.'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal failed User1.'); + }) + } + }) + + ListItem() { + Text($r('app.string.user2')) + .width('100%') + .height(40) + .fontSize(16) + .textAlign(TextAlign.Center) + .borderRadius(5) + } + .onClick(() => { + if (viewData != undefined) { + if (context != undefined) { + let want: Record = {}; + context.reloadInModal({ data: { text: 'User2', want } }).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal successfully User2.'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal failed User2.'); + }) + } + } + }) + + ListItem() { + Text($r('app.string.user3')) + .width('100%') + .height(40) + .fontSize(16) + .textAlign(TextAlign.Center) + .borderRadius(5) + } + .onClick(() => { + if (viewData != undefined) { + if (context != undefined) { + let want: Record = {}; + context.reloadInModal({ data: { text: 'User3', want } }).then(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal successfully User3.'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN_NUMBER, TAG, 'reloadInModal failed User3.'); + }) + } + } + }) + } + .listDirection(Axis.Vertical) + .scrollBar(BarState.Off) + .friction(0.6) + .divider({ strokeWidth: 1, color: $r('app.color.placeholderColor'), startMargin: 20, endMargin: 20 }) + .edgeEffect(EdgeEffect.Spring) + .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { + console.info('first' + firstIndex); + console.info('last' + lastIndex); + console.info('center' + centerIndex); + }) + .onScroll((scrollOffset: number, scrollState: ScrollState) => { + console.info(`onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + scrollOffset); + }) + } + .width('100%') + .shadow(ShadowStyle.OUTER_FLOATING_SM) + } + .height('100%') + .shadow(ShadowStyle.OUTER_FLOATING_SM) + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillNewPassWord.ets b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillNewPassWord.ets index 431a89829ed4ccc976ae050e54987af47d249cca..db80aba105c56b5e3a23b9050636fbce975f5cba 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillNewPassWord.ets +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/AutoFillNewPassWord.ets @@ -1,123 +1,123 @@ -/* - * Copyright (c) 2023-2024 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 { FillRequestCallback, FillResponse } from 'application/AutoFillRequest'; -import ViewData from 'application/ViewData'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -let storage = LocalStorage.getShared(); -let fillCallback: FillRequestCallback | undefined = storage.get('fillCallback'); -let viewData: ViewData | undefined = storage.get('viewData'); -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; - -function successFunc(data: ViewData) { - if (data.pageNodeInfos.length !== 3) { - hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', 'get unEnough pageNodeInfos, skipping!'); - return; - } - data.pageNodeInfos[2].value = 'user1 new password'; - - hilog.info(DOMAIN_NUMBER, TAG, 'autofill about to success with viewData: %{public}s', JSON.stringify(viewData)); - if (fillCallback) { - let response: FillResponse = { viewData: data }; - fillCallback.onSuccess(response); - } -} - -function cancelFunc() { - if (fillCallback) { - fillCallback.onCancel(); - } -} - -@Entry -@Component -struct AutoFillNewPassWord { - build() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image($r('app.media.ic_public_back')) - .height(24) - .width(24) - .onClick(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'autofill cancel'); - cancelFunc(); - }) - Text($r('app.string.newPassword_title')) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(20) - .fontColor($r('app.color.userPassWord_title')) - .margin({ left: '4.4%' }) - }.margin({ top: '8.8%', left: '4.9%' }).height('7.2%') - - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) { - Text($r('app.string.passWord')) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(16) - .fontColor($r('app.color.userPassWord_title')) - .fontWeight(500) - Text($r('app.string.new_Password')) - .fontSize(14) - .fontFamily('HarmonyHeiTi') - .fontWeight(400) - .fontColor($r('app.color.userPassWord_title')) - } - .borderRadius(24) - .backgroundColor($r('app.color.controlBackColor')) - .width('95%') - .height('9.2%') - .padding({ top: '3.8%', left: '3.3%' }) - - Row() { - Text($r('app.string.cancel')) - .backgroundColor($r('app.color.cancelBackColor')) - .borderRadius(20) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(16) - .fontWeight(500) - .lineHeight(22) - .width('41.7%') - .height('16.5%') - .id('Cancel') - .fontColor($r('app.color.cancelBtnColor')) - .textAlign(TextAlign.Center) - .onClick(() => { - cancelFunc(); - }) - Text($r('app.string.confirm')) - .backgroundColor($r('app.color.cancelBtnColor')) - .borderRadius(20) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(16) - .fontWeight(500) - .lineHeight(22) - .fontColor($r('app.color.controlBackColor')) - .width('41.7%') - .height('16.5%') - .textAlign(TextAlign.Center) - .margin({ left: '3.3%' }) - .id('confirm') - .onClick(() => { - if (viewData != undefined) { - successFunc(viewData); - } - }) - }.margin({ top: 550 }) - } - .height('100%').backgroundColor($r('app.color.pageBackColor')) - } +/* + * Copyright (c) 2023-2024 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 { FillRequestCallback, FillResponse } from 'application/AutoFillRequest'; +import ViewData from 'application/ViewData'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +let storage = LocalStorage.getShared(); +let fillCallback: FillRequestCallback | undefined = storage.get('fillCallback'); +let viewData: ViewData | undefined = storage.get('viewData'); +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; + +function successFunc(data: ViewData) { + if (data.pageNodeInfos.length !== 3) { + hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', 'get unEnough pageNodeInfos, skipping!'); + return; + } + data.pageNodeInfos[2].value = 'user1 new password'; + + hilog.info(DOMAIN_NUMBER, TAG, 'autofill about to success with viewData: %{public}s', JSON.stringify(viewData)); + if (fillCallback) { + let response: FillResponse = { viewData: data }; + fillCallback.onSuccess(response); + } +} + +function cancelFunc() { + if (fillCallback) { + fillCallback.onCancel(); + } +} + +@Entry +@Component +struct AutoFillNewPassWord { + build() { + Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Image($r('app.media.ic_public_back')) + .height(24) + .width(24) + .onClick(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'autofill cancel'); + cancelFunc(); + }) + Text($r('app.string.newPassword_title')) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(20) + .fontColor($r('app.color.userPassWord_title')) + .margin({ left: '4.4%' }) + }.margin({ top: '8.8%', left: '4.9%' }).height('7.2%') + + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) { + Text($r('app.string.passWord')) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(16) + .fontColor($r('app.color.userPassWord_title')) + .fontWeight(500) + Text($r('app.string.new_Password')) + .fontSize(14) + .fontFamily('HarmonyHeiTi') + .fontWeight(400) + .fontColor($r('app.color.userPassWord_title')) + } + .borderRadius(24) + .backgroundColor($r('app.color.controlBackColor')) + .width('95%') + .height('9.2%') + .padding({ top: '3.8%', left: '3.3%' }) + + Row() { + Text($r('app.string.cancel')) + .backgroundColor($r('app.color.cancelBackColor')) + .borderRadius(20) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(16) + .fontWeight(500) + .lineHeight(22) + .width('41.7%') + .height('16.5%') + .id('Cancel') + .fontColor($r('app.color.cancelBtnColor')) + .textAlign(TextAlign.Center) + .onClick(() => { + cancelFunc(); + }) + Text($r('app.string.confirm')) + .backgroundColor($r('app.color.cancelBtnColor')) + .borderRadius(20) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(16) + .fontWeight(500) + .lineHeight(22) + .fontColor($r('app.color.controlBackColor')) + .width('41.7%') + .height('16.5%') + .textAlign(TextAlign.Center) + .margin({ left: '3.3%' }) + .id('confirm') + .onClick(() => { + if (viewData != undefined) { + successFunc(viewData); + } + }) + }.margin({ top: 550 }) + } + .height('100%').backgroundColor($r('app.color.pageBackColor')) + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/BiometricAuthentication.ets b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/BiometricAuthentication.ets old mode 100755 new mode 100644 index 46f737189085bdbd53f76e6e7a7e55984b2351f7..07573c924150e5b9d6ef827482d7f0208cf59b30 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/BiometricAuthentication.ets +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/BiometricAuthentication.ets @@ -1,158 +1,158 @@ -/* - * Copyright (c) 2024 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 { FillRequestCallback, FillResponse } from 'application/AutoFillRequest'; -import ViewData from 'application/ViewData'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { autoFillManager } from '@kit.AbilityKit'; - -const storage = LocalStorage.getShared(); -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; -let fillCallback: FillRequestCallback | undefined = storage.get('fillCallback'); -let viewData: ViewData | undefined = storage.get('viewData'); -let customData: autoFillManager.CustomData | undefined = storage.get('customData'); - -function successFunc(data: ViewData, userName: string, passWord: string) { - if (data.pageNodeInfos.length !== 2) { - hilog.info(DOMAIN_NUMBER, TAG, 'get unEnough pageNodeInfos, skipping!'); - return; - } else { - data.pageNodeInfos[0].value = userName; - data.pageNodeInfos[1].value = passWord; - } - if (fillCallback) { - let response: FillResponse = { viewData: data }; - fillCallback.onSuccess(response); - } -} - -function cancelFunc() { - if (fillCallback) { - fillCallback.onCancel(); - } -} - -function onFailure() { - if (fillCallback) { - fillCallback.onFailure(); - } -} - -@Entry -@Component -struct BiometricAuthentication { - @State message: Resource = $r('app.string.biological_Certification'); - - build() { - Column() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image($r('app.media.arrow')) - .height(40) - .width(40) - .onClick(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'autofill cancel'); - cancelFunc(); - }) - Text(this.message) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(22) - .fontColor($r('app.color.userPassWord_title')) - .margin({ left: '2.4%' }) - }.margin({ top: '13.8%', left: '4.9%' }).height('7.2%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Image($r('app.media.svg')) - .height(58) - .width(58) - }.margin({ top: '42.8%' }) - } - .height('70%') - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.End }) { - Column() { - Row() { - Button($r('app.string.success')) - .type(ButtonType.Normal) - .fontSize(16) - .fontWeight(500) - .id('success') - .backgroundColor($r('app.color.cancelBtnColor')) - .borderRadius(20) - .height(40) - .width('86.7%') - .onClick(() => { - if (customData != undefined) { - if (viewData != undefined) { - hilog.info(DOMAIN_NUMBER, TAG, 'Reload in modal custom data is ', JSON.stringify(customData.data)); - let flag = customData.data.text as string; - if (fillCallback != undefined) { - if (flag == 'User1') { - successFunc(viewData, 'user1', '123456'); - } else if (flag == 'User2') { - successFunc(viewData, 'user2', 'abcdef'); - } else if (flag == 'User3') { - successFunc(viewData, 'user3', 'ABCDEF'); - } else { - return; - } - } - } - } - }) - } - .margin({ bottom: '12vp' }) - - Row() { - Button($r('app.string.fail')) - .type(ButtonType.Normal) - .fontSize(16) - .fontWeight(500) - .backgroundColor($r('app.color.cancelBtnColor')) - .borderRadius(20) - .id('fail') - .height(40) - .width('86.7%') - .onClick(() => { - onFailure(); - }) - } - .margin({ bottom: '12vp' }) - - Row() { - Button($r('app.string.onCancel')) - .type(ButtonType.Normal) - .fontSize(16) - .fontWeight(500) - .backgroundColor($r('app.color.cancelColor')) - .fontColor($r('app.color.cancelBtnColor')) - .id('cancel') - .borderRadius(20) - .height(40) - .width('86.7%') - .onClick(() => { - cancelFunc(); - }) - } - } - .margin({ bottom: '44vp' }) - } - .height('30%') - } - .backgroundColor($r('app.color.pageBackColor')).height('100%') - } -} +/* + * Copyright (c) 2024 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 { FillRequestCallback, FillResponse } from 'application/AutoFillRequest'; +import ViewData from 'application/ViewData'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { autoFillManager } from '@kit.AbilityKit'; + +const storage = LocalStorage.getShared(); +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; +let fillCallback: FillRequestCallback | undefined = storage.get('fillCallback'); +let viewData: ViewData | undefined = storage.get('viewData'); +let customData: autoFillManager.CustomData | undefined = storage.get('customData'); + +function successFunc(data: ViewData, userName: string, passWord: string) { + if (data.pageNodeInfos.length !== 2) { + hilog.info(DOMAIN_NUMBER, TAG, 'get unEnough pageNodeInfos, skipping!'); + return; + } else { + data.pageNodeInfos[0].value = userName; + data.pageNodeInfos[1].value = passWord; + } + if (fillCallback) { + let response: FillResponse = { viewData: data }; + fillCallback.onSuccess(response); + } +} + +function cancelFunc() { + if (fillCallback) { + fillCallback.onCancel(); + } +} + +function onFailure() { + if (fillCallback) { + fillCallback.onFailure(); + } +} + +@Entry +@Component +struct BiometricAuthentication { + @State message: Resource = $r('app.string.biological_Certification'); + + build() { + Column() { + Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Image($r('app.media.arrow')) + .height(40) + .width(40) + .onClick(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'autofill cancel'); + cancelFunc(); + }) + Text(this.message) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(22) + .fontColor($r('app.color.userPassWord_title')) + .margin({ left: '2.4%' }) + }.margin({ top: '13.8%', left: '4.9%' }).height('7.2%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Image($r('app.media.svg')) + .height(58) + .width(58) + }.margin({ top: '42.8%' }) + } + .height('70%') + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.End }) { + Column() { + Row() { + Button($r('app.string.success')) + .type(ButtonType.Normal) + .fontSize(16) + .fontWeight(500) + .id('success') + .backgroundColor($r('app.color.cancelBtnColor')) + .borderRadius(20) + .height(40) + .width('86.7%') + .onClick(() => { + if (customData != undefined) { + if (viewData != undefined) { + hilog.info(DOMAIN_NUMBER, TAG, 'Reload in modal custom data is ', JSON.stringify(customData.data)); + let flag = customData.data.text as string; + if (fillCallback != undefined) { + if (flag == 'User1') { + successFunc(viewData, 'user1', '123456'); + } else if (flag == 'User2') { + successFunc(viewData, 'user2', 'abcdef'); + } else if (flag == 'User3') { + successFunc(viewData, 'user3', 'ABCDEF'); + } else { + return; + } + } + } + } + }) + } + .margin({ bottom: '12vp' }) + + Row() { + Button($r('app.string.fail')) + .type(ButtonType.Normal) + .fontSize(16) + .fontWeight(500) + .backgroundColor($r('app.color.cancelBtnColor')) + .borderRadius(20) + .id('fail') + .height(40) + .width('86.7%') + .onClick(() => { + onFailure(); + }) + } + .margin({ bottom: '12vp' }) + + Row() { + Button($r('app.string.onCancel')) + .type(ButtonType.Normal) + .fontSize(16) + .fontWeight(500) + .backgroundColor($r('app.color.cancelColor')) + .fontColor($r('app.color.cancelBtnColor')) + .id('cancel') + .borderRadius(20) + .height(40) + .width('86.7%') + .onClick(() => { + cancelFunc(); + }) + } + } + .margin({ bottom: '44vp' }) + } + .height('30%') + } + .backgroundColor($r('app.color.pageBackColor')).height('100%') + } +} diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/LoginSuccessPage.ets b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/LoginSuccessPage.ets index 3eb96fe7a4c93c2da8b4c5cb671240388b1816b9..3d69f339ddbd1ae2f5b839fa8c9c84477f3f9e5c 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/LoginSuccessPage.ets +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/LoginSuccessPage.ets @@ -1,31 +1,31 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@Entry -@Component -struct LoginSuccessPage { - build() { - Column() { - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Text($r('app.string.loginSuccess')) - .fontSize(24) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontColor($r('app.color.user')) - }.margin({ top: '32.3%' }).width('35%').height('4.1%') - }.backgroundColor($r('app.color.pageBackColor')).height('100%').width('100%') - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Entry +@Component +struct LoginSuccessPage { + build() { + Column() { + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Text($r('app.string.loginSuccess')) + .fontSize(24) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontColor($r('app.color.user')) + }.margin({ top: '32.3%' }).width('35%').height('4.1%') + }.backgroundColor($r('app.color.pageBackColor')).height('100%').width('100%') + } +} + diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/RegisterPage.ets b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/RegisterPage.ets index 15ec594b801c9290e42e21b958c3de1912cdcf6a..b5aeb30e3e055c95e33b972d9ce09831da4cc9e7 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/RegisterPage.ets +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/RegisterPage.ets @@ -1,194 +1,194 @@ -/* - * Copyright (c) 2023-2024 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 { autoFillManager, common } from '@kit.AbilityKit'; -import { UIContext } from '@ohos.arkui.UIContext'; -import { router, promptAction } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -let options: router.RouterOptions = { - url: 'autofillpages/LoginSuccessPage' -}; -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct RegisterPage { - @State registerBtnColor: Resource = $r('app.color.enableColor'); - @State codeNumber: string = ''; - @State isShowLoginBtn: Boolean = false; - private registerSuccess: string = ''; - private context = getContext(this) as common.UIAbilityContext; - - aboutToAppear() { - this.context.resourceManager.getStringValue($r('app.string.registerSuccess')).then((value) => { - this.registerSuccess = value.toString(); - }) - } - - @Builder MyBuilderFunction() { - Text($r('app.string.getCodeNumber')) - .borderRadius(20) - .fontColor($r('app.color.cancelBtnColor')) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .backgroundColor($r('app.color.cancelBackColor')) - .width('33.3%') - .height('80%') - .lineHeight(25) - .textAlign(TextAlign.Center) - .fontSize(16) - .margin({ left: '65%' }) - .onClick(() => { - this.codeNumber = '565789'; - }) - } - - build() { - Column() { - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Text($r('app.string.Welcome')) - .fontSize(24) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontColor($r('app.color.user')) - }.margin({ top: '32.3%' }).width('35%').height('4.1%') - - List() { - ListItemGroup({ style: ListItemGroupStyle.CARD }) { - ListItem({ style: ListItemStyle.CARD }) { - TextInput({ placeholder: $r('app.string.phoneNumber') }) - .type(InputType.PhoneNumber) - .fontFamily('HarmonyHeiTi') - .fontColor($r('app.color.user')) - .fontWeight(400) - .fontSize(16) - .height('100%') - .backgroundColor($r('app.color.controlBackColor')) - .onChange((value: string) => { - if (value) { - this.registerBtnColor = $r('app.color.cancelBtnColor'); - } else { - this.registerBtnColor = $r('app.color.enableColor'); - } - }) - }.padding(0) - - // password container - ListItem({ style: ListItemStyle.CARD }) { - TextInput({ placeholder: $r('app.string.codeNumber'), text: this.codeNumber }) - .fontFamily('HarmonyHeiTi') - .fontColor($r('app.color.user')) - .fontWeight(400) - .height('100%') - .fontSize(16) - .backgroundColor($r('app.color.controlBackColor')) - .onChange((value: string) => { - this.codeNumber = value; - if (value) { - this.registerBtnColor = $r('app.color.cancelBtnColor'); - } else { - this.registerBtnColor = $r('app.color.enableColor'); - } - }) - this.MyBuilderFunction() - } - .margin({ top: 2 }) - .padding(0) - - // newPassword container - ListItem({ style: ListItemStyle.CARD }) { - TextInput({ placeholder: $r('app.string.create_password') }) - .type(InputType.NEW_PASSWORD) - .backgroundColor($r('app.color.controlBackColor')) - .fontFamily('HarmonyHeiTi') - .fontColor($r('app.color.user')) - .fontWeight(400) - .fontSize(16) - .height('100%') - .enableAutoFill(true) - .id('newPassWord') - .onChange((value: string) => { - if (value) { - this.registerBtnColor = $r('app.color.cancelBtnColor'); - } else { - this.registerBtnColor = $r('app.color.enableColor'); - } - }) - }.padding(0).margin({ top: 2 }) - }.divider({ strokeWidth: 0.5, color: $r('app.color.pageBackColor'), startMargin: 15, endMargin: 15 }) - } - .borderRadius(24) - .width('93.3%') - .height('22%') - .margin({ top: '8.6%' }) - - Flex({ justifyContent: FlexAlign.Center, alignContent: FlexAlign.SpaceBetween }) { - if (this.isShowLoginBtn) { - Button($r('app.string.login')) - .width('86.7%') - .height('5.1%') - .fontSize(16) - .fontFamily('HarmonyHeiTi-Medium') - .fontColor($r('app.color.controlBackColor')) - .fontWeight(500) - .backgroundColor(this.registerBtnColor) - .borderRadius(20) - .id('login') - .onClick(() => { - router.pushUrl(options, (err, data) => { - hilog.info(DOMAIN_NUMBER, TAG, 'page jump to LoginSuccessPage page', - JSON.stringify(err), JSON.stringify(data)); - }) - }) - } else { - Button($r('app.string.register_now')) - .width('86.7%') - .height('5.1%') - .fontSize(16) - .fontFamily('HarmonyHeiTi-Medium') - .fontColor($r('app.color.controlBackColor')) - .fontWeight(500) - .backgroundColor(this.registerBtnColor) - .borderRadius(20) - .id('registerNowBtn') - .onClick(() => { - this.isShowLoginBtn = true; - SaveFunc(); - promptAction.showToast({ - message: this.registerSuccess, - duration: 2000, - }) - }) - } - }.margin({ top: '6.3%' }) - }.backgroundColor($r('app.color.pageBackColor')).height('100%') - } -} - -function SaveFunc() { - hilog.info(DOMAIN_NUMBER, TAG, 'send save request'); - let context = AppStorage.get('uiContext'); - hilog.info(DOMAIN_NUMBER, TAG, 'UIContext: ', JSON.stringify(context)); - autoFillManager.requestAutoSave(context, { - onSuccess: () => { - hilog.info(DOMAIN_NUMBER, TAG, 'save request on success'); - }, - onFailure: () => { - hilog.info(DOMAIN_NUMBER, TAG, 'save request on failure'); - } - }); +/* + * Copyright (c) 2023-2024 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 { autoFillManager, common } from '@kit.AbilityKit'; +import { UIContext } from '@ohos.arkui.UIContext'; +import { router, promptAction } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +let options: router.RouterOptions = { + url: 'autofillpages/LoginSuccessPage' +}; +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct RegisterPage { + @State registerBtnColor: Resource = $r('app.color.enableColor'); + @State codeNumber: string = ''; + @State isShowLoginBtn: Boolean = false; + private registerSuccess: string = ''; + private context = getContext(this) as common.UIAbilityContext; + + aboutToAppear() { + this.context.resourceManager.getStringValue($r('app.string.registerSuccess')).then((value) => { + this.registerSuccess = value.toString(); + }) + } + + @Builder MyBuilderFunction() { + Text($r('app.string.getCodeNumber')) + .borderRadius(20) + .fontColor($r('app.color.cancelBtnColor')) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .backgroundColor($r('app.color.cancelBackColor')) + .width('33.3%') + .height('80%') + .lineHeight(25) + .textAlign(TextAlign.Center) + .fontSize(16) + .margin({ left: '65%' }) + .onClick(() => { + this.codeNumber = '565789'; + }) + } + + build() { + Column() { + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Text($r('app.string.Welcome')) + .fontSize(24) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontColor($r('app.color.user')) + }.margin({ top: '32.3%' }).width('35%').height('4.1%') + + List() { + ListItemGroup({ style: ListItemGroupStyle.CARD }) { + ListItem({ style: ListItemStyle.CARD }) { + TextInput({ placeholder: $r('app.string.phoneNumber') }) + .type(InputType.PhoneNumber) + .fontFamily('HarmonyHeiTi') + .fontColor($r('app.color.user')) + .fontWeight(400) + .fontSize(16) + .height('100%') + .backgroundColor($r('app.color.controlBackColor')) + .onChange((value: string) => { + if (value) { + this.registerBtnColor = $r('app.color.cancelBtnColor'); + } else { + this.registerBtnColor = $r('app.color.enableColor'); + } + }) + }.padding(0) + + // password container + ListItem({ style: ListItemStyle.CARD }) { + TextInput({ placeholder: $r('app.string.codeNumber'), text: this.codeNumber }) + .fontFamily('HarmonyHeiTi') + .fontColor($r('app.color.user')) + .fontWeight(400) + .height('100%') + .fontSize(16) + .backgroundColor($r('app.color.controlBackColor')) + .onChange((value: string) => { + this.codeNumber = value; + if (value) { + this.registerBtnColor = $r('app.color.cancelBtnColor'); + } else { + this.registerBtnColor = $r('app.color.enableColor'); + } + }) + this.MyBuilderFunction() + } + .margin({ top: 2 }) + .padding(0) + + // newPassword container + ListItem({ style: ListItemStyle.CARD }) { + TextInput({ placeholder: $r('app.string.create_password') }) + .type(InputType.NEW_PASSWORD) + .backgroundColor($r('app.color.controlBackColor')) + .fontFamily('HarmonyHeiTi') + .fontColor($r('app.color.user')) + .fontWeight(400) + .fontSize(16) + .height('100%') + .enableAutoFill(true) + .id('newPassWord') + .onChange((value: string) => { + if (value) { + this.registerBtnColor = $r('app.color.cancelBtnColor'); + } else { + this.registerBtnColor = $r('app.color.enableColor'); + } + }) + }.padding(0).margin({ top: 2 }) + }.divider({ strokeWidth: 0.5, color: $r('app.color.pageBackColor'), startMargin: 15, endMargin: 15 }) + } + .borderRadius(24) + .width('93.3%') + .height('22%') + .margin({ top: '8.6%' }) + + Flex({ justifyContent: FlexAlign.Center, alignContent: FlexAlign.SpaceBetween }) { + if (this.isShowLoginBtn) { + Button($r('app.string.login')) + .width('86.7%') + .height('5.1%') + .fontSize(16) + .fontFamily('HarmonyHeiTi-Medium') + .fontColor($r('app.color.controlBackColor')) + .fontWeight(500) + .backgroundColor(this.registerBtnColor) + .borderRadius(20) + .id('login') + .onClick(() => { + router.pushUrl(options, (err, data) => { + hilog.info(DOMAIN_NUMBER, TAG, 'page jump to LoginSuccessPage page', + JSON.stringify(err), JSON.stringify(data)); + }) + }) + } else { + Button($r('app.string.register_now')) + .width('86.7%') + .height('5.1%') + .fontSize(16) + .fontFamily('HarmonyHeiTi-Medium') + .fontColor($r('app.color.controlBackColor')) + .fontWeight(500) + .backgroundColor(this.registerBtnColor) + .borderRadius(20) + .id('registerNowBtn') + .onClick(() => { + this.isShowLoginBtn = true; + SaveFunc(); + promptAction.showToast({ + message: this.registerSuccess, + duration: 2000, + }) + }) + } + }.margin({ top: '6.3%' }) + }.backgroundColor($r('app.color.pageBackColor')).height('100%') + } +} + +function SaveFunc() { + hilog.info(DOMAIN_NUMBER, TAG, 'send save request'); + let context = AppStorage.get('uiContext'); + hilog.info(DOMAIN_NUMBER, TAG, 'UIContext: ', JSON.stringify(context)); + autoFillManager.requestAutoSave(context, { + onSuccess: () => { + hilog.info(DOMAIN_NUMBER, TAG, 'save request on success'); + }, + onFailure: () => { + hilog.info(DOMAIN_NUMBER, TAG, 'save request on failure'); + } + }); } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/SavePage.ets b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/SavePage.ets index 2a55ec0814c741813d1c2c4707dd23684ebb5025..5f880b90c99dc8631dcce83a511ef6e41c710fb7 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/SavePage.ets +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/autofillpages/SavePage.ets @@ -1,107 +1,107 @@ -/* - * Copyright (c) 2023-2024 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 { SaveRequestCallback } from 'application/AutoFillRequest'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const storage = LocalStorage.getShared(); -const saveRequestCallback: SaveRequestCallback | undefined = storage.get('saveCallback'); - -function SuccessFunc(success: boolean) { - if (saveRequestCallback) { - if (success) { - saveRequestCallback.onSuccess(); - } - saveRequestCallback.onFailure(); - } - hilog.error(0x0000, 'testTag', '%{public}s', 'saveRequestCallback is nullptr!'); -} - -@Entry -@Component -struct SavePage { - build() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image($r('app.media.ic_public_back')) - .height(24) - .width(24) - .onClick(() => { - hilog.info(0x0000, 'testTag', '%{public}s', 'save cancel'); - SuccessFunc(false); - }) - Text($r('app.string.saveInfo')) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(20) - .fontColor($r('app.color.userPassWord_title')) - .margin({ left: '4.4%' }) - .id('Save') - }.margin({ top: '8.8%', left: '4.9%' }).height('7.2%') - - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) { - Text($r('app.string.passWord')) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(16) - .fontColor($r('app.color.userPassWord_title')) - .fontWeight(500) - Text($r('app.string.new_Password')) - .fontSize(14) - .fontFamily('HarmonyHeiTi') - .fontWeight(400) - .fontColor($r('app.color.userPassWord_title')) - } - .borderRadius(24) - .backgroundColor($r('app.color.controlBackColor')) - .width('95%') - .height('9.2%') - .padding({ top: '3.8%', left: '3.3%' }) - - Row() { - Text($r('app.string.cancel')) - .backgroundColor($r('app.color.cancelBackColor')) - .borderRadius(20) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(16) - .fontWeight(500) - .lineHeight(22) - .width('41.7%') - .height('16.5%') - .fontColor($r('app.color.cancelBtnColor')) - .textAlign(TextAlign.Center) - .onClick(() => { - SuccessFunc(false); - }) - Text($r('app.string.confirm')) - .backgroundColor($r('app.color.cancelBtnColor')) - .borderRadius(20) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(16) - .fontWeight(500) - .lineHeight(22) - .fontColor($r('app.color.controlBackColor')) - .width('41.7%') - .height('16.5%') - .textAlign(TextAlign.Center) - .margin({ left: '3.3%' }) - .id('saveConfirm') - .onClick(() => { - SuccessFunc(true); - }) - }.margin({ top: 550 }) - } - .height('100%').backgroundColor($r('app.color.pageBackColor')) - } +/* + * Copyright (c) 2023-2024 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 { SaveRequestCallback } from 'application/AutoFillRequest'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const storage = LocalStorage.getShared(); +const saveRequestCallback: SaveRequestCallback | undefined = storage.get('saveCallback'); + +function SuccessFunc(success: boolean) { + if (saveRequestCallback) { + if (success) { + saveRequestCallback.onSuccess(); + } + saveRequestCallback.onFailure(); + } + hilog.error(0x0000, 'testTag', '%{public}s', 'saveRequestCallback is nullptr!'); +} + +@Entry +@Component +struct SavePage { + build() { + Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Image($r('app.media.ic_public_back')) + .height(24) + .width(24) + .onClick(() => { + hilog.info(0x0000, 'testTag', '%{public}s', 'save cancel'); + SuccessFunc(false); + }) + Text($r('app.string.saveInfo')) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(20) + .fontColor($r('app.color.userPassWord_title')) + .margin({ left: '4.4%' }) + .id('Save') + }.margin({ top: '8.8%', left: '4.9%' }).height('7.2%') + + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start }) { + Text($r('app.string.passWord')) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(16) + .fontColor($r('app.color.userPassWord_title')) + .fontWeight(500) + Text($r('app.string.new_Password')) + .fontSize(14) + .fontFamily('HarmonyHeiTi') + .fontWeight(400) + .fontColor($r('app.color.userPassWord_title')) + } + .borderRadius(24) + .backgroundColor($r('app.color.controlBackColor')) + .width('95%') + .height('9.2%') + .padding({ top: '3.8%', left: '3.3%' }) + + Row() { + Text($r('app.string.cancel')) + .backgroundColor($r('app.color.cancelBackColor')) + .borderRadius(20) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(16) + .fontWeight(500) + .lineHeight(22) + .width('41.7%') + .height('16.5%') + .fontColor($r('app.color.cancelBtnColor')) + .textAlign(TextAlign.Center) + .onClick(() => { + SuccessFunc(false); + }) + Text($r('app.string.confirm')) + .backgroundColor($r('app.color.cancelBtnColor')) + .borderRadius(20) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(16) + .fontWeight(500) + .lineHeight(22) + .fontColor($r('app.color.controlBackColor')) + .width('41.7%') + .height('16.5%') + .textAlign(TextAlign.Center) + .margin({ left: '3.3%' }) + .id('saveConfirm') + .onClick(() => { + SuccessFunc(true); + }) + }.margin({ top: 550 }) + } + .height('100%').backgroundColor($r('app.color.pageBackColor')) + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/entryability/EntryAbility.ts index cbd7ab860a1fa5ccf179b4301213ecfefb3b861f..b03513e91841c8dc47a5beaa79ec302ca3735060 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2023-2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import type { UIContext, window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'entryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - AppStorage.link('uiContext'); - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - let storage = new LocalStorage( - { - 'message': 'Index Page', - }); - windowStage.loadContent('pages/Index', storage, (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - let errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); - // get UIContext instance - let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); - PersistentStorage.persistProp('uiContext', uiContext); - }); - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023-2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import type { UIContext, window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'entryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + AppStorage.link('uiContext'); + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + let storage = new LocalStorage( + { + 'message': 'Index Page', + }); + windowStage.loadContent('pages/Index', storage, (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + + windowStage.getMainWindow((err: BusinessError, data: window.Window) => { + let errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); + // get UIContext instance + let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); + PersistentStorage.persistProp('uiContext', uiContext); + }); + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/log/Logger.ts b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/log/Logger.ts index 8072a6d5e7b3edd860cda46eb39dcb2d4f6b2b92..41f3d658f47a4aaf47b155aef9f3e86196c22427 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/log/Logger.ts +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/ets/log/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private pre: string = '[Sample_AUTOFILL]'; - private format: string = '%{public}s, %{public}d'; - - constructor(pre: string) { - this.pre = pre; - this.domain = 0xF811; - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.pre, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.pre, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.pre, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.pre, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private pre: string = '[Sample_AUTOFILL]'; + private format: string = '%{public}s, %{public}d'; + + constructor(pre: string) { + this.pre = pre; + this.domain = 0xF811; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.pre, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.pre, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.pre, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.pre, this.format, args); + } +} + export default new Logger('[Sample_AUTOFILL]'); \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/module.json5 b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/module.json5 index 1532e2c3741e22959791119f319e42459fab8991..9b961952281f43177edd09117299e09059555773 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/module.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/module.json5 @@ -1,62 +1,62 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "AutoFillAbility", - "srcEntry": "./ets/autofillability/AutoFillAbility.ts", - "description": "$string:AutofillAbility_desc", - "icon": "$media:icon", - "label": "$string:AutofillAbility_label", - "type": "autoFill/password" - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "AutoFillAbility", + "srcEntry": "./ets/autofillability/AutoFillAbility.ts", + "description": "$string:AutofillAbility_desc", + "icon": "$media:icon", + "label": "$string:AutofillAbility_label", + "type": "autoFill/password" + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/element/color.json b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/element/color.json index c9116bfc0bc15a91ef9670acdf40e6090af5b400..e9df5b0b18e7c02ad494700e227b89de2332c8bb 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/element/color.json @@ -1,48 +1,48 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "userPassWord_title", - "value": "#000000" - }, - { - "name": "user", - "value": "#182431" - }, - { - "name": "controlBackColor", - "value": "#FFFFFF" - }, - { - "name": "pageBackColor", - "value": "#f1f3f5" - }, - { - "name": "cancelBackColor", - "value": "#1824310c" - }, - { - "name": "cancelBtnColor", - "value": "#0A59F7" - }, - { - "name": "enableColor", - "value": "#bfdbf9" - }, - { - "name": "NoAccountColor", - "value": "#6f7780" - }, - { - "name": "cancelColor", - "value": "#FDE5E9E9" - }, - { - "name": "placeholderColor", - "value": "#fff5eeee" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "userPassWord_title", + "value": "#000000" + }, + { + "name": "user", + "value": "#182431" + }, + { + "name": "controlBackColor", + "value": "#FFFFFF" + }, + { + "name": "pageBackColor", + "value": "#f1f3f5" + }, + { + "name": "cancelBackColor", + "value": "#1824310c" + }, + { + "name": "cancelBtnColor", + "value": "#0A59F7" + }, + { + "name": "enableColor", + "value": "#bfdbf9" + }, + { + "name": "NoAccountColor", + "value": "#6f7780" + }, + { + "name": "cancelColor", + "value": "#FDE5E9E9" + }, + { + "name": "placeholderColor", + "value": "#fff5eeee" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/media/arrow.svg b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/media/arrow.svg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/media/svg.png b/code/SystemFeature/AutoFill/AutoFill/entry/src/main/resources/base/media/svg.png old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/ets/util/Logger.ts b/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/ets/util/Logger.ts index 0bc128a9f58383b3e9870945d946f0d1fb49b799..a82540eaffb665f34c5ef83670c091bdb09ec2e9 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/ets/util/Logger.ts +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/ets/util/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private pre: string = ''; - private format: string = '%{public}s, %{public}s'; - - constructor(pre: string) { - this.pre = pre; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.pre, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.pre, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.pre, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.pre, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private pre: string = ''; + private format: string = '%{public}s, %{public}s'; + + constructor(pre: string) { + this.pre = pre; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.pre, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.pre, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.pre, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.pre, this.format, args); + } +} + export default new Logger('[Sample_AUTOFILL]'); \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/module.json5 b/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/module.json5 index 4706623905317528fb208981086fd6e92c1868be..c29979a086796bf6af7ce517cf9a89fd4c206aa0 100644 --- a/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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 permissioAutoFillSampleTestns and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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 permissioAutoFillSampleTestns and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/SystemFeature/AutoFill/AutoFill/hvigor/hvigor-config.json5 b/code/SystemFeature/AutoFill/AutoFill/hvigor/hvigor-config.json5 index bbe82f2ceb84f343909c37b38bda09ed4e8b632e..5ab34e577b0d821f7cc1e69257d0f1c9be180bc4 100644 --- a/code/SystemFeature/AutoFill/AutoFill/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/hvigor/hvigor-config.json5 @@ -1,19 +1,19 @@ -/* - * Copyright (c) 2023-2024 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": { - } +/* + * Copyright (c) 2023-2024 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": { + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/oh-package.json5 b/code/SystemFeature/AutoFill/AutoFill/oh-package.json5 index 9d75f5f96c8b776ee8e99275b0e4ac97b02bf23e..878b6f17719a7e9fe68140c2435b3e4a34a5a9aa 100644 --- a/code/SystemFeature/AutoFill/AutoFill/oh-package.json5 +++ b/code/SystemFeature/AutoFill/AutoFill/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023-2024 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", - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "passwordbox", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} +/* + * Copyright (c) 2023-2024 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", + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "passwordbox", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFill/ohosTest.md b/code/SystemFeature/AutoFill/AutoFill/ohosTest.md index 20e47b961a087a5470e4457f4b7d71f8df9855c1..d3d3aee969543ddb14ddc1ae7a49b9fcb87dbb8e 100644 --- a/code/SystemFeature/AutoFill/AutoFill/ohosTest.md +++ b/code/SystemFeature/AutoFill/AutoFill/ohosTest.md @@ -1,11 +1,11 @@ -# AutoFill测试用例 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ----------------- | ----------------------------------------------------------- | ------------------------------------------------------------ | -------- | -------- | -| USER_NAME类型和Password类型的autofill控件发起自动填充请求成功 | 位于登录页面 | 1、进入登录界面,点击账号输入框
2、点击任意一个账号 | 1、选择一个账号后页面发生发生跳转生物认证界面,点击成功后页面发生跳转,显示原登录页面,用户名的输入框中填充刚选择的用户名,密码输入框会显示出账号对应的密码
| 否 | Pass | -| newPassword类型的autofill控件发起自动填充请求成功 | 位于注册页面 | 1、进入注册界面
2、点击生成密码输入框
3、点击确认 | 1、 会将生成的密码自动填充到生成密码输入框中 | 是 | Pass | -| 登录页面消失,发起自动保存请求成功 | 位于登录页面 | 1、进入账号密码登录界面
2、输入账号密码
3、点击登录 | 1、点击登录按钮后,页面会先跳转到登录成功页面,随后自动触发OnSaveRequest回调,立即跳转新页面询问用户是否保存当前账号密码,观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | -| 用户主动调用requestSave接口成功 | 位于注册页面
| 1、进入注册界面
2、输入账号密码
3、点击立即注册 | 1、点击注册按钮后,页面会先弹出注册成功弹窗,随后触发OnSaveRequest回调,立即跳转新页面询问用户是否保存当前账号密码,观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | - +# AutoFill测试用例 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ----------------- | ----------------------------------------------------------- | ------------------------------------------------------------ | -------- | -------- | +| USER_NAME类型和Password类型的autofill控件发起自动填充请求成功 | 位于登录页面 | 1、进入登录界面,点击账号输入框
2、点击任意一个账号 | 1、选择一个账号后页面发生发生跳转生物认证界面,点击成功后页面发生跳转,显示原登录页面,用户名的输入框中填充刚选择的用户名,密码输入框会显示出账号对应的密码
| 否 | Pass | +| newPassword类型的autofill控件发起自动填充请求成功 | 位于注册页面 | 1、进入注册界面
2、点击生成密码输入框
3、点击确认 | 1、 会将生成的密码自动填充到生成密码输入框中 | 是 | Pass | +| 登录页面消失,发起自动保存请求成功 | 位于登录页面 | 1、进入账号密码登录界面
2、输入账号密码
3、点击登录 | 1、点击登录按钮后,页面会先跳转到登录成功页面,随后自动触发OnSaveRequest回调,立即跳转新页面询问用户是否保存当前账号密码,观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | +| 用户主动调用requestSave接口成功 | 位于注册页面
| 1、进入注册界面
2、输入账号密码
3、点击立即注册 | 1、点击注册按钮后,页面会先弹出注册成功弹窗,随后触发OnSaveRequest回调,立即跳转新页面询问用户是否保存当前账号密码,观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | + diff --git a/code/SystemFeature/AutoFill/AutoFill/screenshots/autoFillControl.jpg b/code/SystemFeature/AutoFill/AutoFill/screenshots/autoFillControl.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFill/screenshots/biometricauthentication.jpg b/code/SystemFeature/AutoFill/AutoFill/screenshots/biometricauthentication.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/app.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/app.json5 old mode 100755 new mode 100644 index 0fea96d300d375c2de68c8f10c10e9491651200d..9c702f7cdb1d32c84ee085d13e9f5ef363bcc792 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/app.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2024 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.ohos.textautofill", - "vendor": "ohos", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.ohos.textautofill", + "vendor": "ohos", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/resources/base/element/string.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/resources/base/element/string.json old mode 100755 new mode 100644 index 56c6dfd8f25d440c3a8e6d67c0b975e4cb9f3699..75874dfa9ba753008f152d836d6b78d2db306818 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AutoFillDemo" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AutoFillDemo" + } + ] +} diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/resources/base/media/app_icon.png b/code/SystemFeature/AutoFill/AutoFillScenarioization/AppScope/resources/base/media/app_icon.png old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/README_zh.md b/code/SystemFeature/AutoFill/AutoFillScenarioization/README_zh.md old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/build-profile.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/build-profile.json5 old mode 100755 new mode 100644 index af6af27aa90941c8132c24f9a25075de2db60dac..863ca041c891616e0bd1af116eadf722d85336d7 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/build-profile.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/build-profile.json5 @@ -1,43 +1,43 @@ -/** - * Copyright (c) 2024 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": 12, - "compatibleSdkVersion": 12, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/** + * Copyright (c) 2024 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": 12, + "compatibleSdkVersion": 12, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/build-profile.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/build-profile.json5 old mode 100755 new mode 100644 index 1dd2b4d46b6dcafdfcf51eebd177736b027fe527..da1ea711ffa566dfe552362708e43fb2c639825d --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/build-profile.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2024 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/hvigorfile.ts b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/oh-package.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/oh-package.json5 old mode 100755 new mode 100644 index 90bacec4608fac3f088450531fc407b0fa88ff48..19b9234a98d43a4711a0fc32cef604159228d3cd --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/oh-package.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/application/ItemListData.ts b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/application/ItemListData.ts old mode 100755 new mode 100644 index cbe70b4e210284e669c45759670396e20f65315b..b6247eaf54175ab97b161da86df2b640d786d528 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/application/ItemListData.ts +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/application/ItemListData.ts @@ -1,17 +1,17 @@ -/* - * Copyright (c) 2024 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 let nameList: Array = ['lily', 'linda', 'john', 'tom', 'peter']; +/* + * Copyright (c) 2024 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 let nameList: Array = ['lily', 'linda', 'john', 'tom', 'peter']; export let phoneList: Array = ['15590031233', '19232466542', '13352589963', '13315584211']; \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillability/TextAutoFillAbility.ts b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillability/TextAutoFillAbility.ts old mode 100755 new mode 100644 index 0ff7188f9e28ede83ba52c468e174022f964924c..179e5e4caa19a01722980864b29092277187079a --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillability/TextAutoFillAbility.ts +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillability/TextAutoFillAbility.ts @@ -1,117 +1,117 @@ -/* - * Copyright (c) 2024 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 { autoFillManager, AutoFillExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; -const BOTTOM_LEFT: number = 6; - -function suggestWords(input: string, words: string[]): string[] { - if (input.length < 1) { - return []; // 如果输入的字符少于1个,则不提供联想 - } - return words.filter(word => word.includes(input)); -} - -export default class TextAutoFillAbility extends AutoFillExtensionAbility { - onCreate(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onCreate'); - AppStorage.setOrCreate('contextEvent', this.context); - } - - onDestroy(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onDestroy'); - } - - onSessionDestroy(session: UIExtensionContentSession) { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSessionDestroy'); - hilog.info(DOMAIN_NUMBER, TAG, 'session content: %{public}s', JSON.stringify(session)); - } - - onForeground(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onForeground'); - } - - onBackground(): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onBackground'); - } - - onUpdateRequest(request: autoFillManager.UpdateRequest): void { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onUpdateRequest'); - let storage = LocalStorage.getShared(); - let fillCallback = storage.get('fillCallback'); - let size: autoFillManager.PopupSize = { - width: 656, - height: 149 - }; - fillCallback.setAutoFillPopupConfig({ - popupSize: size, - placement: BOTTOM_LEFT - }); - let nameList: string = ''; - for (let i = 0; i < request.viewData.pageNodeInfos.length; i++) { - nameList = request.viewData.pageNodeInfos[i].value; - } - const words = ['lily', 'linda', 'john', 'tom', 'peter']; - let suggestions: Array = suggestWords(nameList, words); - - request.viewData.pageNodeInfos.find((item) => { - if (item.isFocus && item.value.length != 0 && item.autoFillType == autoFillManager.AutoFillType.PERSON_FULL_NAME) { - this.context.eventHub.emit('updateRequestData', suggestions); - } - }) - } - - onFillRequest(session: UIExtensionContentSession, request: autoFillManager.FillRequest, callback: autoFillManager.FillRequestCallback) { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onFillRequest'); - AppStorage.setOrCreate('interface', 'actionStr'); - try { - let storage_fill = new LocalStorage( - { - 'session': session, - 'message': 'AutoFill Page', - 'fillCallback': callback, - 'viewData': request.viewData, - 'pageNodeInfos': request.viewData.pageNodeInfos, - 'autoFillType': request.type - }); - let size: autoFillManager.PopupSize = { - width: 656, - height: 220 - }; - callback.setAutoFillPopupConfig({ - popupSize: size, - placement: BOTTOM_LEFT - }); - session.loadContent('autofillpages/SelectorList', storage_fill); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill failed to load content'); - } - } - - onSaveRequest(session: UIExtensionContentSession, request: autoFillManager.SaveRequest, callback: autoFillManager.SaveRequestCallback) { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSaveRequest'); - let storage_save = new LocalStorage( - { - 'session': session, - 'message': 'AutoFill Page', - 'saveCallback': callback, - 'viewData': request.viewData - }); - session.loadContent('autofillpages/SavePage', storage_save); - } +/* + * Copyright (c) 2024 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 { autoFillManager, AutoFillExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; +const BOTTOM_LEFT: number = 6; + +function suggestWords(input: string, words: string[]): string[] { + if (input.length < 1) { + return []; // 如果输入的字符少于1个,则不提供联想 + } + return words.filter(word => word.includes(input)); +} + +export default class TextAutoFillAbility extends AutoFillExtensionAbility { + onCreate(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onCreate'); + AppStorage.setOrCreate('contextEvent', this.context); + } + + onDestroy(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onDestroy'); + } + + onSessionDestroy(session: UIExtensionContentSession) { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSessionDestroy'); + hilog.info(DOMAIN_NUMBER, TAG, 'session content: %{public}s', JSON.stringify(session)); + } + + onForeground(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onForeground'); + } + + onBackground(): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onBackground'); + } + + onUpdateRequest(request: autoFillManager.UpdateRequest): void { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onUpdateRequest'); + let storage = LocalStorage.getShared(); + let fillCallback = storage.get('fillCallback'); + let size: autoFillManager.PopupSize = { + width: 656, + height: 149 + }; + fillCallback.setAutoFillPopupConfig({ + popupSize: size, + placement: BOTTOM_LEFT + }); + let nameList: string = ''; + for (let i = 0; i < request.viewData.pageNodeInfos.length; i++) { + nameList = request.viewData.pageNodeInfos[i].value; + } + const words = ['lily', 'linda', 'john', 'tom', 'peter']; + let suggestions: Array = suggestWords(nameList, words); + + request.viewData.pageNodeInfos.find((item) => { + if (item.isFocus && item.value.length != 0 && item.autoFillType == autoFillManager.AutoFillType.PERSON_FULL_NAME) { + this.context.eventHub.emit('updateRequestData', suggestions); + } + }) + } + + onFillRequest(session: UIExtensionContentSession, request: autoFillManager.FillRequest, callback: autoFillManager.FillRequestCallback) { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onFillRequest'); + AppStorage.setOrCreate('interface', 'actionStr'); + try { + let storage_fill = new LocalStorage( + { + 'session': session, + 'message': 'AutoFill Page', + 'fillCallback': callback, + 'viewData': request.viewData, + 'pageNodeInfos': request.viewData.pageNodeInfos, + 'autoFillType': request.type + }); + let size: autoFillManager.PopupSize = { + width: 656, + height: 220 + }; + callback.setAutoFillPopupConfig({ + popupSize: size, + placement: BOTTOM_LEFT + }); + session.loadContent('autofillpages/SelectorList', storage_fill); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill failed to load content'); + } + } + + onSaveRequest(session: UIExtensionContentSession, request: autoFillManager.SaveRequest, callback: autoFillManager.SaveRequestCallback) { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'autofill onSaveRequest'); + let storage_save = new LocalStorage( + { + 'session': session, + 'message': 'AutoFill Page', + 'saveCallback': callback, + 'viewData': request.viewData + }); + session.loadContent('autofillpages/SavePage', storage_save); + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/ReturnMainPage.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/ReturnMainPage.ets old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SavePage.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SavePage.ets old mode 100755 new mode 100644 index 537e8fe4e2c681cf48f8883d035d21d21cf00ef3..3b8c82d36d54c6a2257121b62aab1504090d5b54 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SavePage.ets +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SavePage.ets @@ -1,104 +1,104 @@ -/* - * Copyright (c) 2024 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 { autoFillManager } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -let storage = LocalStorage.getShared(); -let saveRequestCallback = storage.get('saveCallback'); -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; - -function SuccessFunc(success: boolean) { - if (saveRequestCallback) { - if (success) { - saveRequestCallback.onSuccess(); - hilog.info(DOMAIN_NUMBER, TAG, 'saveRequestCallback success'); - return; - } - saveRequestCallback.onFailure(); - hilog.info(DOMAIN_NUMBER, TAG, 'saveRequestCallback onFailure'); - } - hilog.error(DOMAIN_NUMBER, TAG, 'saveRequestCallback is nullptr!'); -} - -@Entry -@Component -struct SavePage { - build() { - Column() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Image($r('app.media.arrow')) - .height(44) - .width(44) - .onClick(() => { - SuccessFunc(false); - }) - Text($r('app.string.scenarioization')) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize(22) - .margin({ left: '2.4%' }) - }.margin({ top: '12.8%', left: '4.9%' }) - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Image($r('app.media.style')) - .height('448px') - .width('448px') - }.margin({ top: '19.8%' }) - }.height('70%') - - Column() { - Column() { - Row() { - Button($r('app.string.cancel')) - .type(ButtonType.Normal) - .borderRadius(25) - .fontSize(16) - .fontWeight(400) - .margin({ right: 6 }) - .fontColor($r('app.color.cancelBtnColor')) - .backgroundColor($r('app.color.mainInterface')) - .height('20.8%') - .width('44.5%') - .onClick(() => { - SuccessFunc(true); - }) - - Button($r('app.string.confirm')) - .type(ButtonType.Normal) - .borderRadius(25) - .fontSize(16) - .fontWeight(400) - .margin({ left: 6 }) - .fontColor($r('app.color.mainInterface')) - .id('saveOnly') - .backgroundColor($r('app.color.cancelBtnColor')) - .height('20.8%') - .width('44.5%') - .onClick(() => { - SuccessFunc(false); - }) - } - } - .margin({ bottom: '44px' }) - } - .height('30%') - .justifyContent(FlexAlign.End) - .alignItems(HorizontalAlign.Center) - }.backgroundColor($r('app.color.pageBackColor')).height('100%') - } +/* + * Copyright (c) 2024 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 { autoFillManager } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +let storage = LocalStorage.getShared(); +let saveRequestCallback = storage.get('saveCallback'); +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; + +function SuccessFunc(success: boolean) { + if (saveRequestCallback) { + if (success) { + saveRequestCallback.onSuccess(); + hilog.info(DOMAIN_NUMBER, TAG, 'saveRequestCallback success'); + return; + } + saveRequestCallback.onFailure(); + hilog.info(DOMAIN_NUMBER, TAG, 'saveRequestCallback onFailure'); + } + hilog.error(DOMAIN_NUMBER, TAG, 'saveRequestCallback is nullptr!'); +} + +@Entry +@Component +struct SavePage { + build() { + Column() { + Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Image($r('app.media.arrow')) + .height(44) + .width(44) + .onClick(() => { + SuccessFunc(false); + }) + Text($r('app.string.scenarioization')) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize(22) + .margin({ left: '2.4%' }) + }.margin({ top: '12.8%', left: '4.9%' }) + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Image($r('app.media.style')) + .height('448px') + .width('448px') + }.margin({ top: '19.8%' }) + }.height('70%') + + Column() { + Column() { + Row() { + Button($r('app.string.cancel')) + .type(ButtonType.Normal) + .borderRadius(25) + .fontSize(16) + .fontWeight(400) + .margin({ right: 6 }) + .fontColor($r('app.color.cancelBtnColor')) + .backgroundColor($r('app.color.mainInterface')) + .height('20.8%') + .width('44.5%') + .onClick(() => { + SuccessFunc(true); + }) + + Button($r('app.string.confirm')) + .type(ButtonType.Normal) + .borderRadius(25) + .fontSize(16) + .fontWeight(400) + .margin({ left: 6 }) + .fontColor($r('app.color.mainInterface')) + .id('saveOnly') + .backgroundColor($r('app.color.cancelBtnColor')) + .height('20.8%') + .width('44.5%') + .onClick(() => { + SuccessFunc(false); + }) + } + } + .margin({ bottom: '44px' }) + } + .height('30%') + .justifyContent(FlexAlign.End) + .alignItems(HorizontalAlign.Center) + }.backgroundColor($r('app.color.pageBackColor')).height('100%') + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SelectorList.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SelectorList.ets old mode 100755 new mode 100644 index eec2f1e38d1248c03d915ca116b76ffef87baf13..5262c418bc92be954096536454a65a7639f11ab7 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SelectorList.ets +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/autofillpages/SelectorList.ets @@ -1,113 +1,113 @@ -/* - * Copyright (c) 2024 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 { nameList, phoneList } from '../application/ItemListData'; -import { common, autoFillManager } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -let storage = LocalStorage.getShared(); -let fillCallback = storage.get('fillCallback'); -let viewData: autoFillManager.ViewData | undefined = storage.get('viewData'); -let type: number | undefined = storage.get('autoFillType'); -let context = AppStorage.get('contextEvent') as common.UIAbilityContext; -let itemList: Array | undefined; -let typeToDataMap: Map> = new Map(); -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; -const FULL_PHONE_NUMBER: number = 15; -const PERSON_FULL_NAME: number = 10; - -typeToDataMap.set(PERSON_FULL_NAME, nameList); -typeToDataMap.set(FULL_PHONE_NUMBER, phoneList); - -function successFunc(index: number, item: string) { - if (viewData && index >= 0 && type != undefined) { - itemList = typeToDataMap.get(type); - if (itemList) { - for (let i = 0; i < viewData.pageNodeInfos.length; i++) { - if (viewData.pageNodeInfos[i].isFocus === true) { - viewData.pageNodeInfos[i].value = item; - break; - } - } - } - if (fillCallback) { - let response: autoFillManager.FillResponse = { viewData: viewData }; - fillCallback.onSuccess(response); - } - } -} - -@Entry -@Component -struct SelectorList { - @State itemListData: Array = []; - - aboutToAppear(): void { - if (type != undefined) { - let maybeUndefined: Array | undefined = typeToDataMap.get(type); - if (maybeUndefined != undefined) { - this.itemListData = maybeUndefined; - } - } - context.eventHub.on('updateRequestData', (eventData: Array) => { - hilog.info(DOMAIN_NUMBER, TAG, 'eventHub called' + eventData); - this.itemListData = eventData; - }); - } - - build() { - Row() { - Column() { - List({ space: 10, initialIndex: 0 }) { - ForEach(this.itemListData, (item: string, index: number) => { - ListItem() { - Text(item ? item : '') - .width('100%') - .height(40) - .fontSize($r('sys.float.ohos_id_text_size_body1')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .textAlign(TextAlign.Start) - .margin({ left: '4.8%' }) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - } - .onClick(() => { - hilog.info(DOMAIN_NUMBER, TAG, 'click item: ', item); - successFunc(index, item); - }) - }) - } - .listDirection(Axis.Vertical) - .scrollBar(BarState.Off) - .friction(0.6) - .divider({ strokeWidth: 1, color: $r('app.color.placeholderColor'), startMargin: 20, endMargin: 20 }) - .edgeEffect(EdgeEffect.Spring) - .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { - hilog.info(DOMAIN_NUMBER, TAG, 'first' + firstIndex); - hilog.info(DOMAIN_NUMBER, TAG, 'last' + lastIndex); - hilog.info(DOMAIN_NUMBER, TAG, 'center' + centerIndex); - }) - .onScroll((scrollOffset: number, scrollState: ScrollState) => { - hilog.info(DOMAIN_NUMBER, TAG, `onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + - scrollOffset); - }) - } - .width('100%') - .shadow(ShadowStyle.OUTER_FLOATING_SM) - } - .height('100%') - .shadow(ShadowStyle.OUTER_FLOATING_SM) - } +/* + * Copyright (c) 2024 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 { nameList, phoneList } from '../application/ItemListData'; +import { common, autoFillManager } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +let storage = LocalStorage.getShared(); +let fillCallback = storage.get('fillCallback'); +let viewData: autoFillManager.ViewData | undefined = storage.get('viewData'); +let type: number | undefined = storage.get('autoFillType'); +let context = AppStorage.get('contextEvent') as common.UIAbilityContext; +let itemList: Array | undefined; +let typeToDataMap: Map> = new Map(); +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; +const FULL_PHONE_NUMBER: number = 15; +const PERSON_FULL_NAME: number = 10; + +typeToDataMap.set(PERSON_FULL_NAME, nameList); +typeToDataMap.set(FULL_PHONE_NUMBER, phoneList); + +function successFunc(index: number, item: string) { + if (viewData && index >= 0 && type != undefined) { + itemList = typeToDataMap.get(type); + if (itemList) { + for (let i = 0; i < viewData.pageNodeInfos.length; i++) { + if (viewData.pageNodeInfos[i].isFocus === true) { + viewData.pageNodeInfos[i].value = item; + break; + } + } + } + if (fillCallback) { + let response: autoFillManager.FillResponse = { viewData: viewData }; + fillCallback.onSuccess(response); + } + } +} + +@Entry +@Component +struct SelectorList { + @State itemListData: Array = []; + + aboutToAppear(): void { + if (type != undefined) { + let maybeUndefined: Array | undefined = typeToDataMap.get(type); + if (maybeUndefined != undefined) { + this.itemListData = maybeUndefined; + } + } + context.eventHub.on('updateRequestData', (eventData: Array) => { + hilog.info(DOMAIN_NUMBER, TAG, 'eventHub called' + eventData); + this.itemListData = eventData; + }); + } + + build() { + Row() { + Column() { + List({ space: 10, initialIndex: 0 }) { + ForEach(this.itemListData, (item: string, index: number) => { + ListItem() { + Text(item ? item : '') + .width('100%') + .height(40) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .textAlign(TextAlign.Start) + .margin({ left: '4.8%' }) + .borderRadius($r('sys.float.ohos_id_corner_radius_card')) + } + .onClick(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'click item: ', item); + successFunc(index, item); + }) + }) + } + .listDirection(Axis.Vertical) + .scrollBar(BarState.Off) + .friction(0.6) + .divider({ strokeWidth: 1, color: $r('app.color.placeholderColor'), startMargin: 20, endMargin: 20 }) + .edgeEffect(EdgeEffect.Spring) + .onScrollIndex((firstIndex: number, lastIndex: number, centerIndex: number) => { + hilog.info(DOMAIN_NUMBER, TAG, 'first' + firstIndex); + hilog.info(DOMAIN_NUMBER, TAG, 'last' + lastIndex); + hilog.info(DOMAIN_NUMBER, TAG, 'center' + centerIndex); + }) + .onScroll((scrollOffset: number, scrollState: ScrollState) => { + hilog.info(DOMAIN_NUMBER, TAG, `onScroll scrollState = ScrollState` + scrollState + `, scrollOffset = ` + + scrollOffset); + }) + } + .width('100%') + .shadow(ShadowStyle.OUTER_FLOATING_SM) + } + .height('100%') + .shadow(ShadowStyle.OUTER_FLOATING_SM) + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/entryability/EntryAbility.ts old mode 100755 new mode 100644 index c611aa56f028d58b1d5f023cad4832d6ad5c6b9c..a15ab48dd6b2e29717e69e053b4b48f63941a4d2 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; -import { UIContext, window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'entryAbility'; -const DOMAIN_NUMBER: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); - AppStorage.link('uiContext'); - } - - onDestroy() { - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', - JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', - JSON.stringify(data) ?? ''); - let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); - PersistentStorage.persistProp('uiContext', uiContext); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); - } +/* + * Copyright (c) 2024 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 { UIAbility } from '@kit.AbilityKit'; +import { UIContext, window } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'entryAbility'; +const DOMAIN_NUMBER: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onCreate'); + AppStorage.link('uiContext'); + } + + onDestroy() { + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageCreate'); + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(DOMAIN_NUMBER, TAG, 'Failed to load the content. Cause: %{public}s', + JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext(); + PersistentStorage.persistProp('uiContext', uiContext); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(DOMAIN_NUMBER, TAG, '%{public}s', 'Ability onBackground'); + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/pages/Index.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/pages/Index.ets old mode 100755 new mode 100644 index ee0e37719978c29dc8e88c84d3b6b5cc181f3626..a112c160e525bea1c684b5a12498d9058a409c92 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/pages/Index.ets +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/ets/pages/Index.ets @@ -1,170 +1,170 @@ -/* - * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; -import { autoFillManager } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = 'autoFill'; -const DOMAIN_NUMBER: number = 0xFF00; - -@Entry -@Component -struct Index { - @State inputTxt: string = ''; - - build() { - Column() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Text($r('app.string.scenarioization')) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .fontSize($r('sys.float.ohos_id_text_size_headline6')) - .fontColor($r('sys.color.ohos_id_color_text_primary')) - .padding({ - left: $r('sys.float.ohos_id_max_padding_start'), - right: $r('sys.float.ohos_id_max_padding_end') - }) - }.margin({ top: '14.2%' }).height('7.2%') - - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Column() { - Row() { - Text($r('app.string.settingType')) - .fontColor($r('app.color.TextColor')) - .fontSize(14) - .fontWeight(400) - .textAlign(TextAlign.Start) - .width('91%') - .margin({ top: 5, left: -7.5 }) - } - - Row() { - TextInput({ placeholder: $r('app.string.phone_Number'), text: this.inputTxt }) - .contentType(ContentType.FULL_PHONE_NUMBER) - .height('9.4%') - .width('91%') - .fontWeight(FontWeight.Bolder) - .placeholderColor($r('app.color.TextColor')) - .backgroundColor($r('app.color.backgroundColor')) - .id('password1') - .fontSize(16) - .fontWeight(400) - .borderStyle(BorderStyle.Solid) - .enableAutoFill(true) - .borderRadius(25) - .onChange(() => { - }) - .margin({ top: '8vp' }) - } - }.margin({ top: '7.1%' }) - } - - - Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Column() { - Row() { - Text($r('app.string.setTypeName')) - .fontColor($r('app.color.TextColor')) - .fontSize(14) - .fontWeight(400) - .textAlign(TextAlign.Start) - .width('91%') - .margin({ top: 5, left: -7.5 }) - } - - Row() { - TextInput({ placeholder: $r('app.string.person_Full_Name'), text: this.inputTxt }) - .contentType(ContentType.PERSON_FULL_NAME) - .height('9.4%') - .width('91%') - .fontWeight(FontWeight.Bold) - .placeholderColor($r('app.color.TextColor')) - .backgroundColor($r('app.color.backgroundColor')) - .fontSize(16) - .fontWeight(400) - .id('password3') - .borderStyle(BorderStyle.Solid) - .enableAutoFill(true) - .borderRadius(25) - .onChange(() => { - }) - .margin({ top: '8vp' }) - } - } - } - .margin({ top: '20vp' }) - }.height('70%') - - Column() { - Button() { - Text($r('app.string.saveData')) - .fontSize(16) - .fontWeight(400) - .fontColor($r('app.color.backgroundColor')) - } - .type(ButtonType.Normal) - .borderRadius(25) - .margin({ bottom: '12vp' }) - .backgroundColor($r('app.color.cancelBtnColor')) - .width('91%') - .height('19.4%') - .id('save') - .onClick(() => { - let context = AppStorage.get('uiContext'); - if (context == null) { - hilog.info(DOMAIN_NUMBER, TAG, 'UIContext is null. '); - } - hilog.info(DOMAIN_NUMBER, TAG, 'UIContext: ', JSON.stringify(context)); - try { - autoFillManager.requestAutoSave(context, { - onSuccess: () => { - hilog.info(DOMAIN_NUMBER, TAG, 'save request on success'); - }, - onFailure: () => { - hilog.info(DOMAIN_NUMBER, TAG, 'save request on failure'); - } - }); - } catch (err) { - hilog.error(DOMAIN_NUMBER, TAG, 'save err', JSON.stringify(err)); - } - }) - - Button() { - Text($r('app.string.switchInterface')) - .fontSize(16) - .fontWeight(400) - .fontColor($r('app.color.cancelBtnColor')) - } - .type(ButtonType.Normal) - .borderRadius(25) - .backgroundColor($r('app.color.mainInterface')) - .width('91%') - .height('19.4%') - .margin({ bottom: '44px' }) - .id('changInterface') - .onClick(() => { - router.pushUrl({ - url: 'autofillpages/ReturnMainPage', - }) - }) - } - .height('30%') - .justifyContent(FlexAlign.End) - }.backgroundColor($r('app.color.pageBackColor')).height('100%') - } +/* + * Copyright (c) 2024 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 { router } from '@kit.ArkUI'; +import { autoFillManager } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = 'autoFill'; +const DOMAIN_NUMBER: number = 0xFF00; + +@Entry +@Component +struct Index { + @State inputTxt: string = ''; + + build() { + Column() { + Column() { + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Text($r('app.string.scenarioization')) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .fontSize($r('sys.float.ohos_id_text_size_headline6')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .padding({ + left: $r('sys.float.ohos_id_max_padding_start'), + right: $r('sys.float.ohos_id_max_padding_end') + }) + }.margin({ top: '14.2%' }).height('7.2%') + + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Column() { + Row() { + Text($r('app.string.settingType')) + .fontColor($r('app.color.TextColor')) + .fontSize(14) + .fontWeight(400) + .textAlign(TextAlign.Start) + .width('91%') + .margin({ top: 5, left: -7.5 }) + } + + Row() { + TextInput({ placeholder: $r('app.string.phone_Number'), text: this.inputTxt }) + .contentType(ContentType.FULL_PHONE_NUMBER) + .height('9.4%') + .width('91%') + .fontWeight(FontWeight.Bolder) + .placeholderColor($r('app.color.TextColor')) + .backgroundColor($r('app.color.backgroundColor')) + .id('password1') + .fontSize(16) + .fontWeight(400) + .borderStyle(BorderStyle.Solid) + .enableAutoFill(true) + .borderRadius(25) + .onChange(() => { + }) + .margin({ top: '8vp' }) + } + }.margin({ top: '7.1%' }) + } + + + Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { + Column() { + Row() { + Text($r('app.string.setTypeName')) + .fontColor($r('app.color.TextColor')) + .fontSize(14) + .fontWeight(400) + .textAlign(TextAlign.Start) + .width('91%') + .margin({ top: 5, left: -7.5 }) + } + + Row() { + TextInput({ placeholder: $r('app.string.person_Full_Name'), text: this.inputTxt }) + .contentType(ContentType.PERSON_FULL_NAME) + .height('9.4%') + .width('91%') + .fontWeight(FontWeight.Bold) + .placeholderColor($r('app.color.TextColor')) + .backgroundColor($r('app.color.backgroundColor')) + .fontSize(16) + .fontWeight(400) + .id('password3') + .borderStyle(BorderStyle.Solid) + .enableAutoFill(true) + .borderRadius(25) + .onChange(() => { + }) + .margin({ top: '8vp' }) + } + } + } + .margin({ top: '20vp' }) + }.height('70%') + + Column() { + Button() { + Text($r('app.string.saveData')) + .fontSize(16) + .fontWeight(400) + .fontColor($r('app.color.backgroundColor')) + } + .type(ButtonType.Normal) + .borderRadius(25) + .margin({ bottom: '12vp' }) + .backgroundColor($r('app.color.cancelBtnColor')) + .width('91%') + .height('19.4%') + .id('save') + .onClick(() => { + let context = AppStorage.get('uiContext'); + if (context == null) { + hilog.info(DOMAIN_NUMBER, TAG, 'UIContext is null. '); + } + hilog.info(DOMAIN_NUMBER, TAG, 'UIContext: ', JSON.stringify(context)); + try { + autoFillManager.requestAutoSave(context, { + onSuccess: () => { + hilog.info(DOMAIN_NUMBER, TAG, 'save request on success'); + }, + onFailure: () => { + hilog.info(DOMAIN_NUMBER, TAG, 'save request on failure'); + } + }); + } catch (err) { + hilog.error(DOMAIN_NUMBER, TAG, 'save err', JSON.stringify(err)); + } + }) + + Button() { + Text($r('app.string.switchInterface')) + .fontSize(16) + .fontWeight(400) + .fontColor($r('app.color.cancelBtnColor')) + } + .type(ButtonType.Normal) + .borderRadius(25) + .backgroundColor($r('app.color.mainInterface')) + .width('91%') + .height('19.4%') + .margin({ bottom: '44px' }) + .id('changInterface') + .onClick(() => { + router.pushUrl({ + url: 'autofillpages/ReturnMainPage', + }) + }) + } + .height('30%') + .justifyContent(FlexAlign.End) + }.backgroundColor($r('app.color.pageBackColor')).height('100%') + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/module.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/module.json5 old mode 100755 new mode 100644 index bbb80ad28897330a2a59018a90884c345f26a0fb..261e3215c8ef6eea5570c87a2f303f5b889d5835 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/module.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/module.json5 @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2024 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "TextAutoFillAbility", - "srcEntry": "./ets/autofillability/TextAutoFillAbility.ts", - "description": "$string:AutoFillAbility_desc", - "exported": true, - "icon": "$media:icon", - "label": "$string:AutoFillAbility_label", - "type": "autoFill/smart" - } - ], - } +/* + * Copyright (c) 2024 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "TextAutoFillAbility", + "srcEntry": "./ets/autofillability/TextAutoFillAbility.ts", + "description": "$string:AutoFillAbility_desc", + "exported": true, + "icon": "$media:icon", + "label": "$string:AutoFillAbility_label", + "type": "autoFill/smart" + } + ], + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/element/color.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/element/color.json old mode 100755 new mode 100644 index 3ae5515df5606b668c15af71794828e5060a3df1..8dbfb02a3ea35c8ecdd21c611ac8fffbdbdb0a68 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/element/color.json @@ -1,40 +1,40 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "cancelBtnColor", - "value": "#0A59F7" - }, - { - "name": "enableColor", - "value": "#bfdbf9" - }, - { - "name": "pageBackColor", - "value": "#f1f3f5" - }, - { - "name": "cancelColor", - "value": "#D8FCFFFE" - }, - { - "name": "mainInterface", - "value": "#FDE5E9E9" - }, - { - "name": "placeholderColor", - "value": "#fff5eeee" - }, - { - "name": "backgroundColor", - "value": "#ffffffff" - }, - { - "name": "TextColor", - "value": "#99000000" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "cancelBtnColor", + "value": "#0A59F7" + }, + { + "name": "enableColor", + "value": "#bfdbf9" + }, + { + "name": "pageBackColor", + "value": "#f1f3f5" + }, + { + "name": "cancelColor", + "value": "#D8FCFFFE" + }, + { + "name": "mainInterface", + "value": "#FDE5E9E9" + }, + { + "name": "placeholderColor", + "value": "#fff5eeee" + }, + { + "name": "backgroundColor", + "value": "#ffffffff" + }, + { + "name": "TextColor", + "value": "#99000000" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/element/string.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/arrow.png b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/arrow.png old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/ic_public_back.svg b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/ic_public_back.svg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/icon.png b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/style.png b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/media/style.png old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/profile/main_pages.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/base/profile/main_pages.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/en_US/element/string.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/en_US/element/string.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/zh_CN/element/string.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/main/resources/zh_CN/element/string.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/test/Ability.test.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/test/Ability.test.ets old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/test/List.test.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/test/List.test.ets old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/testability/TestAbility.ets old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/testability/pages/Index.ets old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/module.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/module.json5 old mode 100755 new mode 100644 index 269aabf14edc3a6b5b83cfa0f95434b49e2d4e17..17fcedb622e74f14fd1cfd7ab846e777ee233350 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2024 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/element/color.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/element/color.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/element/string.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/element/string.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/media/icon.png b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/media/icon.png old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/SystemFeature/AutoFill/AutoFillScenarioization/entry/src/ohosTest/resources/base/profile/test_pages.json old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigor/hvigor-config.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigor/hvigor-config.json5 old mode 100755 new mode 100644 index fb29482d10a201e0e40fc37b3f492317c45910c5..9a7908507630143024c38e9f282d4d3cd05ef126 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigor/hvigor-config.json5 @@ -1,21 +1,21 @@ -/* - * Copyright (c) 2024 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. - */ - -{ - "hvigorVersion": "4.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "4.0.2" - } +/* + * Copyright (c) 2024 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. + */ + +{ + "hvigorVersion": "4.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "4.0.2" + } } \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigor/hvigor-wrapper.js b/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigor/hvigor-wrapper.js old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigorfile.ts b/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigorfile.ts old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigorw b/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigorw old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigorw.bat b/code/SystemFeature/AutoFill/AutoFillScenarioization/hvigorw.bat old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/oh-package.json5 b/code/SystemFeature/AutoFill/AutoFillScenarioization/oh-package.json5 old mode 100755 new mode 100644 index bbe632713bbeaec1963ab53f6b966fe00c585790..5d3a2789a941ec60531891f3bb9f11ee24191eaa --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/oh-package.json5 +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/oh-package.json5 @@ -1,12 +1,12 @@ -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "autofilldemo", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "autofilldemo", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/ohosTest.md b/code/SystemFeature/AutoFill/AutoFillScenarioization/ohosTest.md old mode 100755 new mode 100644 index 9cd082a951ba3248c867fd3c9df8568c6b575357..9b8d48c4def0ca970bafa86104c3ed645ebda024 --- a/code/SystemFeature/AutoFill/AutoFillScenarioization/ohosTest.md +++ b/code/SystemFeature/AutoFill/AutoFillScenarioization/ohosTest.md @@ -1,11 +1,11 @@ -# AutoFill情景化测试用例 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| ------------------------------------------------------------ | ---------- | ----------------------------------------------------------- | ------------------------------------------------------------ | -------- | -------- | -| 支持情景化自动填充,指定类型判断组件存在,FULL_PHONE_NUMBER的枚举值是否正确 | 位于主界面 | 1、进入主界面
| 1、应用启动成功
2、页面加载成功,组件存在
3、JSON中的contentType值FULL_PHONE_NUMBER | 是 | Pass | -| 支持情景化自动填充,指定类型判断组件存在,PERSON_FULL_NAME的枚举值是否正确 | 位于主界面 | 1、进入主界面
| 1、应用启动成功
2、页面加载成功,组件存在
3、JSON中的contentType值为PERSON_FULL_NAME | 是 | Pass | -| 支持情景化自动填充,输入字符进行联想页面弹出select弹窗并触发onUpdateRequest回调 | 位于主界面 | 1、进入主界面
| 1、输入字符联想成功
2、将选择的名字成功返回到textInput组件 | 否 | Pass | -| 主页面消失,发起手动保存请求成功 | 位于主界面 | 1、进入主界面
2、文本框输入信息
3、点击保存按钮 | 1、主页面点击文本框成功
2、成功输入
3、点击保存按钮后,页面会显示"保存和取消按钮"的页面
4、观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | +# AutoFill情景化测试用例 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------------------ | ---------- | ----------------------------------------------------------- | ------------------------------------------------------------ | -------- | -------- | +| 支持情景化自动填充,指定类型判断组件存在,FULL_PHONE_NUMBER的枚举值是否正确 | 位于主界面 | 1、进入主界面
| 1、应用启动成功
2、页面加载成功,组件存在
3、JSON中的contentType值FULL_PHONE_NUMBER | 是 | Pass | +| 支持情景化自动填充,指定类型判断组件存在,PERSON_FULL_NAME的枚举值是否正确 | 位于主界面 | 1、进入主界面
| 1、应用启动成功
2、页面加载成功,组件存在
3、JSON中的contentType值为PERSON_FULL_NAME | 是 | Pass | +| 支持情景化自动填充,输入字符进行联想页面弹出select弹窗并触发onUpdateRequest回调 | 位于主界面 | 1、进入主界面
| 1、输入字符联想成功
2、将选择的名字成功返回到textInput组件 | 否 | Pass | +| 主页面消失,发起手动保存请求成功 | 位于主界面 | 1、进入主界面
2、文本框输入信息
3、点击保存按钮 | 1、主页面点击文本框成功
2、成功输入
3、点击保存按钮后,页面会显示"保存和取消按钮"的页面
4、观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | | 主页面消失,发起自动保存请求成功 | 位于主界面 | 1、进入主界面
2、文本框输入信息
3、点击切换界面按钮 | 1、主页面点击文本框成功
2、成功输入
3、点击切换按钮后,页面先跳转"返回主界面按钮"界面后显示"保存和取消按钮"的页面
4、观察日志输出能够接收到OnSaveRequestSuccess信息 | 是 | Pass | \ No newline at end of file diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/Index.jpg b/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/Index.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/NameAssociation.jpg b/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/NameAssociation.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/ReturnMainPage.jpg b/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/ReturnMainPage.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/SavePage.jpg b/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/SavePage.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/SelectorList.jpg b/code/SystemFeature/AutoFill/AutoFillScenarioization/screenshots/SelectorList.jpg old mode 100755 new mode 100644 diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/app.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/app.json5 index 669d117d5e524f05ec3c9d9a40aea8d13ddb80c1..5c6d1bca6303a0c73fec6bb24b105ae9ea3463c8 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/app.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.fullscreenstart", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.fullscreenstart", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/resources/base/element/string.json b/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/resources/base/element/string.json index 7fc4af3343dcf9dcf9f3c378b2ef7dfcfd74c428..0a5375ac15fb30b28006efaa97ed557b33f9b863 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "FullScreenStart" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "FullScreenStart" + } + ] +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/build-profile.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/build-profile.json5 index f0b12f54c143d8dbc3f7093b44d7591b4c62cbb3..6774a445081b2bb2d3c125696c625a15faf308e0 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/build-profile.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/build-profile.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 12, - "compileSdkVersion": 12, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 12, + "compileSdkVersion": 12, + "runtimeOS": "OpenHarmony", + } + ], + "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/SystemFeature/FullScreenStart/FullScreenStart/entry/build-profile.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/build-profile.json5 index 97f563b45aac28e7e3ae336f7c0eb06b7b789179..63b88fb1a0053e40acb2391457a7e9d71af748fe 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/build-profile.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/oh-package.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/oh-package.json5 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..4e54d14e1b444a338b2c922f94a4fe4deed5be45 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/oh-package.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": {} -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entryability/EntryAbility.ets b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entryability/EntryAbility.ets index a76c99c8ad8db08511732bc07ee3a2f5c29c3d0f..ca1b0ce571f25c127575bbd38df70de46230a602 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2024 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, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import EmbeddableUIAbility from '@ohos.app.ability.EmbeddableUIAbility'; - -export default class EntryAbility extends EmbeddableUIAbility { - 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'); - } -} +/* + * Copyright (c) 2024 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, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import EmbeddableUIAbility from '@ohos.app.ability.EmbeddableUIAbility'; + +export default class EntryAbility extends EmbeddableUIAbility { + 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/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 1755a4686cf9f79996fdcd75b26f06b555c3ad3f..6b744d7eaa66e51e79fc4e0896e251292ee767c5 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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)); - } +/* + * Copyright (c) 2024 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/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/pages/ExtensionIndex.ets b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/pages/ExtensionIndex.ets index c374a88721e558c87ba624832e11da0d620b3b7d..3169c6f39a8eb4844fd64efdb1871b48ea0a1829 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/pages/ExtensionIndex.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/pages/ExtensionIndex.ets @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { common } from '@kit.AbilityKit'; -import AtomicServiceOptions from '@ohos.app.ability.AtomicServiceOptions'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -@Entry -@Component -struct Index { - // Developers need to create an AtomicService within AppGallery Connect and replace this appId. - private appId: string = '5765880207854787517'; - private options: AtomicServiceOptions = { - displayId: 0 - }; - private extensionContext = getContext(this) as common.UIExtensionContext; - - build() { - Row() { - Column() { - Button($r('app.string.UIExtensionStart')) - .onClick((event: ClickEvent) => { - try { - this.extensionContext.openAtomicService(this.appId, this.options) - .then((result: common.AbilityResult) => { - hilog.info(0x0000, 'testTag', 'UIExtensionContext.openAtomicService succeed'); - }) - .catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', - `UIExtensionContext.openAtomicService failed, code is ${err.code}, message is ${err.message}`); - }); - } catch (err) { - let code = (err as BusinessError).code; - let message = (err as BusinessError).message; - hilog.error(0x0000, 'testTag', - `UIExtensionContext.openAtomicService failed, code is ${code}, message is ${message}`); - } - }) - .id('UIExtensionStart') - .width('93.4%').height('100%') - } - .width('100%').height('100%') - } - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { common } from '@kit.AbilityKit'; +import AtomicServiceOptions from '@ohos.app.ability.AtomicServiceOptions'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +@Entry +@Component +struct Index { + // Developers need to create an AtomicService within AppGallery Connect and replace this appId. + private appId: string = '5765880207854787517'; + private options: AtomicServiceOptions = { + displayId: 0 + }; + private extensionContext = getContext(this) as common.UIExtensionContext; + + build() { + Row() { + Column() { + Button($r('app.string.UIExtensionStart')) + .onClick((event: ClickEvent) => { + try { + this.extensionContext.openAtomicService(this.appId, this.options) + .then((result: common.AbilityResult) => { + hilog.info(0x0000, 'testTag', 'UIExtensionContext.openAtomicService succeed'); + }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', + `UIExtensionContext.openAtomicService failed, code is ${err.code}, message is ${err.message}`); + }); + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', + `UIExtensionContext.openAtomicService failed, code is ${code}, message is ${message}`); + } + }) + .id('UIExtensionStart') + .width('93.4%').height('100%') + } + .width('100%').height('100%') + } + } +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets index 273dd4979377d6b272bf4cbef486d6ede0647463..1c75d8706d0095817ed65af94162365e3dfe92a7 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/ets/uiextensionability/UIExtensionAbility.ets @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2024 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 { Want, UIExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = '[testTag] UIExtAbility '; - -export default class UIExtAbility extends UIExtensionAbility { - onCreate() { - hilog.info(0x0000, TAG, `UIExtensionAbility onCreate`); - } - - onForeground() { - hilog.info(0x0000, TAG, `UIExtensionAbility onForeground`); - } - - onBackground() { - hilog.info(0x0000, TAG, `UIExtensionAbility onBackground`); - } - - onDestroy() { - hilog.info(0x0000, TAG, `UIExtensionAbility onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - hilog.info(0x0000, TAG, `UIExtensionAbility onSessionCreate, want: ${JSON.stringify(want)}`); - let storage: LocalStorage = new LocalStorage(); - storage.setOrCreate('session', session); - session.loadContent('pages/ExtensionIndex', storage); - } - - onSessionDestroy(session: UIExtensionContentSession) { - hilog.info(0x0000, TAG, `onSessionDestroy`); - } +/* + * Copyright (c) 2024 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 { Want, UIExtensionAbility, UIExtensionContentSession } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[testTag] UIExtAbility '; + +export default class UIExtAbility extends UIExtensionAbility { + onCreate() { + hilog.info(0x0000, TAG, `UIExtensionAbility onCreate`); + } + + onForeground() { + hilog.info(0x0000, TAG, `UIExtensionAbility onForeground`); + } + + onBackground() { + hilog.info(0x0000, TAG, `UIExtensionAbility onBackground`); + } + + onDestroy() { + hilog.info(0x0000, TAG, `UIExtensionAbility onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + hilog.info(0x0000, TAG, `UIExtensionAbility onSessionCreate, want: ${JSON.stringify(want)}`); + let storage: LocalStorage = new LocalStorage(); + storage.setOrCreate('session', session); + session.loadContent('pages/ExtensionIndex', storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + hilog.info(0x0000, TAG, `onSessionDestroy`); + } } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/module.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/module.json5 index 2377e8967312f1483a2d74b4f0ef9781e3c27e6e..a5e31081e2656f8bc5e793c79590b35a1919a7ea 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/module.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/module.json5 @@ -1,73 +1,73 @@ -/* - * Copyright (c) 2024 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" - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "EntryBackupAbility", - "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", - "type": "backup", - "exported": false, - "metadata": [ - { - "name": "ohos.extension.backup", - "resource": "$profile:backup_config" - } - ] - }, - { - "name": "UIExtAbility", - "srcEntry": "./ets/uiextensionability/UIExtensionAbility.ets", - "description": "UIExtensionAbility", - "type": "sys/commonUI", - "exported": true, - } - ] - } +/* + * Copyright (c) 2024 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" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + }, + { + "name": "UIExtAbility", + "srcEntry": "./ets/uiextensionability/UIExtensionAbility.ets", + "description": "UIExtensionAbility", + "type": "sys/commonUI", + "exported": true, + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/element/color.json b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/profile/backup_config.json b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/profile/backup_config.json +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/ohosTest/module.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/ohosTest/module.json5 index 1f646ea03f584d15f4a5406ea548af0214a093d4..5f63462032245655b8df990c83c5d7312015c089 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/entry/src/ohosTest/module.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/SystemFeature/FullScreenStart/FullScreenStart/hvigor/hvigor-config.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/hvigor/hvigor-config.json5 index 5f9d8a57584fa98d3e8f6c63a304213b801d0dff..76e3231223076011f7f4400f54fa73a5ab0141d4 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/hvigor/hvigor-config.json5 @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2024 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": { - }, - "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*/ - } -} +/* + * Copyright (c) 2024 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": { + }, + "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/SystemFeature/FullScreenStart/FullScreenStart/oh-package.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart/oh-package.json5 index d645a02be51ec3ec6bec2da93c5350d0b80b935f..a941f4458316c00220a8f9a3b0c15342b6b6255b 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/oh-package.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.18", - "@ohos/hamock": "1.0.0" - } -} +/* + * Copyright (c) 2024 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.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart/ohosTest.md b/code/SystemFeature/FullScreenStart/FullScreenStart/ohosTest.md index 450c6699a6d6dce4aa1f46184a53b5db19dc072b..8c5569adbddf4f375bc3699fbd3f513e31fef499 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart/ohosTest.md +++ b/code/SystemFeature/FullScreenStart/FullScreenStart/ohosTest.md @@ -1,9 +1,9 @@ -# 全屏启动原子化服务测试用例 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | -| -------------------------------------------------- | -------- | -------------------------- | ------------------------- | ------| ------ | -| 验证通过arkui接口FullScreenLaunchComponent嵌入式全屏启动原子化服务 | 位于启动页面 | 点击"全屏启动原子化服务组件"按钮 | 页面通过嵌入式启动方式跳转至原子化服务应用 | 是 | Pass | -| 验证通过UIAbilityContext.openAtomicService接口跳出式启动原子化服务 | 位于启动页面 | 点击"UIAbility启动原子化服务"按钮 | 页面通过跳出式启动方式跳转至原子化服务应用 | 是 | Pass | +# 全屏启动原子化服务测试用例 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------------- | -------- | -------------------------- | ------------------------- | ------| ------ | +| 验证通过arkui接口FullScreenLaunchComponent嵌入式全屏启动原子化服务 | 位于启动页面 | 点击"全屏启动原子化服务组件"按钮 | 页面通过嵌入式启动方式跳转至原子化服务应用 | 是 | Pass | +| 验证通过UIAbilityContext.openAtomicService接口跳出式启动原子化服务 | 位于启动页面 | 点击"UIAbility启动原子化服务"按钮 | 页面通过跳出式启动方式跳转至原子化服务应用 | 是 | Pass | | 验证通过UIExtensionContext.openAtomicService接口跳出式启动原子化服务 | 位于启动页面 | 点击"UIExtension启动原子化服务"按钮 | 页面通过跳出式启动方式跳转至原子化服务应用 | 是 | Pass | \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/app.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/app.json5 index bedd9b53b5baec648b1fed4e835b94c9999a2445..6b04af62c3e7b5503318d09474683594f9904257 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/app.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/app.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2024 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.atomicservice.5765880207854787517", - "bundleType": "atomicService", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.atomicservice.5765880207854787517", + "bundleType": "atomicService", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/resources/base/element/string.json b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/resources/base/element/string.json index 64fcb63f50309e57991b4d3f5a8d6b14515688ae..a7245dde060f9df3c74a33bc7c535d3debb80dd2 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "FullScreenStart_Service" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "FullScreenStart_Service" + } + ] +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/build-profile.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/build-profile.json5 index 94452336dfbc003422f85ab4d0068a5d73592a5b..19d7b77601945210031cba018b92b8617ee17026 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/build-profile.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS", + } + ], + "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/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/build-profile.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/build-profile.json5 index 97f563b45aac28e7e3ae336f7c0eb06b7b789179..63b88fb1a0053e40acb2391457a7e9d71af748fe 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/build-profile.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/build-profile.json5 @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/oh-package.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/oh-package.json5 index 41a4755f666bbe0bb1a9ebbedd6fb045727e62fb..4e54d14e1b444a338b2c922f94a4fe4deed5be45 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/oh-package.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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": {} -} - +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/constants/CommonConstants.ets b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/constants/CommonConstants.ets index 589e72b7d34464794ce1243c5f4933e33987cebf..b74bfe125b7ad3ccc17d905bd8ca1aec063a7c8b 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/constants/CommonConstants.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/constants/CommonConstants.ets @@ -1,124 +1,124 @@ -/* - * Copyright (c) 2024 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. - */ - -/** - * Common constants for all features. - */ -export class CommonConstants { - /** - * Full percent. - */ - static readonly FULL_PERCENT: string = '100%'; - /** - * Operator Collection. - */ - static readonly OPERATORS: string = '+-×÷'; - /** - * Operators with high precedence. - */ - static readonly OPERATORS_PRIORITY: string = '×÷'; - /** - * Addition. - */ - static readonly ADD: string = '+'; - /** - * Minus. - */ - static readonly MIN: string = '-'; - /** - * Multiplication. - */ - static readonly MUL: string = '×'; - /** - * Division. - */ - static readonly DIV: string = '÷'; - /** - * Percent sign. - */ - static readonly PERCENT_SIGN: string = '%'; - /** - * Decimal point. - */ - static readonly DOTS: string = '.'; - /** - * Number two. - */ - static readonly TWO: number = 2; - /** - * Digit ten. - */ - static readonly TEN: number = 10; - /** - * One hundred. - */ - static readonly ONE_HUNDRED: string = '100'; - /** - * Display Maximum Length of Large Fonts. - */ - static readonly INPUT_LENGTH_MAX: number = 9; - /** - * Subscript is two. - */ - static readonly INDEX_TWO: number = 2; - /** - * Maximum length of a single digit. - */ - static readonly NUM_MAX_LEN: number = 16; - /** - * Letter e. - */ - static readonly E: string = 'e'; - /** - * String Zero. - */ - static readonly ZERO: string = '0' - /** - * zero point. - */ - static readonly ZERO_DOTS: string = '0.' -} - -/** - * Symbol value. - */ -export enum Symbol { - ADD = 'add', - MIN = 'min', - MUL = 'mul', - DIV = 'div', - CLEAN = 'clean', - DEL = 'del', - EQU = 'equ' -} - -/** - * Operator Precedence Enumeration. - */ -export enum Priority { - HIGH = 2, - MEDIUM = 1, - LOW = 0 -} - -/** - * Enumerated value: addition, subtraction, multiplication, and division. - */ -export enum SymbolicEnumeration { - ADD = '+', - MIN = '-', - MUL = '×', - DIV = '÷' -} +/* + * Copyright (c) 2024 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. + */ + +/** + * Common constants for all features. + */ +export class CommonConstants { + /** + * Full percent. + */ + static readonly FULL_PERCENT: string = '100%'; + /** + * Operator Collection. + */ + static readonly OPERATORS: string = '+-×÷'; + /** + * Operators with high precedence. + */ + static readonly OPERATORS_PRIORITY: string = '×÷'; + /** + * Addition. + */ + static readonly ADD: string = '+'; + /** + * Minus. + */ + static readonly MIN: string = '-'; + /** + * Multiplication. + */ + static readonly MUL: string = '×'; + /** + * Division. + */ + static readonly DIV: string = '÷'; + /** + * Percent sign. + */ + static readonly PERCENT_SIGN: string = '%'; + /** + * Decimal point. + */ + static readonly DOTS: string = '.'; + /** + * Number two. + */ + static readonly TWO: number = 2; + /** + * Digit ten. + */ + static readonly TEN: number = 10; + /** + * One hundred. + */ + static readonly ONE_HUNDRED: string = '100'; + /** + * Display Maximum Length of Large Fonts. + */ + static readonly INPUT_LENGTH_MAX: number = 9; + /** + * Subscript is two. + */ + static readonly INDEX_TWO: number = 2; + /** + * Maximum length of a single digit. + */ + static readonly NUM_MAX_LEN: number = 16; + /** + * Letter e. + */ + static readonly E: string = 'e'; + /** + * String Zero. + */ + static readonly ZERO: string = '0' + /** + * zero point. + */ + static readonly ZERO_DOTS: string = '0.' +} + +/** + * Symbol value. + */ +export enum Symbol { + ADD = 'add', + MIN = 'min', + MUL = 'mul', + DIV = 'div', + CLEAN = 'clean', + DEL = 'del', + EQU = 'equ' +} + +/** + * Operator Precedence Enumeration. + */ +export enum Priority { + HIGH = 2, + MEDIUM = 1, + LOW = 0 +} + +/** + * Enumerated value: addition, subtraction, multiplication, and division. + */ +export enum SymbolicEnumeration { + ADD = '+', + MIN = '-', + MUL = '×', + DIV = '÷' +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CalculateUtil.ets b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CalculateUtil.ets index a18bbaa9c221dd8e9037fa9ee6b8a19b9e987098..72d5587abef51d821106f7eca755ea5dda277641 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CalculateUtil.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CalculateUtil.ets @@ -1,282 +1,282 @@ -/* - * Copyright (c) 2024 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 { CommonConstants, Priority, SymbolicEnumeration } from '../constants/CommonConstants'; -import CheckEmptyUtil from './CheckEmptyUtil'; - -class CalculateUtil { - /** - * Determines whether it is an operator. - * - * @param value The symbol. - * @return Is Operator. - */ - isSymbol(value: string) { - if (CheckEmptyUtil.isEmpty(value)) { - return; - } - return (CommonConstants.OPERATORS.indexOf(value) !== -1); - } - - /** - * Get Operator Precedence. - * - * @param value The symbol. - * @return Priority. - */ - getPriority(value: string): number { - if (CheckEmptyUtil.isEmpty(value)) { - return Priority.LOW; - } - let result = 0; - switch (value) { - case SymbolicEnumeration.ADD: - case SymbolicEnumeration.MIN: - result = Priority.MEDIUM; - break; - case SymbolicEnumeration.MUL: - case SymbolicEnumeration.DIV: - result = Priority.HIGH; - break; - default: - result = Priority.LOW; - break; - } - return result; - } - - /** - * Determine the priority of addition, subtraction, multiplication, and division. - * - * @param arg1 Parameter 1. - * @param arg2 Parameter 2. - * @return Compare Priority Results. - */ - comparePriority(arg1: string, arg2: string): boolean { - if (CheckEmptyUtil.isEmpty(arg1) || CheckEmptyUtil.isEmpty(arg2)) { - return false; - } - return (this.getPriority(arg1) <= this.getPriority(arg2)); - } - - /** - * Expression Processing. - * - * @param expressions Expressions. - */ - parseExpression(expressions: Array): string { - if (CheckEmptyUtil.isEmpty(expressions)) { - return 'NaN'; - } - let len = expressions.length; - let outputStack: string[] = []; - let outputQueue: string[] = []; - expressions.forEach((item: string, index: number) => { - // Handle % in the expression - if (item.indexOf(CommonConstants.PERCENT_SIGN) !== -1) { - expressions[index] = (this.mulOrDiv(item.slice(0, item.length - 1), - CommonConstants.ONE_HUNDRED, CommonConstants.DIV)).toString(); - } - // Whether the last digit is an operator. - if ((index === len - 1) && this.isSymbol(item)) { - expressions.pop(); - } - }); - while (expressions.length > 0) { - let current: string | undefined = expressions.shift(); - if (current !== undefined) { - if (this.isSymbol(current)) { - // Processing addition, subtraction, multiplication and division. - while (outputStack.length > 0 && this.comparePriority(current, outputStack[outputStack.length - 1])) { - let popValue: string | undefined = outputStack.pop(); - if (popValue !== undefined) { - outputQueue.push(popValue); - } - } - outputStack.push(current); - } else { - // Processing the numbers. - outputQueue.push(current); - } - } - } - while (outputStack.length > 0) { - let popValue: string | undefined = outputStack.pop(); - if (popValue !== undefined) { - outputQueue.push(popValue); - } - } - return this.dealQueue(outputQueue); - } - - /** - * Processing expressions in queues. - * - * @param queue Expression Queue. - * @return The end result. - */ - dealQueue(queue: Array): string { - if (CheckEmptyUtil.isEmpty(queue)) { - return 'NaN'; - } - let outputStack: string[] = []; - while (queue.length > 0) { - let current: string | undefined = queue.shift(); - if (current !== undefined) { - if (!this.isSymbol(current)) { - outputStack.push(current); - } else { - let second: string | undefined = outputStack.pop(); - let first: string | undefined = outputStack.pop(); - if (first !== undefined && second !== undefined) { - let calResultValue: string = this.calResult(first, second, current) - outputStack.push(calResultValue); - } - } - } - } - if (outputStack.length !== 1) { - return 'NaN'; - } else { - let end: string = outputStack[0]?.endsWith(CommonConstants.DOTS) ? - outputStack[0].substring(0, outputStack[0].length - 1) : outputStack[0]; - return end; - } - } - - /** - * Calculation result. - * - * @param arg1 Number 1. - * @param arg2 Number 2. - * @param symbol Operators. - * @return Calculation result. - */ - calResult(arg1: string, arg2: string, symbol: string): string { - if (CheckEmptyUtil.isEmpty(arg1) || CheckEmptyUtil.isEmpty(arg2) || CheckEmptyUtil.isEmpty(symbol)) { - return 'NaN'; - } - let result = 0; - switch (symbol) { - case SymbolicEnumeration.ADD: - result = this.add(arg1, arg2, CommonConstants.ADD); - break; - case SymbolicEnumeration.MIN: - result = this.add(arg1, arg2, CommonConstants.MIN); - break; - case SymbolicEnumeration.MUL: - result = this.mulOrDiv(arg1, arg2, CommonConstants.MUL); - break; - case SymbolicEnumeration.DIV: - result = this.mulOrDiv(arg1, arg2, CommonConstants.DIV); - break; - default: - break; - } - return this.numberToScientificNotation(result); - } - - /** - * Addition and subtraction operation. - * - * @param arg1 Number 1. - * @param arg2 Number 2. - * @param symbol Operators. - * @return Addition and subtraction results. - */ - add(arg1: string, arg2: string, symbol: string): number { - let addFlag = (symbol === CommonConstants.ADD); - if (this.containScientificNotation(arg1) || this.containScientificNotation(arg2)) { - if (addFlag) { - return Number(arg1) + Number(arg2); - } - return Number(arg1) - Number(arg2); - } - arg1 = (arg1 === CommonConstants.ZERO_DOTS) ? '0' : arg1; - arg2 = (arg2 === CommonConstants.ZERO_DOTS) ? '0' : arg2; - let leftArr = arg1.split(CommonConstants.DOTS); - let rightArr = arg2.split(CommonConstants.DOTS); - let leftLen = leftArr.length > 1 ? leftArr[1] : ''; - let rightLen = rightArr.length > 1 ? rightArr[1] : ''; - let maxLen = Math.max(leftLen.length, rightLen.length); - let multiples = Math.pow(CommonConstants.TEN, maxLen); - if (addFlag) { - return Number(((Number(arg1) * multiples + Number(arg2) * multiples) / multiples).toFixed(maxLen)); - } - return Number(((Number(arg1) * multiples - Number(arg2) * multiples) / multiples).toFixed(maxLen)); - } - - /** - * multiplication and division operation. - * - * @param arg1 Number 1. - * @param arg2 Number 2. - * @param symbol Operators. - * @return Multiply and divide result. - */ - mulOrDiv(arg1: string, arg2: string, symbol: string): number { - let mulFlag = (symbol === CommonConstants.MUL); - if (this.containScientificNotation(arg1) || this.containScientificNotation(arg2)) { - if (mulFlag) { - return Number(arg1) * Number(arg2); - } - return Number(arg1) / Number(arg2); - } - let leftLen = arg1.split(CommonConstants.DOTS)[1] ? arg1.split(CommonConstants.DOTS)[1].length : 0; - let rightLen = arg2.split(CommonConstants.DOTS)[1] ? arg2.split(CommonConstants.DOTS)[1].length : 0; - if (mulFlag) { - return Number(arg1.replace(CommonConstants.DOTS, '')) * - Number(arg2.replace(CommonConstants.DOTS, '')) / Math.pow(CommonConstants.TEN, leftLen + rightLen); - } - return Number(arg1.replace(CommonConstants.DOTS, '')) / - (Number(arg2.replace(CommonConstants.DOTS, '')) / Math.pow(CommonConstants.TEN, rightLen - leftLen)); - } - - /** - * Whether the operand contains scientific notation - * - * @param arg Number. - * @return Whether scientific notation is included - */ - containScientificNotation(arg: string) { - return (arg.indexOf(CommonConstants.E) !== -1); - } - - /** - * Results converted to scientific notation. - * - * @param result Digital Results. - */ - numberToScientificNotation(result: number) { - if (result === Number.NEGATIVE_INFINITY || result === Number.POSITIVE_INFINITY) { - return 'NaN'; - } - let resultStr = JSON.stringify(result); - if (this.containScientificNotation(resultStr)) { - return resultStr; - } - let prefixNumber = (resultStr.indexOf(CommonConstants.MIN) === -1) ? 1 : -1; - result *= prefixNumber; - if (resultStr.replace(CommonConstants.DOTS, '').replace(CommonConstants.MIN, '').length < - CommonConstants.NUM_MAX_LEN) { - return resultStr; - } - let suffix = (Math.floor(Math.log(result) / Math.LN10)); - let prefix = (result * Math.pow(CommonConstants.TEN, -suffix) * prefixNumber); - return (prefix + CommonConstants.E + suffix); - } -} - +/* + * Copyright (c) 2024 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 { CommonConstants, Priority, SymbolicEnumeration } from '../constants/CommonConstants'; +import CheckEmptyUtil from './CheckEmptyUtil'; + +class CalculateUtil { + /** + * Determines whether it is an operator. + * + * @param value The symbol. + * @return Is Operator. + */ + isSymbol(value: string) { + if (CheckEmptyUtil.isEmpty(value)) { + return; + } + return (CommonConstants.OPERATORS.indexOf(value) !== -1); + } + + /** + * Get Operator Precedence. + * + * @param value The symbol. + * @return Priority. + */ + getPriority(value: string): number { + if (CheckEmptyUtil.isEmpty(value)) { + return Priority.LOW; + } + let result = 0; + switch (value) { + case SymbolicEnumeration.ADD: + case SymbolicEnumeration.MIN: + result = Priority.MEDIUM; + break; + case SymbolicEnumeration.MUL: + case SymbolicEnumeration.DIV: + result = Priority.HIGH; + break; + default: + result = Priority.LOW; + break; + } + return result; + } + + /** + * Determine the priority of addition, subtraction, multiplication, and division. + * + * @param arg1 Parameter 1. + * @param arg2 Parameter 2. + * @return Compare Priority Results. + */ + comparePriority(arg1: string, arg2: string): boolean { + if (CheckEmptyUtil.isEmpty(arg1) || CheckEmptyUtil.isEmpty(arg2)) { + return false; + } + return (this.getPriority(arg1) <= this.getPriority(arg2)); + } + + /** + * Expression Processing. + * + * @param expressions Expressions. + */ + parseExpression(expressions: Array): string { + if (CheckEmptyUtil.isEmpty(expressions)) { + return 'NaN'; + } + let len = expressions.length; + let outputStack: string[] = []; + let outputQueue: string[] = []; + expressions.forEach((item: string, index: number) => { + // Handle % in the expression + if (item.indexOf(CommonConstants.PERCENT_SIGN) !== -1) { + expressions[index] = (this.mulOrDiv(item.slice(0, item.length - 1), + CommonConstants.ONE_HUNDRED, CommonConstants.DIV)).toString(); + } + // Whether the last digit is an operator. + if ((index === len - 1) && this.isSymbol(item)) { + expressions.pop(); + } + }); + while (expressions.length > 0) { + let current: string | undefined = expressions.shift(); + if (current !== undefined) { + if (this.isSymbol(current)) { + // Processing addition, subtraction, multiplication and division. + while (outputStack.length > 0 && this.comparePriority(current, outputStack[outputStack.length - 1])) { + let popValue: string | undefined = outputStack.pop(); + if (popValue !== undefined) { + outputQueue.push(popValue); + } + } + outputStack.push(current); + } else { + // Processing the numbers. + outputQueue.push(current); + } + } + } + while (outputStack.length > 0) { + let popValue: string | undefined = outputStack.pop(); + if (popValue !== undefined) { + outputQueue.push(popValue); + } + } + return this.dealQueue(outputQueue); + } + + /** + * Processing expressions in queues. + * + * @param queue Expression Queue. + * @return The end result. + */ + dealQueue(queue: Array): string { + if (CheckEmptyUtil.isEmpty(queue)) { + return 'NaN'; + } + let outputStack: string[] = []; + while (queue.length > 0) { + let current: string | undefined = queue.shift(); + if (current !== undefined) { + if (!this.isSymbol(current)) { + outputStack.push(current); + } else { + let second: string | undefined = outputStack.pop(); + let first: string | undefined = outputStack.pop(); + if (first !== undefined && second !== undefined) { + let calResultValue: string = this.calResult(first, second, current) + outputStack.push(calResultValue); + } + } + } + } + if (outputStack.length !== 1) { + return 'NaN'; + } else { + let end: string = outputStack[0]?.endsWith(CommonConstants.DOTS) ? + outputStack[0].substring(0, outputStack[0].length - 1) : outputStack[0]; + return end; + } + } + + /** + * Calculation result. + * + * @param arg1 Number 1. + * @param arg2 Number 2. + * @param symbol Operators. + * @return Calculation result. + */ + calResult(arg1: string, arg2: string, symbol: string): string { + if (CheckEmptyUtil.isEmpty(arg1) || CheckEmptyUtil.isEmpty(arg2) || CheckEmptyUtil.isEmpty(symbol)) { + return 'NaN'; + } + let result = 0; + switch (symbol) { + case SymbolicEnumeration.ADD: + result = this.add(arg1, arg2, CommonConstants.ADD); + break; + case SymbolicEnumeration.MIN: + result = this.add(arg1, arg2, CommonConstants.MIN); + break; + case SymbolicEnumeration.MUL: + result = this.mulOrDiv(arg1, arg2, CommonConstants.MUL); + break; + case SymbolicEnumeration.DIV: + result = this.mulOrDiv(arg1, arg2, CommonConstants.DIV); + break; + default: + break; + } + return this.numberToScientificNotation(result); + } + + /** + * Addition and subtraction operation. + * + * @param arg1 Number 1. + * @param arg2 Number 2. + * @param symbol Operators. + * @return Addition and subtraction results. + */ + add(arg1: string, arg2: string, symbol: string): number { + let addFlag = (symbol === CommonConstants.ADD); + if (this.containScientificNotation(arg1) || this.containScientificNotation(arg2)) { + if (addFlag) { + return Number(arg1) + Number(arg2); + } + return Number(arg1) - Number(arg2); + } + arg1 = (arg1 === CommonConstants.ZERO_DOTS) ? '0' : arg1; + arg2 = (arg2 === CommonConstants.ZERO_DOTS) ? '0' : arg2; + let leftArr = arg1.split(CommonConstants.DOTS); + let rightArr = arg2.split(CommonConstants.DOTS); + let leftLen = leftArr.length > 1 ? leftArr[1] : ''; + let rightLen = rightArr.length > 1 ? rightArr[1] : ''; + let maxLen = Math.max(leftLen.length, rightLen.length); + let multiples = Math.pow(CommonConstants.TEN, maxLen); + if (addFlag) { + return Number(((Number(arg1) * multiples + Number(arg2) * multiples) / multiples).toFixed(maxLen)); + } + return Number(((Number(arg1) * multiples - Number(arg2) * multiples) / multiples).toFixed(maxLen)); + } + + /** + * multiplication and division operation. + * + * @param arg1 Number 1. + * @param arg2 Number 2. + * @param symbol Operators. + * @return Multiply and divide result. + */ + mulOrDiv(arg1: string, arg2: string, symbol: string): number { + let mulFlag = (symbol === CommonConstants.MUL); + if (this.containScientificNotation(arg1) || this.containScientificNotation(arg2)) { + if (mulFlag) { + return Number(arg1) * Number(arg2); + } + return Number(arg1) / Number(arg2); + } + let leftLen = arg1.split(CommonConstants.DOTS)[1] ? arg1.split(CommonConstants.DOTS)[1].length : 0; + let rightLen = arg2.split(CommonConstants.DOTS)[1] ? arg2.split(CommonConstants.DOTS)[1].length : 0; + if (mulFlag) { + return Number(arg1.replace(CommonConstants.DOTS, '')) * + Number(arg2.replace(CommonConstants.DOTS, '')) / Math.pow(CommonConstants.TEN, leftLen + rightLen); + } + return Number(arg1.replace(CommonConstants.DOTS, '')) / + (Number(arg2.replace(CommonConstants.DOTS, '')) / Math.pow(CommonConstants.TEN, rightLen - leftLen)); + } + + /** + * Whether the operand contains scientific notation + * + * @param arg Number. + * @return Whether scientific notation is included + */ + containScientificNotation(arg: string) { + return (arg.indexOf(CommonConstants.E) !== -1); + } + + /** + * Results converted to scientific notation. + * + * @param result Digital Results. + */ + numberToScientificNotation(result: number) { + if (result === Number.NEGATIVE_INFINITY || result === Number.POSITIVE_INFINITY) { + return 'NaN'; + } + let resultStr = JSON.stringify(result); + if (this.containScientificNotation(resultStr)) { + return resultStr; + } + let prefixNumber = (resultStr.indexOf(CommonConstants.MIN) === -1) ? 1 : -1; + result *= prefixNumber; + if (resultStr.replace(CommonConstants.DOTS, '').replace(CommonConstants.MIN, '').length < + CommonConstants.NUM_MAX_LEN) { + return resultStr; + } + let suffix = (Math.floor(Math.log(result) / Math.LN10)); + let prefix = (result * Math.pow(CommonConstants.TEN, -suffix) * prefixNumber); + return (prefix + CommonConstants.E + suffix); + } +} + export default new CalculateUtil(); \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CheckEmptyUtil.ets b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CheckEmptyUtil.ets index 40b849aced08200b751c4e2c62519d7d012d7bbb..1fd436a17fb5c1818c6364052561a6baeaa61310 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CheckEmptyUtil.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/common/util/CheckEmptyUtil.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2024 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. - */ - - -class CheckEmptyUtil { - /** - * Check obj is empty. - * - * @param {object} obj - * @return {boolean} true(empty) - */ - isEmpty(obj: object | string): boolean { - return (typeof obj === 'undefined' || obj === null || obj === ''); - } - - /** - * Check str is empty. - * - * @param {string} str - * @return {boolean} true(empty) - */ - checkStrIsEmpty(str: string): boolean { - return str.trim().length === 0; - } - - /** - * Check array is empty. - * - * @param {Array}arr - * @return {boolean} true(empty) - */ - isEmptyArr(arr: Array) { - return arr.length === 0; - } -} - -export default new CheckEmptyUtil(); - +/* + * Copyright (c) 2024 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. + */ + + +class CheckEmptyUtil { + /** + * Check obj is empty. + * + * @param {object} obj + * @return {boolean} true(empty) + */ + isEmpty(obj: object | string): boolean { + return (typeof obj === 'undefined' || obj === null || obj === ''); + } + + /** + * Check str is empty. + * + * @param {string} str + * @return {boolean} true(empty) + */ + checkStrIsEmpty(str: string): boolean { + return str.trim().length === 0; + } + + /** + * Check array is empty. + * + * @param {Array}arr + * @return {boolean} true(empty) + */ + isEmptyArr(arr: Array) { + return arr.length === 0; + } +} + +export default new CheckEmptyUtil(); + diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/entryability/EntryAbility.ets b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/entryability/EntryAbility.ets index 9668c36c46c96cd3c28a7711d3c74179ba1f2d73..450c59f024be7524656245503997277c4c61e1a8 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2024 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, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; -import EmbeddableUIAbility from '@ohos.app.ability.EmbeddableUIAbility'; -import commonEventManager from '@ohos.commonEventManager'; - -export default class EntryAbility extends EmbeddableUIAbility { - 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'); - let options: commonEventManager.CommonEventPublishData = { - parameters: { - 'bundleName': this.context.abilityInfo.bundleName, - } - } - commonEventManager.publish('GetCurrentTopAbility', options, async () => { - }) - } - - onBackground(): void { - // Ability has back to background - hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import EmbeddableUIAbility from '@ohos.app.ability.EmbeddableUIAbility'; +import commonEventManager from '@ohos.commonEventManager'; + +export default class EntryAbility extends EmbeddableUIAbility { + 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'); + let options: commonEventManager.CommonEventPublishData = { + parameters: { + 'bundleName': this.context.abilityInfo.bundleName, + } + } + commonEventManager.publish('GetCurrentTopAbility', options, async () => { + }) + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PressKeysItem.ets b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PressKeysItem.ets index 4349bfda42a19d6de48be82245ddf1f445dc4a7e..fe8fa5002bea88654e56c477a8b72ee53698ddff 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PressKeysItem.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PressKeysItem.ets @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2024 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 class PressKeysBean { - public flag: number; - public width: string; - public height: string; - public value: string; - public source?: Resource; - - constructor(flag: number, width: string, height: string, value: string, source?: Resource) { - this.flag = flag; - this.width = width; - this.height = height; - this.value = value; - this.source = source; - } +/* + * Copyright (c) 2024 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 class PressKeysBean { + public flag: number; + public width: string; + public height: string; + public value: string; + public source?: Resource; + + constructor(flag: number, width: string, height: string, value: string, source?: Resource) { + this.flag = flag; + this.width = width; + this.height = height; + this.value = value; + this.source = source; + } } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PresskeysViewModel.ets b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PresskeysViewModel.ets index 8305ad33d5c74f45ec4e8e616a113f0d623be6a2..63b34da339945f4cf7d5d6991470ca9ac0ed9f0d 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PresskeysViewModel.ets +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/ets/viewmodel/PresskeysViewModel.ets @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2024 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 { PressKeysBean } from './PressKeysItem'; - -export class PressKeysBeanViewModel { - /** - * Key array data. - */ - getPressKeys(): Array> { - return [ - [ - new PressKeysBean(0, '32vp', '32vp', 'clean', $r('app.media.ic_clean')), - new PressKeysBean(1, '19vp', '43vp', '7'), - new PressKeysBean(1, '19vp', '43vp', '4'), - new PressKeysBean(1, '19vp', '43vp', '1'), - new PressKeysBean(1, '25vp', '43vp', '%') - ], - [ - new PressKeysBean(0, '32vp', '32vp', 'div', $r('app.media.ic_div')), - new PressKeysBean(1, '19vp', '43vp', '8'), - new PressKeysBean(1, '19vp', '43vp', '5'), - new PressKeysBean(1, '19vp', '43vp', '2'), - new PressKeysBean(1, '19vp', '43vp', '0') - ], - [ - new PressKeysBean(0, '32vp', '32vp', 'mul', $r('app.media.ic_mul')), - new PressKeysBean(1, '19vp', '43vp', '9'), - new PressKeysBean(1, '19vp', '43vp', '6'), - new PressKeysBean(1, '19vp', '43vp', '3'), - new PressKeysBean(1, '19vp', '43vp', '.') - ], - [ - new PressKeysBean(0, '30.48vp', '20vp', 'del', $r('app.media.ic_del')), - new PressKeysBean(0, '24vp', '24vp', 'min', $r('app.media.ic_min')), - new PressKeysBean(0, '32vp', '32vp', 'add', $r('app.media.ic_add')), - new PressKeysBean(0, '32vp', '32vp', 'equ', $r('app.media.ic_equ')) - ] - ]; - } -} - -let keysModel = new PressKeysBeanViewModel(); - +/* + * Copyright (c) 2024 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 { PressKeysBean } from './PressKeysItem'; + +export class PressKeysBeanViewModel { + /** + * Key array data. + */ + getPressKeys(): Array> { + return [ + [ + new PressKeysBean(0, '32vp', '32vp', 'clean', $r('app.media.ic_clean')), + new PressKeysBean(1, '19vp', '43vp', '7'), + new PressKeysBean(1, '19vp', '43vp', '4'), + new PressKeysBean(1, '19vp', '43vp', '1'), + new PressKeysBean(1, '25vp', '43vp', '%') + ], + [ + new PressKeysBean(0, '32vp', '32vp', 'div', $r('app.media.ic_div')), + new PressKeysBean(1, '19vp', '43vp', '8'), + new PressKeysBean(1, '19vp', '43vp', '5'), + new PressKeysBean(1, '19vp', '43vp', '2'), + new PressKeysBean(1, '19vp', '43vp', '0') + ], + [ + new PressKeysBean(0, '32vp', '32vp', 'mul', $r('app.media.ic_mul')), + new PressKeysBean(1, '19vp', '43vp', '9'), + new PressKeysBean(1, '19vp', '43vp', '6'), + new PressKeysBean(1, '19vp', '43vp', '3'), + new PressKeysBean(1, '19vp', '43vp', '.') + ], + [ + new PressKeysBean(0, '30.48vp', '20vp', 'del', $r('app.media.ic_del')), + new PressKeysBean(0, '24vp', '24vp', 'min', $r('app.media.ic_min')), + new PressKeysBean(0, '32vp', '32vp', 'add', $r('app.media.ic_add')), + new PressKeysBean(0, '32vp', '32vp', 'equ', $r('app.media.ic_equ')) + ] + ]; + } +} + +let keysModel = new PressKeysBeanViewModel(); + export default keysModel as PressKeysBeanViewModel; \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/module.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/module.json5 index bbda7f34bc12ff35162a85d9c019c208cb892d54..8bac476312f53046c0aa6915aeb04ad80e443c0a 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/module.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry", - "type": "entry", - "description": "$string:module_desc", - "mainElement": "EntryAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": true, - "pages": "$profile:main_pages", - "abilities": [ - { - "name": "EntryAbility", - "srcEntry": "./ets/entryability/EntryAbility.ets", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": true, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/color.json b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/color.json index cec71ab2767acfea85d56dafc9bd25b9819fe44d..ea07df432d5f496a72a2f63cc389bb3e262fcd79 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/color.json @@ -1,32 +1,32 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "input_back_color", - "value": "#F5F5F5" - }, - { - "name": "text_color", - "value": "#182431" - }, - { - "name": "border_color", - "value": "#F5F5F5" - }, - { - "name": "equals_back_color", - "value": "#007DFF" - }, - { - "name": "row_back_color", - "value": "#F8F8FF" - }, - { - "name": "column_back_color", - "value": "#F5F5F5" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "input_back_color", + "value": "#F5F5F5" + }, + { + "name": "text_color", + "value": "#182431" + }, + { + "name": "border_color", + "value": "#F5F5F5" + }, + { + "name": "equals_back_color", + "value": "#007DFF" + }, + { + "name": "row_back_color", + "value": "#F8F8FF" + }, + { + "name": "column_back_color", + "value": "#F5F5F5" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/float.json b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/float.json index f652110bc2661aa8e8bd7b178a343cc1627cf898..5450b9d27f382c3b4690c2f33b7d39b2a621ba80 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/float.json +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/main/resources/base/element/float.json @@ -1,76 +1,76 @@ -{ - "float": [ - { - "name": "float_1", - "value": "30.6" - }, - { - "name": "font_size_input", - "value": "64fp" - }, - { - "name": "font_size_text", - "value": "32fp" - }, - { - "name": "font_size_dot", - "value": "42fp" - }, - { - "name": "input_height", - "value": "86vp" - }, - { - "name": "input_margin_right", - "value": "22vp" - }, - { - "name": "input_margin_top", - "value": "121.96vp" - }, - { - "name": "text_height", - "value": "43vp" - }, - { - "name": "text_margin_right", - "value": "21vp" - }, - { - "name": "text_margin_bottom", - "value": "64vp" - }, - { - "name": "key_width", - "value": "70vp" - }, - { - "name": "key_height", - "value": "60vp" - }, - { - "name": "equals_height", - "value": "125vp" - }, - { - "name": "border_radius", - "value": "36vp" - }, - { - "name": "margin_top", - "value": "70vp" - }, - { - "name": "margin_bottom", - "value": "40vp" - }, - { - "name": "margin_left", - "value": "19vp" - }, - { - "name": "margin_right", - "value": "19vp" - } - ] +{ + "float": [ + { + "name": "float_1", + "value": "30.6" + }, + { + "name": "font_size_input", + "value": "64fp" + }, + { + "name": "font_size_text", + "value": "32fp" + }, + { + "name": "font_size_dot", + "value": "42fp" + }, + { + "name": "input_height", + "value": "86vp" + }, + { + "name": "input_margin_right", + "value": "22vp" + }, + { + "name": "input_margin_top", + "value": "121.96vp" + }, + { + "name": "text_height", + "value": "43vp" + }, + { + "name": "text_margin_right", + "value": "21vp" + }, + { + "name": "text_margin_bottom", + "value": "64vp" + }, + { + "name": "key_width", + "value": "70vp" + }, + { + "name": "key_height", + "value": "60vp" + }, + { + "name": "equals_height", + "value": "125vp" + }, + { + "name": "border_radius", + "value": "36vp" + }, + { + "name": "margin_top", + "value": "70vp" + }, + { + "name": "margin_bottom", + "value": "40vp" + }, + { + "name": "margin_left", + "value": "19vp" + }, + { + "name": "margin_right", + "value": "19vp" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/ohosTest/module.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/ohosTest/module.json5 index af8cda384e3907ed50923b75282388e59ad93ca0..c5691d0a8c8aef0afe153bedd85e07d8dbf77b3b 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/entry/src/ohosTest/module.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -{ - "module": { - "name": "entry_test", - "type": "feature", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": true - } -} +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": true + } +} diff --git a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/hvigor/hvigor-config.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/hvigor/hvigor-config.json5 index 5f9d8a57584fa98d3e8f6c63a304213b801d0dff..76e3231223076011f7f4400f54fa73a5ab0141d4 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/hvigor/hvigor-config.json5 @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2024 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": { - }, - "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*/ - } -} +/* + * Copyright (c) 2024 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": { + }, + "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/SystemFeature/FullScreenStart/FullScreenStart_Service/oh-package.json5 b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/oh-package.json5 index d645a02be51ec3ec6bec2da93c5350d0b80b935f..a941f4458316c00220a8f9a3b0c15342b6b6255b 100644 --- a/code/SystemFeature/FullScreenStart/FullScreenStart_Service/oh-package.json5 +++ b/code/SystemFeature/FullScreenStart/FullScreenStart_Service/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2024 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.18", - "@ohos/hamock": "1.0.0" - } -} +/* + * Copyright (c) 2024 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.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/AppScope/app.json5 b/code/SystemFeature/Security/AuthorizedButton/AppScope/app.json5 index 8e149b0fc40f7edaca60764669bf6653949cd135..1e9e6d483cef0f891dab22b47d05986bd3809673 100644 --- a/code/SystemFeature/Security/AuthorizedButton/AppScope/app.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.authorizedbutton", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name", - "distributedNotificationEnabled": true - } -} +/* + * Copyright (c) 2023 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.authorizedbutton", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/AppScope/resources/base/element/string.json b/code/SystemFeature/Security/AuthorizedButton/AppScope/resources/base/element/string.json index 9c6894f1d5a943877bb987880eac6aaae9bc0619..dfd987d612b16df1f342a912916379a6e385a6f0 100644 --- a/code/SystemFeature/Security/AuthorizedButton/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/Security/AuthorizedButton/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "AuthorizedButton" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "AuthorizedButton" + } + ] +} diff --git a/code/SystemFeature/Security/AuthorizedButton/README_zh.md b/code/SystemFeature/Security/AuthorizedButton/README_zh.md index 965c2a0ddabf51ad4fced56fd3e36fb24a070d92..ffb3e1e839a6d3106e135c3fc90be8d9803cd6a0 100644 --- a/code/SystemFeature/Security/AuthorizedButton/README_zh.md +++ b/code/SystemFeature/Security/AuthorizedButton/README_zh.md @@ -1,93 +1,93 @@ -# 安全控件类型的UI控件(仅对系统应用开放) - -### 介绍 - -本示例提供了安全控件类型的UI控件,支撑应用开发者集成安全控件做临时授权场景,当用户实际点击了某种类型的安全控件时,会对应用进行相应的临时授权,减少权限弹窗对用户的干扰,同时提供更小的授权范围。 - -### 效果预览 - -| 主页 | Location | Paste | **Save** | -|:--------------------------------------:|:----------------------------------------------:|:----------------------------------------:|:--------------------------------------:| -| ![main](screenshots/devices/main.jpeg) | ![location](screenshots/devices/location.jpeg) | ![paste](screenshots/devices/paste.jpeg) | ![save](screenshots/devices/save.jpeg) | - -使用说明 -1. 在主界面,点击“LocationButton安全控件”按钮,进入“LocationButton安全控件”界面,点击“当前位置”按钮,成功获取当前定位信息,并显示在方框中。 - -2. 在主界面,点击“PasteButton安全控件”按钮,进入“PasteButton安全控件”界面,点击”复制“按钮,复制下方“天天开心”文本,点击“粘贴”按钮,获取剪贴板内容并显示在其下方框中。 - -3. 在主界面,点击“SaveButton安全控件”按钮,进入“SaveButton安全控件”界面,点击“下载”按钮,将当前页面中的图片保存到本地图库中。 - -### 工程目录 - -``` -entry/src/main/ets/ -|---securitycomponent -| |---pages -| | |---Location.ets // 位置服务安全控件界面 -| | |---Paste.ets // 剪贴板安全控件界面 -| | |---Save.ets // 媒体库安全控件界面 -|---pages -| |---Index.ets // 首页 -|---common -| |---Component -| | |---AuthorizedButton.ets // 安全控件样式 -| | |---CopyButton.ets // 剪贴板复制控件 -| | |---LocationButton.ets // 位置服务安全控件 -| | |---PasteButton.ets // 剪贴板粘贴控件 -| | |---SaveButton.ets // 媒体库写入文件控件 -| | |---TitleBar.ets // 标题栏 -|---utils -| |---Logger.ts // 日志工具 -``` - -### 具体实现 - -* 本示例分为Location安全控件模块,剪贴板安全控件模块,媒体库安全控件模块 - - * Location安全控件模块 - - * 使用SecLocationButton组件开发获取定位信息功能,在其点击回调onclick事件中调用geoLocationManager.getCurrentLocation()得到当前定位信息经纬度 - * 源码链接:[LocationButton.ets](entry/src/main/ets/common/Component/LocationButton.ets) - * 接口参考:[@ohos.geoLocationManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-location-kit/js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation) - - * 剪贴板安全控件模块 - - * 使用SecPasteButton组件开发获取剪贴板信息功能,在其点击回调onclick事件中调用ystemPasteboard.setData()将文本复制到剪贴板中,systemPasteboard.getData()得到剪贴板内容 - * 源码链接:[PasteButton.ets](entry/src/main/ets/common/Component/PasteButton.ets) - * 接口参考:[@ohos.pasteboard](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-pasteboard.md#getdata9) - - * 媒体库安全控件模块 - - * 使用SecSaveButton组件开发保存图片到媒体库功能,在其点击回调onclick事件中调用photoAccessHelper.getPhotoAccessHelper()得到媒体库图片管理器helper, - helper.createAsset()得到保存到媒体库图片的uri, - resourceManager.getMediaContent()得到存放在Resources/base/media文件下的banner.png图片内容, - fs.open()和fs.write()将图片内容通过得到的uri写到媒体库中,最后fs.close()关闭文件 - * 源码链接:[SaveButton.ets](entry/src/main/ets/common/Component/SaveButton.ets) - * 接口参考:[@ohos.file.photoAccessHelper](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md),[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) - -### 相关权限 - -不涉及。 - -### 依赖 - -不涉及。 - -### 约束与限制 - -1. 本示例仅支持标准系统上运行,支持设备:GPS定位功能仅支持部分机型。 -2. 本示例仅支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release)。 -3. 本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 -4. 本示例需要使用系统权限的系统接口,需要使用Full SDK编译。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)。 - -### 下载 - -如需单独下载本工程,执行如下命令: - -``` -git init -git config core.sparsecheckout true -echo code/SystemFeature/Security/AuthorizedButton/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` +# 安全控件类型的UI控件(仅对系统应用开放) + +### 介绍 + +本示例提供了安全控件类型的UI控件,支撑应用开发者集成安全控件做临时授权场景,当用户实际点击了某种类型的安全控件时,会对应用进行相应的临时授权,减少权限弹窗对用户的干扰,同时提供更小的授权范围。 + +### 效果预览 + +| 主页 | Location | Paste | **Save** | +|:--------------------------------------:|:----------------------------------------------:|:----------------------------------------:|:--------------------------------------:| +| ![main](screenshots/devices/main.jpeg) | ![location](screenshots/devices/location.jpeg) | ![paste](screenshots/devices/paste.jpeg) | ![save](screenshots/devices/save.jpeg) | + +使用说明 +1. 在主界面,点击“LocationButton安全控件”按钮,进入“LocationButton安全控件”界面,点击“当前位置”按钮,成功获取当前定位信息,并显示在方框中。 + +2. 在主界面,点击“PasteButton安全控件”按钮,进入“PasteButton安全控件”界面,点击”复制“按钮,复制下方“天天开心”文本,点击“粘贴”按钮,获取剪贴板内容并显示在其下方框中。 + +3. 在主界面,点击“SaveButton安全控件”按钮,进入“SaveButton安全控件”界面,点击“下载”按钮,将当前页面中的图片保存到本地图库中。 + +### 工程目录 + +``` +entry/src/main/ets/ +|---securitycomponent +| |---pages +| | |---Location.ets // 位置服务安全控件界面 +| | |---Paste.ets // 剪贴板安全控件界面 +| | |---Save.ets // 媒体库安全控件界面 +|---pages +| |---Index.ets // 首页 +|---common +| |---Component +| | |---AuthorizedButton.ets // 安全控件样式 +| | |---CopyButton.ets // 剪贴板复制控件 +| | |---LocationButton.ets // 位置服务安全控件 +| | |---PasteButton.ets // 剪贴板粘贴控件 +| | |---SaveButton.ets // 媒体库写入文件控件 +| | |---TitleBar.ets // 标题栏 +|---utils +| |---Logger.ts // 日志工具 +``` + +### 具体实现 + +* 本示例分为Location安全控件模块,剪贴板安全控件模块,媒体库安全控件模块 + + * Location安全控件模块 + + * 使用SecLocationButton组件开发获取定位信息功能,在其点击回调onclick事件中调用geoLocationManager.getCurrentLocation()得到当前定位信息经纬度 + * 源码链接:[LocationButton.ets](entry/src/main/ets/common/Component/LocationButton.ets) + * 接口参考:[@ohos.geoLocationManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-location-kit/js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation) + + * 剪贴板安全控件模块 + + * 使用SecPasteButton组件开发获取剪贴板信息功能,在其点击回调onclick事件中调用ystemPasteboard.setData()将文本复制到剪贴板中,systemPasteboard.getData()得到剪贴板内容 + * 源码链接:[PasteButton.ets](entry/src/main/ets/common/Component/PasteButton.ets) + * 接口参考:[@ohos.pasteboard](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-pasteboard.md#getdata9) + + * 媒体库安全控件模块 + + * 使用SecSaveButton组件开发保存图片到媒体库功能,在其点击回调onclick事件中调用photoAccessHelper.getPhotoAccessHelper()得到媒体库图片管理器helper, + helper.createAsset()得到保存到媒体库图片的uri, + resourceManager.getMediaContent()得到存放在Resources/base/media文件下的banner.png图片内容, + fs.open()和fs.write()将图片内容通过得到的uri写到媒体库中,最后fs.close()关闭文件 + * 源码链接:[SaveButton.ets](entry/src/main/ets/common/Component/SaveButton.ets) + * 接口参考:[@ohos.file.photoAccessHelper](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md),[@ohos.file.fs](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-fs.md) + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:GPS定位功能仅支持部分机型。 +2. 本示例仅支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release)。 +3. 本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 +4. 本示例需要使用系统权限的系统接口,需要使用Full SDK编译。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/SystemFeature/Security/AuthorizedButton/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` diff --git a/code/SystemFeature/Security/AuthorizedButton/build-profile.json5 b/code/SystemFeature/Security/AuthorizedButton/build-profile.json5 index 260a3004b2f72de30c0e4b89671c3b1afa54b652..1e8e16dcb9710ebee1ca6c47469f31763b0b9b95 100644 --- a/code/SystemFeature/Security/AuthorizedButton/build-profile.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/build-profile.json5 b/code/SystemFeature/Security/AuthorizedButton/entry/build-profile.json5 index d4c82c4ea142d283a27fe78208be32fcbf8d94cc..7981e751157b35415ea1d75b11590dbf147061b6 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/build-profile.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/oh-package.json5 b/code/SystemFeature/Security/AuthorizedButton/entry/oh-package.json5 index a4800abca08d39c85776f42cdb0f0b56f5742d77..22827b13bea5d4c448955c6dd060daf456b05655 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/oh-package.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/AuthorizedButton.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/AuthorizedButton.ets index 70273cb33db30bc998d41bee9d8b4dd94cd1658b..0cbcf2eba38bb7918fb993fe03c32b81a79c782d 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/AuthorizedButton.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/AuthorizedButton.ets @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2023 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. - */ - -@Component -export struct AuthorizedButton { - private title: Resource = $r('app.string.EntryAbility_label'); - @Link image: Resource; - @Link backColor: Resource; - @Link textColor: Resource; - - build() { - Row() { - Image(this.image) - .width(24) - .height(24) - .objectFit(ImageFit.Contain) - Text(this.title) - .fontSize(16) - .margin({ left: 5 }) - .fontColor(this.textColor) - } - .margin({ bottom: 10 }) - .width(92) - .height(40) - .justifyContent(FlexAlign.Center) - .alignItems(VerticalAlign.Center) - .borderRadius(20) - .backgroundColor(this.backColor) - } +/* + * Copyright (c) 2023 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. + */ + +@Component +export struct AuthorizedButton { + private title: Resource = $r('app.string.EntryAbility_label'); + @Link image: Resource; + @Link backColor: Resource; + @Link textColor: Resource; + + build() { + Row() { + Image(this.image) + .width(24) + .height(24) + .objectFit(ImageFit.Contain) + Text(this.title) + .fontSize(16) + .margin({ left: 5 }) + .fontColor(this.textColor) + } + .margin({ bottom: 10 }) + .width(92) + .height(40) + .justifyContent(FlexAlign.Center) + .alignItems(VerticalAlign.Center) + .borderRadius(20) + .backgroundColor(this.backColor) + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/CopyButton.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/CopyButton.ets index ec77200aa391e5172214bd7b1b61578f914356fb..1463e8bd32493eabb44484322a59e96db2b6b5f4 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/CopyButton.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/CopyButton.ets @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2023 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 pasteboard from '@ohos.pasteboard'; -import promptAction from '@ohos.promptAction'; -import { AuthorizedButton } from './AuthorizedButton'; -import Logger from "../../utils/Logger"; - -@Component -export struct CopyButton { - @Link copyContent: string; - @State copyButtonText: Resource = $r('app.string.Copy'); - @StorageLink('copyButtonFocused') copyButtonFocused: boolean = true; - @State imageFocused: Resource = $r('app.media.copy'); - @State backColorFocused: Resource = $r('app.color.button_default_bg_color'); - @State textColorFocused: Resource = $r('app.color.background_shallow_grey'); - @State imageNormal: Resource = $r('app.media.copy1'); - @State backColorNormal: Resource = $r('app.color.button_default_text_color'); - @State textColorNormal: Resource = $r('app.color.button_default_bg_color1'); - - promptAction(message: string | Resource) { - try { - promptAction.showToast({ - message: message, - duration: 3000, - }); - } catch (error) { - Logger.error(`showToast args error code is ${error.code}, message is ${error.message}`); - } - } - - build() { - Column() { - Row() { - if (this.copyButtonFocused) { - AuthorizedButton({ - title: this.copyButtonText, - image: $imageFocused, - backColor: $backColorFocused, - textColor: $textColorFocused, - }) - } else { - AuthorizedButton({ - title: this.copyButtonText, - image: $imageNormal, - backColor: $backColorNormal, - textColor: $textColorNormal, - }) - } - } - .id('copyButton') - .onClick(() => { - this.copyButtonFocused = true; - let systemPasteboard = pasteboard.getSystemPasteboard(); - let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, this.copyContent); - systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.setData(pasteData).then(async () => { - this.promptAction($r('app.string.Copy_succeed')); - Logger.info('Succeeded in setting PasteData.'); - }); - }) - } - } +/* + * Copyright (c) 2023 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 pasteboard from '@ohos.pasteboard'; +import promptAction from '@ohos.promptAction'; +import { AuthorizedButton } from './AuthorizedButton'; +import Logger from "../../utils/Logger"; + +@Component +export struct CopyButton { + @Link copyContent: string; + @State copyButtonText: Resource = $r('app.string.Copy'); + @StorageLink('copyButtonFocused') copyButtonFocused: boolean = true; + @State imageFocused: Resource = $r('app.media.copy'); + @State backColorFocused: Resource = $r('app.color.button_default_bg_color'); + @State textColorFocused: Resource = $r('app.color.background_shallow_grey'); + @State imageNormal: Resource = $r('app.media.copy1'); + @State backColorNormal: Resource = $r('app.color.button_default_text_color'); + @State textColorNormal: Resource = $r('app.color.button_default_bg_color1'); + + promptAction(message: string | Resource) { + try { + promptAction.showToast({ + message: message, + duration: 3000, + }); + } catch (error) { + Logger.error(`showToast args error code is ${error.code}, message is ${error.message}`); + } + } + + build() { + Column() { + Row() { + if (this.copyButtonFocused) { + AuthorizedButton({ + title: this.copyButtonText, + image: $imageFocused, + backColor: $backColorFocused, + textColor: $textColorFocused, + }) + } else { + AuthorizedButton({ + title: this.copyButtonText, + image: $imageNormal, + backColor: $backColorNormal, + textColor: $textColorNormal, + }) + } + } + .id('copyButton') + .onClick(() => { + this.copyButtonFocused = true; + let systemPasteboard = pasteboard.getSystemPasteboard(); + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, this.copyContent); + systemPasteboard = pasteboard.getSystemPasteboard(); + systemPasteboard.setData(pasteData).then(async () => { + this.promptAction($r('app.string.Copy_succeed')); + Logger.info('Succeeded in setting PasteData.'); + }); + }) + } + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/LocationButton.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/LocationButton.ets index b80512a814a99513d2634e1e01696913edb1accb..8de65ed63acca3deea8bb31b0c9742e98f8fcec9 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/LocationButton.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/LocationButton.ets @@ -1,109 +1,109 @@ -/* - * Copyright (c) 2023 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 { BusinessError } from '@ohos.base'; -import common from '@ohos.app.ability.common'; -import geoLocationManager from '@ohos.geoLocationManager'; -import promptAction from '@ohos.promptAction'; -import Logger from '../../utils/Logger'; - -let context: common.Context; - -@Component -export struct SecLocationButton { - @State message: string = ''; - @Link location: string; - - @State textTitle: string = ''; - @State textValue: string = ''; - @State backColor: Resource = $r('app.color.button_default_bg_color'); - @State textColor: Resource = $r('app.color.start_window_background'); - @State image: Resource = $r('app.media.position'); - - aboutToDisappear() { - try { - context.resourceManager.getStringByName("User_authorized").then(value => { - this.textTitle = value; - }).catch ((error: string) => { - Logger.info('promise, getCurrentLocation: error=' + error); - }); - } catch (error) { - let e: BusinessError = error as BusinessError; - Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); - } - try { - context.resourceManager.getStringByName("Loading_positioning").then(value => { - this.textValue = value; - }).catch ((error: string) => { - Logger.info('promise, getCurrentLocation: error=' + JSON.stringify(error)); - }); - } catch (error) { - let e: BusinessError = error as BusinessError; - Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); - } - } - - onCancel() { - Logger.info('Callback when the first button is clicked'); - } - - getLocation(): void { - let requestInfo: Record = { - 'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, - 'scenario': geoLocationManager.LocationRequestScenario.UNSET, - 'maxAccuracy': 0, - }; - try { - // 得到当前定位信息经纬度 - geoLocationManager.getCurrentLocation(requestInfo).then((result) => { - Logger.info('current location: ' + JSON.stringify(result)); - this.location = JSON.stringify(result); - }).catch ((error: string) => { - this.promptAction(JSON.stringify(error)); - Logger.info('promise, getCurrentLocation: error=' + JSON.stringify(error)); - }); - } catch (error) { - this.promptAction(JSON.stringify(error.message)); - let e: BusinessError = error as BusinessError; - Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); - } - } - - promptAction( message : string ) { - this.message = message; - try { - promptAction.showToast({ - message: message, - duration: 60000, - }); - } catch (error) { - let e: BusinessError = error as BusinessError; - Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); - } - } - - build() { - Row() { - LocationButton() - .onClick((event: ClickEvent, result: LocationButtonOnClickResult) => { - if(result == LocationButtonOnClickResult.SUCCESS){ - this.getLocation(); - } - Logger.error('SecLocationButton onClick result ' + result); - }) - } - .id('locationButton') - } -} +/* + * Copyright (c) 2023 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 { BusinessError } from '@ohos.base'; +import common from '@ohos.app.ability.common'; +import geoLocationManager from '@ohos.geoLocationManager'; +import promptAction from '@ohos.promptAction'; +import Logger from '../../utils/Logger'; + +let context: common.Context; + +@Component +export struct SecLocationButton { + @State message: string = ''; + @Link location: string; + + @State textTitle: string = ''; + @State textValue: string = ''; + @State backColor: Resource = $r('app.color.button_default_bg_color'); + @State textColor: Resource = $r('app.color.start_window_background'); + @State image: Resource = $r('app.media.position'); + + aboutToDisappear() { + try { + context.resourceManager.getStringByName("User_authorized").then(value => { + this.textTitle = value; + }).catch ((error: string) => { + Logger.info('promise, getCurrentLocation: error=' + error); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); + } + try { + context.resourceManager.getStringByName("Loading_positioning").then(value => { + this.textValue = value; + }).catch ((error: string) => { + Logger.info('promise, getCurrentLocation: error=' + JSON.stringify(error)); + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); + } + } + + onCancel() { + Logger.info('Callback when the first button is clicked'); + } + + getLocation(): void { + let requestInfo: Record = { + 'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, + 'scenario': geoLocationManager.LocationRequestScenario.UNSET, + 'maxAccuracy': 0, + }; + try { + // 得到当前定位信息经纬度 + geoLocationManager.getCurrentLocation(requestInfo).then((result) => { + Logger.info('current location: ' + JSON.stringify(result)); + this.location = JSON.stringify(result); + }).catch ((error: string) => { + this.promptAction(JSON.stringify(error)); + Logger.info('promise, getCurrentLocation: error=' + JSON.stringify(error)); + }); + } catch (error) { + this.promptAction(JSON.stringify(error.message)); + let e: BusinessError = error as BusinessError; + Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); + } + } + + promptAction( message : string ) { + this.message = message; + try { + promptAction.showToast({ + message: message, + duration: 60000, + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); + } + } + + build() { + Row() { + LocationButton() + .onClick((event: ClickEvent, result: LocationButtonOnClickResult) => { + if(result == LocationButtonOnClickResult.SUCCESS){ + this.getLocation(); + } + Logger.error('SecLocationButton onClick result ' + result); + }) + } + .id('locationButton') + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/PasteButton.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/PasteButton.ets index 77c51271f7d306df01f603509d3c62f650b1d98f..010a797d20ed791d4a82bc0827011fee834eeefb 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/PasteButton.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/PasteButton.ets @@ -1,87 +1,87 @@ -/* - * Copyright (c) 2023 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 { BusinessError } from '@ohos.base'; -import pasteboard from '@ohos.pasteboard'; -import promptAction from '@ohos.promptAction'; -import Logger from '../../utils/Logger'; - -@Component -export struct SecPasteButton { - @Link pasteContent: string; - @StorageLink('copyButtonFocused') copyButtonFocused: boolean = true; - @State imageFocused: Resource = $r('app.media.paste1'); - @State backColorFocused: Resource = $r('app.color.button_default_bg_color1'); - @State textColorFocused: Resource = $r('app.color.button_default_bg_color'); - @State imageNormal: Resource = $r('app.media.paste'); - @State backColorNormal: Resource = $r('app.color.button_default_bg_color1'); - @State textColorNormal: Resource = $r('app.color.button_default_text_color'); - - pastToMessage() { - let systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.getData().then((pasteData) => { - let primaryText = pasteData.getPrimaryText(); - this.pasteContent = primaryText; - if (!primaryText) { - this.promptAction('Empty'); - } - this.promptAction($r('app.string.Paste_succeed')); - Logger.error('Succeed to get PasteData. primaryText' + primaryText); - }).catch ((error: string) => { - this.promptAction(error); - Logger.info('promise, getCurrentLocation: error=' + JSON.stringify(error)); - }); - } - - promptAction(message: string | Resource) { - try { - promptAction.showToast({ - message: message, - duration: 3000, - }); - } catch (error) { - let e: BusinessError = error as BusinessError; - Logger.error(`showToast args error code is ${e.code}, message is ${e.message}`); - } - } - - build() { - Column() { - Row() { - if (!this.copyButtonFocused) { - PasteButton({ - icon:PasteIconStyle.LINES, text:PasteDescription.PASTE, buttonType:ButtonType.Capsule - }) - .onClick(() => { - this.copyButtonFocused = false; - this.pastToMessage(); - }) - .backgroundColor(this.backColorFocused) - .fontColor(this.textColorFocused) - } else { - PasteButton({ - icon:PasteIconStyle.LINES, text:PasteDescription.PASTE, buttonType:ButtonType.Capsule - }) - .onClick(() => { - this.copyButtonFocused = false; - this.pastToMessage(); - }) - .backgroundColor(this.backColorNormal) - .fontColor(this.textColorNormal) - } - } - } - } -} +/* + * Copyright (c) 2023 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 { BusinessError } from '@ohos.base'; +import pasteboard from '@ohos.pasteboard'; +import promptAction from '@ohos.promptAction'; +import Logger from '../../utils/Logger'; + +@Component +export struct SecPasteButton { + @Link pasteContent: string; + @StorageLink('copyButtonFocused') copyButtonFocused: boolean = true; + @State imageFocused: Resource = $r('app.media.paste1'); + @State backColorFocused: Resource = $r('app.color.button_default_bg_color1'); + @State textColorFocused: Resource = $r('app.color.button_default_bg_color'); + @State imageNormal: Resource = $r('app.media.paste'); + @State backColorNormal: Resource = $r('app.color.button_default_bg_color1'); + @State textColorNormal: Resource = $r('app.color.button_default_text_color'); + + pastToMessage() { + let systemPasteboard = pasteboard.getSystemPasteboard(); + systemPasteboard.getData().then((pasteData) => { + let primaryText = pasteData.getPrimaryText(); + this.pasteContent = primaryText; + if (!primaryText) { + this.promptAction('Empty'); + } + this.promptAction($r('app.string.Paste_succeed')); + Logger.error('Succeed to get PasteData. primaryText' + primaryText); + }).catch ((error: string) => { + this.promptAction(error); + Logger.info('promise, getCurrentLocation: error=' + JSON.stringify(error)); + }); + } + + promptAction(message: string | Resource) { + try { + promptAction.showToast({ + message: message, + duration: 3000, + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + Logger.error(`showToast args error code is ${e.code}, message is ${e.message}`); + } + } + + build() { + Column() { + Row() { + if (!this.copyButtonFocused) { + PasteButton({ + icon:PasteIconStyle.LINES, text:PasteDescription.PASTE, buttonType:ButtonType.Capsule + }) + .onClick(() => { + this.copyButtonFocused = false; + this.pastToMessage(); + }) + .backgroundColor(this.backColorFocused) + .fontColor(this.textColorFocused) + } else { + PasteButton({ + icon:PasteIconStyle.LINES, text:PasteDescription.PASTE, buttonType:ButtonType.Capsule + }) + .onClick(() => { + this.copyButtonFocused = false; + this.pastToMessage(); + }) + .backgroundColor(this.backColorNormal) + .fontColor(this.textColorNormal) + } + } + } + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/SaveButton.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/SaveButton.ets index 024e7fc0256d6768551c2ed17cb80a3c9d1b1287..c1700c8e3b228cce5a2d4cb3c17ea678c7bec9ab 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/SaveButton.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/common/Component/SaveButton.ets @@ -1,88 +1,88 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import fs from '@ohos.file.fs'; -import photoAccessHelper from '@ohos.file.photoAccessHelper'; -import promptAction from '@ohos.promptAction'; -import Logger from '../../utils/Logger'; -import dataSharePredicates from '@ohos.data.dataSharePredicates'; - - -@Component -export struct SecSaveButton { - @State backColor: Resource = $r('app.color.button_default_bg_color1'); - @State textColor: Resource = $r('app.color.button_default_bg_color'); - @State image: Resource = $r('app.media.save'); - @Link saveImage: Resource; - private screenDensity: number = 0; - - promptAction(message: string | Resource) { - try { - promptAction.showToast({ - message: message, - duration: 6000, - }); - } catch (error) { - Logger.error(`showToast args error code is ${error.code}, message is ${error.message}`); - } - } - - async saveMedia() { - try { - const context = getContext(this); - // 得到图片内容 - try { - context.resourceManager.getMediaContent($r('app.media.banner').id, async (error, value) => { - if (error != null) { - Logger.error("error is " + error); - } else { - let media = value.buffer; - let helper = photoAccessHelper.getPhotoAccessHelper(context); - let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'png'); - // 通过uri打开媒体库文件 - let file = await fs.open(uri, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - Logger.info('openFile success, fd: ' + file.fd); - // 写到媒体库文件中 - await fs.write(file.fd, media); - await fs.close(file.fd); - this.promptAction($r('app.string.Save_succeed')); - } - }); - } catch (error) { - Logger.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); - } - - } catch (err) { - this.promptAction($r('app.string.Save_failed')); - Logger.error(`promiseerror code: ${err.code}, message: ${err.message}.`); - } - } - build() { - Column() { - SaveButton() - .onClick(async (event, result) => { - if (result === SaveButtonOnClickResult.SUCCESS) { - Logger.info("SUCCESS"); - this.saveMedia(); - } - if(result === SaveButtonOnClickResult.TEMPORARY_AUTHORIZATION_FAILED){ - Logger.info("TEMPORARY_AUTHORIZATION_FAILED"); - } - }) - } - .id('saveButton') - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import fs from '@ohos.file.fs'; +import photoAccessHelper from '@ohos.file.photoAccessHelper'; +import promptAction from '@ohos.promptAction'; +import Logger from '../../utils/Logger'; +import dataSharePredicates from '@ohos.data.dataSharePredicates'; + + +@Component +export struct SecSaveButton { + @State backColor: Resource = $r('app.color.button_default_bg_color1'); + @State textColor: Resource = $r('app.color.button_default_bg_color'); + @State image: Resource = $r('app.media.save'); + @Link saveImage: Resource; + private screenDensity: number = 0; + + promptAction(message: string | Resource) { + try { + promptAction.showToast({ + message: message, + duration: 6000, + }); + } catch (error) { + Logger.error(`showToast args error code is ${error.code}, message is ${error.message}`); + } + } + + async saveMedia() { + try { + const context = getContext(this); + // 得到图片内容 + try { + context.resourceManager.getMediaContent($r('app.media.banner').id, async (error, value) => { + if (error != null) { + Logger.error("error is " + error); + } else { + let media = value.buffer; + let helper = photoAccessHelper.getPhotoAccessHelper(context); + let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'png'); + // 通过uri打开媒体库文件 + let file = await fs.open(uri, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + Logger.info('openFile success, fd: ' + file.fd); + // 写到媒体库文件中 + await fs.write(file.fd, media); + await fs.close(file.fd); + this.promptAction($r('app.string.Save_succeed')); + } + }); + } catch (error) { + Logger.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); + } + + } catch (err) { + this.promptAction($r('app.string.Save_failed')); + Logger.error(`promiseerror code: ${err.code}, message: ${err.message}.`); + } + } + build() { + Column() { + SaveButton() + .onClick(async (event, result) => { + if (result === SaveButtonOnClickResult.SUCCESS) { + Logger.info("SUCCESS"); + this.saveMedia(); + } + if(result === SaveButtonOnClickResult.TEMPORARY_AUTHORIZATION_FAILED){ + Logger.info("TEMPORARY_AUTHORIZATION_FAILED"); + } + }) + } + .id('saveButton') + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/entryability/EntryAbility.ts index 5f07b82124ad3bdceb24b9e3c83a60b4da3fefd5..46e7640d1a31553a9e3f662b2a40ceaf3643e0bb 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import window from '@ohos.window'; -import Logger from '../utils/Logger'; - -export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { - Logger.info('testTag', '%{public}s', 'Ability onCreate'); - } - - onDestroy() { - Logger.info('testTag', '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - - // Main window is created, set main page for this ability - Logger.info('testTag', '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error('testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - - Logger.info('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info('testTag', '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info('testTag', '%{public}s', 'Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info('testTag', '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import Logger from '../utils/Logger'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + Logger.info('testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + Logger.info('testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + + // Main window is created, set main page for this ability + Logger.info('testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error('testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + + Logger.info('testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info('testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info('testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info('testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Location.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Location.ets index 1b3f3666d4094309c87dba4582f182abde9567a3..6adfa96eb2c903322e806e68566a1d79499d99f5 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Location.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Location.ets @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; -import { SecLocationButton } from '../../common/Component/LocationButton'; -import { TitleBar } from '../../common/Component/TitleBar'; -import { IntroductionTitle } from '../../common/Component/IntroductionTitle'; - -@Extend(Column) function backgroundStyle() { - .size({ width: '95%', height: 139 }) - .margin({ top: 5 }) - .padding(12) - .borderRadius(24) - .alignItems(HorizontalAlign.Start) - .backgroundColor(Color.White) -} - -@Entry -@Component -struct Location { - @State location: string = ''; - - build() { - Column() { - TitleBar({ title: $r('app.string.EntryAbility_label') }) - .id('backBtn') - .onClick(() => { - router.back(); - }) - IntroductionTitle({ introduction: $r('app.string.Locate_information') }) - Column() { - Text(this.location ? this.location : $r('app.string.Get_current_positioning_information')) - } - .backgroundStyle() - - Column() { - SecLocationButton({ - location: $location - }) - } - .layoutWeight(1) - .padding(30) - .justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2023 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 router from '@ohos.router'; +import { SecLocationButton } from '../../common/Component/LocationButton'; +import { TitleBar } from '../../common/Component/TitleBar'; +import { IntroductionTitle } from '../../common/Component/IntroductionTitle'; + +@Extend(Column) function backgroundStyle() { + .size({ width: '95%', height: 139 }) + .margin({ top: 5 }) + .padding(12) + .borderRadius(24) + .alignItems(HorizontalAlign.Start) + .backgroundColor(Color.White) +} + +@Entry +@Component +struct Location { + @State location: string = ''; + + build() { + Column() { + TitleBar({ title: $r('app.string.EntryAbility_label') }) + .id('backBtn') + .onClick(() => { + router.back(); + }) + IntroductionTitle({ introduction: $r('app.string.Locate_information') }) + Column() { + Text(this.location ? this.location : $r('app.string.Get_current_positioning_information')) + } + .backgroundStyle() + + Column() { + SecLocationButton({ + location: $location + }) + } + .layoutWeight(1) + .padding(30) + .justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Paste.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Paste.ets index ced8fe87a445a67bc7a64c043f72e92f1ea867d1..970a0601ca9be3f7ea713a695cf28c640acd921a 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Paste.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Paste.ets @@ -1,117 +1,117 @@ -/* - * Copyright (c) 2023 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 { BusinessError } from '@ohos.base'; -import common from '@ohos.app.ability.common'; -import Logger from '../../utils/Logger'; -import router from '@ohos.router'; -import promptAction from '@ohos.promptAction'; -import { SecPasteButton } from '../../common/Component/PasteButton'; -import { CopyButton } from '../../common/Component/CopyButton'; -import { TitleBar } from '../../common/Component/TitleBar'; -import { IntroductionTitle } from '../../common/Component/IntroductionTitle'; - -@Extend(Column) function backgroundStyle() { - .size({ width: '95%', height: 139 }) - .margin({ top: 5 }) - .padding(12) - .borderRadius(24) - .alignItems(HorizontalAlign.Start) - .backgroundColor(Color.White) -} - -@Entry -@Component -struct Paste { - @State pasteContent: string = ''; - @State copyContent: string = ''; - - promptAction(message: string) { - try { - promptAction.showToast({ - message: message, - duration: 2000, - }); - } catch (error) { - Logger.error(`showToast args error code is ${error.code}, message is ${error.message}`); - } - ; - } - - aboutToAppear() { - let context: common.Context = getContext(this); - try { - context.resourceManager.getStringValue($r('app.string.Happy_every_day').id, (error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - this.copyContent = value; - } - }); - } catch (error) { - let e: BusinessError = error as BusinessError; - Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); - } - } - - build() { - Column() { - TitleBar({ title: $r('app.string.EntryAbility_label') }) - .id('backBtn') - .onClick(() => { - router.back(); - }) - IntroductionTitle({ introduction: $r('app.string.Copy_content') }) - Column() { - TextInput({ text: this.copyContent }) - .backgroundColor(Color.White) - .fontColor(Color.Black) - .enableKeyboardOnFocus(false) - .onChange((data => { - this.copyContent = data; - })) - } - .padding({ top: 5 }) - .size({ width: '95%', height: 139 }) - .margin({ top: 5 }) - .borderRadius(24) - .alignItems(HorizontalAlign.Start) - .backgroundColor(Color.White) - - IntroductionTitle({ introduction: $r('app.string.Paste_content') }) - Column() { - Text(this.pasteContent) - .fontColor(Color.Black) - } - .backgroundStyle() - - Column() { - CopyButton({ - copyContent: $copyContent - }) - SecPasteButton({ - pasteContent: $pasteContent, - }) - } - .layoutWeight(1) - .padding(30) - .justifyContent(FlexAlign.End) - - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } -} +/* + * Copyright (c) 2023 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 { BusinessError } from '@ohos.base'; +import common from '@ohos.app.ability.common'; +import Logger from '../../utils/Logger'; +import router from '@ohos.router'; +import promptAction from '@ohos.promptAction'; +import { SecPasteButton } from '../../common/Component/PasteButton'; +import { CopyButton } from '../../common/Component/CopyButton'; +import { TitleBar } from '../../common/Component/TitleBar'; +import { IntroductionTitle } from '../../common/Component/IntroductionTitle'; + +@Extend(Column) function backgroundStyle() { + .size({ width: '95%', height: 139 }) + .margin({ top: 5 }) + .padding(12) + .borderRadius(24) + .alignItems(HorizontalAlign.Start) + .backgroundColor(Color.White) +} + +@Entry +@Component +struct Paste { + @State pasteContent: string = ''; + @State copyContent: string = ''; + + promptAction(message: string) { + try { + promptAction.showToast({ + message: message, + duration: 2000, + }); + } catch (error) { + Logger.error(`showToast args error code is ${error.code}, message is ${error.message}`); + } + ; + } + + aboutToAppear() { + let context: common.Context = getContext(this); + try { + context.resourceManager.getStringValue($r('app.string.Happy_every_day').id, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + this.copyContent = value; + } + }); + } catch (error) { + let e: BusinessError = error as BusinessError; + Logger.error(`promise getStringByName failed, error code: ${e.code}, message: ${e.message}.`); + } + } + + build() { + Column() { + TitleBar({ title: $r('app.string.EntryAbility_label') }) + .id('backBtn') + .onClick(() => { + router.back(); + }) + IntroductionTitle({ introduction: $r('app.string.Copy_content') }) + Column() { + TextInput({ text: this.copyContent }) + .backgroundColor(Color.White) + .fontColor(Color.Black) + .enableKeyboardOnFocus(false) + .onChange((data => { + this.copyContent = data; + })) + } + .padding({ top: 5 }) + .size({ width: '95%', height: 139 }) + .margin({ top: 5 }) + .borderRadius(24) + .alignItems(HorizontalAlign.Start) + .backgroundColor(Color.White) + + IntroductionTitle({ introduction: $r('app.string.Paste_content') }) + Column() { + Text(this.pasteContent) + .fontColor(Color.Black) + } + .backgroundStyle() + + Column() { + CopyButton({ + copyContent: $copyContent + }) + SecPasteButton({ + pasteContent: $pasteContent, + }) + } + .layoutWeight(1) + .padding(30) + .justifyContent(FlexAlign.End) + + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Save.ets b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Save.ets index 1a7bf44263f6bda36d8d36521950026db3655138..d4fa75b8869d6bfabb640706d4d63215de2cc42e 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Save.ets +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/securitycomponent/pages/Save.ets @@ -1,60 +1,60 @@ -/* - * Copyright (c) 2023 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 router from '@ohos.router'; -import { SecSaveButton } from '../../common/Component/SaveButton'; -import { TitleBar } from '../../common/Component/TitleBar'; - -@Extend(Column) function backgroundStyle() { - .size({ width: '95%', height: 139 }) - .margin({ top: 5 }) - .padding(12) - .borderRadius(24) - .alignItems(HorizontalAlign.Start) - .backgroundColor(Color.White) -} - -@Entry -@Component -struct Save { - @State saveImage: Resource = $r('app.media.banner'); - - build() { - Column() { - TitleBar({ title: $r('app.string.EntryAbility_label') }) - .id('backBtn') - .onClick(() => { - router.back() - }) - Column() { - Image($r('app.media.banner')) - .objectFit(ImageFit.Fill) - } - .backgroundStyle() - - Column() { - SecSaveButton({ - saveImage: $saveImage - }) - } - .layoutWeight(1) - .padding(30) - .justifyContent(FlexAlign.End) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2023 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 router from '@ohos.router'; +import { SecSaveButton } from '../../common/Component/SaveButton'; +import { TitleBar } from '../../common/Component/TitleBar'; + +@Extend(Column) function backgroundStyle() { + .size({ width: '95%', height: 139 }) + .margin({ top: 5 }) + .padding(12) + .borderRadius(24) + .alignItems(HorizontalAlign.Start) + .backgroundColor(Color.White) +} + +@Entry +@Component +struct Save { + @State saveImage: Resource = $r('app.media.banner'); + + build() { + Column() { + TitleBar({ title: $r('app.string.EntryAbility_label') }) + .id('backBtn') + .onClick(() => { + router.back() + }) + Column() { + Image($r('app.media.banner')) + .objectFit(ImageFit.Fill) + } + .backgroundStyle() + + Column() { + SecSaveButton({ + saveImage: $saveImage + }) + } + .layoutWeight(1) + .padding(30) + .justifyContent(FlexAlign.End) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/utils/Logger.ts b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/utils/Logger.ts index 098b569cb7edc586788ba576f1318dbfbe954132..06833b8ecf27aa374e16cdccfa678d9b0e645da5 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/utils/Logger.ts +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/ets/utils/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_AuthorizedButton]'); \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/module.json5 b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/module.json5 index b25438604c0dcb8a22210a1770b5858098780c8a..8c60c22573d3415771710f992328165544d1f011 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/module.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "srcEntrance": "./ets/entryability/EntryAbility.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ] - } +/* + * Copyright (c) 2023 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", + "srcEntrance": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/resources/base/element/color.json b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/resources/base/element/color.json index ce6a3fe6411a327fd419bb164312eac4bf8cff7f..9bbf5335514bf042fd383934ee8b7d835179c52d 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/main/resources/base/element/color.json @@ -1,32 +1,32 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "bottom_title_divider", - "value": "#99838388" - }, - { - "name": "font_color_shallow", - "value": "#99000000" - }, - { - "name": "background_shallow_grey", - "value": "#F1F3F5" - }, - { - "name": "button_default_bg_color", - "value": "#007DFF" - }, - { - "name": "button_default_bg_color1", - "value": "#eceef0" - }, - { - "name": "button_default_text_color", - "value": "#FF93BFEC" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "bottom_title_divider", + "value": "#99838388" + }, + { + "name": "font_color_shallow", + "value": "#99000000" + }, + { + "name": "background_shallow_grey", + "value": "#F1F3F5" + }, + { + "name": "button_default_bg_color", + "value": "#007DFF" + }, + { + "name": "button_default_bg_color1", + "value": "#eceef0" + }, + { + "name": "button_default_text_color", + "value": "#FF93BFEC" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/module.json5 b/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/module.json5 index 7402a585529f197d684e1c7237a7afe73d3bf045..f5906847dfb7fbdc7ad8925b88644dee7815e896 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/module.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/utils/Logger.ts b/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/utils/Logger.ts index 098b569cb7edc586788ba576f1318dbfbe954132..06833b8ecf27aa374e16cdccfa678d9b0e645da5 100644 --- a/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/utils/Logger.ts +++ b/code/SystemFeature/Security/AuthorizedButton/entry/src/ohosTest/utils/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xF811; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xF811; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Sample_AuthorizedButton]'); \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/hvigor/hvigor-config.json5 b/code/SystemFeature/Security/AuthorizedButton/hvigor/hvigor-config.json5 index ac737cf85f090c5de41b44bb39986e423bdc39fa..e75281b258e8cec776a34fd96a3c117c58afb9cb 100644 --- a/code/SystemFeature/Security/AuthorizedButton/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ -{ - "hvigorVersion": "3.0.2", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.2" - } +{ + "hvigorVersion": "3.0.2", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.2" + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/AuthorizedButton/oh-package.json5 b/code/SystemFeature/Security/AuthorizedButton/oh-package.json5 index 30f5d350f78cdfb50b17d03c53e477b90bb181b9..6819b579ffac69caa672110ff9fe2246567b4a86 100644 --- a/code/SystemFeature/Security/AuthorizedButton/oh-package.json5 +++ b/code/SystemFeature/Security/AuthorizedButton/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "authorizedbutton", - "description": "example description", - "repository": {}, - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "authorizedbutton", + "description": "example description", + "repository": {}, + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/Security/DLP/AppScope/app.json5 b/code/SystemFeature/Security/DLP/AppScope/app.json5 index 8a83045ec935a460570bec11c09eb3a6d9b8087c..80f737f450954cecd36c2a30d47860ed1636f7bf 100644 --- a/code/SystemFeature/Security/DLP/AppScope/app.json5 +++ b/code/SystemFeature/Security/DLP/AppScope/app.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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.dlp", - "vendor": "samples", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2023 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.dlp", + "vendor": "samples", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/Security/DLP/AppScope/resources/base/element/string.json b/code/SystemFeature/Security/DLP/AppScope/resources/base/element/string.json index 9495f57b0c75813fa7d2f50144b4243e11f32c8e..3db2959d25cb1823737aef9d2b1db7ed3fadeb49 100644 --- a/code/SystemFeature/Security/DLP/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/Security/DLP/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "DLP" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "DLP" + } + ] +} diff --git a/code/SystemFeature/Security/DLP/README_zh.md b/code/SystemFeature/Security/DLP/README_zh.md index 82e8329ba54648521c24f3a48414e8fa96af5655..f3412e24251eef4fd1a0d938a5cf13d320f05c79 100644 --- a/code/SystemFeature/Security/DLP/README_zh.md +++ b/code/SystemFeature/Security/DLP/README_zh.md @@ -1,77 +1,77 @@ -# DLP - -### 介绍 - -本示例是一个安全类App,使用[@ohos.dlpPermission](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-data-protection-kit/js-apis-dlppermission-sys.md) 接口展示了在eTS中普通文件加密受限的过程。 - -### 效果预览 -| Index | Encryption | Encryptied | FileEdit | -|-----------------------------------------|-----------------------------------------------|---------------------------------------------|----------------------------------------------------| -| ![Index](screenshots/devices/Index.jpeg) | ![Encryption](screenshots/devices/Encryption.jpeg) | ![Encryptied](screenshots/devices/Encrypted.jpeg) | ![FileEdit](screenshots/devices/FileEditPage.jpeg) | - -使用说明: -1. 启动应用后点击“**+**”按钮可以添加一个普通文件; -2. 长按点击加密按钮,出现加密权限弹窗,选择需要设置的权限并点击确定; -3. 点击加密文件,跳转到文本编辑应用,如果设置的权限是只读权限,页面置灰,不可编辑。 -4. 长按点击删除按钮,删除文件; - -### 工程目录 -``` -entry/src/main/ets/ -|---component -| |---CustomDialog.ets // 权限弹窗 -|---feature -| |---DlpManager.ets // Dlp管理 -| |---FileManager.ets // 文件管理 -| |---PreferencesManager.ets // 持久化存储 -|---pages -| |---Index.ets // 首页 -|---util -| |---Logger.ts // 日志 -| |---ResourceUtils.ets // 资源转换 -``` -### 具体实现 - -+ 文件的添加和文件列表的获取分别在Index和MediaFileUri中,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) 和 [FileManager.ets](entry/src/main/ets/feature/FileManager.ets): - + 文件的添加:首先通过[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md)接口的DocumentSaveOptions()方法自定一个参数,然后通过new picker.DocumentViewPicker()方法拉起文件管理应用去新建一个普通文件。 - + 文件列表的获取:首先使用[@ohos.file.fileAccess](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileAccess-sys.md) 接口的createFileAccessHelper()方法来创建连接指定wants的helper对象,然后通过getRoots()方法来获取helper对象连接的文件管理服务类的设备根节点信息,并获取到目录url,最后通过getFileInfoFromUri()方法得到文件的信息。 -+ 文件的加密操作在DlpManager中,源码参考[DlpManager.ets](entry/src/main/ets/feature/DlpManager.ets): - + 加密操作:使用dlpPermission接口的generateDLPFile方法获得一个相关的操作型关系数据库RdbStore,将明文文件加密生成权限受控文件。 - -### 相关权限 - -允许文件管理类应用通过FAF框架访问公共数据文件:[ohos.permission.FILE_ACCESS_MANAGER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionfile_access_manager) - -允许应用调用storage manager服务中对空间统计以及卷信息的查询接口:[ohos.permission.STORAGE_MANAGER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionstorage_manager) - -允许查询应用的基本信息和其他敏感信息:[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged) - -允许对DLP文件进行权限配置和管理:[ohos.permission.ACCESS_DLP_FILE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccess_dlp_file) - -允许应用管理系统分布式帐号信息:[ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_distributed_accounts) - -允许应用管理系统本地帐号:[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_local_accounts) - -允许应用查询系统本地帐号信息:[ohos.permission.GET_LOCAL_ACCOUNTS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_local_accounts) - -### 依赖 - -需要依赖三方应用文本编辑FileEdit的[hap](screenshots/haps)。 - -### 约束与限制 - -1. 本示例仅支持标准系统上运行; -2. 本示例仅支持API10版本SDK,SDK版本号(4.0.10.10), 镜像版本号(4.0 Release)。 -3. 本示例需要使用DevEco Studio 4.0 Beta2 (Build Version: 4.0.0.400, built on August 2, 2023)才可编译运行; -4. 本示例需要使用@ohos.dlpPermission系统权限的系统接口。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)。 - -### 下载 - -如需单独下载本工程,执行如下命令: -``` -git init -git config core.sparsecheckout true -echo code/SystemFeature/Security/DLP/ > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master +# DLP + +### 介绍 + +本示例是一个安全类App,使用[@ohos.dlpPermission](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-data-protection-kit/js-apis-dlppermission-sys.md) 接口展示了在eTS中普通文件加密受限的过程。 + +### 效果预览 +| Index | Encryption | Encryptied | FileEdit | +|-----------------------------------------|-----------------------------------------------|---------------------------------------------|----------------------------------------------------| +| ![Index](screenshots/devices/Index.jpeg) | ![Encryption](screenshots/devices/Encryption.jpeg) | ![Encryptied](screenshots/devices/Encrypted.jpeg) | ![FileEdit](screenshots/devices/FileEditPage.jpeg) | + +使用说明: +1. 启动应用后点击“**+**”按钮可以添加一个普通文件; +2. 长按点击加密按钮,出现加密权限弹窗,选择需要设置的权限并点击确定; +3. 点击加密文件,跳转到文本编辑应用,如果设置的权限是只读权限,页面置灰,不可编辑。 +4. 长按点击删除按钮,删除文件; + +### 工程目录 +``` +entry/src/main/ets/ +|---component +| |---CustomDialog.ets // 权限弹窗 +|---feature +| |---DlpManager.ets // Dlp管理 +| |---FileManager.ets // 文件管理 +| |---PreferencesManager.ets // 持久化存储 +|---pages +| |---Index.ets // 首页 +|---util +| |---Logger.ts // 日志 +| |---ResourceUtils.ets // 资源转换 +``` +### 具体实现 + ++ 文件的添加和文件列表的获取分别在Index和MediaFileUri中,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets) 和 [FileManager.ets](entry/src/main/ets/feature/FileManager.ets): + + 文件的添加:首先通过[@ohos.file.picker](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-picker.md)接口的DocumentSaveOptions()方法自定一个参数,然后通过new picker.DocumentViewPicker()方法拉起文件管理应用去新建一个普通文件。 + + 文件列表的获取:首先使用[@ohos.file.fileAccess](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileAccess-sys.md) 接口的createFileAccessHelper()方法来创建连接指定wants的helper对象,然后通过getRoots()方法来获取helper对象连接的文件管理服务类的设备根节点信息,并获取到目录url,最后通过getFileInfoFromUri()方法得到文件的信息。 ++ 文件的加密操作在DlpManager中,源码参考[DlpManager.ets](entry/src/main/ets/feature/DlpManager.ets): + + 加密操作:使用dlpPermission接口的generateDLPFile方法获得一个相关的操作型关系数据库RdbStore,将明文文件加密生成权限受控文件。 + +### 相关权限 + +允许文件管理类应用通过FAF框架访问公共数据文件:[ohos.permission.FILE_ACCESS_MANAGER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionfile_access_manager) + +允许应用调用storage manager服务中对空间统计以及卷信息的查询接口:[ohos.permission.STORAGE_MANAGER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionstorage_manager) + +允许查询应用的基本信息和其他敏感信息:[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_bundle_info_privileged) + +允许对DLP文件进行权限配置和管理:[ohos.permission.ACCESS_DLP_FILE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionaccess_dlp_file) + +允许应用管理系统分布式帐号信息:[ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_distributed_accounts) + +允许应用管理系统本地帐号:[ohos.permission.MANAGE_LOCAL_ACCOUNTS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionmanage_local_accounts) + +允许应用查询系统本地帐号信息:[ohos.permission.GET_LOCAL_ACCOUNTS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_local_accounts) + +### 依赖 + +需要依赖三方应用文本编辑FileEdit的[hap](screenshots/haps)。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行; +2. 本示例仅支持API10版本SDK,SDK版本号(4.0.10.10), 镜像版本号(4.0 Release)。 +3. 本示例需要使用DevEco Studio 4.0 Beta2 (Build Version: 4.0.0.400, built on August 2, 2023)才可编译运行; +4. 本示例需要使用@ohos.dlpPermission系统权限的系统接口。使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)。 + +### 下载 + +如需单独下载本工程,执行如下命令: +``` +git init +git config core.sparsecheckout true +echo code/SystemFeature/Security/DLP/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master ``` \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/build-profile.json5 b/code/SystemFeature/Security/DLP/build-profile.json5 index 9f41ac1f363b7189ea1d02caf5de17aa6b24807c..d1a07a2849b3bc3bf6ba038c9081edf6548713cb 100644 --- a/code/SystemFeature/Security/DLP/build-profile.json5 +++ b/code/SystemFeature/Security/DLP/build-profile.json5 @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2023 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": 10, - "compatibleSdkVersion": 10, - "runtimeOS": "OpenHarmony" - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2023 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": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" + } + ], + "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/SystemFeature/Security/DLP/entry/build-profile.json5 b/code/SystemFeature/Security/DLP/entry/build-profile.json5 index 2eabd9fec317c1bfc530e2676f009dded401ee5d..8e1d0657b6e6528c2a83891933deafcb3dbb0a99 100644 --- a/code/SystemFeature/Security/DLP/entry/build-profile.json5 +++ b/code/SystemFeature/Security/DLP/entry/build-profile.json5 @@ -1,29 +1,29 @@ -/* - * Copyright (c) 2023 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": { - }, - "targets": [ - { - "name": "default", - "runtimeOS": "OpenHarmony" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "OpenHarmony" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/oh-package.json5 b/code/SystemFeature/Security/DLP/entry/oh-package.json5 index 4be95c59ce0dede7a66d6fcb2e3018c8011f838a..3fbe67bbf8193c883bab1ccea7be318bc3a65bdb 100644 --- a/code/SystemFeature/Security/DLP/entry/oh-package.json5 +++ b/code/SystemFeature/Security/DLP/entry/oh-package.json5 @@ -1,25 +1,25 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": {}, - "author": "", - "name": "entry", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": {}, + "author": "", + "name": "entry", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/component/CustomDialog.ets b/code/SystemFeature/Security/DLP/entry/src/main/ets/component/CustomDialog.ets index d73ecc27e1c347bd7e676d2a939d56a967e46b30..47064f888623962bef2ecbbec87873125b9a2756 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/component/CustomDialog.ets +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/component/CustomDialog.ets @@ -1,111 +1,111 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; -import promptAction from '@ohos.promptAction'; -import { BusinessError } from '@ohos.base'; -import { DlpManager, TestDlpFileInfo } from '../feature/DlpManager'; -import { MediaFileUri } from '../feature/FileManager'; -import Logger from '../util/Logger'; -import { getResourceString } from '../util/ResourceUtils'; - -let sourceUri: string = 'file://docs/storage/Users/currentUser'; -let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - -@CustomDialog -export struct CustomDialogExample { - @State dlpManager: DlpManager = new DlpManager(); - @State mediaFileUri: MediaFileUri = new MediaFileUri(); - // dlp文件信息 - @StorageLink('dlpFileInfos') dlpFileInfos: Array = []; - @Link currentPerssion: number; - @Link currentSelectedFileUri: string; - private controller: CustomDialogController = {} as CustomDialogController; - - // 弹窗函数 - promptPopup() { - Logger.info(`promptPopup start`); - try { - promptAction.showToast({ - message: $r('app.string.authorization_reminder'), - // 弹窗延迟时间 - duration: 2000 - }); - } catch (error) { - let message = (error as BusinessError).message; - let code = (error as BusinessError).code; - Logger.error(`showToast args error code is ${code}, message is ${message}`); - } - } - - build() { - Column() { - Text($r('app.string.encryption_protection')) - .fontSize(20) - .margin({ top: 10, bottom: 10 }) - .width('100%') - .textAlign(TextAlign.Start) - Text($r('app.string.authorization_description')) - .fontSize(18) - .width('100%') - .textAlign(TextAlign.Start) - Column() { - Row() { - Text($r('app.string.user_access_rights')).fontSize(18) - Select([ - { value: $r('app.string.read_only') }, { value: $r('app.string.edit_only') }]) - .selected(2) - .value(getResourceString(context, $r('app.string.authorization_reminder'))) - .font({ size: 16, weight: 500 }) - .fontColor('#182431') - .selectedOptionFont({ size: 16, weight: 400 }) - .optionFont({ size: 16, weight: 400 }) - .margin({ top: 20, bottom: 20, left: 6 }) - .onSelect((index: number) => { - this.currentPerssion = index; - }) - }.width('100%').justifyContent(FlexAlign.Start) - - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Button($r('app.string.cancel')) - .onClick(() => { - this.controller.close() - }).backgroundColor(0xffffff) - .fontColor(Color.Black) - Button($r('app.string.confirm')) - .onClick(async () => { - if (this.currentPerssion === -1) { - this.promptPopup(); - } else { - let displayName: string = Date.now().toString() + '.txt.dlp'; - let ciphertextFd: number = await this.mediaFileUri.createFile(sourceUri, displayName); - await this.dlpManager.genTestDlpFile(this.currentSelectedFileUri, ciphertextFd, displayName, this.currentPerssion, this.dlpFileInfos); - await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos); - await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos); - let time: number = new Date().getTime(); - // 切换用户 - await this.dlpManager.AccountLogin(`lisi${time}`); - this.controller.close(); - } - }) - .backgroundColor(0xffffff) - .fontColor(Color.Red) - }.margin({ bottom: 10 }) - } - }.width('100%') - .height('40%') - .padding(15) - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; +import promptAction from '@ohos.promptAction'; +import { BusinessError } from '@ohos.base'; +import { DlpManager, TestDlpFileInfo } from '../feature/DlpManager'; +import { MediaFileUri } from '../feature/FileManager'; +import Logger from '../util/Logger'; +import { getResourceString } from '../util/ResourceUtils'; + +let sourceUri: string = 'file://docs/storage/Users/currentUser'; +let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + +@CustomDialog +export struct CustomDialogExample { + @State dlpManager: DlpManager = new DlpManager(); + @State mediaFileUri: MediaFileUri = new MediaFileUri(); + // dlp文件信息 + @StorageLink('dlpFileInfos') dlpFileInfos: Array = []; + @Link currentPerssion: number; + @Link currentSelectedFileUri: string; + private controller: CustomDialogController = {} as CustomDialogController; + + // 弹窗函数 + promptPopup() { + Logger.info(`promptPopup start`); + try { + promptAction.showToast({ + message: $r('app.string.authorization_reminder'), + // 弹窗延迟时间 + duration: 2000 + }); + } catch (error) { + let message = (error as BusinessError).message; + let code = (error as BusinessError).code; + Logger.error(`showToast args error code is ${code}, message is ${message}`); + } + } + + build() { + Column() { + Text($r('app.string.encryption_protection')) + .fontSize(20) + .margin({ top: 10, bottom: 10 }) + .width('100%') + .textAlign(TextAlign.Start) + Text($r('app.string.authorization_description')) + .fontSize(18) + .width('100%') + .textAlign(TextAlign.Start) + Column() { + Row() { + Text($r('app.string.user_access_rights')).fontSize(18) + Select([ + { value: $r('app.string.read_only') }, { value: $r('app.string.edit_only') }]) + .selected(2) + .value(getResourceString(context, $r('app.string.authorization_reminder'))) + .font({ size: 16, weight: 500 }) + .fontColor('#182431') + .selectedOptionFont({ size: 16, weight: 400 }) + .optionFont({ size: 16, weight: 400 }) + .margin({ top: 20, bottom: 20, left: 6 }) + .onSelect((index: number) => { + this.currentPerssion = index; + }) + }.width('100%').justifyContent(FlexAlign.Start) + + Flex({ justifyContent: FlexAlign.SpaceAround }) { + Button($r('app.string.cancel')) + .onClick(() => { + this.controller.close() + }).backgroundColor(0xffffff) + .fontColor(Color.Black) + Button($r('app.string.confirm')) + .onClick(async () => { + if (this.currentPerssion === -1) { + this.promptPopup(); + } else { + let displayName: string = Date.now().toString() + '.txt.dlp'; + let ciphertextFd: number = await this.mediaFileUri.createFile(sourceUri, displayName); + await this.dlpManager.genTestDlpFile(this.currentSelectedFileUri, ciphertextFd, displayName, this.currentPerssion, this.dlpFileInfos); + await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos); + await this.mediaFileUri.getAllFiles(context, this.dlpFileInfos); + let time: number = new Date().getTime(); + // 切换用户 + await this.dlpManager.AccountLogin(`lisi${time}`); + this.controller.close(); + } + }) + .backgroundColor(0xffffff) + .fontColor(Color.Red) + }.margin({ bottom: 10 }) + } + }.width('100%') + .height('40%') + .padding(15) + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts b/code/SystemFeature/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts index 2d09298881e772d96de6de1892ea98e02e6d2f93..3682d26731764679311d683d9561d974eb2b92b5 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/entryability/EntryAbility.ts @@ -1,82 +1,82 @@ -/* - * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; -import hilog from '@ohos.hilog'; -import UIAbility from '@ohos.app.ability.UIAbility'; -import Want from '@ohos.app.ability.Want'; -import window from '@ohos.window'; -import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; -import type { Permissions } from '@ohos.abilityAccessCtrl'; -import Logger from '../util/Logger'; -import App from '@system.app'; - -class TestDlpFileInfo { - plaintextPath: string = ''; - ciphertextPath: string = ''; -} - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - let permissions: Array = [ - 'ohos.permission.FILE_ACCESS_MANAGER', - 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED', - 'ohos.permission.ACCESS_DLP_FILE', - "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS", - "ohos.permission.MANAGE_LOCAL_ACCOUNTS", - "ohos.permission.GET_LOCAL_ACCOUNTS", - "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS" - ] - let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); - atManager.requestPermissionsFromUser(this.context, permissions, (code, result) => { - Logger.debug('permissionRequest ' + JSON.stringify(code) + ' Result: ' + JSON.stringify(result)) - }) - PersistentStorage.persistProp('dlpFiles',''); - AppStorage.setOrCreate>('dlpFileInfos', []); - Logger.info('Ability onCreate'); - } - - onDestroy() { - Logger.info('Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - // Main window is created, set main page for this ability - Logger.info('Ability onWindowStageCreate'); - - windowStage.loadContent('pages/Index', (err, data) => { - if (err.code) { - Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); - return; - } - Logger.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); - }); - } - - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - Logger.info('Ability onWindowStageDestroy'); - } - - onForeground() { - // Ability has brought to foreground - Logger.info('Ability onForeground'); - } - - onBackground() { - // Ability has back to background - Logger.info('Ability onBackground'); - } -} +/* + * Copyright (c) 2023 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 from '@ohos.app.ability.AbilityConstant'; +import hilog from '@ohos.hilog'; +import UIAbility from '@ohos.app.ability.UIAbility'; +import Want from '@ohos.app.ability.Want'; +import window from '@ohos.window'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import type { Permissions } from '@ohos.abilityAccessCtrl'; +import Logger from '../util/Logger'; +import App from '@system.app'; + +class TestDlpFileInfo { + plaintextPath: string = ''; + ciphertextPath: string = ''; +} + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + let permissions: Array = [ + 'ohos.permission.FILE_ACCESS_MANAGER', + 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED', + 'ohos.permission.ACCESS_DLP_FILE', + "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS", + "ohos.permission.MANAGE_LOCAL_ACCOUNTS", + "ohos.permission.GET_LOCAL_ACCOUNTS", + "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS" + ] + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(this.context, permissions, (code, result) => { + Logger.debug('permissionRequest ' + JSON.stringify(code) + ' Result: ' + JSON.stringify(result)) + }) + PersistentStorage.persistProp('dlpFiles',''); + AppStorage.setOrCreate>('dlpFileInfos', []); + Logger.info('Ability onCreate'); + } + + onDestroy() { + Logger.info('Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + Logger.info('Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + Logger.error(`Failed to load the content. Cause: ${JSON.stringify(err)}`); + return; + } + Logger.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + Logger.info('Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + Logger.info('Ability onForeground'); + } + + onBackground() { + // Ability has back to background + Logger.info('Ability onBackground'); + } +} diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/DlpManager.ets b/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/DlpManager.ets index 52a4c548d932d1f74bedc78a1b15196e8f745aa3..0e70ed205dcf8cf73b9deef09e0a754636ecccd9 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/DlpManager.ets +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/DlpManager.ets @@ -1,238 +1,238 @@ -/* - * Copyright (c) 2023 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 dlpPermission from '@ohos.dlpPermission'; -import fs from '@ohos.file.fs'; -import account from '@ohos.account.distributedAccount' -import account_osAccount from '@ohos.account.osAccount'; -import Want from '@ohos.app.ability.Want'; -import { BusinessError } from '@ohos.base'; -import common from '@ohos.app.ability.common'; -import { PreferencesManager } from '../feature/PreferencesManager'; -import Logger from '../util/Logger'; - -const TAG: string = 'DlpManager'; -const SOURCEURI: string = 'file://docs/storage/Users/currentUser'; -let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; -let accountAbility = account.getDistributedAccountAbility(); -// 用户列表 -let userList: Array = [{ - 'authAccount': '123@ohos.com', - 'authAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, - 'dlpFileAccess': dlpPermission.DLPFileAccess.READ_ONLY, - // 授权到期时间戳 - 'permExpiryTime': 8888520175, -}, { - 'authAccount': '456@ohos.com', - 'authAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, - 'dlpFileAccess': dlpPermission.DLPFileAccess.FULL_CONTROL, - // 授权到期时间戳 - 'permExpiryTime': 8888520175, -}] - -// dlp信息类型 -export class TestDlpFileInfo { - plaintextPath: string = ''; - ciphertextPath: string = ''; -} - -// 用户信息类型 -interface UserInfo { - name: string, - id: string, - event: string, - nickname: string, - avatar: string -} - -export class DlpManager { - // linkFile文件名 - private linkFileName: string = ''; - // link地址文件名 - private linkFilePath: string = ''; - // dlp文件 - private dlpFile: dlpPermission.DLPFile = {} as dlpPermission.DLPFile; - // 沙箱包名 - private sandboxBundleName: string = 'com.example.fileEdit'; - private sandboxAbilityName: string = 'EntryAbility'; - // dlp文件的句柄 - private dlpFd: number = -1; - // 账号信息 - private accountInfo?: account_osAccount.OsAccountInfo; - // dlp文件路径地址 - private dlpFileUri: string = ''; - private preferencesManager: PreferencesManager = new PreferencesManager(); - - constructor() { - } - - // 获取用户id - async getUserId(): Promise { - let accountMgr = account_osAccount.getAccountManager(); - return await accountMgr.getOsAccountLocalIdFromProcess(); - } - - // 获取帐号信息 - async getOsAccountInfo(): Promise { - let accountMgr = account_osAccount.getAccountManager(); - return await accountMgr.getCurrentOsAccount(); - } - - // 获取AuthPerm - getAuthPerm(accountName: string, dlpProperty: dlpPermission.DLPProperty): dlpPermission.DLPFileAccess { - let perm: dlpPermission.DLPFileAccess = dlpPermission.DLPFileAccess.NO_PERMISSION; - if (accountName === dlpProperty.ownerAccount) { - return dlpPermission.DLPFileAccess.FULL_CONTROL; - } - if ((dlpProperty.everyoneAccessList !== undefined) && (dlpProperty.everyoneAccessList.length > 0)) { - perm = Math.max(...dlpProperty.everyoneAccessList); - } - let authUserList = dlpProperty.authUserList ?? []; - for (let i = 0; i < authUserList.length; ++i) { - let authUser = authUserList[i]; - if (authUser.authAccount === accountName) { - return authUser.dlpFileAccess; - } - } - return perm; - } - - // 帐号登录 - async AccountLogin(accountName: string) { - Logger.info('AccountLogin start'); - let info: UserInfo = { - name: '', - id: '1234', - event: 'Ohos.account.event.LOGIN', - nickname: 'nickname', - avatar: 'avatar' - }; - info.name = accountName; - info.event = 'Ohos.account.event.LOGIN'; - try { - await accountAbility.setOsAccountDistributedInfo(info); - } catch (err) { - console.error(TAG, `setOsAccountDistributedInfo LOGIN failed${err.code}, message:${err.message}`); - return - } - let user = await accountAbility.getOsAccountDistributedInfo(); - Logger.info(`CurrentMessage is ${JSON.stringify(user)}`); - } - - // 帐号登出 - async AccountLogout() { - Logger.info('AccountLogout start'); - let accountInfo = await accountAbility.getOsAccountDistributedInfo(); - let info: UserInfo = { - name: '', - id: '1234', - event: 'Ohos.account.event.LOGIN', - nickname: 'nickname', - avatar: 'avatar' - } - if (accountInfo.name === 'ohosAnonymousName') { - return - } - info.name = accountInfo.name - info.event = 'Ohos.account.event.LOGOUT' - await accountAbility.setOsAccountDistributedInfo(info); - Logger.info('AccountLogout end'); - } - - // 生成可选参数的DLP策略 - async genTestOptionalDlpProperty(): Promise { - let accountInfo = await this.getOsAccountInfo(); - let property: dlpPermission.DLPProperty = { - 'ownerAccount': accountInfo.distributedInfo.name, - 'ownerAccountID': accountInfo.distributedInfo.id, - 'ownerAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, - 'contactAccount': accountInfo.distributedInfo.name, - 'offlineAccess': true, - }; - return property; - } - - // 生成DLP策略 - async genTestDlpProperty(): Promise { - this.accountInfo = await this.getOsAccountInfo(); - let property: dlpPermission.DLPProperty = { - 'ownerAccount': this.accountInfo.distributedInfo.name, - 'ownerAccountID': this.accountInfo.distributedInfo.name, - 'ownerAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, - 'authUserList': userList, - 'contactAccount': this.accountInfo.distributedInfo.name, - 'offlineAccess': true, - 'everyoneAccessList': [dlpPermission.DLPFileAccess.READ_ONLY], - }; - return property; - } - - // 启动沙箱应用 - startSandboxApp(): void { - let want: Want = { - bundleName: this.sandboxBundleName, - abilityName: this.sandboxAbilityName, - uri: this.linkFilePath, - parameters: { - 'linkFileName': { - 'name': this.linkFileName - }, - 'uri': this.linkFilePath, - 'dlpUri': { - 'name': this.dlpFileUri - }, - } - }; - context.startAbility(want, (err) => { - Logger.info() - }); - } - - // 生成测试DLP文件 - async genTestDlpFile(plaintextPath: string, ciphertextFd: number, displayName: string, currentPerssion: number, dlpFileInfos: Array) { - Logger.info('GenTestDlpFile start'); - let file: fs.File = fs.openSync(plaintextPath, fs.OpenMode.READ_WRITE); - this.dlpFd = ciphertextFd; - this.dlpFileUri = `${SOURCEURI}/${displayName}`; - let fileInfo: TestDlpFileInfo = new TestDlpFileInfo(); - fileInfo.plaintextPath = plaintextPath; - fileInfo.ciphertextPath = this.dlpFileUri; - dlpFileInfos.push(fileInfo); - AppStorage.set>('dlpFileInfos', dlpFileInfos); - await this.preferencesManager.putDlpFileInfos(dlpFileInfos); - Logger.info(`file.fd:${file.fd},dlpFd:${this.dlpFd}`); - let property = await this.genTestDlpProperty(); - property.everyoneAccessList = [currentPerssion + 1]; - Logger.info(`everyoneList ${JSON.stringify(property.everyoneAccessList)},current`); - try { - this.dlpFile = await dlpPermission.generateDLPFile(file.fd, this.dlpFd, property); - if (await dlpPermission.isDLPFile(this.dlpFd)) { - Logger.info(`generateDLPFile success`); - } else { - Logger.info(`generateDLPFile fail`); - } - this.dlpFile.closeDLPFile(); - } - - catch (err) { - let error: BusinessError = err as BusinessError; - Logger.error(`generateDLPFile failed, errCode:${error.code},message:${error.message}`); - fs.closeSync(file.fd); - fs.closeSync(this.dlpFd); - } - } -} - - +/* + * Copyright (c) 2023 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 dlpPermission from '@ohos.dlpPermission'; +import fs from '@ohos.file.fs'; +import account from '@ohos.account.distributedAccount' +import account_osAccount from '@ohos.account.osAccount'; +import Want from '@ohos.app.ability.Want'; +import { BusinessError } from '@ohos.base'; +import common from '@ohos.app.ability.common'; +import { PreferencesManager } from '../feature/PreferencesManager'; +import Logger from '../util/Logger'; + +const TAG: string = 'DlpManager'; +const SOURCEURI: string = 'file://docs/storage/Users/currentUser'; +let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; +let accountAbility = account.getDistributedAccountAbility(); +// 用户列表 +let userList: Array = [{ + 'authAccount': '123@ohos.com', + 'authAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, + 'dlpFileAccess': dlpPermission.DLPFileAccess.READ_ONLY, + // 授权到期时间戳 + 'permExpiryTime': 8888520175, +}, { + 'authAccount': '456@ohos.com', + 'authAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, + 'dlpFileAccess': dlpPermission.DLPFileAccess.FULL_CONTROL, + // 授权到期时间戳 + 'permExpiryTime': 8888520175, +}] + +// dlp信息类型 +export class TestDlpFileInfo { + plaintextPath: string = ''; + ciphertextPath: string = ''; +} + +// 用户信息类型 +interface UserInfo { + name: string, + id: string, + event: string, + nickname: string, + avatar: string +} + +export class DlpManager { + // linkFile文件名 + private linkFileName: string = ''; + // link地址文件名 + private linkFilePath: string = ''; + // dlp文件 + private dlpFile: dlpPermission.DLPFile = {} as dlpPermission.DLPFile; + // 沙箱包名 + private sandboxBundleName: string = 'com.example.fileEdit'; + private sandboxAbilityName: string = 'EntryAbility'; + // dlp文件的句柄 + private dlpFd: number = -1; + // 账号信息 + private accountInfo?: account_osAccount.OsAccountInfo; + // dlp文件路径地址 + private dlpFileUri: string = ''; + private preferencesManager: PreferencesManager = new PreferencesManager(); + + constructor() { + } + + // 获取用户id + async getUserId(): Promise { + let accountMgr = account_osAccount.getAccountManager(); + return await accountMgr.getOsAccountLocalIdFromProcess(); + } + + // 获取帐号信息 + async getOsAccountInfo(): Promise { + let accountMgr = account_osAccount.getAccountManager(); + return await accountMgr.getCurrentOsAccount(); + } + + // 获取AuthPerm + getAuthPerm(accountName: string, dlpProperty: dlpPermission.DLPProperty): dlpPermission.DLPFileAccess { + let perm: dlpPermission.DLPFileAccess = dlpPermission.DLPFileAccess.NO_PERMISSION; + if (accountName === dlpProperty.ownerAccount) { + return dlpPermission.DLPFileAccess.FULL_CONTROL; + } + if ((dlpProperty.everyoneAccessList !== undefined) && (dlpProperty.everyoneAccessList.length > 0)) { + perm = Math.max(...dlpProperty.everyoneAccessList); + } + let authUserList = dlpProperty.authUserList ?? []; + for (let i = 0; i < authUserList.length; ++i) { + let authUser = authUserList[i]; + if (authUser.authAccount === accountName) { + return authUser.dlpFileAccess; + } + } + return perm; + } + + // 帐号登录 + async AccountLogin(accountName: string) { + Logger.info('AccountLogin start'); + let info: UserInfo = { + name: '', + id: '1234', + event: 'Ohos.account.event.LOGIN', + nickname: 'nickname', + avatar: 'avatar' + }; + info.name = accountName; + info.event = 'Ohos.account.event.LOGIN'; + try { + await accountAbility.setOsAccountDistributedInfo(info); + } catch (err) { + console.error(TAG, `setOsAccountDistributedInfo LOGIN failed${err.code}, message:${err.message}`); + return + } + let user = await accountAbility.getOsAccountDistributedInfo(); + Logger.info(`CurrentMessage is ${JSON.stringify(user)}`); + } + + // 帐号登出 + async AccountLogout() { + Logger.info('AccountLogout start'); + let accountInfo = await accountAbility.getOsAccountDistributedInfo(); + let info: UserInfo = { + name: '', + id: '1234', + event: 'Ohos.account.event.LOGIN', + nickname: 'nickname', + avatar: 'avatar' + } + if (accountInfo.name === 'ohosAnonymousName') { + return + } + info.name = accountInfo.name + info.event = 'Ohos.account.event.LOGOUT' + await accountAbility.setOsAccountDistributedInfo(info); + Logger.info('AccountLogout end'); + } + + // 生成可选参数的DLP策略 + async genTestOptionalDlpProperty(): Promise { + let accountInfo = await this.getOsAccountInfo(); + let property: dlpPermission.DLPProperty = { + 'ownerAccount': accountInfo.distributedInfo.name, + 'ownerAccountID': accountInfo.distributedInfo.id, + 'ownerAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, + 'contactAccount': accountInfo.distributedInfo.name, + 'offlineAccess': true, + }; + return property; + } + + // 生成DLP策略 + async genTestDlpProperty(): Promise { + this.accountInfo = await this.getOsAccountInfo(); + let property: dlpPermission.DLPProperty = { + 'ownerAccount': this.accountInfo.distributedInfo.name, + 'ownerAccountID': this.accountInfo.distributedInfo.name, + 'ownerAccountType': dlpPermission.AccountType.CLOUD_ACCOUNT, + 'authUserList': userList, + 'contactAccount': this.accountInfo.distributedInfo.name, + 'offlineAccess': true, + 'everyoneAccessList': [dlpPermission.DLPFileAccess.READ_ONLY], + }; + return property; + } + + // 启动沙箱应用 + startSandboxApp(): void { + let want: Want = { + bundleName: this.sandboxBundleName, + abilityName: this.sandboxAbilityName, + uri: this.linkFilePath, + parameters: { + 'linkFileName': { + 'name': this.linkFileName + }, + 'uri': this.linkFilePath, + 'dlpUri': { + 'name': this.dlpFileUri + }, + } + }; + context.startAbility(want, (err) => { + Logger.info() + }); + } + + // 生成测试DLP文件 + async genTestDlpFile(plaintextPath: string, ciphertextFd: number, displayName: string, currentPerssion: number, dlpFileInfos: Array) { + Logger.info('GenTestDlpFile start'); + let file: fs.File = fs.openSync(plaintextPath, fs.OpenMode.READ_WRITE); + this.dlpFd = ciphertextFd; + this.dlpFileUri = `${SOURCEURI}/${displayName}`; + let fileInfo: TestDlpFileInfo = new TestDlpFileInfo(); + fileInfo.plaintextPath = plaintextPath; + fileInfo.ciphertextPath = this.dlpFileUri; + dlpFileInfos.push(fileInfo); + AppStorage.set>('dlpFileInfos', dlpFileInfos); + await this.preferencesManager.putDlpFileInfos(dlpFileInfos); + Logger.info(`file.fd:${file.fd},dlpFd:${this.dlpFd}`); + let property = await this.genTestDlpProperty(); + property.everyoneAccessList = [currentPerssion + 1]; + Logger.info(`everyoneList ${JSON.stringify(property.everyoneAccessList)},current`); + try { + this.dlpFile = await dlpPermission.generateDLPFile(file.fd, this.dlpFd, property); + if (await dlpPermission.isDLPFile(this.dlpFd)) { + Logger.info(`generateDLPFile success`); + } else { + Logger.info(`generateDLPFile fail`); + } + this.dlpFile.closeDLPFile(); + } + + catch (err) { + let error: BusinessError = err as BusinessError; + Logger.error(`generateDLPFile failed, errCode:${error.code},message:${error.message}`); + fs.closeSync(file.fd); + fs.closeSync(this.dlpFd); + } + } +} + + diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/FileManager.ets b/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/FileManager.ets index 67d5dfba66aa0a5b76cbb3164bf8d38555b7aeaf..d61ad4a0f9d80ddc48df8f5a1e631bb219eb50cc 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/FileManager.ets +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/FileManager.ets @@ -1,159 +1,159 @@ -/* - * Copyright (c) 2023 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 fs from '@ohos.file.fs'; -import fileAccess from '@ohos.file.fileAccess'; -import { BusinessError } from '@ohos.base'; -import { TestDlpFileInfo } from '../feature/DlpManager'; -import Logger from '../util/Logger'; -import common from '@ohos.app.ability.common'; -import fileUri from '@ohos.file.fileuri'; -import { PreferencesManager } from './PreferencesManager'; - -const TAG = 'FileManager'; -const RECENT_MAX = 10; // 最近打开最大文件数 -let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - -export class FileInfoType { - fileUri: string = ''; - fileName: string = ''; - size: number = 0; - isEncryption: boolean = false; - - constructor(fileUri: string, fileName: string, size: number, isEncryption?: boolean) { - this.fileUri = fileUri; - this.fileName = fileName; - this.size = size; - } -} - -export class MediaFileUri { - private fileAccessHelper: fileAccess.FileAccessHelper = {} as fileAccess.FileAccessHelper; - private fileInfos: Array = []; - - constructor() { - this.fileAccessHelper = fileAccess.createFileAccessHelper(context); - } - - // sync-close - closeSync(fd: number): void { - try { - fs.closeSync(fd); - Logger.info(TAG, 'closeSync file finish.'); - } catch (err) { - Logger.error(TAG, 'closeSync file error = ' + err); - } - } - - myGetFileSize(uri: string, mode: number): number { - let file = fs.openSync(uri, mode); // fs.OpenMode.READ_ONLY - Logger.info(TAG, `file fd: file.fd`); - let stat = fs.statSync(file.fd); - Logger.info(TAG, `get file info succeed, the size of file is ${stat.size}`); - return stat.size; - } - - // 获取文件数据 - async getFileData(url: string): Promise { - let isDone: boolean = false; - let fileInfo = await this.fileAccessHelper.getFileInfoFromUri(url); - try { - let fileIterator = fileInfo.scanFile({ suffix: ['.txt'] }); - if (!fileIterator) { - Logger.info(TAG, 'listFile interface returns an undefined object'); - } - while (!isDone) { - let result = fileIterator.next(); - isDone = result.done; - if (!isDone) { - let fileMsg: FileInfoType = new FileInfoType(result.value.uri, result.value.fileName, result.value.size); - let filterArray: Array = this.fileInfos.filter((item) => { - return item.fileName === fileMsg.fileName; - }) - if (filterArray.length > 0) { - return; - } - this.fileInfos.push(fileMsg); - } - } - } catch (err) { - Logger.info(TAG, `listFile failed, ${err}`); - } - } - - // 获取文件 - async getAllFiles(context: common.UIAbilityContext, dlpFileInfos: Array): Promise { - Logger.info(TAG, 'getAllFiles begin'); - Logger.info(TAG, 'getAllFiles begin' + JSON.stringify(dlpFileInfos)); - this.fileInfos = []; - let rootIterator = await this.fileAccessHelper.getRoots(); - // 获取目录url - let catalogueUrl: string = rootIterator.next().value.uri; - await this.getFileData(catalogueUrl); - await this.handleFileData(dlpFileInfos); - AppStorage.set('fileInfos', this.fileInfos); - } - - // 处理文件数据 - async handleFileData(dlpFileInfos: Array) { - if (dlpFileInfos.length > 0) { - for (let index = 0; index < this.fileInfos.length && index < RECENT_MAX; index++) { - dlpFileInfos.forEach(async (item: TestDlpFileInfo, ind: number) => { - let uriInfo: fileUri.FileUri = await this.getFileName(item.plaintextPath); - let fileInfo: FileInfoType = this.fileInfos[index]; - if (uriInfo.name === fileInfo.fileName) { - fileInfo.isEncryption = true; - } - }) - } - } - } - - // 删除文件 - async deleteFile(uri: string) { - Logger.info(`deleteFile start, uri is ${uri}`); - try { - let code = await this.fileAccessHelper.delete(uri); - if (code !== 0) { - Logger.error(`delete failed, code:${code}`); - } - } catch (err) { - let error: BusinessError = err as BusinessError; - Logger.error(`delete failed, errCode:${error.code}`); - } - } - - // 根据Uri获取名称 - async getFileName(uri: string) { - let uriInfo: fileUri.FileUri = new fileUri.FileUri(uri); - return uriInfo; - } - - // 新增文件 - async createFile(sourceUri: string, displayName: string): Promise { - Logger.info(`SourceUri:${sourceUri}----displayName:${displayName}`); - try { - // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取 - let fileUri = await this.fileAccessHelper.createFile(sourceUri, displayName); - let file = fs.openSync(fileUri, fs.OpenMode.READ_WRITE); - Logger.info('the fd is ' + file.fd); - return file.fd; - } catch (err) { - let error: BusinessError = err as BusinessError; - Logger.error(`createFile failed, errCode:${error.code}, errMessage:${error.message}`); - return -1; - } - } +/* + * Copyright (c) 2023 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 fs from '@ohos.file.fs'; +import fileAccess from '@ohos.file.fileAccess'; +import { BusinessError } from '@ohos.base'; +import { TestDlpFileInfo } from '../feature/DlpManager'; +import Logger from '../util/Logger'; +import common from '@ohos.app.ability.common'; +import fileUri from '@ohos.file.fileuri'; +import { PreferencesManager } from './PreferencesManager'; + +const TAG = 'FileManager'; +const RECENT_MAX = 10; // 最近打开最大文件数 +let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + +export class FileInfoType { + fileUri: string = ''; + fileName: string = ''; + size: number = 0; + isEncryption: boolean = false; + + constructor(fileUri: string, fileName: string, size: number, isEncryption?: boolean) { + this.fileUri = fileUri; + this.fileName = fileName; + this.size = size; + } +} + +export class MediaFileUri { + private fileAccessHelper: fileAccess.FileAccessHelper = {} as fileAccess.FileAccessHelper; + private fileInfos: Array = []; + + constructor() { + this.fileAccessHelper = fileAccess.createFileAccessHelper(context); + } + + // sync-close + closeSync(fd: number): void { + try { + fs.closeSync(fd); + Logger.info(TAG, 'closeSync file finish.'); + } catch (err) { + Logger.error(TAG, 'closeSync file error = ' + err); + } + } + + myGetFileSize(uri: string, mode: number): number { + let file = fs.openSync(uri, mode); // fs.OpenMode.READ_ONLY + Logger.info(TAG, `file fd: file.fd`); + let stat = fs.statSync(file.fd); + Logger.info(TAG, `get file info succeed, the size of file is ${stat.size}`); + return stat.size; + } + + // 获取文件数据 + async getFileData(url: string): Promise { + let isDone: boolean = false; + let fileInfo = await this.fileAccessHelper.getFileInfoFromUri(url); + try { + let fileIterator = fileInfo.scanFile({ suffix: ['.txt'] }); + if (!fileIterator) { + Logger.info(TAG, 'listFile interface returns an undefined object'); + } + while (!isDone) { + let result = fileIterator.next(); + isDone = result.done; + if (!isDone) { + let fileMsg: FileInfoType = new FileInfoType(result.value.uri, result.value.fileName, result.value.size); + let filterArray: Array = this.fileInfos.filter((item) => { + return item.fileName === fileMsg.fileName; + }) + if (filterArray.length > 0) { + return; + } + this.fileInfos.push(fileMsg); + } + } + } catch (err) { + Logger.info(TAG, `listFile failed, ${err}`); + } + } + + // 获取文件 + async getAllFiles(context: common.UIAbilityContext, dlpFileInfos: Array): Promise { + Logger.info(TAG, 'getAllFiles begin'); + Logger.info(TAG, 'getAllFiles begin' + JSON.stringify(dlpFileInfos)); + this.fileInfos = []; + let rootIterator = await this.fileAccessHelper.getRoots(); + // 获取目录url + let catalogueUrl: string = rootIterator.next().value.uri; + await this.getFileData(catalogueUrl); + await this.handleFileData(dlpFileInfos); + AppStorage.set('fileInfos', this.fileInfos); + } + + // 处理文件数据 + async handleFileData(dlpFileInfos: Array) { + if (dlpFileInfos.length > 0) { + for (let index = 0; index < this.fileInfos.length && index < RECENT_MAX; index++) { + dlpFileInfos.forEach(async (item: TestDlpFileInfo, ind: number) => { + let uriInfo: fileUri.FileUri = await this.getFileName(item.plaintextPath); + let fileInfo: FileInfoType = this.fileInfos[index]; + if (uriInfo.name === fileInfo.fileName) { + fileInfo.isEncryption = true; + } + }) + } + } + } + + // 删除文件 + async deleteFile(uri: string) { + Logger.info(`deleteFile start, uri is ${uri}`); + try { + let code = await this.fileAccessHelper.delete(uri); + if (code !== 0) { + Logger.error(`delete failed, code:${code}`); + } + } catch (err) { + let error: BusinessError = err as BusinessError; + Logger.error(`delete failed, errCode:${error.code}`); + } + } + + // 根据Uri获取名称 + async getFileName(uri: string) { + let uriInfo: fileUri.FileUri = new fileUri.FileUri(uri); + return uriInfo; + } + + // 新增文件 + async createFile(sourceUri: string, displayName: string): Promise { + Logger.info(`SourceUri:${sourceUri}----displayName:${displayName}`); + try { + // fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取 + let fileUri = await this.fileAccessHelper.createFile(sourceUri, displayName); + let file = fs.openSync(fileUri, fs.OpenMode.READ_WRITE); + Logger.info('the fd is ' + file.fd); + return file.fd; + } catch (err) { + let error: BusinessError = err as BusinessError; + Logger.error(`createFile failed, errCode:${error.code}, errMessage:${error.message}`); + return -1; + } + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets b/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets index 35d89ac75c3e88dd5cb843281668f76930c777a5..e448c048b6e6611661fa52e7ec2056797b14bcd7 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/feature/PreferencesManager.ets @@ -1,85 +1,85 @@ -/* - * Copyright (c) 2023 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 dataPreferences from '@ohos.data.preferences'; -import common from '@ohos.app.ability.common'; -import { MediaFileUri } from './FileManager'; -import Logger from '../util/Logger'; -import { TestDlpFileInfo } from '../feature/DlpManager'; -import { BusinessError } from '@ohos.base'; - -let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; -let dataPreferencesManager: dataPreferences.Preferences = {} as dataPreferences.Preferences; - - -export class PreferencesManager { - private mediaFileUri: MediaFileUri = new MediaFileUri(); - - async getPreferences() { - try { - dataPreferences.getPreferences(context, 'myStore', (err: BusinessError, val: dataPreferences.Preferences) => { - if (err) { - Logger.error("Failed to get preferences. code =" + err.code + ", message =" + err.message); - return; - } - dataPreferencesManager = val; - this.getDlpFileInfos(); - Logger.info("Succeeded in getting preferences."); - }) - } catch (err) { - let code = (err as BusinessError).code; - let message = (err as BusinessError).message; - Logger.error("Failed to get preferences. code =" + code + ", message =" + message); - } - } - - async putDlpFileInfos(dlpFileInfos: Array) { - try { - dataPreferencesManager.put('dlpFileInfos', JSON.stringify(dlpFileInfos), async (err: BusinessError) => { - if (err) { - Logger.error("Failed to put value of 'dlpFileInfos'. code =" + err.code + ", message =" + err.message); - return; - } - Logger.info("Succeeded in putting value of 'dlpFileInfos'."); - dataPreferencesManager.flush(); - }) - } catch (err) { - let code = (err as BusinessError).code; - let message = (err as BusinessError).message; - Logger.error("Failed to put value of 'dlpFileInfos'. code =" + code + ", message =" + message); - } - } - - async getDlpFileInfos() { - try { - let dlpFileInfos: Array = []; - let promise = dataPreferencesManager.get('dlpFileInfos', []); - promise.then(async (data: dataPreferences.ValueType) => { - if (typeof data === 'string') { - let dlpFileInfos: Array = JSON.parse(data); - AppStorage.set('dlpFileInfos', dlpFileInfos); - await this.mediaFileUri.getAllFiles(context, dlpFileInfos); - Logger.info("Succeeded in getting value of 'dlpFileInfos'. dlpFileInfos: " + JSON.stringify(dlpFileInfos)); - } else { - await this.mediaFileUri.getAllFiles(context, dlpFileInfos); - } - }) - } catch (err) { - let code = (err as BusinessError).code; - let message = (err as BusinessError).message; - Logger.error("Failed to get value of 'dlpFileInfos'. code =" + code + ", message =" + message); - } - } +/* + * Copyright (c) 2023 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 dataPreferences from '@ohos.data.preferences'; +import common from '@ohos.app.ability.common'; +import { MediaFileUri } from './FileManager'; +import Logger from '../util/Logger'; +import { TestDlpFileInfo } from '../feature/DlpManager'; +import { BusinessError } from '@ohos.base'; + +let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; +let dataPreferencesManager: dataPreferences.Preferences = {} as dataPreferences.Preferences; + + +export class PreferencesManager { + private mediaFileUri: MediaFileUri = new MediaFileUri(); + + async getPreferences() { + try { + dataPreferences.getPreferences(context, 'myStore', (err: BusinessError, val: dataPreferences.Preferences) => { + if (err) { + Logger.error("Failed to get preferences. code =" + err.code + ", message =" + err.message); + return; + } + dataPreferencesManager = val; + this.getDlpFileInfos(); + Logger.info("Succeeded in getting preferences."); + }) + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + Logger.error("Failed to get preferences. code =" + code + ", message =" + message); + } + } + + async putDlpFileInfos(dlpFileInfos: Array) { + try { + dataPreferencesManager.put('dlpFileInfos', JSON.stringify(dlpFileInfos), async (err: BusinessError) => { + if (err) { + Logger.error("Failed to put value of 'dlpFileInfos'. code =" + err.code + ", message =" + err.message); + return; + } + Logger.info("Succeeded in putting value of 'dlpFileInfos'."); + dataPreferencesManager.flush(); + }) + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + Logger.error("Failed to put value of 'dlpFileInfos'. code =" + code + ", message =" + message); + } + } + + async getDlpFileInfos() { + try { + let dlpFileInfos: Array = []; + let promise = dataPreferencesManager.get('dlpFileInfos', []); + promise.then(async (data: dataPreferences.ValueType) => { + if (typeof data === 'string') { + let dlpFileInfos: Array = JSON.parse(data); + AppStorage.set('dlpFileInfos', dlpFileInfos); + await this.mediaFileUri.getAllFiles(context, dlpFileInfos); + Logger.info("Succeeded in getting value of 'dlpFileInfos'. dlpFileInfos: " + JSON.stringify(dlpFileInfos)); + } else { + await this.mediaFileUri.getAllFiles(context, dlpFileInfos); + } + }) + } catch (err) { + let code = (err as BusinessError).code; + let message = (err as BusinessError).message; + Logger.error("Failed to get value of 'dlpFileInfos'. code =" + code + ", message =" + message); + } + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/util/Logger.ts b/code/SystemFeature/Security/DLP/entry/src/main/ets/util/Logger.ts index 61a8528793a09fe7bd6accd4720a09b51798c157..ab4fc6047955e72292fc5858d66481f58813a929 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/util/Logger.ts +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/util/Logger.ts @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog' - -class Logger { - private domain: number; - private prefix: string; - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - this.domain = 0xFF00; - } - - debug(...args: string[]) { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]) { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]) { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]) { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog' + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0xFF00; + } + + debug(...args: string[]) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]) { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]) { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]) { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('Sample_DLP'); \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets b/code/SystemFeature/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets index 3085317211d7e92a6435061ff51f984826366dc6..95ea48f5c32d5603b8bb61787045d3bb4d7fac5b 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets +++ b/code/SystemFeature/Security/DLP/entry/src/main/ets/util/ResourceUtils.ets @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import common from '@ohos.app.ability.common'; - -/** - * getResourceString将Resource类型的数据转换成string类型的数据 - * @param context - * @param ResourceData - */ -export function getResourceString(context: common.UIAbilityContext, resourceData: Resource): string { - let stringData: string = context.resourceManager.getStringSync(resourceData.id); - return stringData; +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import common from '@ohos.app.ability.common'; + +/** + * getResourceString将Resource类型的数据转换成string类型的数据 + * @param context + * @param ResourceData + */ +export function getResourceString(context: common.UIAbilityContext, resourceData: Resource): string { + let stringData: string = context.resourceManager.getStringSync(resourceData.id); + return stringData; } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/module.json5 b/code/SystemFeature/Security/DLP/entry/src/main/module.json5 index 3f54f2c18d57916e88301cf66dbcf2df5f5e10fe..a122c7892714298dbb924d785d9dbea081394745 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/module.json5 +++ b/code/SystemFeature/Security/DLP/entry/src/main/module.json5 @@ -1,75 +1,75 @@ -/* - * Copyright (c) 2023 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.ts", - "description": "$string:EntryAbility_desc", - "icon": "$media:icon", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "exported": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ] - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.FILE_ACCESS_MANAGER", - }, - { - "name": "ohos.permission.STORAGE_MANAGER", - }, - { - "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", - }, - { - "name": "ohos.permission.ACCESS_DLP_FILE" - }, - { - "name": "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS" - }, - { - "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" - }, - { - "name": "ohos.permission.GET_LOCAL_ACCOUNTS" - } - ] - } +/* + * Copyright (c) 2023 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.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.FILE_ACCESS_MANAGER", + }, + { + "name": "ohos.permission.STORAGE_MANAGER", + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + }, + { + "name": "ohos.permission.ACCESS_DLP_FILE" + }, + { + "name": "ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS" + }, + { + "name": "ohos.permission.MANAGE_LOCAL_ACCOUNTS" + }, + { + "name": "ohos.permission.GET_LOCAL_ACCOUNTS" + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/element/color.json b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/element/color.json index 65bbb43024bc3d5092987f7ec70bfa0059bd9300..47ff61743b20fe3a1edc8525409ee3b7b2e040d0 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "folder_color_99182431", - "value": "#99182431" - }, - { - "name": "modified_time_font_color", - "value": "#A3A7AD" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "folder_color_99182431", + "value": "#99182431" + }, + { + "name": "modified_time_font_color", + "value": "#A3A7AD" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg index b534ac59023caab422eeab80375ffc6e69ba89f9..1e10662cd8510642ac606e4f7a78181715bfc3f4 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg +++ b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_docs.svg @@ -1,13 +1,13 @@ - - - ic_docs - - - - - - - - - + + + ic_docs + + + + + + + + + \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg index a14cee62442ccb92b9bddcfc8d63dd7142b6ec6b..9b39e709bbd0424fb83e1e9ba73da002293916b8 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg +++ b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_folder.svg @@ -1,13 +1,13 @@ - - - ic_folder - - - - - - - - - + + + ic_folder + + + + + + + + + \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg index 0c5f0e69461abfffa598a622815e22911a9aab80..19b2892ca2facb351ee1c6f8710799dfeac9b443 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg +++ b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/ic_saveas.svg @@ -1,13 +1,13 @@ - - - ic_saveas - - - - - - - - - + + + ic_saveas + + + + + + + + + \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/triangle.svg b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/triangle.svg index b8e411603c399c3607d1c31a7d894188c8ee2a28..6bd84c78e21a55703c5625c0d881eb4ffb112c4f 100644 --- a/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/triangle.svg +++ b/code/SystemFeature/Security/DLP/entry/src/main/resources/base/media/triangle.svg @@ -1,11 +1,11 @@ - - - - -下拉三角 - - + + + + +下拉三角 + + diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets index a0133054f6a4675fdba646f6840b4f475a4f60a3..f4937c1d4563eef67882be73e1b754906335c9df 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Ability.test.ets @@ -1,209 +1,209 @@ -/* - * Copyright (c) 2023 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, beforeAll } from '@ohos/hypium'; -import Logger from './Logger'; -import { Driver, ON } from '@ohos.UiTest'; -import Want from '@ohos.app.ability.Want'; -import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import inputMethod from '@ohos.inputMethod'; -import resourceManager from '@ohos.resourceManager'; - -const BUNDLE = 'DLP'; -const TAG = '[Sample_DLP_TEST]'; -const delegator = abilityDelegatorRegistry.getAbilityDelegator(); - -async function getResourceString(resource: T): Promise { - let manage = delegator.getAppContext().resourceManager; - let text = await manage.getStringValue(resource); - return text; -} - -export default function abilityTest() { - describe('ActsAbilityTest', () => { - beforeAll(async () => { - let want: Want = { - bundleName: 'com.samples.dlp', - abilityName: "EntryAbility" - } - await delegator.startAbility(want); - }) - /** - * 允许 - */ - it(BUNDLE + 'authorization', 0, async () => { - Logger.info(TAG, BUNDLE + 'authorization begin') - let driver = Driver.create(); - await driver.delayMs(5000); - // 点击聊天列表 - await driver.assertComponentExist(ON.text('允许')); - let authorizateBtn = await driver.findComponent(ON.text('允许')); - await driver.delayMs(1000); - await authorizateBtn.click(); - await driver.delayMs(1000); - }) - /** - * 添加普通文件 - */ - it(BUNDLE + 'AddFiles', 0, async () => { - Logger.info(TAG, BUNDLE + 'AddFiles begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - // 添加普通文件 - await driver.assertComponentExist(ON.id('newFile')); - let addBtn = await driver.findComponent(ON.id('newFile')); - await driver.delayMs(1000); - await addBtn.click(); - await driver.delayMs(1000); - let authorizateBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content')))); - await driver.delayMs(1000); - if(authorizateBtn) { - await authorizateBtn.click(); - await driver.delayMs(1000); - } - let authorizateBtn2 = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content')))); - await driver.delayMs(1000); - if(authorizateBtn2) { - await authorizateBtn2.click(); - await driver.delayMs(1000); - } - let timestamp = new Date().getTime(); - let textInput = await driver.findComponent(ON.type('TextInput')); - await driver.delayMs(1000); - await textInput.inputText(`xxx合同${timestamp}.txt`); - await driver.delayMs(1000); - let inputMethodController = inputMethod.getController(); - inputMethodController.hideTextInput(); - await driver.delayMs(1000); - let ImageArray = await driver.findComponents(ON.type('Image')); - Logger.info(TAG, `ImageArray lenth:${ImageArray.length}`); - let finishBtn = ImageArray[2]; - await finishBtn.click(); - Logger.info(TAG, BUNDLE + 'AddFiles end'); - }) - /** - * 加密操作 - */ - it(BUNDLE + 'AddOrdinaryFiles', 0, async () => { - Logger.info(TAG, BUNDLE + 'AddOrdinaryFiles begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - // 点击聊天列表 - await driver.assertComponentExist(ON.id('fileItem')); - let fileItem = await driver.findComponent(ON.id('fileItem')); - await driver.delayMs(1000); - await fileItem.longClick(); - await driver.delayMs(1000); - await driver.assertComponentExist(ON.id('encryption')); - let encryptionBtn = await driver.findComponent(ON.id('encryption')); - await driver.delayMs(1000); - await encryptionBtn.click(); - await driver.delayMs(1000); - // 设置编辑权限 - let selectBtn = await driver.findComponent(ON.text('请选择权限')); - await selectBtn.click(); - await driver.delayMs(1000); - let editBtn = await driver.findComponent(ON.text('编辑')); - await editBtn.click(); - await driver.delayMs(1000); - let confirm = await driver.findComponent(ON.text('确定')); - await driver.delayMs(1000); - await confirm.click(); - await driver.delayMs(1000); - }) - /** - * 保存 - */ - it(BUNDLE + 'SaveContent', 0, async () => { - Logger.info(TAG, BUNDLE + 'SaveContent begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - // 点击进入编辑页面 - let authorizateBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content')))); - await driver.delayMs(1000); - if (authorizateBtn) { - authorizateBtn.click(); - await driver.delayMs(1000); - } - let fileItem = await driver.findComponent(ON.id('fileItem')); - await fileItem.click(); - await driver.delayMs(3000); - let webBtn = await driver.findComponent(ON.id('webComponent')); - await driver.delayMs(1000); - await webBtn.click(); - await webBtn.inputText('hello'); - await driver.delayMs(3000); - // 点击保存 - let saveBtn = await driver.findComponent(ON.id('saveBtn')); - await saveBtn.click(); - await driver.delayMs(1000); - // 返回Home页面 - let want: Want = { - bundleName: 'com.samples.dlp', - abilityName: "EntryAbility" - } - await delegator.startAbility(want); - Logger.info(TAG, BUNDLE + 'SaveContent end'); - }) - /** - * 只读权限 - */ - it(BUNDLE + 'OnlyRead', 0, async () => { - Logger.info(TAG, BUNDLE + 'OnlyRead begin'); - let driver = Driver.create(); - await driver.delayMs(3000); - // 点击进入编辑页面 - let fileItem = await driver.findComponent(ON.id('fileItem')); - await fileItem.longClick(); - await driver.delayMs(1000); - let encryptionBtn = await driver.findComponent(ON.id('encryption')); - await driver.delayMs(1000); - await encryptionBtn.click(); - await driver.delayMs(1000); - let file = await driver.findComponent(ON.id('fileItem')); - await driver.delayMs(1000); - await file.longClick(); - await driver.delayMs(1000); - let encryption = await driver.findComponent(ON.id('encryption')); - await encryption.click(); - await driver.delayMs(1000); - // 设置只读权限 - let selectBtn = await driver.findComponent(ON.text('请选择权限')); - await selectBtn.click(); - await driver.delayMs(1000); - let readBtn = await driver.findComponent(ON.text('只读')); - await readBtn.click(); - await driver.delayMs(1000); - let confirm = await driver.findComponent(ON.text('确定')); - await driver.delayMs(1000); - await confirm.click(); - await driver.delayMs(1000); - Logger.info(TAG, BUNDLE + 'OnlyRead end'); - }) - /** - * 验证只读权限 - */ - it(BUNDLE + 'CheckOnlyRead', 0, async () => { - Logger.info(TAG, BUNDLE + 'CheckOnlyRead begin'); - let driver = Driver.create(); - await driver.delayMs(1000); - // 点击进入编辑页面 - let fileItem = await driver.findComponent(ON.id('fileItem')); - await fileItem.click(); - await driver.delayMs(1000); - Logger.info(TAG, BUNDLE + 'CheckOnlyRead end'); - }) - }) +/* + * Copyright (c) 2023 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, beforeAll } from '@ohos/hypium'; +import Logger from './Logger'; +import { Driver, ON } from '@ohos.UiTest'; +import Want from '@ohos.app.ability.Want'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import inputMethod from '@ohos.inputMethod'; +import resourceManager from '@ohos.resourceManager'; + +const BUNDLE = 'DLP'; +const TAG = '[Sample_DLP_TEST]'; +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); + +async function getResourceString(resource: T): Promise { + let manage = delegator.getAppContext().resourceManager; + let text = await manage.getStringValue(resource); + return text; +} + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + beforeAll(async () => { + let want: Want = { + bundleName: 'com.samples.dlp', + abilityName: "EntryAbility" + } + await delegator.startAbility(want); + }) + /** + * 允许 + */ + it(BUNDLE + 'authorization', 0, async () => { + Logger.info(TAG, BUNDLE + 'authorization begin') + let driver = Driver.create(); + await driver.delayMs(5000); + // 点击聊天列表 + await driver.assertComponentExist(ON.text('允许')); + let authorizateBtn = await driver.findComponent(ON.text('允许')); + await driver.delayMs(1000); + await authorizateBtn.click(); + await driver.delayMs(1000); + }) + /** + * 添加普通文件 + */ + it(BUNDLE + 'AddFiles', 0, async () => { + Logger.info(TAG, BUNDLE + 'AddFiles begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + // 添加普通文件 + await driver.assertComponentExist(ON.id('newFile')); + let addBtn = await driver.findComponent(ON.id('newFile')); + await driver.delayMs(1000); + await addBtn.click(); + await driver.delayMs(1000); + let authorizateBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content')))); + await driver.delayMs(1000); + if(authorizateBtn) { + await authorizateBtn.click(); + await driver.delayMs(1000); + } + let authorizateBtn2 = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content')))); + await driver.delayMs(1000); + if(authorizateBtn2) { + await authorizateBtn2.click(); + await driver.delayMs(1000); + } + let timestamp = new Date().getTime(); + let textInput = await driver.findComponent(ON.type('TextInput')); + await driver.delayMs(1000); + await textInput.inputText(`xxx合同${timestamp}.txt`); + await driver.delayMs(1000); + let inputMethodController = inputMethod.getController(); + inputMethodController.hideTextInput(); + await driver.delayMs(1000); + let ImageArray = await driver.findComponents(ON.type('Image')); + Logger.info(TAG, `ImageArray lenth:${ImageArray.length}`); + let finishBtn = ImageArray[2]; + await finishBtn.click(); + Logger.info(TAG, BUNDLE + 'AddFiles end'); + }) + /** + * 加密操作 + */ + it(BUNDLE + 'AddOrdinaryFiles', 0, async () => { + Logger.info(TAG, BUNDLE + 'AddOrdinaryFiles begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + // 点击聊天列表 + await driver.assertComponentExist(ON.id('fileItem')); + let fileItem = await driver.findComponent(ON.id('fileItem')); + await driver.delayMs(1000); + await fileItem.longClick(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.id('encryption')); + let encryptionBtn = await driver.findComponent(ON.id('encryption')); + await driver.delayMs(1000); + await encryptionBtn.click(); + await driver.delayMs(1000); + // 设置编辑权限 + let selectBtn = await driver.findComponent(ON.text('请选择权限')); + await selectBtn.click(); + await driver.delayMs(1000); + let editBtn = await driver.findComponent(ON.text('编辑')); + await editBtn.click(); + await driver.delayMs(1000); + let confirm = await driver.findComponent(ON.text('确定')); + await driver.delayMs(1000); + await confirm.click(); + await driver.delayMs(1000); + }) + /** + * 保存 + */ + it(BUNDLE + 'SaveContent', 0, async () => { + Logger.info(TAG, BUNDLE + 'SaveContent begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + // 点击进入编辑页面 + let authorizateBtn = await driver.findComponent(ON.text(await getResourceString($r('app.string.text_content')))); + await driver.delayMs(1000); + if (authorizateBtn) { + authorizateBtn.click(); + await driver.delayMs(1000); + } + let fileItem = await driver.findComponent(ON.id('fileItem')); + await fileItem.click(); + await driver.delayMs(3000); + let webBtn = await driver.findComponent(ON.id('webComponent')); + await driver.delayMs(1000); + await webBtn.click(); + await webBtn.inputText('hello'); + await driver.delayMs(3000); + // 点击保存 + let saveBtn = await driver.findComponent(ON.id('saveBtn')); + await saveBtn.click(); + await driver.delayMs(1000); + // 返回Home页面 + let want: Want = { + bundleName: 'com.samples.dlp', + abilityName: "EntryAbility" + } + await delegator.startAbility(want); + Logger.info(TAG, BUNDLE + 'SaveContent end'); + }) + /** + * 只读权限 + */ + it(BUNDLE + 'OnlyRead', 0, async () => { + Logger.info(TAG, BUNDLE + 'OnlyRead begin'); + let driver = Driver.create(); + await driver.delayMs(3000); + // 点击进入编辑页面 + let fileItem = await driver.findComponent(ON.id('fileItem')); + await fileItem.longClick(); + await driver.delayMs(1000); + let encryptionBtn = await driver.findComponent(ON.id('encryption')); + await driver.delayMs(1000); + await encryptionBtn.click(); + await driver.delayMs(1000); + let file = await driver.findComponent(ON.id('fileItem')); + await driver.delayMs(1000); + await file.longClick(); + await driver.delayMs(1000); + let encryption = await driver.findComponent(ON.id('encryption')); + await encryption.click(); + await driver.delayMs(1000); + // 设置只读权限 + let selectBtn = await driver.findComponent(ON.text('请选择权限')); + await selectBtn.click(); + await driver.delayMs(1000); + let readBtn = await driver.findComponent(ON.text('只读')); + await readBtn.click(); + await driver.delayMs(1000); + let confirm = await driver.findComponent(ON.text('确定')); + await driver.delayMs(1000); + await confirm.click(); + await driver.delayMs(1000); + Logger.info(TAG, BUNDLE + 'OnlyRead end'); + }) + /** + * 验证只读权限 + */ + it(BUNDLE + 'CheckOnlyRead', 0, async () => { + Logger.info(TAG, BUNDLE + 'CheckOnlyRead begin'); + let driver = Driver.create(); + await driver.delayMs(1000); + // 点击进入编辑页面 + let fileItem = await driver.findComponent(ON.id('fileItem')); + await fileItem.click(); + await driver.delayMs(1000); + Logger.info(TAG, BUNDLE + 'CheckOnlyRead end'); + }) + }) } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets index ba94018f88c1de6fc6c5da546da88dc2d1163efe..657d194164f932396390ddb56c59cbd65c7d1259 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/List.test.ets @@ -1,20 +1,20 @@ -/* - * Copyright (c) 2023 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(); +/* + * Copyright (c) 2023 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/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts index fbceab7060f5a4911a983583daa04ed0823cf0db..90c9e4074ae5ca0ba64357877d17ab76fe8f64f8 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/test/Logger.ts @@ -1,47 +1,47 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -class Logger { - // 日志对应的领域标识 - private domain: number = 0xF811; - // tag日志标识 - private prefix: string = '[Samples_AuthorizedControl]'; - // 格式字符串,用于日志的格式化输出 - private format: string = '%{public}s, %{public}s'; - - constructor(prefix: string) { - this.prefix = prefix; - } - - debug(...args: string[]): void { - hilog.debug(this.domain, this.prefix, this.format, args); - } - - info(...args: string[]): void { - hilog.info(this.domain, this.prefix, this.format, args); - } - - warn(...args: string[]): void { - hilog.warn(this.domain, this.prefix, this.format, args); - } - - error(...args: string[]): void { - hilog.error(this.domain, this.prefix, this.format, args); - } -} - +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + // 日志对应的领域标识 + private domain: number = 0xF811; + // tag日志标识 + private prefix: string = '[Samples_AuthorizedControl]'; + // 格式字符串,用于日志的格式化输出 + private format: string = '%{public}s, %{public}s'; + + constructor(prefix: string) { + this.prefix = prefix; + } + + debug(...args: string[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + export default new Logger('[Samples_DLP]'); \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets index 650c1df31679efc83086911f3a866255ef5c5461..53e4446e5100ee4689d39d9fca650a40a28abd32 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -1,65 +1,65 @@ -/* - * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; -import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; -import hilog from '@ohos.hilog'; -import { Hypium } from '@ohos/hypium'; -import testsuite from '../test/List.test'; -import window from '@ohos.window'; -import Want from '@ohos.app.ability.Want'; -import AbilityConstant from '@ohos.app.ability.AbilityConstant'; - -export default class TestAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); - hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); - hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); - let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator - abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() - let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs - abilityDelegatorArguments = abilityDelegatorRegistry.getArguments() - hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage) { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); - windowStage.loadContent('testability/pages/Index', (err, data) => { - 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. Data: %{public}s', - JSON.stringify(data) ?? ''); - }); - } - - onWindowStageDestroy() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); - } - - onForeground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); - } - - onBackground() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); - } +/* + * Copyright (c) 2023 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 UIAbility from '@ohos.app.ability.UIAbility'; +import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); + let abilityDelegator: abilityDelegatorRegistry.AbilityDelegator + abilityDelegator = abilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments: abilityDelegatorRegistry.AbilityDelegatorArgs + abilityDelegatorArguments = abilityDelegatorRegistry.getArguments() + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + 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. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets index 8eb693b0ebe5c53e0aa66ad1f223af30e34dfb1c..e91baaf849736366acab7c54a1901943a480a1d2 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; - -@Entry -@Component -struct Index { - aboutToAppear() { - hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); - } - - @State message: string = 'Hello World' - - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - } - .type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(() => { - }) - } - .width('100%') - } - .height('100%') - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(() => { + }) + } + .width('100%') + } + .height('100%') + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts index ba78cb5721efb94a7b03ed6d8250a7674a46dc97..d9f862c2e09f9b021645449659f938ae0c87922f 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import TestRunner from '@ohos.application.testRunner'; -import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -async function onAbilityCreateCallback() { - hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); -} - -async function addAbilityMonitorCallback(err: any) { - hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); - } - - async onRun() { - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - const bundleName = abilityDelegatorArguments.bundleName; - const testAbilityName = 'TestAbility'; - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - const want = { - bundleName: bundleName, - abilityName: testAbilityName - }; - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); - abilityDelegator.startAbility(want, (err: any, data: any) => { - hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? ''); - hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s', JSON.stringify(data) ?? ''); - }) - hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); - } +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + const bundleName = abilityDelegatorArguments.bundleName; + const testAbilityName = 'TestAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + const want = { + bundleName: bundleName, + abilityName: testAbilityName + }; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + abilityDelegator.startAbility(want, (err: any, data: any) => { + hilog.info(0x0000, 'testTag', 'startAbility : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'startAbility : data : %{public}s', JSON.stringify(data) ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/module.json5 b/code/SystemFeature/Security/DLP/entry/src/ohosTest/module.json5 index 7e44e83cf9b7428c7a916f5782b9a6d85bf6d7da..e6a499c49efe53f1a5bab25638ce6b00f612a7d8 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/module.json5 @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2023 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", - "description": "$string:module_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "default", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "abilities": [ - { - "name": "TestAbility", - "srcEntry": "./ets/testability/TestAbility.ets", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "exported": true, - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} +/* + * Copyright (c) 2023 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", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/color.json b/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/color.json index d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33..3c712962da3c2751c2b9ddb53559afcbd2b54a02 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/color.json +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/color.json @@ -1,8 +1,8 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/string.json b/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/string.json index 70d125129f02a118c5030634eea7da1a768f8015..530112a76974db2856aed199cab476c09d99ece9 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/string.json +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/element/string.json @@ -1,24 +1,24 @@ -{ - "string": [ - { - "name": "module_test_desc", - "value": "test ability description" - }, - { - "name": "TestAbility_desc", - "value": "the test ability" - }, - { - "name": "TestAbility_label", - "value": "test label" - }, - { - "name": "file_name", - "value": "xxx合同.txt" - }, - { - "name": "text_content", - "value": "允许" - } - ] +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + }, + { + "name": "file_name", + "value": "xxx合同.txt" + }, + { + "name": "text_content", + "value": "允许" + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json b/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json index c3d813c41aa8ac1b64ccf124bb705adefb381787..b7e7343cacb32ce982a45e76daad86e435e054fe 100644 --- a/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json +++ b/code/SystemFeature/Security/DLP/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -1,5 +1,5 @@ -{ - "src": [ - "testability/pages/Index" - ] -} +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/code/SystemFeature/Security/DLP/hvigor/hvigor-config.json5 b/code/SystemFeature/Security/DLP/hvigor/hvigor-config.json5 index 213d992653403a9be1fa24d0e27327214befd7cb..a7edd62de456a09645989d596aa94da499ab1e96 100644 --- a/code/SystemFeature/Security/DLP/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/Security/DLP/hvigor/hvigor-config.json5 @@ -1,18 +1,18 @@ -{ - "hvigorVersion": "3.0.9", - "dependencies": { - "@ohos/hvigor-ohos-plugin": "3.0.9" - }, - "execution": { - // "daemon": true, /* Enable daemon compilation. Default: true */ - // "incremental": true, /* Enable incremental compilation. Default: true */ - // "parallel": true, /* Enable parallel compilation. Default: true */ - // "typeCheck": false, /* Enable typeCheck. Default: false */ - }, - "logging": { - // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ - }, - "debugging": { - // "stacktrace": false /* Disable stacktrace compilation. Default: false */ - } +{ + "hvigorVersion": "3.0.9", + "dependencies": { + "@ohos/hvigor-ohos-plugin": "3.0.9" + }, + "execution": { + // "daemon": true, /* Enable daemon compilation. Default: true */ + // "incremental": true, /* Enable incremental compilation. Default: true */ + // "parallel": true, /* Enable parallel compilation. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Default: false */ + } } \ No newline at end of file diff --git a/code/SystemFeature/Security/DLP/oh-package.json5 b/code/SystemFeature/Security/DLP/oh-package.json5 index e35556872e4c127921a18f670acaf69fe1ce8543..d8ae900705fc5edc793e91197ce86d2b2712fe03 100644 --- a/code/SystemFeature/Security/DLP/oh-package.json5 +++ b/code/SystemFeature/Security/DLP/oh-package.json5 @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2023 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. - */ - -{ - "license": "", - "devDependencies": { - "@ohos/hypium": "1.0.6" - }, - "author": "", - "name": "dlp", - "description": "Please describe the basic information.", - "main": "", - "version": "1.0.0", - "dependencies": {} -} +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "", + "devDependencies": { + "@ohos/hypium": "1.0.6" + }, + "author": "", + "name": "dlp", + "description": "Please describe the basic information.", + "main": "", + "version": "1.0.0", + "dependencies": {} +} diff --git a/code/SystemFeature/Security/DLP/ohosTest.md b/code/SystemFeature/Security/DLP/ohosTest.md index 7981ae61f8bf5d801d29fafcb8a7f48e669b6597..3f2c8b5e0f9e418ed07b0fb5634eec1eac40bcaf 100644 --- a/code/SystemFeature/Security/DLP/ohosTest.md +++ b/code/SystemFeature/Security/DLP/ohosTest.md @@ -1,12 +1,12 @@ -# 数据防泄漏测试用例归档 - -## 用例表 - -| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 |测试结果| -|--------|-------------|----------------------|-------------------------------|--------------------------------|--------------------------------| -| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 |Pass| -| 新增普通文件 | 页面显示正常 | 点击新增按钮,输入文件名称,点击确定 | 拉起picker页面,文件命名成功,DLP页面显示新增文件 | 是 |Pass| -| 加密授权 | 长按点击加密按钮 | | 弹出提示框 | 是 |Pass| -| 验证编辑文件 | 文件已设置编辑权限 | 点击加密文件 | 成功跳转编辑应用 | 是 | Pass| -| 编辑数据保存 | 编辑页面 | 输入文本数据 | 数据保存成功 | 是 | Pass| +# 数据防泄漏测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 |测试结果| +|--------|-------------|----------------------|-------------------------------|--------------------------------|--------------------------------| +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 |Pass| +| 新增普通文件 | 页面显示正常 | 点击新增按钮,输入文件名称,点击确定 | 拉起picker页面,文件命名成功,DLP页面显示新增文件 | 是 |Pass| +| 加密授权 | 长按点击加密按钮 | | 弹出提示框 | 是 |Pass| +| 验证编辑文件 | 文件已设置编辑权限 | 点击加密文件 | 成功跳转编辑应用 | 是 | Pass| +| 编辑数据保存 | 编辑页面 | 输入文本数据 | 数据保存成功 | 是 | Pass| | 验证只读权限 | 文件已设置只读权限 | 点击文件 | 跳转编辑页面,页面置灰 | 是 | Pass| \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/AppScope/app.json5 b/code/SystemFeature/UIExtensionSamples/AppScope/app.json5 index 261c2c73fd9edd532fa8f025b0a5c7023f00770e..c9822f2a973cc6ee7a652a8b48951772125d7e88 100644 --- a/code/SystemFeature/UIExtensionSamples/AppScope/app.json5 +++ b/code/SystemFeature/UIExtensionSamples/AppScope/app.json5 @@ -1,24 +1,24 @@ -/* - * Copyright (c) 2024 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.UIExtension", - "vendor": "example", - "versionCode": 1000000, - "versionName": "1.0.0", - "icon": "$media:app_icon", - "label": "$string:app_name" - } -} +/* + * Copyright (c) 2024 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.UIExtension", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/SystemFeature/UIExtensionSamples/AppScope/resources/base/element/string.json b/code/SystemFeature/UIExtensionSamples/AppScope/resources/base/element/string.json index 4f432049b50469f947110dfb9c44b0d5fe34c0e0..58d68b7a17f4e587f0a1b50f6ab3e6e988e6e93c 100644 --- a/code/SystemFeature/UIExtensionSamples/AppScope/resources/base/element/string.json +++ b/code/SystemFeature/UIExtensionSamples/AppScope/resources/base/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "app_name", - "value": "UIExtensionSamples" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "UIExtensionSamples" + } + ] +} diff --git a/code/SystemFeature/UIExtensionSamples/README_zh.md b/code/SystemFeature/UIExtensionSamples/README_zh.md index bf7c2d31d7c43fd07cf205134e6d7f2aa72dfe75..2c15691135ff2f3340efebfe8c843a4541ba5999 100644 --- a/code/SystemFeature/UIExtensionSamples/README_zh.md +++ b/code/SystemFeature/UIExtensionSamples/README_zh.md @@ -1,152 +1,152 @@ -# 基础能力增强 - -### 介绍 - -本示例使用 [AbilityStartCallback](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-abilityStartCallback.md) , [UIExtensionContent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiExtensionContext.md) , [UIExtensionContentSession](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md) 中的接口进行实现。 - -### 效果预览 - -| 主页面 | 弹出状态Toast | UIExtensionContentSession页面 | UIExtension启动页 | -| :----------------------------------------------: | :---------------------------------------------------: | :--------------------------------------------------: | :----------------------------------------------------: | -| | | | | - -使用说明 - -AbilityStartCallback对应接口 - -1.点击主页面**AbilityStartCallback开发示例**按钮,跳转到'AbilityStartCallback开发示例'界面; - -2.点击**startAbilityByTyp onResult**按钮,拉起'选择音频'窗口,点击返回按钮,返回上级界面; - -3.点击**startAbilityByType onError**按钮,弹出提示'startAbilityByType onError...'信息。 - - - -UIExtensionContext对应接口 - -1.点击主页面**UIExtensionContext开发示例**按钮,跳转到'UIExtensionContext开发示例'界面; - -2.点击**openLink**按钮,启动一个新的UIAbility,点击返回按钮,返回上级界面; - -3.点击**启动UIExtensionAbility**按钮,启动一个新的UIExtensionAbility,在UIExtensionAbility界面上显示reportDrawnCompleted,terminateSelf callback,terminateSelf promise,terminateSelfWithResult callback,terminateSelfWithResult promise接口对应的按钮; - -4.点击**reportDrawnCompleted**按钮,弹出提示'UIExtensionContent.reportDrawnCompleted succeed.'信息; - -5.点击**terminateSelf callback**按钮,关闭UIExtensionAbility,显示'UIExtensionContext开发示例'界面; - -6.点击**启动UIExtensionAbility**按钮,在UIExtensionAbility界面上点击**terminateSelf promise**按钮,关闭UIExtensionAbility,显示'UIExtensionContext开发示例'界面; - -7.点击**启动UIExtensionAbility**按钮,在UIExtensionAbility界面上点击**terminateSelfWithResult callback**按钮,关闭UIExtensionAbility,显 示'UIExtensionContext开发示例'界面; - -8.点击**启动UIExtensionAbility**按钮,在UIExtensionAbility界面上点击**terminateSelfWithResult promise**按钮,关闭UIExtensionAbility,显示'UIExtensionContext开发示例'界面。 - - - -UIExtensionContentSession对应接口 - -1.点击主页面**UIExtensionContentSession开发示例**按钮,跳转到'UIExtensionContentSession开发示例'界面; - -2.点击**启动UIExtensionAbility**按钮,启动一个新的UIExtensionAbility,在UIExtensionAbility界面上显示terminateSelfWithResult callback,terminateSelfWithResult promise,setWindowPrivacyMode callback,setWindowPrivacyMode promise,getUIExtensionWindowProxy接口对应的按钮; - -3.点击**terminateSelfWithResult callback**按钮,关闭UIExtensionAbility,显示'UIExtensionContentSession开发示例'界面; - -4.点击**terminateSelfWithResult promise**按钮,关闭UIExtensionAbility,显示'UIExtensionContentSession开发示例'界面; - -5.点击**setWindowPrivacyMode callback**按钮,弹出提示'UIExtensionContentSession.setWindowPrivacyMode(callback)...'信息; - -6.点击**setWindowPrivacyMode promise**按钮,弹出提示'UIExtensionContentSession.setWindowPrivacyMode(promise)...'信息; - -7.点击**getUIExtensionWindowProxy**按钮,弹出提示'UIExtensionContentSession.getUIExtensionWindowProxy...'信息; - -### 工程目录 - -``` -entry/src/main/ets/ -|---entryability -| |---EntryAbility.ets // 首页的Ability -| |---OpenLinkUIAbility.ets // UIAbility(用于验证新接口使用) -|---pages -| |---Index.ets // 首页 -| |---OpenLinkIndex.ets // 被启动的OpenLink接口的展示页 -|---uiextensionentry -| |---ContextUIExtensionAbility.ets // UIExtensionAbility(用于验证新接口使用) -| |---SessionUIExtensionAbility.ets // UIExtensionAbility(用于验证新接口使用) -|---uiextensionpages -| |---AbilityStartCallback.ets // AbilityStartCallback的接口的展示页 -| |---UIExtensionContentSession.ets // UIExtensionContentSession的接口的展示页 -| |---UIExtensionContentSessionPage.ets // SessionUIExtensionAbility加载的页面 -| |---UIExtensionContext.ets // UIExtensionContext的接口的展示页 -| |---UIExtensionContextPage.ets // ContextUIExtensionAbility加载的页面 - -``` - -### 具体实现 - -* AbilityStartCallback对应接口实现,源码参考[AbilityStartCallback.ets](entry/src/main/ets/uiextensionpages/AbilityStartCallback.ets) - - * onResult接口实现:通过调用startAbilityByType接口,'所有照片'窗口,关闭窗口回调触发onResult接口; - * onError接口实现:通过调用startAbilityByType接口,调用失败触发onError接口; - -* UIExtensionContext对应接口实现,源码参考[UIExtensionContext.ets](entry/src/main/ets/uiextensionpages/UIExtensionContext.ets)和[UIExtensionContextPage.ets](entry/src/main/ets/uiextensionpages/UIExtensionContextPage.ets) - - * openLink接口实现:在被启动的UIAbility的module.json5中配置下列字段: - - -"actions"列表中包含"ohos.want.action.viewData" - - \- "entities"列表中包含"entity.system.browsable" - - \- "uris"列表中包含"scheme"为"https"且"domainVerify"为true的元素 - - 在调用端调用openLink接口,传入对应字段信息,可以拉起对应的UIAbility; - - * reportDrawnCompleted接口实现:通过调用this.context.reportDrawnCompleted口开发者提供打点功能; - - * terminateSelf(Promise)接口实现:通过调用this.context.terminateSelf()接口实现停止Ability自身功能; - - * terminateSelf(Callback)接口实现:通过调用this.context.terminateSelf()接口实现停止Ability自身功能; - - * terminateSelfWithResult(Promise)接口实现:通过调用this.context.terminateSelfWithResult()接口实现停止Ability自身,并将结果返回给调用者的功能; - - * terminateSelfWithResult(Callback)接口实现:通过调用this.context.terminateSelfWithResult()接口实现停止Ability自身,并将结果返回给调用者的功能; - -* UIExtensionContentSession对应接口实现,源码参考[UIExtensionContentSession.ets](entry/src/main/ets/uiextensionpages/UIExtensionContentSession.ets)和[UIExtensionContentSessionPage.ets](entry/src/main/ets/uiextensionpages/UIExtensionContentSessionPage.ets) - - * terminateSelfWithResult(Promise)接口实现:通过调用this.session.terminateSelfWithResult()接口,实现停止UIExtensionContentSession对应的窗口界面对象,并将结果返回给UIExtensionComponent控件的功能; - * terminateSelfWithResult(Callback)接口实现:通过调用this.session.terminateSelfWithResult()接口,实现停止UIExtensionContentSession对应的窗口界面对象,并将结果返回给UIExtensionComponent控件的功能; - * setWindowPrivacyMode(Promise)接口实现:通过调用this.session.setWindowPrivacyMode()接口,实现设置窗口是否为隐私模式功能; - * setWindowPrivacyMode(Callback)接口实现:通过调用this.session.setWindowPrivacyMode()接口,实现设置窗口是否为隐私模式功能; - * getUIExtensionWindowProxy接口实现:通过调用this.session.getUIExtensionWindowProxy()接口,实现获取UIExtension窗口代理功能; - -### 相关权限 - -[ohos.permission.START_INVISIBLE_ABILITY](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md) - -[ohos.permission.PRIVACY_WINDOW](https://gitee.com/openharmony/docs/blob/eb73c9e9dcdd421131f33bb8ed6ddc030881d06f/zh-cn/application-dev/security/permission-list.md) - -### 依赖 - -不涉及。 - -### 约束与限制 - -1.本示例仅支持标准系统上运行,支持设备:RK3568; - -2.本示例为Stage模型,支持API12版本SDK,版本号:5.0.0.31; - -3.本示例涉及使用系统接口:UIAbilityContext.requestModalUIExtension,UIAbilityContext.startAbilityByType -需要手动替换Full SDK才能编译通过; - -4.本示例需要使用DevEco Studio NEXT Developer Beta1 (Build Version: 5.0.3.403, built on June 20, 2024)才可编译运行; - -5.本示例涉及[ohos.permission.START_INVISIBLE_ABILITY](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md)权限为 system_core级别,需要配置高权限签名。 - -### 下载 - -```shell -git init -git config core.sparsecheckout true -echo code/SystemFeature/UIExtensionSamples > .git/info/sparse-checkout -git remote add origin https://gitee.com/openharmony/applications_app_samples.git -git pull origin master -``` - +# 基础能力增强 + +### 介绍 + +本示例使用 [AbilityStartCallback](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-abilityStartCallback.md) , [UIExtensionContent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-inner-application-uiExtensionContext.md) , [UIExtensionContentSession](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-app-ability-uiExtensionContentSession.md) 中的接口进行实现。 + +### 效果预览 + +| 主页面 | 弹出状态Toast | UIExtensionContentSession页面 | UIExtension启动页 | +| :----------------------------------------------: | :---------------------------------------------------: | :--------------------------------------------------: | :----------------------------------------------------: | +| | | | | + +使用说明 + +AbilityStartCallback对应接口 + +1.点击主页面**AbilityStartCallback开发示例**按钮,跳转到'AbilityStartCallback开发示例'界面; + +2.点击**startAbilityByTyp onResult**按钮,拉起'选择音频'窗口,点击返回按钮,返回上级界面; + +3.点击**startAbilityByType onError**按钮,弹出提示'startAbilityByType onError...'信息。 + + + +UIExtensionContext对应接口 + +1.点击主页面**UIExtensionContext开发示例**按钮,跳转到'UIExtensionContext开发示例'界面; + +2.点击**openLink**按钮,启动一个新的UIAbility,点击返回按钮,返回上级界面; + +3.点击**启动UIExtensionAbility**按钮,启动一个新的UIExtensionAbility,在UIExtensionAbility界面上显示reportDrawnCompleted,terminateSelf callback,terminateSelf promise,terminateSelfWithResult callback,terminateSelfWithResult promise接口对应的按钮; + +4.点击**reportDrawnCompleted**按钮,弹出提示'UIExtensionContent.reportDrawnCompleted succeed.'信息; + +5.点击**terminateSelf callback**按钮,关闭UIExtensionAbility,显示'UIExtensionContext开发示例'界面; + +6.点击**启动UIExtensionAbility**按钮,在UIExtensionAbility界面上点击**terminateSelf promise**按钮,关闭UIExtensionAbility,显示'UIExtensionContext开发示例'界面; + +7.点击**启动UIExtensionAbility**按钮,在UIExtensionAbility界面上点击**terminateSelfWithResult callback**按钮,关闭UIExtensionAbility,显 示'UIExtensionContext开发示例'界面; + +8.点击**启动UIExtensionAbility**按钮,在UIExtensionAbility界面上点击**terminateSelfWithResult promise**按钮,关闭UIExtensionAbility,显示'UIExtensionContext开发示例'界面。 + + + +UIExtensionContentSession对应接口 + +1.点击主页面**UIExtensionContentSession开发示例**按钮,跳转到'UIExtensionContentSession开发示例'界面; + +2.点击**启动UIExtensionAbility**按钮,启动一个新的UIExtensionAbility,在UIExtensionAbility界面上显示terminateSelfWithResult callback,terminateSelfWithResult promise,setWindowPrivacyMode callback,setWindowPrivacyMode promise,getUIExtensionWindowProxy接口对应的按钮; + +3.点击**terminateSelfWithResult callback**按钮,关闭UIExtensionAbility,显示'UIExtensionContentSession开发示例'界面; + +4.点击**terminateSelfWithResult promise**按钮,关闭UIExtensionAbility,显示'UIExtensionContentSession开发示例'界面; + +5.点击**setWindowPrivacyMode callback**按钮,弹出提示'UIExtensionContentSession.setWindowPrivacyMode(callback)...'信息; + +6.点击**setWindowPrivacyMode promise**按钮,弹出提示'UIExtensionContentSession.setWindowPrivacyMode(promise)...'信息; + +7.点击**getUIExtensionWindowProxy**按钮,弹出提示'UIExtensionContentSession.getUIExtensionWindowProxy...'信息; + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +| |---EntryAbility.ets // 首页的Ability +| |---OpenLinkUIAbility.ets // UIAbility(用于验证新接口使用) +|---pages +| |---Index.ets // 首页 +| |---OpenLinkIndex.ets // 被启动的OpenLink接口的展示页 +|---uiextensionentry +| |---ContextUIExtensionAbility.ets // UIExtensionAbility(用于验证新接口使用) +| |---SessionUIExtensionAbility.ets // UIExtensionAbility(用于验证新接口使用) +|---uiextensionpages +| |---AbilityStartCallback.ets // AbilityStartCallback的接口的展示页 +| |---UIExtensionContentSession.ets // UIExtensionContentSession的接口的展示页 +| |---UIExtensionContentSessionPage.ets // SessionUIExtensionAbility加载的页面 +| |---UIExtensionContext.ets // UIExtensionContext的接口的展示页 +| |---UIExtensionContextPage.ets // ContextUIExtensionAbility加载的页面 + +``` + +### 具体实现 + +* AbilityStartCallback对应接口实现,源码参考[AbilityStartCallback.ets](entry/src/main/ets/uiextensionpages/AbilityStartCallback.ets) + + * onResult接口实现:通过调用startAbilityByType接口,'所有照片'窗口,关闭窗口回调触发onResult接口; + * onError接口实现:通过调用startAbilityByType接口,调用失败触发onError接口; + +* UIExtensionContext对应接口实现,源码参考[UIExtensionContext.ets](entry/src/main/ets/uiextensionpages/UIExtensionContext.ets)和[UIExtensionContextPage.ets](entry/src/main/ets/uiextensionpages/UIExtensionContextPage.ets) + + * openLink接口实现:在被启动的UIAbility的module.json5中配置下列字段: + + -"actions"列表中包含"ohos.want.action.viewData" + + \- "entities"列表中包含"entity.system.browsable" + + \- "uris"列表中包含"scheme"为"https"且"domainVerify"为true的元素 + + 在调用端调用openLink接口,传入对应字段信息,可以拉起对应的UIAbility; + + * reportDrawnCompleted接口实现:通过调用this.context.reportDrawnCompleted口开发者提供打点功能; + + * terminateSelf(Promise)接口实现:通过调用this.context.terminateSelf()接口实现停止Ability自身功能; + + * terminateSelf(Callback)接口实现:通过调用this.context.terminateSelf()接口实现停止Ability自身功能; + + * terminateSelfWithResult(Promise)接口实现:通过调用this.context.terminateSelfWithResult()接口实现停止Ability自身,并将结果返回给调用者的功能; + + * terminateSelfWithResult(Callback)接口实现:通过调用this.context.terminateSelfWithResult()接口实现停止Ability自身,并将结果返回给调用者的功能; + +* UIExtensionContentSession对应接口实现,源码参考[UIExtensionContentSession.ets](entry/src/main/ets/uiextensionpages/UIExtensionContentSession.ets)和[UIExtensionContentSessionPage.ets](entry/src/main/ets/uiextensionpages/UIExtensionContentSessionPage.ets) + + * terminateSelfWithResult(Promise)接口实现:通过调用this.session.terminateSelfWithResult()接口,实现停止UIExtensionContentSession对应的窗口界面对象,并将结果返回给UIExtensionComponent控件的功能; + * terminateSelfWithResult(Callback)接口实现:通过调用this.session.terminateSelfWithResult()接口,实现停止UIExtensionContentSession对应的窗口界面对象,并将结果返回给UIExtensionComponent控件的功能; + * setWindowPrivacyMode(Promise)接口实现:通过调用this.session.setWindowPrivacyMode()接口,实现设置窗口是否为隐私模式功能; + * setWindowPrivacyMode(Callback)接口实现:通过调用this.session.setWindowPrivacyMode()接口,实现设置窗口是否为隐私模式功能; + * getUIExtensionWindowProxy接口实现:通过调用this.session.getUIExtensionWindowProxy()接口,实现获取UIExtension窗口代理功能; + +### 相关权限 + +[ohos.permission.START_INVISIBLE_ABILITY](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md) + +[ohos.permission.PRIVACY_WINDOW](https://gitee.com/openharmony/docs/blob/eb73c9e9dcdd421131f33bb8ed6ddc030881d06f/zh-cn/application-dev/security/permission-list.md) + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:RK3568; + +2.本示例为Stage模型,支持API12版本SDK,版本号:5.0.0.31; + +3.本示例涉及使用系统接口:UIAbilityContext.requestModalUIExtension,UIAbilityContext.startAbilityByType +需要手动替换Full SDK才能编译通过; + +4.本示例需要使用DevEco Studio NEXT Developer Beta1 (Build Version: 5.0.3.403, built on June 20, 2024)才可编译运行; + +5.本示例涉及[ohos.permission.START_INVISIBLE_ABILITY](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md)权限为 system_core级别,需要配置高权限签名。 + +### 下载 + +```shell +git init +git config core.sparsecheckout true +echo code/SystemFeature/UIExtensionSamples > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` + diff --git a/code/SystemFeature/UIExtensionSamples/build-profile.json5 b/code/SystemFeature/UIExtensionSamples/build-profile.json5 index fbf59fade1f4e9b14b879b1981431e3ed24770d7..6240b415057a91d681b83294f3f1b9339e529f62 100644 --- a/code/SystemFeature/UIExtensionSamples/build-profile.json5 +++ b/code/SystemFeature/UIExtensionSamples/build-profile.json5 @@ -1,53 +1,53 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -{ - "app": { - "signingConfigs": [ - ], - "products": [ - { - "name": "default", - "signingConfig": "default", - "compatibleSdkVersion": 12, - "compileSdkVersion": 12, - "runtimeOS": "OpenHarmony", - } - ], - "buildModeSet": [ - { - "name": "debug", - }, - { - "name": "release" - } - ] - }, - "modules": [ - { - "name": "entry", - "srcPath": "./entry", - "targets": [ - { - "name": "default", - "applyToProducts": [ - "default" - ] - } - ] - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +{ + "app": { + "signingConfigs": [ + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": 12, + "compileSdkVersion": 12, + "runtimeOS": "OpenHarmony", + } + ], + "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/SystemFeature/UIExtensionSamples/entry/build-profile.json5 b/code/SystemFeature/UIExtensionSamples/entry/build-profile.json5 index 6f9f4c8e9e4705b3f9f622e8ec93df1f2e8a7878..ad6ca3258f68a29fd5d9b1a3303ba727c80d07f2 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/build-profile.json5 +++ b/code/SystemFeature/UIExtensionSamples/entry/build-profile.json5 @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "apiType": "stageMode", - "buildOption": { - }, - "buildOptionSet": [ - { - "name": "release", - "arkOptions": { - "obfuscation": { - "ruleOptions": { - "enable": true, - "files": [ - "./obfuscation-rules.txt" - ] - } - } - } - }, - ], - "targets": [ - { - "name": "default" - }, - { - "name": "ohosTest", - } - ] +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": true, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/oh-package.json5 b/code/SystemFeature/UIExtensionSamples/entry/oh-package.json5 index 2959d78c50285f912adb2cdff9f613df9a503b44..248c3b7541a589682a250f86a6d3ecf7414d2d6a 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/oh-package.json5 +++ b/code/SystemFeature/UIExtensionSamples/entry/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "name": "entry", - "version": "1.0.0", - "description": "Please describe the basic information.", - "main": "", - "author": "", - "license": "", - "dependencies": {} -} - +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/EntryAbility.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/EntryAbility.ets index d0e87e9869806b8ff5898db968858cc00f73415e..36296027acea57079d1e6efa8fdbae560cd2af61 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,88 +1,88 @@ -/* - * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const TAG: string = 'EntryAbility'; -const DOMAIN: number = 0xFF00; - -export default class EntryAbility extends UIAbility { - onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); - } - - onDestroy(): void { - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate') - - let windowClass: window.Window | undefined = undefined; - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - let systemBarProperties: window.SystemBarProperties = { - statusBarColor: '#f1f3f5', - navigationBarColor: '#f1f3f5', - }; - try { - windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); - } - }); - - windowStage.loadContent('pages/Index', (err) => { - if (err.code) { - hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); - }); - } - - onWindowStageDestroy(): void { - // Main window is destroyed, release UI related resources - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); - } - - onForeground(): void { - // Ability has brought to foreground - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground'); - } - - onBackground(): void { - // Ability has back to background - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground'); - } -} +/* + * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const TAG: string = 'EntryAbility'; +const DOMAIN: number = 0xFF00; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate') + + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#f1f3f5', + navigationBarColor: '#f1f3f5', + }; + try { + windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); + }); + } catch (exception) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/OpenLinkUIAbility.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/OpenLinkUIAbility.ets index 8a9feb50e6a62fb263af712429dc2e6bb330f60d..69fbba807743445a3d1731fbc49925535d0bd037 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/OpenLinkUIAbility.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/entryability/OpenLinkUIAbility.ets @@ -1,96 +1,96 @@ -/* - * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import { UIAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { window } from '@kit.ArkUI'; - -const TAG: string = '[OpenLinkUIAbility]'; -const DOMAIN: number = 0xFF00; - -export default class OpenLinkUIAbility extends UIAbility { - onCreate() { - hilog.info(DOMAIN, TAG, 'UIExtAbility onCreate'); - } - - onForeground() { - hilog.info(DOMAIN, TAG, `UIExtAbility onForeground`); - } - - onBackground() { - hilog.info(DOMAIN, TAG, `UIExtAbility onBackground`); - } - - onDestroy() { - hilog.info(DOMAIN, TAG, `UIExtAbility onDestroy`); - } - - onWindowStageCreate(windowStage: window.WindowStage): void { - // Main window is created, set main page for this ability - hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - let windowClass: window.Window | undefined = undefined; - windowStage.getMainWindow((err: BusinessError, data) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - let systemBarProperties: window.SystemBarProperties = { - statusBarColor: '#f1f3f5', - navigationBarColor: '#f1f3f5', - }; - try { - windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { - const errCode: number = err.code; - if (errCode) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); - }); - } catch (exception) { - hilog.error(DOMAIN, TAG, - `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); - } - }); - - windowStage.loadContent('pages/OpenLinkIndex', (err) => { - if (err.code) { - hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); - return; - } - hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); - }); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - hilog.info(DOMAIN, TAG, `UIExtAbility onSessionCreate, want: ${JSON.stringify(want)}`); - - let param: Record = { - 'session': session - }; - - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('uiextensionpages/UIExtensionContextPage', storage); - } - - onSessionDestroy(session: UIExtensionContentSession) { - hilog.info(DOMAIN, TAG, `UIExtAbility onSessionDestroy`); - } +/* + * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import { UIAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const TAG: string = '[OpenLinkUIAbility]'; +const DOMAIN: number = 0xFF00; + +export default class OpenLinkUIAbility extends UIAbility { + onCreate() { + hilog.info(DOMAIN, TAG, 'UIExtAbility onCreate'); + } + + onForeground() { + hilog.info(DOMAIN, TAG, `UIExtAbility onForeground`); + } + + onBackground() { + hilog.info(DOMAIN, TAG, `UIExtAbility onBackground`); + } + + onDestroy() { + hilog.info(DOMAIN, TAG, `UIExtAbility onDestroy`); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); + + let windowClass: window.Window | undefined = undefined; + windowStage.getMainWindow((err: BusinessError, data) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, `Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); + return; + } + windowClass = data; + let systemBarProperties: window.SystemBarProperties = { + statusBarColor: '#f1f3f5', + navigationBarColor: '#f1f3f5', + }; + try { + windowClass.setWindowSystemBarProperties(systemBarProperties, (err: BusinessError) => { + const errCode: number = err.code; + if (errCode) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}`); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in setting the system bar properties.'); + }); + } catch (exception) { + hilog.error(DOMAIN, TAG, + `Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}`); + } + }); + + windowStage.loadContent('pages/OpenLinkIndex', (err) => { + if (err.code) { + hilog.error(DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(DOMAIN, TAG, 'Succeeded in loading the content.'); + }); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + hilog.info(DOMAIN, TAG, `UIExtAbility onSessionCreate, want: ${JSON.stringify(want)}`); + + let param: Record = { + 'session': session + }; + + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('uiextensionpages/UIExtensionContextPage', storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + hilog.info(DOMAIN, TAG, `UIExtAbility onSessionDestroy`); + } }; \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/ContextUIExtensionAbility.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/ContextUIExtensionAbility.ets index 021f255cdc691b876e8e6f23a143bf15fd8f7531..c135148158463d40d6f595c95f412d18fb0bce94 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/ContextUIExtensionAbility.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/ContextUIExtensionAbility.ets @@ -1,53 +1,53 @@ -/* - * Copyright (c) 2024 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 { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; - -const TAG: string = '[UIExtAbility]'; -const DOMAIN: number = 0xFF00; - -export default class ContextUIExtensionAbility extends UIExtensionAbility { - onCreate() { - hilog.info(DOMAIN, TAG, 'UIExtAbility onCreate'); - } - - onForeground() { - hilog.info(DOMAIN, TAG, `UIExtAbility onForeground`); - } - - onBackground() { - hilog.info(DOMAIN, TAG, `UIExtAbility onBackground`); - } - - onDestroy() { - hilog.info(DOMAIN, TAG, `UIExtAbility onDestroy`); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - hilog.info(DOMAIN, TAG, `UIExtAbility onSessionCreate, want: ${JSON.stringify(want)}`); - - let param: Record = { - 'session': session - }; - - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('uiextensionpages/UIExtensionContextPage', storage); - } - - onSessionDestroy(session: UIExtensionContentSession) { - hilog.info(DOMAIN, TAG, `UIExtAbility onSessionDestroy`); - } +/* + * Copyright (c) 2024 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 { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[UIExtAbility]'; +const DOMAIN: number = 0xFF00; + +export default class ContextUIExtensionAbility extends UIExtensionAbility { + onCreate() { + hilog.info(DOMAIN, TAG, 'UIExtAbility onCreate'); + } + + onForeground() { + hilog.info(DOMAIN, TAG, `UIExtAbility onForeground`); + } + + onBackground() { + hilog.info(DOMAIN, TAG, `UIExtAbility onBackground`); + } + + onDestroy() { + hilog.info(DOMAIN, TAG, `UIExtAbility onDestroy`); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + hilog.info(DOMAIN, TAG, `UIExtAbility onSessionCreate, want: ${JSON.stringify(want)}`); + + let param: Record = { + 'session': session + }; + + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('uiextensionpages/UIExtensionContextPage', storage); + } + + onSessionDestroy(session: UIExtensionContentSession) { + hilog.info(DOMAIN, TAG, `UIExtAbility onSessionDestroy`); + } }; \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/SessionUIExtensionAbility.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/SessionUIExtensionAbility.ets index 45dc8a7ca4813f23dfb626dadf081c83fcc095af..f5b7fb56e2606b2a8d831283e8ddc713893832e2 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/SessionUIExtensionAbility.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionentry/SessionUIExtensionAbility.ets @@ -1,50 +1,50 @@ -/* - * Copyright (c) 2024 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 { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; - -const TAG: string = 'SessionUIExtensionAbility'; -const DOMAIN: number = 0xFF00; - -export default class SessionUIExtensionAbility extends UIExtensionAbility { - onCreate() { - hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onCreate'); - } - - onDestroy() { - hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onDestroy'); - } - - onSessionCreate(want: Want, session: UIExtensionContentSession) { - let param: Record = { - 'session': session, - 'want': want - }; - - let storage: LocalStorage = new LocalStorage(param); - session.loadContent('uiextensionpages/UIExtensionContentSessionPage', storage); - } - - onForeground() { - hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onForeground'); - } - - onBackground() { - hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onBackground'); - } -} - - +/* + * Copyright (c) 2024 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 { UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit'; + +const TAG: string = 'SessionUIExtensionAbility'; +const DOMAIN: number = 0xFF00; + +export default class SessionUIExtensionAbility extends UIExtensionAbility { + onCreate() { + hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onCreate'); + } + + onDestroy() { + hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onDestroy'); + } + + onSessionCreate(want: Want, session: UIExtensionContentSession) { + let param: Record = { + 'session': session, + 'want': want + }; + + let storage: LocalStorage = new LocalStorage(param); + session.loadContent('uiextensionpages/UIExtensionContentSessionPage', storage); + } + + onForeground() { + hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onForeground'); + } + + onBackground() { + hilog.info(DOMAIN, TAG, 'MyUIExtensionAbility onBackground'); + } +} + + diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/AbilityStartCallback.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/AbilityStartCallback.ets index b49558edfe8b6a19492aaae9810d3d915f15a679..1ca4c834379c4691ada12f01464d5961083d7bed 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/AbilityStartCallback.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/AbilityStartCallback.ets @@ -1,157 +1,157 @@ -/* - * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import { common } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = '[AbilityStartCallback]'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct AbilityStartCallback { - private promptDuration: number = 2000; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.AbilityStartCallback')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityContext_startAbilityByType_onResult')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - - Row() { - Image($r('app.media.ic_arrow')) - .width(24) - .height(24) - .margin({ top: 16, bottom: 16, right: 6 }) - } - } - .id('onResult') - .onClick(() => { - let wantParam: Record = {}; - let abilityStartCallback: common.AbilityStartCallback = { - onError: (code: number, name: string, message: string) => { - let msg = `startAbilityByType onError, code:${code} name:${name} message:${message}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); - }, - onResult: (abilityResult: common.AbilityResult) => { - hilog.info(DOMAIN, TAG, `resultCode:` + abilityResult.resultCode + `bundleName:` + - abilityResult.want?.bundleName); - let msg = `startAbilityByType onResult, - resultCode:${abilityResult.resultCode} bundleName:${abilityResult.want?.bundleName}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); - } - }; - - this.context.startAbilityByType('audioPicker', wantParam, abilityStartCallback, (err: BusinessError) => { - let msg = `startAbilityByType fail, err: ${JSON.stringify(err)}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); - }); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIAbilityContext_startAbilityByType_onError')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('onError') - .onClick(() => { - let wantParam: Record = {}; - let abilityStartCallback: common.AbilityStartCallback = { - onError: (code: number, name: string, message: string) => { - let msg = `startAbilityByType onError, code:${code} name:${name} message:${message}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); - }, - onResult: (abilityResult: common.AbilityResult) => { - hilog.info(DOMAIN, TAG, `resultCode:` + abilityResult.resultCode + `bundleName:` + - abilityResult.want?.bundleName); - let msg = `startAbilityByType onResult, - resultCode:${abilityResult.resultCode} bundleName:${abilityResult.want?.bundleName}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); - } - }; - - this.context.startAbilityByType('error', wantParam, abilityStartCallback, (err: BusinessError) => { - let msg = `startAbilityByType fail, err: ${JSON.stringify(err)}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); - }); - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = '[AbilityStartCallback]'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct AbilityStartCallback { + private promptDuration: number = 2000; + private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.AbilityStartCallback')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityContext_startAbilityByType_onResult')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + + Row() { + Image($r('app.media.ic_arrow')) + .width(24) + .height(24) + .margin({ top: 16, bottom: 16, right: 6 }) + } + } + .id('onResult') + .onClick(() => { + let wantParam: Record = {}; + let abilityStartCallback: common.AbilityStartCallback = { + onError: (code: number, name: string, message: string) => { + let msg = `startAbilityByType onError, code:${code} name:${name} message:${message}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); + }, + onResult: (abilityResult: common.AbilityResult) => { + hilog.info(DOMAIN, TAG, `resultCode:` + abilityResult.resultCode + `bundleName:` + + abilityResult.want?.bundleName); + let msg = `startAbilityByType onResult, + resultCode:${abilityResult.resultCode} bundleName:${abilityResult.want?.bundleName}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); + } + }; + + this.context.startAbilityByType('audioPicker', wantParam, abilityStartCallback, (err: BusinessError) => { + let msg = `startAbilityByType fail, err: ${JSON.stringify(err)}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); + }); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIAbilityContext_startAbilityByType_onError')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('onError') + .onClick(() => { + let wantParam: Record = {}; + let abilityStartCallback: common.AbilityStartCallback = { + onError: (code: number, name: string, message: string) => { + let msg = `startAbilityByType onError, code:${code} name:${name} message:${message}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); + }, + onResult: (abilityResult: common.AbilityResult) => { + hilog.info(DOMAIN, TAG, `resultCode:` + abilityResult.resultCode + `bundleName:` + + abilityResult.want?.bundleName); + let msg = `startAbilityByType onResult, + resultCode:${abilityResult.resultCode} bundleName:${abilityResult.want?.bundleName}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); + } + }; + + this.context.startAbilityByType('error', wantParam, abilityStartCallback, (err: BusinessError) => { + let msg = `startAbilityByType fail, err: ${JSON.stringify(err)}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration, bottom: '11%' }); + }); + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSession.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSession.ets index 0ca668b6513537125f00b5bc7609f17cc84ecc7d..41b4b2edb7f3616bd8a76f995761f32605ac4b86 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSession.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSession.ets @@ -1,114 +1,114 @@ -/* - * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; -import { common, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = '[UIExtensionContentSession]'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct UIExtensionContentSession { - private promptDuration: number = 2000; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContentSession')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionAbilityContext_requestModalUIExtension')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - - Row() { - Image($r('app.media.ic_arrow')) - .width(24) - .height(24) - .margin({ top: 16, bottom: 16, right: 6 }) - } - } - .id('startUIExtensionAbility') - .onClick(() => { - ((): void => { - let want: Want = { - bundleName: 'com.samples.UIExtension', - moduleName: 'entry', - abilityName: 'SessionUIExtensionAbility', - type: 'sys/commonUI', - parameters: { - bundleName: 'com.samples.UIExtension', - 'ability.want.params.uiExtensionType': 'sys/commonUI', - } - }; - - this.context.requestModalUIExtension(want) - .then(() => { - let msg: string = `requestModalUIExtension succeed.`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }) - .catch((err: BusinessError) => { - let msg = `requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }) - })() - }) - } - .height('8.86%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2024 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 { BusinessError } from '@kit.BasicServicesKit'; +import { common, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = '[UIExtensionContentSession]'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct UIExtensionContentSession { + private promptDuration: number = 2000; + private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContentSession')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionAbilityContext_requestModalUIExtension')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + + Row() { + Image($r('app.media.ic_arrow')) + .width(24) + .height(24) + .margin({ top: 16, bottom: 16, right: 6 }) + } + } + .id('startUIExtensionAbility') + .onClick(() => { + ((): void => { + let want: Want = { + bundleName: 'com.samples.UIExtension', + moduleName: 'entry', + abilityName: 'SessionUIExtensionAbility', + type: 'sys/commonUI', + parameters: { + bundleName: 'com.samples.UIExtension', + 'ability.want.params.uiExtensionType': 'sys/commonUI', + } + }; + + this.context.requestModalUIExtension(want) + .then(() => { + let msg: string = `requestModalUIExtension succeed.`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }) + .catch((err: BusinessError) => { + let msg = `requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }) + })() + }) + } + .height('8.86%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSessionPage.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSessionPage.ets index c7f62ce6bb91e07b089bc5c3162da3e2dfdaad39..2211504a21ef881c89ea51e926202efdb5a8d07b 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSessionPage.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContentSessionPage.ets @@ -1,213 +1,213 @@ -/* - * Copyright (c) 2024 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 { UIExtensionContentSession, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; -import uiExtension from '@ohos.arkui.uiExtension'; - -const TAG: string = 'UIExtensionContentSession'; -const DOMAIN: number = 0xFF00; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry -@Component -struct UIExtensionContentSessionPage { - private session: (UIExtensionContentSession | undefined) = storage.get('session'); - private want: (Want | undefined) = storage.get('want'); - private promptDuration: number = 2000; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionAbilityContext')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: '12%', - left: '2%' - }) - } - } - .width('100%') - .height('18%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContentSession_terminateSelfWithResultCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - - } - .id('terminateSelfWithResultCallback') - .onClick(() => { - ((): void => { - this.session?.terminateSelfWithResult({ resultCode: 99, want: this.want }, () => { - hilog.info(DOMAIN, TAG, 'UIExtensionContentSession.terminateSelfWithResult(callback) called'); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContentSession_terminateSelfWithResultPromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('terminateSelfWithResultPromise') - .onClick(() => { - ((): void => { - this.session?.terminateSelfWithResult({ resultCode: 100, want: this.want }).then(() => { - hilog.info(DOMAIN, TAG, 'UIExtensionContentSession.terminateSelfWithResult(promise) called'); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContentSession_setWindowPrivacyModeCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('setWindowPrivacyModeCallback') - .onClick(() => { - ((): void => { - this.session?.setWindowPrivacyMode(true, () => { - let msg = `UIExtensionContentSession.setWindowPrivacyMode(callback) called. isPrivacyMode: true`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContentSession_setWindowPrivacyModePromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('setWindowPrivacyModePromise') - .onClick(() => { - ((): void => { - this.session?.setWindowPrivacyMode(false).then(() => { - let msg = `UIExtensionContentSession.setWindowPrivacyMode(promise) called. isPrivacyMode: false`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContentSession_getUIExtensionWindowProxy')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('getUIExtensionWindowProxy') - .onClick(() => { - ((): void => { - let windowProxy: (uiExtension.WindowProxy | undefined) = this.session?.getUIExtensionWindowProxy(); - let msg = `UIExtensionContentSession.getUIExtensionWindowProxy called. proxy: ${typeof windowProxy}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2024 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 { UIExtensionContentSession, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; +import uiExtension from '@ohos.arkui.uiExtension'; + +const TAG: string = 'UIExtensionContentSession'; +const DOMAIN: number = 0xFF00; +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry +@Component +struct UIExtensionContentSessionPage { + private session: (UIExtensionContentSession | undefined) = storage.get('session'); + private want: (Want | undefined) = storage.get('want'); + private promptDuration: number = 2000; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionAbilityContext')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: '12%', + left: '2%' + }) + } + } + .width('100%') + .height('18%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContentSession_terminateSelfWithResultCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + + } + .id('terminateSelfWithResultCallback') + .onClick(() => { + ((): void => { + this.session?.terminateSelfWithResult({ resultCode: 99, want: this.want }, () => { + hilog.info(DOMAIN, TAG, 'UIExtensionContentSession.terminateSelfWithResult(callback) called'); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContentSession_terminateSelfWithResultPromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('terminateSelfWithResultPromise') + .onClick(() => { + ((): void => { + this.session?.terminateSelfWithResult({ resultCode: 100, want: this.want }).then(() => { + hilog.info(DOMAIN, TAG, 'UIExtensionContentSession.terminateSelfWithResult(promise) called'); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContentSession_setWindowPrivacyModeCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('setWindowPrivacyModeCallback') + .onClick(() => { + ((): void => { + this.session?.setWindowPrivacyMode(true, () => { + let msg = `UIExtensionContentSession.setWindowPrivacyMode(callback) called. isPrivacyMode: true`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContentSession_setWindowPrivacyModePromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('setWindowPrivacyModePromise') + .onClick(() => { + ((): void => { + this.session?.setWindowPrivacyMode(false).then(() => { + let msg = `UIExtensionContentSession.setWindowPrivacyMode(promise) called. isPrivacyMode: false`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContentSession_getUIExtensionWindowProxy')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('getUIExtensionWindowProxy') + .onClick(() => { + ((): void => { + let windowProxy: (uiExtension.WindowProxy | undefined) = this.session?.getUIExtensionWindowProxy(); + let msg = `UIExtensionContentSession.getUIExtensionWindowProxy called. proxy: ${typeof windowProxy}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContext.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContext.ets index 8a52297096014ba354895ad66b4d186ee3b04cf8..d2eabd256585d3d135a5df89606c087806d1b366 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContext.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContext.ets @@ -1,169 +1,169 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import hilog from '@ohos.hilog'; -import { common, OpenLinkOptions } from '@kit.AbilityKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = '[UIExtensionContext]'; -const DOMAIN: number = 0xFF00; - -@Entry -@Component -struct UIExtensionContext { - private promptDuration: number = 2000; - private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - private uiExtContext = getContext(this) as common.UIExtensionContext; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContext')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: 8, - bottom: 8, - left: 12 - }) - } - } - .width('100%') - .height('14.36%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionAbilityContext_openLink')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - Row() { - Image($r('app.media.ic_arrow')) - .width(24) - .height(24) - .margin({ top: 16, bottom: 16, right: 6 }) - } - } - .id('openLink') - .onClick(() => { - ((): void => { - let link: string = 'http://docs.openharmony.cn'; - let openLinkOptions: OpenLinkOptions = { - appLinkingOnly: false - }; - try { - this.uiExtContext.openLink( - link, - openLinkOptions, - (err, result) => { - hilog.info(DOMAIN, TAG, 'openLink callback result:', JSON.stringify(result.resultCode)); - } - ).then(() => { - hilog.info(DOMAIN, TAG, 'open link success'); - }).catch((err: BusinessError) => { - hilog.info(DOMAIN, TAG, 'open link failed, errCode : %{public}s', JSON.stringify(err.code)); - }); - } catch (e) { - hilog.info(DOMAIN, TAG, 'exception occurred, errCode : %{public}s', JSON.stringify(e.code)); - } - - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionAbilityContext_requestModalUIExtension')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - - Row() { - Image($r('app.media.ic_arrow')) - .width(24) - .height(24) - .margin({ top: 16, bottom: 16, right: 6 }) - } - } - .id('startUIExtensionAbility') - .onClick(() => { - ((): void => { - - let want: Want = { - bundleName: 'com.samples.UIExtension', - moduleName: 'entry', - abilityName: 'ContextUIExtensionAbility', - type: 'sys/commonUI', - parameters: { - bundleName: 'com.samples.UIExtension', - 'ability.want.params.uiExtensionType': 'sys/commonUI', - } - }; - - this.context.requestModalUIExtension(want) - .then(() => { - let msg: string = `requestModalUIExtension succeed.`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }) - .catch((err: BusinessError) => { - let msg = `requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }) - - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import hilog from '@ohos.hilog'; +import { common, OpenLinkOptions } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = '[UIExtensionContext]'; +const DOMAIN: number = 0xFF00; + +@Entry +@Component +struct UIExtensionContext { + private promptDuration: number = 2000; + private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + private uiExtContext = getContext(this) as common.UIExtensionContext; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContext')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: 8, + bottom: 8, + left: 12 + }) + } + } + .width('100%') + .height('14.36%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionAbilityContext_openLink')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + Row() { + Image($r('app.media.ic_arrow')) + .width(24) + .height(24) + .margin({ top: 16, bottom: 16, right: 6 }) + } + } + .id('openLink') + .onClick(() => { + ((): void => { + let link: string = 'http://docs.openharmony.cn'; + let openLinkOptions: OpenLinkOptions = { + appLinkingOnly: false + }; + try { + this.uiExtContext.openLink( + link, + openLinkOptions, + (err, result) => { + hilog.info(DOMAIN, TAG, 'openLink callback result:', JSON.stringify(result.resultCode)); + } + ).then(() => { + hilog.info(DOMAIN, TAG, 'open link success'); + }).catch((err: BusinessError) => { + hilog.info(DOMAIN, TAG, 'open link failed, errCode : %{public}s', JSON.stringify(err.code)); + }); + } catch (e) { + hilog.info(DOMAIN, TAG, 'exception occurred, errCode : %{public}s', JSON.stringify(e.code)); + } + + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionAbilityContext_requestModalUIExtension')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + + Row() { + Image($r('app.media.ic_arrow')) + .width(24) + .height(24) + .margin({ top: 16, bottom: 16, right: 6 }) + } + } + .id('startUIExtensionAbility') + .onClick(() => { + ((): void => { + + let want: Want = { + bundleName: 'com.samples.UIExtension', + moduleName: 'entry', + abilityName: 'ContextUIExtensionAbility', + type: 'sys/commonUI', + parameters: { + bundleName: 'com.samples.UIExtension', + 'ability.want.params.uiExtensionType': 'sys/commonUI', + } + }; + + this.context.requestModalUIExtension(want) + .then(() => { + let msg: string = `requestModalUIExtension succeed.`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }) + .catch((err: BusinessError) => { + let msg = `requestModalUIExtension failed, code is ${err.code}, message is ${err.message}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }) + + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContextPage.ets b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContextPage.ets index 08aaa5a8f12963cb6e525d4653699e2d98c192b6..6f01a2ee005614d41877b6f1557aa3044a8fa800 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContextPage.ets +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/ets/uiextensionpages/UIExtensionContextPage.ets @@ -1,222 +1,222 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { common, Want } from '@kit.AbilityKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { promptAction } from '@kit.ArkUI'; - -const TAG: string = 'UIExtensionContent'; -const DOMAIN: number = 0xFF00; -let storage: LocalStorage = LocalStorage.getShared(); - -@Entry -@Component -struct UIExtensionContextPage { - private context = getContext(this) as common.UIExtensionContext; - private want: (Want | undefined) = storage.get('want'); - private promptDuration: number = 2000; - - build() { - Column() { - Row() { - Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionAbilityContext')) - .fontSize(30) - .fontWeight(700) - .textAlign(TextAlign.Start) - .margin({ - top: '12%', - left: '2%' - }) - } - } - .width('100%') - .height('18%') - .justifyContent(FlexAlign.Start) - .backgroundColor($r('app.color.backGrounding')) - - List({ initialIndex: 0 }) { - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContent_reportDrawnCompleted')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('reportDrawnCompleted') - .onClick(() => { - ((): void => { - try { - this.context.reportDrawnCompleted((err) => { - if (err.code) { - // 处理业务逻辑错误 - let msg = - `UIExtensionContent.reportDrawnCompleted failed, code is ${err.code}, message is ${err.message}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - return; - } - // 执行正常业务 - let msg = `UIExtensionContent.reportDrawnCompleted succeed.`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - }); - } catch (err) { - // 捕获同步的参数错误 - let msg = `UIExtensionContent.reportDrawnCompleted failed,err is ${JSON.stringify(err)}`; - hilog.info(DOMAIN, TAG, msg); - promptAction.showToast({ message: msg, duration: this.promptDuration }); - } - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContent_terminateSelfCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('terminateSelfCallback') - .onClick(() => { - ((): void => { - this.context?.terminateSelf(() => { - hilog.info(DOMAIN, TAG, 'UIExtensionContent_terminateSelfCallback(callback) called'); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContent_terminateSelfPromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('terminateSelfPromise') - .onClick(() => { - ((): void => { - this.context?.terminateSelf().then(() => { - hilog.info(DOMAIN, TAG, 'UIExtensionContent_terminateSelfPromise(promise) called'); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContent_terminateSelfWithResultCallback')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('terminateSelfWithResultCallback') - .onClick(() => { - ((): void => { - this.context?.terminateSelfWithResult({ resultCode: 99, want: this.want }, () => { - hilog.info(DOMAIN, TAG, 'UIExtensionContent_terminateSelfWithResultCallback(callback) called'); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - ListItem() { - Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { - Text($r('app.string.UIExtensionContent_terminateSelfWithResultPromise')) - .textAlign(TextAlign.Start) - .fontWeight(500) - .margin({ - top: 17, - bottom: 17, - left: 12 - }) - .fontSize(16) - .width('77.87%') - .height('39.29%') - .fontColor($r('app.color.text_color')) - } - .id('terminateSelfWithResultPromise') - .onClick(() => { - ((): void => { - this.context?.terminateSelfWithResult({ resultCode: 100, want: this.want }).then(() => { - hilog.info(DOMAIN, TAG, 'UIExtensionContent.terminateSelfWithResult(promise) called'); - }) - })() - }) - } - .height('8.45%') - .backgroundColor($r('app.color.start_window_background')) - .borderRadius(24) - .margin({ top: 12, right: 12, left: 12 }) - - } - .height('86%') - .backgroundColor($r('app.color.backGrounding')) - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.backGrounding')) - } +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { common, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { promptAction } from '@kit.ArkUI'; + +const TAG: string = 'UIExtensionContent'; +const DOMAIN: number = 0xFF00; +let storage: LocalStorage = LocalStorage.getShared(); + +@Entry +@Component +struct UIExtensionContextPage { + private context = getContext(this) as common.UIExtensionContext; + private want: (Want | undefined) = storage.get('want'); + private promptDuration: number = 2000; + + build() { + Column() { + Row() { + Flex({ justifyContent: FlexAlign.Start, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionAbilityContext')) + .fontSize(30) + .fontWeight(700) + .textAlign(TextAlign.Start) + .margin({ + top: '12%', + left: '2%' + }) + } + } + .width('100%') + .height('18%') + .justifyContent(FlexAlign.Start) + .backgroundColor($r('app.color.backGrounding')) + + List({ initialIndex: 0 }) { + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContent_reportDrawnCompleted')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('reportDrawnCompleted') + .onClick(() => { + ((): void => { + try { + this.context.reportDrawnCompleted((err) => { + if (err.code) { + // 处理业务逻辑错误 + let msg = + `UIExtensionContent.reportDrawnCompleted failed, code is ${err.code}, message is ${err.message}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + return; + } + // 执行正常业务 + let msg = `UIExtensionContent.reportDrawnCompleted succeed.`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + }); + } catch (err) { + // 捕获同步的参数错误 + let msg = `UIExtensionContent.reportDrawnCompleted failed,err is ${JSON.stringify(err)}`; + hilog.info(DOMAIN, TAG, msg); + promptAction.showToast({ message: msg, duration: this.promptDuration }); + } + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContent_terminateSelfCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('terminateSelfCallback') + .onClick(() => { + ((): void => { + this.context?.terminateSelf(() => { + hilog.info(DOMAIN, TAG, 'UIExtensionContent_terminateSelfCallback(callback) called'); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContent_terminateSelfPromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('terminateSelfPromise') + .onClick(() => { + ((): void => { + this.context?.terminateSelf().then(() => { + hilog.info(DOMAIN, TAG, 'UIExtensionContent_terminateSelfPromise(promise) called'); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContent_terminateSelfWithResultCallback')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('terminateSelfWithResultCallback') + .onClick(() => { + ((): void => { + this.context?.terminateSelfWithResult({ resultCode: 99, want: this.want }, () => { + hilog.info(DOMAIN, TAG, 'UIExtensionContent_terminateSelfWithResultCallback(callback) called'); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + ListItem() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignContent: FlexAlign.Center }) { + Text($r('app.string.UIExtensionContent_terminateSelfWithResultPromise')) + .textAlign(TextAlign.Start) + .fontWeight(500) + .margin({ + top: 17, + bottom: 17, + left: 12 + }) + .fontSize(16) + .width('77.87%') + .height('39.29%') + .fontColor($r('app.color.text_color')) + } + .id('terminateSelfWithResultPromise') + .onClick(() => { + ((): void => { + this.context?.terminateSelfWithResult({ resultCode: 100, want: this.want }).then(() => { + hilog.info(DOMAIN, TAG, 'UIExtensionContent.terminateSelfWithResult(promise) called'); + }) + })() + }) + } + .height('8.45%') + .backgroundColor($r('app.color.start_window_background')) + .borderRadius(24) + .margin({ top: 12, right: 12, left: 12 }) + + } + .height('86%') + .backgroundColor($r('app.color.backGrounding')) + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.backGrounding')) + } } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/module.json5 b/code/SystemFeature/UIExtensionSamples/entry/src/main/module.json5 index 50d3cb2061107f9fc465bbb67d2c350255e9ad85..7484f69d52b2d4b497eea9b6fcec41c39d9b5b85 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/module.json5 +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/module.json5 @@ -1,105 +1,105 @@ -/* - * Copyright (c) 2024 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" - ] - } - ] - }, - { - "name": "OpenLinkUIAbility", - "srcEntry": "./ets/entryability/OpenLinkUIAbility.ets", - "description": "uri", - "icon": "$media:layered_image", - "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:startIcon", - "startWindowBackground": "$color:start_window_background", - "skills": [ - { - "entities": [ - "entity.system.home", - "entity.system.browsable" - ], - "actions": [ - "action.system.home", - "ohos.want.action.viewData" - ], - "uris": [ - { - // scheme可以自定义 - "scheme": "http", - // host须配置关联的域名 - "host": "docs.openharmony.cn", - // path可选,为了避免匹配到多个应用,建议配置该字段 - "path": "" - } - ] - } - ] - } - ], - "extensionAbilities": [ - { - "name": "SessionUIExtensionAbility", - "srcEntry": "./ets/uiextensionentry/SessionUIExtensionAbility.ets", - "type": "sys/commonUI", - "exported": true - }, - { - "name": "ContextUIExtensionAbility", - "srcEntry": "./ets/uiextensionentry/ContextUIExtensionAbility.ets", - "type": "sys/commonUI", - "exported": true, - } - ], - "requestPermissions": [ - { - "name": "ohos.permission.PRIVACY_WINDOW" - }, - { - "name": "ohos.permission.START_INVISIBLE_ABILITY" - } - ] - } +/* + * Copyright (c) 2024 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" + ] + } + ] + }, + { + "name": "OpenLinkUIAbility", + "srcEntry": "./ets/entryability/OpenLinkUIAbility.ets", + "description": "uri", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "entities": [ + "entity.system.home", + "entity.system.browsable" + ], + "actions": [ + "action.system.home", + "ohos.want.action.viewData" + ], + "uris": [ + { + // scheme可以自定义 + "scheme": "http", + // host须配置关联的域名 + "host": "docs.openharmony.cn", + // path可选,为了避免匹配到多个应用,建议配置该字段 + "path": "" + } + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "SessionUIExtensionAbility", + "srcEntry": "./ets/uiextensionentry/SessionUIExtensionAbility.ets", + "type": "sys/commonUI", + "exported": true + }, + { + "name": "ContextUIExtensionAbility", + "srcEntry": "./ets/uiextensionentry/ContextUIExtensionAbility.ets", + "type": "sys/commonUI", + "exported": true, + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.PRIVACY_WINDOW" + }, + { + "name": "ohos.permission.START_INVISIBLE_ABILITY" + } + ] + } } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/element/color.json b/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/element/color.json index 73d32c4c75edccd6fab2427bf3977e8bd43a7e90..6cdb3e3002dfe27880828a3b181946668beef78c 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/element/color.json +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/element/color.json @@ -1,16 +1,16 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - }, - { - "name": "backGrounding", - "value": "#f1f3f5" - }, - { - "name": "text_color", - "value": "#182431" - } - ] +{ + "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/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/profile/backup_config.json b/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/profile/backup_config.json index d742c2f96e7dd0f406f499941f3147345e998f95..78f40ae7c494d71e2482278f359ec790ca73471a 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/profile/backup_config.json +++ b/code/SystemFeature/UIExtensionSamples/entry/src/main/resources/base/profile/backup_config.json @@ -1,3 +1,3 @@ -{ - "allowToBackupRestore": true +{ + "allowToBackupRestore": true } \ No newline at end of file diff --git a/code/SystemFeature/UIExtensionSamples/entry/src/ohosTest/module.json5 b/code/SystemFeature/UIExtensionSamples/entry/src/ohosTest/module.json5 index 20226beba81da3bcfe437c01ea84dbe96e74497b..944ed99859bbc89eac2d57af2b3600881bb5a47c 100644 --- a/code/SystemFeature/UIExtensionSamples/entry/src/ohosTest/module.json5 +++ b/code/SystemFeature/UIExtensionSamples/entry/src/ohosTest/module.json5 @@ -1,26 +1,26 @@ -/* - * Copyright (c) 2024 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 - } -} +/* + * Copyright (c) 2024 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/SystemFeature/UIExtensionSamples/hvigor/hvigor-config.json5 b/code/SystemFeature/UIExtensionSamples/hvigor/hvigor-config.json5 index e0bd0d82696bcd6337fc106180834b6a9ac56a5d..06b2783670a348f95533b352c1ceda909a842bbc 100644 --- a/code/SystemFeature/UIExtensionSamples/hvigor/hvigor-config.json5 +++ b/code/SystemFeature/UIExtensionSamples/hvigor/hvigor-config.json5 @@ -1,22 +1,22 @@ -{ - "modelVersion": "5.0.0", - "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*/ - } -} +{ + "modelVersion": "5.0.0", + "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/SystemFeature/UIExtensionSamples/oh-package.json5 b/code/SystemFeature/UIExtensionSamples/oh-package.json5 index 11d5feca881263b1e2ebcdf7faee582123a82ca6..ebdda7e54d1c41e952f1c7f6993c6d15ea3d146d 100644 --- a/code/SystemFeature/UIExtensionSamples/oh-package.json5 +++ b/code/SystemFeature/UIExtensionSamples/oh-package.json5 @@ -1,10 +1,10 @@ -{ - "modelVersion": "5.0.0", - "description": "Please describe the basic information.", - "dependencies": { - }, - "devDependencies": { - "@ohos/hypium": "1.0.18", - "@ohos/hamock": "1.0.0" - } -} +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.18", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/layoutAnimationSample/LayoutAnimationSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/layoutAnimationSample/LayoutAnimationSample.ets index 093f2ceddb7d8fbfcc0e8916242b6cdf2c206ae5..695d8e759764d4c944457c2d4566c984956a22f6 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/layoutAnimationSample/LayoutAnimationSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/layoutAnimationSample/LayoutAnimationSample.ets @@ -1,202 +1,202 @@ -/* - * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 { TitleBar } from '../../../../common/TitleBar' -import { IntroductionTitle } from '../../../../common/IntroductionTitle' - -@Extend(Column) function columnStyle() { - .height(150) - .width('100%') - .padding(12) - .borderRadius(24) - .backgroundColor(Color.White) - .margin({ bottom: 12 }) -} - -@Extend(Text) function textStyle() { - .fontColor(Color.White) - .size({ width: 100, height: 100 }) - .margin(5) -} - -@Entry -@Component -struct LayoutAnimationSample { - @State mPadding: number = 5; - @State mMargin: number = 5; - @State mSize: number = 100; - @State mPositionX: number = 10; - @State mPositionY: number = 0; - @State mAlignment: Alignment = Alignment.Center; - @State mDirection: Direction = Direction.Rtl; - @State mColor: Color = Color.Pink; - @State mHorizontalAlign: HorizontalAlign = HorizontalAlign.Start; - intervalID: number | null = null; - - onPageShow() { - this.intervalID = setInterval(() => { - animateTo({ duration: 2000 }, () => { - this.mColor = this.mColor == Color.Pink ? Color.Orange : Color.Pink - this.mPadding = this.mPadding == 5 ? 20 : 5 - this.mMargin = this.mMargin == 5 ? 20 : 5 - this.mSize = this.mSize == 50 ? 100 : 50 - this.mPositionX = this.mPositionX == 10 ? 50 : 10 - this.mAlignment = this.mAlignment == Alignment.Center ? Alignment.TopStart : Alignment.Center - this.mDirection = this.mDirection == Direction.Rtl ? Direction.Ltr : Direction.Rtl - this.mHorizontalAlign = this.mHorizontalAlign == HorizontalAlign.Start ? HorizontalAlign.Center : HorizontalAlign.Start - }) - - }, 3000); - } - - onPageHide() { - clearInterval(this.intervalID) - } - - build() { - Column() { - TitleBar({ title: $r('app.string.layout_animation_expansion') }) - Scroll() { - Column() { - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_align') }) - Column() { - Text($r('app.string.layout_animation_expansion_align')) - .textStyle() - .backgroundColor(this.mColor) - .align(this.mAlignment) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_size') }) - Column() { - Text() - .textStyle() - .size({ width: this.mSize, height: this.mSize }) - .backgroundColor(this.mColor) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_padding') }) - Column() { - Column() { - Text() - .size({ width: '100%', height: '100%' }) - .backgroundColor($r('app.color.white')) - } - .size({ width: 100, height: 100 }) - .margin(5) - .padding(this.mPadding) - .backgroundColor(this.mColor) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_margin') }) - Column() { - Row() { - ForEach(['1', '2', '3'], (item: string) => { - Text(item) - .textStyle() - .margin(this.mMargin) - .backgroundColor(this.mColor) - }) - } - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_direction') }) - Column() { - Row() { - ForEach(['1', '2', '3'], (item: string) => { - Text(item) - .textStyle() - .backgroundColor(this.mColor) - }) - } - .direction(this.mDirection) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_offset') }) - Column() { - Text() - .textStyle() - .offset({ - x: this.mPositionX, - y: this.mPositionY - }) - .backgroundColor(this.mColor) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_position') }) - Column() { - Text() - .textStyle() - .position({ - x: this.mPositionX, - y: this.mPositionY - }) - .backgroundColor(this.mColor) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_markAnchor') }) - Column() { - Text() - .textStyle() - .markAnchor({ - x: this.mPositionX, - y: this.mPositionY - }) - .backgroundColor(this.mColor) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_alignRules') }) - Column() { - RelativeContainer() { - Text() - .size({ width: 100, height: 100 }) - .alignRules({ - top: { - anchor: "__container__", - align: VerticalAlign.Top - }, - left: { - anchor: "__container__", - align: this.mHorizontalAlign - } - }) - .id('text1') - .backgroundColor(this.mColor) - } - .margin({ top: 10 }) - .size({ width: 300, height: 100 }) - .border({ width: 2, color: $r('app.color.radio_response_region_color') }) - } - .columnStyle() - - .margin({ bottom: 80 }) - } - .padding({ left: 12, right: 12 }) - .constraintSize({ minHeight: '100%' }) - - } - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 { TitleBar } from '../../../../common/TitleBar' +import { IntroductionTitle } from '../../../../common/IntroductionTitle' + +@Extend(Column) function columnStyle() { + .height(150) + .width('100%') + .padding(12) + .borderRadius(24) + .backgroundColor(Color.White) + .margin({ bottom: 12 }) +} + +@Extend(Text) function textStyle() { + .fontColor(Color.White) + .size({ width: 100, height: 100 }) + .margin(5) +} + +@Entry +@Component +struct LayoutAnimationSample { + @State mPadding: number = 5; + @State mMargin: number = 5; + @State mSize: number = 100; + @State mPositionX: number = 10; + @State mPositionY: number = 0; + @State mAlignment: Alignment = Alignment.Center; + @State mDirection: Direction = Direction.Rtl; + @State mColor: Color = Color.Pink; + @State mHorizontalAlign: HorizontalAlign = HorizontalAlign.Start; + intervalID: number | null = null; + + onPageShow() { + this.intervalID = setInterval(() => { + animateTo({ duration: 2000 }, () => { + this.mColor = this.mColor == Color.Pink ? Color.Orange : Color.Pink + this.mPadding = this.mPadding == 5 ? 20 : 5 + this.mMargin = this.mMargin == 5 ? 20 : 5 + this.mSize = this.mSize == 50 ? 100 : 50 + this.mPositionX = this.mPositionX == 10 ? 50 : 10 + this.mAlignment = this.mAlignment == Alignment.Center ? Alignment.TopStart : Alignment.Center + this.mDirection = this.mDirection == Direction.Rtl ? Direction.Ltr : Direction.Rtl + this.mHorizontalAlign = this.mHorizontalAlign == HorizontalAlign.Start ? HorizontalAlign.Center : HorizontalAlign.Start + }) + + }, 3000); + } + + onPageHide() { + clearInterval(this.intervalID) + } + + build() { + Column() { + TitleBar({ title: $r('app.string.layout_animation_expansion') }) + Scroll() { + Column() { + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_align') }) + Column() { + Text($r('app.string.layout_animation_expansion_align')) + .textStyle() + .backgroundColor(this.mColor) + .align(this.mAlignment) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_size') }) + Column() { + Text() + .textStyle() + .size({ width: this.mSize, height: this.mSize }) + .backgroundColor(this.mColor) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_padding') }) + Column() { + Column() { + Text() + .size({ width: '100%', height: '100%' }) + .backgroundColor($r('app.color.white')) + } + .size({ width: 100, height: 100 }) + .margin(5) + .padding(this.mPadding) + .backgroundColor(this.mColor) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_margin') }) + Column() { + Row() { + ForEach(['1', '2', '3'], (item: string) => { + Text(item) + .textStyle() + .margin(this.mMargin) + .backgroundColor(this.mColor) + }) + } + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_direction') }) + Column() { + Row() { + ForEach(['1', '2', '3'], (item: string) => { + Text(item) + .textStyle() + .backgroundColor(this.mColor) + }) + } + .direction(this.mDirection) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_offset') }) + Column() { + Text() + .textStyle() + .offset({ + x: this.mPositionX, + y: this.mPositionY + }) + .backgroundColor(this.mColor) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_position') }) + Column() { + Text() + .textStyle() + .position({ + x: this.mPositionX, + y: this.mPositionY + }) + .backgroundColor(this.mColor) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_markAnchor') }) + Column() { + Text() + .textStyle() + .markAnchor({ + x: this.mPositionX, + y: this.mPositionY + }) + .backgroundColor(this.mColor) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.layout_animation_expansion_alignRules') }) + Column() { + RelativeContainer() { + Text() + .size({ width: 100, height: 100 }) + .alignRules({ + top: { + anchor: "__container__", + align: VerticalAlign.Top + }, + left: { + anchor: "__container__", + align: this.mHorizontalAlign + } + }) + .id('text1') + .backgroundColor(this.mColor) + } + .margin({ top: 10 }) + .size({ width: 300, height: 100 }) + .border({ width: 2, color: $r('app.color.radio_response_region_color') }) + } + .columnStyle() + + .margin({ bottom: 80 }) + } + .padding({ left: 12, right: 12 }) + .constraintSize({ minHeight: '100%' }) + + } + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sideBarTransitionSample/SideBarTransitionSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sideBarTransitionSample/SideBarTransitionSample.ets index 3365d4341ec9ae4c363f7d634d797c77086837a5..a0af4fd5905e7d208154240657c89642a7424a20 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sideBarTransitionSample/SideBarTransitionSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sideBarTransitionSample/SideBarTransitionSample.ets @@ -1,85 +1,85 @@ -/* - * Copyright (c) 2023 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 { ChangePanel } from './ChangePanel' -import { TitleBar } from '../../../../common/TitleBar' - -@Extend(Column) function columnStyle() { - .padding(16) - .borderRadius(24) - .backgroundColor(Color.White) - .margin({ top: 20, left: 20, right: 20, bottom: 20 }) -} - -@Entry -@Component -struct SideBarTransitionSample { - @State arr: number[] = [1, 2, 3] - @State current: number = 1 - @State mShowSideBar: boolean = false - @State mSideBarContainerType: SideBarContainerType = SideBarContainerType.Embed - - build() { - Column() { - TitleBar({ title: $r('app.string.side_bar_effects_title') }) - SideBarContainer(this.mSideBarContainerType) { - Column() { - ForEach(this.arr, (item: number, index: number) => { - Column({ space: 5 }) { - Image($r('app.media.icon')).width(64).height(64) - Text(item + '') - .fontSize(25) - .fontColor(this.current === item ? $r('app.color.tab_bar_select') : $r('app.color.tab_bar_unselect')) - } - .onClick(() => { - this.current = item - }) - }, (item: number) => item.toString()) - } - .visibility(this.mShowSideBar ? Visibility.Visible : Visibility.Hidden) - .width('100%') - .transition(TransitionEffect.opacity(0)) - .justifyContent(FlexAlign.SpaceEvenly) - .backgroundColor($r('app.color.contentArea_background_color')) - - Column() { - Column() { - Button(this.mShowSideBar ? $r('app.string.hide_side_bar') : $r('app.string.show_side_bar')) - .onClick(() => { - animateTo({ duration: 2000 }, () => { - this.mShowSideBar = !this.mShowSideBar - }) - }) - .id('hide_or_show_sideBar') - .margin({ bottom: 5 }) - ChangePanel({ - mSideBarContainerType: $mSideBarContainerType - }) - } - .columnStyle() - } - } - .showControlButton(false) - .showSideBar(this.mShowSideBar) - .sideBarWidth(150) - .minSideBarWidth(50) - .maxSideBarWidth(300) - } - .size({ width: '100%', height: '100%' }) - .justifyContent(FlexAlign.Center) - .backgroundColor($r('app.color.background_shallow_grey')) - } -} +/* + * Copyright (c) 2023 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 { ChangePanel } from './ChangePanel' +import { TitleBar } from '../../../../common/TitleBar' + +@Extend(Column) function columnStyle() { + .padding(16) + .borderRadius(24) + .backgroundColor(Color.White) + .margin({ top: 20, left: 20, right: 20, bottom: 20 }) +} + +@Entry +@Component +struct SideBarTransitionSample { + @State arr: number[] = [1, 2, 3] + @State current: number = 1 + @State mShowSideBar: boolean = false + @State mSideBarContainerType: SideBarContainerType = SideBarContainerType.Embed + + build() { + Column() { + TitleBar({ title: $r('app.string.side_bar_effects_title') }) + SideBarContainer(this.mSideBarContainerType) { + Column() { + ForEach(this.arr, (item: number, index: number) => { + Column({ space: 5 }) { + Image($r('app.media.icon')).width(64).height(64) + Text(item + '') + .fontSize(25) + .fontColor(this.current === item ? $r('app.color.tab_bar_select') : $r('app.color.tab_bar_unselect')) + } + .onClick(() => { + this.current = item + }) + }, (item: number) => item.toString()) + } + .visibility(this.mShowSideBar ? Visibility.Visible : Visibility.Hidden) + .width('100%') + .transition(TransitionEffect.opacity(0)) + .justifyContent(FlexAlign.SpaceEvenly) + .backgroundColor($r('app.color.contentArea_background_color')) + + Column() { + Column() { + Button(this.mShowSideBar ? $r('app.string.hide_side_bar') : $r('app.string.show_side_bar')) + .onClick(() => { + animateTo({ duration: 2000 }, () => { + this.mShowSideBar = !this.mShowSideBar + }) + }) + .id('hide_or_show_sideBar') + .margin({ bottom: 5 }) + ChangePanel({ + mSideBarContainerType: $mSideBarContainerType + }) + } + .columnStyle() + } + } + .showControlButton(false) + .showSideBar(this.mShowSideBar) + .sideBarWidth(150) + .minSideBarWidth(50) + .maxSideBarWidth(300) + } + .size({ width: '100%', height: '100%' }) + .justifyContent(FlexAlign.Center) + .backgroundColor($r('app.color.background_shallow_grey')) + } +} diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sizeTransitionSample/SizeTransitionSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sizeTransitionSample/SizeTransitionSample.ets index 9f8955da764ab38313c9673d1e682f91e871eba7..7dfcb409a1bf7fe33c7805eee8bcccee8dc8ffaa 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sizeTransitionSample/SizeTransitionSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/animations/TransitionAnimations/sizeTransitionSample/SizeTransitionSample.ets @@ -1,193 +1,193 @@ -/* - * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 { getStringData } from '../../../../data/ResourceDataHandle' -import { TitleBar } from '../../../../common/TitleBar' -import { IntroductionTitle } from '../../../../common/IntroductionTitle' - -@Extend(Column) function columnStyle() { - .height(150) - .width('100%') - .padding(12) - .borderRadius(24) - .backgroundColor(Color.White) - .margin({ bottom: 12 }) -} - -@AnimatableExtend(Text) function animatableFontSize(size: number) { - .fontSize(size) -} - -@Entry -@Component -struct SizeTransitionSample { - @State mWidth: number = 400 - @State mTabIndex: number = 0 - @State mVisible: Visibility = Visibility.Visible - @State mFontSize: number = 20 - private intervalID = 0 - - @Builder tabbarTitle(name: Resource, index: number) { - Stack() { - Text(name) - .fontSize(22) - .fontColor(this.mTabIndex === index ? $r('app.color.title_colorone') : $r('app.color.title_colortwo')) - - if (this.mTabIndex === index) { - Row() - .backgroundColor($r('app.color.title_colorone')) - .width(200) - .height(2) - .position({ y: 48 }) - } - }.width(200) - .height(56) - } - - onPageShow() { - this.intervalID = setInterval(() => { - animateTo({ duration: 2000 }, () => { - this.mWidth = (this.mWidth == 400 || this.mVisible == Visibility.Hidden) ? 200 : 400 - if (this.mVisible == Visibility.Visible) { - this.mFontSize = this.mFontSize == 20 ? 40 : 20 - } - }) - setTimeout(() => { - animateTo({ duration: 2000 }, () => { - if (this.mWidth == 200 && this.mVisible == Visibility.Visible) { - this.mVisible = Visibility.Hidden - } - else if (this.mVisible == Visibility.Hidden) { - this.mVisible = Visibility.Visible - } - }) - }, 2000); - }, 4000); - } - - onPageHide() { - clearInterval(this.intervalID) - } - - build() { - Column() { - TitleBar({ title: $r('app.string.size_transition_expansion') }) - Scroll() { - Column() { - IntroductionTitle({ introduction: $r('app.string.size_transition_flex') }) - Column() { - Flex() { - Text($r('app.string.size_transition_flex')) - } - .visibility(this.mVisible) - .width(this.mWidth) - .backgroundColor($r('app.color.radio_response_region_color')) - .height(100) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.size_transition_grid_item') }) - Column() { - Grid() { - ForEach([1, 2, 3], (item: number) => { - GridItem() { - Text(getStringData($r('app.string.size_transition_grid_item')) + item) - }.margin(5).width(100) - }) - } - .visibility(this.mVisible) - .margin(5) - .width(this.mWidth) - .backgroundColor($r('app.color.radio_response_region_color')) - .height(100) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.size_transition_list_item') }) - Column() { - List() { - ForEach([1, 2, 3, 4], (item: number) => { - ListItem() { - Text(getStringData($r('app.string.size_transition_list_item')) + item) - }.margin(5).width(100) - }) - } - .visibility(this.mVisible) - .listDirection(Axis.Horizontal) - .margin(5) - .width(this.mWidth) - .backgroundColor($r('app.color.radio_response_region_color')) - .height(100) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.size_transition_swiper_item') }) - Column() { - Swiper() { - ForEach([1, 2, 3, 4], (item: number) => { - Text(getStringData($r('app.string.size_transition_swiper_item')) + item) - }) - } - .visibility(this.mVisible) - .margin(5) - .width(this.mWidth) - .backgroundColor($r('app.color.radio_response_region_color')) - .height(100) - } - .columnStyle() - - IntroductionTitle({ introduction: ($r('app.string.size_transition_expansion_tabContent')) }) - Column() { - Tabs() { - ForEach([0, 1, 2], (item: number) => { - TabContent() { - Text(getStringData($r('app.string.size_transition_expansion_tabContent')) + item) - } - .backgroundColor($r('app.color.select_option_bg_color')) - .tabBar(this.tabbarTitle($r('app.string.size_transition_expansion_tabContent'), item)) - }) - } - .visibility(this.mVisible) - .margin(5) - .width(this.mWidth) - .backgroundColor($r('app.color.radio_response_region_color')) - .height(100) - .onChange((index) => { - this.mTabIndex = index - }) - } - .columnStyle() - - IntroductionTitle({ introduction: $r('app.string.size_transition_font_size') }) - Column() { - Text(getStringData($r('app.string.size_transition_font_size')) + ': ' + this.mFontSize) - .margin(5) - .visibility(this.mVisible) - .animatableFontSize(this.mFontSize) - .backgroundColor($r('app.color.radio_response_region_color')) - .height(100) - .width(200) - } - .columnStyle() - .margin({ bottom: 80 }) - } - .constraintSize({ minWidth: '100%' }) - } - } - .width('100%') - .height('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 { getStringData } from '../../../../data/ResourceDataHandle' +import { TitleBar } from '../../../../common/TitleBar' +import { IntroductionTitle } from '../../../../common/IntroductionTitle' + +@Extend(Column) function columnStyle() { + .height(150) + .width('100%') + .padding(12) + .borderRadius(24) + .backgroundColor(Color.White) + .margin({ bottom: 12 }) +} + +@AnimatableExtend(Text) function animatableFontSize(size: number) { + .fontSize(size) +} + +@Entry +@Component +struct SizeTransitionSample { + @State mWidth: number = 400 + @State mTabIndex: number = 0 + @State mVisible: Visibility = Visibility.Visible + @State mFontSize: number = 20 + private intervalID = 0 + + @Builder tabbarTitle(name: Resource, index: number) { + Stack() { + Text(name) + .fontSize(22) + .fontColor(this.mTabIndex === index ? $r('app.color.title_colorone') : $r('app.color.title_colortwo')) + + if (this.mTabIndex === index) { + Row() + .backgroundColor($r('app.color.title_colorone')) + .width(200) + .height(2) + .position({ y: 48 }) + } + }.width(200) + .height(56) + } + + onPageShow() { + this.intervalID = setInterval(() => { + animateTo({ duration: 2000 }, () => { + this.mWidth = (this.mWidth == 400 || this.mVisible == Visibility.Hidden) ? 200 : 400 + if (this.mVisible == Visibility.Visible) { + this.mFontSize = this.mFontSize == 20 ? 40 : 20 + } + }) + setTimeout(() => { + animateTo({ duration: 2000 }, () => { + if (this.mWidth == 200 && this.mVisible == Visibility.Visible) { + this.mVisible = Visibility.Hidden + } + else if (this.mVisible == Visibility.Hidden) { + this.mVisible = Visibility.Visible + } + }) + }, 2000); + }, 4000); + } + + onPageHide() { + clearInterval(this.intervalID) + } + + build() { + Column() { + TitleBar({ title: $r('app.string.size_transition_expansion') }) + Scroll() { + Column() { + IntroductionTitle({ introduction: $r('app.string.size_transition_flex') }) + Column() { + Flex() { + Text($r('app.string.size_transition_flex')) + } + .visibility(this.mVisible) + .width(this.mWidth) + .backgroundColor($r('app.color.radio_response_region_color')) + .height(100) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.size_transition_grid_item') }) + Column() { + Grid() { + ForEach([1, 2, 3], (item: number) => { + GridItem() { + Text(getStringData($r('app.string.size_transition_grid_item')) + item) + }.margin(5).width(100) + }) + } + .visibility(this.mVisible) + .margin(5) + .width(this.mWidth) + .backgroundColor($r('app.color.radio_response_region_color')) + .height(100) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.size_transition_list_item') }) + Column() { + List() { + ForEach([1, 2, 3, 4], (item: number) => { + ListItem() { + Text(getStringData($r('app.string.size_transition_list_item')) + item) + }.margin(5).width(100) + }) + } + .visibility(this.mVisible) + .listDirection(Axis.Horizontal) + .margin(5) + .width(this.mWidth) + .backgroundColor($r('app.color.radio_response_region_color')) + .height(100) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.size_transition_swiper_item') }) + Column() { + Swiper() { + ForEach([1, 2, 3, 4], (item: number) => { + Text(getStringData($r('app.string.size_transition_swiper_item')) + item) + }) + } + .visibility(this.mVisible) + .margin(5) + .width(this.mWidth) + .backgroundColor($r('app.color.radio_response_region_color')) + .height(100) + } + .columnStyle() + + IntroductionTitle({ introduction: ($r('app.string.size_transition_expansion_tabContent')) }) + Column() { + Tabs() { + ForEach([0, 1, 2], (item: number) => { + TabContent() { + Text(getStringData($r('app.string.size_transition_expansion_tabContent')) + item) + } + .backgroundColor($r('app.color.select_option_bg_color')) + .tabBar(this.tabbarTitle($r('app.string.size_transition_expansion_tabContent'), item)) + }) + } + .visibility(this.mVisible) + .margin(5) + .width(this.mWidth) + .backgroundColor($r('app.color.radio_response_region_color')) + .height(100) + .onChange((index) => { + this.mTabIndex = index + }) + } + .columnStyle() + + IntroductionTitle({ introduction: $r('app.string.size_transition_font_size') }) + Column() { + Text(getStringData($r('app.string.size_transition_font_size')) + ': ' + this.mFontSize) + .margin(5) + .visibility(this.mVisible) + .animatableFontSize(this.mFontSize) + .backgroundColor($r('app.color.radio_response_region_color')) + .height(100) + .width(200) + } + .columnStyle() + .margin({ bottom: 80 }) + } + .constraintSize({ minWidth: '100%' }) + } + } + .width('100%') + .height('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/informationPresentationAndDynamicEffects/listSample/ListSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/informationPresentationAndDynamicEffects/listSample/ListSample.ets old mode 100755 new mode 100644 index 59709cdf4af0a9c8fd135572bc11a3ab8076aa48..4901d4fb337c4534399455bfb03994e27a181523 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/informationPresentationAndDynamicEffects/listSample/ListSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/informationPresentationAndDynamicEffects/listSample/ListSample.ets @@ -1,86 +1,86 @@ -/* - * Copyright (c) 2023 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 { TitleBar } from '../../../../common/TitleBar' - -@Extend(Text) function leftTitleStyle() { - .fontColor($r('app.color.font_color_shallow')) - .fontSize(18) - .height(22) - .alignSelf(ItemAlign.Start) - .margin({ left: 12, bottom: 8 }) -} - -@Extend(Column) function cardStyle() { - .backgroundColor(Color.White) - .borderRadius(24) - .width('100%') - .padding(12) - .margin({ bottom: 12 }) -} - -@Entry -@Component -struct ListSample { - @State arr: number[] = [0, 1, 2, 3, 4] - - @Builder itemEnd() { - Row() { - Button('Delete').margin('4vp') - Button('Set').margin('4vp') - }.padding('4vp').justifyContent(FlexAlign.SpaceEvenly) - } - - build() { - Column() { - TitleBar({ title: $r('app.string.list') }) - Text($r('app.string.delete_list_item')) - .leftTitleStyle() - Column() { - List({ space: 10 }) { - ForEach(this.arr, (item: number) => { - ListItem() { - Text('item' + item) - .width('100%') - .height(100) - .fontSize(16) - .textAlign(TextAlign.Center) - .borderRadius(10) - .backgroundColor(0xFFFFFF) - } - .transition({ type: TransitionType.Delete, opacity: 0 }) - .swipeAction({ - end: { - onAction: () => { - animateTo({ duration: 1000 }, () => { - let index = this.arr.indexOf(item) - this.arr.splice(index, 1) - }) - }, - actionAreaDistance: 56, - } - }) - }, (item: number) => item.toString()) - } - } - .cardStyle() - .width('100%') - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.background_light_gray')) - .padding({ left: 20, right: 20 }) - } +/* + * Copyright (c) 2023 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 { TitleBar } from '../../../../common/TitleBar' + +@Extend(Text) function leftTitleStyle() { + .fontColor($r('app.color.font_color_shallow')) + .fontSize(18) + .height(22) + .alignSelf(ItemAlign.Start) + .margin({ left: 12, bottom: 8 }) +} + +@Extend(Column) function cardStyle() { + .backgroundColor(Color.White) + .borderRadius(24) + .width('100%') + .padding(12) + .margin({ bottom: 12 }) +} + +@Entry +@Component +struct ListSample { + @State arr: number[] = [0, 1, 2, 3, 4] + + @Builder itemEnd() { + Row() { + Button('Delete').margin('4vp') + Button('Set').margin('4vp') + }.padding('4vp').justifyContent(FlexAlign.SpaceEvenly) + } + + build() { + Column() { + TitleBar({ title: $r('app.string.list') }) + Text($r('app.string.delete_list_item')) + .leftTitleStyle() + Column() { + List({ space: 10 }) { + ForEach(this.arr, (item: number) => { + ListItem() { + Text('item' + item) + .width('100%') + .height(100) + .fontSize(16) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0xFFFFFF) + } + .transition({ type: TransitionType.Delete, opacity: 0 }) + .swipeAction({ + end: { + onAction: () => { + animateTo({ duration: 1000 }, () => { + let index = this.arr.indexOf(item) + this.arr.splice(index, 1) + }) + }, + actionAreaDistance: 56, + } + }) + }, (item: number) => item.toString()) + } + } + .cardStyle() + .width('100%') + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.background_light_gray')) + .padding({ left: 20, right: 20 }) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/navigation/navRouterSample/NavRouterSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/navigation/navRouterSample/NavRouterSample.ets old mode 100755 new mode 100644 index e0dae1fb7c6fb4a20b7e2da1ebe62d67df7933f5..210b601152a77776163505fddecc57aa3e05b670 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/navigation/navRouterSample/NavRouterSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/navigation/navRouterSample/NavRouterSample.ets @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2023 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 { TitleBar } from '../../../../common/TitleBar' -import { getStringData } from '../../../../data/ResourceDataHandle' - -@Entry -@Component -struct NavRouterSample { - private arr: number[] = [1, 2, 3]; - - build() { - Column() { - TitleBar({ title: $r('app.string.navRouter_title') }) - Navigation() { - - List({ space: 12 }) { - ForEach(this.arr, (item: number) => { - ListItem() { - NavRouter() { - Text(getStringData($r('app.string.nav_router')) + item) - .width("100%") - .height(72) - .backgroundColor('#FFFFFF') - .borderRadius(24) - .fontSize(16) - .fontWeight(500) - .textAlign(TextAlign.Center) - NavDestination() { - Text("NavDestinationContent" + item) - } - .title("NavDestinationTitle" + item) - } - } - .id('Navigation' + item) - }, (item: number) => item.toString()) - } - .width("90%") - .margin({ top: 12 }) - } - .mode(NavigationMode.Stack) - } - .height('100%') - .width('100%') - .backgroundColor('#F1F3F5') - } +/* + * Copyright (c) 2023 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 { TitleBar } from '../../../../common/TitleBar' +import { getStringData } from '../../../../data/ResourceDataHandle' + +@Entry +@Component +struct NavRouterSample { + private arr: number[] = [1, 2, 3]; + + build() { + Column() { + TitleBar({ title: $r('app.string.navRouter_title') }) + Navigation() { + + List({ space: 12 }) { + ForEach(this.arr, (item: number) => { + ListItem() { + NavRouter() { + Text(getStringData($r('app.string.nav_router')) + item) + .width("100%") + .height(72) + .backgroundColor('#FFFFFF') + .borderRadius(24) + .fontSize(16) + .fontWeight(500) + .textAlign(TextAlign.Center) + NavDestination() { + Text("NavDestinationContent" + item) + } + .title("NavDestinationTitle" + item) + } + } + .id('Navigation' + item) + }, (item: number) => item.toString()) + } + .width("90%") + .margin({ top: 12 }) + } + .mode(NavigationMode.Stack) + } + .height('100%') + .width('100%') + .backgroundColor('#F1F3F5') + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/scrollAndSwipe/swiperSample/SwiperCustomAnimationControlPanel.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/scrollAndSwipe/swiperSample/SwiperCustomAnimationControlPanel.ets index dd57a8f010e13affbdeb766ff844ad241720d65a..5baa988ffa5fabcde815d3ac240079eb8cc9dc26 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/scrollAndSwipe/swiperSample/SwiperCustomAnimationControlPanel.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/scrollAndSwipe/swiperSample/SwiperCustomAnimationControlPanel.ets @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2024 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 { CommonItemSelect, CommonSwitcher } from '../../../../common/AttributeModificationTool'; - -@Component -export struct CustomAnimationPropertiesControlPanel { - @Link changeOpacity: boolean; - @Link changeScale: boolean; - @Link closeTwoPagesTogether: boolean; - @Link cancelDefaultTranslate: boolean; - @Link customAnimationAutoPlay: boolean; - @Link customAnimationDuration: number; - @Link customAnimationCurve: string; - - build() { - Column() { - CommonSwitcher({ - bool: $changeOpacity, - name: $r('app.string.swiper_custom_property_opacity'), - testID: `custom_swiper_001` - }) - - Divider() - - CommonSwitcher({ - bool: $changeScale, - name: $r('app.string.swiper_custom_property_scale'), - testID: `custom_swiper_002` - }) - - Divider() - - CommonSwitcher({ - bool: $closeTwoPagesTogether, - name: $r('app.string.swiper_close_two_pages_together'), - testID: `custom_swiper_003` - }) - - Divider() - - CommonSwitcher({ - bool: $cancelDefaultTranslate, - name: $r('app.string.swiper_cancel_default_translate'), - testID: `custom_swiper_004` - }) - - Divider() - - CommonSwitcher({ - bool: $customAnimationAutoPlay, - name: $r('app.string.swiper_property_auto_play'), - testID: `custom_swiper_005` - }) - - Divider() - - CommonItemSelect({ - name: $r('app.string.swiper_properties_duration'), - selects: ['400', '1000', '2000'], - menuAlignType: MenuAlignType.END, - callback: (index, str) => { - this.customAnimationDuration = Number.parseInt(str); - }, - testId:`custom_swiper_006` - }) - - Divider() - - CommonItemSelect({ - name: $r('app.string.swiper_custom_property_curve'), - selects: ['Linear', 'Ease', 'FastOutSlowIn', 'Sharp', 'Rhythm', 'Smooth', 'Friction'], - menuAlignType: MenuAlignType.END, - callback: (index, str) => { - this.customAnimationCurve = str; - }, - testId:`custom_swiper_007` - }) - } - } +/* + * Copyright (c) 2024 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 { CommonItemSelect, CommonSwitcher } from '../../../../common/AttributeModificationTool'; + +@Component +export struct CustomAnimationPropertiesControlPanel { + @Link changeOpacity: boolean; + @Link changeScale: boolean; + @Link closeTwoPagesTogether: boolean; + @Link cancelDefaultTranslate: boolean; + @Link customAnimationAutoPlay: boolean; + @Link customAnimationDuration: number; + @Link customAnimationCurve: string; + + build() { + Column() { + CommonSwitcher({ + bool: $changeOpacity, + name: $r('app.string.swiper_custom_property_opacity'), + testID: `custom_swiper_001` + }) + + Divider() + + CommonSwitcher({ + bool: $changeScale, + name: $r('app.string.swiper_custom_property_scale'), + testID: `custom_swiper_002` + }) + + Divider() + + CommonSwitcher({ + bool: $closeTwoPagesTogether, + name: $r('app.string.swiper_close_two_pages_together'), + testID: `custom_swiper_003` + }) + + Divider() + + CommonSwitcher({ + bool: $cancelDefaultTranslate, + name: $r('app.string.swiper_cancel_default_translate'), + testID: `custom_swiper_004` + }) + + Divider() + + CommonSwitcher({ + bool: $customAnimationAutoPlay, + name: $r('app.string.swiper_property_auto_play'), + testID: `custom_swiper_005` + }) + + Divider() + + CommonItemSelect({ + name: $r('app.string.swiper_properties_duration'), + selects: ['400', '1000', '2000'], + menuAlignType: MenuAlignType.END, + callback: (index, str) => { + this.customAnimationDuration = Number.parseInt(str); + }, + testId:`custom_swiper_006` + }) + + Divider() + + CommonItemSelect({ + name: $r('app.string.swiper_custom_property_curve'), + selects: ['Linear', 'Ease', 'FastOutSlowIn', 'Sharp', 'Rhythm', 'Smooth', 'Friction'], + menuAlignType: MenuAlignType.END, + callback: (index, str) => { + this.customAnimationCurve = str; + }, + testId:`custom_swiper_007` + }) + } + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/textAndInput/imageSpanSample/ImageSpanSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/textAndInput/imageSpanSample/ImageSpanSample.ets index 9b69b8238dcd112b930bd25996af464fc6c4ced5..f743f8b9b1427ecfa9b0cbe0b860785ffcdbf92f 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/textAndInput/imageSpanSample/ImageSpanSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/components/textAndInput/imageSpanSample/ImageSpanSample.ets @@ -1,74 +1,74 @@ -/* - * Copyright (c) 2022-2023 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 { ChangeVerticalAlign, ChangeObjectFit } from './ChangePanel' -import { IntroductionTitle } from '../../../../common/IntroductionTitle' -import { TitleBar } from '../../../../common/TitleBar' - -@Extend(Column) function backgroundStyle() { - .size({ width: '100%' }) - .margin({ top: 12 }) - .padding(12) - .borderRadius(24) - .justifyContent(FlexAlign.SpaceBetween) - .backgroundColor(Color.White) -} - -@Entry -@Component -struct ImageSpanSample { - @State imageSpanAlignment: ImageSpanAlignment = ImageSpanAlignment.BOTTOM - @State imageFit: ImageFit = ImageFit.Cover - - build() { - Column() { - TitleBar({ title: $r('app.string.image_span_title') }) - Scroll() { - Column() { - IntroductionTitle({ introduction: $r('app.string.image_span_and_span') }) - Column() { - Text(){ - Span($r('app.string.text_content_en_first')) - ImageSpan($r('app.media.banner')) - .verticalAlign(this.imageSpanAlignment) - .objectFit(this.imageFit) - .width(300) - .height(350) - .border({ width: 1 }) - Span($r('app.string.text_content_en_last')) - } - } - .backgroundStyle() - - IntroductionTitle({ introduction: $r('app.string.image_span_vertical_align_and_object_fit') }) - Column() { - ChangeVerticalAlign({ - imageSpanAlignment: $imageSpanAlignment - }) - ChangeObjectFit({ - imageFit: $imageFit - }) - } - .backgroundStyle() - .margin({ bottom: 80 }) - } - .constraintSize({ minHeight: '100%' }) // Let the minHeight of the component cover screen at least - } - .height('100%') - .padding({ left: 12, right: 12 }) - } - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2022-2023 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 { ChangeVerticalAlign, ChangeObjectFit } from './ChangePanel' +import { IntroductionTitle } from '../../../../common/IntroductionTitle' +import { TitleBar } from '../../../../common/TitleBar' + +@Extend(Column) function backgroundStyle() { + .size({ width: '100%' }) + .margin({ top: 12 }) + .padding(12) + .borderRadius(24) + .justifyContent(FlexAlign.SpaceBetween) + .backgroundColor(Color.White) +} + +@Entry +@Component +struct ImageSpanSample { + @State imageSpanAlignment: ImageSpanAlignment = ImageSpanAlignment.BOTTOM + @State imageFit: ImageFit = ImageFit.Cover + + build() { + Column() { + TitleBar({ title: $r('app.string.image_span_title') }) + Scroll() { + Column() { + IntroductionTitle({ introduction: $r('app.string.image_span_and_span') }) + Column() { + Text(){ + Span($r('app.string.text_content_en_first')) + ImageSpan($r('app.media.banner')) + .verticalAlign(this.imageSpanAlignment) + .objectFit(this.imageFit) + .width(300) + .height(350) + .border({ width: 1 }) + Span($r('app.string.text_content_en_last')) + } + } + .backgroundStyle() + + IntroductionTitle({ introduction: $r('app.string.image_span_vertical_align_and_object_fit') }) + Column() { + ChangeVerticalAlign({ + imageSpanAlignment: $imageSpanAlignment + }) + ChangeObjectFit({ + imageFit: $imageFit + }) + } + .backgroundStyle() + .margin({ bottom: 80 }) + } + .constraintSize({ minHeight: '100%' }) // Let the minHeight of the component cover screen at least + } + .height('100%') + .padding({ left: 12, right: 12 }) + } + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomClickEvent.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomClickEvent.ets old mode 100755 new mode 100644 index 2804c8d9f3b7940edd9870e1cc96e31f2898cb6c..e81c7ea33d0889ee76160b197398f8d069d8ed8f --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomClickEvent.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomClickEvent.ets @@ -1,178 +1,178 @@ -/* - * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; -import { getStringData } from '../../../../data/ResourceDataHandle'; -import { IntroductionTitle } from '../../../../common/IntroductionTitle'; -import { TitleBar } from '../../../../common/TitleBar'; -import ShowToast from '../../../../util/ShowToast'; -import Logger from '../../../../util/Logger'; - -const TAG: string = 'CustomClickEvent'; - -@Entry -@Component -struct CustomClickEvent { - private btnFontColor: Resource = $r('app.color.white'); - - isTouchPointInCircle(info: TouchTestInfo): boolean { - let circleCenterX = info.rect.x + info.rect.width / 2; - let circleCenterY = info.rect.y + info.rect.height / 2; - let circleRadius = info.rect.width / 2; - let distance = Math.sqrt((circleCenterX - info.parentX)**2 + (circleCenterY - info.parentY)**2); - Logger.info(TAG, `isTouchPoinInCircle circleCenterX: ${circleCenterX}, circleCenterY: ${circleCenterY},\ - circleRadius: ${circleRadius}, distance: ${distance}`); - if (distance <= circleRadius) { - return true; - } - return false; - } - - build() { - Column() { - // 标题 - Column() { - Row() { - Image($r('app.media.ic_back')) - .width(24) - .height(24) - .margin({ left: 24 }) - .objectFit(ImageFit.Contain) - .onClick(() => { - router.back() - }) - .id('backBtn') - Text($r('app.string.custom_click_event')) - .fontSize(20) - .layoutWeight(1) - .fontWeight(700) - .margin({ left: 16 }) - .align(Alignment.Start) - Blank() - } - .height(56) - .width('100%') - } - .height(56) - .width('100%') - - Column() { - // 大小圆圈 - Column({ space: 12 }) { - Stack({ alignContent: Alignment.Bottom }) { - Button({ type: ButtonType.Circle }) { - Row() { - Text($r('app.string.custom_click_big_btn')) - .fontSize(21) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .textAlign(TextAlign.Center) - .padding({ top: 56, bottom: 300 }) - } - .alignItems(VerticalAlign.Top) - } - .backgroundColor('#007DFF') - .width('100%') - .height('100%') - .fontSize(21) - .fontWeight(500) - .id('BigCircle') - .fontColor(this.btnFontColor) - .onClick(() => { - ShowToast.longToast($r('app.string.custom_bigcircle_prompt')); - }) - - Button($r('app.string.custom_click_small_btn'), { type: ButtonType.Circle }) - .backgroundColor('#F7CE00') - .width(240) - .fontSize(21) - .fontWeight(500) - .borderRadius(20) - .fontColor(this.btnFontColor) - .id('SmallCircle') - .onClick(() => { - ShowToast.longToast($r('app.string.custom_smallcircle_prompt')); - }) - } - .width('100%') - .hitTestBehavior(HitTestMode.Block) - .onChildTouchTest((touchinfo) => { - Logger.info(TAG, `touchinfo array len: ${touchinfo.length}`); - for(let i = 0; i < touchinfo.length; i++) { - let info: TouchTestInfo = touchinfo[i]; - Logger.info(TAG, `touchinfo info.id: ${info.id}`); - Logger.info(TAG, `touchinfo windowX: ${info.windowX}, windowY: ${info.windowY}`); - Logger.info(TAG, `touchinfo parentX: ${info.parentX}, parentY: ${info.parentY}`); - Logger.info(TAG, `touchinfo x: ${info.x}, y: ${info.y}`); - Logger.info(TAG, `touchinfo rect.x: ${info.rect.x}, rect.y: ${info.rect.y}, rect.width: ${info.rect.width}, rect.height: ${info.rect.height}`); - - if (info.id == 'SmallCircle' && info.x > 0 && info.y > 0 && this.isTouchPointInCircle(info) == true) { - Logger.info(TAG, `touchinfo touch point at scope of component: ${info.id}`); - return { id: 'SmallCircle', strategy: TouchTestStrategy.FORWARD }; - } - if (info.id == 'BigCircle' && info.x > 0 && info.y > 0 && this.isTouchPointInCircle(info) == true) { - Logger.info(TAG, `touchinfo touch point at scope of component: ${info.id}`); - return { id: 'BigCircle', strategy: TouchTestStrategy.FORWARD }; - } - } - return { strategy: TouchTestStrategy.DEFAULT }; - }) - } - .padding({ left: 24, right: 24, bottom: 32 }) - - // 文字提示 - Column() { - Row() { - Button({ type: ButtonType.Circle }) - .backgroundColor('#007DFF') - .width(8) - .height(8) - Text($r('app.string.big_circle_prompt')) - .fontSize(14) - .fontWeight(400) - .fontFamily('HarmonyHeiTi') - .textAlign(TextAlign.Start) - .margin({ left: 8 }) - } - .alignItems(VerticalAlign.Center) - .justifyContent(FlexAlign.Center) - - Row() { - Button({ type: ButtonType.Circle }) - .backgroundColor('#F7CE00') - .width(8) - .height(8) - Text($r('app.string.small_circle_prompt')) - .fontSize(14) - .fontWeight(400) - .fontFamily('HarmonyHeiTi') - .textAlign(TextAlign.Start) - .margin({ left: 8 }) - } - .alignItems(VerticalAlign.Center) - .justifyContent(FlexAlign.Center) - } - } - .height('90%') - .width('100%') - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .flexShrink(1) - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } -} +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; +import { getStringData } from '../../../../data/ResourceDataHandle'; +import { IntroductionTitle } from '../../../../common/IntroductionTitle'; +import { TitleBar } from '../../../../common/TitleBar'; +import ShowToast from '../../../../util/ShowToast'; +import Logger from '../../../../util/Logger'; + +const TAG: string = 'CustomClickEvent'; + +@Entry +@Component +struct CustomClickEvent { + private btnFontColor: Resource = $r('app.color.white'); + + isTouchPointInCircle(info: TouchTestInfo): boolean { + let circleCenterX = info.rect.x + info.rect.width / 2; + let circleCenterY = info.rect.y + info.rect.height / 2; + let circleRadius = info.rect.width / 2; + let distance = Math.sqrt((circleCenterX - info.parentX)**2 + (circleCenterY - info.parentY)**2); + Logger.info(TAG, `isTouchPoinInCircle circleCenterX: ${circleCenterX}, circleCenterY: ${circleCenterY},\ + circleRadius: ${circleRadius}, distance: ${distance}`); + if (distance <= circleRadius) { + return true; + } + return false; + } + + build() { + Column() { + // 标题 + Column() { + Row() { + Image($r('app.media.ic_back')) + .width(24) + .height(24) + .margin({ left: 24 }) + .objectFit(ImageFit.Contain) + .onClick(() => { + router.back() + }) + .id('backBtn') + Text($r('app.string.custom_click_event')) + .fontSize(20) + .layoutWeight(1) + .fontWeight(700) + .margin({ left: 16 }) + .align(Alignment.Start) + Blank() + } + .height(56) + .width('100%') + } + .height(56) + .width('100%') + + Column() { + // 大小圆圈 + Column({ space: 12 }) { + Stack({ alignContent: Alignment.Bottom }) { + Button({ type: ButtonType.Circle }) { + Row() { + Text($r('app.string.custom_click_big_btn')) + .fontSize(21) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .textAlign(TextAlign.Center) + .padding({ top: 56, bottom: 300 }) + } + .alignItems(VerticalAlign.Top) + } + .backgroundColor('#007DFF') + .width('100%') + .height('100%') + .fontSize(21) + .fontWeight(500) + .id('BigCircle') + .fontColor(this.btnFontColor) + .onClick(() => { + ShowToast.longToast($r('app.string.custom_bigcircle_prompt')); + }) + + Button($r('app.string.custom_click_small_btn'), { type: ButtonType.Circle }) + .backgroundColor('#F7CE00') + .width(240) + .fontSize(21) + .fontWeight(500) + .borderRadius(20) + .fontColor(this.btnFontColor) + .id('SmallCircle') + .onClick(() => { + ShowToast.longToast($r('app.string.custom_smallcircle_prompt')); + }) + } + .width('100%') + .hitTestBehavior(HitTestMode.Block) + .onChildTouchTest((touchinfo) => { + Logger.info(TAG, `touchinfo array len: ${touchinfo.length}`); + for(let i = 0; i < touchinfo.length; i++) { + let info: TouchTestInfo = touchinfo[i]; + Logger.info(TAG, `touchinfo info.id: ${info.id}`); + Logger.info(TAG, `touchinfo windowX: ${info.windowX}, windowY: ${info.windowY}`); + Logger.info(TAG, `touchinfo parentX: ${info.parentX}, parentY: ${info.parentY}`); + Logger.info(TAG, `touchinfo x: ${info.x}, y: ${info.y}`); + Logger.info(TAG, `touchinfo rect.x: ${info.rect.x}, rect.y: ${info.rect.y}, rect.width: ${info.rect.width}, rect.height: ${info.rect.height}`); + + if (info.id == 'SmallCircle' && info.x > 0 && info.y > 0 && this.isTouchPointInCircle(info) == true) { + Logger.info(TAG, `touchinfo touch point at scope of component: ${info.id}`); + return { id: 'SmallCircle', strategy: TouchTestStrategy.FORWARD }; + } + if (info.id == 'BigCircle' && info.x > 0 && info.y > 0 && this.isTouchPointInCircle(info) == true) { + Logger.info(TAG, `touchinfo touch point at scope of component: ${info.id}`); + return { id: 'BigCircle', strategy: TouchTestStrategy.FORWARD }; + } + } + return { strategy: TouchTestStrategy.DEFAULT }; + }) + } + .padding({ left: 24, right: 24, bottom: 32 }) + + // 文字提示 + Column() { + Row() { + Button({ type: ButtonType.Circle }) + .backgroundColor('#007DFF') + .width(8) + .height(8) + Text($r('app.string.big_circle_prompt')) + .fontSize(14) + .fontWeight(400) + .fontFamily('HarmonyHeiTi') + .textAlign(TextAlign.Start) + .margin({ left: 8 }) + } + .alignItems(VerticalAlign.Center) + .justifyContent(FlexAlign.Center) + + Row() { + Button({ type: ButtonType.Circle }) + .backgroundColor('#F7CE00') + .width(8) + .height(8) + Text($r('app.string.small_circle_prompt')) + .fontSize(14) + .fontWeight(400) + .fontFamily('HarmonyHeiTi') + .textAlign(TextAlign.Start) + .margin({ left: 8 }) + } + .alignItems(VerticalAlign.Center) + .justifyContent(FlexAlign.Center) + } + } + .height('90%') + .width('100%') + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .flexShrink(1) + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } +} diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomEventHome.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomEventHome.ets old mode 100755 new mode 100644 index 50a24d697b8d46af47656665714e1f650e5c8af6..7e4701d7399b7c837b88f2512aa2bbe14084e42a --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomEventHome.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomEventHome.ets @@ -1,99 +1,99 @@ -/* - * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; -import { getStringData } from '../../../../data/ResourceDataHandle'; -import { IntroductionTitle } from '../../../../common/IntroductionTitle'; -import { TitleBar } from '../../../../common/TitleBar'; -import ShowToast from '../../../../util/ShowToast'; - -@Entry -@Component -struct CustomEventHome { - private btnFontColor: Resource = $r('app.color.white'); - private customClickUrl: string = 'pages/universal/events/customEventSample/CustomClickEvent'; - private customScrollingUrl: string = 'pages/universal/events/customEventSample/CustomScrollingEvent'; - - build() { - Column() { - // 标题 - Column() { - Row() { - Image($r('app.media.ic_back')) - .width(24) - .height(24) - .margin({ left: 24 }) - .objectFit(ImageFit.Contain) - .onClick(() => { - router.back() - }) - .id('backBtn') - Text($r('app.string.send_event')) - .fontSize(20) - .layoutWeight(1) - .fontWeight(700) - .margin({ left: 16 }) - .align(Alignment.Start) - Blank() - } - .height(56) - .width('100%') - } - .height(56) - .width('100%') - - Blank() - Column({ space: 12 }) { - Button($r('app.string.custom_click_event_button')) - .backgroundColor('#007DFF') - .width('100%') - .height(40) - .fontSize(16) - .fontWeight(500) - .borderRadius(20) - .fontColor(this.btnFontColor) - .id('customClick') - .onClick(() => { - router.pushUrl({ - url: this.customClickUrl - }); - }) - - Button($r('app.string.custom_Scrolling_event_button')) - .backgroundColor('#007DFF') - .width('100%') - .height(40) - .fontSize(16) - .fontWeight(500) - .borderRadius(20) - .fontColor(this.btnFontColor) - .id('customScrolling') - .onClick(() => { - router.pushUrl({ - url: this.customScrollingUrl - }); - }) - } - .padding({ left: 24, right: 24, bottom: 16 }) - .width('100%') - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.End) - .flexShrink(1) - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; +import { getStringData } from '../../../../data/ResourceDataHandle'; +import { IntroductionTitle } from '../../../../common/IntroductionTitle'; +import { TitleBar } from '../../../../common/TitleBar'; +import ShowToast from '../../../../util/ShowToast'; + +@Entry +@Component +struct CustomEventHome { + private btnFontColor: Resource = $r('app.color.white'); + private customClickUrl: string = 'pages/universal/events/customEventSample/CustomClickEvent'; + private customScrollingUrl: string = 'pages/universal/events/customEventSample/CustomScrollingEvent'; + + build() { + Column() { + // 标题 + Column() { + Row() { + Image($r('app.media.ic_back')) + .width(24) + .height(24) + .margin({ left: 24 }) + .objectFit(ImageFit.Contain) + .onClick(() => { + router.back() + }) + .id('backBtn') + Text($r('app.string.send_event')) + .fontSize(20) + .layoutWeight(1) + .fontWeight(700) + .margin({ left: 16 }) + .align(Alignment.Start) + Blank() + } + .height(56) + .width('100%') + } + .height(56) + .width('100%') + + Blank() + Column({ space: 12 }) { + Button($r('app.string.custom_click_event_button')) + .backgroundColor('#007DFF') + .width('100%') + .height(40) + .fontSize(16) + .fontWeight(500) + .borderRadius(20) + .fontColor(this.btnFontColor) + .id('customClick') + .onClick(() => { + router.pushUrl({ + url: this.customClickUrl + }); + }) + + Button($r('app.string.custom_Scrolling_event_button')) + .backgroundColor('#007DFF') + .width('100%') + .height(40) + .fontSize(16) + .fontWeight(500) + .borderRadius(20) + .fontColor(this.btnFontColor) + .id('customScrolling') + .onClick(() => { + router.pushUrl({ + url: this.customScrollingUrl + }); + }) + } + .padding({ left: 24, right: 24, bottom: 16 }) + .width('100%') + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.End) + .flexShrink(1) + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomScrollingEvent.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomScrollingEvent.ets old mode 100755 new mode 100644 index 21d4841f3459512070fd509429bd5d9f56ee1889..1dfeddc5cc11879c2f3c47428275de0e8b49cc9f --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomScrollingEvent.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/events/customEventSample/CustomScrollingEvent.ets @@ -1,185 +1,185 @@ -/* - * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; -import { getStringData } from '../../../../data/ResourceDataHandle'; -import { IntroductionTitle } from '../../../../common/IntroductionTitle'; -import { TitleBar } from '../../../../common/TitleBar'; -import ShowToast from '../../../../util/ShowToast'; -import Logger from '../../../../util/Logger'; - -const TAG: string = 'CustomScrollingEvent'; - -@Entry -@Component -struct CustomScrollingEvent { - private scrollerForScroll: Scroller = new Scroller(); - private scrollerForList: Scroller = new Scroller(); - @State files: string[] = []; - @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。 - - aboutToAppear() { - for (let i = 1; i <= 30; i++) { - let file: string = "file" + i.toString(); - this.files.push(file); - } - } - - build() { - Column() { - // 标题 - Column() { - Row() { - Image($r('app.media.ic_back')) - .width(24) - .height(24) - .margin({ left: 12 }) - .objectFit(ImageFit.Contain) - .onClick(() => { - router.back() - }) - .id('backBtn') - Text($r('app.string.custom_scrolling_event')) - .fontSize(20) - .layoutWeight(1) - .fontWeight(700) - .margin({ left: 16 }) - .align(Alignment.Start) - Blank() - } - .height(56) - .width('100%') - } - .height(56) - .width('100%') - .padding({ left: 12, right: 12 }) - - Scroll(this.scrollerForScroll) { - Column() { - Column() { - Text($r('app.string.custom_scrolling_area')) - .fontSize(36) - .fontWeight(400) - .fontFamily('HarmonyHeiTi') - .textAlign(TextAlign.Start) - .fontColor('#182431') - .opacity(0.15) - .margin({ top: 142 }) - .id('scrollText') - Image($r('app.media.button')) - .width(40) - .height(40) - .margin({ top: 78, bottom: 40 }) - .id('scrollBtn') - .objectFit(ImageFit.Contain) - } - .height(332) - .width('100%') - .border({ - width: 1, - color: '#55182431', - radius: 24, - style: BorderStyle.Solid - }) - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .margin({ bottom: 16 }) - .backgroundColor('#F2F3F4') - .id('ScrollArea') - - // 目录列表 - List({ space: 12, scroller: this.scrollerForList }) { - ForEach(this.files, (file: string, index: number) => { - ListItem() { - Row() { - Text(file) - .fontSize(16) - .fontWeight(500) - .fontFamily('HarmonyHeiTi-Medium') - .textAlign(TextAlign.Start) - } - .width('100%') - .height(56) - .borderRadius(24) - .backgroundColor(0xFFFFFF) - .alignItems(VerticalAlign.Center) - .padding({ left: 12, right: 12 }) - } - .id("ListItem" + index) - .width('100%') - }) - } - .width('100%') - .height('80%') - .listDirection(Axis.Vertical) // 排列方向 - .borderRadius(24) - .edgeEffect(EdgeEffect.None) // 边缘效果设置为Spring - .nestedScroll({ - scrollForward: NestedScrollMode.PARENT_FIRST, - scrollBackward: NestedScrollMode.SELF_FIRST - }) - .onReachStart(() => { - this.listPosition = 0 - }) - .onReachEnd(() => { - this.listPosition = 2 - }) - .onScrollFrameBegin((offset: number) => { - if ((this.listPosition == 0 && offset <= 0) || (this.listPosition == 2 && offset >= 0)) { - this.scrollerForScroll.scrollBy(0, offset); - return { offsetRemain: 0 }; - } - this.listPosition = 1; - return { offsetRemain: offset }; - }) - .id('fileList') - } - .margin({ left: 12, right: 12 }) - .onChildTouchTest((touchinfo) => { - Logger.info(TAG, `touchinfo array len: ${touchinfo.length}`); - for (let info of touchinfo) { - Logger.info(TAG, `touchinfo info.id: ${info.id}`); - Logger.info(TAG, `touchinfo windowX: ${info.windowX}, windowY: ${info.windowY}`); - Logger.info(TAG, `touchinfo parentX: ${info.parentX}, parentY: ${info.parentY}`); - Logger.info(TAG, `touchinfo x: ${info.x}, y: ${info.y}`); - Logger.info(TAG, `touchinfo rect.x: ${info.rect.x}, rect.y: ${info.rect.y}, rect.width: ${info.rect.width}, rect.height: ${info.rect.height}`); - let compontWidth = info.rect.x + info.rect.width; - let compontHeight = info.rect.y + info.rect.height; - if (info.id == 'ScrollArea' && - info.x > 0 && - info.parentX < compontWidth && - info.parentX > info.rect.x && - info.y > 0 && - info.parentY < compontHeight && - info.parentY > info.rect.y) { - Logger.info(TAG, `touchinfo touch point at scope of component: ${info.id}`); - return { id: 'fileList', strategy: TouchTestStrategy.FORWARD }; - } - } - return { strategy: TouchTestStrategy.DEFAULT }; - }) - } - .edgeEffect(EdgeEffect.Spring) - .friction(0.6) - .scrollBar(BarState.Off) - .width('100%') - .height(700) - .id('GlobalScroll') - } - .height('100%') - .width('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; +import { getStringData } from '../../../../data/ResourceDataHandle'; +import { IntroductionTitle } from '../../../../common/IntroductionTitle'; +import { TitleBar } from '../../../../common/TitleBar'; +import ShowToast from '../../../../util/ShowToast'; +import Logger from '../../../../util/Logger'; + +const TAG: string = 'CustomScrollingEvent'; + +@Entry +@Component +struct CustomScrollingEvent { + private scrollerForScroll: Scroller = new Scroller(); + private scrollerForList: Scroller = new Scroller(); + @State files: string[] = []; + @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。 + + aboutToAppear() { + for (let i = 1; i <= 30; i++) { + let file: string = "file" + i.toString(); + this.files.push(file); + } + } + + build() { + Column() { + // 标题 + Column() { + Row() { + Image($r('app.media.ic_back')) + .width(24) + .height(24) + .margin({ left: 12 }) + .objectFit(ImageFit.Contain) + .onClick(() => { + router.back() + }) + .id('backBtn') + Text($r('app.string.custom_scrolling_event')) + .fontSize(20) + .layoutWeight(1) + .fontWeight(700) + .margin({ left: 16 }) + .align(Alignment.Start) + Blank() + } + .height(56) + .width('100%') + } + .height(56) + .width('100%') + .padding({ left: 12, right: 12 }) + + Scroll(this.scrollerForScroll) { + Column() { + Column() { + Text($r('app.string.custom_scrolling_area')) + .fontSize(36) + .fontWeight(400) + .fontFamily('HarmonyHeiTi') + .textAlign(TextAlign.Start) + .fontColor('#182431') + .opacity(0.15) + .margin({ top: 142 }) + .id('scrollText') + Image($r('app.media.button')) + .width(40) + .height(40) + .margin({ top: 78, bottom: 40 }) + .id('scrollBtn') + .objectFit(ImageFit.Contain) + } + .height(332) + .width('100%') + .border({ + width: 1, + color: '#55182431', + radius: 24, + style: BorderStyle.Solid + }) + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .margin({ bottom: 16 }) + .backgroundColor('#F2F3F4') + .id('ScrollArea') + + // 目录列表 + List({ space: 12, scroller: this.scrollerForList }) { + ForEach(this.files, (file: string, index: number) => { + ListItem() { + Row() { + Text(file) + .fontSize(16) + .fontWeight(500) + .fontFamily('HarmonyHeiTi-Medium') + .textAlign(TextAlign.Start) + } + .width('100%') + .height(56) + .borderRadius(24) + .backgroundColor(0xFFFFFF) + .alignItems(VerticalAlign.Center) + .padding({ left: 12, right: 12 }) + } + .id("ListItem" + index) + .width('100%') + }) + } + .width('100%') + .height('80%') + .listDirection(Axis.Vertical) // 排列方向 + .borderRadius(24) + .edgeEffect(EdgeEffect.None) // 边缘效果设置为Spring + .nestedScroll({ + scrollForward: NestedScrollMode.PARENT_FIRST, + scrollBackward: NestedScrollMode.SELF_FIRST + }) + .onReachStart(() => { + this.listPosition = 0 + }) + .onReachEnd(() => { + this.listPosition = 2 + }) + .onScrollFrameBegin((offset: number) => { + if ((this.listPosition == 0 && offset <= 0) || (this.listPosition == 2 && offset >= 0)) { + this.scrollerForScroll.scrollBy(0, offset); + return { offsetRemain: 0 }; + } + this.listPosition = 1; + return { offsetRemain: offset }; + }) + .id('fileList') + } + .margin({ left: 12, right: 12 }) + .onChildTouchTest((touchinfo) => { + Logger.info(TAG, `touchinfo array len: ${touchinfo.length}`); + for (let info of touchinfo) { + Logger.info(TAG, `touchinfo info.id: ${info.id}`); + Logger.info(TAG, `touchinfo windowX: ${info.windowX}, windowY: ${info.windowY}`); + Logger.info(TAG, `touchinfo parentX: ${info.parentX}, parentY: ${info.parentY}`); + Logger.info(TAG, `touchinfo x: ${info.x}, y: ${info.y}`); + Logger.info(TAG, `touchinfo rect.x: ${info.rect.x}, rect.y: ${info.rect.y}, rect.width: ${info.rect.width}, rect.height: ${info.rect.height}`); + let compontWidth = info.rect.x + info.rect.width; + let compontHeight = info.rect.y + info.rect.height; + if (info.id == 'ScrollArea' && + info.x > 0 && + info.parentX < compontWidth && + info.parentX > info.rect.x && + info.y > 0 && + info.parentY < compontHeight && + info.parentY > info.rect.y) { + Logger.info(TAG, `touchinfo touch point at scope of component: ${info.id}`); + return { id: 'fileList', strategy: TouchTestStrategy.FORWARD }; + } + } + return { strategy: TouchTestStrategy.DEFAULT }; + }) + } + .edgeEffect(EdgeEffect.Spring) + .friction(0.6) + .scrollBar(BarState.Off) + .width('100%') + .height(700) + .id('GlobalScroll') + } + .height('100%') + .width('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/gesture/customGesture/CustomGestureJudge.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/gesture/customGesture/CustomGestureJudge.ets index f3abf9981246a023149b60451daa07bddd6bf3c6..81b124a5beaf84585fecee669a5d9997c189f0b3 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/gesture/customGesture/CustomGestureJudge.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/gesture/customGesture/CustomGestureJudge.ets @@ -1,170 +1,170 @@ -/* - * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; -import { getStringData } from '../../../../data/ResourceDataHandle'; -import { IntroductionTitle } from '../../../../common/IntroductionTitle'; -import { TitleBar } from '../../../../common/TitleBar'; -import ShowToast from '../../../../util/ShowToast'; - -@Entry -@Component -struct CustomJudgeEvent { - private btnFontColor: Resource = $r('app.color.white'); - @State message: string = ''; - - build() { - Column() { - // 标题 - Column() { - Row() { - Image($r('app.media.ic_back')) - .width(24) - .height(24) - .margin({ left: 12 }) - .objectFit(ImageFit.Contain) - .onClick(() => { - router.back() - }) - .id('backBtn') - Text($r('app.string.custom_judge_title')) - .fontSize(20) - .layoutWeight(1) - .fontWeight(700) - .margin({ left: 16 }) - .align(Alignment.Start) - Blank() - } - .height('100%') - .width('100%') - } - .height(56) - .width('100%') - - // 上半部分 - Stack() { - Column() { - } - .height(340) - .width('100%') - .backgroundColor('#007DFF') - .opacity(0.1) - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .id('longPressColumn') - .border({ - width: 1, - color: '#007DFF', - radius: { topLeft: 24, topRight: 24, bottomLeft: 0, bottomRight: 0 }, - style: BorderStyle.Dotted - }) - - Text($r('app.string.custom_judge_long_press')) - .fontSize(16) - .fontWeight(400) - .fontFamily(' HarmonyHeiTi') - .textAlign(TextAlign.Center) - .opacity(0.7) - .fontColor('#007DFF') - .id('longPressPrompt') - } - .id('longPressArea') - .gesture( - TapGesture() - .tag("tap1") // 设置点击手势标志 - ) - .gesture( - LongPressGesture() - .tag("longPress1")// 设置长按手势标志 - .onAction(() => { - this.message = 'longPress'; - ShowToast.longToast($r('app.string.custom_long_press_prompt')); - }) - ) - .onGestureJudgeBegin((gestureInfo: GestureInfo, event: BaseGestureEvent) => { - // 自定义判定标准 - if (gestureInfo.type == GestureControl.GestureType.LONG_PRESS_GESTURE && - gestureInfo.tag == 'longPress1' && - event.fingerList.length > 0 && - event.fingerList[0].localY < 340) { - // 返回 CONTINUE 将保持系统判定。 - return GestureJudgeResult.CONTINUE; - } else { - return GestureJudgeResult.REJECT; - } - }) - - // 下半部分 - Stack() { - Column() { - } - .height(340) - .width('100%') - .backgroundColor('#F7CE00') - .opacity(0.1) - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.Center) - .id('clickColumn') - .border({ - width: 1, - color: '#F7BD00', - radius: { topLeft: 0, topRight: 0, bottomLeft: 24, bottomRight: 24 }, - style: BorderStyle.Dotted - }) - - Text($r('app.string.custom_judge_click')) - .fontSize(16) - .fontWeight(400) - .fontFamily(' HarmonyHeiTi') - .textAlign(TextAlign.Center) - .fontColor('#FF9900') - .opacity(1) - .id('clickTextPrompt') - } - .id('clickArea') - .gesture( - TapGesture() - .tag("tap2")// 设置点击手势标志 - .onAction(() => { - this.message = 'tap'; - ShowToast.longToast($r('app.string.custom_tap_prompt')); - }) - ) - .gesture( - LongPressGesture() - .tag("longPress2")// 设置长按手势标志 - .onAction(() => { - this.message = 'longPress' - }) - ) - .onGestureJudgeBegin((gestureInfo: GestureInfo, event: BaseGestureEvent) => { - // 自定义判定标准 - if (gestureInfo.type == GestureControl.GestureType.TAP_GESTURE && - gestureInfo.tag == 'tap2' && - event.fingerList.length > 0 && - event.fingerList[0].localY <= 340) { - // 返回 CONTINUE 将保持系统判定。 - return GestureJudgeResult.CONTINUE; - } else { - return GestureJudgeResult.REJECT; - } - }) - } - .height('100%') - .width('100%') - .padding({ left: 12, right: 12 }) - .backgroundColor($r('app.color.background_shallow_grey')) - } -} +/* + * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 router from '@ohos.router'; +import { getStringData } from '../../../../data/ResourceDataHandle'; +import { IntroductionTitle } from '../../../../common/IntroductionTitle'; +import { TitleBar } from '../../../../common/TitleBar'; +import ShowToast from '../../../../util/ShowToast'; + +@Entry +@Component +struct CustomJudgeEvent { + private btnFontColor: Resource = $r('app.color.white'); + @State message: string = ''; + + build() { + Column() { + // 标题 + Column() { + Row() { + Image($r('app.media.ic_back')) + .width(24) + .height(24) + .margin({ left: 12 }) + .objectFit(ImageFit.Contain) + .onClick(() => { + router.back() + }) + .id('backBtn') + Text($r('app.string.custom_judge_title')) + .fontSize(20) + .layoutWeight(1) + .fontWeight(700) + .margin({ left: 16 }) + .align(Alignment.Start) + Blank() + } + .height('100%') + .width('100%') + } + .height(56) + .width('100%') + + // 上半部分 + Stack() { + Column() { + } + .height(340) + .width('100%') + .backgroundColor('#007DFF') + .opacity(0.1) + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .id('longPressColumn') + .border({ + width: 1, + color: '#007DFF', + radius: { topLeft: 24, topRight: 24, bottomLeft: 0, bottomRight: 0 }, + style: BorderStyle.Dotted + }) + + Text($r('app.string.custom_judge_long_press')) + .fontSize(16) + .fontWeight(400) + .fontFamily(' HarmonyHeiTi') + .textAlign(TextAlign.Center) + .opacity(0.7) + .fontColor('#007DFF') + .id('longPressPrompt') + } + .id('longPressArea') + .gesture( + TapGesture() + .tag("tap1") // 设置点击手势标志 + ) + .gesture( + LongPressGesture() + .tag("longPress1")// 设置长按手势标志 + .onAction(() => { + this.message = 'longPress'; + ShowToast.longToast($r('app.string.custom_long_press_prompt')); + }) + ) + .onGestureJudgeBegin((gestureInfo: GestureInfo, event: BaseGestureEvent) => { + // 自定义判定标准 + if (gestureInfo.type == GestureControl.GestureType.LONG_PRESS_GESTURE && + gestureInfo.tag == 'longPress1' && + event.fingerList.length > 0 && + event.fingerList[0].localY < 340) { + // 返回 CONTINUE 将保持系统判定。 + return GestureJudgeResult.CONTINUE; + } else { + return GestureJudgeResult.REJECT; + } + }) + + // 下半部分 + Stack() { + Column() { + } + .height(340) + .width('100%') + .backgroundColor('#F7CE00') + .opacity(0.1) + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.Center) + .id('clickColumn') + .border({ + width: 1, + color: '#F7BD00', + radius: { topLeft: 0, topRight: 0, bottomLeft: 24, bottomRight: 24 }, + style: BorderStyle.Dotted + }) + + Text($r('app.string.custom_judge_click')) + .fontSize(16) + .fontWeight(400) + .fontFamily(' HarmonyHeiTi') + .textAlign(TextAlign.Center) + .fontColor('#FF9900') + .opacity(1) + .id('clickTextPrompt') + } + .id('clickArea') + .gesture( + TapGesture() + .tag("tap2")// 设置点击手势标志 + .onAction(() => { + this.message = 'tap'; + ShowToast.longToast($r('app.string.custom_tap_prompt')); + }) + ) + .gesture( + LongPressGesture() + .tag("longPress2")// 设置长按手势标志 + .onAction(() => { + this.message = 'longPress' + }) + ) + .onGestureJudgeBegin((gestureInfo: GestureInfo, event: BaseGestureEvent) => { + // 自定义判定标准 + if (gestureInfo.type == GestureControl.GestureType.TAP_GESTURE && + gestureInfo.tag == 'tap2' && + event.fingerList.length > 0 && + event.fingerList[0].localY <= 340) { + // 返回 CONTINUE 将保持系统判定。 + return GestureJudgeResult.CONTINUE; + } else { + return GestureJudgeResult.REJECT; + } + }) + } + .height('100%') + .width('100%') + .padding({ left: 12, right: 12 }) + .backgroundColor($r('app.color.background_shallow_grey')) + } +} diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/backgroundSample/ChangePanel.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/backgroundSample/ChangePanel.ets index 838f932d2f062199da4d6799b462c6bfb86bd4c3..896d046fa866ec0392946231c402287da68c6e92 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/backgroundSample/ChangePanel.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/backgroundSample/ChangePanel.ets @@ -1,79 +1,79 @@ -/* - * Copyright (c) 2022-2023 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 { CommonItemSelect } from '../../../../common/AttributeModificationTool' -import { selectImageSizeData,selectImageAlignmentData } from '../../UniversialData' -import { getStringArrayData,getStringData } from '../../../../data/ResourceDataHandle' - -@Component -export struct ChangePanel { - @Link imageSize: ImageSize - @Link alignment: Alignment - - build() { - Column() { - CommonItemSelect({ - testId: "test_select1", - name: $r('app.string.set_background_image_size'), - selects: getStringArrayData(selectImageSizeData), - callback: (index) => { - switch (index) { - case 0: - this.imageSize = ImageSize.Cover - break - default: - this.imageSize = ImageSize.Contain - } - } - }) - - CommonItemSelect({ - testId: "test_select2", - name: $r('app.string.set_background_image_position'), - selects: getStringArrayData(selectImageAlignmentData), - callback: (index) => { - switch (index) { - case 0: - this.alignment = Alignment.TopStart - break - case 1: - this.alignment = Alignment.Top - break - case 2: - this.alignment = Alignment.TopEnd - break - case 3: - this.alignment = Alignment.Start - break - case 4: - this.alignment = Alignment.Center - break - case 5: - this.alignment = Alignment.End - break - case 6: - this.alignment = Alignment.BottomStart - break - case 7: - this.alignment = Alignment.Bottom - break - default: - this.alignment = Alignment.BottomEnd - } - } - }) - } - } +/* + * Copyright (c) 2022-2023 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 { CommonItemSelect } from '../../../../common/AttributeModificationTool' +import { selectImageSizeData,selectImageAlignmentData } from '../../UniversialData' +import { getStringArrayData,getStringData } from '../../../../data/ResourceDataHandle' + +@Component +export struct ChangePanel { + @Link imageSize: ImageSize + @Link alignment: Alignment + + build() { + Column() { + CommonItemSelect({ + testId: "test_select1", + name: $r('app.string.set_background_image_size'), + selects: getStringArrayData(selectImageSizeData), + callback: (index) => { + switch (index) { + case 0: + this.imageSize = ImageSize.Cover + break + default: + this.imageSize = ImageSize.Contain + } + } + }) + + CommonItemSelect({ + testId: "test_select2", + name: $r('app.string.set_background_image_position'), + selects: getStringArrayData(selectImageAlignmentData), + callback: (index) => { + switch (index) { + case 0: + this.alignment = Alignment.TopStart + break + case 1: + this.alignment = Alignment.Top + break + case 2: + this.alignment = Alignment.TopEnd + break + case 3: + this.alignment = Alignment.Start + break + case 4: + this.alignment = Alignment.Center + break + case 5: + this.alignment = Alignment.End + break + case 6: + this.alignment = Alignment.BottomStart + break + case 7: + this.alignment = Alignment.Bottom + break + default: + this.alignment = Alignment.BottomEnd + } + } + }) + } + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/effectsSample/ChangePanel.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/effectsSample/ChangePanel.ets index 5ca08b8ee8a20d64c5f6e993695483ad733e4563..a299e7ea07d4add83cef329fbce21a9e04951eb1 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/effectsSample/ChangePanel.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/effectsSample/ChangePanel.ets @@ -1,85 +1,85 @@ -/* - * Copyright (c) 2022-2023 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 { CommonItemSelect } from '../../../../common/AttributeModificationTool' -import { selectBlurStyleColorModeData, selectBlurStyleAdaptiveColorData, selectShadowTypeData} from '../../UniversialData' -import { getStringArrayData,getStringData } from '../../../../data/ResourceDataHandle' - -@Component -export struct BackgroundBlurChangePanel { - @Link mColorMode: ThemeColorMode - @Link mAdaptiveColor: AdaptiveColor - - build() { - Column() { - CommonItemSelect({ - testId: "test_select1", - name: $r('app.string.set_background_blur_style_color_mode'), - selects: getStringArrayData(selectBlurStyleColorModeData), - callback: (index) => { - switch (index) { - case 0: - this.mColorMode = ThemeColorMode.SYSTEM - break - case 1: - this.mColorMode = ThemeColorMode.LIGHT - break - default: - this.mColorMode = ThemeColorMode.DARK - } - } - }) - - CommonItemSelect({ - testId: "test_select2", - name: $r('app.string.set_background_blur_style_adaptive_color'), - selects: getStringArrayData(selectBlurStyleAdaptiveColorData), - callback: (index) => { - switch (index) { - case 0: - this.mAdaptiveColor = AdaptiveColor.DEFAULT - break - default: - this.mAdaptiveColor = AdaptiveColor.AVERAGE - } - } - }) - } - } -} - -@Component -export struct ShadowChangePanel { - @Link mShadowType: ShadowType - - build() { - Column() { - CommonItemSelect({ - testId: "test_select1", - name: $r('app.string.set_shadow_type'), - selects: getStringArrayData(selectShadowTypeData), - callback: (index) => { - switch (index) { - case 0: - this.mShadowType = ShadowType.COLOR - break - default: - this.mShadowType = ShadowType.BLUR - } - } - }) - } - } +/* + * Copyright (c) 2022-2023 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 { CommonItemSelect } from '../../../../common/AttributeModificationTool' +import { selectBlurStyleColorModeData, selectBlurStyleAdaptiveColorData, selectShadowTypeData} from '../../UniversialData' +import { getStringArrayData,getStringData } from '../../../../data/ResourceDataHandle' + +@Component +export struct BackgroundBlurChangePanel { + @Link mColorMode: ThemeColorMode + @Link mAdaptiveColor: AdaptiveColor + + build() { + Column() { + CommonItemSelect({ + testId: "test_select1", + name: $r('app.string.set_background_blur_style_color_mode'), + selects: getStringArrayData(selectBlurStyleColorModeData), + callback: (index) => { + switch (index) { + case 0: + this.mColorMode = ThemeColorMode.SYSTEM + break + case 1: + this.mColorMode = ThemeColorMode.LIGHT + break + default: + this.mColorMode = ThemeColorMode.DARK + } + } + }) + + CommonItemSelect({ + testId: "test_select2", + name: $r('app.string.set_background_blur_style_adaptive_color'), + selects: getStringArrayData(selectBlurStyleAdaptiveColorData), + callback: (index) => { + switch (index) { + case 0: + this.mAdaptiveColor = AdaptiveColor.DEFAULT + break + default: + this.mAdaptiveColor = AdaptiveColor.AVERAGE + } + } + }) + } + } +} + +@Component +export struct ShadowChangePanel { + @Link mShadowType: ShadowType + + build() { + Column() { + CommonItemSelect({ + testId: "test_select1", + name: $r('app.string.set_shadow_type'), + selects: getStringArrayData(selectShadowTypeData), + callback: (index) => { + switch (index) { + case 0: + this.mShadowType = ShadowType.COLOR + break + default: + this.mShadowType = ShadowType.BLUR + } + } + }) + } + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/foregroundSample/ForegroundSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/foregroundSample/ForegroundSample.ets index 5931b45f5cff9abad470b97edce900fbca0d6b25..ac534f496d92cfa7227b2193ef3ff33637aea5b4 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/foregroundSample/ForegroundSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/foregroundSample/ForegroundSample.ets @@ -1,70 +1,70 @@ -/* - * Copyright (c) 2022-2023 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 { IntroductionTitle } from '../../../../common/IntroductionTitle' -import { TitleBar } from '../../../../common/TitleBar' - -@Extend(Row) function rowStyle() { - .padding(8) - .height(120) - .borderRadius(24) - .backgroundColor(Color.White) - .margin({ bottom: 12 }) -} - -@Extend(Text) function textStyle(marginValue: number) { - .height(80) - .fontSize(18) - .layoutWeight(1) - .fontColor(Color.White) - .textAlign(TextAlign.Center) - .margin({ left: marginValue, right: marginValue }) -} - -@Entry -@Component -struct foreground { - - build() { - Column() { - TitleBar({ title: $r('app.string.prop_foreground') }) - Scroll() { - Column() { - IntroductionTitle({ introduction: $r('app.string.foreground_color') }) - Row() { - Text('Brand') - .textStyle(20) - .backgroundColor($r('app.color.scrollbar_background_color')) - .foregroundColor($r('app.color.background_blue')) - Text('Warning') - .textStyle(20) - .backgroundColor($r('app.color.scrollbar_background_color')) - .foregroundColor($r('app.color.background_orange')) - Text('Danger') - .textStyle(20) - .backgroundColor($r('app.color.scrollbar_background_color')) - .foregroundColor($r('app.color.background_pink')) - } - .rowStyle() - } - .padding({ left: 12, right: 12 }) - .margin({ bottom: 80 }) - .constraintSize({ minHeight: '100%' }) - } - } - .width('100%') - .backgroundColor($r('app.color.background_shallow_grey')) - } +/* + * Copyright (c) 2022-2023 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 { IntroductionTitle } from '../../../../common/IntroductionTitle' +import { TitleBar } from '../../../../common/TitleBar' + +@Extend(Row) function rowStyle() { + .padding(8) + .height(120) + .borderRadius(24) + .backgroundColor(Color.White) + .margin({ bottom: 12 }) +} + +@Extend(Text) function textStyle(marginValue: number) { + .height(80) + .fontSize(18) + .layoutWeight(1) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .margin({ left: marginValue, right: marginValue }) +} + +@Entry +@Component +struct foreground { + + build() { + Column() { + TitleBar({ title: $r('app.string.prop_foreground') }) + Scroll() { + Column() { + IntroductionTitle({ introduction: $r('app.string.foreground_color') }) + Row() { + Text('Brand') + .textStyle(20) + .backgroundColor($r('app.color.scrollbar_background_color')) + .foregroundColor($r('app.color.background_blue')) + Text('Warning') + .textStyle(20) + .backgroundColor($r('app.color.scrollbar_background_color')) + .foregroundColor($r('app.color.background_orange')) + Text('Danger') + .textStyle(20) + .backgroundColor($r('app.color.scrollbar_background_color')) + .foregroundColor($r('app.color.background_pink')) + } + .rowStyle() + } + .padding({ left: 12, right: 12 }) + .margin({ bottom: 80 }) + .constraintSize({ minHeight: '100%' }) + } + } + .width('100%') + .backgroundColor($r('app.color.background_shallow_grey')) + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/safeAreaSample/ChangePanel.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/safeAreaSample/ChangePanel.ets old mode 100755 new mode 100644 diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/safeAreaSample/SafeAreaSample.ets b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/safeAreaSample/SafeAreaSample.ets old mode 100755 new mode 100644 index a5f45070ecfff286b977b5e6e57d2974523d51e3..cc9b30247d8d72b62b6fe7be5f74fbcd97ea38fa --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/safeAreaSample/SafeAreaSample.ets +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/ets/pages/universal/properties/safeAreaSample/SafeAreaSample.ets @@ -1,77 +1,77 @@ -/* - * Copyright (c) 2023-2024 Hunan OpenValley Digital Industry Development 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 { ChangePanel } from './ChangePanel' -import { IntroductionTitle } from '../../../../common/IntroductionTitle' -import { TitleBar } from '../../../../common/TitleBar' - -@Extend(Column) -function columnStyle() { - .width('90%') - .padding(16) - .margin(12) - .borderRadius(24) - .backgroundColor(Color.White) -} - -@Entry -@Component -struct SafeAreaSample { - @State mSafeAreaType: SafeAreaType[] = [SafeAreaType.CUTOUT] - @State mSafeAreaEdge: SafeAreaEdge[] = [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM] - - build() { - Column() { - Stack() { - Row() { - } - .height('100%') - .width('100%') - .backgroundImage($r('app.media.img_test_1')) - .backgroundImageSize(ImageSize.Cover) - .alignItems(VerticalAlign.Top) - .expandSafeArea(this.mSafeAreaType, this.mSafeAreaEdge) - - Column() { - TitleBar({ title: $r('app.string.safe_area') }) - Column() { - IntroductionTitle({ introduction: $r('app.string.safe_area_type_and_safe_area_edge') }) - ChangePanel({ - mSafeAreaType: $mSafeAreaType, - mSafeAreaEdge: $mSafeAreaEdge - }) - } - .columnStyle() - .alignItems(HorizontalAlign.Center) - - TextInput({ placeholder: $r('app.string.save_area_input_text') }) - .width(320) - .height(40) - .fontSize(14) - .fontColor(Color.Black) - .backgroundColor(Color.White) - .enableKeyboardOnFocus(false) - .margin({ top: 200 }) - .placeholderFont({ size: 14, weight: 400 }) - } - .width('100%') - .height('100%') - .alignItems(HorizontalAlign.Center) - } - } - .width('100%') - .height('100%') - } +/* + * Copyright (c) 2023-2024 Hunan OpenValley Digital Industry Development 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 { ChangePanel } from './ChangePanel' +import { IntroductionTitle } from '../../../../common/IntroductionTitle' +import { TitleBar } from '../../../../common/TitleBar' + +@Extend(Column) +function columnStyle() { + .width('90%') + .padding(16) + .margin(12) + .borderRadius(24) + .backgroundColor(Color.White) +} + +@Entry +@Component +struct SafeAreaSample { + @State mSafeAreaType: SafeAreaType[] = [SafeAreaType.CUTOUT] + @State mSafeAreaEdge: SafeAreaEdge[] = [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM] + + build() { + Column() { + Stack() { + Row() { + } + .height('100%') + .width('100%') + .backgroundImage($r('app.media.img_test_1')) + .backgroundImageSize(ImageSize.Cover) + .alignItems(VerticalAlign.Top) + .expandSafeArea(this.mSafeAreaType, this.mSafeAreaEdge) + + Column() { + TitleBar({ title: $r('app.string.safe_area') }) + Column() { + IntroductionTitle({ introduction: $r('app.string.safe_area_type_and_safe_area_edge') }) + ChangePanel({ + mSafeAreaType: $mSafeAreaType, + mSafeAreaEdge: $mSafeAreaEdge + }) + } + .columnStyle() + .alignItems(HorizontalAlign.Center) + + TextInput({ placeholder: $r('app.string.save_area_input_text') }) + .width(320) + .height(40) + .fontSize(14) + .fontColor(Color.Black) + .backgroundColor(Color.White) + .enableKeyboardOnFocus(false) + .margin({ top: 200 }) + .placeholderFont({ size: 14, weight: 400 }) + } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Center) + } + } + .width('100%') + .height('100%') + } } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/resources/ar/element/string.json b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/resources/ar/element/string.json index 20f9c01fac19e6c0edec48f6a3919399e7046e20..0dae5b20325949febaff6e6ae41bd249b186d8f0 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/resources/ar/element/string.json +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/entry/src/main/resources/ar/element/string.json @@ -1,5988 +1,5988 @@ -{ - "string": [ - { - "name": "focus_control_tab_status", - "value": "مركز تنسيق نمط التبديل : لوحة المفاتيح الخارجية تبويب مفتاح التبديل مركز تنسيق عرض التغييرات" - }, - { - "name": "select_to_see_status", - "value": "اختيار نمط الدولة التبديل" - }, - { - "name": "disable_to_see_status", - "value": "تعطيل وضع نمط التبديل" - }, - { - "name": "press_to_see_status", - "value": "اضغط على مفتاح نمط الدولة" - }, - { - "name": "click_to_see_status", - "value": "الوضع العادي نمط التبديل" - }, - { - "name": "custom_event", - "value": "عنصر مخصص توزيع الحدث" - }, - { - "name": "custom_click_event_button", - "value": "نقر" - }, - { - "name": "custom_Scrolling_event_button", - "value": "توالت" - }, - { - "name": "custom_judge_title", - "value": "قاضي" - }, - { - "name": "custom_judge_long_press", - "value": "منطقة استجابة طويلة" - }, - { - "name": "custom_long_press_prompt", - "value": "اضغط على الجزء العلوي من المنطقة الزرقاء لفترة طويلة ، المنطقة الزرقاء سوف تستجيب" - }, - { - "name": "custom_judge_click", - "value": "انقر فوق منطقة الاستجابة" - }, - { - "name": "custom_tap_prompt", - "value": "انقر على الجزء السفلي من المنطقة الصفراء ، المنطقة الصفراء سوف تستجيب" - }, - { - "name": "custom_bigcircle_prompt", - "value": "العرف نصائح دائرة كبيرة" - }, - { - "name": "custom_smallcircle_prompt", - "value": "العرف نصائح دائرة صغيرة" - }, - { - "name": "custom_gesture", - "value": "العرف لفتة تحديد" - }, - { - "name": "send_event", - "value": "إرسال الحدث" - }, - { - "name": "custom_click_event", - "value": "نقر" - }, - { - "name": "custom_scrolling_event", - "value": "توالت" - }, - { - "name": "custom_scrolling_area", - "value": "منطقة التمرير" - }, - { - "name": "custom_click_big_btn", - "value": "دائرة كبيرة" - }, - { - "name": "custom_click_small_btn", - "value": "دائرة صغيرة" - }, - { - "name": "big_circle_prompt", - "value": "المنطقة الزرقاء مع دائرة الحدث" - }, - { - "name": "small_circle_prompt", - "value": "المنطقة الصفراء مع دائرة الأحداث" - }, - { - "name": "Blue", - "value": "بلو" - }, - { - "name": "button", - "value": "الأزرار" - }, - { - "name": "entry_desc", - "value": "مجموعة من المكونات" - }, - { - "name": "MainAbility_desc", - "value": "arkui العنصر ، السمة العامة ، طريقة عامة ، الخ ." - }, - { - "name": "animation", - "value": "أنمي" - }, - { - "name": "component", - "value": "مكون" - }, - { - "name": "universal", - "value": "عام ." - }, - { - "name": "global_method", - "value": "النهج العالمي" - }, - { - "name": "auxiliary", - "value": "المعدات المساعدة" - }, - { - "name": "common_properties", - "value": "السمة المشتركة" - }, - { - "name": "prop_background", - "value": "معلومات أساسية" - }, - { - "name": "safe_area", - "value": "منطقة الأمان" - }, - { - "name": "attribute_modifier", - "value": "خاصية تعديل" - }, - { - "name": "prop_foreground", - "value": "احتمال" - }, - { - "name": "prop_border", - "value": "حدود ." - }, - { - "name": "prop_outline", - "value": "مخطط" - }, - { - "name": "prop_font", - "value": "فونت" - }, - { - "name": "prop_bluefont", - "value": "#409EFF" - }, - { - "name": "prop_orangefont", - "value": "#E6A23C" - }, - { - "name": "prop_pinkfont", - "value": "#F56C6C" - }, - { - "name": "prop_size", - "value": "حجم" - }, - { - "name": "graphic_transformation", - "value": "تحويل الرسومات" - }, - { - "name": "common_events", - "value": "الأحداث المشتركة" - }, - { - "name": "click_event", - "value": "انقر فوق الحدث" - }, - { - "name": "touch_event", - "value": "لمس الحدث" - }, - { - "name": "show_hide_event", - "value": "إظهار / إخفاء الأحداث" - }, - { - "name": "drag_drop_event", - "value": "سحب وإسقاط الحدث" - }, - { - "name": "key_event", - "value": "الأحداث الرئيسية" - }, - { - "name": "focus_event", - "value": "التركيز على النشاط" - }, - { - "name": "mouse_event", - "value": "الماوس الحدث" - }, - { - "name": "component_area_change_event", - "value": "عنصر تغيير الحدث" - }, - { - "name": "gesture_processing", - "value": "لفتة تجهيز" - }, - { - "name": "basic_gestures", - "value": "لفتة الأساسية" - }, - { - "name": "tap_gesture", - "value": "انقر على لفتة" - }, - { - "name": "long_press_gesture", - "value": "لفتة طويلة" - }, - { - "name": "pan_gesture", - "value": "بانجيستور" - }, - { - "name": "pinch_gesture", - "value": "قرصة لفتة" - }, - { - "name": "rotation_gesture", - "value": "لفتة التناوب" - }, - { - "name": "swipe_gesture", - "value": "انزلاق الموقف" - }, - { - "name": "combined_gestures", - "value": "الجمع بين لفتة" - }, - { - "name": "transition_animation", - "value": "الانتقال من الرسوم المتحركة" - }, - { - "name": "interpolation_calculation", - "value": "حساب الاستيفاء" - }, - { - "name": "dialog", - "value": "الحوارات" - }, - { - "name": "button_and_selection", - "value": "أزرار واختيار" - }, - { - "name": "information_presentation_and_dynamic_effects", - "value": "عرض المعلومات و تأثير ديناميكي" - }, - { - "name": "blank_and_divider", - "value": "الفراغات و فواصل" - }, - { - "name": "text_and_input", - "value": "النص والمدخلات" - }, - { - "name": "layout_animation_expansion", - "value": "تصميم الرسوم المتحركة" - }, - { - "name": "layout_animation_expansion_align", - "value": "محاذاة الرسوم المتحركة" - }, - { - "name": "layout_animation_expansion_size", - "value": "حجم الرسوم المتحركة" - }, - { - "name": "layout_animation_expansion_padding", - "value": "ملء الرسوم المتحركة" - }, - { - "name": "layout_animation_expansion_margin", - "value": "الهوامش المتحركة" - }, - { - "name": "layout_animation_expansion_offset", - "value": "إزاحة الرسوم المتحركة" - }, - { - "name": "layout_animation_expansion_position", - "value": "الكلمات المتحركة" - }, - { - "name": "layout_animation_expansion_markAnchor", - "value": "مارك انكور للرسوم المتحركة" - }, - { - "name": "layout_animation_expansion_alignRules", - "value": "alignrules المتحركة" - }, - { - "name": "layout_animation_expansion_direction", - "value": "اتجاه الرسوم المتحركة" - }, - { - "name": "size_transition_expansion", - "value": "بعد الانتقال" - }, - { - "name": "alert_dialog", - "value": "تنبيه الحوار" - }, - { - "name": "alert_dialog_type_one", - "value": "مفتاح إنذار مربع الحوار" - }, - { - "name": "alert_dialog_type_two", - "value": "زر مزدوج مربع الحوار التنبيه" - }, - { - "name": "alert_dialog_type_two_button_one", - "value": "هذا هو الزر الأول" - }, - { - "name": "alert_dialog_type_two_button_two", - "value": "هذا هو الزر الثاني" - }, - { - "name": "alert_dialog_prompt", - "value": "جديلة" - }, - { - "name": "alert_dialog_warning", - "value": "حذر" - }, - { - "name": "alert_dialog_info", - "value": "أنت تقوم بعمل" - }, - { - "name": "alert_dialog_confirm", - "value": "أكّد" - }, - { - "name": "alert_dialog_cancel", - "value": "ألغى" - }, - { - "name": "alert_dialog_type", - "value": "نوع الحوار" - }, - { - "name": "alert_dialog_location", - "value": "موقع المحادثة" - }, - { - "name": "alert_dialog_auto_cancel", - "value": "انقر فوق طبقة قناع لإغلاق مربع الحوار" - }, - { - "name": "alert_dialog_true", - "value": "يمكن إغلاق" - }, - { - "name": "alert_dialog_false", - "value": "لم تغلق" - }, - { - "name": "alert_dialog_top", - "value": "أعلى رأسي" - }, - { - "name": "alert_dialog_center", - "value": "مركز عمودي" - }, - { - "name": "alert_dialog_bottom", - "value": "عمودي أسفل" - }, - { - "name": "alert_dialog_offset", - "value": "الموقف النسبي إزاحة مربع الحوار" - }, - { - "name": "alert_dialog_left", - "value": "أعلى اليسار ويقابل" - }, - { - "name": "alert_dialog_right", - "value": "أسفل اليمين ويقابل" - }, - { - "name": "alert_dialog_grid", - "value": "شبكة مختلفة عرض مربع الحوار" - }, - { - "name": "alert_dialog_grid_two", - "value": "عرض الشبكة" - }, - { - "name": "alert_dialog_grid_three", - "value": "عرض الشبكة" - }, - { - "name": "alert_dialog_grid_four", - "value": "عرض الشبكة" - }, - { - "name": "foreground_color", - "value": "تعيين لون المقدمة" - }, - { - "name": "background_color", - "value": "تعيين لون الخلفية" - }, - { - "name": "background_gradient", - "value": "تعيين خلفية التدرج" - }, - { - "name": "background_gradient_linear", - "value": "التدرج الخطي" - }, - { - "name": "background_gradient_sweep", - "value": "زاوية الانحدار" - }, - { - "name": "background_gradient_radial", - "value": "شعاعي التدرج" - }, - { - "name": "background_image_transformation_effect", - "value": "تحويل صورة الخلفية" - }, - { - "name": "set_background_image_size", - "value": "تعيين حجم الصورة الخلفية" - }, - { - "name": "set_background_image_position", - "value": "وضع صورة الخلفية" - }, - { - "name": "background_image_size_cover", - "value": "تغطية" - }, - { - "name": "background_image_size_contain", - "value": "احتواء" - }, - { - "name": "background_image_position_top_start", - "value": "توب ستارت" - }, - { - "name": "background_image_position_top", - "value": "توب ." - }, - { - "name": "background_image_position_top_end", - "value": "توبند" - }, - { - "name": "background_image_position_start", - "value": "توب ." - }, - { - "name": "background_image_position_center", - "value": "مركز" - }, - { - "name": "background_image_position_end", - "value": "نهاية ." - }, - { - "name": "background_image_position_bottom_start", - "value": "بداية القاع" - }, - { - "name": "background_image_position_bottom", - "value": "القاع" - }, - { - "name": "background_image_position_bottom_end", - "value": "نهاية القاع" - }, - { - "name": "background_image", - "value": "تعيين صورة الخلفية" - }, - { - "name": "background_image_default", - "value": "خرق" - }, - { - "name": "background_image_repeat", - "value": "س ص محور تكرار الرسم البياني" - }, - { - "name": "background_image_size", - "value": "حجم الصورة 50% عرض 100% ارتفاع" - }, - { - "name": "background_image_offset", - "value": "صورة الكلمات يقابلها إلى اليمين أو إلى الأسفل" - }, - { - "name": "auxiliary_badge", - "value": "شارات" - }, - { - "name": "badge_type", - "value": "نوع التسمية" - }, - { - "name": "badge_number", - "value": "العلامات الرقمية" - }, - { - "name": "badge_string", - "value": "نص التسمية" - }, - { - "name": "badge_max", - "value": "العلامة الرقمية أقصى عدد من الرسائل" - }, - { - "name": "badge_number_normal", - "value": "شارة عادية" - }, - { - "name": "badge_number_max", - "value": "ماكس شارات" - }, - { - "name": "badge_location", - "value": "وضع علامة" - }, - { - "name": "badge_left", - "value": "علامة على اليسار" - }, - { - "name": "badge_top", - "value": "أعلى اليمين التسمية" - }, - { - "name": "badge_right", - "value": "علامة الحق" - }, - { - "name": "badge_style", - "value": "علامة نمط" - }, - { - "name": "badge_blue", - "value": "علامة زرقاء كبيرة" - }, - { - "name": "badge_green", - "value": "علامة خضراء صغيرة" - }, - { - "name": "border_type", - "value": "نوع الحدود" - }, - { - "name": "border_type_dashed", - "value": "خط منقط" - }, - { - "name": "border_type_dotted", - "value": "نقطة" - }, - { - "name": "border_type_solid", - "value": "خط صلب" - }, - { - "name": "border_border_style", - "value": "عرض الحدود ، اللون ، فيليه" - }, - { - "name": "border_border_width", - "value": "عرض" - }, - { - "name": "border_border_color", - "value": "الألوان" - }, - { - "name": "border_border_radius", - "value": "فيليه" - }, - { - "name": "border_edge_style", - "value": "تعيين الحدود ، والأساليب ، والصفات ، على التوالي" - }, - { - "name": "border_style_top", - "value": "أعلى الحدود" - }, - { - "name": "border_style_bottom", - "value": "أسفل الحدود" - }, - { - "name": "border_style_left", - "value": "الحدود اليسرى" - }, - { - "name": "border_style_right", - "value": "الحدود اليمنى" - }, - { - "name": "border_radius", - "value": "تعيين أربع زوايا مستديرة" - }, - { - "name": "border_radius_left_top", - "value": "الحدود العليا اليسرى" - }, - { - "name": "border_radius_left_bottom", - "value": "أسفل اليسار الحدود" - }, - { - "name": "border_radius_right_top", - "value": "الحدود العليا اليمنى" - }, - { - "name": "border_radius_right_bottom", - "value": "أسفل الحدود اليمنى" - }, - { - "name": "border_3D", - "value": "تعيين الحدود ثلاثية الأبعاد" - }, - { - "name": "outline_text", - "value": "مخطط" - }, - { - "name": "outline_effect", - "value": "تأثير توقعات" - }, - { - "name": "outline_button", - "value": "الأزرار" - }, - { - "name": "button_title", - "value": "الأزرار" - }, - { - "name": "button_type", - "value": "نوع ." - }, - { - "name": "button_confirm", - "value": "أكّد" - }, - { - "name": "button_type_capsule", - "value": "الكبسولة" - }, - { - "name": "button_type_normal", - "value": "عادي ." - }, - { - "name": "button_type_circle", - "value": "دائرة" - }, - { - "name": "button_state_effect", - "value": "تأثير الدولة" - }, - { - "name": "button_state_effect_true", - "value": "تأثير" - }, - { - "name": "button_state_effect_false", - "value": "لا تأثير" - }, - { - "name": "button_disable_style", - "value": "تعطيل" - }, - { - "name": "button_custom_style", - "value": "نمط مخصص" - }, - { - "name": "button_border_radius", - "value": "جولة زر" - }, - { - "name": "button_with_icon", - "value": "زر الأيقونات" - }, - { - "name": "button_custom_bg_color", - "value": "لون مخصص" - }, - { - "name": "button_click", - "value": "اضغط على زر" - }, - { - "name": "click_action_tips", - "value": "انقر فوق المنطقة الرمادية لتغيير موقف الصليب" - }, - { - "name": "touch_action_tips", - "value": "لمس المنطقة الرمادية والانتقال إلى تغيير موقف الصليب" - }, - { - "name": "component_area_change_action_tips", - "value": "انزلاق يمكن تغيير حجم أو موقف المنطقة الرمادية للسيطرة على حركة الكرة في المنطقة" - }, - { - "name": "get_click_event_detail", - "value": "انقر على معلومات الموقع" - }, - { - "name": "drag_drop_action_tips", - "value": "اضغط على أيقونة التطبيق لفترة طويلة واسحب إلى مناطق مختلفة" - }, - { - "name": "component_drag_and_drop", - "value": "عنصر السحب والإفلات" - }, - { - "name": "griditem", - "value": "شبكة البند" - }, - { - "name": "multiselect", - "value": "اختيار متعددة" - }, - { - "name": "listitem", - "value": "قائمة البنود" - }, - { - "name": "hyperlink", - "value": "ارتباط تشعبي" - }, - { - "name": "text", - "value": "نص ." - }, - { - "name": "image", - "value": "صور" - }, - { - "name": "video", - "value": "فيديو : ." - }, - { - "name": "formcomponent", - "value": "شكل العنصر" - }, - { - "name": "custom_dialog", - "value": "تخصيص مربع الحوار" - }, - { - "name": "custom_dialog_style_custom", - "value": "مربع الحوار نمط مخصص" - }, - { - "name": "custom_dialog_style_custom_true", - "value": "عرف" - }, - { - "name": "custom_dialog_style_custom_false", - "value": "غير مخصص" - }, - { - "name": "custom_dialog_title", - "value": "طلب تمكين الأذونات التالية" - }, - { - "name": "custom_dialog_permission_microphone", - "value": "ميكروفون السلطة" - }, - { - "name": "custom_dialog_permission_microphone_info", - "value": "المكالمات الصوتية تتطلب إذن الميكروفون" - }, - { - "name": "custom_dialog_permission_location", - "value": "موقع السلطة" - }, - { - "name": "custom_dialog_permission_location_info", - "value": "الملاحة يتطلب إذن الموقع" - }, - { - "name": "custom_dialog_start", - "value": "فتح" - }, - { - "name": "date_picker_dialog", - "value": "تاريخ محدد" - }, - { - "name": "date_picker_dialog_date", - "value": "عرض تاريخ الحوار" - }, - { - "name": "date_picker_dialog_date_lunar", - "value": "التاريخ القمري" - }, - { - "name": "date_picker_dialog_date_gregorian", - "value": "تاريخ التقويم الغريغوري" - }, - { - "name": "date_picker_dialog_cancel", - "value": "ألغى" - }, - { - "name": "date_picker_toast_date", - "value": "اختيار الوقت :" - }, - { - "name": "date_picker_dialog_datetimeone", - "value": "2022-10-01" - }, - { - "name": "date_picker_dialog_datetimetwo", - "value": "1970-1-1" - }, - { - "name": "date_picker_dialog_datetimethree", - "value": "2100-12-31" - }, - { - "name": "date_picker_title", - "value": "تاريخ محدد" - }, - { - "name": "date_picker_lunar", - "value": "القمر" - }, - { - "name": "divider_title", - "value": "تحويلة" - }, - { - "name": "divider_stroke_width", - "value": "عرض السكتة الدماغية" - }, - { - "name": "divider_line_color", - "value": "لون الخط" - }, - { - "name": "divider_line_cap", - "value": "لين كابستيل" - }, - { - "name": "divider_horizontal", - "value": "الاتجاه الأفقي" - }, - { - "name": "divider_vertical", - "value": "عمودي" - }, - { - "name": "divider_attribute", - "value": "تحويلة" - }, - { - "name": "font_color", - "value": "الألوان" - }, - { - "name": "font_size", - "value": "حجم" - }, - { - "name": "font_thickness", - "value": "سمك ." - }, - { - "name": "font_style", - "value": "أسلوب ." - }, - { - "name": "interpolation_calculation_cubic_bezier_curve", - "value": "ثالث ترتيب منحنى بيزيير الكائن" - }, - { - "name": "interpolation_calculation_spring", - "value": "منحنى الربيع الكائن" - }, - { - "name": "interpolation_calculation_init_curve", - "value": "easein منحنى تفاضلي" - }, - { - "name": "interpolation_calculation_steps_curve", - "value": "سلم منحنى الكائن" - }, - { - "name": "page_transition", - "value": "التحويل بين الصفحات" - }, - { - "name": "page_transition_left", - "value": "مدخل / مخرج يمين يسار" - }, - { - "name": "page_transition_right", - "value": "المدخل الأيمن / المخرج الأيسر" - }, - { - "name": "page_transition_top", - "value": "أعلى مدخل / مخرج أسفل" - }, - { - "name": "page_transition_bottom", - "value": "أسفل مدخل / مخرج أعلى" - }, - { - "name": "page_transition_scale", - "value": "تكبير / تصغير" - }, - { - "name": "page_transition_rotate", - "value": "برغي في / خارج" - }, - { - "name": "page_transition_back", - "value": "تحويل صفحة العودة بين الصفحات" - }, - { - "name": "qrcode_title", - "value": "قركودي" - }, - { - "name": "qrcode_content", - "value": "المحتويات" - }, - { - "name": "qrcode_color", - "value": "الألوان" - }, - { - "name": "qrcode_enter_content", - "value": "أدخل تغيير رمز ثنائي الأبعاد" - }, - { - "name": "search_placeholder", - "value": "اكتب البحث ." - }, - { - "name": "search_name", - "value": "بحث ." - }, - { - "name": "radio_title", - "value": "راديو ." - }, - { - "name": "radio_no_response_region", - "value": "لا إضافة منطقة استجابة ( اضغط على زر الدخول )" - }, - { - "name": "radio_has_response_region", - "value": "إضافة منطقة استجابة ( انقر على زر خط )" - }, - { - "name": "radio_beijing", - "value": "بيجينغ" - }, - { - "name": "radio_shanghai", - "value": "شنغهاي ." - }, - { - "name": "radio_shenzhen", - "value": "شن تشن" - }, - { - "name": "radio_guangzhou", - "value": "غوانغ زهو" - }, - { - "name": "graphic_transformation_rotate", - "value": "استدارة" - }, - { - "name": "rotate_photo", - "value": "صورة التناوب" - }, - { - "name": "rotate_container", - "value": "عنصر التناوب" - }, - { - "name": "rotate_before_image", - "value": "الصورة الأصلية" - }, - { - "name": "rotate_before_component", - "value": "حاوية الجمعية" - }, - { - "name": "rotate_image_angle", - "value": "دوران" - }, - { - "name": "select_title", - "value": "مختار" - }, - { - "name": "select_has_icon", - "value": "اختيار الرموز" - }, - { - "name": "select_option_bg_and_text_style", - "value": "اختيار لون الخلفية و نمط النص" - }, - { - "name": "select_unselect_option_style", - "value": "خيارات الخلفية و نمط النص" - }, - { - "name": "select_button_style", - "value": "زر القائمة المنسدلة نمط النص" - }, - { - "name": "select_picture", - "value": "صور ." - }, - { - "name": "select_collection", - "value": "جمع" - }, - { - "name": "select_gesture", - "value": "الإيماءات" - }, - { - "name": "select_index", - "value": "حدد مؤشر الخيارات :" - }, - { - "name": "select_value", - "value": "قيمة الخيار المختار :" - }, - { - "name": "share_element_transition", - "value": "عنصر مشترك عملة" - }, - { - "name": "Multiplex_interface", - "value": "معدد" - }, - { - "name": "Floating_window", - "value": "نافذة عائمة" - }, - { - "name": "Tips_call", - "value": "إنتظر" - }, - { - "name": "Font_family_regular", - "value": "هارمونيوس اس سي روتاري" - }, - { - "name": "Font_family_medium", - "value": "هارمونيوس سان SC متوسطة" - }, - { - "name": "Folder_expansion", - "value": "مجلد التمديد" - }, - { - "name": "Shop_card_expansion", - "value": "تمديد بطاقة المحل" - }, - { - "name": "Today", - "value": "اليوم ." - }, - { - "name": "Gallery_card_expansion", - "value": "معرض بطاقة التمديد" - }, - { - "name": "size_width", - "value": "عرض" - }, - { - "name": "size_width_fixed_100vp", - "value": "عرض 100vp" - }, - { - "name": "size_width_percent", - "value": "عرض 60%" - }, - { - "name": "size_width_fixed_60vw", - "value": "عرض" - }, - { - "name": "size_height", - "value": "ارتفاع" - }, - { - "name": "size_height_fixed_60vh", - "value": "عرض 60vh" - }, - { - "name": "size_height_fixed_100vp", - "value": "ارتفاع 100vp" - }, - { - "name": "size_height_percent", - "value": "ارتفاع 60%" - }, - { - "name": "size_height_fixed_calc", - "value": "الارتفاع هو القيمة المحسوبة ( 200vp-100vp ) ." - }, - { - "name": "slider_title", - "value": "المنزلق" - }, - { - "name": "slider_step_tip", - "value": "خطوات ونصائح ( الخطوة 10 )" - }, - { - "name": "slider_current_value", - "value": "عرض القيمة الحالية ( مين - 50 / ماكس - 130 )" - }, - { - "name": "slider_events", - "value": "النشاطات" - }, - { - "name": "slider_attributes", - "value": "صفة" - }, - { - "name": "slider_vertical_reverse", - "value": "عمودي وعكس" - }, - { - "name": "slider_forward", - "value": "فورورد" - }, - { - "name": "slider_reverse", - "value": "عكس" - }, - { - "name": "slider_select_color", - "value": "اختيار اللون" - }, - { - "name": "slider_track_color", - "value": "لون المسار" - }, - { - "name": "slider_block_color", - "value": "لون مربع" - }, - { - "name": "slider_track_thickness", - "value": "سمك المسار" - }, - { - "name": "slider_event_begin", - "value": "تبدأ سحب شريط التمرير" - }, - { - "name": "slider_event_moving", - "value": "أثناء سحب شريط التمرير" - }, - { - "name": "slider_event_end", - "value": "نهاية سحب شريط التمرير" - }, - { - "name": "slider_event_click", - "value": "انقر فوق شريط التمرير لنقل شريط التمرير الموقف" - }, - { - "name": "slider_title_value", - "value": "النسبة المئوية من مجموع طول الشريحة :" - }, - { - "name": "span_title", - "value": "فترة طويلة من الزمن ، بما في ذلك فترة طويلة من الزمن" - }, - { - "name": "span_attribute", - "value": "تكوين خصائص مختلفة تمتد" - }, - { - "name": "span_content_one", - "value": "خفف من الصلب في النار والتبريد السريع ،" - }, - { - "name": "span_content_two", - "value": "لذلك يمكن أن يكون من الصعب ، لا تخاف من أي شيء ." - }, - { - "name": "span_content_three", - "value": "ومن خلال هذه الطريقة أن جيلنا قد تدرب على النضال و التجارب الرهيبة ،" - }, - { - "name": "span_content_four", - "value": "تعلم عدم الاستسلام للحياة ." - }, - { - "name": "span_decoration_and_letter_spacing", - "value": "الديكور و تباعد الحروف" - }, - { - "name": "span_letter_spacing", - "value": "تباعد الحروف" - }, - { - "name": "span_line_height", - "value": "خط الطول" - }, - { - "name": "span_decoration_type", - "value": "نوع الديكور" - }, - { - "name": "span_text_decoration", - "value": "الديكور اختبار النص" - }, - { - "name": "span_text_spacing", - "value": "رسالة الفضاء اختبار النص" - }, - { - "name": "span_inherits_text_attribute", - "value": "سبان يرث خصائص النص" - }, - { - "name": "span_does_not_inherit_text_attribute", - "value": "سبان لا ترث خصائص النص" - }, - { - "name": "span_upper_lower", - "value": "كبيرة أو صغيرة" - }, - { - "name": "span_decoration_color", - "value": "لون الديكور" - }, - { - "name": "span_decoration_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "span_decoration_linethrough", - "value": "خط مباشر" - }, - { - "name": "span_decoration_underline", - "value": "التأكيد" - }, - { - "name": "span_decoration_overline", - "value": "على الخط" - }, - { - "name": "image_span_title", - "value": "صورة تمتد" - }, - { - "name": "image_span_vertical_align", - "value": "المحاذاة العمودية" - }, - { - "name": "image_span_alignment_baseline", - "value": "خط الأساس" - }, - { - "name": "image_span_alignment_bottom", - "value": "القاع" - }, - { - "name": "image_span_alignment_center", - "value": "مركز" - }, - { - "name": "image_span_alignment_top", - "value": "توب ." - }, - { - "name": "image_span_object_fit", - "value": "موضوع مطابقة" - }, - { - "name": "image_fit_contain", - "value": "احتواء" - }, - { - "name": "image_fit_auto", - "value": "السيارات" - }, - { - "name": "image_fit_fill", - "value": "ملأ" - }, - { - "name": "image_fit_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "image_fit_scale_down", - "value": "تقليص حجم" - }, - { - "name": "image_fit_cover", - "value": "تغطية" - }, - { - "name": "image_span_and_span", - "value": "صورة تمتد تمتد" - }, - { - "name": "image_span_vertical_align_and_object_fit", - "value": "المحاذاة العمودية و موضوع تركيب الصورة تمتد" - }, - { - "name": "text_title", - "value": "نص ." - }, - { - "name": "text_width", - "value": "عرض النص" - }, - { - "name": "text_height", - "value": "ارتفاع النص" - }, - { - "name": "text_content", - "value": "خفف من الصلب في النار والتبريد السريع ، بحيث يمكن أن يكون من الصعب جدا ، لا تخافوا من أي شيء . وبهذه الطريقة فقط ، فإن جيلنا قد شحذ في النضال و التجارب الرهيبة و تعلمت عدم الاستسلام للحياة ." - }, - { - "name": "text_text_align_center", - "value": "مركز" - }, - { - "name": "text_text_align_start", - "value": "نقطة الانطلاق" - }, - { - "name": "text_text_align_end", - "value": "نهاية ." - }, - { - "name": "text_decoration_type", - "value": "نص نوع الديكور" - }, - { - "name": "text_decoration_type_under_line", - "value": "دوونلين" - }, - { - "name": "text_decoration_type_line_through", - "value": "من خلال خط" - }, - { - "name": "text_decoration_type_over_line", - "value": "أكثر من خط" - }, - { - "name": "text_text_align_type", - "value": "محاذاة النص" - }, - { - "name": "text_letter_spacing", - "value": "تباعد الحروف" - }, - { - "name": "text_overflow", - "value": "تجاوز النص" - }, - { - "name": "text_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "text_text_over_flow_clip", - "value": "قطع" - }, - { - "name": "text_text_over_flow_ellipsis", - "value": "القطع الناقص" - }, - { - "name": "text_line_height", - "value": "خط الطول" - }, - { - "name": "text_font_color", - "value": "لون الخط" - }, - { - "name": "text_over_flow", - "value": "تجاوز النص" - }, - { - "name": "text_text_case_normal", - "value": "عادي ." - }, - { - "name": "text_text_case", - "value": "حالة النص" - }, - { - "name": "text_text_case_uppercase", - "value": "حروف" - }, - { - "name": "text_text_case_lowercase", - "value": "حروف صغيرة" - }, - { - "name": "text_area_set_text_selection", - "value": "حدد النص" - }, - { - "name": "text_area_set_text_selection_start_select_error", - "value": "خطأ في تحديد بداية اختيار النص" - }, - { - "name": "text_area_set_text_selection_end_select_error", - "value": "خطأ في تحديد نهاية اختيار النص" - }, - { - "name": "text_input_set_text_selection_start_select", - "value": "بدء اختيار :" - }, - { - "name": "text_input_set_text_selection_end_select", - "value": "نهاية الاختيار :" - }, - { - "name": "avoiding_input_method_testing", - "value": "تجنب اختبار طريقة الإدخال" - }, - { - "name": "text_input_title", - "value": "مربع إدخال النص" - }, - { - "name": "text_input_normal_type", - "value": "الأرقام ، الحروف ، يؤكد ، والمسافات ، أحرف خاصة ." - }, - { - "name": "text_input_password_type", - "value": "أدخل كلمة السر" - }, - { - "name": "text_input_email_type", - "value": "أدخل البريد الإلكتروني" - }, - { - "name": "text_input_number_type", - "value": "وضع الإدخال الرقمي" - }, - { - "name": "text_input_phone_type", - "value": "Digits, spaces, plus signs (+), hyphens (-), asterisks (*), and number signs (#)" - }, - { - "name": "text_input_input_type", - "value": "نوع الإدخال" - }, - { - "name": "text_input_current_type", - "value": "النوع الحالي" - }, - { - "name": "text_input_show_password_icon", - "value": "عرض رمز كلمة السر" - }, - { - "name": "text_input_icon_show", - "value": "عرض ." - }, - { - "name": "text_input_icon_hide", - "value": "أخفى" - }, - { - "name": "text_input_event", - "value": "النشاطات" - }, - { - "name": "text_input_event_placeholder", - "value": "نسخ ، لصق ، قص ، ارتكاب ، تحرير الحدث" - }, - { - "name": "text_input_placeholder_style", - "value": "نمط النائبة" - }, - { - "name": "text_input_placeholder", - "value": "النائبة" - }, - { - "name": "text_input_filter", - "value": "فلتر الإدخال" - }, - { - "name": "text_input_only_input_english", - "value": "فقط أدخل الحروف الإنجليزية" - }, - { - "name": "text_input_caret_position", - "value": "موقف التمريض" - }, - { - "name": "text_input_set_text_selection", - "value": "حدد النص" - }, - { - "name": "text_input_max_length", - "value": "الحد من إدخال حرف طول" - }, - { - "name": "text_input_placeholder_max_length", - "value": "ما يصل إلى 12 حرفا" - }, - { - "name": "text_input_toast_paste", - "value": "لصق النص كما يلي :" - }, - { - "name": "text_input_toast_cut", - "value": "قص النص كما يلي :" - }, - { - "name": "text_input_toast_copy", - "value": "نسخ النص كما يلي :" - }, - { - "name": "text_input_toast_submit", - "value": "وفيما يلي نص الطلب :" - }, - { - "name": "text_input_toast_edit", - "value": "نص منقح كما يلي :" - }, - { - "name": "time_picker_dialog", - "value": "وقت الحوار" - }, - { - "name": "time_picker_dialog_time", - "value": "عرض مربع الحوار الوقت" - }, - { - "name": "time_picker_dialog_24_hour", - "value": "ساعة" - }, - { - "name": "time_picker_dialog_12_hour", - "value": "ح" - }, - { - "name": "time_picker_dialog_cancel", - "value": "ألغى" - }, - { - "name": "time_picker_toast_time", - "value": "اختيار الوقت :" - }, - { - "name": "time_picker_options_usemilitarytime", - "value": "استخدام الوقت العسكري" - }, - { - "name": "time_picker_dialog_timeone", - "value": "00 : 00" - }, - { - "name": "time_picker_dialog_timetwo", - "value": "10 / 01 / 2022 12 : 00" - }, - { - "name": "toggle_title", - "value": "تبديل" - }, - { - "name": "toggle_select", - "value": "مختار" - }, - { - "name": "toggle_unselect", - "value": "لا خيار" - }, - { - "name": "toggle_type_switch", - "value": "التبديل" - }, - { - "name": "checkbox", - "value": "خانة الاختيار" - }, - { - "name": "toggle_type_checkbox", - "value": "خانة الاختيار" - }, - { - "name": "toggle_type_button", - "value": "الأزرار" - }, - { - "name": "toggle_state", - "value": "مختار" - }, - { - "name": "graphic_transformation_translate", - "value": "ترجمة ." - }, - { - "name": "translate_image", - "value": "صورة الترجمة" - }, - { - "name": "translate_container", - "value": "عنصر الترجمة" - }, - { - "name": "translate_x_axis", - "value": "المحور العاشر" - }, - { - "name": "translate_y_axis", - "value": "المحور الصادي" - }, - { - "name": "components_display", - "value": "عرض" - }, - { - "name": "components_interaction", - "value": "تفاعلي" - }, - { - "name": "components_interaction_menuone", - "value": "قائمة البند 1" - }, - { - "name": "components_interaction_menutwo", - "value": "قائمة البند 2" - }, - { - "name": "components_interaction_menuthree", - "value": "قائمة البند 3" - }, - { - "name": "components_interaction_menufour", - "value": "قائمة البند 4" - }, - { - "name": "components_interaction_clicktextone", - "value": "معلومات أساسية" - }, - { - "name": "components_interaction_clicktexttwo", - "value": "مكان" - }, - { - "name": "components_interaction_clicktextthree", - "value": "فورجروند كيدز" - }, - { - "name": "components_interaction_hittestbehavior", - "value": "Hittest السلوك :" - }, - { - "name": "components_interaction_hovereffect", - "value": "تأثير تعليق" - }, - { - "name": "components_interaction_backgroundresponse", - "value": "انقر على خلفية الرد" - }, - { - "name": "components_interaction_foregroundresponse", - "value": "استجابة الجبهة انقر" - }, - { - "name": "components_interaction_contentresponse", - "value": "محتوى الرد انقر" - }, - { - "name": "components_display_content", - "value": "ABCDEFG" - }, - { - "name": "components_display_center", - "value": "مركز" - }, - { - "name": "components_display_topstart", - "value": "بداية" - }, - { - "name": "components_display_topend", - "value": "أعلى" - }, - { - "name": "components_display_top", - "value": "توب ." - }, - { - "name": "components_display_start", - "value": "بداية ." - }, - { - "name": "components_display_end", - "value": "نهاية ." - }, - { - "name": "components_display_bottomstart", - "value": "أسفل الحذاء" - }, - { - "name": "components_display_bottom", - "value": "القاع" - }, - { - "name": "components_display_bottomend", - "value": "رئيس كبير" - }, - { - "name": "components_display_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "components_display_hidden", - "value": "أخفى" - }, - { - "name": "components_display_visible", - "value": "مرئي" - }, - { - "name": "components_effects", - "value": "أثر" - }, - { - "name": "blur_effects", - "value": "تأثير ضبابي" - }, - { - "name": "blur_radius_modify", - "value": "نصف قطر غامض" - }, - { - "name": "background_blur", - "value": "الخلفية ضبابية" - }, - { - "name": "background_blur_style", - "value": "طمس الخلفية نمط" - }, - { - "name": "set_shadow_type", - "value": "تعيين نوع الظل" - }, - { - "name": "shadow_effects", - "value": "تأثير الظل" - }, - { - "name": "shadow_effects_content", - "value": "تأثير الظل" - }, - { - "name": "offset_min", - "value": "- 40" - }, - { - "name": "offset_max", - "value": "٤٠" - }, - { - "name": "x_offset", - "value": "س تعويض" - }, - { - "name": "y_offset", - "value": "ذ تعويض" - }, - { - "name": "shadow", - "value": "شادو" - }, - { - "name": "blur", - "value": "طمس" - }, - { - "name": "effects", - "value": "تأثير" - }, - { - "name": "effects_display", - "value": "عرض" - }, - { - "name": "grayscale_change", - "value": "مقياس الرمادية" - }, - { - "name": "brightness_change", - "value": "سطوع" - }, - { - "name": "saturate_change", - "value": "نقع" - }, - { - "name": "constrast_change", - "value": "قيد" - }, - { - "name": "invert_change", - "value": "تحويل" - }, - { - "name": "sepia_change", - "value": "الإنتان" - }, - { - "name": "hueRotate_change", - "value": "هيو روت" - }, - { - "name": "color_blend_change", - "value": "خلط الألوان" - }, - { - "name": "spherical_effect_change", - "value": "تأثير المجال" - }, - { - "name": "light_up_effect_change", - "value": "تأثير الإضاءة" - }, - { - "name": "pixel_stretch_effect_change", - "value": "تأثير بكسل تمتد" - }, - { - "name": "z_index", - "value": "ض مؤشر" - }, - { - "name": "overlay", - "value": "تغطية طبقة" - }, - { - "name": "visibility", - "value": "وضوح" - }, - { - "name": "opacity", - "value": "التعتيم" - }, - { - "name": "z_index_display", - "value": "ض مؤشر" - }, - { - "name": "Red", - "value": "رد : ." - }, - { - "name": "Yellow", - "value": "أصفر" - }, - { - "name": "positon_modify", - "value": "الوظائف" - }, - { - "name": "offset_modify", - "value": "قابل" - }, - { - "name": "visibility_change", - "value": "وضوح" - }, - { - "name": "opacity_change", - "value": "التعتيم" - }, - { - "name": "opacity_display", - "value": "التعتيم عرض" - }, - { - "name": "item_select", - "value": "قائمة البند" - }, - { - "name": "disabled", - "value": "المعوقون" - }, - { - "name": "button_disabled", - "value": "زر تعطيل" - }, - { - "name": "list_disabled", - "value": "قائمة المعوقين" - }, - { - "name": "focus", - "value": "فوكوس" - }, - { - "name": "popup_window", - "value": "نافذة منبثقة" - }, - { - "name": "touch_test", - "value": "لمس ." - }, - { - "name": "touch_region", - "value": "منطقة" - }, - { - "name": "hovereffect", - "value": "تحوم" - }, - { - "name": "bind_menu_customBuilder", - "value": "ربط القائمة custombuilder" - }, - { - "name": "bind_content_menu", - "value": "ربط محتوى القائمة" - }, - { - "name": "click_on_any_action_below", - "value": "انقر فوق أي من الإجراءات التالية" - }, - { - "name": "long_press_any_action_below", - "value": "اضغط على أي من العمليات التالية لفترة طويلة" - }, - { - "name": "bind_menu_content", - "value": "ربط محتوى القائمة" - }, - { - "name": "menu", - "value": "قائمة" - }, - { - "name": "multiState", - "value": "العديد من الدول" - }, - { - "name": "multi_short_key", - "value": "مفاتيح متعددة قصيرة" - }, - { - "name": "set_mouse_style", - "value": "تعيين نمط الماوس" - }, - { - "name": "multimode_input", - "value": "مدخلات المتعدد" - }, - { - "name": "short_key_pressed", - "value": "اضغط على مفتاح قصير" - }, - { - "name": "on_short_key", - "value": "وفي الوقت نفسه ، اضغط على مفتاح الاختصار السيطرة + لتحريك الحدث عن طريق النقر على الزر التالي" - }, - { - "name": "alert", - "value": "تنبيه" - }, - { - "name": "result", - "value": "نتيجة" - }, - { - "name": "popup", - "value": "نافذة منبثقة" - }, - { - "name": "custom_popup", - "value": "العرف المنبثقة" - }, - { - "name": "touch_test_region", - "value": "لمس منطقة الاختبار" - }, - { - "name": "action_sheet_dialog", - "value": "طاولة العمليات في مربع الحوار" - }, - { - "name": "action_sheet_title_autoCancel", - "value": "إذا كانت نافذة منبثقة تلقائيا إلغاء" - }, - { - "name": "action_sheet_click_sheets", - "value": "انقر فوق خيارات المحتوى" - }, - { - "name": "action_sheet_dialog_click_content", - "value": "انقر على المحتوى" - }, - { - "name": "text_picker_dialog", - "value": "نص محدد في مربع الحوار" - }, - { - "name": "text_picker_show", - "value": "عرض مربع الحوار النص" - }, - { - "name": "text_picker_click_text", - "value": "انقر فوق النص" - }, - { - "name": "text_picker_text_peach", - "value": "خوخ ." - }, - { - "name": "text_picker_text_apple", - "value": "تفاحة ." - }, - { - "name": "text_picker_text_orange", - "value": "برتقالي" - }, - { - "name": "text_picker_text_grape", - "value": "كرمة" - }, - { - "name": "text_picker_text_banana", - "value": "موز ." - }, - { - "name": "global_menu", - "value": "ربط قائمة السياق" - }, - { - "name": "global_menu_create_way", - "value": "طريقة الخلق" - }, - { - "name": "global_menu_click_right", - "value": "انقر بزر الماوس الأيمن فوق" - }, - { - "name": "global_menu_long_press", - "value": "الصحافة طويلة" - }, - { - "name": "global_menu_close", - "value": "انقر فوق إغلاق القائمة" - }, - { - "name": "component_transition", - "value": "عنصر التحويل" - }, - { - "name": "component_transition_show", - "value": "عرض ." - }, - { - "name": "component_transition_hide", - "value": "أخفى" - }, - { - "name": "attribute_animation", - "value": "خاصية الرسوم المتحركة" - }, - { - "name": "motion_path", - "value": "مسار الرسوم المتحركة" - }, - { - "name": "animate_to", - "value": "عرض الرسوم المتحركة" - }, - { - "name": "animate_over", - "value": "الانتهاء من الرسوم المتحركة" - }, - { - "name": "attribute_animation_change_size", - "value": "تغيير الحجم" - }, - { - "name": "attribute_animation_play_complete", - "value": "الانتهاء من اللعب" - }, - { - "name": "attribute_animation_unlimited_playback", - "value": "اللعب غير محدود" - }, - { - "name": "attribute_animation_play_speed", - "value": "سرعة اللعب" - }, - { - "name": "attribute_animation_delay", - "value": "تأخير 3 ثوان" - }, - { - "name": "attribute_animation_set_curve", - "value": "تعيين منحنى" - }, - { - "name": "attribute_animation_change_rotation", - "value": "تغيير التناوب" - }, - { - "name": "attribute_animation_play_count", - "value": "لعب" - }, - { - "name": "motion_path_click_me", - "value": "انقر على لي" - }, - { - "name": "general_mount", - "value": "تحميل وتفريغ الحدث" - }, - { - "name": "general_mount_toast", - "value": "جبل الصورة" - }, - { - "name": "general_unmount_toast", - "value": "إلغاء تثبيت الصورة" - }, - { - "name": "general_mount_text", - "value": "انقر فوق تحميل الصور غير المحملة" - }, - { - "name": "general_drag", - "value": "سحب وإسقاط الحدث" - }, - { - "name": "general_drag_text_one", - "value": "هنا ثلاثة عناصر النص ، اضغط باستمرار على النص واسحبه إلى القائمة أدناه" - }, - { - "name": "general_drag_text_two", - "value": "هذا هو عنصر القائمة" - }, - { - "name": "drag_list_one", - "value": "1 ." - }, - { - "name": "drag_list_two", - "value": "2 ." - }, - { - "name": "drag_list_three", - "value": "3 ." - }, - { - "name": "drag_list_four", - "value": "4 ." - }, - { - "name": "size_size", - "value": "حجم ." - }, - { - "name": "size_padding", - "value": "حشية" - }, - { - "name": "size_margin", - "value": "حافة" - }, - { - "name": "size_constraintSize", - "value": "حجم القيد" - }, - { - "name": "response_region", - "value": "منطقة الاستجابة" - }, - { - "name": "touch_hit_subtitle", - "value": "انقر فوق المنطقة الخضراء لتحريك المنطقة الزرقاء رد" - }, - { - "name": "option", - "value": "خيارات" - }, - { - "name": "hover_region", - "value": "تحوم الماوس فوق المنطقة الخضراء لمراقبة تأثير" - }, - { - "name": "multistatus_region", - "value": "تبديل الدولة ومراقبة تأثير" - }, - { - "name": "status_select", - "value": "اختيار الدولة" - }, - { - "name": "scroll_bar", - "value": "شريط التمرير" - }, - { - "name": "scroll_vertical_title", - "value": "التمرير الرأسي" - }, - { - "name": "scroll_horizontal_title", - "value": "التمرير الأفقي" - }, - { - "name": "auxiliary_refresh", - "value": "منعش" - }, - { - "name": "auxiliary_refresh_offset", - "value": "قابل" - }, - { - "name": "auxiliary_refresh_minvalue", - "value": "س" - }, - { - "name": "auxiliary_refresh_maxvalue", - "value": "١٠٠" - }, - { - "name": "auxiliary_refresh_friction", - "value": "احتكاك" - }, - { - "name": "auxiliary_panel", - "value": "لوحة" - }, - { - "name": "auxiliary_alphabetIndexer", - "value": "رسالة مفهرس" - }, - { - "name": "loading_progress", - "value": "تحميل الجدول" - }, - { - "name": "marquee_name", - "value": "ماركيز" - }, - { - "name": "marquee_src", - "value": "مرحبا arkui سلسلة أطول من المحتوى" - }, - { - "name": "marquee_fromstart", - "value": "من البداية" - }, - { - "name": "marquee_step", - "value": "خطوة" - }, - { - "name": "marquee_loop", - "value": "حلقة ." - }, - { - "name": "text_timer", - "value": "النص الموقت" - }, - { - "name": "text_timer_start", - "value": "بداية ." - }, - { - "name": "text_timer_pause", - "value": "وقفة" - }, - { - "name": "text_timer_reset", - "value": "إعادة" - }, - { - "name": "text_timer_iscountdown", - "value": "العد التنازلي" - }, - { - "name": "text_timer_timeformatone", - "value": "مم : الفولاذ المقاوم للصدأ" - }, - { - "name": "text_timer_groupformat", - "value": "شكل ." - }, - { - "name": "text_timer_timeformattwo", - "value": "عالية : مم : ثانية" - }, - { - "name": "text_timer_timeformatthree", - "value": "DD سمو مم SS . اس اس اس" - }, - { - "name": "text_clock", - "value": "كتلة النص" - }, - { - "name": "text_clock_start", - "value": "بداية ." - }, - { - "name": "text_clock_stop", - "value": "توقف" - }, - { - "name": "text_clock_timeformatone", - "value": "عالية : مم : ثانية" - }, - { - "name": "text_clock_groupformat", - "value": "شكل ." - }, - { - "name": "text_clock_timeformattwo", - "value": "السنة : الشهر : النهار" - }, - { - "name": "text_clock_timeformatthree", - "value": "ساعة - دقيقة - ثانية" - }, - { - "name": "progress_name", - "value": "تقدم" - }, - { - "name": "gauge_name", - "value": "متر ." - }, - { - "name": "gauge_value", - "value": "قيمة ." - }, - { - "name": "gauge_strokewidth", - "value": "السكتة الدماغية العرض" - }, - { - "name": "gauge_startangle", - "value": "زاوية البداية" - }, - { - "name": "gauge_endangle", - "value": "نهاية زاوية" - }, - { - "name": "data_panel", - "value": "لوحة البيانات" - }, - { - "name": "checkbox_checkboxgroup", - "value": "فحص مربع مجموعة" - }, - { - "name": "checkbox_title", - "value": "خانة الاختيار" - }, - { - "name": "checkbox_checkbox1", - "value": "خانة الاختيار 1" - }, - { - "name": "checkbox_checkbox2", - "value": "خانة الاختيار 2" - }, - { - "name": "checkbox_checkbox3", - "value": "خانة الاختيار 3" - }, - { - "name": "checkbox_checkgroup", - "value": "مجموعة مربع" - }, - { - "name": "checkbox_checkgroup_title", - "value": "مجموعة مربع" - }, - { - "name": "text_picker", - "value": "نص محدد" - }, - { - "name": "time_picker", - "value": "الوقت محدد" - }, - { - "name": "counter_name", - "value": "مكافحة" - }, - { - "name": "rating_name", - "value": "تصنيفات" - }, - { - "name": "rating_options_indicator", - "value": "المؤشر" - }, - { - "name": "rating_options_value", - "value": "قيمة ." - }, - { - "name": "rating_options_stars", - "value": "نجوم ." - }, - { - "name": "rich_text", - "value": "النص التشعبي" - }, - { - "name": "scroll_swiper", - "value": "المتداول والانزلاق" - }, - { - "name": "scroll_name", - "value": "ورقة لفة" - }, - { - "name": "swiper_name", - "value": "بطاقة ممغنطة" - }, - { - "name": "alphabetindexer_an", - "value": "واحد" - }, - { - "name": "alphabetindexer_bu", - "value": "يوم تقسيم" - }, - { - "name": "alphabetindexer_bai", - "value": "ابيض" - }, - { - "name": "alphabetindexer_bao", - "value": "بالة" - }, - { - "name": "alphabetindexer_bi", - "value": "بی" - }, - { - "name": "alphabetindexer_bing", - "value": "بنج" - }, - { - "name": "alphabetindexer_cao", - "value": "شاو" - }, - { - "name": "alphabetindexer_chen", - "value": "تشان ›" - }, - { - "name": "alphabetindexer_lv", - "value": "لو ." - }, - { - "name": "alphabetindexer_liu3", - "value": "ليو" - }, - { - "name": "alphabetindexer_liu", - "value": "خط وحدة واجهة" - }, - { - "name": "alphabetindexer_li", - "value": "الليثيوم" - }, - { - "name": "alphabetindexer_lou", - "value": "لو ." - }, - { - "name": "alphabetindexer_liang", - "value": "شعاع" - }, - { - "name": "alphabetindexer_lei", - "value": "رعد ." - }, - { - "name": "alphabetindexer_lu", - "value": "أرض ." - }, - { - "name": "alphabetindexer_cui", - "value": "تشوي" - }, - { - "name": "alphabetindexer_cheng", - "value": "تشنغ" - }, - { - "name": "alphabetindexer_list_display", - "value": "عرض قائمة" - }, - { - "name": "alphabetindexer_color_select", - "value": "اختيار اللون" - }, - { - "name": "alphabetindexer_selectedcolor_selectedcolor", - "value": "اختيار اللون" - }, - { - "name": "alphabetindexer_selectedcolor_selectedbgcolor", - "value": "اختيار لون الخلفية" - }, - { - "name": "alphabetindexer_selectedcolor_popupcolor", - "value": "لون النوافذ المنبثقة" - }, - { - "name": "alphabetindexer_selectedcolor_popupbackground", - "value": "الخلفية المنبثقة" - }, - { - "name": "alphabetindexer_selectedcolor_usingpopup", - "value": "استخدام النوافذ المنبثقة" - }, - { - "name": "panel_show_minibar", - "value": "عرض شريط ميني نوع الفريق" - }, - { - "name": "panel_close_minibar", - "value": "إغلاق شريط ميني نوع الفريق" - }, - { - "name": "panel_show_foldable", - "value": "عرض نوع قابلة للطي لوحة" - }, - { - "name": "panel_close_foldable", - "value": "إغلاق لوحة قابلة للطي" - }, - { - "name": "panel_show_temporary", - "value": "عرض لوحة نوع مؤقت" - }, - { - "name": "panel_close_temporary", - "value": "إغلاق لوحة نوع مؤقت" - }, - { - "name": "panel_radio_groupname", - "value": "فاكهة" - }, - { - "name": "checkbox_apple", - "value": "تفاحة ." - }, - { - "name": "checkbox_blueberry", - "value": "عنبية" - }, - { - "name": "checkbox_banbana", - "value": "موز ." - }, - { - "name": "checkbox_cherries", - "value": "كرز ." - }, - { - "name": "checkbox_durian", - "value": "دوريان" - }, - { - "name": "checkbox_orange", - "value": "برتقالي" - }, - { - "name": "checkbox_select_color", - "value": "اختيار اللون" - }, - { - "name": "checkbox_select_all", - "value": "اختيار كامل" - }, - { - "name": "normal_display", - "value": "عرض" - }, - { - "name": "normal_options", - "value": "خيارات" - }, - { - "name": "datapanel_circle", - "value": "دائرة" - }, - { - "name": "datapanel_line", - "value": "خط" - }, - { - "name": "progress_linear", - "value": "التقدم الخطي" - }, - { - "name": "progress_eclipse", - "value": "الكسوف التقدم" - }, - { - "name": "progress_scalering", - "value": "مقياس التقدم" - }, - { - "name": "progress_ring", - "value": "حلقة التقدم" - }, - { - "name": "progress_capsule", - "value": "كبسولة التقدم" - }, - { - "name": "progress_change", - "value": "تغيير الجدول الزمني" - }, - { - "name": "textclock_timeformat", - "value": "شكل الوقت" - }, - { - "name": "scroll_horizontal", - "value": "التمرير الأفقي" - }, - { - "name": "scroll_vertical", - "value": "التمرير الرأسي" - }, - { - "name": "interaction_disable_list", - "value": "قائمة الجرحى" - }, - { - "name": "interaction_show_one_alert", - "value": "انقر على عرض تذكير" - }, - { - "name": "interaction_show_two_alert", - "value": "انقر على زر عرض التنبيه المزدوج" - }, - { - "name": "interaction_placementontop", - "value": "وضع سقف :" - }, - { - "name": "interaction_arrowoffset", - "value": "تغيير إزاحة السهم :" - }, - { - "name": "interaction_showpopup", - "value": "عرض النوافذ المنبثقة" - }, - { - "name": "interaction_showcustompopup", - "value": "عرض مخصص المنبثقة" - }, - { - "name": "pan_start", - "value": "نقطة الانطلاق" - }, - { - "name": "pan_end", - "value": "نهاية ." - }, - { - "name": "pan_button", - "value": "تعديل pangesture الزناد" - }, - { - "name": "pinch_description", - "value": "اضغط على الإطار الأسود مع ثلاثة أصابع" - }, - { - "name": "pinch_scale", - "value": "نسبة العجن لفتة :" - }, - { - "name": "interaction_mask", - "value": "إسمك" - }, - { - "name": "rotation_description", - "value": "تدوير الصندوق الأسود مع اثنين من أصابع" - }, - { - "name": "swipe_description", - "value": "الشريحة بسرعة الصندوق الأسود في أي اتجاه مع إصبع واحد" - }, - { - "name": "combinded_description", - "value": "اضغط واسحب مربع أسود" - }, - { - "name": "transform_translate_invert", - "value": "التكبير مرتين و عكس ( التكبير مرتين )" - }, - { - "name": "key_press_description", - "value": "اضغط على لوحة المفاتيح الخارجية التبويب ، ثم اضغط على أي مفتاح" - }, - { - "name": "april", - "value": "ابريل" - }, - { - "name": "bind_click", - "value": "انقر على لي" - }, - { - "name": "interaction_disable", - "value": "تعطيل المكونات :" - }, - { - "name": "canvas_components", - "value": "قماش الجمعية" - }, - { - "name": "canvas_component_attributes", - "value": "السمة الأساسية" - }, - { - "name": "canvas_component_image_bitmap", - "value": "صورة نقطية" - }, - { - "name": "canvas_component_gradient", - "value": "كسر التدرج" - }, - { - "name": "canvas_component_method", - "value": "الطريقة الأساسية" - }, - { - "name": "canvas_component_path_2d", - "value": "باث" - }, - { - "name": "canvas_component_shadow", - "value": "شادو" - }, - { - "name": "canvas_component_transform", - "value": "تحويل" - }, - { - "name": "canvas_canvasZone", - "value": "قماش المنطقة" - }, - { - "name": "canvas_attributesOperations", - "value": "خاصية التشغيل" - }, - { - "name": "canvas_clearEffects", - "value": "تأثير واضح" - }, - { - "name": "canvas_show_message", - "value": "طباعة وحدة التحكم" - }, - { - "name": "scroll_To_effect", - "value": "انتقل إلى تأثير" - }, - { - "name": "scroller", - "value": "لف الجهاز" - }, - { - "name": "list", - "value": "قائمة" - }, - { - "name": "grid", - "value": "شبكة ." - }, - { - "name": "waterFlow", - "value": "تدفق المياه" - }, - { - "name": "tabs_switch_effect", - "value": "تسمية التبديل تأثير" - }, - { - "name": "image_fit_Full_effect", - "value": "صورة مطابقة / تأثير كامل" - }, - { - "name": "particle_effect", - "value": "تأثير الجسيمات" - }, - { - "name": "particle_spawn", - "value": "وضع البيض" - }, - { - "name": "particle_spawn_stop", - "value": "توقف" - }, - { - "name": "global_bindSheet_menu", - "value": "قائمة أوراق فضفاضة" - }, - { - "name": "global_bindSheet_text_allow_interaction", - "value": "تسمح صفحة التفاعل" - }, - { - "name": "global_bindSheet_text_desc", - "value": "تسمح صفحة وصف التفاعل" - }, - { - "name": "bindSheet_popup_style", - "value": "نمط البوب" - }, - { - "name": "bindSheet_default_popup", - "value": "نافذة منبثقة" - }, - { - "name": "bindSheet_centered_popup", - "value": "تركز نافذة منبثقة" - }, - { - "name": "bindSheet_popup_appears", - "value": "تظهر نافذة منبثقة" - }, - { - "name": "bindSheet_icon", - "value": "آيدول" - }, - { - "name": "bindSheet_blurred_background_texture", - "value": "غامض نسيج الخلفية" - }, - { - "name": "bindSheet_popup_modal_interface", - "value": "طريقة إخراج واجهة" - }, - { - "name": "pop_height", - "value": "بوب هايت" - }, - { - "name": "bindSheet_close_modal", - "value": "وضع قبالة" - }, - { - "name": "bindSheet_close_confirm", - "value": "أكّد" - }, - { - "name": "bindSheet_close_cancel", - "value": "ألغى" - }, - { - "name": "global_popUp_menu", - "value": "نافذة منبثقة" - }, - { - "name": "popUp_width", - "value": "عرض" - }, - { - "name": "placement", - "value": "إعادة التوطين" - }, - { - "name": "popUp_advanced_component", - "value": "بوبوب مكونات متقدمة" - }, - { - "name": "global_menu_avoid_rule", - "value": "قائمة تجنب القاعدة" - }, - { - "name": "global_menu_layout", - "value": "تصميم القائمة" - }, - { - "name": "global_menu_width", - "value": "عرض القائمة" - }, - { - "name": "menu_option", - "value": "قائمة الخيارات" - }, - { - "name": "vertical_layout", - "value": "تخطيط عمودي" - }, - { - "name": "horizontal_layout", - "value": "تخطيط أفقي" - }, - { - "name": "menu_width", - "value": "عرض" - }, - { - "name": "textclock_style", - "value": "أسلوب ." - }, - { - "name": "text_clock_textShadow", - "value": "نص الظل" - }, - { - "name": "text_clock_fontSetting", - "value": "إعدادات الخط" - }, - { - "name": "text_clock_select_button", - "value": "اختيار زر" - }, - { - "name": "text_clock_monospaced_numbers", - "value": "رقم واحد" - }, - { - "name": "text_clock_monovolume_numbers", - "value": "حجم واحد عدد" - }, - { - "name": "text_input_text_selection_menu", - "value": "قائمة اختيار النص" - }, - { - "name": "text_custom_menu", - "value": "نص مخصص القائمة" - }, - { - "name": "text_input_text_copy", - "value": "نسخ" - }, - { - "name": "text_input_text_copy_success", - "value": "نسخة ناجحة" - }, - { - "name": "text_input_text_paste", - "value": "لصق" - }, - { - "name": "text_input_text_paste_success", - "value": "لصق بنجاح" - }, - { - "name": "text_input_text_get", - "value": "الحصول على" - }, - { - "name": "text_input_text_delete", - "value": "حذف النص" - }, - { - "name": "text_input_line_break_strategy", - "value": "كسر استراتيجية" - }, - { - "name": "text_input_line_break_strategy_content", - "value": "أنها يمكن أن تكون مقسمة إلى المدمج في المكونات -- المكونات التي يتم توفيرها مباشرة من قبل arkui الإطار ، مكونات مخصصة -- التي يحددها المطور . المدمج في المكونات تشمل أزرار ، أزرار الراديو ، ومؤشرات التقدم ، والنصوص . يمكنك تعيين عرض هذه المكونات في طريقة ربط الوضع ، مكونات الصفحة مقسمة إلى وحدات واجهة المستخدم منفصلة لإنشاء وتطوير وإعادة استخدام وحدات مختلفة على الصفحة ، مما يجعل الصفحة أكثر هندسة المنحى ." - }, - { - "name": "text_input_word_break", - "value": "قطع" - }, - { - "name": "text_input_word_break_content", - "value": "هذه هي ميزة وضع WordBreak إلى نص WordBreak Taumatawakathangakoauotamateature ، وهذا هو ، عندما كنت لا تعرف ، سوف تجد أنك لا تعرف ." - }, - { - "name": "textarea_character_limit", - "value": "الحد من حرف" - }, - { - "name": "grid_item_polymorphic_styles", - "value": "نمط متعدد الأشكال" - }, - { - "name": "previous", - "value": "سابق" - }, - { - "name": "next_step", - "value": "الخطوة التالية" - }, - { - "name": "text_styled_string_title", - "value": "سلسلة نمط النص" - }, - { - "name": "text_mutable_styled_string", - "value": "نمط سلسلة" - }, - { - "name": "text_mutable_styled_string_start", - "value": "نقطة الانطلاق" - }, - { - "name": "text_mutable_styled_string_length", - "value": "طول ." - }, - { - "name": "text_mutable_styled_error", - "value": "من فضلك أدخل" - }, - { - "name": "text_styled_string_gesture_style", - "value": "لفتة نمط" - }, - { - "name": "rows_and_columns", - "value": "الصفوف والأعمدة" - }, - { - "name": "stack_flex_and_grid", - "value": "كومة ، والانحناء ، تنسجم" - }, - { - "name": "list_and_grid", - "value": "قائمة الشبكة" - }, - { - "name": "navigation", - "value": "ملاحة" - }, - { - "name": "canvas_and_graphic_drawing", - "value": "قماش والرسومات" - }, - { - "name": "size_transition_flex", - "value": "بنت ." - }, - { - "name": "size_transition_grid_item", - "value": "شبكة البند" - }, - { - "name": "size_transition_list_item", - "value": "قائمة البنود" - }, - { - "name": "size_transition_swiper_item", - "value": "مشروع بطاقة ممغنطة" - }, - { - "name": "size_transition_font_size", - "value": "حجم الخط" - }, - { - "name": "size_transition_expansion_tabContent", - "value": "علامة التبويب المحتوى" - }, - { - "name": "set_background_blur_style_color_mode", - "value": "تعيين نمط لون الخلفية الضبابية" - }, - { - "name": "set_background_blur_style_adaptive_color", - "value": "تعيين لون الخلفية الضبابي المتكيف" - }, - { - "name": "blur_style_system", - "value": "نظم" - }, - { - "name": "blur_style_light", - "value": "الإضاءة" - }, - { - "name": "blur_style_dark", - "value": "ظلام ." - }, - { - "name": "blur_style_default", - "value": "خرق" - }, - { - "name": "shadow_type_color", - "value": "الألوان" - }, - { - "name": "shadow_type_blur", - "value": "طمس" - }, - { - "name": "blur_style_average", - "value": "متوسط القيمة" - }, - { - "name": "divider_color_blue", - "value": "بلو" - }, - { - "name": "divider_color_green", - "value": "غرين" - }, - { - "name": "divider_color_orange", - "value": "برتقالي" - }, - { - "name": "divider_color_pink", - "value": "وردي" - }, - { - "name": "divider_line_type_butt", - "value": "السيجارة" - }, - { - "name": "divider_line_type_round", - "value": "دائرة" - }, - { - "name": "divider_line_type_square", - "value": "ساحة" - }, - { - "name": "safe_area_type_and_safe_area_edge", - "value": "safeareatype و safeareedge" - }, - { - "name": "save_area_input_text", - "value": "أدخل كلمة . . ." - }, - { - "name": "safe_area_type", - "value": "نوع المنطقة الأمنية" - }, - { - "name": "safe_area_edge", - "value": "سافاريادج" - }, - { - "name": "safe_area_edge_top", - "value": "توب ." - }, - { - "name": "safe_area_edge_bottom", - "value": "القاع" - }, - { - "name": "safe_area_edge_start", - "value": "بداية ." - }, - { - "name": "safe_area_edge_end", - "value": "نهاية ." - }, - { - "name": "safe_area_type_system", - "value": "نظم" - }, - { - "name": "safe_area_type_cutout", - "value": "شق" - }, - { - "name": "safe_area_type_keyboard", - "value": "لوحة المفاتيح ." - }, - { - "name": "System_icon", - "value": "رمز النظام" - }, - { - "name": "text_content_en", - "value": "خفف من الصلب في النار والتبريد السريع ، بحيث يمكن أن يكون من الصعب جدا ، لا تخافوا من أي شيء . وبهذه الطريقة فقط ، فإن جيلنا قد شحذ في النضال و التجارب الرهيبة و تعلمت عدم الاستسلام للحياة ." - }, - { - "name": "text_content_en_first", - "value": "خفف من الصلب في النار والتبريد السريع ، بحيث يمكن أن يكون من الصعب جدا ، لا تخافوا من أي شيء ." - }, - { - "name": "text_content_en_last", - "value": "وبهذه الطريقة فقط ، فإن جيلنا قد شحذ في النضال و التجارب الرهيبة و تعلمت عدم الاستسلام للحياة ." - }, - { - "name": "touch_hit_test", - "value": "انقر فوق منطقة ساخنة : تعيين منطقة ساخنة في المنطقة الخضراء" - }, - { - "name": "side_bar_effects_title", - "value": "تأثير الشريط الجانبي" - }, - { - "name": "set_side_bar_type", - "value": "تعيين نوع الشريط الجانبي" - }, - { - "name": "side_bar_container_content", - "value": "sidebar محتويات الحاوية" - }, - { - "name": "hide_side_bar", - "value": "إخفاء الشريط الجانبي" - }, - { - "name": "show_side_bar", - "value": "عرض شريط جانبي" - }, - { - "name": "side_bar_type_embed", - "value": "جزءا لا يتجزأ من" - }, - { - "name": "side_bar_type_overlay", - "value": "تغطية طبقة" - }, - { - "name": "side_bar_type_auto", - "value": "السيارات" - }, - { - "name": "auxiliary_refresh_refreshing", - "value": "منعش" - }, - { - "name": "rich_editor", - "value": "ريش ديتور" - }, - { - "name": "rich_editor_style", - "value": "أسلوب ." - }, - { - "name": "rich_editor_title", - "value": "ريش ديتور" - }, - { - "name": "nav_router", - "value": "توجيه الملاحة" - }, - { - "name": "tabs_name", - "value": "تبويب" - }, - { - "name": "select_name", - "value": "مختار" - }, - { - "name": "slider_name", - "value": "المنزلق" - }, - { - "name": "delete_list_item", - "value": "حذف قائمة البند" - }, - { - "name": "size_size_description_one", - "value": "العرض والارتفاع" - }, - { - "name": "size_size_description_two", - "value": "العرض والارتفاع 100%" - }, - { - "name": "size_size_padding_one", - "value": "أعلى ، أسفل ، اليسار واليمين الهوامش الداخلية 10vp" - }, - { - "name": "size_size_padding_two", - "value": "الهامش الداخلي 20%" - }, - { - "name": "size_size_margin_one", - "value": "أعلى ، أسفل ، يسار ، يمين" - }, - { - "name": "size_size_margin_two", - "value": "المسافة الخارجية العليا 20%" - }, - { - "name": "size_size_constraintSize_one", - "value": "الحد الأقصى للعرض والارتفاع 90vp" - }, - { - "name": "size_size_constraintSize_two", - "value": "الحد الأدنى من العرض والارتفاع 80vp" - }, - { - "name": "keyPress_event", - "value": "اضغط على الحدث" - }, - { - "name": "focus_event_description", - "value": "اضغط على علامة التبويب لوحة المفاتيح الخارجية للحصول على التركيز ، ثم اضغط على مفتاح التبديل" - }, - { - "name": "focus_event_button_one", - "value": "الزر الأول" - }, - { - "name": "focus_event_button_two", - "value": "الزر الثاني" - }, - { - "name": "focus_event_button_three", - "value": "الزر الثالث" - }, - { - "name": "focus_event_toast_text", - "value": "الزناد التركيز" - }, - { - "name": "press_event_toast_text", - "value": "زر الزناد الحدث" - }, - { - "name": "press_event_toast_description", - "value": "اضغط على أي مفتاح على لوحة المفاتيح الخارجية" - }, - { - "name": "mouse_event_move_description", - "value": "استخدام الماوس الخارجي للانتقال إلى زر" - }, - { - "name": "mouse_event_click_description", - "value": "استخدام الفأرة الخارجية للنقر على زر" - }, - { - "name": "mouse_event_hover_description", - "value": "ماوس" - }, - { - "name": "mouse_event_onHover_description", - "value": "الماوس لا تتحرك" - }, - { - "name": "mouse_event_onMouse_text", - "value": "على الماوس" - }, - { - "name": "mouse_event_mouseBtn_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "mouse_event_mouseBtn_left", - "value": "يسار ." - }, - { - "name": "mouse_event_mouseBtn_right", - "value": "صحيح ." - }, - { - "name": "mouse_event_mouseBtn_back", - "value": "العودة" - }, - { - "name": "mouse_event_mouseBtn_forward", - "value": "فورورد" - }, - { - "name": "mouse_event_mouseBtn_middle", - "value": "متوسط" - }, - { - "name": "mouse_event_mouseAction_hover", - "value": "تحوم" - }, - { - "name": "mouse_event_mouseAction_press", - "value": "ميديا ." - }, - { - "name": "mouse_event_mouseAction_move", - "value": "تحرك ." - }, - { - "name": "mouse_event_mouseAction_release", - "value": "أطلق" - }, - { - "name": "scroll_event", - "value": "عنصر المنطقة المرئية تغيير الحدث" - }, - { - "name": "scroll_event_description", - "value": "قائمة الشرائح يجعل الصورة تختفي و تظهر" - }, - { - "name": "scroll_event_toast_visible", - "value": "صور حب واضحة للعيان" - }, - { - "name": "scroll_event_toast_invisible", - "value": "صورة الحب اختفى تماما" - }, - { - "name": "location_settings", - "value": "وضع" - }, - { - "name": "location_settings_align", - "value": "طريقة محاذاة" - }, - { - "name": "location_settings_direction", - "value": "تخطيط أفقي" - }, - { - "name": "location_settings_position", - "value": "المواقع المطلقة" - }, - { - "name": "location_settings_markAnchor", - "value": "مجموعة مرساة" - }, - { - "name": "location_settings_offset", - "value": "بالنسبة لتحديد المواقع" - }, - { - "name": "location_settings_alignRules", - "value": "محاذاة القاعدة" - }, - { - "name": "location_settings_bottom_end", - "value": "نهاية القاع" - }, - { - "name": "location_settings_top_start", - "value": "أعلى بداية" - }, - { - "name": "location_settings_center", - "value": "مركز" - }, - { - "name": "location_settings_position_text", - "value": "الموقع ( 30 ، 10 )" - }, - { - "name": "location_settings_position_offSet_text", - "value": "Original : ENGLISH" - }, - { - "name": "layout_constrain", - "value": "تخطيط القيد" - }, - { - "name": "layout_constrain_aspectRatio", - "value": "عنصر نسبة الارتفاع" - }, - { - "name": "layout_constrain_displayPriority", - "value": "عنصر الأولوية" - }, - { - "name": "layout_constrain_big_container", - "value": "حاوية كبيرة" - }, - { - "name": "layout_constrain_middle_container", - "value": "حاوية متوسطة الحجم" - }, - { - "name": "layout_constrain_small_container", - "value": "حاوية صغيرة" - }, - { - "name": "layout_constrain_children_one", - "value": "1 : ( أولوية : 2 )" - }, - { - "name": "layout_constrain_children_two", - "value": "2 : ( الأولوية : 1 )" - }, - { - "name": "layout_constrain_children_three", - "value": "3 : ( الأولوية : 3 )" - }, - { - "name": "layout_constrain_children_four", - "value": "4 : ( الأولوية : 1 )" - }, - { - "name": "layout_constrain_children_five", - "value": "5 - ( الأولوية : 2 )" - }, - { - "name": "layout_constrain_one", - "value": "1 ." - }, - { - "name": "layout_constrain_two", - "value": "2 ." - }, - { - "name": "flex", - "value": "بنت ." - }, - { - "name": "flex_flexBasis", - "value": "فليكسباسيس" - }, - { - "name": "flex_flexGrow", - "value": "فلکسجرو" - }, - { - "name": "flex_flexShrink", - "value": "فليكس شرينك" - }, - { - "name": "flex_alignSelf", - "value": "اليغن سلف" - }, - { - "name": "flex_layoutWeight", - "value": "تخطيط الوزن" - }, - { - "name": "flex_no_layoutWeight", - "value": "عن تخطيط الوزن" - }, - { - "name": "flex_no_alignSelf_70", - "value": "محاذاة النفس ، الارتفاع : 70%" - }, - { - "name": "flex_end_alignSelf", - "value": "محاذاة نهاية النفس" - }, - { - "name": "flex_end_alignSelf_100", - "value": "محاذاة نهاية النفس" - }, - { - "name": "flex_shrink_0", - "value": "فليكس انكماش" - }, - { - "name": "flex_shrink_default", - "value": "فليكس شرينك" - }, - { - "name": "flex_shrink_1", - "value": "فليكس شرينك" - }, - { - "name": "flex_grow_1", - "value": "FlexGrow ( 1 )" - }, - { - "name": "flex_grow_2", - "value": "FlexGrow ( 2 )" - }, - { - "name": "flex_no_alignSelf_100", - "value": "محاذاة الذاتي ، الطول : 100%" - }, - { - "name": "flex_basis_100", - "value": "FlexBasis ( 100 )" - }, - { - "name": "flex_basis_auto", - "value": "FlexBasis ( تلقائي )" - }, - { - "name": "picture_border", - "value": "حدود الصورة" - }, - { - "name": "scale", - "value": "مقياس" - }, - { - "name": "transform", - "value": "تحويل" - }, - { - "name": "scale_image", - "value": "تكبير الصورة" - }, - { - "name": "transform_image", - "value": "تحويل الصورة" - }, - { - "name": "transform_init", - "value": "إنشاء مصفوفة من المرتبة الرابعة" - }, - { - "name": "transform_copy", - "value": "مصفوفة النسخ المتماثل" - }, - { - "name": "transform_combine", - "value": "تأثير مصفوفة تراكب" - }, - { - "name": "transform_invert", - "value": "عكس تأثير المصفوفة" - }, - { - "name": "transform_translate", - "value": "مصفوفة تأثير الترجمة" - }, - { - "name": "transform_scale", - "value": "تأثير حجم المصفوفة" - }, - { - "name": "transform_rotate", - "value": "تأثير مصفوفة التناوب" - }, - { - "name": "transform_transformPoint", - "value": "تأثير مصفوفة تحويل الإحداثيات" - }, - { - "name": "transform_combine_text", - "value": "ترجمة × 20 و التكبير مرتين" - }, - { - "name": "transform_translate_text", - "value": "س : 40 ، ص : 40 ، ض : 20" - }, - { - "name": "transform_scale_text", - "value": "العرض والارتفاع بمقدار مرتين" - }, - { - "name": "transform_rotate_text", - "value": "دوران 30 درجة" - }, - { - "name": "transform_transformPoint_before", - "value": "الإحداثيات بعد تحويل المصفوفة : [ 50 , 50 ]" - }, - { - "name": "transform_transformPoint_after", - "value": "الإحداثيات بعد تحويل المصفوفة : [ 100 , 0 ]" - }, - { - "name": "shape_crop", - "value": "شكل الخياطة" - }, - { - "name": "shape_crop_clip", - "value": "قطع" - }, - { - "name": "shape_crop_mask", - "value": "غطى" - }, - { - "name": "grid_settings", - "value": "إعدادات الشبكة" - }, - { - "name": "grid_settings_sm", - "value": "جهاز عرض خ" - }, - { - "name": "grid_settings_md", - "value": "عرض الجهاز MD" - }, - { - "name": "grid_settings_lg", - "value": "عرض الجهاز إل جي" - }, - { - "name": "grid_settings_useSize", - "value": "استخدام نوع الحجم" - }, - { - "name": "grid_settings_gridSpan", - "value": "gridspan شبكة تعويض" - }, - { - "name": "grid_edgeEffect_spring", - "value": "شبكة حافة تأثير الربيع" - }, - { - "name": "focus_control", - "value": "التركيز على السيطرة" - }, - { - "name": "focus_control_tab", - "value": "التركيز على السيطرة على التبويب" - }, - { - "name": "focus_control_lastPageId", - "value": "معرف الصفحة الأخيرة" - }, - { - "name": "focus_control_success", - "value": "التركيز على السيطرة على النجاح" - }, - { - "name": "focus_control_failed", - "value": "التركيز على السيطرة على الفشل" - }, - { - "name": "focus_control_group1", - "value": "المجموعة الأولى" - }, - { - "name": "focus_control_group2", - "value": "المجموعة الثانية" - }, - { - "name": "focus_control_group3", - "value": "المجموعة الثالثة" - }, - { - "name": "focus_control_input", - "value": "المدخلات" - }, - { - "name": "focus_control_request_focus", - "value": "التركيز على السيطرة على الطلب" - }, - { - "name": "component_id", - "value": "عنصر الهوية" - }, - { - "name": "component_id_onKeyTab", - "value": "اونكي تاب" - }, - { - "name": "component_id_click", - "value": "انقر فوق ابدأ" - }, - { - "name": "component_id_longClick", - "value": "نقرات طويلة" - }, - { - "name": "component_id_onTouch", - "value": "اونتوش" - }, - { - "name": "component_id_onMouse", - "value": "اونموس" - }, - { - "name": "component_id_click_text", - "value": "انقر على زر ابدأ" - }, - { - "name": "component_id_longClick_text", - "value": "تم النقر على زر \" LongClick \" لفترة طويلة" - }, - { - "name": "component_id_onTouch_text", - "value": "انقر على زر \" ontouch \"" - }, - { - "name": "component_id_onMouse_text", - "value": "\" onmouse \" زر في onmouse" - }, - { - "name": "component_blurred", - "value": "عنصر غامض" - }, - { - "name": "component_blurred_thin", - "value": "عنصر غامض رقيقة" - }, - { - "name": "restore_id", - "value": "استعادة الهوية" - }, - { - "name": "gesture_process", - "value": "لفتة العملية" - }, - { - "name": "bind_gesture_methods", - "value": "ملزمة لفتة طريقة" - }, - { - "name": "bind_gesture_priorityGesture", - "value": "prioritygeture يتجاهل النص أولوية تحديد الوالد مكون العمود" - }, - { - "name": "bind_gesture_parallelGesture", - "value": "parallelgesture يحدد الوالد الطفل عنصر العمود ، النص" - }, - { - "name": "bind_gesture_tapGesture", - "value": "انقر على الإيماءات :" - }, - { - "name": "bind_gesture_text", - "value": "نص ." - }, - { - "name": "bind_gesture_column", - "value": "عمود" - }, - { - "name": "double_click", - "value": "نقرا مزدوجا فوق الزناد" - }, - { - "name": "onAction", - "value": "على العمل :" - }, - { - "name": "long_press", - "value": "إصبع واحد طويل اضغط على النص" - }, - { - "name": "long_press_cancel", - "value": "إلغاء النشاط" - }, - { - "name": "long_press_text", - "value": "اضغط على لي مع إصبع واحد ، من فضلك ." - }, - { - "name": "pan_text", - "value": "سحب مربع أسود بأي شكل من الأشكال مع اثنين من أصابع" - }, - { - "name": "pan_text_one", - "value": "سحب مربع أسود مع إصبع واحد اليسار واليمين" - }, - { - "name": "pan_offset", - "value": "( بآلاف دولارات الولايات المتحدة )" - }, - { - "name": "pan_offset_y", - "value": "ي > ?" - }, - { - "name": "pinch_center", - "value": "مركز قرصة الإيماءات :" - }, - { - "name": "rotation_text", - "value": "لفتة التناوب" - }, - { - "name": "swipe_text_speed", - "value": "انزلاق الموقف" - }, - { - "name": "swipe_text_angle", - "value": "انزلاق الموقف" - }, - { - "name": "combinded_pan_start", - "value": "بداية الترجمة" - }, - { - "name": "combinded_pan_update", - "value": "بان التحديث" - }, - { - "name": "combinded_pan_end", - "value": "نهاية وعاء" - }, - { - "name": "combinded_longPress_onAction", - "value": "لونغبريس أون أكشن" - }, - { - "name": "combinded_longPress_end", - "value": "الصحافة نهاية طويلة" - }, - { - "name": "combinded_sequence", - "value": "تسلسل لفتة" - }, - { - "name": "combinded_longPress", - "value": "Longpress على العمل :" - }, - { - "name": "combinded_offset", - "value": "( بآلاف دولارات الولايات المتحدة )" - }, - { - "name": "combinded_x", - "value": "عشرة" - }, - { - "name": "key_press_keyType", - "value": "نوع المفتاح :" - }, - { - "name": "key_press_keyCode", - "value": "رمز المفتاح" - }, - { - "name": "key_press_keyText", - "value": "نص الكلمات الرئيسية :" - }, - { - "name": "key_press_down", - "value": "نزل" - }, - { - "name": "key_press_up", - "value": "صاعد" - }, - { - "name": "componentId_longClick", - "value": "نقرات طويلة" - }, - { - "name": "componentId_onTouch", - "value": "اونتوش" - }, - { - "name": "componentId_onMouse", - "value": "على الماوس" - }, - { - "name": "flex_auto", - "value": "السيارات" - }, - { - "name": "row_title", - "value": "فصيلة" - }, - { - "name": "row_introduction_arguments", - "value": "تعديل خط المعلمة" - }, - { - "name": "row_introduction_properties", - "value": "تعديل خصائص الخط" - }, - { - "name": "row_element_spacing", - "value": "عنصر تباعد" - }, - { - "name": "row_alignitems_top", - "value": "توب ." - }, - { - "name": "row_alignitems_bottom", - "value": "القاع" - }, - { - "name": "row_alignitems_center", - "value": "مركز" - }, - { - "name": "row_justifycontent_start", - "value": "نقطة الانطلاق" - }, - { - "name": "row_justifycontent_center", - "value": "مركز" - }, - { - "name": "row_justifycontent_end", - "value": "نهاية ." - }, - { - "name": "row_justifycontent_spacebetween", - "value": "بين الفراغات" - }, - { - "name": "row_justifycontent_spacearound", - "value": "الفضاء المحيط" - }, - { - "name": "row_justifycontent_spaceevenly", - "value": "مساحة موحدة" - }, - { - "name": "row_justifycontent_description", - "value": "تنسيق المغزل" - }, - { - "name": "row_alignitems_description", - "value": "تنسيق المحور الأفقي" - }, - { - "name": "row_introduction_tips", - "value": "نصيحة" - }, - { - "name": "row_tips", - "value": "عندما المغزل هو من نوع spacetween spacearound , أو spaceeven ، المعلمة الفضاء صف العنصر لا يعمل" - }, - { - "name": "rowsplit_title", - "value": "تقسيم أفقي تخطيط" - }, - { - "name": "rowsplit_introduction_properties", - "value": "تعديل خصائص rowsplit السحب والإسقاط" - }, - { - "name": "rowsplit_drag", - "value": "سحب التبديل" - }, - { - "name": "rowsplit_drag_divider", - "value": "سحب فواصل اليسار واليمين لتغيير الموقف" - }, - { - "name": "column_title", - "value": "عمود" - }, - { - "name": "column_introduction_arguments", - "value": "تعديل خط المعلمة" - }, - { - "name": "column_introduction_properties", - "value": "تعديل خصائص الخط" - }, - { - "name": "column_element_spacing", - "value": "عنصر تباعد" - }, - { - "name": "column_alignitems_start", - "value": "نقطة الانطلاق" - }, - { - "name": "column_alignitems_end", - "value": "نهاية ." - }, - { - "name": "column_alignitems_center", - "value": "مركز" - }, - { - "name": "column_justifycontent_start", - "value": "نقطة الانطلاق" - }, - { - "name": "column_justifycontent_center", - "value": "مركز" - }, - { - "name": "column_justifycontent_end", - "value": "نهاية ." - }, - { - "name": "column_justifycontent_spacebetween", - "value": "بين الفراغات" - }, - { - "name": "column_justifycontent_spacearound", - "value": "الفضاء المحيط" - }, - { - "name": "column_justifycontent_spaceevenly", - "value": "مساحة موحدة" - }, - { - "name": "column_justifycontent_description", - "value": "تنسيق المغزل" - }, - { - "name": "column_alignitems_description", - "value": "تنسيق المحور الأفقي" - }, - { - "name": "column_introduction_tips", - "value": "نصيحة" - }, - { - "name": "column_tips", - "value": "عندما المغزل هو من نوع spacetween spacearound , أو spaceeven ، المعلمة الفضاء صف العنصر لا يعمل" - }, - { - "name": "columnsplit_title", - "value": "تقسيم عمودي تخطيط" - }, - { - "name": "columnsplit_introduction_properties", - "value": "تعديل خاصية السحب والإفلات من columnsplit" - }, - { - "name": "columnsplit_drag", - "value": "سحب التبديل" - }, - { - "name": "columnsplit_introduction_drag_divider", - "value": "اسحب خط التقسيم صعودا وهبوطا لتغيير الموقف" - }, - { - "name": "sidebarcontainer_title", - "value": "sidebar حاوية" - }, - { - "name": "sidebarcontainer_content_text", - "value": "sidebarcontainer : حاوية الشريط الجانبي الذي يوفر عرض وإخفاء الشريط الجانبي . الشريط الجانبي ومحتوى المناطق المحددة من قبل عناصر فرعية ، أول عنصر فرعي يمثل الشريط الجانبي ، والثاني عنصر فرعي يمثل محتوى المنطقة . هذا العنصر هو مدعوم من المعهد الإصدار 8 . إذا كان محتوى جديد يضاف إلى الإصدارات اللاحقة ، الزاوية العليا علامة تستخدم علامة بداية الإصدارات الفردية من المحتوى ." - }, - { - "name": "sidebarcontainer_sidebar_text_one", - "value": "جمع" - }, - { - "name": "sidebarcontainer_sidebar_text_two", - "value": "الصفحة الرئيسية" - }, - { - "name": "sidebarcontainer_argument", - "value": "تعديل sidebarcontainer عينة" - }, - { - "name": "sidebarcontainer_property", - "value": "تعديل sidebarcontainer الملكية" - }, - { - "name": "sidebarcontainer_argument_type", - "value": "الشريط الجانبي نوع العرض" - }, - { - "name": "sidebarcontainer_type_embed", - "value": "جزءا لا يتجزأ من" - }, - { - "name": "sidebarcontainer_type_overlay", - "value": "تغطية طبقة" - }, - { - "name": "sidebarcontainer_show_switch", - "value": "عرض التبديل" - }, - { - "name": "sidebarcontainer_left_margin", - "value": "زر التحكم في المسافة إلى اليسار" - }, - { - "name": "sidebarcontainer_top_margin", - "value": "المسافة من زر التحكم" - }, - { - "name": "sidebarcontainer_show_button_switch", - "value": "زر التحكم عرض التبديل" - }, - { - "name": "sidebarcontainer_position_title", - "value": "الشريط الجانبي يظهر الموقع" - }, - { - "name": "sidebarcontainer_sidebar_show_position_start", - "value": "نقطة الانطلاق" - }, - { - "name": "sidebarcontainer_sidebar_show_position_end", - "value": "نهاية ." - }, - { - "name": "sidebarcontainer_min_width", - "value": "الحد الأدنى من عرض الشريط الجانبي" - }, - { - "name": "sidebarcontainer_max_width", - "value": "أقصى عرض الشريط الجانبي" - }, - { - "name": "sidebarcontainer_auto_hide", - "value": "هو الشريط الجانبي مخفي في الحد الأدنى من الدولة" - }, - { - "name": "sidebarcontainer_divider_width", - "value": "تقسيم خط العرض" - }, - { - "name": "sidebarcontainer_drag_divider", - "value": "اسحب فاصل لتغيير حجم الشريط الجانبي" - }, - { - "name": "sidebarcontainer__is_show_true", - "value": "الشريط الجانبي هو توسيع" - }, - { - "name": "sidebarcontainer__is_show_false", - "value": "الشريط الجانبي مغلق" - }, - { - "name": "stack_title", - "value": "كومة" - }, - { - "name": "stack_alignments_topstart", - "value": "توب ستارت" - }, - { - "name": "stack_alignments_top", - "value": "توب ." - }, - { - "name": "stack_alignments_topend", - "value": "توبند" - }, - { - "name": "stack_alignments_start", - "value": "نقطة الانطلاق" - }, - { - "name": "stack_alignment_center", - "value": "مركز" - }, - { - "name": "stack_alignment_end", - "value": "نهاية ." - }, - { - "name": "stack_alignments_bottomstart", - "value": "بداية القاع" - }, - { - "name": "stack_alignments_bottom", - "value": "القاع" - }, - { - "name": "stack_alignments_bottomend", - "value": "نهاية القاع" - }, - { - "name": "stack_alignment", - "value": "محاذاة المحتوى" - }, - { - "name": "stack_introduction", - "value": "خاصية المكدس والمعلمة aligncontent تم تحديثها" - }, - { - "name": "stack_introduction_zindex", - "value": "أكسيد الزنك" - }, - { - "name": "stack_zindex_four", - "value": "4 ." - }, - { - "name": "stack_zindex_one", - "value": "1 ." - }, - { - "name": "stack_zindex", - "value": "زيندكس" - }, - { - "name": "flex_title", - "value": "بنت ." - }, - { - "name": "flex_introduction_arguments", - "value": "تعديل تخطيط مرن المعلمات" - }, - { - "name": "flex_argument_direction", - "value": "الاتجاه" - }, - { - "name": "flex_argument_direction_row", - "value": "فصيلة" - }, - { - "name": "flex_argument_direction_row_reverse", - "value": "صف عكس" - }, - { - "name": "flex_argument_direction_column", - "value": "عمود" - }, - { - "name": "flex_argument_direction_column_reverse", - "value": "العمود عكس" - }, - { - "name": "flex_argument_wrap", - "value": "تعديل حزمة لتناسب هذا الانحناء" - }, - { - "name": "flex_argument_wrap_no_wrap", - "value": "بدون تغليف" - }, - { - "name": "flex_argument_wrap_wrap", - "value": "لف" - }, - { - "name": "flex_argument_wrap_wrap_reverse", - "value": "التعبئة والتغليف عكس" - }, - { - "name": "flex_introduction_direction", - "value": "تغيير اتجاه جميع الانحناء" - }, - { - "name": "flex_argument_justifycontent", - "value": "تعديل هذا فليكس justifycontent" - }, - { - "name": "flex_argument_justifycontent_start", - "value": "نقطة الانطلاق" - }, - { - "name": "flex_argument_justifycontent_center", - "value": "مركز" - }, - { - "name": "flex_argument_justifycontent_End", - "value": "نهاية ." - }, - { - "name": "flex_argument_justifycontent_space_between", - "value": "بين الفراغات" - }, - { - "name": "flex_argument_justifycontent_space_around", - "value": "الفضاء المحيط" - }, - { - "name": "flex_argument_justifycontent_speac_evenly", - "value": "مساحة موحدة" - }, - { - "name": "flex_argument_alignItems", - "value": "تعديل alignitems في هذا فليكس" - }, - { - "name": "flex_argumen_alignItems_auto", - "value": "السيارات" - }, - { - "name": "flex_argumen_alignItems_start", - "value": "نقطة الانطلاق" - }, - { - "name": "flex_argumen_alignItems_center", - "value": "مركز" - }, - { - "name": "flex_argumen_alignItems_end", - "value": "نهاية ." - }, - { - "name": "flex_argumen_alignItems_stretch", - "value": "امتدت" - }, - { - "name": "flex_argumen_alignItems_baseline", - "value": "خط الأساس" - }, - { - "name": "flex_argument_alignContent", - "value": "تعديل aligncontent هذا فليكس" - }, - { - "name": "gridcontainer_title", - "value": "gridcontainer نظام الشبكة" - }, - { - "name": "gridcontainer_introdional_arguments", - "value": "تعديل gridcontainer المعلمة" - }, - { - "name": "gridcontainer_introdional_properties", - "value": "تعديل خاصية gridcontainer" - }, - { - "name": "gridcontainer_sizetype", - "value": "سيزتايب" - }, - { - "name": "gridcontainer_sizetype_xs", - "value": "اكس اس" - }, - { - "name": "gridcontainer_sizetype_sm", - "value": "خ" - }, - { - "name": "gridcontainer_sizetype_md", - "value": "إم دي" - }, - { - "name": "gridcontainer_sizetype_lg", - "value": "إل جي" - }, - { - "name": "gridcontainer_sizetype_auto", - "value": "السيارات" - }, - { - "name": "gridcontainer_column", - "value": "عمود" - }, - { - "name": "gridcontainer_gutter", - "value": "مزراب" - }, - { - "name": "gridcontainer_margin", - "value": "حافة" - }, - { - "name": "image_video_and_media", - "value": "صورة الفيديو ووسائل الإعلام" - }, - { - "name": "image_title", - "value": "صور" - }, - { - "name": "image_animator_title", - "value": "صورة انيماتور" - }, - { - "name": "video_title", - "value": "فيديو : ." - }, - { - "name": "plugin_component_title", - "value": "المكونات في مكونات" - }, - { - "name": "xcomponent_title", - "value": "العنصر العاشر" - }, - { - "name": "image_show_test", - "value": "عرض الصور" - }, - { - "name": "image_object_fit", - "value": "objectfit ؛ objectfit" - }, - { - "name": "image_sourcesize_height", - "value": "حجم الارتفاع" - }, - { - "name": "image_sourcesize_width", - "value": "حجم العرض" - }, - { - "name": "object_fit_cover", - "value": "تغطية" - }, - { - "name": "object_fit_contain", - "value": "احتواء" - }, - { - "name": "object_fit_auto", - "value": "السيارات" - }, - { - "name": "object_fit_fill", - "value": "ملأ" - }, - { - "name": "object_fit_scale_down", - "value": "تقليص حجم" - }, - { - "name": "object_fit_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "object_fit_change", - "value": "ObjectFitChange" - }, - { - "name": "image_sourcesize_change", - "value": "تغيير حجم المصدر" - }, - { - "name": "image_rendermode_original", - "value": "طريقة التقديم الأصلي" - }, - { - "name": "image_rendermode_template", - "value": "تقديم نموذج" - }, - { - "name": "image_renderMode_change", - "value": "تغيير طريقة التقديم" - }, - { - "name": "image_repeat_xy", - "value": "تكرار س ص" - }, - { - "name": "image_repeat_x", - "value": "تكرار س" - }, - { - "name": "image_repeat_y", - "value": "تكرار ذ" - }, - { - "name": "image_repeat_no", - "value": "لا تكرار" - }, - { - "name": "image_repeat_change", - "value": "تكرار التغييرات" - }, - { - "name": "image_fill_color_title", - "value": "ملء لون العنوان" - }, - { - "name": "image_animator_show", - "value": "صورة انيماتور شو" - }, - { - "name": "image_animator_control", - "value": "imageanimator السيطرة" - }, - { - "name": "video_show", - "value": "عرض الفيديو" - }, - { - "name": "video_auto_play", - "value": "اللعب التلقائي" - }, - { - "name": "video_controls_show", - "value": "عرض التحكم" - }, - { - "name": "video_muted_show", - "value": "عرض صامت" - }, - { - "name": "video_fit_change", - "value": "فيديوفيت" - }, - { - "name": "video_loop_show", - "value": "لوپشو" - }, - { - "name": "video_current_rate_change", - "value": "التغيرات في سعر الصرف الحالي" - }, - { - "name": "video_play_mode", - "value": "طريقة تشغيل الفيديو" - }, - { - "name": "video_play_switch", - "value": "تشغيل الفيديو التبديل" - }, - { - "name": "web_title", - "value": "شبكي" - }, - { - "name": "web_show", - "value": "وان نيتكوم" - }, - { - "name": "web_use_reason", - "value": "سبب" - }, - { - "name": "xcomponent_show", - "value": "إكسكومبونينتشو" - }, - { - "name": "textarea_title", - "value": "حقل النص" - }, - { - "name": "patternlock_title", - "value": "رمز قفل" - }, - { - "name": "search_title", - "value": "بحث ." - }, - { - "name": "textarea_textalign_start", - "value": "نقطة الانطلاق" - }, - { - "name": "textarea_textalign_center", - "value": "مركز" - }, - { - "name": "textarea_textalign_end", - "value": "نهاية ." - }, - { - "name": "textareaa_textalign_change", - "value": "textarealatextalignchange" - }, - { - "name": "textarea_show", - "value": "تكست اريشو" - }, - { - "name": "textarea_control", - "value": "السيطرة على منطقة النص" - }, - { - "name": "textarea_copyoptions_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "textarea_copyoptions_inapp", - "value": "داخل التطبيق" - }, - { - "name": "textarea_copyoptions_localdevice", - "value": "الأجهزة المحلية" - }, - { - "name": "textarea_copyoptions_change", - "value": "تغيير خيارات النسخ المتماثل" - }, - { - "name": "textarea_placeholder_change", - "value": "تغيير النائبة" - }, - { - "name": "textarea_caretcolor_change", - "value": "علوم التمريض" - }, - { - "name": "patternlock_active_color", - "value": "باترن لوك اكتف كولور" - }, - { - "name": "patternlock_path_color", - "value": "patternlockparhcolor" - }, - { - "name": "patternlock_select_color", - "value": "نمط قفل اختيار اللون" - }, - { - "name": "patternlock_regular_color", - "value": "patternlockregular اللون" - }, - { - "name": "patternlock_side_length", - "value": "نمط طول القفل" - }, - { - "name": "patternlock_circle_radius", - "value": "نمط قفل دائرة نصف قطرها" - }, - { - "name": "patternlock_pathstroke_width", - "value": "patternlockpath strokewidth" - }, - { - "name": "patternlock_change", - "value": "تغيير نمط قفل" - }, - { - "name": "search_textalign_change", - "value": "البحث عن النص محاذاة التغييرات" - }, - { - "name": "search_placeholder_change", - "value": "البحث عن تغيير النائبة" - }, - { - "name": "search_copyOption_change", - "value": "البحث عن خيارات النسخ المتماثل التغييرات" - }, - { - "name": "search_change", - "value": "البحث عن التغييرات" - }, - { - "name": "list_title", - "value": "قائمة" - }, - { - "name": "list_introduction_arguments", - "value": "قائمة المعلمات" - }, - { - "name": "list_introduction_properties", - "value": "قائمة خصائص" - }, - { - "name": "list_introduction_state", - "value": "شريط الحالة" - }, - { - "name": "list_properties_direction", - "value": "قائمة الاتجاه" - }, - { - "name": "list_properties_direction_vertical", - "value": "عمودي" - }, - { - "name": "list_properties_direction_Horizontal", - "value": "الاتجاه الأفقي" - }, - { - "name": "list_argument_space", - "value": "الفضاء ." - }, - { - "name": "list_properties_divider_stroke_width", - "value": "فاصل - السكتة الدماغية العرض" - }, - { - "name": "list_properties_scroll_bar_width", - "value": "سكرول بار - عرض" - }, - { - "name": "list_properties_scroll_bar_color", - "value": "سكرول بار - لون" - }, - { - "name": "list_properties_divider_color", - "value": "فاصل - لون" - }, - { - "name": "list_properties_scroll_bar", - "value": "سكرول بار" - }, - { - "name": "list_properties_scroll_bar_off", - "value": "قريب" - }, - { - "name": "list_properties_scroll_bar_on", - "value": "ون" - }, - { - "name": "list_properties_scroll_bar_auto", - "value": "السيارات" - }, - { - "name": "list_properties_initial_index", - "value": "initial index" - }, - { - "name": "list_properties_edge_effect", - "value": "تأثير الحافة" - }, - { - "name": "list_properties_edge_effect_spring", - "value": "الربيع ." - }, - { - "name": "list_properties_edge_effect_fade", - "value": "تلاشى" - }, - { - "name": "list_properties_edge_effect_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "list_properties_chain_animation", - "value": "سلسلة الرسوم المتحركة" - }, - { - "name": "list_properties_multi_selectable", - "value": "اختيار متعددة" - }, - { - "name": "list_properties_lanes", - "value": "حارة" - }, - { - "name": "list_properties_align_list_item", - "value": "اليگنليستیتم" - }, - { - "name": "list_properties_align_list_item_start", - "value": "نقطة الانطلاق" - }, - { - "name": "list_properties_align_list_item_Center", - "value": "مركز" - }, - { - "name": "list_properties_align_list_item_End", - "value": "نهاية ." - }, - { - "name": "list_introduction_delete", - "value": "غادر انقر فوق حذف البند" - }, - { - "name": "list_item_title", - "value": "قائمة البنود" - }, - { - "name": "list_item_properties_selectable", - "value": "اختياري" - }, - { - "name": "list_item_introduction_drag", - "value": "اسحب العناصر مع الماوس لعرض خصائص اختيارية" - }, - { - "name": "list_item_introduction_properties", - "value": "تعديل خصائص listitem" - }, - { - "name": "grid_title", - "value": "شبكة ." - }, - { - "name": "grid_item_title", - "value": "شبكة البند" - }, - { - "name": "grid_properties_columns_template", - "value": "columnstemplate ( السيطرة على نسبة العمود الثالث )" - }, - { - "name": "grid_properties_columns_gap", - "value": "إزالة العمود" - }, - { - "name": "girid_properties_rows_gap", - "value": "روس جاب" - }, - { - "name": "grid_properties_layout_direction", - "value": "تخطيط الاتجاه" - }, - { - "name": "grid_properties_layout_direction_row", - "value": "فصيلة" - }, - { - "name": "grid_properties_layout_direction_column", - "value": "عمود" - }, - { - "name": "grid_properties_layout_direction_row_reverse", - "value": "صف عكس" - }, - { - "name": "grid_properties_layout_direction_column_reverse", - "value": "العمود عكس" - }, - { - "name": "grid_properties_rows_template", - "value": "rowstemplate ( السيطرة على نسبة من السطر الثالث )" - }, - { - "name": "grid_item_introduction", - "value": "تغيير الموقع" - }, - { - "name": "grid_item_row_start", - "value": "تغيير رقم السطر الأول" - }, - { - "name": "grid_item_row_end", - "value": "تعديل رقم خط النهاية" - }, - { - "name": "grid_item_column_start", - "value": "تغيير رقم العمود الأولي" - }, - { - "name": "grid_item_column_end", - "value": "تعديل نهاية العمود رقم" - }, - { - "name": "swiper_introduction_arguments", - "value": "انزلاق تحكم" - }, - { - "name": "swiper_introduction_properties", - "value": "تعديل خصائص المنزلق" - }, - { - "name": "swiper_properties_disable_swipe", - "value": "تعطيل التحول إلى اليسار أو اليمين" - }, - { - "name": "swiper_properties_item_space", - "value": "المسافة بين الصفحات المنزلقة" - }, - { - "name": "swiper_properties_vertical", - "value": "انزلاق عمودي" - }, - { - "name": "swiper_properties_duration", - "value": "مدة الانتقال المتحركة في الألف" - }, - { - "name": "swiper_properties_loop", - "value": "تمكين حلقة" - }, - { - "name": "swiper_properties_interval", - "value": "التلقائي الفاصل الزمني ( الوحدة : ماجستير )" - }, - { - "name": "swiper_controller_next", - "value": "الصفحة التالية" - }, - { - "name": "swiper_controller_previous", - "value": "الصفحة السابقة" - }, - { - "name": "swiper_common_interfaces_and_properties", - "value": "واجهة عامة والممتلكات" - }, - { - "name": "swiper_custom_properties", - "value": "خصائص مخصصة الانتقال المتحركة" - }, - { - "name": "swiper_modify_custom_properties", - "value": "تعديل خصائص مخصصة الانتقال المتحركة" - }, - { - "name": "swiper_custom_property_opacity", - "value": "تغيير التعتيم مدة الرسوم المتحركة" - }, - { - "name": "swiper_custom_property_scale", - "value": "زيادة مدة الصفحة المتحركة" - }, - { - "name": "swiper_close_two_pages_together", - "value": "الجمع بين صفحتين عند التكبير" - }, - { - "name": "swiper_cancel_default_translate", - "value": "إلغاء الترجمة الافتراضية" - }, - { - "name": "swiper_property_auto_play", - "value": "اللعب التلقائي" - }, - { - "name": "swiper_custom_property_curve", - "value": "عرف الانتقال منحنى الرسوم المتحركة" - }, - { - "name": "navRouter_title", - "value": "توجيه الملاحة" - }, - { - "name": "navigation_title", - "value": "ملاحة" - }, - { - "name": "navigation_first_page", - "value": "تصفح الصفحة الرئيسية" - }, - { - "name": "navigation_second_page", - "value": "تصفح ب" - }, - { - "name": "navigation_third_page", - "value": "تصفح ب" - }, - { - "name": "navigation_first_page_push", - "value": "انتقل إلى الصفحة الثانية" - }, - { - "name": "navigation_first_page_active", - "value": "انقر فوق تبديل حالة التنشيط" - }, - { - "name": "navigation_second_page_push", - "value": "انتقل إلى الصفحة الثالثة" - }, - { - "name": "navigation_third_page_back", - "value": "العودة إلى الصفحة الأولى" - }, - { - "name": "navigation_basic_title", - "value": "أساسيات الملاحة" - }, - { - "name": "navigation_expand", - "value": "تكشفت" - }, - { - "name": "navigation_list_expand_title", - "value": "قائمة التصفح يوسع منطقة آمنة" - }, - { - "name": "navigation_bindsheet_title", - "value": "منطقة الأمان" - }, - { - "name": "navigation_expand_title", - "value": "الملاحة في المنطقة الأمنية الموسعة" - }, - { - "name": "navigation_unexpand", - "value": "لا تتكشف" - }, - { - "name": "navigation_split_title", - "value": "الملاحة تقسيم" - }, - { - "name": "navigation_sidebar_title", - "value": "شريط التنقل" - }, - { - "name": "navigation_navbar_list_nopara", - "value": "قائمة" - }, - { - "name": "navigation_navbar_list", - "value": "قائمة د" - }, - { - "name": "navigation_navcontent_list", - "value": "المحتوى د" - }, - { - "name": "navigation_hidebar_title", - "value": "إخفاء شريط التنقل" - }, - { - "name": "navigation_replace_title", - "value": "استبدال الملاحة" - }, - { - "name": "navigation_replace_page", - "value": "استبدال الصفحة الحالية" - }, - { - "name": "navigation_modechange_title", - "value": "تغيير نمط" - }, - { - "name": "navigation_rotate_screen", - "value": "تدوير الشاشة" - }, - { - "name": "navigation_modevalue", - "value": "سمود القيمة" - }, - { - "name": "navigation_mode_callback", - "value": "طريقة الاستدعاء" - }, - { - "name": "navigation_safearea_title", - "value": "سلامة الملاحة في المنطقة" - }, - { - "name": "navigation_safearea_default", - "value": "خرق" - }, - { - "name": "navigation_safearea_expand", - "value": "تكشفت" - }, - { - "name": "navigation_safearea_unexpand", - "value": "لا تتكشف" - }, - { - "name": "navigation_router_title", - "value": "هوب هوب هار" - }, - { - "name": "navigation_router_har1", - "value": "القفز إلى har1" - }, - { - "name": "navigation_router_har2", - "value": "القفز إلى هارتو" - }, - { - "name": "tabs_title", - "value": "تبويب" - }, - { - "name": "tabs_introduction_arguments", - "value": "تعديل بارامترات التبويب" - }, - { - "name": "tabs_introduction_properties", - "value": "تعديل خصائص التبويب" - }, - { - "name": "tabs_arguments_bar_position", - "value": "بار الكلمات" - }, - { - "name": "tabs_arguments_bar_position_start", - "value": "نقطة الانطلاق" - }, - { - "name": "tabs_arguments_bar_position_end", - "value": "نهاية ." - }, - { - "name": "tabs_properties_vertical", - "value": "عمودي" - }, - { - "name": "tabs_properties_bar_mode", - "value": "بار مود" - }, - { - "name": "tabs_properties_bar_mode_fixed", - "value": "ثابت" - }, - { - "name": "tabs_properties_bar_scrollable", - "value": "قابل للتدوير" - }, - { - "name": "tabs_properties_is_scrollable", - "value": "قابل للتدوير" - }, - { - "name": "tabs_properties_animation_duration", - "value": "مدة الرسوم المتحركة ( ماجستير )" - }, - { - "name": "tabs_arguments_controller", - "value": "التبديل إلى مؤشر محدد" - }, - { - "name": "tab_content_title", - "value": "علامة التبويب المحتوى" - }, - { - "name": "tab_content_introduction", - "value": "subtab / أسفل التبويب الجلاد" - }, - { - "name": "tab_content_side", - "value": "تبديل الشريط الجانبي" - }, - { - "name": "stepper_title", - "value": "السائر السائر المشروع" - }, - { - "name": "canvas_title", - "value": "قماش" - }, - { - "name": "circle_title", - "value": "دائرة" - }, - { - "name": "ellipse_title", - "value": "القطع الناقص" - }, - { - "name": "line_title", - "value": "خط" - }, - { - "name": "polyline_title", - "value": "خط الرسم البياني" - }, - { - "name": "path_title", - "value": "مسار" - }, - { - "name": "polygon_title", - "value": "مضلع" - }, - { - "name": "rect_title", - "value": "ناظر" - }, - { - "name": "shape_title", - "value": "شكل ." - }, - { - "name": "circle_change", - "value": "دائرة التغيير" - }, - { - "name": "circle_change_fill", - "value": "دائرة تغيير ملء" - }, - { - "name": "circle_change_radius", - "value": "دائرة نصف قطرها" - }, - { - "name": "circle_change_fillopacity", - "value": "جولة تغيير ملء التعتيم" - }, - { - "name": "circle_change_strokewidth", - "value": "عرض الحلزون" - }, - { - "name": "circle_stroke_dash", - "value": "سيركلي تروك داش" - }, - { - "name": "circle_stroke_color", - "value": "نمط دائري" - }, - { - "name": "circle_stroke_opacity", - "value": "مسار دائري التعتيم" - }, - { - "name": "ellipse_fill", - "value": "بيضاوي الشكل ملء" - }, - { - "name": "ellipse_stroke_color", - "value": "القطع الناقص لون السكتة الدماغية" - }, - { - "name": "ellipse_stroke_width", - "value": "عرض القطع الناقص" - }, - { - "name": "ellipse_width", - "value": "عرض القطع الناقص" - }, - { - "name": "ellipse_height", - "value": "ارتفاع القطع الناقص" - }, - { - "name": "ellipse_fill_opacity", - "value": "بيضاوي الشكل ملء التعتيم" - }, - { - "name": "ellipse_stroke_opacity", - "value": "حذفي ستروبوسكوبيك التعتيم" - }, - { - "name": "ellipse_stroke_dash", - "value": "إليبسو ستروك داش" - }, - { - "name": "line_start_point_x", - "value": "خط البداية س" - }, - { - "name": "line_start_point_y", - "value": "خط البداية ذ" - }, - { - "name": "line_end_point_x", - "value": "خط النهاية ذ" - }, - { - "name": "line_end_point_y", - "value": "خط النهاية ذ" - }, - { - "name": "line_stroke_width", - "value": "خط العرض" - }, - { - "name": "line_stroke_color", - "value": "لون الخط" - }, - { - "name": "line_stroke_opacity", - "value": "خط التعتيم" - }, - { - "name": "line_stroke_dash", - "value": "لين ستروك داش" - }, - { - "name": "polygon_fill", - "value": "مضلع ملء" - }, - { - "name": "polygon_fill_opacity", - "value": "مضلع ملء التعتيم" - }, - { - "name": "polygon_stroke_color", - "value": "مضلع لون السكتة الدماغية" - }, - { - "name": "polygon_stroke_opacity", - "value": "مضلع السكتة الدماغية التعتيم" - }, - { - "name": "polygon_stroke_width", - "value": "عرض مضلع السكتة الدماغية" - }, - { - "name": "polygon_stroke_dash", - "value": "بوليغون ستروك داش" - }, - { - "name": "polyline_first_x", - "value": "بولين فيرست إكس" - }, - { - "name": "polyline_first_y", - "value": "بولين فيرست" - }, - { - "name": "polyline_second_x", - "value": "بولين سيكوندكس" - }, - { - "name": "polyline_second_y", - "value": "بولين سيندي" - }, - { - "name": "polyline_third_x", - "value": "بولين ثيردكس" - }, - { - "name": "polyline_third_y", - "value": "بولين ثيردي" - }, - { - "name": "polyline_stroke_width", - "value": "عرض السكتة الدماغية" - }, - { - "name": "polyline_stroke_color", - "value": "لون الخط" - }, - { - "name": "polyline_stroke_dash", - "value": "بولين ستروك داش" - }, - { - "name": "polyline_stroke_opacity", - "value": "السكتة الدماغية التعتيم" - }, - { - "name": "rect_height", - "value": "ارتفاع المستطيل" - }, - { - "name": "rect_width", - "value": "عرض مستطيل" - }, - { - "name": "rect_radius_width", - "value": "عرض المستطيل" - }, - { - "name": "rect_radius_height", - "value": "ارتفاع المستقيم" - }, - { - "name": "rect_fill_opacity", - "value": "مستطيلة التعتيم" - }, - { - "name": "rect_stroke", - "value": "السكتة الدماغية المستقيم" - }, - { - "name": "rect_stroke_width", - "value": "rectstrokewidth" - }, - { - "name": "rect_stroke_dash", - "value": "ريكت سروك داش" - }, - { - "name": "rect_stroke_opacity", - "value": "rectstrokeopacity" - }, - { - "name": "rect_fill", - "value": "ريكتفيل" - }, - { - "name": "path_line", - "value": "باث لين" - }, - { - "name": "path_triangle", - "value": "باث تريانجل" - }, - { - "name": "path_square", - "value": "باث سكوير" - }, - { - "name": "path_polygon", - "value": "باث بوليغون" - }, - { - "name": "path_camber_first", - "value": "باث كامبر فيرست" - }, - { - "name": "path_camber_second", - "value": "باث كامبر سوند" - }, - { - "name": "path_camber_third", - "value": "باث كامبر ثيرد" - }, - { - "name": "path_commands_select", - "value": "اختيار مسار القيادة" - }, - { - "name": "path_fill", - "value": "باث فيل" - }, - { - "name": "path_fill_opacity", - "value": "pathfill التعتيم" - }, - { - "name": "path_stroke_color", - "value": "باث ستروك كولور" - }, - { - "name": "path_stroke_opacity", - "value": "باث ستوك اوباسيتي" - }, - { - "name": "path_stroke_dash", - "value": "باث ستوك داش" - }, - { - "name": "path_stroke_width", - "value": "باث ستوك ويدث" - }, - { - "name": "shape_fill", - "value": "شكل ملء" - }, - { - "name": "shape_stroke_color", - "value": "شكل ولون السكتة الدماغية" - }, - { - "name": "shape_view_port_x", - "value": "shapeviewportx" - }, - { - "name": "shape_view_port_y", - "value": "شابي فيو بورتي" - }, - { - "name": "shape_view_port_width", - "value": "shapeviewportwidth" - }, - { - "name": "shape_view_port_height", - "value": "shapeviewportheight" - }, - { - "name": "shape_stroke_opacity", - "value": "shapestroke التعتيم" - }, - { - "name": "shape_fill_opacity", - "value": "shapefill التعتيم" - }, - { - "name": "shape_stroke_width", - "value": "شكل عرض السكتة الدماغية" - }, - { - "name": "shape_stroke_dash", - "value": "شابستروك داش" - }, - { - "name": "web", - "value": "شبكي" - }, - { - "name": "canvas_fillStyle", - "value": "فيل ستايل" - }, - { - "name": "canvas_lineWidth", - "value": "خط العرض" - }, - { - "name": "canvas_strokeStyle", - "value": "ستروك ستايل" - }, - { - "name": "canvas_lineCap", - "value": "لين كاب" - }, - { - "name": "canvas_lineJoin", - "value": "خط الانضمام" - }, - { - "name": "canvas_miterLimit", - "value": "ميتر ليميت" - }, - { - "name": "canvas_font", - "value": "فونت" - }, - { - "name": "canvas_textAlign", - "value": "محاذاة النص" - }, - { - "name": "canvas_textBaseline", - "value": "خط النص" - }, - { - "name": "canvas_globalAlpha", - "value": "غلوبال ألفا" - }, - { - "name": "canvas_lineDashOffset", - "value": "لين داش اوفست" - }, - { - "name": "canvas_globalCompositeOperation", - "value": "عملية التوليف العالمية" - }, - { - "name": "canvas_imageSmoothingEnabled", - "value": "imagesmoothing تمكين" - }, - { - "name": "canvas_createLinearGradient", - "value": "إنشاء التدرج الخطي" - }, - { - "name": "cavas_createRadialGradient", - "value": "خلق التدرج الإشعاعي" - }, - { - "name": "canvas_createRadialGradient", - "value": "خلق التدرج الإشعاعي" - }, - { - "name": "canvas_fillRect", - "value": "فيلريكت" - }, - { - "name": "canvas_strokeRect", - "value": "ستروك ريكت" - }, - { - "name": "canvas_fillText", - "value": "فيلت تكست" - }, - { - "name": "canvas_strokeText", - "value": "ستروكيتكست" - }, - { - "name": "canvas_measureText", - "value": "ميسوريتكست" - }, - { - "name": "canvas_stroke", - "value": "( ضرب ، ضرب ، الخ )" - }, - { - "name": "canvas_createPattern", - "value": "كرياتيباترن" - }, - { - "name": "canvas_fill", - "value": "شغل" - }, - { - "name": "canvas_clip", - "value": "قطع" - }, - { - "name": "canvas_rotate", - "value": "استدارة" - }, - { - "name": "canvas_scale", - "value": "مقياس" - }, - { - "name": "canvas_drawImage", - "value": "دراويماغي" - }, - { - "name": "canvas_getImageData", - "value": "الحصول على بيانات الصورة" - }, - { - "name": "canvas_putImageData", - "value": "بوتیمگدیتا" - }, - { - "name": "canvas_setLineDash", - "value": "ست لين داش" - }, - { - "name": "canvas_getLineDash", - "value": "جيتلين داش" - }, - { - "name": "canvas_transferFromImageBitmap", - "value": "transferfrom imagebitmap" - }, - { - "name": "canvas_toDataURL", - "value": "توداتورل" - }, - { - "name": "cavnas_clearRect", - "value": "كلير ريكت" - }, - { - "name": "canvas_clearRect", - "value": "كلير ريكت" - }, - { - "name": "canvas_shadowBlur", - "value": "شادوبلور" - }, - { - "name": "canvas_shadowColor", - "value": "لون الظل" - }, - { - "name": "canvas_shadowOffsetX", - "value": "شادووفسيتكس" - }, - { - "name": "canvas_shadowOffsetY", - "value": "الظل تعويض ذ" - }, - { - "name": "canvas_addColorStop", - "value": "addclorstop" - }, - { - "name": "canvas_beginPath", - "value": "بيغن باث" - }, - { - "name": "canvas_moveTo", - "value": "تحرك" - }, - { - "name": "canvas_lineTo", - "value": "لين تو" - }, - { - "name": "canvas_closePath", - "value": "كلوس باث" - }, - { - "name": "canvas_bezierCurveTo", - "value": "بيزير كيرفيتو" - }, - { - "name": "canvas_quadraticCurveTo", - "value": "الرسم البياني مع منحنى بيزيير" - }, - { - "name": "canvas_arc", - "value": "قوس" - }, - { - "name": "canvas_arcTo", - "value": "اركتو" - }, - { - "name": "canvas_ellipse", - "value": "القطع الناقص" - }, - { - "name": "canvas_rect", - "value": "ريست" - }, - { - "name": "canvas_transform", - "value": "تحول" - }, - { - "name": "canvas_setTransform", - "value": "ست ترانسفورم" - }, - { - "name": "canvas_translate", - "value": "ترجمة ." - }, - { - "name": "canvas_imageSmoothingQuality", - "value": "تجانس الصورة" - }, - { - "name": "navigator_title", - "value": "الملاح" - }, - { - "name": "navigator_first_page", - "value": "الصفحة الأولى من Navigaor" - }, - { - "name": "navigator_second_page", - "value": "الصفحة الثانية من المستكشف" - }, - { - "name": "navigator_third_page", - "value": "الصفحة الثالثة من المستكشف" - }, - { - "name": "navigator_first_page_push", - "value": "انتقل إلى الصفحة الثانية" - }, - { - "name": "navigator_first_page_active", - "value": "انقر فوق تبديل حالة التنشيط" - }, - { - "name": "navigator_second_page_push", - "value": "انتقل إلى الصفحة الثالثة" - }, - { - "name": "navigator_third_page_back", - "value": "العودة إلى الصفحة الأولى" - }, - { - "name": "navigator_return_message", - "value": "! مرحباً - ! مرحباً - هذه هي الصفحة الأولى من المعلمات" - }, - { - "name": "component_id_press_to_see_attributeModifier", - "value": "عرض attributemodifier حسب العنصر رقم" - }, - { - "name": "component_id_click_to_see_attributeModifier", - "value": "انقر على عنصر معرف لعرض attributemodifier" - }, - { - "name": "component_id_disable_to_see_attributeModifier", - "value": "العنصر رقم تعطيل عرض attributemodifier" - }, - { - "name": "component_id_disable_radio", - "value": "العنصر رقم تعطيل الراديو" - }, - { - "name": "component_id_press_list_to_see_attributeModifier", - "value": "عنصر معرف عرض attributemodifier القائمة" - }, - { - "name": "water_flow_title", - "value": "تدفق المياه" - }, - { - "name": "water_flow_controller", - "value": "تحكم تدفق المياه" - }, - { - "name": "water_flow_properties", - "value": "خصائص تدفق المياه" - }, - { - "name": "water_flow_controller_scrollEdge", - "value": "سكرول ايدج" - }, - { - "name": "water_flow_controller_scrollBy", - "value": "المتداول الصحافة" - }, - { - "name": "water_flow_controller_top", - "value": "توب ." - }, - { - "name": "water_flow_controller_bottom", - "value": "القاع" - }, - { - "name": "water_flow_properties_scroll_bar_width", - "value": "scrollbar العرض" - }, - { - "name": "water_flow_properties_scroll_bar_color", - "value": "لون سكرول بار" - }, - { - "name": "water_flow_properties_scroll_bar", - "value": "سكرول بار" - }, - { - "name": "water_flow_properties_edge_effect", - "value": "تأثير الحافة" - }, - { - "name": "water_flow_properties_edge_effect_spring", - "value": "الربيع ." - }, - { - "name": "water_flow_properties_edge_effect_fade", - "value": "تلاشى" - }, - { - "name": "water_flow_properties_edge_effect_none", - "value": "هل أنت بخير ؟ - لا -" - }, - { - "name": "horizontal_reach_start", - "value": "التمرير الأفقي على reachstart" - }, - { - "name": "horizontal_reach_end", - "value": "التمرير الأفقي على reachend" - }, - { - "name": "vertical_reach_start", - "value": "التمرير الرأسي على reachstart" - }, - { - "name": "vertical_reach_end", - "value": "التمرير الرأسي على reachend" - }, - { - "name": "current_initialIndex", - "value": "initialindex الحالي هو :" - }, - { - "name": "modify_initialIndex_tips", - "value": "بعد initialindex التغييرات ، أدخل هذه الصفحة مرة أخرى" - }, - { - "name": "current_scroll_event", - "value": "أحداث التمرير الحالية :" - }, - { - "name": "current_scroll_state", - "value": "الوضع الحالي :" - }, - { - "name": "current_scroll_distance", - "value": "المسافة الحالية التمرير :" - }, - { - "name": "current_scroll_index_first", - "value": "مؤشر التمرير الحالي ، الأول :" - }, - { - "name": "current_scroll_index_last", - "value": "وأخيرا :" - }, - { - "name": "current_event_value", - "value": "لا أحداث" - }, - { - "name": "current_event_on_scroll", - "value": "على المتداول" - }, - { - "name": "current_event_on_scroll_index", - "value": "أونسولل إنديكس" - }, - { - "name": "current_event_on_scroll_start", - "value": "أونسكرول ستارت" - }, - { - "name": "current_event_on_scroll_stop", - "value": "انسكولستوب" - }, - { - "name": "panel_background_color", - "value": "#ffffff" - }, - { - "name": "multiple_attribute_take_effect", - "value": "دينامية مجموعة خصائص العنصر : خصائص متعددة الإعدادات في وقت واحد" - }, - { - "name": "click_to_see_image_border_change", - "value": "انقر على زر عرض تغيير حدود الصورة" - }, - { - "name": "dynamical_updates_ui_directly", - "value": "خصائص العنصر هي مجموعة ديناميكية ، غير الدولة متغير يؤدي مباشرة إلى تحديث واجهة المستخدم" - }, - { - "name": "click_to_see_component_change", - "value": "انقر على زر عرض عنصر تغيير قيمة الممتلكات" - }, - { - "name": "click_to_see_text_component_change", - "value": "انقر فوق تحديث مكونات النص البناء باستخدام المعلمات" - } - ] +{ + "string": [ + { + "name": "focus_control_tab_status", + "value": "مركز تنسيق نمط التبديل : لوحة المفاتيح الخارجية تبويب مفتاح التبديل مركز تنسيق عرض التغييرات" + }, + { + "name": "select_to_see_status", + "value": "اختيار نمط الدولة التبديل" + }, + { + "name": "disable_to_see_status", + "value": "تعطيل وضع نمط التبديل" + }, + { + "name": "press_to_see_status", + "value": "اضغط على مفتاح نمط الدولة" + }, + { + "name": "click_to_see_status", + "value": "الوضع العادي نمط التبديل" + }, + { + "name": "custom_event", + "value": "عنصر مخصص توزيع الحدث" + }, + { + "name": "custom_click_event_button", + "value": "نقر" + }, + { + "name": "custom_Scrolling_event_button", + "value": "توالت" + }, + { + "name": "custom_judge_title", + "value": "قاضي" + }, + { + "name": "custom_judge_long_press", + "value": "منطقة استجابة طويلة" + }, + { + "name": "custom_long_press_prompt", + "value": "اضغط على الجزء العلوي من المنطقة الزرقاء لفترة طويلة ، المنطقة الزرقاء سوف تستجيب" + }, + { + "name": "custom_judge_click", + "value": "انقر فوق منطقة الاستجابة" + }, + { + "name": "custom_tap_prompt", + "value": "انقر على الجزء السفلي من المنطقة الصفراء ، المنطقة الصفراء سوف تستجيب" + }, + { + "name": "custom_bigcircle_prompt", + "value": "العرف نصائح دائرة كبيرة" + }, + { + "name": "custom_smallcircle_prompt", + "value": "العرف نصائح دائرة صغيرة" + }, + { + "name": "custom_gesture", + "value": "العرف لفتة تحديد" + }, + { + "name": "send_event", + "value": "إرسال الحدث" + }, + { + "name": "custom_click_event", + "value": "نقر" + }, + { + "name": "custom_scrolling_event", + "value": "توالت" + }, + { + "name": "custom_scrolling_area", + "value": "منطقة التمرير" + }, + { + "name": "custom_click_big_btn", + "value": "دائرة كبيرة" + }, + { + "name": "custom_click_small_btn", + "value": "دائرة صغيرة" + }, + { + "name": "big_circle_prompt", + "value": "المنطقة الزرقاء مع دائرة الحدث" + }, + { + "name": "small_circle_prompt", + "value": "المنطقة الصفراء مع دائرة الأحداث" + }, + { + "name": "Blue", + "value": "بلو" + }, + { + "name": "button", + "value": "الأزرار" + }, + { + "name": "entry_desc", + "value": "مجموعة من المكونات" + }, + { + "name": "MainAbility_desc", + "value": "arkui العنصر ، السمة العامة ، طريقة عامة ، الخ ." + }, + { + "name": "animation", + "value": "أنمي" + }, + { + "name": "component", + "value": "مكون" + }, + { + "name": "universal", + "value": "عام ." + }, + { + "name": "global_method", + "value": "النهج العالمي" + }, + { + "name": "auxiliary", + "value": "المعدات المساعدة" + }, + { + "name": "common_properties", + "value": "السمة المشتركة" + }, + { + "name": "prop_background", + "value": "معلومات أساسية" + }, + { + "name": "safe_area", + "value": "منطقة الأمان" + }, + { + "name": "attribute_modifier", + "value": "خاصية تعديل" + }, + { + "name": "prop_foreground", + "value": "احتمال" + }, + { + "name": "prop_border", + "value": "حدود ." + }, + { + "name": "prop_outline", + "value": "مخطط" + }, + { + "name": "prop_font", + "value": "فونت" + }, + { + "name": "prop_bluefont", + "value": "#409EFF" + }, + { + "name": "prop_orangefont", + "value": "#E6A23C" + }, + { + "name": "prop_pinkfont", + "value": "#F56C6C" + }, + { + "name": "prop_size", + "value": "حجم" + }, + { + "name": "graphic_transformation", + "value": "تحويل الرسومات" + }, + { + "name": "common_events", + "value": "الأحداث المشتركة" + }, + { + "name": "click_event", + "value": "انقر فوق الحدث" + }, + { + "name": "touch_event", + "value": "لمس الحدث" + }, + { + "name": "show_hide_event", + "value": "إظهار / إخفاء الأحداث" + }, + { + "name": "drag_drop_event", + "value": "سحب وإسقاط الحدث" + }, + { + "name": "key_event", + "value": "الأحداث الرئيسية" + }, + { + "name": "focus_event", + "value": "التركيز على النشاط" + }, + { + "name": "mouse_event", + "value": "الماوس الحدث" + }, + { + "name": "component_area_change_event", + "value": "عنصر تغيير الحدث" + }, + { + "name": "gesture_processing", + "value": "لفتة تجهيز" + }, + { + "name": "basic_gestures", + "value": "لفتة الأساسية" + }, + { + "name": "tap_gesture", + "value": "انقر على لفتة" + }, + { + "name": "long_press_gesture", + "value": "لفتة طويلة" + }, + { + "name": "pan_gesture", + "value": "بانجيستور" + }, + { + "name": "pinch_gesture", + "value": "قرصة لفتة" + }, + { + "name": "rotation_gesture", + "value": "لفتة التناوب" + }, + { + "name": "swipe_gesture", + "value": "انزلاق الموقف" + }, + { + "name": "combined_gestures", + "value": "الجمع بين لفتة" + }, + { + "name": "transition_animation", + "value": "الانتقال من الرسوم المتحركة" + }, + { + "name": "interpolation_calculation", + "value": "حساب الاستيفاء" + }, + { + "name": "dialog", + "value": "الحوارات" + }, + { + "name": "button_and_selection", + "value": "أزرار واختيار" + }, + { + "name": "information_presentation_and_dynamic_effects", + "value": "عرض المعلومات و تأثير ديناميكي" + }, + { + "name": "blank_and_divider", + "value": "الفراغات و فواصل" + }, + { + "name": "text_and_input", + "value": "النص والمدخلات" + }, + { + "name": "layout_animation_expansion", + "value": "تصميم الرسوم المتحركة" + }, + { + "name": "layout_animation_expansion_align", + "value": "محاذاة الرسوم المتحركة" + }, + { + "name": "layout_animation_expansion_size", + "value": "حجم الرسوم المتحركة" + }, + { + "name": "layout_animation_expansion_padding", + "value": "ملء الرسوم المتحركة" + }, + { + "name": "layout_animation_expansion_margin", + "value": "الهوامش المتحركة" + }, + { + "name": "layout_animation_expansion_offset", + "value": "إزاحة الرسوم المتحركة" + }, + { + "name": "layout_animation_expansion_position", + "value": "الكلمات المتحركة" + }, + { + "name": "layout_animation_expansion_markAnchor", + "value": "مارك انكور للرسوم المتحركة" + }, + { + "name": "layout_animation_expansion_alignRules", + "value": "alignrules المتحركة" + }, + { + "name": "layout_animation_expansion_direction", + "value": "اتجاه الرسوم المتحركة" + }, + { + "name": "size_transition_expansion", + "value": "بعد الانتقال" + }, + { + "name": "alert_dialog", + "value": "تنبيه الحوار" + }, + { + "name": "alert_dialog_type_one", + "value": "مفتاح إنذار مربع الحوار" + }, + { + "name": "alert_dialog_type_two", + "value": "زر مزدوج مربع الحوار التنبيه" + }, + { + "name": "alert_dialog_type_two_button_one", + "value": "هذا هو الزر الأول" + }, + { + "name": "alert_dialog_type_two_button_two", + "value": "هذا هو الزر الثاني" + }, + { + "name": "alert_dialog_prompt", + "value": "جديلة" + }, + { + "name": "alert_dialog_warning", + "value": "حذر" + }, + { + "name": "alert_dialog_info", + "value": "أنت تقوم بعمل" + }, + { + "name": "alert_dialog_confirm", + "value": "أكّد" + }, + { + "name": "alert_dialog_cancel", + "value": "ألغى" + }, + { + "name": "alert_dialog_type", + "value": "نوع الحوار" + }, + { + "name": "alert_dialog_location", + "value": "موقع المحادثة" + }, + { + "name": "alert_dialog_auto_cancel", + "value": "انقر فوق طبقة قناع لإغلاق مربع الحوار" + }, + { + "name": "alert_dialog_true", + "value": "يمكن إغلاق" + }, + { + "name": "alert_dialog_false", + "value": "لم تغلق" + }, + { + "name": "alert_dialog_top", + "value": "أعلى رأسي" + }, + { + "name": "alert_dialog_center", + "value": "مركز عمودي" + }, + { + "name": "alert_dialog_bottom", + "value": "عمودي أسفل" + }, + { + "name": "alert_dialog_offset", + "value": "الموقف النسبي إزاحة مربع الحوار" + }, + { + "name": "alert_dialog_left", + "value": "أعلى اليسار ويقابل" + }, + { + "name": "alert_dialog_right", + "value": "أسفل اليمين ويقابل" + }, + { + "name": "alert_dialog_grid", + "value": "شبكة مختلفة عرض مربع الحوار" + }, + { + "name": "alert_dialog_grid_two", + "value": "عرض الشبكة" + }, + { + "name": "alert_dialog_grid_three", + "value": "عرض الشبكة" + }, + { + "name": "alert_dialog_grid_four", + "value": "عرض الشبكة" + }, + { + "name": "foreground_color", + "value": "تعيين لون المقدمة" + }, + { + "name": "background_color", + "value": "تعيين لون الخلفية" + }, + { + "name": "background_gradient", + "value": "تعيين خلفية التدرج" + }, + { + "name": "background_gradient_linear", + "value": "التدرج الخطي" + }, + { + "name": "background_gradient_sweep", + "value": "زاوية الانحدار" + }, + { + "name": "background_gradient_radial", + "value": "شعاعي التدرج" + }, + { + "name": "background_image_transformation_effect", + "value": "تحويل صورة الخلفية" + }, + { + "name": "set_background_image_size", + "value": "تعيين حجم الصورة الخلفية" + }, + { + "name": "set_background_image_position", + "value": "وضع صورة الخلفية" + }, + { + "name": "background_image_size_cover", + "value": "تغطية" + }, + { + "name": "background_image_size_contain", + "value": "احتواء" + }, + { + "name": "background_image_position_top_start", + "value": "توب ستارت" + }, + { + "name": "background_image_position_top", + "value": "توب ." + }, + { + "name": "background_image_position_top_end", + "value": "توبند" + }, + { + "name": "background_image_position_start", + "value": "توب ." + }, + { + "name": "background_image_position_center", + "value": "مركز" + }, + { + "name": "background_image_position_end", + "value": "نهاية ." + }, + { + "name": "background_image_position_bottom_start", + "value": "بداية القاع" + }, + { + "name": "background_image_position_bottom", + "value": "القاع" + }, + { + "name": "background_image_position_bottom_end", + "value": "نهاية القاع" + }, + { + "name": "background_image", + "value": "تعيين صورة الخلفية" + }, + { + "name": "background_image_default", + "value": "خرق" + }, + { + "name": "background_image_repeat", + "value": "س ص محور تكرار الرسم البياني" + }, + { + "name": "background_image_size", + "value": "حجم الصورة 50% عرض 100% ارتفاع" + }, + { + "name": "background_image_offset", + "value": "صورة الكلمات يقابلها إلى اليمين أو إلى الأسفل" + }, + { + "name": "auxiliary_badge", + "value": "شارات" + }, + { + "name": "badge_type", + "value": "نوع التسمية" + }, + { + "name": "badge_number", + "value": "العلامات الرقمية" + }, + { + "name": "badge_string", + "value": "نص التسمية" + }, + { + "name": "badge_max", + "value": "العلامة الرقمية أقصى عدد من الرسائل" + }, + { + "name": "badge_number_normal", + "value": "شارة عادية" + }, + { + "name": "badge_number_max", + "value": "ماكس شارات" + }, + { + "name": "badge_location", + "value": "وضع علامة" + }, + { + "name": "badge_left", + "value": "علامة على اليسار" + }, + { + "name": "badge_top", + "value": "أعلى اليمين التسمية" + }, + { + "name": "badge_right", + "value": "علامة الحق" + }, + { + "name": "badge_style", + "value": "علامة نمط" + }, + { + "name": "badge_blue", + "value": "علامة زرقاء كبيرة" + }, + { + "name": "badge_green", + "value": "علامة خضراء صغيرة" + }, + { + "name": "border_type", + "value": "نوع الحدود" + }, + { + "name": "border_type_dashed", + "value": "خط منقط" + }, + { + "name": "border_type_dotted", + "value": "نقطة" + }, + { + "name": "border_type_solid", + "value": "خط صلب" + }, + { + "name": "border_border_style", + "value": "عرض الحدود ، اللون ، فيليه" + }, + { + "name": "border_border_width", + "value": "عرض" + }, + { + "name": "border_border_color", + "value": "الألوان" + }, + { + "name": "border_border_radius", + "value": "فيليه" + }, + { + "name": "border_edge_style", + "value": "تعيين الحدود ، والأساليب ، والصفات ، على التوالي" + }, + { + "name": "border_style_top", + "value": "أعلى الحدود" + }, + { + "name": "border_style_bottom", + "value": "أسفل الحدود" + }, + { + "name": "border_style_left", + "value": "الحدود اليسرى" + }, + { + "name": "border_style_right", + "value": "الحدود اليمنى" + }, + { + "name": "border_radius", + "value": "تعيين أربع زوايا مستديرة" + }, + { + "name": "border_radius_left_top", + "value": "الحدود العليا اليسرى" + }, + { + "name": "border_radius_left_bottom", + "value": "أسفل اليسار الحدود" + }, + { + "name": "border_radius_right_top", + "value": "الحدود العليا اليمنى" + }, + { + "name": "border_radius_right_bottom", + "value": "أسفل الحدود اليمنى" + }, + { + "name": "border_3D", + "value": "تعيين الحدود ثلاثية الأبعاد" + }, + { + "name": "outline_text", + "value": "مخطط" + }, + { + "name": "outline_effect", + "value": "تأثير توقعات" + }, + { + "name": "outline_button", + "value": "الأزرار" + }, + { + "name": "button_title", + "value": "الأزرار" + }, + { + "name": "button_type", + "value": "نوع ." + }, + { + "name": "button_confirm", + "value": "أكّد" + }, + { + "name": "button_type_capsule", + "value": "الكبسولة" + }, + { + "name": "button_type_normal", + "value": "عادي ." + }, + { + "name": "button_type_circle", + "value": "دائرة" + }, + { + "name": "button_state_effect", + "value": "تأثير الدولة" + }, + { + "name": "button_state_effect_true", + "value": "تأثير" + }, + { + "name": "button_state_effect_false", + "value": "لا تأثير" + }, + { + "name": "button_disable_style", + "value": "تعطيل" + }, + { + "name": "button_custom_style", + "value": "نمط مخصص" + }, + { + "name": "button_border_radius", + "value": "جولة زر" + }, + { + "name": "button_with_icon", + "value": "زر الأيقونات" + }, + { + "name": "button_custom_bg_color", + "value": "لون مخصص" + }, + { + "name": "button_click", + "value": "اضغط على زر" + }, + { + "name": "click_action_tips", + "value": "انقر فوق المنطقة الرمادية لتغيير موقف الصليب" + }, + { + "name": "touch_action_tips", + "value": "لمس المنطقة الرمادية والانتقال إلى تغيير موقف الصليب" + }, + { + "name": "component_area_change_action_tips", + "value": "انزلاق يمكن تغيير حجم أو موقف المنطقة الرمادية للسيطرة على حركة الكرة في المنطقة" + }, + { + "name": "get_click_event_detail", + "value": "انقر على معلومات الموقع" + }, + { + "name": "drag_drop_action_tips", + "value": "اضغط على أيقونة التطبيق لفترة طويلة واسحب إلى مناطق مختلفة" + }, + { + "name": "component_drag_and_drop", + "value": "عنصر السحب والإفلات" + }, + { + "name": "griditem", + "value": "شبكة البند" + }, + { + "name": "multiselect", + "value": "اختيار متعددة" + }, + { + "name": "listitem", + "value": "قائمة البنود" + }, + { + "name": "hyperlink", + "value": "ارتباط تشعبي" + }, + { + "name": "text", + "value": "نص ." + }, + { + "name": "image", + "value": "صور" + }, + { + "name": "video", + "value": "فيديو : ." + }, + { + "name": "formcomponent", + "value": "شكل العنصر" + }, + { + "name": "custom_dialog", + "value": "تخصيص مربع الحوار" + }, + { + "name": "custom_dialog_style_custom", + "value": "مربع الحوار نمط مخصص" + }, + { + "name": "custom_dialog_style_custom_true", + "value": "عرف" + }, + { + "name": "custom_dialog_style_custom_false", + "value": "غير مخصص" + }, + { + "name": "custom_dialog_title", + "value": "طلب تمكين الأذونات التالية" + }, + { + "name": "custom_dialog_permission_microphone", + "value": "ميكروفون السلطة" + }, + { + "name": "custom_dialog_permission_microphone_info", + "value": "المكالمات الصوتية تتطلب إذن الميكروفون" + }, + { + "name": "custom_dialog_permission_location", + "value": "موقع السلطة" + }, + { + "name": "custom_dialog_permission_location_info", + "value": "الملاحة يتطلب إذن الموقع" + }, + { + "name": "custom_dialog_start", + "value": "فتح" + }, + { + "name": "date_picker_dialog", + "value": "تاريخ محدد" + }, + { + "name": "date_picker_dialog_date", + "value": "عرض تاريخ الحوار" + }, + { + "name": "date_picker_dialog_date_lunar", + "value": "التاريخ القمري" + }, + { + "name": "date_picker_dialog_date_gregorian", + "value": "تاريخ التقويم الغريغوري" + }, + { + "name": "date_picker_dialog_cancel", + "value": "ألغى" + }, + { + "name": "date_picker_toast_date", + "value": "اختيار الوقت :" + }, + { + "name": "date_picker_dialog_datetimeone", + "value": "2022-10-01" + }, + { + "name": "date_picker_dialog_datetimetwo", + "value": "1970-1-1" + }, + { + "name": "date_picker_dialog_datetimethree", + "value": "2100-12-31" + }, + { + "name": "date_picker_title", + "value": "تاريخ محدد" + }, + { + "name": "date_picker_lunar", + "value": "القمر" + }, + { + "name": "divider_title", + "value": "تحويلة" + }, + { + "name": "divider_stroke_width", + "value": "عرض السكتة الدماغية" + }, + { + "name": "divider_line_color", + "value": "لون الخط" + }, + { + "name": "divider_line_cap", + "value": "لين كابستيل" + }, + { + "name": "divider_horizontal", + "value": "الاتجاه الأفقي" + }, + { + "name": "divider_vertical", + "value": "عمودي" + }, + { + "name": "divider_attribute", + "value": "تحويلة" + }, + { + "name": "font_color", + "value": "الألوان" + }, + { + "name": "font_size", + "value": "حجم" + }, + { + "name": "font_thickness", + "value": "سمك ." + }, + { + "name": "font_style", + "value": "أسلوب ." + }, + { + "name": "interpolation_calculation_cubic_bezier_curve", + "value": "ثالث ترتيب منحنى بيزيير الكائن" + }, + { + "name": "interpolation_calculation_spring", + "value": "منحنى الربيع الكائن" + }, + { + "name": "interpolation_calculation_init_curve", + "value": "easein منحنى تفاضلي" + }, + { + "name": "interpolation_calculation_steps_curve", + "value": "سلم منحنى الكائن" + }, + { + "name": "page_transition", + "value": "التحويل بين الصفحات" + }, + { + "name": "page_transition_left", + "value": "مدخل / مخرج يمين يسار" + }, + { + "name": "page_transition_right", + "value": "المدخل الأيمن / المخرج الأيسر" + }, + { + "name": "page_transition_top", + "value": "أعلى مدخل / مخرج أسفل" + }, + { + "name": "page_transition_bottom", + "value": "أسفل مدخل / مخرج أعلى" + }, + { + "name": "page_transition_scale", + "value": "تكبير / تصغير" + }, + { + "name": "page_transition_rotate", + "value": "برغي في / خارج" + }, + { + "name": "page_transition_back", + "value": "تحويل صفحة العودة بين الصفحات" + }, + { + "name": "qrcode_title", + "value": "قركودي" + }, + { + "name": "qrcode_content", + "value": "المحتويات" + }, + { + "name": "qrcode_color", + "value": "الألوان" + }, + { + "name": "qrcode_enter_content", + "value": "أدخل تغيير رمز ثنائي الأبعاد" + }, + { + "name": "search_placeholder", + "value": "اكتب البحث ." + }, + { + "name": "search_name", + "value": "بحث ." + }, + { + "name": "radio_title", + "value": "راديو ." + }, + { + "name": "radio_no_response_region", + "value": "لا إضافة منطقة استجابة ( اضغط على زر الدخول )" + }, + { + "name": "radio_has_response_region", + "value": "إضافة منطقة استجابة ( انقر على زر خط )" + }, + { + "name": "radio_beijing", + "value": "بيجينغ" + }, + { + "name": "radio_shanghai", + "value": "شنغهاي ." + }, + { + "name": "radio_shenzhen", + "value": "شن تشن" + }, + { + "name": "radio_guangzhou", + "value": "غوانغ زهو" + }, + { + "name": "graphic_transformation_rotate", + "value": "استدارة" + }, + { + "name": "rotate_photo", + "value": "صورة التناوب" + }, + { + "name": "rotate_container", + "value": "عنصر التناوب" + }, + { + "name": "rotate_before_image", + "value": "الصورة الأصلية" + }, + { + "name": "rotate_before_component", + "value": "حاوية الجمعية" + }, + { + "name": "rotate_image_angle", + "value": "دوران" + }, + { + "name": "select_title", + "value": "مختار" + }, + { + "name": "select_has_icon", + "value": "اختيار الرموز" + }, + { + "name": "select_option_bg_and_text_style", + "value": "اختيار لون الخلفية و نمط النص" + }, + { + "name": "select_unselect_option_style", + "value": "خيارات الخلفية و نمط النص" + }, + { + "name": "select_button_style", + "value": "زر القائمة المنسدلة نمط النص" + }, + { + "name": "select_picture", + "value": "صور ." + }, + { + "name": "select_collection", + "value": "جمع" + }, + { + "name": "select_gesture", + "value": "الإيماءات" + }, + { + "name": "select_index", + "value": "حدد مؤشر الخيارات :" + }, + { + "name": "select_value", + "value": "قيمة الخيار المختار :" + }, + { + "name": "share_element_transition", + "value": "عنصر مشترك عملة" + }, + { + "name": "Multiplex_interface", + "value": "معدد" + }, + { + "name": "Floating_window", + "value": "نافذة عائمة" + }, + { + "name": "Tips_call", + "value": "إنتظر" + }, + { + "name": "Font_family_regular", + "value": "هارمونيوس اس سي روتاري" + }, + { + "name": "Font_family_medium", + "value": "هارمونيوس سان SC متوسطة" + }, + { + "name": "Folder_expansion", + "value": "مجلد التمديد" + }, + { + "name": "Shop_card_expansion", + "value": "تمديد بطاقة المحل" + }, + { + "name": "Today", + "value": "اليوم ." + }, + { + "name": "Gallery_card_expansion", + "value": "معرض بطاقة التمديد" + }, + { + "name": "size_width", + "value": "عرض" + }, + { + "name": "size_width_fixed_100vp", + "value": "عرض 100vp" + }, + { + "name": "size_width_percent", + "value": "عرض 60%" + }, + { + "name": "size_width_fixed_60vw", + "value": "عرض" + }, + { + "name": "size_height", + "value": "ارتفاع" + }, + { + "name": "size_height_fixed_60vh", + "value": "عرض 60vh" + }, + { + "name": "size_height_fixed_100vp", + "value": "ارتفاع 100vp" + }, + { + "name": "size_height_percent", + "value": "ارتفاع 60%" + }, + { + "name": "size_height_fixed_calc", + "value": "الارتفاع هو القيمة المحسوبة ( 200vp-100vp ) ." + }, + { + "name": "slider_title", + "value": "المنزلق" + }, + { + "name": "slider_step_tip", + "value": "خطوات ونصائح ( الخطوة 10 )" + }, + { + "name": "slider_current_value", + "value": "عرض القيمة الحالية ( مين - 50 / ماكس - 130 )" + }, + { + "name": "slider_events", + "value": "النشاطات" + }, + { + "name": "slider_attributes", + "value": "صفة" + }, + { + "name": "slider_vertical_reverse", + "value": "عمودي وعكس" + }, + { + "name": "slider_forward", + "value": "فورورد" + }, + { + "name": "slider_reverse", + "value": "عكس" + }, + { + "name": "slider_select_color", + "value": "اختيار اللون" + }, + { + "name": "slider_track_color", + "value": "لون المسار" + }, + { + "name": "slider_block_color", + "value": "لون مربع" + }, + { + "name": "slider_track_thickness", + "value": "سمك المسار" + }, + { + "name": "slider_event_begin", + "value": "تبدأ سحب شريط التمرير" + }, + { + "name": "slider_event_moving", + "value": "أثناء سحب شريط التمرير" + }, + { + "name": "slider_event_end", + "value": "نهاية سحب شريط التمرير" + }, + { + "name": "slider_event_click", + "value": "انقر فوق شريط التمرير لنقل شريط التمرير الموقف" + }, + { + "name": "slider_title_value", + "value": "النسبة المئوية من مجموع طول الشريحة :" + }, + { + "name": "span_title", + "value": "فترة طويلة من الزمن ، بما في ذلك فترة طويلة من الزمن" + }, + { + "name": "span_attribute", + "value": "تكوين خصائص مختلفة تمتد" + }, + { + "name": "span_content_one", + "value": "خفف من الصلب في النار والتبريد السريع ،" + }, + { + "name": "span_content_two", + "value": "لذلك يمكن أن يكون من الصعب ، لا تخاف من أي شيء ." + }, + { + "name": "span_content_three", + "value": "ومن خلال هذه الطريقة أن جيلنا قد تدرب على النضال و التجارب الرهيبة ،" + }, + { + "name": "span_content_four", + "value": "تعلم عدم الاستسلام للحياة ." + }, + { + "name": "span_decoration_and_letter_spacing", + "value": "الديكور و تباعد الحروف" + }, + { + "name": "span_letter_spacing", + "value": "تباعد الحروف" + }, + { + "name": "span_line_height", + "value": "خط الطول" + }, + { + "name": "span_decoration_type", + "value": "نوع الديكور" + }, + { + "name": "span_text_decoration", + "value": "الديكور اختبار النص" + }, + { + "name": "span_text_spacing", + "value": "رسالة الفضاء اختبار النص" + }, + { + "name": "span_inherits_text_attribute", + "value": "سبان يرث خصائص النص" + }, + { + "name": "span_does_not_inherit_text_attribute", + "value": "سبان لا ترث خصائص النص" + }, + { + "name": "span_upper_lower", + "value": "كبيرة أو صغيرة" + }, + { + "name": "span_decoration_color", + "value": "لون الديكور" + }, + { + "name": "span_decoration_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "span_decoration_linethrough", + "value": "خط مباشر" + }, + { + "name": "span_decoration_underline", + "value": "التأكيد" + }, + { + "name": "span_decoration_overline", + "value": "على الخط" + }, + { + "name": "image_span_title", + "value": "صورة تمتد" + }, + { + "name": "image_span_vertical_align", + "value": "المحاذاة العمودية" + }, + { + "name": "image_span_alignment_baseline", + "value": "خط الأساس" + }, + { + "name": "image_span_alignment_bottom", + "value": "القاع" + }, + { + "name": "image_span_alignment_center", + "value": "مركز" + }, + { + "name": "image_span_alignment_top", + "value": "توب ." + }, + { + "name": "image_span_object_fit", + "value": "موضوع مطابقة" + }, + { + "name": "image_fit_contain", + "value": "احتواء" + }, + { + "name": "image_fit_auto", + "value": "السيارات" + }, + { + "name": "image_fit_fill", + "value": "ملأ" + }, + { + "name": "image_fit_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "image_fit_scale_down", + "value": "تقليص حجم" + }, + { + "name": "image_fit_cover", + "value": "تغطية" + }, + { + "name": "image_span_and_span", + "value": "صورة تمتد تمتد" + }, + { + "name": "image_span_vertical_align_and_object_fit", + "value": "المحاذاة العمودية و موضوع تركيب الصورة تمتد" + }, + { + "name": "text_title", + "value": "نص ." + }, + { + "name": "text_width", + "value": "عرض النص" + }, + { + "name": "text_height", + "value": "ارتفاع النص" + }, + { + "name": "text_content", + "value": "خفف من الصلب في النار والتبريد السريع ، بحيث يمكن أن يكون من الصعب جدا ، لا تخافوا من أي شيء . وبهذه الطريقة فقط ، فإن جيلنا قد شحذ في النضال و التجارب الرهيبة و تعلمت عدم الاستسلام للحياة ." + }, + { + "name": "text_text_align_center", + "value": "مركز" + }, + { + "name": "text_text_align_start", + "value": "نقطة الانطلاق" + }, + { + "name": "text_text_align_end", + "value": "نهاية ." + }, + { + "name": "text_decoration_type", + "value": "نص نوع الديكور" + }, + { + "name": "text_decoration_type_under_line", + "value": "دوونلين" + }, + { + "name": "text_decoration_type_line_through", + "value": "من خلال خط" + }, + { + "name": "text_decoration_type_over_line", + "value": "أكثر من خط" + }, + { + "name": "text_text_align_type", + "value": "محاذاة النص" + }, + { + "name": "text_letter_spacing", + "value": "تباعد الحروف" + }, + { + "name": "text_overflow", + "value": "تجاوز النص" + }, + { + "name": "text_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "text_text_over_flow_clip", + "value": "قطع" + }, + { + "name": "text_text_over_flow_ellipsis", + "value": "القطع الناقص" + }, + { + "name": "text_line_height", + "value": "خط الطول" + }, + { + "name": "text_font_color", + "value": "لون الخط" + }, + { + "name": "text_over_flow", + "value": "تجاوز النص" + }, + { + "name": "text_text_case_normal", + "value": "عادي ." + }, + { + "name": "text_text_case", + "value": "حالة النص" + }, + { + "name": "text_text_case_uppercase", + "value": "حروف" + }, + { + "name": "text_text_case_lowercase", + "value": "حروف صغيرة" + }, + { + "name": "text_area_set_text_selection", + "value": "حدد النص" + }, + { + "name": "text_area_set_text_selection_start_select_error", + "value": "خطأ في تحديد بداية اختيار النص" + }, + { + "name": "text_area_set_text_selection_end_select_error", + "value": "خطأ في تحديد نهاية اختيار النص" + }, + { + "name": "text_input_set_text_selection_start_select", + "value": "بدء اختيار :" + }, + { + "name": "text_input_set_text_selection_end_select", + "value": "نهاية الاختيار :" + }, + { + "name": "avoiding_input_method_testing", + "value": "تجنب اختبار طريقة الإدخال" + }, + { + "name": "text_input_title", + "value": "مربع إدخال النص" + }, + { + "name": "text_input_normal_type", + "value": "الأرقام ، الحروف ، يؤكد ، والمسافات ، أحرف خاصة ." + }, + { + "name": "text_input_password_type", + "value": "أدخل كلمة السر" + }, + { + "name": "text_input_email_type", + "value": "أدخل البريد الإلكتروني" + }, + { + "name": "text_input_number_type", + "value": "وضع الإدخال الرقمي" + }, + { + "name": "text_input_phone_type", + "value": "Digits, spaces, plus signs (+), hyphens (-), asterisks (*), and number signs (#)" + }, + { + "name": "text_input_input_type", + "value": "نوع الإدخال" + }, + { + "name": "text_input_current_type", + "value": "النوع الحالي" + }, + { + "name": "text_input_show_password_icon", + "value": "عرض رمز كلمة السر" + }, + { + "name": "text_input_icon_show", + "value": "عرض ." + }, + { + "name": "text_input_icon_hide", + "value": "أخفى" + }, + { + "name": "text_input_event", + "value": "النشاطات" + }, + { + "name": "text_input_event_placeholder", + "value": "نسخ ، لصق ، قص ، ارتكاب ، تحرير الحدث" + }, + { + "name": "text_input_placeholder_style", + "value": "نمط النائبة" + }, + { + "name": "text_input_placeholder", + "value": "النائبة" + }, + { + "name": "text_input_filter", + "value": "فلتر الإدخال" + }, + { + "name": "text_input_only_input_english", + "value": "فقط أدخل الحروف الإنجليزية" + }, + { + "name": "text_input_caret_position", + "value": "موقف التمريض" + }, + { + "name": "text_input_set_text_selection", + "value": "حدد النص" + }, + { + "name": "text_input_max_length", + "value": "الحد من إدخال حرف طول" + }, + { + "name": "text_input_placeholder_max_length", + "value": "ما يصل إلى 12 حرفا" + }, + { + "name": "text_input_toast_paste", + "value": "لصق النص كما يلي :" + }, + { + "name": "text_input_toast_cut", + "value": "قص النص كما يلي :" + }, + { + "name": "text_input_toast_copy", + "value": "نسخ النص كما يلي :" + }, + { + "name": "text_input_toast_submit", + "value": "وفيما يلي نص الطلب :" + }, + { + "name": "text_input_toast_edit", + "value": "نص منقح كما يلي :" + }, + { + "name": "time_picker_dialog", + "value": "وقت الحوار" + }, + { + "name": "time_picker_dialog_time", + "value": "عرض مربع الحوار الوقت" + }, + { + "name": "time_picker_dialog_24_hour", + "value": "ساعة" + }, + { + "name": "time_picker_dialog_12_hour", + "value": "ح" + }, + { + "name": "time_picker_dialog_cancel", + "value": "ألغى" + }, + { + "name": "time_picker_toast_time", + "value": "اختيار الوقت :" + }, + { + "name": "time_picker_options_usemilitarytime", + "value": "استخدام الوقت العسكري" + }, + { + "name": "time_picker_dialog_timeone", + "value": "00 : 00" + }, + { + "name": "time_picker_dialog_timetwo", + "value": "10 / 01 / 2022 12 : 00" + }, + { + "name": "toggle_title", + "value": "تبديل" + }, + { + "name": "toggle_select", + "value": "مختار" + }, + { + "name": "toggle_unselect", + "value": "لا خيار" + }, + { + "name": "toggle_type_switch", + "value": "التبديل" + }, + { + "name": "checkbox", + "value": "خانة الاختيار" + }, + { + "name": "toggle_type_checkbox", + "value": "خانة الاختيار" + }, + { + "name": "toggle_type_button", + "value": "الأزرار" + }, + { + "name": "toggle_state", + "value": "مختار" + }, + { + "name": "graphic_transformation_translate", + "value": "ترجمة ." + }, + { + "name": "translate_image", + "value": "صورة الترجمة" + }, + { + "name": "translate_container", + "value": "عنصر الترجمة" + }, + { + "name": "translate_x_axis", + "value": "المحور العاشر" + }, + { + "name": "translate_y_axis", + "value": "المحور الصادي" + }, + { + "name": "components_display", + "value": "عرض" + }, + { + "name": "components_interaction", + "value": "تفاعلي" + }, + { + "name": "components_interaction_menuone", + "value": "قائمة البند 1" + }, + { + "name": "components_interaction_menutwo", + "value": "قائمة البند 2" + }, + { + "name": "components_interaction_menuthree", + "value": "قائمة البند 3" + }, + { + "name": "components_interaction_menufour", + "value": "قائمة البند 4" + }, + { + "name": "components_interaction_clicktextone", + "value": "معلومات أساسية" + }, + { + "name": "components_interaction_clicktexttwo", + "value": "مكان" + }, + { + "name": "components_interaction_clicktextthree", + "value": "فورجروند كيدز" + }, + { + "name": "components_interaction_hittestbehavior", + "value": "Hittest السلوك :" + }, + { + "name": "components_interaction_hovereffect", + "value": "تأثير تعليق" + }, + { + "name": "components_interaction_backgroundresponse", + "value": "انقر على خلفية الرد" + }, + { + "name": "components_interaction_foregroundresponse", + "value": "استجابة الجبهة انقر" + }, + { + "name": "components_interaction_contentresponse", + "value": "محتوى الرد انقر" + }, + { + "name": "components_display_content", + "value": "ABCDEFG" + }, + { + "name": "components_display_center", + "value": "مركز" + }, + { + "name": "components_display_topstart", + "value": "بداية" + }, + { + "name": "components_display_topend", + "value": "أعلى" + }, + { + "name": "components_display_top", + "value": "توب ." + }, + { + "name": "components_display_start", + "value": "بداية ." + }, + { + "name": "components_display_end", + "value": "نهاية ." + }, + { + "name": "components_display_bottomstart", + "value": "أسفل الحذاء" + }, + { + "name": "components_display_bottom", + "value": "القاع" + }, + { + "name": "components_display_bottomend", + "value": "رئيس كبير" + }, + { + "name": "components_display_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "components_display_hidden", + "value": "أخفى" + }, + { + "name": "components_display_visible", + "value": "مرئي" + }, + { + "name": "components_effects", + "value": "أثر" + }, + { + "name": "blur_effects", + "value": "تأثير ضبابي" + }, + { + "name": "blur_radius_modify", + "value": "نصف قطر غامض" + }, + { + "name": "background_blur", + "value": "الخلفية ضبابية" + }, + { + "name": "background_blur_style", + "value": "طمس الخلفية نمط" + }, + { + "name": "set_shadow_type", + "value": "تعيين نوع الظل" + }, + { + "name": "shadow_effects", + "value": "تأثير الظل" + }, + { + "name": "shadow_effects_content", + "value": "تأثير الظل" + }, + { + "name": "offset_min", + "value": "- 40" + }, + { + "name": "offset_max", + "value": "٤٠" + }, + { + "name": "x_offset", + "value": "س تعويض" + }, + { + "name": "y_offset", + "value": "ذ تعويض" + }, + { + "name": "shadow", + "value": "شادو" + }, + { + "name": "blur", + "value": "طمس" + }, + { + "name": "effects", + "value": "تأثير" + }, + { + "name": "effects_display", + "value": "عرض" + }, + { + "name": "grayscale_change", + "value": "مقياس الرمادية" + }, + { + "name": "brightness_change", + "value": "سطوع" + }, + { + "name": "saturate_change", + "value": "نقع" + }, + { + "name": "constrast_change", + "value": "قيد" + }, + { + "name": "invert_change", + "value": "تحويل" + }, + { + "name": "sepia_change", + "value": "الإنتان" + }, + { + "name": "hueRotate_change", + "value": "هيو روت" + }, + { + "name": "color_blend_change", + "value": "خلط الألوان" + }, + { + "name": "spherical_effect_change", + "value": "تأثير المجال" + }, + { + "name": "light_up_effect_change", + "value": "تأثير الإضاءة" + }, + { + "name": "pixel_stretch_effect_change", + "value": "تأثير بكسل تمتد" + }, + { + "name": "z_index", + "value": "ض مؤشر" + }, + { + "name": "overlay", + "value": "تغطية طبقة" + }, + { + "name": "visibility", + "value": "وضوح" + }, + { + "name": "opacity", + "value": "التعتيم" + }, + { + "name": "z_index_display", + "value": "ض مؤشر" + }, + { + "name": "Red", + "value": "رد : ." + }, + { + "name": "Yellow", + "value": "أصفر" + }, + { + "name": "positon_modify", + "value": "الوظائف" + }, + { + "name": "offset_modify", + "value": "قابل" + }, + { + "name": "visibility_change", + "value": "وضوح" + }, + { + "name": "opacity_change", + "value": "التعتيم" + }, + { + "name": "opacity_display", + "value": "التعتيم عرض" + }, + { + "name": "item_select", + "value": "قائمة البند" + }, + { + "name": "disabled", + "value": "المعوقون" + }, + { + "name": "button_disabled", + "value": "زر تعطيل" + }, + { + "name": "list_disabled", + "value": "قائمة المعوقين" + }, + { + "name": "focus", + "value": "فوكوس" + }, + { + "name": "popup_window", + "value": "نافذة منبثقة" + }, + { + "name": "touch_test", + "value": "لمس ." + }, + { + "name": "touch_region", + "value": "منطقة" + }, + { + "name": "hovereffect", + "value": "تحوم" + }, + { + "name": "bind_menu_customBuilder", + "value": "ربط القائمة custombuilder" + }, + { + "name": "bind_content_menu", + "value": "ربط محتوى القائمة" + }, + { + "name": "click_on_any_action_below", + "value": "انقر فوق أي من الإجراءات التالية" + }, + { + "name": "long_press_any_action_below", + "value": "اضغط على أي من العمليات التالية لفترة طويلة" + }, + { + "name": "bind_menu_content", + "value": "ربط محتوى القائمة" + }, + { + "name": "menu", + "value": "قائمة" + }, + { + "name": "multiState", + "value": "العديد من الدول" + }, + { + "name": "multi_short_key", + "value": "مفاتيح متعددة قصيرة" + }, + { + "name": "set_mouse_style", + "value": "تعيين نمط الماوس" + }, + { + "name": "multimode_input", + "value": "مدخلات المتعدد" + }, + { + "name": "short_key_pressed", + "value": "اضغط على مفتاح قصير" + }, + { + "name": "on_short_key", + "value": "وفي الوقت نفسه ، اضغط على مفتاح الاختصار السيطرة + لتحريك الحدث عن طريق النقر على الزر التالي" + }, + { + "name": "alert", + "value": "تنبيه" + }, + { + "name": "result", + "value": "نتيجة" + }, + { + "name": "popup", + "value": "نافذة منبثقة" + }, + { + "name": "custom_popup", + "value": "العرف المنبثقة" + }, + { + "name": "touch_test_region", + "value": "لمس منطقة الاختبار" + }, + { + "name": "action_sheet_dialog", + "value": "طاولة العمليات في مربع الحوار" + }, + { + "name": "action_sheet_title_autoCancel", + "value": "إذا كانت نافذة منبثقة تلقائيا إلغاء" + }, + { + "name": "action_sheet_click_sheets", + "value": "انقر فوق خيارات المحتوى" + }, + { + "name": "action_sheet_dialog_click_content", + "value": "انقر على المحتوى" + }, + { + "name": "text_picker_dialog", + "value": "نص محدد في مربع الحوار" + }, + { + "name": "text_picker_show", + "value": "عرض مربع الحوار النص" + }, + { + "name": "text_picker_click_text", + "value": "انقر فوق النص" + }, + { + "name": "text_picker_text_peach", + "value": "خوخ ." + }, + { + "name": "text_picker_text_apple", + "value": "تفاحة ." + }, + { + "name": "text_picker_text_orange", + "value": "برتقالي" + }, + { + "name": "text_picker_text_grape", + "value": "كرمة" + }, + { + "name": "text_picker_text_banana", + "value": "موز ." + }, + { + "name": "global_menu", + "value": "ربط قائمة السياق" + }, + { + "name": "global_menu_create_way", + "value": "طريقة الخلق" + }, + { + "name": "global_menu_click_right", + "value": "انقر بزر الماوس الأيمن فوق" + }, + { + "name": "global_menu_long_press", + "value": "الصحافة طويلة" + }, + { + "name": "global_menu_close", + "value": "انقر فوق إغلاق القائمة" + }, + { + "name": "component_transition", + "value": "عنصر التحويل" + }, + { + "name": "component_transition_show", + "value": "عرض ." + }, + { + "name": "component_transition_hide", + "value": "أخفى" + }, + { + "name": "attribute_animation", + "value": "خاصية الرسوم المتحركة" + }, + { + "name": "motion_path", + "value": "مسار الرسوم المتحركة" + }, + { + "name": "animate_to", + "value": "عرض الرسوم المتحركة" + }, + { + "name": "animate_over", + "value": "الانتهاء من الرسوم المتحركة" + }, + { + "name": "attribute_animation_change_size", + "value": "تغيير الحجم" + }, + { + "name": "attribute_animation_play_complete", + "value": "الانتهاء من اللعب" + }, + { + "name": "attribute_animation_unlimited_playback", + "value": "اللعب غير محدود" + }, + { + "name": "attribute_animation_play_speed", + "value": "سرعة اللعب" + }, + { + "name": "attribute_animation_delay", + "value": "تأخير 3 ثوان" + }, + { + "name": "attribute_animation_set_curve", + "value": "تعيين منحنى" + }, + { + "name": "attribute_animation_change_rotation", + "value": "تغيير التناوب" + }, + { + "name": "attribute_animation_play_count", + "value": "لعب" + }, + { + "name": "motion_path_click_me", + "value": "انقر على لي" + }, + { + "name": "general_mount", + "value": "تحميل وتفريغ الحدث" + }, + { + "name": "general_mount_toast", + "value": "جبل الصورة" + }, + { + "name": "general_unmount_toast", + "value": "إلغاء تثبيت الصورة" + }, + { + "name": "general_mount_text", + "value": "انقر فوق تحميل الصور غير المحملة" + }, + { + "name": "general_drag", + "value": "سحب وإسقاط الحدث" + }, + { + "name": "general_drag_text_one", + "value": "هنا ثلاثة عناصر النص ، اضغط باستمرار على النص واسحبه إلى القائمة أدناه" + }, + { + "name": "general_drag_text_two", + "value": "هذا هو عنصر القائمة" + }, + { + "name": "drag_list_one", + "value": "1 ." + }, + { + "name": "drag_list_two", + "value": "2 ." + }, + { + "name": "drag_list_three", + "value": "3 ." + }, + { + "name": "drag_list_four", + "value": "4 ." + }, + { + "name": "size_size", + "value": "حجم ." + }, + { + "name": "size_padding", + "value": "حشية" + }, + { + "name": "size_margin", + "value": "حافة" + }, + { + "name": "size_constraintSize", + "value": "حجم القيد" + }, + { + "name": "response_region", + "value": "منطقة الاستجابة" + }, + { + "name": "touch_hit_subtitle", + "value": "انقر فوق المنطقة الخضراء لتحريك المنطقة الزرقاء رد" + }, + { + "name": "option", + "value": "خيارات" + }, + { + "name": "hover_region", + "value": "تحوم الماوس فوق المنطقة الخضراء لمراقبة تأثير" + }, + { + "name": "multistatus_region", + "value": "تبديل الدولة ومراقبة تأثير" + }, + { + "name": "status_select", + "value": "اختيار الدولة" + }, + { + "name": "scroll_bar", + "value": "شريط التمرير" + }, + { + "name": "scroll_vertical_title", + "value": "التمرير الرأسي" + }, + { + "name": "scroll_horizontal_title", + "value": "التمرير الأفقي" + }, + { + "name": "auxiliary_refresh", + "value": "منعش" + }, + { + "name": "auxiliary_refresh_offset", + "value": "قابل" + }, + { + "name": "auxiliary_refresh_minvalue", + "value": "س" + }, + { + "name": "auxiliary_refresh_maxvalue", + "value": "١٠٠" + }, + { + "name": "auxiliary_refresh_friction", + "value": "احتكاك" + }, + { + "name": "auxiliary_panel", + "value": "لوحة" + }, + { + "name": "auxiliary_alphabetIndexer", + "value": "رسالة مفهرس" + }, + { + "name": "loading_progress", + "value": "تحميل الجدول" + }, + { + "name": "marquee_name", + "value": "ماركيز" + }, + { + "name": "marquee_src", + "value": "مرحبا arkui سلسلة أطول من المحتوى" + }, + { + "name": "marquee_fromstart", + "value": "من البداية" + }, + { + "name": "marquee_step", + "value": "خطوة" + }, + { + "name": "marquee_loop", + "value": "حلقة ." + }, + { + "name": "text_timer", + "value": "النص الموقت" + }, + { + "name": "text_timer_start", + "value": "بداية ." + }, + { + "name": "text_timer_pause", + "value": "وقفة" + }, + { + "name": "text_timer_reset", + "value": "إعادة" + }, + { + "name": "text_timer_iscountdown", + "value": "العد التنازلي" + }, + { + "name": "text_timer_timeformatone", + "value": "مم : الفولاذ المقاوم للصدأ" + }, + { + "name": "text_timer_groupformat", + "value": "شكل ." + }, + { + "name": "text_timer_timeformattwo", + "value": "عالية : مم : ثانية" + }, + { + "name": "text_timer_timeformatthree", + "value": "DD سمو مم SS . اس اس اس" + }, + { + "name": "text_clock", + "value": "كتلة النص" + }, + { + "name": "text_clock_start", + "value": "بداية ." + }, + { + "name": "text_clock_stop", + "value": "توقف" + }, + { + "name": "text_clock_timeformatone", + "value": "عالية : مم : ثانية" + }, + { + "name": "text_clock_groupformat", + "value": "شكل ." + }, + { + "name": "text_clock_timeformattwo", + "value": "السنة : الشهر : النهار" + }, + { + "name": "text_clock_timeformatthree", + "value": "ساعة - دقيقة - ثانية" + }, + { + "name": "progress_name", + "value": "تقدم" + }, + { + "name": "gauge_name", + "value": "متر ." + }, + { + "name": "gauge_value", + "value": "قيمة ." + }, + { + "name": "gauge_strokewidth", + "value": "السكتة الدماغية العرض" + }, + { + "name": "gauge_startangle", + "value": "زاوية البداية" + }, + { + "name": "gauge_endangle", + "value": "نهاية زاوية" + }, + { + "name": "data_panel", + "value": "لوحة البيانات" + }, + { + "name": "checkbox_checkboxgroup", + "value": "فحص مربع مجموعة" + }, + { + "name": "checkbox_title", + "value": "خانة الاختيار" + }, + { + "name": "checkbox_checkbox1", + "value": "خانة الاختيار 1" + }, + { + "name": "checkbox_checkbox2", + "value": "خانة الاختيار 2" + }, + { + "name": "checkbox_checkbox3", + "value": "خانة الاختيار 3" + }, + { + "name": "checkbox_checkgroup", + "value": "مجموعة مربع" + }, + { + "name": "checkbox_checkgroup_title", + "value": "مجموعة مربع" + }, + { + "name": "text_picker", + "value": "نص محدد" + }, + { + "name": "time_picker", + "value": "الوقت محدد" + }, + { + "name": "counter_name", + "value": "مكافحة" + }, + { + "name": "rating_name", + "value": "تصنيفات" + }, + { + "name": "rating_options_indicator", + "value": "المؤشر" + }, + { + "name": "rating_options_value", + "value": "قيمة ." + }, + { + "name": "rating_options_stars", + "value": "نجوم ." + }, + { + "name": "rich_text", + "value": "النص التشعبي" + }, + { + "name": "scroll_swiper", + "value": "المتداول والانزلاق" + }, + { + "name": "scroll_name", + "value": "ورقة لفة" + }, + { + "name": "swiper_name", + "value": "بطاقة ممغنطة" + }, + { + "name": "alphabetindexer_an", + "value": "واحد" + }, + { + "name": "alphabetindexer_bu", + "value": "يوم تقسيم" + }, + { + "name": "alphabetindexer_bai", + "value": "ابيض" + }, + { + "name": "alphabetindexer_bao", + "value": "بالة" + }, + { + "name": "alphabetindexer_bi", + "value": "بی" + }, + { + "name": "alphabetindexer_bing", + "value": "بنج" + }, + { + "name": "alphabetindexer_cao", + "value": "شاو" + }, + { + "name": "alphabetindexer_chen", + "value": "تشان ›" + }, + { + "name": "alphabetindexer_lv", + "value": "لو ." + }, + { + "name": "alphabetindexer_liu3", + "value": "ليو" + }, + { + "name": "alphabetindexer_liu", + "value": "خط وحدة واجهة" + }, + { + "name": "alphabetindexer_li", + "value": "الليثيوم" + }, + { + "name": "alphabetindexer_lou", + "value": "لو ." + }, + { + "name": "alphabetindexer_liang", + "value": "شعاع" + }, + { + "name": "alphabetindexer_lei", + "value": "رعد ." + }, + { + "name": "alphabetindexer_lu", + "value": "أرض ." + }, + { + "name": "alphabetindexer_cui", + "value": "تشوي" + }, + { + "name": "alphabetindexer_cheng", + "value": "تشنغ" + }, + { + "name": "alphabetindexer_list_display", + "value": "عرض قائمة" + }, + { + "name": "alphabetindexer_color_select", + "value": "اختيار اللون" + }, + { + "name": "alphabetindexer_selectedcolor_selectedcolor", + "value": "اختيار اللون" + }, + { + "name": "alphabetindexer_selectedcolor_selectedbgcolor", + "value": "اختيار لون الخلفية" + }, + { + "name": "alphabetindexer_selectedcolor_popupcolor", + "value": "لون النوافذ المنبثقة" + }, + { + "name": "alphabetindexer_selectedcolor_popupbackground", + "value": "الخلفية المنبثقة" + }, + { + "name": "alphabetindexer_selectedcolor_usingpopup", + "value": "استخدام النوافذ المنبثقة" + }, + { + "name": "panel_show_minibar", + "value": "عرض شريط ميني نوع الفريق" + }, + { + "name": "panel_close_minibar", + "value": "إغلاق شريط ميني نوع الفريق" + }, + { + "name": "panel_show_foldable", + "value": "عرض نوع قابلة للطي لوحة" + }, + { + "name": "panel_close_foldable", + "value": "إغلاق لوحة قابلة للطي" + }, + { + "name": "panel_show_temporary", + "value": "عرض لوحة نوع مؤقت" + }, + { + "name": "panel_close_temporary", + "value": "إغلاق لوحة نوع مؤقت" + }, + { + "name": "panel_radio_groupname", + "value": "فاكهة" + }, + { + "name": "checkbox_apple", + "value": "تفاحة ." + }, + { + "name": "checkbox_blueberry", + "value": "عنبية" + }, + { + "name": "checkbox_banbana", + "value": "موز ." + }, + { + "name": "checkbox_cherries", + "value": "كرز ." + }, + { + "name": "checkbox_durian", + "value": "دوريان" + }, + { + "name": "checkbox_orange", + "value": "برتقالي" + }, + { + "name": "checkbox_select_color", + "value": "اختيار اللون" + }, + { + "name": "checkbox_select_all", + "value": "اختيار كامل" + }, + { + "name": "normal_display", + "value": "عرض" + }, + { + "name": "normal_options", + "value": "خيارات" + }, + { + "name": "datapanel_circle", + "value": "دائرة" + }, + { + "name": "datapanel_line", + "value": "خط" + }, + { + "name": "progress_linear", + "value": "التقدم الخطي" + }, + { + "name": "progress_eclipse", + "value": "الكسوف التقدم" + }, + { + "name": "progress_scalering", + "value": "مقياس التقدم" + }, + { + "name": "progress_ring", + "value": "حلقة التقدم" + }, + { + "name": "progress_capsule", + "value": "كبسولة التقدم" + }, + { + "name": "progress_change", + "value": "تغيير الجدول الزمني" + }, + { + "name": "textclock_timeformat", + "value": "شكل الوقت" + }, + { + "name": "scroll_horizontal", + "value": "التمرير الأفقي" + }, + { + "name": "scroll_vertical", + "value": "التمرير الرأسي" + }, + { + "name": "interaction_disable_list", + "value": "قائمة الجرحى" + }, + { + "name": "interaction_show_one_alert", + "value": "انقر على عرض تذكير" + }, + { + "name": "interaction_show_two_alert", + "value": "انقر على زر عرض التنبيه المزدوج" + }, + { + "name": "interaction_placementontop", + "value": "وضع سقف :" + }, + { + "name": "interaction_arrowoffset", + "value": "تغيير إزاحة السهم :" + }, + { + "name": "interaction_showpopup", + "value": "عرض النوافذ المنبثقة" + }, + { + "name": "interaction_showcustompopup", + "value": "عرض مخصص المنبثقة" + }, + { + "name": "pan_start", + "value": "نقطة الانطلاق" + }, + { + "name": "pan_end", + "value": "نهاية ." + }, + { + "name": "pan_button", + "value": "تعديل pangesture الزناد" + }, + { + "name": "pinch_description", + "value": "اضغط على الإطار الأسود مع ثلاثة أصابع" + }, + { + "name": "pinch_scale", + "value": "نسبة العجن لفتة :" + }, + { + "name": "interaction_mask", + "value": "إسمك" + }, + { + "name": "rotation_description", + "value": "تدوير الصندوق الأسود مع اثنين من أصابع" + }, + { + "name": "swipe_description", + "value": "الشريحة بسرعة الصندوق الأسود في أي اتجاه مع إصبع واحد" + }, + { + "name": "combinded_description", + "value": "اضغط واسحب مربع أسود" + }, + { + "name": "transform_translate_invert", + "value": "التكبير مرتين و عكس ( التكبير مرتين )" + }, + { + "name": "key_press_description", + "value": "اضغط على لوحة المفاتيح الخارجية التبويب ، ثم اضغط على أي مفتاح" + }, + { + "name": "april", + "value": "ابريل" + }, + { + "name": "bind_click", + "value": "انقر على لي" + }, + { + "name": "interaction_disable", + "value": "تعطيل المكونات :" + }, + { + "name": "canvas_components", + "value": "قماش الجمعية" + }, + { + "name": "canvas_component_attributes", + "value": "السمة الأساسية" + }, + { + "name": "canvas_component_image_bitmap", + "value": "صورة نقطية" + }, + { + "name": "canvas_component_gradient", + "value": "كسر التدرج" + }, + { + "name": "canvas_component_method", + "value": "الطريقة الأساسية" + }, + { + "name": "canvas_component_path_2d", + "value": "باث" + }, + { + "name": "canvas_component_shadow", + "value": "شادو" + }, + { + "name": "canvas_component_transform", + "value": "تحويل" + }, + { + "name": "canvas_canvasZone", + "value": "قماش المنطقة" + }, + { + "name": "canvas_attributesOperations", + "value": "خاصية التشغيل" + }, + { + "name": "canvas_clearEffects", + "value": "تأثير واضح" + }, + { + "name": "canvas_show_message", + "value": "طباعة وحدة التحكم" + }, + { + "name": "scroll_To_effect", + "value": "انتقل إلى تأثير" + }, + { + "name": "scroller", + "value": "لف الجهاز" + }, + { + "name": "list", + "value": "قائمة" + }, + { + "name": "grid", + "value": "شبكة ." + }, + { + "name": "waterFlow", + "value": "تدفق المياه" + }, + { + "name": "tabs_switch_effect", + "value": "تسمية التبديل تأثير" + }, + { + "name": "image_fit_Full_effect", + "value": "صورة مطابقة / تأثير كامل" + }, + { + "name": "particle_effect", + "value": "تأثير الجسيمات" + }, + { + "name": "particle_spawn", + "value": "وضع البيض" + }, + { + "name": "particle_spawn_stop", + "value": "توقف" + }, + { + "name": "global_bindSheet_menu", + "value": "قائمة أوراق فضفاضة" + }, + { + "name": "global_bindSheet_text_allow_interaction", + "value": "تسمح صفحة التفاعل" + }, + { + "name": "global_bindSheet_text_desc", + "value": "تسمح صفحة وصف التفاعل" + }, + { + "name": "bindSheet_popup_style", + "value": "نمط البوب" + }, + { + "name": "bindSheet_default_popup", + "value": "نافذة منبثقة" + }, + { + "name": "bindSheet_centered_popup", + "value": "تركز نافذة منبثقة" + }, + { + "name": "bindSheet_popup_appears", + "value": "تظهر نافذة منبثقة" + }, + { + "name": "bindSheet_icon", + "value": "آيدول" + }, + { + "name": "bindSheet_blurred_background_texture", + "value": "غامض نسيج الخلفية" + }, + { + "name": "bindSheet_popup_modal_interface", + "value": "طريقة إخراج واجهة" + }, + { + "name": "pop_height", + "value": "بوب هايت" + }, + { + "name": "bindSheet_close_modal", + "value": "وضع قبالة" + }, + { + "name": "bindSheet_close_confirm", + "value": "أكّد" + }, + { + "name": "bindSheet_close_cancel", + "value": "ألغى" + }, + { + "name": "global_popUp_menu", + "value": "نافذة منبثقة" + }, + { + "name": "popUp_width", + "value": "عرض" + }, + { + "name": "placement", + "value": "إعادة التوطين" + }, + { + "name": "popUp_advanced_component", + "value": "بوبوب مكونات متقدمة" + }, + { + "name": "global_menu_avoid_rule", + "value": "قائمة تجنب القاعدة" + }, + { + "name": "global_menu_layout", + "value": "تصميم القائمة" + }, + { + "name": "global_menu_width", + "value": "عرض القائمة" + }, + { + "name": "menu_option", + "value": "قائمة الخيارات" + }, + { + "name": "vertical_layout", + "value": "تخطيط عمودي" + }, + { + "name": "horizontal_layout", + "value": "تخطيط أفقي" + }, + { + "name": "menu_width", + "value": "عرض" + }, + { + "name": "textclock_style", + "value": "أسلوب ." + }, + { + "name": "text_clock_textShadow", + "value": "نص الظل" + }, + { + "name": "text_clock_fontSetting", + "value": "إعدادات الخط" + }, + { + "name": "text_clock_select_button", + "value": "اختيار زر" + }, + { + "name": "text_clock_monospaced_numbers", + "value": "رقم واحد" + }, + { + "name": "text_clock_monovolume_numbers", + "value": "حجم واحد عدد" + }, + { + "name": "text_input_text_selection_menu", + "value": "قائمة اختيار النص" + }, + { + "name": "text_custom_menu", + "value": "نص مخصص القائمة" + }, + { + "name": "text_input_text_copy", + "value": "نسخ" + }, + { + "name": "text_input_text_copy_success", + "value": "نسخة ناجحة" + }, + { + "name": "text_input_text_paste", + "value": "لصق" + }, + { + "name": "text_input_text_paste_success", + "value": "لصق بنجاح" + }, + { + "name": "text_input_text_get", + "value": "الحصول على" + }, + { + "name": "text_input_text_delete", + "value": "حذف النص" + }, + { + "name": "text_input_line_break_strategy", + "value": "كسر استراتيجية" + }, + { + "name": "text_input_line_break_strategy_content", + "value": "أنها يمكن أن تكون مقسمة إلى المدمج في المكونات -- المكونات التي يتم توفيرها مباشرة من قبل arkui الإطار ، مكونات مخصصة -- التي يحددها المطور . المدمج في المكونات تشمل أزرار ، أزرار الراديو ، ومؤشرات التقدم ، والنصوص . يمكنك تعيين عرض هذه المكونات في طريقة ربط الوضع ، مكونات الصفحة مقسمة إلى وحدات واجهة المستخدم منفصلة لإنشاء وتطوير وإعادة استخدام وحدات مختلفة على الصفحة ، مما يجعل الصفحة أكثر هندسة المنحى ." + }, + { + "name": "text_input_word_break", + "value": "قطع" + }, + { + "name": "text_input_word_break_content", + "value": "هذه هي ميزة وضع WordBreak إلى نص WordBreak Taumatawakathangakoauotamateature ، وهذا هو ، عندما كنت لا تعرف ، سوف تجد أنك لا تعرف ." + }, + { + "name": "textarea_character_limit", + "value": "الحد من حرف" + }, + { + "name": "grid_item_polymorphic_styles", + "value": "نمط متعدد الأشكال" + }, + { + "name": "previous", + "value": "سابق" + }, + { + "name": "next_step", + "value": "الخطوة التالية" + }, + { + "name": "text_styled_string_title", + "value": "سلسلة نمط النص" + }, + { + "name": "text_mutable_styled_string", + "value": "نمط سلسلة" + }, + { + "name": "text_mutable_styled_string_start", + "value": "نقطة الانطلاق" + }, + { + "name": "text_mutable_styled_string_length", + "value": "طول ." + }, + { + "name": "text_mutable_styled_error", + "value": "من فضلك أدخل" + }, + { + "name": "text_styled_string_gesture_style", + "value": "لفتة نمط" + }, + { + "name": "rows_and_columns", + "value": "الصفوف والأعمدة" + }, + { + "name": "stack_flex_and_grid", + "value": "كومة ، والانحناء ، تنسجم" + }, + { + "name": "list_and_grid", + "value": "قائمة الشبكة" + }, + { + "name": "navigation", + "value": "ملاحة" + }, + { + "name": "canvas_and_graphic_drawing", + "value": "قماش والرسومات" + }, + { + "name": "size_transition_flex", + "value": "بنت ." + }, + { + "name": "size_transition_grid_item", + "value": "شبكة البند" + }, + { + "name": "size_transition_list_item", + "value": "قائمة البنود" + }, + { + "name": "size_transition_swiper_item", + "value": "مشروع بطاقة ممغنطة" + }, + { + "name": "size_transition_font_size", + "value": "حجم الخط" + }, + { + "name": "size_transition_expansion_tabContent", + "value": "علامة التبويب المحتوى" + }, + { + "name": "set_background_blur_style_color_mode", + "value": "تعيين نمط لون الخلفية الضبابية" + }, + { + "name": "set_background_blur_style_adaptive_color", + "value": "تعيين لون الخلفية الضبابي المتكيف" + }, + { + "name": "blur_style_system", + "value": "نظم" + }, + { + "name": "blur_style_light", + "value": "الإضاءة" + }, + { + "name": "blur_style_dark", + "value": "ظلام ." + }, + { + "name": "blur_style_default", + "value": "خرق" + }, + { + "name": "shadow_type_color", + "value": "الألوان" + }, + { + "name": "shadow_type_blur", + "value": "طمس" + }, + { + "name": "blur_style_average", + "value": "متوسط القيمة" + }, + { + "name": "divider_color_blue", + "value": "بلو" + }, + { + "name": "divider_color_green", + "value": "غرين" + }, + { + "name": "divider_color_orange", + "value": "برتقالي" + }, + { + "name": "divider_color_pink", + "value": "وردي" + }, + { + "name": "divider_line_type_butt", + "value": "السيجارة" + }, + { + "name": "divider_line_type_round", + "value": "دائرة" + }, + { + "name": "divider_line_type_square", + "value": "ساحة" + }, + { + "name": "safe_area_type_and_safe_area_edge", + "value": "safeareatype و safeareedge" + }, + { + "name": "save_area_input_text", + "value": "أدخل كلمة . . ." + }, + { + "name": "safe_area_type", + "value": "نوع المنطقة الأمنية" + }, + { + "name": "safe_area_edge", + "value": "سافاريادج" + }, + { + "name": "safe_area_edge_top", + "value": "توب ." + }, + { + "name": "safe_area_edge_bottom", + "value": "القاع" + }, + { + "name": "safe_area_edge_start", + "value": "بداية ." + }, + { + "name": "safe_area_edge_end", + "value": "نهاية ." + }, + { + "name": "safe_area_type_system", + "value": "نظم" + }, + { + "name": "safe_area_type_cutout", + "value": "شق" + }, + { + "name": "safe_area_type_keyboard", + "value": "لوحة المفاتيح ." + }, + { + "name": "System_icon", + "value": "رمز النظام" + }, + { + "name": "text_content_en", + "value": "خفف من الصلب في النار والتبريد السريع ، بحيث يمكن أن يكون من الصعب جدا ، لا تخافوا من أي شيء . وبهذه الطريقة فقط ، فإن جيلنا قد شحذ في النضال و التجارب الرهيبة و تعلمت عدم الاستسلام للحياة ." + }, + { + "name": "text_content_en_first", + "value": "خفف من الصلب في النار والتبريد السريع ، بحيث يمكن أن يكون من الصعب جدا ، لا تخافوا من أي شيء ." + }, + { + "name": "text_content_en_last", + "value": "وبهذه الطريقة فقط ، فإن جيلنا قد شحذ في النضال و التجارب الرهيبة و تعلمت عدم الاستسلام للحياة ." + }, + { + "name": "touch_hit_test", + "value": "انقر فوق منطقة ساخنة : تعيين منطقة ساخنة في المنطقة الخضراء" + }, + { + "name": "side_bar_effects_title", + "value": "تأثير الشريط الجانبي" + }, + { + "name": "set_side_bar_type", + "value": "تعيين نوع الشريط الجانبي" + }, + { + "name": "side_bar_container_content", + "value": "sidebar محتويات الحاوية" + }, + { + "name": "hide_side_bar", + "value": "إخفاء الشريط الجانبي" + }, + { + "name": "show_side_bar", + "value": "عرض شريط جانبي" + }, + { + "name": "side_bar_type_embed", + "value": "جزءا لا يتجزأ من" + }, + { + "name": "side_bar_type_overlay", + "value": "تغطية طبقة" + }, + { + "name": "side_bar_type_auto", + "value": "السيارات" + }, + { + "name": "auxiliary_refresh_refreshing", + "value": "منعش" + }, + { + "name": "rich_editor", + "value": "ريش ديتور" + }, + { + "name": "rich_editor_style", + "value": "أسلوب ." + }, + { + "name": "rich_editor_title", + "value": "ريش ديتور" + }, + { + "name": "nav_router", + "value": "توجيه الملاحة" + }, + { + "name": "tabs_name", + "value": "تبويب" + }, + { + "name": "select_name", + "value": "مختار" + }, + { + "name": "slider_name", + "value": "المنزلق" + }, + { + "name": "delete_list_item", + "value": "حذف قائمة البند" + }, + { + "name": "size_size_description_one", + "value": "العرض والارتفاع" + }, + { + "name": "size_size_description_two", + "value": "العرض والارتفاع 100%" + }, + { + "name": "size_size_padding_one", + "value": "أعلى ، أسفل ، اليسار واليمين الهوامش الداخلية 10vp" + }, + { + "name": "size_size_padding_two", + "value": "الهامش الداخلي 20%" + }, + { + "name": "size_size_margin_one", + "value": "أعلى ، أسفل ، يسار ، يمين" + }, + { + "name": "size_size_margin_two", + "value": "المسافة الخارجية العليا 20%" + }, + { + "name": "size_size_constraintSize_one", + "value": "الحد الأقصى للعرض والارتفاع 90vp" + }, + { + "name": "size_size_constraintSize_two", + "value": "الحد الأدنى من العرض والارتفاع 80vp" + }, + { + "name": "keyPress_event", + "value": "اضغط على الحدث" + }, + { + "name": "focus_event_description", + "value": "اضغط على علامة التبويب لوحة المفاتيح الخارجية للحصول على التركيز ، ثم اضغط على مفتاح التبديل" + }, + { + "name": "focus_event_button_one", + "value": "الزر الأول" + }, + { + "name": "focus_event_button_two", + "value": "الزر الثاني" + }, + { + "name": "focus_event_button_three", + "value": "الزر الثالث" + }, + { + "name": "focus_event_toast_text", + "value": "الزناد التركيز" + }, + { + "name": "press_event_toast_text", + "value": "زر الزناد الحدث" + }, + { + "name": "press_event_toast_description", + "value": "اضغط على أي مفتاح على لوحة المفاتيح الخارجية" + }, + { + "name": "mouse_event_move_description", + "value": "استخدام الماوس الخارجي للانتقال إلى زر" + }, + { + "name": "mouse_event_click_description", + "value": "استخدام الفأرة الخارجية للنقر على زر" + }, + { + "name": "mouse_event_hover_description", + "value": "ماوس" + }, + { + "name": "mouse_event_onHover_description", + "value": "الماوس لا تتحرك" + }, + { + "name": "mouse_event_onMouse_text", + "value": "على الماوس" + }, + { + "name": "mouse_event_mouseBtn_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "mouse_event_mouseBtn_left", + "value": "يسار ." + }, + { + "name": "mouse_event_mouseBtn_right", + "value": "صحيح ." + }, + { + "name": "mouse_event_mouseBtn_back", + "value": "العودة" + }, + { + "name": "mouse_event_mouseBtn_forward", + "value": "فورورد" + }, + { + "name": "mouse_event_mouseBtn_middle", + "value": "متوسط" + }, + { + "name": "mouse_event_mouseAction_hover", + "value": "تحوم" + }, + { + "name": "mouse_event_mouseAction_press", + "value": "ميديا ." + }, + { + "name": "mouse_event_mouseAction_move", + "value": "تحرك ." + }, + { + "name": "mouse_event_mouseAction_release", + "value": "أطلق" + }, + { + "name": "scroll_event", + "value": "عنصر المنطقة المرئية تغيير الحدث" + }, + { + "name": "scroll_event_description", + "value": "قائمة الشرائح يجعل الصورة تختفي و تظهر" + }, + { + "name": "scroll_event_toast_visible", + "value": "صور حب واضحة للعيان" + }, + { + "name": "scroll_event_toast_invisible", + "value": "صورة الحب اختفى تماما" + }, + { + "name": "location_settings", + "value": "وضع" + }, + { + "name": "location_settings_align", + "value": "طريقة محاذاة" + }, + { + "name": "location_settings_direction", + "value": "تخطيط أفقي" + }, + { + "name": "location_settings_position", + "value": "المواقع المطلقة" + }, + { + "name": "location_settings_markAnchor", + "value": "مجموعة مرساة" + }, + { + "name": "location_settings_offset", + "value": "بالنسبة لتحديد المواقع" + }, + { + "name": "location_settings_alignRules", + "value": "محاذاة القاعدة" + }, + { + "name": "location_settings_bottom_end", + "value": "نهاية القاع" + }, + { + "name": "location_settings_top_start", + "value": "أعلى بداية" + }, + { + "name": "location_settings_center", + "value": "مركز" + }, + { + "name": "location_settings_position_text", + "value": "الموقع ( 30 ، 10 )" + }, + { + "name": "location_settings_position_offSet_text", + "value": "Original : ENGLISH" + }, + { + "name": "layout_constrain", + "value": "تخطيط القيد" + }, + { + "name": "layout_constrain_aspectRatio", + "value": "عنصر نسبة الارتفاع" + }, + { + "name": "layout_constrain_displayPriority", + "value": "عنصر الأولوية" + }, + { + "name": "layout_constrain_big_container", + "value": "حاوية كبيرة" + }, + { + "name": "layout_constrain_middle_container", + "value": "حاوية متوسطة الحجم" + }, + { + "name": "layout_constrain_small_container", + "value": "حاوية صغيرة" + }, + { + "name": "layout_constrain_children_one", + "value": "1 : ( أولوية : 2 )" + }, + { + "name": "layout_constrain_children_two", + "value": "2 : ( الأولوية : 1 )" + }, + { + "name": "layout_constrain_children_three", + "value": "3 : ( الأولوية : 3 )" + }, + { + "name": "layout_constrain_children_four", + "value": "4 : ( الأولوية : 1 )" + }, + { + "name": "layout_constrain_children_five", + "value": "5 - ( الأولوية : 2 )" + }, + { + "name": "layout_constrain_one", + "value": "1 ." + }, + { + "name": "layout_constrain_two", + "value": "2 ." + }, + { + "name": "flex", + "value": "بنت ." + }, + { + "name": "flex_flexBasis", + "value": "فليكسباسيس" + }, + { + "name": "flex_flexGrow", + "value": "فلکسجرو" + }, + { + "name": "flex_flexShrink", + "value": "فليكس شرينك" + }, + { + "name": "flex_alignSelf", + "value": "اليغن سلف" + }, + { + "name": "flex_layoutWeight", + "value": "تخطيط الوزن" + }, + { + "name": "flex_no_layoutWeight", + "value": "عن تخطيط الوزن" + }, + { + "name": "flex_no_alignSelf_70", + "value": "محاذاة النفس ، الارتفاع : 70%" + }, + { + "name": "flex_end_alignSelf", + "value": "محاذاة نهاية النفس" + }, + { + "name": "flex_end_alignSelf_100", + "value": "محاذاة نهاية النفس" + }, + { + "name": "flex_shrink_0", + "value": "فليكس انكماش" + }, + { + "name": "flex_shrink_default", + "value": "فليكس شرينك" + }, + { + "name": "flex_shrink_1", + "value": "فليكس شرينك" + }, + { + "name": "flex_grow_1", + "value": "FlexGrow ( 1 )" + }, + { + "name": "flex_grow_2", + "value": "FlexGrow ( 2 )" + }, + { + "name": "flex_no_alignSelf_100", + "value": "محاذاة الذاتي ، الطول : 100%" + }, + { + "name": "flex_basis_100", + "value": "FlexBasis ( 100 )" + }, + { + "name": "flex_basis_auto", + "value": "FlexBasis ( تلقائي )" + }, + { + "name": "picture_border", + "value": "حدود الصورة" + }, + { + "name": "scale", + "value": "مقياس" + }, + { + "name": "transform", + "value": "تحويل" + }, + { + "name": "scale_image", + "value": "تكبير الصورة" + }, + { + "name": "transform_image", + "value": "تحويل الصورة" + }, + { + "name": "transform_init", + "value": "إنشاء مصفوفة من المرتبة الرابعة" + }, + { + "name": "transform_copy", + "value": "مصفوفة النسخ المتماثل" + }, + { + "name": "transform_combine", + "value": "تأثير مصفوفة تراكب" + }, + { + "name": "transform_invert", + "value": "عكس تأثير المصفوفة" + }, + { + "name": "transform_translate", + "value": "مصفوفة تأثير الترجمة" + }, + { + "name": "transform_scale", + "value": "تأثير حجم المصفوفة" + }, + { + "name": "transform_rotate", + "value": "تأثير مصفوفة التناوب" + }, + { + "name": "transform_transformPoint", + "value": "تأثير مصفوفة تحويل الإحداثيات" + }, + { + "name": "transform_combine_text", + "value": "ترجمة × 20 و التكبير مرتين" + }, + { + "name": "transform_translate_text", + "value": "س : 40 ، ص : 40 ، ض : 20" + }, + { + "name": "transform_scale_text", + "value": "العرض والارتفاع بمقدار مرتين" + }, + { + "name": "transform_rotate_text", + "value": "دوران 30 درجة" + }, + { + "name": "transform_transformPoint_before", + "value": "الإحداثيات بعد تحويل المصفوفة : [ 50 , 50 ]" + }, + { + "name": "transform_transformPoint_after", + "value": "الإحداثيات بعد تحويل المصفوفة : [ 100 , 0 ]" + }, + { + "name": "shape_crop", + "value": "شكل الخياطة" + }, + { + "name": "shape_crop_clip", + "value": "قطع" + }, + { + "name": "shape_crop_mask", + "value": "غطى" + }, + { + "name": "grid_settings", + "value": "إعدادات الشبكة" + }, + { + "name": "grid_settings_sm", + "value": "جهاز عرض خ" + }, + { + "name": "grid_settings_md", + "value": "عرض الجهاز MD" + }, + { + "name": "grid_settings_lg", + "value": "عرض الجهاز إل جي" + }, + { + "name": "grid_settings_useSize", + "value": "استخدام نوع الحجم" + }, + { + "name": "grid_settings_gridSpan", + "value": "gridspan شبكة تعويض" + }, + { + "name": "grid_edgeEffect_spring", + "value": "شبكة حافة تأثير الربيع" + }, + { + "name": "focus_control", + "value": "التركيز على السيطرة" + }, + { + "name": "focus_control_tab", + "value": "التركيز على السيطرة على التبويب" + }, + { + "name": "focus_control_lastPageId", + "value": "معرف الصفحة الأخيرة" + }, + { + "name": "focus_control_success", + "value": "التركيز على السيطرة على النجاح" + }, + { + "name": "focus_control_failed", + "value": "التركيز على السيطرة على الفشل" + }, + { + "name": "focus_control_group1", + "value": "المجموعة الأولى" + }, + { + "name": "focus_control_group2", + "value": "المجموعة الثانية" + }, + { + "name": "focus_control_group3", + "value": "المجموعة الثالثة" + }, + { + "name": "focus_control_input", + "value": "المدخلات" + }, + { + "name": "focus_control_request_focus", + "value": "التركيز على السيطرة على الطلب" + }, + { + "name": "component_id", + "value": "عنصر الهوية" + }, + { + "name": "component_id_onKeyTab", + "value": "اونكي تاب" + }, + { + "name": "component_id_click", + "value": "انقر فوق ابدأ" + }, + { + "name": "component_id_longClick", + "value": "نقرات طويلة" + }, + { + "name": "component_id_onTouch", + "value": "اونتوش" + }, + { + "name": "component_id_onMouse", + "value": "اونموس" + }, + { + "name": "component_id_click_text", + "value": "انقر على زر ابدأ" + }, + { + "name": "component_id_longClick_text", + "value": "تم النقر على زر \" LongClick \" لفترة طويلة" + }, + { + "name": "component_id_onTouch_text", + "value": "انقر على زر \" ontouch \"" + }, + { + "name": "component_id_onMouse_text", + "value": "\" onmouse \" زر في onmouse" + }, + { + "name": "component_blurred", + "value": "عنصر غامض" + }, + { + "name": "component_blurred_thin", + "value": "عنصر غامض رقيقة" + }, + { + "name": "restore_id", + "value": "استعادة الهوية" + }, + { + "name": "gesture_process", + "value": "لفتة العملية" + }, + { + "name": "bind_gesture_methods", + "value": "ملزمة لفتة طريقة" + }, + { + "name": "bind_gesture_priorityGesture", + "value": "prioritygeture يتجاهل النص أولوية تحديد الوالد مكون العمود" + }, + { + "name": "bind_gesture_parallelGesture", + "value": "parallelgesture يحدد الوالد الطفل عنصر العمود ، النص" + }, + { + "name": "bind_gesture_tapGesture", + "value": "انقر على الإيماءات :" + }, + { + "name": "bind_gesture_text", + "value": "نص ." + }, + { + "name": "bind_gesture_column", + "value": "عمود" + }, + { + "name": "double_click", + "value": "نقرا مزدوجا فوق الزناد" + }, + { + "name": "onAction", + "value": "على العمل :" + }, + { + "name": "long_press", + "value": "إصبع واحد طويل اضغط على النص" + }, + { + "name": "long_press_cancel", + "value": "إلغاء النشاط" + }, + { + "name": "long_press_text", + "value": "اضغط على لي مع إصبع واحد ، من فضلك ." + }, + { + "name": "pan_text", + "value": "سحب مربع أسود بأي شكل من الأشكال مع اثنين من أصابع" + }, + { + "name": "pan_text_one", + "value": "سحب مربع أسود مع إصبع واحد اليسار واليمين" + }, + { + "name": "pan_offset", + "value": "( بآلاف دولارات الولايات المتحدة )" + }, + { + "name": "pan_offset_y", + "value": "ي > ?" + }, + { + "name": "pinch_center", + "value": "مركز قرصة الإيماءات :" + }, + { + "name": "rotation_text", + "value": "لفتة التناوب" + }, + { + "name": "swipe_text_speed", + "value": "انزلاق الموقف" + }, + { + "name": "swipe_text_angle", + "value": "انزلاق الموقف" + }, + { + "name": "combinded_pan_start", + "value": "بداية الترجمة" + }, + { + "name": "combinded_pan_update", + "value": "بان التحديث" + }, + { + "name": "combinded_pan_end", + "value": "نهاية وعاء" + }, + { + "name": "combinded_longPress_onAction", + "value": "لونغبريس أون أكشن" + }, + { + "name": "combinded_longPress_end", + "value": "الصحافة نهاية طويلة" + }, + { + "name": "combinded_sequence", + "value": "تسلسل لفتة" + }, + { + "name": "combinded_longPress", + "value": "Longpress على العمل :" + }, + { + "name": "combinded_offset", + "value": "( بآلاف دولارات الولايات المتحدة )" + }, + { + "name": "combinded_x", + "value": "عشرة" + }, + { + "name": "key_press_keyType", + "value": "نوع المفتاح :" + }, + { + "name": "key_press_keyCode", + "value": "رمز المفتاح" + }, + { + "name": "key_press_keyText", + "value": "نص الكلمات الرئيسية :" + }, + { + "name": "key_press_down", + "value": "نزل" + }, + { + "name": "key_press_up", + "value": "صاعد" + }, + { + "name": "componentId_longClick", + "value": "نقرات طويلة" + }, + { + "name": "componentId_onTouch", + "value": "اونتوش" + }, + { + "name": "componentId_onMouse", + "value": "على الماوس" + }, + { + "name": "flex_auto", + "value": "السيارات" + }, + { + "name": "row_title", + "value": "فصيلة" + }, + { + "name": "row_introduction_arguments", + "value": "تعديل خط المعلمة" + }, + { + "name": "row_introduction_properties", + "value": "تعديل خصائص الخط" + }, + { + "name": "row_element_spacing", + "value": "عنصر تباعد" + }, + { + "name": "row_alignitems_top", + "value": "توب ." + }, + { + "name": "row_alignitems_bottom", + "value": "القاع" + }, + { + "name": "row_alignitems_center", + "value": "مركز" + }, + { + "name": "row_justifycontent_start", + "value": "نقطة الانطلاق" + }, + { + "name": "row_justifycontent_center", + "value": "مركز" + }, + { + "name": "row_justifycontent_end", + "value": "نهاية ." + }, + { + "name": "row_justifycontent_spacebetween", + "value": "بين الفراغات" + }, + { + "name": "row_justifycontent_spacearound", + "value": "الفضاء المحيط" + }, + { + "name": "row_justifycontent_spaceevenly", + "value": "مساحة موحدة" + }, + { + "name": "row_justifycontent_description", + "value": "تنسيق المغزل" + }, + { + "name": "row_alignitems_description", + "value": "تنسيق المحور الأفقي" + }, + { + "name": "row_introduction_tips", + "value": "نصيحة" + }, + { + "name": "row_tips", + "value": "عندما المغزل هو من نوع spacetween spacearound , أو spaceeven ، المعلمة الفضاء صف العنصر لا يعمل" + }, + { + "name": "rowsplit_title", + "value": "تقسيم أفقي تخطيط" + }, + { + "name": "rowsplit_introduction_properties", + "value": "تعديل خصائص rowsplit السحب والإسقاط" + }, + { + "name": "rowsplit_drag", + "value": "سحب التبديل" + }, + { + "name": "rowsplit_drag_divider", + "value": "سحب فواصل اليسار واليمين لتغيير الموقف" + }, + { + "name": "column_title", + "value": "عمود" + }, + { + "name": "column_introduction_arguments", + "value": "تعديل خط المعلمة" + }, + { + "name": "column_introduction_properties", + "value": "تعديل خصائص الخط" + }, + { + "name": "column_element_spacing", + "value": "عنصر تباعد" + }, + { + "name": "column_alignitems_start", + "value": "نقطة الانطلاق" + }, + { + "name": "column_alignitems_end", + "value": "نهاية ." + }, + { + "name": "column_alignitems_center", + "value": "مركز" + }, + { + "name": "column_justifycontent_start", + "value": "نقطة الانطلاق" + }, + { + "name": "column_justifycontent_center", + "value": "مركز" + }, + { + "name": "column_justifycontent_end", + "value": "نهاية ." + }, + { + "name": "column_justifycontent_spacebetween", + "value": "بين الفراغات" + }, + { + "name": "column_justifycontent_spacearound", + "value": "الفضاء المحيط" + }, + { + "name": "column_justifycontent_spaceevenly", + "value": "مساحة موحدة" + }, + { + "name": "column_justifycontent_description", + "value": "تنسيق المغزل" + }, + { + "name": "column_alignitems_description", + "value": "تنسيق المحور الأفقي" + }, + { + "name": "column_introduction_tips", + "value": "نصيحة" + }, + { + "name": "column_tips", + "value": "عندما المغزل هو من نوع spacetween spacearound , أو spaceeven ، المعلمة الفضاء صف العنصر لا يعمل" + }, + { + "name": "columnsplit_title", + "value": "تقسيم عمودي تخطيط" + }, + { + "name": "columnsplit_introduction_properties", + "value": "تعديل خاصية السحب والإفلات من columnsplit" + }, + { + "name": "columnsplit_drag", + "value": "سحب التبديل" + }, + { + "name": "columnsplit_introduction_drag_divider", + "value": "اسحب خط التقسيم صعودا وهبوطا لتغيير الموقف" + }, + { + "name": "sidebarcontainer_title", + "value": "sidebar حاوية" + }, + { + "name": "sidebarcontainer_content_text", + "value": "sidebarcontainer : حاوية الشريط الجانبي الذي يوفر عرض وإخفاء الشريط الجانبي . الشريط الجانبي ومحتوى المناطق المحددة من قبل عناصر فرعية ، أول عنصر فرعي يمثل الشريط الجانبي ، والثاني عنصر فرعي يمثل محتوى المنطقة . هذا العنصر هو مدعوم من المعهد الإصدار 8 . إذا كان محتوى جديد يضاف إلى الإصدارات اللاحقة ، الزاوية العليا علامة تستخدم علامة بداية الإصدارات الفردية من المحتوى ." + }, + { + "name": "sidebarcontainer_sidebar_text_one", + "value": "جمع" + }, + { + "name": "sidebarcontainer_sidebar_text_two", + "value": "الصفحة الرئيسية" + }, + { + "name": "sidebarcontainer_argument", + "value": "تعديل sidebarcontainer عينة" + }, + { + "name": "sidebarcontainer_property", + "value": "تعديل sidebarcontainer الملكية" + }, + { + "name": "sidebarcontainer_argument_type", + "value": "الشريط الجانبي نوع العرض" + }, + { + "name": "sidebarcontainer_type_embed", + "value": "جزءا لا يتجزأ من" + }, + { + "name": "sidebarcontainer_type_overlay", + "value": "تغطية طبقة" + }, + { + "name": "sidebarcontainer_show_switch", + "value": "عرض التبديل" + }, + { + "name": "sidebarcontainer_left_margin", + "value": "زر التحكم في المسافة إلى اليسار" + }, + { + "name": "sidebarcontainer_top_margin", + "value": "المسافة من زر التحكم" + }, + { + "name": "sidebarcontainer_show_button_switch", + "value": "زر التحكم عرض التبديل" + }, + { + "name": "sidebarcontainer_position_title", + "value": "الشريط الجانبي يظهر الموقع" + }, + { + "name": "sidebarcontainer_sidebar_show_position_start", + "value": "نقطة الانطلاق" + }, + { + "name": "sidebarcontainer_sidebar_show_position_end", + "value": "نهاية ." + }, + { + "name": "sidebarcontainer_min_width", + "value": "الحد الأدنى من عرض الشريط الجانبي" + }, + { + "name": "sidebarcontainer_max_width", + "value": "أقصى عرض الشريط الجانبي" + }, + { + "name": "sidebarcontainer_auto_hide", + "value": "هو الشريط الجانبي مخفي في الحد الأدنى من الدولة" + }, + { + "name": "sidebarcontainer_divider_width", + "value": "تقسيم خط العرض" + }, + { + "name": "sidebarcontainer_drag_divider", + "value": "اسحب فاصل لتغيير حجم الشريط الجانبي" + }, + { + "name": "sidebarcontainer__is_show_true", + "value": "الشريط الجانبي هو توسيع" + }, + { + "name": "sidebarcontainer__is_show_false", + "value": "الشريط الجانبي مغلق" + }, + { + "name": "stack_title", + "value": "كومة" + }, + { + "name": "stack_alignments_topstart", + "value": "توب ستارت" + }, + { + "name": "stack_alignments_top", + "value": "توب ." + }, + { + "name": "stack_alignments_topend", + "value": "توبند" + }, + { + "name": "stack_alignments_start", + "value": "نقطة الانطلاق" + }, + { + "name": "stack_alignment_center", + "value": "مركز" + }, + { + "name": "stack_alignment_end", + "value": "نهاية ." + }, + { + "name": "stack_alignments_bottomstart", + "value": "بداية القاع" + }, + { + "name": "stack_alignments_bottom", + "value": "القاع" + }, + { + "name": "stack_alignments_bottomend", + "value": "نهاية القاع" + }, + { + "name": "stack_alignment", + "value": "محاذاة المحتوى" + }, + { + "name": "stack_introduction", + "value": "خاصية المكدس والمعلمة aligncontent تم تحديثها" + }, + { + "name": "stack_introduction_zindex", + "value": "أكسيد الزنك" + }, + { + "name": "stack_zindex_four", + "value": "4 ." + }, + { + "name": "stack_zindex_one", + "value": "1 ." + }, + { + "name": "stack_zindex", + "value": "زيندكس" + }, + { + "name": "flex_title", + "value": "بنت ." + }, + { + "name": "flex_introduction_arguments", + "value": "تعديل تخطيط مرن المعلمات" + }, + { + "name": "flex_argument_direction", + "value": "الاتجاه" + }, + { + "name": "flex_argument_direction_row", + "value": "فصيلة" + }, + { + "name": "flex_argument_direction_row_reverse", + "value": "صف عكس" + }, + { + "name": "flex_argument_direction_column", + "value": "عمود" + }, + { + "name": "flex_argument_direction_column_reverse", + "value": "العمود عكس" + }, + { + "name": "flex_argument_wrap", + "value": "تعديل حزمة لتناسب هذا الانحناء" + }, + { + "name": "flex_argument_wrap_no_wrap", + "value": "بدون تغليف" + }, + { + "name": "flex_argument_wrap_wrap", + "value": "لف" + }, + { + "name": "flex_argument_wrap_wrap_reverse", + "value": "التعبئة والتغليف عكس" + }, + { + "name": "flex_introduction_direction", + "value": "تغيير اتجاه جميع الانحناء" + }, + { + "name": "flex_argument_justifycontent", + "value": "تعديل هذا فليكس justifycontent" + }, + { + "name": "flex_argument_justifycontent_start", + "value": "نقطة الانطلاق" + }, + { + "name": "flex_argument_justifycontent_center", + "value": "مركز" + }, + { + "name": "flex_argument_justifycontent_End", + "value": "نهاية ." + }, + { + "name": "flex_argument_justifycontent_space_between", + "value": "بين الفراغات" + }, + { + "name": "flex_argument_justifycontent_space_around", + "value": "الفضاء المحيط" + }, + { + "name": "flex_argument_justifycontent_speac_evenly", + "value": "مساحة موحدة" + }, + { + "name": "flex_argument_alignItems", + "value": "تعديل alignitems في هذا فليكس" + }, + { + "name": "flex_argumen_alignItems_auto", + "value": "السيارات" + }, + { + "name": "flex_argumen_alignItems_start", + "value": "نقطة الانطلاق" + }, + { + "name": "flex_argumen_alignItems_center", + "value": "مركز" + }, + { + "name": "flex_argumen_alignItems_end", + "value": "نهاية ." + }, + { + "name": "flex_argumen_alignItems_stretch", + "value": "امتدت" + }, + { + "name": "flex_argumen_alignItems_baseline", + "value": "خط الأساس" + }, + { + "name": "flex_argument_alignContent", + "value": "تعديل aligncontent هذا فليكس" + }, + { + "name": "gridcontainer_title", + "value": "gridcontainer نظام الشبكة" + }, + { + "name": "gridcontainer_introdional_arguments", + "value": "تعديل gridcontainer المعلمة" + }, + { + "name": "gridcontainer_introdional_properties", + "value": "تعديل خاصية gridcontainer" + }, + { + "name": "gridcontainer_sizetype", + "value": "سيزتايب" + }, + { + "name": "gridcontainer_sizetype_xs", + "value": "اكس اس" + }, + { + "name": "gridcontainer_sizetype_sm", + "value": "خ" + }, + { + "name": "gridcontainer_sizetype_md", + "value": "إم دي" + }, + { + "name": "gridcontainer_sizetype_lg", + "value": "إل جي" + }, + { + "name": "gridcontainer_sizetype_auto", + "value": "السيارات" + }, + { + "name": "gridcontainer_column", + "value": "عمود" + }, + { + "name": "gridcontainer_gutter", + "value": "مزراب" + }, + { + "name": "gridcontainer_margin", + "value": "حافة" + }, + { + "name": "image_video_and_media", + "value": "صورة الفيديو ووسائل الإعلام" + }, + { + "name": "image_title", + "value": "صور" + }, + { + "name": "image_animator_title", + "value": "صورة انيماتور" + }, + { + "name": "video_title", + "value": "فيديو : ." + }, + { + "name": "plugin_component_title", + "value": "المكونات في مكونات" + }, + { + "name": "xcomponent_title", + "value": "العنصر العاشر" + }, + { + "name": "image_show_test", + "value": "عرض الصور" + }, + { + "name": "image_object_fit", + "value": "objectfit ؛ objectfit" + }, + { + "name": "image_sourcesize_height", + "value": "حجم الارتفاع" + }, + { + "name": "image_sourcesize_width", + "value": "حجم العرض" + }, + { + "name": "object_fit_cover", + "value": "تغطية" + }, + { + "name": "object_fit_contain", + "value": "احتواء" + }, + { + "name": "object_fit_auto", + "value": "السيارات" + }, + { + "name": "object_fit_fill", + "value": "ملأ" + }, + { + "name": "object_fit_scale_down", + "value": "تقليص حجم" + }, + { + "name": "object_fit_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "object_fit_change", + "value": "ObjectFitChange" + }, + { + "name": "image_sourcesize_change", + "value": "تغيير حجم المصدر" + }, + { + "name": "image_rendermode_original", + "value": "طريقة التقديم الأصلي" + }, + { + "name": "image_rendermode_template", + "value": "تقديم نموذج" + }, + { + "name": "image_renderMode_change", + "value": "تغيير طريقة التقديم" + }, + { + "name": "image_repeat_xy", + "value": "تكرار س ص" + }, + { + "name": "image_repeat_x", + "value": "تكرار س" + }, + { + "name": "image_repeat_y", + "value": "تكرار ذ" + }, + { + "name": "image_repeat_no", + "value": "لا تكرار" + }, + { + "name": "image_repeat_change", + "value": "تكرار التغييرات" + }, + { + "name": "image_fill_color_title", + "value": "ملء لون العنوان" + }, + { + "name": "image_animator_show", + "value": "صورة انيماتور شو" + }, + { + "name": "image_animator_control", + "value": "imageanimator السيطرة" + }, + { + "name": "video_show", + "value": "عرض الفيديو" + }, + { + "name": "video_auto_play", + "value": "اللعب التلقائي" + }, + { + "name": "video_controls_show", + "value": "عرض التحكم" + }, + { + "name": "video_muted_show", + "value": "عرض صامت" + }, + { + "name": "video_fit_change", + "value": "فيديوفيت" + }, + { + "name": "video_loop_show", + "value": "لوپشو" + }, + { + "name": "video_current_rate_change", + "value": "التغيرات في سعر الصرف الحالي" + }, + { + "name": "video_play_mode", + "value": "طريقة تشغيل الفيديو" + }, + { + "name": "video_play_switch", + "value": "تشغيل الفيديو التبديل" + }, + { + "name": "web_title", + "value": "شبكي" + }, + { + "name": "web_show", + "value": "وان نيتكوم" + }, + { + "name": "web_use_reason", + "value": "سبب" + }, + { + "name": "xcomponent_show", + "value": "إكسكومبونينتشو" + }, + { + "name": "textarea_title", + "value": "حقل النص" + }, + { + "name": "patternlock_title", + "value": "رمز قفل" + }, + { + "name": "search_title", + "value": "بحث ." + }, + { + "name": "textarea_textalign_start", + "value": "نقطة الانطلاق" + }, + { + "name": "textarea_textalign_center", + "value": "مركز" + }, + { + "name": "textarea_textalign_end", + "value": "نهاية ." + }, + { + "name": "textareaa_textalign_change", + "value": "textarealatextalignchange" + }, + { + "name": "textarea_show", + "value": "تكست اريشو" + }, + { + "name": "textarea_control", + "value": "السيطرة على منطقة النص" + }, + { + "name": "textarea_copyoptions_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "textarea_copyoptions_inapp", + "value": "داخل التطبيق" + }, + { + "name": "textarea_copyoptions_localdevice", + "value": "الأجهزة المحلية" + }, + { + "name": "textarea_copyoptions_change", + "value": "تغيير خيارات النسخ المتماثل" + }, + { + "name": "textarea_placeholder_change", + "value": "تغيير النائبة" + }, + { + "name": "textarea_caretcolor_change", + "value": "علوم التمريض" + }, + { + "name": "patternlock_active_color", + "value": "باترن لوك اكتف كولور" + }, + { + "name": "patternlock_path_color", + "value": "patternlockparhcolor" + }, + { + "name": "patternlock_select_color", + "value": "نمط قفل اختيار اللون" + }, + { + "name": "patternlock_regular_color", + "value": "patternlockregular اللون" + }, + { + "name": "patternlock_side_length", + "value": "نمط طول القفل" + }, + { + "name": "patternlock_circle_radius", + "value": "نمط قفل دائرة نصف قطرها" + }, + { + "name": "patternlock_pathstroke_width", + "value": "patternlockpath strokewidth" + }, + { + "name": "patternlock_change", + "value": "تغيير نمط قفل" + }, + { + "name": "search_textalign_change", + "value": "البحث عن النص محاذاة التغييرات" + }, + { + "name": "search_placeholder_change", + "value": "البحث عن تغيير النائبة" + }, + { + "name": "search_copyOption_change", + "value": "البحث عن خيارات النسخ المتماثل التغييرات" + }, + { + "name": "search_change", + "value": "البحث عن التغييرات" + }, + { + "name": "list_title", + "value": "قائمة" + }, + { + "name": "list_introduction_arguments", + "value": "قائمة المعلمات" + }, + { + "name": "list_introduction_properties", + "value": "قائمة خصائص" + }, + { + "name": "list_introduction_state", + "value": "شريط الحالة" + }, + { + "name": "list_properties_direction", + "value": "قائمة الاتجاه" + }, + { + "name": "list_properties_direction_vertical", + "value": "عمودي" + }, + { + "name": "list_properties_direction_Horizontal", + "value": "الاتجاه الأفقي" + }, + { + "name": "list_argument_space", + "value": "الفضاء ." + }, + { + "name": "list_properties_divider_stroke_width", + "value": "فاصل - السكتة الدماغية العرض" + }, + { + "name": "list_properties_scroll_bar_width", + "value": "سكرول بار - عرض" + }, + { + "name": "list_properties_scroll_bar_color", + "value": "سكرول بار - لون" + }, + { + "name": "list_properties_divider_color", + "value": "فاصل - لون" + }, + { + "name": "list_properties_scroll_bar", + "value": "سكرول بار" + }, + { + "name": "list_properties_scroll_bar_off", + "value": "قريب" + }, + { + "name": "list_properties_scroll_bar_on", + "value": "ون" + }, + { + "name": "list_properties_scroll_bar_auto", + "value": "السيارات" + }, + { + "name": "list_properties_initial_index", + "value": "initial index" + }, + { + "name": "list_properties_edge_effect", + "value": "تأثير الحافة" + }, + { + "name": "list_properties_edge_effect_spring", + "value": "الربيع ." + }, + { + "name": "list_properties_edge_effect_fade", + "value": "تلاشى" + }, + { + "name": "list_properties_edge_effect_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "list_properties_chain_animation", + "value": "سلسلة الرسوم المتحركة" + }, + { + "name": "list_properties_multi_selectable", + "value": "اختيار متعددة" + }, + { + "name": "list_properties_lanes", + "value": "حارة" + }, + { + "name": "list_properties_align_list_item", + "value": "اليگنليستیتم" + }, + { + "name": "list_properties_align_list_item_start", + "value": "نقطة الانطلاق" + }, + { + "name": "list_properties_align_list_item_Center", + "value": "مركز" + }, + { + "name": "list_properties_align_list_item_End", + "value": "نهاية ." + }, + { + "name": "list_introduction_delete", + "value": "غادر انقر فوق حذف البند" + }, + { + "name": "list_item_title", + "value": "قائمة البنود" + }, + { + "name": "list_item_properties_selectable", + "value": "اختياري" + }, + { + "name": "list_item_introduction_drag", + "value": "اسحب العناصر مع الماوس لعرض خصائص اختيارية" + }, + { + "name": "list_item_introduction_properties", + "value": "تعديل خصائص listitem" + }, + { + "name": "grid_title", + "value": "شبكة ." + }, + { + "name": "grid_item_title", + "value": "شبكة البند" + }, + { + "name": "grid_properties_columns_template", + "value": "columnstemplate ( السيطرة على نسبة العمود الثالث )" + }, + { + "name": "grid_properties_columns_gap", + "value": "إزالة العمود" + }, + { + "name": "girid_properties_rows_gap", + "value": "روس جاب" + }, + { + "name": "grid_properties_layout_direction", + "value": "تخطيط الاتجاه" + }, + { + "name": "grid_properties_layout_direction_row", + "value": "فصيلة" + }, + { + "name": "grid_properties_layout_direction_column", + "value": "عمود" + }, + { + "name": "grid_properties_layout_direction_row_reverse", + "value": "صف عكس" + }, + { + "name": "grid_properties_layout_direction_column_reverse", + "value": "العمود عكس" + }, + { + "name": "grid_properties_rows_template", + "value": "rowstemplate ( السيطرة على نسبة من السطر الثالث )" + }, + { + "name": "grid_item_introduction", + "value": "تغيير الموقع" + }, + { + "name": "grid_item_row_start", + "value": "تغيير رقم السطر الأول" + }, + { + "name": "grid_item_row_end", + "value": "تعديل رقم خط النهاية" + }, + { + "name": "grid_item_column_start", + "value": "تغيير رقم العمود الأولي" + }, + { + "name": "grid_item_column_end", + "value": "تعديل نهاية العمود رقم" + }, + { + "name": "swiper_introduction_arguments", + "value": "انزلاق تحكم" + }, + { + "name": "swiper_introduction_properties", + "value": "تعديل خصائص المنزلق" + }, + { + "name": "swiper_properties_disable_swipe", + "value": "تعطيل التحول إلى اليسار أو اليمين" + }, + { + "name": "swiper_properties_item_space", + "value": "المسافة بين الصفحات المنزلقة" + }, + { + "name": "swiper_properties_vertical", + "value": "انزلاق عمودي" + }, + { + "name": "swiper_properties_duration", + "value": "مدة الانتقال المتحركة في الألف" + }, + { + "name": "swiper_properties_loop", + "value": "تمكين حلقة" + }, + { + "name": "swiper_properties_interval", + "value": "التلقائي الفاصل الزمني ( الوحدة : ماجستير )" + }, + { + "name": "swiper_controller_next", + "value": "الصفحة التالية" + }, + { + "name": "swiper_controller_previous", + "value": "الصفحة السابقة" + }, + { + "name": "swiper_common_interfaces_and_properties", + "value": "واجهة عامة والممتلكات" + }, + { + "name": "swiper_custom_properties", + "value": "خصائص مخصصة الانتقال المتحركة" + }, + { + "name": "swiper_modify_custom_properties", + "value": "تعديل خصائص مخصصة الانتقال المتحركة" + }, + { + "name": "swiper_custom_property_opacity", + "value": "تغيير التعتيم مدة الرسوم المتحركة" + }, + { + "name": "swiper_custom_property_scale", + "value": "زيادة مدة الصفحة المتحركة" + }, + { + "name": "swiper_close_two_pages_together", + "value": "الجمع بين صفحتين عند التكبير" + }, + { + "name": "swiper_cancel_default_translate", + "value": "إلغاء الترجمة الافتراضية" + }, + { + "name": "swiper_property_auto_play", + "value": "اللعب التلقائي" + }, + { + "name": "swiper_custom_property_curve", + "value": "عرف الانتقال منحنى الرسوم المتحركة" + }, + { + "name": "navRouter_title", + "value": "توجيه الملاحة" + }, + { + "name": "navigation_title", + "value": "ملاحة" + }, + { + "name": "navigation_first_page", + "value": "تصفح الصفحة الرئيسية" + }, + { + "name": "navigation_second_page", + "value": "تصفح ب" + }, + { + "name": "navigation_third_page", + "value": "تصفح ب" + }, + { + "name": "navigation_first_page_push", + "value": "انتقل إلى الصفحة الثانية" + }, + { + "name": "navigation_first_page_active", + "value": "انقر فوق تبديل حالة التنشيط" + }, + { + "name": "navigation_second_page_push", + "value": "انتقل إلى الصفحة الثالثة" + }, + { + "name": "navigation_third_page_back", + "value": "العودة إلى الصفحة الأولى" + }, + { + "name": "navigation_basic_title", + "value": "أساسيات الملاحة" + }, + { + "name": "navigation_expand", + "value": "تكشفت" + }, + { + "name": "navigation_list_expand_title", + "value": "قائمة التصفح يوسع منطقة آمنة" + }, + { + "name": "navigation_bindsheet_title", + "value": "منطقة الأمان" + }, + { + "name": "navigation_expand_title", + "value": "الملاحة في المنطقة الأمنية الموسعة" + }, + { + "name": "navigation_unexpand", + "value": "لا تتكشف" + }, + { + "name": "navigation_split_title", + "value": "الملاحة تقسيم" + }, + { + "name": "navigation_sidebar_title", + "value": "شريط التنقل" + }, + { + "name": "navigation_navbar_list_nopara", + "value": "قائمة" + }, + { + "name": "navigation_navbar_list", + "value": "قائمة د" + }, + { + "name": "navigation_navcontent_list", + "value": "المحتوى د" + }, + { + "name": "navigation_hidebar_title", + "value": "إخفاء شريط التنقل" + }, + { + "name": "navigation_replace_title", + "value": "استبدال الملاحة" + }, + { + "name": "navigation_replace_page", + "value": "استبدال الصفحة الحالية" + }, + { + "name": "navigation_modechange_title", + "value": "تغيير نمط" + }, + { + "name": "navigation_rotate_screen", + "value": "تدوير الشاشة" + }, + { + "name": "navigation_modevalue", + "value": "سمود القيمة" + }, + { + "name": "navigation_mode_callback", + "value": "طريقة الاستدعاء" + }, + { + "name": "navigation_safearea_title", + "value": "سلامة الملاحة في المنطقة" + }, + { + "name": "navigation_safearea_default", + "value": "خرق" + }, + { + "name": "navigation_safearea_expand", + "value": "تكشفت" + }, + { + "name": "navigation_safearea_unexpand", + "value": "لا تتكشف" + }, + { + "name": "navigation_router_title", + "value": "هوب هوب هار" + }, + { + "name": "navigation_router_har1", + "value": "القفز إلى har1" + }, + { + "name": "navigation_router_har2", + "value": "القفز إلى هارتو" + }, + { + "name": "tabs_title", + "value": "تبويب" + }, + { + "name": "tabs_introduction_arguments", + "value": "تعديل بارامترات التبويب" + }, + { + "name": "tabs_introduction_properties", + "value": "تعديل خصائص التبويب" + }, + { + "name": "tabs_arguments_bar_position", + "value": "بار الكلمات" + }, + { + "name": "tabs_arguments_bar_position_start", + "value": "نقطة الانطلاق" + }, + { + "name": "tabs_arguments_bar_position_end", + "value": "نهاية ." + }, + { + "name": "tabs_properties_vertical", + "value": "عمودي" + }, + { + "name": "tabs_properties_bar_mode", + "value": "بار مود" + }, + { + "name": "tabs_properties_bar_mode_fixed", + "value": "ثابت" + }, + { + "name": "tabs_properties_bar_scrollable", + "value": "قابل للتدوير" + }, + { + "name": "tabs_properties_is_scrollable", + "value": "قابل للتدوير" + }, + { + "name": "tabs_properties_animation_duration", + "value": "مدة الرسوم المتحركة ( ماجستير )" + }, + { + "name": "tabs_arguments_controller", + "value": "التبديل إلى مؤشر محدد" + }, + { + "name": "tab_content_title", + "value": "علامة التبويب المحتوى" + }, + { + "name": "tab_content_introduction", + "value": "subtab / أسفل التبويب الجلاد" + }, + { + "name": "tab_content_side", + "value": "تبديل الشريط الجانبي" + }, + { + "name": "stepper_title", + "value": "السائر السائر المشروع" + }, + { + "name": "canvas_title", + "value": "قماش" + }, + { + "name": "circle_title", + "value": "دائرة" + }, + { + "name": "ellipse_title", + "value": "القطع الناقص" + }, + { + "name": "line_title", + "value": "خط" + }, + { + "name": "polyline_title", + "value": "خط الرسم البياني" + }, + { + "name": "path_title", + "value": "مسار" + }, + { + "name": "polygon_title", + "value": "مضلع" + }, + { + "name": "rect_title", + "value": "ناظر" + }, + { + "name": "shape_title", + "value": "شكل ." + }, + { + "name": "circle_change", + "value": "دائرة التغيير" + }, + { + "name": "circle_change_fill", + "value": "دائرة تغيير ملء" + }, + { + "name": "circle_change_radius", + "value": "دائرة نصف قطرها" + }, + { + "name": "circle_change_fillopacity", + "value": "جولة تغيير ملء التعتيم" + }, + { + "name": "circle_change_strokewidth", + "value": "عرض الحلزون" + }, + { + "name": "circle_stroke_dash", + "value": "سيركلي تروك داش" + }, + { + "name": "circle_stroke_color", + "value": "نمط دائري" + }, + { + "name": "circle_stroke_opacity", + "value": "مسار دائري التعتيم" + }, + { + "name": "ellipse_fill", + "value": "بيضاوي الشكل ملء" + }, + { + "name": "ellipse_stroke_color", + "value": "القطع الناقص لون السكتة الدماغية" + }, + { + "name": "ellipse_stroke_width", + "value": "عرض القطع الناقص" + }, + { + "name": "ellipse_width", + "value": "عرض القطع الناقص" + }, + { + "name": "ellipse_height", + "value": "ارتفاع القطع الناقص" + }, + { + "name": "ellipse_fill_opacity", + "value": "بيضاوي الشكل ملء التعتيم" + }, + { + "name": "ellipse_stroke_opacity", + "value": "حذفي ستروبوسكوبيك التعتيم" + }, + { + "name": "ellipse_stroke_dash", + "value": "إليبسو ستروك داش" + }, + { + "name": "line_start_point_x", + "value": "خط البداية س" + }, + { + "name": "line_start_point_y", + "value": "خط البداية ذ" + }, + { + "name": "line_end_point_x", + "value": "خط النهاية ذ" + }, + { + "name": "line_end_point_y", + "value": "خط النهاية ذ" + }, + { + "name": "line_stroke_width", + "value": "خط العرض" + }, + { + "name": "line_stroke_color", + "value": "لون الخط" + }, + { + "name": "line_stroke_opacity", + "value": "خط التعتيم" + }, + { + "name": "line_stroke_dash", + "value": "لين ستروك داش" + }, + { + "name": "polygon_fill", + "value": "مضلع ملء" + }, + { + "name": "polygon_fill_opacity", + "value": "مضلع ملء التعتيم" + }, + { + "name": "polygon_stroke_color", + "value": "مضلع لون السكتة الدماغية" + }, + { + "name": "polygon_stroke_opacity", + "value": "مضلع السكتة الدماغية التعتيم" + }, + { + "name": "polygon_stroke_width", + "value": "عرض مضلع السكتة الدماغية" + }, + { + "name": "polygon_stroke_dash", + "value": "بوليغون ستروك داش" + }, + { + "name": "polyline_first_x", + "value": "بولين فيرست إكس" + }, + { + "name": "polyline_first_y", + "value": "بولين فيرست" + }, + { + "name": "polyline_second_x", + "value": "بولين سيكوندكس" + }, + { + "name": "polyline_second_y", + "value": "بولين سيندي" + }, + { + "name": "polyline_third_x", + "value": "بولين ثيردكس" + }, + { + "name": "polyline_third_y", + "value": "بولين ثيردي" + }, + { + "name": "polyline_stroke_width", + "value": "عرض السكتة الدماغية" + }, + { + "name": "polyline_stroke_color", + "value": "لون الخط" + }, + { + "name": "polyline_stroke_dash", + "value": "بولين ستروك داش" + }, + { + "name": "polyline_stroke_opacity", + "value": "السكتة الدماغية التعتيم" + }, + { + "name": "rect_height", + "value": "ارتفاع المستطيل" + }, + { + "name": "rect_width", + "value": "عرض مستطيل" + }, + { + "name": "rect_radius_width", + "value": "عرض المستطيل" + }, + { + "name": "rect_radius_height", + "value": "ارتفاع المستقيم" + }, + { + "name": "rect_fill_opacity", + "value": "مستطيلة التعتيم" + }, + { + "name": "rect_stroke", + "value": "السكتة الدماغية المستقيم" + }, + { + "name": "rect_stroke_width", + "value": "rectstrokewidth" + }, + { + "name": "rect_stroke_dash", + "value": "ريكت سروك داش" + }, + { + "name": "rect_stroke_opacity", + "value": "rectstrokeopacity" + }, + { + "name": "rect_fill", + "value": "ريكتفيل" + }, + { + "name": "path_line", + "value": "باث لين" + }, + { + "name": "path_triangle", + "value": "باث تريانجل" + }, + { + "name": "path_square", + "value": "باث سكوير" + }, + { + "name": "path_polygon", + "value": "باث بوليغون" + }, + { + "name": "path_camber_first", + "value": "باث كامبر فيرست" + }, + { + "name": "path_camber_second", + "value": "باث كامبر سوند" + }, + { + "name": "path_camber_third", + "value": "باث كامبر ثيرد" + }, + { + "name": "path_commands_select", + "value": "اختيار مسار القيادة" + }, + { + "name": "path_fill", + "value": "باث فيل" + }, + { + "name": "path_fill_opacity", + "value": "pathfill التعتيم" + }, + { + "name": "path_stroke_color", + "value": "باث ستروك كولور" + }, + { + "name": "path_stroke_opacity", + "value": "باث ستوك اوباسيتي" + }, + { + "name": "path_stroke_dash", + "value": "باث ستوك داش" + }, + { + "name": "path_stroke_width", + "value": "باث ستوك ويدث" + }, + { + "name": "shape_fill", + "value": "شكل ملء" + }, + { + "name": "shape_stroke_color", + "value": "شكل ولون السكتة الدماغية" + }, + { + "name": "shape_view_port_x", + "value": "shapeviewportx" + }, + { + "name": "shape_view_port_y", + "value": "شابي فيو بورتي" + }, + { + "name": "shape_view_port_width", + "value": "shapeviewportwidth" + }, + { + "name": "shape_view_port_height", + "value": "shapeviewportheight" + }, + { + "name": "shape_stroke_opacity", + "value": "shapestroke التعتيم" + }, + { + "name": "shape_fill_opacity", + "value": "shapefill التعتيم" + }, + { + "name": "shape_stroke_width", + "value": "شكل عرض السكتة الدماغية" + }, + { + "name": "shape_stroke_dash", + "value": "شابستروك داش" + }, + { + "name": "web", + "value": "شبكي" + }, + { + "name": "canvas_fillStyle", + "value": "فيل ستايل" + }, + { + "name": "canvas_lineWidth", + "value": "خط العرض" + }, + { + "name": "canvas_strokeStyle", + "value": "ستروك ستايل" + }, + { + "name": "canvas_lineCap", + "value": "لين كاب" + }, + { + "name": "canvas_lineJoin", + "value": "خط الانضمام" + }, + { + "name": "canvas_miterLimit", + "value": "ميتر ليميت" + }, + { + "name": "canvas_font", + "value": "فونت" + }, + { + "name": "canvas_textAlign", + "value": "محاذاة النص" + }, + { + "name": "canvas_textBaseline", + "value": "خط النص" + }, + { + "name": "canvas_globalAlpha", + "value": "غلوبال ألفا" + }, + { + "name": "canvas_lineDashOffset", + "value": "لين داش اوفست" + }, + { + "name": "canvas_globalCompositeOperation", + "value": "عملية التوليف العالمية" + }, + { + "name": "canvas_imageSmoothingEnabled", + "value": "imagesmoothing تمكين" + }, + { + "name": "canvas_createLinearGradient", + "value": "إنشاء التدرج الخطي" + }, + { + "name": "cavas_createRadialGradient", + "value": "خلق التدرج الإشعاعي" + }, + { + "name": "canvas_createRadialGradient", + "value": "خلق التدرج الإشعاعي" + }, + { + "name": "canvas_fillRect", + "value": "فيلريكت" + }, + { + "name": "canvas_strokeRect", + "value": "ستروك ريكت" + }, + { + "name": "canvas_fillText", + "value": "فيلت تكست" + }, + { + "name": "canvas_strokeText", + "value": "ستروكيتكست" + }, + { + "name": "canvas_measureText", + "value": "ميسوريتكست" + }, + { + "name": "canvas_stroke", + "value": "( ضرب ، ضرب ، الخ )" + }, + { + "name": "canvas_createPattern", + "value": "كرياتيباترن" + }, + { + "name": "canvas_fill", + "value": "شغل" + }, + { + "name": "canvas_clip", + "value": "قطع" + }, + { + "name": "canvas_rotate", + "value": "استدارة" + }, + { + "name": "canvas_scale", + "value": "مقياس" + }, + { + "name": "canvas_drawImage", + "value": "دراويماغي" + }, + { + "name": "canvas_getImageData", + "value": "الحصول على بيانات الصورة" + }, + { + "name": "canvas_putImageData", + "value": "بوتیمگدیتا" + }, + { + "name": "canvas_setLineDash", + "value": "ست لين داش" + }, + { + "name": "canvas_getLineDash", + "value": "جيتلين داش" + }, + { + "name": "canvas_transferFromImageBitmap", + "value": "transferfrom imagebitmap" + }, + { + "name": "canvas_toDataURL", + "value": "توداتورل" + }, + { + "name": "cavnas_clearRect", + "value": "كلير ريكت" + }, + { + "name": "canvas_clearRect", + "value": "كلير ريكت" + }, + { + "name": "canvas_shadowBlur", + "value": "شادوبلور" + }, + { + "name": "canvas_shadowColor", + "value": "لون الظل" + }, + { + "name": "canvas_shadowOffsetX", + "value": "شادووفسيتكس" + }, + { + "name": "canvas_shadowOffsetY", + "value": "الظل تعويض ذ" + }, + { + "name": "canvas_addColorStop", + "value": "addclorstop" + }, + { + "name": "canvas_beginPath", + "value": "بيغن باث" + }, + { + "name": "canvas_moveTo", + "value": "تحرك" + }, + { + "name": "canvas_lineTo", + "value": "لين تو" + }, + { + "name": "canvas_closePath", + "value": "كلوس باث" + }, + { + "name": "canvas_bezierCurveTo", + "value": "بيزير كيرفيتو" + }, + { + "name": "canvas_quadraticCurveTo", + "value": "الرسم البياني مع منحنى بيزيير" + }, + { + "name": "canvas_arc", + "value": "قوس" + }, + { + "name": "canvas_arcTo", + "value": "اركتو" + }, + { + "name": "canvas_ellipse", + "value": "القطع الناقص" + }, + { + "name": "canvas_rect", + "value": "ريست" + }, + { + "name": "canvas_transform", + "value": "تحول" + }, + { + "name": "canvas_setTransform", + "value": "ست ترانسفورم" + }, + { + "name": "canvas_translate", + "value": "ترجمة ." + }, + { + "name": "canvas_imageSmoothingQuality", + "value": "تجانس الصورة" + }, + { + "name": "navigator_title", + "value": "الملاح" + }, + { + "name": "navigator_first_page", + "value": "الصفحة الأولى من Navigaor" + }, + { + "name": "navigator_second_page", + "value": "الصفحة الثانية من المستكشف" + }, + { + "name": "navigator_third_page", + "value": "الصفحة الثالثة من المستكشف" + }, + { + "name": "navigator_first_page_push", + "value": "انتقل إلى الصفحة الثانية" + }, + { + "name": "navigator_first_page_active", + "value": "انقر فوق تبديل حالة التنشيط" + }, + { + "name": "navigator_second_page_push", + "value": "انتقل إلى الصفحة الثالثة" + }, + { + "name": "navigator_third_page_back", + "value": "العودة إلى الصفحة الأولى" + }, + { + "name": "navigator_return_message", + "value": "! مرحباً - ! مرحباً - هذه هي الصفحة الأولى من المعلمات" + }, + { + "name": "component_id_press_to_see_attributeModifier", + "value": "عرض attributemodifier حسب العنصر رقم" + }, + { + "name": "component_id_click_to_see_attributeModifier", + "value": "انقر على عنصر معرف لعرض attributemodifier" + }, + { + "name": "component_id_disable_to_see_attributeModifier", + "value": "العنصر رقم تعطيل عرض attributemodifier" + }, + { + "name": "component_id_disable_radio", + "value": "العنصر رقم تعطيل الراديو" + }, + { + "name": "component_id_press_list_to_see_attributeModifier", + "value": "عنصر معرف عرض attributemodifier القائمة" + }, + { + "name": "water_flow_title", + "value": "تدفق المياه" + }, + { + "name": "water_flow_controller", + "value": "تحكم تدفق المياه" + }, + { + "name": "water_flow_properties", + "value": "خصائص تدفق المياه" + }, + { + "name": "water_flow_controller_scrollEdge", + "value": "سكرول ايدج" + }, + { + "name": "water_flow_controller_scrollBy", + "value": "المتداول الصحافة" + }, + { + "name": "water_flow_controller_top", + "value": "توب ." + }, + { + "name": "water_flow_controller_bottom", + "value": "القاع" + }, + { + "name": "water_flow_properties_scroll_bar_width", + "value": "scrollbar العرض" + }, + { + "name": "water_flow_properties_scroll_bar_color", + "value": "لون سكرول بار" + }, + { + "name": "water_flow_properties_scroll_bar", + "value": "سكرول بار" + }, + { + "name": "water_flow_properties_edge_effect", + "value": "تأثير الحافة" + }, + { + "name": "water_flow_properties_edge_effect_spring", + "value": "الربيع ." + }, + { + "name": "water_flow_properties_edge_effect_fade", + "value": "تلاشى" + }, + { + "name": "water_flow_properties_edge_effect_none", + "value": "هل أنت بخير ؟ - لا -" + }, + { + "name": "horizontal_reach_start", + "value": "التمرير الأفقي على reachstart" + }, + { + "name": "horizontal_reach_end", + "value": "التمرير الأفقي على reachend" + }, + { + "name": "vertical_reach_start", + "value": "التمرير الرأسي على reachstart" + }, + { + "name": "vertical_reach_end", + "value": "التمرير الرأسي على reachend" + }, + { + "name": "current_initialIndex", + "value": "initialindex الحالي هو :" + }, + { + "name": "modify_initialIndex_tips", + "value": "بعد initialindex التغييرات ، أدخل هذه الصفحة مرة أخرى" + }, + { + "name": "current_scroll_event", + "value": "أحداث التمرير الحالية :" + }, + { + "name": "current_scroll_state", + "value": "الوضع الحالي :" + }, + { + "name": "current_scroll_distance", + "value": "المسافة الحالية التمرير :" + }, + { + "name": "current_scroll_index_first", + "value": "مؤشر التمرير الحالي ، الأول :" + }, + { + "name": "current_scroll_index_last", + "value": "وأخيرا :" + }, + { + "name": "current_event_value", + "value": "لا أحداث" + }, + { + "name": "current_event_on_scroll", + "value": "على المتداول" + }, + { + "name": "current_event_on_scroll_index", + "value": "أونسولل إنديكس" + }, + { + "name": "current_event_on_scroll_start", + "value": "أونسكرول ستارت" + }, + { + "name": "current_event_on_scroll_stop", + "value": "انسكولستوب" + }, + { + "name": "panel_background_color", + "value": "#ffffff" + }, + { + "name": "multiple_attribute_take_effect", + "value": "دينامية مجموعة خصائص العنصر : خصائص متعددة الإعدادات في وقت واحد" + }, + { + "name": "click_to_see_image_border_change", + "value": "انقر على زر عرض تغيير حدود الصورة" + }, + { + "name": "dynamical_updates_ui_directly", + "value": "خصائص العنصر هي مجموعة ديناميكية ، غير الدولة متغير يؤدي مباشرة إلى تحديث واجهة المستخدم" + }, + { + "name": "click_to_see_component_change", + "value": "انقر على زر عرض عنصر تغيير قيمة الممتلكات" + }, + { + "name": "click_to_see_text_component_change", + "value": "انقر فوق تحديث مكونات النص البناء باستخدام المعلمات" + } + ] } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/harA/src/main/resources/ar/element/string.json b/code/UI/ArkTsComponentCollection/ComponentCollection/harA/src/main/resources/ar/element/string.json index 1c5e36d89f938b805d9f9e32b66f627fef7ff1f5..6aaf8f9f5f3331981bf5200e7d0f79834110ba9b 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/harA/src/main/resources/ar/element/string.json +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/harA/src/main/resources/ar/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "navigation_router_har2", - "value": "Har2 قفز إلى" - } - ] -} +{ + "string": [ + { + "name": "navigation_router_har2", + "value": "Har2 قفز إلى" + } + ] +} diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/harB/src/main/resources/ar/element/string.json b/code/UI/ArkTsComponentCollection/ComponentCollection/harB/src/main/resources/ar/element/string.json index ee4eff18f6afffffec4980fb3fba41a0d393c339..2da7944a84da16f714d9a8d5a5551ad4a6721008 100644 --- a/code/UI/ArkTsComponentCollection/ComponentCollection/harB/src/main/resources/ar/element/string.json +++ b/code/UI/ArkTsComponentCollection/ComponentCollection/harB/src/main/resources/ar/element/string.json @@ -1,8 +1,8 @@ -{ - "string": [ - { - "name": "navigation_router_har1", - "value": "Har1 قفز إلى" - } - ] +{ + "string": [ + { + "name": "navigation_router_har1", + "value": "Har1 قفز إلى" + } + ] } \ No newline at end of file diff --git a/code/UI/ArkTsComponentCollection/ComponentCollection/screenshots/devices/general.jpeg b/code/UI/ArkTsComponentCollection/ComponentCollection/screenshots/devices/general.jpeg old mode 100755 new mode 100644